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

@htmdjs/elements

v0.1.0-alpha.5

Published

Lit web components — the base element set for .htmd

Readme

@htmdjs/elements

Lit web components implementing the nine base HTMD contracts: <chat-message>, <data-table>, <choice-group> + <choice-item>, <code-block>, <image-card>, <file-preview>, <refine-prompt>, <htmd-fragment>. Their attributes, children, partial behavior, state, and intents are defined in @htmdjs/contracts.

import { ComponentEvents } from '@htmdjs/contracts';
import type { ChoiceDetail } from '@htmdjs/contracts';
import { registerHtmdElements } from '@htmdjs/elements';

registerHtmdElements();
const stage = document.querySelector('#stage');
stage?.addEventListener(ComponentEvents.Choice, (event) => {
  const { name, value, region } = (event as CustomEvent<ChoiceDetail>).detail;
  console.info(name, value, region);
});

Node/SSR-safe: importing never touches customElements; registerHtmdElements() guards it. Registration makes the tags known to the browser; the renderer still instantiates only components in the host's catalog.

Host capabilities

Components ask for their host with requestHtmdHost(this) when an effect is about to happen, and pass every URL through authorizeComponentUrl for its purpose. Under a renderer the host is the one it was given; standalone elements fall back to defaultHost.

  • <data-table> loads src only when the host authorizes data, through host.loadData when present (a complete TablePayload or progressive TableBatch batches) or as fetched JSON otherwise. With the default host, data tables are blocked. Loads are cancelled when src changes or the element is removed; an error after rows arrive leaves the table interrupted with its rows kept. At most MAX_TABLE_ROWS rows render.
  • <image-card> loads src only when authorized for image; otherwise, or when the image fails to load, it shows the alt text. Changing src retries.
  • <file-preview> exposes its download link only when href is authorized for download.
  • <htmd-fragment> renders nested components only when the host catalog resolves them; native img sources are authorized as image and a links as link.

Intents

choice and refine events use ComponentEvents, ChoiceDetail, and RefineDetail from @htmdjs/contracts. Both bubble, are composed, and carry region, the nearest enclosing data-htmd-region (omitted outside regions). After handling a refine, end the submission with completeRefine(event, { clearInput? }), which finds the <refine-prompt> that dispatched event, calls its reset(clearInput), and returns whether it found one. It works after dispatch has ended (when composedPath() is empty) and for prompts inside shadow trees, so hosts can call it when an asynchronous round-trip finishes:

import { ComponentEvents } from '@htmdjs/contracts';
import type { RefineDetail } from '@htmdjs/contracts';
import { completeRefine } from '@htmdjs/elements';

stage.addEventListener(ComponentEvents.Refine, async (event) => {
  await revise((event as CustomEvent<RefineDetail>).detail);
  completeRefine(event, { clearInput: true });
});

Interaction state

<choice-group> and <refine-prompt> implement StatefulComponent from @htmdjs/contracts, so captureInteractionState / restoreInteractionState carry their user-owned state across renders:

  • <choice-group> snapshots { value } while a choice is selected. Restoring sets the selection (and tab stop) without emitting choice.
  • <refine-prompt> snapshots { draft } while its textarea has text. Restoring sets the draft, even before the element first renders; it never submits.

This package no longer exports HtmdElementEvents, ChoiceDetail, ChoiceSelectDetail, or RefineDetail; import intents from @htmdjs/contracts. The static DataTable.urlPolicy hook is removed; authorize URLs with a host.

Register only trusted component implementations. A hyphenated tag name is not a sandbox for arbitrary registered code.

Part of the .htmd project — https://github.com/zacariec/htmd#readme.