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/vite.mjs CHANGED
@@ -1,7 +1,7 @@
1
+ import { createRequire } from 'module';
1
2
  import path3 from 'path';
2
3
  import { fileURLToPath, pathToFileURL } from 'url';
3
4
  import fs from 'fs';
4
- import { createRequire } from 'module';
5
5
  import { Worker } from 'worker_threads';
6
6
  import { z } from 'zod';
7
7
  import 'perf_hooks';
@@ -407,6 +407,147 @@ var init_src = __esm({
407
407
  _require2 = getRequire2();
408
408
  }
409
409
  });
410
+ var log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge;
411
+ var init_nativeBridge = __esm({
412
+ "packages/domain/compiler/src/nativeBridge.ts"() {
413
+ init_src();
414
+ log = (...args) => {
415
+ if (process.env.DEBUG?.includes("compiler:native")) {
416
+ console.log("[compiler:native]", ...args);
417
+ }
418
+ };
419
+ 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";
420
+ nativeBridge = null;
421
+ bridgeLoadAttempted = false;
422
+ bridgeLoadError = null;
423
+ isValidNativeBridge = (mod) => {
424
+ const m = mod;
425
+ return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
426
+ };
427
+ getNativeBridge = () => {
428
+ if (nativeBridge) {
429
+ return nativeBridge;
430
+ }
431
+ if (bridgeLoadAttempted) {
432
+ if (bridgeLoadError) {
433
+ throw bridgeLoadError;
434
+ }
435
+ throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
436
+ }
437
+ bridgeLoadAttempted = true;
438
+ try {
439
+ const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
440
+ const require3 = createRequire(import.meta.url);
441
+ const result = resolveNativeBinary(runtimeDir);
442
+ if (result.path && result.path.endsWith(".node")) {
443
+ try {
444
+ const binding = require3(result.path);
445
+ if (isValidNativeBridge(binding)) {
446
+ nativeBridge = binding;
447
+ log("Native bridge loaded successfully from:", result.path);
448
+ return nativeBridge;
449
+ }
450
+ } catch (e) {
451
+ log("Failed to require native binding:", e);
452
+ }
453
+ }
454
+ throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
455
+
456
+ Tried paths: ${result.tried.join("\n")}`);
457
+ } catch (err) {
458
+ bridgeLoadError = err instanceof Error ? err : new Error(String(err));
459
+ log("Failed to load native bridge:", bridgeLoadError.message);
460
+ throw bridgeLoadError;
461
+ }
462
+ };
463
+ if (typeof process !== "undefined" && !bridgeLoadAttempted) {
464
+ try {
465
+ getNativeBridge();
466
+ } catch {
467
+ }
468
+ }
469
+ }
470
+ });
471
+
472
+ // packages/domain/compiler/src/tailwindEngine.ts
473
+ var tailwindEngine_exports = {};
474
+ __export(tailwindEngine_exports, {
475
+ generateRawCss: () => generateRawCss,
476
+ runCssPipeline: () => runCssPipeline,
477
+ runCssPipelineSync: () => runCssPipelineSync
478
+ });
479
+ function loadTailwindEngine() {
480
+ if (_twEngine) return _twEngine;
481
+ if (_twEngineError) throw _twEngineError;
482
+ try {
483
+ const tw = require2("tailwindcss");
484
+ if (typeof tw.compile !== "function") {
485
+ throw new Error("tailwindcss v4 not found \u2014 compile() API missing. Check tailwindcss version >= 4.");
486
+ }
487
+ _twEngine = tw;
488
+ return _twEngine;
489
+ } catch (e) {
490
+ _twEngineError = e instanceof Error ? e : new Error(String(e));
491
+ throw _twEngineError;
492
+ }
493
+ }
494
+ function generateRawCss(classes) {
495
+ if (classes.length === 0) return "";
496
+ const tw = loadTailwindEngine();
497
+ const compiler = tw.compile("@import 'tailwindcss';");
498
+ return compiler.build(classes);
499
+ }
500
+ function postProcessWithLightning(rawCss) {
501
+ if (!rawCss) return "";
502
+ const native = getNativeBridge();
503
+ if (typeof native.processTailwindCssLightning === "function") {
504
+ const result = native.processTailwindCssLightning(rawCss);
505
+ return result?.css ?? rawCss;
506
+ }
507
+ console.warn("[tailwind-styled] processTailwindCssLightning tidak tersedia \u2014 gunakan raw CSS");
508
+ return rawCss;
509
+ }
510
+ async function runCssPipeline(classes) {
511
+ const unique = [...new Set(classes.filter(Boolean))];
512
+ if (unique.length === 0) {
513
+ return { css: "", classes: [], sizeBytes: 0, optimized: false };
514
+ }
515
+ const rawCss = generateRawCss(unique);
516
+ const native = getNativeBridge();
517
+ const hasLightning = typeof native.processTailwindCssLightning === "function";
518
+ const finalCss = hasLightning ? postProcessWithLightning(rawCss) : rawCss;
519
+ return {
520
+ css: finalCss,
521
+ classes: unique,
522
+ sizeBytes: finalCss.length,
523
+ optimized: hasLightning
524
+ };
525
+ }
526
+ function runCssPipelineSync(classes) {
527
+ const unique = [...new Set(classes.filter(Boolean))];
528
+ if (unique.length === 0) {
529
+ return { css: "", classes: [], sizeBytes: 0, optimized: false };
530
+ }
531
+ const rawCss = generateRawCss(unique);
532
+ const native = getNativeBridge();
533
+ const hasLightning = typeof native.processTailwindCssLightning === "function";
534
+ const finalCss = hasLightning ? postProcessWithLightning(rawCss) : rawCss;
535
+ return {
536
+ css: finalCss,
537
+ classes: unique,
538
+ sizeBytes: finalCss.length,
539
+ optimized: hasLightning
540
+ };
541
+ }
542
+ var require2, _twEngine, _twEngineError;
543
+ var init_tailwindEngine = __esm({
544
+ "packages/domain/compiler/src/tailwindEngine.ts"() {
545
+ init_nativeBridge();
546
+ require2 = createRequire(import.meta.url);
547
+ _twEngine = null;
548
+ _twEngineError = null;
549
+ }
550
+ });
410
551
 
411
552
  // packages/domain/scanner/src/native-bridge.ts
412
553
  var native_bridge_exports = {};
@@ -591,59 +732,8 @@ var init_native_bridge = __esm({
591
732
  }
592
733
  });
593
734
 
594
- // packages/domain/compiler/src/nativeBridge.ts
595
- init_src();
596
- var log = (...args) => {
597
- if (process.env.DEBUG?.includes("compiler:native")) {
598
- console.log("[compiler:native]", ...args);
599
- }
600
- };
601
- 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";
602
- var nativeBridge = null;
603
- var bridgeLoadAttempted = false;
604
- var bridgeLoadError = null;
605
- var isValidNativeBridge = (mod) => {
606
- const m = mod;
607
- return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
608
- };
609
- var getNativeBridge = () => {
610
- if (nativeBridge) {
611
- return nativeBridge;
612
- }
613
- if (bridgeLoadAttempted) {
614
- if (bridgeLoadError) {
615
- throw bridgeLoadError;
616
- }
617
- throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
618
- }
619
- bridgeLoadAttempted = true;
620
- try {
621
- const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
622
- const require2 = createRequire(import.meta.url);
623
- const result = resolveNativeBinary(runtimeDir);
624
- if (result.path && result.path.endsWith(".node")) {
625
- try {
626
- const binding = require2(result.path);
627
- if (isValidNativeBridge(binding)) {
628
- nativeBridge = binding;
629
- log("Native bridge loaded successfully from:", result.path);
630
- return nativeBridge;
631
- }
632
- } catch (e) {
633
- log("Failed to require native binding:", e);
634
- }
635
- }
636
- throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
637
-
638
- Tried paths: ${result.tried.join("\n")}`);
639
- } catch (err) {
640
- bridgeLoadError = err instanceof Error ? err : new Error(String(err));
641
- log("Failed to load native bridge:", bridgeLoadError.message);
642
- throw bridgeLoadError;
643
- }
644
- };
645
-
646
735
  // packages/domain/compiler/src/index.ts
736
+ init_nativeBridge();
647
737
  var transformSource = (source, opts) => {
648
738
  const native = getNativeBridge();
649
739
  if (!native?.transformSource) {
@@ -655,20 +745,10 @@ var transformSource = (source, opts) => {
655
745
  }
656
746
  return result;
657
747
  };
658
- var compileCssFromClasses = (classes, prefix) => {
659
- const native = getNativeBridge();
660
- if (!native?.transformSource) {
661
- throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
662
- }
663
- const result = native.transformSource(classes.join(" "), { prefix: "" });
664
- if (!result) {
665
- throw new Error("FATAL: transformSource returned null");
666
- }
667
- return result;
668
- };
669
748
  var generateCssForClasses = async (classes, _tailwindConfig, _root) => {
670
- const result = await compileCssFromClasses(classes);
671
- return result?.code || "";
749
+ const { runCssPipeline: runCssPipeline2 } = await Promise.resolve().then(() => (init_tailwindEngine(), tailwindEngine_exports));
750
+ const result = await runCssPipeline2(classes);
751
+ return result.css;
672
752
  };
673
753
  var mergeClassesStatic = (classes) => {
674
754
  const result = normalizeAndDedupClasses(classes);