|
Last change
on this file since cdcff72 was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | let comparisonMap = {
|
|---|
| 2 | atrule: ['name', 'params'],
|
|---|
| 3 | rule: ['selector'],
|
|---|
| 4 | }
|
|---|
| 5 | let types = new Set(Object.keys(comparisonMap))
|
|---|
| 6 |
|
|---|
| 7 | export default function collapseAdjacentRules() {
|
|---|
| 8 | function collapseRulesIn(root) {
|
|---|
| 9 | let currentRule = null
|
|---|
| 10 | root.each((node) => {
|
|---|
| 11 | if (!types.has(node.type)) {
|
|---|
| 12 | currentRule = null
|
|---|
| 13 | return
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | if (currentRule === null) {
|
|---|
| 17 | currentRule = node
|
|---|
| 18 | return
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | let properties = comparisonMap[node.type]
|
|---|
| 22 |
|
|---|
| 23 | if (node.type === 'atrule' && node.name === 'font-face') {
|
|---|
| 24 | currentRule = node
|
|---|
| 25 | } else if (
|
|---|
| 26 | properties.every(
|
|---|
| 27 | (property) =>
|
|---|
| 28 | (node[property] ?? '').replace(/\s+/g, ' ') ===
|
|---|
| 29 | (currentRule[property] ?? '').replace(/\s+/g, ' ')
|
|---|
| 30 | )
|
|---|
| 31 | ) {
|
|---|
| 32 | // An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
|
|---|
| 33 | if (node.nodes) {
|
|---|
| 34 | currentRule.append(node.nodes)
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | node.remove()
|
|---|
| 38 | } else {
|
|---|
| 39 | currentRule = node
|
|---|
| 40 | }
|
|---|
| 41 | })
|
|---|
| 42 |
|
|---|
| 43 | // After we've collapsed adjacent rules & at-rules, we need to collapse
|
|---|
| 44 | // adjacent rules & at-rules that are children of at-rules.
|
|---|
| 45 | // We do not care about nesting rules because Tailwind CSS
|
|---|
| 46 | // explicitly does not handle rule nesting on its own as
|
|---|
| 47 | // the user is expected to use a nesting plugin
|
|---|
| 48 | root.each((node) => {
|
|---|
| 49 | if (node.type === 'atrule') {
|
|---|
| 50 | collapseRulesIn(node)
|
|---|
| 51 | }
|
|---|
| 52 | })
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | return (root) => {
|
|---|
| 56 | collapseRulesIn(root)
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.