@compa11y/web 0.1.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.
- package/LICENSE +21 -0
- package/README.md +249 -0
- package/dist/compa11y.iife.js +533 -0
- package/dist/compa11y.iife.js.map +1 -0
- package/dist/compa11y.js +1352 -0
- package/dist/compa11y.js.map +1 -0
- package/dist/compa11y.umd.cjs +533 -0
- package/dist/compa11y.umd.cjs.map +1 -0
- package/dist/components/combobox.d.ts +51 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/dialog.d.ts +36 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.test.d.ts +2 -0
- package/dist/components/dialog.test.d.ts.map +1 -0
- package/dist/components/menu.d.ts +40 -0
- package/dist/components/menu.d.ts.map +1 -0
- package/dist/components/menu.test.d.ts +2 -0
- package/dist/components/menu.test.d.ts.map +1 -0
- package/dist/components/switch.d.ts +68 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/tabs.d.ts +35 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.test.d.ts +2 -0
- package/dist/components/tabs.test.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/utils/base-element.d.ts +61 -0
- package/dist/utils/base-element.d.ts.map +1 -0
- package/dist/utils/styles.d.ts +31 -0
- package/dist/utils/styles.d.ts.map +1 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ivan Trajkovski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# @compa11y/web
|
|
2
|
+
|
|
3
|
+
Accessible Web Components for any HTML page. No framework required.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### CDN (Recommended for quick start)
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script src="https://unpkg.com/@compa11y/web"></script>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### npm
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @compa11y/web
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import '@compa11y/web';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Components
|
|
24
|
+
|
|
25
|
+
### Dialog
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<button id="open-dialog">Open Dialog</button>
|
|
29
|
+
|
|
30
|
+
<a11y-dialog trigger="#open-dialog">
|
|
31
|
+
<h2 slot="title">Confirm Action</h2>
|
|
32
|
+
<p slot="description">Are you sure you want to proceed?</p>
|
|
33
|
+
|
|
34
|
+
<p>This action cannot be undone.</p>
|
|
35
|
+
|
|
36
|
+
<div slot="actions">
|
|
37
|
+
<button onclick="this.closest('a11y-dialog').close()">Cancel</button>
|
|
38
|
+
<button onclick="handleConfirm()">Confirm</button>
|
|
39
|
+
</div>
|
|
40
|
+
</a11y-dialog>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Attributes
|
|
44
|
+
|
|
45
|
+
| Attribute | Description | Default |
|
|
46
|
+
| ------------------------ | ------------------------------- | ------- |
|
|
47
|
+
| `trigger` | CSS selector for trigger button | — |
|
|
48
|
+
| `open` | Whether dialog is open | `false` |
|
|
49
|
+
| `close-on-outside-click` | Close when clicking overlay | `true` |
|
|
50
|
+
| `close-on-escape` | Close when pressing Escape | `true` |
|
|
51
|
+
|
|
52
|
+
#### Slots
|
|
53
|
+
|
|
54
|
+
| Slot | Description |
|
|
55
|
+
| ------------- | ----------------------------------------- |
|
|
56
|
+
| `title` | Dialog title (required for accessibility) |
|
|
57
|
+
| `description` | Optional description |
|
|
58
|
+
| (default) | Dialog content |
|
|
59
|
+
| `actions` | Footer buttons |
|
|
60
|
+
|
|
61
|
+
#### Methods
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
const dialog = document.querySelector('a11y-dialog');
|
|
65
|
+
dialog.show(); // Open
|
|
66
|
+
dialog.close(); // Close
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Events
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
dialog.addEventListener('a11y-dialog-open', () => {});
|
|
73
|
+
dialog.addEventListener('a11y-dialog-close', () => {});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Menu
|
|
77
|
+
|
|
78
|
+
```html
|
|
79
|
+
<a11y-menu>
|
|
80
|
+
<button slot="trigger">Actions ▾</button>
|
|
81
|
+
|
|
82
|
+
<button role="menuitem">Edit</button>
|
|
83
|
+
<button role="menuitem">Duplicate</button>
|
|
84
|
+
<div role="separator"></div>
|
|
85
|
+
<button role="menuitem">Delete</button>
|
|
86
|
+
</a11y-menu>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Attributes
|
|
90
|
+
|
|
91
|
+
| Attribute | Description | Default |
|
|
92
|
+
| --------- | -------------------- | ------- |
|
|
93
|
+
| `open` | Whether menu is open | `false` |
|
|
94
|
+
|
|
95
|
+
#### Methods
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
const menu = document.querySelector('a11y-menu');
|
|
99
|
+
menu.show(); // Open
|
|
100
|
+
menu.close(); // Close
|
|
101
|
+
menu.toggle(); // Toggle
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Events
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
menu.addEventListener('a11y-menu-open', () => {});
|
|
108
|
+
menu.addEventListener('a11y-menu-close', () => {});
|
|
109
|
+
menu.addEventListener('a11y-menu-select', (e) => {
|
|
110
|
+
console.log(e.detail.item);
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Tabs
|
|
115
|
+
|
|
116
|
+
```html
|
|
117
|
+
<a11y-tabs>
|
|
118
|
+
<button role="tab" aria-controls="panel-1">Tab 1</button>
|
|
119
|
+
<button role="tab" aria-controls="panel-2">Tab 2</button>
|
|
120
|
+
<button role="tab" aria-controls="panel-3">Tab 3</button>
|
|
121
|
+
|
|
122
|
+
<div role="tabpanel" id="panel-1">Content 1</div>
|
|
123
|
+
<div role="tabpanel" id="panel-2">Content 2</div>
|
|
124
|
+
<div role="tabpanel" id="panel-3">Content 3</div>
|
|
125
|
+
</a11y-tabs>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Attributes
|
|
129
|
+
|
|
130
|
+
| Attribute | Description | Default |
|
|
131
|
+
| ----------------- | ---------------------------- | ------------ |
|
|
132
|
+
| `orientation` | `horizontal` or `vertical` | `horizontal` |
|
|
133
|
+
| `activation-mode` | `automatic` or `manual` | `automatic` |
|
|
134
|
+
| `selected-index` | Currently selected tab index | `0` |
|
|
135
|
+
|
|
136
|
+
#### Methods
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
const tabs = document.querySelector('a11y-tabs');
|
|
140
|
+
tabs.select(2); // Select by index
|
|
141
|
+
tabs.next(); // Select next tab
|
|
142
|
+
tabs.previous(); // Select previous tab
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Events
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
tabs.addEventListener('a11y-tabs-change', (e) => {
|
|
149
|
+
console.log(e.detail.index, e.detail.tab, e.detail.panel);
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Styling
|
|
154
|
+
|
|
155
|
+
Use CSS custom properties for theming:
|
|
156
|
+
|
|
157
|
+
```css
|
|
158
|
+
/* Dialog */
|
|
159
|
+
a11y-dialog {
|
|
160
|
+
--compa11y-dialog-bg: white;
|
|
161
|
+
--compa11y-dialog-radius: 8px;
|
|
162
|
+
--compa11y-dialog-padding: 1.5rem;
|
|
163
|
+
--compa11y-dialog-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
|
|
164
|
+
--compa11y-dialog-overlay-bg: rgba(0, 0, 0, 0.5);
|
|
165
|
+
--compa11y-dialog-z-index: 9999;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Menu */
|
|
169
|
+
a11y-menu {
|
|
170
|
+
--compa11y-menu-bg: white;
|
|
171
|
+
--compa11y-menu-border: 1px solid #e0e0e0;
|
|
172
|
+
--compa11y-menu-radius: 4px;
|
|
173
|
+
--compa11y-menu-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
174
|
+
--compa11y-menu-item-hover-bg: #f5f5f5;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Tabs */
|
|
178
|
+
a11y-tabs {
|
|
179
|
+
--compa11y-tabs-border: 1px solid #e0e0e0;
|
|
180
|
+
--compa11y-tab-padding: 0.75rem 1rem;
|
|
181
|
+
--compa11y-tab-color: #666;
|
|
182
|
+
--compa11y-tab-active-color: #0066cc;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* Focus ring */
|
|
186
|
+
:root {
|
|
187
|
+
--compa11y-focus-color: #0066cc;
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Use `::part()` for Shadow DOM styling:
|
|
192
|
+
|
|
193
|
+
```css
|
|
194
|
+
a11y-dialog::part(overlay) {
|
|
195
|
+
backdrop-filter: blur(4px);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
a11y-dialog::part(dialog) {
|
|
199
|
+
max-width: 600px;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
a11y-dialog::part(close-button) {
|
|
203
|
+
color: #666;
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## JavaScript API
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
import {
|
|
211
|
+
// Announcer
|
|
212
|
+
announce,
|
|
213
|
+
announcePolite,
|
|
214
|
+
announceAssertive,
|
|
215
|
+
|
|
216
|
+
// Focus
|
|
217
|
+
createFocusTrap,
|
|
218
|
+
createFocusScope,
|
|
219
|
+
|
|
220
|
+
// Keyboard
|
|
221
|
+
createKeyboardManager,
|
|
222
|
+
KeyboardPatterns,
|
|
223
|
+
|
|
224
|
+
// ARIA
|
|
225
|
+
aria,
|
|
226
|
+
|
|
227
|
+
// Platform
|
|
228
|
+
prefersReducedMotion,
|
|
229
|
+
prefersHighContrast,
|
|
230
|
+
} from '@compa11y/web';
|
|
231
|
+
|
|
232
|
+
// Make announcements
|
|
233
|
+
announcePolite('Item added to cart');
|
|
234
|
+
|
|
235
|
+
// Check preferences
|
|
236
|
+
if (prefersReducedMotion()) {
|
|
237
|
+
// Disable animations
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Browser Support
|
|
242
|
+
|
|
243
|
+
- Chrome/Edge 88+
|
|
244
|
+
- Firefox 78+
|
|
245
|
+
- Safari 14+
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT
|