@polymorph/elements-ui
The polymorph vocabulary as custom elements, for a page written in HTML: a static page, a
server-rendered template, or a page htmx or Turbo swaps. Every member the elements map marks
native (design/frameworks/elements.json) is an element, poly- and its kebab name
(<poly-button>), and each public part is an element of its own (<poly-tabs-content>). An
element renders the generated Solid member (@polymorph/solid-ui) into
itself, in the light DOM, on @polymorph/elements, the foundation. The
elements add no anatomy and no decision: the Solid member draws everything, with its recipes.
What it contains
src/<tier>/<Member>.ts: the member's definition (its tag, how each attribute reads into a prop,
its events and its slots) and its element class, Poly<Member>, defined over the Solid member.
src/<tier>/<Member><Part>.ts is a public part's.
src/<tier>/<file>.states.ts: the member's states fixture in element form, each entry the markup
a page writes and what a script sets, named as the React fixture's entries are.
src/index.ts: the entry; importing it defines every element. It exports each element class
and every member's prop types. src/galleries.ts lists every fixture for the laws,
src/definitions.ts holds every definition by tag, and src/loaders.ts each tag's module, for
a page that defines every tag at once and loads a member's code when it first renders.
A definition module imports its Solid member by the member's own module
(@polymorph/solid-ui/controls/Button), not by the Solid vocabulary's index, which attaches every
compound's parts: a page that uses one element loads that member and what it composes.
These files are generated by pnpm shells (pnpm shells --target elements for these alone,
--check to check without writing). Never edit them by hand: change the member's description, or
the renderer in packages/shells/src/elements.ts, and run pnpm shells. The laws, the bridge's
tests, src/parity/, src/conformance/, src/cdn/, src/screen/, src/mount.ts,
src/test-setup.ts and reach-through.ts are written by hand.
docs/shells.md says how the renderer writes each
element and which laws hold the elements, the parity law against the Solid member among them.
How a React prop reads as an element
A prop is an attribute in kebab case (icon-only) and a property in camel case (iconOnly). A
boolean is present, or "false"; data is a JSON attribute; a date or a time is ISO 8601 text; a
function, a render prop or a ref is a property set from script. A node prop is a child with
slot="name". A callback is the event poly-<name>, whose detail is its first argument. The
full mapping is in docs/frameworks.md, and how
a page loads and uses the elements is in
docs/consuming.md.
Run-time screens
src/screen/ draws a screen a model writes, a polymorph-screen/1 document, as poly-* elements
at run time, with no build. It is written by hand and draws from the run-time core
(@polymorph/screen), which decides what a document may draw; it builds
each element with createElement, sets its props as properties, fills its slots with
fillSlot and listens for its events, and writes no markup.
<poly-screen> (src/screen/element.ts) is an element written by hand, as poly-icon is: not a
member, with no Solid member behind it. It draws its spec property, its text property (a
model's answer so far, read with parsePartial), or the JSON in its <script type="application/json"> child. data, streaming, members, addresses (allowed or
refused) and faults (hidden or inline) set what it draws; values, changed and
check() read it. streaming is the page's
to set, for text too; a members value that cannot be read allows no member and is a fault. It
dispatches poly-action when a member calls one of the document's callback inputs, with { name, args, values, changed } as detail (event.waitUntil hands the member a promise), and
poly-fault for what cannot be drawn. It draws in the light DOM and, while it draws, draws no box
of its own.
drawScreen(container, options) (src/screen/api.ts) draws into a plain element and returns a
drawing with update, values, changed, faults, check and dispose. checkScreen,
checkAnswer, runtimeCard, outputContract and parsePartial are the core's, bound to the
members the elements draw.
src/screen/draw.ts is the renderer both use: a drawing is updated in place by each node's
path, and an element whose node did not change is left alone.
@polymorph/elements-ui/screen defines <poly-screen> and every element, each loading its
member's code when it first renders. On a page with no build, polymorph.js defines
<poly-screen> and holds nothing else of it: the renderer and the vocabulary table are a chunk the
first <poly-screen> to connect fetches, the validator a chunk its check() fetches, and
loadScreen() resolves to drawScreen, parsePartial, checkScreen, checkAnswer,
runtimeCard and outputContract. polymorph-all.js holds all of it.
Entry points
| Import |
In-repo (exports) |
@polymorph/elements-ui |
src/index.ts: every element |
@polymorph/elements-ui/<tier>/<Member> |
src/<tier>/<Member>.ts: one element (@polymorph/elements-ui/controls/Button) |
@polymorph/elements-ui/definitions, /loaders |
src/definitions.ts, src/loaders.ts |
@polymorph/elements-ui/screen |
src/screen/index.ts: run-time screens, <poly-screen> and drawScreen |
@polymorph/elements-ui/cdn/<file> |
dist/cdn/<file>: the files a page with no build loads |
pnpm build:packages runs vite.build.config.ts in three modes. The default writes the modules a
bundler reads to dist/: each element's module, with the Solid member it renders compiled under
dist/solid/ and its recipe, through the reach-through transform (reach-through.ts), under
dist/recipes/, each module importing its own stylesheet; the foundations, Solid and Zag are
external. --mode cdn writes the files a page with no build loads to dist/cdn/: polymorph.js,
which defines every tag and <poly-screen> and loads each member's chunk the first time one of its
elements renders, the chunks (the run-time screen's among them), polymorph.css (the base layer,
every recipe through the transform, Icon's, the host rule and the rules for an element that has not
rendered), prepaint.js and a theme sheet per house pairing (themes/<system>.css). --mode cdn-all adds polymorph-all.js, every element in one file. Everything in dist/cdn/ is bundled,
Solid included. No public URL serves those files, because the package is published to a restricted
registry, so polymorph init --framework elements copies them into the app. It is published as
@metamorph-labs/polymorph-elements-ui.