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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v2.7.4
2
+ * tailwind-to-style v2.7.6
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
@@ -1533,10 +1533,12 @@ 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
- themeKeys.forEach(key => {
1538
- if (themeExtend[key] && newTheme[key]) {
1539
- newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1536
+ if (isFunction(newTheme[key])) {
1537
+ newTheme[key] = newTheme[key]({
1538
+ theme: keyRef => {
1539
+ return configOptions.theme[keyRef];
1540
+ }
1541
+ });
1540
1542
  }
1541
1543
  });
1542
1544
  themeKeys.forEach(key => {
@@ -1547,6 +1549,9 @@ function getConfigOptions() {
1547
1549
  }
1548
1550
  });
1549
1551
  }
1552
+ if (themeExtend[key]) {
1553
+ newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1554
+ }
1550
1555
  });
1551
1556
  return {
1552
1557
  prefix: "",
@@ -6308,10 +6313,10 @@ function parseCustomClassWithPatterns(className) {
6308
6313
  return null;
6309
6314
  }
6310
6315
 
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;'
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;'
6315
6320
  */
6316
6321
  function resolveCssToClearCss(cssString) {
6317
6322
  const customVars = {};
@@ -6378,196 +6383,19 @@ function convertCssToObject(cssString) {
6378
6383
  }
6379
6384
  let twString = null;
6380
6385
  let cssObject = null;
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
- };
6386
+ if (!twString) {
6387
+ twString = generateTailwindCssString().replace(/\s\s+/g, " ");
6532
6388
  }
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, " ");
6389
+ if (!cssObject) {
6566
6390
  cssObject = convertCssToObject(twString);
6567
- return {
6568
- ...globalConfig
6569
- };
6570
6391
  }
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
+ };
6571
6399
  const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
6572
6400
  const specialVariants = {
6573
6401
  group: (state, sel) => `.group:${state} ${sel}`,
@@ -6617,9 +6445,6 @@ function resolveVariants(selector, variants) {
6617
6445
  let media = null;
6618
6446
  let finalSelector = selector;
6619
6447
  for (const v of variants) {
6620
- // Always get fresh config from global storage
6621
- const currentConfig = getGlobalStorage();
6622
- const breakpoints = convertScreensToBreakpoints(currentConfig.theme.screens || {});
6623
6448
  if (breakpoints[v]) {
6624
6449
  media = breakpoints[v];
6625
6450
  } else if (pseudoVariants.has(v)) {
@@ -6769,11 +6594,11 @@ function separateAndResolveCSS(arr) {
6769
6594
  }
6770
6595
  }
6771
6596
 
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
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
6777
6602
  */
6778
6603
  function processOpacityModifier(className, cssDeclaration) {
6779
6604
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6815,7 +6640,7 @@ function processOpacityModifier(className, cssDeclaration) {
6815
6640
 
6816
6641
  // Handle hex colors
6817
6642
  const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
6818
- modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
6643
+ modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
6819
6644
  // Convert hex to rgba
6820
6645
  const hex = hexColor.replace("#", "");
6821
6646
  let r, g, b;
@@ -6834,17 +6659,15 @@ function processOpacityModifier(className, cssDeclaration) {
6834
6659
  return modifiedDeclaration;
6835
6660
  }
6836
6661
 
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
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
6842
6667
  */
6843
6668
  function tws(classNames, convertToJson) {
6844
6669
  const totalMarker = performanceMonitor.start("tws:total");
6845
6670
  try {
6846
- // Ensure CSS is initialized with current global config
6847
- initializeCss();
6848
6671
  if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
6849
6672
  performanceMonitor.end(totalMarker);
6850
6673
  return convertToJson ? {} : "";
@@ -7219,12 +7042,12 @@ function generateCssString(styles) {
7219
7042
  return cssString.trim();
7220
7043
  }
7221
7044
 
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
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, e.g. { inject: true/false }
7050
+ * @returns {string} Generated CSS string
7228
7051
  */
7229
7052
  function twsx(obj) {
7230
7053
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7234,13 +7057,9 @@ function twsx(obj) {
7234
7057
  console.warn("twsx: Expected an object but received:", obj);
7235
7058
  return "";
7236
7059
  }
7237
- const mergedOptions = {
7238
- ...getGlobalStorage(),
7239
- ...options
7240
- };
7241
7060
  const {
7242
7061
  inject = true
7243
- } = mergedOptions;
7062
+ } = options;
7244
7063
  const styles = {};
7245
7064
 
7246
7065
  // Create walk function with closure over styles
@@ -7335,19 +7154,19 @@ function autoInjectCss(cssString) {
7335
7154
  }
7336
7155
 
7337
7156
  // Enhanced debounced functions with performance monitoring configuration
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
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
7343
7162
  */
7344
7163
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7345
7164
 
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
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
7351
7170
  */
7352
7171
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7353
7172
 
@@ -7385,9 +7204,6 @@ const performanceUtils = {
7385
7204
 
7386
7205
  exports.debouncedTws = debouncedTws;
7387
7206
  exports.debouncedTwsx = debouncedTwsx;
7388
- exports.getConfig = getConfig;
7389
7207
  exports.performanceUtils = performanceUtils;
7390
- exports.resetConfig = resetConfig;
7391
- exports.setConfig = setConfig;
7392
7208
  exports.tws = tws;
7393
7209
  exports.twsx = twsx;
package/dist/index.d.ts CHANGED
@@ -7,18 +7,6 @@ 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
-
22
10
  export interface PerformanceStats {
23
11
  cacheStats: {
24
12
  cssResolution: number;
@@ -56,37 +44,24 @@ export function tws(classNames: string, convertToJson?: boolean): string | Recor
56
44
  * Generates CSS string from style object with SCSS-like syntax
57
45
  * Supports nested selectors, state variants, responsive variants, and @css directives
58
46
  * @param obj - Object with SCSS-like style format
59
- * @param options - Additional options, merges with global config
47
+ * @param options - Additional options
60
48
  * @returns Generated CSS string
61
49
  */
62
50
  export function twsx(obj: StyleObject, options?: TwsxOptions): string;
63
51
 
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
-
83
52
  /**
84
53
  * 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
85
57
  */
86
58
  export const debouncedTws: typeof tws;
87
59
 
88
60
  /**
89
61
  * 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
90
65
  */
91
66
  export const debouncedTwsx: typeof twsx;
92
67