Skip to content

Commit 3030728

Browse files
committed
fix: Scaling problem on non-responsive webpage
1 parent 8840ccf commit 3030728

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "compodraw",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Compose with JSX or XML then draw to Canvas API",
55
"main": "build/compodraw.js",
66
"types": "types/index.d.ts",

src/renderer/draw.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ import { Instruct } from "../interfaces";
55
*
66
* @param composed Typically a group of instructions
77
* @param canvasDOM Targeted canvas element
8+
* @param isResponsive Set to false if canvas behaves weird
89
*/
9-
export function draw(composed: Instruct, canvasDOM: HTMLCanvasElement): void {
10+
export function draw(
11+
composed: Instruct,
12+
canvasDOM: HTMLCanvasElement,
13+
isResponsive: boolean = true
14+
): void {
1015
if (!canvasDOM) return;
1116

12-
canvasDOM.width = canvasDOM.clientWidth * window.devicePixelRatio;
13-
canvasDOM.height = canvasDOM.clientHeight * window.devicePixelRatio;
17+
if (isResponsive) {
18+
canvasDOM.width = canvasDOM.clientWidth * window.devicePixelRatio;
19+
canvasDOM.height = canvasDOM.clientHeight * window.devicePixelRatio;
20+
}
1421

1522
if (typeof canvasDOM.getContext === "function") {
1623
const canvasCtx = canvasDOM.getContext("2d");

0 commit comments

Comments
 (0)