mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-29 05:34:21 +08:00
Bug: none Change-Id: I9389834400d90beed8df9f28356720031abe9ef1 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6225902 Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Auto-Submit: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
'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;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|
|
};
|