1 | 'use strict';
|
2 |
|
3 | exports.type = 'perItem';
|
4 |
|
5 | exports.active = true;
|
6 |
|
7 | exports.description = 'moves some group attributes to the content elements';
|
8 |
|
9 | var collections = require('./_collections.js'),
|
10 | pathElems = collections.pathElems.concat(['g', 'text']),
|
11 | referencesProps = collections.referencesProps;
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | exports.fn = function(item) {
|
33 |
|
34 |
|
35 | if (
|
36 | item.isElem('g') &&
|
37 | item.hasAttr('transform') &&
|
38 | !item.isEmpty() &&
|
39 | !item.someAttr(function(attr) {
|
40 | return ~referencesProps.indexOf(attr.name) && ~attr.value.indexOf('url(');
|
41 | }) &&
|
42 | item.content.every(function(inner) {
|
43 | return inner.isElem(pathElems) && !inner.hasAttr('id');
|
44 | })
|
45 | ) {
|
46 | item.content.forEach(function(inner) {
|
47 | var attr = item.attr('transform');
|
48 | if (inner.hasAttr('transform')) {
|
49 | inner.attr('transform').value = attr.value + ' ' + inner.attr('transform').value;
|
50 | } else {
|
51 | inner.addAttr({
|
52 | 'name': attr.name,
|
53 | 'local': attr.local,
|
54 | 'prefix': attr.prefix,
|
55 | 'value': attr.value
|
56 | });
|
57 | }
|
58 | });
|
59 |
|
60 | item.removeAttr('transform');
|
61 | }
|
62 |
|
63 | };
|