All Downloads are FREE. Search and download functionalities are using the official Maven repository.

svgo-0.3.7.node_modules.svgo.plugins.moveGroupAttrsToElems.js Maven / Gradle / Ivy

The newest version!
'use strict';

exports.type = 'perItemReverse';

exports.active = true;

var pathElems = require('./_collections.js').pathElems;

/**
 * Move group attrs to the content elements.
 *
 * @example
 * 
 *     
 *     
 * 
 *                          ⬇
 * 
 *     
 *     
 * 
 *
 * @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.content.every(function(inner) {
            return inner.isElem(pathElems);
        })
    ) {
        item.content.forEach(function(inner) {
            if (inner.hasAttr('transform')) {
                inner.attr('transform').value = item.attr('transform').value + ' ' + inner.attr('transform').value;
            } else {
                inner.addAttr(item.attr('transform'));
            }
        });

        item.removeAttr('transform');
    }

};




© 2015 - 2025 Weber Informatics LLC | Privacy Policy