DjDeveloperr / skia_canvas

Fast HTML Canvas API implementation for Deno using Google Skia
https://jsr.io/@gfx/canvas
Apache License 2.0
135 stars 9 forks source link

Types don't match web standard canvas API #69

Closed alexgleason closed 1 month ago

alexgleason commented 2 months ago

I threw /// <reference lib="dom" /> at the top of context2d.ts and changed:

- export class CanvasRenderingContext2D {
+ export class _CanvasRenderingContext2D implements CanvasRenderingContext2D {

The file is then full of type errors. Mainly about things that should be strings vs numbers, etc.

image

After some edits:

image

DjDeveloperr commented 1 month ago

The type errors about numbers vs strings are right and I've fixed them, it will be out with next release. It was a matter of returning number suffixed with px and accepting them too. Though most of these errors do not mean incompatibility with the web. In some cases we support more properties (eg Path2D, FontStretch, ImageData) which causes the mismatch between types, and in some cases our types have less properties so only to support 2D canvas while web has more to offer (DOMMatrix is very primitive, just has a-f fields not all 4x4 fields, and drawing image only supports taking Image object not a canvas). There are some fields where a custom value is not supported so only auto is allowed and hence the mismatch. It is never going to not error if you just bring in web types.

DjDeveloperr commented 1 month ago

I've released the fix in v0.5.7 for a part of it, rest of it seems to be as intended.