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 🙏

© 2024 – Pkg Stats / Ryan Hefner

builtin-elements

v1.0.1

Published

[![Coverage Status](https://coveralls.io/repos/github/WebReflection/builtin-elements/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/builtin-elements?branch=main)

Downloads

623

Readme

builtin-elements

Coverage Status

Social Media Photo by zebbache djoubair on Unsplash

A zero friction custom elements like primitive.

  • zero polyfills needed
  • nothing to define(...)
  • same Custom Elements mechanism plus ...
  • ... the ability to upgrade or downgrade any element, at any time (hydration)
  • all in ~1K once minified+gzipped (~2K without compression)
  • it works even on IE11 (requires transpilation if written as ES6+)
import {HTML, SVG} from 'builtin-elements';

class MyButton extends HTML.Button {
  constructor(text) {
    super();
    this.textContent = text;
  }
}

document.body.appendChild(new MyButton('Hello!'));

Examples


API

This module exports the following utilities:

  • An HTML namespace to extend, example:
    • class Div extends HTML.Div {}
    • class P extends HTML.Paragraph {}
    • class P extends HTML.P {}
    • class TD extends HTML.TD {}
    • class UL extends HTML.UL {}
    • class UL extends HTML.UList {}
    • ... and all available HTML natives ...
    • class Main extends HTML.Main {} works too, together with Header, Footer, Section, Article, and others
  • An SVG namespace to extend too
  • An upgrade(element, Class) helper to manually upgrade any element at any time:
    • no replacement, hence nothing is lost or changed
  • A downgrade(element) utility to drop all notifications about anything when/if needed
  • An observer, from element-notifier, able to .add(specialNodes) to observe. Also the main library observer that can be disconnected whenever is needed.
// full class features
class BuiltinElement extends HTML.Element {

  // exact same Custom Elements primitives
  static get observedAttributes() { return ['test']; }
  attributeChangedCallback(name, oldValue, newValue) {}
  connectedCallback() {}
  disconnectedCallback() {}

  // the best place to setup any component
  upgradedCallback() {}

  // the best place to teardown any component
  downgradedCallback() {}
}

When hydration is desired, upgradedCallback is the method to setup once all listeners, and if elements are subject to change extend, or be downgraded as regular element, downgradedCallback is the best place to cleanup listeners and/or anything else.