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 7 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/03-plugins/optimize-path-order.mdx
@@ -0,0 +1,31 @@
---
title: Optimize Path Order
svgo:
pluginId: optimizePathOrder
defaultPlugin: true
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
---

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
1 change: 1 addition & 0 deletions lib/builtin.js
Expand Up @@ -23,6 +23,7 @@ exports.builtin = [
require('../plugins/minifyStyles.js'),
require('../plugins/moveElemsAttrsToGroup.js'),
require('../plugins/moveGroupAttrsToElems.js'),
require('../plugins/optimizePathOrder.js'),
require('../plugins/prefixIds.js'),
require('../plugins/removeAttributesBySelector.js'),
require('../plugins/removeAttrs.js'),
Expand Down
2 changes: 1 addition & 1 deletion plugins/mergePaths.js
Expand Up @@ -17,7 +17,7 @@ exports.description = 'merges multiple paths in one if possible';
exports.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