@mintlify/common 1.0.1238 → 1.0.1240
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/css/tailwind.js
CHANGED
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import postcss from 'postcss';
|
|
11
|
-
import tailwindcss from 'tailwindcss-v3';
|
|
12
11
|
import { MINTLIFY_TAILWIND_PREFIX } from '../index.js';
|
|
12
|
+
import { cloneNodes, createContext, defaultExtractor, generateRules, NOT_ON_DEMAND, postProcessSteps, resolveConfig, } from './tailwindInternals.js';
|
|
13
13
|
function removeDarkClassNamePrefix(css) {
|
|
14
14
|
return css.replace(/\.mint-dark \*/g, '.dark *');
|
|
15
15
|
}
|
|
@@ -25,35 +25,74 @@ function getAllSelectors(nodes) {
|
|
|
25
25
|
}
|
|
26
26
|
return selectors;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// a postcss plugin instance re-hashes the whole config per call; one context per prefix instead
|
|
29
|
+
const runtimes = new Map();
|
|
30
|
+
// the context remembers every candidate it has classified; rebuild past this
|
|
31
|
+
const CANDIDATE_CACHE_LIMIT = 100000;
|
|
32
|
+
function candidateCount({ context }) {
|
|
33
|
+
return context.classCache.size + context.notClassCache.size;
|
|
34
|
+
}
|
|
35
|
+
function getRuntime(prefix) {
|
|
36
|
+
const cached = runtimes.get(prefix);
|
|
37
|
+
if (cached && candidateCount(cached) <= CANDIDATE_CACHE_LIMIT)
|
|
38
|
+
return cached;
|
|
39
|
+
const context = createContext(resolveConfig(Object.assign({ content: [], corePlugins: { preflight: false }, darkMode: 'class' }, (prefix && { prefix }))));
|
|
40
|
+
const runtime = { context, extract: defaultExtractor(context) };
|
|
41
|
+
runtimes.set(prefix, runtime);
|
|
42
|
+
return runtime;
|
|
43
|
+
}
|
|
44
|
+
// lines are deduped like tailwind's getClassCandidates; candidates are copied since v8 slices
|
|
45
|
+
// would keep the whole page alive in the context's caches
|
|
46
|
+
function collectCandidates(content, extract) {
|
|
47
|
+
const candidates = new Set([NOT_ON_DEMAND]);
|
|
48
|
+
const seenLines = new Set();
|
|
49
|
+
for (const rawLine of content.split('\n')) {
|
|
50
|
+
const line = rawLine.trim();
|
|
51
|
+
if (seenLines.has(line))
|
|
52
|
+
continue;
|
|
53
|
+
seenLines.add(line);
|
|
54
|
+
for (const candidate of extract(line)) {
|
|
55
|
+
if (candidate !== '!*')
|
|
56
|
+
candidates.add((' ' + candidate).slice(1));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return new Set([...candidates].sort());
|
|
60
|
+
}
|
|
61
|
+
function isComponentVariant(node) {
|
|
62
|
+
const raws = node.raws.tailwind;
|
|
63
|
+
return (typeof raws === 'object' &&
|
|
64
|
+
raws !== null &&
|
|
65
|
+
'parentLayer' in raws &&
|
|
66
|
+
raws.parentLayer === 'components');
|
|
67
|
+
}
|
|
68
|
+
function generateUtilities(content, prefix) {
|
|
69
|
+
const { context, extract } = getRuntime(prefix);
|
|
70
|
+
const rules = context.offsets.sort(generateRules(collectCandidates(content, extract), context));
|
|
71
|
+
const utilities = [];
|
|
72
|
+
// no components layer in this sheet, so tailwind drops those variants
|
|
73
|
+
const variants = [];
|
|
74
|
+
for (const [{ layer }, rule] of rules) {
|
|
75
|
+
if (layer === 'utilities')
|
|
76
|
+
utilities.push(rule);
|
|
77
|
+
else if (layer === 'variants' && !isComponentVariant(rule))
|
|
78
|
+
variants.push(rule);
|
|
79
|
+
}
|
|
80
|
+
const root = postcss.root();
|
|
81
|
+
root.append(cloneNodes(utilities, undefined, { layer: 'utilities' }));
|
|
82
|
+
if (variants.length > 0)
|
|
83
|
+
root.append(cloneNodes(variants, undefined, { layer: 'variants' }));
|
|
84
|
+
for (const step of postProcessSteps)
|
|
85
|
+
step(context)(root);
|
|
86
|
+
return root;
|
|
31
87
|
}
|
|
32
88
|
/** Get generated TailwindCSS from the content with prefix added to each class */
|
|
33
89
|
export function getDynamicTailwindCss(_a) {
|
|
34
90
|
return __awaiter(this, arguments, void 0, function* ({ content, prefix = MINTLIFY_TAILWIND_PREFIX, }) {
|
|
35
|
-
|
|
36
|
-
const tailwindPlugin = tailwindcss({
|
|
37
|
-
content: getContent(content),
|
|
38
|
-
corePlugins: { preflight: false },
|
|
39
|
-
prefix,
|
|
40
|
-
darkMode: 'class',
|
|
41
|
-
});
|
|
42
|
-
const result = yield postcss([tailwindPlugin]).process(css, { from: undefined });
|
|
43
|
-
result.css = removeDarkClassNamePrefix(result.css);
|
|
44
|
-
return result.css;
|
|
91
|
+
return removeDarkClassNamePrefix(generateUtilities(content, prefix).toString());
|
|
45
92
|
});
|
|
46
93
|
}
|
|
47
94
|
export function getTailwindSelectors(_a) {
|
|
48
95
|
return __awaiter(this, arguments, void 0, function* ({ content }) {
|
|
49
|
-
|
|
50
|
-
const tailwindPlugin = tailwindcss({
|
|
51
|
-
content: getContent(content),
|
|
52
|
-
corePlugins: { preflight: false },
|
|
53
|
-
darkMode: 'class',
|
|
54
|
-
});
|
|
55
|
-
const result = yield postcss([tailwindPlugin]).process(css, { from: undefined });
|
|
56
|
-
const selectors = getAllSelectors(result.root.nodes);
|
|
57
|
-
return selectors;
|
|
96
|
+
return getAllSelectors(generateUtilities(content, '').nodes);
|
|
58
97
|
});
|
|
59
98
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { TailwindContext } from 'tailwindcss-v3/lib/lib/setupContextUtils.js';
|
|
2
|
+
export { default as resolveConfig } from 'tailwindcss-v3/resolveConfig.js';
|
|
3
|
+
export declare const createContext: (config: ReturnType<typeof import("tailwindcss-v3/resolveConfig.js")>) => import("tailwindcss-v3/lib/lib/setupContextUtils.js").TailwindContext;
|
|
4
|
+
export declare const generateRules: (candidates: Set<string>, context: import("tailwindcss-v3/lib/lib/setupContextUtils.js").TailwindContext) => import("tailwindcss-v3/lib/lib/setupContextUtils.js").RuleEntry[];
|
|
5
|
+
export declare const defaultExtractor: (context: import("tailwindcss-v3/lib/lib/setupContextUtils.js").TailwindContext) => (content: string) => string[];
|
|
6
|
+
export declare const NOT_ON_DEMAND: string;
|
|
7
|
+
export declare const cloneNodes: (nodes: import("postcss/lib/node").ChildNode[], source?: unknown, raws?: {
|
|
8
|
+
layer: string;
|
|
9
|
+
}) => import("postcss/lib/node").ChildNode[];
|
|
10
|
+
export declare const postProcessSteps: ((context: import("tailwindcss-v3/lib/lib/setupContextUtils.js").TailwindContext) => (root: import("postcss").Root) => void)[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// internals composed by processTailwindFeatures
|
|
2
|
+
import collapseAdjacentRulesModule from 'tailwindcss-v3/lib/lib/collapseAdjacentRules.js';
|
|
3
|
+
import collapseDuplicateDeclarationsModule from 'tailwindcss-v3/lib/lib/collapseDuplicateDeclarations.js';
|
|
4
|
+
import defaultExtractorModule from 'tailwindcss-v3/lib/lib/defaultExtractor.js';
|
|
5
|
+
import evaluateTailwindFunctionsModule from 'tailwindcss-v3/lib/lib/evaluateTailwindFunctions.js';
|
|
6
|
+
import generateRulesModule from 'tailwindcss-v3/lib/lib/generateRules.js';
|
|
7
|
+
import resolveDefaultsAtRulesModule from 'tailwindcss-v3/lib/lib/resolveDefaultsAtRules.js';
|
|
8
|
+
import setupContextUtils from 'tailwindcss-v3/lib/lib/setupContextUtils.js';
|
|
9
|
+
import sharedState from 'tailwindcss-v3/lib/lib/sharedState.js';
|
|
10
|
+
import substituteScreenAtRulesModule from 'tailwindcss-v3/lib/lib/substituteScreenAtRules.js';
|
|
11
|
+
import cloneNodesModule from 'tailwindcss-v3/lib/util/cloneNodes.js';
|
|
12
|
+
export { default as resolveConfig } from 'tailwindcss-v3/resolveConfig.js';
|
|
13
|
+
// node exposes these cjs internals as a namespace; bundlers and vitest unwrap default
|
|
14
|
+
function unwrapDefault(mod) {
|
|
15
|
+
return typeof mod === 'function' ? mod : mod.default;
|
|
16
|
+
}
|
|
17
|
+
export const { createContext } = setupContextUtils;
|
|
18
|
+
export const { generateRules } = generateRulesModule;
|
|
19
|
+
export const { defaultExtractor } = defaultExtractorModule;
|
|
20
|
+
export const { NOT_ON_DEMAND } = sharedState;
|
|
21
|
+
export const cloneNodes = unwrapDefault(cloneNodesModule);
|
|
22
|
+
export const postProcessSteps = [
|
|
23
|
+
unwrapDefault(evaluateTailwindFunctionsModule),
|
|
24
|
+
unwrapDefault(substituteScreenAtRulesModule),
|
|
25
|
+
unwrapDefault(resolveDefaultsAtRulesModule),
|
|
26
|
+
unwrapDefault(collapseAdjacentRulesModule),
|
|
27
|
+
unwrapDefault(collapseDuplicateDeclarationsModule),
|
|
28
|
+
];
|
|
@@ -53,8 +53,13 @@ export function getMdx(_a) {
|
|
|
53
53
|
const traceFn = trace !== null && trace !== void 0 ? trace : ((_name, fn) => fn());
|
|
54
54
|
const processedContent = preprocessPageContent(content, variables);
|
|
55
55
|
const processedSnippets = snippets.map((snippet) => (Object.assign(Object.assign({}, snippet), { content: preprocessCustomHeadingIds(preprocessMdxFragmentCode(replaceVariables(snippet.content, variables))) })));
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
// selectors only feed rehypeDynamicTailwindCss, which rewrites class attributes
|
|
57
|
+
if (!tailwindSelectors) {
|
|
58
|
+
const hasClasses = [processedContent, ...processedSnippets.map(({ content }) => content)].some(hasClassAttribute);
|
|
59
|
+
tailwindSelectors = hasClasses
|
|
60
|
+
? yield traceFn('getMdx.getTailwindSelectors', () => __awaiter(this, void 0, void 0, function* () { return getTailwindSelectors({ content: processedContent }); }))
|
|
61
|
+
: [];
|
|
62
|
+
}
|
|
58
63
|
const snippetTreeMap = yield traceFn('getMdx.createSnippetTreeMap', () => __awaiter(this, void 0, void 0, function* () { return createSnippetTreeMap(processedSnippets); }));
|
|
59
64
|
const mdxOptionsData = {
|
|
60
65
|
subdomain,
|
|
@@ -173,6 +178,10 @@ export function getMdx(_a) {
|
|
|
173
178
|
panelMdxSourceWithNoJs }, (parseFailed && { parseFailed }));
|
|
174
179
|
});
|
|
175
180
|
}
|
|
181
|
+
const CLASS_ATTRIBUTE = /\bclass(?:Name)?\b/;
|
|
182
|
+
function hasClassAttribute(content) {
|
|
183
|
+
return CLASS_ATTRIBUTE.test(content);
|
|
184
|
+
}
|
|
176
185
|
function compileMdx(_a) {
|
|
177
186
|
return __awaiter(this, arguments, void 0, function* ({ content, failure, scope, mdxOptions, mdxOptionsNoJs, fallbackOptions, codeStyling, path, traceFn, customLanguages, skipNoJs, }) {
|
|
178
187
|
const withJs = yield traceFn('compileMdx.withJs', () => __awaiter(this, void 0, void 0, function* () {
|