tailwind-styled-v4 5.0.7 → 5.0.9

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 (46) hide show
  1. package/CHANGELOG.md +184 -410
  2. package/README.md +45 -15
  3. package/dist/cli.js +62 -52
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.mjs +62 -52
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/compiler.d.mts +8 -3
  8. package/dist/compiler.d.ts +8 -3
  9. package/dist/compiler.js +214 -127
  10. package/dist/compiler.js.map +1 -1
  11. package/dist/compiler.mjs +195 -103
  12. package/dist/compiler.mjs.map +1 -1
  13. package/dist/engine.js +146 -66
  14. package/dist/engine.js.map +1 -1
  15. package/dist/engine.mjs +146 -66
  16. package/dist/engine.mjs.map +1 -1
  17. package/dist/index.d.mts +26 -8
  18. package/dist/index.d.ts +26 -8
  19. package/dist/index.js +72 -19
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +72 -19
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/next.d.mts +12 -40
  24. package/dist/next.d.ts +12 -40
  25. package/dist/next.js +27 -320
  26. package/dist/next.js.map +1 -1
  27. package/dist/next.mjs +27 -320
  28. package/dist/next.mjs.map +1 -1
  29. package/dist/turbopackLoader.js +137 -88
  30. package/dist/turbopackLoader.js.map +1 -1
  31. package/dist/turbopackLoader.mjs +137 -88
  32. package/dist/turbopackLoader.mjs.map +1 -1
  33. package/dist/tw.js +62 -52
  34. package/dist/tw.js.map +1 -1
  35. package/dist/tw.mjs +62 -52
  36. package/dist/tw.mjs.map +1 -1
  37. package/dist/vite.js +146 -66
  38. package/dist/vite.js.map +1 -1
  39. package/dist/vite.mjs +146 -66
  40. package/dist/vite.mjs.map +1 -1
  41. package/dist/webpackLoader.js +92 -83
  42. package/dist/webpackLoader.js.map +1 -1
  43. package/dist/webpackLoader.mjs +92 -83
  44. package/dist/webpackLoader.mjs.map +1 -1
  45. package/native/tailwind-styled-native.node +0 -0
  46. package/package.json +3 -3
package/dist/compiler.mjs CHANGED
@@ -1,16 +1,23 @@
1
1
  import { createRequire } from 'module';
2
2
 
3
3
  /* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
6
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
7
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
8
  }) : x)(function(x) {
7
9
  if (typeof require !== "undefined") return require.apply(this, arguments);
8
10
  throw Error('Dynamic require of "' + x + '" is not supported');
9
11
  });
12
+ var __esm = (fn, res) => function __init() {
13
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
14
+ };
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
10
19
 
11
20
  // packages/domain/shared/src/native-resolution.ts
12
- var isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
13
- var nodeModuleRef = null;
14
21
  function getNodeModuleRef() {
15
22
  if (isBrowser) return null;
16
23
  if (nodeModuleRef !== null) return nodeModuleRef;
@@ -23,9 +30,6 @@ function getNodeModuleRef() {
23
30
  return null;
24
31
  }
25
32
  }
26
- var _nodeFs = null;
27
- var _nodePath = null;
28
- var _require = null;
29
33
  function getNodeFs() {
30
34
  if (isBrowser) return { existsSync: () => false };
31
35
  const nodeRequire = getNodeModuleRef();
@@ -51,14 +55,6 @@ function getRequire(_importMetaUrl) {
51
55
  if (!_require) _require = nodeRequire.createRequire(_importMetaUrl);
52
56
  return _require;
53
57
  }
54
- var PLATFORM_MAP = {
55
- "linux-x64": ["@tailwind-styled/native-linux-x64"],
56
- "linux-arm64": ["@tailwind-styled/native-linux-arm64"],
57
- "darwin-x64": ["@tailwind-styled/native-darwin-x64"],
58
- "darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
59
- "win32-x64": ["@tailwind-styled/native-win32-x64"],
60
- "win32-arm64": ["@tailwind-styled/native-win32-arm64"]
61
- };
62
58
  function platformKey() {
63
59
  if (isBrowser) return "browser";
64
60
  return `${process.platform}-${process.arch}`;
@@ -112,10 +108,26 @@ function resolveNativeBinary(runtimeDir) {
112
108
  }
113
109
  return { path: null, source: "not-found", platform, tried };
114
110
  }
111
+ var isBrowser, nodeModuleRef, _nodeFs, _nodePath, _require, PLATFORM_MAP;
112
+ var init_native_resolution = __esm({
113
+ "packages/domain/shared/src/native-resolution.ts"() {
114
+ isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
115
+ nodeModuleRef = null;
116
+ _nodeFs = null;
117
+ _nodePath = null;
118
+ _require = null;
119
+ PLATFORM_MAP = {
120
+ "linux-x64": ["@tailwind-styled/native-linux-x64"],
121
+ "linux-arm64": ["@tailwind-styled/native-linux-arm64"],
122
+ "darwin-x64": ["@tailwind-styled/native-darwin-x64"],
123
+ "darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
124
+ "win32-x64": ["@tailwind-styled/native-win32-x64"],
125
+ "win32-arm64": ["@tailwind-styled/native-win32-arm64"]
126
+ };
127
+ }
128
+ });
115
129
 
116
130
  // packages/domain/shared/src/index.ts
117
- var isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
118
- var nodeModuleRef2 = null;
119
131
  function getNodeModuleRef2() {
120
132
  if (isBrowser2) return null;
121
133
  if (nodeModuleRef2 !== null) return nodeModuleRef2;
@@ -128,7 +140,6 @@ function getNodeModuleRef2() {
128
140
  return null;
129
141
  }
130
142
  }
131
- var _nodeUrl = null;
132
143
  function getNodeUrl() {
133
144
  if (isBrowser2) throw new Error("node:url not available in browser");
134
145
  const nodeRequire = getNodeModuleRef2();
@@ -146,7 +157,6 @@ function getRequire2() {
146
157
  });
147
158
  return nodeRequire.createRequire(import.meta.url);
148
159
  }
149
- getRequire2();
150
160
  function resolveRuntimeDir(dir, importMetaUrl) {
151
161
  if (isBrowser2) return "";
152
162
  try {
@@ -155,72 +165,175 @@ function resolveRuntimeDir(dir, importMetaUrl) {
155
165
  return process.cwd();
156
166
  }
157
167
  }
158
- var log = (...args) => {
159
- if (process.env.DEBUG?.includes("compiler:native")) {
160
- console.log("[compiler:native]", ...args);
161
- }
162
- };
163
- var NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/compiler v5] Native binding is required but not available.\nThis package requires native Rust bindings. There is no JavaScript fallback.\nPlease ensure:\n 1. The native module is properly installed\n 2. You have run: npm run build:rust (or use prebuilt binary)\n\nFor help, see: https://tailwind-styled.dev/docs/install";
164
- var nativeBridge = null;
165
- var bridgeLoadAttempted = false;
166
- var bridgeLoadError = null;
167
- var isValidNativeBridge = (mod) => {
168
- const m = mod;
169
- return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
170
- };
171
- var getNativeBridge = () => {
172
- if (nativeBridge) {
173
- return nativeBridge;
174
- }
175
- if (bridgeLoadAttempted) {
176
- if (bridgeLoadError) {
177
- throw bridgeLoadError;
178
- }
179
- throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
168
+ var isBrowser2, nodeModuleRef2, _nodeUrl;
169
+ var init_src = __esm({
170
+ "packages/domain/shared/src/index.ts"() {
171
+ init_native_resolution();
172
+ isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
173
+ nodeModuleRef2 = null;
174
+ _nodeUrl = null;
175
+ getRequire2();
180
176
  }
181
- bridgeLoadAttempted = true;
182
- try {
183
- const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
184
- const require2 = createRequire(import.meta.url);
185
- const result = resolveNativeBinary(runtimeDir);
186
- if (result.path && result.path.endsWith(".node")) {
177
+ });
178
+ var log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge, resetNativeBridgeCache, adaptNativeResult;
179
+ var init_nativeBridge = __esm({
180
+ "packages/domain/compiler/src/nativeBridge.ts"() {
181
+ init_src();
182
+ log = (...args) => {
183
+ if (process.env.DEBUG?.includes("compiler:native")) {
184
+ console.log("[compiler:native]", ...args);
185
+ }
186
+ };
187
+ NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/compiler v5] Native binding is required but not available.\nThis package requires native Rust bindings. There is no JavaScript fallback.\nPlease ensure:\n 1. The native module is properly installed\n 2. You have run: npm run build:rust (or use prebuilt binary)\n\nFor help, see: https://tailwind-styled.dev/docs/install";
188
+ nativeBridge = null;
189
+ bridgeLoadAttempted = false;
190
+ bridgeLoadError = null;
191
+ isValidNativeBridge = (mod) => {
192
+ const m = mod;
193
+ return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
194
+ };
195
+ getNativeBridge = () => {
196
+ if (nativeBridge) {
197
+ return nativeBridge;
198
+ }
199
+ if (bridgeLoadAttempted) {
200
+ if (bridgeLoadError) {
201
+ throw bridgeLoadError;
202
+ }
203
+ throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
204
+ }
205
+ bridgeLoadAttempted = true;
187
206
  try {
188
- const binding = require2(result.path);
189
- if (isValidNativeBridge(binding)) {
190
- nativeBridge = binding;
191
- log("Native bridge loaded successfully from:", result.path);
192
- return nativeBridge;
207
+ const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
208
+ const require3 = createRequire(import.meta.url);
209
+ const result = resolveNativeBinary(runtimeDir);
210
+ if (result.path && result.path.endsWith(".node")) {
211
+ try {
212
+ const binding = require3(result.path);
213
+ if (isValidNativeBridge(binding)) {
214
+ nativeBridge = binding;
215
+ log("Native bridge loaded successfully from:", result.path);
216
+ return nativeBridge;
217
+ }
218
+ } catch (e) {
219
+ log("Failed to require native binding:", e);
220
+ }
193
221
  }
194
- } catch (e) {
195
- log("Failed to require native binding:", e);
222
+ throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
223
+
224
+ Tried paths: ${result.tried.join("\n")}`);
225
+ } catch (err) {
226
+ bridgeLoadError = err instanceof Error ? err : new Error(String(err));
227
+ log("Failed to load native bridge:", bridgeLoadError.message);
228
+ throw bridgeLoadError;
229
+ }
230
+ };
231
+ resetNativeBridgeCache = () => {
232
+ nativeBridge = null;
233
+ bridgeLoadAttempted = false;
234
+ bridgeLoadError = null;
235
+ log("Native bridge cache reset");
236
+ };
237
+ adaptNativeResult = (raw) => {
238
+ return {
239
+ code: raw.code ?? "",
240
+ classes: raw.classes ?? [],
241
+ changed: raw.changed ?? false,
242
+ rsc: raw.rscJson ? JSON.parse(raw.rscJson) : void 0,
243
+ metadata: raw.metadataJson ? JSON.parse(raw.metadataJson) : void 0
244
+ };
245
+ };
246
+ if (typeof process !== "undefined" && !bridgeLoadAttempted) {
247
+ try {
248
+ getNativeBridge();
249
+ } catch {
196
250
  }
197
251
  }
198
- throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
252
+ }
253
+ });
199
254
 
200
- Tried paths: ${result.tried.join("\n")}`);
201
- } catch (err) {
202
- bridgeLoadError = err instanceof Error ? err : new Error(String(err));
203
- log("Failed to load native bridge:", bridgeLoadError.message);
204
- throw bridgeLoadError;
255
+ // packages/domain/compiler/src/tailwindEngine.ts
256
+ var tailwindEngine_exports = {};
257
+ __export(tailwindEngine_exports, {
258
+ generateRawCss: () => generateRawCss,
259
+ runCssPipeline: () => runCssPipeline,
260
+ runCssPipelineSync: () => runCssPipelineSync
261
+ });
262
+ function loadTailwindEngine() {
263
+ if (_twEngine) return _twEngine;
264
+ if (_twEngineError) throw _twEngineError;
265
+ try {
266
+ const tw = require2("tailwindcss");
267
+ if (typeof tw.compile !== "function") {
268
+ throw new Error("tailwindcss v4 not found \u2014 compile() API missing. Check tailwindcss version >= 4.");
269
+ }
270
+ _twEngine = tw;
271
+ return _twEngine;
272
+ } catch (e) {
273
+ _twEngineError = e instanceof Error ? e : new Error(String(e));
274
+ throw _twEngineError;
205
275
  }
206
- };
207
- var resetNativeBridgeCache = () => {
208
- nativeBridge = null;
209
- bridgeLoadAttempted = false;
210
- bridgeLoadError = null;
211
- log("Native bridge cache reset");
212
- };
213
- var adaptNativeResult = (raw) => {
276
+ }
277
+ function generateRawCss(classes) {
278
+ if (classes.length === 0) return "";
279
+ const tw = loadTailwindEngine();
280
+ const compiler = tw.compile("@import 'tailwindcss';");
281
+ return compiler.build(classes);
282
+ }
283
+ function postProcessWithLightning(rawCss) {
284
+ if (!rawCss) return "";
285
+ const native = getNativeBridge();
286
+ if (typeof native.processTailwindCssLightning === "function") {
287
+ const result = native.processTailwindCssLightning(rawCss);
288
+ return result?.css ?? rawCss;
289
+ }
290
+ console.warn("[tailwind-styled] processTailwindCssLightning tidak tersedia \u2014 gunakan raw CSS");
291
+ return rawCss;
292
+ }
293
+ async function runCssPipeline(classes) {
294
+ const unique = [...new Set(classes.filter(Boolean))];
295
+ if (unique.length === 0) {
296
+ return { css: "", classes: [], sizeBytes: 0, optimized: false };
297
+ }
298
+ const rawCss = generateRawCss(unique);
299
+ const native = getNativeBridge();
300
+ const hasLightning = typeof native.processTailwindCssLightning === "function";
301
+ const finalCss = hasLightning ? postProcessWithLightning(rawCss) : rawCss;
214
302
  return {
215
- code: raw.code ?? "",
216
- classes: raw.classes ?? [],
217
- changed: raw.changed ?? false,
218
- rsc: raw.rscJson ? JSON.parse(raw.rscJson) : void 0,
219
- metadata: raw.metadataJson ? JSON.parse(raw.metadataJson) : void 0
303
+ css: finalCss,
304
+ classes: unique,
305
+ sizeBytes: finalCss.length,
306
+ optimized: hasLightning
220
307
  };
221
- };
308
+ }
309
+ function runCssPipelineSync(classes) {
310
+ const unique = [...new Set(classes.filter(Boolean))];
311
+ if (unique.length === 0) {
312
+ return { css: "", classes: [], sizeBytes: 0, optimized: false };
313
+ }
314
+ const rawCss = generateRawCss(unique);
315
+ const native = getNativeBridge();
316
+ const hasLightning = typeof native.processTailwindCssLightning === "function";
317
+ const finalCss = hasLightning ? postProcessWithLightning(rawCss) : rawCss;
318
+ return {
319
+ css: finalCss,
320
+ classes: unique,
321
+ sizeBytes: finalCss.length,
322
+ optimized: hasLightning
323
+ };
324
+ }
325
+ var require2, _twEngine, _twEngineError;
326
+ var init_tailwindEngine = __esm({
327
+ "packages/domain/compiler/src/tailwindEngine.ts"() {
328
+ init_nativeBridge();
329
+ require2 = createRequire(import.meta.url);
330
+ _twEngine = null;
331
+ _twEngineError = null;
332
+ }
333
+ });
222
334
 
223
335
  // packages/domain/compiler/src/index.ts
336
+ init_nativeBridge();
224
337
  var transformSource = (source, opts) => {
225
338
  const native = getNativeBridge();
226
339
  if (!native?.transformSource) {
@@ -268,8 +381,9 @@ var compileCssNative = (classes, prefix = null) => {
268
381
  return compileCssFromClasses(classes, prefix);
269
382
  };
270
383
  var generateCssForClasses = async (classes, _tailwindConfig, _root) => {
271
- const result = await compileCssFromClasses(classes);
272
- return result?.code || "";
384
+ const { runCssPipeline: runCssPipeline2 } = await Promise.resolve().then(() => (init_tailwindEngine(), tailwindEngine_exports));
385
+ const result = await runCssPipeline2(classes);
386
+ return result.css;
273
387
  };
274
388
  var extractAllClasses = (source) => {
275
389
  const native = getNativeBridge();
@@ -575,43 +689,21 @@ var fileToRoute = (filepath) => {
575
689
  if (normalized.includes("/layout.") || normalized.includes("/loading.") || normalized.includes("/error.")) {
576
690
  return "__global";
577
691
  }
578
- const appPageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
579
- if (appPageMatch) return `/${appPageMatch[1]}`;
580
- const appRootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
581
- if (appRootPage) return "/";
582
- const pagesMatch = normalized.match(/\/pages\/(.+?)\.[tj]sx?$/);
583
- if (pagesMatch) {
584
- const pagePath = pagesMatch[1];
585
- if (pagePath.startsWith("_") || pagePath.startsWith("api/")) return "__global";
586
- return pagePath === "index" ? "/" : `/${pagePath}`;
587
- }
692
+ const pageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
693
+ if (pageMatch) return `/${pageMatch[1]}`;
694
+ const rootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
695
+ if (rootPage) return "/";
588
696
  return null;
589
697
  };
590
698
  var getAllRoutes = () => {
591
- return Array.from(_routeClassMap.keys());
699
+ return ["/", "__global"];
592
700
  };
593
- var _routeClassMap = /* @__PURE__ */ new Map();
594
701
  var getRouteClasses = (route) => {
595
- return _routeClassMap.get(route) ?? /* @__PURE__ */ new Set();
596
- };
597
- var getAllRouteClasses = () => {
598
- return new Map(_routeClassMap);
702
+ return /* @__PURE__ */ new Set();
599
703
  };
600
704
  var registerFileClasses = (filepath, classes) => {
601
- if (!classes.length) return;
602
- const route = fileToRoute(filepath) ?? "__global";
603
- const existing = _routeClassMap.get(route) ?? /* @__PURE__ */ new Set();
604
- for (const cls of classes) existing.add(cls);
605
- _routeClassMap.set(route, existing);
606
705
  };
607
706
  var registerGlobalClasses = (classes) => {
608
- if (!classes.length) return;
609
- const existing = _routeClassMap.get("__global") ?? /* @__PURE__ */ new Set();
610
- for (const cls of classes) existing.add(cls);
611
- _routeClassMap.set("__global", existing);
612
- };
613
- var clearRouteClasses = () => {
614
- _routeClassMap.clear();
615
707
  };
616
708
  var incrementalEngineInstance = null;
617
709
  var getIncrementalEngine = () => {
@@ -658,6 +750,6 @@ var bucketSort = (classes) => {
658
750
  return classes;
659
751
  };
660
752
 
661
- export { BucketEngine, IncrementalEngine, adaptNativeResult, analyzeClassUsage, analyzeClasses, analyzeFile, analyzeRsc, analyzeVariantUsage, astExtractClasses, batchExtractClasses, bucketSort, buildStyleTag, checkAgainstSafelist, classifyAndSortClasses, classifyNode, clearRouteClasses, compileCssFromClasses, compileCssNative, compileVariantTable, compileVariants, detectConflicts, diffClassLists, eliminateDeadCss, extractAllClasses, extractClassesFromSource, extractComponentUsage, fileToRoute, findDeadVariants, generateCssForClasses, generateSafelist, getAllRouteClasses, getAllRoutes, getBucketEngine, getContentPaths, getIncrementalEngine, getNativeBridge, getRouteClasses, hasTwUsage, hoistComponents, injectClientDirective, injectServerOnlyComment, isAlreadyTransformed, loadSafelist, loadTailwindConfig, mergeClassesStatic, mergeCssDeclarations, normalizeAndDedupClasses, normalizeClasses, optimizeCss, parseClasses, registerFileClasses, registerGlobalClasses, resetBucketEngine, resetIncrementalEngine, resetNativeBridgeCache, runElimination, runLoaderTransform, scanProjectUsage, shouldProcess, shouldSkipFile, transformSource };
753
+ export { BucketEngine, IncrementalEngine, adaptNativeResult, analyzeClassUsage, analyzeClasses, analyzeFile, analyzeRsc, analyzeVariantUsage, astExtractClasses, batchExtractClasses, bucketSort, buildStyleTag, checkAgainstSafelist, classifyAndSortClasses, classifyNode, compileCssFromClasses, compileCssNative, compileVariantTable, compileVariants, detectConflicts, diffClassLists, eliminateDeadCss, extractAllClasses, extractClassesFromSource, extractComponentUsage, fileToRoute, findDeadVariants, generateCssForClasses, generateSafelist, getAllRoutes, getBucketEngine, getContentPaths, getIncrementalEngine, getNativeBridge, getRouteClasses, hasTwUsage, hoistComponents, injectClientDirective, injectServerOnlyComment, isAlreadyTransformed, loadSafelist, loadTailwindConfig, mergeClassesStatic, mergeCssDeclarations, normalizeAndDedupClasses, normalizeClasses, optimizeCss, parseClasses, registerFileClasses, registerGlobalClasses, resetBucketEngine, resetIncrementalEngine, resetNativeBridgeCache, runElimination, runLoaderTransform, scanProjectUsage, shouldProcess, shouldSkipFile, transformSource };
662
754
  //# sourceMappingURL=compiler.mjs.map
663
755
  //# sourceMappingURL=compiler.mjs.map