Files
readeck/web/ui/plugins/responsive-units.js
Olivier Meunier fe60cf4168 Removed postcss-unit-processor
Instead of adding dvh and dvw values as expected, the plugin would
duplicate *all* declaration with a unit...

For our needs, a custom plugin is more than enough.

Removed postcss-selector-parser that was not used anymore
2023-10-08 10:06:41 +02:00

43 lines
937 B
JavaScript

// SPDX-FileCopyrightText: © 2023 Olivier Meunier <olivier@neokraft.net>
//
// SPDX-License-Identifier: AGPL-3.0-only
"use strict"
const {Declaration} = require("postcss")
const valueParser = require("postcss-value-parser")
/**
*
* @param {Declaration} decl
*/
function resopnsiveUnits(decl) {
const parsed = valueParser(decl.value)
let modified = false
parsed.walk((node) => {
if (node.type != "word") {
return
}
const unit = valueParser.unit(node.value)
if (!unit || (unit.unit != "vh" && unit.unit != "vw")) {
return
}
node.value = `${unit.number}d${unit.unit}`
modified = true
})
if (modified) {
// Add a new rule with the dvh value
decl.after({prop: decl.prop, value: valueParser.stringify(parsed)})
}
}
const plugin = () => {
return {
postcssPlugin: "responsive-units",
Declaration: resopnsiveUnits,
}
}
plugin.postcss = true
module.exports = plugin