tailwind-styled-v4 5.0.16 → 5.0.18

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 (62) hide show
  1. package/dist/atomic.js +14 -14
  2. package/dist/atomic.js.map +1 -1
  3. package/dist/atomic.mjs +14 -14
  4. package/dist/atomic.mjs.map +1 -1
  5. package/dist/cli.js +14 -14
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cli.mjs +14 -14
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/compiler.js +14 -14
  10. package/dist/compiler.js.map +1 -1
  11. package/dist/compiler.mjs +14 -14
  12. package/dist/compiler.mjs.map +1 -1
  13. package/dist/engine.js +14 -14
  14. package/dist/engine.js.map +1 -1
  15. package/dist/engine.mjs +14 -14
  16. package/dist/engine.mjs.map +1 -1
  17. package/dist/index.browser.mjs +5 -66
  18. package/dist/index.browser.mjs.map +1 -1
  19. package/dist/index.js +64 -105
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +64 -105
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/next.js +14 -14
  24. package/dist/next.js.map +1 -1
  25. package/dist/next.mjs +14 -14
  26. package/dist/next.mjs.map +1 -1
  27. package/dist/plugin.d.mts +3 -3
  28. package/dist/plugin.d.ts +3 -3
  29. package/dist/plugin.js.map +1 -1
  30. package/dist/plugin.mjs.map +1 -1
  31. package/dist/shared.d.mts +2 -3
  32. package/dist/shared.d.ts +2 -3
  33. package/dist/shared.js +14 -14
  34. package/dist/shared.js.map +1 -1
  35. package/dist/shared.mjs +14 -14
  36. package/dist/shared.mjs.map +1 -1
  37. package/dist/svelte.js +24 -42
  38. package/dist/svelte.js.map +1 -1
  39. package/dist/svelte.mjs +24 -42
  40. package/dist/svelte.mjs.map +1 -1
  41. package/dist/turbopackLoader.js +14 -14
  42. package/dist/turbopackLoader.js.map +1 -1
  43. package/dist/turbopackLoader.mjs +14 -14
  44. package/dist/turbopackLoader.mjs.map +1 -1
  45. package/dist/tw.js +14 -14
  46. package/dist/tw.js.map +1 -1
  47. package/dist/tw.mjs +14 -14
  48. package/dist/tw.mjs.map +1 -1
  49. package/dist/vite.js +14 -14
  50. package/dist/vite.js.map +1 -1
  51. package/dist/vite.mjs +14 -14
  52. package/dist/vite.mjs.map +1 -1
  53. package/dist/vue.js +24 -42
  54. package/dist/vue.js.map +1 -1
  55. package/dist/vue.mjs +24 -42
  56. package/dist/vue.mjs.map +1 -1
  57. package/dist/webpackLoader.js +14 -14
  58. package/dist/webpackLoader.js.map +1 -1
  59. package/dist/webpackLoader.mjs +14 -14
  60. package/dist/webpackLoader.mjs.map +1 -1
  61. package/native/tailwind-styled-native.node +0 -0
  62. package/package.json +1 -4
package/dist/index.mjs CHANGED
@@ -860,15 +860,27 @@ function resolveNativeBinary(runtimeDir) {
860
860
  }
861
861
  tried.push(`env:${envPath} (not found)`);
862
862
  }
863
+ const prebuiltPkgs = PLATFORM_MAP[platform] ?? [];
864
+ for (const pkg of prebuiltPkgs) {
865
+ try {
866
+ const candidate = _require.resolve(`${pkg}/tailwind_styled_parser.node`);
867
+ if (fs3.existsSync(candidate)) {
868
+ return { path: candidate, source: "prebuilt", platform, tried };
869
+ }
870
+ tried.push(`prebuilt:${pkg} (resolved but missing)`);
871
+ } catch {
872
+ tried.push(`prebuilt:${pkg} (not installed)`);
873
+ }
874
+ }
863
875
  const napiPlatform = platform === "linux-x64" ? "linux-x64-gnu" : platform === "linux-arm64" ? "linux-arm64-gnu" : platform;
864
- const BINARY_NAMES_SELF = ["tailwind-styled-native", "tailwind_styled_parser", "index"];
876
+ const BINARY_NAMES_SELF = ["tailwind-styled-native", "tailwind_styled_parser"];
865
877
  if (runtimeDir) {
866
878
  for (const depth of ["..", path9.join("..", ".."), path9.join("..", "..", "..")]) {
867
879
  const pkgRoot = path9.resolve(runtimeDir, depth);
868
880
  for (const bin of BINARY_NAMES_SELF) {
869
881
  for (const suffix of ["", `.${platform}`, `.${napiPlatform}`]) {
870
882
  const candidate = path9.resolve(pkgRoot, "native", `${bin}${suffix}.node`);
871
- tried.push(`native:${candidate}`);
883
+ tried.push(`self-bundled:${candidate}`);
872
884
  if (fs3.existsSync(candidate)) {
873
885
  return { path: candidate, source: "prebuilt", platform, tried };
874
886
  }
@@ -876,18 +888,6 @@ function resolveNativeBinary(runtimeDir) {
876
888
  }
877
889
  }
878
890
  }
879
- const prebuiltPkgs = PLATFORM_MAP[platform] ?? [];
880
- for (const pkg of prebuiltPkgs) {
881
- try {
882
- const candidate = _require.resolve(`${pkg}/tailwind_styled_parser.node`);
883
- if (fs3.existsSync(candidate)) {
884
- return { path: candidate, source: "prebuilt", platform, tried };
885
- }
886
- tried.push(`prebuilt:${pkg} (resolved but missing)`);
887
- } catch {
888
- tried.push(`prebuilt:${pkg} (not installed)`);
889
- }
890
- }
891
891
  const cwd = process.cwd();
892
892
  const base = runtimeDir ?? cwd;
893
893
  const BINARY_NAMES = ["tailwind-styled-native", "tailwind_styled_parser"];
@@ -4771,31 +4771,24 @@ var init_native_bridge2 = __esm({
4771
4771
 
4772
4772
  // packages/domain/core/src/native.ts
4773
4773
  init_src2();
4774
- var isBrowser4 = typeof window !== "undefined" && typeof document !== "undefined";
4775
- var NATIVE_UNAVAILABLE_MESSAGE2 = "[tailwind-styled/core] Native binding is required but not available.\nMake sure:\n 1. .node files were copied to dist/ during build\n 2. You installed the correct native package for your platform\n 3. npm run build:rust was executed successfully";
4774
+ var isBrowser4 = typeof window !== "undefined" || typeof document !== "undefined";
4775
+ var NATIVE_UNAVAILABLE_MESSAGE2 = "[tailwind-styled/core] Native binding is required but not available.\nPlease ensure you have run: npm run build:rust";
4776
4776
  var _nodeRequire = createRequire(import.meta.url);
4777
4777
  var _loadNative2 = (path15) => _nodeRequire(path15);
4778
4778
  var nativeBinding = null;
4779
4779
  var bindingLoadAttempted = false;
4780
- var bindingError = null;
4781
4780
  var getBinding = () => {
4782
- if (nativeBinding) return nativeBinding;
4783
- if (bindingError) {
4784
- throw bindingError;
4781
+ if (isBrowser4) {
4782
+ throw new Error(NATIVE_UNAVAILABLE_MESSAGE2 + "\n\nNative bindings are not available in browser. Use the compiled CSS output instead.");
4785
4783
  }
4784
+ if (nativeBinding) return nativeBinding;
4786
4785
  if (bindingLoadAttempted) {
4787
4786
  throw new Error(NATIVE_UNAVAILABLE_MESSAGE2);
4788
4787
  }
4789
4788
  bindingLoadAttempted = true;
4790
4789
  try {
4791
- if (isBrowser4) {
4792
- bindingError = new Error(
4793
- "[tailwind-styled/core] Cannot use template literals (tw`...`) in browser environment.\n\nTemplate literal parsing requires native Rust bindings compiled to WebAssembly,\nwhich is not currently supported.\n\nSolutions:\n1. Use object config only: tw.button({ base: '...', variants: {...} })\n2. Pre-compile components on the server (Next.js Server Components)\n3. Use @tailwind-styled browser-safe packages if available\n\nFor more info: https://github.com/Dictionar32/css-in-rust/discussions"
4794
- );
4795
- throw bindingError;
4796
- }
4797
- const runtimeDir = dirname(fileURLToPath(import.meta.url));
4798
- const result = resolveNativeBinary(runtimeDir);
4790
+ const runtimeDir = isBrowser4 ? "" : dirname(fileURLToPath(import.meta.url));
4791
+ const result = isBrowser4 ? { path: null, source: "not-found", platform: "browser", tried: [] } : resolveNativeBinary(runtimeDir);
4799
4792
  if (result.path && result.path.endsWith(".node")) {
4800
4793
  const mod = _loadNative2(result.path);
4801
4794
  if (mod?.batchSplitClasses) {
@@ -4803,22 +4796,11 @@ var getBinding = () => {
4803
4796
  return nativeBinding;
4804
4797
  }
4805
4798
  }
4806
- bindingError = new Error(
4807
- `${NATIVE_UNAVAILABLE_MESSAGE2}
4808
-
4809
- Resolution Attempts:
4810
- ${result.tried.map((t2) => ` - ${t2}`).join("\n")}
4799
+ throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE2}
4811
4800
 
4812
- Quick fixes:
4813
- 1. npm run build:rust # Build native binaries
4814
- 2. npm install # Reinstall with pre-built binaries
4815
- 3. TW_NATIVE_PATH=/path/to/index.node npm run dev # Specify binary path`
4816
- );
4817
- throw bindingError;
4801
+ Tried: ${result.tried.join("\n")}`);
4818
4802
  } catch (err) {
4819
- const error = err instanceof Error ? err : new Error(String(err));
4820
- bindingError = error;
4821
- throw error;
4803
+ throw err instanceof Error ? err : new Error(String(err));
4822
4804
  }
4823
4805
  };
4824
4806
  var getNativeBinding = getBinding;
@@ -5485,70 +5467,49 @@ function lookupGenerated(componentId, props, defaultVariants, variantKeys) {
5485
5467
  );
5486
5468
  return table[key];
5487
5469
  }
5488
- function resolveVariantsNative(config, props) {
5489
- const { variants = {}, defaultVariants = {} } = config;
5490
- try {
5491
- const binding = getNativeBinding();
5492
- if (!binding?.resolveVariants) {
5493
- throw new Error("resolveVariants not available");
5470
+ var _configJsonCache = /* @__PURE__ */ new WeakMap();
5471
+ function _getConfigJson(config) {
5472
+ let json = _configJsonCache.get(config);
5473
+ if (!json) {
5474
+ const cfgObj = config;
5475
+ const cfgStr = JSON.stringify(cfgObj);
5476
+ const parsed = JSON.parse(cfgStr);
5477
+ if ("defaultVariants" in parsed && !("default_variants" in parsed)) {
5478
+ parsed.default_variants = parsed.defaultVariants;
5479
+ delete parsed.defaultVariants;
5494
5480
  }
5495
- const variantKeys = Object.keys(variants);
5496
- const configJson = (() => {
5497
- const cfgObj = config;
5498
- const cfgStr = JSON.stringify(cfgObj);
5499
- const parsed = JSON.parse(cfgStr);
5500
- if ("defaultVariants" in parsed && !("default_variants" in parsed)) {
5501
- parsed.default_variants = parsed.defaultVariants;
5502
- delete parsed.defaultVariants;
5503
- }
5504
- if ("compoundVariants" in parsed && !("compound_variants" in parsed)) {
5505
- parsed.compound_variants = parsed.compoundVariants;
5506
- delete parsed.compoundVariants;
5507
- }
5508
- if (!("variants" in parsed) || parsed.variants == null) {
5509
- parsed.variants = {};
5510
- }
5511
- return JSON.stringify(parsed);
5512
- })();
5513
- const cleanProps = {};
5514
- for (const k of variantKeys) {
5515
- const dv = defaultVariants[k];
5516
- if (dv !== void 0 && dv !== null) cleanProps[k] = String(dv);
5481
+ if ("compoundVariants" in parsed && !("compound_variants" in parsed)) {
5482
+ parsed.compound_variants = parsed.compoundVariants;
5483
+ delete parsed.compoundVariants;
5517
5484
  }
5518
- for (const k of variantKeys) {
5519
- const v = props[k];
5520
- if (v !== void 0 && v !== null) cleanProps[k] = String(v);
5521
- }
5522
- const propsJson = JSON.stringify(cleanProps);
5523
- const result = binding.resolveVariants(configJson, propsJson);
5524
- return result?.classes ?? "";
5525
- } catch (_err) {
5526
- if (process.env.NODE_ENV !== "production") {
5527
- console.warn("[cv() fallback] getNativeBinding threw error, using JS fallback");
5528
- }
5529
- const result = [];
5530
- const { base = "", compoundVariants = [] } = config;
5531
- if (base) result.push(base);
5532
- const merged = { ...defaultVariants };
5533
- for (const [key, values] of Object.entries(variants || {})) {
5534
- const selected = props[key] ?? defaultVariants?.[key];
5535
- if (selected !== void 0 && selected !== null) merged[key] = selected;
5536
- if (selected && typeof values === "object" && values !== null) {
5537
- const variantValues = values;
5538
- if (variantValues[String(selected)]) {
5539
- result.push(variantValues[String(selected)]);
5540
- }
5541
- }
5542
- }
5543
- for (const compound of compoundVariants) {
5544
- const { class: compoundClass, ...conditions } = compound;
5545
- const matches = Object.entries(conditions).every(
5546
- ([k, v]) => String(merged[k]) === String(v)
5547
- );
5548
- if (matches && compoundClass) result.push(compoundClass);
5485
+ if (!("variants" in parsed) || parsed.variants == null) {
5486
+ parsed.variants = {};
5549
5487
  }
5550
- return result.join(" ");
5488
+ json = JSON.stringify(parsed);
5489
+ _configJsonCache.set(config, json);
5551
5490
  }
5491
+ return json;
5492
+ }
5493
+ function resolveVariantsNative(config, props) {
5494
+ const { variants = {}, defaultVariants = {} } = config;
5495
+ const binding = getNativeBinding();
5496
+ if (!binding?.resolveVariants) {
5497
+ throw new Error("FATAL: Native binding 'resolveVariants' is required but not available. Build cannot continue.");
5498
+ }
5499
+ const variantKeys = Object.keys(variants);
5500
+ const configJson = _getConfigJson(config);
5501
+ const cleanProps = {};
5502
+ for (const k of variantKeys) {
5503
+ const dv = defaultVariants[k];
5504
+ if (dv !== void 0 && dv !== null) cleanProps[k] = String(dv);
5505
+ }
5506
+ for (const k of variantKeys) {
5507
+ const v = props[k];
5508
+ if (v !== void 0 && v !== null) cleanProps[k] = String(v);
5509
+ }
5510
+ const propsJson = JSON.stringify(cleanProps);
5511
+ const result = binding.resolveVariants(configJson, propsJson);
5512
+ return result.classes;
5552
5513
  }
5553
5514
  function cv(config, componentId) {
5554
5515
  if (process.env.NODE_ENV !== "production") {
@@ -6042,9 +6003,7 @@ function parseTemplate(strings, exprs) {
6042
6003
  if (cached) return cached;
6043
6004
  const binding = getNativeBinding();
6044
6005
  if (!binding?.parseTemplate) {
6045
- throw new Error(
6046
- "FATAL: Native binding 'parseTemplate' is required but not available in this environment.\n\nThis function is only available on Node.js with native bindings loaded.\nFor browser environments, use object config instead:\n tw.button({ base: '...', variants: {...} })"
6047
- );
6006
+ throw new Error("FATAL: Native binding 'parseTemplate' is required but not available.");
6048
6007
  }
6049
6008
  const r = binding.parseTemplate(raw);
6050
6009
  const subs = r.hasSubs ? JSON.parse(r.subsJson) : {};