AGENT SKILL
交互式 WebUI 应用开发
webui-dev
构建交互式 WebUI 应用,涉及编译模板的 hydration(水合)、模板语法、组件模式和 CLI 使用。
- License 许可
- MIT
- 所属仓库
- microsoft/webui
- 最近更新
- 2026-11-15
- Stars
- ★ 102
- Forks
- 25
01 前言 Front Matter
- name
- webui-dev
- description
- Build interactive WebUI apps with compiled-template hydration, template syntax, component patterns, and CLI usage.
03 SKILL.md 正文
WebUI App Development
Use this skill when building or modifying WebUI applications.
Critical rules (memorize these)
- The template is the UI. All structure lives in
.html. Neverdocument.createElement,innerHTML,insertAdjacentHTML, orappendChild. Show/hide with<if>, repeat with<for>. The only exception is mounting a lazily loaded component. - CSS owns all styling and animation. Never
el.style.x =,classList.toggle, oradoptedStyleSheets. Bind?data-active="{{expr}}"and select[data-active]in CSS. Animate withtransition,@keyframes,@starting-style- neverelement.animate()or a JS animation library. - JavaScript is opt-in. A component needs no
.tsfile unless it has an@event, aw-reffor an imperative API, a lifecycle hook, a fetch, or a public method API.WebUIElement,@observable, and@attrare optional - add them only when TypeScript reads/writes the value or it is public API. Otherwise the value belongs in the server state JSON. - Use the web platform.
<dialog>over a div modal,popoverover a JS dropdown,<details>over a JS accordion. Prefer:has(),@container,color-mix(),light-dark(),content-visibility. - Every template binding must exist in the server state JSON. Missing keys render empty, silently.
- HTML, CSS, TypeScript are separate files. No JSX. No CSS-in-JS. No JS in templates.
- Unwrapped components default to Shadow;
--dom lightmakes them global Light DOM while authored open wrappers stay Shadow. A sole bare top-level<template>explicitly selects Light and is unwrapped even under the Shadow fallback. Light CSS uses ordinary selectors in its owning CSS tree. Use one sole top-level<template shadowrootmode="open">when the component needs native<slot>projection, Shadow encapsulation, CSS-heavy frequent restyling, root host events, or Shadow-only selectors such as:host. A<slot>and:hostfail only in an effective Light component. - Components inside
<for>loops do NOT inherit loop variables. Pass data via attributes. - Text bindings are path lookups; comparisons belong in conditions.
{{count}}and{{user.name}}resolve a dotted state path - nothing else.{{count > 0}}is looked up as a key literally namedcount > 0and renders empty. Comparisons go in<if condition="count > 0">or?active="{{section == 'guide'}}". Operators:==,!=,<,>,<=,>=,&&,||,!. Forbidden everywhere: ternary (? :), function calls, arithmetic (items.length - 1resolves as a path and silently fails - send a precomputedlastIndex), mixing&&with||, more than 5 logical operators. w-refrequires braces.w-ref="{inputEl}", neverw-ref="inputEl"- non-braced fails the build withinvalid-w-ref. Use it only for imperative APIs (focus, scroll,showModal), never to read state.@attr({ mode: 'boolean' })for true/false. Present = true, absent = false. Never use string"false".
Quick reference
Most components need only HTML and CSS:
<!-- user-card.html - no .ts file -->
<h2>{{user.name}}</h2>
<if condition="user.isAdmin"><span class="badge">Admin</span></if>
Add a class only when something interactive happens:
import { WebUIElement, attr, observable } from '@microsoft/webui-framework';
export class MyComponent extends WebUIElement {
@attr label = ''; // set by a parent template
@attr({ mode: 'boolean' }) disabled = false;
@observable count = 0; // mutated by increment()
inputEl!: HTMLInputElement; // populated by w-ref="{inputEl}"
increment(): void { this.count += 1; }
onKeydown(e: KeyboardEvent): void { if (e.key === 'Enter') this.submit(); }
}
MyComponent.define('my-component');
webui build ./src --out ./dist --plugin=webui
webui serve ./src --state ./data/state.json --plugin=webui --watch
Full reference
The complete guide covering all template syntax, styling and animation rules, anti-patterns, routing, and a pre-flight checklist:
Read that file before generating any WebUI code.
04 同仓库更多 Skills
WebUI 开发参考文档查阅
webui-reference
编写或审查 WebUI 应用或框架代码时使用。加载应用已安装的参考文档,或 WebUI 源代码检出中的权威参考文档。
★ 102
测试模式与测试策略
testing
测试模式、fixture(测试夹具)结构,以及何时该用 E2E 测试、何时该用单元测试。
★ 102
提交前质量门禁检查
quality-gate
在每次提交或推送前运行:格式化、代码检查(lint)、测试、依赖审计、构建和文档检查。
★ 102
Git 提交与 PR 规范
pr
关于分支命名、提交信息(commit message)和 PR 标题的规范指南。
★ 102
Rust 与 Node 性能优化规则
perf
针对 Rust crates、Node 插件(Node addon)、webui-framework 和 webui-delivery 的速度与内存性能规则。
★ 102
用户文档与 DESIGN 同步更新
docs-sync
保持面向用户的文档为最新,并使 DESIGN 与架构变更保持一致。
★ 102