diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:05:55 +0800 |
| commit | c06f7ee0a40255214c477e13d9b956a7e07c2900 (patch) | |
| tree | f5982a568ef8fab865d0142e71c7494fea3e4c1b /node_modules/svgo/plugins/removeDimensions.js | |
| parent | 3fd9400d4dccc25aa29b5702216732e0b7542073 (diff) | |
postcss,(plugins): nanocss, postcss-preset-env
Diffstat (limited to 'node_modules/svgo/plugins/removeDimensions.js')
| -rw-r--r-- | node_modules/svgo/plugins/removeDimensions.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/svgo/plugins/removeDimensions.js b/node_modules/svgo/plugins/removeDimensions.js new file mode 100644 index 00000000..4f4f3984 --- /dev/null +++ b/node_modules/svgo/plugins/removeDimensions.js @@ -0,0 +1,43 @@ +'use strict'; + +exports.name = 'removeDimensions'; +exports.description = + 'removes width and height in presence of viewBox (opposite to removeViewBox, disable it first)'; + +/** + * Remove width/height attributes and add the viewBox attribute if it's missing + * + * @example + * <svg width="100" height="50" /> + * ↓ + * <svg viewBox="0 0 100 50" /> + * + * @author Benny Schudel + * + * @type {import('./plugins-types').Plugin<'removeDimensions'>} + */ +exports.fn = () => { + return { + element: { + enter: (node) => { + if (node.name === 'svg') { + if (node.attributes.viewBox != null) { + delete node.attributes.width; + delete node.attributes.height; + } else if ( + node.attributes.width != null && + node.attributes.height != null && + Number.isNaN(Number(node.attributes.width)) === false && + Number.isNaN(Number(node.attributes.height)) === false + ) { + const width = Number(node.attributes.width); + const height = Number(node.attributes.height); + node.attributes.viewBox = `0 0 ${width} ${height}`; + delete node.attributes.width; + delete node.attributes.height; + } + } + }, + }, + }; +}; |
