tailwindcss-patch 9.4.4 → 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-srv0kRlt.js → cli-CGyUnvFc.js} +3 -2
- package/dist/{cli-CLvyx3xl.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-Dn7cMVhi.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-oAkURzUC.d.mts → validate-B5-08lrU.d.ts} +8 -252
- package/dist/{validate-BuqRodYI.d.ts → validate-CgrG4aAY.d.mts} +8 -252
- package/dist/{validate-CUNJFfHh.mjs → validate-Q00Ccqht.mjs} +5 -1402
- package/dist/{validate-RpdgpjgT.js → validate-XiYmTZcd.js} +79 -1705
- package/package.json +4 -6
- package/src/api/tailwindcss-patcher.ts +3 -2
- 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
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import type { Node } from 'postcss'
|
|
2
|
-
import type { Config } from 'tailwindcss'
|
|
3
|
-
import type { TailwindStyleCandidateOptions, TailwindStyleSource } from '../style-candidates'
|
|
4
|
-
import type { TailwindcssRuntimeContext } from '../types'
|
|
5
|
-
import { createRequire } from 'node:module'
|
|
6
|
-
import process from 'node:process'
|
|
7
|
-
import path from 'pathe'
|
|
8
|
-
import postcss from 'postcss'
|
|
9
|
-
import { collectTailwindStyleCandidates } from '../style-candidates'
|
|
10
|
-
|
|
11
|
-
type NodeRequire = ReturnType<typeof createRequire>
|
|
12
|
-
|
|
13
|
-
interface TailwindV3CreateContextModule {
|
|
14
|
-
createContext: (
|
|
15
|
-
tailwindConfig: Config,
|
|
16
|
-
changedContent?: Array<{ content?: string, extension?: string }>,
|
|
17
|
-
root?: ReturnType<typeof postcss.root>,
|
|
18
|
-
) => TailwindcssRuntimeContext
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface TailwindV3GenerateRulesModule {
|
|
22
|
-
generateRules: (
|
|
23
|
-
candidates: Set<string>,
|
|
24
|
-
context: TailwindcssRuntimeContext,
|
|
25
|
-
) => Array<[unknown, Node]>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface TailwindV3ProcessResult {
|
|
29
|
-
css: string
|
|
30
|
-
messages: Array<Record<string, unknown>>
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface TailwindV3CollapseRulesModule {
|
|
34
|
-
default?: (context: TailwindcssRuntimeContext) => (root: postcss.Root, result: TailwindV3ProcessResult) => void
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface TailwindV3ProcessTailwindFeaturesModule {
|
|
38
|
-
default?: (
|
|
39
|
-
setupContext: () => (root: postcss.Root) => TailwindcssRuntimeContext,
|
|
40
|
-
) => (root: postcss.Root, result: TailwindV3ProcessResult) => Promise<TailwindcssRuntimeContext>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface TailwindV3ResolveDefaultsAtRulesModule {
|
|
44
|
-
default?: (context: TailwindcssRuntimeContext) => (root: postcss.Root, result: TailwindV3ProcessResult) => void
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface TailwindV3ValidateConfigModule {
|
|
48
|
-
validateConfig: (config: unknown) => Config
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface TailwindV3SharedStateModule {
|
|
52
|
-
NOT_ON_DEMAND?: string
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type ResolveConfig = (config: Config) => Config
|
|
56
|
-
|
|
57
|
-
interface TailwindV3Offsets {
|
|
58
|
-
sort: <T>(rules: Array<[unknown, T]>) => Array<[{
|
|
59
|
-
layer: 'base' | 'components' | 'defaults' | 'utilities' | 'variants'
|
|
60
|
-
}, T]>
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface TailwindV3StyleGenerateOptions extends TailwindStyleCandidateOptions {
|
|
64
|
-
/**
|
|
65
|
-
* Tailwind v3 package name or alias. Defaults to `tailwindcss`.
|
|
66
|
-
*/
|
|
67
|
-
packageName?: string
|
|
68
|
-
/**
|
|
69
|
-
* `createRequire` base used to resolve the Tailwind v3 package.
|
|
70
|
-
*/
|
|
71
|
-
cwd?: string
|
|
72
|
-
/**
|
|
73
|
-
* Inline Tailwind v3 config. `content` is injected from collected candidates.
|
|
74
|
-
*/
|
|
75
|
-
config?: Partial<Config>
|
|
76
|
-
/**
|
|
77
|
-
* Generate all layers by default. Pass a subset to emit only selected layers.
|
|
78
|
-
*/
|
|
79
|
-
layers?: TailwindV3StyleLayer[]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type TailwindV3StyleLayer = 'base' | 'components' | 'utilities' | 'variants'
|
|
83
|
-
|
|
84
|
-
export interface TailwindV3RawStyleGenerateOptions extends TailwindStyleCandidateOptions {
|
|
85
|
-
/**
|
|
86
|
-
* Tailwind v3 package name or alias. Defaults to `tailwindcss`.
|
|
87
|
-
*/
|
|
88
|
-
packageName?: string
|
|
89
|
-
/**
|
|
90
|
-
* `createRequire` base used to resolve the Tailwind v3 package.
|
|
91
|
-
*/
|
|
92
|
-
cwd?: string
|
|
93
|
-
/**
|
|
94
|
-
* Tailwind v3 entry CSS. Defaults to `@tailwind utilities;`.
|
|
95
|
-
*/
|
|
96
|
-
css?: string
|
|
97
|
-
/**
|
|
98
|
-
* Inline Tailwind v3 config. Candidate content is injected automatically.
|
|
99
|
-
*/
|
|
100
|
-
config?: Partial<Config>
|
|
101
|
-
/**
|
|
102
|
-
* Directly append generated utility rules when the CSS is exactly `@tailwind utilities;`.
|
|
103
|
-
* This mirrors Tailwind v3's internal fast path and keeps output order aligned.
|
|
104
|
-
*/
|
|
105
|
-
directUtilitiesOnly?: boolean | 'auto'
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface TailwindV3RawStyleGenerateResult {
|
|
109
|
-
version: 3
|
|
110
|
-
css: string
|
|
111
|
-
tokens: Set<string>
|
|
112
|
-
classSet: Set<string>
|
|
113
|
-
context: TailwindcssRuntimeContext
|
|
114
|
-
dependencies: string[]
|
|
115
|
-
sources: TailwindStyleSource[]
|
|
116
|
-
config: Config
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface TailwindV3StyleGenerateResult {
|
|
120
|
-
version: 3
|
|
121
|
-
css: string
|
|
122
|
-
tokens: Set<string>
|
|
123
|
-
classSet: Set<string>
|
|
124
|
-
sources: TailwindStyleSource[]
|
|
125
|
-
config: Config
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function createPackageRequire(cwd?: string): NodeRequire {
|
|
129
|
-
return createRequire(path.join(path.resolve(cwd ?? process.cwd()), 'package.json'))
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function createDefaultTailwindV3Config(tokens: Set<string>): Config {
|
|
133
|
-
return {
|
|
134
|
-
content: [
|
|
135
|
-
{
|
|
136
|
-
raw: [...tokens].join(' '),
|
|
137
|
-
extension: 'html',
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
theme: {
|
|
141
|
-
extend: {},
|
|
142
|
-
},
|
|
143
|
-
plugins: [],
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function getDefaultExport<T>(module: { default?: T } | T): T {
|
|
148
|
-
if (module && typeof module === 'object' && 'default' in module) {
|
|
149
|
-
return module.default as T
|
|
150
|
-
}
|
|
151
|
-
return module as T
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function loadTailwindV3Modules(options: Pick<TailwindV3StyleGenerateOptions, 'cwd' | 'packageName'>) {
|
|
155
|
-
const packageName = options.packageName ?? 'tailwindcss'
|
|
156
|
-
const moduleRequire = createPackageRequire(options.cwd)
|
|
157
|
-
const resolveConfig = getDefaultExport<ResolveConfig>(
|
|
158
|
-
moduleRequire(`${packageName}/lib/public/resolve-config`) as { default?: ResolveConfig } | ResolveConfig,
|
|
159
|
-
)
|
|
160
|
-
const contextModule = moduleRequire(`${packageName}/lib/lib/setupContextUtils`) as TailwindV3CreateContextModule
|
|
161
|
-
const generateRulesModule = moduleRequire(`${packageName}/lib/lib/generateRules`) as TailwindV3GenerateRulesModule
|
|
162
|
-
const collapseAdjacentRulesModule = moduleRequire(`${packageName}/lib/lib/collapseAdjacentRules`) as TailwindV3CollapseRulesModule
|
|
163
|
-
const collapseDuplicateDeclarationsModule = moduleRequire(`${packageName}/lib/lib/collapseDuplicateDeclarations`) as TailwindV3CollapseRulesModule
|
|
164
|
-
const processTailwindFeaturesModule = moduleRequire(`${packageName}/lib/processTailwindFeatures`) as TailwindV3ProcessTailwindFeaturesModule
|
|
165
|
-
const resolveDefaultsAtRulesModule = moduleRequire(`${packageName}/lib/lib/resolveDefaultsAtRules`) as TailwindV3ResolveDefaultsAtRulesModule
|
|
166
|
-
const sharedStateModule = moduleRequire(`${packageName}/lib/lib/sharedState`) as TailwindV3SharedStateModule
|
|
167
|
-
const validateConfigModule = moduleRequire(`${packageName}/lib/util/validateConfig.js`) as TailwindV3ValidateConfigModule
|
|
168
|
-
return {
|
|
169
|
-
collapseAdjacentRules: getDefaultExport(collapseAdjacentRulesModule),
|
|
170
|
-
collapseDuplicateDeclarations: getDefaultExport(collapseDuplicateDeclarationsModule),
|
|
171
|
-
createContext: contextModule.createContext,
|
|
172
|
-
generateRules: generateRulesModule.generateRules,
|
|
173
|
-
notOnDemandCandidate: sharedStateModule.NOT_ON_DEMAND ?? '*',
|
|
174
|
-
processTailwindFeatures: getDefaultExport(processTailwindFeaturesModule),
|
|
175
|
-
resolveDefaultsAtRules: getDefaultExport(resolveDefaultsAtRulesModule),
|
|
176
|
-
resolveConfig,
|
|
177
|
-
validateConfig: validateConfigModule.validateConfig,
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function createRawContentEntries(candidates: Iterable<string>, sources: TailwindStyleSource[]) {
|
|
182
|
-
const entries: Array<{ raw: string, extension: string }> = []
|
|
183
|
-
const candidateContent = [...candidates].join(' ')
|
|
184
|
-
if (candidateContent.length > 0) {
|
|
185
|
-
entries.push({
|
|
186
|
-
raw: candidateContent,
|
|
187
|
-
extension: 'html',
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
for (const source of sources) {
|
|
191
|
-
entries.push({
|
|
192
|
-
raw: source.content,
|
|
193
|
-
extension: source.extension ?? 'html',
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
return entries
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function createChangedContentEntries(candidates: Iterable<string>, sources: TailwindStyleSource[]) {
|
|
200
|
-
return createRawContentEntries(candidates, sources).map(entry => ({
|
|
201
|
-
content: entry.raw,
|
|
202
|
-
extension: entry.extension,
|
|
203
|
-
}))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function createTailwindConfigWithContent(
|
|
207
|
-
config: Partial<Config> | undefined,
|
|
208
|
-
tokens: Set<string>,
|
|
209
|
-
sources: TailwindStyleSource[],
|
|
210
|
-
) {
|
|
211
|
-
const userContent = config?.content
|
|
212
|
-
return {
|
|
213
|
-
...createDefaultTailwindV3Config(tokens),
|
|
214
|
-
...(config ?? {}),
|
|
215
|
-
content: [
|
|
216
|
-
...(Array.isArray(userContent) ? userContent : []),
|
|
217
|
-
...createRawContentEntries(tokens, sources),
|
|
218
|
-
],
|
|
219
|
-
} as Config
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function isDirectUtilitiesOnlyCss(css: string) {
|
|
223
|
-
return css.replace(/\s+/g, '') === '@tailwindutilities;'
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function sortCandidates(candidates: Iterable<string>) {
|
|
227
|
-
return [...candidates].sort((a, z) => {
|
|
228
|
-
if (a === z) {
|
|
229
|
-
return 0
|
|
230
|
-
}
|
|
231
|
-
return a < z ? -1 : 1
|
|
232
|
-
})
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function appendUtilityRules(
|
|
236
|
-
root: postcss.Root,
|
|
237
|
-
context: TailwindcssRuntimeContext,
|
|
238
|
-
rules: Array<[unknown, Node]>,
|
|
239
|
-
) {
|
|
240
|
-
const sortedRules = (context.offsets as unknown as TailwindV3Offsets).sort(rules)
|
|
241
|
-
for (const [sort, rule] of sortedRules) {
|
|
242
|
-
const tailwindRaw = rule.raws.tailwind as { parentLayer?: string } | undefined
|
|
243
|
-
if (sort.layer === 'utilities' || (sort.layer === 'variants' && tailwindRaw?.parentLayer === 'utilities')) {
|
|
244
|
-
root.append(rule.clone())
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function collectClassSet(context: TailwindcssRuntimeContext, notOnDemandCandidate: string) {
|
|
250
|
-
const classSet = new Set<string>()
|
|
251
|
-
for (const candidate of context.classCache.keys()) {
|
|
252
|
-
if (String(candidate) !== String(notOnDemandCandidate)) {
|
|
253
|
-
classSet.add(candidate)
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return classSet
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function collectDependencyMessages(result: TailwindV3ProcessResult) {
|
|
260
|
-
const dependencies = new Set<string>()
|
|
261
|
-
for (const message of result.messages) {
|
|
262
|
-
const file = message.file
|
|
263
|
-
if (message.type === 'dependency' && typeof file === 'string') {
|
|
264
|
-
dependencies.add(file)
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return [...dependencies]
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function buildStylesheetNodes(
|
|
271
|
-
rules: Array<[unknown, Node]>,
|
|
272
|
-
context: TailwindcssRuntimeContext,
|
|
273
|
-
layers: TailwindV3StyleLayer[],
|
|
274
|
-
) {
|
|
275
|
-
const sortedRules = (context.offsets as unknown as TailwindV3Offsets).sort(rules)
|
|
276
|
-
const nodes: Node[] = []
|
|
277
|
-
const layerSet = new Set<TailwindV3StyleLayer>(layers)
|
|
278
|
-
|
|
279
|
-
for (const [sort, rule] of sortedRules) {
|
|
280
|
-
const layer = sort.layer === 'defaults' ? 'base' : sort.layer
|
|
281
|
-
if (layerSet.has(layer)) {
|
|
282
|
-
nodes.push(rule.clone())
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return nodes
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function createRootFromNodes(nodes: Node[]) {
|
|
289
|
-
const root = postcss.root()
|
|
290
|
-
for (const node of nodes) {
|
|
291
|
-
root.append(node)
|
|
292
|
-
}
|
|
293
|
-
return root
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export async function generateTailwindV3Style(
|
|
297
|
-
options: TailwindV3StyleGenerateOptions = {},
|
|
298
|
-
): Promise<TailwindV3StyleGenerateResult> {
|
|
299
|
-
const tokens = await collectTailwindStyleCandidates(options)
|
|
300
|
-
const { createContext, generateRules, resolveConfig } = loadTailwindV3Modules(options)
|
|
301
|
-
const userContent = options.config?.content
|
|
302
|
-
const config = resolveConfig({
|
|
303
|
-
...createDefaultTailwindV3Config(tokens),
|
|
304
|
-
...(options.config ?? {}),
|
|
305
|
-
content: [
|
|
306
|
-
...(Array.isArray(userContent) ? userContent : []),
|
|
307
|
-
{
|
|
308
|
-
raw: [...tokens].join(' '),
|
|
309
|
-
extension: 'html',
|
|
310
|
-
},
|
|
311
|
-
],
|
|
312
|
-
} as Config)
|
|
313
|
-
const root = postcss.root()
|
|
314
|
-
const context = createContext(config, [], root)
|
|
315
|
-
const rules = generateRules(tokens, context)
|
|
316
|
-
const nodes = buildStylesheetNodes(rules, context, options.layers ?? ['base', 'components', 'utilities', 'variants'])
|
|
317
|
-
const css = createRootFromNodes(nodes).toString()
|
|
318
|
-
|
|
319
|
-
return {
|
|
320
|
-
version: 3,
|
|
321
|
-
css,
|
|
322
|
-
tokens,
|
|
323
|
-
classSet: new Set(context.classCache.keys()),
|
|
324
|
-
sources: options.sources ?? [],
|
|
325
|
-
config,
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export async function generateTailwindV3RawStyle(
|
|
330
|
-
options: TailwindV3RawStyleGenerateOptions = {},
|
|
331
|
-
): Promise<TailwindV3RawStyleGenerateResult> {
|
|
332
|
-
const tokens = await collectTailwindStyleCandidates(options)
|
|
333
|
-
const {
|
|
334
|
-
collapseAdjacentRules,
|
|
335
|
-
collapseDuplicateDeclarations,
|
|
336
|
-
createContext,
|
|
337
|
-
generateRules,
|
|
338
|
-
notOnDemandCandidate,
|
|
339
|
-
processTailwindFeatures,
|
|
340
|
-
resolveConfig,
|
|
341
|
-
resolveDefaultsAtRules,
|
|
342
|
-
validateConfig,
|
|
343
|
-
} = loadTailwindV3Modules(options)
|
|
344
|
-
const css = options.css ?? '@tailwind utilities;'
|
|
345
|
-
const config = validateConfig(resolveConfig(createTailwindConfigWithContent(options.config, tokens, options.sources ?? [])))
|
|
346
|
-
const root = postcss.parse(css, {
|
|
347
|
-
from: undefined,
|
|
348
|
-
})
|
|
349
|
-
const result: TailwindV3ProcessResult = {
|
|
350
|
-
css: '',
|
|
351
|
-
messages: [],
|
|
352
|
-
}
|
|
353
|
-
const changedContent = createChangedContentEntries(tokens, options.sources ?? [])
|
|
354
|
-
const shouldUseDirectUtilities = options.directUtilitiesOnly === true
|
|
355
|
-
|| (options.directUtilitiesOnly !== false && isDirectUtilitiesOnlyCss(css))
|
|
356
|
-
let context: TailwindcssRuntimeContext
|
|
357
|
-
|
|
358
|
-
if (shouldUseDirectUtilities) {
|
|
359
|
-
context = createContext(config, changedContent, root)
|
|
360
|
-
generateRules(new Set(sortCandidates([notOnDemandCandidate, ...tokens])), context)
|
|
361
|
-
root.removeAll()
|
|
362
|
-
appendUtilityRules(root, context, [...context.ruleCache])
|
|
363
|
-
resolveDefaultsAtRules(context)(root, result)
|
|
364
|
-
collapseAdjacentRules(context)(root, result)
|
|
365
|
-
collapseDuplicateDeclarations(context)(root, result)
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
const setupContext = () => {
|
|
369
|
-
return (currentRoot: postcss.Root) => createContext(config, changedContent, currentRoot)
|
|
370
|
-
}
|
|
371
|
-
context = await processTailwindFeatures(setupContext)(root, result)
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return {
|
|
375
|
-
version: 3,
|
|
376
|
-
css: root.toString(),
|
|
377
|
-
tokens,
|
|
378
|
-
classSet: collectClassSet(context, notOnDemandCandidate),
|
|
379
|
-
context,
|
|
380
|
-
dependencies: collectDependencyMessages(result),
|
|
381
|
-
sources: options.sources ?? [],
|
|
382
|
-
config,
|
|
383
|
-
}
|
|
384
|
-
}
|