tailwindcss-patch 9.4.3 → 9.5.0
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/{cli-BztQHMRp.js → cli-CGyUnvFc.js} +3 -2
- package/dist/{cli-D0jXMGXf.mjs → cli-DRfALTSo.mjs} +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/commands/cli-runtime.d.mts +1 -1
- package/dist/commands/cli-runtime.d.ts +1 -1
- package/dist/commands/cli-runtime.js +2 -2
- package/dist/commands/cli-runtime.mjs +2 -2
- package/dist/{dist-DDcbvOwe.js → dist-DlC5vuI2.js} +1 -1
- package/dist/index.d.mts +7 -149
- package/dist/index.d.ts +8 -150
- package/dist/index.js +294 -521
- package/dist/index.mjs +6 -471
- package/dist/{validate-BuqRodYI.d.ts → validate-B5-08lrU.d.ts} +7 -251
- package/dist/{validate-oAkURzUC.d.mts → validate-CgrG4aAY.d.mts} +7 -251
- package/dist/{validate-Bug_WYcU.mjs → validate-Q00Ccqht.mjs} +8 -1405
- package/dist/{validate-DbuKewV-.js → validate-XiYmTZcd.js} +82 -1708
- package/package.json +8 -10
- package/src/api/tailwindcss-patcher.ts +8 -5
- package/src/extraction/candidate-extractor.ts +17 -701
- package/src/extraction/split-candidate-tokens.ts +5 -101
- package/src/options/types.ts +1 -2
- package/src/style-candidates.ts +5 -35
- package/src/style-generator.ts +11 -80
- package/src/types.ts +21 -95
- package/src/v3/index.ts +2 -2
- package/src/v4/index.ts +104 -28
- package/src/v3/style-generator.ts +0 -384
- package/src/v4/bare-arbitrary-values.ts +0 -545
- package/src/v4/candidates.ts +0 -316
- package/src/v4/engine.ts +0 -112
- package/src/v4/node-adapter.ts +0 -207
- package/src/v4/source-scan.ts +0 -432
- package/src/v4/source.ts +0 -235
- package/src/v4/style-generator.ts +0 -44
- package/src/v4/types.ts +0 -103
package/dist/index.mjs
CHANGED
|
@@ -1,311 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as resolveProjectSourceFiles, D as CacheStore, E as normalizeOptions, O as logger, S as groupTokensByFile, _ as extractRawCandidates, a as tailwindcssPatchCommands, b as extractSourceCandidatesWithPositions, c as MIGRATION_REPORT_KIND, d as getPatchStatusReport, f as runTailwindBuild, g as extractProjectCandidatesWithPositions, h as collectClassesFromTailwindV4, l as MIGRATION_REPORT_SCHEMA_VERSION, m as collectClassesFromContexts, n as VALIDATE_FAILURE_REASONS, o as migrateConfigFiles, p as loadRuntimeContexts, r as ValidateCommandError, s as restoreConfigFiles, t as VALIDATE_EXIT_CODES, u as TailwindcssPatcher, v as extractRawCandidatesWithPositions, x as extractValidCandidates, y as extractSourceCandidates } from "./validate-Q00Ccqht.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import process from "node:process";
|
|
4
3
|
import path from "pathe";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function isValidCandidateToken(token = "") {
|
|
10
|
-
return validateCandidateTokenRE.test(token);
|
|
11
|
-
}
|
|
12
|
-
const SPLIT_CACHE_LIMIT = 8192;
|
|
13
|
-
const ESCAPED_WHITESPACE_RE = /\\[nrt]/g;
|
|
14
|
-
const splitCache = /* @__PURE__ */ new Map();
|
|
15
|
-
function isSplitter(char, bracketDepth) {
|
|
16
|
-
return bracketDepth === 0 && (char === "\"" || /\s/.test(char));
|
|
17
|
-
}
|
|
18
|
-
function hasClosingQuotedArbitraryValue(code, start, quote) {
|
|
19
|
-
for (let index = start; index < code.length; index++) {
|
|
20
|
-
if (code[index] === "\\") {
|
|
21
|
-
index++;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (code[index] === quote) return code.includes("]", index + 1);
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
function splitBracketAware(code) {
|
|
29
|
-
const result = [];
|
|
30
|
-
let bracketDepth = 0;
|
|
31
|
-
let bracketQuote;
|
|
32
|
-
let start = 0;
|
|
33
|
-
for (let index = 0; index < code.length; index++) {
|
|
34
|
-
const char = code[index];
|
|
35
|
-
if (char === void 0) continue;
|
|
36
|
-
if (bracketDepth > 0 && char === "\\") {
|
|
37
|
-
index++;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (bracketDepth > 0 && (char === "\"" || char === "'")) {
|
|
41
|
-
if (bracketQuote === char) bracketQuote = void 0;
|
|
42
|
-
else if (bracketQuote === void 0 && hasClosingQuotedArbitraryValue(code, index + 1, char)) bracketQuote = char;
|
|
43
|
-
}
|
|
44
|
-
if (bracketQuote === void 0) {
|
|
45
|
-
if (char === "[" && code.includes("]", index + 1)) bracketDepth++;
|
|
46
|
-
else if (char === "]" && bracketDepth > 0) bracketDepth--;
|
|
47
|
-
}
|
|
48
|
-
if (!isSplitter(char, bracketDepth)) continue;
|
|
49
|
-
const candidate = code.slice(start, index);
|
|
50
|
-
if (isValidCandidateToken(candidate)) result.push(candidate);
|
|
51
|
-
start = index + 1;
|
|
52
|
-
}
|
|
53
|
-
const candidate = code.slice(start);
|
|
54
|
-
if (isValidCandidateToken(candidate)) result.push(candidate);
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
function splitCandidateTokens(code) {
|
|
58
|
-
const cached = splitCache.get(code);
|
|
59
|
-
if (cached) return cached;
|
|
60
|
-
const result = splitBracketAware(code.includes("\\") ? code.replace(ESCAPED_WHITESPACE_RE, " ") : code);
|
|
61
|
-
if (splitCache.size >= SPLIT_CACHE_LIMIT) splitCache.clear();
|
|
62
|
-
splitCache.set(code, result);
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/style-candidates.ts
|
|
67
|
-
async function collectTailwindStyleCandidates(options = {}) {
|
|
68
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
69
|
-
for (const candidate of options.candidates ?? []) candidates.add(candidate);
|
|
70
|
-
for (const source of options.sources ?? []) {
|
|
71
|
-
const sourceCandidates = await extractSourceCandidates(source.content, source.extension, { bareArbitraryValues: options.bareArbitraryValues });
|
|
72
|
-
for (const candidate of sourceCandidates) candidates.add(candidate);
|
|
73
|
-
}
|
|
74
|
-
return candidates;
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/v3/style-generator.ts
|
|
78
|
-
function createPackageRequire(cwd) {
|
|
79
|
-
return createRequire(path.join(path.resolve(cwd ?? process.cwd()), "package.json"));
|
|
80
|
-
}
|
|
81
|
-
function createDefaultTailwindV3Config(tokens) {
|
|
82
|
-
return {
|
|
83
|
-
content: [{
|
|
84
|
-
raw: [...tokens].join(" "),
|
|
85
|
-
extension: "html"
|
|
86
|
-
}],
|
|
87
|
-
theme: { extend: {} },
|
|
88
|
-
plugins: []
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function getDefaultExport(module) {
|
|
92
|
-
if (module && typeof module === "object" && "default" in module) return module.default;
|
|
93
|
-
return module;
|
|
94
|
-
}
|
|
95
|
-
function loadTailwindV3Modules(options) {
|
|
96
|
-
const packageName = options.packageName ?? "tailwindcss";
|
|
97
|
-
const moduleRequire = createPackageRequire(options.cwd);
|
|
98
|
-
const resolveConfig = getDefaultExport(moduleRequire(`${packageName}/lib/public/resolve-config`));
|
|
99
|
-
const contextModule = moduleRequire(`${packageName}/lib/lib/setupContextUtils`);
|
|
100
|
-
const generateRulesModule = moduleRequire(`${packageName}/lib/lib/generateRules`);
|
|
101
|
-
const collapseAdjacentRulesModule = moduleRequire(`${packageName}/lib/lib/collapseAdjacentRules`);
|
|
102
|
-
const collapseDuplicateDeclarationsModule = moduleRequire(`${packageName}/lib/lib/collapseDuplicateDeclarations`);
|
|
103
|
-
const processTailwindFeaturesModule = moduleRequire(`${packageName}/lib/processTailwindFeatures`);
|
|
104
|
-
const resolveDefaultsAtRulesModule = moduleRequire(`${packageName}/lib/lib/resolveDefaultsAtRules`);
|
|
105
|
-
const sharedStateModule = moduleRequire(`${packageName}/lib/lib/sharedState`);
|
|
106
|
-
const validateConfigModule = moduleRequire(`${packageName}/lib/util/validateConfig.js`);
|
|
107
|
-
return {
|
|
108
|
-
collapseAdjacentRules: getDefaultExport(collapseAdjacentRulesModule),
|
|
109
|
-
collapseDuplicateDeclarations: getDefaultExport(collapseDuplicateDeclarationsModule),
|
|
110
|
-
createContext: contextModule.createContext,
|
|
111
|
-
generateRules: generateRulesModule.generateRules,
|
|
112
|
-
notOnDemandCandidate: sharedStateModule.NOT_ON_DEMAND ?? "*",
|
|
113
|
-
processTailwindFeatures: getDefaultExport(processTailwindFeaturesModule),
|
|
114
|
-
resolveDefaultsAtRules: getDefaultExport(resolveDefaultsAtRulesModule),
|
|
115
|
-
resolveConfig,
|
|
116
|
-
validateConfig: validateConfigModule.validateConfig
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function createRawContentEntries(candidates, sources) {
|
|
120
|
-
const entries = [];
|
|
121
|
-
const candidateContent = [...candidates].join(" ");
|
|
122
|
-
if (candidateContent.length > 0) entries.push({
|
|
123
|
-
raw: candidateContent,
|
|
124
|
-
extension: "html"
|
|
125
|
-
});
|
|
126
|
-
for (const source of sources) entries.push({
|
|
127
|
-
raw: source.content,
|
|
128
|
-
extension: source.extension ?? "html"
|
|
129
|
-
});
|
|
130
|
-
return entries;
|
|
131
|
-
}
|
|
132
|
-
function createChangedContentEntries(candidates, sources) {
|
|
133
|
-
return createRawContentEntries(candidates, sources).map((entry) => ({
|
|
134
|
-
content: entry.raw,
|
|
135
|
-
extension: entry.extension
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
function createTailwindConfigWithContent(config, tokens, sources) {
|
|
139
|
-
const userContent = config?.content;
|
|
140
|
-
return {
|
|
141
|
-
...createDefaultTailwindV3Config(tokens),
|
|
142
|
-
...config ?? {},
|
|
143
|
-
content: [...Array.isArray(userContent) ? userContent : [], ...createRawContentEntries(tokens, sources)]
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function isDirectUtilitiesOnlyCss(css) {
|
|
147
|
-
return css.replace(/\s+/g, "") === "@tailwindutilities;";
|
|
148
|
-
}
|
|
149
|
-
function sortCandidates(candidates) {
|
|
150
|
-
return [...candidates].sort((a, z) => {
|
|
151
|
-
if (a === z) return 0;
|
|
152
|
-
return a < z ? -1 : 1;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
function appendUtilityRules(root, context, rules) {
|
|
156
|
-
const sortedRules = context.offsets.sort(rules);
|
|
157
|
-
for (const [sort, rule] of sortedRules) {
|
|
158
|
-
const tailwindRaw = rule.raws.tailwind;
|
|
159
|
-
if (sort.layer === "utilities" || sort.layer === "variants" && tailwindRaw?.parentLayer === "utilities") root.append(rule.clone());
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function collectClassSet(context, notOnDemandCandidate) {
|
|
163
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
164
|
-
for (const candidate of context.classCache.keys()) if (String(candidate) !== String(notOnDemandCandidate)) classSet.add(candidate);
|
|
165
|
-
return classSet;
|
|
166
|
-
}
|
|
167
|
-
function collectDependencyMessages(result) {
|
|
168
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
169
|
-
for (const message of result.messages) {
|
|
170
|
-
const file = message.file;
|
|
171
|
-
if (message.type === "dependency" && typeof file === "string") dependencies.add(file);
|
|
172
|
-
}
|
|
173
|
-
return [...dependencies];
|
|
174
|
-
}
|
|
175
|
-
function buildStylesheetNodes(rules, context, layers) {
|
|
176
|
-
const sortedRules = context.offsets.sort(rules);
|
|
177
|
-
const nodes = [];
|
|
178
|
-
const layerSet = new Set(layers);
|
|
179
|
-
for (const [sort, rule] of sortedRules) {
|
|
180
|
-
const layer = sort.layer === "defaults" ? "base" : sort.layer;
|
|
181
|
-
if (layerSet.has(layer)) nodes.push(rule.clone());
|
|
182
|
-
}
|
|
183
|
-
return nodes;
|
|
184
|
-
}
|
|
185
|
-
function createRootFromNodes(nodes) {
|
|
186
|
-
const root = postcss.root();
|
|
187
|
-
for (const node of nodes) root.append(node);
|
|
188
|
-
return root;
|
|
189
|
-
}
|
|
190
|
-
async function generateTailwindV3Style(options = {}) {
|
|
191
|
-
const tokens = await collectTailwindStyleCandidates(options);
|
|
192
|
-
const { createContext, generateRules, resolveConfig } = loadTailwindV3Modules(options);
|
|
193
|
-
const userContent = options.config?.content;
|
|
194
|
-
const config = resolveConfig({
|
|
195
|
-
...createDefaultTailwindV3Config(tokens),
|
|
196
|
-
...options.config ?? {},
|
|
197
|
-
content: [...Array.isArray(userContent) ? userContent : [], {
|
|
198
|
-
raw: [...tokens].join(" "),
|
|
199
|
-
extension: "html"
|
|
200
|
-
}]
|
|
201
|
-
});
|
|
202
|
-
const context = createContext(config, [], postcss.root());
|
|
203
|
-
return {
|
|
204
|
-
version: 3,
|
|
205
|
-
css: createRootFromNodes(buildStylesheetNodes(generateRules(tokens, context), context, options.layers ?? [
|
|
206
|
-
"base",
|
|
207
|
-
"components",
|
|
208
|
-
"utilities",
|
|
209
|
-
"variants"
|
|
210
|
-
])).toString(),
|
|
211
|
-
tokens,
|
|
212
|
-
classSet: new Set(context.classCache.keys()),
|
|
213
|
-
sources: options.sources ?? [],
|
|
214
|
-
config
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
async function generateTailwindV3RawStyle(options = {}) {
|
|
218
|
-
const tokens = await collectTailwindStyleCandidates(options);
|
|
219
|
-
const { collapseAdjacentRules, collapseDuplicateDeclarations, createContext, generateRules, notOnDemandCandidate, processTailwindFeatures, resolveConfig, resolveDefaultsAtRules, validateConfig } = loadTailwindV3Modules(options);
|
|
220
|
-
const css = options.css ?? "@tailwind utilities;";
|
|
221
|
-
const config = validateConfig(resolveConfig(createTailwindConfigWithContent(options.config, tokens, options.sources ?? [])));
|
|
222
|
-
const root = postcss.parse(css, { from: void 0 });
|
|
223
|
-
const result = {
|
|
224
|
-
css: "",
|
|
225
|
-
messages: []
|
|
226
|
-
};
|
|
227
|
-
const changedContent = createChangedContentEntries(tokens, options.sources ?? []);
|
|
228
|
-
const shouldUseDirectUtilities = options.directUtilitiesOnly === true || options.directUtilitiesOnly !== false && isDirectUtilitiesOnlyCss(css);
|
|
229
|
-
let context;
|
|
230
|
-
if (shouldUseDirectUtilities) {
|
|
231
|
-
context = createContext(config, changedContent, root);
|
|
232
|
-
generateRules(new Set(sortCandidates([notOnDemandCandidate, ...tokens])), context);
|
|
233
|
-
root.removeAll();
|
|
234
|
-
appendUtilityRules(root, context, [...context.ruleCache]);
|
|
235
|
-
resolveDefaultsAtRules(context)(root, result);
|
|
236
|
-
collapseAdjacentRules(context)(root, result);
|
|
237
|
-
collapseDuplicateDeclarations(context)(root, result);
|
|
238
|
-
} else {
|
|
239
|
-
const setupContext = () => {
|
|
240
|
-
return (currentRoot) => createContext(config, changedContent, currentRoot);
|
|
241
|
-
};
|
|
242
|
-
context = await processTailwindFeatures(setupContext)(root, result);
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
version: 3,
|
|
246
|
-
css: root.toString(),
|
|
247
|
-
tokens,
|
|
248
|
-
classSet: collectClassSet(context, notOnDemandCandidate),
|
|
249
|
-
context,
|
|
250
|
-
dependencies: collectDependencyMessages(result),
|
|
251
|
-
sources: options.sources ?? [],
|
|
252
|
-
config
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/v4/engine.ts
|
|
257
|
-
function resolveScanSources(options, source, compiledRoot, compiledSources) {
|
|
258
|
-
if (Array.isArray(options?.scanSources)) return options.scanSources;
|
|
259
|
-
if (options?.scanSources === true) return createTailwindV4CompiledSourceEntries(compiledRoot, compiledSources, source.base);
|
|
260
|
-
return [];
|
|
261
|
-
}
|
|
262
|
-
async function collectRawCandidates(source, options, compiledRoot, compiledSources = []) {
|
|
263
|
-
const rawCandidates = /* @__PURE__ */ new Set();
|
|
264
|
-
const extractOptions = options?.bareArbitraryValues === void 0 ? void 0 : { bareArbitraryValues: options.bareArbitraryValues };
|
|
265
|
-
for (const candidate of options?.candidates ?? []) rawCandidates.add(candidate);
|
|
266
|
-
for (const candidateSource of options?.sources ?? []) {
|
|
267
|
-
const candidates = await extractRawCandidatesWithPositions(candidateSource.content, candidateSource.extension, extractOptions);
|
|
268
|
-
for (const candidate of candidates) rawCandidates.add(candidate.rawCandidate);
|
|
269
|
-
}
|
|
270
|
-
const filesystemSources = resolveScanSources(options, source, compiledRoot, compiledSources);
|
|
271
|
-
if (filesystemSources.length > 0) for (const candidate of await extractRawCandidates(filesystemSources, extractOptions)) rawCandidates.add(candidate);
|
|
272
|
-
const inlineSources = extractTailwindV4InlineSourceCandidates(source.css);
|
|
273
|
-
for (const candidate of inlineSources.included) rawCandidates.add(candidate);
|
|
274
|
-
for (const candidate of inlineSources.excluded) rawCandidates.delete(candidate);
|
|
275
|
-
return rawCandidates;
|
|
276
|
-
}
|
|
277
|
-
function createTailwindV4Engine(source) {
|
|
278
|
-
return {
|
|
279
|
-
source,
|
|
280
|
-
loadDesignSystem() {
|
|
281
|
-
return loadTailwindV4DesignSystem(source);
|
|
282
|
-
},
|
|
283
|
-
async validateCandidates(candidates) {
|
|
284
|
-
return resolveValidTailwindV4Candidates(await loadTailwindV4DesignSystem(source), candidates);
|
|
285
|
-
},
|
|
286
|
-
async generate(options) {
|
|
287
|
-
const { compiled, dependencies } = await compileTailwindV4Source(source);
|
|
288
|
-
const rawCandidates = await collectRawCandidates(source, options, compiled.root, compiled.sources);
|
|
289
|
-
const classSet = resolveValidTailwindV4Candidates(await loadTailwindV4DesignSystem(source), rawCandidates, { ...options?.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
290
|
-
const inlineSources = extractTailwindV4InlineSourceCandidates(source.css);
|
|
291
|
-
for (const candidate of inlineSources.excluded) classSet.delete(candidate);
|
|
292
|
-
const buildCandidates = canonicalizeBareArbitraryValueCandidates(classSet, options?.bareArbitraryValues);
|
|
293
|
-
return {
|
|
294
|
-
css: replaceBareArbitraryValueSelectors(compiled.build(buildCandidates), classSet, options?.bareArbitraryValues),
|
|
295
|
-
classSet,
|
|
296
|
-
rawCandidates,
|
|
297
|
-
dependencies: Array.from(dependencies),
|
|
298
|
-
sources: compiled.sources,
|
|
299
|
-
root: compiled.root
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
//#endregion
|
|
305
|
-
//#region src/v4/source.ts
|
|
306
|
-
function resolveBase(value, fallback) {
|
|
307
|
-
return value === void 0 ? fallback : path.isAbsolute(value) ? path.resolve(value) : path.resolve(fallback, value);
|
|
308
|
-
}
|
|
4
|
+
import { collectTailwindStyleCandidates, generateCustomStyle, generateTailwindStyle, isValidCandidateToken, splitCandidateTokens, validateCandidateTokenRE } from "@tailwindcss-mangle/engine";
|
|
5
|
+
import { generateTailwindV3RawStyle, generateTailwindV3Style } from "@tailwindcss-mangle/engine/v3";
|
|
6
|
+
import { TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, TAILWIND_V4_IGNORED_CONTENT_DIRS, TAILWIND_V4_IGNORED_EXTENSIONS, TAILWIND_V4_IGNORED_FILES, canonicalizeBareArbitraryValueCandidates, collectTailwindV4StyleCandidates, createTailwindV4CompiledSourceEntries, createTailwindV4DefaultIgnoreSources, createTailwindV4Engine, createTailwindV4RootSources, createTailwindV4SourceEntryMatcher, createTailwindV4SourceExclusionMatcher, escapeCssClassName, expandTailwindV4SourceEntries, expandTailwindV4SourceEntryBraces, extractBareArbitraryValueSourceCandidates, extractBareArbitraryValueSourceCandidatesWithPositions, generateTailwindV4Style, isBareArbitraryValuesEnabled, isFileExcludedByTailwindV4SourceEntries, isFileMatchedByTailwindV4SourceEntries, loadTailwindV4DesignSystem, mergeTailwindV4SourceEntries, normalizeTailwindV4ScannerSources, normalizeTailwindV4SourceEntries, replaceBareArbitraryValueSelectors, resolveBareArbitraryValueCandidate, resolveSourceScanPath, resolveTailwindV4Source, resolveTailwindV4Source as resolveTailwindV4Source$1, resolveTailwindV4SourceBaseCandidates, resolveTailwindV4SourceEntry, resolveValidTailwindV4Candidates } from "@tailwindcss-mangle/engine/v4";
|
|
7
|
+
//#region src/v4/index.ts
|
|
309
8
|
function uniquePaths(values) {
|
|
310
9
|
const result = [];
|
|
311
10
|
for (const value of values) {
|
|
@@ -315,113 +14,6 @@ function uniquePaths(values) {
|
|
|
315
14
|
}
|
|
316
15
|
return result;
|
|
317
16
|
}
|
|
318
|
-
function toCssImportPath(value) {
|
|
319
|
-
return value.replaceAll("\\", "/");
|
|
320
|
-
}
|
|
321
|
-
function quoteCssImport(value) {
|
|
322
|
-
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
323
|
-
}
|
|
324
|
-
function isPostcssPluginSpecifier(packageName) {
|
|
325
|
-
return packageName === "@tailwindcss/postcss" || /(?:^|[/\\])@tailwindcss[/\\]postcss(?:[/\\]|$)/.test(packageName) || /(?:^|[/\\])postcss(?:[/\\]|$)/i.test(packageName) || /postcss\.config\.[cm]?[jt]s$/i.test(packageName);
|
|
326
|
-
}
|
|
327
|
-
function createDefaultCss(packageName) {
|
|
328
|
-
return `@import "${quoteCssImport(toCssImportPath(packageName && !isPostcssPluginSpecifier(packageName) ? packageName : "tailwindcss"))}";`;
|
|
329
|
-
}
|
|
330
|
-
async function pathExists(filePath) {
|
|
331
|
-
try {
|
|
332
|
-
await promises.access(filePath);
|
|
333
|
-
return true;
|
|
334
|
-
} catch {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
async function resolveCssEntries(entries, projectRoot, base) {
|
|
339
|
-
const resolvedEntries = entries.map((entry) => ({
|
|
340
|
-
original: entry,
|
|
341
|
-
absolute: path.isAbsolute(entry) ? path.resolve(entry) : path.resolve(projectRoot, entry)
|
|
342
|
-
}));
|
|
343
|
-
const resolvedBase = base ?? path.dirname(resolvedEntries[0]?.absolute ?? projectRoot);
|
|
344
|
-
const dependencies = resolvedEntries.map((entry) => entry.absolute);
|
|
345
|
-
const cssParts = [];
|
|
346
|
-
for (const entry of resolvedEntries) {
|
|
347
|
-
if (await pathExists(entry.absolute)) {
|
|
348
|
-
cssParts.push(await promises.readFile(entry.absolute, "utf8"));
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
const importPath = path.isAbsolute(entry.original) ? entry.absolute : path.relative(resolvedBase, entry.absolute);
|
|
352
|
-
cssParts.push(`@import "${quoteCssImport(toCssImportPath(importPath))}";`);
|
|
353
|
-
}
|
|
354
|
-
return {
|
|
355
|
-
base: resolvedBase,
|
|
356
|
-
css: cssParts.join("\n"),
|
|
357
|
-
dependencies
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
function resolveCssSources(sources, projectRoot, base) {
|
|
361
|
-
const resolvedSources = sources.map((source) => ({
|
|
362
|
-
...source,
|
|
363
|
-
base: source.base === void 0 ? void 0 : resolveBase(source.base, projectRoot),
|
|
364
|
-
file: source.file === void 0 ? void 0 : path.isAbsolute(source.file) ? path.resolve(source.file) : path.resolve(projectRoot, source.file),
|
|
365
|
-
dependencies: source.dependencies?.map((dependency) => path.isAbsolute(dependency) ? path.resolve(dependency) : path.resolve(projectRoot, dependency)) ?? []
|
|
366
|
-
}));
|
|
367
|
-
const firstSource = resolvedSources[0];
|
|
368
|
-
const resolvedBase = base ?? firstSource?.base ?? (firstSource?.file ? path.dirname(firstSource.file) : projectRoot);
|
|
369
|
-
const dependencies = resolvedSources.flatMap((source) => [source.file, ...source.dependencies]).filter((dependency) => Boolean(dependency));
|
|
370
|
-
return {
|
|
371
|
-
base: resolvedBase,
|
|
372
|
-
css: resolvedSources.map((source) => source.css).join("\n"),
|
|
373
|
-
dependencies
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
function normalizeResolvedSource(source) {
|
|
377
|
-
const baseFallbacks = uniquePaths([
|
|
378
|
-
...source.baseFallbacks,
|
|
379
|
-
source.projectRoot,
|
|
380
|
-
source.cwd
|
|
381
|
-
]).filter((base) => base !== source.base);
|
|
382
|
-
return {
|
|
383
|
-
projectRoot: source.projectRoot,
|
|
384
|
-
base: source.base,
|
|
385
|
-
baseFallbacks,
|
|
386
|
-
css: source.css,
|
|
387
|
-
dependencies: Array.from(new Set(source.dependencies.map((dependency) => path.resolve(dependency))))
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
async function resolveTailwindV4Source(options = {}) {
|
|
391
|
-
const projectRoot = resolveBase(options.projectRoot, process.cwd());
|
|
392
|
-
const cwd = resolveBase(options.cwd, projectRoot);
|
|
393
|
-
const configuredBase = options.base === void 0 ? void 0 : resolveBase(options.base, projectRoot);
|
|
394
|
-
const baseFallbacks = uniquePaths(options.baseFallbacks?.map((base) => resolveBase(base, projectRoot)) ?? []);
|
|
395
|
-
if (options.css !== void 0) return normalizeResolvedSource({
|
|
396
|
-
projectRoot,
|
|
397
|
-
cwd,
|
|
398
|
-
base: configuredBase ?? cwd,
|
|
399
|
-
baseFallbacks,
|
|
400
|
-
css: options.css,
|
|
401
|
-
dependencies: []
|
|
402
|
-
});
|
|
403
|
-
if (options.cssEntries?.length || options.cssSources?.length) {
|
|
404
|
-
const entries = options.cssEntries?.length ? await resolveCssEntries(options.cssEntries, projectRoot, configuredBase) : void 0;
|
|
405
|
-
const sources = options.cssSources?.length ? resolveCssSources(options.cssSources, projectRoot, configuredBase) : void 0;
|
|
406
|
-
const css = [entries?.css, sources?.css].filter(Boolean).join("\n");
|
|
407
|
-
return normalizeResolvedSource({
|
|
408
|
-
projectRoot,
|
|
409
|
-
cwd,
|
|
410
|
-
base: configuredBase ?? entries?.base ?? sources?.base ?? cwd,
|
|
411
|
-
baseFallbacks,
|
|
412
|
-
css,
|
|
413
|
-
dependencies: [...entries?.dependencies ?? [], ...sources?.dependencies ?? []]
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
return normalizeResolvedSource({
|
|
417
|
-
projectRoot,
|
|
418
|
-
cwd,
|
|
419
|
-
base: configuredBase ?? cwd,
|
|
420
|
-
baseFallbacks,
|
|
421
|
-
css: createDefaultCss(options.packageName),
|
|
422
|
-
dependencies: []
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
17
|
function resolveConfigDir(config, projectRoot) {
|
|
426
18
|
if (!config) return;
|
|
427
19
|
const configPath = path.isAbsolute(config) ? config : path.resolve(projectRoot, config);
|
|
@@ -451,64 +43,7 @@ function tailwindV4SourceOptionsFromPatchOptions(options) {
|
|
|
451
43
|
return createSourceOptionsFromNormalizedPatchOptions(normalizeOptions(options));
|
|
452
44
|
}
|
|
453
45
|
async function resolveTailwindV4SourceFromPatchOptions(options) {
|
|
454
|
-
return resolveTailwindV4Source(tailwindV4SourceOptionsFromPatchOptions(options));
|
|
455
|
-
}
|
|
456
|
-
//#endregion
|
|
457
|
-
//#region src/v4/style-generator.ts
|
|
458
|
-
function createSourceOptions(options) {
|
|
459
|
-
return {
|
|
460
|
-
...options.projectRoot === void 0 ? {} : { projectRoot: options.projectRoot },
|
|
461
|
-
...options.cwd === void 0 ? {} : { cwd: options.cwd },
|
|
462
|
-
...options.base === void 0 ? {} : { base: options.base },
|
|
463
|
-
...options.baseFallbacks === void 0 ? {} : { baseFallbacks: options.baseFallbacks },
|
|
464
|
-
...options.css === void 0 ? {} : { css: options.css },
|
|
465
|
-
...options.cssSources === void 0 ? {} : { cssSources: options.cssSources },
|
|
466
|
-
...options.cssEntries === void 0 ? {} : { cssEntries: options.cssEntries },
|
|
467
|
-
...options.packageName === void 0 ? {} : { packageName: options.packageName }
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
async function collectTailwindV4StyleCandidates(options) {
|
|
471
|
-
return collectTailwindStyleCandidates(options);
|
|
472
|
-
}
|
|
473
|
-
async function generateTailwindV4Style(options = {}) {
|
|
474
|
-
const source = options.source ?? await resolveTailwindV4Source(createSourceOptions(options));
|
|
475
|
-
const candidates = await collectTailwindV4StyleCandidates(options);
|
|
476
|
-
const result = await createTailwindV4Engine(source).generate({
|
|
477
|
-
candidates,
|
|
478
|
-
...options.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues },
|
|
479
|
-
...options.scanSources === void 0 ? {} : { scanSources: options.scanSources }
|
|
480
|
-
});
|
|
481
|
-
return {
|
|
482
|
-
...result,
|
|
483
|
-
tokens: result.rawCandidates,
|
|
484
|
-
source
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
//#endregion
|
|
488
|
-
//#region src/style-generator.ts
|
|
489
|
-
async function generateCustomStyle(options) {
|
|
490
|
-
const tokens = await collectTailwindStyleCandidates(options);
|
|
491
|
-
const classSet = new Set(tokens);
|
|
492
|
-
const sources = options.sources ?? [];
|
|
493
|
-
return {
|
|
494
|
-
version: "custom",
|
|
495
|
-
css: await options.generate({
|
|
496
|
-
tokens,
|
|
497
|
-
classSet,
|
|
498
|
-
sources
|
|
499
|
-
}),
|
|
500
|
-
tokens,
|
|
501
|
-
classSet,
|
|
502
|
-
sources
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
async function generateTailwindStyle(options) {
|
|
506
|
-
if (options.version === 3) return generateTailwindV3Style(options);
|
|
507
|
-
if (options.version === 4) return {
|
|
508
|
-
...await generateTailwindV4Style(options),
|
|
509
|
-
version: 4
|
|
510
|
-
};
|
|
511
|
-
return generateCustomStyle(options);
|
|
46
|
+
return resolveTailwindV4Source$1(tailwindV4SourceOptionsFromPatchOptions(options));
|
|
512
47
|
}
|
|
513
48
|
//#endregion
|
|
514
49
|
//#region src/public-api.ts
|