Sha256: 2afe183c1debcf134b87a1c8825a04916541a5cb5011251c910a1cd57667ccf0

Contents?: true

Size: 1.81 KB

Versions: 34

Compression:

Stored size: 1.81 KB

Contents

'use strict';

exports.type = 'perItem';

exports.active = true;

exports.description = 'moves some group attributes to the content elements';

var collections = require('./_collections.js'),
    pathElems = collections.pathElems.concat(['g', 'text']),
    referencesProps = collections.referencesProps;

/**
 * Move group attrs to the content elements.
 *
 * @example
 * <g transform="scale(2)">
 *     <path transform="rotate(45)" d="M0,0 L10,20"/>
 *     <path transform="translate(10, 20)" d="M0,10 L20,30"/>
 * </g>
 *                          ⬇
 * <g>
 *     <path transform="scale(2) rotate(45)" d="M0,0 L10,20"/>
 *     <path transform="scale(2) translate(10, 20)" d="M0,10 L20,30"/>
 * </g>
 *
 * @param {Object} item current iteration item
 * @return {Boolean} if false, item will be filtered out
 *
 * @author Kir Belevich
 */
exports.fn = function(item) {

    // move group transform attr to content's pathElems
    if (
        item.isElem('g') &&
        item.hasAttr('transform') &&
        !item.isEmpty() &&
        !item.someAttr(function(attr) {
            return ~referencesProps.indexOf(attr.name) && ~attr.value.indexOf('url(');
        }) &&
        item.content.every(function(inner) {
            return inner.isElem(pathElems) && !inner.hasAttr('id');
        })
    ) {
        item.content.forEach(function(inner) {
            var attr = item.attr('transform');
            if (inner.hasAttr('transform')) {
                inner.attr('transform').value = attr.value + ' ' + inner.attr('transform').value;
            } else {
                inner.addAttr({
                    'name': attr.name,
                    'local': attr.local,
                    'prefix': attr.prefix,
                    'value': attr.value
                });
            }
        });

        item.removeAttr('transform');
    }

};

Version data entries

34 entries across 31 versions & 11 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.18.0 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.18.2 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.16.1 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.15.2 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.18.4 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.18.1 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.14.0 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
tang-0.2.1 spec/tang_app/node_modules/svgo/plugins/moveGroupAttrsToElems.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/svgo/plugins/moveGroupAttrsToElems.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/svgo/plugins/moveGroupAttrsToElems.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/svgo/plugins/moveGroupAttrsToElems.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/svgo/plugins/moveGroupAttrsToElems.js
tang-0.2.0 spec/tang_app/node_modules/svgo/plugins/moveGroupAttrsToElems.js
tang-0.1.0 spec/tang_app/node_modules/svgo/plugins/moveGroupAttrsToElems.js
tang-0.0.9 spec/tang_app/node_modules/svgo/plugins/moveGroupAttrsToElems.js
enju_library-0.3.8 spec/dummy/node_modules/svgo/plugins/moveGroupAttrsToElems.js
jester-data-8.0.0 node_modules/svgo/plugins/moveGroupAttrsToElems.js