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

@webreflection/elements

v0.1.9

Published

HTML & SVG Custom Elements

Readme

@webreflection/elements

Social Media Photo by Marek Piwnicki on Unsplash

HTML & SVG Custom Elements, glueing qsa-observer and nonchalance together.

Live Test

<script type="module">

  import { elements, HTML, SVG } from 'https://esm.run/@webreflection/elements';

  // same Custom Elements API
  elements.whenDefined('my-h1').then(Class => {
    console.log(Class.name, 'defined');
  });

  // native extends out of the box
  // <h1 is="my-h1"></h1>
  elements.define('my-h1', class MyH1 extends HTML.H1 {
    // anything that works with classes works here
    #private;

    // only caveat:
    //   if defined, the constructor MUST forward arguments!
    constructor(...args) {
      super(...args);
      this.#private = 'test';
    }

    // custom elements lifecycle (connected/disconnected/attributeChanged)
    connectedCallback() {
      console.log('connected', this.#private);
      this.innerHTML = '@webreflection/elements 🥳';
    }
  });

  // regular HTMLElement extends out of the box too
  // <my-element></my-element>
  elements.define('my-element', class MyElement extends HTML.Element {
    connectedCallback() {
      this.innerHTML = '<small>made with ❤️ by <a href="https://github.com/WebReflection/elements">@webreflection</a></small>';
    }
  });

  // as it is for customElements, whenDefined works both
  // before and after an element has been defined
  elements.whenDefined('my-element').then(Class => {
    console.log(Class.name, 'defined');
  });

</script>
<h1 is="my-h1"></h1>
<my-element></my-element>

Enjoy 👋

Native Support Included

If your browser supports natively HTML custom elements builtin extends (i.e. Chrome/ium or Firefox based), and HTML is all you want/need to extend 'cause SVG custom elements do not exist natively on the Web, you can use @webreflection/elements/native export instead, which offers the exact same API without any dependency, hence it's lightweight, easier to reason about, and natively wonderful.

If you don't know if that's supported and you would like to feature detect this ability, you can pick the @webreflection/elements/auto export insted, which uses a lazy load for Safari or any browser that wouldn't support builtins' extends.

Benefits around this module

  • it is based on Web Standard APIs without requiring bloated polyfills
  • it normalizes Custom Elements definition, without diverging between the builtin extend and the regular one:
    • define('my-link', class MyLink extend HTML.A {}) to extend HTMLAnchorElement (output: <a is="my-link"></a>)
    • define('my-el', class MyEl extend HTML.Element {}) to extend HTMLElement (output: <my-el></my-el>)
    • elements are automatically upgraded once live on the DOM
  • it simplifies creation of custom elements:
    • elements can be created via new MyLink() or new MyEl(), reducing confusion around document.createElement('a', { is: 'my-link' }) VS document.createElement('my-el')
  • it simplifies styling of elements via [is="ce-name"] when attribute is present:
    • combined with @webreflection/element it helps creating custom elements builtins extend that will always reflect the is attribute