/** * @typedef {import('../lib/types.js').PathDataItem} PathDataItem * @typedef {import('../lib/types.js').XastElement} XastElement */ import { path2js } from './_path.js'; import { transformsMultiply, transform2js, transformArc, } from './_transforms.js'; import { referencesProps, attrsGroupsDefaults } from './_collections.js'; import { collectStylesheet, computeStyle } from '../lib/style.js'; import { removeLeadingZero, includesUrlReference } from '../lib/svgo/tools.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.js').Plugin<{ * transformPrecision: number, * applyTransformsStroked: boolean, * }>} */ export 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