API & CLI

monorepo 各包的导出、命令行工具用法,以及全部 RPML 元素索引。

说明导出
@21stware/rpuiWeb Components 运行时(渲染器)registerAll() · 副作用注册全部自定义元素
rpml-parser.rpml → AST / DOMparse · parseNode · parseToPage · astToDom · expandSelfClosing · RpmlNode
rpml-validator结构 + 语义校验validate(ast)ValidationError[]
rpml-compiler目录 → 单 HTMLcollectRpml(dir) · compileDocs(docs)

运行时加载

三种方式把 .rpml 渲染到页面:

1. 内联标记

<script type="module" src="dist/rpui.js"></script>
<page title="..."> ... </page>

2. 加载器元素

<script type="module" src="dist/rpml-loader.js"></script>
<rpml-app src="./page.rpml"></rpml-app>
<!-- 或 URL 参数:playground.html?rpml=./page.rpml -->

3. 编程式

import { parseToPage } from 'rpml-parser';
document.body.appendChild(parseToPage(rpmlSource));

解析与校验

import { parseNode } from 'rpml-parser';
import { validate } from 'rpml-validator';

const ast = parseNode(rpmlText);        // 任意环境(Bun/Node/浏览器),无需 DOMParser
const errors = validate(ast);            // [{ path, message, severity }]
const fatal = errors.filter(e => e.severity === 'error');

命令行工具

rpml validate

校验单个 .rpml 文件的结构与 pin↔annotation 引用完整性。

bun run validate examples/04-ticket-desk.rpml
# 或:bash tools/validate-examples.sh   # 校验全部示例

rpml-compile

把一个目录的 .rpml 编译成带侧边栏导航的单 HTML 文件,index.rpml 作主页,纯 file:// 离线可用。

bun run compile <dir> -o out.html [--title "..."]

# 示例:把 examples/ 编译成一个门户
bun run compile examples -o examples.html
参数说明
<dir>包含 .rpml 的目录(递归扫描)
-o, --out输出 HTML 路径(默认取目录名)
--title站点标题(默认取目录名)

rpui serve

把当前目录的 .rpml 作为一个带侧边栏的文档集本地托管,启动后打印本地访问地址并自动打开浏览器。每次刷新都会重新扫描目录,编辑后刷新即可看到更新——无需构建、无需 watcher。

npx @21stware/rpui serve .

# 指定目录与端口
npx @21stware/rpui serve ./prototypes --port 4000

# 不自动打开浏览器(headless / CI)
npx @21stware/rpui serve . --no-open
参数说明
[dir]要托管的目录(默认当前目录)
-p, --port端口(默认 3000,占用时自动 +1)
--host主机(默认 localhost)
--no-open启动后不自动打开浏览器

rpui build

把一个目录的 .rpml 编译成单个自包含 HTML 文件(内联运行时 + 带侧边栏的文档集),纯 file:// 离线可用。与 serve 共享同一套零依赖运行时,index.rpml 作默认主页。

npx @21stware/rpui build .

# 指定输出路径与标题
npx @21stware/rpui build ./prototypes -o prototypes.html --title "原型集"
参数说明
[dir]包含 .rpml 的目录(递归扫描,默认当前目录)
-o, --out输出 HTML 路径(默认取目录名)
--title文档集标题(默认取目录名)

Playground

Playground 支持三种加载:URL 参数 ?rpml=、拖拽单个 .rpml、拖拽文件夹构建带侧边栏的文档集(按文件路径生成导航树,hash 路由,index.rpml 作默认主页)。

元素索引

全部 RPML 元素一句话索引。完整属性见组件页与 spec/elements

RPML Element Index

All elements registered by the RPUI runtime. RPML authoring uses the bare language tag names listed below; the runtime maps each to its Web Component tag. This table is the authoritative roster — packages/parser/src/vocabulary.ts is the single source it mirrors.

Canvas elements

ElementCategoryDescription
pageCanvasRoot document shell; title, route, description, optional mode. Default (snapshot): main view left, annotations right. mode="doc": single-column document flow, no route badge, no view/pins/pane
viewCanvasScaled snapshot frame; device preset sets fixed width; scale attribute zooms the canvas
annotationCanvasSpecification block; top-level (id=N) links to data-pin="N"; nested adds sub-region spec
annotation-globalCanvasPage-level, pin-less note for cross-cutting concerns; renders at top of pane; no id/pin
enumCanvasHorizontal row of mutually exclusive state/variant cards
enum-itemCanvasOne state card with label and optional description; auto-numbered with a black square badge
anchorCanvasCross-page link (to, optional section) to another screen in the file set
diagramCanvasRenders Mermaid text (flow/state/sequence/ER) to inline SVG inside an annotation

Layout primitives

ElementCategoryDescription
viewportLayoutFixed-width snapshot viewport matching a device preset
layoutLayoutCSS grid container with columns, rows, and gap attributes
panelLayoutWhite panel/card shell with optional padding and elevation
navigatorLayoutTop navigation bar container
sidebarLayoutSide navigation container; supports collapsed state
logoLayoutLogo placeholder with size and label
split-paneLayoutTwo-column split layout
dividerLayoutHorizontal or vertical divider line
spacerLayoutEmpty space with explicit size
scroll-areaLayoutCustom-styled scrollable container with thin scrollbar; height attribute
collapsibleLayoutExpand/collapse section with label and expanded state; body slot for children
aspect-ratioLayoutContainer maintaining a width/height ratio; ratio attribute (e.g. 16/9)

Control primitives

ElementCategoryDescription
searchControlsSearch field with state (default/focus/filled/error/disabled) and optional clear button
inputControlsText input with label, state, value, optional leading icon, error, help
textareaControlsMulti-line text input with rows, label, state, error, help
selectControlsDropdown select; state collapsed/expanded/filled/error/disabled; options CSV; error
buttonControlsAction button with variant (primary/secondary/ghost/danger/link), state, icon, size
button-groupControlsContainer grouping related buttons
checkboxControlsCheckbox with state (unchecked/checked/indeterminate/disabled/error)
checkbox-groupControlsCheckbox group with label, direction, and validation error
radioControlsRadio button with state (unchecked/checked/disabled/error)
radio-groupControlsRadio group with label, direction, and validation error
toggleControlsToggle switch with state (on/off/disabled/error)
password-inputControlsMasked password field with optional eye toggle; full state matrix
tag-inputControlsChip multi-input; tags CSV, placeholder, label, state, error
formControlsForm container with layout (vertical/horizontal)
form-itemControlsLabeled form field wrapper with required, error, help
form-field-descriptionControlsField-level remark rendered below a field; text attr or child text
radio-cardControlsSelectable card with radio indicator; label, description, state unchecked/checked/disabled
date-pickerControlsDate picker input with state, value, error, help
uploadControlsFile upload zone with state (empty/has-file/uploading/error) and progress
image-placeholderControlsPlaceholder for images; use instead of external image URLs
progressControlsProgress bar or circle with value, kind, and status
sliderControlsSingle-thumb slider with value, min, max; state error/disabled
rangeControlsDual-thumb range slider with low, high, min, max; state error/disabled
number-inputControlsNumeric input with +/- steppers; state error/disabled
ratingControlsStar rating display with value and max; state disabled
pin-inputControlsOTP/PIN cell input with length and value; state disabled
color-swatchControlsColor swatch chip with hex value and label; state disabled
autocompleteControlsAutocomplete input; open shows list; label, state, error
comboboxControlsSearch-select combo box; options CSV, value, placeholder
input-groupControlsInput with prefix/suffix addons; prefix, suffix, placeholder, value
toggle-groupControlsToggle button group; type single/multiple, options CSV, active index
toggle-group-itemControlsIndividual toggle group button with label and active state
fieldControlsField wrapper; label, description, error attributes; control slot for children
ElementCategoryDescription
badgeNavigationNumeric badge/count indicator with max cap
avatarNavigationUser avatar circle with initials and size
listNavigationGenerated list; auto-creates items when no children provided
list-itemNavigationList row with label, icon, badge, and state
tabsNavigationTabbed navigation container with active tab
tabNavigationIndividual tab with label and optional badge
paginationNavigationPagination control with total, current, and page-size
stepsNavigationStep indicator for multi-step flows with active step
breadcrumbNavigationBreadcrumb trail from comma-separated items
segmentedNavigationSegmented control (button group acting as radio)
command-paletteNavigationCommand palette overlay with query and results
context-menuNavigationContext menu with comma-separated items
menuNavigationMenu container
menu-itemNavigationMenu row with label, icon, shortcut, and state
tocNavigationTable of contents from comma-separated items
kbdNavigationKeyboard shortcut chip(s)
menubarNavigationHorizontal menu bar container; contains menubar-item children
menubar-itemNavigationMenu bar item with label and dropdown chevron
nav-menuNavigationHorizontal navigation menu with bottom-border active indicator; contains nav-menu-item children
nav-menu-itemNavigationNavigation menu item with label and active state

Data display primitives

ElementCategoryDescription
tableData displayStatic table; columns CSV; has-checkbox and has-action add affordances; <table-row> children pin exact cell values, else sampled by rows
table-rowData displaytable child declaring one explicit row; content CSV, optional checked
table-list-rowData displayStandalone row slice with content CSV and state (default/selected/unread/highlighted/disabled)
chartData displayStatic inline-SVG data viz; kind bar/line/area/donut/sparkline; data CSV; labels; height; color
avatar-groupData displayOverlapping avatar stack with +N overflow; items count or <avatar> children
commentData displayComment thread entry; author/avatar/time; body slot; nest for replies
file-listData displayFile attachment list container; items count or <file-item> children
file-itemData displayOne file row; name (sets icon), size, state uploaded/uploading/error, progress
bulk-action-barData displayBulk action bar shown when rows are selected; count and actions CSV
emptyData displayEmpty state with label, description, and optional action
loadingData displayLoading placeholder; kind skeleton or spinner; rows count
alertData displayInline alert banner (info/success/warning/error) with title and message
toastData displayToast notification (info/success/warning/error) rendered in annotations
dropdownData displayStatic opened dropdown panel
popoverData displayStatic opened popover panel
tooltipData displayVisible tooltip bubble with text and position
modalData displayStatic opened modal dialog with title, width, optional footer
drawerData displayStatic opened side drawer with side, width, title
cardData displayContent card with title, subtitle, optional image and footer slots
stat-cardData displayKPI card with label, value, trend, and change
tagData displayColored label tag; closable variant
chipData displayCompact token chip with label, icon, closable
treeData displayTree container
tree-itemData displayTree node with label, icon, level, expanded/collapsed, state
timelineData displayTimeline container
timeline-itemData displayTimeline event with label, time, and state
calendarData displayMonth grid calendar with selected date
kanbanData displayKanban board container
kanban-columnData displayKanban column with title and count
kanban-cardData displayKanban card with label and tag
code-blockData displayCode placeholder with language and line count
diffData displayDiff view with added/removed/context lines
image-gridData displayGrid of image placeholders with count and columns
key-valueData displayDescription list container
kv-rowData displayKey-value row with label and value
accordionData displayAccordion container
accordion-itemData displayExpandable accordion section with label
bannerData displayFull-width page-level banner (info/success/warning/error)
skeletonData displayLoading skeleton shape (line/block/card/list/avatar)
countdownData displayTime-remaining chip with value
resultData displayFull-page result screen (success/error/empty) with title and optional action
carouselData displayHorizontal scrolling carousel with prev/next buttons; contains carousel-item children
carousel-itemData displayOne slide in a carousel; fixed 300px width
data-tableData displayEnhanced table with sortable headers; columns CSV, rows semicolon-separated
hover-cardData displayInline trigger text that shows a card on hover; trigger, title, description
sonnerData displayToast notification card; title, description, type (info/success/warning/error)
permission-gateEnterpriseLocked content wrapper with reason label
quota-barEnterpriseUsage bar that turns red at ≥90%; label, used, limit
api-keyEnterpriseMasked API key display with copy affordance
audit-rowEnterpriseAudit log row with actor, action, time
workflow-nodeEnterpriseWorkflow step node with label and state

iOS platform primitives (use with device="mobile")

ElementCategoryDescription
ios-navbariOSiOS-style navigation bar with title, large variant, back, trailing
ios-tabbariOSiOS tab bar with items, icons, active tab
ios-listiOSiOS grouped list with header
ios-list-itemiOSiOS list row with label, detail, icon, chevron
ios-action-sheetiOSiOS action sheet with title, actions, destructive action
ios-alertiOSiOS alert dialog with title, message, actions
ios-switchiOSiOS-style toggle switch
ios-segmentediOSiOS segmented control
ios-buttoniOSiOS-style button (filled/tinted/plain)
ios-searchiOSiOS search bar
ios-stepperiOSiOS stepper control

macOS platform primitives (use with device="web")

ElementCategoryDescription
macos-windowmacOSmacOS window chrome with traffic light buttons
macos-toolbarmacOSmacOS toolbar strip
macos-menubarmacOSmacOS menu bar with items
macos-sidebarmacOSmacOS source list sidebar
macos-source-itemmacOSmacOS sidebar source item with label, icon, group, state
macos-segmentedmacOSmacOS segmented control
macos-popovermacOSmacOS-style popover
macos-sheetmacOSmacOS sheet dialog
macos-steppermacOSmacOS stepper control
macos-disclosuremacOSmacOS disclosure triangle with label and expanded state
macos-tablemacOSmacOS-style table with sortable header look

Agent / conversational UI primitives

ElementCategoryDescription
chatAgentConversation container wrapping the message stream
user-messageAgentRight-aligned user message bubble
agent-messageAgentLeft-aligned agent message (default role "Agent") with optional rich children
system-messageAgentCentered system/context note
tool-callAgentTool call; shows the tool name as headline + 工具 tag + status; args on their own line
agent-outputAgentCommand/code/tool output block (kind: text/code/terminal)
reasoningAgentCollapsible thinking/reasoning block
message-actionsAgentPer-message action buttons (copy/retry/up/down/edit/share)
suggestionsAgentSuggested reply/prompt chips
typingAgentStreaming typing indicator
composerAgentPrompt input bar; attachments (files), mode toggles (thinking/web/code), model pill, state idle/streaming/disabled
citationAgentSource reference chip with index and title
token-usageAgentToken/context usage meter with used and limit

Document mode primitives (mode="doc" pages only)

ElementCategoryDescription
doc-headingDocumentHeading level 1–6; level 2+ adds a bottom border
doc-paragraphDocumentBody paragraph; inline strong, em, code, a allowed
doc-listDocumentOrdered/unordered list; type bullet (default) or number
doc-list-itemDocumentList item inside doc-list
doc-quoteDocumentBlock quote with optional cite attribution line

Design system palette primitives

ElementCategoryDescription
color-paletteDesign SystemGrid of color swatches; items="Name:#hex,…" CSV
font-paletteDesign SystemTypography sample table; items="Label:size/weight,…" CSV
space-paletteDesign SystemProportional bar chart of spacing tokens; tokens="name:px,…" CSV
radius-paletteDesign SystemCorner-radius swatch grid; tokens="name:value,…" CSV