svg-vectordrawable 0.1.0
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 +21 -0
- package/README.md +104 -0
- package/dist/browser.global.js +18984 -0
- package/dist/browser.js +1129 -0
- package/dist/chunk-QG2B6V6V.js +1130 -0
- package/dist/cli.cjs +1221 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +94 -0
- package/dist/index.cjs +1184 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +32 -0
- package/package.json +68 -0
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
convert
|
|
4
|
+
} from "./chunk-QG2B6V6V.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import { readFileSync, writeFileSync, readdirSync, statSync } from "fs";
|
|
8
|
+
import { join, extname, basename, dirname } from "path";
|
|
9
|
+
var HELP = `svgvd \u2014 convert SVG to Android VectorDrawable
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
svgvd <input.svg|dir> [options]
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
-s, --string <svg> Convert an inline SVG string (prints to stdout)
|
|
16
|
+
-o, --out <path> Output file (single input) or directory (batch)
|
|
17
|
+
--stdout Print result to stdout instead of writing a file
|
|
18
|
+
--no-optimize Skip svgo normalization (not recommended)
|
|
19
|
+
--strict Fail on the first unsupported construct
|
|
20
|
+
--xml-tag Prepend an XML declaration
|
|
21
|
+
--tint <color> Add android:tint to the <vector>
|
|
22
|
+
-p, --precision <n> Decimal places for numbers (default 3)
|
|
23
|
+
-h, --help Show this help
|
|
24
|
+
`;
|
|
25
|
+
function parseArgs(argv) {
|
|
26
|
+
const inputs = [];
|
|
27
|
+
const opts = {};
|
|
28
|
+
let out;
|
|
29
|
+
let inline;
|
|
30
|
+
let stdout = false;
|
|
31
|
+
for (let i = 0; i < argv.length; i++) {
|
|
32
|
+
const arg = argv[i];
|
|
33
|
+
if (arg === "-h" || arg === "--help") {
|
|
34
|
+
process.stdout.write(HELP);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
} else if (arg === "-s" || arg === "--string") inline = argv[++i];
|
|
37
|
+
else if (arg === "-o" || arg === "--out") out = argv[++i];
|
|
38
|
+
else if (arg === "--stdout") stdout = true;
|
|
39
|
+
else if (arg === "--no-optimize") opts.optimize = false;
|
|
40
|
+
else if (arg === "--strict") opts.strict = true;
|
|
41
|
+
else if (arg === "--xml-tag") opts.xmlTag = true;
|
|
42
|
+
else if (arg === "--tint") opts.tint = argv[++i];
|
|
43
|
+
else if (arg === "-p" || arg === "--precision") opts.floatPrecision = Number(argv[++i]);
|
|
44
|
+
else if (arg.startsWith("-") && arg !== "-") {
|
|
45
|
+
process.stderr.write(`Unknown option: ${arg}
|
|
46
|
+
`);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
} else inputs.push(arg);
|
|
49
|
+
}
|
|
50
|
+
return { inputs, inline, out, stdout, opts };
|
|
51
|
+
}
|
|
52
|
+
function listSvgs(path) {
|
|
53
|
+
if (statSync(path).isDirectory())
|
|
54
|
+
return readdirSync(path).filter((f) => extname(f).toLowerCase() === ".svg").map((f) => join(path, f));
|
|
55
|
+
return [path];
|
|
56
|
+
}
|
|
57
|
+
function run() {
|
|
58
|
+
const { inputs, inline, out, stdout, opts } = parseArgs(process.argv.slice(2));
|
|
59
|
+
if (inline !== void 0) {
|
|
60
|
+
const { xml, warnings } = convert(inline, opts);
|
|
61
|
+
for (const w of warnings) process.stderr.write(` \u26A0 [${w.code}] ${w.message}
|
|
62
|
+
`);
|
|
63
|
+
if (out && extname(out) === ".xml") writeFileSync(out, xml);
|
|
64
|
+
else process.stdout.write(xml);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (inputs.length === 0) {
|
|
68
|
+
process.stderr.write(HELP);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const files = inputs.flatMap(listSvgs);
|
|
72
|
+
let failures = 0;
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
try {
|
|
75
|
+
const { xml, warnings } = convert(readFileSync(file, "utf8"), opts);
|
|
76
|
+
for (const w of warnings) process.stderr.write(` \u26A0 ${basename(file)}: [${w.code}] ${w.message}
|
|
77
|
+
`);
|
|
78
|
+
if (stdout) {
|
|
79
|
+
process.stdout.write(xml);
|
|
80
|
+
} else {
|
|
81
|
+
const target = out && files.length === 1 && extname(out) === ".xml" ? out : join(out ?? dirname(file), `${basename(file, ".svg")}.xml`);
|
|
82
|
+
writeFileSync(target, xml);
|
|
83
|
+
process.stderr.write(`\u2713 ${file} \u2192 ${target}
|
|
84
|
+
`);
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
failures++;
|
|
88
|
+
process.stderr.write(`\u2717 ${file}: ${err.message}
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (failures) process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
run();
|