|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @param {import('postcss').Container[]} nodes
|
|---|
| 3 | * @param {any} source
|
|---|
| 4 | * @param {any} raws
|
|---|
| 5 | * @returns {import('postcss').Container[]}
|
|---|
| 6 | */
|
|---|
| 7 | export default function cloneNodes(nodes, source = undefined, raws = undefined) {
|
|---|
| 8 | return nodes.map((node) => {
|
|---|
| 9 | let cloned = node.clone()
|
|---|
| 10 |
|
|---|
| 11 | if (raws !== undefined) {
|
|---|
| 12 | cloned.raws.tailwind = {
|
|---|
| 13 | ...cloned.raws.tailwind,
|
|---|
| 14 | ...raws,
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | if (source !== undefined) {
|
|---|
| 19 | traverse(cloned, (node) => {
|
|---|
| 20 | // Do not traverse nodes that have opted
|
|---|
| 21 | // to preserve their original source
|
|---|
| 22 | let shouldPreserveSource = node.raws.tailwind?.preserveSource === true && node.source
|
|---|
| 23 | if (shouldPreserveSource) {
|
|---|
| 24 | return false
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | // Otherwise we can safely replace the source
|
|---|
| 28 | // And continue traversing
|
|---|
| 29 | node.source = source
|
|---|
| 30 | })
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | return cloned
|
|---|
| 34 | })
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Traverse a tree of nodes and don't traverse children if the callback
|
|---|
| 39 | * returns false. Ideally we'd use Container#walk instead of this
|
|---|
| 40 | * function but it stops traversing siblings too.
|
|---|
| 41 | *
|
|---|
| 42 | * @param {import('postcss').Container} node
|
|---|
| 43 | * @param {(node: import('postcss').Container) => boolean} onNode
|
|---|
| 44 | */
|
|---|
| 45 | function traverse(node, onNode) {
|
|---|
| 46 | if (onNode(node) !== false) {
|
|---|
| 47 | node.each?.((child) => traverse(child, onNode))
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.