tailwind-to-style 2.7.7 → 2.8.0

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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.7.7
2
+ * tailwind-to-style v2.8.0
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
@@ -6401,10 +6401,10 @@ function parseCustomClassWithPatterns(className) {
6401
6401
  return null;
6402
6402
  }
6403
6403
 
6404
- /**
6405
- * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6406
- * @param {string} cssString
6407
- * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6404
+ /**
6405
+ * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6406
+ * @param {string} cssString
6407
+ * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6408
6408
  */
6409
6409
  function resolveCssToClearCss(cssString) {
6410
6410
  const customVars = {};
@@ -6682,11 +6682,11 @@ function separateAndResolveCSS(arr) {
6682
6682
  }
6683
6683
  }
6684
6684
 
6685
- /**
6686
- * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6687
- * @param {string} className - Class name with potential opacity modifier
6688
- * @param {string} cssDeclaration - CSS declaration to modify
6689
- * @returns {string} Modified CSS declaration with opacity applied
6685
+ /**
6686
+ * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6687
+ * @param {string} className - Class name with potential opacity modifier
6688
+ * @param {string} cssDeclaration - CSS declaration to modify
6689
+ * @returns {string} Modified CSS declaration with opacity applied
6690
6690
  */
6691
6691
  function processOpacityModifier(className, cssDeclaration) {
6692
6692
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6747,11 +6747,11 @@ function processOpacityModifier(className, cssDeclaration) {
6747
6747
  return modifiedDeclaration;
6748
6748
  }
6749
6749
 
6750
- /**
6751
- * Convert Tailwind class string to inline CSS styles or JSON object
6752
- * @param {string} classNames - String containing Tailwind classes to convert
6753
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6754
- * @returns {string|Object} Inline CSS string or style JSON object
6750
+ /**
6751
+ * Convert Tailwind class string to inline CSS styles or JSON object
6752
+ * @param {string} classNames - String containing Tailwind classes to convert
6753
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6754
+ * @returns {string|Object} Inline CSS string or style JSON object
6755
6755
  */
6756
6756
  function tws(classNames, convertToJson) {
6757
6757
  const totalMarker = performanceMonitor.start("tws:total");
@@ -6782,11 +6782,29 @@ function tws(classNames, convertToJson) {
6782
6782
  const processMarker = performanceMonitor.start("tws:process");
6783
6783
  let cssResult = classes.map(className => {
6784
6784
  // Extract base class name without opacity modifier
6785
- const baseClassName = className.replace(/\/\d+$/, "");
6786
- let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6785
+ // Only remove /digits if it's an opacity modifier (not a fraction like w-2/3)
6786
+ // Opacity modifiers are typically /0-100, fractions are /2, /3, /4, /5, /6, /12
6787
+ const opacityMatch = className.match(/\/(\d+)$/);
6788
+ let baseClassName = className;
6789
+ let hasOpacityModifier = false;
6790
+ if (opacityMatch) {
6791
+ const opacityValue = parseInt(opacityMatch[1], 10);
6792
+ // If it's a valid opacity value (0-100), treat it as opacity modifier
6793
+ if (opacityValue >= 0 && opacityValue <= 100) {
6794
+ // Check if this could be a fraction (e.g., w-2/3, h-1/2)
6795
+ // Fractions typically have denominators of 2, 3, 4, 5, 6, 12
6796
+ const fractionDenominators = [2, 3, 4, 5, 6, 12];
6797
+ const couldBeFraction = fractionDenominators.includes(opacityValue) && (className.startsWith('w-') || className.startsWith('h-') || className.startsWith('max-w-') || className.startsWith('max-h-') || className.startsWith('min-w-') || className.startsWith('min-h-'));
6798
+ if (!couldBeFraction) {
6799
+ baseClassName = className.replace(/\/\d+$/, "");
6800
+ hasOpacityModifier = true;
6801
+ }
6802
+ }
6803
+ }
6804
+ let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/\//g, "\\/")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6787
6805
  if (result) {
6788
6806
  // Apply opacity modifier if present
6789
- if (className.includes("/") && /\/\d+$/.test(className)) {
6807
+ if (hasOpacityModifier && className.includes("/") && /\/\d+$/.test(className)) {
6790
6808
  result = processOpacityModifier(className, result);
6791
6809
  }
6792
6810
  return resolveCssToClearCss(result);
@@ -6798,7 +6816,7 @@ function tws(classNames, convertToJson) {
6798
6816
  if (cssObject[`${baseKey}custom`]) {
6799
6817
  let customResult = cssObject[`${baseKey}custom`].replace(/custom_value/g, customValue);
6800
6818
  // Apply opacity modifier to custom values too
6801
- if (className.includes("/") && /\/\d+$/.test(className)) {
6819
+ if (hasOpacityModifier && className.includes("/") && /\/\d+$/.test(className)) {
6802
6820
  customResult = processOpacityModifier(className, customResult);
6803
6821
  }
6804
6822
  return customResult;
@@ -6934,7 +6952,23 @@ function processClass(cls, selector, styles) {
6934
6952
  } = resolveVariants(selector, rawVariants);
6935
6953
 
6936
6954
  // Extract base class name without opacity modifier for CSS lookup
6937
- const baseClassName = pureClassName.replace(/\/\d+$/, "");
6955
+ // Only remove /digits if it's an opacity modifier (not a fraction like w-2/3)
6956
+ const opacityMatch = pureClassName.match(/\/(\d+)$/);
6957
+ let baseClassName = pureClassName;
6958
+ let hasOpacityModifier = false;
6959
+ if (opacityMatch) {
6960
+ const opacityValue = parseInt(opacityMatch[1], 10);
6961
+ // If it's a valid opacity value (0-100), treat it as opacity modifier
6962
+ if (opacityValue >= 0 && opacityValue <= 100) {
6963
+ // Check if this could be a fraction (e.g., w-2/3, h-1/2)
6964
+ const fractionDenominators = [2, 3, 4, 5, 6, 12];
6965
+ const couldBeFraction = fractionDenominators.includes(opacityValue) && (pureClassName.startsWith('w-') || pureClassName.startsWith('h-') || pureClassName.startsWith('max-w-') || pureClassName.startsWith('max-h-') || pureClassName.startsWith('min-w-') || pureClassName.startsWith('min-h-'));
6966
+ if (!couldBeFraction) {
6967
+ baseClassName = pureClassName.replace(/\/\d+$/, "");
6968
+ hasOpacityModifier = true;
6969
+ }
6970
+ }
6971
+ }
6938
6972
  let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6939
6973
  if (!declarations && baseClassName.includes("[")) {
6940
6974
  const match = baseClassName.match(/^(.+?)\[(.+)\]$/);
@@ -6955,7 +6989,7 @@ function processClass(cls, selector, styles) {
6955
6989
  }
6956
6990
 
6957
6991
  // Apply opacity modifier if present
6958
- if (pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
6992
+ if (hasOpacityModifier && pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
6959
6993
  declarations = processOpacityModifier(pureClassName, declarations);
6960
6994
  }
6961
6995
  if (isImportant) {
@@ -7130,12 +7164,12 @@ function generateCssString(styles) {
7130
7164
  return cssString.trim();
7131
7165
  }
7132
7166
 
7133
- /**
7134
- * Generate CSS string from style object with SCSS-like syntax
7135
- * Supports nested selectors, state variants, responsive variants, and @css directives
7136
- * @param {Object} obj - Object with SCSS-like style format
7137
- * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7138
- * @returns {string} Generated CSS string
7167
+ /**
7168
+ * Generate CSS string from style object with SCSS-like syntax
7169
+ * Supports nested selectors, state variants, responsive variants, and @css directives
7170
+ * @param {Object} obj - Object with SCSS-like style format
7171
+ * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7172
+ * @returns {string} Generated CSS string
7139
7173
  */
7140
7174
  function twsx(obj) {
7141
7175
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7242,19 +7276,19 @@ function autoInjectCss(cssString) {
7242
7276
  }
7243
7277
 
7244
7278
  // Enhanced debounced functions with performance monitoring configuration
7245
- /**
7246
- * Debounced version of tws function with performance monitoring
7247
- * @param {string} classNames - String containing Tailwind classes to convert
7248
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7249
- * @returns {string|Object} Inline CSS string or style JSON object
7279
+ /**
7280
+ * Debounced version of tws function with performance monitoring
7281
+ * @param {string} classNames - String containing Tailwind classes to convert
7282
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7283
+ * @returns {string|Object} Inline CSS string or style JSON object
7250
7284
  */
7251
7285
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7252
7286
 
7253
- /**
7254
- * Debounced version of twsx function with performance monitoring
7255
- * @param {Object} obj - Object with SCSS-like style format
7256
- * @param {Object} [options] - Additional options
7257
- * @returns {string} Generated CSS string
7287
+ /**
7288
+ * Debounced version of twsx function with performance monitoring
7289
+ * @param {Object} obj - Object with SCSS-like style format
7290
+ * @param {Object} [options] - Additional options
7291
+ * @returns {string} Generated CSS string
7258
7292
  */
7259
7293
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7260
7294
 
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.7.7
2
+ * tailwind-to-style v2.8.0
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
@@ -6397,10 +6397,10 @@ function parseCustomClassWithPatterns(className) {
6397
6397
  return null;
6398
6398
  }
6399
6399
 
6400
- /**
6401
- * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6402
- * @param {string} cssString
6403
- * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6400
+ /**
6401
+ * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6402
+ * @param {string} cssString
6403
+ * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6404
6404
  */
6405
6405
  function resolveCssToClearCss(cssString) {
6406
6406
  const customVars = {};
@@ -6678,11 +6678,11 @@ function separateAndResolveCSS(arr) {
6678
6678
  }
6679
6679
  }
6680
6680
 
6681
- /**
6682
- * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6683
- * @param {string} className - Class name with potential opacity modifier
6684
- * @param {string} cssDeclaration - CSS declaration to modify
6685
- * @returns {string} Modified CSS declaration with opacity applied
6681
+ /**
6682
+ * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6683
+ * @param {string} className - Class name with potential opacity modifier
6684
+ * @param {string} cssDeclaration - CSS declaration to modify
6685
+ * @returns {string} Modified CSS declaration with opacity applied
6686
6686
  */
6687
6687
  function processOpacityModifier(className, cssDeclaration) {
6688
6688
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6743,11 +6743,11 @@ function processOpacityModifier(className, cssDeclaration) {
6743
6743
  return modifiedDeclaration;
6744
6744
  }
6745
6745
 
6746
- /**
6747
- * Convert Tailwind class string to inline CSS styles or JSON object
6748
- * @param {string} classNames - String containing Tailwind classes to convert
6749
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6750
- * @returns {string|Object} Inline CSS string or style JSON object
6746
+ /**
6747
+ * Convert Tailwind class string to inline CSS styles or JSON object
6748
+ * @param {string} classNames - String containing Tailwind classes to convert
6749
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6750
+ * @returns {string|Object} Inline CSS string or style JSON object
6751
6751
  */
6752
6752
  function tws(classNames, convertToJson) {
6753
6753
  const totalMarker = performanceMonitor.start("tws:total");
@@ -6778,11 +6778,29 @@ function tws(classNames, convertToJson) {
6778
6778
  const processMarker = performanceMonitor.start("tws:process");
6779
6779
  let cssResult = classes.map(className => {
6780
6780
  // Extract base class name without opacity modifier
6781
- const baseClassName = className.replace(/\/\d+$/, "");
6782
- let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6781
+ // Only remove /digits if it's an opacity modifier (not a fraction like w-2/3)
6782
+ // Opacity modifiers are typically /0-100, fractions are /2, /3, /4, /5, /6, /12
6783
+ const opacityMatch = className.match(/\/(\d+)$/);
6784
+ let baseClassName = className;
6785
+ let hasOpacityModifier = false;
6786
+ if (opacityMatch) {
6787
+ const opacityValue = parseInt(opacityMatch[1], 10);
6788
+ // If it's a valid opacity value (0-100), treat it as opacity modifier
6789
+ if (opacityValue >= 0 && opacityValue <= 100) {
6790
+ // Check if this could be a fraction (e.g., w-2/3, h-1/2)
6791
+ // Fractions typically have denominators of 2, 3, 4, 5, 6, 12
6792
+ const fractionDenominators = [2, 3, 4, 5, 6, 12];
6793
+ const couldBeFraction = fractionDenominators.includes(opacityValue) && (className.startsWith('w-') || className.startsWith('h-') || className.startsWith('max-w-') || className.startsWith('max-h-') || className.startsWith('min-w-') || className.startsWith('min-h-'));
6794
+ if (!couldBeFraction) {
6795
+ baseClassName = className.replace(/\/\d+$/, "");
6796
+ hasOpacityModifier = true;
6797
+ }
6798
+ }
6799
+ }
6800
+ let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/\//g, "\\/")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6783
6801
  if (result) {
6784
6802
  // Apply opacity modifier if present
6785
- if (className.includes("/") && /\/\d+$/.test(className)) {
6803
+ if (hasOpacityModifier && className.includes("/") && /\/\d+$/.test(className)) {
6786
6804
  result = processOpacityModifier(className, result);
6787
6805
  }
6788
6806
  return resolveCssToClearCss(result);
@@ -6794,7 +6812,7 @@ function tws(classNames, convertToJson) {
6794
6812
  if (cssObject[`${baseKey}custom`]) {
6795
6813
  let customResult = cssObject[`${baseKey}custom`].replace(/custom_value/g, customValue);
6796
6814
  // Apply opacity modifier to custom values too
6797
- if (className.includes("/") && /\/\d+$/.test(className)) {
6815
+ if (hasOpacityModifier && className.includes("/") && /\/\d+$/.test(className)) {
6798
6816
  customResult = processOpacityModifier(className, customResult);
6799
6817
  }
6800
6818
  return customResult;
@@ -6930,7 +6948,23 @@ function processClass(cls, selector, styles) {
6930
6948
  } = resolveVariants(selector, rawVariants);
6931
6949
 
6932
6950
  // Extract base class name without opacity modifier for CSS lookup
6933
- const baseClassName = pureClassName.replace(/\/\d+$/, "");
6951
+ // Only remove /digits if it's an opacity modifier (not a fraction like w-2/3)
6952
+ const opacityMatch = pureClassName.match(/\/(\d+)$/);
6953
+ let baseClassName = pureClassName;
6954
+ let hasOpacityModifier = false;
6955
+ if (opacityMatch) {
6956
+ const opacityValue = parseInt(opacityMatch[1], 10);
6957
+ // If it's a valid opacity value (0-100), treat it as opacity modifier
6958
+ if (opacityValue >= 0 && opacityValue <= 100) {
6959
+ // Check if this could be a fraction (e.g., w-2/3, h-1/2)
6960
+ const fractionDenominators = [2, 3, 4, 5, 6, 12];
6961
+ const couldBeFraction = fractionDenominators.includes(opacityValue) && (pureClassName.startsWith('w-') || pureClassName.startsWith('h-') || pureClassName.startsWith('max-w-') || pureClassName.startsWith('max-h-') || pureClassName.startsWith('min-w-') || pureClassName.startsWith('min-h-'));
6962
+ if (!couldBeFraction) {
6963
+ baseClassName = pureClassName.replace(/\/\d+$/, "");
6964
+ hasOpacityModifier = true;
6965
+ }
6966
+ }
6967
+ }
6934
6968
  let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6935
6969
  if (!declarations && baseClassName.includes("[")) {
6936
6970
  const match = baseClassName.match(/^(.+?)\[(.+)\]$/);
@@ -6951,7 +6985,7 @@ function processClass(cls, selector, styles) {
6951
6985
  }
6952
6986
 
6953
6987
  // Apply opacity modifier if present
6954
- if (pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
6988
+ if (hasOpacityModifier && pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
6955
6989
  declarations = processOpacityModifier(pureClassName, declarations);
6956
6990
  }
6957
6991
  if (isImportant) {
@@ -7126,12 +7160,12 @@ function generateCssString(styles) {
7126
7160
  return cssString.trim();
7127
7161
  }
7128
7162
 
7129
- /**
7130
- * Generate CSS string from style object with SCSS-like syntax
7131
- * Supports nested selectors, state variants, responsive variants, and @css directives
7132
- * @param {Object} obj - Object with SCSS-like style format
7133
- * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7134
- * @returns {string} Generated CSS string
7163
+ /**
7164
+ * Generate CSS string from style object with SCSS-like syntax
7165
+ * Supports nested selectors, state variants, responsive variants, and @css directives
7166
+ * @param {Object} obj - Object with SCSS-like style format
7167
+ * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7168
+ * @returns {string} Generated CSS string
7135
7169
  */
7136
7170
  function twsx(obj) {
7137
7171
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7238,19 +7272,19 @@ function autoInjectCss(cssString) {
7238
7272
  }
7239
7273
 
7240
7274
  // Enhanced debounced functions with performance monitoring configuration
7241
- /**
7242
- * Debounced version of tws function with performance monitoring
7243
- * @param {string} classNames - String containing Tailwind classes to convert
7244
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7245
- * @returns {string|Object} Inline CSS string or style JSON object
7275
+ /**
7276
+ * Debounced version of tws function with performance monitoring
7277
+ * @param {string} classNames - String containing Tailwind classes to convert
7278
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7279
+ * @returns {string|Object} Inline CSS string or style JSON object
7246
7280
  */
7247
7281
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7248
7282
 
7249
- /**
7250
- * Debounced version of twsx function with performance monitoring
7251
- * @param {Object} obj - Object with SCSS-like style format
7252
- * @param {Object} [options] - Additional options
7253
- * @returns {string} Generated CSS string
7283
+ /**
7284
+ * Debounced version of twsx function with performance monitoring
7285
+ * @param {Object} obj - Object with SCSS-like style format
7286
+ * @param {Object} [options] - Additional options
7287
+ * @returns {string} Generated CSS string
7254
7288
  */
7255
7289
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7256
7290