Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

canvas-app

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-app - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

demo/webgl.js

50

index.js

@@ -0,1 +1,2 @@

var isGL = require('is-webgl-context');
var getGL = require('webgl-context');

@@ -5,2 +6,7 @@ var debounce = require('debounce');

function isCanvasContext(obj) {
var ctx2d = typeof CanvasRenderingContext2D !== 'undefined' && obj instanceof CanvasRenderingContext2D;
return obj && (ctx2d || isGL(obj));
}
function CanvasApp(render, options) {

@@ -34,6 +40,34 @@ if (!(this instanceof CanvasApp))

//setup the canvas
var canvas = options.canvas || document.createElement("canvas");
var canvas,
context,
attribs = options.contextAttributes||{};
this.isWebGL = false;
//if user provided a context object
if (isCanvasContext(options.context)) {
context = options.context;
canvas = context.canvas;
}
//otherwise allow for a string to set one up
if (!canvas)
canvas = options.canvas || document.createElement("canvas");
canvas.width = options.width * DPR;
canvas.height = options.height * DPR;
if (!context) {
if (options.context === "webgl" || options.context === "experimental-webgl") {
context = getGL({ canvas: canvas, attributes: attribs });
if (!context) {
throw "WebGL Context Not Supported -- try enabling it or using a different browser";
}
} else {
context = canvas.getContext(options.context||"2d", attribs);
}
}
this.isWebGL = isGL(context);
if (options.retina) {

@@ -44,16 +78,2 @@ canvas.style.width = options.width + 'px';

var context,
attribs = options.contextAttributes||{};
this.isWebGL = false;
if (options.context === "webgl" || options.context === "experimental-webgl") {
context = getGL({ canvas: canvas, attributes: attribs });
if (!context) {
throw "WebGL Context Not Supported -- try enabling it or using a different browser";
}
this.isWebGL = true;
} else {
context = canvas.getContext(options.context||"2d", attribs);
}
this.running = false;

@@ -60,0 +80,0 @@ this.width = options.width;

{
"name": "canvas-app",
"version": "2.1.1",
"version": "2.2.0",
"description": "sets up a retina-scaled canvas with render loop",

@@ -11,2 +11,3 @@ "main": "index.js",

"debounce": "^1.0.0",
"is-webgl-context": "^1.0.0",
"webgl-context": "^1.2.1"

@@ -16,3 +17,5 @@ },

"domready": "^1.0.5",
"tape": "~2.13.2"
"gl-clear": "0.0.1",
"tape": "~2.13.2",
"webgl-context": "^1.2.1"
},

@@ -19,0 +22,0 @@ "scripts": {

@@ -76,2 +76,4 @@ # canvas-app

If `context is a WebGLRenderingContext or CanvasRenderingContext, it will be used along with its associated `canvas`. This is useful to avoid consecutive `getContext('webgl')` calls which can interfere with WebGL inspectors.
### methods

@@ -78,0 +80,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc