@mintlify/common 1.0.318 → 1.0.319

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.
@@ -10,6 +10,7 @@ type MDXOptionsData = {
10
10
  pageMetadata: PageMetaTags;
11
11
  config?: DocsConfig | MintConfig;
12
12
  subdomain?: string;
13
+ tailwindSelectors?: string[];
13
14
  };
14
15
  export declare const getMDXOptions: ({ data, remarkPlugins, rehypePlugins, mdxExtracts, }: {
15
16
  data: MDXOptionsData;
@@ -30,7 +30,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
30
30
  rehypeRawComponents,
31
31
  rehypeZoomImages,
32
32
  rehypeUnicodeIds,
33
- rehypeDynamicTailwindCss,
33
+ [rehypeDynamicTailwindCss, data.tailwindSelectors],
34
34
  ...rehypePlugins,
35
35
  ],
36
36
  format: 'mdx',
@@ -1,3 +1,3 @@
1
1
  import type { Root } from 'hast';
2
2
  export declare const MINTLIFY_TAILWIND_PREFIX = "mint-";
3
- export declare const rehypeDynamicTailwindCss: () => (tree: Root) => void;
3
+ export declare const rehypeDynamicTailwindCss: (tailwindSelectors?: string[]) => (tree: Root) => void;
@@ -1,23 +1,23 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
  export const MINTLIFY_TAILWIND_PREFIX = 'mint-';
3
- export const rehypeDynamicTailwindCss = () => {
4
- return (tree) => {
5
- visit(tree, (node) => {
6
- if ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') &&
7
- node.name &&
8
- typeof node.name === 'string' &&
9
- /^[a-z]/.test(node.name) && // check for valid html tags
10
- !node.name.includes('.') &&
11
- node.attributes.length > 0) {
12
- const className = node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'className');
13
- if (className && typeof className.value === 'string') {
14
- className.value = transformClassNames(className.value);
15
- }
3
+ export const rehypeDynamicTailwindCss = (tailwindSelectors) => (tree) => {
4
+ visit(tree, (node) => {
5
+ if ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') &&
6
+ node.name &&
7
+ typeof node.name === 'string' &&
8
+ /^[a-z]/.test(node.name) && // check for valid html tags
9
+ !node.name.includes('.') &&
10
+ node.attributes.length > 0) {
11
+ const className = node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'className');
12
+ if (className && typeof className.value === 'string') {
13
+ className.value = transformClassNames(className.value, tailwindSelectors);
16
14
  }
17
- });
18
- };
15
+ }
16
+ });
19
17
  };
20
- const transformClassNames = (value) => {
18
+ const transformClassNames = (value, tailwindSelectors) => {
19
+ if (!tailwindSelectors || !tailwindSelectors.length)
20
+ return value;
21
21
  return value
22
22
  .split(/\s+/)
23
23
  .map((className) => {
@@ -29,8 +29,11 @@ const transformClassNames = (value) => {
29
29
  const parts = className.split(':');
30
30
  const baseClass = parts.pop();
31
31
  const variants = parts;
32
- const transformedClass = `${MINTLIFY_TAILWIND_PREFIX}${baseClass}`;
33
- return [...variants, transformedClass].join(':');
32
+ if (tailwindSelectors.some((selector) => selector.includes(baseClass))) {
33
+ const transformedClass = `${MINTLIFY_TAILWIND_PREFIX}${baseClass}`;
34
+ return [...variants, transformedClass].join(':');
35
+ }
36
+ return className;
34
37
  })
35
38
  .join(' ');
36
39
  };