Merge remote-tracking branch 'upstream/main'

This commit is contained in:
2026-08-26 09:31:34 +08:00
parent 9b8c4bfab6
commit 394eb0285d
34137 changed files with 3589424 additions and 0 deletions
@@ -0,0 +1,34 @@
const merge = require('merge-options');
const { getRoot } = require('../utils');
const defaultConfig = {
removeDimensions: false
};
/**
* @param {Object} [config] {@see defaultConfig}
* @return {Function} PostHTML plugin
*/
function normalizeViewBox(config = {}) {
const cfg = merge(defaultConfig, config);
return (tree) => {
const root = getRoot(tree);
root.attrs = root.attrs || {};
const attrs = root.attrs;
const { width, height, viewBox } = attrs;
if (!viewBox && width && height) {
attrs.viewBox = `0 0 ${parseFloat(width).toString()} ${parseFloat(height).toString()}`;
if (cfg.removeDimensions) {
delete attrs.width;
delete attrs.height;
}
}
return tree;
};
}
module.exports = normalizeViewBox;