Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(optimizePathOrder): new plugin #1848

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d17ccee
New plugin: optimize path order
KTibow Nov 23, 2023
37fe2d6
properly account for precision
KTibow Nov 23, 2023
1a3ee7c
update logic to account for more stuff
KTibow Nov 23, 2023
e305966
implement arcs
KTibow Nov 23, 2023
913f27c
add a doc page
KTibow Nov 23, 2023
7007104
rename data to arc
KTibow Nov 23, 2023
192d29c
less hacky way of reducing precision
KTibow Nov 23, 2023
68b3c34
Fix ternaries
KTibow Nov 24, 2023
e31afa2
switch to a for loop
KTibow Nov 24, 2023
5bfef70
fix formatting & use a faster, better stringifyargs
KTibow Nov 24, 2023
2016d6a
properly handle fill none
KTibow Nov 24, 2023
d7bf163
use an even faster way of stringifying args
KTibow Nov 24, 2023
ad9d5da
faster way to estimate path length
KTibow Nov 24, 2023
876afcb
don't run process on identical version
KTibow Nov 24, 2023
94f45cd
use estimation in base size, fix estimation
KTibow Nov 24, 2023
87bb736
also optimize curves
KTibow Nov 24, 2023
a2bf7ec
add polylineOnly
KTibow Nov 24, 2023
b2ea7a2
go from transformPath to transformCommand
KTibow Nov 25, 2023
b54e168
speed: roll through commands
KTibow Nov 25, 2023
25377cd
also stage the shortened svgs
KTibow Nov 25, 2023
6883612
assume fill
KTibow Nov 25, 2023
ab5a098
allow changing direction if there is only one part
KTibow Nov 26, 2023
991fcd3
Merge remote-tracking branch 'upstream' into patch-optimize-order
KTibow Nov 26, 2023
88782bc
Merge remote-tracking branch 'upstream' into patch-optimize-order
KTibow Nov 29, 2023
c0c4cf0
don't crash if convertPathData is off and add tests
KTibow Dec 3, 2023
f6d3906
Make it not on by default
KTibow Dec 20, 2023
b50a6e7
fix formatting
KTibow Dec 20, 2023
927c326
Merge remote-tracking branch 'upstream/main' into patch-optimize-order
KTibow Dec 28, 2023
e62675a
use new set
KTibow Dec 28, 2023
444e12f
Merge remote-tracking branch 'upstream/main' into patch-optimize-order
KTibow Jan 6, 2024
d065475
update to esm, return early for perf
KTibow Jan 6, 2024
6d1e7d5
rearrange statement, use tofixed, fix test
KTibow Jan 6, 2024
ea8237f
more efficient estimatepathlength
KTibow Jan 6, 2024
9b8e1e3
marginally improve estimatelength perf
KTibow Jan 6, 2024
462b7c0
skip on totally unsafe
KTibow Jan 6, 2024
7675369
fix ts issue
KTibow Jan 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/03-plugins/optimize-path-order.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Optimize Path Order
svgo:
pluginId: optimizePathOrder
parameters:
floatPrecision:
description: Number of decimal places to round to, using conventional rounding rules.
default: 3
noSpaceAfterFlags:
description: If to omit spaces after flags. Flags are values that can only be <code>0</code> or <code>1</code> and are used by some path commands, namely <a href="https://developer.mozilla.org/docs/Web/SVG/Attribute/d#elliptical_arc_curve" target="_blank"><code>A</code> and <code>a</code></a>.
default: false
polylineOnly:
description: If to skip path parts that include curves. This will speed up optimization but not get as good of a result.
default: false
---

Optimizes parts of paths by starting in different places and reversing them.

## Usage

<PluginUsage />

### Parameters

<PluginParams />

## Demo

<PluginDemo />

## Implementation

- https://github.com/svg/svgo/blob/main/plugins/optimizePathOrder.js
2 changes: 2 additions & 0 deletions lib/builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as mergePaths from '../plugins/mergePaths.js';
import * as minifyStyles from '../plugins/minifyStyles.js';
import * as moveElemsAttrsToGroup from '../plugins/moveElemsAttrsToGroup.js';
import * as moveGroupAttrsToElems from '../plugins/moveGroupAttrsToElems.js';
import * as optimizePathOrder from '../plugins/optimizePathOrder.js';
import * as prefixIds from '../plugins/prefixIds.js';
import * as removeAttributesBySelector from '../plugins/removeAttributesBySelector.js';
import * as removeAttrs from '../plugins/removeAttrs.js';
Expand Down Expand Up @@ -75,6 +76,7 @@ export const builtin = [
minifyStyles,
moveElemsAttrsToGroup,
moveGroupAttrsToElems,
optimizePathOrder,
prefixIds,
removeAttributesBySelector,
removeAttrs,
Expand Down
2 changes: 1 addition & 1 deletion plugins/mergePaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const description = 'merges multiple paths in one if possible';
export const fn = (root, params) => {
const {
force = false,
floatPrecision,
floatPrecision = 3,
Copy link
Contributor Author

@KTibow KTibow Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't do this, whenever I set an exact value for an argument it leaks out, despite my plugin having a default set. (js2path stores the value exactly, and if it gets called later with a different precision it overrides.)

noSpaceAfterFlags = false, // a20 60 45 0 1 30 20 → a20 60 45 0130 20
} = params;
const stylesheet = collectStylesheet(root);
Expand Down
Loading