stitch-kit 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/AGENTS.md +139 -0
  2. package/CHANGELOG.md +86 -0
  3. package/README.md +167 -0
  4. package/agents/stitch-kit.md +93 -0
  5. package/bin/stitch-kit.mjs +430 -0
  6. package/docs/architecture.md +118 -0
  7. package/docs/color-prompt-guide.md +119 -0
  8. package/docs/mcp-naming-convention.md +64 -0
  9. package/docs/mcp-schemas/README.md +130 -0
  10. package/docs/mcp-schemas/apply_design_system.json +36 -0
  11. package/docs/mcp-schemas/create_design_system.json +78 -0
  12. package/docs/mcp-schemas/create_project.json +290 -0
  13. package/docs/mcp-schemas/delete_project.json +20 -0
  14. package/docs/mcp-schemas/edit_screens.json +46 -0
  15. package/docs/mcp-schemas/generate_screen_from_text.json +242 -0
  16. package/docs/mcp-schemas/generate_variants.json +77 -0
  17. package/docs/mcp-schemas/get_project.json +137 -0
  18. package/docs/mcp-schemas/get_screen.json +92 -0
  19. package/docs/mcp-schemas/list_design_systems.json +32 -0
  20. package/docs/mcp-schemas/list_projects.json +136 -0
  21. package/docs/mcp-schemas/list_screens.json +56 -0
  22. package/docs/mcp-schemas/update_design_system.json +32 -0
  23. package/docs/mcp-schemas/upload_screens_from_images.json +52 -0
  24. package/docs/prd-to-stitch-workflow.md +137 -0
  25. package/docs/skills-index.md +108 -0
  26. package/docs/tailwind-reference.md +207 -0
  27. package/package.json +41 -0
  28. package/skills/stitch-a11y/SKILL.md +428 -0
  29. package/skills/stitch-a11y/resources/audit-checklist.md +102 -0
  30. package/skills/stitch-animate/SKILL.md +371 -0
  31. package/skills/stitch-animate/resources/animation-patterns.md +248 -0
  32. package/skills/stitch-design-md/SKILL.md +215 -0
  33. package/skills/stitch-design-md/examples/DESIGN.md +54 -0
  34. package/skills/stitch-design-md/examples/usage.md +67 -0
  35. package/skills/stitch-design-md/scripts/fetch-stitch.sh +35 -0
  36. package/skills/stitch-design-system/SKILL.md +314 -0
  37. package/skills/stitch-design-system/resources/tokens-template.css +237 -0
  38. package/skills/stitch-html-components/SKILL.md +344 -0
  39. package/skills/stitch-html-components/resources/architecture-checklist.md +74 -0
  40. package/skills/stitch-html-components/scripts/fetch-stitch.sh +45 -0
  41. package/skills/stitch-loop/SKILL.md +183 -0
  42. package/skills/stitch-loop/examples/SITE.md +39 -0
  43. package/skills/stitch-loop/examples/next-prompt.md +24 -0
  44. package/skills/stitch-loop/examples/usage.md +77 -0
  45. package/skills/stitch-mcp-apply-design-system/SKILL.md +82 -0
  46. package/skills/stitch-mcp-create-design-system/SKILL.md +117 -0
  47. package/skills/stitch-mcp-create-project/SKILL.md +77 -0
  48. package/skills/stitch-mcp-delete-project/SKILL.md +62 -0
  49. package/skills/stitch-mcp-edit-screens/SKILL.md +121 -0
  50. package/skills/stitch-mcp-generate-screen-from-text/SKILL.md +102 -0
  51. package/skills/stitch-mcp-generate-screen-from-text/examples/desktop.md +53 -0
  52. package/skills/stitch-mcp-generate-screen-from-text/examples/mobile.md +71 -0
  53. package/skills/stitch-mcp-generate-variants/SKILL.md +124 -0
  54. package/skills/stitch-mcp-get-project/SKILL.md +67 -0
  55. package/skills/stitch-mcp-get-screen/SKILL.md +117 -0
  56. package/skills/stitch-mcp-get-screen/scripts/fetch-stitch.sh +35 -0
  57. package/skills/stitch-mcp-list-design-systems/SKILL.md +84 -0
  58. package/skills/stitch-mcp-list-projects/SKILL.md +77 -0
  59. package/skills/stitch-mcp-list-screens/SKILL.md +69 -0
  60. package/skills/stitch-mcp-update-design-system/SKILL.md +82 -0
  61. package/skills/stitch-mcp-upload-screens-from-images/SKILL.md +95 -0
  62. package/skills/stitch-mcp-upload-screens-from-images/scripts/encode-image.sh +43 -0
  63. package/skills/stitch-nextjs-components/SKILL.md +181 -0
  64. package/skills/stitch-nextjs-components/resources/architecture-checklist.md +65 -0
  65. package/skills/stitch-nextjs-components/resources/component-template.tsx +101 -0
  66. package/skills/stitch-nextjs-components/scripts/fetch-stitch.sh +45 -0
  67. package/skills/stitch-orchestrator/SKILL.md +337 -0
  68. package/skills/stitch-orchestrator/examples/workflow.md +173 -0
  69. package/skills/stitch-react-components/SKILL.md +236 -0
  70. package/skills/stitch-react-components/references/tailwind-to-react.md +117 -0
  71. package/skills/stitch-react-components/resources/architecture-checklist.md +34 -0
  72. package/skills/stitch-react-components/resources/component-template.tsx +35 -0
  73. package/skills/stitch-react-components/scripts/fetch-stitch.sh +35 -0
  74. package/skills/stitch-react-native-components/SKILL.md +333 -0
  75. package/skills/stitch-react-native-components/resources/architecture-checklist.md +74 -0
  76. package/skills/stitch-react-native-components/resources/component-template.tsx +104 -0
  77. package/skills/stitch-react-native-components/scripts/fetch-stitch.sh +45 -0
  78. package/skills/stitch-remotion/SKILL.md +280 -0
  79. package/skills/stitch-setup/SKILL.md +183 -0
  80. package/skills/stitch-shadcn-ui/SKILL.md +255 -0
  81. package/skills/stitch-skill-creator/SKILL.md +257 -0
  82. package/skills/stitch-skill-creator/references/output-patterns.md +71 -0
  83. package/skills/stitch-skill-creator/scripts/init_stitch_skill.py +229 -0
  84. package/skills/stitch-svelte-components/SKILL.md +282 -0
  85. package/skills/stitch-svelte-components/resources/architecture-checklist.md +62 -0
  86. package/skills/stitch-svelte-components/resources/component-template.svelte +193 -0
  87. package/skills/stitch-svelte-components/scripts/fetch-stitch.sh +36 -0
  88. package/skills/stitch-swiftui-components/SKILL.md +424 -0
  89. package/skills/stitch-swiftui-components/resources/architecture-checklist.md +83 -0
  90. package/skills/stitch-swiftui-components/resources/component-template.swift +131 -0
  91. package/skills/stitch-swiftui-components/resources/layout-mapping.md +155 -0
  92. package/skills/stitch-swiftui-components/scripts/fetch-stitch.sh +45 -0
  93. package/skills/stitch-ued-guide/SKILL.md +124 -0
  94. package/skills/stitch-ui-design-spec-generator/SKILL.md +115 -0
  95. package/skills/stitch-ui-design-spec-generator/examples/usage.md +79 -0
  96. package/skills/stitch-ui-design-variants/SKILL.md +127 -0
  97. package/skills/stitch-ui-prompt-architect/SKILL.md +196 -0
  98. package/skills/stitch-ui-prompt-architect/references/KEYWORDS.md +170 -0
@@ -0,0 +1,207 @@
1
+ # Tailwind Utility Reference for Stitch Conversions
2
+
3
+ Stitch exports **Tailwind-based HTML**. When converting to a target framework, map Tailwind utilities to the framework's native patterns — do not copy class names verbatim into non-Tailwind projects.
4
+
5
+ This is the Tailwind-side lookup. Framework-specific mappings live in each skill's `resources/` directory.
6
+
7
+ ---
8
+
9
+ ## Scale quick reference
10
+
11
+ Default spacing scale: `1` unit = `0.25rem` = `4px`
12
+
13
+ | Tailwind | px | rem |
14
+ |----------|----|-----|
15
+ | `p-1` | 4px | 0.25rem |
16
+ | `p-2` | 8px | 0.5rem |
17
+ | `p-3` | 12px | 0.75rem |
18
+ | `p-4` | 16px | 1rem |
19
+ | `p-5` | 20px | 1.25rem |
20
+ | `p-6` | 24px | 1.5rem |
21
+ | `p-8` | 32px | 2rem |
22
+ | `p-10` | 40px | 2.5rem |
23
+ | `p-12` | 48px | 3rem |
24
+ | `p-16` | 64px | 4rem |
25
+
26
+ Same scale applies to `m-*`, `gap-*`, `space-*`, `w-*`, `h-*`.
27
+
28
+ ---
29
+
30
+ ## Layout
31
+
32
+ | Tailwind class | Meaning |
33
+ |----------------|---------|
34
+ | `flex` | `display: flex` |
35
+ | `flex-col` | `flex-direction: column` |
36
+ | `flex-row` | `flex-direction: row` |
37
+ | `flex-wrap` | `flex-wrap: wrap` |
38
+ | `items-center` | `align-items: center` |
39
+ | `items-start` | `align-items: flex-start` |
40
+ | `items-end` | `align-items: flex-end` |
41
+ | `justify-center` | `justify-content: center` |
42
+ | `justify-between` | `justify-content: space-between` |
43
+ | `justify-around` | `justify-content: space-around` |
44
+ | `justify-end` | `justify-content: flex-end` |
45
+ | `grid` | `display: grid` |
46
+ | `grid-cols-2` | `grid-template-columns: repeat(2, 1fr)` |
47
+ | `grid-cols-3` | `grid-template-columns: repeat(3, 1fr)` |
48
+ | `gap-4` | `gap: 16px` |
49
+ | `absolute` | `position: absolute` |
50
+ | `relative` | `position: relative` |
51
+ | `fixed` | `position: fixed` |
52
+ | `sticky` | `position: sticky` |
53
+ | `inset-0` | `top:0; right:0; bottom:0; left:0` |
54
+ | `z-10` | `z-index: 10` |
55
+ | `overflow-hidden` | `overflow: hidden` |
56
+ | `overflow-y-scroll` | `overflow-y: scroll` |
57
+
58
+ ---
59
+
60
+ ## Sizing
61
+
62
+ | Tailwind | CSS equivalent |
63
+ |----------|----------------|
64
+ | `w-full` | `width: 100%` |
65
+ | `w-screen` | `width: 100vw` |
66
+ | `w-1/2` | `width: 50%` |
67
+ | `w-1/3` | `width: 33.333%` |
68
+ | `w-auto` | `width: auto` |
69
+ | `w-fit` | `width: fit-content` |
70
+ | `h-full` | `height: 100%` |
71
+ | `h-screen` | `height: 100vh` |
72
+ | `h-auto` | `height: auto` |
73
+ | `min-h-screen` | `min-height: 100vh` |
74
+ | `min-h-[44px]` | `min-height: 44px` (touch target) |
75
+ | `max-w-xs` | `max-width: 320px` |
76
+ | `max-w-sm` | `max-width: 384px` |
77
+ | `max-w-md` | `max-width: 448px` |
78
+ | `max-w-lg` | `max-width: 512px` |
79
+ | `max-w-xl` | `max-width: 576px` |
80
+ | `max-w-2xl` | `max-width: 672px` |
81
+ | `max-w-7xl` | `max-width: 1280px` |
82
+
83
+ ---
84
+
85
+ ## Typography
86
+
87
+ | Tailwind | Size / weight |
88
+ |----------|---------------|
89
+ | `text-xs` | 12px |
90
+ | `text-sm` | 14px |
91
+ | `text-base` | 16px |
92
+ | `text-lg` | 18px |
93
+ | `text-xl` | 20px |
94
+ | `text-2xl` | 24px |
95
+ | `text-3xl` | 30px |
96
+ | `text-4xl` | 36px |
97
+ | `font-normal` | weight 400 |
98
+ | `font-medium` | weight 500 |
99
+ | `font-semibold` | weight 600 |
100
+ | `font-bold` | weight 700 |
101
+ | `leading-tight` | line-height 1.25 |
102
+ | `leading-normal` | line-height 1.5 |
103
+ | `leading-relaxed` | line-height 1.625 |
104
+ | `tracking-tight` | letter-spacing -0.025em |
105
+ | `tracking-wide` | letter-spacing 0.025em |
106
+ | `truncate` | `overflow: hidden; text-overflow: ellipsis; white-space: nowrap` |
107
+ | `line-clamp-2` | clamp to 2 lines |
108
+ | `text-left` | `text-align: left` |
109
+ | `text-center` | `text-align: center` |
110
+
111
+ ---
112
+
113
+ ## Colors (Stitch custom tokens)
114
+
115
+ Stitch extends Tailwind with custom theme keys. These appear in the HTML as classes like `bg-primary`, `text-primary`, `border-[var(--color-border)]`.
116
+
117
+ | Stitch class / token | Likely semantic role |
118
+ |----------------------|---------------------|
119
+ | `bg-primary` / `--color-primary` | Brand primary color |
120
+ | `text-primary` | Primary foreground text |
121
+ | `bg-background` / `--color-background` | Page background |
122
+ | `bg-surface` / `--color-surface` | Card / panel background |
123
+ | `bg-card-light` / `bg-card-dark` | Card background (theme-specific) |
124
+ | `border-[var(--color-border)]` | Default border color |
125
+ | `text-muted` / `--color-text-muted` | Secondary / muted text |
126
+ | `shadow-soft` / `shadow-floating` | Custom shadow values |
127
+
128
+ When converting, map these to:
129
+ - **CSS variables** (HTML, Next.js) — keep as `var(--color-primary)` etc.
130
+ - **ThemeTokens struct** (SwiftUI) — `theme.primary`, `theme.surface`
131
+ - **useTheme() hook** (React Native) — `theme.primary`, `theme.surface`
132
+ - **Tailwind theme extension** (Next.js + Tailwind) — add to `tailwind.config.js`
133
+
134
+ ---
135
+
136
+ ## Border radius
137
+
138
+ | Tailwind | Radius |
139
+ |----------|--------|
140
+ | `rounded-sm` | 2px |
141
+ | `rounded` / `rounded-md` | 6–8px |
142
+ | `rounded-lg` | 12px |
143
+ | `rounded-xl` | 16px |
144
+ | `rounded-2xl` | 24px |
145
+ | `rounded-full` | 9999px (pill / circle) |
146
+ | `rounded-none` | 0px |
147
+
148
+ ---
149
+
150
+ ## Backgrounds & effects
151
+
152
+ | Tailwind | CSS |
153
+ |----------|-----|
154
+ | `bg-transparent` | `background: transparent` |
155
+ | `opacity-50` | `opacity: 0.5` |
156
+ | `shadow-sm` | small drop shadow |
157
+ | `shadow-md` | medium drop shadow |
158
+ | `shadow-lg` | large drop shadow |
159
+ | `shadow-none` | no shadow |
160
+ | `backdrop-blur-sm` | `backdrop-filter: blur(4px)` |
161
+ | `backdrop-blur-md` | `backdrop-filter: blur(12px)` |
162
+
163
+ ---
164
+
165
+ ## Dark mode
166
+
167
+ Stitch uses the `dark:` prefix. Classes like `dark:bg-gray-800` override the light mode value.
168
+
169
+ In conversions:
170
+ - **CSS variables approach** (Next.js, Svelte, HTML): map to `.dark` selector or `[data-theme="dark"]`
171
+ - **`prefers-color-scheme`**: use `@media (prefers-color-scheme: dark)` for HTML/CSS
172
+ - **React Native**: `useColorScheme()` → select `darkTokens` vs. `lightTokens`
173
+ - **SwiftUI**: `@Environment(\.colorScheme)` → select `ThemeTokens.dark` vs. `.light`
174
+
175
+ ---
176
+
177
+ ## State variants
178
+
179
+ | Tailwind prefix | When it applies |
180
+ |-----------------|----------------|
181
+ | `hover:` | Mouse hover |
182
+ | `focus:` | Keyboard / programmatic focus |
183
+ | `focus-visible:` | Focus only from keyboard (not click) |
184
+ | `active:` | While being pressed |
185
+ | `disabled:` | Element is disabled |
186
+ | `sm:` | ≥ 640px viewport |
187
+ | `md:` | ≥ 768px viewport |
188
+ | `lg:` | ≥ 1024px viewport |
189
+ | `xl:` | ≥ 1280px viewport |
190
+ | `dark:` | Dark color scheme |
191
+
192
+ ---
193
+
194
+ ## Transitions & animation
195
+
196
+ | Tailwind | CSS |
197
+ |----------|-----|
198
+ | `transition` | `transition: all 150ms cubic-bezier(...)` |
199
+ | `transition-colors` | transition only color properties |
200
+ | `duration-150` | 150ms |
201
+ | `duration-300` | 300ms |
202
+ | `ease-in-out` | `animation-timing-function: ease-in-out` |
203
+ | `animate-spin` | infinite rotation |
204
+ | `animate-pulse` | opacity pulse |
205
+ | `animate-bounce` | bounce |
206
+
207
+ For production animations, use `stitch-animate` instead of raw Tailwind animation utilities.
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "stitch-kit",
3
+ "version": "1.5.0",
4
+ "description": "AI UI design to production code — Stitch MCP skills for Claude Code and Codex CLI. Generates screens, iterates designs, extracts tokens, converts to Next.js, Svelte, React, React Native, SwiftUI, or HTML.",
5
+ "bin": {
6
+ "stitch-kit": "./bin/stitch-kit.mjs"
7
+ },
8
+ "type": "module",
9
+ "files": [
10
+ "bin/",
11
+ "skills/",
12
+ "agents/",
13
+ "docs/",
14
+ "scripts/",
15
+ "AGENTS.md",
16
+ "README.md",
17
+ "CHANGELOG.md",
18
+ "LICENSE"
19
+ ],
20
+ "keywords": [
21
+ "stitch",
22
+ "ui-design",
23
+ "text-to-ui",
24
+ "claude-code",
25
+ "codex-cli",
26
+ "mcp",
27
+ "design-to-code",
28
+ "nextjs",
29
+ "svelte",
30
+ "react-native",
31
+ "swiftui",
32
+ "agent-skills"
33
+ ],
34
+ "author": "gabelul",
35
+ "license": "Apache-2.0",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/gabelul/stitch-kit.git"
39
+ },
40
+ "homepage": "https://github.com/gabelul/stitch-kit#readme"
41
+ }
@@ -0,0 +1,428 @@
1
+ ---
2
+ name: stitch-a11y
3
+ description: Audits Stitch-generated components for WCAG 2.1 AA accessibility issues and applies fixes — semantic HTML, ARIA attributes, keyboard navigation, focus management, and screen reader support.
4
+ allowed-tools:
5
+ - "Read"
6
+ - "Write"
7
+ - "Bash"
8
+ ---
9
+
10
+ # Stitch Accessibility Audit & Fix
11
+
12
+ You are an accessibility engineer. You audit components generated from Stitch designs, identify WCAG 2.1 AA violations, and apply fixes directly to the source files. You don't just report issues — you fix them.
13
+
14
+ **Run this skill AFTER** component generation. Components should be working before you audit them.
15
+
16
+ ## When to use this skill
17
+
18
+ Use this skill when:
19
+ - Components are generated and working, and need accessibility review before shipping
20
+ - The design has complex interactive patterns (modals, dropdowns, tab panels, accordions, carousels)
21
+ - The user mentions "accessibility", "a11y", "WCAG", "screen reader", "keyboard navigation"
22
+ - Preparing for a production launch or accessibility audit
23
+
24
+ ## Step 1: Discover components to audit
25
+
26
+ Read the project file structure to find all component files:
27
+ ```bash
28
+ # Next.js / React
29
+ find src -name "*.tsx" -not -path "*/node_modules/*"
30
+
31
+ # SvelteKit
32
+ find src -name "*.svelte" -not -path "*/node_modules/*"
33
+ ```
34
+
35
+ Read each component file before auditing. Focus your energy on interactive components — static content needs less attention than forms, navigation, modals, and dropdowns.
36
+
37
+ ## Step 2: The audit — 6 categories
38
+
39
+ Work through each category systematically for every component.
40
+
41
+ ### Category 1: Semantic HTML
42
+
43
+ **Violations to find:**
44
+ - `<div>` or `<span>` used for navigation, headers, footers, main content, articles, sections
45
+ - `<div onClick>` instead of `<button>` or `<a>`
46
+ - Heading hierarchy out of order (h3 before h2, skipping levels)
47
+ - Tables used for layout (not data)
48
+ - Lists rendered as plain `<div>` elements
49
+
50
+ **Fixes:**
51
+ ```tsx
52
+ // ❌ Wrong
53
+ <div className="nav">
54
+ <div onClick={goHome}>Home</div>
55
+ </div>
56
+
57
+ // ✅ Fixed
58
+ <nav aria-label="Main navigation">
59
+ <a href="/">Home</a>
60
+ </nav>
61
+
62
+ // ❌ Wrong — div button
63
+ <div className="btn" onClick={handleClick}>Submit</div>
64
+
65
+ // ✅ Fixed — real button
66
+ <button type="button" onClick={handleClick}>Submit</button>
67
+
68
+ // ❌ Wrong — visual list as divs
69
+ <div className="menu">
70
+ <div>Item 1</div>
71
+ <div>Item 2</div>
72
+ </div>
73
+
74
+ // ✅ Fixed
75
+ <ul role="list">
76
+ <li>Item 1</li>
77
+ <li>Item 2</li>
78
+ </ul>
79
+ ```
80
+
81
+ ### Category 2: ARIA attributes
82
+
83
+ Only add ARIA where semantic HTML doesn't provide sufficient information. Remember: **no ARIA is better than bad ARIA.**
84
+
85
+ **Violations to find:**
86
+ - Icon-only buttons with no accessible name
87
+ - Multiple `<nav>` landmarks with no `aria-label`
88
+ - Multiple `<main>` elements
89
+ - Status/live regions that update dynamically but have no `aria-live`
90
+ - Interactive elements missing `aria-expanded`, `aria-haspopup`, `aria-controls`
91
+
92
+ **Fixes:**
93
+ ```tsx
94
+ // Icon-only button
95
+ <button aria-label="Close dialog" type="button">
96
+ <XIcon aria-hidden="true" />
97
+ </button>
98
+
99
+ // Multiple nav regions
100
+ <nav aria-label="Main navigation">...</nav>
101
+ <nav aria-label="Breadcrumb">...</nav>
102
+ <nav aria-label="Pagination">...</nav>
103
+
104
+ // Dropdown toggle
105
+ <button
106
+ aria-expanded={isOpen}
107
+ aria-haspopup="menu"
108
+ aria-controls="user-menu"
109
+ >
110
+ Account
111
+ </button>
112
+ <ul id="user-menu" role="menu" hidden={!isOpen}>
113
+ <li role="menuitem"><a href="/profile">Profile</a></li>
114
+ </ul>
115
+
116
+ // Live status region
117
+ <div aria-live="polite" aria-atomic="true" className="sr-only">
118
+ {statusMessage}
119
+ </div>
120
+ ```
121
+
122
+ ### Category 3: Keyboard navigation
123
+
124
+ Every interactive element must be operable by keyboard. Test this mental model: Tab through the page — can you reach and activate every action?
125
+
126
+ **Violations to find:**
127
+ - Custom interactive elements that don't receive Tab focus
128
+ - `tabIndex={-1}` used where focus should be reachable
129
+ - `tabIndex={1}` or higher (breaks natural tab order)
130
+ - Modal open — focus not moved into modal
131
+ - Modal closed — focus not returned to trigger
132
+ - Dropdown closed with Escape — focus not returned
133
+
134
+ **Fixes:**
135
+ ```tsx
136
+ // Focus management for modal — React
137
+ import { useEffect, useRef } from 'react'
138
+
139
+ export function Modal({ isOpen, onClose, children }: ModalProps) {
140
+ const modalRef = useRef<HTMLDivElement>(null)
141
+ const triggerRef = useRef<HTMLButtonElement>(null)
142
+
143
+ useEffect(() => {
144
+ if (isOpen) {
145
+ // Move focus into modal when it opens
146
+ modalRef.current?.focus()
147
+ }
148
+ }, [isOpen])
149
+
150
+ function handleClose() {
151
+ onClose()
152
+ // Return focus to trigger when modal closes
153
+ triggerRef.current?.focus()
154
+ }
155
+
156
+ return (
157
+ <>
158
+ <button ref={triggerRef} onClick={() => setIsOpen(true)}>
159
+ Open Modal
160
+ </button>
161
+ {isOpen && (
162
+ <div
163
+ ref={modalRef}
164
+ role="dialog"
165
+ aria-modal="true"
166
+ aria-labelledby="modal-title"
167
+ tabIndex={-1} /* Makes div focusable without entering tab order */
168
+ >
169
+ <h2 id="modal-title">Modal Title</h2>
170
+ {children}
171
+ <button onClick={handleClose}>Close</button>
172
+ </div>
173
+ )}
174
+ </>
175
+ )
176
+ }
177
+
178
+ // Keyboard handler for custom interactive elements
179
+ <div
180
+ role="button"
181
+ tabIndex={0}
182
+ onClick={handleAction}
183
+ onKeyDown={(e) => {
184
+ if (e.key === 'Enter' || e.key === ' ') {
185
+ e.preventDefault()
186
+ handleAction()
187
+ }
188
+ }}
189
+ >
190
+ Custom button behavior
191
+ </div>
192
+ ```
193
+
194
+ ```svelte
195
+ <!-- Focus management in Svelte -->
196
+ <script lang="ts">
197
+ let dialogEl = $state<HTMLDialogElement>()
198
+ let triggerEl = $state<HTMLButtonElement>()
199
+ let isOpen = $state(false)
200
+
201
+ function openDialog() {
202
+ isOpen = true
203
+ // tick() ensures DOM is updated before focusing
204
+ tick().then(() => dialogEl?.focus())
205
+ }
206
+
207
+ function closeDialog() {
208
+ isOpen = false
209
+ triggerEl?.focus() // Return focus to trigger
210
+ }
211
+ </script>
212
+
213
+ <button bind:this={triggerEl} onclick={openDialog}>Open</button>
214
+
215
+ {#if isOpen}
216
+ <dialog
217
+ bind:this={dialogEl}
218
+ tabindex="-1"
219
+ aria-modal="true"
220
+ onkeydown={(e) => e.key === 'Escape' && closeDialog()}
221
+ >
222
+ <button onclick={closeDialog}>Close</button>
223
+ </dialog>
224
+ {/if}
225
+ ```
226
+
227
+ ### Category 4: Focus visibility
228
+
229
+ Every interactive element must have a visible focus indicator. Never remove the focus ring without providing an equally visible replacement.
230
+
231
+ **Violations to find:**
232
+ - `outline: none` or `outline: 0` without a custom focus style
233
+ - `.focus:outline-none` in Tailwind without `focus-visible:ring-*`
234
+ - Focus styles that only appear on click, not keyboard focus
235
+
236
+ **Fixes:**
237
+
238
+ In CSS:
239
+ ```css
240
+ /* Never this */
241
+ *:focus { outline: none; }
242
+
243
+ /* Always this — uses :focus-visible to show only on keyboard focus */
244
+ *:focus-visible {
245
+ outline: 2px solid var(--color-primary);
246
+ outline-offset: 2px;
247
+ border-radius: 2px;
248
+ }
249
+ ```
250
+
251
+ In Tailwind:
252
+ ```tsx
253
+ // ❌ Wrong
254
+ <button className="focus:outline-none">
255
+
256
+ // ✅ Fixed
257
+ <button className="focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2">
258
+ ```
259
+
260
+ ### Category 5: Images and media
261
+
262
+ **Violations to find:**
263
+ - `<img>` or `<Image>` without `alt` attribute
264
+ - Meaningful images with `alt=""`
265
+ - Decorative images with descriptive alt text (adds noise to screen readers)
266
+ - Icons without accessible labels when used as interactive elements
267
+ - Video without captions
268
+
269
+ **Fixes:**
270
+ ```tsx
271
+ // Meaningful image
272
+ <Image src="/hero.jpg" alt="Team members collaborating at a whiteboard in a modern office" />
273
+
274
+ // Decorative image — empty alt so screen readers skip it
275
+ <Image src="/bg-pattern.svg" alt="" aria-hidden="true" />
276
+
277
+ // Icon in a button — hide icon, label the button
278
+ <button aria-label="Delete item">
279
+ <TrashIcon aria-hidden="true" />
280
+ </button>
281
+
282
+ // Icon with adjacent text — hide the icon (it's redundant)
283
+ <button>
284
+ <SaveIcon aria-hidden="true" />
285
+ <span>Save changes</span>
286
+ </button>
287
+ ```
288
+
289
+ ### Category 6: Color and contrast
290
+
291
+ Check these without automated tools by reasoning about the design:
292
+
293
+ **Violations to find:**
294
+ - Muted text (`--color-text-muted`) on a muted background (`--color-surface`) — often fails 4.5:1
295
+ - Primary color on white at small sizes — verify it passes 4.5:1
296
+ - Disabled state text that's too light to read even as a hint
297
+ - Relying on color alone to convey meaning (error states, required fields)
298
+
299
+ **Fixes:**
300
+ ```tsx
301
+ // Add non-color indicator for errors
302
+ <input
303
+ aria-invalid={hasError}
304
+ aria-describedby={hasError ? 'email-error' : undefined}
305
+ className={hasError ? 'border-error' : 'border-border'}
306
+ />
307
+ {hasError && (
308
+ <p id="email-error" role="alert" className="text-error">
309
+ {/* Icon + text — not color alone */}
310
+ <AlertIcon aria-hidden="true" />
311
+ Please enter a valid email address
312
+ </p>
313
+ )}
314
+
315
+ // Required field indicator
316
+ <label>
317
+ Email
318
+ <span aria-hidden="true" className="text-error"> *</span>
319
+ <span className="sr-only">(required)</span>
320
+ </label>
321
+ ```
322
+
323
+ ## Step 3: The `sr-only` utility class
324
+
325
+ Add this to your global CSS if it's not there already. You'll use it frequently:
326
+
327
+ ```css
328
+ /* Visually hidden, but readable by screen readers */
329
+ .sr-only {
330
+ position: absolute;
331
+ width: 1px;
332
+ height: 1px;
333
+ padding: 0;
334
+ margin: -1px;
335
+ overflow: hidden;
336
+ clip: rect(0, 0, 0, 0);
337
+ white-space: nowrap;
338
+ border-width: 0;
339
+ }
340
+
341
+ /* Skip link — visible on focus for keyboard users */
342
+ .skip-link {
343
+ position: absolute;
344
+ left: -9999px;
345
+ top: auto;
346
+ width: 1px;
347
+ height: 1px;
348
+ overflow: hidden;
349
+ }
350
+ .skip-link:focus {
351
+ position: fixed;
352
+ top: 1rem;
353
+ left: 1rem;
354
+ width: auto;
355
+ height: auto;
356
+ padding: 0.5rem 1rem;
357
+ background: var(--color-primary);
358
+ color: var(--color-primary-fg);
359
+ border-radius: var(--radius-md);
360
+ font-weight: 600;
361
+ z-index: 9999;
362
+ }
363
+ ```
364
+
365
+ ## Step 4: Skip navigation link
366
+
367
+ Add a skip link as the first element in every page layout. This lets keyboard users jump past the navigation:
368
+
369
+ ```tsx
370
+ // app/layout.tsx or +layout.svelte — first child of <body>
371
+ <a href="#main-content" className="skip-link">
372
+ Skip to main content
373
+ </a>
374
+
375
+ // The target
376
+ <main id="main-content" tabIndex={-1}>
377
+ {children}
378
+ </main>
379
+ ```
380
+
381
+ ## Step 5: Generate the audit report
382
+
383
+ After fixing, create `accessibility-audit.md` summarizing what was found and fixed:
384
+
385
+ ```markdown
386
+ # Accessibility Audit Report
387
+
388
+ **Date:** [date]
389
+ **WCAG Target:** 2.1 AA
390
+ **Components audited:** [list]
391
+
392
+ ## Issues Found & Fixed
393
+
394
+ ### Critical (would block screen reader users)
395
+ - [Component]: [issue] → [fix applied]
396
+
397
+ ### Important (keyboard navigation issues)
398
+ - [Component]: [issue] → [fix applied]
399
+
400
+ ### Minor (improvements to quality of life)
401
+ - [Component]: [issue] → [fix applied]
402
+
403
+ ## Remaining Recommendations
404
+
405
+ [Any issues that require design changes or user testing to resolve]
406
+
407
+ ## How to test
408
+
409
+ 1. Tab through the entire page — every interactive element should be reachable
410
+ 2. Activate with Enter/Space — all buttons and links should work
411
+ 3. Test with VoiceOver (Mac) or NVDA (Windows) — key flows should be narrated correctly
412
+ 4. Browser DevTools → Rendering → Emulate prefers-reduced-motion → Verify animations stop
413
+ 5. axe DevTools extension for automated checks
414
+ ```
415
+
416
+ ## Troubleshooting
417
+
418
+ | Issue | Fix |
419
+ |-------|-----|
420
+ | `aria-labelledby` points to wrong ID | Ensure IDs are unique across the page |
421
+ | Focus trap locking keyboard in modal | Implement proper Tab/Shift+Tab cycling within modal bounds |
422
+ | Screen reader announcing redundant info | Add `aria-hidden="true"` to decorative elements |
423
+ | Multiple violations in one component | Fix semantic HTML first — ARIA issues often cascade from it |
424
+ | Skip link not showing | Ensure `:focus` state overrides the off-screen positioning |
425
+
426
+ ## References
427
+
428
+ - `resources/audit-checklist.md` — Quick reference checklist for pre-ship review