Socket
Socket
Sign inDemoInstall

context-filter-polyfill

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    context-filter-polyfill

Polyfills `CanvasRenderingContext2d.filter` capability of adopting CSS3 filters to canvas contexts at least partially.


Version published
Weekly downloads
1.5K
decreased by-21.78%
Maintainers
1
Install size
194 kB
Created
Weekly downloads
 

Readme

Source

context-filter-polyfill

Build Status

https://davidenke.github.io/context-filter-polyfill/

Polyfills CanvasRenderingContext2d.filter capability of adopting CSS3 filters to canvas contexts at least partially.

Successfully tested on

  • macOS Safari
  • iOS Safari
  • Windows 10 IE11
  • Windows 10 Edge 16-18

Installation

Add the polyfill to your page via script tag from a CDN:

<head>
  <script src="https://cdn.jsdelivr.net/npm/context-filter-polyfill/dist/index.min.js"></script>
</head>

Or from npm:

npm install context-filter-polyfill

... and import it in your code:

import 'context-filter-polyfill';

Supported filters

See it in action

Just open the integration demo on Safari / iOS or IE11.

Strategy

The polyfill is applied by the following steps:

  1. monkey patching all properties of the CanvasRenderingContext2d
  2. monkey patching all getters and setters of the CanvasRenderingContext2d
  3. monkey patching all methods of the CanvasRenderingContext2d

These patches are proxying all changes to a offscreen canvas which applies the appropriate filter polyfills everytime a drawing function is called:

  • clearRect
  • drawImage
  • fill
  • fillRect
  • fillText
  • stroke
  • strokeRect
  • strokeText

The contents of the offscreen canvas are applied back to the original canvas and is then resetted.

FAQs

Last updated on 04 Jan 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc