npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

scratch-card-web-component

v0.1.0

Published

Scratch card web component made in Lit

Readme

Scratch card

A scratch card wrapped in a web component, inspired by the CodePen made by Totati and written with Lit and TypeScript.

Table of Contents

Demo

You can see the scratch card in action here with explicit config details.

Installation

# npm
npm install scratch-card

# yarn
yarn add scratch-card

# pnpm
pnpm add scratch-card

Usage

The scratch card can be imported and used in an HTML page in this way:

<script type="module">
    import "scratch-card"
</script>

<div id="app">
    <scratch-card fillColor="salmon">
        <span>Ciao!</span>
    </scratch-card>
</div>

The scratch card sets its dimensions to 100% width and height of its parent.

You should not create a scratch card via JavaScript/TypeScript, but there you can access and modify its attributes:

const scratchCard = document.querySelector("scratch-card") as ScratchCard;
scratchCard.fillColor = "rebeccapurple";

Properties

Note that the boolean properties are false when they are missing from the html (Lit docs).

  • brushScale: number (default 1), scales up (> 1) or down (< 1) the size of the uncovered area with a single scratch.
  • centerCover: boolean (default false), if true, the cover image is centered in the scratching area.
  • coverSrc: string or undefined (default undefined), URL path (relative or absolute) of the image to be used as cover to scratch. If undefined, then the scratch area will be filled with a rectangle with style specified by the fillColor property.
  • fillColor: string (default white), specifies the color to use to fill the scratch area if a coverSrc is not provided. If this is an invalid value while the coverSrc is missing, the scratch card will show as already scratched.
  • preserveAspectRatio: boolean (default false), whether to scale or not the cover to avoid leaving empty spaces in the scratch area. This can happen when the scratch area and the cover image have not the same aspect ratio.
  • showAllAt: number (default 100), percentage threshold to consider the card as fully scratched. For instance, if showAllAt="80" the content will be entirely revealed when the 80% of the card's surface is scratched.
  • silenceWarnings: boolean (default false), whether to stop emitting or not warnings to the browser console, such as "The image is being scaled up".

CSS properties

You can customize some styling of the scratch card via these CSS properties:

  • --scratch-card-bg-fallback (default transparent): background to show while the canvas image is still loading (use to avoid FUOC effect).
  • --scratch-card-border-radius (default 0): applies a border-radius to the scratch card.
  • --scratch-card-cursor (default default): applies a custom cursor when scratching the card.

You can set a CSS property directly on one of the scratch-card's parent elements.

License

MIT