@compa11y/core 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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +160 -0
  3. package/dist/announcer/index.cjs +49 -0
  4. package/dist/announcer/index.cjs.map +1 -0
  5. package/dist/announcer/index.d.cts +61 -0
  6. package/dist/announcer/index.d.ts +61 -0
  7. package/dist/announcer/index.js +4 -0
  8. package/dist/announcer/index.js.map +1 -0
  9. package/dist/aria/index.cjs +24 -0
  10. package/dist/aria/index.cjs.map +1 -0
  11. package/dist/aria/index.d.cts +176 -0
  12. package/dist/aria/index.d.ts +176 -0
  13. package/dist/aria/index.js +3 -0
  14. package/dist/aria/index.js.map +1 -0
  15. package/dist/chunk-24U5HHMC.js +309 -0
  16. package/dist/chunk-24U5HHMC.js.map +1 -0
  17. package/dist/chunk-2CQOLVQH.js +147 -0
  18. package/dist/chunk-2CQOLVQH.js.map +1 -0
  19. package/dist/chunk-2PUYKF2E.js +631 -0
  20. package/dist/chunk-2PUYKF2E.js.map +1 -0
  21. package/dist/chunk-2WF5Y6D7.js +175 -0
  22. package/dist/chunk-2WF5Y6D7.js.map +1 -0
  23. package/dist/chunk-CQXMBRLD.cjs +657 -0
  24. package/dist/chunk-CQXMBRLD.cjs.map +1 -0
  25. package/dist/chunk-HQOFVJFO.cjs +181 -0
  26. package/dist/chunk-HQOFVJFO.cjs.map +1 -0
  27. package/dist/chunk-NBGFFCIJ.cjs +314 -0
  28. package/dist/chunk-NBGFFCIJ.cjs.map +1 -0
  29. package/dist/chunk-V6TZIZZ4.cjs +158 -0
  30. package/dist/chunk-V6TZIZZ4.cjs.map +1 -0
  31. package/dist/chunk-XEGB27QF.cjs +78 -0
  32. package/dist/chunk-XEGB27QF.cjs.map +1 -0
  33. package/dist/chunk-Z7K2G6FX.js +66 -0
  34. package/dist/chunk-Z7K2G6FX.js.map +1 -0
  35. package/dist/focus/index.cjs +53 -0
  36. package/dist/focus/index.cjs.map +1 -0
  37. package/dist/focus/index.d.cts +139 -0
  38. package/dist/focus/index.d.ts +139 -0
  39. package/dist/focus/index.js +4 -0
  40. package/dist/focus/index.js.map +1 -0
  41. package/dist/index.cjs +573 -0
  42. package/dist/index.cjs.map +1 -0
  43. package/dist/index.d.cts +241 -0
  44. package/dist/index.d.ts +241 -0
  45. package/dist/index.js +343 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/keyboard/index.cjs +28 -0
  48. package/dist/keyboard/index.cjs.map +1 -0
  49. package/dist/keyboard/index.d.cts +102 -0
  50. package/dist/keyboard/index.d.ts +102 -0
  51. package/dist/keyboard/index.js +3 -0
  52. package/dist/keyboard/index.js.map +1 -0
  53. package/dist/types-DDSPmE8m.d.cts +52 -0
  54. package/dist/types-DDSPmE8m.d.ts +52 -0
  55. package/package.json +78 -0
@@ -0,0 +1,241 @@
1
+ import { D as DevWarningHandler, a as DevWarning } from './types-DDSPmE8m.cjs';
2
+ export { A as AnnouncerOptions, b as AriaLivePoliteness, c as AriaRole, F as FocusTrapOptions, d as FocusableElement, K as KeyboardNavigationOptions } from './types-DDSPmE8m.cjs';
3
+ export { FocusScope, FocusScopeOptions, RovingTabindex, RovingTabindexOptions, createFocusScope, createFocusTrap, createRovingTabindex, focusWithVisibleRing, getActiveFocusTrap, getLastFocusSource, hasFocusTrap, hasVisibleFocus, initFocusVisible, isFocusVisible, setFocusVisible } from './focus/index.cjs';
4
+ export { KeyboardHandler, KeyboardHandlers, KeyboardManager, KeyboardManagerOptions, KeyboardPatterns, TypeAhead, createKeyboardManager, createTypeAhead, getKeyCombo, normalizeKey } from './keyboard/index.cjs';
5
+ export { announce, announceAssertive, announceError, announcePolite, announceProgress, announceStatus, clearAnnouncements, createAnnouncer, initAnnouncer, queueAnnouncement } from './announcer/index.cjs';
6
+ export { aria, buildAriaProps, hasAccessibleName, mergeAriaIds } from './aria/index.cjs';
7
+
8
+ /**
9
+ * ID generation utilities for accessible components
10
+ *
11
+ * Generates unique, predictable IDs for ARIA relationships
12
+ */
13
+ /**
14
+ * Generate a unique ID with optional prefix
15
+ */
16
+ declare function generateId(prefix?: string): string;
17
+ /**
18
+ * Generate a set of related IDs for a component
19
+ * Useful for complex components with multiple ARIA relationships
20
+ */
21
+ declare function generateIds<T extends readonly string[]>(parts: T, prefix?: string): Record<T[number], string>;
22
+ /**
23
+ * Reset the ID counter (useful for testing)
24
+ */
25
+ declare function resetIdCounter(): void;
26
+ /**
27
+ * Create a scoped ID generator for a component instance
28
+ */
29
+ declare function createIdScope(componentName: string): {
30
+ id: string;
31
+ generate: (suffix: string) => string;
32
+ generateMultiple: <T extends readonly string[]>(parts: T) => Record<T[number], string>;
33
+ };
34
+
35
+ /**
36
+ * DOM utilities for accessibility
37
+ */
38
+ /**
39
+ * Focusable element selectors
40
+ * Based on WHATWG focus management spec
41
+ */
42
+ declare const FOCUSABLE_SELECTORS: string;
43
+ /**
44
+ * Tabbable element selectors (subset of focusable that can be tabbed to)
45
+ */
46
+ declare const TABBABLE_SELECTORS: string;
47
+ /**
48
+ * Check if an element is visible (not hidden by CSS)
49
+ */
50
+ declare function isVisible(element: Element): boolean;
51
+ /**
52
+ * Check if an element is focusable
53
+ */
54
+ declare function isFocusable(element: Element): boolean;
55
+ /**
56
+ * Check if an element is tabbable (can receive focus via Tab key)
57
+ */
58
+ declare function isTabbable(element: Element): boolean;
59
+ /**
60
+ * Get all focusable elements within a container
61
+ */
62
+ declare function getFocusableElements(container: HTMLElement): HTMLElement[];
63
+ /**
64
+ * Get all tabbable elements within a container (sorted by tabIndex)
65
+ */
66
+ declare function getTabbableElements(container: HTMLElement): HTMLElement[];
67
+ /**
68
+ * Get the first focusable element in a container
69
+ */
70
+ declare function getFirstFocusable(container: HTMLElement): HTMLElement | null;
71
+ /**
72
+ * Get the last focusable element in a container
73
+ */
74
+ declare function getLastFocusable(container: HTMLElement): HTMLElement | null;
75
+ /**
76
+ * Check if an element contains the currently focused element
77
+ */
78
+ declare function containsFocus(container: HTMLElement): boolean;
79
+ /**
80
+ * Get the next focusable element
81
+ */
82
+ declare function getNextFocusable(container: HTMLElement, current: HTMLElement, wrap?: boolean): HTMLElement | null;
83
+ /**
84
+ * Get the previous focusable element
85
+ */
86
+ declare function getPreviousFocusable(container: HTMLElement, current: HTMLElement, wrap?: boolean): HTMLElement | null;
87
+ /**
88
+ * Check if element is within a specific container
89
+ */
90
+ declare function isWithinContainer(element: Element, container: Element): boolean;
91
+ /**
92
+ * Query for an element, supporting various input types
93
+ */
94
+ declare function resolveElement<T extends HTMLElement = HTMLElement>(target: T | string | (() => T | null) | null | undefined, container?: HTMLElement): T | null;
95
+
96
+ /**
97
+ * Platform detection utilities
98
+ *
99
+ * Used for platform-specific accessibility behavior
100
+ */
101
+ /**
102
+ * Check if we're in a browser environment
103
+ */
104
+ declare function isBrowser(): boolean;
105
+ /**
106
+ * Detect if running on macOS
107
+ */
108
+ declare function isMac(): boolean;
109
+ /**
110
+ * Detect if running on iOS
111
+ */
112
+ declare function isIOS(): boolean;
113
+ /**
114
+ * Detect if running on Android
115
+ */
116
+ declare function isAndroid(): boolean;
117
+ /**
118
+ * Detect if running on Windows
119
+ */
120
+ declare function isWindows(): boolean;
121
+ /**
122
+ * Detect if using a touch device
123
+ */
124
+ declare function isTouchDevice(): boolean;
125
+ /**
126
+ * Detect if user prefers reduced motion
127
+ */
128
+ declare function prefersReducedMotion(): boolean;
129
+ /**
130
+ * Detect if user prefers high contrast
131
+ */
132
+ declare function prefersHighContrast(): boolean;
133
+ /**
134
+ * Detect if user prefers dark color scheme
135
+ */
136
+ declare function prefersDarkMode(): boolean;
137
+ /**
138
+ * Get the current screen reader mode (if detectable)
139
+ * Note: This is not 100% reliable and should not be depended upon
140
+ */
141
+ declare function getScreenReaderHints(): {
142
+ possibleScreenReader: boolean;
143
+ forcedColors: boolean;
144
+ };
145
+ /**
146
+ * Create a media query listener with cleanup
147
+ */
148
+ declare function createMediaQueryListener(query: string, callback: (matches: boolean) => void): () => void;
149
+
150
+ /**
151
+ * Developer Warnings System
152
+ *
153
+ * Provides development-time feedback for accessibility issues
154
+ */
155
+
156
+ /**
157
+ * Set a custom warning handler
158
+ */
159
+ declare function setWarningHandler(handler: DevWarningHandler | null): void;
160
+ /**
161
+ * Issue a development warning
162
+ */
163
+ declare function warn(warning: DevWarning): void;
164
+ /**
165
+ * Clear issued warnings (useful for testing)
166
+ */
167
+ declare function clearWarnings(): void;
168
+ /**
169
+ * Pre-built warning checks
170
+ */
171
+ declare const checks: {
172
+ /**
173
+ * Check for missing accessible label
174
+ */
175
+ accessibleLabel(element: HTMLElement | null, component: string, propName?: string): void;
176
+ /**
177
+ * Check for missing required prop
178
+ */
179
+ requiredProp(value: unknown, propName: string, component: string): void;
180
+ /**
181
+ * Check for invalid ARIA role
182
+ */
183
+ validRole(role: string | undefined, component: string, element?: HTMLElement): void;
184
+ /**
185
+ * Check for interactive element without keyboard support
186
+ */
187
+ keyboardAccessible(element: HTMLElement | null, component: string, handlers: {
188
+ onClick?: unknown;
189
+ onKeyDown?: unknown;
190
+ }): void;
191
+ /**
192
+ * Check tabIndex usage
193
+ */
194
+ tabIndex(tabIndex: number | undefined, component: string, element?: HTMLElement): void;
195
+ /**
196
+ * Check for autofocus in dialogs
197
+ */
198
+ dialogAutoFocus(hasAutoFocus: boolean, component: string): void;
199
+ /**
200
+ * Check for missing form labels
201
+ */
202
+ formLabel(inputElement: HTMLElement | null, labelId: string | undefined, component: string): void;
203
+ /**
204
+ * Check for missing alt text on images
205
+ */
206
+ imageAlt(element: HTMLElement | null, component: string): void;
207
+ };
208
+ /**
209
+ * Create a component-scoped warning function
210
+ */
211
+ declare function createComponentWarnings(componentName: string): {
212
+ error: (message: string, suggestion?: string, element?: Element) => void;
213
+ warning: (message: string, suggestion?: string, element?: Element) => void;
214
+ info: (message: string, suggestion?: string, element?: Element) => void;
215
+ checks: {
216
+ accessibleLabel: (element: HTMLElement | null, propName?: string) => void;
217
+ requiredProp: (value: unknown, propName: string) => void;
218
+ keyboardAccessible: (element: HTMLElement | null, handlers: {
219
+ onClick?: unknown;
220
+ onKeyDown?: unknown;
221
+ }) => void;
222
+ tabIndex: (tabIndex: number | undefined, element?: HTMLElement) => void;
223
+ };
224
+ };
225
+
226
+ /**
227
+ * @compa11y/core
228
+ *
229
+ * Framework-agnostic accessibility primitives
230
+ *
231
+ * This package provides the foundational utilities used by all
232
+ * compa11y packages (React, Web Components, etc.)
233
+ */
234
+
235
+ /**
236
+ * Initialize all compa11y systems
237
+ * Call this once at app startup for optimal behavior
238
+ */
239
+ declare function initA11yKit(): () => void;
240
+
241
+ export { DevWarning, DevWarningHandler, FOCUSABLE_SELECTORS, TABBABLE_SELECTORS, checks, clearWarnings, containsFocus, createComponentWarnings, createIdScope, createMediaQueryListener, generateId, generateIds, getFirstFocusable, getFocusableElements, getLastFocusable, getNextFocusable, getPreviousFocusable, getScreenReaderHints, getTabbableElements, initA11yKit, isAndroid, isBrowser, isFocusable, isIOS, isMac, isTabbable, isTouchDevice, isVisible, isWindows, isWithinContainer, prefersDarkMode, prefersHighContrast, prefersReducedMotion, resetIdCounter, resolveElement, setWarningHandler, warn };
@@ -0,0 +1,241 @@
1
+ import { D as DevWarningHandler, a as DevWarning } from './types-DDSPmE8m.js';
2
+ export { A as AnnouncerOptions, b as AriaLivePoliteness, c as AriaRole, F as FocusTrapOptions, d as FocusableElement, K as KeyboardNavigationOptions } from './types-DDSPmE8m.js';
3
+ export { FocusScope, FocusScopeOptions, RovingTabindex, RovingTabindexOptions, createFocusScope, createFocusTrap, createRovingTabindex, focusWithVisibleRing, getActiveFocusTrap, getLastFocusSource, hasFocusTrap, hasVisibleFocus, initFocusVisible, isFocusVisible, setFocusVisible } from './focus/index.js';
4
+ export { KeyboardHandler, KeyboardHandlers, KeyboardManager, KeyboardManagerOptions, KeyboardPatterns, TypeAhead, createKeyboardManager, createTypeAhead, getKeyCombo, normalizeKey } from './keyboard/index.js';
5
+ export { announce, announceAssertive, announceError, announcePolite, announceProgress, announceStatus, clearAnnouncements, createAnnouncer, initAnnouncer, queueAnnouncement } from './announcer/index.js';
6
+ export { aria, buildAriaProps, hasAccessibleName, mergeAriaIds } from './aria/index.js';
7
+
8
+ /**
9
+ * ID generation utilities for accessible components
10
+ *
11
+ * Generates unique, predictable IDs for ARIA relationships
12
+ */
13
+ /**
14
+ * Generate a unique ID with optional prefix
15
+ */
16
+ declare function generateId(prefix?: string): string;
17
+ /**
18
+ * Generate a set of related IDs for a component
19
+ * Useful for complex components with multiple ARIA relationships
20
+ */
21
+ declare function generateIds<T extends readonly string[]>(parts: T, prefix?: string): Record<T[number], string>;
22
+ /**
23
+ * Reset the ID counter (useful for testing)
24
+ */
25
+ declare function resetIdCounter(): void;
26
+ /**
27
+ * Create a scoped ID generator for a component instance
28
+ */
29
+ declare function createIdScope(componentName: string): {
30
+ id: string;
31
+ generate: (suffix: string) => string;
32
+ generateMultiple: <T extends readonly string[]>(parts: T) => Record<T[number], string>;
33
+ };
34
+
35
+ /**
36
+ * DOM utilities for accessibility
37
+ */
38
+ /**
39
+ * Focusable element selectors
40
+ * Based on WHATWG focus management spec
41
+ */
42
+ declare const FOCUSABLE_SELECTORS: string;
43
+ /**
44
+ * Tabbable element selectors (subset of focusable that can be tabbed to)
45
+ */
46
+ declare const TABBABLE_SELECTORS: string;
47
+ /**
48
+ * Check if an element is visible (not hidden by CSS)
49
+ */
50
+ declare function isVisible(element: Element): boolean;
51
+ /**
52
+ * Check if an element is focusable
53
+ */
54
+ declare function isFocusable(element: Element): boolean;
55
+ /**
56
+ * Check if an element is tabbable (can receive focus via Tab key)
57
+ */
58
+ declare function isTabbable(element: Element): boolean;
59
+ /**
60
+ * Get all focusable elements within a container
61
+ */
62
+ declare function getFocusableElements(container: HTMLElement): HTMLElement[];
63
+ /**
64
+ * Get all tabbable elements within a container (sorted by tabIndex)
65
+ */
66
+ declare function getTabbableElements(container: HTMLElement): HTMLElement[];
67
+ /**
68
+ * Get the first focusable element in a container
69
+ */
70
+ declare function getFirstFocusable(container: HTMLElement): HTMLElement | null;
71
+ /**
72
+ * Get the last focusable element in a container
73
+ */
74
+ declare function getLastFocusable(container: HTMLElement): HTMLElement | null;
75
+ /**
76
+ * Check if an element contains the currently focused element
77
+ */
78
+ declare function containsFocus(container: HTMLElement): boolean;
79
+ /**
80
+ * Get the next focusable element
81
+ */
82
+ declare function getNextFocusable(container: HTMLElement, current: HTMLElement, wrap?: boolean): HTMLElement | null;
83
+ /**
84
+ * Get the previous focusable element
85
+ */
86
+ declare function getPreviousFocusable(container: HTMLElement, current: HTMLElement, wrap?: boolean): HTMLElement | null;
87
+ /**
88
+ * Check if element is within a specific container
89
+ */
90
+ declare function isWithinContainer(element: Element, container: Element): boolean;
91
+ /**
92
+ * Query for an element, supporting various input types
93
+ */
94
+ declare function resolveElement<T extends HTMLElement = HTMLElement>(target: T | string | (() => T | null) | null | undefined, container?: HTMLElement): T | null;
95
+
96
+ /**
97
+ * Platform detection utilities
98
+ *
99
+ * Used for platform-specific accessibility behavior
100
+ */
101
+ /**
102
+ * Check if we're in a browser environment
103
+ */
104
+ declare function isBrowser(): boolean;
105
+ /**
106
+ * Detect if running on macOS
107
+ */
108
+ declare function isMac(): boolean;
109
+ /**
110
+ * Detect if running on iOS
111
+ */
112
+ declare function isIOS(): boolean;
113
+ /**
114
+ * Detect if running on Android
115
+ */
116
+ declare function isAndroid(): boolean;
117
+ /**
118
+ * Detect if running on Windows
119
+ */
120
+ declare function isWindows(): boolean;
121
+ /**
122
+ * Detect if using a touch device
123
+ */
124
+ declare function isTouchDevice(): boolean;
125
+ /**
126
+ * Detect if user prefers reduced motion
127
+ */
128
+ declare function prefersReducedMotion(): boolean;
129
+ /**
130
+ * Detect if user prefers high contrast
131
+ */
132
+ declare function prefersHighContrast(): boolean;
133
+ /**
134
+ * Detect if user prefers dark color scheme
135
+ */
136
+ declare function prefersDarkMode(): boolean;
137
+ /**
138
+ * Get the current screen reader mode (if detectable)
139
+ * Note: This is not 100% reliable and should not be depended upon
140
+ */
141
+ declare function getScreenReaderHints(): {
142
+ possibleScreenReader: boolean;
143
+ forcedColors: boolean;
144
+ };
145
+ /**
146
+ * Create a media query listener with cleanup
147
+ */
148
+ declare function createMediaQueryListener(query: string, callback: (matches: boolean) => void): () => void;
149
+
150
+ /**
151
+ * Developer Warnings System
152
+ *
153
+ * Provides development-time feedback for accessibility issues
154
+ */
155
+
156
+ /**
157
+ * Set a custom warning handler
158
+ */
159
+ declare function setWarningHandler(handler: DevWarningHandler | null): void;
160
+ /**
161
+ * Issue a development warning
162
+ */
163
+ declare function warn(warning: DevWarning): void;
164
+ /**
165
+ * Clear issued warnings (useful for testing)
166
+ */
167
+ declare function clearWarnings(): void;
168
+ /**
169
+ * Pre-built warning checks
170
+ */
171
+ declare const checks: {
172
+ /**
173
+ * Check for missing accessible label
174
+ */
175
+ accessibleLabel(element: HTMLElement | null, component: string, propName?: string): void;
176
+ /**
177
+ * Check for missing required prop
178
+ */
179
+ requiredProp(value: unknown, propName: string, component: string): void;
180
+ /**
181
+ * Check for invalid ARIA role
182
+ */
183
+ validRole(role: string | undefined, component: string, element?: HTMLElement): void;
184
+ /**
185
+ * Check for interactive element without keyboard support
186
+ */
187
+ keyboardAccessible(element: HTMLElement | null, component: string, handlers: {
188
+ onClick?: unknown;
189
+ onKeyDown?: unknown;
190
+ }): void;
191
+ /**
192
+ * Check tabIndex usage
193
+ */
194
+ tabIndex(tabIndex: number | undefined, component: string, element?: HTMLElement): void;
195
+ /**
196
+ * Check for autofocus in dialogs
197
+ */
198
+ dialogAutoFocus(hasAutoFocus: boolean, component: string): void;
199
+ /**
200
+ * Check for missing form labels
201
+ */
202
+ formLabel(inputElement: HTMLElement | null, labelId: string | undefined, component: string): void;
203
+ /**
204
+ * Check for missing alt text on images
205
+ */
206
+ imageAlt(element: HTMLElement | null, component: string): void;
207
+ };
208
+ /**
209
+ * Create a component-scoped warning function
210
+ */
211
+ declare function createComponentWarnings(componentName: string): {
212
+ error: (message: string, suggestion?: string, element?: Element) => void;
213
+ warning: (message: string, suggestion?: string, element?: Element) => void;
214
+ info: (message: string, suggestion?: string, element?: Element) => void;
215
+ checks: {
216
+ accessibleLabel: (element: HTMLElement | null, propName?: string) => void;
217
+ requiredProp: (value: unknown, propName: string) => void;
218
+ keyboardAccessible: (element: HTMLElement | null, handlers: {
219
+ onClick?: unknown;
220
+ onKeyDown?: unknown;
221
+ }) => void;
222
+ tabIndex: (tabIndex: number | undefined, element?: HTMLElement) => void;
223
+ };
224
+ };
225
+
226
+ /**
227
+ * @compa11y/core
228
+ *
229
+ * Framework-agnostic accessibility primitives
230
+ *
231
+ * This package provides the foundational utilities used by all
232
+ * compa11y packages (React, Web Components, etc.)
233
+ */
234
+
235
+ /**
236
+ * Initialize all compa11y systems
237
+ * Call this once at app startup for optimal behavior
238
+ */
239
+ declare function initA11yKit(): () => void;
240
+
241
+ export { DevWarning, DevWarningHandler, FOCUSABLE_SELECTORS, TABBABLE_SELECTORS, checks, clearWarnings, containsFocus, createComponentWarnings, createIdScope, createMediaQueryListener, generateId, generateIds, getFirstFocusable, getFocusableElements, getLastFocusable, getNextFocusable, getPreviousFocusable, getScreenReaderHints, getTabbableElements, initA11yKit, isAndroid, isBrowser, isFocusable, isIOS, isMac, isTabbable, isTouchDevice, isVisible, isWindows, isWithinContainer, prefersDarkMode, prefersHighContrast, prefersReducedMotion, resetIdCounter, resolveElement, setWarningHandler, warn };