svgo-mbt 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yiming Pan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # svgo-mbt
2
+
3
+ WebAssembly build of [svgo.mbt](https://github.com/PerfectPan/svgo.mbt), an
4
+ SVG optimizer written in MoonBit: all 34 plugins in svgo's preset-default, in its order and with its semantics.
5
+ One 200 KB `wasm-gc` file plus a 2 KB loader, no other dependencies.
6
+
7
+ ```bash
8
+ npm i svgo-mbt # the library
9
+ npx svgo-mbt in.svg -o out.svg # the command line tool, no install
10
+ ```
11
+
12
+ ```js
13
+ import { optimize, plugins } from "svgo-mbt";
14
+
15
+ const r = await optimize(svgText, {
16
+ precision: 3, // decimal places (default 3)
17
+ multipass: true, // repeat until stable (default true)
18
+ pretty: false, // indent output (default false)
19
+ // plugins: ["removeComments", "convertPathData", ...] // explicit list, in order
20
+ });
21
+ r.data; // optimized SVG
22
+ r.originalSize; // bytes in
23
+ r.size; // bytes out
24
+ r.passes; // pipeline passes
25
+ r.applied; // plugins that changed something
26
+
27
+ await plugins(); // [{ name, description, enabled }]
28
+ ```
29
+
30
+ ## Command line
31
+
32
+ The bin is the same optimizer compiled for node, so it needs no toolchain:
33
+
34
+ ```bash
35
+ npx svgo-mbt in.svg -o out.svg
36
+ cat in.svg | npx svgo-mbt > out.svg # stdin, or pass "-" as the input
37
+ npx svgo-mbt icons -r -o dist # a directory, recursively
38
+ npx svgo-mbt in.svg --stats # size statistics on stderr
39
+ npx svgo-mbt in.svg --json # {data, originalSize, size, passes, applied}
40
+ npx svgo-mbt --list # available plugins
41
+ ```
42
+
43
+ Exit codes: 0 on success, 1 for a usage error, 2 when a file could not be
44
+ parsed, with the failing names on stderr.
45
+
46
+ In a browser the module is fetched relative to the loader; pass your own URL
47
+ to `init(url)` before the first `optimize` call if you host it elsewhere.
48
+
49
+ Requires WebAssembly GC and JS String Builtins (V8 13.6): Node 24+, Chrome 130+,
50
+ Firefox 134+, Safari 18.4+.
51
+
52
+ Same-process timings against svgo 4.1 (ms per call, both multipass): a Sketch
53
+ icon 0.07 vs 0.30, a 50 KB Inkscape drawing 3.5 vs 14.5, the 68 KB
54
+ Ghostscript Tiger 7.8 vs 38. Playground and details:
55
+ <https://perfectpan.github.io/svgo.mbt/>.
56
+
57
+ MIT.
58
+
59
+ Plugin entries may also be objects, for example:
60
+
61
+ ```js
62
+ await optimize(svg, {
63
+ plugins: [{ name: "cleanupIds", params: { preserve: ["logo"], minify: false } }],
64
+ });
65
+ ```
66
+
67
+ Top-level `params: { cleanupIds: { preserve: ["logo"] } }` works with either
68
+ the default preset or an explicit plugin list. An entry's `params` object takes
69
+ precedence over the top-level object for that plugin. Missing parameters use
70
+ plugin defaults. `removeComments.preservePatterns` supports literal substrings
71
+ and `^`-prefixed literal prefixes, not full regular expressions.