tailwind-to-style 2.7.2 → 2.7.3

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.2
2
+ * tailwind-to-style v2.7.3
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
@@ -1532,12 +1532,10 @@ 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
- if (isFunction(newTheme[key])) {
1536
- newTheme[key] = newTheme[key]({
1537
- theme: keyRef => {
1538
- return configOptions.theme[keyRef];
1539
- }
1540
- });
1535
+ });
1536
+ themeKeys.forEach(key => {
1537
+ if (themeExtend[key] && newTheme[key]) {
1538
+ newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1541
1539
  }
1542
1540
  });
1543
1541
  themeKeys.forEach(key => {
@@ -1548,9 +1546,6 @@ var tailwindToStyle = (function (exports) {
1548
1546
  }
1549
1547
  });
1550
1548
  }
1551
- if (themeExtend[key]) {
1552
- newTheme[key] = Object.assign({}, newTheme[key], themeExtend[key]);
1553
- }
1554
1549
  });
1555
1550
  return {
1556
1551
  prefix: "",
@@ -6312,10 +6307,10 @@ var tailwindToStyle = (function (exports) {
6312
6307
  return null;
6313
6308
  }
6314
6309
 
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;'
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;'
6319
6314
  */
6320
6315
  function resolveCssToClearCss(cssString) {
6321
6316
  const customVars = {};
@@ -6382,19 +6377,120 @@ var tailwindToStyle = (function (exports) {
6382
6377
  }
6383
6378
  let twString = null;
6384
6379
  let cssObject = null;
6385
- if (!twString) {
6386
- twString = generateTailwindCssString().replace(/\s\s+/g, " ");
6380
+ let globalConfig = {
6381
+ theme: {
6382
+ extend: {
6383
+ colors: {}
6384
+ },
6385
+ screens: {
6386
+ sm: "640px",
6387
+ md: "768px",
6388
+ lg: "1024px",
6389
+ xl: "1280px",
6390
+ "2xl": "1536px"
6391
+ }
6392
+ },
6393
+ inject: true
6394
+ };
6395
+ function initializeCss() {
6396
+ if (!twString) {
6397
+ const configForGeneration = {
6398
+ ...globalConfig,
6399
+ theme: {
6400
+ ...globalConfig.theme
6401
+ }
6402
+ };
6403
+ twString = generateTailwindCssString(configForGeneration).replace(/\s\s+/g, " ");
6404
+ }
6405
+ if (!cssObject) {
6406
+ cssObject = convertCssToObject(twString);
6407
+ }
6408
+ }
6409
+ initializeCss();
6410
+ function convertScreensToBreakpoints(screens) {
6411
+ const breakpoints = {};
6412
+ for (const [key, value] of Object.entries(screens)) {
6413
+ breakpoints[key] = `@media (min-width: ${value})`;
6414
+ }
6415
+ return breakpoints;
6387
6416
  }
6388
- if (!cssObject) {
6417
+
6418
+ /**
6419
+ * Set global configuration for both tws and twsx functions
6420
+ * @param {Object} config - Global configuration object
6421
+ * @returns {Object} Current global configuration
6422
+ */
6423
+ function setConfig(config) {
6424
+ var _config$theme, _config$theme2, _config$theme2$extend, _config$theme3;
6425
+ // Reset CSS object cache when config changes
6426
+ twString = null;
6427
+ cssObject = null;
6428
+ configOptionsCache.clear();
6429
+ globalConfig = {
6430
+ ...globalConfig,
6431
+ ...config,
6432
+ theme: {
6433
+ ...globalConfig.theme,
6434
+ ...(config.theme || {}),
6435
+ extend: {
6436
+ ...globalConfig.theme.extend,
6437
+ ...(((_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.extend) || {}),
6438
+ colors: {
6439
+ ...globalConfig.theme.extend.colors,
6440
+ ...(((_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) || {})
6441
+ }
6442
+ }
6443
+ }
6444
+ };
6445
+
6446
+ // Handle screens configuration
6447
+ if ((_config$theme3 = config.theme) !== null && _config$theme3 !== void 0 && _config$theme3.screens) {
6448
+ globalConfig.theme.screens = {
6449
+ ...globalConfig.theme.screens,
6450
+ ...config.theme.screens
6451
+ };
6452
+ }
6453
+ initializeCss();
6454
+ return globalConfig;
6455
+ }
6456
+
6457
+ /**
6458
+ * Get current global configuration
6459
+ * @returns {Object} Current global configuration
6460
+ */
6461
+ function getConfig() {
6462
+ return {
6463
+ ...globalConfig
6464
+ };
6465
+ }
6466
+
6467
+ /**
6468
+ * Reset global configuration to default
6469
+ * @returns {Object} Default configuration
6470
+ */
6471
+ function resetConfig() {
6472
+ twString = null;
6473
+ cssObject = null;
6474
+ configOptionsCache.clear();
6475
+ globalConfig = {
6476
+ theme: {
6477
+ extend: {
6478
+ colors: {}
6479
+ },
6480
+ screens: {
6481
+ sm: "640px",
6482
+ md: "768px",
6483
+ lg: "1024px",
6484
+ xl: "1280px",
6485
+ "2xl": "1536px"
6486
+ }
6487
+ },
6488
+ inject: true
6489
+ };
6490
+ twString = generateTailwindCssString(globalConfig).replace(/\s\s+/g, " ");
6389
6491
  cssObject = convertCssToObject(twString);
6492
+ return globalConfig;
6390
6493
  }
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
- };
6398
6494
  const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
6399
6495
  const specialVariants = {
6400
6496
  group: (state, sel) => `.group:${state} ${sel}`,
@@ -6444,6 +6540,7 @@ var tailwindToStyle = (function (exports) {
6444
6540
  let media = null;
6445
6541
  let finalSelector = selector;
6446
6542
  for (const v of variants) {
6543
+ const breakpoints = convertScreensToBreakpoints(globalConfig.theme.screens || {});
6447
6544
  if (breakpoints[v]) {
6448
6545
  media = breakpoints[v];
6449
6546
  } else if (pseudoVariants.has(v)) {
@@ -6505,7 +6602,7 @@ var tailwindToStyle = (function (exports) {
6505
6602
  callCount++;
6506
6603
  clearTimeout(timeout);
6507
6604
  timeout = setTimeout(() => {
6508
- const marker = performanceMonitor.start(`debounced:${func.name || 'anonymous'}`);
6605
+ const marker = performanceMonitor.start(`debounced:${func.name || "anonymous"}`);
6509
6606
  try {
6510
6607
  const result = func.apply(context, args);
6511
6608
  performanceMonitor.end(marker);
@@ -6593,11 +6690,11 @@ var tailwindToStyle = (function (exports) {
6593
6690
  }
6594
6691
  }
6595
6692
 
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
6693
+ /**
6694
+ * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6695
+ * @param {string} className - Class name with potential opacity modifier
6696
+ * @param {string} cssDeclaration - CSS declaration to modify
6697
+ * @returns {string} Modified CSS declaration with opacity applied
6601
6698
  */
6602
6699
  function processOpacityModifier(className, cssDeclaration) {
6603
6700
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6610,20 +6707,20 @@ var tailwindToStyle = (function (exports) {
6610
6707
  let modifiedDeclaration = cssDeclaration;
6611
6708
 
6612
6709
  // Replace opacity custom properties
6613
- const opacityProperties = ['--text-opacity', '--bg-opacity', '--border-opacity', '--ring-opacity', '--divide-opacity', '--placeholder-opacity', '--text-decoration-opacity', '--outline-opacity', '--accent-opacity', '--caret-opacity'];
6710
+ const opacityProperties = ["--text-opacity", "--bg-opacity", "--border-opacity", "--ring-opacity", "--divide-opacity", "--placeholder-opacity", "--text-decoration-opacity", "--outline-opacity", "--accent-opacity", "--caret-opacity"];
6614
6711
  opacityProperties.forEach(prop => {
6615
- const propRegex = new RegExp(`${prop}\\s*:\\s*[\\d.]+`, 'gi');
6712
+ const propRegex = new RegExp(`${prop}\\s*:\\s*[\\d.]+`, "gi");
6616
6713
  modifiedDeclaration = modifiedDeclaration.replace(propRegex, `${prop}: ${alphaValue}`);
6617
6714
  });
6618
6715
 
6619
6716
  // Also handle direct color values that might not use CSS variables
6620
- const colorProperties = ['color', 'background-color', 'border-color', 'text-decoration-color', 'outline-color', 'fill', 'stroke', 'caret-color', 'accent-color'];
6717
+ const colorProperties = ["color", "background-color", "border-color", "text-decoration-color", "outline-color", "fill", "stroke", "caret-color", "accent-color"];
6621
6718
  colorProperties.forEach(prop => {
6622
6719
  // Match rgb(), rgba(), hsl(), hsla() functions
6623
- const rgbRegex = new RegExp(`(${prop}\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)`, 'gi');
6624
- const rgbaRegex = new RegExp(`(${prop}\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)`, 'gi');
6625
- const hslRegex = new RegExp(`(${prop}\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)`, 'gi');
6626
- const hslaRegex = new RegExp(`(${prop}\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)`, 'gi');
6720
+ const rgbRegex = new RegExp(`(${prop}\\s*:\\s*)rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)`, "gi");
6721
+ const rgbaRegex = new RegExp(`(${prop}\\s*:\\s*)rgba\\((\\d+),\\s*(\\d+),\\s*(\\d+),\\s*[\\d.]+\\)`, "gi");
6722
+ const hslRegex = new RegExp(`(${prop}\\s*:\\s*)hsl\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%)\\)`, "gi");
6723
+ const hslaRegex = new RegExp(`(${prop}\\s*:\\s*)hsla\\((\\d+),\\s*([\\d.]+%),\\s*([\\d.]+%),\\s*[\\d.]+\\)`, "gi");
6627
6724
 
6628
6725
  // Convert rgb to rgba with opacity
6629
6726
  modifiedDeclaration = modifiedDeclaration.replace(rgbRegex, `$1rgba($2, $3, $4, ${alphaValue})`);
@@ -6638,10 +6735,10 @@ var tailwindToStyle = (function (exports) {
6638
6735
  modifiedDeclaration = modifiedDeclaration.replace(hslaRegex, `$1hsla($2, $3, $4, ${alphaValue})`);
6639
6736
 
6640
6737
  // Handle hex colors
6641
- const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, 'gi');
6642
- modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (match, propPart, hexColor) => {
6738
+ const hexRegex = new RegExp(`(${prop}\\s*:\\s*)(#[0-9a-fA-F]{3,6})`, "gi");
6739
+ modifiedDeclaration = modifiedDeclaration.replace(hexRegex, (_, propPart, hexColor) => {
6643
6740
  // Convert hex to rgba
6644
- const hex = hexColor.replace('#', '');
6741
+ const hex = hexColor.replace("#", "");
6645
6742
  let r, g, b;
6646
6743
  if (hex.length === 3) {
6647
6744
  r = parseInt(hex[0] + hex[0], 16);
@@ -6658,15 +6755,17 @@ var tailwindToStyle = (function (exports) {
6658
6755
  return modifiedDeclaration;
6659
6756
  }
6660
6757
 
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
6758
+ /**
6759
+ * Convert Tailwind class string to inline CSS styles or JSON object
6760
+ * @param {string} classNames - String containing Tailwind classes to convert
6761
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6762
+ * @returns {string|Object} Inline CSS string or style JSON object
6666
6763
  */
6667
6764
  function tws(classNames, convertToJson) {
6668
6765
  const totalMarker = performanceMonitor.start("tws:total");
6669
6766
  try {
6767
+ // Ensure CSS is initialized with current global config
6768
+ initializeCss();
6670
6769
  if ([!classNames, typeof classNames !== "string", classNames.trim() === ""].includes(true)) {
6671
6770
  performanceMonitor.end(totalMarker);
6672
6771
  return convertToJson ? {} : "";
@@ -6693,11 +6792,11 @@ var tailwindToStyle = (function (exports) {
6693
6792
  const processMarker = performanceMonitor.start("tws:process");
6694
6793
  let cssResult = classes.map(className => {
6695
6794
  // Extract base class name without opacity modifier
6696
- const baseClassName = className.replace(/\/\d+$/, '');
6795
+ const baseClassName = className.replace(/\/\d+$/, "");
6697
6796
  let result = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6698
6797
  if (result) {
6699
6798
  // Apply opacity modifier if present
6700
- if (className.includes('/') && /\/\d+$/.test(className)) {
6799
+ if (className.includes("/") && /\/\d+$/.test(className)) {
6701
6800
  result = processOpacityModifier(className, result);
6702
6801
  }
6703
6802
  return resolveCssToClearCss(result);
@@ -6709,7 +6808,7 @@ var tailwindToStyle = (function (exports) {
6709
6808
  if (cssObject[`${baseKey}custom`]) {
6710
6809
  let customResult = cssObject[`${baseKey}custom`].replace(/custom_value/g, customValue);
6711
6810
  // Apply opacity modifier to custom values too
6712
- if (className.includes('/') && /\/\d+$/.test(className)) {
6811
+ if (className.includes("/") && /\/\d+$/.test(className)) {
6713
6812
  customResult = processOpacityModifier(className, customResult);
6714
6813
  }
6715
6814
  return customResult;
@@ -6845,7 +6944,7 @@ var tailwindToStyle = (function (exports) {
6845
6944
  } = resolveVariants(selector, rawVariants);
6846
6945
 
6847
6946
  // Extract base class name without opacity modifier for CSS lookup
6848
- const baseClassName = pureClassName.replace(/\/\d+$/, '');
6947
+ const baseClassName = pureClassName.replace(/\/\d+$/, "");
6849
6948
  let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(/(\/)/g, "\\$1")] || cssObject[baseClassName.replace(/\./g, "\\.")];
6850
6949
  if (!declarations && baseClassName.includes("[")) {
6851
6950
  const match = baseClassName.match(/^(.+?)\[(.+)\]$/);
@@ -6866,7 +6965,7 @@ var tailwindToStyle = (function (exports) {
6866
6965
  }
6867
6966
 
6868
6967
  // Apply opacity modifier if present
6869
- if (pureClassName.includes('/') && /\/\d+$/.test(pureClassName)) {
6968
+ if (pureClassName.includes("/") && /\/\d+$/.test(pureClassName)) {
6870
6969
  declarations = processOpacityModifier(pureClassName, declarations);
6871
6970
  }
6872
6971
  if (isImportant) {
@@ -7041,12 +7140,12 @@ var tailwindToStyle = (function (exports) {
7041
7140
  return cssString.trim();
7042
7141
  }
7043
7142
 
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
7143
+ /**
7144
+ * Generate CSS string from style object with SCSS-like syntax
7145
+ * Supports nested selectors, state variants, responsive variants, and @css directives
7146
+ * @param {Object} obj - Object with SCSS-like style format
7147
+ * @param {Object} [options] - Additional options, merges with global config
7148
+ * @returns {string} Generated CSS string
7050
7149
  */
7051
7150
  function twsx(obj) {
7052
7151
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7056,9 +7155,13 @@ var tailwindToStyle = (function (exports) {
7056
7155
  console.warn("twsx: Expected an object but received:", obj);
7057
7156
  return "";
7058
7157
  }
7158
+ const mergedOptions = {
7159
+ ...globalConfig,
7160
+ ...options
7161
+ };
7059
7162
  const {
7060
7163
  inject = true
7061
- } = options;
7164
+ } = mergedOptions;
7062
7165
  const styles = {};
7063
7166
 
7064
7167
  // Create walk function with closure over styles
@@ -7153,19 +7256,19 @@ var tailwindToStyle = (function (exports) {
7153
7256
  }
7154
7257
 
7155
7258
  // Enhanced debounced functions with performance monitoring configuration
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
7259
+ /**
7260
+ * Debounced version of tws function with performance monitoring
7261
+ * @param {string} classNames - String containing Tailwind classes to convert
7262
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7263
+ * @returns {string|Object} Inline CSS string or style JSON object
7161
7264
  */
7162
7265
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7163
7266
 
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
7267
+ /**
7268
+ * Debounced version of twsx function with performance monitoring
7269
+ * @param {Object} obj - Object with SCSS-like style format
7270
+ * @param {Object} [options] - Additional options
7271
+ * @returns {string} Generated CSS string
7169
7272
  */
7170
7273
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7171
7274
 
@@ -7197,13 +7300,16 @@ var tailwindToStyle = (function (exports) {
7197
7300
  enablePerformanceLogging() {
7198
7301
  let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7199
7302
  performanceMonitor.enabled = enabled && typeof performance !== "undefined";
7200
- console.log(`Performance monitoring ${enabled ? 'enabled' : 'disabled'}`);
7303
+ console.log(`Performance monitoring ${enabled ? "enabled" : "disabled"}`);
7201
7304
  }
7202
7305
  };
7203
7306
 
7204
7307
  exports.debouncedTws = debouncedTws;
7205
7308
  exports.debouncedTwsx = debouncedTwsx;
7309
+ exports.getConfig = getConfig;
7206
7310
  exports.performanceUtils = performanceUtils;
7311
+ exports.resetConfig = resetConfig;
7312
+ exports.setConfig = setConfig;
7207
7313
  exports.tws = tws;
7208
7314
  exports.twsx = twsx;
7209
7315