npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@flyskywhy/react-native-browser-polyfill

v2.0.1

Published

Browser polyfill with native canvas 2d 3d for making React Native compatible with web libs like zdog (and pixi.js, three.js, phaser.js to be validated)

Downloads

466

Readme

@flyskywhy/react-native-browser-polyfill

Browser polyfill with native canvas 2d 3d for React Native, can directly use canvas based html frameworks without code modified, e.g. zdog.

@flyskywhy/react-native-browser-polyfill is forked from @expo/browser-polyfill, then use @flyskywhy/react-native-gcanvas instead of expo-2d-context, use event-target-shim instead of fbemitter, and fix some bugs.

Installation

npm install @flyskywhy/react-native-browser-polyfill @flyskywhy/react-native-gcanvas

And follow the steps to install @flyskywhy/react-native-gcanvas.

Usage

Import the library just into your project root /index.js , /index.android.js , /index.ios.js or /index.native.js.

If you don't want import it in your project root, you can also import the library into any JavaScript file where you want use it. But if inlineRequires is true in your metro.config.js, you will get ERROR ReferenceError: Can't find variable: document or ERROR ReferenceError: Property 'document' doesn't exist, js engine: hermes, then you should change inlineRequires to false or import the library into your project root e.g. /index.android.js.

import '@flyskywhy/react-native-browser-polyfill';

If canvas 2d or 3d needed, ref to README.md of @flyskywhy/react-native-gcanvas, or just ref to ZdogAndTests.js.

Example

zdog

No need modify any code of framework zdog itself.

Only modify one line code of app demo Made with Zdog CodePen Collection, e.g. just modify .zdog-canvas in JS of https://codepen.io/clarke-nicol/pen/OezRdM into this.canvas in this GCanvasRNExamples APP commit react -> react-native: Zdog and Tests step3 Zdog works well.

Here is the result of ZdogAndTests.js, you can directly discover that the render and mousemove is same with the original html version https://codepen.io/clarke-nicol/pen/OezRdM.

Implements

DOM

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, HTMLImageElement, ImageBitmap

Image can load from https://somewhere.com/some.png or from require('some.png') on Android, iOS and Web, ref to the ZdogAndTests.js or nonDeclarative.js.

const image = document.createElement('img');
const image = new global.HTMLImageElement();
const image = new Image();

image.onload = () => console.log('Can recieve event load by onload');
image.addEventListener('load', () => console.log('Also can recieve event load by addEventListener');

Canvas, HTMLCanvasElement

Example As Usage of @flyskywhy/react-native-gcanvas

document.createElement('canvas') (as offscreen canvas) usage also is described in src/window.js.

window as global

addEventListener;
removeEventListener;
dispatchEvent;
Buffer;
TextDecoder;
TextEncoder;
document;
Document;
Element;
Image;
HTMLImageElement;
ImageBitmap;
CanvasRenderingContext2D;
WebGLRenderingContext;
// window.devicePixelRatio; // undefined as described in `src\resize.js`
window.screen.orientation;
userAgent;
location;

Document

document.createElement;
document.createElementNS;

Element

All sizes return the window size:

element.clientWidth;
element.clientHeight;
element.innerWidth;
element.innerHeight;
element.offsetWidth;
element.offsetHeight;
element.getBoundingClientRect;
element.getAttribute;
element.setAttribute;

Empty attributes that prevent libraries from crashing

element.tagName;
element.setAttributeNS;
element.focus;

Node

node.ownerDocument;
node.className;
node.addEventListener;
node.removeEventListener;
node.dispatchEvent;
node.appendChild;
node.insertBefore;
node.removeChild;

External Libraries

Some external node.js polyfills are added as well.

text-encoding

global.TextEncoder
global.TextDecoder

xmldom-qsa

window.DOMParser