tailwind-to-style 2.7.4 → 2.7.6
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 +52 -236
- package/dist/index.cjs +52 -236
- package/dist/index.d.ts +7 -32
- package/dist/index.esm.js +53 -234
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tailwind-to-style v2.7.
|
|
2
|
+
* tailwind-to-style v2.7.6
|
|
3
3
|
* Convert tailwind classes to inline style
|
|
4
4
|
*
|
|
5
5
|
* @author Bigetion
|
|
@@ -1532,10 +1532,12 @@ 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
|
-
|
|
1535
|
+
if (isFunction(newTheme[key])) {
|
|
1536
|
+
newTheme[key] = newTheme[key]({
|
|
1537
|
+
theme: keyRef => {
|
|
1538
|
+
return configOptions.theme[keyRef];
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1539
1541
|
}
|
|
1540
1542
|
});
|
|
1541
1543
|
themeKeys.forEach(key => {
|
|
@@ -1546,6 +1548,9 @@ var tailwindToStyle = (function (exports) {
|
|
|
1546
1548
|
}
|
|
1547
1549
|
});
|
|
1548
1550
|
}
|
|
1551
|
+
if (themeExtend[key]) {
|
|
1552
|
+
newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
|
|
1553
|
+
}
|
|
1549
1554
|
});
|
|
1550
1555
|
return {
|
|
1551
1556
|
prefix: "",
|
|
@@ -6307,10 +6312,10 @@ var tailwindToStyle = (function (exports) {
|
|
|
6307
6312
|
return null;
|
|
6308
6313
|
}
|
|
6309
6314
|
|
|
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;'
|
|
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;'
|
|
6314
6319
|
*/
|
|
6315
6320
|
function resolveCssToClearCss(cssString) {
|
|
6316
6321
|
const customVars = {};
|
|
@@ -6377,196 +6382,19 @@ var tailwindToStyle = (function (exports) {
|
|
|
6377
6382
|
}
|
|
6378
6383
|
let twString = null;
|
|
6379
6384
|
let cssObject = null;
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
const CONFIG_STORAGE_KEY = "__tailwind_to_style_global_config__";
|
|
6383
|
-
|
|
6384
|
-
// Default configuration
|
|
6385
|
-
const defaultConfig = {
|
|
6386
|
-
theme: {
|
|
6387
|
-
extend: {
|
|
6388
|
-
colors: {}
|
|
6389
|
-
},
|
|
6390
|
-
screens: {
|
|
6391
|
-
sm: "640px",
|
|
6392
|
-
md: "768px",
|
|
6393
|
-
lg: "1024px",
|
|
6394
|
-
xl: "1280px",
|
|
6395
|
-
"2xl": "1536px"
|
|
6396
|
-
}
|
|
6397
|
-
},
|
|
6398
|
-
inject: true
|
|
6399
|
-
};
|
|
6400
|
-
|
|
6401
|
-
// Detect environment and create global storage
|
|
6402
|
-
function getGlobalStorage() {
|
|
6403
|
-
if (typeof window !== "undefined") {
|
|
6404
|
-
// Browser environment - use window object
|
|
6405
|
-
if (!window[CONFIG_STORAGE_KEY]) {
|
|
6406
|
-
window[CONFIG_STORAGE_KEY] = {
|
|
6407
|
-
...defaultConfig
|
|
6408
|
-
};
|
|
6409
|
-
}
|
|
6410
|
-
return window[CONFIG_STORAGE_KEY];
|
|
6411
|
-
} else if (typeof global !== "undefined") {
|
|
6412
|
-
// Node.js environment - use global object
|
|
6413
|
-
if (!global[CONFIG_STORAGE_KEY]) {
|
|
6414
|
-
global[CONFIG_STORAGE_KEY] = {
|
|
6415
|
-
...defaultConfig
|
|
6416
|
-
};
|
|
6417
|
-
}
|
|
6418
|
-
return global[CONFIG_STORAGE_KEY];
|
|
6419
|
-
} else {
|
|
6420
|
-
// Fallback - use module-level variable (will work only within same file)
|
|
6421
|
-
console.warn("tailwind-to-style: Unable to create global config storage. Config will only work within the same module.");
|
|
6422
|
-
return defaultConfig;
|
|
6423
|
-
}
|
|
6424
|
-
}
|
|
6425
|
-
|
|
6426
|
-
// Get global config reference
|
|
6427
|
-
let globalConfig = getGlobalStorage();
|
|
6428
|
-
function initializeCss() {
|
|
6429
|
-
if (!twString) {
|
|
6430
|
-
// Always get fresh config from global storage
|
|
6431
|
-
const currentConfig = getGlobalStorage();
|
|
6432
|
-
const configForGeneration = {
|
|
6433
|
-
...currentConfig,
|
|
6434
|
-
theme: {
|
|
6435
|
-
...currentConfig.theme
|
|
6436
|
-
}
|
|
6437
|
-
};
|
|
6438
|
-
twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
|
|
6439
|
-
}
|
|
6440
|
-
if (!cssObject) {
|
|
6441
|
-
cssObject = convertCssToObject(twString);
|
|
6442
|
-
}
|
|
6443
|
-
}
|
|
6444
|
-
initializeCss();
|
|
6445
|
-
function convertScreensToBreakpoints(screens) {
|
|
6446
|
-
const breakpoints = {};
|
|
6447
|
-
for (const [key, value] of Object.entries(screens)) {
|
|
6448
|
-
breakpoints[key] = `@media (min-width: ${value})`;
|
|
6449
|
-
}
|
|
6450
|
-
return breakpoints;
|
|
6385
|
+
if (!twString) {
|
|
6386
|
+
twString = generateTailwindCssString().replace(/\s\s+/g, " ");
|
|
6451
6387
|
}
|
|
6452
|
-
|
|
6453
|
-
/**
|
|
6454
|
-
* Set global configuration for both tws and twsx functions
|
|
6455
|
-
* @param {Object} config - Global configuration object
|
|
6456
|
-
* @returns {Object} Current global configuration
|
|
6457
|
-
*/
|
|
6458
|
-
function setConfig(config) {
|
|
6459
|
-
var _config$theme, _config$theme2, _config$theme2$extend, _config$theme3;
|
|
6460
|
-
// Reset CSS object cache when config changes
|
|
6461
|
-
twString = null;
|
|
6462
|
-
cssObject = null;
|
|
6463
|
-
configOptionsCache.clear();
|
|
6464
|
-
|
|
6465
|
-
// Get current global storage reference
|
|
6466
|
-
const globalStorage = getGlobalStorage();
|
|
6467
|
-
|
|
6468
|
-
// Update global storage directly
|
|
6469
|
-
Object.assign(globalStorage, {
|
|
6470
|
-
...globalStorage,
|
|
6471
|
-
...config,
|
|
6472
|
-
theme: {
|
|
6473
|
-
...globalStorage.theme,
|
|
6474
|
-
...(config.theme || {}),
|
|
6475
|
-
extend: {
|
|
6476
|
-
...globalStorage.theme.extend,
|
|
6477
|
-
...(((_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.extend) || {}),
|
|
6478
|
-
colors: {
|
|
6479
|
-
...globalStorage.theme.extend.colors,
|
|
6480
|
-
...(((_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) || {})
|
|
6481
|
-
}
|
|
6482
|
-
}
|
|
6483
|
-
}
|
|
6484
|
-
});
|
|
6485
|
-
|
|
6486
|
-
// Handle screens configuration
|
|
6487
|
-
if ((_config$theme3 = config.theme) !== null && _config$theme3 !== void 0 && _config$theme3.screens) {
|
|
6488
|
-
globalStorage.theme.screens = {
|
|
6489
|
-
...globalStorage.theme.screens,
|
|
6490
|
-
...config.theme.screens
|
|
6491
|
-
};
|
|
6492
|
-
}
|
|
6493
|
-
|
|
6494
|
-
// Handle legacy breakpoints with deprecation warning
|
|
6495
|
-
if (config.breakpoints) {
|
|
6496
|
-
console.warn("Warning: config.breakpoints is deprecated. Use config.theme.screens instead.");
|
|
6497
|
-
|
|
6498
|
-
// Convert legacy breakpoints to screens format
|
|
6499
|
-
const screens = {};
|
|
6500
|
-
for (const [key, value] of Object.entries(config.breakpoints)) {
|
|
6501
|
-
// Extract min-width value from media query
|
|
6502
|
-
const match = value.match(/min-width:\s*([^)]+)/);
|
|
6503
|
-
if (match) {
|
|
6504
|
-
screens[key] = match[1].trim();
|
|
6505
|
-
}
|
|
6506
|
-
}
|
|
6507
|
-
globalStorage.theme.screens = {
|
|
6508
|
-
...globalStorage.theme.screens,
|
|
6509
|
-
...screens
|
|
6510
|
-
};
|
|
6511
|
-
}
|
|
6512
|
-
|
|
6513
|
-
// Update local reference
|
|
6514
|
-
globalConfig = globalStorage;
|
|
6515
|
-
initializeCss();
|
|
6516
|
-
return {
|
|
6517
|
-
...globalConfig
|
|
6518
|
-
};
|
|
6519
|
-
}
|
|
6520
|
-
|
|
6521
|
-
/**
|
|
6522
|
-
* Get current global configuration
|
|
6523
|
-
* @returns {Object} Current global configuration
|
|
6524
|
-
*/
|
|
6525
|
-
function getConfig() {
|
|
6526
|
-
// Always get fresh reference from global storage
|
|
6527
|
-
globalConfig = getGlobalStorage();
|
|
6528
|
-
return {
|
|
6529
|
-
...globalConfig
|
|
6530
|
-
};
|
|
6531
|
-
}
|
|
6532
|
-
|
|
6533
|
-
/**
|
|
6534
|
-
* Reset global configuration to default
|
|
6535
|
-
* @returns {Object} Default configuration
|
|
6536
|
-
*/
|
|
6537
|
-
function resetConfig() {
|
|
6538
|
-
twString = null;
|
|
6539
|
-
cssObject = null;
|
|
6540
|
-
configOptionsCache.clear();
|
|
6541
|
-
|
|
6542
|
-
// Get global storage reference and reset it
|
|
6543
|
-
const globalStorage = getGlobalStorage();
|
|
6544
|
-
|
|
6545
|
-
// Reset to default config
|
|
6546
|
-
Object.assign(globalStorage, {
|
|
6547
|
-
theme: {
|
|
6548
|
-
extend: {
|
|
6549
|
-
colors: {}
|
|
6550
|
-
},
|
|
6551
|
-
screens: {
|
|
6552
|
-
sm: "640px",
|
|
6553
|
-
md: "768px",
|
|
6554
|
-
lg: "1024px",
|
|
6555
|
-
xl: "1280px",
|
|
6556
|
-
"2xl": "1536px"
|
|
6557
|
-
}
|
|
6558
|
-
},
|
|
6559
|
-
inject: true
|
|
6560
|
-
});
|
|
6561
|
-
|
|
6562
|
-
// Update local reference
|
|
6563
|
-
globalConfig = globalStorage;
|
|
6564
|
-
twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
|
|
6388
|
+
if (!cssObject) {
|
|
6565
6389
|
cssObject = convertCssToObject(twString);
|
|
6566
|
-
return {
|
|
6567
|
-
...globalConfig
|
|
6568
|
-
};
|
|
6569
6390
|
}
|
|
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
|
+
};
|
|
6570
6398
|
const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
|
|
6571
6399
|
const specialVariants = {
|
|
6572
6400
|
group: (state, sel) => `.group:${state} ${sel}`,
|
|
@@ -6616,9 +6444,6 @@ var tailwindToStyle = (function (exports) {
|
|
|
6616
6444
|
let media = null;
|
|
6617
6445
|
let finalSelector = selector;
|
|
6618
6446
|
for (const v of variants) {
|
|
6619
|
-
// Always get fresh config from global storage
|
|
6620
|
-
const currentConfig = getGlobalStorage();
|
|
6621
|
-
const breakpoints = convertScreensToBreakpoints(currentConfig.theme.screens || {});
|
|
6622
6447
|
if (breakpoints[v]) {
|
|
6623
6448
|
media = breakpoints[v];
|
|
6624
6449
|
} else if (pseudoVariants.has(v)) {
|
|
@@ -6768,11 +6593,11 @@ var tailwindToStyle = (function (exports) {
|
|
|
6768
6593
|
}
|
|
6769
6594
|
}
|
|
6770
6595
|
|
|
6771
|
-
/**
|
|
6772
|
-
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6773
|
-
* @param {string} className - Class name with potential opacity modifier
|
|
6774
|
-
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6775
|
-
* @returns {string} Modified CSS declaration with opacity applied
|
|
6596
|
+
/**
|
|
6597
|
+
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6598
|
+
* @param {string} className - Class name with potential opacity modifier
|
|
6599
|
+
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6600
|
+
* @returns {string} Modified CSS declaration with opacity applied
|
|
6776
6601
|
*/
|
|
6777
6602
|
function processOpacityModifier(className, cssDeclaration) {
|
|
6778
6603
|
const opacityMatch = className.match(/\/(\d+)$/);
|
|
@@ -6814,7 +6639,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
6814
6639
|
|
|
6815
6640
|
// Handle hex colors
|
|
6816
6641
|
const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
|
|
6817
|
-
modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (
|
|
6642
|
+
modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
|
|
6818
6643
|
// Convert hex to rgba
|
|
6819
6644
|
const hex = hexColor.replace("#", "");
|
|
6820
6645
|
let r, g, b;
|
|
@@ -6833,17 +6658,15 @@ var tailwindToStyle = (function (exports) {
|
|
|
6833
6658
|
return modifiedDeclaration;
|
|
6834
6659
|
}
|
|
6835
6660
|
|
|
6836
|
-
/**
|
|
6837
|
-
* Convert Tailwind class string to inline CSS styles or JSON object
|
|
6838
|
-
* @param {string} classNames - String containing Tailwind classes to convert
|
|
6839
|
-
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
6840
|
-
* @returns {string|Object} Inline CSS string or style JSON object
|
|
6661
|
+
/**
|
|
6662
|
+
* Convert Tailwind class string to inline CSS styles or JSON object
|
|
6663
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
6664
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
6665
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
6841
6666
|
*/
|
|
6842
6667
|
function tws(classNames, convertToJson) {
|
|
6843
6668
|
const totalMarker = performanceMonitor.start("tws:total");
|
|
6844
6669
|
try {
|
|
6845
|
-
// Ensure CSS is initialized with current global config
|
|
6846
|
-
initializeCss();
|
|
6847
6670
|
if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
|
|
6848
6671
|
performanceMonitor.end(totalMarker);
|
|
6849
6672
|
return convertToJson ? {} : "";
|
|
@@ -7218,12 +7041,12 @@ var tailwindToStyle = (function (exports) {
|
|
|
7218
7041
|
return cssString.trim();
|
|
7219
7042
|
}
|
|
7220
7043
|
|
|
7221
|
-
/**
|
|
7222
|
-
* Generate CSS string from style object with SCSS-like syntax
|
|
7223
|
-
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
7224
|
-
* @param {Object} obj - Object with SCSS-like style format
|
|
7225
|
-
* @param {Object} [options] - Additional options,
|
|
7226
|
-
* @returns {string} Generated CSS string
|
|
7044
|
+
/**
|
|
7045
|
+
* Generate CSS string from style object with SCSS-like syntax
|
|
7046
|
+
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
7047
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7048
|
+
* @param {Object} [options] - Additional options, e.g. { inject: true/false }
|
|
7049
|
+
* @returns {string} Generated CSS string
|
|
7227
7050
|
*/
|
|
7228
7051
|
function twsx(obj) {
|
|
7229
7052
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -7233,13 +7056,9 @@ var tailwindToStyle = (function (exports) {
|
|
|
7233
7056
|
console.warn("twsx: Expected an object but received:", obj);
|
|
7234
7057
|
return "";
|
|
7235
7058
|
}
|
|
7236
|
-
const mergedOptions = {
|
|
7237
|
-
...getGlobalStorage(),
|
|
7238
|
-
...options
|
|
7239
|
-
};
|
|
7240
7059
|
const {
|
|
7241
7060
|
inject = true
|
|
7242
|
-
} =
|
|
7061
|
+
} = options;
|
|
7243
7062
|
const styles = {};
|
|
7244
7063
|
|
|
7245
7064
|
// Create walk function with closure over styles
|
|
@@ -7334,19 +7153,19 @@ var tailwindToStyle = (function (exports) {
|
|
|
7334
7153
|
}
|
|
7335
7154
|
|
|
7336
7155
|
// Enhanced debounced functions with performance monitoring configuration
|
|
7337
|
-
/**
|
|
7338
|
-
* Debounced version of tws function with performance monitoring
|
|
7339
|
-
* @param {string} classNames - String containing Tailwind classes to convert
|
|
7340
|
-
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
7341
|
-
* @returns {string|Object} Inline CSS string or style JSON object
|
|
7156
|
+
/**
|
|
7157
|
+
* Debounced version of tws function with performance monitoring
|
|
7158
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
7159
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
7160
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
7342
7161
|
*/
|
|
7343
7162
|
const debouncedTws = debounce(tws, 50); // Faster debounce for tws
|
|
7344
7163
|
|
|
7345
|
-
/**
|
|
7346
|
-
* Debounced version of twsx function with performance monitoring
|
|
7347
|
-
* @param {Object} obj - Object with SCSS-like style format
|
|
7348
|
-
* @param {Object} [options] - Additional options
|
|
7349
|
-
* @returns {string} Generated CSS string
|
|
7164
|
+
/**
|
|
7165
|
+
* Debounced version of twsx function with performance monitoring
|
|
7166
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7167
|
+
* @param {Object} [options] - Additional options
|
|
7168
|
+
* @returns {string} Generated CSS string
|
|
7350
7169
|
*/
|
|
7351
7170
|
const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
|
|
7352
7171
|
|
|
@@ -7384,10 +7203,7 @@ var tailwindToStyle = (function (exports) {
|
|
|
7384
7203
|
|
|
7385
7204
|
exports.debouncedTws = debouncedTws;
|
|
7386
7205
|
exports.debouncedTwsx = debouncedTwsx;
|
|
7387
|
-
exports.getConfig = getConfig;
|
|
7388
7206
|
exports.performanceUtils = performanceUtils;
|
|
7389
|
-
exports.resetConfig = resetConfig;
|
|
7390
|
-
exports.setConfig = setConfig;
|
|
7391
7207
|
exports.tws = tws;
|
|
7392
7208
|
exports.twsx = twsx;
|
|
7393
7209
|
|