From efbc2ffe6a1ee5ec38a4396305561d6515d0943e Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 30 Aug 2024 17:21:18 +0800 Subject: node fixes, updates --- .../lib/optimizer/level-1/value-optimizers/unit.js | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js (limited to 'node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js') diff --git a/node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js b/node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js new file mode 100644 index 00000000..df2cda59 --- /dev/null +++ b/node_modules/clean-css/lib/optimizer/level-1/value-optimizers/unit.js @@ -0,0 +1,46 @@ +var WHOLE_PIXEL_VALUE = /(?:^|\s|\()(-?\d+)px/; + +var plugin = { + level1: { + value: function unit(_name, value, options) { + if (!WHOLE_PIXEL_VALUE.test(value)) { + return value; + } + + return value.replace(WHOLE_PIXEL_VALUE, function(match, val) { + var newValue; + var intVal = parseInt(val); + + if (intVal === 0) { + return match; + } + + if (options.compatibility.properties.shorterLengthUnits + && options.compatibility.units.pt + && intVal * 3 % 4 === 0) { + newValue = intVal * 3 / 4 + 'pt'; + } + + if (options.compatibility.properties.shorterLengthUnits + && options.compatibility.units.pc + && intVal % 16 === 0) { + newValue = intVal / 16 + 'pc'; + } + + if (options.compatibility.properties.shorterLengthUnits + && options.compatibility.units.in + && intVal % 96 === 0) { + newValue = intVal / 96 + 'in'; + } + + if (newValue) { + newValue = match.substring(0, match.indexOf(val)) + newValue; + } + + return newValue && newValue.length < match.length ? newValue : match; + }); + } + } +}; + +module.exports = plugin; -- cgit v1.2.3