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

@pynklynn/backdraft

v0.1.0

Published

Slots in the light DOM for web components.

Readme

Backdraft

Backdraft provides slotting functionality to components using the light DOM.

Why use the light DOM? Until some proposals related to accessibility are implemented as part of the web components spec, there are issues related to accessibility and boundary breaking of the shadow DOM. Given that, if accessibility needs to be supported in an application (which frankly, the answer should be "always"), then slots are not usable at the moment.

Backdraft is based on Daniel Nagy's work on Vampire Slots.

Installation

This module is installable through npm.

npm install --save @pynklynn/backdraft

Examples

Basic Example

This example demonstrates moving content to a nameless slot.

import { backdraftify } from '@pynklynn/backdraft';

const div = Object.assign(document.createElement('div'), {
  innerHTML: backdraftify`
    <h4>Example</h4>
    <v-slot></v-slot>
  `
};

const pTag = document.createElement('p');
pTag.innerHTML = 'This is slotted content';
div.appendChild(pTag);

The above script will produce the following output.

<div>
  <bd-root>
    <h4>Example</h4>
    <bd-slot>
      <bd-slot-assigned-content>
        <p>This is slotted content</p>
      </bd-slot-assigned-content>
    </bd-slot>
  </bd-root>
</div>

Example Using LitElement

Slots are most useful when combined with custom elements. This is example shows how easy it is to use Vampire with LitElement.

import { backdraftifyLit } from '@pynklynn/backdraft';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js'

@customElement('x-example')
@backdraftifyLit
export class ExampleElement extends WithSlots(LitElement) {
  render() {
    return html`
      <h5>Example</h5>
      <bd-slot></bd-slot>
    `;
  }
}

Given the following markup.

<x-example>
  <p>This content will be slotted.</p>
<x-example>

The above component will produce the following output when rendered.

<x-example>
  <bd-root>
    <h5>Example</h5>
    <bd-slot>
      <bd-slot-assigned-content>
        <p>This content will be slotted.</p>
      </bd-slot-assigned-content>
    </bd-slot>
  </bd-root>
<x-example>

Simple Todo List App

https://stackblitz.com/edit/typescript-uykxn4

API Documentation

Backdraft is distributed in ES2022 module format.

BackdraftRoot

A BackdraftRoot is the root node of a DOM subtree.

BackdraftSlot

A BackdraftSlot marks the insertion point of foreign content.

Properties

BackdraftSlot::name: string = '';

A slot may be given a name so that it can be targeted.

Methods

BackdraftSlot::assignedElements(options?: {flatten?: boolean}): Element[];

Returns the elements assigned to this slot. If the flatten option is set to true it will return fallback content if, and only if, there is no assigned content, otherwise it will still return the assigned content.

BackdraftSlot::assignedNodes(options?: {flatten?: boolean}): Node[];

Returns the nodes assigned to this slot. If the flatten option is set to true it will return fallback content if, and only if, there is no assigned content, otherwise it will still return the assigned content.

Example

<div>
  <bd-root>
    <bd-slot></bd-slot>
    <bd-slot name="second-slot"></bd-slot>
  </bd-root>
  <div>This will be moved to the default slot</div>
  <div v-slot="second-slot">This will be moved to the second slot.</div>
</div>

Events

interface ISlotChangeEvent extends CustomEvent {
  readonly type = 'bd-slot-change';
  readonly bubbles = true;
}

The bd-slot-change event is fired when the slot's assigned content changes.

Example

slot.addEventListener('bd-slot-change', (event: Event) => {
  console.log(event.target.assignedNodes());
});

BackdraftSlotFallbackContent

Allows fallback content to be assigned to a slot.

Example

<bd-slot>
  <bd-slot-fallback-content>
    This will be rendered if no content is assigned to this slot.
  </bd-slot-fallback-content>
</bd-slot>

Browser Support

Evergreen browsers are supported.

Caveats

  • Empty Text nodes will be assign to a slot and will prevent fallback content from being rendered.
  • Fallback content cannot contain more slots.