@maizzle/framework 6.0.0-0 → 6.0.0-2
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/CHANGELOG.md +75 -0
- package/package.json +2 -2
- package/src/posthtml/index.js +8 -12
- package/src/posthtml/plugins/lowerCssSyntax.js +43 -0
- package/src/posthtml/plugins/postcss/cleanupTailwindArtifacts.js +78 -0
- package/src/posthtml/plugins/postcss/removeDuplicateSelectors.js +35 -0
- package/src/transformers/inline.js +60 -58
- package/types/config.d.ts +25 -3
- package/types/css/combineMediaQueries.d.ts +90 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,81 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [6.0.0-2] - 2025-07-11
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- fixed an issue with duplicate CSS selectors for utilities that cannot be disabled in Tailwind CSS v4, like `text-decoration`
|
|
12
|
+
- fixed an issue where some Tailwind directives like `@layer` or `@property` were still present in the final build, even though they were not used
|
|
13
|
+
|
|
14
|
+
## [6.0.0-1] - 2025-07-11
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- types for `css.combineMediaQueries` and `css.lightningcss` options in the config
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- made `combineMediaQueries` configurable through the `css.combineMediaQueries` option, which can be set to an object with options for `postcss-sort-media-queries` or to `false` to disable it
|
|
23
|
+
- made `lightningcss` configurable through the `css.lightningcss` option
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- fixed an issue with CSS syntax lowering, we now use `lightningcss` directly instead of `postcss-lightningcss` which was it to trip on CSS inside `style=""` attributes
|
|
28
|
+
|
|
29
|
+
## [6.0.0-0] - 2025-07-10
|
|
30
|
+
|
|
31
|
+
This release adds initial support for Tailwind CSS v4 in Maizzle.
|
|
32
|
+
|
|
33
|
+
To jump right in, simply use the `next` branch of the Starter:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
git clone -b next https://github.com/maizzle/maizzle.git
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or, if you have a project:
|
|
40
|
+
|
|
41
|
+
1. Update `package.json`:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"private": true,
|
|
46
|
+
"type": "module",
|
|
47
|
+
"scripts": {
|
|
48
|
+
"dev": "maizzle serve",
|
|
49
|
+
"build": "maizzle build"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@maizzle/framework": "next",
|
|
53
|
+
"@maizzle/tailwindcss": "latest"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
2. Update the `style` tag in `layouts/main.html`:
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<style>
|
|
62
|
+
@import "@maizzle/tailwindcss";
|
|
63
|
+
|
|
64
|
+
img {
|
|
65
|
+
@apply max-w-full align-middle;
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
There are still things missign and/or broken:
|
|
71
|
+
|
|
72
|
+
- inline CSS like the `line-height` on spacers is broken/missing
|
|
73
|
+
- `tailwindcss-email-variants` and `tailwindcss-mso` are not ported yet
|
|
74
|
+
- some CSS duplication and artifacts still present in the final build
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
- feat: add tailwindcss v4 support 8b5596e
|
|
79
|
+
|
|
80
|
+
https://github.com/maizzle/framework/compare/v5.2.1...v6.0.0-0
|
|
81
|
+
|
|
7
82
|
## [5.2.1] - 2025-06-25
|
|
8
83
|
|
|
9
84
|
This is just a maintenance release to update dependencies.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maizzle/framework",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-2",
|
|
4
4
|
"description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"is-url-superb": "^6.1.0",
|
|
66
66
|
"istextorbinary": "^9.5.0",
|
|
67
67
|
"juice": "^11.0.0",
|
|
68
|
+
"lightningcss": "^1.30.1",
|
|
68
69
|
"lodash-es": "^4.17.21",
|
|
69
70
|
"morphdom": "^2.7.4",
|
|
70
71
|
"ora": "^8.1.0",
|
|
@@ -72,7 +73,6 @@
|
|
|
72
73
|
"postcss": "^8.4.49",
|
|
73
74
|
"postcss-calc": "^10.0.2",
|
|
74
75
|
"postcss-css-variables": "^0.19.0",
|
|
75
|
-
"postcss-lightningcss": "^1.0.1",
|
|
76
76
|
"postcss-safe-parser": "^7.0.0",
|
|
77
77
|
"postcss-sort-media-queries": "^5.2.0",
|
|
78
78
|
"posthtml": "^0.16.6",
|
package/src/posthtml/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import posthtmlPostcss from 'posthtml-postcss'
|
|
|
10
10
|
import expandLinkTag from './plugins/expandLinkTag.js'
|
|
11
11
|
import envAttributes from './plugins/envAttributes.js'
|
|
12
12
|
import { getPosthtmlOptions } from './defaultConfig.js'
|
|
13
|
+
import lowerCssSyntax from './plugins/lowerCssSyntax.js'
|
|
13
14
|
import combineMediaQueries from './plugins/combineMediaQueries.js'
|
|
14
15
|
|
|
15
16
|
// PostCSS
|
|
@@ -17,7 +18,8 @@ import tailwindcss from '@tailwindcss/postcss'
|
|
|
17
18
|
import postcssCalc from 'postcss-calc'
|
|
18
19
|
import cssVariables from 'postcss-css-variables'
|
|
19
20
|
import postcssSafeParser from 'postcss-safe-parser'
|
|
20
|
-
import
|
|
21
|
+
import removeDuplicateSelectors from './plugins/postcss/removeDuplicateSelectors.js'
|
|
22
|
+
import cleanupTailwindArtifacts from './plugins/postcss/cleanupTailwindArtifacts.js'
|
|
21
23
|
|
|
22
24
|
import defaultComponentsConfig from './defaultComponentsConfig.js'
|
|
23
25
|
|
|
@@ -36,15 +38,8 @@ export async function process(html = '', config = {}) {
|
|
|
36
38
|
tailwindcss(get(config, 'css.tailwind', {})),
|
|
37
39
|
resolveCSSProps !== false && cssVariables(resolveCSSProps),
|
|
38
40
|
resolveCalc !== false && postcssCalc(resolveCalc),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
errorRecovery: true,
|
|
42
|
-
minify: false,
|
|
43
|
-
targets: {
|
|
44
|
-
ie: 1,
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}),
|
|
41
|
+
removeDuplicateSelectors(),
|
|
42
|
+
cleanupTailwindArtifacts(get(config, 'css.cleanup', {})),
|
|
48
43
|
...get(config, 'postcss.plugins', []),
|
|
49
44
|
],
|
|
50
45
|
merge(
|
|
@@ -121,7 +116,8 @@ export async function process(html = '', config = {}) {
|
|
|
121
116
|
postcssPlugin,
|
|
122
117
|
envTags(config.env),
|
|
123
118
|
envAttributes(config.env),
|
|
124
|
-
|
|
119
|
+
lowerCssSyntax(get(config, 'css.lightningcss', {})),
|
|
120
|
+
get(config, 'css.combineMediaQueries') !== false && combineMediaQueries(get(config, 'css.combineMediaQueries', { sort: 'mobile-first' })),
|
|
125
121
|
...get(
|
|
126
122
|
config,
|
|
127
123
|
'posthtml.plugins.after',
|
|
@@ -129,7 +125,7 @@ export async function process(html = '', config = {}) {
|
|
|
129
125
|
? []
|
|
130
126
|
: get(config, 'posthtml.plugins', [])
|
|
131
127
|
),
|
|
132
|
-
])
|
|
128
|
+
].filter(Boolean))
|
|
133
129
|
.process(html, posthtmlOptions)
|
|
134
130
|
.then(result => ({
|
|
135
131
|
config: merge(config, { page: config }),
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defu as merge } from 'defu'
|
|
2
|
+
import { transform } from 'lightningcss'
|
|
3
|
+
|
|
4
|
+
const plugin = (options = {}) => tree => {
|
|
5
|
+
options = merge(options, {
|
|
6
|
+
targets: options.targets ? {} : {
|
|
7
|
+
ie: 1,
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const process = node => {
|
|
12
|
+
// Check if this is a style tag with content
|
|
13
|
+
if (node.tag === 'style' && node.content && Array.isArray(node.content)) {
|
|
14
|
+
// Get the CSS content from the style tag
|
|
15
|
+
const cssContent = node.content.join('')
|
|
16
|
+
|
|
17
|
+
if (cssContent.trim()) {
|
|
18
|
+
try {
|
|
19
|
+
const { code } = transform(
|
|
20
|
+
merge(
|
|
21
|
+
options,
|
|
22
|
+
{
|
|
23
|
+
code: Buffer.from(cssContent)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
// Replace the content with processed CSS
|
|
29
|
+
node.content = [code.toString()]
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// If processing fails, leave the content unchanged
|
|
32
|
+
console.warn('Failed to process media queries:', error.message)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return node
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return tree.walk(process)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default plugin
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostCSS plugin to clean up Tailwind CSS artifacts and leftovers.
|
|
3
|
+
*
|
|
4
|
+
* This plugin safely removes unused Tailwind-specific CSS that
|
|
5
|
+
* may be left behind after processing, while preserving
|
|
6
|
+
* any CSS that might be intentionally used.
|
|
7
|
+
*/
|
|
8
|
+
export default function cleanupTailwindArtifacts(options = {}) {
|
|
9
|
+
const opts = {
|
|
10
|
+
removeEmptyLayers: true,
|
|
11
|
+
removeUnusedTwProperties: true,
|
|
12
|
+
removeEmptyRules: false,
|
|
13
|
+
preserveCustomProperties: [], // Array of custom property names to preserve
|
|
14
|
+
...options
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
postcssPlugin: 'cleanup-tailwind-artifacts',
|
|
19
|
+
OnceExit(root) {
|
|
20
|
+
const usedCustomProperties = new Set()
|
|
21
|
+
const rulesToRemove = []
|
|
22
|
+
|
|
23
|
+
// First pass: collect all custom properties usage
|
|
24
|
+
root.walkDecls(decl => {
|
|
25
|
+
// Check if any declaration uses custom properties
|
|
26
|
+
if (decl.value.includes('var(--')) {
|
|
27
|
+
const matches = decl.value.match(/var\(--[\w-]+\)/g)
|
|
28
|
+
if (matches) {
|
|
29
|
+
matches.forEach(match => {
|
|
30
|
+
const propName = match.replace(/var\(|-|\)/g, '')
|
|
31
|
+
usedCustomProperties.add(propName)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Second pass: find unused @property declarations and empty @layer rules
|
|
38
|
+
root.walkAtRules(rule => {
|
|
39
|
+
// Handle @property declarations
|
|
40
|
+
if (rule.name === 'property' && opts.removeUnusedTwProperties) {
|
|
41
|
+
const propertyName = rule.params.replace(/^--/, '')
|
|
42
|
+
|
|
43
|
+
// Only remove Tailwind-specific custom properties that aren't used
|
|
44
|
+
if (propertyName.startsWith('tw-') && !usedCustomProperties.has(propertyName)) {
|
|
45
|
+
// Check if it's in the preserve list
|
|
46
|
+
if (!opts.preserveCustomProperties.includes(propertyName)) {
|
|
47
|
+
rulesToRemove.push(rule)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Handle @layer rules
|
|
53
|
+
if (rule.name === 'layer' && opts.removeEmptyLayers) {
|
|
54
|
+
// Only remove @layer rules that have no nodes
|
|
55
|
+
if (!rule.nodes || rule.nodes.length === 0) {
|
|
56
|
+
rulesToRemove.push(rule)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Third pass: remove empty rules (optional, off by default)
|
|
62
|
+
if (opts.removeEmptyRules) {
|
|
63
|
+
root.walkRules(rule => {
|
|
64
|
+
if (!rule.nodes || rule.nodes.length === 0) {
|
|
65
|
+
rulesToRemove.push(rule)
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Remove all identified artifacts
|
|
71
|
+
rulesToRemove.forEach(rule => {
|
|
72
|
+
rule.remove()
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
cleanupTailwindArtifacts.postcss = true
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostCSS plugin to remove duplicate selectors, keeping only the last occurrence.
|
|
3
|
+
* This is useful when CSS contains multiple rules with the same selector,
|
|
4
|
+
* and we want to keep only the most recent one.
|
|
5
|
+
*/
|
|
6
|
+
export default function removeDuplicateSelectors() {
|
|
7
|
+
return {
|
|
8
|
+
postcssPlugin: 'remove-duplicate-selectors',
|
|
9
|
+
OnceExit(root) {
|
|
10
|
+
const selectorMap = new Map()
|
|
11
|
+
const rulesToRemove = []
|
|
12
|
+
|
|
13
|
+
// First pass: collect all rules and their selectors
|
|
14
|
+
root.walkRules(rule => {
|
|
15
|
+
const selector = rule.selector
|
|
16
|
+
|
|
17
|
+
// If we've seen this selector before, mark the previous one for removal
|
|
18
|
+
if (selectorMap.has(selector)) {
|
|
19
|
+
const previousRule = selectorMap.get(selector)
|
|
20
|
+
rulesToRemove.push(previousRule)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Update the map with the current rule (latest occurrence)
|
|
24
|
+
selectorMap.set(selector, rule)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// Second pass: remove all the duplicate rules
|
|
28
|
+
rulesToRemove.forEach(rule => {
|
|
29
|
+
rule.remove()
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
removeDuplicateSelectors.postcss = true
|
|
@@ -177,69 +177,71 @@ export async function inline(html = '', options = {}) {
|
|
|
177
177
|
|
|
178
178
|
// Loop over selectors that we found in the <style> tags
|
|
179
179
|
selectors.forEach(({ name, prop }) => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
value
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
180
|
+
try {
|
|
181
|
+
const elements = $(name).get()
|
|
182
|
+
|
|
183
|
+
// If the property is excluded from inlining, skip
|
|
184
|
+
if (!juice.excludedProperties.includes(prop)) {
|
|
185
|
+
// Find the selector in the HTML
|
|
186
|
+
elements.forEach((el) => {
|
|
187
|
+
// Get a `property|value` list from the inline style attribute
|
|
188
|
+
const styleAttr = $(el).attr('style')
|
|
189
|
+
const inlineStyles = {}
|
|
190
|
+
|
|
191
|
+
// 1. `preferUnitlessValues`
|
|
192
|
+
if (styleAttr) {
|
|
193
|
+
try {
|
|
194
|
+
const root = postcss.parse(`* { ${styleAttr} }`)
|
|
195
|
+
|
|
196
|
+
root.first.each((decl) => {
|
|
197
|
+
const property = decl.prop
|
|
198
|
+
let value = decl.value
|
|
199
|
+
|
|
200
|
+
if (value && options.preferUnitlessValues) {
|
|
201
|
+
value = value.replace(
|
|
202
|
+
/\b0(px|rem|em|%|vh|vw|vmin|vmax|in|cm|mm|pt|pc|ex|ch)\b/g,
|
|
203
|
+
'0'
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (property) {
|
|
208
|
+
inlineStyles[property] = value
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
// Update the element's style attribute with the new value
|
|
213
|
+
$(el).attr(
|
|
214
|
+
'style',
|
|
215
|
+
Object.entries(inlineStyles).map(([property, value]) => `${property}: ${value}`).join('; ')
|
|
216
|
+
)
|
|
217
|
+
} catch {}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Get the classes from the element's class attribute
|
|
221
|
+
const classes = $(el).attr('class')
|
|
205
222
|
|
|
206
|
-
|
|
207
|
-
|
|
223
|
+
// 2. `removeInlinedSelectors`
|
|
224
|
+
if (options.removeInlinedSelectors && classes) {
|
|
225
|
+
const classList = classes.split(' ')
|
|
226
|
+
|
|
227
|
+
// If the class has been inlined in the style attribute...
|
|
228
|
+
if (has(inlineStyles, prop)) {
|
|
229
|
+
// Try to remove the classes that have been inlined
|
|
230
|
+
if (![...options.safelist].some(item => item.includes(name))) {
|
|
231
|
+
remove(classList, classToRemove => name.includes(classToRemove))
|
|
208
232
|
}
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
// Update the element's style attribute with the new value
|
|
212
|
-
$(el).attr(
|
|
213
|
-
'style',
|
|
214
|
-
Object.entries(inlineStyles).map(([property, value]) => `${property}: ${value}`).join('; ')
|
|
215
|
-
)
|
|
216
|
-
} catch {}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Get the classes from the element's class attribute
|
|
220
|
-
const classes = $(el).attr('class')
|
|
221
|
-
|
|
222
|
-
// 2. `removeInlinedSelectors`
|
|
223
|
-
if (options.removeInlinedSelectors && classes) {
|
|
224
|
-
const classList = classes.split(' ')
|
|
225
|
-
|
|
226
|
-
// If the class has been inlined in the style attribute...
|
|
227
|
-
if (has(inlineStyles, prop)) {
|
|
228
|
-
// Try to remove the classes that have been inlined
|
|
229
|
-
if (![...options.safelist].some(item => item.includes(name))) {
|
|
230
|
-
remove(classList, classToRemove => name.includes(classToRemove))
|
|
231
|
-
}
|
|
232
233
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
// Update the class list on the element with the new classes
|
|
235
|
+
if (classList.length > 0) {
|
|
236
|
+
$(el).attr('class', classList.join(' '))
|
|
237
|
+
} else {
|
|
238
|
+
$(el).removeAttr('class')
|
|
239
|
+
}
|
|
238
240
|
}
|
|
239
241
|
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
} catch {}
|
|
243
245
|
})
|
|
244
246
|
})
|
|
245
247
|
|
package/types/config.d.ts
CHANGED
|
@@ -14,9 +14,10 @@ import type { BaseURLConfig } from 'posthtml-base-url';
|
|
|
14
14
|
import type URLParametersConfig from './urlParameters';
|
|
15
15
|
import type { PostCssCalcOptions } from 'postcss-calc';
|
|
16
16
|
import type { PostHTMLFetchConfig } from 'posthtml-fetch';
|
|
17
|
-
import type { Config as TailwindConfig } from 'tailwindcss';
|
|
18
17
|
import type { PostHTMLComponents } from 'posthtml-component';
|
|
19
18
|
import type { PostHTMLExpressions } from 'posthtml-expressions';
|
|
19
|
+
import type { TransformOptions, CustomAtRules } from 'lightningcss';
|
|
20
|
+
import type { PostCSSSortMediaQueriesOptions } from './css/combineMediaQueries';
|
|
20
21
|
|
|
21
22
|
export default interface Config {
|
|
22
23
|
/**
|
|
@@ -217,9 +218,30 @@ export default interface Config {
|
|
|
217
218
|
sixHex?: boolean;
|
|
218
219
|
|
|
219
220
|
/**
|
|
220
|
-
*
|
|
221
|
+
* Configure Lightning CSS.
|
|
222
|
+
*
|
|
223
|
+
* This is used mainly for lowering CSS syntax to be more compatible with email clients.
|
|
224
|
+
*/
|
|
225
|
+
lightningcss?: TransformOptions<CustomAtRules>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Combine media queries in your CSS.
|
|
229
|
+
*
|
|
230
|
+
* @default { sort: 'mobile-first' }
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```
|
|
234
|
+
* export default {
|
|
235
|
+
* css: {
|
|
236
|
+
* combineMediaQueries: {
|
|
237
|
+
* sort: 'desktop-first',
|
|
238
|
+
* onlyTopLevel: true,
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
221
243
|
*/
|
|
222
|
-
|
|
244
|
+
combineMediaQueries?: PostCSSSortMediaQueriesOptions;
|
|
223
245
|
}
|
|
224
246
|
|
|
225
247
|
/**
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Plugin } from 'postcss';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sort function for media queries.
|
|
5
|
+
* Takes two media query strings and returns a number indicating their relative order.
|
|
6
|
+
*/
|
|
7
|
+
export type SortFunction = (a: string, b: string) => number;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Configuration object for sort-css-media-queries library.
|
|
11
|
+
*/
|
|
12
|
+
export interface SortConfiguration {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Options for the postcss-sort-media-queries plugin.
|
|
18
|
+
*/
|
|
19
|
+
export interface PostCSSSortMediaQueriesOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Sorting method for media queries.
|
|
22
|
+
*
|
|
23
|
+
* @default 'mobile-first'
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* // Use built-in mobile-first sorting
|
|
28
|
+
* sort: 'mobile-first'
|
|
29
|
+
*
|
|
30
|
+
* // Use built-in desktop-first sorting
|
|
31
|
+
* sort: 'desktop-first'
|
|
32
|
+
*
|
|
33
|
+
* // Use custom sorting function
|
|
34
|
+
* sort: (a, b) => a.localeCompare(b)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
sort?: 'mobile-first' | 'desktop-first' | SortFunction;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Custom configuration object for the sort-css-media-queries library.
|
|
41
|
+
* When provided, it will be used to create a custom sort function.
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```
|
|
47
|
+
* configuration: {
|
|
48
|
+
* unitlessMqAlwaysFirst: true,
|
|
49
|
+
* sort: 'mobile-first'
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
configuration?: false | SortConfiguration;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether to only process media queries at the top level (direct children of root).
|
|
57
|
+
* When true, nested media queries will be ignored.
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```
|
|
63
|
+
* onlyTopLevel: true
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
onlyTopLevel?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* PostCSS plugin that sorts CSS media queries.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Plugin configuration options
|
|
73
|
+
* @returns PostCSS plugin instance
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```
|
|
77
|
+
* import postcss from 'postcss';
|
|
78
|
+
* import sortMediaQueries from 'postcss-sort-media-queries';
|
|
79
|
+
*
|
|
80
|
+
* postcss([
|
|
81
|
+
* sortMediaQueries({
|
|
82
|
+
* sort: 'mobile-first',
|
|
83
|
+
* onlyTopLevel: false
|
|
84
|
+
* })
|
|
85
|
+
* ])
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
declare function postcssSortMediaQueries(options?: PostCSSSortMediaQueriesOptions): Plugin;
|
|
89
|
+
|
|
90
|
+
export default postcssSortMediaQueries;
|