source: trip-planner-front/node_modules/svgo/plugins/removeDimensions.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[6a3a178]1'use strict';
2
3exports.name = 'removeDimensions';
4
5exports.type = 'perItem';
6
7exports.active = false;
8
9exports.description =
10 'removes width and height in presence of viewBox (opposite to removeViewBox, disable it first)';
11
12/**
13 * Remove width/height attributes and add the viewBox attribute if it's missing
14 *
15 * @example
16 * <svg width="100" height="50" />
17 * ↓
18 * <svg viewBox="0 0 100 50" />
19 *
20 * @param {Object} item current iteration item
21 * @return {Boolean} if true, with and height will be filtered out
22 *
23 * @author Benny Schudel
24 */
25exports.fn = function (item) {
26 if (item.type === 'element' && item.name === 'svg') {
27 if (item.attributes.viewBox != null) {
28 delete item.attributes.width;
29 delete item.attributes.height;
30 } else if (
31 item.attributes.width != null &&
32 item.attributes.height != null &&
33 Number.isNaN(Number(item.attributes.width)) === false &&
34 Number.isNaN(Number(item.attributes.height)) === false
35 ) {
36 const width = Number(item.attributes.width);
37 const height = Number(item.attributes.height);
38 item.attributes.viewBox = `0 0 ${width} ${height}`;
39 delete item.attributes.width;
40 delete item.attributes.height;
41 }
42 }
43};
Note: See TracBrowser for help on using the repository browser.