Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken canvas dependency #3

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/*.png
/*.png
test
30 changes: 13 additions & 17 deletions config/CanvasInstance.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import Canvas, {
EmulatedCanvas2D,
CanvasRenderingContext2D,
} from '../deps.ts';

import Canvas, { type EmulatedCanvas2D, type CanvasRenderingContext2D } from "../deps.ts";

export class CanvasInstance {
// CANVAS API INSTANCES
private static _canvas: EmulatedCanvas2D | null = null;
private static _canvas: EmulatedCanvas2D | null = null;
private static _ctx: CanvasRenderingContext2D | null = null;

// CANVAS CONFIGURATION
private static _WIDTH: number = 200; // Default 200
private static _HEIGHT: number = 200; // Default 200
private static _WIDTH: number = 200; // Default 200
private static _HEIGHT: number = 200; // Default 200

private constructor() {}

/**
Expand All @@ -26,18 +22,18 @@ export class CanvasInstance {
* Instantiates a Canvas Instance
* @param width Canvas Width
* @param height Canvas Height
* @returns
* @returns
*/
public static init(width: number, height: number) {
public static init(width: number, height: number): CanvasRenderingContext2D | null {
if (this._canvas === null) {
this._canvas = Canvas.MakeCanvas(width, height);
this._ctx = this._canvas.getContext('2d');
this._WIDTH = width;
this._HEIGHT = height;
this._canvas = Canvas.MakeCanvas(width, height);
this._ctx = this._canvas.getContext("2d");
this._WIDTH = width;
this._HEIGHT = height;
}
return this._ctx;
}

public static get WIDTH(): number {
return this._WIDTH;
}
Expand All @@ -54,4 +50,4 @@ export class CanvasInstance {
if (this._ctx === null) this.init(200, 200);
return this._ctx as CanvasRenderingContext2D;
}
};
}
2 changes: 1 addition & 1 deletion config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './CanvasInstance.ts';
export * from "./CanvasInstance.ts";
8 changes: 8 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@josefabio/denochart",
"version": "1.2.3",
"exports": "./mod.ts",
"imports": {
"deno-canvas": "jsr:@gfx/canvas-wasm@^0.4.2"
}
}
23 changes: 23 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Canvas from 'https://deno.land/x/canvas@v1.2.2/mod.ts';
import Canvas from "deno-canvas";
export default Canvas;

export * from 'https://deno.land/x/canvas@v1.2.2/mod.ts';
export * from "deno-canvas";
Loading