tailwind-styled-v4 5.1.16 → 5.1.17

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 (59) hide show
  1. package/dist/atomic.js +16 -4
  2. package/dist/atomic.js.map +1 -1
  3. package/dist/atomic.mjs +13 -2
  4. package/dist/atomic.mjs.map +1 -1
  5. package/dist/cli.js +80 -68
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cli.mjs +77 -66
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/compiler.d.mts +84 -4
  10. package/dist/compiler.d.ts +84 -4
  11. package/dist/compiler.js +245 -15
  12. package/dist/compiler.js.map +1 -1
  13. package/dist/compiler.mjs +240 -14
  14. package/dist/compiler.mjs.map +1 -1
  15. package/dist/engine.js +209 -167
  16. package/dist/engine.js.map +1 -1
  17. package/dist/engine.mjs +200 -159
  18. package/dist/engine.mjs.map +1 -1
  19. package/dist/index.browser.mjs +1 -1
  20. package/dist/index.browser.mjs.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +1 -1
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/next.d.mts +16 -0
  26. package/dist/next.d.ts +16 -0
  27. package/dist/next.js +458 -158
  28. package/dist/next.js.map +1 -1
  29. package/dist/next.mjs +454 -154
  30. package/dist/next.mjs.map +1 -1
  31. package/dist/runtime.js +1 -1
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/runtime.mjs +1 -1
  34. package/dist/runtime.mjs.map +1 -1
  35. package/dist/shared.js +106 -64
  36. package/dist/shared.js.map +1 -1
  37. package/dist/shared.mjs +101 -60
  38. package/dist/shared.mjs.map +1 -1
  39. package/dist/theme.js +1 -1
  40. package/dist/theme.js.map +1 -1
  41. package/dist/theme.mjs +1 -1
  42. package/dist/theme.mjs.map +1 -1
  43. package/dist/turbopackLoader.js +94 -52
  44. package/dist/turbopackLoader.js.map +1 -1
  45. package/dist/turbopackLoader.mjs +92 -51
  46. package/dist/turbopackLoader.mjs.map +1 -1
  47. package/dist/tw.js +80 -68
  48. package/dist/tw.js.map +1 -1
  49. package/dist/tw.mjs +77 -66
  50. package/dist/tw.mjs.map +1 -1
  51. package/dist/vite.js +172 -130
  52. package/dist/vite.js.map +1 -1
  53. package/dist/vite.mjs +166 -125
  54. package/dist/vite.mjs.map +1 -1
  55. package/dist/webpackLoader.js +28 -10
  56. package/dist/webpackLoader.js.map +1 -1
  57. package/dist/webpackLoader.mjs +26 -9
  58. package/dist/webpackLoader.mjs.map +1 -1
  59. package/package.json +1 -1
@@ -182,7 +182,7 @@ var init_nativeBridge = __esm({
182
182
  "use strict";
183
183
  init_esm_shims();
184
184
  init_src();
185
- _loadNative = (path6) => __require(path6);
185
+ _loadNative = (path7) => __require(path7);
186
186
  log = (...args) => {
187
187
  if (process.env.DEBUG?.includes("compiler:native")) {
188
188
  console.log("[compiler:native]", ...args);
@@ -2006,9 +2006,19 @@ var init_watch = __esm({
2006
2006
  }
2007
2007
  });
2008
2008
 
2009
- // packages/domain/compiler/src/index.ts
2009
+ // packages/domain/compiler/src/routeGraph.ts
2010
2010
  import fs3 from "fs";
2011
2011
  import path4 from "path";
2012
+ var init_routeGraph = __esm({
2013
+ "packages/domain/compiler/src/routeGraph.ts"() {
2014
+ "use strict";
2015
+ init_esm_shims();
2016
+ }
2017
+ });
2018
+
2019
+ // packages/domain/compiler/src/index.ts
2020
+ import fs4 from "fs";
2021
+ import path5 from "path";
2012
2022
  import { createRequire as createRequire5 } from "module";
2013
2023
  function _layoutClassesToCss(classes) {
2014
2024
  const native = getNativeBridge();
@@ -2044,7 +2054,7 @@ function extractContainerCssFromSource(source) {
2044
2054
  }
2045
2055
  return rules.join("\n");
2046
2056
  }
2047
- var _require3, transformSource, hasTwUsage, isAlreadyTransformed, shouldProcess, compileCssFromClasses, buildStyleTag, generateCssForClasses, eliminateDeadCss, findDeadVariants, runElimination, scanProjectUsage, generateSafelist, loadSafelist, loadTailwindConfig, getContentPaths, _CONTAINER_BREAKPOINTS, runLoaderTransform, shouldSkipFile, fileToRoute, getAllRoutes, getRouteClasses, registerFileClasses, registerGlobalClasses, _incrementalEngineInstance, getIncrementalEngine, resetIncrementalEngine, IncrementalEngine, getBucketEngine, resetBucketEngine, classifyNode, detectConflicts, bucketSort, analyzeFile, analyzeVariantUsage, injectClientDirective, injectServerOnlyComment, analyzeClasses, extractTwStateConfigs, generateStaticStateCss, extractAndGenerateStateCss;
2057
+ var _require3, transformSource, hasTwUsage, isAlreadyTransformed, shouldProcess, compileCssFromClasses, buildStyleTag, generateCssForClasses, eliminateDeadCss, findDeadVariants, runElimination, scanProjectUsage, generateSafelist, loadSafelist, loadTailwindConfig, getContentPaths, _CONTAINER_BREAKPOINTS, runLoaderTransform, shouldSkipFile, fileToRoute, getAllRoutes, _fileClassesMap, _globalClasses, getRouteClasses, getAllRegisteredClasses, registerFileClasses, registerGlobalClasses, resetRouteClassRegistry, _incrementalEngineInstance, getIncrementalEngine, resetIncrementalEngine, IncrementalEngine, getBucketEngine, resetBucketEngine, classifyNode, detectConflicts, bucketSort, analyzeFile, analyzeVariantUsage, injectClientDirective, injectServerOnlyComment, analyzeClasses, extractTwStateConfigs, generateStaticStateCss, extractAndGenerateStateCss;
2048
2058
  var init_src2 = __esm({
2049
2059
  "packages/domain/compiler/src/index.ts"() {
2050
2060
  "use strict";
@@ -2056,6 +2066,7 @@ var init_src2 = __esm({
2056
2066
  init_cache();
2057
2067
  init_redis();
2058
2068
  init_watch();
2069
+ init_routeGraph();
2059
2070
  _require3 = createRequire5(
2060
2071
  typeof __require !== "undefined" ? typeof __filename !== "undefined" ? `file://${__filename}` : "file://unknown" : import.meta.url
2061
2072
  );
@@ -2150,7 +2161,7 @@ var init_src2 = __esm({
2150
2161
  };
2151
2162
  scanProjectUsage = (dirs, cwd) => {
2152
2163
  const { batchExtractClasses: batchExtractClasses2 } = _require3("./parser");
2153
- const files = dirs.map((dir) => path4.resolve(cwd, dir));
2164
+ const files = dirs.map((dir) => path5.resolve(cwd, dir));
2154
2165
  const results = batchExtractClasses2(files) || [];
2155
2166
  const combined = {};
2156
2167
  for (const result of results) {
@@ -2167,13 +2178,13 @@ var init_src2 = __esm({
2167
2178
  const classes = scanProjectUsage(scanDirs, cwd || process.cwd());
2168
2179
  const allClasses = Object.keys(classes).sort();
2169
2180
  if (outputPath) {
2170
- fs3.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2));
2181
+ fs4.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2));
2171
2182
  }
2172
2183
  return allClasses;
2173
2184
  };
2174
2185
  loadSafelist = (safelistPath) => {
2175
2186
  try {
2176
- const content = fs3.readFileSync(safelistPath, "utf-8");
2187
+ const content = fs4.readFileSync(safelistPath, "utf-8");
2177
2188
  return JSON.parse(content);
2178
2189
  } catch {
2179
2190
  return [];
@@ -2187,8 +2198,8 @@ var init_src2 = __esm({
2187
2198
  "tailwind.config.cjs"
2188
2199
  ];
2189
2200
  for (const file of configFiles) {
2190
- const fullPath = path4.join(cwd, file);
2191
- if (fs3.existsSync(fullPath)) {
2201
+ const fullPath = path5.join(cwd, file);
2202
+ if (fs4.existsSync(fullPath)) {
2192
2203
  const mod = __require(fullPath);
2193
2204
  return mod.default || mod;
2194
2205
  }
@@ -2198,9 +2209,9 @@ var init_src2 = __esm({
2198
2209
  getContentPaths = (cwd = process.cwd()) => {
2199
2210
  return {
2200
2211
  content: [
2201
- path4.join(cwd, "src/**/*.{js,ts,jsx,tsx}"),
2202
- path4.join(cwd, "app/**/*.{js,ts,jsx,tsx}"),
2203
- path4.join(cwd, "pages/**/*.{js,ts,jsx,tsx}")
2212
+ path5.join(cwd, "src/**/*.{js,ts,jsx,tsx}"),
2213
+ path5.join(cwd, "app/**/*.{js,ts,jsx,tsx}"),
2214
+ path5.join(cwd, "pages/**/*.{js,ts,jsx,tsx}")
2204
2215
  ]
2205
2216
  };
2206
2217
  };
@@ -2271,10 +2282,38 @@ var init_src2 = __esm({
2271
2282
  }
2272
2283
  return ["/", "__global"];
2273
2284
  };
2274
- getRouteClasses = (_route) => /* @__PURE__ */ new Set();
2275
- registerFileClasses = (_filepath, _classes) => {
2285
+ _fileClassesMap = /* @__PURE__ */ new Map();
2286
+ _globalClasses = /* @__PURE__ */ new Set();
2287
+ getRouteClasses = (route) => {
2288
+ const result = /* @__PURE__ */ new Set();
2289
+ for (const [filepath, classes] of _fileClassesMap) {
2290
+ const fileRoute = fileToRoute(filepath) ?? "__global";
2291
+ if (fileRoute === route) {
2292
+ for (const cls of classes) result.add(cls);
2293
+ }
2294
+ }
2295
+ return result;
2296
+ };
2297
+ getAllRegisteredClasses = () => {
2298
+ const result = new Set(_globalClasses);
2299
+ for (const classes of _fileClassesMap.values()) {
2300
+ for (const cls of classes) result.add(cls);
2301
+ }
2302
+ return result;
2303
+ };
2304
+ registerFileClasses = (filepath, classes) => {
2305
+ if (!classes || classes.length === 0) {
2306
+ _fileClassesMap.delete(filepath);
2307
+ return;
2308
+ }
2309
+ _fileClassesMap.set(filepath, new Set(classes));
2310
+ };
2311
+ registerGlobalClasses = (classes) => {
2312
+ for (const cls of classes) _globalClasses.add(cls);
2276
2313
  };
2277
- registerGlobalClasses = (_classes) => {
2314
+ resetRouteClassRegistry = () => {
2315
+ _fileClassesMap.clear();
2316
+ _globalClasses.clear();
2278
2317
  };
2279
2318
  _incrementalEngineInstance = null;
2280
2319
  getIncrementalEngine = () => {
@@ -2465,6 +2504,7 @@ __export(internal_exports, {
2465
2504
  generateStaticStateCss: () => generateStaticStateCss,
2466
2505
  generateStaticStateCssNative: () => generateStaticStateCssNative,
2467
2506
  generateSubComponentTypes: () => generateSubComponentTypes,
2507
+ getAllRegisteredClasses: () => getAllRegisteredClasses,
2468
2508
  getAllRoutes: () => getAllRoutes,
2469
2509
  getBucketEngine: () => getBucketEngine,
2470
2510
  getCacheOptimizationHints: () => getCacheOptimizationHints,
@@ -2567,6 +2607,7 @@ __export(internal_exports, {
2567
2607
  resetIncrementalEngine: () => resetIncrementalEngine,
2568
2608
  resetMemoryStats: () => resetMemoryStats,
2569
2609
  resetResolverPoolStats: () => resetResolverPoolStats,
2610
+ resetRouteClassRegistry: () => resetRouteClassRegistry,
2570
2611
  resolveCascade: () => resolveCascade,
2571
2612
  resolveClassNames: () => resolveClassNames,
2572
2613
  resolveColorCached: () => resolveColorCached,
@@ -2630,12 +2671,12 @@ var init_internal = __esm({
2630
2671
  // packages/presentation/next/src/turbopackLoader.ts
2631
2672
  init_esm_shims();
2632
2673
  init_internal();
2633
- import fs4 from "fs";
2634
- import path5 from "path";
2674
+ import fs5 from "fs";
2675
+ import path6 from "path";
2635
2676
  var _writtenRules = /* @__PURE__ */ new Set();
2636
2677
  function appendStaticCssToFile(staticCss, safelistPath) {
2637
2678
  if (!staticCss.trim() || !safelistPath) return;
2638
- const stateFilePath = path5.join(path5.dirname(safelistPath), "_tw-state-static.css");
2679
+ const stateFilePath = path6.join(path6.dirname(safelistPath), "_tw-state-static.css");
2639
2680
  const newRules = [];
2640
2681
  for (const chunk of staticCss.split(/(?<=\})\s*/)) {
2641
2682
  const rule = chunk.trim();
@@ -2646,9 +2687,9 @@ function appendStaticCssToFile(staticCss, safelistPath) {
2646
2687
  }
2647
2688
  if (newRules.length === 0) return;
2648
2689
  try {
2649
- fs4.mkdirSync(path5.dirname(stateFilePath), { recursive: true });
2650
- if (!fs4.existsSync(stateFilePath)) {
2651
- fs4.writeFileSync(
2690
+ fs5.mkdirSync(path6.dirname(stateFilePath), { recursive: true });
2691
+ if (!fs5.existsSync(stateFilePath)) {
2692
+ fs5.writeFileSync(
2652
2693
  stateFilePath,
2653
2694
  `/* _tw-state-static.css \u2014 Auto-generated by tailwind-styled-v4. DO NOT EDIT.
2654
2695
  * Import di globals.css: @import "./_tw-state-static.css";
@@ -2659,7 +2700,7 @@ function appendStaticCssToFile(staticCss, safelistPath) {
2659
2700
  "utf-8"
2660
2701
  );
2661
2702
  }
2662
- fs4.appendFileSync(stateFilePath, newRules.join("\n") + "\n", "utf-8");
2703
+ fs5.appendFileSync(stateFilePath, newRules.join("\n") + "\n", "utf-8");
2663
2704
  } catch {
2664
2705
  }
2665
2706
  }
@@ -2698,11 +2739,11 @@ var CYCLE_SENTINEL = "_cycle.txt";
2698
2739
  var START_SENTINEL = "_start.txt";
2699
2740
  var _workerCache = /* @__PURE__ */ new Map();
2700
2741
  function getTwClassesDir(safelistPath) {
2701
- return path5.join(path5.dirname(safelistPath), "tw-classes");
2742
+ return path6.join(path6.dirname(safelistPath), "tw-classes");
2702
2743
  }
2703
2744
  function readSentinel(filePath) {
2704
2745
  try {
2705
- return fs4.readFileSync(filePath, "utf-8").trim();
2746
+ return fs5.readFileSync(filePath, "utf-8").trim();
2706
2747
  } catch {
2707
2748
  return "";
2708
2749
  }
@@ -2712,36 +2753,36 @@ function clearAndMarkCycle(twClassesDir, startId) {
2712
2753
  if (_clearLock) return;
2713
2754
  _clearLock = true;
2714
2755
  try {
2715
- if (fs4.existsSync(twClassesDir)) {
2756
+ if (fs5.existsSync(twClassesDir)) {
2716
2757
  const tempDir = `${twClassesDir}_clearing_${Date.now()}`;
2717
2758
  try {
2718
- fs4.renameSync(twClassesDir, tempDir);
2719
- fs4.mkdirSync(twClassesDir, { recursive: true });
2720
- const startFile = path5.join(tempDir, START_SENTINEL);
2721
- if (fs4.existsSync(startFile)) {
2722
- fs4.copyFileSync(startFile, path5.join(twClassesDir, START_SENTINEL));
2759
+ fs5.renameSync(twClassesDir, tempDir);
2760
+ fs5.mkdirSync(twClassesDir, { recursive: true });
2761
+ const startFile = path6.join(tempDir, START_SENTINEL);
2762
+ if (fs5.existsSync(startFile)) {
2763
+ fs5.copyFileSync(startFile, path6.join(twClassesDir, START_SENTINEL));
2723
2764
  }
2724
- const mergedFile = path5.join(tempDir, "_webpack-merged.css");
2725
- if (fs4.existsSync(mergedFile)) {
2726
- fs4.copyFileSync(mergedFile, path5.join(twClassesDir, "_webpack-merged.css"));
2765
+ const mergedFile = path6.join(tempDir, "_webpack-merged.css");
2766
+ if (fs5.existsSync(mergedFile)) {
2767
+ fs5.copyFileSync(mergedFile, path6.join(twClassesDir, "_webpack-merged.css"));
2727
2768
  }
2728
- fs4.writeFileSync(path5.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
2769
+ fs5.writeFileSync(path6.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
2729
2770
  _workerCache.set(twClassesDir, startId);
2730
- fs4.rmSync(tempDir, { recursive: true, force: true });
2771
+ fs5.rmSync(tempDir, { recursive: true, force: true });
2731
2772
  } catch {
2732
- for (const file of fs4.readdirSync(twClassesDir)) {
2773
+ for (const file of fs5.readdirSync(twClassesDir)) {
2733
2774
  if (file === START_SENTINEL || file === "_webpack-merged.css") continue;
2734
2775
  try {
2735
- fs4.unlinkSync(path5.join(twClassesDir, file));
2776
+ fs5.unlinkSync(path6.join(twClassesDir, file));
2736
2777
  } catch {
2737
2778
  }
2738
2779
  }
2739
- fs4.writeFileSync(path5.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
2780
+ fs5.writeFileSync(path6.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
2740
2781
  _workerCache.set(twClassesDir, startId);
2741
2782
  }
2742
2783
  } else {
2743
- fs4.mkdirSync(twClassesDir, { recursive: true });
2744
- fs4.writeFileSync(path5.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
2784
+ fs5.mkdirSync(twClassesDir, { recursive: true });
2785
+ fs5.writeFileSync(path6.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
2745
2786
  _workerCache.set(twClassesDir, startId);
2746
2787
  }
2747
2788
  } catch {
@@ -2752,41 +2793,41 @@ function clearAndMarkCycle(twClassesDir, startId) {
2752
2793
  function getPerFileSafelistPath(safelistDir, resourcePath) {
2753
2794
  const normalized = resourcePath.replace(/\\/g, "/");
2754
2795
  const slug = normalized.replace(/^.*\/src\//, "").replace(/\.[tj]sx?$/, "").replace(/[^a-zA-Z0-9]/g, "_").slice(0, 80);
2755
- return path5.join(safelistDir, `${slug}.css`);
2796
+ return path6.join(safelistDir, `${slug}.css`);
2756
2797
  }
2757
2798
  function writePerFileSafelist(safelistPath, resourcePath, classes) {
2758
2799
  if (!safelistPath || classes.length === 0) return;
2759
2800
  try {
2760
2801
  const twClassesDir = getTwClassesDir(safelistPath);
2761
- const startId = readSentinel(path5.join(twClassesDir, START_SENTINEL));
2762
- const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path5.join(twClassesDir, CYCLE_SENTINEL));
2802
+ const startId = readSentinel(path6.join(twClassesDir, START_SENTINEL));
2803
+ const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path6.join(twClassesDir, CYCLE_SENTINEL));
2763
2804
  if (startId && cachedCycle !== startId) {
2764
2805
  clearAndMarkCycle(twClassesDir, startId);
2765
- } else if (!fs4.existsSync(twClassesDir)) {
2766
- fs4.mkdirSync(twClassesDir, { recursive: true });
2806
+ } else if (!fs5.existsSync(twClassesDir)) {
2807
+ fs5.mkdirSync(twClassesDir, { recursive: true });
2767
2808
  }
2768
2809
  const outPath = getPerFileSafelistPath(twClassesDir, resourcePath);
2769
2810
  const sorted = [...new Set(classes)].sort();
2770
2811
  const css = [
2771
- `/* tw-safelist: ${path5.basename(resourcePath)} \u2014 auto-generated */`,
2812
+ `/* tw-safelist: ${path6.basename(resourcePath)} \u2014 auto-generated */`,
2772
2813
  "@layer utilities {",
2773
2814
  sorted.map((cls) => `.${cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1")} {}`).join("\n"),
2774
2815
  "}"
2775
2816
  ].join("\n");
2776
2817
  try {
2777
- if (fs4.readFileSync(outPath, "utf-8") === css) return;
2818
+ if (fs5.readFileSync(outPath, "utf-8") === css) return;
2778
2819
  } catch {
2779
2820
  }
2780
2821
  const tmpPath = `${outPath}.tmp`;
2781
2822
  try {
2782
- fs4.writeFileSync(tmpPath, css, "utf-8");
2783
- fs4.renameSync(tmpPath, outPath);
2823
+ fs5.writeFileSync(tmpPath, css, "utf-8");
2824
+ fs5.renameSync(tmpPath, outPath);
2784
2825
  } catch {
2785
2826
  try {
2786
- fs4.unlinkSync(tmpPath);
2827
+ fs5.unlinkSync(tmpPath);
2787
2828
  } catch {
2788
2829
  }
2789
- fs4.writeFileSync(outPath, css, "utf-8");
2830
+ fs5.writeFileSync(outPath, css, "utf-8");
2790
2831
  }
2791
2832
  } catch {
2792
2833
  }
@@ -2800,7 +2841,7 @@ function turbopackLoader(source, options = {}) {
2800
2841
  const router = detectRouter(this.resourcePath);
2801
2842
  const nextMajor = parseNum(options.nextMajor);
2802
2843
  const debug = parseBool(options.debug);
2803
- const filename = path5.basename(this.resourcePath);
2844
+ const filename = path6.basename(this.resourcePath);
2804
2845
  const effective = {
2805
2846
  addDataAttr: parseBool(options.addDataAttr),
2806
2847
  // App Router: selalu auto-detect client boundary