a11y-elements 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.txt +22 -0
- package/README.md +141 -0
- package/dist/a11y.css +1019 -0
- package/dist/accessibility-components/anchor/anchor.element.d.ts +28 -0
- package/dist/accessibility-components/anchor/anchor.element.js +87 -0
- package/dist/accessibility-components/anchor/anchor.element.js.map +1 -0
- package/dist/accessibility-components/anchor/define.d.ts +7 -0
- package/dist/accessibility-components/anchor/define.js +6 -0
- package/dist/accessibility-components/anchor/define.js.map +1 -0
- package/dist/accessibility-components/avatar/avatar.element.d.ts +21 -0
- package/dist/accessibility-components/avatar/avatar.element.js +73 -0
- package/dist/accessibility-components/avatar/avatar.element.js.map +1 -0
- package/dist/accessibility-components/avatar/define.d.ts +7 -0
- package/dist/accessibility-components/avatar/define.js +6 -0
- package/dist/accessibility-components/avatar/define.js.map +1 -0
- package/dist/accessibility-components/checkbox/checkbox.element.d.ts +36 -0
- package/dist/accessibility-components/checkbox/checkbox.element.js +79 -0
- package/dist/accessibility-components/checkbox/checkbox.element.js.map +1 -0
- package/dist/accessibility-components/checkbox/define.d.ts +7 -0
- package/dist/accessibility-components/checkbox/define.js +6 -0
- package/dist/accessibility-components/checkbox/define.js.map +1 -0
- package/dist/accessibility-components/focusable/define.d.ts +7 -0
- package/dist/accessibility-components/focusable/define.js +6 -0
- package/dist/accessibility-components/focusable/define.js.map +1 -0
- package/dist/accessibility-components/focusable/focusable.element.d.ts +30 -0
- package/dist/accessibility-components/focusable/focusable.element.js +52 -0
- package/dist/accessibility-components/focusable/focusable.element.js.map +1 -0
- package/dist/accessibility-components/picture/define.d.ts +7 -0
- package/dist/accessibility-components/picture/define.js +6 -0
- package/dist/accessibility-components/picture/define.js.map +1 -0
- package/dist/accessibility-components/picture/picture.element.d.ts +23 -0
- package/dist/accessibility-components/picture/picture.element.js +43 -0
- package/dist/accessibility-components/picture/picture.element.js.map +1 -0
- package/dist/accessibility-components/progress/define.d.ts +7 -0
- package/dist/accessibility-components/progress/define.js +6 -0
- package/dist/accessibility-components/progress/define.js.map +1 -0
- package/dist/accessibility-components/progress/progress.element.d.ts +20 -0
- package/dist/accessibility-components/progress/progress.element.js +44 -0
- package/dist/accessibility-components/progress/progress.element.js.map +1 -0
- package/dist/accessibility-components/radio-group/define.d.ts +7 -0
- package/dist/accessibility-components/radio-group/define.js +6 -0
- package/dist/accessibility-components/radio-group/define.js.map +1 -0
- package/dist/accessibility-components/radio-group/radio-group.element.d.ts +27 -0
- package/dist/accessibility-components/radio-group/radio-group.element.js +82 -0
- package/dist/accessibility-components/radio-group/radio-group.element.js.map +1 -0
- package/dist/accessibility-components/select/define.d.ts +7 -0
- package/dist/accessibility-components/select/define.js +6 -0
- package/dist/accessibility-components/select/define.js.map +1 -0
- package/dist/accessibility-components/select/select.element.d.ts +25 -0
- package/dist/accessibility-components/select/select.element.js +67 -0
- package/dist/accessibility-components/select/select.element.js.map +1 -0
- package/dist/accessibility-components/skeleton/define.d.ts +7 -0
- package/dist/accessibility-components/skeleton/define.js +6 -0
- package/dist/accessibility-components/skeleton/define.js.map +1 -0
- package/dist/accessibility-components/skeleton/skeleton.element.d.ts +16 -0
- package/dist/accessibility-components/skeleton/skeleton.element.js +40 -0
- package/dist/accessibility-components/skeleton/skeleton.element.js.map +1 -0
- package/dist/accessibility-components/spinner/define.d.ts +7 -0
- package/dist/accessibility-components/spinner/define.js +6 -0
- package/dist/accessibility-components/spinner/define.js.map +1 -0
- package/dist/accessibility-components/spinner/spinner.element.d.ts +21 -0
- package/dist/accessibility-components/spinner/spinner.element.js +60 -0
- package/dist/accessibility-components/spinner/spinner.element.js.map +1 -0
- package/dist/accessibility-components/switch/define.d.ts +7 -0
- package/dist/accessibility-components/switch/define.js +6 -0
- package/dist/accessibility-components/switch/define.js.map +1 -0
- package/dist/accessibility-components/switch/switch.element.d.ts +22 -0
- package/dist/accessibility-components/switch/switch.element.js +65 -0
- package/dist/accessibility-components/switch/switch.element.js.map +1 -0
- package/dist/accessibility-components/visually-hidden/define.d.ts +7 -0
- package/dist/accessibility-components/visually-hidden/define.js +6 -0
- package/dist/accessibility-components/visually-hidden/define.js.map +1 -0
- package/dist/accessibility-components/visually-hidden/visually-hidden.element.d.ts +16 -0
- package/dist/accessibility-components/visually-hidden/visually-hidden.element.js +24 -0
- package/dist/accessibility-components/visually-hidden/visually-hidden.element.js.map +1 -0
- package/dist/browser/accessibility-components/anchor/define.js +192 -0
- package/dist/browser/accessibility-components/anchor/define.js.map +1 -0
- package/dist/browser/accessibility-components/avatar/define.js +159 -0
- package/dist/browser/accessibility-components/avatar/define.js.map +1 -0
- package/dist/browser/accessibility-components/checkbox/define.js +186 -0
- package/dist/browser/accessibility-components/checkbox/define.js.map +1 -0
- package/dist/browser/accessibility-components/focusable/define.js +113 -0
- package/dist/browser/accessibility-components/focusable/define.js.map +1 -0
- package/dist/browser/accessibility-components/picture/define.js +156 -0
- package/dist/browser/accessibility-components/picture/define.js.map +1 -0
- package/dist/browser/accessibility-components/progress/define.js +135 -0
- package/dist/browser/accessibility-components/progress/define.js.map +1 -0
- package/dist/browser/accessibility-components/radio-group/define.js +204 -0
- package/dist/browser/accessibility-components/radio-group/define.js.map +1 -0
- package/dist/browser/accessibility-components/select/define.js +184 -0
- package/dist/browser/accessibility-components/select/define.js.map +1 -0
- package/dist/browser/accessibility-components/skeleton/define.js +136 -0
- package/dist/browser/accessibility-components/skeleton/define.js.map +1 -0
- package/dist/browser/accessibility-components/spinner/define.js +156 -0
- package/dist/browser/accessibility-components/spinner/define.js.map +1 -0
- package/dist/browser/accessibility-components/switch/define.js +192 -0
- package/dist/browser/accessibility-components/switch/define.js.map +1 -0
- package/dist/browser/accessibility-components/visually-hidden/define.js +97 -0
- package/dist/browser/accessibility-components/visually-hidden/define.js.map +1 -0
- package/dist/browser/overlays/blocking-loader/define.js +351 -0
- package/dist/browser/overlays/blocking-loader/define.js.map +1 -0
- package/dist/browser/overlays/context-menu/define.js +774 -0
- package/dist/browser/overlays/context-menu/define.js.map +1 -0
- package/dist/browser/overlays/drawer/define.js +529 -0
- package/dist/browser/overlays/drawer/define.js.map +1 -0
- package/dist/browser/overlays/dropdown/define.js +770 -0
- package/dist/browser/overlays/dropdown/define.js.map +1 -0
- package/dist/browser/overlays/emergency-dialog/define.js +525 -0
- package/dist/browser/overlays/emergency-dialog/define.js.map +1 -0
- package/dist/browser/overlays/modal/define.js +523 -0
- package/dist/browser/overlays/modal/define.js.map +1 -0
- package/dist/browser/overlays/notification-banner/define.js +289 -0
- package/dist/browser/overlays/notification-banner/define.js.map +1 -0
- package/dist/browser/overlays/popover/define.js +625 -0
- package/dist/browser/overlays/popover/define.js.map +1 -0
- package/dist/browser/overlays/snackbar/define.js +268 -0
- package/dist/browser/overlays/snackbar/define.js.map +1 -0
- package/dist/browser/overlays/tooltip/define.js +707 -0
- package/dist/browser/overlays/tooltip/define.js.map +1 -0
- package/dist/core/a11y-element.d.ts +53 -0
- package/dist/core/a11y-element.js +104 -0
- package/dist/core/a11y-element.js.map +1 -0
- package/dist/core/a11y-form-element.d.ts +23 -0
- package/dist/core/a11y-form-element.js +30 -0
- package/dist/core/a11y-form-element.js.map +1 -0
- package/dist/core/a11y-overlay-element.d.ts +100 -0
- package/dist/core/a11y-overlay-element.js +160 -0
- package/dist/core/a11y-overlay-element.js.map +1 -0
- package/dist/core/a11y-wrapper-element.d.ts +48 -0
- package/dist/core/a11y-wrapper-element.js +70 -0
- package/dist/core/a11y-wrapper-element.js.map +1 -0
- package/dist/core/dom-sync.d.ts +15 -0
- package/dist/core/dom-sync.js +30 -0
- package/dist/core/dom-sync.js.map +1 -0
- package/dist/core/focus-trap.d.ts +47 -0
- package/dist/core/focus-trap.js +138 -0
- package/dist/core/focus-trap.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/overlay-registry.d.ts +36 -0
- package/dist/core/overlay-registry.js +60 -0
- package/dist/core/overlay-registry.js.map +1 -0
- package/dist/core/template.d.ts +32 -0
- package/dist/core/template.js +48 -0
- package/dist/core/template.js.map +1 -0
- package/dist/core/transition.d.ts +16 -0
- package/dist/core/transition.js +53 -0
- package/dist/core/transition.js.map +1 -0
- package/dist/overlays/blocking-loader/blocking-loader.element.d.ts +29 -0
- package/dist/overlays/blocking-loader/blocking-loader.element.js +77 -0
- package/dist/overlays/blocking-loader/blocking-loader.element.js.map +1 -0
- package/dist/overlays/blocking-loader/define.d.ts +9 -0
- package/dist/overlays/blocking-loader/define.js +10 -0
- package/dist/overlays/blocking-loader/define.js.map +1 -0
- package/dist/overlays/context-menu/context-menu.element.d.ts +31 -0
- package/dist/overlays/context-menu/context-menu.element.js +86 -0
- package/dist/overlays/context-menu/context-menu.element.js.map +1 -0
- package/dist/overlays/context-menu/define.d.ts +8 -0
- package/dist/overlays/context-menu/define.js +8 -0
- package/dist/overlays/context-menu/define.js.map +1 -0
- package/dist/overlays/core/a11y-anchored-overlay-element.d.ts +68 -0
- package/dist/overlays/core/a11y-anchored-overlay-element.js +276 -0
- package/dist/overlays/core/a11y-anchored-overlay-element.js.map +1 -0
- package/dist/overlays/core/a11y-menu-overlay-element.d.ts +46 -0
- package/dist/overlays/core/a11y-menu-overlay-element.js +152 -0
- package/dist/overlays/core/a11y-menu-overlay-element.js.map +1 -0
- package/dist/overlays/core/a11y-modal-overlay-element.d.ts +44 -0
- package/dist/overlays/core/a11y-modal-overlay-element.js +163 -0
- package/dist/overlays/core/a11y-modal-overlay-element.js.map +1 -0
- package/dist/overlays/core/a11y-passive-overlay-element.d.ts +38 -0
- package/dist/overlays/core/a11y-passive-overlay-element.js +108 -0
- package/dist/overlays/core/a11y-passive-overlay-element.js.map +1 -0
- package/dist/overlays/drawer/define.d.ts +8 -0
- package/dist/overlays/drawer/define.js +8 -0
- package/dist/overlays/drawer/define.js.map +1 -0
- package/dist/overlays/drawer/drawer.element.d.ts +19 -0
- package/dist/overlays/drawer/drawer.element.js +37 -0
- package/dist/overlays/drawer/drawer.element.js.map +1 -0
- package/dist/overlays/dropdown/define.d.ts +8 -0
- package/dist/overlays/dropdown/define.js +8 -0
- package/dist/overlays/dropdown/define.js.map +1 -0
- package/dist/overlays/dropdown/dropdown.element.d.ts +30 -0
- package/dist/overlays/dropdown/dropdown.element.js +82 -0
- package/dist/overlays/dropdown/dropdown.element.js.map +1 -0
- package/dist/overlays/emergency-dialog/define.d.ts +8 -0
- package/dist/overlays/emergency-dialog/define.js +8 -0
- package/dist/overlays/emergency-dialog/define.js.map +1 -0
- package/dist/overlays/emergency-dialog/emergency-dialog.element.d.ts +23 -0
- package/dist/overlays/emergency-dialog/emergency-dialog.element.js +38 -0
- package/dist/overlays/emergency-dialog/emergency-dialog.element.js.map +1 -0
- package/dist/overlays/modal/define.d.ts +8 -0
- package/dist/overlays/modal/define.js +8 -0
- package/dist/overlays/modal/define.js.map +1 -0
- package/dist/overlays/modal/modal.element.d.ts +26 -0
- package/dist/overlays/modal/modal.element.js +42 -0
- package/dist/overlays/modal/modal.element.js.map +1 -0
- package/dist/overlays/notification-banner/define.d.ts +14 -0
- package/dist/overlays/notification-banner/define.js +26 -0
- package/dist/overlays/notification-banner/define.js.map +1 -0
- package/dist/overlays/notification-banner/notification-banner.element.d.ts +39 -0
- package/dist/overlays/notification-banner/notification-banner.element.js +88 -0
- package/dist/overlays/notification-banner/notification-banner.element.js.map +1 -0
- package/dist/overlays/popover/define.d.ts +8 -0
- package/dist/overlays/popover/define.js +8 -0
- package/dist/overlays/popover/define.js.map +1 -0
- package/dist/overlays/popover/popover.element.d.ts +20 -0
- package/dist/overlays/popover/popover.element.js +41 -0
- package/dist/overlays/popover/popover.element.js.map +1 -0
- package/dist/overlays/snackbar/define.d.ts +14 -0
- package/dist/overlays/snackbar/define.js +26 -0
- package/dist/overlays/snackbar/define.js.map +1 -0
- package/dist/overlays/snackbar/snackbar.element.d.ts +30 -0
- package/dist/overlays/snackbar/snackbar.element.js +61 -0
- package/dist/overlays/snackbar/snackbar.element.js.map +1 -0
- package/dist/overlays/tooltip/define.d.ts +8 -0
- package/dist/overlays/tooltip/define.js +8 -0
- package/dist/overlays/tooltip/define.js.map +1 -0
- package/dist/overlays/tooltip/tooltip.element.d.ts +41 -0
- package/dist/overlays/tooltip/tooltip.element.js +133 -0
- package/dist/overlays/tooltip/tooltip.element.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { A11yElement } from './a11y-element.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base for elements that enhance real, consumer-authored light-DOM children
|
|
4
|
+
* instead of generating their own markup from a template string — e.g. a
|
|
5
|
+
* `<a11y-picture>` wrapping a real `<picture>`/`<img>`/`<figcaption>`, or
|
|
6
|
+
* `<a11y-select>` wrapping a real `<select>`/`<option>`s.
|
|
7
|
+
*
|
|
8
|
+
* Unlike `A11yElement`, this never sets `innerHTML` from a `render()`
|
|
9
|
+
* string — that would destroy the author's children — so it opts out of the
|
|
10
|
+
* normal render pipeline and instead re-syncs (`_sync()`) from two sources:
|
|
11
|
+
*
|
|
12
|
+
* - **This element's own observed attributes** (e.g. `label`, `legend`),
|
|
13
|
+
* listed via `static observedAttributes` same as any other element —
|
|
14
|
+
* these re-sync *synchronously*, matching every other element in this
|
|
15
|
+
* library, so `el.setAttribute('label', 'x')` takes effect immediately.
|
|
16
|
+
* - **Everything else** (children added/removed, an attribute changing on
|
|
17
|
+
* one of *those* children) — light DOM has no `slotchange`, so a
|
|
18
|
+
* `MutationObserver` is the equivalent, necessarily asynchronous (a real
|
|
19
|
+
* microtask/task delay after the mutation).
|
|
20
|
+
*
|
|
21
|
+
* `_sync()` runs inside that `MutationObserver` callback, so every DOM write
|
|
22
|
+
* it makes must be guarded (see `core/dom-sync.ts`) — `setAttribute`/
|
|
23
|
+
* `classList.add`/`textContent =` all queue a mutation record even when the
|
|
24
|
+
* value is unchanged, and an unguarded write would retrigger the observer
|
|
25
|
+
* forever.
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class A11yWrapperElement extends A11yElement {
|
|
28
|
+
private _observer;
|
|
29
|
+
/** Nodes already given their listeners since the last connect — see `wireOnce()`. */
|
|
30
|
+
private _wiredNodes;
|
|
31
|
+
connectedCallback(): void;
|
|
32
|
+
disconnectedCallback(): void;
|
|
33
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* Runs `wire` the first time `node` is seen since this element was last
|
|
36
|
+
* connected. `_sync()` runs on every mutation, so listener setup must be
|
|
37
|
+
* idempotent — but those listeners (added via `listen()`) are all removed
|
|
38
|
+
* on disconnect, so the "already wired" memory must reset with them, or a
|
|
39
|
+
* reparented element (disconnect + connect) would silently stop firing.
|
|
40
|
+
*/
|
|
41
|
+
protected wireOnce(node: Node, wire: () => void): void;
|
|
42
|
+
/** What to watch for changes worth re-syncing on. Override for a narrower/wider scope. */
|
|
43
|
+
protected observerInit(): MutationObserverInit;
|
|
44
|
+
/** Re-derive this element's own attributes/classes from its current children. */
|
|
45
|
+
protected abstract _sync(): void;
|
|
46
|
+
/** Unused — content is the author's own children, never replaced. */
|
|
47
|
+
protected render(): string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { A11yElement } from './a11y-element.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base for elements that enhance real, consumer-authored light-DOM children
|
|
4
|
+
* instead of generating their own markup from a template string — e.g. a
|
|
5
|
+
* `<a11y-picture>` wrapping a real `<picture>`/`<img>`/`<figcaption>`, or
|
|
6
|
+
* `<a11y-select>` wrapping a real `<select>`/`<option>`s.
|
|
7
|
+
*
|
|
8
|
+
* Unlike `A11yElement`, this never sets `innerHTML` from a `render()`
|
|
9
|
+
* string — that would destroy the author's children — so it opts out of the
|
|
10
|
+
* normal render pipeline and instead re-syncs (`_sync()`) from two sources:
|
|
11
|
+
*
|
|
12
|
+
* - **This element's own observed attributes** (e.g. `label`, `legend`),
|
|
13
|
+
* listed via `static observedAttributes` same as any other element —
|
|
14
|
+
* these re-sync *synchronously*, matching every other element in this
|
|
15
|
+
* library, so `el.setAttribute('label', 'x')` takes effect immediately.
|
|
16
|
+
* - **Everything else** (children added/removed, an attribute changing on
|
|
17
|
+
* one of *those* children) — light DOM has no `slotchange`, so a
|
|
18
|
+
* `MutationObserver` is the equivalent, necessarily asynchronous (a real
|
|
19
|
+
* microtask/task delay after the mutation).
|
|
20
|
+
*
|
|
21
|
+
* `_sync()` runs inside that `MutationObserver` callback, so every DOM write
|
|
22
|
+
* it makes must be guarded (see `core/dom-sync.ts`) — `setAttribute`/
|
|
23
|
+
* `classList.add`/`textContent =` all queue a mutation record even when the
|
|
24
|
+
* value is unchanged, and an unguarded write would retrigger the observer
|
|
25
|
+
* forever.
|
|
26
|
+
*/
|
|
27
|
+
export class A11yWrapperElement extends A11yElement {
|
|
28
|
+
_observer = null;
|
|
29
|
+
/** Nodes already given their listeners since the last connect — see `wireOnce()`. */
|
|
30
|
+
_wiredNodes = new WeakSet();
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this._connected = true;
|
|
33
|
+
this._sync();
|
|
34
|
+
this._observer = new MutationObserver(() => this._sync());
|
|
35
|
+
this._observer.observe(this, this.observerInit());
|
|
36
|
+
}
|
|
37
|
+
disconnectedCallback() {
|
|
38
|
+
this._observer?.disconnect();
|
|
39
|
+
this._observer = null;
|
|
40
|
+
super.disconnectedCallback(); // removes every `listen()` listener…
|
|
41
|
+
this._wiredNodes = new WeakSet(); // …so the next connect must wire them again
|
|
42
|
+
}
|
|
43
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
44
|
+
if (oldValue === newValue || !this._connected)
|
|
45
|
+
return;
|
|
46
|
+
this._sync();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Runs `wire` the first time `node` is seen since this element was last
|
|
50
|
+
* connected. `_sync()` runs on every mutation, so listener setup must be
|
|
51
|
+
* idempotent — but those listeners (added via `listen()`) are all removed
|
|
52
|
+
* on disconnect, so the "already wired" memory must reset with them, or a
|
|
53
|
+
* reparented element (disconnect + connect) would silently stop firing.
|
|
54
|
+
*/
|
|
55
|
+
wireOnce(node, wire) {
|
|
56
|
+
if (this._wiredNodes.has(node))
|
|
57
|
+
return;
|
|
58
|
+
this._wiredNodes.add(node);
|
|
59
|
+
wire();
|
|
60
|
+
}
|
|
61
|
+
/** What to watch for changes worth re-syncing on. Override for a narrower/wider scope. */
|
|
62
|
+
observerInit() {
|
|
63
|
+
return { childList: true, subtree: true, attributes: true };
|
|
64
|
+
}
|
|
65
|
+
/** Unused — content is the author's own children, never replaced. */
|
|
66
|
+
render() {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=a11y-wrapper-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a11y-wrapper-element.js","sourceRoot":"","sources":["../../src/core/a11y-wrapper-element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;IAClD,SAAS,GAA4B,IAAI,CAAC;IAClD,qFAAqF;IAC7E,WAAW,GAAG,IAAI,OAAO,EAAQ,CAAC;IAEjC,iBAAiB;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACpD,CAAC;IAEQ,oBAAoB;QAC3B,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,qCAAqC;QACnE,IAAI,CAAC,WAAW,GAAG,IAAI,OAAO,EAAE,CAAC,CAAC,4CAA4C;IAChF,CAAC;IAEQ,wBAAwB,CAAC,KAAa,EAAE,QAAuB,EAAE,QAAuB;QAC/F,IAAI,QAAQ,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO;QACtD,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACO,QAAQ,CAAC,IAAU,EAAE,IAAgB;QAC7C,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO;QACvC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,EAAE,CAAC;IACT,CAAC;IAED,0FAA0F;IAChF,YAAY;QACpB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9D,CAAC;IAKD,qEAAqE;IAClD,MAAM;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarded DOM writes for use inside `A11yWrapperElement._sync()` methods (or
|
|
3
|
+
* anywhere else re-syncing against a live MutationObserver).
|
|
4
|
+
*
|
|
5
|
+
* `setAttribute`/`removeAttribute`/`classList.add`/`classList.remove`/
|
|
6
|
+
* `textContent =` all queue a mutation record unconditionally — even when
|
|
7
|
+
* the value being written is identical to what's already there. Call one of
|
|
8
|
+
* these unguarded inside a MutationObserver callback that's itself watching
|
|
9
|
+
* the element being written to, and every "no-op" write retriggers the
|
|
10
|
+
* observer, forever. These helpers check first, so a `_sync()` call that
|
|
11
|
+
* changes nothing produces zero mutations and the observer loop terminates.
|
|
12
|
+
*/
|
|
13
|
+
export declare function syncText(el: Element, text: string): void;
|
|
14
|
+
export declare function syncAttr(el: Element, name: string, value: string | null | undefined): void;
|
|
15
|
+
export declare function syncClass(el: Element, name: string, present: boolean): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guarded DOM writes for use inside `A11yWrapperElement._sync()` methods (or
|
|
3
|
+
* anywhere else re-syncing against a live MutationObserver).
|
|
4
|
+
*
|
|
5
|
+
* `setAttribute`/`removeAttribute`/`classList.add`/`classList.remove`/
|
|
6
|
+
* `textContent =` all queue a mutation record unconditionally — even when
|
|
7
|
+
* the value being written is identical to what's already there. Call one of
|
|
8
|
+
* these unguarded inside a MutationObserver callback that's itself watching
|
|
9
|
+
* the element being written to, and every "no-op" write retriggers the
|
|
10
|
+
* observer, forever. These helpers check first, so a `_sync()` call that
|
|
11
|
+
* changes nothing produces zero mutations and the observer loop terminates.
|
|
12
|
+
*/
|
|
13
|
+
export function syncText(el, text) {
|
|
14
|
+
if (el.textContent !== text)
|
|
15
|
+
el.textContent = text;
|
|
16
|
+
}
|
|
17
|
+
export function syncAttr(el, name, value) {
|
|
18
|
+
if (value == null) {
|
|
19
|
+
if (el.hasAttribute(name))
|
|
20
|
+
el.removeAttribute(name);
|
|
21
|
+
}
|
|
22
|
+
else if (el.getAttribute(name) !== value) {
|
|
23
|
+
el.setAttribute(name, value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function syncClass(el, name, present) {
|
|
27
|
+
if (el.classList.contains(name) !== present)
|
|
28
|
+
el.classList.toggle(name, present);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=dom-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-sync.js","sourceRoot":"","sources":["../../src/core/dom-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,UAAU,QAAQ,CAAC,EAAW,EAAE,IAAY;IAChD,IAAI,EAAE,CAAC,WAAW,KAAK,IAAI;QAAE,EAAE,CAAC,WAAW,GAAG,IAAI,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,EAAW,EAAE,IAAY,EAAE,KAAgC;IAClF,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC;YAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;SAAM,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;QAC3C,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAW,EAAE,IAAY,EAAE,OAAgB;IACnE,IAAI,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,OAAO;QAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface IFocusTrapOptions {
|
|
2
|
+
escapeDeactivates?: boolean;
|
|
3
|
+
returnFocusOnDeactivate?: boolean;
|
|
4
|
+
onDeactivate?: () => void;
|
|
5
|
+
/**
|
|
6
|
+
* An element (or selector resolving to one) to mark `inert` while the trap
|
|
7
|
+
* is active, so assistive tech can't reach content behind the trap.
|
|
8
|
+
* Defaults to `null` (no side effect) — the old implementation hardcoded
|
|
9
|
+
* `document.querySelector('#app')`, which assumed every consumer had a
|
|
10
|
+
* single a11y-shell element with that exact id. A library meant to be
|
|
11
|
+
* dropped into arbitrary HTML can't assume that, so this is opt-in.
|
|
12
|
+
*/
|
|
13
|
+
inertTarget?: HTMLElement | string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface IFocusTrapHelperParams {
|
|
16
|
+
container: HTMLElement;
|
|
17
|
+
options?: IFocusTrapOptions;
|
|
18
|
+
}
|
|
19
|
+
export declare class FocusTrapHelper {
|
|
20
|
+
private _container;
|
|
21
|
+
private _previousActiveElement;
|
|
22
|
+
private _focusableElements;
|
|
23
|
+
private _firstFocusableElement;
|
|
24
|
+
private _boundKeyDown;
|
|
25
|
+
private _options;
|
|
26
|
+
private _inertTarget;
|
|
27
|
+
private _isActive;
|
|
28
|
+
constructor({ container, options }: IFocusTrapHelperParams);
|
|
29
|
+
private _getFocusableElements;
|
|
30
|
+
private _resolveInertTarget;
|
|
31
|
+
activate(): void;
|
|
32
|
+
deactivate(): void;
|
|
33
|
+
getIsActive(): boolean;
|
|
34
|
+
updateFocusableElements(): void;
|
|
35
|
+
private _handleKeyDown;
|
|
36
|
+
/**
|
|
37
|
+
* Drives every Tab/Shift+Tab press manually instead of only intercepting
|
|
38
|
+
* at the first/last boundary and otherwise trusting the browser's native
|
|
39
|
+
* tab order to match `_focusableElements`' DOM order. Safari on macOS, by
|
|
40
|
+
* default, excludes buttons/links from the native Tab order entirely (only
|
|
41
|
+
* text inputs get native tab stops) — so a boundary-only trap can let
|
|
42
|
+
* focus silently escape once native Tab skips past what this class thinks
|
|
43
|
+
* is the last focusable element. Owning every Tab press removes that
|
|
44
|
+
* dependency on any browser's native tab-stop behavior altogether.
|
|
45
|
+
*/
|
|
46
|
+
private _handleTabKey;
|
|
47
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const FOCUSABLE_SELECTOR = 'button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a selector-matched element can actually take focus right now:
|
|
4
|
+
* not inside a `hidden`/`inert` subtree, and (where the browser supports
|
|
5
|
+
* `checkVisibility()`) actually rendered — `display: none`, `visibility:
|
|
6
|
+
* hidden` or a collapsed `<details>` would otherwise become a Tab stop
|
|
7
|
+
* that silently swallows the key press.
|
|
8
|
+
*/
|
|
9
|
+
function isTabbable(el) {
|
|
10
|
+
if (el.closest('[hidden], [inert]'))
|
|
11
|
+
return false;
|
|
12
|
+
if (typeof el.checkVisibility === 'function')
|
|
13
|
+
return el.checkVisibility({ visibilityProperty: true });
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
export class FocusTrapHelper {
|
|
17
|
+
_container;
|
|
18
|
+
_previousActiveElement = null;
|
|
19
|
+
_focusableElements = null;
|
|
20
|
+
_firstFocusableElement = null;
|
|
21
|
+
_boundKeyDown;
|
|
22
|
+
_options;
|
|
23
|
+
_inertTarget = null;
|
|
24
|
+
_isActive = false;
|
|
25
|
+
constructor({ container, options = {} }) {
|
|
26
|
+
this._container = container;
|
|
27
|
+
this._options = {
|
|
28
|
+
escapeDeactivates: options.escapeDeactivates ?? true,
|
|
29
|
+
returnFocusOnDeactivate: options.returnFocusOnDeactivate ?? true,
|
|
30
|
+
onDeactivate: options.onDeactivate,
|
|
31
|
+
inertTarget: options.inertTarget ?? null,
|
|
32
|
+
};
|
|
33
|
+
this._boundKeyDown = this._handleKeyDown.bind(this);
|
|
34
|
+
}
|
|
35
|
+
_getFocusableElements() {
|
|
36
|
+
return Array.from(this._container.querySelectorAll(FOCUSABLE_SELECTOR)).filter(isTabbable);
|
|
37
|
+
}
|
|
38
|
+
_resolveInertTarget() {
|
|
39
|
+
const target = this._options.inertTarget;
|
|
40
|
+
if (!target)
|
|
41
|
+
return null;
|
|
42
|
+
return typeof target === 'string' ? document.querySelector(target) : target;
|
|
43
|
+
}
|
|
44
|
+
activate() {
|
|
45
|
+
if (this._isActive)
|
|
46
|
+
return;
|
|
47
|
+
this._previousActiveElement = document.activeElement;
|
|
48
|
+
this._focusableElements = this._getFocusableElements();
|
|
49
|
+
if (this._focusableElements.length > 0) {
|
|
50
|
+
this._firstFocusableElement = this._focusableElements[0] ?? null;
|
|
51
|
+
this._firstFocusableElement?.focus();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this._container.setAttribute('tabindex', '-1');
|
|
55
|
+
this._container.focus();
|
|
56
|
+
this._firstFocusableElement = this._container;
|
|
57
|
+
}
|
|
58
|
+
this._container.addEventListener('keydown', this._boundKeyDown);
|
|
59
|
+
this._inertTarget = this._resolveInertTarget();
|
|
60
|
+
if (this._inertTarget)
|
|
61
|
+
this._inertTarget.inert = true;
|
|
62
|
+
this._isActive = true;
|
|
63
|
+
}
|
|
64
|
+
deactivate() {
|
|
65
|
+
if (!this._isActive)
|
|
66
|
+
return;
|
|
67
|
+
this._container.removeEventListener('keydown', this._boundKeyDown);
|
|
68
|
+
if (this._inertTarget)
|
|
69
|
+
this._inertTarget.inert = false;
|
|
70
|
+
this._inertTarget = null;
|
|
71
|
+
if (this._container.getAttribute('tabindex') === '-1') {
|
|
72
|
+
this._container.removeAttribute('tabindex');
|
|
73
|
+
}
|
|
74
|
+
if (this._options.returnFocusOnDeactivate && this._previousActiveElement?.focus) {
|
|
75
|
+
this._previousActiveElement.focus();
|
|
76
|
+
}
|
|
77
|
+
this._focusableElements = null;
|
|
78
|
+
this._firstFocusableElement = null;
|
|
79
|
+
this._previousActiveElement = null;
|
|
80
|
+
this._isActive = false;
|
|
81
|
+
}
|
|
82
|
+
getIsActive() {
|
|
83
|
+
return this._isActive;
|
|
84
|
+
}
|
|
85
|
+
updateFocusableElements() {
|
|
86
|
+
if (!this._isActive)
|
|
87
|
+
return;
|
|
88
|
+
this._focusableElements = this._getFocusableElements();
|
|
89
|
+
if (this._focusableElements.length > 0) {
|
|
90
|
+
this._firstFocusableElement = this._focusableElements[0] ?? null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
_handleKeyDown(event) {
|
|
94
|
+
switch (event.key) {
|
|
95
|
+
case 'Tab':
|
|
96
|
+
this._handleTabKey(event);
|
|
97
|
+
break;
|
|
98
|
+
case 'Escape':
|
|
99
|
+
if (this._options.escapeDeactivates) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
this._options.onDeactivate?.();
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Drives every Tab/Shift+Tab press manually instead of only intercepting
|
|
108
|
+
* at the first/last boundary and otherwise trusting the browser's native
|
|
109
|
+
* tab order to match `_focusableElements`' DOM order. Safari on macOS, by
|
|
110
|
+
* default, excludes buttons/links from the native Tab order entirely (only
|
|
111
|
+
* text inputs get native tab stops) — so a boundary-only trap can let
|
|
112
|
+
* focus silently escape once native Tab skips past what this class thinks
|
|
113
|
+
* is the last focusable element. Owning every Tab press removes that
|
|
114
|
+
* dependency on any browser's native tab-stop behavior altogether.
|
|
115
|
+
*/
|
|
116
|
+
_handleTabKey(event) {
|
|
117
|
+
// Re-queried on every press, so content added/removed/shown/hidden
|
|
118
|
+
// inside the trap after activation is always reachable (and nothing
|
|
119
|
+
// stale is).
|
|
120
|
+
this.updateFocusableElements();
|
|
121
|
+
if (!this._focusableElements || this._focusableElements.length === 0) {
|
|
122
|
+
event.preventDefault(); // nothing to move to — keep focus on the container rather than letting it escape
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
const elements = this._focusableElements;
|
|
127
|
+
const currentIndex = elements.indexOf(document.activeElement);
|
|
128
|
+
const nextIndex = event.shiftKey
|
|
129
|
+
? currentIndex <= 0
|
|
130
|
+
? elements.length - 1
|
|
131
|
+
: currentIndex - 1
|
|
132
|
+
: currentIndex === -1 || currentIndex === elements.length - 1
|
|
133
|
+
? 0
|
|
134
|
+
: currentIndex + 1;
|
|
135
|
+
elements[nextIndex]?.focus();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=focus-trap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus-trap.js","sourceRoot":"","sources":["../../src/core/focus-trap.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GACtB,sIAAsI,CAAC;AAsBzI;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,EAAe;IACjC,IAA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gBACD,MAAM;QACV,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACK,aAAa,CAAC,KAAoB;QACxC,mEAAmE;QACnE,oEAAoE;QACpE,aAAa;QACb,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,iFAAiF;YACzG,OAAO;QACT,CAAC;QAED,KAAK,CAAC,cAAc,EAAE,CAAC;QAEvB,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC;QACzC,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,aAA4B,CAAC,CAAC;QAE7E,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ;YAC9B,CAAC,CAAC,YAAY,IAAI,CAAC;gBACjB,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBACrB,CAAC,CAAC,YAAY,GAAG,CAAC;YACpB,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,IAAI,YAAY,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAC3D,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC;QAEvB,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './template.js';
|
|
2
|
+
export * from './a11y-element.js';
|
|
3
|
+
export * from './a11y-wrapper-element.js';
|
|
4
|
+
export * from './a11y-form-element.js';
|
|
5
|
+
export * from './a11y-overlay-element.js';
|
|
6
|
+
export * from './focus-trap.js';
|
|
7
|
+
export * from './overlay-registry.js';
|
|
8
|
+
export * from './dom-sync.js';
|
|
9
|
+
export * from './transition.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './template.js';
|
|
2
|
+
export * from './a11y-element.js';
|
|
3
|
+
export * from './a11y-wrapper-element.js';
|
|
4
|
+
export * from './a11y-form-element.js';
|
|
5
|
+
export * from './a11y-overlay-element.js';
|
|
6
|
+
export * from './focus-trap.js';
|
|
7
|
+
export * from './overlay-registry.js';
|
|
8
|
+
export * from './dom-sync.js';
|
|
9
|
+
export * from './transition.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface OverlayOpenCloseDetail {
|
|
2
|
+
name: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const OVERLAY_OPEN_EVENT = "a11y-overlay-open";
|
|
5
|
+
export declare const OVERLAY_CLOSE_EVENT = "a11y-overlay-close";
|
|
6
|
+
interface Dismissible {
|
|
7
|
+
close(): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tracks every currently-open overlay instance so a consumer's own SPA
|
|
11
|
+
* router (or anything else) can force-dismiss all of them, e.g. on
|
|
12
|
+
* navigation — the framework-agnostic replacement for the old
|
|
13
|
+
* `Lifecycle.onViewUnmount` global hook, which only `notification-banner`
|
|
14
|
+
* used and `snackbar` deliberately opted out of. That asymmetry is
|
|
15
|
+
* preserved: nothing here calls `dismissAllOverlays()` automatically, a
|
|
16
|
+
* consumer wires it into their own navigation event if they want it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerOpenOverlay(overlay: Dismissible): void;
|
|
19
|
+
export declare function unregisterOpenOverlay(overlay: Dismissible): void;
|
|
20
|
+
export declare function dismissAllOverlays(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Reference-counted page scroll lock. Every scroll-locking overlay (modal,
|
|
23
|
+
* drawer, emergency-dialog, blocking-loader) calls `lockScroll()` once on
|
|
24
|
+
* show and `unlockScroll()` once when fully hidden, so closing one of two
|
|
25
|
+
* stacked overlays doesn't unlock the page under the one still open.
|
|
26
|
+
*/
|
|
27
|
+
export declare function lockScroll(): void;
|
|
28
|
+
export declare function unlockScroll(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Standardized replacement for the old `Overlays.overlayOpened/overlayClosed`
|
|
31
|
+
* singleton, which was only called by 4 of the 10 concrete overlays. Every
|
|
32
|
+
* `A11yOverlayElement` now dispatches these uniformly on `document`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function emitOverlayOpen(name: string): boolean;
|
|
35
|
+
export declare function emitOverlayClose(name: string): boolean;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const OVERLAY_OPEN_EVENT = 'a11y-overlay-open';
|
|
2
|
+
export const OVERLAY_CLOSE_EVENT = 'a11y-overlay-close';
|
|
3
|
+
/**
|
|
4
|
+
* Page-wide state, stored on `globalThis` rather than in module scope: each
|
|
5
|
+
* standalone `dist/browser/**\/define.js` bundle inlines its own copy of this
|
|
6
|
+
* module, so a module-scoped `Set` would give every bundle loaded on the
|
|
7
|
+
* same page its own private registry (and its own scroll-lock count). A
|
|
8
|
+
* `Symbol.for()` key is shared across all of them.
|
|
9
|
+
*/
|
|
10
|
+
const STATE_KEY = Symbol.for('a11y-elements/overlay-state');
|
|
11
|
+
const store = globalThis;
|
|
12
|
+
const state = (store[STATE_KEY] ??= { openOverlays: new Set(), scrollLocks: 0 });
|
|
13
|
+
/**
|
|
14
|
+
* Tracks every currently-open overlay instance so a consumer's own SPA
|
|
15
|
+
* router (or anything else) can force-dismiss all of them, e.g. on
|
|
16
|
+
* navigation — the framework-agnostic replacement for the old
|
|
17
|
+
* `Lifecycle.onViewUnmount` global hook, which only `notification-banner`
|
|
18
|
+
* used and `snackbar` deliberately opted out of. That asymmetry is
|
|
19
|
+
* preserved: nothing here calls `dismissAllOverlays()` automatically, a
|
|
20
|
+
* consumer wires it into their own navigation event if they want it.
|
|
21
|
+
*/
|
|
22
|
+
export function registerOpenOverlay(overlay) {
|
|
23
|
+
state.openOverlays.add(overlay);
|
|
24
|
+
}
|
|
25
|
+
export function unregisterOpenOverlay(overlay) {
|
|
26
|
+
state.openOverlays.delete(overlay);
|
|
27
|
+
}
|
|
28
|
+
export function dismissAllOverlays() {
|
|
29
|
+
for (const overlay of Array.from(state.openOverlays))
|
|
30
|
+
overlay.close();
|
|
31
|
+
}
|
|
32
|
+
const NO_SCROLL_CLASS = 'a11y-no-scroll';
|
|
33
|
+
/**
|
|
34
|
+
* Reference-counted page scroll lock. Every scroll-locking overlay (modal,
|
|
35
|
+
* drawer, emergency-dialog, blocking-loader) calls `lockScroll()` once on
|
|
36
|
+
* show and `unlockScroll()` once when fully hidden, so closing one of two
|
|
37
|
+
* stacked overlays doesn't unlock the page under the one still open.
|
|
38
|
+
*/
|
|
39
|
+
export function lockScroll() {
|
|
40
|
+
if (state.scrollLocks++ === 0)
|
|
41
|
+
document.documentElement.classList.add(NO_SCROLL_CLASS);
|
|
42
|
+
}
|
|
43
|
+
export function unlockScroll() {
|
|
44
|
+
if (state.scrollLocks === 0)
|
|
45
|
+
return;
|
|
46
|
+
if (--state.scrollLocks === 0)
|
|
47
|
+
document.documentElement.classList.remove(NO_SCROLL_CLASS);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Standardized replacement for the old `Overlays.overlayOpened/overlayClosed`
|
|
51
|
+
* singleton, which was only called by 4 of the 10 concrete overlays. Every
|
|
52
|
+
* `A11yOverlayElement` now dispatches these uniformly on `document`.
|
|
53
|
+
*/
|
|
54
|
+
export function emitOverlayOpen(name) {
|
|
55
|
+
return document.dispatchEvent(new CustomEvent(OVERLAY_OPEN_EVENT, { bubbles: true, detail: { name } }));
|
|
56
|
+
}
|
|
57
|
+
export function emitOverlayClose(name) {
|
|
58
|
+
return document.dispatchEvent(new CustomEvent(OVERLAY_CLOSE_EVENT, { bubbles: true, detail: { name } }));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=overlay-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-registry.js","sourceRoot":"","sources":["../../src/core/overlay-registry.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AACtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAWxD;;;;;;GAMG;AACH,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC5D,MAAM,KAAK,GAAG,UAAgE,CAAC;AAC/E,MAAM,KAAK,GAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;AAE9F;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoB;IACtD,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAoB;IACxD,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;QAAE,OAAO,CAAC,KAAK,EAAE,CAAC;AACxE,CAAC;AAED,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,UAAU;IACxB,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC;QAAE,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,IAAI,KAAK,CAAC,WAAW,KAAK,CAAC;QAAE,OAAO;IACpC,IAAI,EAAE,KAAK,CAAC,WAAW,KAAK,CAAC;QAAE,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;AAC5F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,QAAQ,CAAC,aAAa,CAC3B,IAAI,WAAW,CAAyB,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CACjG,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,QAAQ,CAAC,aAAa,CAC3B,IAAI,WAAW,CAAyB,mBAAmB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAClG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-trusted HTML: opts out of auto-escaping when interpolated into an
|
|
3
|
+
* `html` tagged template, and stringifies back to that exact markup when
|
|
4
|
+
* assigned to `innerHTML` or concatenated. `html\`...\`` itself returns one
|
|
5
|
+
* of these, which is what makes nesting `html` calls inside another `html`
|
|
6
|
+
* call safe by construction — the inner result is never re-escaped, no
|
|
7
|
+
* caller discipline (remembering to wrap it) required.
|
|
8
|
+
*/
|
|
9
|
+
export interface Raw {
|
|
10
|
+
readonly __html: string;
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
13
|
+
/** Wraps a string as pre-trusted HTML. Use only for markup you built yourself — never for raw user input. */
|
|
14
|
+
export declare function raw(value: string): Raw;
|
|
15
|
+
/**
|
|
16
|
+
* Tagged template for building element markup. Literal template parts are
|
|
17
|
+
* trusted structure; every interpolated value is HTML-escaped by default
|
|
18
|
+
* (falsy values render as nothing, so `${cond && '<span>…</span>'}`-style
|
|
19
|
+
* conditionals work without a directive attribute). Returns a `Raw`, so
|
|
20
|
+
* nesting `html\`...\`` inside another `html\`...\`` template composes
|
|
21
|
+
* safely without needing an explicit `raw()` wrapper.
|
|
22
|
+
*/
|
|
23
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): Raw;
|
|
24
|
+
/**
|
|
25
|
+
* A `name="value"` HTML attribute, with a leading space, escaped — or
|
|
26
|
+
* nothing at all when `value` is `null`/`undefined`/`false`/`''`. Meant for
|
|
27
|
+
* building conditional attribute lists inline:
|
|
28
|
+
* `` html`<input${attr('id', id)}${flag('disabled', disabled)}>` ``
|
|
29
|
+
*/
|
|
30
|
+
export declare function attr(name: string, value: unknown): Raw;
|
|
31
|
+
/** A bare boolean attribute (e.g. `disabled`, `checked`), with a leading space, present only when `condition` is true. */
|
|
32
|
+
export declare function flag(name: string, condition: boolean | undefined): Raw;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Wraps a string as pre-trusted HTML. Use only for markup you built yourself — never for raw user input. */
|
|
2
|
+
export function raw(value) {
|
|
3
|
+
return { __html: value, toString: () => value };
|
|
4
|
+
}
|
|
5
|
+
function isRaw(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && '__html' in value;
|
|
7
|
+
}
|
|
8
|
+
function escape(value) {
|
|
9
|
+
if (value == null || value === false)
|
|
10
|
+
return '';
|
|
11
|
+
if (isRaw(value))
|
|
12
|
+
return value.__html;
|
|
13
|
+
if (Array.isArray(value))
|
|
14
|
+
return value.map(escape).join('');
|
|
15
|
+
return String(value)
|
|
16
|
+
.replace(/&/g, '&')
|
|
17
|
+
.replace(/</g, '<')
|
|
18
|
+
.replace(/>/g, '>')
|
|
19
|
+
.replace(/"/g, '"')
|
|
20
|
+
.replace(/'/g, ''');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tagged template for building element markup. Literal template parts are
|
|
24
|
+
* trusted structure; every interpolated value is HTML-escaped by default
|
|
25
|
+
* (falsy values render as nothing, so `${cond && '<span>…</span>'}`-style
|
|
26
|
+
* conditionals work without a directive attribute). Returns a `Raw`, so
|
|
27
|
+
* nesting `html\`...\`` inside another `html\`...\`` template composes
|
|
28
|
+
* safely without needing an explicit `raw()` wrapper.
|
|
29
|
+
*/
|
|
30
|
+
export function html(strings, ...values) {
|
|
31
|
+
return raw(strings.reduce((out, part, i) => out + part + escape(values[i]), ''));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A `name="value"` HTML attribute, with a leading space, escaped — or
|
|
35
|
+
* nothing at all when `value` is `null`/`undefined`/`false`/`''`. Meant for
|
|
36
|
+
* building conditional attribute lists inline:
|
|
37
|
+
* `` html`<input${attr('id', id)}${flag('disabled', disabled)}>` ``
|
|
38
|
+
*/
|
|
39
|
+
export function attr(name, value) {
|
|
40
|
+
if (value == null || value === false || value === '')
|
|
41
|
+
return raw('');
|
|
42
|
+
return raw(` ${name}="${escape(value)}"`);
|
|
43
|
+
}
|
|
44
|
+
/** A bare boolean attribute (e.g. `disabled`, `checked`), with a leading space, present only when `condition` is true. */
|
|
45
|
+
export function flag(name, condition) {
|
|
46
|
+
return raw(condition ? ` ${name}` : '');
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/core/template.ts"],"names":[],"mappings":"AAaA,6GAA6G;AAC7G,MAAM,UAAU,GAAG,CAAC,KAAa;IAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;AAClD,CAAC;AAED,SAAS,KAAK,CAAC,KAAc;IAC3B,OAAO,OAAO,KAAK,KAAK,QAAQ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AC1H,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,SAA8B;IAC/D,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `done` once `el`'s own close transition has finished, and returns a
|
|
3
|
+
* function that cancels the wait (without calling `done`).
|
|
4
|
+
*
|
|
5
|
+
* A bare `transitionend` listener isn't enough on its own:
|
|
6
|
+
* - it never fires when there's no transition at all — the default
|
|
7
|
+
* stylesheet not loaded, a `0s` duration, or a reduced-motion reset
|
|
8
|
+
* (`transition: none`) — which would leave the overlay stuck half-closed;
|
|
9
|
+
* - it bubbles, so a descendant's unrelated transition (e.g. a hovered
|
|
10
|
+
* button's background fade) would end the wait early.
|
|
11
|
+
*
|
|
12
|
+
* So: no computed transition → `done` runs synchronously; otherwise the
|
|
13
|
+
* first `transitionend` targeting `el` itself, with a timeout fallback
|
|
14
|
+
* slightly past the computed duration in case the event is never delivered.
|
|
15
|
+
*/
|
|
16
|
+
export declare function whenTransitionDone(el: Element, done: () => void): () => void;
|