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

interestfor

v1.0.7

Published

A polyfill for the `interestfor` API

Readme

interestfor Polyfill

A polyfill for the interestfor attribute. This is a new API for "interest interactions" that is in the process of being implemented in browsers. It will likely ship soon in Chrome. See the explainer for all of the details for the "real" feature:

https://open-ui.org/components/interest-invokers.explainer/

Usage

To use this polyfill, simply load it:

<script src="interestfor.min.js" async></script>

<a interestfor=foo href=bar>Link</a>
<div popover id=foo>Popover</div>

Behavior Summary

Adding the interestfor attribute to a button or link (the "interest invoker"), and giving it a value that is the IDREF of another element (the "target" element), will cause the target to get "interest" and "loseinterest" events when the user "shows interest" in the interest invoker. Showing interest can be done by hovering the element with the mouse, or focusing it with the keyboard. If the target is a popover, it will automatically be shown and hidden upon receiving and losing interest.

Again, this is a quick summary. For the complete details, please read the explainer.

Touchscreen support

This polyfill provides limited touchscreen support. On a touchscreen, long-pressing a <button> element that has an interestfor attribute will show interest in the target.

However, long-pressing a link (<a> element) is not supported. This is because on today's browsers, long-pressing a link element brings up a useful context menu that contains items like "Share" and "Open in new tab". In order for the polyfill to support interest on links, that context menu would need to be surpressed completely. There is currently no way to provide access to the long-press context menu and also provide a way to show interest. Since the context menu contains items that users often use, eliminating access to the context menu is not what most people want. So this polyfill will not support long-press on links.

This is one of the primary motivations for Chromium championing this as a native API in all browsers: to support all users, including those using touchscreens. If you'd like to weigh in on the need for this native API, please feel free to comment on the standards positions for the non-supporting browsers:

  • WebKit: https://github.com/WebKit/standards-positions/issues/464
  • Mozilla: https://github.com/mozilla/standards-positions/issues/1181

Implementation

The polyfill adds event listeners to document.body that monitor for hover or keyboard events relevant for the interestfor API. When interesting events happen to elements with the interestfor attribute or elements that are the targets of those elements, it fires interest and loseinterest events on the target of the interestfor attribute. If the target is a popover, it also handles showing or hiding the popover.

Because this is a polyfill, a few things are slightly different than the native feature:

  • The CSS properties for controlling delays are implemented as custom properties, so you'll want to add both the regular property and the custom property, prefixed with --, to your stylesheet:

    [interestfor] {
      interest-delay-start: 400ms;
      --interest-delay-start: 400ms;
      interest-delay-end: 200ms;
      --interest-delay-end: 200ms;
    }
    /* Or, use the shorthand: */
    [interestfor] {
      interest-delay: 400ms 200ms;
      --interest-delay: 400ms 200ms;
    }
    /* The keyword `normal` can also be used to specify the default delay: */
    [interestfor] {
      interest-delay-end: normal;
      --interest-delay-end: normal;
    }
  • The CSS pseudo classes for detecting invoker and target interest states are implemented as regular class names, so again add both to your stylesheet:

    :is([interestfor]:interest-source),
    [interestfor].interest-source {
      /* invoker styles */
    }
    :is([popover]:interest-target),
    [popover].interest-target {
      /* target popover styles */
    }

    Note the :is() wrapped around the "normal" selector for the real pseudo class names. This is to avoid the entire selector being invalidated if the browser does not recognize the native pseudo class (e.g. :interest-source).

Tests

The test/test.html file exercises the various parts of this feature and tests for correctness. This is a manual test, since hovering, keyboard-focusing, etc. cannot be done programmatically. The test is capable of testing either the polyfill (optionally minified) or the native feature. You can run tests directly from this repo, here.

Browser Compatibility

This polyfill uses all standard APIs, and is therefore compatible with all modern browsers, including Safari and Firefox.

Improvements / Bugs

If you find issues with the polyfill, feel free to file them here. Even better, if you would like to contribute to this polyfill, I'm happy to review pull requests. Thanks in advance!