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

Update ID in animateMotion ‘begin’ attribute. Fixes #373

This commit is contained in:
GreLI
2015-06-21 17:51:00 +03:00
parent b5d4166fa9
commit 20e2a30773
2 changed files with 22 additions and 11 deletions

View File

@ -15,6 +15,7 @@ exports.params = {
var referencesProps = require('./_collections').referencesProps,
regReferencesUrl = /^url\(("|')?#(.+?)\1\)$/,
regReferencesHref = /^#(.+?)$/,
regReferencesBegin = /^(\w+?)\./,
styleOrScript = ['style', 'script'],
generateIDchars = [
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
@ -83,17 +84,16 @@ exports.fn = function(data, params) {
}
// save IDs href references
else if (attr.name === 'xlink:href') {
match = attr.value.match(regReferencesHref);
if (match) {
else if (
attr.name === 'xlink:href' && (match = attr.value.match(regReferencesHref)) ||
attr.name === 'begin' && (match = attr.value.match(regReferencesBegin))
) {
if (referencesIDs[idPrefix + match[1]]) {
referencesIDs[idPrefix + match[1]].push(attr);
} else {
referencesIDs[idPrefix + match[1]] = [attr];
}
}
}
});
}
@ -126,13 +126,16 @@ exports.fn = function(data, params) {
IDs[k].attr('id').value = currentIDstring;
referencesIDs[k].forEach(function(attr) {
attr.value = attr.value.replace('#' + k.replace(idPrefix, ''), '#' + currentIDstring);
k = k.replace(idPrefix, '');
attr.value = attr.value
.replace('#' + k, '#' + currentIDstring)
.replace(k + '.', currentIDstring + '.');
});
}
// don't remove referenced IDs
delete IDs[k];
delete IDs[idPrefix + k];
}
}

View File

@ -7,14 +7,18 @@
<text id="referencedText">
referenced text
</text>
<path id="crochet" d="..."/>
<path id="block" d="..."/>
</defs>
<g id="g001">
<circle id="circle001" fill="url(#gradient001)" cx="60" cy="60" r="50"/>
<rect fill="url('#gradient001')" x="0" y="0" width="500" height="100"/>
<tref xlink:href="#referencedText"/>
</g>
<g>
<tref xlink:href="#referencedText"/>
</g>
<animateMotion xlink:href="#crochet" dur="0.5s" begin="block.mouseover" fill="freeze" path="m 0,0 0,-21"/>
</svg>
@@@
@ -28,12 +32,16 @@
<text id="b">
referenced text
</text>
<path id="c" d="..."/>
<path id="d" d="..."/>
</defs>
<g>
<circle fill="url(#a)" cx="60" cy="60" r="50"/>
<rect fill="url('#a')" x="0" y="0" width="500" height="100"/>
<tref xlink:href="#b"/>
</g>
<g>
<tref xlink:href="#b"/>
</g>
<animateMotion xlink:href="#c" dur="0.5s" begin="d.mouseover" fill="freeze" path="m 0,0 0,-21"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB