1
0
mirror of https://github.com/svg/svgo.git synced 2025-08-07 15:22:54 +03:00

Update presentation attribute collection for removeNonInheritableGroupAttrs plugin

This commit is contained in:
GreLI
2018-09-16 11:07:43 +03:00
parent 36db31adcf
commit a165206632
2 changed files with 25 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
'use strict'; 'use strict';
// http://www.w3.org/TR/SVG/intro.html#Definitions // http://www.w3.org/TR/SVG11/intro.html#Definitions
exports.elemsGroups = { exports.elemsGroups = {
animation: ['animate', 'animateColor', 'animateMotion', 'animateTransform', 'set'], animation: ['animate', 'animateColor', 'animateMotion', 'animateTransform', 'set'],
descriptive: ['desc', 'metadata', 'title'], descriptive: ['desc', 'metadata', 'title'],
@@ -17,7 +17,7 @@ exports.elemsGroups = {
exports.pathElems = ['path', 'glyph', 'missing-glyph']; exports.pathElems = ['path', 'glyph', 'missing-glyph'];
// http://www.w3.org/TR/SVG/intro.html#Definitions // http://www.w3.org/TR/SVG11/intro.html#Definitions
exports.attrsGroups = { exports.attrsGroups = {
animationAddition: ['additive', 'accumulate'], animationAddition: ['additive', 'accumulate'],
animationAttributeTarget: ['attributeType', 'attributeName'], animationAttributeTarget: ['attributeType', 'attributeName'],
@@ -30,7 +30,6 @@ exports.attrsGroups = {
presentation: [ presentation: [
'alignment-baseline', 'alignment-baseline',
'baseline-shift', 'baseline-shift',
'buffered-rendering',
'clip', 'clip',
'clip-path', 'clip-path',
'clip-rule', 'clip-rule',
@@ -60,7 +59,6 @@ exports.attrsGroups = {
'glyph-orientation-horizontal', 'glyph-orientation-horizontal',
'glyph-orientation-vertical', 'glyph-orientation-vertical',
'image-rendering', 'image-rendering',
'kerning',
'letter-spacing', 'letter-spacing',
'lighting-color', 'lighting-color',
'marker-end', 'marker-end',
@@ -69,10 +67,9 @@ exports.attrsGroups = {
'mask', 'mask',
'opacity', 'opacity',
'overflow', 'overflow',
'paint-order',
'pointer-events', 'pointer-events',
'shape-rendering', 'shape-rendering',
'solid-color',
'solid-opacity',
'stop-color', 'stop-color',
'stop-opacity', 'stop-opacity',
'stroke', 'stroke',
@@ -83,18 +80,14 @@ exports.attrsGroups = {
'stroke-miterlimit', 'stroke-miterlimit',
'stroke-opacity', 'stroke-opacity',
'stroke-width', 'stroke-width',
'paint-order',
'text-anchor', 'text-anchor',
'text-decoration', 'text-decoration',
'text-overflow', 'text-overflow',
'white-space',
'text-rendering', 'text-rendering',
'transform',
'unicode-bidi', 'unicode-bidi',
'vector-effect', 'vector-effect',
'viewport-fill',
'viewport-fill-opacity',
'visibility', 'visibility',
'white-space',
'word-spacing', 'word-spacing',
'writing-mode' 'writing-mode'
], ],
@@ -113,8 +106,6 @@ exports.attrsGroupsDefaults = {
'clip-rule': 'nonzero', 'clip-rule': 'nonzero',
mask: 'none', mask: 'none',
opacity: '1', opacity: '1',
'solid-color': '#000',
'solid-opacity': '1',
'stop-color': '#000', 'stop-color': '#000',
'stop-opacity': '1', 'stop-opacity': '1',
'fill-opacity': '1', 'fill-opacity': '1',
@@ -130,8 +121,6 @@ exports.attrsGroupsDefaults = {
'stroke-opacity': '1', 'stroke-opacity': '1',
'paint-order': 'normal', 'paint-order': 'normal',
'vector-effect': 'none', 'vector-effect': 'none',
'viewport-fill': 'none',
'viewport-fill-opacity': '1',
display: 'inline', display: 'inline',
visibility: 'visible', visibility: 'visible',
'marker-start': 'none', 'marker-start': 'none',
@@ -143,7 +132,6 @@ exports.attrsGroupsDefaults = {
'shape-rendering': 'auto', 'shape-rendering': 'auto',
'text-rendering': 'auto', 'text-rendering': 'auto',
'image-rendering': 'auto', 'image-rendering': 'auto',
'buffered-rendering': 'auto',
'font-style': 'normal', 'font-style': 'normal',
'font-variant': 'normal', 'font-variant': 'normal',
'font-weight': 'normal', 'font-weight': 'normal',
@@ -168,7 +156,7 @@ exports.attrsGroupsDefaults = {
transferFunction: {slope: '1', intercept: '0', amplitude: '1', exponent: '1', offset: '0'} transferFunction: {slope: '1', intercept: '0', amplitude: '1', exponent: '1', offset: '0'}
}; };
// http://www.w3.org/TR/SVG/eltindex.html // http://www.w3.org/TR/SVG11/eltindex.html
exports.elems = { exports.elems = {
a: { a: {
attrsGroups: [ attrsGroups: [
@@ -2295,7 +2283,7 @@ exports.editorNamespaces = [
'http://schemas.microsoft.com/visio/2003/SVGExtensions/' 'http://schemas.microsoft.com/visio/2003/SVGExtensions/'
]; ];
// http://www.w3.org/TR/SVG/linking.html#processingIRI // http://www.w3.org/TR/SVG11/linking.html#processingIRI
exports.referencesProps = [ exports.referencesProps = [
'clip-path', 'clip-path',
'color-profile', 'color-profile',
@@ -2309,7 +2297,7 @@ exports.referencesProps = [
'style' 'style'
]; ];
// http://www.w3.org/TR/SVG/propidx.html // http://www.w3.org/TR/SVG11/propidx.html
exports.inheritableAttrs = [ exports.inheritableAttrs = [
'clip-rule', 'clip-rule',
'color', 'color',
@@ -2319,6 +2307,7 @@ exports.inheritableAttrs = [
'color-rendering', 'color-rendering',
'cursor', 'cursor',
'direction', 'direction',
'dominant-baseline',
'fill', 'fill',
'fill-opacity', 'fill-opacity',
'fill-rule', 'fill-rule',
@@ -2333,7 +2322,6 @@ exports.inheritableAttrs = [
'glyph-orientation-horizontal', 'glyph-orientation-horizontal',
'glyph-orientation-vertical', 'glyph-orientation-vertical',
'image-rendering', 'image-rendering',
'kerning',
'letter-spacing', 'letter-spacing',
'marker', 'marker',
'marker-end', 'marker-end',
@@ -2354,12 +2342,23 @@ exports.inheritableAttrs = [
'text-rendering', 'text-rendering',
'transform', 'transform',
'visibility', 'visibility',
'white-space',
'word-spacing', 'word-spacing',
'writing-mode' 'writing-mode'
]; ];
// http://www.w3.org/TR/SVG/single-page.html#types-ColorKeywords exports.presentationNonInheritableGroupAttrs = [
'display',
'clip-path',
'filter',
'mask',
'opacity',
'text-decoration',
'transform',
'unicode-bidi',
'visibility'
];
// http://www.w3.org/TR/SVG11/single-page.html#types-ColorKeywords
exports.colorsNames = { exports.colorsNames = {
'aliceblue': '#f0f8ff', 'aliceblue': '#f0f8ff',
'antiquewhite': '#faebd7', 'antiquewhite': '#faebd7',
@@ -2546,7 +2545,7 @@ exports.colorsShortNames = {
'#f5deb3': 'wheat' '#f5deb3': 'wheat'
}; };
// http://www.w3.org/TR/SVG/single-page.html#types-DataTypeColor // http://www.w3.org/TR/SVG11/single-page.html#types-DataTypeColor
exports.colorsProps = [ exports.colorsProps = [
'color', 'fill', 'stroke', 'stop-color', 'flood-color', 'lighting-color' 'color', 'fill', 'stroke', 'stop-color', 'flood-color', 'lighting-color'
]; ];

View File

@@ -8,7 +8,7 @@ exports.description = 'removes non-inheritable groups presentational attribut
var inheritableAttrs = require('./_collections').inheritableAttrs, var inheritableAttrs = require('./_collections').inheritableAttrs,
attrsGroups = require('./_collections').attrsGroups, attrsGroups = require('./_collections').attrsGroups,
excludedAttrs = ['display', 'clip', 'clip-path', 'mask', 'opacity', 'overflow', 'visibility']; applyGroups = require('./_collections').presentationNonInheritableGroupAttrs;
/** /**
* Remove non-inheritable group's "presentation" attributes. * Remove non-inheritable group's "presentation" attributes.
@@ -25,11 +25,8 @@ exports.fn = function(item) {
item.eachAttr(function(attr) { item.eachAttr(function(attr) {
if ( if (
~attrsGroups.presentation.indexOf(attr.name) && ~attrsGroups.presentation.indexOf(attr.name) &&
!~attrsGroups.graphicalEvent.indexOf(attr.name) && !~inheritableAttrs.indexOf(attr.name) &&
!~attrsGroups.core.indexOf(attr.name) && !~applyGroups.indexOf(attr.name)
!~attrsGroups.conditionalProcessing.indexOf(attr.name) &&
!~excludedAttrs.indexOf(attr.name) &&
!~inheritableAttrs.indexOf(attr.name)
) { ) {
item.removeAttr(attr.name); item.removeAttr(attr.name);
} }