@csszyx/unplugin 0.8.0 → 0.9.1

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.
Files changed (48) hide show
  1. package/README.md +16 -7
  2. package/dist/css-mangler.cjs +4 -4
  3. package/dist/css-mangler.mjs +4 -4
  4. package/dist/index.cjs +23 -1
  5. package/dist/index.d.cts +100 -5
  6. package/dist/index.d.mts +99 -3
  7. package/dist/index.mjs +7 -1
  8. package/dist/next-prebuild.cjs +148 -0
  9. package/dist/next-prebuild.d.cts +66 -0
  10. package/dist/next-prebuild.d.mts +66 -0
  11. package/dist/next-prebuild.mjs +131 -0
  12. package/dist/next-turbo-loader.cjs +210 -0
  13. package/dist/next-turbo-loader.d.cts +68 -0
  14. package/dist/next-turbo-loader.d.mts +66 -0
  15. package/dist/next-turbo-loader.mjs +190 -0
  16. package/dist/next-watcher.cjs +237 -0
  17. package/dist/next-watcher.d.cts +106 -0
  18. package/dist/next-watcher.d.mts +106 -0
  19. package/dist/next-watcher.mjs +219 -0
  20. package/dist/shared/unplugin.8er8o6rn.mjs +276 -0
  21. package/dist/shared/unplugin.B_U4rZvG.cjs +281 -0
  22. package/dist/shared/unplugin.BbtspS8t.mjs +3271 -0
  23. package/dist/shared/unplugin.BceVw1eW.mjs +184 -0
  24. package/dist/shared/unplugin.BtQzlC2C.mjs +567 -0
  25. package/dist/shared/unplugin.CFp386gH.cjs +3321 -0
  26. package/dist/shared/unplugin.CPEWNSA0.d.cts +77 -0
  27. package/dist/shared/unplugin.CPEWNSA0.d.mts +77 -0
  28. package/dist/shared/unplugin.CScQRdTp.d.cts +15 -0
  29. package/dist/shared/unplugin.CScQRdTp.d.mts +15 -0
  30. package/dist/shared/unplugin.CdZxp0x-.d.mts +16 -0
  31. package/dist/shared/unplugin.DLrBgECN.d.cts +282 -0
  32. package/dist/shared/unplugin.DLrBgECN.d.mts +282 -0
  33. package/dist/shared/unplugin.DUxdYaSG.cjs +205 -0
  34. package/dist/shared/unplugin.s62yJbu1.cjs +591 -0
  35. package/dist/shared/unplugin.xeED_qwh.d.cts +16 -0
  36. package/dist/vite.cjs +7 -1
  37. package/dist/vite.d.cts +2 -1
  38. package/dist/vite.d.mts +2 -1
  39. package/dist/vite.mjs +7 -1
  40. package/dist/webpack.cjs +7 -1
  41. package/dist/webpack.d.cts +2 -1
  42. package/dist/webpack.d.mts +2 -1
  43. package/dist/webpack.mjs +7 -1
  44. package/package.json +41 -8
  45. package/dist/shared/unplugin.BNsv2szs.cjs +0 -1753
  46. package/dist/shared/unplugin.DCv0RtVZ.mjs +0 -1722
  47. package/dist/shared/unplugin.DUbr5w-N.d.cts +0 -49
  48. package/dist/shared/unplugin.DUbr5w-N.d.mts +0 -49
package/README.md CHANGED
@@ -66,7 +66,7 @@ module.exports = {
66
66
 
67
67
  ## Features
68
68
 
69
- - **sz prop transform** -- Compiles `sz={{ }}` objects into `className` strings. Defaults to **oxc-parser + magic-string** (surgical edits, preserves source formatting) since v0.8.0; falls back to Babel automatically on unexpected oxc failures.
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
@@ -74,24 +74,33 @@ module.exports = {
74
74
 
75
75
  ## Parser selection
76
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
+
77
83
  Per project:
78
84
 
79
85
  ```ts
80
86
  csszyx({
81
- build: { parser: "babel" }, // opt out of oxc default
87
+ build: { parser: "oxc" }, // JavaScript oxc parser, no native addon
82
88
  });
83
89
  ```
84
90
 
85
91
  Per build:
86
92
 
87
93
  ```bash
88
- CSSZYX_PARSER=babel pnpm build
94
+ CSSZYX_PARSER=oxc pnpm build
89
95
  ```
90
96
 
91
- Either path routes prescan, transform, and HMR discovery through the
92
- legacy Babel implementation. Both paths produce identical class output;
93
- the only difference is whether magic-string preserves your original
94
- formatting (oxc) or Babel's code generator pretty-prints it.
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.
95
104
 
96
105
  ## License
97
106
 
@@ -18,9 +18,9 @@ function unescapeTailwindClass(escapedName) {
18
18
  break;
19
19
  }
20
20
  const char = escapedName[i];
21
- if (/[0-9a-fA-F]/.test(char)) {
21
+ if (/[0-9a-f]/i.test(char)) {
22
22
  let hexStr = "";
23
- while (i < escapedName.length && /[0-9a-fA-F]/.test(escapedName[i]) && hexStr.length < 6) {
23
+ while (i < escapedName.length && /[0-9a-f]/i.test(escapedName[i]) && hexStr.length < 6) {
24
24
  hexStr += escapedName[i];
25
25
  i++;
26
26
  }
@@ -48,13 +48,13 @@ function escapeCSSClassName(className) {
48
48
  const char = className[i];
49
49
  const code = char.charCodeAt(0);
50
50
  if (i === 0) {
51
- if (/[0-9]/.test(char)) {
51
+ if (/\d/.test(char)) {
52
52
  result += `\\3${char} `;
53
53
  continue;
54
54
  }
55
55
  if (char === "-" && i + 1 < className.length) {
56
56
  const next = className[i + 1];
57
- if (/[0-9]/.test(next) || next === "-") {
57
+ if (/\d/.test(next) || next === "-") {
58
58
  result += "\\-";
59
59
  continue;
60
60
  }
@@ -11,9 +11,9 @@ function unescapeTailwindClass(escapedName) {
11
11
  break;
12
12
  }
13
13
  const char = escapedName[i];
14
- if (/[0-9a-fA-F]/.test(char)) {
14
+ if (/[0-9a-f]/i.test(char)) {
15
15
  let hexStr = "";
16
- while (i < escapedName.length && /[0-9a-fA-F]/.test(escapedName[i]) && hexStr.length < 6) {
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,13 +41,13 @@ function escapeCSSClassName(className) {
41
41
  const char = className[i];
42
42
  const code = char.charCodeAt(0);
43
43
  if (i === 0) {
44
- if (/[0-9]/.test(char)) {
44
+ if (/\d/.test(char)) {
45
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 (/[0-9]/.test(next) || next === "-") {
50
+ if (/\d/.test(next) || next === "-") {
51
51
  result += "\\-";
52
52
  continue;
53
53
  }
package/dist/index.cjs CHANGED
@@ -3,17 +3,23 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const cssMangler = require('./css-mangler.cjs');
6
- const unplugin = require('./shared/unplugin.BNsv2szs.cjs');
6
+ const unplugin = require('./shared/unplugin.CFp386gH.cjs');
7
+ const types = require('@csszyx/types');
7
8
  require('postcss');
8
9
  require('postcss-selector-parser');
9
10
  require('node:fs');
11
+ require('node:module');
10
12
  require('node:path');
13
+ require('node:perf_hooks');
14
+ require('node:url');
11
15
  require('@csszyx/compiler');
12
16
  require('@csszyx/core');
13
17
  require('@csszyx/svelte-adapter');
14
18
  require('@csszyx/vue-adapter');
15
19
  require('unplugin');
16
20
  require('node:crypto');
21
+ require('./shared/unplugin.DUxdYaSG.cjs');
22
+ require('postcss-value-parser');
17
23
 
18
24
 
19
25
 
@@ -24,19 +30,35 @@ exports.mangleCSSSync = cssMangler.mangleCSSSync;
24
30
  exports.unescapeTailwindClass = cssMangler.unescapeTailwindClass;
25
31
  exports.assertNoRSCBoundaryViolation = unplugin.assertNoRSCBoundaryViolation;
26
32
  exports.assertNoRSCGraphViolation = unplugin.assertNoRSCGraphViolation;
33
+ exports.createGlobalVarAliasValidationOptions = unplugin.createGlobalVarAliasValidationOptions;
34
+ exports.createGlobalVarMapAssetSource = unplugin.createGlobalVarMapAssetSource;
35
+ exports.createGlobalVarScanCacheKey = unplugin.createGlobalVarScanCacheKey;
27
36
  exports.createRSCModuleRecord = unplugin.createRSCModuleRecord;
28
37
  exports.default = unplugin.unplugin;
38
+ exports.deleteRSCModuleRecord = unplugin.deleteRSCModuleRecord;
29
39
  exports.esbuildPlugin = unplugin.esbuildPlugin;
40
+ exports.extractGlobalVarAliasesForManifest = unplugin.extractGlobalVarAliasesForManifest;
30
41
  exports.findRSCBoundaryViolation = unplugin.findRSCBoundaryViolation;
31
42
  exports.findRSCGraphViolation = unplugin.findRSCGraphViolation;
32
43
  exports.hasTokens = unplugin.hasTokens;
33
44
  exports.hasUseClientDirective = unplugin.hasUseClientDirective;
34
45
  exports.hasUseServerDirective = unplugin.hasUseServerDirective;
35
46
  exports.isRSCServerModule = unplugin.isRSCServerModule;
47
+ exports.isTailwindReservedGlobalVar = unplugin.isTailwindReservedGlobalVar;
36
48
  exports.mangleCodeClassesSync = unplugin.mangleCodeClassesSync;
37
49
  exports.mergeThemes = unplugin.mergeThemes;
50
+ exports.normalizeGlobalVarAliasesForCache = unplugin.normalizeGlobalVarAliasesForCache;
38
51
  exports.parseThemeBlocks = unplugin.parseThemeBlocks;
52
+ exports.planGlobalVarAliases = unplugin.planGlobalVarAliases;
53
+ exports.readGlobalVarScanCache = unplugin.readGlobalVarScanCache;
54
+ exports.resolveGlobalVarScanCacheDir = unplugin.resolveGlobalVarScanCacheDir;
55
+ exports.rewriteGlobalVarCssAliases = unplugin.rewriteGlobalVarCssAliases;
39
56
  exports.rollupPlugin = unplugin.rollupPlugin;
57
+ exports.scanGlobalVarCss = unplugin.scanGlobalVarCss;
40
58
  exports.unplugin = unplugin.unplugin;
59
+ exports.validateGlobalVarAliasInputs = unplugin.validateGlobalVarAliasInputs;
41
60
  exports.vitePlugin = unplugin.vitePlugin;
42
61
  exports.webpackPlugin = unplugin.webpackPlugin;
62
+ exports.writeGlobalVarScanCache = unplugin.writeGlobalVarScanCache;
63
+ exports.CSSZYX_GLOBAL_ALIAS_PREFIX = types.CSSZYX_GLOBAL_ALIAS_PREFIX;
64
+ exports.TAILWIND_RESERVED_PREFIXES = types.TAILWIND_RESERVED_PREFIXES;
package/dist/index.d.cts CHANGED
@@ -1,15 +1,101 @@
1
- import _default from './shared/unplugin.DUbr5w-N.cjs';
2
1
  export { CSSManglerOptions, CSSManglerResult, MangleMap, createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass } from './css-mangler.cjs';
2
+ export { CSSZYX_GLOBAL_ALIAS_PREFIX, TAILWIND_RESERVED_PREFIXES } from '@csszyx/types';
3
+ import { G as GlobalVarScanCacheKeyInput, C as CssVarScanResult, S as ScanGlobalVarCssOptions, P as PlanGlobalVarAliasesInput, a as GlobalVarAliasPlan, R as RewriteGlobalVarCssAliasesOptions, b as GlobalVarCssAliasRewriteResult, c as CreateGlobalVarAliasValidationOptionsInput, V as ValidateGlobalVarAliasInputsOptions, d as GlobalVarAliasValidationResult } from './shared/unplugin.DLrBgECN.cjs';
3
4
  // @ts-ignore
4
- export = _default;
5
- export { e as esbuildPlugin, m as mangleCodeClassesSync, r as rollupPlugin, u as unplugin, v as vitePlugin, w as webpackPlugin } from './shared/unplugin.DUbr5w-N.cjs';
5
+ export = undefined;
6
+ export { e as CssVarDefinition, f as CssVarLocation, g as CssVarReference, h as GlobalVarAliasDiagnostic, i as GlobalVarAliasDiagnosticSeverity, j as GlobalVarAliasEntry, k as GlobalVarCodeSource, l as GlobalVarCssAssetSource, m as GlobalVarCssSource, n as GlobalVarScanCacheEntry, o as createGlobalVarMapAssetSource, p as esbuildPlugin, q as extractGlobalVarAliasesForManifest, r as mangleCodeClassesSync, s as normalizeGlobalVarAliasesForCache, t as rollupPlugin, u as unplugin, v as vitePlugin, w as webpackPlugin } from './shared/unplugin.DLrBgECN.cjs';
6
7
  import 'postcss';
7
- import '@csszyx/types';
8
+ import '@csszyx/compiler';
8
9
  import 'esbuild';
9
10
  import 'rollup';
10
11
  import 'unplugin';
11
12
  import 'vite';
12
13
 
14
+ /**
15
+ * Resolves the global variable scan cache directory.
16
+ *
17
+ * @param cacheDir csszyx cache root.
18
+ * @returns Cache directory for Phase H CSS scans.
19
+ */
20
+ declare function resolveGlobalVarScanCacheDir(cacheDir: string): string;
21
+ /**
22
+ * Creates a cache key from file path, mtime, and content hash.
23
+ *
24
+ * @param input Cache key input.
25
+ * @returns Stable SHA-256 cache key.
26
+ */
27
+ declare function createGlobalVarScanCacheKey(input: GlobalVarScanCacheKeyInput): string;
28
+ /**
29
+ * Reads a cached global variable scan result when the key matches.
30
+ *
31
+ * @param cacheDir Global variable scan cache directory.
32
+ * @param key Expected cache key.
33
+ * @returns Cached scan result, or null on miss/corruption.
34
+ */
35
+ declare function readGlobalVarScanCache(cacheDir: string, key: string): CssVarScanResult | null;
36
+ /**
37
+ * Writes a global variable scan result cache entry.
38
+ *
39
+ * @param cacheDir Global variable scan cache directory.
40
+ * @param key Cache key.
41
+ * @param result Scan result to cache.
42
+ */
43
+ declare function writeGlobalVarScanCache(cacheDir: string, key: string, result: CssVarScanResult): void;
44
+
45
+ /**
46
+ * Scans one CSS source for custom-property definitions and var() references.
47
+ *
48
+ * @param css CSS source text.
49
+ * @param options Scan options.
50
+ * @returns Definitions, references, registrations, and ownership metadata.
51
+ */
52
+ declare function scanGlobalVarCss(css: string, options?: ScanGlobalVarCssOptions): CssVarScanResult;
53
+
54
+ /**
55
+ * Plans deterministic global aliases for explicit app-owned tokens.
56
+ *
57
+ * @param input Planner input.
58
+ * @returns Alias plan or fail-closed diagnostics.
59
+ */
60
+ declare function planGlobalVarAliases(input: PlanGlobalVarAliasesInput): GlobalVarAliasPlan;
61
+ /**
62
+ * Checks if a custom-property name is reserved by Tailwind v4.
63
+ *
64
+ * @param name Custom-property name.
65
+ * @returns true when the name is Tailwind-owned by namespace.
66
+ */
67
+ declare function isTailwindReservedGlobalVar(name: string): boolean;
68
+
69
+ /**
70
+ * Rewrites one CSS source with a validated global variable alias plan.
71
+ *
72
+ * This is intentionally pure M5 plumbing. It does not integrate with build
73
+ * hooks yet; callers must provide a fail-closed plan from `planGlobalVarAliases`.
74
+ *
75
+ * @param options Rewrite options.
76
+ * @returns Rewritten CSS and rewrite counters.
77
+ */
78
+ declare function rewriteGlobalVarCssAliases(options: RewriteGlobalVarCssAliasesOptions): GlobalVarCssAliasRewriteResult;
79
+
80
+ /**
81
+ * Runs the Phase H pure validation pipeline without mutating build output.
82
+ *
83
+ * @param options Validation input.
84
+ * @returns CSS scans, alias plan, and JS/JSX out-of-band diagnostics.
85
+ */
86
+ declare function validateGlobalVarAliasInputs(options: ValidateGlobalVarAliasInputsOptions): GlobalVarAliasValidationResult;
87
+ /**
88
+ * Builds validation options from bundler CSS assets and observed source files.
89
+ *
90
+ * This keeps production hook wiring deterministic: the same normalized CSS asset
91
+ * inventory can feed fail-closed validation before any CSS/TSX rewrite mutates
92
+ * output.
93
+ *
94
+ * @param input Bundler output and user global-var alias config fields.
95
+ * @returns Normalized validation options.
96
+ */
97
+ declare function createGlobalVarAliasValidationOptions(input: CreateGlobalVarAliasValidationOptionsInput): ValidateGlobalVarAliasInputsOptions;
98
+
13
99
  /**
14
100
  * Direct RSC boundary violation found in a transformed module.
15
101
  */
@@ -81,6 +167,15 @@ declare function findRSCBoundaryViolation(code: string, id: string): RSCBoundary
81
167
  * @returns graph metadata for the module
82
168
  */
83
169
  declare function createRSCModuleRecord(code: string, id: string): RSCModuleRecord;
170
+ /**
171
+ * Removes a module record after the bundler watcher reports that the file was
172
+ * deleted.
173
+ *
174
+ * @param records module graph records keyed by normalized module ID
175
+ * @param id module ID/path from the watcher event
176
+ * @returns true when a stale record was removed
177
+ */
178
+ declare function deleteRSCModuleRecord(records: Map<string, RSCModuleRecord>, id: string): boolean;
84
179
  /**
85
180
  * Finds forbidden runtime helper imports reachable from an RSC server module.
86
181
  * Traversal stops at `'use client'` modules because they define a separate
@@ -153,5 +248,5 @@ declare function mergeThemes(themes: ParsedTheme[]): ParsedTheme;
153
248
  */
154
249
  declare function hasTokens(theme: ParsedTheme): boolean;
155
250
 
156
- export { assertNoRSCBoundaryViolation, assertNoRSCGraphViolation, createRSCModuleRecord, findRSCBoundaryViolation, findRSCGraphViolation, hasTokens, hasUseClientDirective, hasUseServerDirective, isRSCServerModule, mergeThemes, parseThemeBlocks };
251
+ export { CreateGlobalVarAliasValidationOptionsInput, CssVarScanResult, GlobalVarAliasPlan, GlobalVarAliasValidationResult, GlobalVarCssAliasRewriteResult, GlobalVarScanCacheKeyInput, PlanGlobalVarAliasesInput, RewriteGlobalVarCssAliasesOptions, ScanGlobalVarCssOptions, ValidateGlobalVarAliasInputsOptions, assertNoRSCBoundaryViolation, assertNoRSCGraphViolation, createGlobalVarAliasValidationOptions, createGlobalVarScanCacheKey, createRSCModuleRecord, deleteRSCModuleRecord, findRSCBoundaryViolation, findRSCGraphViolation, hasTokens, hasUseClientDirective, hasUseServerDirective, isRSCServerModule, isTailwindReservedGlobalVar, mergeThemes, parseThemeBlocks, planGlobalVarAliases, readGlobalVarScanCache, resolveGlobalVarScanCacheDir, rewriteGlobalVarCssAliases, scanGlobalVarCss, validateGlobalVarAliasInputs, writeGlobalVarScanCache };
157
252
  export type { ParsedTheme, RSCBoundaryViolation, RSCModuleRecord };
package/dist/index.d.mts CHANGED
@@ -1,12 +1,99 @@
1
1
  export { CSSManglerOptions, CSSManglerResult, MangleMap, createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass } from './css-mangler.mjs';
2
- export { u as default, e as esbuildPlugin, m as mangleCodeClassesSync, r as rollupPlugin, u as unplugin, v as vitePlugin, w as webpackPlugin } from './shared/unplugin.DUbr5w-N.mjs';
2
+ export { CSSZYX_GLOBAL_ALIAS_PREFIX, TAILWIND_RESERVED_PREFIXES } from '@csszyx/types';
3
+ import { G as GlobalVarScanCacheKeyInput, C as CssVarScanResult, S as ScanGlobalVarCssOptions, P as PlanGlobalVarAliasesInput, a as GlobalVarAliasPlan, R as RewriteGlobalVarCssAliasesOptions, b as GlobalVarCssAliasRewriteResult, c as CreateGlobalVarAliasValidationOptionsInput, V as ValidateGlobalVarAliasInputsOptions, d as GlobalVarAliasValidationResult } from './shared/unplugin.DLrBgECN.mjs';
4
+ export { e as CssVarDefinition, f as CssVarLocation, g as CssVarReference, h as GlobalVarAliasDiagnostic, i as GlobalVarAliasDiagnosticSeverity, j as GlobalVarAliasEntry, k as GlobalVarCodeSource, l as GlobalVarCssAssetSource, m as GlobalVarCssSource, n as GlobalVarScanCacheEntry, o as createGlobalVarMapAssetSource, u as default, p as esbuildPlugin, q as extractGlobalVarAliasesForManifest, r as mangleCodeClassesSync, s as normalizeGlobalVarAliasesForCache, t as rollupPlugin, u as unplugin, v as vitePlugin, w as webpackPlugin } from './shared/unplugin.DLrBgECN.mjs';
3
5
  import 'postcss';
4
- import '@csszyx/types';
6
+ import '@csszyx/compiler';
5
7
  import 'esbuild';
6
8
  import 'rollup';
7
9
  import 'unplugin';
8
10
  import 'vite';
9
11
 
12
+ /**
13
+ * Resolves the global variable scan cache directory.
14
+ *
15
+ * @param cacheDir csszyx cache root.
16
+ * @returns Cache directory for Phase H CSS scans.
17
+ */
18
+ declare function resolveGlobalVarScanCacheDir(cacheDir: string): string;
19
+ /**
20
+ * Creates a cache key from file path, mtime, and content hash.
21
+ *
22
+ * @param input Cache key input.
23
+ * @returns Stable SHA-256 cache key.
24
+ */
25
+ declare function createGlobalVarScanCacheKey(input: GlobalVarScanCacheKeyInput): string;
26
+ /**
27
+ * Reads a cached global variable scan result when the key matches.
28
+ *
29
+ * @param cacheDir Global variable scan cache directory.
30
+ * @param key Expected cache key.
31
+ * @returns Cached scan result, or null on miss/corruption.
32
+ */
33
+ declare function readGlobalVarScanCache(cacheDir: string, key: string): CssVarScanResult | null;
34
+ /**
35
+ * Writes a global variable scan result cache entry.
36
+ *
37
+ * @param cacheDir Global variable scan cache directory.
38
+ * @param key Cache key.
39
+ * @param result Scan result to cache.
40
+ */
41
+ declare function writeGlobalVarScanCache(cacheDir: string, key: string, result: CssVarScanResult): void;
42
+
43
+ /**
44
+ * Scans one CSS source for custom-property definitions and var() references.
45
+ *
46
+ * @param css CSS source text.
47
+ * @param options Scan options.
48
+ * @returns Definitions, references, registrations, and ownership metadata.
49
+ */
50
+ declare function scanGlobalVarCss(css: string, options?: ScanGlobalVarCssOptions): CssVarScanResult;
51
+
52
+ /**
53
+ * Plans deterministic global aliases for explicit app-owned tokens.
54
+ *
55
+ * @param input Planner input.
56
+ * @returns Alias plan or fail-closed diagnostics.
57
+ */
58
+ declare function planGlobalVarAliases(input: PlanGlobalVarAliasesInput): GlobalVarAliasPlan;
59
+ /**
60
+ * Checks if a custom-property name is reserved by Tailwind v4.
61
+ *
62
+ * @param name Custom-property name.
63
+ * @returns true when the name is Tailwind-owned by namespace.
64
+ */
65
+ declare function isTailwindReservedGlobalVar(name: string): boolean;
66
+
67
+ /**
68
+ * Rewrites one CSS source with a validated global variable alias plan.
69
+ *
70
+ * This is intentionally pure M5 plumbing. It does not integrate with build
71
+ * hooks yet; callers must provide a fail-closed plan from `planGlobalVarAliases`.
72
+ *
73
+ * @param options Rewrite options.
74
+ * @returns Rewritten CSS and rewrite counters.
75
+ */
76
+ declare function rewriteGlobalVarCssAliases(options: RewriteGlobalVarCssAliasesOptions): GlobalVarCssAliasRewriteResult;
77
+
78
+ /**
79
+ * Runs the Phase H pure validation pipeline without mutating build output.
80
+ *
81
+ * @param options Validation input.
82
+ * @returns CSS scans, alias plan, and JS/JSX out-of-band diagnostics.
83
+ */
84
+ declare function validateGlobalVarAliasInputs(options: ValidateGlobalVarAliasInputsOptions): GlobalVarAliasValidationResult;
85
+ /**
86
+ * Builds validation options from bundler CSS assets and observed source files.
87
+ *
88
+ * This keeps production hook wiring deterministic: the same normalized CSS asset
89
+ * inventory can feed fail-closed validation before any CSS/TSX rewrite mutates
90
+ * output.
91
+ *
92
+ * @param input Bundler output and user global-var alias config fields.
93
+ * @returns Normalized validation options.
94
+ */
95
+ declare function createGlobalVarAliasValidationOptions(input: CreateGlobalVarAliasValidationOptionsInput): ValidateGlobalVarAliasInputsOptions;
96
+
10
97
  /**
11
98
  * Direct RSC boundary violation found in a transformed module.
12
99
  */
@@ -78,6 +165,15 @@ declare function findRSCBoundaryViolation(code: string, id: string): RSCBoundary
78
165
  * @returns graph metadata for the module
79
166
  */
80
167
  declare function createRSCModuleRecord(code: string, id: string): RSCModuleRecord;
168
+ /**
169
+ * Removes a module record after the bundler watcher reports that the file was
170
+ * deleted.
171
+ *
172
+ * @param records module graph records keyed by normalized module ID
173
+ * @param id module ID/path from the watcher event
174
+ * @returns true when a stale record was removed
175
+ */
176
+ declare function deleteRSCModuleRecord(records: Map<string, RSCModuleRecord>, id: string): boolean;
81
177
  /**
82
178
  * Finds forbidden runtime helper imports reachable from an RSC server module.
83
179
  * Traversal stops at `'use client'` modules because they define a separate
@@ -150,5 +246,5 @@ declare function mergeThemes(themes: ParsedTheme[]): ParsedTheme;
150
246
  */
151
247
  declare function hasTokens(theme: ParsedTheme): boolean;
152
248
 
153
- export { assertNoRSCBoundaryViolation, assertNoRSCGraphViolation, createRSCModuleRecord, findRSCBoundaryViolation, findRSCGraphViolation, hasTokens, hasUseClientDirective, hasUseServerDirective, isRSCServerModule, mergeThemes, parseThemeBlocks };
249
+ export { CreateGlobalVarAliasValidationOptionsInput, CssVarScanResult, GlobalVarAliasPlan, GlobalVarAliasValidationResult, GlobalVarCssAliasRewriteResult, GlobalVarScanCacheKeyInput, PlanGlobalVarAliasesInput, RewriteGlobalVarCssAliasesOptions, ScanGlobalVarCssOptions, ValidateGlobalVarAliasInputsOptions, assertNoRSCBoundaryViolation, assertNoRSCGraphViolation, createGlobalVarAliasValidationOptions, createGlobalVarScanCacheKey, createRSCModuleRecord, deleteRSCModuleRecord, findRSCBoundaryViolation, findRSCGraphViolation, hasTokens, hasUseClientDirective, hasUseServerDirective, isRSCServerModule, isTailwindReservedGlobalVar, mergeThemes, parseThemeBlocks, planGlobalVarAliases, readGlobalVarScanCache, resolveGlobalVarScanCacheDir, rewriteGlobalVarCssAliases, scanGlobalVarCss, validateGlobalVarAliasInputs, writeGlobalVarScanCache };
154
250
  export type { ParsedTheme, RSCBoundaryViolation, RSCModuleRecord };
package/dist/index.mjs CHANGED
@@ -1,12 +1,18 @@
1
1
  export { createPostCSSPlugin, escapeCSSClassName, mangleCSS, mangleCSSSync, unescapeTailwindClass } from './css-mangler.mjs';
2
- export { a as assertNoRSCBoundaryViolation, b as assertNoRSCGraphViolation, c as createRSCModuleRecord, u as default, e as esbuildPlugin, f as findRSCBoundaryViolation, d as findRSCGraphViolation, h as hasTokens, g as hasUseClientDirective, i as hasUseServerDirective, j as isRSCServerModule, m as mangleCodeClassesSync, k as mergeThemes, p as parseThemeBlocks, r as rollupPlugin, u as unplugin, v as vitePlugin, w as webpackPlugin } from './shared/unplugin.DCv0RtVZ.mjs';
2
+ export { a as assertNoRSCBoundaryViolation, b as assertNoRSCGraphViolation, c as createGlobalVarAliasValidationOptions, d as createGlobalVarMapAssetSource, e as createGlobalVarScanCacheKey, f as createRSCModuleRecord, u as default, g as deleteRSCModuleRecord, h as esbuildPlugin, i as extractGlobalVarAliasesForManifest, j as findRSCBoundaryViolation, k as findRSCGraphViolation, l as hasTokens, m as hasUseClientDirective, n as hasUseServerDirective, o as isRSCServerModule, p as isTailwindReservedGlobalVar, q as mangleCodeClassesSync, r as mergeThemes, s as normalizeGlobalVarAliasesForCache, t as parseThemeBlocks, v as planGlobalVarAliases, w as readGlobalVarScanCache, x as resolveGlobalVarScanCacheDir, y as rewriteGlobalVarCssAliases, z as rollupPlugin, A as scanGlobalVarCss, u as unplugin, B as validateGlobalVarAliasInputs, C as vitePlugin, D as webpackPlugin, E as writeGlobalVarScanCache } from './shared/unplugin.BbtspS8t.mjs';
3
+ export { CSSZYX_GLOBAL_ALIAS_PREFIX, TAILWIND_RESERVED_PREFIXES } from '@csszyx/types';
3
4
  import 'postcss';
4
5
  import 'postcss-selector-parser';
5
6
  import 'node:fs';
7
+ import 'node:module';
6
8
  import 'node:path';
9
+ import 'node:perf_hooks';
10
+ import 'node:url';
7
11
  import '@csszyx/compiler';
8
12
  import '@csszyx/core';
9
13
  import '@csszyx/svelte-adapter';
10
14
  import '@csszyx/vue-adapter';
11
15
  import 'unplugin';
12
16
  import 'node:crypto';
17
+ import './shared/unplugin.BceVw1eW.mjs';
18
+ import 'postcss-value-parser';
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ const node_crypto = require('node:crypto');
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const nextTransformMetadata = require('./shared/unplugin.B_U4rZvG.cjs');
7
+ const nextWatcherCycle = require('./shared/unplugin.s62yJbu1.cjs');
8
+ const transformCache = require('./shared/unplugin.DUxdYaSG.cjs');
9
+ require('@csszyx/compiler');
10
+ require('node:os');
11
+ require('proper-lockfile');
12
+
13
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
14
+ function _interopNamespaceCompat(e) {
15
+ if (e && typeof e === 'object' && 'default' in e) return e;
16
+ const n = Object.create(null);
17
+ if (e) {
18
+ for (const k in e) {
19
+ n[k] = e[k];
20
+ }
21
+ }
22
+ n.default = e;
23
+ return n;
24
+ }
25
+
26
+ const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
27
+
28
+ function runNextPrebuild(options) {
29
+ assertProductionManglingBoundary(options);
30
+ const csszyxVersion = options.csszyxVersion ?? nextTransformMetadata.readPackageVersion("../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('next-prebuild.cjs', document.baseURI).href)));
31
+ const compilerVersion = options.compilerVersion ?? nextTransformMetadata.readPackageVersion("../../compiler/package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('next-prebuild.cjs', document.baseURI).href)));
32
+ const nativeVersion = options.nativeVersion ?? compilerVersion;
33
+ const nextVersion = options.nextVersion ?? "unknown-next";
34
+ const context = nextWatcherCycle.createNextStateContext({
35
+ explicitRoot: options.explicitRoot,
36
+ loaderRootContext: options.loaderRootContext,
37
+ loaderContext: options.loaderContext,
38
+ cwd: options.cwd,
39
+ cacheDir: options.cacheDir,
40
+ safelistOutputFile: options.safelistOutputFile,
41
+ config: options.config ?? {},
42
+ env: options.env ?? process.env,
43
+ envKeys: options.envKeys,
44
+ nextVersion,
45
+ csszyxVersion,
46
+ nativeVersion,
47
+ mode: options.mode ?? "production"
48
+ });
49
+ const cacheRoot = transformCache.resolveTransformCacheDir(
50
+ context.root,
51
+ path__namespace.relative(context.root, context.cacheDir)
52
+ );
53
+ const files = [];
54
+ let scannedCount = 0;
55
+ let transformedCount = 0;
56
+ let skippedMissingCount = 0;
57
+ for (const filename of uniqueFiles(options.files)) {
58
+ scannedCount++;
59
+ if (!fs.existsSync(filename)) {
60
+ skippedMissingCount++;
61
+ continue;
62
+ }
63
+ const source = fs.readFileSync(filename, "utf8");
64
+ const transform = nextTransformMetadata.transformNextSource({
65
+ source,
66
+ filename,
67
+ parserMode: options.parserMode ?? "rust",
68
+ compilerOptions: options.compilerOptions,
69
+ cacheRoot,
70
+ pluginVersion: csszyxVersion,
71
+ compilerVersion,
72
+ astBudget: options.astBudget,
73
+ allowBabelFallback: options.allowBabelFallback
74
+ });
75
+ const metadata = nextTransformMetadata.collectNextTransformMetadata(transform.result, source, filename);
76
+ transformedCount++;
77
+ const shardResult = nextWatcherCycle.writeNextSafelistShard(
78
+ context.safelist.shardsDir,
79
+ nextTransformMetadata.createNextSafelistShardFromMetadata(metadata, createShardCacheKey(context, metadata)),
80
+ options.writeOptions
81
+ );
82
+ files.push({
83
+ filename,
84
+ shardPath: shardResult.filePath,
85
+ classCount: metadata.classes.length,
86
+ cacheStatus: transform.cacheStatus,
87
+ producer: transform.producer
88
+ });
89
+ }
90
+ const cycle = nextWatcherCycle.runNextWatcherCycle(context, {
91
+ writeOptions: options.writeOptions,
92
+ lockOptions: {
93
+ root: context.root,
94
+ mode: context.manifestExpectation.mode,
95
+ command: "csszyx next prebuild"
96
+ },
97
+ createdAt: options.createdAt
98
+ });
99
+ return {
100
+ context,
101
+ scannedCount,
102
+ transformedCount,
103
+ skippedMissingCount,
104
+ classCount: cycle.materialize.classCount,
105
+ sourceCount: cycle.materialize.sourceCount,
106
+ manifestPath: context.manifestPath,
107
+ safelistOutputPath: context.safelist.outputPath,
108
+ files,
109
+ cycle
110
+ };
111
+ }
112
+ function assertProductionManglingBoundary(options) {
113
+ if (options.allowProductionMangling) {
114
+ return;
115
+ }
116
+ if ((options.mode ?? "production") !== "production") {
117
+ return;
118
+ }
119
+ if (options.compilerOptions?.mangleVars === true || hasEnabledMangleVars(options.config)) {
120
+ throw new Error(
121
+ "[csszyx] Next prebuild does not support production CSS variable mangling. Use Next Webpack mode for full csszyx parity."
122
+ );
123
+ }
124
+ }
125
+ function hasEnabledMangleVars(config) {
126
+ if (config === null || typeof config !== "object" || Array.isArray(config)) {
127
+ return false;
128
+ }
129
+ return config.mangleVars === true;
130
+ }
131
+ function uniqueFiles(files) {
132
+ const seen = /* @__PURE__ */ new Set();
133
+ const result = [];
134
+ for (const file of files) {
135
+ const resolved = path__namespace.resolve(file);
136
+ if (seen.has(resolved)) {
137
+ continue;
138
+ }
139
+ seen.add(resolved);
140
+ result.push(resolved);
141
+ }
142
+ return result;
143
+ }
144
+ function createShardCacheKey(context, metadata) {
145
+ return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(path__namespace.relative(context.root, metadata.sourcePath).replace(/\\/g, "/")).digest("hex");
146
+ }
147
+
148
+ exports.runNextPrebuild = runNextPrebuild;
@@ -0,0 +1,66 @@
1
+ import { TransformSourceCodeOptions } from '@csszyx/compiler';
2
+ import { J as JsonLike, A as AtomicWriteOptions, N as NextStateContext } from './shared/unplugin.CPEWNSA0.cjs';
3
+ import { a as NextSourceTransformOutput, N as NextSourceParserMode } from './shared/unplugin.CScQRdTp.cjs';
4
+ import { N as NextWatcherCycleResult } from './shared/unplugin.xeED_qwh.cjs';
5
+
6
+ /** Serializable options accepted by the Next Turbopack csszyx prebuild core. */
7
+ interface NextPrebuildOptions {
8
+ files: readonly string[];
9
+ explicitRoot?: string;
10
+ loaderRootContext?: string;
11
+ loaderContext?: string;
12
+ cwd?: string;
13
+ cacheDir?: string;
14
+ safelistOutputFile?: string;
15
+ parserMode?: NextSourceParserMode;
16
+ compilerOptions?: TransformSourceCodeOptions;
17
+ config?: JsonLike;
18
+ env?: Record<string, string | undefined>;
19
+ envKeys?: readonly string[];
20
+ nextVersion?: string;
21
+ csszyxVersion?: string;
22
+ compilerVersion?: string;
23
+ nativeVersion?: string;
24
+ mode?: 'development' | 'production';
25
+ astBudget?: number;
26
+ allowBabelFallback?: boolean;
27
+ allowProductionMangling?: boolean;
28
+ writeOptions?: AtomicWriteOptions;
29
+ createdAt?: string;
30
+ }
31
+ /** Per-file result captured by one prebuild pass. */
32
+ interface NextPrebuildFileResult {
33
+ filename: string;
34
+ shardPath: string | null;
35
+ classCount: number;
36
+ cacheStatus: NextSourceTransformOutput['cacheStatus'];
37
+ producer: NextSourceTransformOutput['producer'];
38
+ }
39
+ /** Aggregated result returned by `runNextPrebuild`. */
40
+ interface NextPrebuildResult {
41
+ context: NextStateContext;
42
+ scannedCount: number;
43
+ transformedCount: number;
44
+ skippedMissingCount: number;
45
+ classCount: number;
46
+ sourceCount: number;
47
+ manifestPath: string;
48
+ safelistOutputPath: string;
49
+ files: NextPrebuildFileResult[];
50
+ cycle: NextWatcherCycleResult;
51
+ }
52
+ /**
53
+ * Run one synchronous Next Turbopack csszyx prebuild pass.
54
+ *
55
+ * The prebuild walks an explicit file list, reuses the same state, transform,
56
+ * metadata, shard, and materialization contract as the loader, and finalizes
57
+ * the canonical Tailwind safelist plus a completed generation manifest. It
58
+ * intentionally does not own glob/chokidar dependencies or a CLI surface yet.
59
+ *
60
+ * @param options Prebuild input options.
61
+ * @returns Summary covering scanned/transformed counts and materialization paths.
62
+ */
63
+ declare function runNextPrebuild(options: NextPrebuildOptions): NextPrebuildResult;
64
+
65
+ export { runNextPrebuild };
66
+ export type { NextPrebuildFileResult, NextPrebuildOptions, NextPrebuildResult };