@csszyx/unplugin 0.7.0 → 0.9.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/README.md +32 -1
- package/dist/css-mangler.cjs +27 -72
- package/dist/css-mangler.d.cts +2 -1
- package/dist/{css-mangler.d.ts → css-mangler.d.mts} +2 -1
- package/dist/{chunk-4M7CPGP7.js → css-mangler.mjs} +13 -31
- package/dist/index.cjs +47 -1856
- package/dist/index.d.cts +15 -2
- package/dist/{index.d.ts → index.d.mts} +13 -3
- package/dist/index.mjs +16 -0
- package/dist/shared/unplugin.BEOG6ePC.mjs +2159 -0
- package/dist/shared/unplugin.CL0F6RZa.cjs +2192 -0
- package/dist/vite.cjs +24 -1678
- package/dist/vite.d.cts +2 -2
- package/dist/{vite.d.ts → vite.d.mts} +1 -1
- package/dist/vite.mjs +20 -0
- package/dist/webpack.cjs +24 -1687
- package/dist/webpack.d.cts +2 -2
- package/dist/{webpack.d.ts → webpack.d.mts} +1 -1
- package/dist/webpack.mjs +20 -0
- package/package.json +51 -27
- package/dist/chunk-GXGGTRUA.js +0 -1602
- package/dist/css-mangler.js +0 -14
- package/dist/index.js +0 -51
- package/dist/vite.js +0 -10
- package/dist/webpack.js +0 -10
- /package/dist/{unplugin-DUbr5w-N.d.cts → shared/unplugin.DUbr5w-N.d.cts} +0 -0
- /package/dist/{unplugin-DUbr5w-N.d.ts → shared/unplugin.DUbr5w-N.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -66,10 +66,41 @@ module.exports = {
|
|
|
66
66
|
|
|
67
67
|
## Features
|
|
68
68
|
|
|
69
|
-
- **sz prop transform** -- Compiles `sz={{ }}` objects into `className` strings
|
|
69
|
+
- **sz prop transform** -- Compiles `sz={{ }}` objects into `className` strings. Defaults to the **native Rust engine** through the optional `@csszyx/core-*` platform package; opt back into the previous oxc-parser JavaScript path with `build.parser: "oxc"`, or fall through to Babel with `build.parser: "babel"`.
|
|
70
70
|
- **HTML injection** -- Injects mangle maps and checksums for SSR hydration
|
|
71
71
|
- **HMR support** -- Updates styles instantly during development
|
|
72
72
|
- **CSS mangling** -- Compresses class names (e.g., `text-center` -> `z`) in production builds
|
|
73
|
+
- **File filters** -- Top-level `include` / `exclude` (glob or RegExp) skip large generated files before the AST budget guard fires; see [Config Overview](https://csszyx.com/config/overview#file-filters)
|
|
74
|
+
|
|
75
|
+
## Parser selection
|
|
76
|
+
|
|
77
|
+
The default parser is `rust`, which runs through the native engine in the
|
|
78
|
+
matching optional `@csszyx/core-*` platform package. When that package is
|
|
79
|
+
missing, csszyx fails loudly instead of silently falling back to another
|
|
80
|
+
parser; reinstall to pick up the optional dependency for your platform, or
|
|
81
|
+
opt into the JavaScript engine explicitly.
|
|
82
|
+
|
|
83
|
+
Per project:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
csszyx({
|
|
87
|
+
build: { parser: "oxc" }, // JavaScript oxc parser, no native addon
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Per build:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
CSSZYX_PARSER=oxc pnpm build
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The default `rust` path uses the native engine and shares the same
|
|
98
|
+
`className` output shape as the JavaScript parsers. `build.parser: "oxc"`
|
|
99
|
+
uses the previous JavaScript oxc-parser path with surgical magic-string
|
|
100
|
+
edits to preserve source formatting outside touched ranges.
|
|
101
|
+
`build.parser: "babel"` routes prescan, transform, and HMR discovery
|
|
102
|
+
through the legacy Babel implementation as a final compatibility escape
|
|
103
|
+
hatch.
|
|
73
104
|
|
|
74
105
|
## License
|
|
75
106
|
|
package/dist/css-mangler.cjs
CHANGED
|
@@ -1,44 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const postcss = require('postcss');
|
|
4
|
+
const selectorParser = require('postcss-selector-parser');
|
|
5
|
+
|
|
6
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
7
|
+
|
|
8
|
+
const postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
|
|
9
|
+
const selectorParser__default = /*#__PURE__*/_interopDefaultCompat(selectorParser);
|
|
29
10
|
|
|
30
|
-
// src/css-mangler.ts
|
|
31
|
-
var css_mangler_exports = {};
|
|
32
|
-
__export(css_mangler_exports, {
|
|
33
|
-
createPostCSSPlugin: () => createPostCSSPlugin,
|
|
34
|
-
escapeCSSClassName: () => escapeCSSClassName,
|
|
35
|
-
mangleCSS: () => mangleCSS,
|
|
36
|
-
mangleCSSSync: () => mangleCSSSync,
|
|
37
|
-
unescapeTailwindClass: () => unescapeTailwindClass
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(css_mangler_exports);
|
|
40
|
-
var import_postcss = __toESM(require("postcss"), 1);
|
|
41
|
-
var import_postcss_selector_parser = __toESM(require("postcss-selector-parser"), 1);
|
|
42
11
|
function unescapeTailwindClass(escapedName) {
|
|
43
12
|
let result = "";
|
|
44
13
|
let i = 0;
|
|
@@ -49,9 +18,9 @@ function unescapeTailwindClass(escapedName) {
|
|
|
49
18
|
break;
|
|
50
19
|
}
|
|
51
20
|
const char = escapedName[i];
|
|
52
|
-
if (/[0-9a-
|
|
21
|
+
if (/[0-9a-f]/i.test(char)) {
|
|
53
22
|
let hexStr = "";
|
|
54
|
-
while (i < escapedName.length && /[0-9a-
|
|
23
|
+
while (i < escapedName.length && /[0-9a-f]/i.test(escapedName[i]) && hexStr.length < 6) {
|
|
55
24
|
hexStr += escapedName[i];
|
|
56
25
|
i++;
|
|
57
26
|
}
|
|
@@ -79,20 +48,20 @@ function escapeCSSClassName(className) {
|
|
|
79
48
|
const char = className[i];
|
|
80
49
|
const code = char.charCodeAt(0);
|
|
81
50
|
if (i === 0) {
|
|
82
|
-
if (
|
|
83
|
-
result +=
|
|
51
|
+
if (/\d/.test(char)) {
|
|
52
|
+
result += `\\3${char} `;
|
|
84
53
|
continue;
|
|
85
54
|
}
|
|
86
55
|
if (char === "-" && i + 1 < className.length) {
|
|
87
56
|
const next = className[i + 1];
|
|
88
|
-
if (
|
|
57
|
+
if (/\d/.test(next) || next === "-") {
|
|
89
58
|
result += "\\-";
|
|
90
59
|
continue;
|
|
91
60
|
}
|
|
92
61
|
}
|
|
93
62
|
}
|
|
94
63
|
if (/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/.test(char)) {
|
|
95
|
-
result +=
|
|
64
|
+
result += `\\${char}`;
|
|
96
65
|
} else if (code >= 128) {
|
|
97
66
|
result += char;
|
|
98
67
|
} else {
|
|
@@ -102,7 +71,7 @@ function escapeCSSClassName(className) {
|
|
|
102
71
|
return result;
|
|
103
72
|
}
|
|
104
73
|
function createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses) {
|
|
105
|
-
return (
|
|
74
|
+
return selectorParser__default((selectors) => {
|
|
106
75
|
selectors.walkClasses((classNode) => {
|
|
107
76
|
const originalValue = classNode.value;
|
|
108
77
|
const unescapedValue = unescapeTailwindClass(originalValue);
|
|
@@ -127,11 +96,7 @@ async function mangleCSS(css, mangleMap, options = {}) {
|
|
|
127
96
|
const mangledClasses = /* @__PURE__ */ new Set();
|
|
128
97
|
const unmangledClasses = /* @__PURE__ */ new Set();
|
|
129
98
|
let transformedCount = 0;
|
|
130
|
-
const selectorProcessor = createSelectorProcessor(
|
|
131
|
-
mangleMap,
|
|
132
|
-
mangledClasses,
|
|
133
|
-
unmangledClasses
|
|
134
|
-
);
|
|
99
|
+
const selectorProcessor = createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses);
|
|
135
100
|
const csszyxManglerPlugin = {
|
|
136
101
|
postcssPlugin: "csszyx-css-mangler",
|
|
137
102
|
Rule(rule) {
|
|
@@ -149,7 +114,7 @@ async function mangleCSS(css, mangleMap, options = {}) {
|
|
|
149
114
|
}
|
|
150
115
|
}
|
|
151
116
|
};
|
|
152
|
-
const result = await (
|
|
117
|
+
const result = await postcss__default([csszyxManglerPlugin]).process(css, {
|
|
153
118
|
from: options.from
|
|
154
119
|
});
|
|
155
120
|
if (options.debug) {
|
|
@@ -168,12 +133,8 @@ function mangleCSSSync(css, mangleMap, options = {}) {
|
|
|
168
133
|
const mangledClasses = /* @__PURE__ */ new Set();
|
|
169
134
|
const unmangledClasses = /* @__PURE__ */ new Set();
|
|
170
135
|
let transformedCount = 0;
|
|
171
|
-
const selectorProcessor = createSelectorProcessor(
|
|
172
|
-
|
|
173
|
-
mangledClasses,
|
|
174
|
-
unmangledClasses
|
|
175
|
-
);
|
|
176
|
-
const root = import_postcss.default.parse(css, { from: options.from });
|
|
136
|
+
const selectorProcessor = createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses);
|
|
137
|
+
const root = postcss__default.parse(css, { from: options.from });
|
|
177
138
|
root.walkRules((rule) => {
|
|
178
139
|
try {
|
|
179
140
|
const originalSelector = rule.selector;
|
|
@@ -203,11 +164,7 @@ function mangleCSSSync(css, mangleMap, options = {}) {
|
|
|
203
164
|
function createPostCSSPlugin(mangleMap, options = {}) {
|
|
204
165
|
const mangledClasses = /* @__PURE__ */ new Set();
|
|
205
166
|
const unmangledClasses = /* @__PURE__ */ new Set();
|
|
206
|
-
const selectorProcessor = createSelectorProcessor(
|
|
207
|
-
mangleMap,
|
|
208
|
-
mangledClasses,
|
|
209
|
-
unmangledClasses
|
|
210
|
-
);
|
|
167
|
+
const selectorProcessor = createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses);
|
|
211
168
|
return {
|
|
212
169
|
postcssPlugin: "csszyx-css-mangler",
|
|
213
170
|
Rule(rule) {
|
|
@@ -230,11 +187,9 @@ function createPostCSSPlugin(mangleMap, options = {}) {
|
|
|
230
187
|
}
|
|
231
188
|
};
|
|
232
189
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
unescapeTailwindClass
|
|
240
|
-
});
|
|
190
|
+
|
|
191
|
+
exports.createPostCSSPlugin = createPostCSSPlugin;
|
|
192
|
+
exports.escapeCSSClassName = escapeCSSClassName;
|
|
193
|
+
exports.mangleCSS = mangleCSS;
|
|
194
|
+
exports.mangleCSSSync = mangleCSSSync;
|
|
195
|
+
exports.unescapeTailwindClass = unescapeTailwindClass;
|
package/dist/css-mangler.d.cts
CHANGED
|
@@ -120,4 +120,5 @@ declare function mangleCSSSync(css: string, mangleMap: MangleMap, options?: CSSM
|
|
|
120
120
|
*/
|
|
121
121
|
declare function createPostCSSPlugin(mangleMap: MangleMap, options?: CSSManglerOptions): postcss.Plugin;
|
|
122
122
|
|
|
123
|
-
export {
|
|
123
|
+
export { createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass };
|
|
124
|
+
export type { CSSManglerOptions, CSSManglerResult, MangleMap };
|
|
@@ -120,4 +120,5 @@ declare function mangleCSSSync(css: string, mangleMap: MangleMap, options?: CSSM
|
|
|
120
120
|
*/
|
|
121
121
|
declare function createPostCSSPlugin(mangleMap: MangleMap, options?: CSSManglerOptions): postcss.Plugin;
|
|
122
122
|
|
|
123
|
-
export {
|
|
123
|
+
export { createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass };
|
|
124
|
+
export type { CSSManglerOptions, CSSManglerResult, MangleMap };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
import selectorParser from 'postcss-selector-parser';
|
|
3
|
+
|
|
4
4
|
function unescapeTailwindClass(escapedName) {
|
|
5
5
|
let result = "";
|
|
6
6
|
let i = 0;
|
|
@@ -11,9 +11,9 @@ function unescapeTailwindClass(escapedName) {
|
|
|
11
11
|
break;
|
|
12
12
|
}
|
|
13
13
|
const char = escapedName[i];
|
|
14
|
-
if (/[0-9a-
|
|
14
|
+
if (/[0-9a-f]/i.test(char)) {
|
|
15
15
|
let hexStr = "";
|
|
16
|
-
while (i < escapedName.length && /[0-9a-
|
|
16
|
+
while (i < escapedName.length && /[0-9a-f]/i.test(escapedName[i]) && hexStr.length < 6) {
|
|
17
17
|
hexStr += escapedName[i];
|
|
18
18
|
i++;
|
|
19
19
|
}
|
|
@@ -41,20 +41,20 @@ function escapeCSSClassName(className) {
|
|
|
41
41
|
const char = className[i];
|
|
42
42
|
const code = char.charCodeAt(0);
|
|
43
43
|
if (i === 0) {
|
|
44
|
-
if (
|
|
45
|
-
result +=
|
|
44
|
+
if (/\d/.test(char)) {
|
|
45
|
+
result += `\\3${char} `;
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
48
|
if (char === "-" && i + 1 < className.length) {
|
|
49
49
|
const next = className[i + 1];
|
|
50
|
-
if (
|
|
50
|
+
if (/\d/.test(next) || next === "-") {
|
|
51
51
|
result += "\\-";
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
if (/[!"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/.test(char)) {
|
|
57
|
-
result +=
|
|
57
|
+
result += `\\${char}`;
|
|
58
58
|
} else if (code >= 128) {
|
|
59
59
|
result += char;
|
|
60
60
|
} else {
|
|
@@ -89,11 +89,7 @@ async function mangleCSS(css, mangleMap, options = {}) {
|
|
|
89
89
|
const mangledClasses = /* @__PURE__ */ new Set();
|
|
90
90
|
const unmangledClasses = /* @__PURE__ */ new Set();
|
|
91
91
|
let transformedCount = 0;
|
|
92
|
-
const selectorProcessor = createSelectorProcessor(
|
|
93
|
-
mangleMap,
|
|
94
|
-
mangledClasses,
|
|
95
|
-
unmangledClasses
|
|
96
|
-
);
|
|
92
|
+
const selectorProcessor = createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses);
|
|
97
93
|
const csszyxManglerPlugin = {
|
|
98
94
|
postcssPlugin: "csszyx-css-mangler",
|
|
99
95
|
Rule(rule) {
|
|
@@ -130,11 +126,7 @@ function mangleCSSSync(css, mangleMap, options = {}) {
|
|
|
130
126
|
const mangledClasses = /* @__PURE__ */ new Set();
|
|
131
127
|
const unmangledClasses = /* @__PURE__ */ new Set();
|
|
132
128
|
let transformedCount = 0;
|
|
133
|
-
const selectorProcessor = createSelectorProcessor(
|
|
134
|
-
mangleMap,
|
|
135
|
-
mangledClasses,
|
|
136
|
-
unmangledClasses
|
|
137
|
-
);
|
|
129
|
+
const selectorProcessor = createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses);
|
|
138
130
|
const root = postcss.parse(css, { from: options.from });
|
|
139
131
|
root.walkRules((rule) => {
|
|
140
132
|
try {
|
|
@@ -165,11 +157,7 @@ function mangleCSSSync(css, mangleMap, options = {}) {
|
|
|
165
157
|
function createPostCSSPlugin(mangleMap, options = {}) {
|
|
166
158
|
const mangledClasses = /* @__PURE__ */ new Set();
|
|
167
159
|
const unmangledClasses = /* @__PURE__ */ new Set();
|
|
168
|
-
const selectorProcessor = createSelectorProcessor(
|
|
169
|
-
mangleMap,
|
|
170
|
-
mangledClasses,
|
|
171
|
-
unmangledClasses
|
|
172
|
-
);
|
|
160
|
+
const selectorProcessor = createSelectorProcessor(mangleMap, mangledClasses, unmangledClasses);
|
|
173
161
|
return {
|
|
174
162
|
postcssPlugin: "csszyx-css-mangler",
|
|
175
163
|
Rule(rule) {
|
|
@@ -193,10 +181,4 @@ function createPostCSSPlugin(mangleMap, options = {}) {
|
|
|
193
181
|
};
|
|
194
182
|
}
|
|
195
183
|
|
|
196
|
-
export {
|
|
197
|
-
unescapeTailwindClass,
|
|
198
|
-
escapeCSSClassName,
|
|
199
|
-
mangleCSS,
|
|
200
|
-
mangleCSSSync,
|
|
201
|
-
createPostCSSPlugin
|
|
202
|
-
};
|
|
184
|
+
export { createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass };
|