Skip to content

Instantly share code, notes, and snippets.

@mathieudutour
Last active July 22, 2020 16:34
Show Gist options
  • Save mathieudutour/73309f6fb7fb6e7b830e20e43ee8f850 to your computer and use it in GitHub Desktop.
Save mathieudutour/73309f6fb7fb6e7b830e20e43ee8f850 to your computer and use it in GitHub Desktop.
SVGO plugin to fix color space issue in Safari on SVG Filter primitives
'use strict';
exports.type = 'perItem';
exports.active = true;
exports.description = 'add color-interpolation-filters="sRGB" to filters';
exports.params = {
force: false,
key: 'color-interpolation-filters',
value: 'sRGB',
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element#Filter_primitive_elements
tags: ['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'feSpecularLighting', 'feTile', 'feTurbulence']
};
exports.fn = function(item, params) {
if ((params.tags || []).every(function (tag) {
return !item.isElem(String(tag));
})) {
return;
}
if (!params.force && item.hasAttr(String(params.key))) {
return
}
if (!item.attrs) {
item.attrs = {}
}
item.attrs[String(params.key)] = {
name: String(params.key),
value: String(params.value),
prefix: '',
local: String(params.key)
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment