@pathscale/rsbuild-plugin-ui-css-purge 0.9.2 → 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,45 +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
- import type { PurgeManifest } from "./scan-consumer";
19
- interface KillListResult {
20
- killList: Set<string>;
21
- /**
22
- * BEM root classes of components the consumer actually uses. Used to
23
- * preserve pure attribute selector rules like
24
- * `[data-slot="checkbox-default-indicator--checkmark"]` that have no class
25
- * reference but are still component-scoped.
26
- */
27
- usedBemRoots: Set<string>;
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
+ };
28
30
  }
29
- export declare function buildKillList(manifest: PurgeManifest, importedComponents: Set<string>): KillListResult;
30
- /**
31
- * Extract all `[data-slot="..."]` attribute values from a selector. Handles
32
- * quoted and unquoted forms (Lightning CSS strips quotes when the value is a
33
- * simple identifier-like token, so post-minify CSS often looks like
34
- * `[data-slot=checkbox-default-indicator--checkmark]`).
35
- */
36
- export declare function extractDataSlotValues(sel: string): string[];
37
- /**
38
- * True when every `[data-slot="X"]` in `sel` belongs to a used component —
39
- * X matches one of `usedBemRoots` as exact, or as `root-`, `root__`, `root--`
40
- * prefix. Returns false when the selector has no `[data-slot]` at all
41
- * (caller decides via other heuristics) or when any slot doesn't match.
42
- */
43
- export declare function dataSlotsMatchUsedRoots(sel: string, usedBemRoots: Set<string>): boolean;
44
- export declare function isKeepableNonClassSelector(sel: string, usedBemRoots?: Set<string>): boolean;
45
- export declare function purgeClasses(css: string, killList: Set<string>, usedBemRoots?: Set<string>): string;
46
- export {};
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, };