From 785ee48ba074d57ce3d9ebfbff3c09fea1cdbb55 Mon Sep 17 00:00:00 2001 From: hizzgdev Date: Tue, 20 Feb 2024 01:10:12 +0800 Subject: [PATCH] add option to control the background color of the exported image --- src/plugins/jsmind.screenshot.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/plugins/jsmind.screenshot.js b/src/plugins/jsmind.screenshot.js index fa344a59..67d983c5 100644 --- a/src/plugins/jsmind.screenshot.js +++ b/src/plugins/jsmind.screenshot.js @@ -25,6 +25,7 @@ const DEFAULT_OPTIONS = { left: $.w.location, right: 'https://github.com/hizzgdev/jsmind', }, + background: 'transparent', }; class JmScreenshot { @@ -42,6 +43,7 @@ class JmScreenshot { let c = this.create_canvas(); let ctx = c.getContext('2d'); Promise.resolve(ctx) + .then(() => this.draw_background(ctx)) .then(() => this.draw_lines(ctx)) .then(() => this.draw_nodes(ctx)) .then(() => this.draw_watermark(c, ctx)) @@ -62,6 +64,19 @@ class JmScreenshot { c.parentNode.removeChild(c); } + draw_background(ctx) { + return new Promise( + function (resolve, _) { + const bg = this.options.background; + if (!!bg && bg !== 'transparent') { + ctx.fillStyle = this.options.background; + ctx.fillRect(0, 0, this.jm.view.size.w, this.jm.view.size.h); + } + resolve(ctx); + }.bind(this) + ); + } + draw_lines(ctx) { return new Promise( function (resolve, _) {