tailwind-to-style 2.7.0 → 2.7.2
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/README.md +77 -25
- package/dist/index.browser.js +126 -42
- package/dist/index.cjs.js +126 -42
- package/dist/index.d.ts +82 -0
- package/dist/index.esm.js +126 -42
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +2 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tailwind-to-style v2.7.
|
|
2
|
+
* tailwind-to-style v2.7.2
|
|
3
3
|
* Convert tailwind classes to inline style
|
|
4
4
|
*
|
|
5
5
|
* @author Bigetion
|
|
@@ -6339,13 +6339,13 @@ function resolveCssToClearCss(cssString) {
|
|
|
6339
6339
|
}).join(" ");
|
|
6340
6340
|
}
|
|
6341
6341
|
|
|
6342
|
-
// Cache
|
|
6342
|
+
// Cache for getConfigOptions
|
|
6343
6343
|
const configOptionsCache = new Map();
|
|
6344
6344
|
const cacheKey = options => JSON.stringify(options);
|
|
6345
6345
|
function generateTailwindCssString() {
|
|
6346
6346
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6347
6347
|
const pluginKeys = Object.keys(plugins);
|
|
6348
|
-
//
|
|
6348
|
+
// Use cache to prevent unnecessary reprocessing
|
|
6349
6349
|
const key = cacheKey(options);
|
|
6350
6350
|
if (!configOptionsCache.has(key)) {
|
|
6351
6351
|
configOptionsCache.set(key, getConfigOptions(options, pluginKeys));
|
|
@@ -6406,7 +6406,7 @@ const selectorVariants = {
|
|
|
6406
6406
|
number: arg => `> :nth-child(${arg})`
|
|
6407
6407
|
};
|
|
6408
6408
|
|
|
6409
|
-
//
|
|
6409
|
+
// Optimize encoding/decoding bracket values with memoization
|
|
6410
6410
|
const encodeBracketCache = new Map();
|
|
6411
6411
|
function encodeBracketValues(input) {
|
|
6412
6412
|
if (!input) return input;
|
|
@@ -6473,7 +6473,7 @@ function inlineStyleToJson(styleString) {
|
|
|
6473
6473
|
return styleObject;
|
|
6474
6474
|
}
|
|
6475
6475
|
|
|
6476
|
-
// Cache
|
|
6476
|
+
// Cache for CSS resolution
|
|
6477
6477
|
const cssResolutionCache = new Map();
|
|
6478
6478
|
|
|
6479
6479
|
// Enhanced cache management with performance monitoring
|
|
@@ -6481,7 +6481,7 @@ function limitCacheSize(cache) {
|
|
|
6481
6481
|
let maxSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
6482
6482
|
if (cache.size > maxSize) {
|
|
6483
6483
|
const cleanupMarker = performanceMonitor.start("cache:cleanup");
|
|
6484
|
-
//
|
|
6484
|
+
// Remove 20% of the oldest entries
|
|
6485
6485
|
const entriesToRemove = Math.floor(cache.size * 0.2);
|
|
6486
6486
|
const keys = Array.from(cache.keys()).slice(0, entriesToRemove);
|
|
6487
6487
|
keys.forEach(key => cache.delete(key));
|
|
@@ -6520,14 +6520,14 @@ function debounce(func) {
|
|
|
6520
6520
|
function separateAndResolveCSS(arr) {
|
|
6521
6521
|
const marker = performanceMonitor.start("css:resolve");
|
|
6522
6522
|
try {
|
|
6523
|
-
//
|
|
6523
|
+
// Fix: cacheKey must be unique for each input array
|
|
6524
6524
|
const cacheKey = Array.isArray(arr) ? arr.join("|") : String(arr);
|
|
6525
6525
|
if (cssResolutionCache.has(cacheKey)) {
|
|
6526
6526
|
performanceMonitor.end(marker);
|
|
6527
6527
|
return cssResolutionCache.get(cacheKey);
|
|
6528
6528
|
}
|
|
6529
6529
|
|
|
6530
|
-
//
|
|
6530
|
+
// Limit cache size to avoid memory leaks
|
|
6531
6531
|
limitCacheSize(cssResolutionCache);
|
|
6532
6532
|
const cssProperties = {};
|
|
6533
6533
|
arr.forEach(item => {
|
|
@@ -6540,7 +6540,7 @@ function separateAndResolveCSS(arr) {
|
|
|
6540
6540
|
const key = declaration.substring(0, colonIndex).trim();
|
|
6541
6541
|
const value = declaration.substring(colonIndex + 1).trim();
|
|
6542
6542
|
if (key && value) {
|
|
6543
|
-
//
|
|
6543
|
+
// Prioritize more specific values (e.g., !important)
|
|
6544
6544
|
if (value.includes("!important") || !cssProperties[key]) {
|
|
6545
6545
|
cssProperties[key] = value;
|
|
6546
6546
|
}
|
|
@@ -6591,10 +6591,75 @@ function separateAndResolveCSS(arr) {
|
|
|
6591
6591
|
}
|
|
6592
6592
|
|
|
6593
6593
|
/**
|
|
6594
|
-
*
|
|
6595
|
-
* @param {string}
|
|
6596
|
-
* @param {
|
|
6597
|
-
* @returns {string
|
|
6594
|
+
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6595
|
+
* @param {string} className - Class name with potential opacity modifier
|
|
6596
|
+
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6597
|
+
* @returns {string} Modified CSS declaration with opacity applied
|
|
6598
|
+
*/
|
|
6599
|
+
function processOpacityModifier(className, cssDeclaration) {
|
|
6600
|
+
const opacityMatch = className.match(/\/(\d+)$/);
|
|
6601
|
+
if (!opacityMatch) return cssDeclaration;
|
|
6602
|
+
const opacityValue = parseInt(opacityMatch[1], 10);
|
|
6603
|
+
if (opacityValue < 0 || opacityValue > 100) return cssDeclaration;
|
|
6604
|
+
const alphaValue = (opacityValue / 100).toString();
|
|
6605
|
+
|
|
6606
|
+
// Handle Tailwind's CSS custom property pattern
|
|
6607
|
+
let modifiedDeclaration = cssDeclaration;
|
|
6608
|
+
|
|
6609
|
+
// Replace opacity custom properties
|
|
6610
|
+
const opacityProperties = ['--text-opacity', '--bg-opacity', '--border-opacity', '--ring-opacity', '--divide-opacity', '--placeholder-opacity', '--text-decoration-opacity', '--outline-opacity', '--accent-opacity', '--caret-opacity'];
|
|
6611
|
+
opacityProperties.forEach(prop => {
|
|
6612
|
+
const propRegex = new RegExp(`${prop}\\s*:\\s*[\\d.]+`, 'gi');
|
|
6613
|
+
modifiedDeclaration = modifiedDeclaration.replace(propRegex, `${prop}: ${alphaValue}`);
|
|
6614
|
+
});
|
|
6615
|
+
|
|
6616
|
+
// Also handle direct color values that might not use CSS variables
|
|
6617
|
+
const colorProperties = ['color', 'background-color', 'border-color', 'text-decoration-color', 'outline-color', 'fill', 'stroke', 'caret-color', 'accent-color'];
|
|
6618
|
+
colorProperties.forEach(prop => {
|
|
6619
|
+
// Match rgb(), rgba(), hsl(), hsla() functions
|
|
6620
|
+
const rgbRegex = new RegExp(`(${prop}\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)`, 'gi');
|
|
6621
|
+
const rgbaRegex = new RegExp(`(${prop}\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)`, 'gi');
|
|
6622
|
+
const hslRegex = new RegExp(`(${prop}\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)`, 'gi');
|
|
6623
|
+
const hslaRegex = new RegExp(`(${prop}\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)`, 'gi');
|
|
6624
|
+
|
|
6625
|
+
// Convert rgb to rgba with opacity
|
|
6626
|
+
modifiedDeclaration = modifiedDeclaration.replace(rgbRegex, `$1rgba($2, $3, $4, ${alphaValue})`);
|
|
6627
|
+
|
|
6628
|
+
// Update existing rgba opacity
|
|
6629
|
+
modifiedDeclaration = modifiedDeclaration.replace(rgbaRegex, `$1rgba($2, $3, $4, ${alphaValue})`);
|
|
6630
|
+
|
|
6631
|
+
// Convert hsl to hsla with opacity
|
|
6632
|
+
modifiedDeclaration = modifiedDeclaration.replace(hslRegex, `$1hsla($2, $3, $4, ${alphaValue})`);
|
|
6633
|
+
|
|
6634
|
+
// Update existing hsla opacity
|
|
6635
|
+
modifiedDeclaration = modifiedDeclaration.replace(hslaRegex, `$1hsla($2, $3, $4, ${alphaValue})`);
|
|
6636
|
+
|
|
6637
|
+
// Handle hex colors
|
|
6638
|
+
const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, 'gi');
|
|
6639
|
+
modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
|
|
6640
|
+
// Convert hex to rgba
|
|
6641
|
+
const hex = hexColor.replace('#', '');
|
|
6642
|
+
let r, g, b;
|
|
6643
|
+
if (hex.length === 3) {
|
|
6644
|
+
r = parseInt(hex[0] + hex[0], 16);
|
|
6645
|
+
g = parseInt(hex[1] + hex[1], 16);
|
|
6646
|
+
b = parseInt(hex[2] + hex[2], 16);
|
|
6647
|
+
} else {
|
|
6648
|
+
r = parseInt(hex.substring(0, 2), 16);
|
|
6649
|
+
g = parseInt(hex.substring(2, 4), 16);
|
|
6650
|
+
b = parseInt(hex.substring(4, 6), 16);
|
|
6651
|
+
}
|
|
6652
|
+
return `${propPart}rgba(${r}, ${g}, ${b}, ${alphaValue})`;
|
|
6653
|
+
});
|
|
6654
|
+
});
|
|
6655
|
+
return modifiedDeclaration;
|
|
6656
|
+
}
|
|
6657
|
+
|
|
6658
|
+
/**
|
|
6659
|
+
* Convert Tailwind class string to inline CSS styles or JSON object
|
|
6660
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
6661
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
6662
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
6598
6663
|
*/
|
|
6599
6664
|
function tws(classNames, convertToJson) {
|
|
6600
6665
|
const totalMarker = performanceMonitor.start("tws:total");
|
|
@@ -6606,10 +6671,10 @@ function tws(classNames, convertToJson) {
|
|
|
6606
6671
|
let classes;
|
|
6607
6672
|
try {
|
|
6608
6673
|
const parseMarker = performanceMonitor.start("tws:parse");
|
|
6609
|
-
classes = classNames.match(/[\w-\/]+(?:\[[^\]]+\])?/g);
|
|
6674
|
+
classes = classNames.match(/[\w-\/]+(?:\/\d+)?(?:\[[^\]]+\])?/g);
|
|
6610
6675
|
performanceMonitor.end(parseMarker);
|
|
6611
6676
|
|
|
6612
|
-
//
|
|
6677
|
+
// If no valid classes are found
|
|
6613
6678
|
if (!classes || classes.length === 0) {
|
|
6614
6679
|
console.warn(`No valid Tailwind classes found in input: "${classNames}"`);
|
|
6615
6680
|
performanceMonitor.end(totalMarker);
|
|
@@ -6624,16 +6689,27 @@ function tws(classNames, convertToJson) {
|
|
|
6624
6689
|
// Process classes with performance monitoring
|
|
6625
6690
|
const processMarker = performanceMonitor.start("tws:process");
|
|
6626
6691
|
let cssResult = classes.map(className => {
|
|
6627
|
-
|
|
6692
|
+
// Extract base class name without opacity modifier
|
|
6693
|
+
const baseClassName = className.replace(/\/\d+$/, '');
|
|
6694
|
+
let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
|
|
6628
6695
|
if (result) {
|
|
6696
|
+
// Apply opacity modifier if present
|
|
6697
|
+
if (className.includes('/') && /\/\d+$/.test(className)) {
|
|
6698
|
+
result = processOpacityModifier(className, result);
|
|
6699
|
+
}
|
|
6629
6700
|
return resolveCssToClearCss(result);
|
|
6630
|
-
} else if (
|
|
6631
|
-
const match =
|
|
6701
|
+
} else if (baseClassName.includes("[")) {
|
|
6702
|
+
const match = baseClassName.match(/\[([^\]]+)\]/);
|
|
6632
6703
|
if (match) {
|
|
6633
6704
|
const customValue = match[1];
|
|
6634
|
-
const baseKey =
|
|
6705
|
+
const baseKey = baseClassName.split("[")[0];
|
|
6635
6706
|
if (cssObject[`${baseKey}custom`]) {
|
|
6636
|
-
|
|
6707
|
+
let customResult = cssObject[`${baseKey}custom`].replace(/custom_value/g, customValue);
|
|
6708
|
+
// Apply opacity modifier to custom values too
|
|
6709
|
+
if (className.includes('/') && /\/\d+$/.test(className)) {
|
|
6710
|
+
customResult = processOpacityModifier(className, customResult);
|
|
6711
|
+
}
|
|
6712
|
+
return customResult;
|
|
6637
6713
|
}
|
|
6638
6714
|
}
|
|
6639
6715
|
}
|
|
@@ -6764,9 +6840,12 @@ function processClass(cls, selector, styles) {
|
|
|
6764
6840
|
media,
|
|
6765
6841
|
finalSelector
|
|
6766
6842
|
} = resolveVariants(selector, rawVariants);
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6843
|
+
|
|
6844
|
+
// Extract base class name without opacity modifier for CSS lookup
|
|
6845
|
+
const baseClassName = pureClassName.replace(/\/\d+$/, '');
|
|
6846
|
+
let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
|
|
6847
|
+
if (!declarations && baseClassName.includes("[")) {
|
|
6848
|
+
const match = baseClassName.match(/^(.+?)\[(.+)\]$/);
|
|
6770
6849
|
if (match) {
|
|
6771
6850
|
const [, prefix, dynamicValue] = match;
|
|
6772
6851
|
const customKey = `${prefix}custom`;
|
|
@@ -6777,17 +6856,22 @@ function processClass(cls, selector, styles) {
|
|
|
6777
6856
|
}
|
|
6778
6857
|
}
|
|
6779
6858
|
if (!declarations) {
|
|
6780
|
-
declarations = parseCustomClassWithPatterns(
|
|
6859
|
+
declarations = parseCustomClassWithPatterns(baseClassName);
|
|
6781
6860
|
}
|
|
6782
6861
|
if (!declarations) {
|
|
6783
6862
|
return;
|
|
6784
6863
|
}
|
|
6864
|
+
|
|
6865
|
+
// Apply opacity modifier if present
|
|
6866
|
+
if (pureClassName.includes('/') && /\/\d+$/.test(pureClassName)) {
|
|
6867
|
+
declarations = processOpacityModifier(pureClassName, declarations);
|
|
6868
|
+
}
|
|
6785
6869
|
if (isImportant) {
|
|
6786
6870
|
declarations = declarations.replace(/([^:;]+):([^;]+)(;?)/g, (_, prop, value) => {
|
|
6787
6871
|
return prop.trim().startsWith("--") ? `${prop}:${value};` : `${prop}:${value.trim()} !important;`;
|
|
6788
6872
|
});
|
|
6789
6873
|
}
|
|
6790
|
-
const isSpaceOrDivide = ["space-x-", "-space-x-", "space-y-", "-space-y-", "divide-"].some(prefix =>
|
|
6874
|
+
const isSpaceOrDivide = ["space-x-", "-space-x-", "space-y-", "-space-y-", "divide-"].some(prefix => baseClassName.startsWith(prefix));
|
|
6791
6875
|
const expandedSelector = replaceSelector(finalSelector);
|
|
6792
6876
|
const targetSelector = isSpaceOrDivide ? `${expandedSelector} > :not([hidden]) ~ :not([hidden])` : expandedSelector;
|
|
6793
6877
|
if (media) {
|
|
@@ -6955,11 +7039,11 @@ function generateCssString(styles) {
|
|
|
6955
7039
|
}
|
|
6956
7040
|
|
|
6957
7041
|
/**
|
|
6958
|
-
*
|
|
6959
|
-
*
|
|
6960
|
-
* @param {Object} obj -
|
|
6961
|
-
* @param {Object} [options] -
|
|
6962
|
-
* @returns {string}
|
|
7042
|
+
* Generate CSS string from style object with SCSS-like syntax
|
|
7043
|
+
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
7044
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7045
|
+
* @param {Object} [options] - Additional options, e.g. { inject: true/false }
|
|
7046
|
+
* @returns {string} Generated CSS string
|
|
6963
7047
|
*/
|
|
6964
7048
|
function twsx(obj) {
|
|
6965
7049
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -7019,7 +7103,7 @@ function twsx(obj) {
|
|
|
7019
7103
|
}
|
|
7020
7104
|
}
|
|
7021
7105
|
|
|
7022
|
-
//
|
|
7106
|
+
// Simple hashCode function for CSS deduplication
|
|
7023
7107
|
function getCssHash(str) {
|
|
7024
7108
|
let hash = 0,
|
|
7025
7109
|
i,
|
|
@@ -7033,7 +7117,7 @@ function getCssHash(str) {
|
|
|
7033
7117
|
return hash;
|
|
7034
7118
|
}
|
|
7035
7119
|
|
|
7036
|
-
// Enhanced auto-inject CSS
|
|
7120
|
+
// Enhanced auto-inject CSS with performance monitoring
|
|
7037
7121
|
const injectedCssHashSet = new Set();
|
|
7038
7122
|
function autoInjectCss(cssString) {
|
|
7039
7123
|
const marker = performanceMonitor.start("css:inject");
|
|
@@ -7065,24 +7149,24 @@ function autoInjectCss(cssString) {
|
|
|
7065
7149
|
}
|
|
7066
7150
|
}
|
|
7067
7151
|
|
|
7068
|
-
// Enhanced debounced functions
|
|
7152
|
+
// Enhanced debounced functions with performance monitoring configuration
|
|
7069
7153
|
/**
|
|
7070
|
-
*
|
|
7071
|
-
* @param {string} classNames - String
|
|
7072
|
-
* @param {boolean} convertToJson -
|
|
7073
|
-
* @returns {string|Object}
|
|
7154
|
+
* Debounced version of tws function with performance monitoring
|
|
7155
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
7156
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
7157
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
7074
7158
|
*/
|
|
7075
7159
|
const debouncedTws = debounce(tws, 50); // Faster debounce for tws
|
|
7076
7160
|
|
|
7077
7161
|
/**
|
|
7078
|
-
*
|
|
7079
|
-
* @param {Object} obj -
|
|
7080
|
-
* @param {Object} [options] -
|
|
7081
|
-
* @returns {string}
|
|
7162
|
+
* Debounced version of twsx function with performance monitoring
|
|
7163
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7164
|
+
* @param {Object} [options] - Additional options
|
|
7165
|
+
* @returns {string} Generated CSS string
|
|
7082
7166
|
*/
|
|
7083
7167
|
const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
|
|
7084
7168
|
|
|
7085
|
-
// Export performance utilities
|
|
7169
|
+
// Export performance utilities for debugging
|
|
7086
7170
|
const performanceUtils = {
|
|
7087
7171
|
getStats() {
|
|
7088
7172
|
return {
|