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

@corpuscule/custom-builtin-elements

v0.3.0

Published

A full-featured polyfill for customized built-in elements

Downloads

16

Readme

@corpuscule/custom-builtin-elements

Latest Stable Version Package size Build Status GitHub license Coverage Vulnerabilities Bugs

This package is a polyfill for the Customized Built-in Elements specification.

Rationale

Unfortunately, Safari is not going to support this part of the Custom Elements spec, as well as IE 11 and Edge do not have this feature on board. This polyfill aims to fill this gap and provide support for this feature for all browsers that miss it.

You may have a question: why choose this polyfill if there already is a well-known and popular @ungap/custom-elements-builtin? Unfortunately, it has some problems that make it hard to use. For example, with the @ungap/custom-elements-builtin you cannot use class constructors or create new elements with the new operator.

This polyfill provides the solution for all of these issues and makes it possible to use the customized built-in elements in all browsers that lack support for them: Safari, Edge, IE 11.

Installation

npm:

$ npm install @corpuscule/custom-builtin-elements

Yarn:

$ yarn add @corpuscule/custom-builtin-elements

https://unpkg.com

import 'https://unpkg.com/@corpuscule/custom-builtin-elements';

Support

To use this polyfill with IE 11 you need the following tools:

  • Symbol polyfill (with support for Symbol.hasInstance).
  • Promise polyfill.
  • @babel/plugin-transform-instanceof applied to your code that uses instanceof against any built-in constructor (like HTMLButtonElement etc.).

Also, for all browsers that do not support native web components, you need an implementation of the customElements registry existing. You have the following choices:

  • Use @webcomponents/webcomponentsjs, that will also add support for autonomous custom elements.
  • Use the minimal implementation of customElements provided by this polyfill that would allow you to use the customized built-in elements only.

Note that both minimal implementation or @webcomponents/webcomponentsjs polyfill should be executed before the main polyfill because it will override methods of the customElements registry.

Examples of adding minimal implementation:

  • via npm and ESM:
import '@corpuscule/custom-builtin-elements/lib/customElementsBase';
import '@corpuscule/custom-builtin-elements';
<script src="https://unpkg.com/@corpuscule/custom-builtin-elements/lib/customElementsBase.js"></script>
<script src="https://unpkg.com/@corpuscule/custom-builtin-elements"></script>

Example

class ClickCounter extends HTMLButtonElement {
  constructor() {
    super();
    this._count = 0;
    this.increase = this.increase.bind(this);
  }

  get count() {
    return this._count;
  }

  connectedCallback() {
    this.addEventListener('click', this.increase);
  }

  disconnectedCallback() {
    this.removeEventListener('click', this.increase);
  }

  increase() {
    this._count += 1;
  }
}

customElements.define('x-click-counter', ClickCounter, {extends: 'button'});