Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
The Easy Bake Oven of canvas rendering. Sets up a canvas for 2D or WebGL context, handling a few things like:
Simplest use might look like this:
//a simple render loop
function render(context, width, height, dt) {
context.clearRect(0, 0, width, height);
context.fillRect(0, 0, 25, 25);
}
//defaults to a full-screen canvas
var app = require('canvas-app')(render);
//append to DOM
document.body.appendChild( app.canvas );
//start render loop
app.start();
For simple use like the above, you may want to use canvas-testbed, which also handles DOM ready event, better body styling for full-screen canvas apps, and requestAnimationFrame polyfills.
Another example:
var app = require('canvas-app')(renderHandler, {
width: 256,
height: 256,
once: true, //only render once
retina: false, //don't try to scale for retina displays
});
//renders a single frame
app.renderOnce();
The constructor can take two forms:
canvasApp(renderHandler, options);
canvasApp(options);
width
force a width of the canvas in pixels. If passed, resize events will be ignoredheight
force a height of the canvas in pixels. If passed, resize events will be ignoredignoreResize
if true, resize events will be ignoredretina
default true, whether to scale the canvas style and context for device pixel ratioonce
only renders a single frame, and then again on resizecanvas
the canvas element to use, otherwise creates a new elementcontext
the context to use, can be either 'webgl' or '2d', defaults to 2dcontextAttributes
passed to the getContext callonResize
a function called on resize with arguments width, height
onRender
a function called on render with arguments context, width, height, deltaTime
(can instead be passed as first argument to the constructor)renderOnce()
renders a single framestart()
starts the render loopstop()
stops the current render loopresize(width, height)
resizes the canvas to the given size. You should probably use ignoreResize
if you want to manually handle resize events.canvas
the canvas elementcontext
the 2D or WebGL rendering contextwidth
, height
the current size, not scaled by devicePixelRatiorunning
whether the loop is currently runningMIT, see LICENSE.md for details.
FAQs
sets up a retina-scaled canvas with render loop
The npm package canvas-app receives a total of 5,263 weekly downloads. As such, canvas-app popularity was classified as popular.
We found that canvas-app demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.