Skip to content

Commit 07ae4f1

Browse files
committed
breaking-change: The default render engine is now resvg-js
1 parent a4a801a commit 07ae4f1

File tree

14 files changed

+230
-221
lines changed

14 files changed

+230
-221
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Breaking Changes
1313

14-
- The default renderer is now [resvg-js](https://github.com/yisibl/resvg-js).
14+
- The default render engine is now [resvg-js](https://github.com/yisibl/resvg-js).
1515
To use Puppeteer, either assign the `--puppeteer` option in the command line or set `"use": "puppeteer"` in the JSON config.
1616

1717
**Example in CLI Argument:**

bin/cbmp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const cliApp = () => __awaiter(void 0, void 0, void 0, function* () {
3838
})
3939
.option("-d, --dir <path>", "Specify the directory to search for SVG files.")
4040
.option("-o, --out <path>", "Specify the directory where rasterized PNG files will be saved.", "./bitmaps")
41-
.option("--puppeteer", "Render using Puppeteer (which require internet).")
41+
.option("--puppeteer", "Use Puppeteer for rendering (requires internet) or default to '@resvg/resvg-js' for SVG rendering.")
4242
.option("-n, --themeName <string>", `Specify the name of sub-directory inside output directory. ${chalk.yellow("(Deprecated: Use the '-o' option to specify the full output path instead.)")}`)
4343
.option("-bc, --baseColor [string]", "Specifies the CSS color for inner part of cursor. (optional)")
4444
.option("-oc, --outlineColor [string]", "Specifies the CSS color for cursor's ouline. (optional)")
@@ -53,14 +53,14 @@ const cliApp = () => __awaiter(void 0, void 0, void 0, function* () {
5353
const options = program.opts();
5454
// ---------------------- Config Based Rendering
5555
if (configPath) {
56-
const { use, configs } = parseConfig(configPath);
56+
const configs = parseConfig(configPath);
5757
try {
5858
for (var _e = true, _f = __asyncValues(Object.entries(configs)), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
5959
_c = _g.value;
6060
_e = false;
6161
const [key, config] = _c;
6262
console.log(`${chalk.blueBright.bold("[+]")} Parsing ${key} Config...`);
63-
if (use === "puppeteer") {
63+
if (options.puppeteer || config.use.toLowerCase() === "puppeteer") {
6464
yield renderer.renderPngsWithPuppeteer(config.dir, config.out, {
6565
colors: config.colors,
6666
fps: options.fps || config.fps,

bin/lib/parseConfig.d.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { Color } from "./colorSvg.js";
22
export type Config = {
3+
use: "puppeteer" | "default";
4+
colors?: Color[];
35
dir: string;
4-
out: string;
56
fps?: number;
6-
colors?: Color[];
7+
out: string;
78
};
89
export type Configs = {
910
[key: string]: Config;
1011
};
11-
export type ParsedConfig = {
12-
use: "puppeteer" | "default";
13-
configs: Configs;
14-
};
15-
export declare const parseConfig: (p: string) => ParsedConfig;
12+
export declare const parseConfig: (p: string) => Configs;

bin/lib/parseConfig.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,5 @@ import path from "path";
33
export const parseConfig = (p) => {
44
const file = path.resolve(p);
55
const configs = JSON.parse(fs.readFileSync(file, { encoding: "utf-8", flag: "r" }));
6-
const use = configs["use"];
7-
delete configs["use"];
8-
if (use.lowerCase() === "puppeteer") {
9-
return { configs, use: "puppeteer" };
10-
}
11-
else {
12-
return { configs, use: "default" };
13-
}
6+
return configs;
147
};

bin/lib/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const renderPngs = (dir, out, options) => __awaiter(void 0, void 0, void 0, func
116116
if (options === null || options === void 0 ? void 0 : options.colors) {
117117
code = colorSvg(code, options.colors);
118118
}
119-
subSpinner.text = fmt("Extracting PNG frames...");
119+
subSpinner.text = fmt("Rendering PNG frames...");
120120
const resvg = new Resvg(code);
121121
const pngData = resvg.render();
122122
const pngBuffer = pngData.asPng();

bin/modules/PngRenderer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
1111
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
1212
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1313
var g = generator.apply(thisArg, _arguments || []), i, q = [];
14-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
15-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
14+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
15+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
16+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
1617
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
1718
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
1819
function fulfill(value) { resume("next", value); }

bin/version.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare const LIB_VERSION = "1.0.1";
1+
export declare const LIB_VERSION = "1.1.0";

bin/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const LIB_VERSION = "1.0.1";
1+
export const LIB_VERSION = "1.1.0";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"cbmp": "bin/cbmp.js"
2222
},
2323
"engines": {
24-
"node": "^12.17.0 || ^14.13 || >=16.0.0"
24+
"node": ">=16.16.0"
2525
},
2626
"scripts": {
2727
"prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",

src/cbmp.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ const cliApp = async () => {
4949
"./bitmaps",
5050
)
5151

52-
.option("--puppeteer", "Render using Puppeteer (which require internet).")
52+
.option(
53+
"--puppeteer",
54+
"Use Puppeteer for rendering (requires internet) or default to '@resvg/resvg-js' for SVG rendering.",
55+
)
5356

5457
.option(
5558
"-n, --themeName <string>",
@@ -89,12 +92,12 @@ const cliApp = async () => {
8992

9093
// ---------------------- Config Based Rendering
9194
if (configPath) {
92-
const { use, configs } = parseConfig(configPath);
95+
const configs = parseConfig(configPath);
9396

9497
for await (const [key, config] of Object.entries(configs)) {
9598
console.log(`${chalk.blueBright.bold("[+]")} Parsing ${key} Config...`);
9699

97-
if (use === "puppeteer") {
100+
if (options.puppeteer || config.use.toLowerCase() === "puppeteer") {
98101
await renderer.renderPngsWithPuppeteer(config.dir, config.out, {
99102
colors: config.colors,
100103
fps: options.fps || config.fps,

0 commit comments

Comments
 (0)