
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
canvas-animation-loader
Advanced tools
canvas-animation-loader lets you hardware accelerate your canvas animations.
It converts a javascript file that exports an icon class into a static SVG,
with one panel for each frame of the animation. This lets you run the animation
on the GPU using CSS's translateX()
transform with a step()
parameter.
npm install --save-dev canvas-animation-loader
First create a javascript file that exports an animated icon class:
export default class SearchIcon {
constructor(duration, width, height) {
// configure your renderer to produce an animation of the given size
// when render is called.
// in the default configuration animations last for 166 milliseconds and
// are 32x32pixels.
}
render(context, time) {
// context is obtained from a canvas element's .getContext('2d'),
// time is the point in time that the animation should render at.
// In the default configuration this method will be called 11 times
// at 16.6ms intervals (60 frames per second), e.g. with values:
// [0, 16.6, 33.2, 49.8, 66.4, 83, 99.6, 116.2, 132.8, 149.4, 166]
}
}
module.exports = class SearchIcon
constructor: (@duration, @width, @height) ->
render: (context, time) ->
# draw your animation to the canas as it should appear at time T.
Then use it as a background image on some HTML in this configuration:
<div class="animation-viewPort">
<div class="animation-slider"/>
</div>
And load the image into CSS thusly:
.animation-viewPort {
width: 32px;
height: 32px;
overflow: hidden;
}
.animation-slider {
width: calc(32px * 11);
height: 32px;
background-image: url(~!url-loader?mimeType=image/svg+xml!val-loader!canvas-animation-loader!./search_icon.js);
// transform one less than the number of frames so that the last
// frame is visible in the viewport.
transform: translateX(calc(-32px * 10));
// show ten frames, each one lasts for 16.6ms (which is a rounded approximation of 1/60, so 60 frames per second)
transition: transform 166ms step(10);
}
.animation-slider:hover {
// cause the animation to move to the other end.
transform: translateX(0);
}
There are four configurable parameters to the loader, each of which is determined by the values in your CSS (or vice-versa).
url(~!url-loader?mimeType=image/svg+xml!val-loader!canvas-animation-loader?width=X&height=X&duration=X&interval=X);
To make all this work in the CSS:
translateX(-(duration/interval) * frame width)
.translateX(0px)
.FAQs
webpack loader for canvas animations
The npm package canvas-animation-loader receives a total of 4 weekly downloads. As such, canvas-animation-loader popularity was classified as not popular.
We found that canvas-animation-loader 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
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.