GithubHelp home page GithubHelp logo

isabella232 / css-paint-polyfill Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googlechromelabs/css-paint-polyfill

0.0 0.0 0.0 155 KB

CSS Custom Paint / Paint Worklet polyfill with special browser optimizations.

Home Page: https://googlechromelabs.github.io/css-paint-polyfill/

License: Apache License 2.0

JavaScript 100.00%

css-paint-polyfill's Introduction

CSS Paint Polyfill demo

CSS Custom Paint / Paint Worklets polyfill npm

A polyfill that brings Houdini's CSS Custom Paint API and Paint Worklets to all modern browsers (Edge, Firefox, Safari and Chrome).

Performance is particularly good in Firefox and Safari, where this polyfill leverages -webkit-canvas() and -moz-element() for optimized rendering. For other browsers, framerate is governed by Canvas toDataURL() / toBlob() speed.

As of version 3, this polyfill also includes basic implementations of CSS.supports(), CSS.registerProperty() and CSS unit functions (CSS.px() etc), which are injected in browsers without native support.

What are Paint Worklets?

Paint Worklets are JavaScript modules in which you can program custom graphics code. Once registered, they can be applied to elements using CSS:

An example box.js worklet:

registerPaint('box', class {
  paint(ctx, geom, properties) {
    ctx.fillRect(0, 0, geom.width, geom.height)
  }
})

... registered and applied on a page:

CSS.paintWorklet.addModule('./box.js')

var el = document.querySelector('h1')
el.style.background = 'paint(box)'

For a more complete example, see the demo.


Installation & Usage

<script src="css-paint-polyfill.js"></script>
<!-- or: -->
<script src="https://unpkg.com/css-paint-polyfill"></script>

Or with a bundler:

import 'css-paint-polyfill';

... or with ES Modules on the web:

import 'https://unpkg.com/css-paint-polyfill';

Contributing

See CONTRIBUTING.md.

To hack on the polyfill locally:

git clone [email protected]:GoogleChromeLabs/css-paint-polyfill.git
cd css-paint-polyfill
npm i
npm start
# open http://localhost:5000

css-paint-polyfill

css-paint-polyfill's People

Contributors

dependabot[bot] avatar developit avatar mathiasbynens avatar samthor avatar tjkohli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.