tailwind-styled-v4 5.0.11 → 5.0.12

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 (107) hide show
  1. package/dist/{analyzeWorkspace-DDOQdzzI.d.ts → analyzeWorkspace-CopJNGmi.d.ts} +2 -0
  2. package/dist/{analyzeWorkspace-BS5O4rhC.d.mts → analyzeWorkspace-DpVPccjz.d.mts} +2 -0
  3. package/dist/analyzer.d.mts +4 -4
  4. package/dist/analyzer.d.ts +4 -4
  5. package/dist/analyzer.js +34 -69
  6. package/dist/analyzer.js.map +1 -1
  7. package/dist/analyzer.mjs +33 -68
  8. package/dist/analyzer.mjs.map +1 -1
  9. package/dist/animate.js +11 -11
  10. package/dist/animate.js.map +1 -1
  11. package/dist/animate.mjs +11 -11
  12. package/dist/animate.mjs.map +1 -1
  13. package/dist/atomic.js +16 -7
  14. package/dist/atomic.js.map +1 -1
  15. package/dist/atomic.mjs +16 -7
  16. package/dist/atomic.mjs.map +1 -1
  17. package/dist/cli.js +262 -190
  18. package/dist/cli.js.map +1 -1
  19. package/dist/cli.mjs +259 -187
  20. package/dist/cli.mjs.map +1 -1
  21. package/dist/compiler.d.mts +2543 -109
  22. package/dist/compiler.d.ts +2543 -109
  23. package/dist/compiler.js +1962 -435
  24. package/dist/compiler.js.map +1 -1
  25. package/dist/compiler.mjs +1816 -382
  26. package/dist/compiler.mjs.map +1 -1
  27. package/dist/devtools.js +17 -4
  28. package/dist/devtools.js.map +1 -1
  29. package/dist/devtools.mjs +17 -4
  30. package/dist/devtools.mjs.map +1 -1
  31. package/dist/engine.d.mts +11 -470
  32. package/dist/engine.d.ts +11 -470
  33. package/dist/engine.js +1442 -417
  34. package/dist/engine.js.map +1 -1
  35. package/dist/engine.mjs +1442 -417
  36. package/dist/engine.mjs.map +1 -1
  37. package/dist/index-BDQw13kn.d.ts +464 -0
  38. package/dist/index-DJv28Uzq.d.mts +464 -0
  39. package/dist/index.browser.mjs +143 -255
  40. package/dist/index.browser.mjs.map +1 -1
  41. package/dist/index.d.mts +23 -39
  42. package/dist/index.d.ts +23 -39
  43. package/dist/index.js +6000 -1463
  44. package/dist/index.js.map +1 -1
  45. package/dist/index.mjs +5995 -1458
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/next.d.mts +44 -1
  48. package/dist/next.d.ts +44 -1
  49. package/dist/next.js +3197 -1128
  50. package/dist/next.js.map +1 -1
  51. package/dist/next.mjs +3196 -1129
  52. package/dist/next.mjs.map +1 -1
  53. package/dist/rspack.d.mts +9 -0
  54. package/dist/rspack.d.ts +9 -0
  55. package/dist/rspack.js +99 -61
  56. package/dist/rspack.js.map +1 -1
  57. package/dist/rspack.mjs +99 -61
  58. package/dist/rspack.mjs.map +1 -1
  59. package/dist/runtime-css.d.mts +8 -0
  60. package/dist/runtime-css.d.ts +8 -0
  61. package/dist/runtime-css.js +23 -7
  62. package/dist/runtime-css.js.map +1 -1
  63. package/dist/runtime-css.mjs +23 -7
  64. package/dist/runtime-css.mjs.map +1 -1
  65. package/dist/scanner.js +16 -37
  66. package/dist/scanner.js.map +1 -1
  67. package/dist/scanner.mjs +15 -36
  68. package/dist/scanner.mjs.map +1 -1
  69. package/dist/shared.d.mts +107 -1
  70. package/dist/shared.d.ts +107 -1
  71. package/dist/shared.js +1627 -376
  72. package/dist/shared.js.map +1 -1
  73. package/dist/shared.mjs +1620 -354
  74. package/dist/shared.mjs.map +1 -1
  75. package/dist/svelte.js +39 -35
  76. package/dist/svelte.js.map +1 -1
  77. package/dist/svelte.mjs +38 -34
  78. package/dist/svelte.mjs.map +1 -1
  79. package/dist/theme.js +85 -76
  80. package/dist/theme.js.map +1 -1
  81. package/dist/theme.mjs +83 -74
  82. package/dist/theme.mjs.map +1 -1
  83. package/dist/turbopackLoader.js +943 -76
  84. package/dist/turbopackLoader.js.map +1 -1
  85. package/dist/turbopackLoader.mjs +943 -76
  86. package/dist/turbopackLoader.mjs.map +1 -1
  87. package/dist/tw.js +262 -190
  88. package/dist/tw.js.map +1 -1
  89. package/dist/tw.mjs +259 -187
  90. package/dist/tw.mjs.map +1 -1
  91. package/dist/vite.js +1336 -296
  92. package/dist/vite.js.map +1 -1
  93. package/dist/vite.mjs +1336 -296
  94. package/dist/vite.mjs.map +1 -1
  95. package/dist/vue.js +39 -35
  96. package/dist/vue.js.map +1 -1
  97. package/dist/vue.mjs +38 -34
  98. package/dist/vue.mjs.map +1 -1
  99. package/dist/webpackLoader.js +140 -34
  100. package/dist/webpackLoader.js.map +1 -1
  101. package/dist/webpackLoader.mjs +140 -34
  102. package/dist/webpackLoader.mjs.map +1 -1
  103. package/native/index.node +0 -0
  104. package/native/tailwind-styled-native.node +0 -0
  105. package/native/tailwind-styled-native.win32-x64-msvc.node +0 -0
  106. package/package.json +9 -4
  107. package/CHANGELOG.md +0 -285
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var module$1 = require('module');
4
- var fs3 = require('fs');
5
- var path3 = require('path');
4
+ var fs4 = require('fs');
5
+ var path4 = require('path');
6
6
  require('crypto');
7
7
  var url = require('url');
8
8
 
@@ -25,11 +25,14 @@ function _interopNamespace(e) {
25
25
  return Object.freeze(n);
26
26
  }
27
27
 
28
- var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
29
- var path3__namespace = /*#__PURE__*/_interopNamespace(path3);
28
+ var fs4__namespace = /*#__PURE__*/_interopNamespace(fs4);
29
+ var path4__namespace = /*#__PURE__*/_interopNamespace(path4);
30
30
 
31
31
  /* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
32
+ var __defProp = Object.defineProperty;
33
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
32
34
  var __getOwnPropNames = Object.getOwnPropertyNames;
35
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
33
36
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
34
37
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
35
38
  }) : x)(function(x) {
@@ -39,6 +42,19 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
39
42
  var __esm = (fn, res) => function __init() {
40
43
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
41
44
  };
45
+ var __export = (target, all) => {
46
+ for (var name in all)
47
+ __defProp(target, name, { get: all[name], enumerable: true });
48
+ };
49
+ var __copyProps = (to, from, except, desc) => {
50
+ if (from && typeof from === "object" || typeof from === "function") {
51
+ for (let key of __getOwnPropNames(from))
52
+ if (!__hasOwnProp.call(to, key) && key !== except)
53
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
54
+ }
55
+ return to;
56
+ };
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
58
  function platformKey() {
43
59
  if (isBrowser) return "browser";
44
60
  return `${process.platform}-${process.arch}`;
@@ -49,12 +65,12 @@ function resolveNativeBinary(runtimeDir) {
49
65
  if (isBrowser) {
50
66
  return { path: null, source: "not-found", platform, tried: ["not available in browser"] };
51
67
  }
52
- if (process.env.TWS_DISABLE_NATIVE === "1") {
68
+ if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_DISABLE_NATIVE === "1") {
53
69
  return { path: null, source: "not-found", platform, tried: [] };
54
70
  }
55
71
  const envPath = process.env.TW_NATIVE_PATH?.trim();
56
72
  if (envPath) {
57
- if (fs3__namespace.existsSync(envPath)) {
73
+ if (fs4__namespace.existsSync(envPath)) {
58
74
  return { path: envPath, source: "env", platform, tried };
59
75
  }
60
76
  tried.push(`env:${envPath} (not found)`);
@@ -63,7 +79,7 @@ function resolveNativeBinary(runtimeDir) {
63
79
  for (const pkg of prebuiltPkgs) {
64
80
  try {
65
81
  const candidate = _require.resolve(`${pkg}/tailwind_styled_parser.node`);
66
- if (fs3__namespace.existsSync(candidate)) {
82
+ if (fs4__namespace.existsSync(candidate)) {
67
83
  return { path: candidate, source: "prebuilt", platform, tried };
68
84
  }
69
85
  tried.push(`prebuilt:${pkg} (resolved but missing)`);
@@ -74,13 +90,13 @@ function resolveNativeBinary(runtimeDir) {
74
90
  const napiPlatform = platform === "linux-x64" ? "linux-x64-gnu" : platform === "linux-arm64" ? "linux-arm64-gnu" : platform;
75
91
  const BINARY_NAMES_SELF = ["tailwind-styled-native", "tailwind_styled_parser"];
76
92
  if (runtimeDir) {
77
- for (const depth of ["..", path3__namespace.join("..", ".."), path3__namespace.join("..", "..", "..")]) {
78
- const pkgRoot = path3__namespace.resolve(runtimeDir, depth);
93
+ for (const depth of ["..", path4__namespace.join("..", ".."), path4__namespace.join("..", "..", "..")]) {
94
+ const pkgRoot = path4__namespace.resolve(runtimeDir, depth);
79
95
  for (const bin of BINARY_NAMES_SELF) {
80
96
  for (const suffix of ["", `.${platform}`, `.${napiPlatform}`]) {
81
- const candidate = path3__namespace.resolve(pkgRoot, "native", `${bin}${suffix}.node`);
97
+ const candidate = path4__namespace.resolve(pkgRoot, "native", `${bin}${suffix}.node`);
82
98
  tried.push(`self-bundled:${candidate}`);
83
- if (fs3__namespace.existsSync(candidate)) {
99
+ if (fs4__namespace.existsSync(candidate)) {
84
100
  return { path: candidate, source: "prebuilt", platform, tried };
85
101
  }
86
102
  }
@@ -92,29 +108,29 @@ function resolveNativeBinary(runtimeDir) {
92
108
  const BINARY_NAMES = ["tailwind-styled-native", "tailwind_styled_parser"];
93
109
  const localCandidates = [];
94
110
  for (const bin of BINARY_NAMES) {
95
- localCandidates.push(path3__namespace.resolve(base, `${bin}.node`));
96
- localCandidates.push(path3__namespace.resolve(base, "..", `${bin}.node`));
97
- localCandidates.push(path3__namespace.resolve(base, `${bin}.${platform}.node`));
98
- localCandidates.push(path3__namespace.resolve(base, `${bin}.${napiPlatform}.node`));
111
+ localCandidates.push(path4__namespace.resolve(base, `${bin}.node`));
112
+ localCandidates.push(path4__namespace.resolve(base, "..", `${bin}.node`));
113
+ localCandidates.push(path4__namespace.resolve(base, `${bin}.${platform}.node`));
114
+ localCandidates.push(path4__namespace.resolve(base, `${bin}.${napiPlatform}.node`));
99
115
  }
100
116
  for (const startDir of [cwd, base]) {
101
117
  let dir = startDir;
102
118
  for (let i = 0; i < 6; i++) {
103
- const nativeDir = path3__namespace.resolve(dir, "native");
119
+ const nativeDir = path4__namespace.resolve(dir, "native");
104
120
  for (const bin of BINARY_NAMES) {
105
- localCandidates.push(path3__namespace.resolve(nativeDir, `${bin}.node`));
106
- localCandidates.push(path3__namespace.resolve(nativeDir, `${bin}.${platform}.node`));
107
- localCandidates.push(path3__namespace.resolve(nativeDir, `${bin}.${napiPlatform}.node`));
108
- localCandidates.push(path3__namespace.resolve(nativeDir, "target", "release", `${bin}.node`));
121
+ localCandidates.push(path4__namespace.resolve(nativeDir, `${bin}.node`));
122
+ localCandidates.push(path4__namespace.resolve(nativeDir, `${bin}.${platform}.node`));
123
+ localCandidates.push(path4__namespace.resolve(nativeDir, `${bin}.${napiPlatform}.node`));
124
+ localCandidates.push(path4__namespace.resolve(nativeDir, "target", "release", `${bin}.node`));
109
125
  }
110
- const parent = path3__namespace.resolve(dir, "..");
126
+ const parent = path4__namespace.resolve(dir, "..");
111
127
  if (parent === dir) break;
112
128
  dir = parent;
113
129
  }
114
130
  }
115
131
  for (const candidate of localCandidates) {
116
132
  tried.push(`local:${candidate}`);
117
- if (fs3__namespace.existsSync(candidate)) {
133
+ if (fs4__namespace.existsSync(candidate)) {
118
134
  return { path: candidate, source: "local", platform, tried };
119
135
  }
120
136
  }
@@ -137,7 +153,7 @@ var init_native_resolution = __esm({
137
153
  });
138
154
  function resolveRuntimeDir(dir, importMetaUrl) {
139
155
  try {
140
- return path3__namespace.default.dirname(url.fileURLToPath(importMetaUrl));
156
+ return path4__namespace.default.dirname(url.fileURLToPath(importMetaUrl));
141
157
  } catch {
142
158
  return process.cwd();
143
159
  }
@@ -150,11 +166,11 @@ var init_src = __esm({
150
166
  });
151
167
 
152
168
  // packages/domain/compiler/src/nativeBridge.ts
153
- var _loadNative, log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge;
169
+ var _loadNative, log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge, adaptNativeResult;
154
170
  var init_nativeBridge = __esm({
155
171
  "packages/domain/compiler/src/nativeBridge.ts"() {
156
172
  init_src();
157
- _loadNative = (path4) => __require(path4);
173
+ _loadNative = (path5) => __require(path5);
158
174
  log = (...args) => {
159
175
  if (process.env.DEBUG?.includes("compiler:native")) {
160
176
  console.log("[compiler:native]", ...args);
@@ -203,6 +219,15 @@ Tried paths: ${result.tried.join("\n")}`);
203
219
  throw bridgeLoadError;
204
220
  }
205
221
  };
222
+ adaptNativeResult = (raw) => {
223
+ return {
224
+ code: raw.code ?? "",
225
+ classes: raw.classes ?? [],
226
+ changed: raw.changed ?? false,
227
+ rsc: raw.rscJson ? JSON.parse(raw.rscJson) : void 0,
228
+ metadata: raw.metadataJson ? JSON.parse(raw.metadataJson) : void 0
229
+ };
230
+ };
206
231
  if (typeof process !== "undefined" && !bridgeLoadAttempted) {
207
232
  try {
208
233
  getNativeBridge();
@@ -212,30 +237,852 @@ Tried paths: ${result.tried.join("\n")}`);
212
237
  }
213
238
  });
214
239
 
215
- // packages/domain/compiler/src/index.ts
216
- init_nativeBridge();
217
- var transformSource = (source, opts) => {
218
- const native = getNativeBridge();
219
- if (!native?.transformSource) {
220
- throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
240
+ // packages/domain/compiler/src/tailwindEngine.ts
241
+ var tailwindEngine_exports = {};
242
+ __export(tailwindEngine_exports, {
243
+ clearCache: () => clearCache,
244
+ generateRawCss: () => generateRawCss,
245
+ getCacheStats: () => getCacheStats,
246
+ processTailwindCssWithTargets: () => processTailwindCssWithTargets,
247
+ runCssPipeline: () => runCssPipeline,
248
+ runCssPipelineSync: () => runCssPipelineSync
249
+ });
250
+ function _getCacheKey(classes, minify, cssEntry, root) {
251
+ const sorted = [...classes].sort().join(",");
252
+ const flags = `${minify ? "1" : "0"}${cssEntry ? "1" : "0"}${root ? "1" : "0"}`;
253
+ return `${sorted}|${flags}`;
254
+ }
255
+ function _evictOldestIfNeeded() {
256
+ if (_cssCache.size >= MAX_CACHE_SIZE) {
257
+ const firstKey = _cssCache.keys().next().value;
258
+ if (firstKey !== void 0) {
259
+ _cssCache.delete(firstKey);
260
+ }
221
261
  }
222
- const result = native.transformSource(source, opts);
223
- if (!result) {
224
- throw new Error("FATAL: transformSource returned null");
262
+ }
263
+ function getCacheStats() {
264
+ const total = _cacheHits + _cacheMisses;
265
+ return {
266
+ hits: _cacheHits,
267
+ misses: _cacheMisses,
268
+ hitRate: total > 0 ? _cacheHits / total : 0,
269
+ size: _cssCache.size,
270
+ maxSize: MAX_CACHE_SIZE
271
+ };
272
+ }
273
+ function clearCache() {
274
+ _cssCache.clear();
275
+ _cacheHits = 0;
276
+ _cacheMisses = 0;
277
+ }
278
+ function loadTailwindEngine() {
279
+ if (_twEngine) return _twEngine;
280
+ if (_twEngineError) throw _twEngineError;
281
+ try {
282
+ const tw = require2("tailwindcss");
283
+ if (typeof tw.compile !== "function") {
284
+ throw new Error("tailwindcss v4 not found \u2014 compile() API missing. Check tailwindcss version >= 4.");
285
+ }
286
+ _twEngine = tw;
287
+ return _twEngine;
288
+ } catch (e) {
289
+ _twEngineError = e instanceof Error ? e : new Error(String(e));
290
+ throw _twEngineError;
225
291
  }
226
- return result;
227
- };
228
- var runLoaderTransform = (ctx) => {
229
- const { filepath, source, options } = ctx;
230
- const result = transformSource(source, { filename: filepath, ...options });
292
+ }
293
+ async function generateRawCss(classes, cssEntryContent, root) {
294
+ if (classes.length === 0) return "";
295
+ const tw = loadTailwindEngine();
296
+ const input = cssEntryContent ?? "@import 'tailwindcss';";
297
+ const { readFileSync, existsSync: existsSync2 } = await import('fs');
298
+ const { dirname, resolve: resolve2 } = await import('path');
299
+ const projectRoot = root ?? process.cwd();
300
+ const req = module$1.createRequire(resolve2(projectRoot, "package.json"));
301
+ const loadStylesheet = async (id, base) => {
302
+ try {
303
+ const cssId = id === "tailwindcss" ? "tailwindcss/index.css" : id === "tailwindcss/preflight" ? "tailwindcss/preflight.css" : id === "tailwindcss/utilities" ? "tailwindcss/utilities.css" : id === "tailwindcss/theme" ? "tailwindcss/theme.css" : id;
304
+ const pkgPath = req.resolve(cssId);
305
+ return { content: readFileSync(pkgPath, "utf-8"), base: dirname(pkgPath) };
306
+ } catch {
307
+ try {
308
+ const absPath = resolve2(base, id);
309
+ if (existsSync2(absPath)) {
310
+ return { content: readFileSync(absPath, "utf-8"), base: dirname(absPath) };
311
+ }
312
+ } catch {
313
+ }
314
+ return { content: "", base };
315
+ }
316
+ };
317
+ const compiler = await Promise.resolve(tw.compile(input, { loadStylesheet }));
318
+ return compiler.build(classes);
319
+ }
320
+ function getThemeConfig() {
231
321
  return {
232
- code: result?.code || "",
233
- changed: result?.changed || false,
234
- classes: result?.classes || []
322
+ colors: {
323
+ slate: {
324
+ "50": "#f8fafc",
325
+ "100": "#f1f5f9",
326
+ "200": "#e2e8f0",
327
+ "300": "#cbd5e1",
328
+ "400": "#94a3b8",
329
+ "500": "#64748b",
330
+ "600": "#475569",
331
+ "700": "#334155",
332
+ "800": "#1e293b",
333
+ "900": "#0f172a"
334
+ },
335
+ gray: {
336
+ "50": "#f9fafb",
337
+ "100": "#f3f4f6",
338
+ "200": "#e5e7eb",
339
+ "300": "#d1d5db",
340
+ "400": "#9ca3af",
341
+ "500": "#6b7280",
342
+ "600": "#4b5563",
343
+ "700": "#374151",
344
+ "800": "#1f2937",
345
+ "900": "#111827"
346
+ },
347
+ white: "#ffffff",
348
+ black: "#000000",
349
+ red: {
350
+ "500": "#ef4444",
351
+ "600": "#dc2626"
352
+ },
353
+ blue: {
354
+ "500": "#3b82f6",
355
+ "600": "#1e40af"
356
+ }
357
+ },
358
+ spacing: {
359
+ "0": "0px",
360
+ "1": "0.25rem",
361
+ "2": "0.5rem",
362
+ "3": "0.75rem",
363
+ "4": "1rem",
364
+ "5": "1.25rem",
365
+ "6": "1.5rem",
366
+ "8": "2rem",
367
+ "10": "2.5rem",
368
+ "12": "3rem",
369
+ "16": "4rem",
370
+ "20": "5rem",
371
+ "24": "6rem"
372
+ },
373
+ breakpoints: {
374
+ "sm": "640px",
375
+ "md": "768px",
376
+ "lg": "1024px",
377
+ "xl": "1280px",
378
+ "2xl": "1536px"
379
+ }
235
380
  };
236
- };
237
- var registerFileClasses = (_filepath, _classes) => {
238
- };
381
+ }
382
+ function postProcessWithLightning(rawCss) {
383
+ if (!rawCss) return "";
384
+ const native = getNativeBridge();
385
+ if (!native?.processTailwindCssLightning) {
386
+ throw new Error("FATAL: Native binding 'processTailwindCssLightning' is required but not available.");
387
+ }
388
+ const result = native.processTailwindCssLightning(rawCss);
389
+ if (!result?.css) {
390
+ throw new Error("FATAL: processTailwindCssLightning returned null");
391
+ }
392
+ return result.css;
393
+ }
394
+ async function runCssPipeline(classes, cssEntryContent, root, minify = true) {
395
+ const filtered = classes.filter(Boolean);
396
+ const uniqueMap = /* @__PURE__ */ new Map();
397
+ filtered.forEach((cls) => uniqueMap.set(cls, cls));
398
+ const unique = Array.from(uniqueMap.values());
399
+ if (unique.length === 0) {
400
+ return { css: "", classes: [], sizeBytes: 0, optimized: false };
401
+ }
402
+ const cacheKey = _getCacheKey(unique, minify, cssEntryContent, root);
403
+ const cached = _cssCache.get(cacheKey);
404
+ if (cached) {
405
+ _cacheHits++;
406
+ if (process.env.DEBUG?.includes("compiler")) {
407
+ console.log(
408
+ `[Compiler] Cache HIT: ${unique.length} classes (hit rate: ${(getCacheStats().hitRate * 100).toFixed(1)}%)`
409
+ );
410
+ }
411
+ return cached;
412
+ }
413
+ _cacheMisses++;
414
+ let rawCss;
415
+ let usedRustCompiler = false;
416
+ try {
417
+ const theme = getThemeConfig();
418
+ rawCss = await generateCssNative(unique, {
419
+ theme,
420
+ fallbackToJs: true,
421
+ logFallback: process.env.DEBUG?.includes("compiler") === true
422
+ });
423
+ usedRustCompiler = true;
424
+ } catch (error) {
425
+ if (process.env.DEBUG?.includes("compiler")) {
426
+ console.warn("[Compiler] Rust compiler failed, using JavaScript Tailwind:", error);
427
+ }
428
+ rawCss = await generateRawCss(unique, cssEntryContent, root);
429
+ }
430
+ const finalCss = minify ? postProcessWithLightning(rawCss) : rawCss;
431
+ if (process.env.DEBUG?.includes("compiler")) {
432
+ console.log(
433
+ `[Compiler] Generated CSS from ${unique.length} classes (${usedRustCompiler ? "Rust" : "JavaScript"})`,
434
+ `Size: ${finalCss.length} bytes`
435
+ );
436
+ }
437
+ const result = {
438
+ css: finalCss,
439
+ classes: unique,
440
+ sizeBytes: finalCss.length,
441
+ optimized: minify
442
+ };
443
+ _evictOldestIfNeeded();
444
+ _cssCache.set(cacheKey, result);
445
+ return result;
446
+ }
447
+ function runCssPipelineSync(_classes) {
448
+ return { css: "", classes: [], sizeBytes: 0, optimized: false };
449
+ }
450
+ function processTailwindCssWithTargets(css, targets) {
451
+ const native = getNativeBridge();
452
+ if (!native?.processTailwindCssWithTargets) {
453
+ throw new Error("FATAL: Native binding 'processTailwindCssWithTargets' is required but not available.");
454
+ }
455
+ const result = native.processTailwindCssWithTargets(css, targets ?? null);
456
+ if (!result?.css) {
457
+ throw new Error("FATAL: processTailwindCssWithTargets returned null");
458
+ }
459
+ return result.css;
460
+ }
461
+ var require2, _cssCache, _cacheHits, _cacheMisses, MAX_CACHE_SIZE, _twEngine, _twEngineError;
462
+ var init_tailwindEngine = __esm({
463
+ "packages/domain/compiler/src/tailwindEngine.ts"() {
464
+ init_nativeBridge();
465
+ init_cssGeneratorNative();
466
+ require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('turbopackLoader.js', document.baseURI).href)));
467
+ _cssCache = /* @__PURE__ */ new Map();
468
+ _cacheHits = 0;
469
+ _cacheMisses = 0;
470
+ MAX_CACHE_SIZE = 100;
471
+ _twEngine = null;
472
+ _twEngineError = null;
473
+ }
474
+ });
475
+
476
+ // packages/domain/compiler/src/cssGeneratorNative.ts
477
+ async function generateCssNative(classes, options) {
478
+ const {
479
+ theme,
480
+ fallbackToJs = true,
481
+ logFallback = false
482
+ } = options;
483
+ try {
484
+ const native = getNativeBridge();
485
+ if (!native?.generateCssNative) {
486
+ throw new Error("generateCssNative not available in native binding");
487
+ }
488
+ const themeJson = JSON.stringify(theme);
489
+ const css = native.generateCssNative(classes, themeJson);
490
+ return css;
491
+ } catch (error) {
492
+ if (!fallbackToJs) {
493
+ throw error;
494
+ }
495
+ if (logFallback) {
496
+ console.warn(
497
+ "[CSS Compiler] Rust CSS generator unavailable, falling back to JavaScript Tailwind",
498
+ error instanceof Error ? error.message : String(error)
499
+ );
500
+ }
501
+ return generateRawCss(classes);
502
+ }
503
+ }
504
+ var init_cssGeneratorNative = __esm({
505
+ "packages/domain/compiler/src/cssGeneratorNative.ts"() {
506
+ init_nativeBridge();
507
+ init_tailwindEngine();
508
+ }
509
+ });
510
+ function _layoutClassesToCss(classes) {
511
+ const native = getNativeBridge();
512
+ if (!native?.layoutClassesToCss) {
513
+ throw new Error("FATAL: Native binding 'layoutClassesToCss' is required but not available.");
514
+ }
515
+ return native.layoutClassesToCss(classes);
516
+ }
517
+ function _hashContainer(tag, containerJson, name) {
518
+ const sortedKey = tag + (name ?? "") + containerJson;
519
+ const native = getNativeBridge();
520
+ if (!native?.hashContent) {
521
+ throw new Error("FATAL: Native binding 'hashContent' is required but not available.");
522
+ }
523
+ return `tw-cq-${native.hashContent(sortedKey, "fnv", 6)}`;
524
+ }
525
+ function extractContainerCssFromSource(source) {
526
+ const native = getNativeBridge();
527
+ if (!native?.extractTwContainerConfigs) {
528
+ throw new Error("FATAL: Native binding 'extractTwContainerConfigs' is required but not available.");
529
+ }
530
+ const configs = native.extractTwContainerConfigs(source);
531
+ const rules = [];
532
+ for (const cfg of configs) {
533
+ const id = _hashContainer(cfg.tag, cfg.containerJson, cfg.containerName);
534
+ for (const { key, classes } of cfg.breakpoints) {
535
+ const minWidth = _CONTAINER_BREAKPOINTS[key] ?? key;
536
+ const css = _layoutClassesToCss(classes);
537
+ if (!css) continue;
538
+ const query = cfg.containerName ? `@container ${cfg.containerName} (min-width: ${minWidth})` : `@container (min-width: ${minWidth})`;
539
+ rules.push(`${query}{.${id}{${css}}}`);
540
+ }
541
+ }
542
+ return rules.join("\n");
543
+ }
544
+ var transformSource, hasTwUsage, isAlreadyTransformed, shouldProcess, compileCssFromClasses, buildStyleTag, compileCssNative, generateCssForClasses, extractAllClasses, extractClassesFromSource, astExtractClasses, parseClasses, normalizeClasses, mergeClassesStatic, normalizeAndDedupClasses, eliminateDeadCss, findDeadVariants, runElimination, optimizeCss, scanProjectUsage, extractComponentUsage, diffClassLists, batchExtractClasses, checkAgainstSafelist, hoistComponents, compileVariantTable, compileVariants, classifyAndSortClasses, mergeCssDeclarations, analyzeClassUsage, analyzeRsc, analyzeFile, analyzeVariantUsage, injectClientDirective, injectServerOnlyComment, analyzeClasses, generateSafelist, loadSafelist, loadTailwindConfig, getContentPaths, _CONTAINER_BREAKPOINTS, runLoaderTransform, shouldSkipFile, fileToRoute, getAllRoutes, getRouteClasses, registerFileClasses, registerGlobalClasses, _incrementalEngineInstance, getIncrementalEngine, resetIncrementalEngine, IncrementalEngine, getBucketEngine, resetBucketEngine, classifyNode, detectConflicts, bucketSort, extractTwStateConfigs, generateStaticStateCss, extractAndGenerateStateCss;
545
+ var init_src2 = __esm({
546
+ "packages/domain/compiler/src/index.ts"() {
547
+ init_nativeBridge();
548
+ transformSource = (source, opts) => {
549
+ const native = getNativeBridge();
550
+ if (!native?.transformSource) {
551
+ throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
552
+ }
553
+ const result = native.transformSource(source, opts);
554
+ if (!result) {
555
+ throw new Error("FATAL: transformSource returned null");
556
+ }
557
+ return result;
558
+ };
559
+ hasTwUsage = (source) => {
560
+ const native = getNativeBridge();
561
+ if (!native?.hasTwUsage) {
562
+ throw new Error("FATAL: Native binding 'hasTwUsage' is required but not available.");
563
+ }
564
+ return native.hasTwUsage(source);
565
+ };
566
+ isAlreadyTransformed = (source) => {
567
+ const native = getNativeBridge();
568
+ if (!native?.isAlreadyTransformed) {
569
+ throw new Error("FATAL: Native binding 'isAlreadyTransformed' is required but not available.");
570
+ }
571
+ return native.isAlreadyTransformed(source);
572
+ };
573
+ shouldProcess = (source) => {
574
+ return hasTwUsage(source) && !isAlreadyTransformed(source);
575
+ };
576
+ compileCssFromClasses = (classes, prefix) => {
577
+ const native = getNativeBridge();
578
+ if (!native?.transformSource) {
579
+ throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
580
+ }
581
+ const result = native.transformSource(classes.join(" "), { prefix: prefix ?? "" });
582
+ if (!result) {
583
+ throw new Error("FATAL: transformSource returned null");
584
+ }
585
+ return result;
586
+ };
587
+ buildStyleTag = (classes) => {
588
+ const result = compileCssFromClasses(classes);
589
+ return result?.code ? `<style data-tailwind-styled>${result.code}</style>` : "";
590
+ };
591
+ compileCssNative = (classes, prefix = null) => {
592
+ return compileCssFromClasses(classes, prefix);
593
+ };
594
+ generateCssForClasses = async (classes, _tailwindConfig, root, cssEntryContent, minify = false) => {
595
+ const { runCssPipeline: runCssPipeline2 } = await Promise.resolve().then(() => (init_tailwindEngine(), tailwindEngine_exports));
596
+ const result = await runCssPipeline2(classes, cssEntryContent, root, minify);
597
+ return result.css;
598
+ };
599
+ extractAllClasses = (source) => {
600
+ const native = getNativeBridge();
601
+ if (!native?.extractAllClasses) {
602
+ throw new Error("FATAL: Native binding 'extractAllClasses' is required but not available.");
603
+ }
604
+ return native.extractAllClasses(source) || [];
605
+ };
606
+ extractClassesFromSource = (source) => {
607
+ const native = getNativeBridge();
608
+ if (!native?.extractClassesFromSource) {
609
+ throw new Error("FATAL: Native binding 'extractClassesFromSource' is required but not available.");
610
+ }
611
+ const result = native.extractClassesFromSource(source);
612
+ return Array.isArray(result) ? result.join(" ") : String(result || "");
613
+ };
614
+ astExtractClasses = (source, _filename) => {
615
+ const native = getNativeBridge();
616
+ if (!native?.extractClassesFromSource) {
617
+ throw new Error("FATAL: Native binding 'extractClassesFromSource' is required but not available.");
618
+ }
619
+ return native.extractClassesFromSource(source) || [];
620
+ };
621
+ parseClasses = (raw) => {
622
+ const native = getNativeBridge();
623
+ if (!native?.parseClasses) {
624
+ throw new Error("FATAL: Native binding 'parseClasses' is required but not available.");
625
+ }
626
+ return native.parseClasses(raw) || [];
627
+ };
628
+ normalizeClasses = (raw) => {
629
+ const result = normalizeAndDedupClasses(raw);
630
+ return result?.normalized || "";
631
+ };
632
+ mergeClassesStatic = (classes) => {
633
+ const result = normalizeAndDedupClasses(classes);
634
+ return result?.normalized || "";
635
+ };
636
+ normalizeAndDedupClasses = (raw) => {
637
+ const native = getNativeBridge();
638
+ if (!native?.normalizeAndDedupClasses) {
639
+ throw new Error("FATAL: Native binding 'normalizeAndDedupClasses' is required but not available.");
640
+ }
641
+ const result = native.normalizeAndDedupClasses(raw);
642
+ return result || { normalized: "", duplicatesRemoved: 0, uniqueCount: 0 };
643
+ };
644
+ eliminateDeadCss = (css, deadClasses) => {
645
+ const native = getNativeBridge();
646
+ if (!native?.eliminateDeadCss) {
647
+ throw new Error("FATAL: Native binding 'eliminateDeadCss' is required but not available.");
648
+ }
649
+ return native.eliminateDeadCss(css, Array.from(deadClasses));
650
+ };
651
+ findDeadVariants = (variantConfig, usage) => {
652
+ const unused = [];
653
+ const configs = Array.isArray(variantConfig) ? variantConfig : [{ name: "__root__", variants: variantConfig }];
654
+ for (const component of configs) {
655
+ const componentUsage = usage[component.name] ?? /* @__PURE__ */ new Set();
656
+ const variants = component.variants;
657
+ for (const [key, values] of Object.entries(variants)) {
658
+ for (const [value] of Object.entries(values)) {
659
+ if (!componentUsage.has(`${key}:${value}`)) {
660
+ unused.push(`${component.name !== "__root__" ? `${component.name}/` : ""}${key}:${value}`);
661
+ }
662
+ }
663
+ }
664
+ }
665
+ return { unusedCount: unused.length, unused };
666
+ };
667
+ runElimination = (css, scanResult) => {
668
+ const native = getNativeBridge();
669
+ if (!native?.detectDeadCode) {
670
+ throw new Error("FATAL: Native binding 'detectDeadCode' is required but not available.");
671
+ }
672
+ const dead = native.detectDeadCode(JSON.stringify(scanResult), css);
673
+ return eliminateDeadCss(css, new Set(dead.deadInCss ?? []));
674
+ };
675
+ optimizeCss = (css) => {
676
+ const native = getNativeBridge();
677
+ if (!native?.optimizeCss) {
678
+ throw new Error("FATAL: Native binding 'optimizeCss' is required but not available.");
679
+ }
680
+ return native.optimizeCss(css);
681
+ };
682
+ scanProjectUsage = (dirs, cwd) => {
683
+ const files = dirs.map((dir) => path4__namespace.default.resolve(cwd, dir));
684
+ const results = batchExtractClasses(files) || [];
685
+ const combined = {};
686
+ for (const result of results) {
687
+ if (result.ok && result.classes) {
688
+ for (const cls of result.classes) {
689
+ if (!combined[cls]) combined[cls] = {};
690
+ combined[cls][result.file] = /* @__PURE__ */ new Set([cls]);
691
+ }
692
+ }
693
+ }
694
+ return combined;
695
+ };
696
+ extractComponentUsage = (source) => {
697
+ const native = getNativeBridge();
698
+ if (!native?.extractComponentUsage) {
699
+ throw new Error("FATAL: Native binding 'extractComponentUsage' is required but not available.");
700
+ }
701
+ return native.extractComponentUsage(source) || [];
702
+ };
703
+ diffClassLists = (previous, current) => {
704
+ const native = getNativeBridge();
705
+ if (!native?.diffClassLists) {
706
+ throw new Error("FATAL: Native binding 'diffClassLists' is required but not available.");
707
+ }
708
+ return native.diffClassLists(previous, current) || { added: [], removed: [], unchanged: [], hasChanges: false };
709
+ };
710
+ batchExtractClasses = (filePaths) => {
711
+ const native = getNativeBridge();
712
+ if (!native?.batchExtractClasses) {
713
+ throw new Error("FATAL: Native binding 'batchExtractClasses' is required but not available.");
714
+ }
715
+ return native.batchExtractClasses(filePaths) || [];
716
+ };
717
+ checkAgainstSafelist = (classes, safelist) => {
718
+ const native = getNativeBridge();
719
+ if (!native?.checkAgainstSafelist) {
720
+ throw new Error("FATAL: Native binding 'checkAgainstSafelist' is required but not available.");
721
+ }
722
+ return native.checkAgainstSafelist(classes, safelist) || { matched: [], unmatched: [], safelistSize: 0 };
723
+ };
724
+ hoistComponents = (source) => {
725
+ const native = getNativeBridge();
726
+ if (!native?.hoistComponents) {
727
+ throw new Error("FATAL: Native binding 'hoistComponents' is required but not available.");
728
+ }
729
+ return native.hoistComponents(source) || { code: source, hoisted: [], warnings: [] };
730
+ };
731
+ compileVariantTable = (configJson) => {
732
+ const native = getNativeBridge();
733
+ if (!native?.compileVariantTable) {
734
+ throw new Error("FATAL: Native binding 'compileVariantTable' is required but not available.");
735
+ }
736
+ return native.compileVariantTable(configJson) || { id: "", tableJson: "{}", keys: [], defaultKey: "", combinations: 0 };
737
+ };
738
+ compileVariants = (componentId, config) => {
739
+ return compileVariantTable(JSON.stringify({ componentId, ...config }));
740
+ };
741
+ classifyAndSortClasses = (classes) => {
742
+ const native = getNativeBridge();
743
+ if (!native?.classifyAndSortClasses) {
744
+ throw new Error("FATAL: Native binding 'classifyAndSortClasses' is required but not available.");
745
+ }
746
+ return native.classifyAndSortClasses(classes) || [];
747
+ };
748
+ mergeCssDeclarations = (cssChunks) => {
749
+ const native = getNativeBridge();
750
+ if (!native?.mergeCssDeclarations) {
751
+ throw new Error("FATAL: Native binding 'mergeCssDeclarations' is required but not available.");
752
+ }
753
+ return native.mergeCssDeclarations(cssChunks) || { declarationsJson: "{}", declarationString: "", count: 0 };
754
+ };
755
+ analyzeClassUsage = (classes, scanResultJson, css) => {
756
+ const native = getNativeBridge();
757
+ if (!native?.analyzeClassUsage) {
758
+ throw new Error("FATAL: Native binding 'analyzeClassUsage' is required but not available.");
759
+ }
760
+ return native.analyzeClassUsage(classes, scanResultJson, css) || [];
761
+ };
762
+ analyzeRsc = (source, filename) => {
763
+ const native = getNativeBridge();
764
+ if (!native?.analyzeRsc) {
765
+ throw new Error("FATAL: Native binding 'analyzeRsc' is required but not available.");
766
+ }
767
+ return native.analyzeRsc(source, filename) || { isServer: true, needsClientDirective: false, clientReasons: [] };
768
+ };
769
+ analyzeFile = (source, filename) => {
770
+ const rsc = analyzeRsc(source, filename);
771
+ return {
772
+ isServer: rsc?.isServer ?? true,
773
+ needsClientDirective: rsc?.needsClientDirective ?? false,
774
+ clientReasons: rsc?.clientReasons ?? [],
775
+ interactiveClasses: [],
776
+ canStaticResolveVariants: true
777
+ };
778
+ };
779
+ analyzeVariantUsage = (_source, _componentName, _variantKeys) => {
780
+ return { resolved: {}, dynamic: [] };
781
+ };
782
+ injectClientDirective = (source) => {
783
+ if (!source.includes('"use client"') && !source.includes("'use client'")) {
784
+ return '"use client";\n' + source;
785
+ }
786
+ return source;
787
+ };
788
+ injectServerOnlyComment = (source) => {
789
+ return `/* @server-only */
790
+ ${source}`;
791
+ };
792
+ analyzeClasses = (filesJson, cwd, flags) => {
793
+ const native = getNativeBridge();
794
+ if (!native?.analyzeClasses) {
795
+ throw new Error("FATAL: Native binding 'analyzeClasses' is required but not available.");
796
+ }
797
+ return native.analyzeClasses(filesJson, cwd, flags);
798
+ };
799
+ generateSafelist = (scanDirs, outputPath, cwd) => {
800
+ const classes = scanProjectUsage(scanDirs, cwd || process.cwd());
801
+ const allClasses = Object.keys(classes).sort();
802
+ if (outputPath) {
803
+ fs4__namespace.default.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2));
804
+ }
805
+ return allClasses;
806
+ };
807
+ loadSafelist = (safelistPath) => {
808
+ try {
809
+ const content = fs4__namespace.default.readFileSync(safelistPath, "utf-8");
810
+ return JSON.parse(content);
811
+ } catch {
812
+ return [];
813
+ }
814
+ };
815
+ loadTailwindConfig = (cwd = process.cwd()) => {
816
+ const configFiles = [
817
+ "tailwind.config.ts",
818
+ "tailwind.config.js",
819
+ "tailwind.config.mjs",
820
+ "tailwind.config.cjs"
821
+ ];
822
+ for (const file of configFiles) {
823
+ const fullPath = path4__namespace.default.join(cwd, file);
824
+ if (fs4__namespace.default.existsSync(fullPath)) {
825
+ const mod = __require(fullPath);
826
+ return mod.default || mod;
827
+ }
828
+ }
829
+ return {};
830
+ };
831
+ getContentPaths = (cwd = process.cwd()) => {
832
+ return {
833
+ content: [
834
+ path4__namespace.default.join(cwd, "src/**/*.{js,ts,jsx,tsx}"),
835
+ path4__namespace.default.join(cwd, "app/**/*.{js,ts,jsx,tsx}"),
836
+ path4__namespace.default.join(cwd, "pages/**/*.{js,ts,jsx,tsx}")
837
+ ]
838
+ };
839
+ };
840
+ _CONTAINER_BREAKPOINTS = {
841
+ xs: "240px",
842
+ sm: "320px",
843
+ md: "640px",
844
+ lg: "1024px",
845
+ xl: "1280px",
846
+ "2xl": "1536px"
847
+ };
848
+ runLoaderTransform = (ctx) => {
849
+ const { filepath, source, options } = ctx;
850
+ const result = transformSource(source, { filename: filepath, ...options });
851
+ let staticCss;
852
+ try {
853
+ const cssChunks = [];
854
+ const stateRules = extractAndGenerateStateCss(source, filepath);
855
+ if (stateRules.length > 0) {
856
+ cssChunks.push(stateRules.map((r) => r.cssRule).join("\n"));
857
+ }
858
+ const containerCss = extractContainerCssFromSource(source);
859
+ if (containerCss) cssChunks.push(containerCss);
860
+ const combined = cssChunks.join("\n").trim();
861
+ if (combined) staticCss = combined;
862
+ } catch {
863
+ }
864
+ return {
865
+ code: result?.code || "",
866
+ changed: result?.changed || false,
867
+ classes: result?.classes || [],
868
+ staticCss
869
+ };
870
+ };
871
+ shouldSkipFile = (filepath) => {
872
+ const SKIP_PATHS = ["node_modules", ".next", ".rspack-dist", ".turbo", "dist/", "out/"];
873
+ const skipExtensions = [".css", ".json", ".md", ".txt", ".yaml", ".yml"];
874
+ for (const p of SKIP_PATHS) {
875
+ if (filepath.includes(p)) return true;
876
+ }
877
+ for (const ext of skipExtensions) {
878
+ if (filepath.endsWith(ext)) return true;
879
+ }
880
+ return false;
881
+ };
882
+ fileToRoute = (filepath) => {
883
+ const normalized = filepath.replace(/\\/g, "/");
884
+ if (normalized.includes("/layout.") || normalized.includes("/loading.") || normalized.includes("/error.")) {
885
+ return "__global";
886
+ }
887
+ const pageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
888
+ if (pageMatch) return `/${pageMatch[1]}`;
889
+ const rootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
890
+ if (rootPage) return "/";
891
+ return null;
892
+ };
893
+ getAllRoutes = () => {
894
+ const native = getNativeBridge();
895
+ if (!native?.analyzeClasses) {
896
+ throw new Error("FATAL: Native binding 'analyzeClasses' is required but not available.");
897
+ }
898
+ return ["/", "__global"];
899
+ };
900
+ getRouteClasses = (_route) => /* @__PURE__ */ new Set();
901
+ registerFileClasses = (_filepath, _classes) => {
902
+ };
903
+ registerGlobalClasses = (_classes) => {
904
+ };
905
+ _incrementalEngineInstance = null;
906
+ getIncrementalEngine = () => {
907
+ if (!_incrementalEngineInstance) {
908
+ _incrementalEngineInstance = new IncrementalEngine();
909
+ }
910
+ return _incrementalEngineInstance;
911
+ };
912
+ resetIncrementalEngine = () => {
913
+ _incrementalEngineInstance = null;
914
+ };
915
+ IncrementalEngine = class {
916
+ compile(source) {
917
+ return transformSource(source);
918
+ }
919
+ };
920
+ getBucketEngine = () => {
921
+ const native = getNativeBridge();
922
+ if (!native?.classifyAndSortClasses) {
923
+ throw new Error("FATAL: Native binding 'classifyAndSortClasses' is required but not available.");
924
+ }
925
+ return {
926
+ add: (className) => className,
927
+ get: (_bucket) => []
928
+ };
929
+ };
930
+ resetBucketEngine = () => {
931
+ };
932
+ classifyNode = (_node) => {
933
+ const native = getNativeBridge();
934
+ if (!native?.classifyAndSortClasses) {
935
+ throw new Error("FATAL: Native binding 'classifyAndSortClasses' is required but not available.");
936
+ }
937
+ return "unknown";
938
+ };
939
+ detectConflicts = (_classes) => {
940
+ const native = getNativeBridge();
941
+ if (!native?.analyzeClassUsage) {
942
+ throw new Error("FATAL: Native binding 'analyzeClassUsage' is required but not available.");
943
+ }
944
+ return [];
945
+ };
946
+ bucketSort = (classes) => {
947
+ return classifyAndSortClasses(classes).map((c) => c.raw ?? c);
948
+ };
949
+ extractTwStateConfigs = (source, filename) => {
950
+ const native = getNativeBridge();
951
+ if (!native?.extractTwStateConfigs) {
952
+ throw new Error("FATAL: Native binding 'extractTwStateConfigs' is required but not available.");
953
+ }
954
+ return native.extractTwStateConfigs(source, filename);
955
+ };
956
+ generateStaticStateCss = (inputs, resolvedCss = null) => {
957
+ const native = getNativeBridge();
958
+ if (!native?.generateStaticStateCss) {
959
+ throw new Error("FATAL: Native binding 'generateStaticStateCss' is required but not available.");
960
+ }
961
+ return native.generateStaticStateCss(inputs, resolvedCss);
962
+ };
963
+ extractAndGenerateStateCss = (source, filename) => {
964
+ const native = getNativeBridge();
965
+ if (!native?.extractAndGenerateStateCss) {
966
+ const configs = extractTwStateConfigs(source, filename);
967
+ if (configs.length === 0) return [];
968
+ return generateStaticStateCss(
969
+ configs.map((c) => ({ tag: c.tag, componentName: c.componentName, statesJson: c.statesJson }))
970
+ );
971
+ }
972
+ return native.extractAndGenerateStateCss(source, filename);
973
+ };
974
+ }
975
+ });
976
+
977
+ // packages/domain/compiler/src/internal.ts
978
+ var internal_exports = {};
979
+ __export(internal_exports, {
980
+ adaptNativeResult: () => adaptNativeResult,
981
+ analyzeClassUsage: () => analyzeClassUsage,
982
+ analyzeClasses: () => analyzeClasses,
983
+ analyzeFile: () => analyzeFile,
984
+ analyzeRsc: () => analyzeRsc,
985
+ analyzeVariantUsage: () => analyzeVariantUsage,
986
+ astExtractClasses: () => astExtractClasses,
987
+ batchExtractClasses: () => batchExtractClasses,
988
+ bucketSort: () => bucketSort,
989
+ buildStyleTag: () => buildStyleTag,
990
+ checkAgainstSafelist: () => checkAgainstSafelist,
991
+ classifyAndSortClasses: () => classifyAndSortClasses,
992
+ classifyNode: () => classifyNode,
993
+ clearCache: () => clearCache,
994
+ compileCssFromClasses: () => compileCssFromClasses,
995
+ compileCssNative: () => compileCssNative,
996
+ compileVariantTable: () => compileVariantTable,
997
+ compileVariants: () => compileVariants,
998
+ detectConflicts: () => detectConflicts,
999
+ diffClassLists: () => diffClassLists,
1000
+ eliminateDeadCss: () => eliminateDeadCss,
1001
+ extractAllClasses: () => extractAllClasses,
1002
+ extractAndGenerateStateCss: () => extractAndGenerateStateCss,
1003
+ extractClassesFromSource: () => extractClassesFromSource,
1004
+ extractComponentUsage: () => extractComponentUsage,
1005
+ extractContainerCssFromSource: () => extractContainerCssFromSource,
1006
+ extractTwStateConfigs: () => extractTwStateConfigs,
1007
+ fileToRoute: () => fileToRoute,
1008
+ findDeadVariants: () => findDeadVariants,
1009
+ generateCssForClasses: () => generateCssForClasses,
1010
+ generateRawCss: () => generateRawCss,
1011
+ generateSafelist: () => generateSafelist,
1012
+ generateStaticStateCss: () => generateStaticStateCss,
1013
+ getAllRoutes: () => getAllRoutes,
1014
+ getBucketEngine: () => getBucketEngine,
1015
+ getCacheStats: () => getCacheStats,
1016
+ getContentPaths: () => getContentPaths,
1017
+ getIncrementalEngine: () => getIncrementalEngine,
1018
+ getNativeBridge: () => getNativeBridge,
1019
+ getRouteClasses: () => getRouteClasses,
1020
+ hasTwUsage: () => hasTwUsage,
1021
+ hoistComponents: () => hoistComponents,
1022
+ injectClientDirective: () => injectClientDirective,
1023
+ injectServerOnlyComment: () => injectServerOnlyComment,
1024
+ isAlreadyTransformed: () => isAlreadyTransformed,
1025
+ loadSafelist: () => loadSafelist,
1026
+ loadTailwindConfig: () => loadTailwindConfig,
1027
+ mergeClassesStatic: () => mergeClassesStatic,
1028
+ mergeCssDeclarations: () => mergeCssDeclarations,
1029
+ normalizeAndDedupClasses: () => normalizeAndDedupClasses,
1030
+ normalizeClasses: () => normalizeClasses,
1031
+ optimizeCss: () => optimizeCss,
1032
+ parseClasses: () => parseClasses,
1033
+ registerFileClasses: () => registerFileClasses,
1034
+ registerGlobalClasses: () => registerGlobalClasses,
1035
+ resetBucketEngine: () => resetBucketEngine,
1036
+ resetIncrementalEngine: () => resetIncrementalEngine,
1037
+ runCssPipeline: () => runCssPipeline,
1038
+ runCssPipelineSync: () => runCssPipelineSync,
1039
+ runElimination: () => runElimination,
1040
+ runLoaderTransform: () => runLoaderTransform,
1041
+ scanProjectUsage: () => scanProjectUsage,
1042
+ shouldProcess: () => shouldProcess,
1043
+ shouldSkipFile: () => shouldSkipFile,
1044
+ transformSource: () => transformSource
1045
+ });
1046
+ var init_internal = __esm({
1047
+ "packages/domain/compiler/src/internal.ts"() {
1048
+ init_src2();
1049
+ init_tailwindEngine();
1050
+ }
1051
+ });
1052
+
1053
+ // packages/presentation/next/src/turbopackLoader.ts
1054
+ init_internal();
1055
+ var _writtenRules = /* @__PURE__ */ new Set();
1056
+ function appendStaticCssToFile(staticCss, safelistPath) {
1057
+ if (!staticCss.trim() || !safelistPath) return;
1058
+ const stateFilePath = path4__namespace.default.join(path4__namespace.default.dirname(safelistPath), "_tw-state-static.css");
1059
+ const newRules = [];
1060
+ for (const chunk of staticCss.split(/(?<=\})\s*/)) {
1061
+ const rule = chunk.trim();
1062
+ if (rule && !_writtenRules.has(rule)) {
1063
+ _writtenRules.add(rule);
1064
+ newRules.push(rule);
1065
+ }
1066
+ }
1067
+ if (newRules.length === 0) return;
1068
+ try {
1069
+ fs4__namespace.default.mkdirSync(path4__namespace.default.dirname(stateFilePath), { recursive: true });
1070
+ if (!fs4__namespace.default.existsSync(stateFilePath)) {
1071
+ fs4__namespace.default.writeFileSync(
1072
+ stateFilePath,
1073
+ `/* _tw-state-static.css \u2014 Auto-generated by tailwind-styled-v4. DO NOT EDIT.
1074
+ * Import di globals.css: @import "./_tw-state-static.css";
1075
+ * Berisi: state CSS (.tw-s-*[data-*="true"]) + container queries (@container .tw-cq-*).
1076
+ */
1077
+
1078
+ `,
1079
+ "utf-8"
1080
+ );
1081
+ }
1082
+ fs4__namespace.default.appendFileSync(stateFilePath, newRules.join("\n") + "\n", "utf-8");
1083
+ } catch {
1084
+ }
1085
+ }
239
1086
  function parseBool(val, fallback = false) {
240
1087
  if (typeof val === "boolean") return val;
241
1088
  if (typeof val === "string") return val === "true" || val === "1";
@@ -271,11 +1118,11 @@ var CYCLE_SENTINEL = "_cycle.txt";
271
1118
  var START_SENTINEL = "_start.txt";
272
1119
  var _workerCache = /* @__PURE__ */ new Map();
273
1120
  function getTwClassesDir(safelistPath) {
274
- return path3__namespace.default.join(path3__namespace.default.dirname(safelistPath), "tw-classes");
1121
+ return path4__namespace.default.join(path4__namespace.default.dirname(safelistPath), "tw-classes");
275
1122
  }
276
1123
  function readSentinel(filePath) {
277
1124
  try {
278
- return fs3__namespace.default.readFileSync(filePath, "utf-8").trim();
1125
+ return fs4__namespace.default.readFileSync(filePath, "utf-8").trim();
279
1126
  } catch {
280
1127
  return "";
281
1128
  }
@@ -285,36 +1132,36 @@ function clearAndMarkCycle(twClassesDir, startId) {
285
1132
  if (_clearLock) return;
286
1133
  _clearLock = true;
287
1134
  try {
288
- if (fs3__namespace.default.existsSync(twClassesDir)) {
1135
+ if (fs4__namespace.default.existsSync(twClassesDir)) {
289
1136
  const tempDir = `${twClassesDir}_clearing_${Date.now()}`;
290
1137
  try {
291
- fs3__namespace.default.renameSync(twClassesDir, tempDir);
292
- fs3__namespace.default.mkdirSync(twClassesDir, { recursive: true });
293
- const startFile = path3__namespace.default.join(tempDir, START_SENTINEL);
294
- if (fs3__namespace.default.existsSync(startFile)) {
295
- fs3__namespace.default.copyFileSync(startFile, path3__namespace.default.join(twClassesDir, START_SENTINEL));
1138
+ fs4__namespace.default.renameSync(twClassesDir, tempDir);
1139
+ fs4__namespace.default.mkdirSync(twClassesDir, { recursive: true });
1140
+ const startFile = path4__namespace.default.join(tempDir, START_SENTINEL);
1141
+ if (fs4__namespace.default.existsSync(startFile)) {
1142
+ fs4__namespace.default.copyFileSync(startFile, path4__namespace.default.join(twClassesDir, START_SENTINEL));
296
1143
  }
297
- const mergedFile = path3__namespace.default.join(tempDir, "_webpack-merged.css");
298
- if (fs3__namespace.default.existsSync(mergedFile)) {
299
- fs3__namespace.default.copyFileSync(mergedFile, path3__namespace.default.join(twClassesDir, "_webpack-merged.css"));
1144
+ const mergedFile = path4__namespace.default.join(tempDir, "_webpack-merged.css");
1145
+ if (fs4__namespace.default.existsSync(mergedFile)) {
1146
+ fs4__namespace.default.copyFileSync(mergedFile, path4__namespace.default.join(twClassesDir, "_webpack-merged.css"));
300
1147
  }
301
- fs3__namespace.default.writeFileSync(path3__namespace.default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
1148
+ fs4__namespace.default.writeFileSync(path4__namespace.default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
302
1149
  _workerCache.set(twClassesDir, startId);
303
- fs3__namespace.default.rmSync(tempDir, { recursive: true, force: true });
1150
+ fs4__namespace.default.rmSync(tempDir, { recursive: true, force: true });
304
1151
  } catch {
305
- for (const file of fs3__namespace.default.readdirSync(twClassesDir)) {
1152
+ for (const file of fs4__namespace.default.readdirSync(twClassesDir)) {
306
1153
  if (file === START_SENTINEL || file === "_webpack-merged.css") continue;
307
1154
  try {
308
- fs3__namespace.default.unlinkSync(path3__namespace.default.join(twClassesDir, file));
1155
+ fs4__namespace.default.unlinkSync(path4__namespace.default.join(twClassesDir, file));
309
1156
  } catch {
310
1157
  }
311
1158
  }
312
- fs3__namespace.default.writeFileSync(path3__namespace.default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
1159
+ fs4__namespace.default.writeFileSync(path4__namespace.default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
313
1160
  _workerCache.set(twClassesDir, startId);
314
1161
  }
315
1162
  } else {
316
- fs3__namespace.default.mkdirSync(twClassesDir, { recursive: true });
317
- fs3__namespace.default.writeFileSync(path3__namespace.default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
1163
+ fs4__namespace.default.mkdirSync(twClassesDir, { recursive: true });
1164
+ fs4__namespace.default.writeFileSync(path4__namespace.default.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
318
1165
  _workerCache.set(twClassesDir, startId);
319
1166
  }
320
1167
  } catch {
@@ -325,41 +1172,41 @@ function clearAndMarkCycle(twClassesDir, startId) {
325
1172
  function getPerFileSafelistPath(safelistDir, resourcePath) {
326
1173
  const normalized = resourcePath.replace(/\\/g, "/");
327
1174
  const slug = normalized.replace(/^.*\/src\//, "").replace(/\.[tj]sx?$/, "").replace(/[^a-zA-Z0-9]/g, "_").slice(0, 80);
328
- return path3__namespace.default.join(safelistDir, `${slug}.css`);
1175
+ return path4__namespace.default.join(safelistDir, `${slug}.css`);
329
1176
  }
330
1177
  function writePerFileSafelist(safelistPath, resourcePath, classes) {
331
1178
  if (!safelistPath || classes.length === 0) return;
332
1179
  try {
333
1180
  const twClassesDir = getTwClassesDir(safelistPath);
334
- const startId = readSentinel(path3__namespace.default.join(twClassesDir, START_SENTINEL));
335
- const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path3__namespace.default.join(twClassesDir, CYCLE_SENTINEL));
1181
+ const startId = readSentinel(path4__namespace.default.join(twClassesDir, START_SENTINEL));
1182
+ const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path4__namespace.default.join(twClassesDir, CYCLE_SENTINEL));
336
1183
  if (startId && cachedCycle !== startId) {
337
1184
  clearAndMarkCycle(twClassesDir, startId);
338
- } else if (!fs3__namespace.default.existsSync(twClassesDir)) {
339
- fs3__namespace.default.mkdirSync(twClassesDir, { recursive: true });
1185
+ } else if (!fs4__namespace.default.existsSync(twClassesDir)) {
1186
+ fs4__namespace.default.mkdirSync(twClassesDir, { recursive: true });
340
1187
  }
341
1188
  const outPath = getPerFileSafelistPath(twClassesDir, resourcePath);
342
1189
  const sorted = [...new Set(classes)].sort();
343
1190
  const css = [
344
- `/* tw-safelist: ${path3__namespace.default.basename(resourcePath)} \u2014 auto-generated */`,
1191
+ `/* tw-safelist: ${path4__namespace.default.basename(resourcePath)} \u2014 auto-generated */`,
345
1192
  "@layer utilities {",
346
1193
  sorted.map((cls) => `.${cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1")} {}`).join("\n"),
347
1194
  "}"
348
1195
  ].join("\n");
349
1196
  try {
350
- if (fs3__namespace.default.readFileSync(outPath, "utf-8") === css) return;
1197
+ if (fs4__namespace.default.readFileSync(outPath, "utf-8") === css) return;
351
1198
  } catch {
352
1199
  }
353
1200
  const tmpPath = `${outPath}.tmp`;
354
1201
  try {
355
- fs3__namespace.default.writeFileSync(tmpPath, css, "utf-8");
356
- fs3__namespace.default.renameSync(tmpPath, outPath);
1202
+ fs4__namespace.default.writeFileSync(tmpPath, css, "utf-8");
1203
+ fs4__namespace.default.renameSync(tmpPath, outPath);
357
1204
  } catch {
358
1205
  try {
359
- fs3__namespace.default.unlinkSync(tmpPath);
1206
+ fs4__namespace.default.unlinkSync(tmpPath);
360
1207
  } catch {
361
1208
  }
362
- fs3__namespace.default.writeFileSync(outPath, css, "utf-8");
1209
+ fs4__namespace.default.writeFileSync(outPath, css, "utf-8");
363
1210
  }
364
1211
  } catch {
365
1212
  }
@@ -369,7 +1216,7 @@ function turbopackLoader(source, options = {}) {
369
1216
  const router = detectRouter(this.resourcePath);
370
1217
  const nextMajor = parseNum(options.nextMajor);
371
1218
  const debug = parseBool(options.debug);
372
- const filename = path3__namespace.default.basename(this.resourcePath);
1219
+ const filename = path4__namespace.default.basename(this.resourcePath);
373
1220
  const effective = {
374
1221
  addDataAttr: parseBool(options.addDataAttr),
375
1222
  // App Router: selalu auto-detect client boundary
@@ -384,22 +1231,42 @@ function turbopackLoader(source, options = {}) {
384
1231
  console.debug(`[tw-loader] ${filename}: router=${router} nextMajor=${nextMajor ?? "unknown"}`);
385
1232
  }
386
1233
  const { directive, stripped } = extractDirective(source);
1234
+ let processedSource = stripped;
1235
+ try {
1236
+ const compilerMod = (init_internal(), __toCommonJS(internal_exports));
1237
+ if (typeof compilerMod?.injectStateHash === "function" && stripped.includes("states:")) {
1238
+ const hashResult = compilerMod.injectStateHash(stripped, this.resourcePath);
1239
+ if (hashResult.changed) {
1240
+ processedSource = hashResult.code;
1241
+ if (debug) {
1242
+ console.debug(`[tw-loader] ${filename}: injected __hash for ${hashResult.injectedCount} component(s)`);
1243
+ }
1244
+ }
1245
+ }
1246
+ } catch {
1247
+ }
387
1248
  try {
388
1249
  const output = runLoaderTransform({
389
1250
  filepath: this.resourcePath,
390
- source: stripped,
1251
+ source: processedSource,
391
1252
  options: effective
392
1253
  });
393
1254
  if (!output.changed) {
394
1255
  if (output.classes.length > 0) {
395
1256
  writePerFileSafelist(options.safelistPath, this.resourcePath, output.classes);
396
1257
  }
1258
+ if (output.staticCss && options.safelistPath) {
1259
+ appendStaticCssToFile(output.staticCss, options.safelistPath);
1260
+ }
397
1261
  return source;
398
1262
  }
399
1263
  if (output.classes.length > 0) {
400
1264
  registerFileClasses(this.resourcePath, output.classes);
401
1265
  writePerFileSafelist(options.safelistPath, this.resourcePath, output.classes);
402
1266
  }
1267
+ if (output.staticCss && options.safelistPath) {
1268
+ appendStaticCssToFile(output.staticCss, options.safelistPath);
1269
+ }
403
1270
  if (!directive) return output.code;
404
1271
  const clean = output.code.replace(/^\s*["'](use client|use server)["']\s*;?\s*\n?/, "");
405
1272
  return directive + clean;