tailwind-to-style 2.7.1 → 2.7.3
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.browser.js +262 -72
- package/dist/{index.cjs.js → index.cjs} +262 -72
- package/dist/index.d.ts +32 -7
- package/dist/index.esm.js +260 -73
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +2 -2
package/dist/index.browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tailwind-to-style v2.7.
|
|
2
|
+
* tailwind-to-style v2.7.3
|
|
3
3
|
* Convert tailwind classes to inline style
|
|
4
4
|
*
|
|
5
5
|
* @author Bigetion
|
|
@@ -1532,12 +1532,10 @@ var tailwindToStyle = (function (exports) {
|
|
|
1532
1532
|
const themeKeys = Object.keys(configOptions.theme);
|
|
1533
1533
|
themeKeys.forEach(key => {
|
|
1534
1534
|
newTheme[key] = theme[key] || configOptions.theme[key];
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1540
|
-
});
|
|
1535
|
+
});
|
|
1536
|
+
themeKeys.forEach(key => {
|
|
1537
|
+
if (themeExtend[key] && newTheme[key]) {
|
|
1538
|
+
newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
|
|
1541
1539
|
}
|
|
1542
1540
|
});
|
|
1543
1541
|
themeKeys.forEach(key => {
|
|
@@ -1548,9 +1546,6 @@ var tailwindToStyle = (function (exports) {
|
|
|
1548
1546
|
}
|
|
1549
1547
|
});
|
|
1550
1548
|
}
|
|
1551
|
-
if (themeExtend[key]) {
|
|
1552
|
-
newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
|
|
1553
|
-
}
|
|
1554
1549
|
});
|
|
1555
1550
|
return {
|
|
1556
1551
|
prefix: "",
|
|
@@ -6312,10 +6307,10 @@ var tailwindToStyle = (function (exports) {
|
|
|
6312
6307
|
return null;
|
|
6313
6308
|
}
|
|
6314
6309
|
|
|
6315
|
-
/**
|
|
6316
|
-
* Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
|
|
6317
|
-
* @param {string} cssString
|
|
6318
|
-
* @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
|
|
6310
|
+
/**
|
|
6311
|
+
* Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
|
|
6312
|
+
* @param {string} cssString
|
|
6313
|
+
* @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
|
|
6319
6314
|
*/
|
|
6320
6315
|
function resolveCssToClearCss(cssString) {
|
|
6321
6316
|
const customVars = {};
|
|
@@ -6342,13 +6337,13 @@ var tailwindToStyle = (function (exports) {
|
|
|
6342
6337
|
}).join(" ");
|
|
6343
6338
|
}
|
|
6344
6339
|
|
|
6345
|
-
// Cache
|
|
6340
|
+
// Cache for getConfigOptions
|
|
6346
6341
|
const configOptionsCache = new Map();
|
|
6347
6342
|
const cacheKey = options => JSON.stringify(options);
|
|
6348
6343
|
function generateTailwindCssString() {
|
|
6349
6344
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6350
6345
|
const pluginKeys = Object.keys(plugins);
|
|
6351
|
-
//
|
|
6346
|
+
// Use cache to prevent unnecessary reprocessing
|
|
6352
6347
|
const key = cacheKey(options);
|
|
6353
6348
|
if (!configOptionsCache.has(key)) {
|
|
6354
6349
|
configOptionsCache.set(key, getConfigOptions(options, pluginKeys));
|
|
@@ -6382,19 +6377,120 @@ var tailwindToStyle = (function (exports) {
|
|
|
6382
6377
|
}
|
|
6383
6378
|
let twString = null;
|
|
6384
6379
|
let cssObject = null;
|
|
6385
|
-
|
|
6386
|
-
|
|
6380
|
+
let globalConfig = {
|
|
6381
|
+
theme: {
|
|
6382
|
+
extend: {
|
|
6383
|
+
colors: {}
|
|
6384
|
+
},
|
|
6385
|
+
screens: {
|
|
6386
|
+
sm: "640px",
|
|
6387
|
+
md: "768px",
|
|
6388
|
+
lg: "1024px",
|
|
6389
|
+
xl: "1280px",
|
|
6390
|
+
"2xl": "1536px"
|
|
6391
|
+
}
|
|
6392
|
+
},
|
|
6393
|
+
inject: true
|
|
6394
|
+
};
|
|
6395
|
+
function initializeCss() {
|
|
6396
|
+
if (!twString) {
|
|
6397
|
+
const configForGeneration = {
|
|
6398
|
+
...globalConfig,
|
|
6399
|
+
theme: {
|
|
6400
|
+
...globalConfig.theme
|
|
6401
|
+
}
|
|
6402
|
+
};
|
|
6403
|
+
twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
|
|
6404
|
+
}
|
|
6405
|
+
if (!cssObject) {
|
|
6406
|
+
cssObject = convertCssToObject(twString);
|
|
6407
|
+
}
|
|
6387
6408
|
}
|
|
6388
|
-
|
|
6409
|
+
initializeCss();
|
|
6410
|
+
function convertScreensToBreakpoints(screens) {
|
|
6411
|
+
const breakpoints = {};
|
|
6412
|
+
for (const [key, value] of Object.entries(screens)) {
|
|
6413
|
+
breakpoints[key] = `@media (min-width: ${value})`;
|
|
6414
|
+
}
|
|
6415
|
+
return breakpoints;
|
|
6416
|
+
}
|
|
6417
|
+
|
|
6418
|
+
/**
|
|
6419
|
+
* Set global configuration for both tws and twsx functions
|
|
6420
|
+
* @param {Object} config - Global configuration object
|
|
6421
|
+
* @returns {Object} Current global configuration
|
|
6422
|
+
*/
|
|
6423
|
+
function setConfig(config) {
|
|
6424
|
+
var _config$theme, _config$theme2, _config$theme2$extend, _config$theme3;
|
|
6425
|
+
// Reset CSS object cache when config changes
|
|
6426
|
+
twString = null;
|
|
6427
|
+
cssObject = null;
|
|
6428
|
+
configOptionsCache.clear();
|
|
6429
|
+
globalConfig = {
|
|
6430
|
+
...globalConfig,
|
|
6431
|
+
...config,
|
|
6432
|
+
theme: {
|
|
6433
|
+
...globalConfig.theme,
|
|
6434
|
+
...(config.theme || {}),
|
|
6435
|
+
extend: {
|
|
6436
|
+
...globalConfig.theme.extend,
|
|
6437
|
+
...(((_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.extend) || {}),
|
|
6438
|
+
colors: {
|
|
6439
|
+
...globalConfig.theme.extend.colors,
|
|
6440
|
+
...(((_config$theme2 = config.theme) === null || _config$theme2 === void 0 ? void 0 : (_config$theme2$extend = _config$theme2.extend) === null || _config$theme2$extend === void 0 ? void 0 : _config$theme2$extend.colors) || {})
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
}
|
|
6444
|
+
};
|
|
6445
|
+
|
|
6446
|
+
// Handle screens configuration
|
|
6447
|
+
if ((_config$theme3 = config.theme) !== null && _config$theme3 !== void 0 && _config$theme3.screens) {
|
|
6448
|
+
globalConfig.theme.screens = {
|
|
6449
|
+
...globalConfig.theme.screens,
|
|
6450
|
+
...config.theme.screens
|
|
6451
|
+
};
|
|
6452
|
+
}
|
|
6453
|
+
initializeCss();
|
|
6454
|
+
return globalConfig;
|
|
6455
|
+
}
|
|
6456
|
+
|
|
6457
|
+
/**
|
|
6458
|
+
* Get current global configuration
|
|
6459
|
+
* @returns {Object} Current global configuration
|
|
6460
|
+
*/
|
|
6461
|
+
function getConfig() {
|
|
6462
|
+
return {
|
|
6463
|
+
...globalConfig
|
|
6464
|
+
};
|
|
6465
|
+
}
|
|
6466
|
+
|
|
6467
|
+
/**
|
|
6468
|
+
* Reset global configuration to default
|
|
6469
|
+
* @returns {Object} Default configuration
|
|
6470
|
+
*/
|
|
6471
|
+
function resetConfig() {
|
|
6472
|
+
twString = null;
|
|
6473
|
+
cssObject = null;
|
|
6474
|
+
configOptionsCache.clear();
|
|
6475
|
+
globalConfig = {
|
|
6476
|
+
theme: {
|
|
6477
|
+
extend: {
|
|
6478
|
+
colors: {}
|
|
6479
|
+
},
|
|
6480
|
+
screens: {
|
|
6481
|
+
sm: "640px",
|
|
6482
|
+
md: "768px",
|
|
6483
|
+
lg: "1024px",
|
|
6484
|
+
xl: "1280px",
|
|
6485
|
+
"2xl": "1536px"
|
|
6486
|
+
}
|
|
6487
|
+
},
|
|
6488
|
+
inject: true
|
|
6489
|
+
};
|
|
6490
|
+
twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
|
|
6389
6491
|
cssObject = convertCssToObject(twString);
|
|
6492
|
+
return globalConfig;
|
|
6390
6493
|
}
|
|
6391
|
-
const breakpoints = {
|
|
6392
|
-
sm: "@media (min-width: 640px)",
|
|
6393
|
-
md: "@media (min-width: 768px)",
|
|
6394
|
-
lg: "@media (min-width: 1024px)",
|
|
6395
|
-
xl: "@media (min-width: 1280px)",
|
|
6396
|
-
"2xl": "@media (min-width: 1536px)"
|
|
6397
|
-
};
|
|
6398
6494
|
const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
|
|
6399
6495
|
const specialVariants = {
|
|
6400
6496
|
group: (state, sel) => `.group:${state} ${sel}`,
|
|
@@ -6409,7 +6505,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6409
6505
|
number: arg => `> :nth-child(${arg})`
|
|
6410
6506
|
};
|
|
6411
6507
|
|
|
6412
|
-
//
|
|
6508
|
+
// Optimize encoding/decoding bracket values with memoization
|
|
6413
6509
|
const encodeBracketCache = new Map();
|
|
6414
6510
|
function encodeBracketValues(input) {
|
|
6415
6511
|
if (!input) return input;
|
|
@@ -6444,6 +6540,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6444
6540
|
let media = null;
|
|
6445
6541
|
let finalSelector = selector;
|
|
6446
6542
|
for (const v of variants) {
|
|
6543
|
+
const breakpoints = convertScreensToBreakpoints(globalConfig.theme.screens || {});
|
|
6447
6544
|
if (breakpoints[v]) {
|
|
6448
6545
|
media = breakpoints[v];
|
|
6449
6546
|
} else if (pseudoVariants.has(v)) {
|
|
@@ -6476,7 +6573,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6476
6573
|
return styleObject;
|
|
6477
6574
|
}
|
|
6478
6575
|
|
|
6479
|
-
// Cache
|
|
6576
|
+
// Cache for CSS resolution
|
|
6480
6577
|
const cssResolutionCache = new Map();
|
|
6481
6578
|
|
|
6482
6579
|
// Enhanced cache management with performance monitoring
|
|
@@ -6484,7 +6581,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6484
6581
|
let maxSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
|
|
6485
6582
|
if (cache.size > maxSize) {
|
|
6486
6583
|
const cleanupMarker = performanceMonitor.start("cache:cleanup");
|
|
6487
|
-
//
|
|
6584
|
+
// Remove 20% of the oldest entries
|
|
6488
6585
|
const entriesToRemove = Math.floor(cache.size * 0.2);
|
|
6489
6586
|
const keys = Array.from(cache.keys()).slice(0, entriesToRemove);
|
|
6490
6587
|
keys.forEach(key => cache.delete(key));
|
|
@@ -6505,7 +6602,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6505
6602
|
callCount++;
|
|
6506
6603
|
clearTimeout(timeout);
|
|
6507
6604
|
timeout = setTimeout(() => {
|
|
6508
|
-
const marker = performanceMonitor.start(`debounced:${func.name ||
|
|
6605
|
+
const marker = performanceMonitor.start(`debounced:${func.name || "anonymous"}`);
|
|
6509
6606
|
try {
|
|
6510
6607
|
const result = func.apply(context, args);
|
|
6511
6608
|
performanceMonitor.end(marker);
|
|
@@ -6523,14 +6620,14 @@ var tailwindToStyle = (function (exports) {
|
|
|
6523
6620
|
function separateAndResolveCSS(arr) {
|
|
6524
6621
|
const marker = performanceMonitor.start("css:resolve");
|
|
6525
6622
|
try {
|
|
6526
|
-
//
|
|
6623
|
+
// Fix: cacheKey must be unique for each input array
|
|
6527
6624
|
const cacheKey = Array.isArray(arr) ? arr.join("|") : String(arr);
|
|
6528
6625
|
if (cssResolutionCache.has(cacheKey)) {
|
|
6529
6626
|
performanceMonitor.end(marker);
|
|
6530
6627
|
return cssResolutionCache.get(cacheKey);
|
|
6531
6628
|
}
|
|
6532
6629
|
|
|
6533
|
-
//
|
|
6630
|
+
// Limit cache size to avoid memory leaks
|
|
6534
6631
|
limitCacheSize(cssResolutionCache);
|
|
6535
6632
|
const cssProperties = {};
|
|
6536
6633
|
arr.forEach(item => {
|
|
@@ -6543,7 +6640,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6543
6640
|
const key = declaration.substring(0, colonIndex).trim();
|
|
6544
6641
|
const value = declaration.substring(colonIndex + 1).trim();
|
|
6545
6642
|
if (key && value) {
|
|
6546
|
-
//
|
|
6643
|
+
// Prioritize more specific values (e.g., !important)
|
|
6547
6644
|
if (value.includes("!important") || !cssProperties[key]) {
|
|
6548
6645
|
cssProperties[key] = value;
|
|
6549
6646
|
}
|
|
@@ -6593,15 +6690,82 @@ var tailwindToStyle = (function (exports) {
|
|
|
6593
6690
|
}
|
|
6594
6691
|
}
|
|
6595
6692
|
|
|
6596
|
-
/**
|
|
6597
|
-
*
|
|
6598
|
-
* @param {string}
|
|
6599
|
-
* @param {
|
|
6600
|
-
* @returns {string
|
|
6693
|
+
/**
|
|
6694
|
+
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6695
|
+
* @param {string} className - Class name with potential opacity modifier
|
|
6696
|
+
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6697
|
+
* @returns {string} Modified CSS declaration with opacity applied
|
|
6698
|
+
*/
|
|
6699
|
+
function processOpacityModifier(className, cssDeclaration) {
|
|
6700
|
+
const opacityMatch = className.match(/\/(\d+)$/);
|
|
6701
|
+
if (!opacityMatch) return cssDeclaration;
|
|
6702
|
+
const opacityValue = parseInt(opacityMatch[1], 10);
|
|
6703
|
+
if (opacityValue < 0 || opacityValue > 100) return cssDeclaration;
|
|
6704
|
+
const alphaValue = (opacityValue / 100).toString();
|
|
6705
|
+
|
|
6706
|
+
// Handle Tailwind's CSS custom property pattern
|
|
6707
|
+
let modifiedDeclaration = cssDeclaration;
|
|
6708
|
+
|
|
6709
|
+
// Replace opacity custom properties
|
|
6710
|
+
const opacityProperties = ["--text-opacity", "--bg-opacity", "--border-opacity", "--ring-opacity", "--divide-opacity", "--placeholder-opacity", "--text-decoration-opacity", "--outline-opacity", "--accent-opacity", "--caret-opacity"];
|
|
6711
|
+
opacityProperties.forEach(prop => {
|
|
6712
|
+
const propRegex = new RegExp(`${prop}\\s*:\\s*[\\d.]+`, "gi");
|
|
6713
|
+
modifiedDeclaration = modifiedDeclaration.replace(propRegex, `${prop}: ${alphaValue}`);
|
|
6714
|
+
});
|
|
6715
|
+
|
|
6716
|
+
// Also handle direct color values that might not use CSS variables
|
|
6717
|
+
const colorProperties = ["color", "background-color", "border-color", "text-decoration-color", "outline-color", "fill", "stroke", "caret-color", "accent-color"];
|
|
6718
|
+
colorProperties.forEach(prop => {
|
|
6719
|
+
// Match rgb(), rgba(), hsl(), hsla() functions
|
|
6720
|
+
const rgbRegex = new RegExp(`(${prop}\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)`, "gi");
|
|
6721
|
+
const rgbaRegex = new RegExp(`(${prop}\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)`, "gi");
|
|
6722
|
+
const hslRegex = new RegExp(`(${prop}\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)`, "gi");
|
|
6723
|
+
const hslaRegex = new RegExp(`(${prop}\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)`, "gi");
|
|
6724
|
+
|
|
6725
|
+
// Convert rgb to rgba with opacity
|
|
6726
|
+
modifiedDeclaration = modifiedDeclaration.replace(rgbRegex, `$1rgba($2, $3, $4, ${alphaValue})`);
|
|
6727
|
+
|
|
6728
|
+
// Update existing rgba opacity
|
|
6729
|
+
modifiedDeclaration = modifiedDeclaration.replace(rgbaRegex, `$1rgba($2, $3, $4, ${alphaValue})`);
|
|
6730
|
+
|
|
6731
|
+
// Convert hsl to hsla with opacity
|
|
6732
|
+
modifiedDeclaration = modifiedDeclaration.replace(hslRegex, `$1hsla($2, $3, $4, ${alphaValue})`);
|
|
6733
|
+
|
|
6734
|
+
// Update existing hsla opacity
|
|
6735
|
+
modifiedDeclaration = modifiedDeclaration.replace(hslaRegex, `$1hsla($2, $3, $4, ${alphaValue})`);
|
|
6736
|
+
|
|
6737
|
+
// Handle hex colors
|
|
6738
|
+
const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
|
|
6739
|
+
modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
|
|
6740
|
+
// Convert hex to rgba
|
|
6741
|
+
const hex = hexColor.replace("#", "");
|
|
6742
|
+
let r, g, b;
|
|
6743
|
+
if (hex.length === 3) {
|
|
6744
|
+
r = parseInt(hex[0] + hex[0], 16);
|
|
6745
|
+
g = parseInt(hex[1] + hex[1], 16);
|
|
6746
|
+
b = parseInt(hex[2] + hex[2], 16);
|
|
6747
|
+
} else {
|
|
6748
|
+
r = parseInt(hex.substring(0, 2), 16);
|
|
6749
|
+
g = parseInt(hex.substring(2, 4), 16);
|
|
6750
|
+
b = parseInt(hex.substring(4, 6), 16);
|
|
6751
|
+
}
|
|
6752
|
+
return `${propPart}rgba(${r}, ${g}, ${b}, ${alphaValue})`;
|
|
6753
|
+
});
|
|
6754
|
+
});
|
|
6755
|
+
return modifiedDeclaration;
|
|
6756
|
+
}
|
|
6757
|
+
|
|
6758
|
+
/**
|
|
6759
|
+
* Convert Tailwind class string to inline CSS styles or JSON object
|
|
6760
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
6761
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
6762
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
6601
6763
|
*/
|
|
6602
6764
|
function tws(classNames, convertToJson) {
|
|
6603
6765
|
const totalMarker = performanceMonitor.start("tws:total");
|
|
6604
6766
|
try {
|
|
6767
|
+
// Ensure CSS is initialized with current global config
|
|
6768
|
+
initializeCss();
|
|
6605
6769
|
if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
|
|
6606
6770
|
performanceMonitor.end(totalMarker);
|
|
6607
6771
|
return convertToJson ? {} : "";
|
|
@@ -6609,10 +6773,10 @@ var tailwindToStyle = (function (exports) {
|
|
|
6609
6773
|
let classes;
|
|
6610
6774
|
try {
|
|
6611
6775
|
const parseMarker = performanceMonitor.start("tws:parse");
|
|
6612
|
-
classes = classNames.match(/[\w-\/]+(?:\[[^\]]+\])?/g);
|
|
6776
|
+
classes = classNames.match(/[\w-\/]+(?:\/\d+)?(?:\[[^\]]+\])?/g);
|
|
6613
6777
|
performanceMonitor.end(parseMarker);
|
|
6614
6778
|
|
|
6615
|
-
//
|
|
6779
|
+
// If no valid classes are found
|
|
6616
6780
|
if (!classes || classes.length === 0) {
|
|
6617
6781
|
console.warn(`No valid Tailwind classes found in input: "${classNames}"`);
|
|
6618
6782
|
performanceMonitor.end(totalMarker);
|
|
@@ -6627,16 +6791,27 @@ var tailwindToStyle = (function (exports) {
|
|
|
6627
6791
|
// Process classes with performance monitoring
|
|
6628
6792
|
const processMarker = performanceMonitor.start("tws:process");
|
|
6629
6793
|
let cssResult = classes.map(className => {
|
|
6630
|
-
|
|
6794
|
+
// Extract base class name without opacity modifier
|
|
6795
|
+
const baseClassName = className.replace(/\/\d+$/, "");
|
|
6796
|
+
let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
|
|
6631
6797
|
if (result) {
|
|
6798
|
+
// Apply opacity modifier if present
|
|
6799
|
+
if (className.includes("/") && /\/\d+$/.test(className)) {
|
|
6800
|
+
result = processOpacityModifier(className, result);
|
|
6801
|
+
}
|
|
6632
6802
|
return resolveCssToClearCss(result);
|
|
6633
|
-
} else if (
|
|
6634
|
-
const match =
|
|
6803
|
+
} else if (baseClassName.includes("[")) {
|
|
6804
|
+
const match = baseClassName.match(/\[([^\]]+)\]/);
|
|
6635
6805
|
if (match) {
|
|
6636
6806
|
const customValue = match[1];
|
|
6637
|
-
const baseKey =
|
|
6807
|
+
const baseKey = baseClassName.split("[")[0];
|
|
6638
6808
|
if (cssObject[`${baseKey}custom`]) {
|
|
6639
|
-
|
|
6809
|
+
let customResult = cssObject[`${baseKey}custom`].replace(/custom_value/g, customValue);
|
|
6810
|
+
// Apply opacity modifier to custom values too
|
|
6811
|
+
if (className.includes("/") && /\/\d+$/.test(className)) {
|
|
6812
|
+
customResult = processOpacityModifier(className, customResult);
|
|
6813
|
+
}
|
|
6814
|
+
return customResult;
|
|
6640
6815
|
}
|
|
6641
6816
|
}
|
|
6642
6817
|
}
|
|
@@ -6767,9 +6942,12 @@ var tailwindToStyle = (function (exports) {
|
|
|
6767
6942
|
media,
|
|
6768
6943
|
finalSelector
|
|
6769
6944
|
} = resolveVariants(selector, rawVariants);
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6945
|
+
|
|
6946
|
+
// Extract base class name without opacity modifier for CSS lookup
|
|
6947
|
+
const baseClassName = pureClassName.replace(/\/\d+$/, "");
|
|
6948
|
+
let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
|
|
6949
|
+
if (!declarations && baseClassName.includes("[")) {
|
|
6950
|
+
const match = baseClassName.match(/^(.+?)\[(.+)\]$/);
|
|
6773
6951
|
if (match) {
|
|
6774
6952
|
const [, prefix, dynamicValue] = match;
|
|
6775
6953
|
const customKey = `${prefix}custom`;
|
|
@@ -6780,17 +6958,22 @@ var tailwindToStyle = (function (exports) {
|
|
|
6780
6958
|
}
|
|
6781
6959
|
}
|
|
6782
6960
|
if (!declarations) {
|
|
6783
|
-
declarations = parseCustomClassWithPatterns(
|
|
6961
|
+
declarations = parseCustomClassWithPatterns(baseClassName);
|
|
6784
6962
|
}
|
|
6785
6963
|
if (!declarations) {
|
|
6786
6964
|
return;
|
|
6787
6965
|
}
|
|
6966
|
+
|
|
6967
|
+
// Apply opacity modifier if present
|
|
6968
|
+
if (pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
|
|
6969
|
+
declarations = processOpacityModifier(pureClassName, declarations);
|
|
6970
|
+
}
|
|
6788
6971
|
if (isImportant) {
|
|
6789
6972
|
declarations = declarations.replace(/([^:;]+):([^;]+)(;?)/g, (_, prop, value) => {
|
|
6790
6973
|
return prop.trim().startsWith("--") ? `${prop}:${value};` : `${prop}:${value.trim()} !important;`;
|
|
6791
6974
|
});
|
|
6792
6975
|
}
|
|
6793
|
-
const isSpaceOrDivide = ["space-x-", "-space-x-", "space-y-", "-space-y-", "divide-"].some(prefix =>
|
|
6976
|
+
const isSpaceOrDivide = ["space-x-", "-space-x-", "space-y-", "-space-y-", "divide-"].some(prefix => baseClassName.startsWith(prefix));
|
|
6794
6977
|
const expandedSelector = replaceSelector(finalSelector);
|
|
6795
6978
|
const targetSelector = isSpaceOrDivide ? `${expandedSelector} > :not([hidden]) ~ :not([hidden])` : expandedSelector;
|
|
6796
6979
|
if (media) {
|
|
@@ -6957,12 +7140,12 @@ var tailwindToStyle = (function (exports) {
|
|
|
6957
7140
|
return cssString.trim();
|
|
6958
7141
|
}
|
|
6959
7142
|
|
|
6960
|
-
/**
|
|
6961
|
-
*
|
|
6962
|
-
*
|
|
6963
|
-
* @param {Object} obj -
|
|
6964
|
-
* @param {Object} [options] -
|
|
6965
|
-
* @returns {string}
|
|
7143
|
+
/**
|
|
7144
|
+
* Generate CSS string from style object with SCSS-like syntax
|
|
7145
|
+
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
7146
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7147
|
+
* @param {Object} [options] - Additional options, merges with global config
|
|
7148
|
+
* @returns {string} Generated CSS string
|
|
6966
7149
|
*/
|
|
6967
7150
|
function twsx(obj) {
|
|
6968
7151
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -6972,9 +7155,13 @@ var tailwindToStyle = (function (exports) {
|
|
|
6972
7155
|
console.warn("twsx: Expected an object but received:", obj);
|
|
6973
7156
|
return "";
|
|
6974
7157
|
}
|
|
7158
|
+
const mergedOptions = {
|
|
7159
|
+
...globalConfig,
|
|
7160
|
+
...options
|
|
7161
|
+
};
|
|
6975
7162
|
const {
|
|
6976
7163
|
inject = true
|
|
6977
|
-
} =
|
|
7164
|
+
} = mergedOptions;
|
|
6978
7165
|
const styles = {};
|
|
6979
7166
|
|
|
6980
7167
|
// Create walk function with closure over styles
|
|
@@ -7022,7 +7209,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
7022
7209
|
}
|
|
7023
7210
|
}
|
|
7024
7211
|
|
|
7025
|
-
//
|
|
7212
|
+
// Simple hashCode function for CSS deduplication
|
|
7026
7213
|
function getCssHash(str) {
|
|
7027
7214
|
let hash = 0,
|
|
7028
7215
|
i,
|
|
@@ -7036,7 +7223,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
7036
7223
|
return hash;
|
|
7037
7224
|
}
|
|
7038
7225
|
|
|
7039
|
-
// Enhanced auto-inject CSS
|
|
7226
|
+
// Enhanced auto-inject CSS with performance monitoring
|
|
7040
7227
|
const injectedCssHashSet = new Set();
|
|
7041
7228
|
function autoInjectCss(cssString) {
|
|
7042
7229
|
const marker = performanceMonitor.start("css:inject");
|
|
@@ -7068,24 +7255,24 @@ var tailwindToStyle = (function (exports) {
|
|
|
7068
7255
|
}
|
|
7069
7256
|
}
|
|
7070
7257
|
|
|
7071
|
-
// Enhanced debounced functions
|
|
7072
|
-
/**
|
|
7073
|
-
*
|
|
7074
|
-
* @param {string} classNames - String
|
|
7075
|
-
* @param {boolean} convertToJson -
|
|
7076
|
-
* @returns {string|Object}
|
|
7258
|
+
// Enhanced debounced functions with performance monitoring configuration
|
|
7259
|
+
/**
|
|
7260
|
+
* Debounced version of tws function with performance monitoring
|
|
7261
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
7262
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
7263
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
7077
7264
|
*/
|
|
7078
7265
|
const debouncedTws = debounce(tws, 50); // Faster debounce for tws
|
|
7079
7266
|
|
|
7080
|
-
/**
|
|
7081
|
-
*
|
|
7082
|
-
* @param {Object} obj -
|
|
7083
|
-
* @param {Object} [options] -
|
|
7084
|
-
* @returns {string}
|
|
7267
|
+
/**
|
|
7268
|
+
* Debounced version of twsx function with performance monitoring
|
|
7269
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7270
|
+
* @param {Object} [options] - Additional options
|
|
7271
|
+
* @returns {string} Generated CSS string
|
|
7085
7272
|
*/
|
|
7086
7273
|
const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
|
|
7087
7274
|
|
|
7088
|
-
// Export performance utilities
|
|
7275
|
+
// Export performance utilities for debugging
|
|
7089
7276
|
const performanceUtils = {
|
|
7090
7277
|
getStats() {
|
|
7091
7278
|
return {
|
|
@@ -7113,13 +7300,16 @@ var tailwindToStyle = (function (exports) {
|
|
|
7113
7300
|
enablePerformanceLogging() {
|
|
7114
7301
|
let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
7115
7302
|
performanceMonitor.enabled = enabled && typeof performance !== "undefined";
|
|
7116
|
-
console.log(`Performance monitoring ${enabled ?
|
|
7303
|
+
console.log(`Performance monitoring ${enabled ? "enabled" : "disabled"}`);
|
|
7117
7304
|
}
|
|
7118
7305
|
};
|
|
7119
7306
|
|
|
7120
7307
|
exports.debouncedTws = debouncedTws;
|
|
7121
7308
|
exports.debouncedTwsx = debouncedTwsx;
|
|
7309
|
+
exports.getConfig = getConfig;
|
|
7122
7310
|
exports.performanceUtils = performanceUtils;
|
|
7311
|
+
exports.resetConfig = resetConfig;
|
|
7312
|
+
exports.setConfig = setConfig;
|
|
7123
7313
|
exports.tws = tws;
|
|
7124
7314
|
exports.twsx = twsx;
|
|
7125
7315
|
|