tailwind-to-style 2.7.5 → 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.5
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,179 +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
- class ConfigManager {
6402
- constructor() {
6403
- this.storage = null;
6404
- this.initialized = false;
6405
- }
6406
- initialize() {
6407
- if (this.initialized) return this.storage;
6408
- if (typeof window !== "undefined") {
6409
- if (!window[CONFIG_STORAGE_KEY]) {
6410
- window[CONFIG_STORAGE_KEY] = JSON.parse(JSON.stringify(defaultConfig));
6411
- }
6412
- this.storage = window[CONFIG_STORAGE_KEY];
6413
- } else if (typeof global !== "undefined") {
6414
- // Node.js environment
6415
- if (!global[CONFIG_STORAGE_KEY]) {
6416
- global[CONFIG_STORAGE_KEY] = JSON.parse(JSON.stringify(defaultConfig));
6417
- }
6418
- this.storage = global[CONFIG_STORAGE_KEY];
6419
- } else {
6420
- // Fallback
6421
- console.warn("tailwind-to-style: Unable to create global config storage. Config will only work within the same module.");
6422
- this.storage = JSON.parse(JSON.stringify(defaultConfig));
6423
- }
6424
- this.initialized = true;
6425
- return this.storage;
6426
- }
6427
- get() {
6428
- return this.initialize();
6429
- }
6430
- set(config) {
6431
- const storage = this.initialize();
6432
- this.deepMerge(storage, config);
6433
- return storage;
6434
- }
6435
- reset() {
6436
- const storage = this.initialize();
6437
- Object.keys(storage).forEach(key => delete storage[key]);
6438
- Object.assign(storage, JSON.parse(JSON.stringify(defaultConfig)));
6439
- return storage;
6440
- }
6441
- deepMerge(target, source) {
6442
- for (const key in source) {
6443
- if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
6444
- if (!target[key] || typeof target[key] !== "object") {
6445
- target[key] = {};
6446
- }
6447
- this.deepMerge(target[key], source[key]);
6448
- } else {
6449
- target[key] = source[key];
6450
- }
6451
- }
6452
- }
6386
+ if (!twString) {
6387
+ twString = generateTailwindCssString().replace(/\s\s+/g, " ");
6453
6388
  }
6454
- const configManager = new ConfigManager();
6455
- function getGlobalStorage() {
6456
- return configManager.get();
6457
- }
6458
- let globalConfig = null;
6459
- function initializeCss() {
6460
- if (!twString) {
6461
- // Always get fresh config from global storage
6462
- const currentConfig = getGlobalStorage();
6463
- const configForGeneration = {
6464
- ...currentConfig,
6465
- theme: {
6466
- ...currentConfig.theme
6467
- }
6468
- };
6469
- twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
6470
- }
6471
- if (!cssObject) {
6472
- cssObject = convertCssToObject(twString);
6473
- }
6474
- }
6475
- initializeCss();
6476
- function convertScreensToBreakpoints(screens) {
6477
- const breakpoints = {};
6478
- for (const [key, value] of Object.entries(screens)) {
6479
- breakpoints[key] = `@media (min-width: ${value})`;
6480
- }
6481
- return breakpoints;
6482
- }
6483
-
6484
- /**
6485
- * Set global configuration for both tws and twsx functions
6486
- * @param {Object} config - Global configuration object
6487
- * @returns {Object} Current global configuration
6488
- */
6489
- function setConfig(config) {
6490
- // Reset CSS object cache when config changes
6491
- twString = null;
6492
- cssObject = null;
6493
- configOptionsCache.clear();
6494
-
6495
- // Use ConfigManager to set config
6496
- const globalStorage = configManager.set(config);
6497
-
6498
- // Handle legacy breakpoints with deprecation warning
6499
- if (config.breakpoints) {
6500
- console.warn("Warning: config.breakpoints is deprecated. Use config.theme.screens instead.");
6501
-
6502
- // Convert legacy breakpoints to screens format
6503
- const screens = {};
6504
- for (const [key, value] of Object.entries(config.breakpoints)) {
6505
- // Extract min-width value from media query
6506
- const match = value.match(/min-width:\s*([^)]+)/);
6507
- if (match) {
6508
- screens[key] = match[1].trim();
6509
- }
6510
- }
6511
- if (!globalStorage.theme.screens) {
6512
- globalStorage.theme.screens = {};
6513
- }
6514
- Object.assign(globalStorage.theme.screens, screens);
6515
- }
6516
-
6517
- // Update local reference
6518
- globalConfig = globalStorage;
6519
- initializeCss();
6520
- return {
6521
- ...globalStorage
6522
- };
6523
- }
6524
-
6525
- /**
6526
- * Get current global configuration
6527
- * @returns {Object} Current global configuration
6528
- */
6529
- function getConfig() {
6530
- globalConfig = configManager.get();
6531
- return {
6532
- ...globalConfig
6533
- };
6534
- }
6535
-
6536
- /**
6537
- * Reset global configuration to default
6538
- * @returns {Object} Default configuration
6539
- */
6540
- function resetConfig() {
6541
- twString = null;
6542
- cssObject = null;
6543
- configOptionsCache.clear();
6544
- const globalStorage = configManager.reset();
6545
-
6546
- // Update local reference
6547
- globalConfig = globalStorage;
6548
- twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
6389
+ if (!cssObject) {
6549
6390
  cssObject = convertCssToObject(twString);
6550
- return {
6551
- ...globalConfig
6552
- };
6553
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
+ };
6554
6399
  const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
6555
6400
  const specialVariants = {
6556
6401
  group: (state, sel) => `.group:${state} ${sel}`,
@@ -6600,9 +6445,6 @@ function resolveVariants(selector, variants) {
6600
6445
  let media = null;
6601
6446
  let finalSelector = selector;
6602
6447
  for (const v of variants) {
6603
- // Always get fresh config from global storage
6604
- const currentConfig = getGlobalStorage();
6605
- const breakpoints = convertScreensToBreakpoints(currentConfig.theme.screens || {});
6606
6448
  if (breakpoints[v]) {
6607
6449
  media = breakpoints[v];
6608
6450
  } else if (pseudoVariants.has(v)) {
@@ -6752,11 +6594,11 @@ function separateAndResolveCSS(arr) {
6752
6594
  }
6753
6595
  }
6754
6596
 
6755
- /**
6756
- * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6757
- * @param {string} className - Class name with potential opacity modifier
6758
- * @param {string} cssDeclaration - CSS declaration to modify
6759
- * @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
6760
6602
  */
6761
6603
  function processOpacityModifier(className, cssDeclaration) {
6762
6604
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6798,7 +6640,7 @@ function processOpacityModifier(className, cssDeclaration) {
6798
6640
 
6799
6641
  // Handle hex colors
6800
6642
  const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
6801
- modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
6643
+ modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
6802
6644
  // Convert hex to rgba
6803
6645
  const hex = hexColor.replace("#", "");
6804
6646
  let r, g, b;
@@ -6817,17 +6659,15 @@ function processOpacityModifier(className, cssDeclaration) {
6817
6659
  return modifiedDeclaration;
6818
6660
  }
6819
6661
 
6820
- /**
6821
- * Convert Tailwind class string to inline CSS styles or JSON object
6822
- * @param {string} classNames - String containing Tailwind classes to convert
6823
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6824
- * @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
6825
6667
  */
6826
6668
  function tws(classNames, convertToJson) {
6827
6669
  const totalMarker = performanceMonitor.start("tws:total");
6828
6670
  try {
6829
- // Ensure CSS is initialized with current global config
6830
- initializeCss();
6831
6671
  if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
6832
6672
  performanceMonitor.end(totalMarker);
6833
6673
  return convertToJson ? {} : "";
@@ -7202,12 +7042,12 @@ function generateCssString(styles) {
7202
7042
  return cssString.trim();
7203
7043
  }
7204
7044
 
7205
- /**
7206
- * Generate CSS string from style object with SCSS-like syntax
7207
- * Supports nested selectors, state variants, responsive variants, and @css directives
7208
- * @param {Object} obj - Object with SCSS-like style format
7209
- * @param {Object} [options] - Additional options, merges with global config
7210
- * @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
7211
7051
  */
7212
7052
  function twsx(obj) {
7213
7053
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7217,13 +7057,9 @@ function twsx(obj) {
7217
7057
  console.warn("twsx: Expected an object but received:", obj);
7218
7058
  return "";
7219
7059
  }
7220
- const mergedOptions = {
7221
- ...getGlobalStorage(),
7222
- ...options
7223
- };
7224
7060
  const {
7225
7061
  inject = true
7226
- } = mergedOptions;
7062
+ } = options;
7227
7063
  const styles = {};
7228
7064
 
7229
7065
  // Create walk function with closure over styles
@@ -7318,19 +7154,19 @@ function autoInjectCss(cssString) {
7318
7154
  }
7319
7155
 
7320
7156
  // Enhanced debounced functions with performance monitoring configuration
7321
- /**
7322
- * Debounced version of tws function with performance monitoring
7323
- * @param {string} classNames - String containing Tailwind classes to convert
7324
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7325
- * @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
7326
7162
  */
7327
7163
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7328
7164
 
7329
- /**
7330
- * Debounced version of twsx function with performance monitoring
7331
- * @param {Object} obj - Object with SCSS-like style format
7332
- * @param {Object} [options] - Additional options
7333
- * @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
7334
7170
  */
7335
7171
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7336
7172
 
@@ -7368,9 +7204,6 @@ const performanceUtils = {
7368
7204
 
7369
7205
  exports.debouncedTws = debouncedTws;
7370
7206
  exports.debouncedTwsx = debouncedTwsx;
7371
- exports.getConfig = getConfig;
7372
7207
  exports.performanceUtils = performanceUtils;
7373
- exports.resetConfig = resetConfig;
7374
- exports.setConfig = setConfig;
7375
7208
  exports.tws = tws;
7376
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