tailwind-to-style 3.2.0 → 3.2.1

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/core/tws.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v3.2.0
2
+ * tailwind-to-style v3.2.1
3
3
  * Runtime Tailwind CSS to inline styles converter
4
4
  *
5
5
  * @author Bigetion
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v3.2.0
2
+ * tailwind-to-style v3.2.1
3
3
  * Runtime Tailwind CSS to inline styles converter
4
4
  *
5
5
  * @author Bigetion
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v3.2.0
2
+ * tailwind-to-style v3.2.1
3
3
  * Runtime Tailwind CSS to inline styles converter
4
4
  *
5
5
  * @author Bigetion
@@ -8371,7 +8371,7 @@ function processClass(cls, selector, styles) {
8371
8371
 
8372
8372
  // Get cssObject from singleton cache
8373
8373
  const cssObject = tailwindCache.getOrGenerate(generateTailwindCssString, convertCssToObject);
8374
- let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(ESCAPE_SLASH_REGEX, "\\$1")] || cssObject[baseClassName.replace(ESCAPE_DOT_REGEX, "\\.")];
8374
+ let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(ESCAPE_SLASH_REGEX, "\\/")] || cssObject[baseClassName.replace(ESCAPE_DOT_REGEX, "\\.")];
8375
8375
  if (!declarations && baseClassName.includes("[")) {
8376
8376
  const match = CUSTOM_VALUE_FULL_REGEX.exec(baseClassName);
8377
8377
  if (match) {
@@ -8593,11 +8593,26 @@ function flattenStyleObject(obj) {
8593
8593
  flatArray.push(item);
8594
8594
  } else if (isSelectorObject(item)) {
8595
8595
  const nested = flattenStyleObject(item, currentSelector);
8596
- Object.assign(result, nested);
8596
+ // Merge nested results, handling & that resolves to same selector
8597
+ for (const ns in nested) {
8598
+ if (ns === currentSelector) {
8599
+ // & resolved to same selector — include in this array
8600
+ if (Array.isArray(nested[ns])) {
8601
+ flatArray.push(...nested[ns]);
8602
+ } else {
8603
+ flatArray.push(nested[ns]);
8604
+ }
8605
+ } else {
8606
+ result[ns] = nested[ns];
8607
+ }
8608
+ }
8597
8609
  }
8598
8610
  }
8599
8611
  if (flatArray.length > 0) {
8600
8612
  result[currentSelector] = result[currentSelector] || [];
8613
+ if (!Array.isArray(result[currentSelector])) {
8614
+ result[currentSelector] = [result[currentSelector]];
8615
+ }
8601
8616
  result[currentSelector].push(...flatArray);
8602
8617
  }
8603
8618
  } else if (isSelectorObject(val)) {
@@ -8729,6 +8744,20 @@ function twsxNoCache(obj) {
8729
8744
  // Process each selector within the media query
8730
8745
  for (const innerSelector in val) {
8731
8746
  const innerVal = val[innerSelector];
8747
+
8748
+ // Handle @css string directive inside media queries
8749
+ if (typeof innerVal === "string") {
8750
+ const trimmedInner = innerVal.trim();
8751
+ if (trimmedInner.startsWith('@css')) {
8752
+ const cssMatch = trimmedInner.match(/^@css\s*\{([\s\S]*)\}\s*$/);
8753
+ if (cssMatch) {
8754
+ const rawCss = cssMatch[1].trim();
8755
+ styles[selector][innerSelector] = styles[selector][innerSelector] || '';
8756
+ styles[selector][innerSelector] += rawCss.split(';').filter(d => d.trim()).map(d => d.trim() + ';').join(' ') + '\n';
8757
+ continue;
8758
+ }
8759
+ }
8760
+ }
8732
8761
  const baseClass = typeof innerVal === "string" ? expandGroupedClass(innerVal) : "";
8733
8762
 
8734
8763
  // Process Tailwind classes for this selector
@@ -8768,6 +8797,17 @@ function twsxNoCache(obj) {
8768
8797
  } else if (Array.isArray(val)) {
8769
8798
  for (const item of val) {
8770
8799
  if (typeof item === "string") {
8800
+ // Handle @css strings inside arrays
8801
+ const trimmedItem = item.trim();
8802
+ if (trimmedItem.startsWith('@css')) {
8803
+ const cssMatch = trimmedItem.match(/^@css\s*\{([\s\S]*)\}\s*$/);
8804
+ if (cssMatch) {
8805
+ const rawCss = cssMatch[1].trim();
8806
+ styles[selector] = styles[selector] || '';
8807
+ styles[selector] += rawCss.split(';').filter(d => d.trim()).map(d => d.trim() + ';').join(' ') + '\n';
8808
+ continue;
8809
+ }
8810
+ }
8771
8811
  baseClass += (baseClass ? " " : "") + expandGroupedClass(item);
8772
8812
  } else if (typeof item === "object" && item !== null) {
8773
8813
  Object.assign(nested, item);
@@ -9019,30 +9059,11 @@ function autoInjectCss(cssString) {
9019
9059
  document.head.appendChild(styleTag);
9020
9060
  }
9021
9061
 
9022
- // Use insertRule for better performance (avoids full stylesheet reparse)
9023
- try {
9024
- const sheet = styleTag.sheet;
9025
- if (sheet) {
9026
- // Split CSS by closing brace to insert individual rules
9027
- const rules = cssString.split('}').filter(r => r.trim());
9028
- for (const rule of rules) {
9029
- const trimmed = rule.trim();
9030
- if (trimmed) {
9031
- try {
9032
- sheet.insertRule(trimmed + '}', sheet.cssRules.length);
9033
- } catch (e) {
9034
- // Fallback for complex rules (e.g., @keyframes, @media)
9035
- styleTag.textContent += `\n${trimmed}}`;
9036
- }
9037
- }
9038
- }
9039
- } else {
9040
- styleTag.textContent += `\n${cssString}`;
9041
- }
9042
- } catch (e) {
9043
- // Ultimate fallback
9044
- styleTag.textContent += `\n${cssString}`;
9045
- }
9062
+ // Append CSS to style tag using textContent for reliability
9063
+ // Note: insertRule + textContent mixing destroys CSSOM rules,
9064
+ // so we use textContent exclusively for consistent behavior
9065
+ // with @keyframes, @media, and other nested CSS blocks.
9066
+ styleTag.textContent += `\n${cssString}`;
9046
9067
 
9047
9068
  // Log injection stats periodically
9048
9069
  if (injectedCssHashSet.size % 10 === 0) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tailwind-to-style v3.2.0
2
+ * tailwind-to-style v3.2.1
3
3
  * Runtime Tailwind CSS to inline styles converter
4
4
  *
5
5
  * @author Bigetion
@@ -8369,7 +8369,7 @@ function processClass(cls, selector, styles) {
8369
8369
 
8370
8370
  // Get cssObject from singleton cache
8371
8371
  const cssObject = tailwindCache.getOrGenerate(generateTailwindCssString, convertCssToObject);
8372
- let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(ESCAPE_SLASH_REGEX, "\\$1")] || cssObject[baseClassName.replace(ESCAPE_DOT_REGEX, "\\.")];
8372
+ let declarations = cssObject[baseClassName] || cssObject[baseClassName.replace(ESCAPE_SLASH_REGEX, "\\/")] || cssObject[baseClassName.replace(ESCAPE_DOT_REGEX, "\\.")];
8373
8373
  if (!declarations && baseClassName.includes("[")) {
8374
8374
  const match = CUSTOM_VALUE_FULL_REGEX.exec(baseClassName);
8375
8375
  if (match) {
@@ -8591,11 +8591,26 @@ function flattenStyleObject(obj) {
8591
8591
  flatArray.push(item);
8592
8592
  } else if (isSelectorObject(item)) {
8593
8593
  const nested = flattenStyleObject(item, currentSelector);
8594
- Object.assign(result, nested);
8594
+ // Merge nested results, handling & that resolves to same selector
8595
+ for (const ns in nested) {
8596
+ if (ns === currentSelector) {
8597
+ // & resolved to same selector — include in this array
8598
+ if (Array.isArray(nested[ns])) {
8599
+ flatArray.push(...nested[ns]);
8600
+ } else {
8601
+ flatArray.push(nested[ns]);
8602
+ }
8603
+ } else {
8604
+ result[ns] = nested[ns];
8605
+ }
8606
+ }
8595
8607
  }
8596
8608
  }
8597
8609
  if (flatArray.length > 0) {
8598
8610
  result[currentSelector] = result[currentSelector] || [];
8611
+ if (!Array.isArray(result[currentSelector])) {
8612
+ result[currentSelector] = [result[currentSelector]];
8613
+ }
8599
8614
  result[currentSelector].push(...flatArray);
8600
8615
  }
8601
8616
  } else if (isSelectorObject(val)) {
@@ -8727,6 +8742,20 @@ function twsxNoCache(obj) {
8727
8742
  // Process each selector within the media query
8728
8743
  for (const innerSelector in val) {
8729
8744
  const innerVal = val[innerSelector];
8745
+
8746
+ // Handle @css string directive inside media queries
8747
+ if (typeof innerVal === "string") {
8748
+ const trimmedInner = innerVal.trim();
8749
+ if (trimmedInner.startsWith('@css')) {
8750
+ const cssMatch = trimmedInner.match(/^@css\s*\{([\s\S]*)\}\s*$/);
8751
+ if (cssMatch) {
8752
+ const rawCss = cssMatch[1].trim();
8753
+ styles[selector][innerSelector] = styles[selector][innerSelector] || '';
8754
+ styles[selector][innerSelector] += rawCss.split(';').filter(d => d.trim()).map(d => d.trim() + ';').join(' ') + '\n';
8755
+ continue;
8756
+ }
8757
+ }
8758
+ }
8730
8759
  const baseClass = typeof innerVal === "string" ? expandGroupedClass(innerVal) : "";
8731
8760
 
8732
8761
  // Process Tailwind classes for this selector
@@ -8766,6 +8795,17 @@ function twsxNoCache(obj) {
8766
8795
  } else if (Array.isArray(val)) {
8767
8796
  for (const item of val) {
8768
8797
  if (typeof item === "string") {
8798
+ // Handle @css strings inside arrays
8799
+ const trimmedItem = item.trim();
8800
+ if (trimmedItem.startsWith('@css')) {
8801
+ const cssMatch = trimmedItem.match(/^@css\s*\{([\s\S]*)\}\s*$/);
8802
+ if (cssMatch) {
8803
+ const rawCss = cssMatch[1].trim();
8804
+ styles[selector] = styles[selector] || '';
8805
+ styles[selector] += rawCss.split(';').filter(d => d.trim()).map(d => d.trim() + ';').join(' ') + '\n';
8806
+ continue;
8807
+ }
8808
+ }
8769
8809
  baseClass += (baseClass ? " " : "") + expandGroupedClass(item);
8770
8810
  } else if (typeof item === "object" && item !== null) {
8771
8811
  Object.assign(nested, item);
@@ -9017,30 +9057,11 @@ function autoInjectCss(cssString) {
9017
9057
  document.head.appendChild(styleTag);
9018
9058
  }
9019
9059
 
9020
- // Use insertRule for better performance (avoids full stylesheet reparse)
9021
- try {
9022
- const sheet = styleTag.sheet;
9023
- if (sheet) {
9024
- // Split CSS by closing brace to insert individual rules
9025
- const rules = cssString.split('}').filter(r => r.trim());
9026
- for (const rule of rules) {
9027
- const trimmed = rule.trim();
9028
- if (trimmed) {
9029
- try {
9030
- sheet.insertRule(trimmed + '}', sheet.cssRules.length);
9031
- } catch (e) {
9032
- // Fallback for complex rules (e.g., @keyframes, @media)
9033
- styleTag.textContent += `\n${trimmed}}`;
9034
- }
9035
- }
9036
- }
9037
- } else {
9038
- styleTag.textContent += `\n${cssString}`;
9039
- }
9040
- } catch (e) {
9041
- // Ultimate fallback
9042
- styleTag.textContent += `\n${cssString}`;
9043
- }
9060
+ // Append CSS to style tag using textContent for reliability
9061
+ // Note: insertRule + textContent mixing destroys CSSOM rules,
9062
+ // so we use textContent exclusively for consistent behavior
9063
+ // with @keyframes, @media, and other nested CSS blocks.
9064
+ styleTag.textContent += `\n${cssString}`;
9044
9065
 
9045
9066
  // Log injection stats periodically
9046
9067
  if (injectedCssHashSet.size % 10 === 0) {