catom 2.0.2 → 2.0.3
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/dist/plugin.d.ts +0 -5
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -42
- package/package.json +3 -5
package/dist/plugin.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
import { transform } from "lightningcss";
|
|
3
2
|
export interface CatomOptions {
|
|
4
3
|
/** Function name to transform. Default: "css" */
|
|
5
4
|
functionName?: string;
|
|
6
|
-
/** LightningCSS browser targets */
|
|
7
|
-
targets?: Parameters<typeof transform>[0]["targets"];
|
|
8
|
-
/** Minify CSS output. Default: true in production */
|
|
9
|
-
minify?: boolean;
|
|
10
5
|
/** File patterns to include. Default: /\.[jt]sx?$/ */
|
|
11
6
|
include?: RegExp | RegExp[];
|
|
12
7
|
/** File patterns to exclude */
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC,MAAM,WAAW,YAAY;IAC3B,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B;AAKD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,EAAE,CAoFlE"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import { transform } from "lightningcss";
|
|
2
1
|
import AST from "unplugin-ast/vite";
|
|
3
2
|
import { createCatomTransformer } from "./transformer.js";
|
|
4
3
|
import { dedupeRules } from "./css.js";
|
|
5
4
|
const VIRTUAL_ID = "virtual:catom.css";
|
|
6
5
|
const RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_ID;
|
|
7
|
-
const DEFAULT_TARGETS = {
|
|
8
|
-
chrome: 80 << 16,
|
|
9
|
-
firefox: 80 << 16,
|
|
10
|
-
safari: 14 << 16,
|
|
11
|
-
};
|
|
12
6
|
export default function catom(options = {}) {
|
|
13
|
-
const { functionName = "css",
|
|
7
|
+
const { functionName = "css", include = /\.[jt]sx?$/, exclude, } = options;
|
|
14
8
|
// Collect CSS rules from all files.
|
|
15
9
|
// Using a Set for automatic deduplication (deterministic hashing means same rule = same string)
|
|
16
10
|
const collectedRules = new Set();
|
|
17
|
-
let isDev = false;
|
|
18
11
|
// The AST plugin handles transformation
|
|
19
12
|
const astPlugin = AST({
|
|
20
13
|
include: Array.isArray(include) ? include : [include],
|
|
@@ -32,9 +25,6 @@ export default function catom(options = {}) {
|
|
|
32
25
|
const cssPlugin = {
|
|
33
26
|
name: "catom:css",
|
|
34
27
|
enforce: "post",
|
|
35
|
-
configResolved(config) {
|
|
36
|
-
isDev = config.command === "serve";
|
|
37
|
-
},
|
|
38
28
|
buildStart() {
|
|
39
29
|
// Clear collected rules at the start of each build
|
|
40
30
|
collectedRules.clear();
|
|
@@ -58,26 +48,11 @@ export default function catom(options = {}) {
|
|
|
58
48
|
if (collectedRules.size === 0)
|
|
59
49
|
return [];
|
|
60
50
|
const css = dedupeRules([...collectedRules]);
|
|
61
|
-
const shouldMinify = minify ?? !isDev;
|
|
62
|
-
let finalCss;
|
|
63
|
-
try {
|
|
64
|
-
const { code } = transform({
|
|
65
|
-
code: Buffer.from(css),
|
|
66
|
-
filename: "catom.css",
|
|
67
|
-
minify: shouldMinify,
|
|
68
|
-
targets,
|
|
69
|
-
});
|
|
70
|
-
finalCss = code.toString();
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
// Fallback if lightningcss fails
|
|
74
|
-
finalCss = css;
|
|
75
|
-
}
|
|
76
51
|
return [
|
|
77
52
|
{
|
|
78
53
|
tag: "style",
|
|
79
54
|
attrs: { "data-catom": "" },
|
|
80
|
-
children:
|
|
55
|
+
children: css,
|
|
81
56
|
injectTo: "head",
|
|
82
57
|
},
|
|
83
58
|
];
|
|
@@ -88,24 +63,10 @@ export default function catom(options = {}) {
|
|
|
88
63
|
if (collectedRules.size === 0)
|
|
89
64
|
return;
|
|
90
65
|
const css = dedupeRules([...collectedRules]);
|
|
91
|
-
const shouldMinify = minify ?? true;
|
|
92
|
-
let finalCss;
|
|
93
|
-
try {
|
|
94
|
-
const { code } = transform({
|
|
95
|
-
code: Buffer.from(css),
|
|
96
|
-
filename: "catom.css",
|
|
97
|
-
minify: shouldMinify,
|
|
98
|
-
targets,
|
|
99
|
-
});
|
|
100
|
-
finalCss = code.toString();
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
finalCss = css;
|
|
104
|
-
}
|
|
105
66
|
this.emitFile({
|
|
106
67
|
type: "asset",
|
|
107
68
|
fileName: "catom.css",
|
|
108
|
-
source:
|
|
69
|
+
source: css,
|
|
109
70
|
});
|
|
110
71
|
},
|
|
111
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catom",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Zero-runtime atomic CSS-in-JS for Vite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
33
|
-
"lightningcss": "^1.16.0"
|
|
32
|
+
"vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"unplugin-ast": "^0.15.4",
|
|
@@ -40,7 +39,6 @@
|
|
|
40
39
|
"@babel/types": "^7.26.0",
|
|
41
40
|
"@types/node": "^20.0.0",
|
|
42
41
|
"typescript": "^5.0.0",
|
|
43
|
-
"vite": "^5.0.0"
|
|
44
|
-
"lightningcss": "^1.28.0"
|
|
42
|
+
"vite": "^5.0.0"
|
|
45
43
|
}
|
|
46
44
|
}
|