tailwind-to-style 2.9.0 → 2.9.2

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.9.0
2
+ * tailwind-to-style v2.9.2
3
3
  * Convert tailwind classes to inline style
4
4
  *
5
5
  * @author Bigetion
@@ -3244,6 +3244,7 @@ function generator$1C() {
3244
3244
  theme = {}
3245
3245
  } = configOptions;
3246
3246
  const prefix = `${globalPrefix}font`;
3247
+ const customPrefix = `${globalPrefix}font-weight`;
3247
3248
  const {
3248
3249
  fontWeight = {}
3249
3250
  } = theme;
@@ -3251,11 +3252,20 @@ function generator$1C() {
3251
3252
  let {
3252
3253
  getCssByOptions
3253
3254
  } = _ref;
3254
- const cssString = getCssByOptions(fontWeight, (key, value) => `
3255
+ const cssString = getCssByOptions(fontWeight, (key, value) => {
3256
+ if (value === "custom_value") {
3257
+ return `
3258
+ ${customPrefix}${key} {
3259
+ font-weight: ${value};
3260
+ }
3261
+ `;
3262
+ }
3263
+ return `
3255
3264
  ${prefix}-${key} {
3256
3265
  font-weight: ${value};
3257
3266
  }
3258
- `);
3267
+ `;
3268
+ });
3259
3269
  return cssString;
3260
3270
  }, configOptions);
3261
3271
  return responsiveCssString;
@@ -6219,8 +6229,32 @@ const transition = {
6219
6229
  }
6220
6230
  };
6221
6231
 
6232
+ const fontFamily = {
6233
+ fontCustom: {
6234
+ regex: /^font-\[([^\]]+)\]$/,
6235
+ cssProp: "font-family",
6236
+ formatter: value => {
6237
+ // Decode URL-encoded value first (in case it comes from bracket encoding)
6238
+ const decodedValue = decodeURIComponent(value.replace(/__P__/g, "(").replace(/__C__/g, ")"));
6239
+
6240
+ // Split by comma and process each font
6241
+ const fonts = decodedValue.split(",").map(font => {
6242
+ const trimmedFont = font.trim();
6243
+
6244
+ // If font contains spaces and is not already quoted, add quotes
6245
+ if (trimmedFont.includes(" ") && !trimmedFont.startsWith('"') && !trimmedFont.startsWith("'")) {
6246
+ return `"${trimmedFont}"`;
6247
+ }
6248
+ return trimmedFont;
6249
+ });
6250
+ return fonts.join(", ");
6251
+ }
6252
+ }
6253
+ };
6254
+
6222
6255
  const patterns = {
6223
- ...transition
6256
+ ...transition,
6257
+ ...fontFamily
6224
6258
  };
6225
6259
 
6226
6260
  const plugins = {
@@ -6397,10 +6431,10 @@ function parseCustomClassWithPatterns(className) {
6397
6431
  return null;
6398
6432
  }
6399
6433
 
6400
- /**
6401
- * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6402
- * @param {string} cssString
6403
- * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6434
+ /**
6435
+ * Resolve all CSS custom properties (var) in a CSS string and output only clear CSS (no custom property)
6436
+ * @param {string} cssString
6437
+ * @returns {string} e.g. 'color: rgba(255,255,255,1); background: #fff;'
6404
6438
  */
6405
6439
  function resolveCssToClearCss(cssString) {
6406
6440
  const customVars = {};
@@ -6485,7 +6519,8 @@ const breakpoints = {
6485
6519
  const pseudoVariants = new Set(["hover", "focus", "focus-within", "active", "visited", "disabled", "first", "last", "checked", "invalid", "required"]);
6486
6520
  const specialVariants = {
6487
6521
  group: (state, sel) => `.group:${state} ${sel}`,
6488
- peer: (state, sel) => `.peer:${state} ~ ${sel}`
6522
+ peer: (state, sel) => `.peer:${state} ~ ${sel}`,
6523
+ dark: (state, sel) => `.dark ${sel}`
6489
6524
  };
6490
6525
  const selectorVariants = {
6491
6526
  first: () => `> :first-child`,
@@ -6535,6 +6570,9 @@ function resolveVariants(selector, variants) {
6535
6570
  media = breakpoints[v];
6536
6571
  } else if (pseudoVariants.has(v)) {
6537
6572
  finalSelector += `:${v}`;
6573
+ } else if (v === "dark") {
6574
+ // Special handling for dark variant
6575
+ finalSelector = `.dark ${finalSelector}`;
6538
6576
  } else {
6539
6577
  for (const key in specialVariants) {
6540
6578
  if (v.startsWith(`${key}-`)) {
@@ -6680,11 +6718,11 @@ function separateAndResolveCSS(arr) {
6680
6718
  }
6681
6719
  }
6682
6720
 
6683
- /**
6684
- * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6685
- * @param {string} className - Class name with potential opacity modifier
6686
- * @param {string} cssDeclaration - CSS declaration to modify
6687
- * @returns {string} Modified CSS declaration with opacity applied
6721
+ /**
6722
+ * Process opacity modifier from class name (e.g., text-red-500/50 -> 50% opacity)
6723
+ * @param {string} className - Class name with potential opacity modifier
6724
+ * @param {string} cssDeclaration - CSS declaration to modify
6725
+ * @returns {string} Modified CSS declaration with opacity applied
6688
6726
  */
6689
6727
  function processOpacityModifier(className, cssDeclaration) {
6690
6728
  const opacityMatch = className.match(/\/(\d+)$/);
@@ -6745,11 +6783,11 @@ function processOpacityModifier(className, cssDeclaration) {
6745
6783
  return modifiedDeclaration;
6746
6784
  }
6747
6785
 
6748
- /**
6749
- * Convert Tailwind class string to inline CSS styles or JSON object
6750
- * @param {string} classNames - String containing Tailwind classes to convert
6751
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6752
- * @returns {string|Object} Inline CSS string or style JSON object
6786
+ /**
6787
+ * Convert Tailwind class string to inline CSS styles or JSON object
6788
+ * @param {string} classNames - String containing Tailwind classes to convert
6789
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
6790
+ * @returns {string|Object} Inline CSS string or style JSON object
6753
6791
  */
6754
6792
  function tws(classNames, convertToJson) {
6755
6793
  const totalMarker = performanceMonitor.start("tws:total");
@@ -6874,6 +6912,10 @@ const performanceMonitor = {
6874
6912
  // Utility functions for class expansion
6875
6913
  function expandDirectiveGroups(str) {
6876
6914
  return str.replace(/(\w+)\(([^()]+)\)/g, (_, directive, content) => {
6915
+ // Special handling for dark mode syntax: dark:(classes)
6916
+ if (directive === "dark") {
6917
+ return content.trim().split(/\s+/).map(cls => `dark:${cls}`).join(" ");
6918
+ }
6877
6919
  return content.trim().split(/\s+/).map(val => {
6878
6920
  if (val.includes(":")) {
6879
6921
  const [variant, v] = val.split(":");
@@ -7013,7 +7055,7 @@ function processNestedSelectors(nested, selector, styles, walk) {
7013
7055
  const cssDeclarations = Object.entries(nestedVal).map(_ref3 => {
7014
7056
  let [key, value] = _ref3;
7015
7057
  // Ensure CSS values are properly formatted and not processed through Tailwind conversion
7016
- const cleanValue = typeof value === 'string' ? value.trim() : String(value);
7058
+ const cleanValue = typeof value === "string" ? value.trim() : String(value);
7017
7059
  return `${key}: ${cleanValue};`;
7018
7060
  }).join(" ");
7019
7061
  if (selector in styles) {
@@ -7073,12 +7115,12 @@ function walkStyleTree(selector, val, styles, walk) {
7073
7115
  }
7074
7116
 
7075
7117
  // Check if this is a @css object within the current object
7076
- if (val['@css'] && typeof val['@css'] === 'object') {
7118
+ if (val["@css"] && typeof val["@css"] === "object") {
7077
7119
  // Handle object with @css directive - process the @css part specially
7078
- const cssDeclarations = Object.entries(val['@css']).map(_ref4 => {
7120
+ const cssDeclarations = Object.entries(val["@css"]).map(_ref4 => {
7079
7121
  let [key, value] = _ref4;
7080
7122
  // Keep CSS values intact without any processing
7081
- const cleanValue = typeof value === 'string' ? value.trim() : String(value);
7123
+ const cleanValue = typeof value === "string" ? value.trim() : String(value);
7082
7124
  return `${key}: ${cleanValue};`;
7083
7125
  }).join(" ");
7084
7126
  if (selector in styles) {
@@ -7091,7 +7133,7 @@ function walkStyleTree(selector, val, styles, walk) {
7091
7133
  const otherProps = {
7092
7134
  ...val
7093
7135
  };
7094
- delete otherProps['@css'];
7136
+ delete otherProps["@css"];
7095
7137
  if (Object.keys(otherProps).length > 0) {
7096
7138
  processNestedSelectors(otherProps, selector, styles, walk);
7097
7139
  }
@@ -7182,12 +7224,12 @@ function generateCssString(styles) {
7182
7224
  return cssString.trim();
7183
7225
  }
7184
7226
 
7185
- /**
7186
- * Generate CSS string from style object with SCSS-like syntax
7187
- * Supports nested selectors, state variants, responsive variants, and @css directives
7188
- * @param {Object} obj - Object with SCSS-like style format
7189
- * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7190
- * @returns {string} Generated CSS string
7227
+ /**
7228
+ * Generate CSS string from style object with SCSS-like syntax
7229
+ * Supports nested selectors, state variants, responsive variants, and @css directives
7230
+ * @param {Object} obj - Object with SCSS-like style format
7231
+ * @param {Object} [options] - Additional options, e.g. { inject: true/false }
7232
+ * @returns {string} Generated CSS string
7191
7233
  */
7192
7234
  function twsx(obj) {
7193
7235
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -7329,19 +7371,19 @@ function autoInjectCss(cssString) {
7329
7371
  }
7330
7372
 
7331
7373
  // Enhanced debounced functions with performance monitoring configuration
7332
- /**
7333
- * Debounced version of tws function with performance monitoring
7334
- * @param {string} classNames - String containing Tailwind classes to convert
7335
- * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7336
- * @returns {string|Object} Inline CSS string or style JSON object
7374
+ /**
7375
+ * Debounced version of tws function with performance monitoring
7376
+ * @param {string} classNames - String containing Tailwind classes to convert
7377
+ * @param {boolean} convertToJson - If true, result will be JSON object, if false becomes CSS string
7378
+ * @returns {string|Object} Inline CSS string or style JSON object
7337
7379
  */
7338
7380
  const debouncedTws = debounce(tws, 50); // Faster debounce for tws
7339
7381
 
7340
- /**
7341
- * Debounced version of twsx function with performance monitoring
7342
- * @param {Object} obj - Object with SCSS-like style format
7343
- * @param {Object} [options] - Additional options
7344
- * @returns {string} Generated CSS string
7382
+ /**
7383
+ * Debounced version of twsx function with performance monitoring
7384
+ * @param {Object} obj - Object with SCSS-like style format
7385
+ * @param {Object} [options] - Additional options
7386
+ * @returns {string} Generated CSS string
7345
7387
  */
7346
7388
  const debouncedTwsx = debounce(twsx, 100); // Standard debounce for twsx
7347
7389