summaryrefslogtreecommitdiffstats
path: root/svgo.config.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-03 09:10:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-03 09:10:03 +0000
commit9aeff034f5cdf4e22090904bf9dfecf439b34658 (patch)
tree7ed7a2f5bc0291104a79f90f547c4b250e50c21b /svgo.config.mjs
parentReleasing debian version 1.10.4+dfsg-1. (diff)
downloadbootstrap-icons-9aeff034f5cdf4e22090904bf9dfecf439b34658.tar.xz
bootstrap-icons-9aeff034f5cdf4e22090904bf9dfecf439b34658.zip
Merging upstream version 1.10.5+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'svgo.config.mjs')
-rw-r--r--svgo.config.mjs73
1 files changed, 73 insertions, 0 deletions
diff --git a/svgo.config.mjs b/svgo.config.mjs
new file mode 100644
index 0000000..4f4c9e2
--- /dev/null
+++ b/svgo.config.mjs
@@ -0,0 +1,73 @@
+import path from 'node:path'
+
+export default {
+ multipass: true,
+ js2svg: {
+ pretty: true,
+ indent: 2,
+ eol: 'lf'
+ },
+ plugins: [
+ {
+ name: 'preset-default',
+ params: {
+ overrides: {
+ removeUnknownsAndDefaults: {
+ keepRoleAttr: true
+ },
+ removeViewBox: false
+ }
+ }
+ },
+ // The next plugins are included in svgo but are not part of preset-default,
+ // so we need to enable them separately
+ 'cleanupListOfValues',
+ {
+ name: 'removeAttrs',
+ params: {
+ attrs: [
+ 'clip-rule',
+ 'data-name',
+ 'fill'
+ ]
+ }
+ },
+ // Custom plugin which resets the SVG attributes to explicit values
+ {
+ name: 'explicitAttrs',
+ type: 'visitor',
+ params: {
+ attributes: {
+ xmlns: 'http://www.w3.org/2000/svg',
+ width: '16',
+ height: '16',
+ fill: 'currentColor',
+ class: '', // We replace the class with the correct one based on filename later
+ viewBox: '0 0 16 16'
+ }
+ },
+ fn(_root, params, info) {
+ if (!params.attributes) {
+ return null
+ }
+
+ const basename = path.basename(info.path, '.svg')
+
+ return {
+ element: {
+ enter(node, parentNode) {
+ if (node.name === 'svg' && parentNode.type === 'root') {
+ // We set the `svgAttributes` in the order we want to,
+ // hence why we remove the attributes and add them back
+ node.attributes = {}
+ for (const [key, value] of Object.entries(params.attributes)) {
+ node.attributes[key] = key === 'class' ? `bi bi-${basename}` : value
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+}