@csszyx/unplugin 0.15.3 → 0.17.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +8 -4
  3. package/dist/index.d.cts +2 -2
  4. package/dist/index.d.mts +2 -2
  5. package/dist/index.mjs +6 -4
  6. package/dist/jest-transform.cjs +186 -0
  7. package/dist/jest-transform.d.cts +112 -0
  8. package/dist/jest-transform.d.mts +110 -0
  9. package/dist/jest-transform.mjs +175 -0
  10. package/dist/next-prebuild.cjs +6 -5
  11. package/dist/next-prebuild.mjs +5 -4
  12. package/dist/next-turbo-loader.cjs +10 -8
  13. package/dist/next-turbo-loader.mjs +7 -5
  14. package/dist/next-watcher.cjs +3 -2
  15. package/dist/next-watcher.mjs +3 -2
  16. package/dist/shared/{unplugin.J6ue_lRJ.cjs → unplugin.2qOISpzl.cjs} +1 -114
  17. package/dist/shared/{unplugin.C-oQU1jl.mjs → unplugin.2uf-U76p.mjs} +1 -1
  18. package/dist/shared/{unplugin.Ceq-N4jI.mjs → unplugin.995yC_cN.mjs} +2 -110
  19. package/dist/shared/{unplugin.ZqxgHk5F.cjs → unplugin.9zs6T4Gf.cjs} +119 -92
  20. package/dist/shared/{unplugin.nvme_dSL.d.cts → unplugin.BO2_hyS3.d.cts} +54 -5
  21. package/dist/shared/{unplugin.DH_ij6cf.mjs → unplugin.Ba3O1r8M.mjs} +2 -6
  22. package/dist/shared/unplugin.BqKLlo1h.cjs +8 -0
  23. package/dist/shared/{unplugin.Vn9x8SBP.mjs → unplugin.C3bgc29e.mjs} +3 -2
  24. package/dist/shared/{unplugin.CPo2xrEy.mjs → unplugin.Cs4H9z9v.mjs} +91 -66
  25. package/dist/shared/{unplugin.BLptVbUe.mjs → unplugin.DPSQP5XG.mjs} +1 -1
  26. package/dist/shared/{unplugin.DDSWQJYX.cjs → unplugin.DS6CFjim.cjs} +3 -8
  27. package/dist/shared/{unplugin.gksolKh2.cjs → unplugin.DXzIP7lP.cjs} +5 -4
  28. package/dist/shared/unplugin.DcXM9sq5.mjs +109 -0
  29. package/dist/shared/unplugin.Defu9wGh.cjs +115 -0
  30. package/dist/shared/{unplugin.CInSoHdQ.d.mts → unplugin.DptK3pl4.d.mts} +54 -5
  31. package/dist/shared/{unplugin.BzF0V2kw.cjs → unplugin.YcnV3Izb.cjs} +6 -6
  32. package/dist/shared/{unplugin.BWnmKv07.cjs → unplugin.alhYXymJ.cjs} +1 -1
  33. package/dist/shared/unplugin.wMeicb6E.mjs +6 -0
  34. package/dist/vite.cjs +6 -4
  35. package/dist/vite.d.cts +2 -2
  36. package/dist/vite.d.mts +1 -1
  37. package/dist/vite.mjs +6 -4
  38. package/dist/webpack.cjs +6 -4
  39. package/dist/webpack.d.cts +1 -2
  40. package/dist/webpack.d.mts +1 -1
  41. package/dist/webpack.mjs +6 -4
  42. package/package.json +19 -9
@@ -0,0 +1,175 @@
1
+ import { createHash } from 'node:crypto';
2
+ import fs__default from 'node:fs';
3
+ import path__default from 'node:path';
4
+ import { VERSION, transformSource, szFallbackConsequenceOf } from '@csszyx/compiler';
5
+ import { i as injectNextRuntimeImports } from './shared/unplugin.DcXM9sq5.mjs';
6
+ import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
+
8
+ const SETTLE_MS = 2e3;
9
+ function mtimeOf(dir) {
10
+ try {
11
+ return fs__default.statSync(dir).mtimeMs;
12
+ } catch {
13
+ return -1;
14
+ }
15
+ }
16
+ function settled(mtime) {
17
+ return Date.now() - mtime < SETTLE_MS ? -1 : mtime;
18
+ }
19
+ function writtenAt(entry) {
20
+ return typeof entry.timestamp === "string" ? entry.timestamp : "";
21
+ }
22
+ class TransformCacheIndex {
23
+ /** Directories seen, with the modification time they were last read at. */
24
+ dirs = /* @__PURE__ */ new Map();
25
+ seen = /* @__PURE__ */ new Set();
26
+ byFilename = /* @__PURE__ */ new Map();
27
+ /**
28
+ * @param root - The transform cache directory.
29
+ */
30
+ constructor(root) {
31
+ this.dirs.set(root, -1);
32
+ }
33
+ /**
34
+ * Read every entry file written since the last refresh.
35
+ */
36
+ refresh() {
37
+ const moved = [];
38
+ for (const [dir, readAt] of this.dirs) {
39
+ const mtime = mtimeOf(dir);
40
+ if (mtime !== readAt) moved.push(dir);
41
+ }
42
+ for (const dir of moved) {
43
+ this.dirs.set(dir, settled(mtimeOf(dir)));
44
+ this.readDir(dir);
45
+ }
46
+ }
47
+ /**
48
+ * Parse the entry files in one directory the index has not read yet.
49
+ *
50
+ * @param dir - The directory.
51
+ */
52
+ readDir(dir) {
53
+ let names;
54
+ try {
55
+ names = fs__default.readdirSync(dir, { withFileTypes: true });
56
+ } catch {
57
+ return;
58
+ }
59
+ for (const entry of names) {
60
+ const full = path__default.join(dir, entry.name);
61
+ if (entry.isDirectory()) {
62
+ if (!this.dirs.has(full)) {
63
+ this.dirs.set(full, settled(mtimeOf(full)));
64
+ this.readDir(full);
65
+ }
66
+ continue;
67
+ }
68
+ if (!entry.name.endsWith(".json") || this.seen.has(full)) continue;
69
+ this.seen.add(full);
70
+ this.add(full);
71
+ }
72
+ }
73
+ /**
74
+ * Parse one entry file into the index.
75
+ *
76
+ * @param file - The entry file.
77
+ */
78
+ add(file) {
79
+ let entry;
80
+ try {
81
+ entry = JSON.parse(fs__default.readFileSync(file, "utf8"));
82
+ } catch {
83
+ return;
84
+ }
85
+ if (typeof entry.filename !== "string") return;
86
+ const list = this.byFilename.get(entry.filename) ?? [];
87
+ list.push(entry);
88
+ this.byFilename.set(entry.filename, list);
89
+ }
90
+ /**
91
+ * The build output for one file, when the build saw exactly these contents.
92
+ *
93
+ * @param filename - Path of the file under test, as the plugin records it.
94
+ * @param source - Its current contents.
95
+ * @returns The matching entry's result, or null.
96
+ */
97
+ find(filename, source) {
98
+ const wanted = createHash("sha256").update(source).digest("hex");
99
+ const hit = this.pick(filename, wanted);
100
+ if (hit !== null) return hit;
101
+ this.refresh();
102
+ return this.pick(filename, wanted);
103
+ }
104
+ /**
105
+ * The best entry among those recorded for one file and hash.
106
+ *
107
+ * The plugin keys its cache on more than the source — the compiler that
108
+ * wrote the entry, whether variables were mangled, the cross-module
109
+ * registry — so one file and hash can have several entries. A test wants
110
+ * the output this compiler produces with readable variable names, and of
111
+ * those the newest.
112
+ *
113
+ * @param filename - Path as the plugin records it.
114
+ * @param sha256 - Hash of the current contents.
115
+ * @returns The chosen entry's result, or null when none qualifies.
116
+ */
117
+ pick(filename, sha256) {
118
+ let best = null;
119
+ for (const entry of this.byFilename.get(filename) ?? []) {
120
+ if (entry.inputSha256 !== sha256) continue;
121
+ if (entry.compilerVersion !== VERSION || entry.mangleVars === true) continue;
122
+ if (typeof entry.result?.code !== "string") continue;
123
+ if (best === null || writtenAt(entry) > writtenAt(best)) {
124
+ best = entry;
125
+ }
126
+ }
127
+ return best?.result ?? null;
128
+ }
129
+ }
130
+ function findCachedTransform(cacheRoot, filename, source) {
131
+ const index = new TransformCacheIndex(cacheRoot);
132
+ index.refresh();
133
+ const code = index.find(normalizePathSeparators(filename), source)?.code;
134
+ return typeof code === "string" ? code : null;
135
+ }
136
+ const DEFAULT_EXTENSIONS = [".tsx", ".jsx", ".ts", ".js", ".mts", ".mjs"];
137
+ function reportDeadClasses(sourcePath, diagnostics) {
138
+ if (!Array.isArray(diagnostics)) return;
139
+ for (const message of diagnostics) {
140
+ if (typeof message !== "string" || szFallbackConsequenceOf(message) === "nudge") continue;
141
+ console.warn(`[csszyx] ${sourcePath}
142
+ ${message}`);
143
+ }
144
+ }
145
+ function finish(code, usage) {
146
+ return injectNextRuntimeImports(code, usage).code;
147
+ }
148
+ function createTransformer(options = {}) {
149
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
150
+ const cacheRoot = options.cacheRoot ?? path__default.resolve(process.cwd(), ".csszyx/cache", "transform");
151
+ const index = new TransformCacheIndex(cacheRoot);
152
+ index.refresh();
153
+ const compiles = (sourcePath) => extensions.some((extension) => sourcePath.endsWith(extension));
154
+ const cached = (sourceText, sourcePath) => index.find(normalizePathSeparators(sourcePath), sourceText);
155
+ return {
156
+ process(sourceText, sourcePath) {
157
+ if (!compiles(sourcePath)) return { code: sourceText };
158
+ const built = cached(sourceText, sourcePath);
159
+ if (built !== null && typeof built.code === "string") {
160
+ reportDeadClasses(sourcePath, built.diagnostics);
161
+ return { code: finish(built.code, built) };
162
+ }
163
+ const result = transformSource(sourceText, sourcePath);
164
+ reportDeadClasses(sourcePath, result.diagnostics);
165
+ return { code: result.transformed ? finish(result.code, result) : sourceText };
166
+ },
167
+ getCacheKey(sourceText, sourcePath, cacheKeyOptions) {
168
+ const built = compiles(sourcePath) ? cached(sourceText, sourcePath) : null;
169
+ return createHash("sha256").update(sourceText).update("\0").update(sourcePath).update("\0").update(typeof built?.code === "string" ? built.code : "").update("\0").update(cacheKeyOptions?.configString ?? "").update("\0").update(VERSION).digest("hex");
170
+ }
171
+ };
172
+ }
173
+ const transformerModule = { createTransformer };
174
+
175
+ export { createTransformer, transformerModule as default, findCachedTransform };
@@ -3,10 +3,11 @@
3
3
  const node_crypto = require('node:crypto');
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
- const nextTransformMetadata = require('./shared/unplugin.gksolKh2.cjs');
7
- const nextWatcherCycle = require('./shared/unplugin.BWnmKv07.cjs');
8
- const safelistSource = require('./shared/unplugin.DDSWQJYX.cjs');
9
- const transformCache = require('./shared/unplugin.BzF0V2kw.cjs');
6
+ const nextTransformMetadata = require('./shared/unplugin.DXzIP7lP.cjs');
7
+ const nextWatcherCycle = require('./shared/unplugin.alhYXymJ.cjs');
8
+ const pathNormalization = require('./shared/unplugin.BqKLlo1h.cjs');
9
+ const safelistSource = require('./shared/unplugin.DS6CFjim.cjs');
10
+ const transformCache = require('./shared/unplugin.YcnV3Izb.cjs');
10
11
  require('@csszyx/compiler');
11
12
  require('@csszyx/types');
12
13
  require('node:os');
@@ -153,7 +154,7 @@ function uniqueFiles(files) {
153
154
  return result;
154
155
  }
155
156
  function createShardCacheKey(context, metadata) {
156
- return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(safelistSource.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
157
+ return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(pathNormalization.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
157
158
  }
158
159
 
159
160
  exports.runNextPrebuild = runNextPrebuild;
@@ -1,10 +1,11 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import * as path from 'node:path';
4
- import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.Vn9x8SBP.mjs';
5
- import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle } from './shared/unplugin.BLptVbUe.mjs';
6
- import { f as findPostcssConfigWithoutCsszyx, m as missingPostcssPluginMessage, n as normalizePathSeparators } from './shared/unplugin.DH_ij6cf.mjs';
7
- import { r as resolveTransformCacheDir } from './shared/unplugin.C-oQU1jl.mjs';
4
+ import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.C3bgc29e.mjs';
5
+ import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle } from './shared/unplugin.DPSQP5XG.mjs';
6
+ import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
+ import { f as findPostcssConfigWithoutCsszyx, m as missingPostcssPluginMessage } from './shared/unplugin.Ba3O1r8M.mjs';
8
+ import { r as resolveTransformCacheDir } from './shared/unplugin.2uf-U76p.mjs';
8
9
  import '@csszyx/compiler';
9
10
  import '@csszyx/types';
10
11
  import 'node:os';
@@ -4,14 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const node_crypto = require('node:crypto');
6
6
  const path = require('node:path');
7
- const themeGroupsFile = require('./shared/unplugin.J6ue_lRJ.cjs');
8
- const nextTransformMetadata = require('./shared/unplugin.gksolKh2.cjs');
9
- const nextWatcherCycle = require('./shared/unplugin.BWnmKv07.cjs');
10
- const safelistSource = require('./shared/unplugin.DDSWQJYX.cjs');
11
- const transformCache = require('./shared/unplugin.BzF0V2kw.cjs');
7
+ const nextRuntimeInjection = require('./shared/unplugin.Defu9wGh.cjs');
8
+ const nextTransformMetadata = require('./shared/unplugin.DXzIP7lP.cjs');
9
+ const nextWatcherCycle = require('./shared/unplugin.alhYXymJ.cjs');
10
+ const pathNormalization = require('./shared/unplugin.BqKLlo1h.cjs');
11
+ const themeGroupsFile = require('./shared/unplugin.2qOISpzl.cjs');
12
+ const transformCache = require('./shared/unplugin.YcnV3Izb.cjs');
12
13
  require('node:fs');
13
14
  require('@csszyx/compiler');
14
15
  require('@csszyx/types');
16
+ require('./shared/unplugin.DS6CFjim.cjs');
15
17
  require('node:os');
16
18
  require('proper-lockfile');
17
19
 
@@ -67,14 +69,14 @@ function runNextTurboLoader(source, loaderContext, explicitOptions = {}) {
67
69
  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-turbo-loader.cjs', document.baseURI).href))),
68
70
  astBudget: options.astBudget
69
71
  });
70
- const injected = themeGroupsFile.injectNextRuntimeImports(transform.result.code, transform.result);
72
+ const injected = nextRuntimeInjection.injectNextRuntimeImports(transform.result.code, transform.result);
71
73
  const callsSzcn = transform.result.usesSzcn || /\bszcn\s*\(/.test(source);
72
74
  const themeGroups = callsSzcn ? themeGroupsFile.ensureThemeGroupsFile(context.root, path__namespace.join(context.root, ".csszyx")) : { file: null, watch: [] };
73
75
  for (const stylesheet of themeGroups.watch) loaderContext.addDependency?.(stylesheet);
74
76
  for (const provider of nextTransformMetadata.normalizeProviderPaths(crossModule.providers)) {
75
77
  loaderContext.addDependency?.(provider);
76
78
  }
77
- const code = themeGroups.file === null ? injected.code : themeGroupsFile.insertAfterUseDirective(
79
+ const code = themeGroups.file === null ? injected.code : nextRuntimeInjection.insertAfterUseDirective(
78
80
  injected.code,
79
81
  `import '${themeGroupsFile.themeGroupsSpecifier(loaderContext.resourcePath, themeGroups.file)}';
80
82
  `
@@ -192,7 +194,7 @@ function hasEnabledMangleVars(config) {
192
194
  return config.mangleVars === true;
193
195
  }
194
196
  function createShardCacheKey(context, metadata) {
195
- return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(safelistSource.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
197
+ return node_crypto.createHash("sha256").update(context.identity.generation).update("\0").update(pathNormalization.normalizePathSeparators(path__namespace.relative(context.root, metadata.sourcePath))).digest("hex");
196
198
  }
197
199
 
198
200
  exports.default = nextTurboLoader;
@@ -1,13 +1,15 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import * as path from 'node:path';
3
- import { i as injectNextRuntimeImports, e as ensureThemeGroupsFile, b as insertAfterUseDirective, t as themeGroupsSpecifier } from './shared/unplugin.Ceq-N4jI.mjs';
4
- import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, n as normalizeProviderPaths, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.Vn9x8SBP.mjs';
5
- import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, N as NextSafelistStateLockedError, a as NEXT_WATCH_LOCK_COMMAND, v as validateNextGenerationManifest, b as readNextGenerationManifest } from './shared/unplugin.BLptVbUe.mjs';
6
- import { n as normalizePathSeparators } from './shared/unplugin.DH_ij6cf.mjs';
7
- import { r as resolveTransformCacheDir } from './shared/unplugin.C-oQU1jl.mjs';
3
+ import { i as injectNextRuntimeImports, a as insertAfterUseDirective } from './shared/unplugin.DcXM9sq5.mjs';
4
+ import { r as readPackageVersion, c as configWithImportedStaticSz, a as resolveNextCrossModule, t as transformNextSource, w as withCrossModuleStatics, n as normalizeProviderPaths, b as collectNextTransformMetadata, d as createNextSafelistShardFromMetadata } from './shared/unplugin.C3bgc29e.mjs';
5
+ import { c as createNextStateContext, w as writeNextSafelistShard, r as runNextWatcherCycle, N as NextSafelistStateLockedError, a as NEXT_WATCH_LOCK_COMMAND, v as validateNextGenerationManifest, b as readNextGenerationManifest } from './shared/unplugin.DPSQP5XG.mjs';
6
+ import { n as normalizePathSeparators } from './shared/unplugin.wMeicb6E.mjs';
7
+ import { e as ensureThemeGroupsFile, t as themeGroupsSpecifier } from './shared/unplugin.995yC_cN.mjs';
8
+ import { r as resolveTransformCacheDir } from './shared/unplugin.2uf-U76p.mjs';
8
9
  import 'node:fs';
9
10
  import '@csszyx/compiler';
10
11
  import '@csszyx/types';
12
+ import './shared/unplugin.Ba3O1r8M.mjs';
11
13
  import 'node:os';
12
14
  import 'proper-lockfile';
13
15
 
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('node:path');
4
- const nextWatcherCycle = require('./shared/unplugin.BWnmKv07.cjs');
4
+ const nextWatcherCycle = require('./shared/unplugin.alhYXymJ.cjs');
5
5
  require('node:fs');
6
- require('./shared/unplugin.DDSWQJYX.cjs');
6
+ require('./shared/unplugin.DS6CFjim.cjs');
7
7
  require('node:crypto');
8
+ require('./shared/unplugin.BqKLlo1h.cjs');
8
9
  require('node:os');
9
10
  require('proper-lockfile');
10
11
 
@@ -1,8 +1,9 @@
1
1
  import * as path from 'node:path';
2
- import { r as runNextWatcherCycle } from './shared/unplugin.BLptVbUe.mjs';
2
+ import { r as runNextWatcherCycle } from './shared/unplugin.DPSQP5XG.mjs';
3
3
  import 'node:fs';
4
- import './shared/unplugin.DH_ij6cf.mjs';
4
+ import './shared/unplugin.Ba3O1r8M.mjs';
5
5
  import 'node:crypto';
6
+ import './shared/unplugin.wMeicb6E.mjs';
6
7
  import 'node:os';
7
8
  import 'proper-lockfile';
8
9
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  const fs = require('node:fs');
4
4
  const path = require('node:path');
5
- const safelistSource = require('./unplugin.DDSWQJYX.cjs');
5
+ const safelistSource = require('./unplugin.DS6CFjim.cjs');
6
6
 
7
7
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
8
 
@@ -273,26 +273,6 @@ function scanCustomPropertyNames(block) {
273
273
  return names;
274
274
  }
275
275
 
276
- const LEADING_WHITESPACE_RE = /^\s+/;
277
- const LINE_COMMENT_RE = /^\/\/[^\n]*(?:\n|$)/;
278
- const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?\*\//;
279
- const USE_DIRECTIVE_RE = /^['"]use (?:client|server)['"];?\s*/;
280
- function insertAfterUseDirective(code, insertion) {
281
- let offset = 0;
282
- while (offset < code.length) {
283
- const triviaLength = leadingTriviaLength(code.slice(offset));
284
- if (triviaLength === 0) break;
285
- offset += triviaLength;
286
- }
287
- const directive = USE_DIRECTIVE_RE.exec(code.slice(offset));
288
- if (!directive) return `${insertion}${code}`;
289
- const insertionOffset = offset + directive[0].length;
290
- return `${code.slice(0, insertionOffset)}${insertion}${code.slice(insertionOffset)}`;
291
- }
292
- function leadingTriviaLength(source) {
293
- return LEADING_WHITESPACE_RE.exec(source)?.[0].length ?? LINE_COMMENT_RE.exec(source)?.[0].length ?? BLOCK_COMMENT_RE.exec(source)?.[0].length ?? 0;
294
- }
295
-
296
276
  const VIRTUAL_MODULE_ID = "virtual:csszyx/mangle-map";
297
277
  const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
298
278
  const THEME_GROUPS_VIRTUAL_ID = "virtual:csszyx/theme-groups";
@@ -396,94 +376,6 @@ function createThemeGroupsModule(tokens) {
396
376
  ].join("\n");
397
377
  }
398
378
 
399
- const RUNTIME_IMPORT_CLAUSE_RE = /(?:import|export)\s+\{([^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/g;
400
- function clauseNames(clauseBody) {
401
- const names = [];
402
- for (const part of clauseBody.split(",")) {
403
- const trimmed = part.trim();
404
- if (!trimmed) {
405
- continue;
406
- }
407
- const spaceAt = trimmed.search(/\s/);
408
- names.push(spaceAt === -1 ? trimmed : trimmed.slice(0, spaceAt));
409
- }
410
- return names;
411
- }
412
- function importsRuntimeHelper(code, helper) {
413
- RUNTIME_IMPORT_CLAUSE_RE.lastIndex = 0;
414
- for (let match = RUNTIME_IMPORT_CLAUSE_RE.exec(code); match; match = RUNTIME_IMPORT_CLAUSE_RE.exec(code)) {
415
- if (clauseNames(match[1]).includes(helper)) {
416
- return true;
417
- }
418
- }
419
- return false;
420
- }
421
- const RUNTIME_IMPORT_APPEND_RE = /(import\s+\{[^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/;
422
- function findRuntimeImportClause(code) {
423
- const match = RUNTIME_IMPORT_APPEND_RE.exec(code);
424
- return match ? { statement: match[0], prefixWithBody: match[1] } : null;
425
- }
426
-
427
- function runtimeHelperGroupsFromUsage(usage) {
428
- const slim = usage.usesSzPart === true && usage.szPartArgsProvable === true && usage.usesRuntime !== true && usage.usesMerge !== true;
429
- const groups = { all: [], barrel: [], merge: [] };
430
- const append = (helper, toMerge = false) => {
431
- groups.all.push(helper);
432
- (toMerge ? groups.merge : groups.barrel).push(helper);
433
- };
434
- if (usage.usesRuntime) append("_sz");
435
- if (usage.usesMerge) append("_szMerge");
436
- if (usage.usesSzcn) append("_szcn", slim);
437
- if (usage.usesSzPart) append("_szPart", slim);
438
- if (usage.usesSzvPick) append("__szvPick");
439
- if (usage.usesSzvPick1) append("__szvPick1");
440
- if (usage.usesColorVar) append("__szColorVar");
441
- if (usage.usesSpacingVar) append("__szSpacingVar");
442
- if (usage.usesUnitVar) append("__szUnitVar");
443
- if (usage.usesBoolClass) append("__szBoolClass");
444
- return groups;
445
- }
446
- function injectNextRuntimeImports(code, usage) {
447
- const groups = runtimeHelperGroupsFromUsage(usage);
448
- const helpers = groups.all;
449
- if (helpers.length === 0) {
450
- return { code, injected: [] };
451
- }
452
- const hasRuntimeImport = code.includes("@csszyx/runtime");
453
- const missing = hasRuntimeImport ? helpers.filter((helper) => !importsRuntimeHelper(code, helper)) : helpers;
454
- if (missing.length === 0) {
455
- return { code, injected: [] };
456
- }
457
- if (groups.merge.length > 0) {
458
- const mergeHelpers = missing.filter((helper) => groups.merge.includes(helper));
459
- const barrelHelpers = missing.filter((helper) => groups.barrel.includes(helper));
460
- let next = insertRuntimeImport(
461
- code,
462
- `import { ${mergeHelpers.join(", ")} } from '@csszyx/runtime/merge';
463
- `
464
- );
465
- if (barrelHelpers.length > 0) {
466
- next = insertRuntimeImport(
467
- next,
468
- `import { ${barrelHelpers.join(", ")} } from '@csszyx/runtime';
469
- `
470
- );
471
- }
472
- return { code: next, injected: missing };
473
- }
474
- return {
475
- code: insertRuntimeImport(
476
- code,
477
- `import { ${missing.join(", ")} } from '@csszyx/runtime';
478
- `
479
- ),
480
- injected: missing
481
- };
482
- }
483
- function insertRuntimeImport(code, importStmt) {
484
- return insertAfterUseDirective(code, importStmt);
485
- }
486
-
487
379
  const THEME_SCAN_IGNORE_DIRS = /* @__PURE__ */ new Set([
488
380
  "node_modules",
489
381
  ".next",
@@ -611,16 +503,11 @@ exports.createMangleRuntimeModule = createMangleRuntimeModule;
611
503
  exports.createThemeGroupsModule = createThemeGroupsModule;
612
504
  exports.discoverProjectTheme = discoverProjectTheme;
613
505
  exports.ensureThemeGroupsFile = ensureThemeGroupsFile;
614
- exports.findRuntimeImportClause = findRuntimeImportClause;
615
506
  exports.hasTokens = hasTokens;
616
- exports.importsRuntimeHelper = importsRuntimeHelper;
617
- exports.injectNextRuntimeImports = injectNextRuntimeImports;
618
- exports.insertAfterUseDirective = insertAfterUseDirective;
619
507
  exports.isVirtualModule = isVirtualModule;
620
508
  exports.mergeThemes = mergeThemes;
621
509
  exports.parseThemeBlocks = parseThemeBlocks;
622
510
  exports.parseUtilityBlocks = parseUtilityBlocks;
623
511
  exports.resolveVirtualModule = resolveVirtualModule;
624
- exports.runtimeHelperGroupsFromUsage = runtimeHelperGroupsFromUsage;
625
512
  exports.scanCustomPropertyNames = scanCustomPropertyNames;
626
513
  exports.themeGroupsSpecifier = themeGroupsSpecifier;
@@ -1,6 +1,6 @@
1
1
  import * as path from 'node:path';
2
2
  import { extractCrossModuleRegistryEntries, extractCrossModuleForwards } from '@csszyx/compiler';
3
- import { n as normalizePathSeparators } from './unplugin.DH_ij6cf.mjs';
3
+ import { n as normalizePathSeparators } from './unplugin.wMeicb6E.mjs';
4
4
  import * as fs from 'node:fs';
5
5
  import { existsSync, statSync } from 'node:fs';
6
6
  import { createHash, randomUUID } from 'node:crypto';
@@ -1,6 +1,6 @@
1
1
  import fs__default from 'node:fs';
2
2
  import path__default from 'node:path';
3
- import { s as sortStrings } from './unplugin.DH_ij6cf.mjs';
3
+ import { s as sortStrings } from './unplugin.Ba3O1r8M.mjs';
4
4
 
5
5
  const EMPTY_THEME = {
6
6
  colors: [],
@@ -266,26 +266,6 @@ function scanCustomPropertyNames(block) {
266
266
  return names;
267
267
  }
268
268
 
269
- const LEADING_WHITESPACE_RE = /^\s+/;
270
- const LINE_COMMENT_RE = /^\/\/[^\n]*(?:\n|$)/;
271
- const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?\*\//;
272
- const USE_DIRECTIVE_RE = /^['"]use (?:client|server)['"];?\s*/;
273
- function insertAfterUseDirective(code, insertion) {
274
- let offset = 0;
275
- while (offset < code.length) {
276
- const triviaLength = leadingTriviaLength(code.slice(offset));
277
- if (triviaLength === 0) break;
278
- offset += triviaLength;
279
- }
280
- const directive = USE_DIRECTIVE_RE.exec(code.slice(offset));
281
- if (!directive) return `${insertion}${code}`;
282
- const insertionOffset = offset + directive[0].length;
283
- return `${code.slice(0, insertionOffset)}${insertion}${code.slice(insertionOffset)}`;
284
- }
285
- function leadingTriviaLength(source) {
286
- return LEADING_WHITESPACE_RE.exec(source)?.[0].length ?? LINE_COMMENT_RE.exec(source)?.[0].length ?? BLOCK_COMMENT_RE.exec(source)?.[0].length ?? 0;
287
- }
288
-
289
269
  const VIRTUAL_MODULE_ID = "virtual:csszyx/mangle-map";
290
270
  const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
291
271
  const THEME_GROUPS_VIRTUAL_ID = "virtual:csszyx/theme-groups";
@@ -389,94 +369,6 @@ function createThemeGroupsModule(tokens) {
389
369
  ].join("\n");
390
370
  }
391
371
 
392
- const RUNTIME_IMPORT_CLAUSE_RE = /(?:import|export)\s+\{([^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/g;
393
- function clauseNames(clauseBody) {
394
- const names = [];
395
- for (const part of clauseBody.split(",")) {
396
- const trimmed = part.trim();
397
- if (!trimmed) {
398
- continue;
399
- }
400
- const spaceAt = trimmed.search(/\s/);
401
- names.push(spaceAt === -1 ? trimmed : trimmed.slice(0, spaceAt));
402
- }
403
- return names;
404
- }
405
- function importsRuntimeHelper(code, helper) {
406
- RUNTIME_IMPORT_CLAUSE_RE.lastIndex = 0;
407
- for (let match = RUNTIME_IMPORT_CLAUSE_RE.exec(code); match; match = RUNTIME_IMPORT_CLAUSE_RE.exec(code)) {
408
- if (clauseNames(match[1]).includes(helper)) {
409
- return true;
410
- }
411
- }
412
- return false;
413
- }
414
- const RUNTIME_IMPORT_APPEND_RE = /(import\s+\{[^{}]*)\}\s*from\s*['"]@csszyx\/runtime['"]/;
415
- function findRuntimeImportClause(code) {
416
- const match = RUNTIME_IMPORT_APPEND_RE.exec(code);
417
- return match ? { statement: match[0], prefixWithBody: match[1] } : null;
418
- }
419
-
420
- function runtimeHelperGroupsFromUsage(usage) {
421
- const slim = usage.usesSzPart === true && usage.szPartArgsProvable === true && usage.usesRuntime !== true && usage.usesMerge !== true;
422
- const groups = { all: [], barrel: [], merge: [] };
423
- const append = (helper, toMerge = false) => {
424
- groups.all.push(helper);
425
- (toMerge ? groups.merge : groups.barrel).push(helper);
426
- };
427
- if (usage.usesRuntime) append("_sz");
428
- if (usage.usesMerge) append("_szMerge");
429
- if (usage.usesSzcn) append("_szcn", slim);
430
- if (usage.usesSzPart) append("_szPart", slim);
431
- if (usage.usesSzvPick) append("__szvPick");
432
- if (usage.usesSzvPick1) append("__szvPick1");
433
- if (usage.usesColorVar) append("__szColorVar");
434
- if (usage.usesSpacingVar) append("__szSpacingVar");
435
- if (usage.usesUnitVar) append("__szUnitVar");
436
- if (usage.usesBoolClass) append("__szBoolClass");
437
- return groups;
438
- }
439
- function injectNextRuntimeImports(code, usage) {
440
- const groups = runtimeHelperGroupsFromUsage(usage);
441
- const helpers = groups.all;
442
- if (helpers.length === 0) {
443
- return { code, injected: [] };
444
- }
445
- const hasRuntimeImport = code.includes("@csszyx/runtime");
446
- const missing = hasRuntimeImport ? helpers.filter((helper) => !importsRuntimeHelper(code, helper)) : helpers;
447
- if (missing.length === 0) {
448
- return { code, injected: [] };
449
- }
450
- if (groups.merge.length > 0) {
451
- const mergeHelpers = missing.filter((helper) => groups.merge.includes(helper));
452
- const barrelHelpers = missing.filter((helper) => groups.barrel.includes(helper));
453
- let next = insertRuntimeImport(
454
- code,
455
- `import { ${mergeHelpers.join(", ")} } from '@csszyx/runtime/merge';
456
- `
457
- );
458
- if (barrelHelpers.length > 0) {
459
- next = insertRuntimeImport(
460
- next,
461
- `import { ${barrelHelpers.join(", ")} } from '@csszyx/runtime';
462
- `
463
- );
464
- }
465
- return { code: next, injected: missing };
466
- }
467
- return {
468
- code: insertRuntimeImport(
469
- code,
470
- `import { ${missing.join(", ")} } from '@csszyx/runtime';
471
- `
472
- ),
473
- injected: missing
474
- };
475
- }
476
- function insertRuntimeImport(code, importStmt) {
477
- return insertAfterUseDirective(code, importStmt);
478
- }
479
-
480
372
  const THEME_SCAN_IGNORE_DIRS = /* @__PURE__ */ new Set([
481
373
  "node_modules",
482
374
  ".next",
@@ -587,4 +479,4 @@ function themeGroupsSpecifier(fromFile, themeGroupsFile) {
587
479
  return relative.startsWith("./") || relative.startsWith("../") ? relative : `./${relative}`;
588
480
  }
589
481
 
590
- export { CHECKSUM_PLACEHOLDER as C, MANGLE_RUNTIME_VIRTUAL_ID as M, RESOLVED_VIRTUAL_MODULE_ID as R, THEME_GROUPS_VIRTUAL_ID as T, VAR_MANGLE_MAP_PLACEHOLDER as V, parseUtilityBlocks as a, insertAfterUseDirective as b, createMangleRuntimeModule as c, createMangleMapModule as d, ensureThemeGroupsFile as e, RESOLVED_VIRTUAL_CHECKSUM_ID as f, createChecksumModule as g, hasTokens as h, injectNextRuntimeImports as i, RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID as j, RESOLVED_THEME_GROUPS_VIRTUAL_ID as k, createThemeGroupsModule as l, mergeThemes as m, isVirtualModule as n, discoverProjectTheme as o, parseThemeBlocks as p, CENSUS_PLACEHOLDER as q, resolveVirtualModule as r, scanCustomPropertyNames as s, themeGroupsSpecifier as t, importsRuntimeHelper as u, findRuntimeImportClause as v, THEME_GROUPS_FILE_MARKER as w, runtimeHelperGroupsFromUsage as x, MANGLE_MAP_PLACEHOLDER as y };
482
+ export { CHECKSUM_PLACEHOLDER as C, MANGLE_RUNTIME_VIRTUAL_ID as M, RESOLVED_VIRTUAL_MODULE_ID as R, THEME_GROUPS_VIRTUAL_ID as T, VAR_MANGLE_MAP_PLACEHOLDER as V, parseUtilityBlocks as a, createMangleMapModule as b, createMangleRuntimeModule as c, RESOLVED_VIRTUAL_CHECKSUM_ID as d, ensureThemeGroupsFile as e, createChecksumModule as f, RESOLVED_MANGLE_RUNTIME_VIRTUAL_ID as g, hasTokens as h, RESOLVED_THEME_GROUPS_VIRTUAL_ID as i, createThemeGroupsModule as j, isVirtualModule as k, discoverProjectTheme as l, mergeThemes as m, CENSUS_PLACEHOLDER as n, THEME_GROUPS_FILE_MARKER as o, parseThemeBlocks as p, MANGLE_MAP_PLACEHOLDER as q, resolveVirtualModule as r, scanCustomPropertyNames as s, themeGroupsSpecifier as t };