@vitus-labs/styler 2.0.0-alpha.6 → 2.0.0-alpha.7
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/lib/index.js +41 -10
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -25,18 +25,49 @@ const resolve = (strings, values, props) => {
|
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Normalize resolved CSS text for strict `insertRule` compatibility.
|
|
28
|
-
*
|
|
29
|
-
* that
|
|
30
|
-
*
|
|
28
|
+
*
|
|
29
|
+
* Single-pass scanner that handles all cleanup in one traversal:
|
|
30
|
+
* - Strips block comments and line comments (preserves :// in URLs)
|
|
31
|
+
* - Collapses whitespace to single spaces
|
|
32
|
+
* - Removes redundant semicolons
|
|
33
|
+
* - Trims leading/trailing whitespace
|
|
31
34
|
*/
|
|
32
35
|
const normalizeCSS = (css) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const len = css.length;
|
|
37
|
+
let out = "";
|
|
38
|
+
let space = false;
|
|
39
|
+
let last = 0;
|
|
40
|
+
for (let i = 0; i < len; i++) {
|
|
41
|
+
const c = css.charCodeAt(i);
|
|
42
|
+
if (c === 47 && css.charCodeAt(i + 1) === 42) {
|
|
43
|
+
const end = css.indexOf("*/", i + 2);
|
|
44
|
+
i = end === -1 ? len : end + 1;
|
|
45
|
+
space = true;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (c === 47 && css.charCodeAt(i + 1) === 47 && last !== 58) {
|
|
49
|
+
const nl = css.indexOf("\n", i + 2);
|
|
50
|
+
i = nl === -1 ? len : nl;
|
|
51
|
+
space = true;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (c === 32 || c === 9 || c === 10 || c === 13 || c === 12) {
|
|
55
|
+
space = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (c === 59) {
|
|
59
|
+
if (last === 0 || last === 123 || last === 125 || last === 59) continue;
|
|
60
|
+
space = false;
|
|
61
|
+
out += ";";
|
|
62
|
+
last = 59;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (space && last !== 0) out += " ";
|
|
66
|
+
space = false;
|
|
67
|
+
out += css[i];
|
|
68
|
+
last = c;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
40
71
|
};
|
|
41
72
|
const resolveValue = (value, props) => {
|
|
42
73
|
if (value == null || value === false || value === true) return "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/styler",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7+006ed81",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
6
|
"maintainers": [
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"goober": "^2.1.18",
|
|
64
64
|
"styled-components": "^6.3.9"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "006ed81acbebc3a0a827c3f265a37b0722f2ae75"
|
|
67
67
|
}
|