@mintlify/common 1.0.319 → 1.0.320
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,3 +1,4 @@
|
|
|
1
|
+
import { walk } from 'estree-walker';
|
|
1
2
|
import { visit } from 'unist-util-visit';
|
|
2
3
|
export const MINTLIFY_TAILWIND_PREFIX = 'mint-';
|
|
3
4
|
export const rehypeDynamicTailwindCss = (tailwindSelectors) => (tree) => {
|
|
@@ -13,6 +14,29 @@ export const rehypeDynamicTailwindCss = (tailwindSelectors) => (tree) => {
|
|
|
13
14
|
className.value = transformClassNames(className.value, tailwindSelectors);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
17
|
+
if (node.type === 'mdxjsEsm' && node.data && node.data.estree) {
|
|
18
|
+
transformMdxJsEsmNode(node.data.estree, tailwindSelectors);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const transformMdxJsEsmNode = (estreeNode, tailwindSelectors) => {
|
|
23
|
+
walk(estreeNode, {
|
|
24
|
+
enter(node) {
|
|
25
|
+
if (node.type === 'JSXAttribute' &&
|
|
26
|
+
node.name.type === 'JSXIdentifier' &&
|
|
27
|
+
(node.name.name === 'className' || node.name.name === 'class')) {
|
|
28
|
+
if (node.value && node.value.type === 'Literal' && typeof node.value.value === 'string') {
|
|
29
|
+
const originalValue = node.value.value;
|
|
30
|
+
const transformedValue = transformClassNames(originalValue, tailwindSelectors);
|
|
31
|
+
if (originalValue !== transformedValue) {
|
|
32
|
+
node.value.value = transformedValue;
|
|
33
|
+
if (typeof node.value.raw === 'string') {
|
|
34
|
+
node.value.raw = JSON.stringify(transformedValue);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
16
40
|
});
|
|
17
41
|
};
|
|
18
42
|
const transformClassNames = (value, tailwindSelectors) => {
|
|
@@ -27,10 +51,19 @@ const transformClassNames = (value, tailwindSelectors) => {
|
|
|
27
51
|
return className;
|
|
28
52
|
}
|
|
29
53
|
const parts = className.split(':');
|
|
30
|
-
|
|
54
|
+
let baseClass = parts.pop();
|
|
55
|
+
const hasImportantModifier = baseClass.startsWith('!');
|
|
56
|
+
if (hasImportantModifier) {
|
|
57
|
+
baseClass = baseClass.slice(1);
|
|
58
|
+
}
|
|
31
59
|
const variants = parts;
|
|
32
|
-
if (tailwindSelectors.some((selector) =>
|
|
33
|
-
|
|
60
|
+
if (tailwindSelectors.some((selector) => {
|
|
61
|
+
// remove the leading dot and any escaping backslashes from the selector
|
|
62
|
+
// for example, .bg-orange-400\\/50 -> bg-orange-400/50
|
|
63
|
+
const normalizedSelector = selector.replace(/^\.|\\+/g, '');
|
|
64
|
+
return normalizedSelector.includes(baseClass);
|
|
65
|
+
})) {
|
|
66
|
+
const transformedClass = `${hasImportantModifier ? '!' : ''}${MINTLIFY_TAILWIND_PREFIX}${baseClass}`;
|
|
34
67
|
return [...variants, transformedClass].join(':');
|
|
35
68
|
}
|
|
36
69
|
return className;
|