Skip to content

Commit

Permalink
fix(canvas): add globals
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Oct 15, 2021
1 parent 14d36f5 commit 91ef2f9
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/canvas/Canvas2D/DOMMatrix/DOMMatrix.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { DOMMatrixBase } from './common';
export class DOMMatrix extends DOMMatrixBase {
constructor(instance) {
super(instance);
if (!instance) {
this.nativeInstance = org.nativescript.canvas.TNSCanvas.createSVGMatrix();
}
}

get a(): number {
Expand Down
3 changes: 3 additions & 0 deletions packages/canvas/Canvas2D/DOMMatrix/DOMMatrix.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {DOMMatrixBase} from './common';
export class DOMMatrix extends DOMMatrixBase {
constructor(instance) {
super(instance);
if (!this.nativeInstance) {
this.nativeInstance = TNSCanvas.createSVGMatrix();
}
}

get a(): number {
Expand Down
8 changes: 8 additions & 0 deletions packages/canvas/ImageBitmap/common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export declare abstract class ImageBitmapBase {
private nativeInstance;
constructor(nativeInstance: any);
get native(): any;
abstract readonly width: number;
abstract readonly height: number;
abstract close(): any;
}
15 changes: 15 additions & 0 deletions packages/canvas/ImageBitmap/common.js

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

1 change: 1 addition & 0 deletions packages/canvas/ImageBitmap/common.js.map

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

43 changes: 40 additions & 3 deletions packages/canvas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,33 @@ export * from './WebGL';
export * from './WebGL2';
export * from './SVG';

import { ImageBitmap } from './ImageBitmap';

export * from './ImageBitmap';

export {CanvasRenderingContext2D} from './Canvas2D/CanvasRenderingContext2D';
export {WebGLRenderingContext} from './WebGL/WebGLRenderingContext';
export {WebGL2RenderingContext} from './WebGL2/WebGL2RenderingContext';
import {CanvasPattern, CanvasGradient, Path2D} from './Canvas2D';

import {CanvasPattern, CanvasGradient, Path2D, ImageData, DOMMatrix} from './Canvas2D';

Object.defineProperty(global, 'CanvasRenderingContext2D', {
value: CanvasRenderingContext2D,
configurable: true,
writable: true,
});

Object.defineProperty(global, 'WebGLRenderingContext', {
value: WebGLRenderingContext,
configurable: true,
writable: true,
});

Object.defineProperty(global, 'WebGL2RenderingContext', {
value: WebGL2RenderingContext,
configurable: true,
writable: true,
});

Object.defineProperty(global, 'CanvasPattern', {
value: CanvasPattern,
Expand All @@ -32,7 +53,6 @@ Object.defineProperty(global, 'CanvasGradient', {
writable: true,
});


Object.defineProperty(global, 'TextEncoder', {
value: TextEncoder,
configurable: true,
Expand All @@ -45,9 +65,26 @@ Object.defineProperty(global, 'TextDecoder', {
writable: true,
});


Object.defineProperty(global, 'Path2D', {
value: Path2D,
configurable: true,
writable: true,
});

Object.defineProperty(global, 'ImageData', {
value: ImageData,
configurable: true,
writable: true,
});

Object.defineProperty(global, 'DOMMatrix', {
value: DOMMatrix,
configurable: true,
writable: true,
});

Object.defineProperty(global, 'ImageBitmap', {
value: ImageBitmap,
configurable: true,
writable: true,
});
2 changes: 1 addition & 1 deletion packages/canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nativescript/canvas",
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.5",
"description": "DOM Canvas API for NativeScript",
"main": "index",
"typings": "index.d.ts",
Expand Down

0 comments on commit 91ef2f9

Please sign in to comment.