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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@manxz/gradient-select

v0.1.0

Published

Customizable gradient text selection. Tiny, dependency-free, and native to the browser.

Readme

Gradient select

A little color for the text you select. Gradient select paints a customizable gradient across a native text selection, without wrapping your text in extra elements. Selection, copying, and links keep working as usual.

Try the playground.

Install

npm install @manxz/gradient-select

Or use pnpm add @manxz/gradient-select.

import gradientSelect from '@manxz/gradient-select';

const selection = gradientSelect({ colors: ['#FFB3BA', '#FFD0A8'] });

Call it in the browser after the document is available. Importing the module has no side effects and is safe during server rendering. A call on the server returns an inactive controller; initialize again in the browser, such as inside a component's mount effect.

One-line script

For a plain HTML site, add this to your page:

<script defer src="https://cdn.jsdelivr.net/npm/@manxz/[email protected]/dist/gradient-select.js" data-colors='["#FFB3BA","#FFD0A8"]'></script>

The script initializes automatically and exposes window.GradientSelection. You can also download dist/gradient-select.js from the package and host it yourself.

Colors

Choose 1–64 CSS colors. One color creates a solid highlight; two or more create a gradient. Colors are evenly spaced in the order you supply. The default is pink to peach: #FFB3BA → #FFD0A8.

selection.setColors(['#FFD1E8', '#D5C4F5', '#BBDFFA']);

Opaque, light colors work best because the selected text is black. CSS variables and context-dependent colors such as currentColor are not accepted.

API

gradientSelect(options?) starts the effect and returns a controller. Repeated calls in the same document reuse the controller.

| Member | Purpose | | --- | --- | | setColors(colors) | Update the palette immediately. | | setPreview(element) | Keep an element's text highlighted as a live sample. | | setPreview(null) | Remove the persistent sample. | | refresh() | Repaint immediately after a layout change. | | destroy() | Remove the effect, listeners, styles, and owned highlights. | | init(options?) | Start again after cleanup. | | supported | Whether the browser has the required highlighting features. | | colors | A copy of the current palette. |

The same controller methods are available through window.GradientSelection when using the script tag. Add data-manual to that tag to initialize it yourself with GradientSelection.init().

Live preview

selection.setPreview(document.querySelector('.sample'));
selection.setColors(['#BBDFFA', '#FFD1E8']);

A preview highlights the sample without changing the native selection or moving focus. A real selection takes priority. This makes it useful for color pickers and playgrounds.

Cleanup

selection.destroy();

The controller is shared within a document. Have one application-level owner initialize and clean it up.

Content Security Policy

If your site requires a nonce for inline styles, pass the permitted value:

gradientSelect({ colors: ['#FFB3BA', '#FFD0A8'], nonce: yourCspNonce });

With a script tag, put the nonce on that tag. Your policy must permit the script and the generated stylesheet. If the stylesheet is blocked, ordinary native selection remains available.

Browser behavior

Gradient select uses CSS Custom Highlights, color-mix() in OKLab, and Intl.Segmenter. Unsupported browsers and forced-color mode keep ordinary native selection. Inputs, textareas, and editable content retain their usual selection behavior.

The gradient is approximated with up to 64 highlight bands. Short selections have fewer visible steps. Multiple selection ranges, selections inside shadow roots, and selections longer than 40,000 graphemes fall back to native selection. Traversal is also capped at 10,000 text nodes.

This is an early release. Browser capabilities are checked at runtime; test the interaction in the browsers and devices your site supports.

License

MIT © Oscar Manxz