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

plugins/moveElemsAttrsToGroup: fix inheitable only attrs array (fix #47)

This commit is contained in:
deepsweet
2012-11-23 18:11:21 +04:00
parent 88121c7723
commit 87cdc92b37
10 changed files with 59 additions and 33 deletions

View File

@ -899,25 +899,51 @@ exports.stylingProps = [
];
// http://www.w3.org/TR/SVG/propidx.html
exports.nonInheritedAttrs = [
'alignment-baseline',
'baseline-shift',
'clip',
'clip-path',
'display',
'dominant-baseline',
'enable-background',
'filter',
'flood-color',
'flood-opacity',
'lighting-color',
'mask',
'opacity',
'overflow',
'stop-color',
'stop-opacity',
'text-decoration', // TODO: "see prose"
'unicode-bidi'
exports.inheritableAttrs = [
'clip-rule',
'color',
'color-interpolation',
'color-interpolation-filters',
'color-profile',
'color-rendering',
'cursor',
'direction',
'fill',
'fill-opacity',
'fill-rule',
'font',
'font-family',
'font-size',
'font-size-adjust',
'font-stretch',
'font-style',
'font-variant',
'font-weight',
'glyph-orientation-horizontal',
'glyph-orientation-vertical',
'image-rendering',
'kerning',
'letter-spacing',
'marker',
'marker-end',
'marker-mid',
'marker-start',
'pointer-events',
'shape-rendering',
'stroke',
'stroke-dasharray',
'stroke-dashoffset',
'stroke-linecap',
'stroke-linejoin',
'stroke-miterlimit',
'stroke-opacity',
'stroke-width',
'text-anchor',
'text-rendering',
'transform',
'visibility',
'word-spacing',
'writing-mode'
];
// http://www.w3.org/TR/SVG/single-page.html#types-ColorKeywords

View File

@ -1,4 +1,4 @@
var nonInheritedAttrs = require('./_collections').nonInheritedAttrs;
var inheritableAttrs = require('./_collections').inheritableAttrs;
/**
* Collapse content's intersected and inheritable
@ -85,7 +85,7 @@ function intersectInheritableAttrs(a, b) {
for (var n in a) {
if (
b.hasOwnProperty(n) &&
nonInheritedAttrs.indexOf(n) === -1 &&
inheritableAttrs.indexOf(n) > -1 &&
a[n].name === b[n].name &&
a[n].value === b[n].value &&
a[n].prefix === b[n].prefix &&

View File

@ -1,8 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g attr1="val1">
<g attr2="val2">
<g fill="red">
text
</g>
<circle attr2="val2" attr3="val3"/>
<circle fill="red" attr3="val3"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 177 B

After

Width:  |  Height:  |  Size: 173 B

View File

@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g attr1="val1" attr2="val2">
<g attr1="val1" fill="red">
<g>
text
</g>

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 162 B

View File

@ -1,8 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g attr1="val1">
<g attr2="val2" attr3="val3">
<g fill="red" color="#000">
text
</g>
<circle attr2="val2" attr3="val3"/>
<circle fill="red" color="#000"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 186 B

View File

@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g attr1="val1" attr2="val2" attr3="val3">
<g attr1="val1" fill="red" color="#000">
<g>
text
</g>

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 162 B

View File

@ -1,8 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g transform="rotate(45)">
<g transform="scale(2)" attr="val">
<g transform="scale(2)" fill="red">
<path d="..."/>
</g>
<circle attr="val" transform="scale(2)"/>
<circle fill="red" transform="scale(2)"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 223 B

After

Width:  |  Height:  |  Size: 223 B

View File

@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g transform="rotate(45) scale(2)" attr="val">
<g transform="rotate(45) scale(2)" fill="red">
<g>
<path d="..."/>
</g>

Before

Width:  |  Height:  |  Size: 179 B

After

Width:  |  Height:  |  Size: 179 B

View File

@ -1,8 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g attr1="val1">
<g attr2="val2" attr3="val3" opacity="1">
<g fill="red" color="#000" opacity="1">
text
</g>
<circle attr2="val2" attr3="val3" opacity="1"/>
<circle fill="red" color="#000" opacity="1"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 214 B

After

Width:  |  Height:  |  Size: 210 B

View File

@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg">
<g attr1="val1" attr2="val2" attr3="val3">
<g attr1="val1" fill="red" color="#000">
<g opacity="1">
text
</g>

Before

Width:  |  Height:  |  Size: 188 B

After

Width:  |  Height:  |  Size: 186 B