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

@webreflection/custom-elements

v1.3.0

Published

All inclusive customElements polyfill for every browser

Downloads

3,423

Readme

Custom Elements V1 Polyfill

Social Media Photo by Joanna Kosinska on Unsplash

An unobtrusive customElements V1 polyfill.

Warning: @ungap/custom-elements is what you are looking for!

This module is a ponyfill but the official module for CE is not here.

Use this module only if you understand what a ponyfill here, and only if you are capable of not invoking this more than once in your project.


Compatibility

The polyfill gracefully enhances the following minimum versions of at least these browsers, up to their latest version:

  • Chrome 38
  • Firefox 14
  • Opera 25
  • Internet Explorer 11 and Edge 12
  • Safari 8 and WebKit based
  • Samsung Internet 3

How To Polyfill

This polyfill provides both global fixes and ESM or CJS modules.

As global polyfill

The index.js and its min.js versions are dedicated for usage within HTML pages.

<!-- simply include this script on top of your HTML files -->
<script src="//unpkg.com/@webreflection/custom-elements"></script>

Patches are applied after feature detections to bring customElements V1 to legacy browsers, as well as modern browsers that are not fully specs compliant (i.e. Safari / WebKit).

As ESM

The esm/index.js is the default export. The module does not patch anything until explicitly invoked.

import cePolyfill from '@webreflection/custom-elements';
const customElements = cePolyfill(self || window || global);
const {define, get, whenDefined} = customElements;

As CJS

Everything said for ESM, except the file is in cjs/index.js.

const cePolyfill = require('@webreflection/custom-elements');
const customElements = cePolyfill(self || window || global);
const {define, get, whenDefined} = customElements;

Extra note about ESM/CJS modules

If you'd like to not pollute the global object with all the patches, you need to pass an object that contains all needed globals.

However, this is strongly discouraged unless you are doing this to test/cover something via node.js only, not browsers.

Example

const customElements = cePolyfill({
  // pass a bound version of customElements if available
  customElements: self.customElements && {
    // only define and get are needed
    define: customElements.define.bind(customElements),
    get: customElements.get.bind(customElements)
  },

  // needed globals through this `self` namespace
  Map, MutationObserver, Object, Set, WeakMap,
  HTMLElement, Error, TypeError,

  // the `document.createElement` might be patched regardless
  document,
  // the `Element.prototype.attachShadow` might be patched regardless
  Element,
  // the `Node.prototype.isConnected` might be patched regardless
  Node,

  // one or more globals you'd like to ake available for builtin extends
  HTMLButtonElement,
  HTMLDivElement,
});

To Keep In Mind

This is not a ShadowDOM polyfill, this is just the current Custom Elements V1 as specified by standard bodies.

If you are looking for a reasonable attempt to polyfill ShadowDOM too, ShadyDOM would be my recommendation.

Please note, once this polyfill has been tested enough it will be moved to under @ungap.

Please also note that: