You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your plugin request related to a problem? Please describe.
Many (but not all) svg element attributes can be hoisted into a group if they are equal among two or more elements. This doesn't impact rendering oftentimes, is less verbose, and hence takes fewer characters. I am aware that moveElemsAttrsToGroup exists, however, it does not create groups. It just populates them if they already exist.
Describe what the plugin should do
I want to create a plugin that finds the best, or an approximation of the best, way of packing all elements into groups so that the minimum number of characters is emitted. The following examples should illustrate the desired behavior. Please note that the attributes names are dummies, and root (svg) element has been omitted for better legibility.
Input
<pathxaaa/>
<pathyaaa/>
<pathzaaa/>
Output
<gaaa>
<pathx/>
<pathy/>
<pathz/>
</g>
Note that the attributes need to be this long, as otherwise the cost of making a group (7 characters + its attributes) would be greater than just leaving them alone
I think this problem is not analytically solvable, so exhaustively searching all possible arrangements is the only way to guarantee that we find the best solution. I have a working prototype that does this for up to 15 elements. More elements do not work, as I am memory limited and shortly after I reach maximum call stack size. I know that this is suboptimal, but making it work for element counts <= 15 would work and be better than nothing. We could also think about computing approximations for element counts > 15. The prototype I have is standalone, so not integrated into the svgo ecosystem, but I am sure that with some guidance, I can integrate it without much trouble. Are you open to making this a plugin? Or should I release this somewhere else, as standalone?
Open questions
I am not quite sure where I need to be cautious when hoisting attributes into groups, so that the visual rendering of the svg doesn't change. I took the following from moveElemsAttrsToGroup: If "style", "clip-path" or "mask" are present somewhere, abort everything. If "transform" is present, don't touch it, but continue with the rest. Maybe your expertise could help me here.
[ x ] Are you volunteering to work on this plugin?
Is your plugin request related to a problem? Please describe.
Many (but not all) svg element attributes can be hoisted into a group if they are equal among two or more elements. This doesn't impact rendering oftentimes, is less verbose, and hence takes fewer characters. I am aware that moveElemsAttrsToGroup exists, however, it does not create groups. It just populates them if they already exist.
Describe what the plugin should do
I want to create a plugin that finds the best, or an approximation of the best, way of packing all elements into groups so that the minimum number of characters is emitted. The following examples should illustrate the desired behavior. Please note that the attributes names are dummies, and root (
svg
) element has been omitted for better legibility.Input
Output
Note that the attributes need to be this long, as otherwise the cost of making a group (7 characters + its attributes) would be greater than just leaving them alone
Input
Output
And lastly a less trivial example:
Input
Output
Implementation
I think this problem is not analytically solvable, so exhaustively searching all possible arrangements is the only way to guarantee that we find the best solution. I have a working prototype that does this for up to 15 elements. More elements do not work, as I am memory limited and shortly after I reach maximum call stack size. I know that this is suboptimal, but making it work for element counts <= 15 would work and be better than nothing. We could also think about computing approximations for element counts > 15. The prototype I have is standalone, so not integrated into the svgo ecosystem, but I am sure that with some guidance, I can integrate it without much trouble. Are you open to making this a plugin? Or should I release this somewhere else, as standalone?
Open questions
I am not quite sure where I need to be cautious when hoisting attributes into groups, so that the visual rendering of the svg doesn't change. I took the following from moveElemsAttrsToGroup: If "style", "clip-path" or "mask" are present somewhere, abort everything. If "transform" is present, don't touch it, but continue with the rest. Maybe your expertise could help me here.
Related
#801
The text was updated successfully, but these errors were encountered: