'use strict'; /** * @typedef {import('../lib/types').PathDataItem} PathDataItem * @typedef {import('../lib/types').XastElement} XastElement */ const { collectStylesheet, computeStyle } = require('../lib/style.js'); const { transformsMultiply, transform2js, transformArc, } = require('./_transforms.js'); const { path2js } = require('./_path.js'); const { removeLeadingZero, includesUrlReference, } = require('../lib/svgo/tools.js'); const { referencesProps, attrsGroupsDefaults } = require('./_collections.js'); /** * @typedef {PathDataItem[]} PathData * @typedef {number[]} Matrix */ const regNumericValues = /[-+]?(\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g; /** * Apply transformation(s) to the Path data. * * @type {import('../lib/types').Plugin<{ * transformPrecision: number, * applyTransformsStroked: boolean, * }>} */ const applyTransforms = (root, params) => { const stylesheet = collectStylesheet(root); return { element: { enter: (node) => { if (node.attributes.d == null) { return; } // stroke and stroke-width can be redefined with if (node.attributes.id != null) { return; } // if there are no 'stroke' attr and references to other objects such as // gradients or clip-path which are also subjects to transform. if ( node.attributes.transform == null || node.attributes.transform === '' || // styles are not considered when applying transform // can be fixed properly with new style engine node.attributes.style != null || Object.entries(node.attributes).some( ([name, value]) => referencesProps.has(name) && includesUrlReference(value), ) ) { return; } const computedStyle = computeStyle(stylesheet, node); const transformStyle = computedStyle.transform; // Transform overridden in