npm GitHub

Hydrargyri

Reactive custom elements in plain HTML. No build step, no shadow DOM.

Every reactive framework starts the same way: move your markup into our world. Templates in JS, decorators that need a build step, expressions interpreted out of attributes. The page you already had — the one that renders without any of it — becomes the framework's output instead of your document.

Hydrargyri goes the other way. You keep the HTML. A custom element wraps the part that changes, bind says where state lands, on says what fires, and the script never loading leaves the page exactly as written.

<demo-greeter name="stranger">
  <label>Name <input on="input:rename"></label>
  <p>Hello, <span bind="name">stranger</span>!</p>
</demo-greeter>
hg("demo-greeter", {
  attributes: ["name"],
  handlers: {
    rename(e, el) { el.name = e.target.value || null }
  }
});

Edit the markup above and it re-renders — that is the whole contract. Block the script and it still greets a stranger, because hydrargyri never wrote that word.

No build step, no shadow DOM, no expression language — bind and on hold names, never code. Quicksilver, in the alchemical sense: the volatile principle, the one that moves while the body stays put. Your markup holds still; the values are what run through it. It sits on book-of-spells, same shelf as sulphuris 🜍.

Catalyst is where this started — markup first, custom elements, names in attributes; the shape was already right. What it charges for that shape is a build step — decorators and TypeScript are the path it is written for, even though a plain function call exists. Hydrargyri is the same idea attempted with nothing but the platform underneath: plain ES modules, plain classes, attributes a browser already parses. Whether that trade is worth losing Catalyst's type safety is a taste question, and the table below is the honest version of it.

Read the docs →

Against the alternatives

Like sulphuris, the value here is personal first: this is the wrapper I wanted to exist, and it transfers to whoever shares the taste for markup-first pages. If you want templating, two-way binding, or an ecosystem, the table says where to go — those are fine tools and hydrargyri does not compete on their ground.

The table is drawn on hydrargyri's axes, which is the caveat to read it with: a row exists because this library has an opinion about it, and the rows it has no answer for are the ones the others win.

hydrargyri Catalyst Stimulus Alpine Lit
Size, gzipped 4.2 kB 2.6 kB 11.3 kB 17.1 kB 6.2 kB
Build step no yes — TS decorators no no no, but expected
Component boundary custom element custom element its own registry attribute scan custom element
Shadow DOM never opt-in n/a n/a by default
Evaluates attributes no no no yes no
Declarative value binding bind no — refs you repaint no — refs you repaint x-text, x-bind in the JS template
Conditionals named predicates your DOM code your controller code x-if, evaluated ternaries in JS
Typed attributes attributes, reflected @attr the values API no @property
Formatters at paint formatters no no expressions directives
Invoker Commands a handler key that is a command no no no no
Deep reactivity opt-in, reactive() no no yes, implicit no
Two-way binding no no no x-model no
Lists and templating no — hg-each is its own package no no x-for yes
Renders without the script yes yes yes mostly — x-cloak no
Ecosystem none GitHub's large, especially Rails large large
Pick it when the markup exists first and must survive without the script you already build with TypeScript you want the mature ecosystem, especially around Rails you want logic inline and accept the CSP cost you are building an app, not upgrading a page

Sizes are each package's public entry bundled and minified as ESM through esbuild, then gzipped — hydrargyri's carries book-of-spells, which ships inside dist/. Every one of those numbers moves with a release; measure before quoting.

Where hydrargyri loses is the bottom of the table, and it loses there on purpose: no templating, no two-way binding, no ecosystem. That is the trade, and Limits is the page that spells it out rather than burying it.

Stimulus earns the honest footnote: same religion, different church. The same names-in-markup creed, the same CSP-cleanliness, near-identical event wiring and typed attribute-backed values. The doctrine splits on exactly two points — bind paints declaratively where Stimulus targets are refs you repaint by hand, and the component boundary is the platform's custom element instead of a runtime with a registry, which is also why hydrargyri is 4.2 kB gzipped where Stimulus is 11.3. Past that split it reaches where the table above does not look: outlets wiring one controller to another, action params and options, targetConnected, a classes API, Turbo underneath the whole thing. Weigh the two points against that reach, not the row count.

Install

npm install hydrargyri
import hg, { HgElement, reactive } from "hydrargyri";

Or straight from a CDN as a module, no install:

<script type="module">
  import hg from "https://cdn.jsdelivr.net/npm/hydrargyri/dist/hydrargyri.mjs";
</script>

Nothing is registered by importing hydrargyri — it is a factory, not a bundle of elements. You call it once per tag, and the tag upgrades wherever it appears.

The whole surface

Page What it covers
Getting started the three parts of a hydrargyri element, in one screen
API hg(), HgElement, typed attributes, properties, lifecycle, update(), reactive(), share()
bind where state lands: text, html, value, attr#name, prop#name, class#name, if / unless, and paths into objects
on what fires: event names, handler resolution, the (event, element) signature
Composition elements talking to each other — events up, attributes down, no bus
Limits what hydrargyri will not do, and the threat model for :html

Agents: llms.txt is the link index, llms-full.txt the whole thing in one file.

MIT © Stamat