(root)
| 60 | return { |
| 61 | postcssPlugin: 'postcss-content-density-variables', |
| 62 | Once(root) { |
| 63 | let hasRootHost = false; |
| 64 | let hostRule; |
| 65 | |
| 66 | root.walkRules((rule) => { |
| 67 | // Only process :host rules |
| 68 | if (rule.selector !== SELECTOR) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Handle root-level :host rules (cozy) |
| 73 | if (rule.parent.type === "root") { |
| 74 | if (!hasRootHost) { |
| 75 | hasRootHost = true; |
| 76 | hostRule = rule; |
| 77 | } |
| 78 | |
| 79 | rule.walkDecls((decl) => { |
| 80 | if (decl.prop.startsWith('--')) { |
| 81 | saveVariable(decl.prop, decl.value, 'cozy'); |
| 82 | decl.remove(); |
| 83 | } |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | // Handle :host rules inside @container (compact) |
| 88 | if (rule.parent.type === "atrule") { |
| 89 | if (rule.parent.params.replaceAll("\s", "") === 'style(--ui5_content_density: compact)'.replaceAll("\s", "")) { |
| 90 | rule.walkDecls((decl) => { |
| 91 | if (decl.prop.startsWith('--')) { |
| 92 | saveVariable(decl.prop, decl.value, 'compact'); |
| 93 | decl.remove(); |
| 94 | } |
| 95 | }); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | let current = rule; |
| 100 | // Remove up empty rules |
| 101 | while (current) { |
| 102 | if (current.nodes.length === 0) { |
| 103 | const parent = current.parent; |
| 104 | current.remove(); |
| 105 | current = parent; |
| 106 | } |
| 107 | |
| 108 | if (current.type === "root") { |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | }); |
| 113 | |
| 114 | if (!hasRootHost) { |
| 115 | hostRule = postcss.rule({ selector: SELECTOR }); |
| 116 | } |
| 117 | |
| 118 | // Construct merged variable declarations depending on available modes |
| 119 | for (const [variable, variableData] of hostVariables) { |
nothing calls this directly
no test coverage detected