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