a11y-elements 0.1.0 → 0.3.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/README.md +1382 -10
- package/dist/a11y.css +346 -12
- package/dist/browser/components/anchor/define.js +328 -0
- package/dist/browser/components/anchor/define.js.map +1 -0
- package/dist/browser/components/avatar/define.js +264 -0
- package/dist/browser/components/avatar/define.js.map +1 -0
- package/dist/browser/{accessibility-components → components}/checkbox/define.js +104 -7
- package/dist/browser/components/checkbox/define.js.map +1 -0
- package/dist/browser/components/checkbox-group/define.js +394 -0
- package/dist/browser/components/checkbox-group/define.js.map +1 -0
- package/dist/browser/components/file-input/define.js +1069 -0
- package/dist/browser/components/file-input/define.js.map +1 -0
- package/dist/browser/components/focusable/define.js +211 -0
- package/dist/browser/components/focusable/define.js.map +1 -0
- package/dist/browser/components/input/define.js +697 -0
- package/dist/browser/components/input/define.js.map +1 -0
- package/dist/browser/components/label/define.js +274 -0
- package/dist/browser/components/label/define.js.map +1 -0
- package/dist/browser/components/picture/define.js +411 -0
- package/dist/browser/components/picture/define.js.map +1 -0
- package/dist/browser/components/progress/define.js +239 -0
- package/dist/browser/components/progress/define.js.map +1 -0
- package/dist/browser/{accessibility-components → components}/radio-group/define.js +106 -6
- package/dist/browser/components/radio-group/define.js.map +1 -0
- package/dist/browser/{accessibility-components → components}/select/define.js +104 -6
- package/dist/browser/components/select/define.js.map +1 -0
- package/dist/browser/components/skeleton/define.js +234 -0
- package/dist/browser/components/skeleton/define.js.map +1 -0
- package/dist/browser/components/spinner/define.js +260 -0
- package/dist/browser/components/spinner/define.js.map +1 -0
- package/dist/browser/{accessibility-components → components}/switch/define.js +104 -6
- package/dist/browser/components/switch/define.js.map +1 -0
- package/dist/browser/components/textarea/define.js +697 -0
- package/dist/browser/components/textarea/define.js.map +1 -0
- package/dist/browser/components/visually-hidden/define.js +195 -0
- package/dist/browser/components/visually-hidden/define.js.map +1 -0
- package/dist/browser/overlays/blocking-loader/define.js +182 -13
- package/dist/browser/overlays/blocking-loader/define.js.map +1 -1
- package/dist/browser/overlays/context-menu/define.js +300 -122
- package/dist/browser/overlays/context-menu/define.js.map +1 -1
- package/dist/browser/overlays/drawer/define.js +207 -14
- package/dist/browser/overlays/drawer/define.js.map +1 -1
- package/dist/browser/overlays/dropdown/define.js +300 -122
- package/dist/browser/overlays/dropdown/define.js.map +1 -1
- package/dist/browser/overlays/emergency-dialog/define.js +207 -14
- package/dist/browser/overlays/emergency-dialog/define.js.map +1 -1
- package/dist/browser/overlays/modal/define.js +207 -15
- package/dist/browser/overlays/modal/define.js.map +1 -1
- package/dist/browser/overlays/notification-banner/define.js +183 -15
- package/dist/browser/overlays/notification-banner/define.js.map +1 -1
- package/dist/browser/overlays/popover/define.js +189 -12
- package/dist/browser/overlays/popover/define.js.map +1 -1
- package/dist/browser/overlays/snackbar/define.js +160 -15
- package/dist/browser/overlays/snackbar/define.js.map +1 -1
- package/dist/browser/overlays/tooltip/define.js +206 -15
- package/dist/browser/overlays/tooltip/define.js.map +1 -1
- package/dist/{accessibility-components → components}/anchor/anchor.element.d.ts +12 -4
- package/dist/{accessibility-components → components}/anchor/anchor.element.js +56 -11
- package/dist/components/anchor/anchor.element.js.map +1 -0
- package/dist/{accessibility-components → components}/anchor/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/anchor/define.js +2 -0
- package/dist/components/anchor/define.js.map +1 -0
- package/dist/{accessibility-components → components}/avatar/avatar.element.d.ts +2 -0
- package/dist/{accessibility-components → components}/avatar/avatar.element.js +10 -3
- package/dist/components/avatar/avatar.element.js.map +1 -0
- package/dist/{accessibility-components → components}/avatar/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/avatar/define.js +2 -0
- package/dist/components/avatar/define.js.map +1 -0
- package/dist/{accessibility-components → components}/checkbox/checkbox.element.js +0 -2
- package/dist/components/checkbox/checkbox.element.js.map +1 -0
- package/dist/{accessibility-components → components}/checkbox/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/checkbox/define.js +2 -0
- package/dist/components/checkbox/define.js.map +1 -0
- package/dist/components/checkbox-group/checkbox-group.element.d.ts +51 -0
- package/dist/components/checkbox-group/checkbox-group.element.js +189 -0
- package/dist/components/checkbox-group/checkbox-group.element.js.map +1 -0
- package/dist/components/checkbox-group/define.d.ts +8 -0
- package/dist/components/checkbox-group/define.js +8 -0
- package/dist/components/checkbox-group/define.js.map +1 -0
- package/dist/components/file-input/define.d.ts +9 -0
- package/dist/components/file-input/define.js +9 -0
- package/dist/components/file-input/define.js.map +1 -0
- package/dist/components/file-input/file-input.element.d.ts +95 -0
- package/dist/components/file-input/file-input.element.js +471 -0
- package/dist/components/file-input/file-input.element.js.map +1 -0
- package/dist/{accessibility-components → components}/focusable/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/focusable/define.js +2 -0
- package/dist/components/focusable/define.js.map +1 -0
- package/dist/components/focusable/focusable.element.js.map +1 -0
- package/dist/components/input/define.d.ts +9 -0
- package/dist/components/input/define.js +9 -0
- package/dist/components/input/define.js.map +1 -0
- package/dist/components/input/input.element.d.ts +22 -0
- package/dist/components/input/input.element.js +23 -0
- package/dist/components/input/input.element.js.map +1 -0
- package/dist/components/label/define.d.ts +8 -0
- package/dist/components/label/define.js +8 -0
- package/dist/components/label/define.js.map +1 -0
- package/dist/components/label/label.element.d.ts +32 -0
- package/dist/components/label/label.element.js +62 -0
- package/dist/components/label/label.element.js.map +1 -0
- package/dist/{accessibility-components → components}/picture/define.d.ts +2 -0
- package/dist/{accessibility-components → components}/picture/define.js +2 -0
- package/dist/components/picture/define.js.map +1 -0
- package/dist/components/picture/picture.element.d.ts +89 -0
- package/dist/components/picture/picture.element.js +235 -0
- package/dist/components/picture/picture.element.js.map +1 -0
- package/dist/{accessibility-components → components}/progress/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/progress/define.js +2 -0
- package/dist/components/progress/define.js.map +1 -0
- package/dist/{accessibility-components → components}/progress/progress.element.d.ts +1 -0
- package/dist/{accessibility-components → components}/progress/progress.element.js +5 -1
- package/dist/components/progress/progress.element.js.map +1 -0
- package/dist/{accessibility-components → components}/radio-group/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/radio-group/define.js +2 -0
- package/dist/components/radio-group/define.js.map +1 -0
- package/dist/{accessibility-components → components}/radio-group/radio-group.element.js +4 -1
- package/dist/components/radio-group/radio-group.element.js.map +1 -0
- package/dist/{accessibility-components → components}/select/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/select/define.js +2 -0
- package/dist/components/select/define.js.map +1 -0
- package/dist/{accessibility-components → components}/select/select.element.js +0 -1
- package/dist/components/select/select.element.js.map +1 -0
- package/dist/{accessibility-components → components}/skeleton/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/skeleton/define.js +2 -0
- package/dist/components/skeleton/define.js.map +1 -0
- package/dist/components/skeleton/skeleton.element.js.map +1 -0
- package/dist/{accessibility-components → components}/spinner/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/spinner/define.js +2 -0
- package/dist/components/spinner/define.js.map +1 -0
- package/dist/{accessibility-components → components}/spinner/spinner.element.d.ts +1 -0
- package/dist/{accessibility-components → components}/spinner/spinner.element.js +5 -1
- package/dist/components/spinner/spinner.element.js.map +1 -0
- package/dist/{accessibility-components → components}/switch/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/switch/define.js +2 -0
- package/dist/components/switch/define.js.map +1 -0
- package/dist/{accessibility-components → components}/switch/switch.element.js +0 -1
- package/dist/components/switch/switch.element.js.map +1 -0
- package/dist/components/textarea/define.d.ts +9 -0
- package/dist/components/textarea/define.js +9 -0
- package/dist/components/textarea/define.js.map +1 -0
- package/dist/components/textarea/textarea.element.d.ts +18 -0
- package/dist/components/textarea/textarea.element.js +19 -0
- package/dist/components/textarea/textarea.element.js.map +1 -0
- package/dist/{accessibility-components → components}/visually-hidden/define.d.ts +1 -0
- package/dist/{accessibility-components → components}/visually-hidden/define.js +2 -0
- package/dist/components/visually-hidden/define.js.map +1 -0
- package/dist/components/visually-hidden/visually-hidden.element.js.map +1 -0
- package/dist/core/a11y-element.d.ts +29 -1
- package/dist/core/a11y-element.js +65 -2
- package/dist/core/a11y-element.js.map +1 -1
- package/dist/core/a11y-field-element.d.ts +86 -0
- package/dist/core/a11y-field-element.js +240 -0
- package/dist/core/a11y-field-element.js.map +1 -0
- package/dist/core/a11y-overlay-element.d.ts +3 -1
- package/dist/core/a11y-overlay-element.js +12 -4
- package/dist/core/a11y-overlay-element.js.map +1 -1
- package/dist/core/a11y-wrapper-element.js +1 -0
- package/dist/core/a11y-wrapper-element.js.map +1 -1
- package/dist/core/dom-sync.d.ts +6 -0
- package/dist/core/dom-sync.js +13 -0
- package/dist/core/dom-sync.js.map +1 -1
- package/dist/core/field.d.ts +80 -0
- package/dist/core/field.js +256 -0
- package/dist/core/field.js.map +1 -0
- package/dist/core/focus-trap.d.ts +22 -0
- package/dist/core/focus-trap.js +98 -5
- package/dist/core/focus-trap.js.map +1 -1
- package/dist/core/ids.d.ts +2 -0
- package/dist/core/ids.js +18 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/overlay-registry.d.ts +12 -0
- package/dist/core/overlay-registry.js +29 -1
- package/dist/core/overlay-registry.js.map +1 -1
- package/dist/core/strings.d.ts +63 -0
- package/dist/core/strings.js +59 -0
- package/dist/core/strings.js.map +1 -0
- package/dist/overlays/blocking-loader/blocking-loader.element.d.ts +1 -0
- package/dist/overlays/blocking-loader/blocking-loader.element.js +8 -2
- package/dist/overlays/blocking-loader/blocking-loader.element.js.map +1 -1
- package/dist/overlays/blocking-loader/define.d.ts +3 -2
- package/dist/overlays/blocking-loader/define.js +4 -3
- package/dist/overlays/blocking-loader/define.js.map +1 -1
- package/dist/overlays/context-menu/define.d.ts +2 -1
- package/dist/overlays/context-menu/define.js +3 -2
- package/dist/overlays/context-menu/define.js.map +1 -1
- package/dist/overlays/core/a11y-menu-overlay-element.js +3 -2
- package/dist/overlays/core/a11y-menu-overlay-element.js.map +1 -1
- package/dist/overlays/core/a11y-modal-overlay-element.d.ts +7 -0
- package/dist/overlays/core/a11y-modal-overlay-element.js +19 -2
- package/dist/overlays/core/a11y-modal-overlay-element.js.map +1 -1
- package/dist/overlays/core/a11y-passive-overlay-element.d.ts +11 -3
- package/dist/overlays/core/a11y-passive-overlay-element.js +40 -13
- package/dist/overlays/core/a11y-passive-overlay-element.js.map +1 -1
- package/dist/overlays/drawer/define.d.ts +2 -1
- package/dist/overlays/drawer/define.js +3 -2
- package/dist/overlays/drawer/define.js.map +1 -1
- package/dist/overlays/drawer/drawer.element.js +0 -1
- package/dist/overlays/drawer/drawer.element.js.map +1 -1
- package/dist/overlays/dropdown/define.d.ts +2 -1
- package/dist/overlays/dropdown/define.js +3 -2
- package/dist/overlays/dropdown/define.js.map +1 -1
- package/dist/overlays/emergency-dialog/define.d.ts +2 -1
- package/dist/overlays/emergency-dialog/define.js +3 -2
- package/dist/overlays/emergency-dialog/define.js.map +1 -1
- package/dist/overlays/emergency-dialog/emergency-dialog.element.js +0 -1
- package/dist/overlays/emergency-dialog/emergency-dialog.element.js.map +1 -1
- package/dist/overlays/modal/define.d.ts +2 -1
- package/dist/overlays/modal/define.js +3 -2
- package/dist/overlays/modal/define.js.map +1 -1
- package/dist/overlays/modal/modal.element.js +0 -2
- package/dist/overlays/modal/modal.element.js.map +1 -1
- package/dist/overlays/notification-banner/define.d.ts +2 -0
- package/dist/overlays/notification-banner/define.js +3 -0
- package/dist/overlays/notification-banner/define.js.map +1 -1
- package/dist/overlays/notification-banner/notification-banner.element.d.ts +11 -0
- package/dist/overlays/notification-banner/notification-banner.element.js +27 -1
- package/dist/overlays/notification-banner/notification-banner.element.js.map +1 -1
- package/dist/overlays/popover/define.d.ts +2 -1
- package/dist/overlays/popover/define.js +3 -2
- package/dist/overlays/popover/define.js.map +1 -1
- package/dist/overlays/popover/popover.element.js +0 -1
- package/dist/overlays/popover/popover.element.js.map +1 -1
- package/dist/overlays/snackbar/define.d.ts +2 -0
- package/dist/overlays/snackbar/define.js +3 -0
- package/dist/overlays/snackbar/define.js.map +1 -1
- package/dist/overlays/snackbar/snackbar.element.d.ts +1 -1
- package/dist/overlays/tooltip/define.d.ts +2 -1
- package/dist/overlays/tooltip/define.js +3 -2
- package/dist/overlays/tooltip/define.js.map +1 -1
- package/dist/overlays/tooltip/tooltip.element.js +2 -7
- package/dist/overlays/tooltip/tooltip.element.js.map +1 -1
- package/package.json +10 -10
- package/dist/accessibility-components/anchor/anchor.element.js.map +0 -1
- package/dist/accessibility-components/anchor/define.js.map +0 -1
- package/dist/accessibility-components/avatar/avatar.element.js.map +0 -1
- package/dist/accessibility-components/avatar/define.js.map +0 -1
- package/dist/accessibility-components/checkbox/checkbox.element.js.map +0 -1
- package/dist/accessibility-components/checkbox/define.js.map +0 -1
- package/dist/accessibility-components/focusable/define.js.map +0 -1
- package/dist/accessibility-components/focusable/focusable.element.js.map +0 -1
- package/dist/accessibility-components/picture/define.js.map +0 -1
- package/dist/accessibility-components/picture/picture.element.d.ts +0 -23
- package/dist/accessibility-components/picture/picture.element.js +0 -43
- package/dist/accessibility-components/picture/picture.element.js.map +0 -1
- package/dist/accessibility-components/progress/define.js.map +0 -1
- package/dist/accessibility-components/progress/progress.element.js.map +0 -1
- package/dist/accessibility-components/radio-group/define.js.map +0 -1
- package/dist/accessibility-components/radio-group/radio-group.element.js.map +0 -1
- package/dist/accessibility-components/select/define.js.map +0 -1
- package/dist/accessibility-components/select/select.element.js.map +0 -1
- package/dist/accessibility-components/skeleton/define.js.map +0 -1
- package/dist/accessibility-components/skeleton/skeleton.element.js.map +0 -1
- package/dist/accessibility-components/spinner/define.js.map +0 -1
- package/dist/accessibility-components/spinner/spinner.element.js.map +0 -1
- package/dist/accessibility-components/switch/define.js.map +0 -1
- package/dist/accessibility-components/switch/switch.element.js.map +0 -1
- package/dist/accessibility-components/visually-hidden/define.js.map +0 -1
- package/dist/accessibility-components/visually-hidden/visually-hidden.element.js.map +0 -1
- package/dist/browser/accessibility-components/anchor/define.js +0 -192
- package/dist/browser/accessibility-components/anchor/define.js.map +0 -1
- package/dist/browser/accessibility-components/avatar/define.js +0 -159
- package/dist/browser/accessibility-components/avatar/define.js.map +0 -1
- package/dist/browser/accessibility-components/checkbox/define.js.map +0 -1
- package/dist/browser/accessibility-components/focusable/define.js +0 -113
- package/dist/browser/accessibility-components/focusable/define.js.map +0 -1
- package/dist/browser/accessibility-components/picture/define.js +0 -156
- package/dist/browser/accessibility-components/picture/define.js.map +0 -1
- package/dist/browser/accessibility-components/progress/define.js +0 -135
- package/dist/browser/accessibility-components/progress/define.js.map +0 -1
- package/dist/browser/accessibility-components/radio-group/define.js.map +0 -1
- package/dist/browser/accessibility-components/select/define.js.map +0 -1
- package/dist/browser/accessibility-components/skeleton/define.js +0 -136
- package/dist/browser/accessibility-components/skeleton/define.js.map +0 -1
- package/dist/browser/accessibility-components/spinner/define.js +0 -156
- package/dist/browser/accessibility-components/spinner/define.js.map +0 -1
- package/dist/browser/accessibility-components/switch/define.js.map +0 -1
- package/dist/browser/accessibility-components/visually-hidden/define.js +0 -97
- package/dist/browser/accessibility-components/visually-hidden/define.js.map +0 -1
- /package/dist/{accessibility-components → components}/checkbox/checkbox.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/focusable/focusable.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/focusable/focusable.element.js +0 -0
- /package/dist/{accessibility-components → components}/radio-group/radio-group.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/select/select.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/skeleton/skeleton.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/skeleton/skeleton.element.js +0 -0
- /package/dist/{accessibility-components → components}/switch/switch.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/visually-hidden/visually-hidden.element.d.ts +0 -0
- /package/dist/{accessibility-components → components}/visually-hidden/visually-hidden.element.js +0 -0
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// src/core/a11y-element.ts
|
|
2
|
-
var A11yElement = class extends HTMLElement {
|
|
3
|
-
_connected = false;
|
|
4
|
-
_listeners = [];
|
|
5
|
-
_updating = false;
|
|
6
|
-
connectedCallback() {
|
|
7
|
-
this._connected = true;
|
|
8
|
-
this.update();
|
|
9
|
-
}
|
|
10
|
-
disconnectedCallback() {
|
|
11
|
-
this._connected = false;
|
|
12
|
-
this._cleanupListeners();
|
|
13
|
-
this.onDisconnect?.();
|
|
14
|
-
}
|
|
15
|
-
attributeChangedCallback(_name, oldValue, newValue) {
|
|
16
|
-
if (oldValue === newValue || !this._connected) return;
|
|
17
|
-
this.update();
|
|
18
|
-
}
|
|
19
|
-
update() {
|
|
20
|
-
if (this._updating) return;
|
|
21
|
-
this._updating = true;
|
|
22
|
-
try {
|
|
23
|
-
this._cleanupListeners();
|
|
24
|
-
this.onBeforeRender?.();
|
|
25
|
-
this.innerHTML = String(this.render());
|
|
26
|
-
this.onAfterRender?.();
|
|
27
|
-
} finally {
|
|
28
|
-
this._updating = false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Adds a listener and tracks it for automatic removal on the next render
|
|
33
|
-
* and on disconnect — the direct replacement for the old framework's
|
|
34
|
-
* `[el, type, handler]` cleanup-array convention.
|
|
35
|
-
*/
|
|
36
|
-
listen(target, type, handler, options) {
|
|
37
|
-
target.addEventListener(type, handler, options);
|
|
38
|
-
this._listeners.push([target, type, handler, options]);
|
|
39
|
-
}
|
|
40
|
-
_cleanupListeners() {
|
|
41
|
-
for (const [target, type, handler, options] of this._listeners) {
|
|
42
|
-
target.removeEventListener(type, handler, options);
|
|
43
|
-
}
|
|
44
|
-
this._listeners = [];
|
|
45
|
-
}
|
|
46
|
-
/** Dispatches a bubbling CustomEvent from this element. */
|
|
47
|
-
emit(type, detail) {
|
|
48
|
-
return this.dispatchEvent(new CustomEvent(type, { bubbles: true, detail }));
|
|
49
|
-
}
|
|
50
|
-
// --- small attribute-reflection helpers, shared across components ---
|
|
51
|
-
stringAttr(name, fallback = "") {
|
|
52
|
-
return this.getAttribute(name) ?? fallback;
|
|
53
|
-
}
|
|
54
|
-
optionalStringAttr(name) {
|
|
55
|
-
return this.getAttribute(name) ?? void 0;
|
|
56
|
-
}
|
|
57
|
-
boolAttr(name) {
|
|
58
|
-
return this.hasAttribute(name);
|
|
59
|
-
}
|
|
60
|
-
numberAttr(name, fallback) {
|
|
61
|
-
const value = this.getAttribute(name);
|
|
62
|
-
if (value == null) return fallback;
|
|
63
|
-
const parsed = Number(value);
|
|
64
|
-
return Number.isNaN(parsed) ? fallback : parsed;
|
|
65
|
-
}
|
|
66
|
-
setBoolAttr(name, value) {
|
|
67
|
-
if (value) this.setAttribute(name, "");
|
|
68
|
-
else this.removeAttribute(name);
|
|
69
|
-
}
|
|
70
|
-
/** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */
|
|
71
|
-
setCssVar(name, value) {
|
|
72
|
-
if (value) this.style.setProperty(name, value);
|
|
73
|
-
else this.style.removeProperty(name);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/core/a11y-wrapper-element.ts
|
|
78
|
-
var A11yWrapperElement = class extends A11yElement {
|
|
79
|
-
_observer = null;
|
|
80
|
-
/** Nodes already given their listeners since the last connect — see `wireOnce()`. */
|
|
81
|
-
_wiredNodes = /* @__PURE__ */ new WeakSet();
|
|
82
|
-
connectedCallback() {
|
|
83
|
-
this._connected = true;
|
|
84
|
-
this._sync();
|
|
85
|
-
this._observer = new MutationObserver(() => this._sync());
|
|
86
|
-
this._observer.observe(this, this.observerInit());
|
|
87
|
-
}
|
|
88
|
-
disconnectedCallback() {
|
|
89
|
-
this._observer?.disconnect();
|
|
90
|
-
this._observer = null;
|
|
91
|
-
super.disconnectedCallback();
|
|
92
|
-
this._wiredNodes = /* @__PURE__ */ new WeakSet();
|
|
93
|
-
}
|
|
94
|
-
attributeChangedCallback(_name, oldValue, newValue) {
|
|
95
|
-
if (oldValue === newValue || !this._connected) return;
|
|
96
|
-
this._sync();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Runs `wire` the first time `node` is seen since this element was last
|
|
100
|
-
* connected. `_sync()` runs on every mutation, so listener setup must be
|
|
101
|
-
* idempotent — but those listeners (added via `listen()`) are all removed
|
|
102
|
-
* on disconnect, so the "already wired" memory must reset with them, or a
|
|
103
|
-
* reparented element (disconnect + connect) would silently stop firing.
|
|
104
|
-
*/
|
|
105
|
-
wireOnce(node, wire) {
|
|
106
|
-
if (this._wiredNodes.has(node)) return;
|
|
107
|
-
this._wiredNodes.add(node);
|
|
108
|
-
wire();
|
|
109
|
-
}
|
|
110
|
-
/** What to watch for changes worth re-syncing on. Override for a narrower/wider scope. */
|
|
111
|
-
observerInit() {
|
|
112
|
-
return { childList: true, subtree: true, attributes: true };
|
|
113
|
-
}
|
|
114
|
-
/** Unused — content is the author's own children, never replaced. */
|
|
115
|
-
render() {
|
|
116
|
-
return "";
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// src/core/dom-sync.ts
|
|
121
|
-
function syncAttr(el, name, value) {
|
|
122
|
-
if (value == null) {
|
|
123
|
-
if (el.hasAttribute(name)) el.removeAttribute(name);
|
|
124
|
-
} else if (el.getAttribute(name) !== value) {
|
|
125
|
-
el.setAttribute(name, value);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function syncClass(el, name, present) {
|
|
129
|
-
if (el.classList.contains(name) !== present) el.classList.toggle(name, present);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// src/accessibility-components/picture/picture.element.ts
|
|
133
|
-
var PictureElement = class extends A11yWrapperElement {
|
|
134
|
-
observerInit() {
|
|
135
|
-
return { childList: true, subtree: true, attributes: true, attributeFilter: ["alt"] };
|
|
136
|
-
}
|
|
137
|
-
_sync() {
|
|
138
|
-
const img = this.querySelector("img");
|
|
139
|
-
if (!img) return;
|
|
140
|
-
syncClass(this, "a11y-picture", true);
|
|
141
|
-
syncAttr(this, "role", "figure");
|
|
142
|
-
const caption = this.querySelector("figcaption");
|
|
143
|
-
const hasCaption = !!caption?.textContent?.trim();
|
|
144
|
-
const isDecorative = img.getAttribute("alt") === "" && !hasCaption;
|
|
145
|
-
syncAttr(this, "aria-hidden", isDecorative ? "true" : null);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// src/accessibility-components/picture/define.ts
|
|
150
|
-
if (!customElements.get("a11y-picture")) {
|
|
151
|
-
customElements.define("a11y-picture", PictureElement);
|
|
152
|
-
}
|
|
153
|
-
export {
|
|
154
|
-
PictureElement
|
|
155
|
-
};
|
|
156
|
-
//# sourceMappingURL=define.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/a11y-element.ts","../../../../src/core/a11y-wrapper-element.ts","../../../../src/core/dom-sync.ts","../../../../src/accessibility-components/picture/picture.element.ts","../../../../src/accessibility-components/picture/define.ts"],"sourcesContent":["import type { Raw } from './template.js';\n\ntype Listener = [target: EventTarget, type: string, handler: EventListener, options?: AddEventListenerOptions | boolean];\n\n/**\n * Base class for every element in this library. Light DOM only — elements\n * render real child markup styled by the consumer's own CSS, not a shadow\n * root.\n *\n * Lifecycle mirrors the old `onBeforeRender -> innerHTML = template ->\n * onAfterRender` pipeline this library used to run through a proprietary\n * framework, just mapped onto native custom-element callbacks:\n *\n * connectedCallback -> first update()\n * attributeChangedCallback -> update() for any observed attribute change\n * disconnectedCallback -> remove all tracked listeners, then onDisconnect()\n *\n * Subclasses list attributes to watch via `static observedAttributes` and\n * implement `render()` to return the markup for `this.innerHTML`. Attribute/\n * property setters that need to reflect into the DOM should just mutate the\n * attribute — `attributeChangedCallback` re-renders synchronously while\n * connected, so state and DOM never drift out of sync across a render.\n */\nexport abstract class A11yElement extends HTMLElement {\n protected _connected = false;\n private _listeners: Listener[] = [];\n private _updating = false;\n\n connectedCallback(): void {\n this._connected = true;\n this.update();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this._cleanupListeners();\n this.onDisconnect?.();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this.update();\n }\n\n protected update(): void {\n // Re-entrancy guard: a listener/hook that itself mutates an observed\n // attribute during render must not trigger a nested render.\n if (this._updating) return;\n this._updating = true;\n try {\n this._cleanupListeners();\n this.onBeforeRender?.();\n this.innerHTML = String(this.render());\n this.onAfterRender?.();\n } finally {\n this._updating = false;\n }\n }\n\n /** Returns the markup to set as `this.innerHTML` on every render — a plain string, or an `html\\`...\\`` result. */\n protected abstract render(): string | Raw;\n\n /** Runs before `render()`. Typical use: set root-level classes/ARIA/CSS custom properties. */\n protected onBeforeRender?(): void;\n\n /** Runs after `render()` replaces `innerHTML`. Typical use: query into fresh markup, wire listeners, set DOM-only properties. */\n protected onAfterRender?(): void;\n\n /** Runs once, after listener cleanup, when the element leaves the DOM. */\n protected onDisconnect?(): void;\n\n /**\n * Adds a listener and tracks it for automatic removal on the next render\n * and on disconnect — the direct replacement for the old framework's\n * `[el, type, handler]` cleanup-array convention.\n */\n protected listen(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions | boolean,\n ): void {\n target.addEventListener(type, handler, options);\n this._listeners.push([target, type, handler, options]);\n }\n\n private _cleanupListeners(): void {\n for (const [target, type, handler, options] of this._listeners) {\n target.removeEventListener(type, handler, options);\n }\n this._listeners = [];\n }\n\n /** Dispatches a bubbling CustomEvent from this element. */\n protected emit<T = unknown>(type: string, detail?: T): boolean {\n return this.dispatchEvent(new CustomEvent<T>(type, { bubbles: true, detail: detail as T }));\n }\n\n // --- small attribute-reflection helpers, shared across components ---\n\n protected stringAttr(name: string, fallback = ''): string {\n return this.getAttribute(name) ?? fallback;\n }\n\n protected optionalStringAttr(name: string): string | undefined {\n return this.getAttribute(name) ?? undefined;\n }\n\n protected boolAttr(name: string): boolean {\n return this.hasAttribute(name);\n }\n\n protected numberAttr(name: string, fallback: number): number {\n const value = this.getAttribute(name);\n if (value == null) return fallback;\n const parsed = Number(value);\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n protected setBoolAttr(name: string, value: boolean): void {\n if (value) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n /** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */\n protected setCssVar(name: string, value: string | null | undefined): void {\n if (value) this.style.setProperty(name, value);\n else this.style.removeProperty(name);\n }\n}\n","import { A11yElement } from './a11y-element.js';\n\n/**\n * Base for elements that enhance real, consumer-authored light-DOM children\n * instead of generating their own markup from a template string — e.g. a\n * `<a11y-picture>` wrapping a real `<picture>`/`<img>`/`<figcaption>`, or\n * `<a11y-select>` wrapping a real `<select>`/`<option>`s.\n *\n * Unlike `A11yElement`, this never sets `innerHTML` from a `render()`\n * string — that would destroy the author's children — so it opts out of the\n * normal render pipeline and instead re-syncs (`_sync()`) from two sources:\n *\n * - **This element's own observed attributes** (e.g. `label`, `legend`),\n * listed via `static observedAttributes` same as any other element —\n * these re-sync *synchronously*, matching every other element in this\n * library, so `el.setAttribute('label', 'x')` takes effect immediately.\n * - **Everything else** (children added/removed, an attribute changing on\n * one of *those* children) — light DOM has no `slotchange`, so a\n * `MutationObserver` is the equivalent, necessarily asynchronous (a real\n * microtask/task delay after the mutation).\n *\n * `_sync()` runs inside that `MutationObserver` callback, so every DOM write\n * it makes must be guarded (see `core/dom-sync.ts`) — `setAttribute`/\n * `classList.add`/`textContent =` all queue a mutation record even when the\n * value is unchanged, and an unguarded write would retrigger the observer\n * forever.\n */\nexport abstract class A11yWrapperElement extends A11yElement {\n private _observer: MutationObserver | null = null;\n /** Nodes already given their listeners since the last connect — see `wireOnce()`. */\n private _wiredNodes = new WeakSet<Node>();\n\n override connectedCallback(): void {\n this._connected = true;\n this._sync();\n this._observer = new MutationObserver(() => this._sync());\n this._observer.observe(this, this.observerInit());\n }\n\n override disconnectedCallback(): void {\n this._observer?.disconnect();\n this._observer = null;\n super.disconnectedCallback(); // removes every `listen()` listener…\n this._wiredNodes = new WeakSet(); // …so the next connect must wire them again\n }\n\n override attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this._sync();\n }\n\n /**\n * Runs `wire` the first time `node` is seen since this element was last\n * connected. `_sync()` runs on every mutation, so listener setup must be\n * idempotent — but those listeners (added via `listen()`) are all removed\n * on disconnect, so the \"already wired\" memory must reset with them, or a\n * reparented element (disconnect + connect) would silently stop firing.\n */\n protected wireOnce(node: Node, wire: () => void): void {\n if (this._wiredNodes.has(node)) return;\n this._wiredNodes.add(node);\n wire();\n }\n\n /** What to watch for changes worth re-syncing on. Override for a narrower/wider scope. */\n protected observerInit(): MutationObserverInit {\n return { childList: true, subtree: true, attributes: true };\n }\n\n /** Re-derive this element's own attributes/classes from its current children. */\n protected abstract _sync(): void;\n\n /** Unused — content is the author's own children, never replaced. */\n protected override render(): string {\n return '';\n }\n}\n","/**\n * Guarded DOM writes for use inside `A11yWrapperElement._sync()` methods (or\n * anywhere else re-syncing against a live MutationObserver).\n *\n * `setAttribute`/`removeAttribute`/`classList.add`/`classList.remove`/\n * `textContent =` all queue a mutation record unconditionally — even when\n * the value being written is identical to what's already there. Call one of\n * these unguarded inside a MutationObserver callback that's itself watching\n * the element being written to, and every \"no-op\" write retriggers the\n * observer, forever. These helpers check first, so a `_sync()` call that\n * changes nothing produces zero mutations and the observer loop terminates.\n */\n\nexport function syncText(el: Element, text: string): void {\n if (el.textContent !== text) el.textContent = text;\n}\n\nexport function syncAttr(el: Element, name: string, value: string | null | undefined): void {\n if (value == null) {\n if (el.hasAttribute(name)) el.removeAttribute(name);\n } else if (el.getAttribute(name) !== value) {\n el.setAttribute(name, value);\n }\n}\n\nexport function syncClass(el: Element, name: string, present: boolean): void {\n if (el.classList.contains(name) !== present) el.classList.toggle(name, present);\n}\n","import { A11yWrapperElement } from '../../core/a11y-wrapper-element.js';\nimport { syncAttr, syncClass } from '../../core/dom-sync.js';\n\n/**\n * An accessible figure wrapper around a real `<picture>`/`<img>` (and an\n * optional `<figcaption>`) authored directly by the consumer — native HTML\n * already handles responsive source selection via real `<source>` children,\n * so this element's only job is accessibility: it toggles `aria-hidden`\n * automatically when the image is decorative (an empty `alt` and no\n * caption), the same rule the old framework-driven version used.\n *\n * ```html\n * <a11y-picture>\n * <picture>\n * <source srcset=\"hero.webp\" type=\"image/webp\">\n * <img src=\"hero.jpg\" alt=\"Sunset over the Rockies\" loading=\"lazy\" decoding=\"async\">\n * </picture>\n * <figcaption>Sunset over the Rockies</figcaption>\n * </a11y-picture>\n * ```\n */\nexport class PictureElement extends A11yWrapperElement {\n protected override observerInit(): MutationObserverInit {\n return { childList: true, subtree: true, attributes: true, attributeFilter: ['alt'] };\n }\n\n protected override _sync(): void {\n const img = this.querySelector('img');\n if (!img) return;\n\n // Guarded writes: this runs inside a MutationObserver callback watching\n // this subtree, and setAttribute/classList.add queue a mutation record\n // even when the value is unchanged — unguarded, that retriggers the\n // observer forever. The attributeFilter above already keeps this element's\n // own writes (role/class/aria-hidden) out of scope, but staying guarded\n // here too means that isn't load-bearing for correctness.\n syncClass(this, 'a11y-picture', true);\n syncAttr(this, 'role', 'figure');\n\n const caption = this.querySelector('figcaption');\n const hasCaption = !!caption?.textContent?.trim();\n const isDecorative = img.getAttribute('alt') === '' && !hasCaption;\n\n syncAttr(this, 'aria-hidden', isDecorative ? 'true' : null);\n }\n}\n","import { PictureElement } from './picture.element.js';\n\nif (!customElements.get('a11y-picture')) {\n customElements.define('a11y-picture', PictureElement);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-picture': PictureElement;\n }\n}\n\nexport { PictureElement };\n"],"mappings":";AAuBO,IAAe,cAAf,cAAmC,YAAY;AAAA,EAC1C,aAAa;AAAA,EACf,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEpB,oBAA0B;AACxB,SAAK,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O,SAAS,SAAS,IAAa,MAAc,OAAwC;AAC1F,MAAI,SAAS,MAAM;AACjB,QAAI,GAAG,aAAa,IAAI,EAAG,IAAG,gBAAgB,IAAI;AAAA,EACpD,WAAW,GAAG,aAAa,IAAI,MAAM,OAAO;AAC1C,OAAG,aAAa,MAAM,KAAK;AAAA,EAC7B;AACF;AAEO,SAAS,UAAU,IAAa,MAAc,SAAwB;AAC3E,MAAI,GAAG,UAAU,SAAS,IAAI,MAAM,QAAS,IAAG,UAAU,OAAO,MAAM,OAAO;AAChF;;;ACNO,IAAM,iBAAN,cAA6B,mBAAmB;AAAA,EAClC,eAAqC;AACtD,WAAO,EAAE,WAAW,MAAM,SAAS,MAAM,YAAY,MAAM,iBAAiB,CAAC,KAAK,EAAE;AAAA,EACtF;AAAA,EAEmB,QAAc;AAC/B,UAAM,MAAM,KAAK,cAAc,KAAK;AACpC,QAAI,CAAC,IAAK;AAQV,cAAU,MAAM,gBAAgB,IAAI;AACpC,aAAS,MAAM,QAAQ,QAAQ;AAE/B,UAAM,UAAU,KAAK,cAAc,YAAY;AAC/C,UAAM,aAAa,CAAC,CAAC,SAAS,aAAa,KAAK;AAChD,UAAM,eAAe,IAAI,aAAa,KAAK,MAAM,MAAM,CAAC;AAExD,aAAS,MAAM,eAAe,eAAe,SAAS,IAAI;AAAA,EAC5D;AACF;;;AC3CA,IAAI,CAAC,eAAe,IAAI,cAAc,GAAG;AACvC,iBAAe,OAAO,gBAAgB,cAAc;AACtD;","names":[]}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// src/core/a11y-element.ts
|
|
2
|
-
var A11yElement = class extends HTMLElement {
|
|
3
|
-
_connected = false;
|
|
4
|
-
_listeners = [];
|
|
5
|
-
_updating = false;
|
|
6
|
-
connectedCallback() {
|
|
7
|
-
this._connected = true;
|
|
8
|
-
this.update();
|
|
9
|
-
}
|
|
10
|
-
disconnectedCallback() {
|
|
11
|
-
this._connected = false;
|
|
12
|
-
this._cleanupListeners();
|
|
13
|
-
this.onDisconnect?.();
|
|
14
|
-
}
|
|
15
|
-
attributeChangedCallback(_name, oldValue, newValue) {
|
|
16
|
-
if (oldValue === newValue || !this._connected) return;
|
|
17
|
-
this.update();
|
|
18
|
-
}
|
|
19
|
-
update() {
|
|
20
|
-
if (this._updating) return;
|
|
21
|
-
this._updating = true;
|
|
22
|
-
try {
|
|
23
|
-
this._cleanupListeners();
|
|
24
|
-
this.onBeforeRender?.();
|
|
25
|
-
this.innerHTML = String(this.render());
|
|
26
|
-
this.onAfterRender?.();
|
|
27
|
-
} finally {
|
|
28
|
-
this._updating = false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Adds a listener and tracks it for automatic removal on the next render
|
|
33
|
-
* and on disconnect — the direct replacement for the old framework's
|
|
34
|
-
* `[el, type, handler]` cleanup-array convention.
|
|
35
|
-
*/
|
|
36
|
-
listen(target, type, handler, options) {
|
|
37
|
-
target.addEventListener(type, handler, options);
|
|
38
|
-
this._listeners.push([target, type, handler, options]);
|
|
39
|
-
}
|
|
40
|
-
_cleanupListeners() {
|
|
41
|
-
for (const [target, type, handler, options] of this._listeners) {
|
|
42
|
-
target.removeEventListener(type, handler, options);
|
|
43
|
-
}
|
|
44
|
-
this._listeners = [];
|
|
45
|
-
}
|
|
46
|
-
/** Dispatches a bubbling CustomEvent from this element. */
|
|
47
|
-
emit(type, detail) {
|
|
48
|
-
return this.dispatchEvent(new CustomEvent(type, { bubbles: true, detail }));
|
|
49
|
-
}
|
|
50
|
-
// --- small attribute-reflection helpers, shared across components ---
|
|
51
|
-
stringAttr(name, fallback = "") {
|
|
52
|
-
return this.getAttribute(name) ?? fallback;
|
|
53
|
-
}
|
|
54
|
-
optionalStringAttr(name) {
|
|
55
|
-
return this.getAttribute(name) ?? void 0;
|
|
56
|
-
}
|
|
57
|
-
boolAttr(name) {
|
|
58
|
-
return this.hasAttribute(name);
|
|
59
|
-
}
|
|
60
|
-
numberAttr(name, fallback) {
|
|
61
|
-
const value = this.getAttribute(name);
|
|
62
|
-
if (value == null) return fallback;
|
|
63
|
-
const parsed = Number(value);
|
|
64
|
-
return Number.isNaN(parsed) ? fallback : parsed;
|
|
65
|
-
}
|
|
66
|
-
setBoolAttr(name, value) {
|
|
67
|
-
if (value) this.setAttribute(name, "");
|
|
68
|
-
else this.removeAttribute(name);
|
|
69
|
-
}
|
|
70
|
-
/** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */
|
|
71
|
-
setCssVar(name, value) {
|
|
72
|
-
if (value) this.style.setProperty(name, value);
|
|
73
|
-
else this.style.removeProperty(name);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/core/template.ts
|
|
78
|
-
function raw(value) {
|
|
79
|
-
return { __html: value, toString: () => value };
|
|
80
|
-
}
|
|
81
|
-
function isRaw(value) {
|
|
82
|
-
return typeof value === "object" && value !== null && "__html" in value;
|
|
83
|
-
}
|
|
84
|
-
function escape(value) {
|
|
85
|
-
if (value == null || value === false) return "";
|
|
86
|
-
if (isRaw(value)) return value.__html;
|
|
87
|
-
if (Array.isArray(value)) return value.map(escape).join("");
|
|
88
|
-
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
89
|
-
}
|
|
90
|
-
function html(strings, ...values) {
|
|
91
|
-
return raw(strings.reduce((out, part, i) => out + part + escape(values[i]), ""));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// src/accessibility-components/progress/progress.element.ts
|
|
95
|
-
var uidCounter = 0;
|
|
96
|
-
var nextLabelId = () => `a11y-progress-label-${++uidCounter}`;
|
|
97
|
-
var ProgressElement = class extends A11yElement {
|
|
98
|
-
static get observedAttributes() {
|
|
99
|
-
return ["value", "max", "label", "aria-label"];
|
|
100
|
-
}
|
|
101
|
-
_labelId = nextLabelId();
|
|
102
|
-
get value() {
|
|
103
|
-
const v = this.getAttribute("value");
|
|
104
|
-
return v == null ? void 0 : Number(v);
|
|
105
|
-
}
|
|
106
|
-
set value(v) {
|
|
107
|
-
v == null ? this.removeAttribute("value") : this.setAttribute("value", String(v));
|
|
108
|
-
}
|
|
109
|
-
get max() {
|
|
110
|
-
return this.numberAttr("max", 100);
|
|
111
|
-
}
|
|
112
|
-
set max(v) {
|
|
113
|
-
this.setAttribute("max", String(v));
|
|
114
|
-
}
|
|
115
|
-
onBeforeRender() {
|
|
116
|
-
this.classList.add("a11y-progress");
|
|
117
|
-
}
|
|
118
|
-
render() {
|
|
119
|
-
const { value, max } = this;
|
|
120
|
-
const label = this.optionalStringAttr("label");
|
|
121
|
-
const ariaLabel = this.optionalStringAttr("aria-label");
|
|
122
|
-
const labelMarkup = label ? html`<span class="a11y-progress__label" id="${this._labelId}">${label}</span>` : "";
|
|
123
|
-
const progressAttrs = html`class="a11y-progress__bar"${value !== void 0 ? html` value="${value}"` : ""} max="${max}"${label ? html` aria-labelledby="${this._labelId}"` : ariaLabel ? html` aria-label="${ariaLabel}"` : html` aria-label="Progress"`}`;
|
|
124
|
-
return `${labelMarkup}<progress ${progressAttrs}></progress>`;
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// src/accessibility-components/progress/define.ts
|
|
129
|
-
if (!customElements.get("a11y-progress")) {
|
|
130
|
-
customElements.define("a11y-progress", ProgressElement);
|
|
131
|
-
}
|
|
132
|
-
export {
|
|
133
|
-
ProgressElement
|
|
134
|
-
};
|
|
135
|
-
//# sourceMappingURL=define.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/a11y-element.ts","../../../../src/core/template.ts","../../../../src/accessibility-components/progress/progress.element.ts","../../../../src/accessibility-components/progress/define.ts"],"sourcesContent":["import type { Raw } from './template.js';\n\ntype Listener = [target: EventTarget, type: string, handler: EventListener, options?: AddEventListenerOptions | boolean];\n\n/**\n * Base class for every element in this library. Light DOM only — elements\n * render real child markup styled by the consumer's own CSS, not a shadow\n * root.\n *\n * Lifecycle mirrors the old `onBeforeRender -> innerHTML = template ->\n * onAfterRender` pipeline this library used to run through a proprietary\n * framework, just mapped onto native custom-element callbacks:\n *\n * connectedCallback -> first update()\n * attributeChangedCallback -> update() for any observed attribute change\n * disconnectedCallback -> remove all tracked listeners, then onDisconnect()\n *\n * Subclasses list attributes to watch via `static observedAttributes` and\n * implement `render()` to return the markup for `this.innerHTML`. Attribute/\n * property setters that need to reflect into the DOM should just mutate the\n * attribute — `attributeChangedCallback` re-renders synchronously while\n * connected, so state and DOM never drift out of sync across a render.\n */\nexport abstract class A11yElement extends HTMLElement {\n protected _connected = false;\n private _listeners: Listener[] = [];\n private _updating = false;\n\n connectedCallback(): void {\n this._connected = true;\n this.update();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this._cleanupListeners();\n this.onDisconnect?.();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this.update();\n }\n\n protected update(): void {\n // Re-entrancy guard: a listener/hook that itself mutates an observed\n // attribute during render must not trigger a nested render.\n if (this._updating) return;\n this._updating = true;\n try {\n this._cleanupListeners();\n this.onBeforeRender?.();\n this.innerHTML = String(this.render());\n this.onAfterRender?.();\n } finally {\n this._updating = false;\n }\n }\n\n /** Returns the markup to set as `this.innerHTML` on every render — a plain string, or an `html\\`...\\`` result. */\n protected abstract render(): string | Raw;\n\n /** Runs before `render()`. Typical use: set root-level classes/ARIA/CSS custom properties. */\n protected onBeforeRender?(): void;\n\n /** Runs after `render()` replaces `innerHTML`. Typical use: query into fresh markup, wire listeners, set DOM-only properties. */\n protected onAfterRender?(): void;\n\n /** Runs once, after listener cleanup, when the element leaves the DOM. */\n protected onDisconnect?(): void;\n\n /**\n * Adds a listener and tracks it for automatic removal on the next render\n * and on disconnect — the direct replacement for the old framework's\n * `[el, type, handler]` cleanup-array convention.\n */\n protected listen(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions | boolean,\n ): void {\n target.addEventListener(type, handler, options);\n this._listeners.push([target, type, handler, options]);\n }\n\n private _cleanupListeners(): void {\n for (const [target, type, handler, options] of this._listeners) {\n target.removeEventListener(type, handler, options);\n }\n this._listeners = [];\n }\n\n /** Dispatches a bubbling CustomEvent from this element. */\n protected emit<T = unknown>(type: string, detail?: T): boolean {\n return this.dispatchEvent(new CustomEvent<T>(type, { bubbles: true, detail: detail as T }));\n }\n\n // --- small attribute-reflection helpers, shared across components ---\n\n protected stringAttr(name: string, fallback = ''): string {\n return this.getAttribute(name) ?? fallback;\n }\n\n protected optionalStringAttr(name: string): string | undefined {\n return this.getAttribute(name) ?? undefined;\n }\n\n protected boolAttr(name: string): boolean {\n return this.hasAttribute(name);\n }\n\n protected numberAttr(name: string, fallback: number): number {\n const value = this.getAttribute(name);\n if (value == null) return fallback;\n const parsed = Number(value);\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n protected setBoolAttr(name: string, value: boolean): void {\n if (value) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n /** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */\n protected setCssVar(name: string, value: string | null | undefined): void {\n if (value) this.style.setProperty(name, value);\n else this.style.removeProperty(name);\n }\n}\n","/**\n * Pre-trusted HTML: opts out of auto-escaping when interpolated into an\n * `html` tagged template, and stringifies back to that exact markup when\n * assigned to `innerHTML` or concatenated. `html\\`...\\`` itself returns one\n * of these, which is what makes nesting `html` calls inside another `html`\n * call safe by construction — the inner result is never re-escaped, no\n * caller discipline (remembering to wrap it) required.\n */\nexport interface Raw {\n readonly __html: string;\n toString(): string;\n}\n\n/** Wraps a string as pre-trusted HTML. Use only for markup you built yourself — never for raw user input. */\nexport function raw(value: string): Raw {\n return { __html: value, toString: () => value };\n}\n\nfunction isRaw(value: unknown): value is Raw {\n return typeof value === 'object' && value !== null && '__html' in value;\n}\n\nfunction escape(value: unknown): string {\n if (value == null || value === false) return '';\n if (isRaw(value)) return value.__html;\n if (Array.isArray(value)) return value.map(escape).join('');\n return String(value)\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/**\n * Tagged template for building element markup. Literal template parts are\n * trusted structure; every interpolated value is HTML-escaped by default\n * (falsy values render as nothing, so `${cond && '<span>…</span>'}`-style\n * conditionals work without a directive attribute). Returns a `Raw`, so\n * nesting `html\\`...\\`` inside another `html\\`...\\`` template composes\n * safely without needing an explicit `raw()` wrapper.\n */\nexport function html(strings: TemplateStringsArray, ...values: unknown[]): Raw {\n return raw(strings.reduce((out, part, i) => out + part + escape(values[i]), ''));\n}\n\n/**\n * A `name=\"value\"` HTML attribute, with a leading space, escaped — or\n * nothing at all when `value` is `null`/`undefined`/`false`/`''`. Meant for\n * building conditional attribute lists inline:\n * `` html`<input${attr('id', id)}${flag('disabled', disabled)}>` ``\n */\nexport function attr(name: string, value: unknown): Raw {\n if (value == null || value === false || value === '') return raw('');\n return raw(` ${name}=\"${escape(value)}\"`);\n}\n\n/** A bare boolean attribute (e.g. `disabled`, `checked`), with a leading space, present only when `condition` is true. */\nexport function flag(name: string, condition: boolean | undefined): Raw {\n return raw(condition ? ` ${name}` : '');\n}\n","import { A11yElement } from '../../core/a11y-element.js';\nimport { html } from '../../core/template.js';\n\nlet uidCounter = 0;\nconst nextLabelId = (): string => `a11y-progress-label-${++uidCounter}`;\n\n/**\n * A progress bar. `<a11y-progress value=\"50\" max=\"100\" label=\"Uploading…\"></a11y-progress>`\n *\n * The old version rendered a real `<label>` wrapping the `<progress>`, relying\n * on HTML's implicit label-wraps-control naming. A custom element can't\n * itself *be* a `<label>`, so the same accessible-name relationship is\n * expressed explicitly instead, via `aria-labelledby` pointing at the visible\n * label text — an equally robust, arguably more explicit equivalent.\n */\nexport class ProgressElement extends A11yElement {\n static get observedAttributes(): string[] {\n return ['value', 'max', 'label', 'aria-label'];\n }\n\n private _labelId = nextLabelId();\n\n get value(): number | undefined {\n const v = this.getAttribute('value');\n return v == null ? undefined : Number(v);\n }\n set value(v: number | undefined) {\n v == null ? this.removeAttribute('value') : this.setAttribute('value', String(v));\n }\n\n get max(): number {\n return this.numberAttr('max', 100);\n }\n set max(v: number) {\n this.setAttribute('max', String(v));\n }\n\n protected override onBeforeRender(): void {\n this.classList.add('a11y-progress');\n }\n\n protected override render(): string {\n const { value, max } = this;\n const label = this.optionalStringAttr('label');\n const ariaLabel = this.optionalStringAttr('aria-label');\n\n const labelMarkup = label ? html`<span class=\"a11y-progress__label\" id=\"${this._labelId}\">${label}</span>` : '';\n const progressAttrs = html`class=\"a11y-progress__bar\"${value !== undefined ? html` value=\"${value}\"` : ''} max=\"${max}\"${\n label ? html` aria-labelledby=\"${this._labelId}\"` : ariaLabel ? html` aria-label=\"${ariaLabel}\"` : html` aria-label=\"Progress\"`\n }`;\n\n return `${labelMarkup}<progress ${progressAttrs}></progress>`;\n }\n}\n","import { ProgressElement } from './progress.element.js';\n\nif (!customElements.get('a11y-progress')) {\n customElements.define('a11y-progress', ProgressElement);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-progress': ProgressElement;\n }\n}\n\nexport { ProgressElement };\n"],"mappings":";AAuBO,IAAe,cAAf,cAAmC,YAAY;AAAA,EAC1C,aAAa;AAAA,EACf,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEpB,oBAA0B;AACxB,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,uBAA6B;AAC3B,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,yBAAyB,OAAe,UAAyB,UAA+B;AAC9F,QAAI,aAAa,YAAY,CAAC,KAAK,WAAY;AAC/C,SAAK,OAAO;AAAA,EACd;AAAA,EAEU,SAAe;AAGvB,QAAI,KAAK,UAAW;AACpB,SAAK,YAAY;AACjB,QAAI;AACF,WAAK,kBAAkB;AACvB,WAAK,iBAAiB;AACtB,WAAK,YAAY,OA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AI,IAAI,GAAW;AACjB,SAAK,aAAa,OAAO,OAAO,CAAC,CAAC;AAAA,EACpC;AAAA,EAEmB,iBAAuB;AACxC,SAAK,UAAU,IAAI,eAAe;AAAA,EACpC;AAAA,EAEmB,SAAiB;AAClC,UAAM,EAAE,OAAO,IAAI,IAAI;AACvB,UAAM,QAAQ,KAAK,mBAAmB,OAAO;AAC7C,UAAM,YAAY,KAAK,mBAAmB,YAAY;AAEtD,UAAM,cAAc,QAAQ,8CAA8C,KAAK,QAAQ,KAAK,KAAK,YAAY;AAC7G,UAAM,gBAAgB,iCAAiC,UAAU,SAAY,eAAe,KAAK,MAAM,EAAE,SAAS,GAAG,IACnH,QAAQ,yBAAyB,KAAK,QAAQ,MAAM,YAAY,oBAAoB,SAAS,MAAM,4BACrG;AAEA,WAAO,GAAG,WAAW,aAAa,aAAa;AAAA,EACjD;AACF;;;ACnDA,IAAI,CAAC,eAAe,IAAI,eAAe,GAAG;AACxC,iBAAe,OAAO,iBAAiB,eAAe;AACxD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/a11y-element.ts","../../../../src/core/a11y-wrapper-element.ts","../../../../src/core/dom-sync.ts","../../../../src/accessibility-components/radio-group/radio-group.element.ts","../../../../src/accessibility-components/radio-group/define.ts"],"sourcesContent":["import type { Raw } from './template.js';\n\ntype Listener = [target: EventTarget, type: string, handler: EventListener, options?: AddEventListenerOptions | boolean];\n\n/**\n * Base class for every element in this library. Light DOM only — elements\n * render real child markup styled by the consumer's own CSS, not a shadow\n * root.\n *\n * Lifecycle mirrors the old `onBeforeRender -> innerHTML = template ->\n * onAfterRender` pipeline this library used to run through a proprietary\n * framework, just mapped onto native custom-element callbacks:\n *\n * connectedCallback -> first update()\n * attributeChangedCallback -> update() for any observed attribute change\n * disconnectedCallback -> remove all tracked listeners, then onDisconnect()\n *\n * Subclasses list attributes to watch via `static observedAttributes` and\n * implement `render()` to return the markup for `this.innerHTML`. Attribute/\n * property setters that need to reflect into the DOM should just mutate the\n * attribute — `attributeChangedCallback` re-renders synchronously while\n * connected, so state and DOM never drift out of sync across a render.\n */\nexport abstract class A11yElement extends HTMLElement {\n protected _connected = false;\n private _listeners: Listener[] = [];\n private _updating = false;\n\n connectedCallback(): void {\n this._connected = true;\n this.update();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this._cleanupListeners();\n this.onDisconnect?.();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this.update();\n }\n\n protected update(): void {\n // Re-entrancy guard: a listener/hook that itself mutates an observed\n // attribute during render must not trigger a nested render.\n if (this._updating) return;\n this._updating = true;\n try {\n this._cleanupListeners();\n this.onBeforeRender?.();\n this.innerHTML = String(this.render());\n this.onAfterRender?.();\n } finally {\n this._updating = false;\n }\n }\n\n /** Returns the markup to set as `this.innerHTML` on every render — a plain string, or an `html\\`...\\`` result. */\n protected abstract render(): string | Raw;\n\n /** Runs before `render()`. Typical use: set root-level classes/ARIA/CSS custom properties. */\n protected onBeforeRender?(): void;\n\n /** Runs after `render()` replaces `innerHTML`. Typical use: query into fresh markup, wire listeners, set DOM-only properties. */\n protected onAfterRender?(): void;\n\n /** Runs once, after listener cleanup, when the element leaves the DOM. */\n protected onDisconnect?(): void;\n\n /**\n * Adds a listener and tracks it for automatic removal on the next render\n * and on disconnect — the direct replacement for the old framework's\n * `[el, type, handler]` cleanup-array convention.\n */\n protected listen(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions | boolean,\n ): void {\n target.addEventListener(type, handler, options);\n this._listeners.push([target, type, handler, options]);\n }\n\n private _cleanupListeners(): void {\n for (const [target, type, handler, options] of this._listeners) {\n target.removeEventListener(type, handler, options);\n }\n this._listeners = [];\n }\n\n /** Dispatches a bubbling CustomEvent from this element. */\n protected emit<T = unknown>(type: string, detail?: T): boolean {\n return this.dispatchEvent(new CustomEvent<T>(type, { bubbles: true, detail: detail as T }));\n }\n\n // --- small attribute-reflection helpers, shared across components ---\n\n protected stringAttr(name: string, fallback = ''): string {\n return this.getAttribute(name) ?? fallback;\n }\n\n protected optionalStringAttr(name: string): string | undefined {\n return this.getAttribute(name) ?? undefined;\n }\n\n protected boolAttr(name: string): boolean {\n return this.hasAttribute(name);\n }\n\n protected numberAttr(name: string, fallback: number): number {\n const value = this.getAttribute(name);\n if (value == null) return fallback;\n const parsed = Number(value);\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n protected setBoolAttr(name: string, value: boolean): void {\n if (value) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n /** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */\n protected setCssVar(name: string, value: string | null | undefined): void {\n if (value) this.style.setProperty(name, value);\n else this.style.removeProperty(name);\n }\n}\n","import { A11yElement } from './a11y-element.js';\n\n/**\n * Base for elements that enhance real, consumer-authored light-DOM children\n * instead of generating their own markup from a template string — e.g. a\n * `<a11y-picture>` wrapping a real `<picture>`/`<img>`/`<figcaption>`, or\n * `<a11y-select>` wrapping a real `<select>`/`<option>`s.\n *\n * Unlike `A11yElement`, this never sets `innerHTML` from a `render()`\n * string — that would destroy the author's children — so it opts out of the\n * normal render pipeline and instead re-syncs (`_sync()`) from two sources:\n *\n * - **This element's own observed attributes** (e.g. `label`, `legend`),\n * listed via `static observedAttributes` same as any other element —\n * these re-sync *synchronously*, matching every other element in this\n * library, so `el.setAttribute('label', 'x')` takes effect immediately.\n * - **Everything else** (children added/removed, an attribute changing on\n * one of *those* children) — light DOM has no `slotchange`, so a\n * `MutationObserver` is the equivalent, necessarily asynchronous (a real\n * microtask/task delay after the mutation).\n *\n * `_sync()` runs inside that `MutationObserver` callback, so every DOM write\n * it makes must be guarded (see `core/dom-sync.ts`) — `setAttribute`/\n * `classList.add`/`textContent =` all queue a mutation record even when the\n * value is unchanged, and an unguarded write would retrigger the observer\n * forever.\n */\nexport abstract class A11yWrapperElement extends A11yElement {\n private _observer: MutationObserver | null = null;\n /** Nodes already given their listeners since the last connect — see `wireOnce()`. */\n private _wiredNodes = new WeakSet<Node>();\n\n override connectedCallback(): void {\n this._connected = true;\n this._sync();\n this._observer = new MutationObserver(() => this._sync());\n this._observer.observe(this, this.observerInit());\n }\n\n override disconnectedCallback(): void {\n this._observer?.disconnect();\n this._observer = null;\n super.disconnectedCallback(); // removes every `listen()` listener…\n this._wiredNodes = new WeakSet(); // …so the next connect must wire them again\n }\n\n override attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this._sync();\n }\n\n /**\n * Runs `wire` the first time `node` is seen since this element was last\n * connected. `_sync()` runs on every mutation, so listener setup must be\n * idempotent — but those listeners (added via `listen()`) are all removed\n * on disconnect, so the \"already wired\" memory must reset with them, or a\n * reparented element (disconnect + connect) would silently stop firing.\n */\n protected wireOnce(node: Node, wire: () => void): void {\n if (this._wiredNodes.has(node)) return;\n this._wiredNodes.add(node);\n wire();\n }\n\n /** What to watch for changes worth re-syncing on. Override for a narrower/wider scope. */\n protected observerInit(): MutationObserverInit {\n return { childList: true, subtree: true, attributes: true };\n }\n\n /** Re-derive this element's own attributes/classes from its current children. */\n protected abstract _sync(): void;\n\n /** Unused — content is the author's own children, never replaced. */\n protected override render(): string {\n return '';\n }\n}\n","/**\n * Guarded DOM writes for use inside `A11yWrapperElement._sync()` methods (or\n * anywhere else re-syncing against a live MutationObserver).\n *\n * `setAttribute`/`removeAttribute`/`classList.add`/`classList.remove`/\n * `textContent =` all queue a mutation record unconditionally — even when\n * the value being written is identical to what's already there. Call one of\n * these unguarded inside a MutationObserver callback that's itself watching\n * the element being written to, and every \"no-op\" write retriggers the\n * observer, forever. These helpers check first, so a `_sync()` call that\n * changes nothing produces zero mutations and the observer loop terminates.\n */\n\nexport function syncText(el: Element, text: string): void {\n if (el.textContent !== text) el.textContent = text;\n}\n\nexport function syncAttr(el: Element, name: string, value: string | null | undefined): void {\n if (value == null) {\n if (el.hasAttribute(name)) el.removeAttribute(name);\n } else if (el.getAttribute(name) !== value) {\n el.setAttribute(name, value);\n }\n}\n\nexport function syncClass(el: Element, name: string, present: boolean): void {\n if (el.classList.contains(name) !== present) el.classList.toggle(name, present);\n}\n","import { A11yWrapperElement } from '../../core/a11y-wrapper-element.js';\nimport { syncAttr, syncClass, syncText } from '../../core/dom-sync.js';\n\n/**\n * Enhances a set of real, consumer-authored `<input type=\"radio\">` options\n * (each already fully accessible on its own, typically inside its own\n * `<label>`) with a wrapping `<fieldset>`/`<legend>` and a delegated change\n * convenience. The consumer is responsible for giving every radio the same\n * `name` (that's what makes them a mutually-exclusive native group — nothing\n * for this element to inject) and any `disabled`/`required` they want.\n *\n * ```html\n * <a11y-radio-group legend=\"Choose a plan\">\n * <label><input type=\"radio\" name=\"plan\" value=\"basic\"> Basic</label>\n * <label><input type=\"radio\" name=\"plan\" value=\"pro\"> Pro</label>\n * </a11y-radio-group>\n * ```\n */\nexport class RadioGroupElement extends A11yWrapperElement {\n static get observedAttributes(): string[] {\n return ['legend', 'aria-label', 'disabled'];\n }\n\n\n onChange?: (value: string) => void;\n\n getValue(): string {\n return this._fieldset()?.querySelector<HTMLInputElement>('.a11y-radio__input:checked')?.value ?? '';\n }\n\n /** Checks the option with this value; does not uncheck the others (native same-`name` grouping already does that). */\n setValue(value: string): void {\n const inputs = this._fieldset()?.querySelectorAll<HTMLInputElement>('.a11y-radio__input') ?? [];\n const match = [...inputs].find((input) => input.value === value);\n if (match) match.checked = true;\n }\n\n private _fieldset(): HTMLFieldSetElement | null {\n return this.querySelector('fieldset.a11y-radio-group');\n }\n\n protected override _sync(): void {\n if (!this.querySelector('input[type=\"radio\"]')) return;\n\n const fieldset = this._ensureFieldset();\n for (const input of fieldset.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]')) {\n syncClass(input, 'a11y-radio__input', true);\n }\n\n syncAttr(fieldset, 'disabled', this.boolAttr('disabled') ? '' : null);\n this._syncLegend(fieldset);\n\n this.wireOnce(fieldset, () =>\n this.listen(fieldset, 'change', (e) => {\n const target = e.target as HTMLInputElement;\n if (target.matches('input[type=\"radio\"]') && target.checked) this.onChange?.(target.value);\n }),\n );\n }\n\n private _ensureFieldset(): HTMLFieldSetElement {\n const existing = this._fieldset();\n if (existing) return existing;\n\n const fieldset = document.createElement('fieldset');\n fieldset.className = 'a11y-radio-group';\n // Move every existing child (the consumer's option markup) into it.\n while (this.firstChild) fieldset.appendChild(this.firstChild);\n this.appendChild(fieldset);\n return fieldset;\n }\n\n private _syncLegend(fieldset: HTMLFieldSetElement): void {\n const legendText = this.optionalStringAttr('legend');\n const ariaLabel = this.optionalStringAttr('aria-label');\n let legend = fieldset.querySelector<HTMLLegendElement>('.a11y-radio-group__legend');\n\n if (legendText) {\n if (!legend) {\n legend = document.createElement('legend');\n legend.className = 'a11y-radio-group__legend';\n fieldset.prepend(legend);\n }\n syncText(legend, legendText);\n syncAttr(fieldset, 'aria-label', null); // <legend> already provides an accessible name natively\n } else {\n legend?.remove();\n syncAttr(fieldset, 'aria-label', ariaLabel);\n }\n }\n}\n","import { RadioGroupElement } from './radio-group.element.js';\n\nif (!customElements.get('a11y-radio-group')) {\n customElements.define('a11y-radio-group', RadioGroupElement);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-radio-group': RadioGroupElement;\n }\n}\n\nexport { RadioGroupElement };\n"],"mappings":";AAuBO,IAAe,cAAf,cAAmC,YAAY;AAAA,EAC1C,aAAa;AAAA,EACf,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEpB,oBAA0B;AACxB,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,uBAA6B;AAC3B,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,yBAAyB,OAAe,UAAyB,UAA+B;AAC9F,QAAI,aAAa,YAAY,CAAC,KAAK,WAAY;AAC/C,SAAK,OAAO;AAAA,EACd;AAAA,EAEU,SAAe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,QAAO;AAErB,UAAM,WAAW,SAAS,cAAc,UAAU;AAClD,aAAS,YAAY;AAErB,WAAO,KAAK,WAAY,UAAS,YAAY,KAAK,UAAU;AAC5D,SAAK,YAAY,QAAQ;AACzB,WAAO;AAAA,EACT;AAAA,EAEQ,YAAY,UAAqC;AACvD,UAAM,aAAa,KAAK,mBAAmB,QAAQ;AACnD,UAAM,YAAY,KAAK,mBAAmB,YAAY;AACtD,QAAI,SAAS,SAAS,cAAiC,2BAA2B;AAElF,QAAI,YAAY;AACd,UAAI,CAAC,QAAQ;AACX,iBAAS,SAAS,cAAc,QAAQ;AACxC,eAAO,YAAY;AACnB,iBAAS,QAAQ,MAAM;AAAA,MACzB;AACA,eAAS,QAAQ,UAAU;AAC3B,eAAS,UAAU,cAAc,IAAI;AAAA,IACvC,OAAO;AACL,cAAQ,OAAO;AACf,eAAS,UAAU,cAAc,SAAS;AAAA,IAC5C;AAAA,EACF;AACF;;;ACxFA,IAAI,CAAC,eAAe,IAAI,kBAAkB,GAAG;AAC3C,iBAAe,OAAO,oBAAoB,iBAAiB;AAC7D;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/a11y-element.ts","../../../../src/core/a11y-wrapper-element.ts","../../../../src/core/dom-sync.ts","../../../../src/accessibility-components/select/select.element.ts","../../../../src/accessibility-components/select/define.ts"],"sourcesContent":["import type { Raw } from './template.js';\n\ntype Listener = [target: EventTarget, type: string, handler: EventListener, options?: AddEventListenerOptions | boolean];\n\n/**\n * Base class for every element in this library. Light DOM only — elements\n * render real child markup styled by the consumer's own CSS, not a shadow\n * root.\n *\n * Lifecycle mirrors the old `onBeforeRender -> innerHTML = template ->\n * onAfterRender` pipeline this library used to run through a proprietary\n * framework, just mapped onto native custom-element callbacks:\n *\n * connectedCallback -> first update()\n * attributeChangedCallback -> update() for any observed attribute change\n * disconnectedCallback -> remove all tracked listeners, then onDisconnect()\n *\n * Subclasses list attributes to watch via `static observedAttributes` and\n * implement `render()` to return the markup for `this.innerHTML`. Attribute/\n * property setters that need to reflect into the DOM should just mutate the\n * attribute — `attributeChangedCallback` re-renders synchronously while\n * connected, so state and DOM never drift out of sync across a render.\n */\nexport abstract class A11yElement extends HTMLElement {\n protected _connected = false;\n private _listeners: Listener[] = [];\n private _updating = false;\n\n connectedCallback(): void {\n this._connected = true;\n this.update();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this._cleanupListeners();\n this.onDisconnect?.();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this.update();\n }\n\n protected update(): void {\n // Re-entrancy guard: a listener/hook that itself mutates an observed\n // attribute during render must not trigger a nested render.\n if (this._updating) return;\n this._updating = true;\n try {\n this._cleanupListeners();\n this.onBeforeRender?.();\n this.innerHTML = String(this.render());\n this.onAfterRender?.();\n } finally {\n this._updating = false;\n }\n }\n\n /** Returns the markup to set as `this.innerHTML` on every render — a plain string, or an `html\\`...\\`` result. */\n protected abstract render(): string | Raw;\n\n /** Runs before `render()`. Typical use: set root-level classes/ARIA/CSS custom properties. */\n protected onBeforeRender?(): void;\n\n /** Runs after `render()` replaces `innerHTML`. Typical use: query into fresh markup, wire listeners, set DOM-only properties. */\n protected onAfterRender?(): void;\n\n /** Runs once, after listener cleanup, when the element leaves the DOM. */\n protected onDisconnect?(): void;\n\n /**\n * Adds a listener and tracks it for automatic removal on the next render\n * and on disconnect — the direct replacement for the old framework's\n * `[el, type, handler]` cleanup-array convention.\n */\n protected listen(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions | boolean,\n ): void {\n target.addEventListener(type, handler, options);\n this._listeners.push([target, type, handler, options]);\n }\n\n private _cleanupListeners(): void {\n for (const [target, type, handler, options] of this._listeners) {\n target.removeEventListener(type, handler, options);\n }\n this._listeners = [];\n }\n\n /** Dispatches a bubbling CustomEvent from this element. */\n protected emit<T = unknown>(type: string, detail?: T): boolean {\n return this.dispatchEvent(new CustomEvent<T>(type, { bubbles: true, detail: detail as T }));\n }\n\n // --- small attribute-reflection helpers, shared across components ---\n\n protected stringAttr(name: string, fallback = ''): string {\n return this.getAttribute(name) ?? fallback;\n }\n\n protected optionalStringAttr(name: string): string | undefined {\n return this.getAttribute(name) ?? undefined;\n }\n\n protected boolAttr(name: string): boolean {\n return this.hasAttribute(name);\n }\n\n protected numberAttr(name: string, fallback: number): number {\n const value = this.getAttribute(name);\n if (value == null) return fallback;\n const parsed = Number(value);\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n protected setBoolAttr(name: string, value: boolean): void {\n if (value) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n /** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */\n protected setCssVar(name: string, value: string | null | undefined): void {\n if (value) this.style.setProperty(name, value);\n else this.style.removeProperty(name);\n }\n}\n","import { A11yElement } from './a11y-element.js';\n\n/**\n * Base for elements that enhance real, consumer-authored light-DOM children\n * instead of generating their own markup from a template string — e.g. a\n * `<a11y-picture>` wrapping a real `<picture>`/`<img>`/`<figcaption>`, or\n * `<a11y-select>` wrapping a real `<select>`/`<option>`s.\n *\n * Unlike `A11yElement`, this never sets `innerHTML` from a `render()`\n * string — that would destroy the author's children — so it opts out of the\n * normal render pipeline and instead re-syncs (`_sync()`) from two sources:\n *\n * - **This element's own observed attributes** (e.g. `label`, `legend`),\n * listed via `static observedAttributes` same as any other element —\n * these re-sync *synchronously*, matching every other element in this\n * library, so `el.setAttribute('label', 'x')` takes effect immediately.\n * - **Everything else** (children added/removed, an attribute changing on\n * one of *those* children) — light DOM has no `slotchange`, so a\n * `MutationObserver` is the equivalent, necessarily asynchronous (a real\n * microtask/task delay after the mutation).\n *\n * `_sync()` runs inside that `MutationObserver` callback, so every DOM write\n * it makes must be guarded (see `core/dom-sync.ts`) — `setAttribute`/\n * `classList.add`/`textContent =` all queue a mutation record even when the\n * value is unchanged, and an unguarded write would retrigger the observer\n * forever.\n */\nexport abstract class A11yWrapperElement extends A11yElement {\n private _observer: MutationObserver | null = null;\n /** Nodes already given their listeners since the last connect — see `wireOnce()`. */\n private _wiredNodes = new WeakSet<Node>();\n\n override connectedCallback(): void {\n this._connected = true;\n this._sync();\n this._observer = new MutationObserver(() => this._sync());\n this._observer.observe(this, this.observerInit());\n }\n\n override disconnectedCallback(): void {\n this._observer?.disconnect();\n this._observer = null;\n super.disconnectedCallback(); // removes every `listen()` listener…\n this._wiredNodes = new WeakSet(); // …so the next connect must wire them again\n }\n\n override attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this._sync();\n }\n\n /**\n * Runs `wire` the first time `node` is seen since this element was last\n * connected. `_sync()` runs on every mutation, so listener setup must be\n * idempotent — but those listeners (added via `listen()`) are all removed\n * on disconnect, so the \"already wired\" memory must reset with them, or a\n * reparented element (disconnect + connect) would silently stop firing.\n */\n protected wireOnce(node: Node, wire: () => void): void {\n if (this._wiredNodes.has(node)) return;\n this._wiredNodes.add(node);\n wire();\n }\n\n /** What to watch for changes worth re-syncing on. Override for a narrower/wider scope. */\n protected observerInit(): MutationObserverInit {\n return { childList: true, subtree: true, attributes: true };\n }\n\n /** Re-derive this element's own attributes/classes from its current children. */\n protected abstract _sync(): void;\n\n /** Unused — content is the author's own children, never replaced. */\n protected override render(): string {\n return '';\n }\n}\n","/**\n * Guarded DOM writes for use inside `A11yWrapperElement._sync()` methods (or\n * anywhere else re-syncing against a live MutationObserver).\n *\n * `setAttribute`/`removeAttribute`/`classList.add`/`classList.remove`/\n * `textContent =` all queue a mutation record unconditionally — even when\n * the value being written is identical to what's already there. Call one of\n * these unguarded inside a MutationObserver callback that's itself watching\n * the element being written to, and every \"no-op\" write retriggers the\n * observer, forever. These helpers check first, so a `_sync()` call that\n * changes nothing produces zero mutations and the observer loop terminates.\n */\n\nexport function syncText(el: Element, text: string): void {\n if (el.textContent !== text) el.textContent = text;\n}\n\nexport function syncAttr(el: Element, name: string, value: string | null | undefined): void {\n if (value == null) {\n if (el.hasAttribute(name)) el.removeAttribute(name);\n } else if (el.getAttribute(name) !== value) {\n el.setAttribute(name, value);\n }\n}\n\nexport function syncClass(el: Element, name: string, present: boolean): void {\n if (el.classList.contains(name) !== present) el.classList.toggle(name, present);\n}\n","import { A11yWrapperElement } from '../../core/a11y-wrapper-element.js';\nimport { syncClass, syncText } from '../../core/dom-sync.js';\n\n/**\n * Enhances a real `<select>` (with real `<option>` children — the browser's\n * own native picker/keyboard handling needs no help) with a wrapping\n * `<label>` and visible label span.\n *\n * ```html\n * <a11y-select label=\"Country\">\n * <select name=\"country\">\n * <option value=\"us\">United States</option>\n * <option value=\"ca\">Canada</option>\n * </select>\n * </a11y-select>\n * ```\n */\nexport class SelectElement extends A11yWrapperElement {\n static get observedAttributes(): string[] {\n return ['label'];\n }\n\n\n onChange?: (value: string) => void;\n\n getValue(): string {\n return this._select()?.value ?? '';\n }\n\n setValue(value: string): void {\n const select = this._select();\n if (select) select.value = value;\n }\n\n private _select(): HTMLSelectElement | null {\n return this.querySelector('select');\n }\n\n protected override _sync(): void {\n const select = this._select();\n if (!select) return;\n\n const wrapper = this._ensureWrapper(select);\n syncClass(select, 'a11y-select__control', true);\n this._syncLabel(wrapper);\n\n this.wireOnce(select, () => this.listen(select, 'change', () => this.onChange?.(select.value)));\n }\n\n private _ensureWrapper(select: HTMLSelectElement): HTMLLabelElement {\n const existing = select.closest<HTMLLabelElement>('label.a11y-select');\n if (existing && existing.parentElement === this) return existing;\n\n const wrapper = document.createElement('label');\n wrapper.className = 'a11y-select';\n select.replaceWith(wrapper);\n wrapper.appendChild(select);\n return wrapper;\n }\n\n private _syncLabel(wrapper: HTMLLabelElement): void {\n const text = this.optionalStringAttr('label');\n let span = wrapper.querySelector<HTMLElement>('.a11y-select__label');\n if (!text) {\n span?.remove();\n return;\n }\n if (!span) {\n span = document.createElement('span');\n span.className = 'a11y-select__label';\n wrapper.prepend(span); // label text visually precedes the control\n }\n syncText(span, text);\n }\n}\n","import { SelectElement } from './select.element.js';\n\nif (!customElements.get('a11y-select')) {\n customElements.define('a11y-select', SelectElement);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-select': SelectElement;\n }\n}\n\nexport { SelectElement };\n"],"mappings":";AAuBO,IAAe,cAAf,cAAmC,YAAY;AAAA,EAC1C,aAAa;AAAA,EACf,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEpB,oBAA0B;AACxB,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,uBAA6B;AAC3B,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,yBAAyB,OAAe,UAAyB,UAA+B;AAC9F,QAAI,aAAa,YAAY,CAAC,KAAK,WAAY;AAC/C,SAAK,OAAO;AAAA,EACd;AAAA,EAEU,SAAe;AAGvB,QAAI,KAAK,UAAW;AACpB,SAAK,YAAY;AACjB,QAAI;AACF,WAAK,kBAAkB;AACvB,WAAK,iBAAiB;AACtB,WAAK,YAAY,OAAO,KAAK,OAAO,CAAC;AACrC,WAAK,gBAAgB;AAAA,IACvB,UAAE;AACA,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBU,OACR,QACA,MACA,SACA,SACM;AACN,WAAO,iBAAiB,MAAM,SAAS,OAAO;AAC9C,SAAK,WAAW,KAAK,CAAC,QAAQ,MAAM,SAAS,OAAO,CAAC;AAAA,EACvD;AAAA,EAEQ,oBAA0B;AAChC,eAAW,CAAC,QAAQ,MAAM,SAAS,OAAO,KAAK,KAAK,YAAY;AAC9D,aAAO,oBAAoB,MAAM,SAAS,OAAO;AAAA,IACnD;AACA,SAAK,aAAa,CAAC;AAAA,EACrB;AAAA;AAAA,EAGU,KAAkB,MAAc,QAAqB;AAC7D,WAAO,KAAK,cAAc,IAAI,YAAe,MAAM,EAAE,SAAS,MAAM,OAAoB,CAAC,CAA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AM,QAAO;AAExD,UAAM,UAAU,SAAS,cAAc,OAAO;AAC9C,YAAQ,YAAY;AACpB,WAAO,YAAY,OAAO;AAC1B,YAAQ,YAAY,MAAM;AAC1B,WAAO;AAAA,EACT;AAAA,EAEQ,WAAW,SAAiC;AAClD,UAAM,OAAO,KAAK,mBAAmB,OAAO;AAC5C,QAAI,OAAO,QAAQ,cAA2B,qBAAqB;AACnE,QAAI,CAAC,MAAM;AACT,YAAM,OAAO;AACb;AAAA,IACF;AACA,QAAI,CAAC,MAAM;AACT,aAAO,SAAS,cAAc,MAAM;AACpC,WAAK,YAAY;AACjB,cAAQ,QAAQ,IAAI;AAAA,IACtB;AACA,aAAS,MAAM,IAAI;AAAA,EACrB;AACF;;;ACxEA,IAAI,CAAC,eAAe,IAAI,aAAa,GAAG;AACtC,iBAAe,OAAO,eAAe,aAAa;AACpD;","names":[]}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// src/core/a11y-element.ts
|
|
2
|
-
var A11yElement = class extends HTMLElement {
|
|
3
|
-
_connected = false;
|
|
4
|
-
_listeners = [];
|
|
5
|
-
_updating = false;
|
|
6
|
-
connectedCallback() {
|
|
7
|
-
this._connected = true;
|
|
8
|
-
this.update();
|
|
9
|
-
}
|
|
10
|
-
disconnectedCallback() {
|
|
11
|
-
this._connected = false;
|
|
12
|
-
this._cleanupListeners();
|
|
13
|
-
this.onDisconnect?.();
|
|
14
|
-
}
|
|
15
|
-
attributeChangedCallback(_name, oldValue, newValue) {
|
|
16
|
-
if (oldValue === newValue || !this._connected) return;
|
|
17
|
-
this.update();
|
|
18
|
-
}
|
|
19
|
-
update() {
|
|
20
|
-
if (this._updating) return;
|
|
21
|
-
this._updating = true;
|
|
22
|
-
try {
|
|
23
|
-
this._cleanupListeners();
|
|
24
|
-
this.onBeforeRender?.();
|
|
25
|
-
this.innerHTML = String(this.render());
|
|
26
|
-
this.onAfterRender?.();
|
|
27
|
-
} finally {
|
|
28
|
-
this._updating = false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Adds a listener and tracks it for automatic removal on the next render
|
|
33
|
-
* and on disconnect — the direct replacement for the old framework's
|
|
34
|
-
* `[el, type, handler]` cleanup-array convention.
|
|
35
|
-
*/
|
|
36
|
-
listen(target, type, handler, options) {
|
|
37
|
-
target.addEventListener(type, handler, options);
|
|
38
|
-
this._listeners.push([target, type, handler, options]);
|
|
39
|
-
}
|
|
40
|
-
_cleanupListeners() {
|
|
41
|
-
for (const [target, type, handler, options] of this._listeners) {
|
|
42
|
-
target.removeEventListener(type, handler, options);
|
|
43
|
-
}
|
|
44
|
-
this._listeners = [];
|
|
45
|
-
}
|
|
46
|
-
/** Dispatches a bubbling CustomEvent from this element. */
|
|
47
|
-
emit(type, detail) {
|
|
48
|
-
return this.dispatchEvent(new CustomEvent(type, { bubbles: true, detail }));
|
|
49
|
-
}
|
|
50
|
-
// --- small attribute-reflection helpers, shared across components ---
|
|
51
|
-
stringAttr(name, fallback = "") {
|
|
52
|
-
return this.getAttribute(name) ?? fallback;
|
|
53
|
-
}
|
|
54
|
-
optionalStringAttr(name) {
|
|
55
|
-
return this.getAttribute(name) ?? void 0;
|
|
56
|
-
}
|
|
57
|
-
boolAttr(name) {
|
|
58
|
-
return this.hasAttribute(name);
|
|
59
|
-
}
|
|
60
|
-
numberAttr(name, fallback) {
|
|
61
|
-
const value = this.getAttribute(name);
|
|
62
|
-
if (value == null) return fallback;
|
|
63
|
-
const parsed = Number(value);
|
|
64
|
-
return Number.isNaN(parsed) ? fallback : parsed;
|
|
65
|
-
}
|
|
66
|
-
setBoolAttr(name, value) {
|
|
67
|
-
if (value) this.setAttribute(name, "");
|
|
68
|
-
else this.removeAttribute(name);
|
|
69
|
-
}
|
|
70
|
-
/** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */
|
|
71
|
-
setCssVar(name, value) {
|
|
72
|
-
if (value) this.style.setProperty(name, value);
|
|
73
|
-
else this.style.removeProperty(name);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/core/template.ts
|
|
78
|
-
function raw(value) {
|
|
79
|
-
return { __html: value, toString: () => value };
|
|
80
|
-
}
|
|
81
|
-
function isRaw(value) {
|
|
82
|
-
return typeof value === "object" && value !== null && "__html" in value;
|
|
83
|
-
}
|
|
84
|
-
function escape(value) {
|
|
85
|
-
if (value == null || value === false) return "";
|
|
86
|
-
if (isRaw(value)) return value.__html;
|
|
87
|
-
if (Array.isArray(value)) return value.map(escape).join("");
|
|
88
|
-
return String(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
89
|
-
}
|
|
90
|
-
function html(strings, ...values) {
|
|
91
|
-
return raw(strings.reduce((out, part, i) => out + part + escape(values[i]), ""));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// src/accessibility-components/skeleton/skeleton.element.ts
|
|
95
|
-
var SkeletonElement = class extends A11yElement {
|
|
96
|
-
static get observedAttributes() {
|
|
97
|
-
return ["variant", "width", "height", "lines"];
|
|
98
|
-
}
|
|
99
|
-
get variant() {
|
|
100
|
-
const value = this.getAttribute("variant");
|
|
101
|
-
return value === "circle" || value === "text" ? value : "rect";
|
|
102
|
-
}
|
|
103
|
-
set variant(value) {
|
|
104
|
-
this.setAttribute("variant", value);
|
|
105
|
-
}
|
|
106
|
-
get lines() {
|
|
107
|
-
return this.numberAttr("lines", 1);
|
|
108
|
-
}
|
|
109
|
-
set lines(value) {
|
|
110
|
-
this.setAttribute("lines", String(value));
|
|
111
|
-
}
|
|
112
|
-
onBeforeRender() {
|
|
113
|
-
this.setAttribute("aria-hidden", "true");
|
|
114
|
-
this.classList.add("a11y-skeleton");
|
|
115
|
-
this.classList.remove("a11y-skeleton--rect", "a11y-skeleton--circle", "a11y-skeleton--text");
|
|
116
|
-
this.classList.add(`a11y-skeleton--${this.variant}`);
|
|
117
|
-
this.setCssVar("--a11y-skeleton-width", this.optionalStringAttr("width"));
|
|
118
|
-
this.setCssVar("--a11y-skeleton-height", this.optionalStringAttr("height"));
|
|
119
|
-
this.classList.toggle("a11y-skeleton--multiline", this.variant === "text" && this.lines > 1);
|
|
120
|
-
}
|
|
121
|
-
render() {
|
|
122
|
-
if (this.variant === "text" && this.lines > 1) {
|
|
123
|
-
return html`${Array.from({ length: this.lines }, () => raw('<span class="a11y-skeleton__line"></span>'))}`;
|
|
124
|
-
}
|
|
125
|
-
return "";
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// src/accessibility-components/skeleton/define.ts
|
|
130
|
-
if (!customElements.get("a11y-skeleton")) {
|
|
131
|
-
customElements.define("a11y-skeleton", SkeletonElement);
|
|
132
|
-
}
|
|
133
|
-
export {
|
|
134
|
-
SkeletonElement
|
|
135
|
-
};
|
|
136
|
-
//# sourceMappingURL=define.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/a11y-element.ts","../../../../src/core/template.ts","../../../../src/accessibility-components/skeleton/skeleton.element.ts","../../../../src/accessibility-components/skeleton/define.ts"],"sourcesContent":["import type { Raw } from './template.js';\n\ntype Listener = [target: EventTarget, type: string, handler: EventListener, options?: AddEventListenerOptions | boolean];\n\n/**\n * Base class for every element in this library. Light DOM only — elements\n * render real child markup styled by the consumer's own CSS, not a shadow\n * root.\n *\n * Lifecycle mirrors the old `onBeforeRender -> innerHTML = template ->\n * onAfterRender` pipeline this library used to run through a proprietary\n * framework, just mapped onto native custom-element callbacks:\n *\n * connectedCallback -> first update()\n * attributeChangedCallback -> update() for any observed attribute change\n * disconnectedCallback -> remove all tracked listeners, then onDisconnect()\n *\n * Subclasses list attributes to watch via `static observedAttributes` and\n * implement `render()` to return the markup for `this.innerHTML`. Attribute/\n * property setters that need to reflect into the DOM should just mutate the\n * attribute — `attributeChangedCallback` re-renders synchronously while\n * connected, so state and DOM never drift out of sync across a render.\n */\nexport abstract class A11yElement extends HTMLElement {\n protected _connected = false;\n private _listeners: Listener[] = [];\n private _updating = false;\n\n connectedCallback(): void {\n this._connected = true;\n this.update();\n }\n\n disconnectedCallback(): void {\n this._connected = false;\n this._cleanupListeners();\n this.onDisconnect?.();\n }\n\n attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void {\n if (oldValue === newValue || !this._connected) return;\n this.update();\n }\n\n protected update(): void {\n // Re-entrancy guard: a listener/hook that itself mutates an observed\n // attribute during render must not trigger a nested render.\n if (this._updating) return;\n this._updating = true;\n try {\n this._cleanupListeners();\n this.onBeforeRender?.();\n this.innerHTML = String(this.render());\n this.onAfterRender?.();\n } finally {\n this._updating = false;\n }\n }\n\n /** Returns the markup to set as `this.innerHTML` on every render — a plain string, or an `html\\`...\\`` result. */\n protected abstract render(): string | Raw;\n\n /** Runs before `render()`. Typical use: set root-level classes/ARIA/CSS custom properties. */\n protected onBeforeRender?(): void;\n\n /** Runs after `render()` replaces `innerHTML`. Typical use: query into fresh markup, wire listeners, set DOM-only properties. */\n protected onAfterRender?(): void;\n\n /** Runs once, after listener cleanup, when the element leaves the DOM. */\n protected onDisconnect?(): void;\n\n /**\n * Adds a listener and tracks it for automatic removal on the next render\n * and on disconnect — the direct replacement for the old framework's\n * `[el, type, handler]` cleanup-array convention.\n */\n protected listen(\n target: EventTarget,\n type: string,\n handler: EventListener,\n options?: AddEventListenerOptions | boolean,\n ): void {\n target.addEventListener(type, handler, options);\n this._listeners.push([target, type, handler, options]);\n }\n\n private _cleanupListeners(): void {\n for (const [target, type, handler, options] of this._listeners) {\n target.removeEventListener(type, handler, options);\n }\n this._listeners = [];\n }\n\n /** Dispatches a bubbling CustomEvent from this element. */\n protected emit<T = unknown>(type: string, detail?: T): boolean {\n return this.dispatchEvent(new CustomEvent<T>(type, { bubbles: true, detail: detail as T }));\n }\n\n // --- small attribute-reflection helpers, shared across components ---\n\n protected stringAttr(name: string, fallback = ''): string {\n return this.getAttribute(name) ?? fallback;\n }\n\n protected optionalStringAttr(name: string): string | undefined {\n return this.getAttribute(name) ?? undefined;\n }\n\n protected boolAttr(name: string): boolean {\n return this.hasAttribute(name);\n }\n\n protected numberAttr(name: string, fallback: number): number {\n const value = this.getAttribute(name);\n if (value == null) return fallback;\n const parsed = Number(value);\n return Number.isNaN(parsed) ? fallback : parsed;\n }\n\n protected setBoolAttr(name: string, value: boolean): void {\n if (value) this.setAttribute(name, '');\n else this.removeAttribute(name);\n }\n\n /** Sets or removes a CSS custom property on this element depending on truthiness of `value`. */\n protected setCssVar(name: string, value: string | null | undefined): void {\n if (value) this.style.setProperty(name, value);\n else this.style.removeProperty(name);\n }\n}\n","/**\n * Pre-trusted HTML: opts out of auto-escaping when interpolated into an\n * `html` tagged template, and stringifies back to that exact markup when\n * assigned to `innerHTML` or concatenated. `html\\`...\\`` itself returns one\n * of these, which is what makes nesting `html` calls inside another `html`\n * call safe by construction — the inner result is never re-escaped, no\n * caller discipline (remembering to wrap it) required.\n */\nexport interface Raw {\n readonly __html: string;\n toString(): string;\n}\n\n/** Wraps a string as pre-trusted HTML. Use only for markup you built yourself — never for raw user input. */\nexport function raw(value: string): Raw {\n return { __html: value, toString: () => value };\n}\n\nfunction isRaw(value: unknown): value is Raw {\n return typeof value === 'object' && value !== null && '__html' in value;\n}\n\nfunction escape(value: unknown): string {\n if (value == null || value === false) return '';\n if (isRaw(value)) return value.__html;\n if (Array.isArray(value)) return value.map(escape).join('');\n return String(value)\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/**\n * Tagged template for building element markup. Literal template parts are\n * trusted structure; every interpolated value is HTML-escaped by default\n * (falsy values render as nothing, so `${cond && '<span>…</span>'}`-style\n * conditionals work without a directive attribute). Returns a `Raw`, so\n * nesting `html\\`...\\`` inside another `html\\`...\\`` template composes\n * safely without needing an explicit `raw()` wrapper.\n */\nexport function html(strings: TemplateStringsArray, ...values: unknown[]): Raw {\n return raw(strings.reduce((out, part, i) => out + part + escape(values[i]), ''));\n}\n\n/**\n * A `name=\"value\"` HTML attribute, with a leading space, escaped — or\n * nothing at all when `value` is `null`/`undefined`/`false`/`''`. Meant for\n * building conditional attribute lists inline:\n * `` html`<input${attr('id', id)}${flag('disabled', disabled)}>` ``\n */\nexport function attr(name: string, value: unknown): Raw {\n if (value == null || value === false || value === '') return raw('');\n return raw(` ${name}=\"${escape(value)}\"`);\n}\n\n/** A bare boolean attribute (e.g. `disabled`, `checked`), with a leading space, present only when `condition` is true. */\nexport function flag(name: string, condition: boolean | undefined): Raw {\n return raw(condition ? ` ${name}` : '');\n}\n","import { A11yElement } from '../../core/a11y-element.js';\nimport { html, raw, type Raw } from '../../core/template.js';\n\nexport type SkeletonVariant = 'rect' | 'circle' | 'text';\n\n/**\n * A loading placeholder shape. Zero JS required:\n * `<a11y-skeleton variant=\"text\" lines=\"3\"></a11y-skeleton>`\n */\nexport class SkeletonElement extends A11yElement {\n static get observedAttributes(): string[] {\n return ['variant', 'width', 'height', 'lines'];\n }\n\n get variant(): SkeletonVariant {\n const value = this.getAttribute('variant');\n return value === 'circle' || value === 'text' ? value : 'rect';\n }\n set variant(value: SkeletonVariant) {\n this.setAttribute('variant', value);\n }\n\n get lines(): number {\n return this.numberAttr('lines', 1);\n }\n set lines(value: number) {\n this.setAttribute('lines', String(value));\n }\n\n protected override onBeforeRender(): void {\n this.setAttribute('aria-hidden', 'true');\n this.classList.add('a11y-skeleton');\n this.classList.remove('a11y-skeleton--rect', 'a11y-skeleton--circle', 'a11y-skeleton--text');\n this.classList.add(`a11y-skeleton--${this.variant}`);\n this.setCssVar('--a11y-skeleton-width', this.optionalStringAttr('width'));\n this.setCssVar('--a11y-skeleton-height', this.optionalStringAttr('height'));\n this.classList.toggle('a11y-skeleton--multiline', this.variant === 'text' && this.lines > 1);\n }\n\n protected override render(): string | Raw {\n if (this.variant === 'text' && this.lines > 1) {\n return html`${Array.from({ length: this.lines }, () => raw('<span class=\"a11y-skeleton__line\"></span>'))}`;\n }\n return '';\n }\n}\n","import { SkeletonElement } from './skeleton.element.js';\n\nif (!customElements.get('a11y-skeleton')) {\n customElements.define('a11y-skeleton', SkeletonElement);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'a11y-skeleton': SkeletonElement;\n }\n}\n\nexport { SkeletonElement };\n"],"mappings":";AAuBO,IAAe,cAAf,cAAmC,YAAY;AAAA,EAC1C,aAAa;AAAA,EACf,aAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EAEpB,oBAA0B;AACxB,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,uBAA6B;AAC3B,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAAA,EACtB;AAAA,EAEA,yBAAyB,OAAe,UAAyB,UAA+B;AAC9F,QAAI,aAAa,YAAY,CAAC,KAAK,WAAY;AAC/C,SAAK,OAAO;AAAA,EACd;AAAA,EAEU,SAAe;AAGvB,QAAI,KAAK,UAAW;AACpB,SAAK,YAAY;AACjB,QAAI;AACF,WAAK,kBAAkB;AACvB,WAAK,iBAAiB;AACtB,WAAK,YAAY,OAAO,KAAK,OAAO,CAAC;AACrC,WAAK,gBAAgB;AAAA,IACvB,UAAE;AACA,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBU,OACR,QACA,MACA,SACA,SACM;AACN,WAAO,iBAAiB,MAAM,SAAS,OAAO;AAC9C,SAAK,WAAW,KAAK,CAAC,QAAQ,MAAM,SAAS,OAAO,CAAC;AAAA,EACvD;AAAA,EAEQ,oBAA0B;AAChC,eAAW,CAAC,QAAQ,MAAM,SAAS,OAAO,KAAK,KAAK,YAAY;AAC9D,aAAO,oBAAoB,MAAM,SAAS,OAAO;AAAA,IACnD;AACA,SAAK,aAAa,CAAC;AAAA,EACrB;AAAA;AAAA,EAGU,KAAkB,MAAc,QAAqB;AAC7D,WAAO,KAAK,cAAc,IAAI,YAAe,MAAM,EAA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