tailwind-styled-v4 5.0.35 → 5.0.36

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.
package/dist/index.js CHANGED
@@ -5228,17 +5228,12 @@ function hashState(tag, state) {
5228
5228
  _hashStateCache.set(sortedKey, id);
5229
5229
  return id;
5230
5230
  }
5231
- var _twClassesToCssCache = /* @__PURE__ */ new Map();
5232
- function twClassesToCss(classes) {
5233
- const cached = _twClassesToCssCache.get(classes);
5234
- if (cached !== void 0) return cached;
5231
+ function generateStateRules(id, state) {
5235
5232
  const native = getNativeBinding();
5236
- if (!native?.twClassesToCss) {
5237
- throw new Error("FATAL: Native binding 'twClassesToCss' is required but not available.");
5233
+ if (!native?.generateRuntimeStateCss) {
5234
+ throw new Error("FATAL: Native binding 'generateRuntimeStateCss' is required but not available.");
5238
5235
  }
5239
- const result = native.twClassesToCss(classes);
5240
- _twClassesToCssCache.set(classes, result);
5241
- return result;
5236
+ return native.generateRuntimeStateCss(id, JSON.stringify(state), null).map((rule) => rule.cssRule);
5242
5237
  }
5243
5238
  var _staticCssDetected = /* @__PURE__ */ new Set();
5244
5239
  var _batchedInjectFn = null;
@@ -5270,10 +5265,7 @@ function injectStateStyles(id, state) {
5270
5265
  }
5271
5266
  }
5272
5267
  }
5273
- const rules = Object.entries(state).map(([stateName, classes]) => {
5274
- const css = twClassesToCss(classes);
5275
- return css ? `.${id}[data-${stateName}="true"]{${css}}` : null;
5276
- }).filter(Boolean);
5268
+ const rules = generateStateRules(id, state);
5277
5269
  if (rules.length === 0) return;
5278
5270
  if (_batchedInjectFn) {
5279
5271
  for (const rule of rules) _batchedInjectFn(rule);
@@ -5303,11 +5295,7 @@ function processState(tag, state, precomputedHash) {
5303
5295
  }
5304
5296
  function generateStateCss(tag, state) {
5305
5297
  const id = hashState(tag, state);
5306
- const rules = Object.entries(state).map(([stateName, classes]) => {
5307
- const css = twClassesToCss(classes);
5308
- return css ? `.${id}[data-${stateName}="true"]{${css}}` : null;
5309
- }).filter(Boolean);
5310
- return rules.join("\n");
5298
+ return generateStateRules(id, state).join("\n");
5311
5299
  }
5312
5300
  function getStateRegistry() {
5313
5301
  return stateRegistry;
@@ -5712,7 +5700,13 @@ function lookupGenerated(componentId, props, defaultVariants, variantKeys) {
5712
5700
  }
5713
5701
  const binding = getNativeBinding();
5714
5702
  if (!binding?.buildVariantLookupKey) {
5715
- throw new Error("FATAL: Native binding 'buildVariantLookupKey' is required but not available.");
5703
+ const parts = [];
5704
+ for (const k of sortedKeys) {
5705
+ const v = props[k] ?? defaultVariants?.[k];
5706
+ if (v != null) parts.push(`${k}:${String(v)}`);
5707
+ }
5708
+ const key2 = parts.join("|");
5709
+ return table[key2];
5716
5710
  }
5717
5711
  const relevantDefaults = {};
5718
5712
  const relevantProps = {};
@@ -5755,7 +5749,31 @@ function resolveVariantsNative(config, props) {
5755
5749
  const { variants = {}, defaultVariants = {} } = config;
5756
5750
  const binding = getNativeBinding();
5757
5751
  if (!binding?.resolveVariants) {
5758
- throw new Error("FATAL: Native binding 'resolveVariants' is required but not available. Build cannot continue.");
5752
+ const variantKeys2 = Object.keys(variants);
5753
+ const classes = [];
5754
+ for (const key of variantKeys2) {
5755
+ const value = props[key] ?? defaultVariants[key];
5756
+ if (value != null) {
5757
+ const variantClass = variants[key]?.[String(value)];
5758
+ if (variantClass) classes.push(variantClass);
5759
+ }
5760
+ }
5761
+ if (config.compoundVariants) {
5762
+ for (const compound of config.compoundVariants) {
5763
+ const { class: compoundClass, ...conditions } = compound;
5764
+ const resolved = {};
5765
+ for (const key of variantKeys2) {
5766
+ resolved[key] = String(
5767
+ props[key] ?? defaultVariants[key] ?? ""
5768
+ );
5769
+ }
5770
+ const matches = Object.entries(conditions).every(
5771
+ ([k, v]) => resolved[k] === v
5772
+ );
5773
+ if (matches) classes.push(compoundClass);
5774
+ }
5775
+ }
5776
+ return classes.join(" ");
5759
5777
  }
5760
5778
  const variantKeys = Object.keys(variants);
5761
5779
  const configJson = _getConfigJson(config);