@hubpav/hwio-web-runtime 0.7.0 → 0.7.1
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/dist/nav.d.ts +4 -2
- package/dist/nav.js +40 -11
- package/package.json +1 -1
package/dist/nav.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Header behaviours:
|
|
3
|
-
*
|
|
2
|
+
* Header behaviours: drives the DaisyUI drawer from its [data-hwio-drawer-toggle] buttons (Enter and
|
|
3
|
+
* Space work because they are buttons; aria-expanded follows the checkbox, focus moves to the panel's
|
|
4
|
+
* first control on open and back to the trigger on close, Escape closes, a followed link closes),
|
|
5
|
+
* opens HWioHeader's mega panels
|
|
4
6
|
* ([data-hwio-mega-trigger] buttons and their [data-hwio-mega-panel]; hover with intent on pointer
|
|
5
7
|
* devices, click, ArrowDown into the panel, Escape / outside click / focus leaving close; one at a
|
|
6
8
|
* time), and marks the nav link whose section is in view ([data-hwio-scrollspy] nav with same-page
|
package/dist/nav.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { hwioMount } from './mount.js';
|
|
2
2
|
/**
|
|
3
|
-
* Header behaviours:
|
|
4
|
-
*
|
|
3
|
+
* Header behaviours: drives the DaisyUI drawer from its [data-hwio-drawer-toggle] buttons (Enter and
|
|
4
|
+
* Space work because they are buttons; aria-expanded follows the checkbox, focus moves to the panel's
|
|
5
|
+
* first control on open and back to the trigger on close, Escape closes, a followed link closes),
|
|
6
|
+
* opens HWioHeader's mega panels
|
|
5
7
|
* ([data-hwio-mega-trigger] buttons and their [data-hwio-mega-panel]; hover with intent on pointer
|
|
6
8
|
* devices, click, ArrowDown into the panel, Escape / outside click / focus leaving close; one at a
|
|
7
9
|
* time), and marks the nav link whose section is in view ([data-hwio-scrollspy] nav with same-page
|
|
@@ -21,16 +23,43 @@ export function hwioNavRuntime() {
|
|
|
21
23
|
controller = new AbortController();
|
|
22
24
|
const { signal } = controller;
|
|
23
25
|
document.querySelectorAll('input.drawer-toggle').forEach((input) => {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const side = input.parentElement?.querySelector('.drawer-side') ?? null;
|
|
27
|
+
const toggles = Array.from(document.querySelectorAll(`[data-hwio-drawer-toggle="${input.id}"]`));
|
|
28
|
+
const trigger = toggles.find((t) => !side?.contains(t)) ?? null;
|
|
29
|
+
const sync = () => toggles.forEach((t) => t.setAttribute('aria-expanded', String(input.checked)));
|
|
30
|
+
// DaisyUI reveals .drawer-side after a 100 ms visibility delay; retry per frame until the control takes focus.
|
|
31
|
+
const focusWhenVisible = (el, frames = 40) => {
|
|
32
|
+
if (!input.checked)
|
|
33
|
+
return;
|
|
34
|
+
el.focus();
|
|
35
|
+
if (document.activeElement !== el && frames > 0)
|
|
36
|
+
requestAnimationFrame(() => focusWhenVisible(el, frames - 1));
|
|
37
|
+
};
|
|
38
|
+
const apply = (restoreFocus) => {
|
|
32
39
|
sync();
|
|
33
|
-
|
|
40
|
+
if (input.checked) {
|
|
41
|
+
const first = side?.querySelector('button, a[href], input:not([type="hidden"]), select, textarea, summary, [tabindex]:not([tabindex="-1"])');
|
|
42
|
+
if (first)
|
|
43
|
+
focusWhenVisible(first);
|
|
44
|
+
}
|
|
45
|
+
else if (restoreFocus) {
|
|
46
|
+
trigger?.focus();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const setOpen = (open, restoreFocus = true) => {
|
|
50
|
+
if (input.checked === open)
|
|
51
|
+
return;
|
|
52
|
+
input.checked = open;
|
|
53
|
+
apply(restoreFocus);
|
|
54
|
+
};
|
|
55
|
+
sync();
|
|
56
|
+
toggles.forEach((t) => t.addEventListener('click', () => setOpen(!input.checked), { signal }));
|
|
57
|
+
// Labels (the overlay) still flip the checkbox natively; follow them.
|
|
58
|
+
input.addEventListener('change', () => apply(true), { signal });
|
|
59
|
+
// A followed link closes the drawer without stealing focus from the navigation target (same-page anchors).
|
|
60
|
+
side?.querySelectorAll('a[href]').forEach((a) => a.addEventListener('click', () => setOpen(false, false), { signal }));
|
|
61
|
+
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && input.checked)
|
|
62
|
+
setOpen(false); }, { signal });
|
|
34
63
|
});
|
|
35
64
|
const triggers = Array.from(document.querySelectorAll('[data-hwio-mega-trigger]'));
|
|
36
65
|
if (triggers.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubpav/hwio-web-runtime",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Framework-free browser runtime for the HARDWARIO websites: consent (Consent Mode v2 + GTM), HubSpot forms with Turnstile, attribution, theme, CTA tracking and small behaviours. View-transition safe.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|