Browser polyfill for NativeScript
npm i @nativescript/canvas-polyfill
Import the library into your JavaScript file:
import '@nativescript/canvas-polyfill';
DOM is provided with very low support, these are used for libs like pixi.js that validate type.
class Node
class Element
class Document
class HTMLImageElement
class Image
class ImageBitmap
class HTMLVideoElement
class Video
class HTMLCanvasElement
class Canvas
Image has support for loading callbacks, however the loaded uri must be passed to the src already.
const image = new Image();
image.src = '';
image.onload = () => {
const { src, width, height } = image;
};
image.addEventListener('loading', () => {});
image.addEventListener('error', () => {});
const element = document.createElement('div');
const fakeContext = element.getContext('');
element.clientWidth;
element.clientHeight;
element.innerWidth;
element.innerHeight;
element.offsetWidth;
element.offsetHeight;
element.tagName;
element.addEventListener;
element.removeEventListener;
element.setAttributeNS;
element.createElementNS;
node.ownerDocument;
node.className;
node.appendChild;
node.insertBefore;
node.removeChild;
node.setAttributeNS;
node.getBoundingClientRect;
For debugging base64 image transformations toggle:
global.__debug_browser_polyfill_image = true;
By default global.__debug_browser_polyfill_image
is false.
Apache License Version 2.0, January 2004