UI8Kit 3 ecosystem
- github.com/ui8kit/codegen — generator of primitives (spec →
generated/) ← you are here- github.com/ui8kit/registry — packed per-runtime registry on npm/CDN — npm
@ui8kit/registry- github.com/ui8kit/cli — installer
ui8kit— npmui8kitPipeline: codegen (spec →
generated/) → registry (packr/<rt>/) → CDN (unpkg / jsDelivr) → cli (init/add) → app
Spec-driven generator: bricks/<name>/<name>.def.ts is the single source of truth; emitters in
src/emitters/ print it into React, Svelte 5, Vue 3, SolidJS, Web Components and Go templ.
generated/ is build output (git-ignored) — never edit it, change the brick or the emitter.
- The set of outputs is 11 targets (render targets): 5 UI frameworks (React, Vue 3, Svelte 5, SolidJS, Web Components)
- 6 server-side template engines (templ, html/template, Twig, Latte, Jinja2, MiniJinja). Say "targets", not "runtimes"/"frameworks", for the set
(see README → Terminology); code identifiers and CLI flags (
--runtimes,runtime/,r/<runtime>/) keep their names.
- 6 server-side template engines (templ, html/template, Twig, Latte, Jinja2, MiniJinja). Say "targets", not "runtimes"/"frameworks", for the set
(see README → Terminology); code identifiers and CLI flags (
docs/is the single, exhaustive home for primitives docs (docs/README.md). Readdocs/primitives/<name>.mdbefore using or changing a primitive; runtime specifics indocs/runtimes/<rt>.md, rules indocs/contract.md.docs/primitives/<brick>.mdand the index indocs/README.mdare generated bybun run docs(scripts/docs.ts) — after changing a brick/fixture run it and commit the result. Hand-written notes go only between<!-- ui8kit-docs:prose:start/end -->; runtimes/, contract.md, slot.md are fully hand-written.bun run docs:check(inverify) fails on stale docs;tests/docs.test.tsexecutes every doc snippet in all 11 targets.
bun run verify— must stay green (check, generate, docs:check, tsc, generated typecheck, all tests).bun run docs/bun run docs:check— regenerate / verify the generated docs.bun run generate [-- --runtimes …,templ]— writesgenerated/.- templ:
cd generated/templ && templ generate && go vet ./... && go build ./....
-
Text is compared strictly by the parity suites (
tests/support/normalize.ts): server templates (Twig/Latte/Jinja2/MiniJinja) print children flush against their tags (<a>admin</a>, exact<textarea>value) — never wrap{children}/ slots in newlines or indentation. Only whitespace-only nodes between sibling elements are ignored. -
React boolean attrs are forwarded as-is (
checked={checked}), never|| undefined:checked={false}must stay controlled (tests/react-controlled.test.ts). -
generate --cn joinswaps only the TSutils/cn.tsforruntime/ts-join/cn.ts(no tailwind-merge, no conflict resolution) for catalog builds; the defaultmergeis what the registry packs and stays byte-identical (tests/cn-join.test.ts). Never pack the registry with--cn join. -
cn/CnMergeports (Go, PHP, Python) keep tailwind-merge groups:ring-offset-N,ring-offset-<color>,ring-Nandring-<color>are four separate groups (tests/cn-merge.test.ts). -
Forms:
Form(<form>) is the only path —Boxno longer acceptstag="form".Separatorrenders<hr>;decorative⇒role="none"(see docs/primitives/separator.md). -
Every target renders the same DOM, classes (tokens) and ARIA as React / the canonical renderer (
src/domain/render.ts). Parity tests prove it:tests/parity*.test.ts. -
Attribute rules (docs/contract.md#attributes-precedence-empty-values-urls): extra attrs win over the named attribute, then blank optional attrs (all but
value) and unsafe URLs are omitted;data:image/…only in<img src>(Latte >= 3.1.9 dropsdata:insrcitself: not portable, the parity fixtures use https there).tests/parity.attrs.test.tschecks every rule in all 9 real targets against explicit HTML. -
New runtime ⇒ add an emitter, a real-engine parity test (no mocks), CI setup, rules entry in
templates/rules/runtimes.json, README section. -
UI8KIT_REQUIRE_ALL_RUNTIMES=1(set in CI) turns a missing toolchain (Go/templ) into a failure; locally the suite skips with a message.
- Output
generated/templ/(own Go module, templv0.3.1070, Go 1.26); helpers come fromruntime/go/*.go(+go.sum), tag groups are generated fromsrc/domain/tags.ts. - No asChild/Slot: each part with a class contract exports
<Name>Classes(p <Name>Props) string— the escape hatch for custom roots. - Dynamic tags (Box/Text
Tag) become aswitchwith one static element per allowed tag;whenbranches (Button/LinkHref) repeat{ children... }; items (SelectOptions) loop withfor _, item := range. - Go zero values mean "unset": empty strings omit attributes (
Valueis*string:new("")=value=""); propdefaults are unsupported (the emitter throws). A key inAttrsreplaces the named attribute (uiutils.HasAttr);Attrsgo throughuiutils.RestAttrs(unsafe URLs, blank optional attrs dropped). - Children are trusted HTML (
{ children... },templ.Rawin the harness). Props and text are escaped by templ; never route user input into raw children (XSS).
- Output
generated/jinja2/(oneui/<brick>/<part>.html.j2per part); Python helpers come fromruntime/python/(ui8kit_jinja, ported from xgen tagxgen-archive-2026-10-23),ui8kit_jinja/classes.pyis generated. Local check:pip install jinja2thenbun test tests/parity.jinja2.test.ts(PYTHON=overrides the interpreter). - No asChild/Slot: each part with a class contract gets a
<name>_classes(p)Jinja global. - Children are trusted HTML (
{{ children|safe }}, repeated per branch); never route user input into children (XSS). Props/text are autoescaped.
- Output
generated/htmltemplate/(src/emitters/htmltemplate.ts): packageui(one<brick>.go+ embeddedui/<brick>/<part>.htmlper brick, registered ininit()),utils/=runtime/go/(engine-free core) +runtime/go-htmltemplate/(props coercion,AttrsHTML, registry,Funcs()); stdlib only. - Every computed value is a Go method
X<n>on<Part>Props(printed withgo-expr.ts, as templ); templates contain onlyif/else if eq/range/end,$.X<n>and$.Children(tests/emitters.test.tschecks). Never generatetemplate.HTML(/HTMLAttr(/JS(/CSS(from data; URLs go throughuiutils.SafeURL/SafeImgURL, thentemplate.URL(otherwise html/template rewritestel:/data:imageto#ZgotmplZ); computed JS/CSS attributes are an emitter error. - html/template quirks: no dynamic tag or attribute names (
{{if eq}}branches per tag), comments stripped,{{if}}branches must end in the same context, URL values are percent-normalized (the parity suites normalize the expected side withtests/support/htmltemplate.ts). - Local check: Go on PATH,
bun test tests/parity.htmltemplate.test.ts. runtime/go-templ/templ_attrs.goholds the templ-only helpers: not*_templ.go, whichtempl generatedeletes.
- Output
generated/minijinja/: the local crateui8kit_minijinja(no crates.io). The templates are the Jinja2 emitter'sminijinjadialect (src/emitters/jinja2.ts,.html, same bodies as.html.j2); the crate files come fromsrc/emitters/minijinja.ts(Cargo.toml, build.rs, classes.rs, recipes.rs,ui8kit.htmlmacros, parity harness) andruntime/rust/*.rs(helpers,cn_mergeport,register). - MiniJinja is not Jinja2: no Python methods (
.update(),.items()), no macrokwargs/varargs, a bare bool or none printstrue/none(Laravel Rust:true/empty),undefined['x']fails under SemiStrict. Templates must never print a bare bool/none (tests/emitters.test.tschecks); helpers takeValueand treat undefined as unset. - Local check:
cargoon PATH,bun test tests/parity.minijinja.test.ts(CI also runs clippy-D warnings). - Children are trusted HTML, as in Jinja2.
- Output
generated/twig/andgenerated/latte/(Composer packages,twig/twig ^3,latte/latte ^3); emitterssrc/emitters/{twig,latte,php-common}.ts, PHP helpers copied fromruntime/php/*.php(__NAMESPACE__→UI8Kit\Twig/UI8Kit\Latte);Tags.phpandClasses.phpare generated. - No asChild:
Classes::<part>Classes(array $props)(Twig:ui8kit_classes('<part>Classes', {…})). - Dynamic tags:
ifchain, one static element per allowed tag; slot repeated per branch; Select options loop overoptions. - Children are trusted HTML (
|raw/|noescape); never route user input into them (XSS). - Parity:
tests/parity.{twig,latte}.test.ts(sharedtests/support/php-parity.ts); CI usesshivammathur/setup-php(PHP 8.3 + Composer).
- Never commit
generated/; it is build output ofbun run generateand is ignored. - Change specs/emitters in
src/, then runbun run verify(regenerates and checks all targets). @ui8kit/registryis packed from a freshbun run generate, never from a stale tree.
This repo generates the primitives (source of truth). You normally do not install from here — apps install the packed output via the CLI:
Always call the CLI with a pinned major: npx ui8kit@3. add all and add --all are equivalent.
# UI frameworks (writes package.json peers clsx + tailwind-merge for utils)
npx ui8kit@3 init --yes --framework react --dir src && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework vue --dir src && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework svelte --dir src && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework solid --dir src && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework webcomponent --dir src && npx ui8kit@3 add button
npx ui8kit@3 add --all # everything in r/<runtime>/index.json
# Server template engines (no package.json is written or required)
npx ui8kit@3 init --yes --framework templ --dir internal && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework twig --dir templates && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework latte --dir templates && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework jinja2 --dir templates && npx ui8kit@3 add button
npx ui8kit@3 init --yes --framework minijinja --dir crates/ui8kit && npx ui8kit@3 add button # ui8kit >= 3.6
npx ui8kit@3 init --yes --framework htmltemplate --dir internal/ui8kit && npx ui8kit@3 add button # ui8kit >= 3.7Post-install for server template engines (the CLI prints the exact commands from item meta; it never runs them and never edits composer.json / go.mod):
- templ:
go get github.com/a-h/templ@<printed version>→templ generate(after everyadd, and in CI;*_templ.gois generated, not shipped) →go build ./.... Withgo.modpresent the utils import is rewritten to<module>/<dir>/utils. - twig / latte:
composer require "twig/twig:^3.0"(or the printed latte package), add the printed PSR-4 entry tocomposer.json, thencomposer dump-autoload:({ "autoload": { "psr-4": { "UI8Kit\\Twig\\": "templates/runtime/" } } }UI8Kit\\Latte\\for latte). Twig:$twig->addExtension(new \UI8Kit\Twig\TwigExtension()). - jinja2:
pip install "Jinja2>=3.1,<4";from ui8kit_jinja import environment→environment().get_template("ui/button/button.html.j2").render(p={...}, children=...). - minijinja: add
ui8kit_minijinja = { path = "crates/ui8kit" }toCargo.toml(minijinja 2.24+,preserve_order), thenui8kit_minijinja::register(&mut env)(Laravel Rust:app.views().minijinja(ui8kit_minijinja::register)) →{% import "ui8kit.html" as ui %}{{ ui.button({'Variant': 'outline'}, children='Save') }}. - htmltemplate: nothing to install (stdlib); parse views with
ui.Funcs()(Laravel Go:laravel.Options{ViewFuncs: …}) →{{ ui8kit_render "button" (ui8kit_dict "Children" "Save") }}.
Global: -c, --cwd <dir>, -v, --verbose, --no-cache, -V, --version.
| Command | Flags |
|---|---|
init |
-y, --yes, --framework <react|vue|svelte|solid|webcomponent|templ|latte|twig|jinja2|none>, --runtime <name> (defaults to framework), --dir <path>, --skip-core, -r, --registry <type> (default ui), --registry-url <url>, --registry-version <v>, --strict-cdn, --import-style <alias|package> (package deprecated) |
add [components...] |
-a, --all (or add all), -f, --force, --runtime <name>, --path <key=dir> (repeatable, e.g. ui=kit), --dry-run, --retry, -r, --registry <type>, --registry-url, --registry-version, --strict-cdn |
check |
offline verify vs ui8kit.lock.json; --json, --adopt (fetches registry, adopts only matching files), --runtime, --registry-url, --registry-version, --strict-cdn (the last three only with --adopt) |
list |
--json, -r, --registry, --registry-url, --registry-version, --strict-cdn |
diff [component] |
--json, -r, --registry, --registry-url, --registry-version, --strict-cdn |
info |
--json, --cdn (resolved CDN order and overrides) |
scan |
-r, --registry <type|path>, -o, --output <file>, -s, --source <dir> |
build [registry] |
default ./src/registry.json; -o, --output <path> (default ./packages/registry/r) |
cache clear |
— |
registry clean |
--dry-run, --all, -f, --force |
reset |
--dry-run, --with-cache, -y, --yes, -f, --force |
- Default:
@ui8kit/registry@<CLI major>from npm via CDN, tried in order unpkg → jsDelivr:https://unpkg.com/@ui8kit/registry@3/r/<runtime>/index.jsonhttps://cdn.jsdelivr.net/npm/@ui8kit/registry@3/r/<runtime>/index.json
- Per target (
react,vue,svelte,solid,webcomponent,templ,twig,latte,jinja2) underr/<runtime>/:index.json— cataloguecomponents/ui/<name>.json— primitives (e.g.button.json)utils/utils.json—registry:utils(installed byinit)rules/rules.json—registry:rules→.cursor/rules/ui8kit-primitives.mdc(installed byinit)
$schema:https://cdn.jsdelivr.net/npm/@ui8kit/registry@3/schema/{schema,registry,registry-item}.json(config / index / item).- Version:
--registry-versionor"registryVersion"inui8kit.config.jsonaccepts exact (3.1.0), range (3.1) or dist-tag (canary); default is the CLI major (3→ newest 3.x.y). - Resolution order:
--registry-url/registryUrl→cdnBaseUrls(config) → built-in unpkg / jsDelivr. With--strict-cdn(orstrictCdn) and an explicit URL, only that URL is used. - Brand registries:
@ui8kit/registryships primitives only. Brand kits (blocks, composites) host their own registry, e.g.--registry-url https://registry.buildy.tw/react, and reference primitives by absolute URL inregistryDependencies(pinned digest, recorded inmeta.primitives). Brand items get their own lock entries. - Lock:
init/addwriteui8kit.lock.json(source URL, exact version, sha256 per file). Commit it; verify withnpx ui8kit@3 check(offline, exit 1 onmissing/modified/mixed-versions/rules-version). No lock yet →npx ui8kit@3 check --adoptonce.
codegen specs/ + bricks/ ─gen─▶ generated/<rt>/ (build output, NOT committed)
registry pack:runtimes ──────────▶ r/<rt>/*.json (published: @ui8kit/registry)
npm ──▶ unpkg / jsDelivr ──▶ cli: ui8kit init / add ──▶ app {dir}/ui, {dir}/utils + ui8kit.lock.json
Fix a primitive in codegen, repack in registry, publish, then add <name> --force in the app. Never fix it in the app or in r/ by hand.
- Always pin the major:
npx ui8kit@3 …, never barenpx ui8kit. - Install primitives only via
init/add; never copy files fromr/orgenerated/by hand. - Never edit
ui8kit.lock.jsonmanually; never edit files under{dir}/uior{dir}/utils— style viaclassName/ tokens. - Run
npx ui8kit@3 checkbefore every commit; fix drift withadd <name> --force. - Upgrade deliberately: change
registryVersion,add --all --force, re-runinit(rules),check, commit. childrenpassed to server-template primitives is trusted HTML (not escaped) — escape user input yourself.- Server template engines: after
add, run the printed toolchain steps (templ generate,composer dump-autoload,pip install). - New UI that is not a primitive goes to a brand registry (
--registry-url), never into@ui8kit/registry.