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.esm.js 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
@@ -1529,10 +1529,12 @@ function getConfigOptions() {
1529
1529
  const themeKeys = Object.keys(configOptions.theme);
1530
1530
  themeKeys.forEach(key => {
1531
1531
  newTheme[key] = theme[key] || configOptions.theme[key];
1532
- });
1533
- themeKeys.forEach(key => {
1534
- if (themeExtend[key] && newTheme[key]) {
1535
- newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1532
+ if (isFunction(newTheme[key])) {
1533
+ newTheme[key] = newTheme[key]({
1534
+ theme: keyRef => {
1535
+ return configOptions.theme[keyRef];
1536
+ }
1537
+ });
1536
1538
  }
1537
1539
  });
1538
1540
  themeKeys.forEach(key => {
@@ -1543,6 +1545,9 @@ function getConfigOptions() {
1543
1545
  }
1544
1546
  });
1545
1547
  }
1548
+ if (themeExtend[key]) {
1549
+ newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1550
+ }
1546
1551
  });
1547
1552
  return {
1548
1553
  prefix: "",
@@ -6304,10 +6309,10 @@ function parseCustomClassWithPatterns(className) {
6304
6309
  return null;
6305
6310
  }
6306
6311
 
6307
- /**
6308
- * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6309
- * @param {string} cssString
6310
- * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6312
+ /**
6313
+ * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6314
+ * @param {string} cssString
6315
+ * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6311
6316
  */
6312
6317
  function resolveCssToClearCss(cssString) {
6313
6318
  const customVars = {};
@@ -6374,179 +6379,19 @@ function convertCssToObject(cssString) {
6374
6379
  }
6375
6380
  let twString = null;
6376
6381
  let cssObject = null;
6377
-
6378
- // Global config storage key
6379
- const CONFIG_STORAGE_KEY = "__tailwind_to_style_global_config__";
6380
-
6381
- // Default configuration
6382
- const defaultConfig = {
6383
- theme: {
6384
- extend: {
6385
- colors: {}
6386
- },
6387
- screens: {
6388
- sm: "640px",
6389
- md: "768px",
6390
- lg: "1024px",
6391
- xl: "1280px",
6392
- "2xl": "1536px"
6393
- }
6394
- },
6395
- inject: true
6396
- };
6397
- class ConfigManager {
6398
- constructor() {
6399
- this.storage = null;
6400
- this.initialized = false;
6401
- }
6402
- initialize() {
6403
- if (this.initialized) return this.storage;
6404
- if (typeof window !== "undefined") {
6405
- if (!window[CONFIG_STORAGE_KEY]) {
6406
- window[CONFIG_STORAGE_KEY] = JSON.parse(JSON.stringify(defaultConfig));
6407
- }
6408
- this.storage = window[CONFIG_STORAGE_KEY];
6409
- } else if (typeof global !== "undefined") {
6410
- // Node.js environment
6411
- if (!global[CONFIG_STORAGE_KEY]) {
6412
- global[CONFIG_STORAGE_KEY] = JSON.parse(JSON.stringify(defaultConfig));
6413
- }
6414
- this.storage = global[CONFIG_STORAGE_KEY];
6415
- } else {
6416
- // Fallback
6417
- console.warn("tailwind-to-style: Unable to create global config storage. Config will only work within the same module.");
6418
- this.storage = JSON.parse(JSON.stringify(defaultConfig));
6419
- }
6420
- this.initialized = true;
6421
- return this.storage;
6422
- }
6423
- get() {
6424
- return this.initialize();
6425
- }
6426
- set(config) {
6427
- const storage = this.initialize();
6428
- this.deepMerge(storage, config);
6429
- return storage;
6430
- }
6431
- reset() {
6432
- const storage = this.initialize();
6433
- Object.keys(storage).forEach(key => delete storage[key]);
6434
- Object.assign(storage, JSON.parse(JSON.stringify(defaultConfig)));
6435
- return storage;
6436
- }
6437
- deepMerge(target, source) {
6438
- for (const key in source) {
6439
- if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
6440
- if (!target[key] || typeof target[key] !== "object") {
6441
- target[key] = {};
6442
- }
6443
- this.deepMerge(target[key], source[key]);
6444
- } else {
6445
- target[key] = source[key];
6446
- }
6447
- }
6448
- }
6382
+ if (!twString) {
6383
+ twString = generateTailwindCssString().replace(/\s\s+/g, " ");
6449
6384
  }
6450
- const configManager = new ConfigManager();
6451
- function getGlobalStorage() {
6452
- return configManager.get();
6453
- }
6454
- let globalConfig = null;
6455
- function initializeCss() {
6456
- if (!twString) {
6457
- // Always get fresh config from global storage
6458
- const currentConfig = getGlobalStorage();
6459
- const configForGeneration = {
6460
- ...currentConfig,
6461
- theme: {
6462
- ...currentConfig.theme
6463
- }
6464
- };
6465
- twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
6466
- }
6467
- if (!cssObject) {
6468
- cssObject = convertCssToObject(twString);
6469
- }
6470
- }
6471
- initializeCss();
6472
- function convertScreensToBreakpoints(screens) {
6473
- const breakpoints = {};
6474
- for (const [key, value] of Object.entries(screens)) {
6475
- breakpoints[key] = `@media (min-width: ${value})`;
6476
- }
6477
- return breakpoints;
6478
- }
6479
-
6480
- /**
6481
- * Set global configuration for both tws and twsx functions
6482
- * @param {Object} config - Global configuration object
6483
- * @returns {Object} Current global configuration
6484
- */
6485
- function setConfig(config) {
6486
- // Reset CSS object cache when config changes
6487
- twString = null;
6488
- cssObject = null;
6489
- configOptionsCache.clear();
6490
-
6491
- // Use ConfigManager to set config
6492
- const globalStorage = configManager.set(config);
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
- if (!globalStorage.theme.screens) {
6508
- globalStorage.theme.screens = {};
6509
- }
6510
- Object.assign(globalStorage.theme.screens, screens);
6511
- }
6512
-
6513
- // Update local reference
6514
- globalConfig = globalStorage;
6515
- initializeCss();
6516
- return {
6517
- ...globalStorage
6518
- };
6519
- }
6520
-
6521
- /**
6522
- * Get current global configuration
6523
- * @returns {Object} Current global configuration
6524
- */
6525
- function getConfig() {
6526
- globalConfig = configManager.get();
6527
- return {
6528
- ...globalConfig
6529
- };
6530
- }
6531
-
6532
- /**
6533
- * Reset global configuration to default
6534
- * @returns {Object} Default configuration
6535
- */
6536
- function resetConfig() {
6537
- twString = null;
6538
- cssObject = null;
6539
- configOptionsCache.clear();
6540
- const globalStorage = configManager.reset();
6541
-
6542
- // Update local reference
6543
- globalConfig = globalStorage;
6544
- twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
6385
+ if (!cssObject) {
6545
6386
  cssObject = convertCssToObject(twString);
6546
- return {
6547
- ...globalConfig
6548
- };
6549
6387
  }
6388
+ const breakpoints = {
6389
+ sm: "@media (min-width: 640px)",
6390
+ md: "@media (min-width: 768px)",
6391
+ lg: "@media (min-width: 1024px)",
6392
+ xl: "@media (min-width: 1280px)",
6393
+ "2xl": "@media (min-width: 1536px)"
6394
+ };
6550
6395
  const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
6551
6396
  const specialVariants = {
6552
6397
  group: (state, sel) => `.group:${state} ${sel}`,
@@ -6596,9 +6441,6 @@ function resolveVariants(selector, variants) {
6596
6441
  let media = null;
6597
6442
  let finalSelector = selector;
6598
6443
  for (const v of variants) {
6599
- // Always get fresh config from global storage
6600
- const currentConfig = getGlobalStorage();
6601
- const breakpoints = convertScreensToBreakpoints(currentConfig.theme.screens || {});
6602
6444
  if (breakpoints[v]) {
6603
6445
  media = breakpoints[v];
6604
6446
  } else if (pseudoVariants.has(v)) {
@@ -6748,11 +6590,11 @@ function separateAndResolveCSS(arr) {
6748
6590
  }
6749
6591
  }
6750
6592
 
6751
- /**
6752
- * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6753
- * @param {string} className - Class name with potential opacity modifier
6754
- * @param {string} cssDeclaration - CSS declaration to modify
6755
- * @returns {string} Modified CSS declaration with opacity applied
6593
+ /**
6594
+ * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6595
+ * @param {string} className - Class name with potential opacity modifier
6596
+ * @param {string} cssDeclaration - CSS declaration to modify
6597
+ * @returns {string} Modified CSS declaration with opacity applied
6756
6598
  */
6757
6599
  function processOpacityModifier(className, cssDeclaration) {
6758
6600
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6794,7 +6636,7 @@ function processOpacityModifier(className, cssDeclaration) {
6794
6636
 
6795
6637
  // Handle hex colors
6796
6638
  const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
6797
- modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
6639
+ modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
6798
6640
  // Convert hex to rgba
6799
6641
  const hex = hexColor.replace("#", "");
6800
6642
  let r, g, b;
@@ -6813,17 +6655,15 @@ function processOpacityModifier(className, cssDeclaration) {
6813
6655
  return modifiedDeclaration;
6814
6656
  }
6815
6657
 
6816
- /**
6817
- * Convert Tailwind class string to inline CSS styles or JSON object
6818
- * @param {string} classNames - String containing Tailwind classes to convert
6819
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6820
- * @returns {string|Object} Inline CSS string or style JSON object
6658
+ /**
6659
+ * Convert Tailwind class string to inline CSS styles or JSON object
6660
+ * @param {string} classNames - String containing Tailwind classes to convert
6661
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6662
+ * @returns {string|Object} Inline CSS string or style JSON object
6821
6663
  */
6822
6664
  function tws(classNames, convertToJson) {
6823
6665
  const totalMarker = performanceMonitor.start("tws:total");
6824
6666
  try {
6825
- // Ensure CSS is initialized with current global config
6826
- initializeCss();
6827
6667
  if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
6828
6668
  performanceMonitor.end(totalMarker);
6829
6669
  return convertToJson ? {} : "";
@@ -7198,12 +7038,12 @@ function generateCssString(styles) {
7198
7038
  return cssString.trim();
7199
7039
  }
7200
7040
 
7201
- /**
7202
- * Generate CSS string from style object with SCSS-like syntax
7203
- * Supports nested selectors, state variants, responsive variants, and @css directives
7204
- * @param {Object} obj - Object with SCSS-like style format
7205
- * @param {Object} [options] - Additional options, merges with global config
7206
- * @returns {string} Generated CSS string
7041
+ /**
7042
+ * Generate CSS string from style object with SCSS-like syntax
7043
+ * Supports nested selectors, state variants, responsive variants, and @css directives
7044
+ * @param {Object} obj - Object with SCSS-like style format
7045
+ * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7046
+ * @returns {string} Generated CSS string
7207
7047
  */
7208
7048
  function twsx(obj) {
7209
7049
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7213,13 +7053,9 @@ function twsx(obj) {
7213
7053
  console.warn("twsx: Expected an object but received:", obj);
7214
7054
  return "";
7215
7055
  }
7216
- const mergedOptions = {
7217
- ...getGlobalStorage(),
7218
- ...options
7219
- };
7220
7056
  const {
7221
7057
  inject = true
7222
- } = mergedOptions;
7058
+ } = options;
7223
7059
  const styles = {};
7224
7060
 
7225
7061
  // Create walk function with closure over styles
@@ -7314,19 +7150,19 @@ function autoInjectCss(cssString) {
7314
7150
  }
7315
7151
 
7316
7152
  // Enhanced debounced functions with performance monitoring configuration
7317
- /**
7318
- * Debounced version of tws function with performance monitoring
7319
- * @param {string} classNames - String containing Tailwind classes to convert
7320
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7321
- * @returns {string|Object} Inline CSS string or style JSON object
7153
+ /**
7154
+ * Debounced version of tws function with performance monitoring
7155
+ * @param {string} classNames - String containing Tailwind classes to convert
7156
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7157
+ * @returns {string|Object} Inline CSS string or style JSON object
7322
7158
  */
7323
7159
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7324
7160
 
7325
- /**
7326
- * Debounced version of twsx function with performance monitoring
7327
- * @param {Object} obj - Object with SCSS-like style format
7328
- * @param {Object} [options] - Additional options
7329
- * @returns {string} Generated CSS string
7161
+ /**
7162
+ * Debounced version of twsx function with performance monitoring
7163
+ * @param {Object} obj - Object with SCSS-like style format
7164
+ * @param {Object} [options] - Additional options
7165
+ * @returns {string} Generated CSS string
7330
7166
  */
7331
7167
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7332
7168
 
@@ -7362,4 +7198,4 @@ const performanceUtils = {
7362
7198
  }
7363
7199
  };
7364
7200
 
7365
- export { debouncedTws, debouncedTwsx, getConfig, performanceUtils, resetConfig, setConfig, tws, twsx };
7201
+ export { debouncedTws, debouncedTwsx, performanceUtils, tws, twsx };