tailwind-to-style 2.7.2 → 2.7.4
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 +252 -68
- package/dist/{index.cjs.js → index.cjs} +252 -68
- package/dist/index.d.ts +32 -7
- package/dist/index.esm.js +250 -69
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tailwind-to-style v2.7.
|
|
2
|
+
* tailwind-to-style v2.7.4
|
|
3
3
|
* Convert tailwind classes to inline style
|
|
4
4
|
*
|
|
5
5
|
* @author Bigetion
|
|
@@ -1533,12 +1533,10 @@ function getConfigOptions() {
|
|
|
1533
1533
|
const themeKeys = Object.keys(configOptions.theme);
|
|
1534
1534
|
themeKeys.forEach(key => {
|
|
1535
1535
|
newTheme[key] = theme[key] || configOptions.theme[key];
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
});
|
|
1536
|
+
});
|
|
1537
|
+
themeKeys.forEach(key => {
|
|
1538
|
+
if (themeExtend[key] && newTheme[key]) {
|
|
1539
|
+
newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
|
|
1542
1540
|
}
|
|
1543
1541
|
});
|
|
1544
1542
|
themeKeys.forEach(key => {
|
|
@@ -1549,9 +1547,6 @@ function getConfigOptions() {
|
|
|
1549
1547
|
}
|
|
1550
1548
|
});
|
|
1551
1549
|
}
|
|
1552
|
-
if (themeExtend[key]) {
|
|
1553
|
-
newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
|
|
1554
|
-
}
|
|
1555
1550
|
});
|
|
1556
1551
|
return {
|
|
1557
1552
|
prefix: "",
|
|
@@ -6313,10 +6308,10 @@ function parseCustomClassWithPatterns(className) {
|
|
|
6313
6308
|
return null;
|
|
6314
6309
|
}
|
|
6315
6310
|
|
|
6316
|
-
/**
|
|
6317
|
-
* Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
|
|
6318
|
-
* @param {string} cssString
|
|
6319
|
-
* @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
|
|
6311
|
+
/**
|
|
6312
|
+
* Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
|
|
6313
|
+
* @param {string} cssString
|
|
6314
|
+
* @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
|
|
6320
6315
|
*/
|
|
6321
6316
|
function resolveCssToClearCss(cssString) {
|
|
6322
6317
|
const customVars = {};
|
|
@@ -6383,19 +6378,196 @@ function convertCssToObject(cssString) {
|
|
|
6383
6378
|
}
|
|
6384
6379
|
let twString = null;
|
|
6385
6380
|
let cssObject = null;
|
|
6386
|
-
|
|
6387
|
-
|
|
6381
|
+
|
|
6382
|
+
// Global config storage key
|
|
6383
|
+
const CONFIG_STORAGE_KEY = "__tailwind_to_style_global_config__";
|
|
6384
|
+
|
|
6385
|
+
// Default configuration
|
|
6386
|
+
const defaultConfig = {
|
|
6387
|
+
theme: {
|
|
6388
|
+
extend: {
|
|
6389
|
+
colors: {}
|
|
6390
|
+
},
|
|
6391
|
+
screens: {
|
|
6392
|
+
sm: "640px",
|
|
6393
|
+
md: "768px",
|
|
6394
|
+
lg: "1024px",
|
|
6395
|
+
xl: "1280px",
|
|
6396
|
+
"2xl": "1536px"
|
|
6397
|
+
}
|
|
6398
|
+
},
|
|
6399
|
+
inject: true
|
|
6400
|
+
};
|
|
6401
|
+
|
|
6402
|
+
// Detect environment and create global storage
|
|
6403
|
+
function getGlobalStorage() {
|
|
6404
|
+
if (typeof window !== "undefined") {
|
|
6405
|
+
// Browser environment - use window object
|
|
6406
|
+
if (!window[CONFIG_STORAGE_KEY]) {
|
|
6407
|
+
window[CONFIG_STORAGE_KEY] = {
|
|
6408
|
+
...defaultConfig
|
|
6409
|
+
};
|
|
6410
|
+
}
|
|
6411
|
+
return window[CONFIG_STORAGE_KEY];
|
|
6412
|
+
} else if (typeof global !== "undefined") {
|
|
6413
|
+
// Node.js environment - use global object
|
|
6414
|
+
if (!global[CONFIG_STORAGE_KEY]) {
|
|
6415
|
+
global[CONFIG_STORAGE_KEY] = {
|
|
6416
|
+
...defaultConfig
|
|
6417
|
+
};
|
|
6418
|
+
}
|
|
6419
|
+
return global[CONFIG_STORAGE_KEY];
|
|
6420
|
+
} else {
|
|
6421
|
+
// Fallback - use module-level variable (will work only within same file)
|
|
6422
|
+
console.warn("tailwind-to-style: Unable to create global config storage. Config will only work within the same module.");
|
|
6423
|
+
return defaultConfig;
|
|
6424
|
+
}
|
|
6425
|
+
}
|
|
6426
|
+
|
|
6427
|
+
// Get global config reference
|
|
6428
|
+
let globalConfig = getGlobalStorage();
|
|
6429
|
+
function initializeCss() {
|
|
6430
|
+
if (!twString) {
|
|
6431
|
+
// Always get fresh config from global storage
|
|
6432
|
+
const currentConfig = getGlobalStorage();
|
|
6433
|
+
const configForGeneration = {
|
|
6434
|
+
...currentConfig,
|
|
6435
|
+
theme: {
|
|
6436
|
+
...currentConfig.theme
|
|
6437
|
+
}
|
|
6438
|
+
};
|
|
6439
|
+
twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
|
|
6440
|
+
}
|
|
6441
|
+
if (!cssObject) {
|
|
6442
|
+
cssObject = convertCssToObject(twString);
|
|
6443
|
+
}
|
|
6444
|
+
}
|
|
6445
|
+
initializeCss();
|
|
6446
|
+
function convertScreensToBreakpoints(screens) {
|
|
6447
|
+
const breakpoints = {};
|
|
6448
|
+
for (const [key, value] of Object.entries(screens)) {
|
|
6449
|
+
breakpoints[key] = `@media (min-width: ${value})`;
|
|
6450
|
+
}
|
|
6451
|
+
return breakpoints;
|
|
6452
|
+
}
|
|
6453
|
+
|
|
6454
|
+
/**
|
|
6455
|
+
* Set global configuration for both tws and twsx functions
|
|
6456
|
+
* @param {Object} config - Global configuration object
|
|
6457
|
+
* @returns {Object} Current global configuration
|
|
6458
|
+
*/
|
|
6459
|
+
function setConfig(config) {
|
|
6460
|
+
var _config$theme, _config$theme2, _config$theme2$extend, _config$theme3;
|
|
6461
|
+
// Reset CSS object cache when config changes
|
|
6462
|
+
twString = null;
|
|
6463
|
+
cssObject = null;
|
|
6464
|
+
configOptionsCache.clear();
|
|
6465
|
+
|
|
6466
|
+
// Get current global storage reference
|
|
6467
|
+
const globalStorage = getGlobalStorage();
|
|
6468
|
+
|
|
6469
|
+
// Update global storage directly
|
|
6470
|
+
Object.assign(globalStorage, {
|
|
6471
|
+
...globalStorage,
|
|
6472
|
+
...config,
|
|
6473
|
+
theme: {
|
|
6474
|
+
...globalStorage.theme,
|
|
6475
|
+
...(config.theme || {}),
|
|
6476
|
+
extend: {
|
|
6477
|
+
...globalStorage.theme.extend,
|
|
6478
|
+
...(((_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.extend) || {}),
|
|
6479
|
+
colors: {
|
|
6480
|
+
...globalStorage.theme.extend.colors,
|
|
6481
|
+
...(((_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) || {})
|
|
6482
|
+
}
|
|
6483
|
+
}
|
|
6484
|
+
}
|
|
6485
|
+
});
|
|
6486
|
+
|
|
6487
|
+
// Handle screens configuration
|
|
6488
|
+
if ((_config$theme3 = config.theme) !== null && _config$theme3 !== void 0 && _config$theme3.screens) {
|
|
6489
|
+
globalStorage.theme.screens = {
|
|
6490
|
+
...globalStorage.theme.screens,
|
|
6491
|
+
...config.theme.screens
|
|
6492
|
+
};
|
|
6493
|
+
}
|
|
6494
|
+
|
|
6495
|
+
// Handle legacy breakpoints with deprecation warning
|
|
6496
|
+
if (config.breakpoints) {
|
|
6497
|
+
console.warn("Warning: config.breakpoints is deprecated. Use config.theme.screens instead.");
|
|
6498
|
+
|
|
6499
|
+
// Convert legacy breakpoints to screens format
|
|
6500
|
+
const screens = {};
|
|
6501
|
+
for (const [key, value] of Object.entries(config.breakpoints)) {
|
|
6502
|
+
// Extract min-width value from media query
|
|
6503
|
+
const match = value.match(/min-width:\s*([^)]+)/);
|
|
6504
|
+
if (match) {
|
|
6505
|
+
screens[key] = match[1].trim();
|
|
6506
|
+
}
|
|
6507
|
+
}
|
|
6508
|
+
globalStorage.theme.screens = {
|
|
6509
|
+
...globalStorage.theme.screens,
|
|
6510
|
+
...screens
|
|
6511
|
+
};
|
|
6512
|
+
}
|
|
6513
|
+
|
|
6514
|
+
// Update local reference
|
|
6515
|
+
globalConfig = globalStorage;
|
|
6516
|
+
initializeCss();
|
|
6517
|
+
return {
|
|
6518
|
+
...globalConfig
|
|
6519
|
+
};
|
|
6520
|
+
}
|
|
6521
|
+
|
|
6522
|
+
/**
|
|
6523
|
+
* Get current global configuration
|
|
6524
|
+
* @returns {Object} Current global configuration
|
|
6525
|
+
*/
|
|
6526
|
+
function getConfig() {
|
|
6527
|
+
// Always get fresh reference from global storage
|
|
6528
|
+
globalConfig = getGlobalStorage();
|
|
6529
|
+
return {
|
|
6530
|
+
...globalConfig
|
|
6531
|
+
};
|
|
6388
6532
|
}
|
|
6389
|
-
|
|
6533
|
+
|
|
6534
|
+
/**
|
|
6535
|
+
* Reset global configuration to default
|
|
6536
|
+
* @returns {Object} Default configuration
|
|
6537
|
+
*/
|
|
6538
|
+
function resetConfig() {
|
|
6539
|
+
twString = null;
|
|
6540
|
+
cssObject = null;
|
|
6541
|
+
configOptionsCache.clear();
|
|
6542
|
+
|
|
6543
|
+
// Get global storage reference and reset it
|
|
6544
|
+
const globalStorage = getGlobalStorage();
|
|
6545
|
+
|
|
6546
|
+
// Reset to default config
|
|
6547
|
+
Object.assign(globalStorage, {
|
|
6548
|
+
theme: {
|
|
6549
|
+
extend: {
|
|
6550
|
+
colors: {}
|
|
6551
|
+
},
|
|
6552
|
+
screens: {
|
|
6553
|
+
sm: "640px",
|
|
6554
|
+
md: "768px",
|
|
6555
|
+
lg: "1024px",
|
|
6556
|
+
xl: "1280px",
|
|
6557
|
+
"2xl": "1536px"
|
|
6558
|
+
}
|
|
6559
|
+
},
|
|
6560
|
+
inject: true
|
|
6561
|
+
});
|
|
6562
|
+
|
|
6563
|
+
// Update local reference
|
|
6564
|
+
globalConfig = globalStorage;
|
|
6565
|
+
twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
|
|
6390
6566
|
cssObject = convertCssToObject(twString);
|
|
6567
|
+
return {
|
|
6568
|
+
...globalConfig
|
|
6569
|
+
};
|
|
6391
6570
|
}
|
|
6392
|
-
const breakpoints = {
|
|
6393
|
-
sm: "@media (min-width: 640px)",
|
|
6394
|
-
md: "@media (min-width: 768px)",
|
|
6395
|
-
lg: "@media (min-width: 1024px)",
|
|
6396
|
-
xl: "@media (min-width: 1280px)",
|
|
6397
|
-
"2xl": "@media (min-width: 1536px)"
|
|
6398
|
-
};
|
|
6399
6571
|
const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
|
|
6400
6572
|
const specialVariants = {
|
|
6401
6573
|
group: (state, sel) => `.group:${state} ${sel}`,
|
|
@@ -6445,6 +6617,9 @@ function resolveVariants(selector, variants) {
|
|
|
6445
6617
|
let media = null;
|
|
6446
6618
|
let finalSelector = selector;
|
|
6447
6619
|
for (const v of variants) {
|
|
6620
|
+
// Always get fresh config from global storage
|
|
6621
|
+
const currentConfig = getGlobalStorage();
|
|
6622
|
+
const breakpoints = convertScreensToBreakpoints(currentConfig.theme.screens || {});
|
|
6448
6623
|
if (breakpoints[v]) {
|
|
6449
6624
|
media = breakpoints[v];
|
|
6450
6625
|
} else if (pseudoVariants.has(v)) {
|
|
@@ -6506,7 +6681,7 @@ function debounce(func) {
|
|
|
6506
6681
|
callCount++;
|
|
6507
6682
|
clearTimeout(timeout);
|
|
6508
6683
|
timeout = setTimeout(() => {
|
|
6509
|
-
const marker = performanceMonitor.start(`debounced:${func.name ||
|
|
6684
|
+
const marker = performanceMonitor.start(`debounced:${func.name || "anonymous"}`);
|
|
6510
6685
|
try {
|
|
6511
6686
|
const result = func.apply(context, args);
|
|
6512
6687
|
performanceMonitor.end(marker);
|
|
@@ -6594,11 +6769,11 @@ function separateAndResolveCSS(arr) {
|
|
|
6594
6769
|
}
|
|
6595
6770
|
}
|
|
6596
6771
|
|
|
6597
|
-
/**
|
|
6598
|
-
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6599
|
-
* @param {string} className - Class name with potential opacity modifier
|
|
6600
|
-
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6601
|
-
* @returns {string} Modified CSS declaration with opacity applied
|
|
6772
|
+
/**
|
|
6773
|
+
* Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
|
|
6774
|
+
* @param {string} className - Class name with potential opacity modifier
|
|
6775
|
+
* @param {string} cssDeclaration - CSS declaration to modify
|
|
6776
|
+
* @returns {string} Modified CSS declaration with opacity applied
|
|
6602
6777
|
*/
|
|
6603
6778
|
function processOpacityModifier(className, cssDeclaration) {
|
|
6604
6779
|
const opacityMatch = className.match(/\/(\d+)$/);
|
|
@@ -6611,20 +6786,20 @@ function processOpacityModifier(className, cssDeclaration) {
|
|
|
6611
6786
|
let modifiedDeclaration = cssDeclaration;
|
|
6612
6787
|
|
|
6613
6788
|
// Replace opacity custom properties
|
|
6614
|
-
const opacityProperties = [
|
|
6789
|
+
const opacityProperties = ["--text-opacity", "--bg-opacity", "--border-opacity", "--ring-opacity", "--divide-opacity", "--placeholder-opacity", "--text-decoration-opacity", "--outline-opacity", "--accent-opacity", "--caret-opacity"];
|
|
6615
6790
|
opacityProperties.forEach(prop => {
|
|
6616
|
-
const propRegex = new RegExp(`${prop}\\s*:\\s*[\\d.]+`,
|
|
6791
|
+
const propRegex = new RegExp(`${prop}\\s*:\\s*[\\d.]+`, "gi");
|
|
6617
6792
|
modifiedDeclaration = modifiedDeclaration.replace(propRegex, `${prop}: ${alphaValue}`);
|
|
6618
6793
|
});
|
|
6619
6794
|
|
|
6620
6795
|
// Also handle direct color values that might not use CSS variables
|
|
6621
|
-
const colorProperties = [
|
|
6796
|
+
const colorProperties = ["color", "background-color", "border-color", "text-decoration-color", "outline-color", "fill", "stroke", "caret-color", "accent-color"];
|
|
6622
6797
|
colorProperties.forEach(prop => {
|
|
6623
6798
|
// Match rgb(), rgba(), hsl(), hsla() functions
|
|
6624
|
-
const rgbRegex = new RegExp(`(${prop}\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)`,
|
|
6625
|
-
const rgbaRegex = new RegExp(`(${prop}\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)`,
|
|
6626
|
-
const hslRegex = new RegExp(`(${prop}\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)`,
|
|
6627
|
-
const hslaRegex = new RegExp(`(${prop}\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)`,
|
|
6799
|
+
const rgbRegex = new RegExp(`(${prop}\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)`, "gi");
|
|
6800
|
+
const rgbaRegex = new RegExp(`(${prop}\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)`, "gi");
|
|
6801
|
+
const hslRegex = new RegExp(`(${prop}\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)`, "gi");
|
|
6802
|
+
const hslaRegex = new RegExp(`(${prop}\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)`, "gi");
|
|
6628
6803
|
|
|
6629
6804
|
// Convert rgb to rgba with opacity
|
|
6630
6805
|
modifiedDeclaration = modifiedDeclaration.replace(rgbRegex, `$1rgba($2, $3, $4, ${alphaValue})`);
|
|
@@ -6639,10 +6814,10 @@ function processOpacityModifier(className, cssDeclaration) {
|
|
|
6639
6814
|
modifiedDeclaration = modifiedDeclaration.replace(hslaRegex, `$1hsla($2, $3, $4, ${alphaValue})`);
|
|
6640
6815
|
|
|
6641
6816
|
// Handle hex colors
|
|
6642
|
-
const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`,
|
|
6643
|
-
modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (
|
|
6817
|
+
const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
|
|
6818
|
+
modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
|
|
6644
6819
|
// Convert hex to rgba
|
|
6645
|
-
const hex = hexColor.replace(
|
|
6820
|
+
const hex = hexColor.replace("#", "");
|
|
6646
6821
|
let r, g, b;
|
|
6647
6822
|
if (hex.length === 3) {
|
|
6648
6823
|
r = parseInt(hex[0] + hex[0], 16);
|
|
@@ -6659,15 +6834,17 @@ function processOpacityModifier(className, cssDeclaration) {
|
|
|
6659
6834
|
return modifiedDeclaration;
|
|
6660
6835
|
}
|
|
6661
6836
|
|
|
6662
|
-
/**
|
|
6663
|
-
* Convert Tailwind class string to inline CSS styles or JSON object
|
|
6664
|
-
* @param {string} classNames - String containing Tailwind classes to convert
|
|
6665
|
-
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
6666
|
-
* @returns {string|Object} Inline CSS string or style JSON object
|
|
6837
|
+
/**
|
|
6838
|
+
* Convert Tailwind class string to inline CSS styles or JSON object
|
|
6839
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
6840
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
6841
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
6667
6842
|
*/
|
|
6668
6843
|
function tws(classNames, convertToJson) {
|
|
6669
6844
|
const totalMarker = performanceMonitor.start("tws:total");
|
|
6670
6845
|
try {
|
|
6846
|
+
// Ensure CSS is initialized with current global config
|
|
6847
|
+
initializeCss();
|
|
6671
6848
|
if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
|
|
6672
6849
|
performanceMonitor.end(totalMarker);
|
|
6673
6850
|
return convertToJson ? {} : "";
|
|
@@ -6694,11 +6871,11 @@ function tws(classNames, convertToJson) {
|
|
|
6694
6871
|
const processMarker = performanceMonitor.start("tws:process");
|
|
6695
6872
|
let cssResult = classes.map(className => {
|
|
6696
6873
|
// Extract base class name without opacity modifier
|
|
6697
|
-
const baseClassName = className.replace(/\/\d+$/,
|
|
6874
|
+
const baseClassName = className.replace(/\/\d+$/, "");
|
|
6698
6875
|
let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
|
|
6699
6876
|
if (result) {
|
|
6700
6877
|
// Apply opacity modifier if present
|
|
6701
|
-
if (className.includes(
|
|
6878
|
+
if (className.includes("/") && /\/\d+$/.test(className)) {
|
|
6702
6879
|
result = processOpacityModifier(className, result);
|
|
6703
6880
|
}
|
|
6704
6881
|
return resolveCssToClearCss(result);
|
|
@@ -6710,7 +6887,7 @@ function tws(classNames, convertToJson) {
|
|
|
6710
6887
|
if (cssObject[`${baseKey}custom`]) {
|
|
6711
6888
|
let customResult = cssObject[`${baseKey}custom`].replace(/custom_value/g, customValue);
|
|
6712
6889
|
// Apply opacity modifier to custom values too
|
|
6713
|
-
if (className.includes(
|
|
6890
|
+
if (className.includes("/") && /\/\d+$/.test(className)) {
|
|
6714
6891
|
customResult = processOpacityModifier(className, customResult);
|
|
6715
6892
|
}
|
|
6716
6893
|
return customResult;
|
|
@@ -6846,7 +7023,7 @@ function processClass(cls, selector, styles) {
|
|
|
6846
7023
|
} = resolveVariants(selector, rawVariants);
|
|
6847
7024
|
|
|
6848
7025
|
// Extract base class name without opacity modifier for CSS lookup
|
|
6849
|
-
const baseClassName = pureClassName.replace(/\/\d+$/,
|
|
7026
|
+
const baseClassName = pureClassName.replace(/\/\d+$/, "");
|
|
6850
7027
|
let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
|
|
6851
7028
|
if (!declarations && baseClassName.includes("[")) {
|
|
6852
7029
|
const match = baseClassName.match(/^(.+?)\[(.+)\]$/);
|
|
@@ -6867,7 +7044,7 @@ function processClass(cls, selector, styles) {
|
|
|
6867
7044
|
}
|
|
6868
7045
|
|
|
6869
7046
|
// Apply opacity modifier if present
|
|
6870
|
-
if (pureClassName.includes(
|
|
7047
|
+
if (pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
|
|
6871
7048
|
declarations = processOpacityModifier(pureClassName, declarations);
|
|
6872
7049
|
}
|
|
6873
7050
|
if (isImportant) {
|
|
@@ -7042,12 +7219,12 @@ function generateCssString(styles) {
|
|
|
7042
7219
|
return cssString.trim();
|
|
7043
7220
|
}
|
|
7044
7221
|
|
|
7045
|
-
/**
|
|
7046
|
-
* Generate CSS string from style object with SCSS-like syntax
|
|
7047
|
-
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
7048
|
-
* @param {Object} obj - Object with SCSS-like style format
|
|
7049
|
-
* @param {Object} [options] - Additional options,
|
|
7050
|
-
* @returns {string} Generated CSS string
|
|
7222
|
+
/**
|
|
7223
|
+
* Generate CSS string from style object with SCSS-like syntax
|
|
7224
|
+
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
7225
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7226
|
+
* @param {Object} [options] - Additional options, merges with global config
|
|
7227
|
+
* @returns {string} Generated CSS string
|
|
7051
7228
|
*/
|
|
7052
7229
|
function twsx(obj) {
|
|
7053
7230
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -7057,9 +7234,13 @@ function twsx(obj) {
|
|
|
7057
7234
|
console.warn("twsx: Expected an object but received:", obj);
|
|
7058
7235
|
return "";
|
|
7059
7236
|
}
|
|
7237
|
+
const mergedOptions = {
|
|
7238
|
+
...getGlobalStorage(),
|
|
7239
|
+
...options
|
|
7240
|
+
};
|
|
7060
7241
|
const {
|
|
7061
7242
|
inject = true
|
|
7062
|
-
} =
|
|
7243
|
+
} = mergedOptions;
|
|
7063
7244
|
const styles = {};
|
|
7064
7245
|
|
|
7065
7246
|
// Create walk function with closure over styles
|
|
@@ -7154,19 +7335,19 @@ function autoInjectCss(cssString) {
|
|
|
7154
7335
|
}
|
|
7155
7336
|
|
|
7156
7337
|
// Enhanced debounced functions with performance monitoring configuration
|
|
7157
|
-
/**
|
|
7158
|
-
* Debounced version of tws function with performance monitoring
|
|
7159
|
-
* @param {string} classNames - String containing Tailwind classes to convert
|
|
7160
|
-
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
7161
|
-
* @returns {string|Object} Inline CSS string or style JSON object
|
|
7338
|
+
/**
|
|
7339
|
+
* Debounced version of tws function with performance monitoring
|
|
7340
|
+
* @param {string} classNames - String containing Tailwind classes to convert
|
|
7341
|
+
* @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
|
|
7342
|
+
* @returns {string|Object} Inline CSS string or style JSON object
|
|
7162
7343
|
*/
|
|
7163
7344
|
const debouncedTws = debounce(tws, 50); // Faster debounce for tws
|
|
7164
7345
|
|
|
7165
|
-
/**
|
|
7166
|
-
* Debounced version of twsx function with performance monitoring
|
|
7167
|
-
* @param {Object} obj - Object with SCSS-like style format
|
|
7168
|
-
* @param {Object} [options] - Additional options
|
|
7169
|
-
* @returns {string} Generated CSS string
|
|
7346
|
+
/**
|
|
7347
|
+
* Debounced version of twsx function with performance monitoring
|
|
7348
|
+
* @param {Object} obj - Object with SCSS-like style format
|
|
7349
|
+
* @param {Object} [options] - Additional options
|
|
7350
|
+
* @returns {string} Generated CSS string
|
|
7170
7351
|
*/
|
|
7171
7352
|
const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
|
|
7172
7353
|
|
|
@@ -7198,12 +7379,15 @@ const performanceUtils = {
|
|
|
7198
7379
|
enablePerformanceLogging() {
|
|
7199
7380
|
let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
7200
7381
|
performanceMonitor.enabled = enabled && typeof performance !== "undefined";
|
|
7201
|
-
console.log(`Performance monitoring ${enabled ?
|
|
7382
|
+
console.log(`Performance monitoring ${enabled ? "enabled" : "disabled"}`);
|
|
7202
7383
|
}
|
|
7203
7384
|
};
|
|
7204
7385
|
|
|
7205
7386
|
exports.debouncedTws = debouncedTws;
|
|
7206
7387
|
exports.debouncedTwsx = debouncedTwsx;
|
|
7388
|
+
exports.getConfig = getConfig;
|
|
7207
7389
|
exports.performanceUtils = performanceUtils;
|
|
7390
|
+
exports.resetConfig = resetConfig;
|
|
7391
|
+
exports.setConfig = setConfig;
|
|
7208
7392
|
exports.tws = tws;
|
|
7209
7393
|
exports.twsx = twsx;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,18 @@ export interface TwsxOptions {
|
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export interface GlobalConfig {
|
|
11
|
+
theme: {
|
|
12
|
+
extend: {
|
|
13
|
+
colors: Record<string, string | Record<string, string>>;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
screens: Record<string, string>;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
inject: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
export interface PerformanceStats {
|
|
11
23
|
cacheStats: {
|
|
12
24
|
cssResolution: number;
|
|
@@ -44,24 +56,37 @@ export function tws(classNames: string, convertToJson?: boolean): string | Recor
|
|
|
44
56
|
* Generates CSS string from style object with SCSS-like syntax
|
|
45
57
|
* Supports nested selectors, state variants, responsive variants, and @css directives
|
|
46
58
|
* @param obj - Object with SCSS-like style format
|
|
47
|
-
* @param options - Additional options
|
|
59
|
+
* @param options - Additional options, merges with global config
|
|
48
60
|
* @returns Generated CSS string
|
|
49
61
|
*/
|
|
50
62
|
export function twsx(obj: StyleObject, options?: TwsxOptions): string;
|
|
51
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Set global configuration for both tws and twsx
|
|
66
|
+
* @param config - Global configuration object
|
|
67
|
+
* @returns Current global configuration
|
|
68
|
+
*/
|
|
69
|
+
export function setConfig(config: Partial<GlobalConfig>): GlobalConfig;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get current global configuration for both tws and twsx
|
|
73
|
+
* @returns Current global configuration
|
|
74
|
+
*/
|
|
75
|
+
export function getConfig(): GlobalConfig;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Reset global configuration to default
|
|
79
|
+
* @returns Default configuration
|
|
80
|
+
*/
|
|
81
|
+
export function resetConfig(): GlobalConfig;
|
|
82
|
+
|
|
52
83
|
/**
|
|
53
84
|
* Debounced version of tws function with performance monitoring
|
|
54
|
-
* @param classNames - String containing Tailwind classes to convert
|
|
55
|
-
* @param convertToJson - If true, returns JSON object, if false returns CSS string
|
|
56
|
-
* @returns CSS inline string or style JSON object
|
|
57
85
|
*/
|
|
58
86
|
export const debouncedTws: typeof tws;
|
|
59
87
|
|
|
60
88
|
/**
|
|
61
89
|
* Debounced version of twsx function with performance monitoring
|
|
62
|
-
* @param obj - Object with SCSS-like style format
|
|
63
|
-
* @param options - Additional options
|
|
64
|
-
* @returns Generated CSS string
|
|
65
90
|
*/
|
|
66
91
|
export const debouncedTwsx: typeof twsx;
|
|
67
92
|
|