@pathscale/rsbuild-plugin-ui-css-purge 0.9.1 → 0.9.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.
@@ -2,17 +2,57 @@
2
2
  /**
3
3
  * Postbuild CSS purge — standalone Bun script.
4
4
  *
5
- * Runs after rsbuild build, purges CSS files in dist/ using the purge manifest
6
- * and consumer JSX analysis. Zero Node imports.
5
+ * Runs after rsbuild build, purges CSS files in dist/ using a database-first
6
+ * component manifest and consumer JSX usage analysis.
7
7
  *
8
- * Three-level purge:
9
- * L1 — class-level: drop rules whose class selectors aren't in the safelist (postcss)
10
- * L2 attr-level: drop rules with data/aria attribute selectors for unused props (postcss)
11
- * L3 var cleanup: iteratively remove declared-but-unreferenced CSS custom properties (postcss)
12
- * Final minification via Lightning CSS
13
- *
14
- * Usage:
15
- * bunx @pathscale/rsbuild-plugin-ui-css-purge \
16
- * --dist dist --src src --manifest node_modules/@pathscale/ui/dist/purge-manifest.json
8
+ * Conservative rules:
9
+ * - selectors owned only by unused known components can be removed
10
+ * - selectors owned by used components but unused known prop variants can be removed
11
+ * - selectors with unknown ownership are kept
12
+ * - data/aria runtime state is kept when the owning component selector is kept
13
+ * - vars/keyframes are removed only after selector purge proves them unreferenced
17
14
  */
18
- export {};
15
+ import type { LegacyComponentManifest, PurgeManifest, Safelists } from "./scan-consumer";
16
+ interface NormalizedComponentRecord extends LegacyComponentManifest {
17
+ key: string;
18
+ component: string;
19
+ part?: string;
20
+ selectors: string[];
21
+ attributeSelectors: string[];
22
+ cssVars: {
23
+ declared: string[];
24
+ referenced: string[];
25
+ };
26
+ keyframes: {
27
+ declared: string[];
28
+ referenced: string[];
29
+ };
30
+ }
31
+ interface NormalizedPurgeDatabase {
32
+ version: 2;
33
+ components: Record<string, NormalizedComponentRecord>;
34
+ }
35
+ declare function normalizePurgeDatabase(manifest: PurgeManifest): NormalizedPurgeDatabase;
36
+ interface SelectorPurgeReport {
37
+ selectorsKeptKnown: number;
38
+ selectorsKeptUnknown: number;
39
+ selectorsRemoved: number;
40
+ selectorsRemovedUnusedComponent: number;
41
+ selectorsRemovedUnusedVariant: number;
42
+ attrSelectorsSeen: number;
43
+ keyframesRemoved: number;
44
+ fontFacesRemoved: number;
45
+ }
46
+ interface PurgeResult {
47
+ css: string;
48
+ report: SelectorPurgeReport;
49
+ }
50
+ declare function purgeCssWithDatabase(css: string, manifest: PurgeManifest | NormalizedPurgeDatabase, safelists: Safelists): PurgeResult;
51
+ interface VarCleanupResult {
52
+ css: string;
53
+ removed: number;
54
+ }
55
+ declare function cleanUnusedVarsWithReport(css: string, externallyReferencedVars: Set<string>): VarCleanupResult;
56
+ declare function cleanUnusedVars(css: string, externallyReferencedVars: Set<string>): string;
57
+ export { cleanUnusedVars, cleanUnusedVarsWithReport, normalizePurgeDatabase, purgeCssWithDatabase, };
58
+ export type { NormalizedPurgeDatabase, PurgeResult, SelectorPurgeReport, VarCleanupResult, };