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.esm.js 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
@@ -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,196 +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
-
6398
- // Detect environment and create global storage
6399
- function getGlobalStorage() {
6400
- if (typeof window !== "undefined") {
6401
- // Browser environment - use window object
6402
- if (!window[CONFIG_STORAGE_KEY]) {
6403
- window[CONFIG_STORAGE_KEY] = {
6404
- ...defaultConfig
6405
- };
6406
- }
6407
- return window[CONFIG_STORAGE_KEY];
6408
- } else if (typeof global !== "undefined") {
6409
- // Node.js environment - use global object
6410
- if (!global[CONFIG_STORAGE_KEY]) {
6411
- global[CONFIG_STORAGE_KEY] = {
6412
- ...defaultConfig
6413
- };
6414
- }
6415
- return global[CONFIG_STORAGE_KEY];
6416
- } else {
6417
- // Fallback - use module-level variable (will work only within same file)
6418
- console.warn("tailwind-to-style: Unable to create global config storage. Config will only work within the same module.");
6419
- return defaultConfig;
6420
- }
6421
- }
6422
-
6423
- // Get global config reference
6424
- let globalConfig = getGlobalStorage();
6425
- function initializeCss() {
6426
- if (!twString) {
6427
- // Always get fresh config from global storage
6428
- const currentConfig = getGlobalStorage();
6429
- const configForGeneration = {
6430
- ...currentConfig,
6431
- theme: {
6432
- ...currentConfig.theme
6433
- }
6434
- };
6435
- twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
6436
- }
6437
- if (!cssObject) {
6438
- cssObject = convertCssToObject(twString);
6439
- }
6440
- }
6441
- initializeCss();
6442
- function convertScreensToBreakpoints(screens) {
6443
- const breakpoints = {};
6444
- for (const [key, value] of Object.entries(screens)) {
6445
- breakpoints[key] = `@media (min-width: ${value})`;
6446
- }
6447
- return breakpoints;
6448
- }
6449
-
6450
- /**
6451
- * Set global configuration for both tws and twsx functions
6452
- * @param {Object} config - Global configuration object
6453
- * @returns {Object} Current global configuration
6454
- */
6455
- function setConfig(config) {
6456
- var _config$theme, _config$theme2, _config$theme2$extend, _config$theme3;
6457
- // Reset CSS object cache when config changes
6458
- twString = null;
6459
- cssObject = null;
6460
- configOptionsCache.clear();
6461
-
6462
- // Get current global storage reference
6463
- const globalStorage = getGlobalStorage();
6464
-
6465
- // Update global storage directly
6466
- Object.assign(globalStorage, {
6467
- ...globalStorage,
6468
- ...config,
6469
- theme: {
6470
- ...globalStorage.theme,
6471
- ...(config.theme || {}),
6472
- extend: {
6473
- ...globalStorage.theme.extend,
6474
- ...(((_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.extend) || {}),
6475
- colors: {
6476
- ...globalStorage.theme.extend.colors,
6477
- ...(((_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) || {})
6478
- }
6479
- }
6480
- }
6481
- });
6482
-
6483
- // Handle screens configuration
6484
- if ((_config$theme3 = config.theme) !== null && _config$theme3 !== void 0 && _config$theme3.screens) {
6485
- globalStorage.theme.screens = {
6486
- ...globalStorage.theme.screens,
6487
- ...config.theme.screens
6488
- };
6489
- }
6490
-
6491
- // Handle legacy breakpoints with deprecation warning
6492
- if (config.breakpoints) {
6493
- console.warn("Warning: config.breakpoints is deprecated. Use config.theme.screens instead.");
6494
-
6495
- // Convert legacy breakpoints to screens format
6496
- const screens = {};
6497
- for (const [key, value] of Object.entries(config.breakpoints)) {
6498
- // Extract min-width value from media query
6499
- const match = value.match(/min-width:\s*([^)]+)/);
6500
- if (match) {
6501
- screens[key] = match[1].trim();
6502
- }
6503
- }
6504
- globalStorage.theme.screens = {
6505
- ...globalStorage.theme.screens,
6506
- ...screens
6507
- };
6508
- }
6509
-
6510
- // Update local reference
6511
- globalConfig = globalStorage;
6512
- initializeCss();
6513
- return {
6514
- ...globalConfig
6515
- };
6516
- }
6517
-
6518
- /**
6519
- * Get current global configuration
6520
- * @returns {Object} Current global configuration
6521
- */
6522
- function getConfig() {
6523
- // Always get fresh reference from global storage
6524
- globalConfig = getGlobalStorage();
6525
- return {
6526
- ...globalConfig
6527
- };
6382
+ if (!twString) {
6383
+ twString = generateTailwindCssString().replace(/\s\s+/g, " ");
6528
6384
  }
6529
-
6530
- /**
6531
- * Reset global configuration to default
6532
- * @returns {Object} Default configuration
6533
- */
6534
- function resetConfig() {
6535
- twString = null;
6536
- cssObject = null;
6537
- configOptionsCache.clear();
6538
-
6539
- // Get global storage reference and reset it
6540
- const globalStorage = getGlobalStorage();
6541
-
6542
- // Reset to default config
6543
- Object.assign(globalStorage, {
6544
- theme: {
6545
- extend: {
6546
- colors: {}
6547
- },
6548
- screens: {
6549
- sm: "640px",
6550
- md: "768px",
6551
- lg: "1024px",
6552
- xl: "1280px",
6553
- "2xl": "1536px"
6554
- }
6555
- },
6556
- inject: true
6557
- });
6558
-
6559
- // Update local reference
6560
- globalConfig = globalStorage;
6561
- twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
6385
+ if (!cssObject) {
6562
6386
  cssObject = convertCssToObject(twString);
6563
- return {
6564
- ...globalConfig
6565
- };
6566
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
+ };
6567
6395
  const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
6568
6396
  const specialVariants = {
6569
6397
  group: (state, sel) => `.group:${state} ${sel}`,
@@ -6613,9 +6441,6 @@ function resolveVariants(selector, variants) {
6613
6441
  let media = null;
6614
6442
  let finalSelector = selector;
6615
6443
  for (const v of variants) {
6616
- // Always get fresh config from global storage
6617
- const currentConfig = getGlobalStorage();
6618
- const breakpoints = convertScreensToBreakpoints(currentConfig.theme.screens || {});
6619
6444
  if (breakpoints[v]) {
6620
6445
  media = breakpoints[v];
6621
6446
  } else if (pseudoVariants.has(v)) {
@@ -6765,11 +6590,11 @@ function separateAndResolveCSS(arr) {
6765
6590
  }
6766
6591
  }
6767
6592
 
6768
- /**
6769
- * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6770
- * @param {string} className - Class name with potential opacity modifier
6771
- * @param {string} cssDeclaration - CSS declaration to modify
6772
- * @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
6773
6598
  */
6774
6599
  function processOpacityModifier(className, cssDeclaration) {
6775
6600
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6811,7 +6636,7 @@ function processOpacityModifier(className, cssDeclaration) {
6811
6636
 
6812
6637
  // Handle hex colors
6813
6638
  const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
6814
- modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
6639
+ modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
6815
6640
  // Convert hex to rgba
6816
6641
  const hex = hexColor.replace("#", "");
6817
6642
  let r, g, b;
@@ -6830,17 +6655,15 @@ function processOpacityModifier(className, cssDeclaration) {
6830
6655
  return modifiedDeclaration;
6831
6656
  }
6832
6657
 
6833
- /**
6834
- * Convert Tailwind class string to inline CSS styles or JSON object
6835
- * @param {string} classNames - String containing Tailwind classes to convert
6836
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6837
- * @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
6838
6663
  */
6839
6664
  function tws(classNames, convertToJson) {
6840
6665
  const totalMarker = performanceMonitor.start("tws:total");
6841
6666
  try {
6842
- // Ensure CSS is initialized with current global config
6843
- initializeCss();
6844
6667
  if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
6845
6668
  performanceMonitor.end(totalMarker);
6846
6669
  return convertToJson ? {} : "";
@@ -7215,12 +7038,12 @@ function generateCssString(styles) {
7215
7038
  return cssString.trim();
7216
7039
  }
7217
7040
 
7218
- /**
7219
- * Generate CSS string from style object with SCSS-like syntax
7220
- * Supports nested selectors, state variants, responsive variants, and @css directives
7221
- * @param {Object} obj - Object with SCSS-like style format
7222
- * @param {Object} [options] - Additional options, merges with global config
7223
- * @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
7224
7047
  */
7225
7048
  function twsx(obj) {
7226
7049
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7230,13 +7053,9 @@ function twsx(obj) {
7230
7053
  console.warn("twsx: Expected an object but received:", obj);
7231
7054
  return "";
7232
7055
  }
7233
- const mergedOptions = {
7234
- ...getGlobalStorage(),
7235
- ...options
7236
- };
7237
7056
  const {
7238
7057
  inject = true
7239
- } = mergedOptions;
7058
+ } = options;
7240
7059
  const styles = {};
7241
7060
 
7242
7061
  // Create walk function with closure over styles
@@ -7331,19 +7150,19 @@ function autoInjectCss(cssString) {
7331
7150
  }
7332
7151
 
7333
7152
  // Enhanced debounced functions with performance monitoring configuration
7334
- /**
7335
- * Debounced version of tws function with performance monitoring
7336
- * @param {string} classNames - String containing Tailwind classes to convert
7337
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7338
- * @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
7339
7158
  */
7340
7159
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7341
7160
 
7342
- /**
7343
- * Debounced version of twsx function with performance monitoring
7344
- * @param {Object} obj - Object with SCSS-like style format
7345
- * @param {Object} [options] - Additional options
7346
- * @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
7347
7166
  */
7348
7167
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7349
7168
 
@@ -7379,4 +7198,4 @@ const performanceUtils = {
7379
7198
  }
7380
7199
  };
7381
7200
 
7382
- export { debouncedTws, debouncedTwsx, getConfig, performanceUtils, resetConfig, setConfig, tws, twsx };
7201
+ export { debouncedTws, debouncedTwsx, performanceUtils, tws, twsx };