diff --git a/.claude/skills/README.md b/.claude/skills/README.md index 4c7ef226..f18bde6e 100644 --- a/.claude/skills/README.md +++ b/.claude/skills/README.md @@ -10,8 +10,9 @@ Specialized knowledge for AI agents working on Video.js 10. | Building HTML components | `component` + `aria` | | Building React components | `component` + `aria` | | Writing documentation | `docs` | -| Writing Design Docs / RFCs | `design` or `rfc` | -| Reviewing API/architecture | `api` → `review/workflow.md` | +| Writing component reference| `api-reference` | +| Writing Design Docs / RFCs | `design` or `rfc` | +| Reviewing API/architecture | `api` → `review/workflow.md` | | Reviewing documentation | `docs` → `review/workflow.md` | | Reviewing components | `component` → `review/workflow.md` | | Reviewing accessibility | `aria` → `review/workflow.md` | @@ -33,7 +34,8 @@ Specialized knowledge for AI agents working on Video.js 10. | [component](component/SKILL.md) | Build headless UI components — compound patterns, state, styling | Yes | | [create-skill](create-skill/SKILL.md) | Create new skills with proper structure and conventions | No | | [design](design/SKILL.md) | Write Design Docs — decisions you own, component specs, feature designs| No | -| [docs](docs/SKILL.md) | Write Video.js 10 documentation | Yes | +| [api-reference](api-reference/SKILL.md) | Scaffold component API reference pages | No | +| [docs](docs/SKILL.md) | Write Video.js 10 documentation (concepts, how-to, READMEs) | Yes | | [gh-issue](gh-issue/SKILL.md) | Analyze GitHub issues and create implementation plans | No | | [git](git/SKILL.md) | Git workflow — commit messages, PRs, branch naming, scope inference | No | | [review-branch](review-branch/SKILL.md) | Review branch changes and suggest improvements | No | @@ -56,7 +58,7 @@ skill/ | Skill | Review Focus | | ------------------- | ------------------------------------------------- | | `api/review/` | API design, architecture, DX, type safety | -| `docs/review/` | Documentation quality — tone, structure, examples | +| `docs/review/` | Documentation quality — tone, structure, examples | | `component/review/` | Component architecture, state, props, styling | | `aria/review/` | Accessibility — ARIA, keyboard, focus, WCAG | diff --git a/.claude/skills/api-reference/SKILL.md b/.claude/skills/api-reference/SKILL.md new file mode 100644 index 00000000..f4c42557 --- /dev/null +++ b/.claude/skills/api-reference/SKILL.md @@ -0,0 +1,101 @@ +--- +name: api-reference +description: >- + Scaffold API reference documentation for Video.js 10 components. Validates + the api-docs-builder output, checks design docs and linked PRs for context, + creates the MDX reference page with anatomy, prose sections, demos, and the + ApiReference component. Triggers: "api reference", "reference page", + "scaffold api docs", "add api docs", "component reference". +--- + +# API Reference + +Scaffold a complete API reference page for a Video.js 10 component. + +## Usage + +``` +/api-reference [component-name] +``` + +- `component-name` (optional): kebab-case component name (e.g., `play-button`). If omitted, will prompt. + +## Arguments + +$ARGUMENTS + +## Reference Material + +Load these files based on task: + +| Need | Load | +|------|------| +| Builder naming conventions | `references/builder-conventions.md` | +| MDX page structure | `references/mdx-structure.md` | +| Demo file patterns | `references/demo-patterns.md` | +| Component libraries reference | `docs` skill → `references/component-libraries.md` | +| Component patterns | `component` skill | +| Accessibility | `aria` skill | +| Design docs | `internal/design/` | + +## Your Tasks + +### Step 1: Gather context + +Accept component name as argument (kebab-case). + +1. Read the core file at `packages/core/src/core/ui/{name}/{name}-core.ts` — extract Props, State, behavior +2. Read data-attrs file at `packages/core/src/core/ui/{name}/{name}-data-attrs.ts` — extract data attributes +3. Check `packages/react/src/ui/{name}/index.parts.ts` — detect if multi-part +4. Search `internal/design/` for matching design doc: `internal/design/**/*{name}*`. If no design doc is found, proceed — the core file is the primary source of truth; design docs are supplementary context. +5. Read the HTML element file(s) for tag names at `packages/html/src/ui/{name}/` +6. (Optional) Use `git log --oneline --all -- packages/core/src/core/ui/{name}` to find the commit that added the component, then check linked PRs via `gh pr list --search` for additional context. This enriches understanding but steps 1-3 and 5 are sufficient to build the reference page. + +### Step 2: Validate api-docs-builder compatibility + +1. Run `pnpm -F site api-docs` and check for errors +2. Read the generated JSON at `site/src/content/generated-api-reference/{name}.json` +3. Verify the JSON has expected sections (props, state, dataAttributes, platforms.html.tagName) +4. For multi-part: verify each part appears in `parts` with correct names + +If JSON is missing or incomplete, diagnose which convention isn't met. Load `references/builder-conventions.md` for the full list of naming requirements and common failures. Propose fixes: either adjust the component to match conventions, or add a name override — prefer aligning with conventions unless there's good reason not to. + +### Step 3: Determine relevant prose sections + +Based on design docs, core logic, and component complexity, decide which sections to include between `## Anatomy` and `## Examples`. Not all are required — include only what adds value: + +- **Behavior** — include when the component has state transitions, timing, interaction logic, or non-obvious behavior (e.g., Controls auto-hide, BufferingIndicator delay, Time formatting). Skip for trivial components. +- **Styling** — include when the component has data attributes for CSS targeting. Show CSS selector patterns. Always include for components with 2+ data attributes. +- **Accessibility** — include when the component has ARIA attributes, keyboard interactions, or screen reader considerations. Always include for interactive components (buttons, sliders). +- Other sections may be relevant depending on the component (e.g., "Platform Support" for features with availability detection). + +### Step 4: Create demos + +Create at least a BasicUsage demo in both HTML and React. Load `references/demo-patterns.md` for the full file structure and conventions. + +- HTML demo: 4 files (`.astro`, `.html`, `.css`, `.ts`) +- React demo: 2 files (`.tsx`, `.css`) +- Follow BEM naming: `{framework}-{component}-{variant}__{element}` +- CSS uses data-attribute selectors for state-based styling +- React uses `render` prop for state-based rendering +- Video source: `https://stream.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/highest.mp4` +- Poster image: `https://image.mux.com/lhnU49l1VGi3zrTAZhDm9LUUxSjpaPW9BL4jY25Kwo4/thumbnail.jpg` +- Consider additional demos for features not covered by BasicUsage + +### Step 5: Create MDX reference page + +Load `references/mdx-structure.md` for the full structure template. + +1. Create `site/src/content/docs/reference/{name}.mdx` +2. Add to sidebar in `site/src/docs.config.ts` (alphabetically within Components section) +3. Structure: frontmatter → imports → Anatomy → prose sections → Examples → `` +4. Run `pnpm dev` from root and verify the page renders in both HTML and React framework modes + +## Related Skills + +| Need | Use | +|------|-----| +| Building UI components | `component` skill | +| Accessibility patterns | `aria` skill | +| Documentation standards | `docs` skill | +| API design principles | `api` skill | diff --git a/.claude/skills/api-reference/references/builder-conventions.md b/.claude/skills/api-reference/references/builder-conventions.md new file mode 100644 index 00000000..6e4fa088 --- /dev/null +++ b/.claude/skills/api-reference/references/builder-conventions.md @@ -0,0 +1,85 @@ +# Builder Conventions + +Naming and file placement conventions required by the api-docs-builder at `site/scripts/api-docs-builder/`. + +## File Locations + +| File | Path | Purpose | +|------|------|---------| +| Core | `packages/core/src/core/ui/{name}/{name}-core.ts` | Props, State, defaultProps | +| Data attrs | `packages/core/src/core/ui/{name}/{name}-data-attrs.ts` | Data attribute definitions | +| HTML element | `packages/html/src/ui/{name}/{name}-element.ts` | Custom element with `static tagName` | +| React parts | `packages/react/src/ui/{name}/index.parts.ts` | Multi-part detection (optional) | + +## Naming Requirements + +The builder derives PascalCase from kebab-case using `kebabCase` from es-toolkit. All interfaces and exports must follow this pattern: + +| Convention | Example (play-button) | +|-----------|----------------------| +| Props interface | `PlayButtonProps` | +| State interface | `PlayButtonState` | +| Core class | `PlayButtonCore` | +| Data attrs export | `PlayButtonDataAttrs` | +| HTML element class | `PlayButtonElement` | +| HTML tag name | `static tagName = 'media-play-button'` | + +## NAME_OVERRIDES + +When kebab-to-pascal conversion doesn't produce the correct name, add an override in `site/scripts/api-docs-builder/src/index.ts`: + +```ts +const NAME_OVERRIDES: Record = { + 'pip-button': 'PiPButton', +}; +``` + +Use overrides only when the standard conversion fails (e.g., acronyms like PiP). Prefer aligning component naming with the standard conversion when possible. + +## Multi-Part Components + +**Detection**: Presence of `packages/react/src/ui/{name}/index.parts.ts`. + +**Primary part identification**: The part whose HTML element file is `{name}-element.ts` (not `{name}-{part}-element.ts`). The primary part receives the shared core props/state/data-attrs. + +**Non-primary parts**: Each gets its own element file at `{name}-{part}-element.ts`. Element class must be `{Name}{Part}Element` (e.g., `TimeGroupElement`). + +**Part descriptions**: Extracted from JSDoc on the React component export: +```tsx +/** Displays a formatted time value. */ +export const Value = ...; +``` + +## JSDoc Extraction + +- **Data attribute descriptions**: From JSDoc comments on each property in the data-attrs export object +- **Part descriptions**: From JSDoc on React component exports in their `.tsx` files +- **Prop/state descriptions**: From JSDoc on interface properties in the core file + +## Common Failures + +The builder fails silently for many issues — data just won't appear in the JSON: + +| Symptom | Cause | +|---------|-------| +| No JSON generated | Core file missing or Props interface not found | +| Empty props | Interface not named `{PascalCase}Props` | +| Empty state | Interface not named `{PascalCase}State` | +| No data attributes | File missing or export not named `{PascalCase}DataAttrs` | +| No HTML tag | Element file missing or no `static tagName` | +| No part descriptions | Missing JSDoc on React component exports | +| Wrong PascalCase | Need a `NAME_OVERRIDES` entry | + +## Validation + +```bash +# Generate JSON +pnpm -F site api-docs + +# Check output +cat site/src/content/generated-api-reference/{name}.json + +# Verify schema +# The builder validates against ComponentApiReferenceSchema before writing. +# Schema errors are logged as errors and cause exit code 1. +``` diff --git a/.claude/skills/api-reference/references/demo-patterns.md b/.claude/skills/api-reference/references/demo-patterns.md new file mode 100644 index 00000000..45d64079 --- /dev/null +++ b/.claude/skills/api-reference/references/demo-patterns.md @@ -0,0 +1,274 @@ +# Demo Patterns + +File structure and conventions for interactive component demos. + +## Directory Structure + +``` +site/src/components/docs/demos/{component}/ +├── html/css/ +│ ├── BasicUsage.astro # Astro wrapper (renders HTML, imports CSS, bundles script) +│ ├── BasicUsage.html # Markup only (no