ab-nextjs-components 0.4.2 โ†’ 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +81 -17
  2. package/README.md +16 -2
  3. package/ab-app-bar/index.tsx +5 -5
  4. package/ab-app-bar/styles.module.css +5 -5
  5. package/ab-bottom-drawer/index.tsx +3 -3
  6. package/ab-bottom-drawer/styles.module.css +2 -2
  7. package/ab-bottom-drawer/use-ab-swipe-down.ts +1 -1
  8. package/ab-breadcrumbs/index.tsx +1 -1
  9. package/ab-breadcrumbs/styles.module.css +5 -5
  10. package/ab-button/index.tsx +1 -1
  11. package/ab-button/styles.module.css +5 -5
  12. package/ab-callout/index.tsx +1 -1
  13. package/ab-callout/styles.module.css +1 -1
  14. package/ab-carousel/helpers.ts +1 -1
  15. package/ab-carousel/index.tsx +4 -4
  16. package/ab-carousel/styles.module.css +2 -2
  17. package/ab-chip/styles.module.css +1 -1
  18. package/ab-code-block/focus.tsx +63 -0
  19. package/ab-code-block/index.tsx +55 -28
  20. package/ab-code-block/styles.module.css +4 -3
  21. package/ab-content-tabs/index.tsx +25 -3
  22. package/ab-demo-box/index.tsx +45 -7
  23. package/ab-demo-box/styles.module.css +19 -7
  24. package/ab-demo-code/index.tsx +38 -34
  25. package/ab-demo-code/styles.module.css +3 -41
  26. package/ab-doc-pager/index.tsx +1 -1
  27. package/ab-drawer/gestures.ts +1 -1
  28. package/ab-drawer/index.tsx +12 -4
  29. package/ab-drawer/kit.module.css +13 -13
  30. package/ab-drawer/styles.module.css +2 -2
  31. package/ab-drawer/use-ab-edge-swipe.ts +2 -2
  32. package/ab-flow-diagram/helpers.ts +2 -2
  33. package/ab-flow-diagram/index.tsx +2 -2
  34. package/ab-flow-diagram/styles.module.css +3 -3
  35. package/ab-icon/builtin.ts +4 -0
  36. package/ab-icon/helpers.ts +1 -1
  37. package/ab-icon/index.tsx +3 -3
  38. package/ab-icon/registrar.tsx +1 -1
  39. package/ab-icon-button/index.tsx +1 -1
  40. package/ab-install-snippet/styles.module.css +1 -1
  41. package/ab-link/index.tsx +2 -2
  42. package/ab-link/locale.ts +1 -1
  43. package/ab-list/styles.module.css +1 -1
  44. package/ab-locale-switcher/index.tsx +6 -6
  45. package/ab-locale-switcher/styles.module.css +5 -5
  46. package/ab-mobile-header/index.tsx +6 -6
  47. package/ab-nav-drawer/index.tsx +11 -6
  48. package/ab-navbar/index.tsx +1 -1
  49. package/ab-navbar/styles.module.css +1 -1
  50. package/ab-navbar/view.tsx +1 -1
  51. package/ab-package-card/index.tsx +3 -3
  52. package/ab-package-card/previews.tsx +1 -1
  53. package/ab-package-card/styles.module.css +2 -2
  54. package/ab-playground-scene/i18n.module.css +1 -1
  55. package/ab-playground-scene/icons.tsx +1 -1
  56. package/ab-playground-scene/index.tsx +4 -4
  57. package/ab-playground-scene/labels.ts +3 -3
  58. package/ab-playground-scene/scenes.tsx +4 -4
  59. package/ab-playground-scene/styles.module.css +6 -6
  60. package/ab-playground-scene/upgraded.tsx +3 -3
  61. package/ab-playground-scene/welcome.tsx +1 -1
  62. package/ab-preview-code/index.tsx +115 -0
  63. package/ab-preview-code/stage.tsx +153 -0
  64. package/ab-preview-code/styles.module.css +43 -0
  65. package/ab-progress-chips/index.tsx +1 -1
  66. package/ab-search-drawer/index.tsx +4 -4
  67. package/ab-search-trigger/index.tsx +5 -5
  68. package/ab-search-trigger/styles.module.css +3 -3
  69. package/ab-settings-drawer/index.tsx +2 -2
  70. package/ab-sidebar/active.ts +105 -0
  71. package/ab-sidebar/index.tsx +10 -6
  72. package/ab-sidebar/profile-button.tsx +2 -2
  73. package/ab-sidebar/styles.module.css +4 -4
  74. package/ab-sidebar/view.tsx +16 -8
  75. package/ab-theme-mode/index.tsx +3 -3
  76. package/ab-theme-toggle/index.tsx +6 -6
  77. package/ab-theme-toggle/styles.module.css +2 -2
  78. package/ab-toc/index.tsx +3 -3
  79. package/ab-toc/promo.tsx +2 -2
  80. package/ab-toc/styles.module.css +1 -1
  81. package/ab-toc-drawer/index.tsx +1 -1
  82. package/ab-version-switcher/index.tsx +2 -2
  83. package/css/dialog.css +1 -1
  84. package/index.ts +29 -18
  85. package/package.json +3 -1
  86. package/server/ab-button/index.tsx +1 -1
  87. package/server/ab-icon/index.tsx +2 -2
  88. package/server/ab-sidebar/index.tsx +3 -2
  89. package/types/index.d.ts +8 -7
@@ -0,0 +1,63 @@
1
+ /*
2
+ * @license MIT
3
+ * ~~~~~~~~~~~~
4
+ * ab-nextjs-components
5
+ * ~~~~~~~~~~~~
6
+ * Copyright (c) 2026 Abraham Ukachi. The abElements Project.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the 'Software'), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *
26
+ * @project: ab-nextjs-components
27
+ * @name: AbCodeBlockFocus (0.6.0)
28
+ * @file: ab-code-block/focus.tsx
29
+ * @type: Client component (island)
30
+ * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
31
+ */
32
+
33
+ /*
34
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
35
+ * MOTTO: We'll always do more ๐Ÿ˜œ!!!
36
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
+ */
38
+
39
+ 'use client';
40
+
41
+ // โš›๏ธ React
42
+ import { useEffect, useRef, type ReactElement } from 'react';
43
+
44
+ /**
45
+ * โŒจ๏ธ AbCodeBlockFocus โ€” keeps ONE tab stop in a `trustedHtml` block. Shiki's string carries
46
+ * `<pre tabindex="0">`; we never edit that string, so after hydration this island sets the inner <pre>'s
47
+ * tabindex to -1 in the DOM (the wrapper scroller stays the stop). Before hydration / without JS the
48
+ * leftover tabindex remains (a harmless second stop); pass `highlighted` / children to avoid it entirely.
49
+ */
50
+ const AbCodeBlockFocus = (): ReactElement => {
51
+ const ref = useRef<HTMLSpanElement>(null); // ๐Ÿ“ to find our block
52
+ useEffect(() => {
53
+ const block = ref.current?.closest('[data-ab-part="code-block"]'); // ๐Ÿงฑ our AbCodeBlock
54
+ block?.querySelectorAll<HTMLElement>('[data-ab-part="code-block-code"] pre[tabindex]').forEach((pre) => {
55
+ if (pre.tabIndex >= 0) pre.setAttribute('tabindex', '-1'); // โœ‚๏ธ demote Shiki's stop (string untouched)
56
+ });
57
+ }); // ๐Ÿ” every render: a new trustedHtml string brings a new <pre>
58
+ return <span ref={ref} hidden data-ab-part="code-block-focus" />; // ๐Ÿซฅ an invisible anchor
59
+ };
60
+
61
+ // ๐Ÿ“ฆ exports
62
+ export default AbCodeBlockFocus;
63
+ export { AbCodeBlockFocus };
@@ -24,13 +24,13 @@
24
24
  * SOFTWARE.
25
25
  *
26
26
  * @project: ab-nextjs-components
27
- * @name: AbCodeBlock (0.3.4, Joseph 0.2.24 MDX docs)
27
+ * @name: AbCodeBlock (0.3.4, QA 0.2.24 MDX docs)
28
28
  * @file: ab-code-block/index.tsx
29
29
  * @type: Server component (no hooks; the copy button is a client island)
30
30
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
31
31
  *
32
32
  * Example usage:
33
- * 1+|> <AbCodeBlock filename="app/page.tsx" language="tsx" code={source} html={await codeToHtml(source, โ€ฆ)} />
33
+ * 1+|> <AbCodeBlock filename="app/page.tsx" language="tsx" code={source} trustedHtml={await codeToHtml(source, โ€ฆ)} />
34
34
  * 2+|> <AbCodeBlock language="bash" copyLabel={t('copy')} copiedLabel={t('copied')}><pre><code>pnpm add ab-nextjs-components</code></pre></AbCodeBlock>
35
35
  */
36
36
 
@@ -46,40 +46,52 @@ import { Children, cloneElement, isValidElement, type ReactElement, type ReactNo
46
46
  import clsx from 'clsx';
47
47
  // ๐Ÿ“‹ the copy button (the only client part)
48
48
  import AbCodeBlockCopy from './copy';
49
+ // โŒจ๏ธ 0.6.0: demotes Shiki's <pre tabindex="0"> inside a trustedHtml block after hydration (one tab stop)
50
+ import AbCodeBlockFocus from './focus';
49
51
  // ๐ŸŽจ styles
50
52
  import styles from './styles.module.css';
51
53
 
52
- // ๐Ÿ”ค escape a name for an HTML attribute (the `html` path)
53
- const escAttr = (v: string) => v.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;'); // ๐Ÿงน
54
+ /**
55
+ * ๐Ÿšจ risky patterns in a `trustedHtml` string (dev warning only, NOT a sanitizer):
56
+ * <script, an onโ€ฆ= event handler, javascript:, <iframe, srcdoc
57
+ */
58
+ const AB_RISKY_HTML: ReadonlyArray<[string, RegExp]> = [
59
+ ['<script', /<script\b/i], // ๐Ÿ“œ inline script
60
+ ['onโ€ฆ= handler', /\son[a-z]+\s*=/i], // ๐Ÿ–ฑ๏ธ onclick=, onerror=, โ€ฆ
61
+ ['javascript:', /javascript\s*:/i], // ๐Ÿ”— script URL
62
+ ['<iframe', /<iframe\b/i], // ๐ŸชŸ embedded frame
63
+ ['srcdoc', /\bsrcdoc\b/i], // ๐Ÿ“„ inline frame document
64
+ ];
65
+
66
+ /** โš ๏ธ dev only: warn when `trustedHtml` looks like it carries script (silent in production) */
67
+ export function warnAbRiskyHtml(html: string, where = 'AbCodeBlock'): void {
68
+ if (process.env.NODE_ENV === 'production') return; // ๐Ÿคซ never in production
69
+ const hits = AB_RISKY_HTML.filter(([, re]) => re.test(html)).map(([n]) => n); // ๐Ÿ”Ž
70
+ if (hits.length) console.warn(`[${where}] trustedHtml contains ${hits.join(', ')}. It is injected without sanitizing: only pass HTML you render yourself (e.g. Shiki), never user input. Prefer \`highlighted\`/children.`); // โš ๏ธ
71
+ }
54
72
 
55
73
  /**
56
- * โŒจ๏ธ 0.4.0 (God): a plain <pre> gets tabIndex 0 (keyboard users can scroll long lines with the arrow keys) and a name.
57
- * Shiki's <pre tabindex="0"> keeps its own tabindex (never doubled); an existing aria-label is never replaced.
74
+ * โŒจ๏ธ 0.6.0: ONE tab stop per block. The wrapper (`code-block-code`) is the horizontal scroller and the focus
75
+ * target (arrow keys scroll long lines), so a direct <pre> child loses an auto/Shiki `tabIndex={0}` (it would be
76
+ * a second stop). An author's explicit negative tabIndex and any aria-label on the <pre> are kept.
58
77
  */
59
- function withAbFocusablePre(children: ReactNode, name?: string): ReactNode {
78
+ function withAbSingleStopPre(children: ReactNode): ReactNode {
60
79
  return Children.map(children, (c) => {
61
80
  if (!isValidElement<Record<string, unknown>>(c) || c.type !== 'pre') return c; // ๐Ÿ™… only a direct <pre>
62
- const extra: Record<string, unknown> = {}; // ๐Ÿงฉ what we add
63
- if (c.props.tabIndex == null && c.props.tabindex == null) extra.tabIndex = 0; // โŒจ๏ธ focusable
64
- if (name && c.props['aria-label'] == null && c.props['aria-labelledby'] == null) extra['aria-label'] = name; // ๐Ÿท๏ธ named
65
- return Object.keys(extra).length ? cloneElement(c, extra) : c; // โœ…
66
- });
67
- }
68
-
69
- /** ๐Ÿงพ the same for an `html` string: patch the FIRST <pre โ€ฆ> tag only */
70
- function withAbFocusablePreHtml(html: string, name?: string): string {
71
- return html.replace(/<pre\b([^>]*)>/i, (tag, attrs: string) => {
72
- let a = attrs; // ๐Ÿงฉ
73
- if (!/\stabindex\s*=/i.test(a)) a += ' tabindex="0"'; // โŒจ๏ธ Shiki already has one โ†’ untouched
74
- if (name && !/\saria-label(ledby)?\s*=/i.test(a)) a += ` aria-label="${escAttr(name)}"`; // ๐Ÿท๏ธ
75
- return `<pre${a}>`; // โœ…
81
+ const t = c.props.tabIndex ?? c.props.tabindex; // ๐Ÿ”Ž Shiki sets 0
82
+ if (t == null || Number(t) < 0) return c; // โœ… nothing to drop (or an author's -1)
83
+ return cloneElement(c, { tabIndex: undefined, tabindex: undefined }); // โœ‚๏ธ the wrapper is the stop now
76
84
  });
77
85
  }
78
86
 
79
87
  /** โš™๏ธ props */
80
88
  export interface AbCodeBlockProps {
81
89
  children?: ReactNode; // ๐Ÿ–๏ธ Shiki-rendered (or plain) <pre><code>โ€ฆ</code></pre>, e.g. from rehype-pretty-code in MDX
82
- html?: string; // ๐Ÿงพ OR a pre-rendered HTML string (Shiki `codeToHtml`), trusted: YOU render it, never user input
90
+ /**
91
+ * ๐Ÿงพ OR a pre-rendered HTML string (Shiki `codeToHtml`). โš ๏ธ Injected via dangerouslySetInnerHTML WITHOUT
92
+ * sanitizing: it MUST be trusted (you render it at build/server time), never user input. Prefer children.
93
+ */
94
+ trustedHtml?: string;
83
95
  code?: string; // ๐Ÿ“‹ the raw source to copy (best). Without it the button copies the rendered <pre>'s text
84
96
  title?: ReactNode; // ๐Ÿท๏ธ a caption in the header bar (e.g. "Install")
85
97
  filename?: string; // ๐Ÿ“„ a file name in the header bar (mono), e.g. "app/page.tsx"
@@ -92,15 +104,16 @@ export interface AbCodeBlockProps {
92
104
 
93
105
  /**
94
106
  * ๐Ÿ’ป AbCodeBlock โ€” a server-rendered code block for MDX docs: an optional header (title / filename ยท language),
95
- * the highlighted code (children or an `html` string, both from Shiki), and a small client copy button. It is a
107
+ * the highlighted code (children or a `trustedHtml` string, both from Shiki), and a small client copy button. It is a
96
108
  * <figure> (with a <figcaption> when there is a header), so the caption names the code for assistive tech; the
97
- * <pre> is focusable (Shiki's tabindex kept, a plain one gets tabIndex 0) and named, so keyboard users can scroll it.
109
+ * scroller wrapper is the single focusable, named tab stop, so keyboard users can scroll long lines with the arrows.
98
110
  */
99
- const AbCodeBlock = ({ children, html, code, title, filename, language, copyLabel = 'Copy code', copiedLabel = 'Copied', copy = true, className }: AbCodeBlockProps): ReactElement => {
111
+ const AbCodeBlock = ({ children, trustedHtml, code, title, filename, language, copyLabel = 'Copy code', copiedLabel = 'Copied', copy = true, className }: AbCodeBlockProps): ReactElement => {
100
112
  const hasHeader = title != null || !!filename || !!language; // ๐Ÿท๏ธ a header bar?
101
113
  const caption = (title ?? filename) != null; // ๐Ÿ’ฌ a visible name for the figure
102
114
  // ๐Ÿท๏ธ the scroller's name: the title (if text), else the filename, else "<language> code"
103
115
  const preName = typeof title === 'string' ? title : filename || (language ? `${language} code` : undefined);
116
+ if (trustedHtml != null) warnAbRiskyHtml(trustedHtml); // โš ๏ธ dev-only check
104
117
  return (
105
118
  <figure
106
119
  className={clsx('AbCodeBlock', 'ab-prose-none', styles.abCodeBlock, className)} // ๐ŸŽจ (opts out of theme .ab-prose)
@@ -116,9 +129,23 @@ const AbCodeBlock = ({ children, html, code, title, filename, language, copyLabe
116
129
  </figcaption>
117
130
  )}
118
131
  <div className={styles.abCodeBlockBody}>
119
- {html != null
120
- ? <div className={styles.abCodeBlockCode} data-ab-part="code-block-code" dangerouslySetInnerHTML={{ __html: withAbFocusablePreHtml(html, preName) }} /> // ๐Ÿงพ Shiki string (+ a focusable, named <pre>)
121
- : <div className={styles.abCodeBlockCode} data-ab-part="code-block-code">{withAbFocusablePre(children, preName)}</div> /* ๐Ÿ–๏ธ Shiki children (+ a focusable, named <pre>) */}
132
+ {trustedHtml != null
133
+ ? <div
134
+ className={styles.abCodeBlockCode} // โ†”๏ธ 0.6.0: the scroller (the inner <pre> is overflow: visible)
135
+ data-ab-part="code-block-code"
136
+ tabIndex={0} // โŒจ๏ธ the ONE tab stop: arrow keys scroll long lines (no regex patching of the HTML)
137
+ role="group" // โ™ฟ a named, focusable group (aria-label needs a role)
138
+ aria-label={preName} // ๐Ÿท๏ธ
139
+ dangerouslySetInnerHTML={{ __html: trustedHtml }} // ๐Ÿงพ trusted Shiki string, injected as-is
140
+ />
141
+ : <div
142
+ className={styles.abCodeBlockCode} // โ†”๏ธ the scroller
143
+ data-ab-part="code-block-code"
144
+ tabIndex={0} // โŒจ๏ธ the ONE tab stop
145
+ role="group" // โ™ฟ
146
+ aria-label={preName} // ๐Ÿท๏ธ
147
+ >{withAbSingleStopPre(children) /* ๐Ÿ–๏ธ Shiki children, minus their own tab stop */}</div>}
148
+ {trustedHtml != null && <AbCodeBlockFocus /> /* โŒจ๏ธ client island: Shiki's leftover <pre tabindex> โ†’ -1 */}
122
149
  {copy && <AbCodeBlockCopy code={code} label={copyLabel} copiedLabel={copiedLabel} /> /* ๐Ÿ“‹ client island */}
123
150
  </div>
124
151
  </figure>
@@ -44,7 +44,7 @@
44
44
  border-radius: var(--ab-radius-code, 12px); /* ๐ŸŸข */
45
45
  background: var(--ab-color-code-surface, #231a14); /* ๐ŸŽจ */
46
46
  color: var(--ab-color-on-code-surface, #f4ece5); /* ๐Ÿ–‹๏ธ */
47
- color-scheme: dark; /* ๐ŸŒ‘ 0.4.1 (Joseph 0.2.24, gap 3): scrollbars, selection + the copy button match the dark surface in every page scheme */
47
+ color-scheme: dark; /* ๐ŸŒ‘ 0.4.1 (0.2.24, gap 3): scrollbars, selection + the copy button match the dark surface in every page scheme */
48
48
  }
49
49
  /* ๐Ÿท๏ธ header: title ยท filename ยท language badge */
50
50
  .abCodeBlockHead { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px 0 16px; border-bottom: 1px solid rgb(255 255 255 / 0.08); font: 500 12.5px/1.2 var(--ab-font-body, system-ui, sans-serif); } /* ๐Ÿ“ */
@@ -53,8 +53,9 @@
53
53
  .abCodeBlockLang { margin-inline-start: auto; padding: 2px 6px; border-radius: 4px; background: rgb(255 255 255 / 0.08); font: 600 11px/1 var(--ab-font-code, ui-monospace, monospace); text-transform: lowercase; } /* ๐Ÿ”ค badge */
54
54
  /* ๐Ÿงฑ body: the code + the copy button in its top-end corner */
55
55
  .abCodeBlockBody { position: relative; } /* ๐Ÿ“Œ */
56
- .abCodeBlockCode :where(pre) { margin: 0; padding: 14px 56px 14px 16px; overflow-x: auto; background: transparent !important; font: 13.5px/1.6 var(--ab-font-code, ui-monospace, monospace); } /* โ†”๏ธ scrolls; room for the button; Shiki's inline bg yields to ours */
57
- .abCodeBlockCode :where(pre):focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; } /* โ™ฟ */
56
+ .abCodeBlockCode { overflow-x: auto; margin-inline-end: 48px; } /* โ†”๏ธ 0.6.0: the WRAPPER is the scroller + the one tab stop; ๐Ÿ“‹ its end stops 48px short, so long lines (390px phones too) never scroll UNDER the 44px copy button */
57
+ .abCodeBlockCode:focus-visible { outline: 2px solid var(--ab-color-accent, #a67c52); outline-offset: -2px; } /* โ™ฟ */
58
+ .abCodeBlockCode :where(pre) { margin: 0; padding: 14px 8px 14px 16px; overflow: visible; inline-size: max-content; min-inline-size: 100%; box-sizing: border-box; background: transparent !important; font: 13.5px/1.6 var(--ab-font-code, ui-monospace, monospace); } /* ๐Ÿ“œ (end room comes from the scroller's gutter) grows with its longest line, the wrapper scrolls it; Shiki's inline bg yields to ours */
58
59
  .abCodeBlockCode :where(code) { font: inherit; } /* ๐Ÿ”ค */
59
60
  .abCodeBlockCopy { position: absolute; inset-block-start: 4px; inset-inline-end: 4px; color: inherit; } /* ๐Ÿ“‹ 44px button (AbIconButton) */
60
61
  .srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } /* ๐Ÿ•ถ๏ธ */
@@ -24,7 +24,7 @@
24
24
  * SOFTWARE.
25
25
  *
26
26
  * @project: ab-nextjs-components
27
- * @name: AbContentTabs + AbContentTab (0.3.4, Joseph 0.2.24 MDX docs)
27
+ * @name: AbContentTabs + AbContentTab (0.3.4, QA 0.2.24 MDX docs)
28
28
  * @file: ab-content-tabs/index.tsx
29
29
  * @type: Client component
30
30
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
@@ -43,12 +43,18 @@
43
43
  'use client';
44
44
 
45
45
  // โš›๏ธ React
46
- import { Children, isValidElement, useId, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
46
+ import { Children, isValidElement, useEffect, useId, useRef, useState, type KeyboardEvent, type ReactElement, type ReactNode } from 'react';
47
47
  // ๐Ÿงต classes
48
48
  import clsx from 'clsx';
49
49
  // ๐ŸŽจ styles
50
50
  import styles from './styles.module.css';
51
51
 
52
+ /**
53
+ * โŒจ๏ธ 0.6.0: what counts as "already focusable" inside a panel. A panel that holds one of these is left OUT of
54
+ * the tab order (its content is the stop, e.g. a code block's scroller); an empty / text-only panel stays tabIndex 0.
55
+ */
56
+ export const AB_FOCUSABLE_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable]:not([contenteditable="false"]), summary';
57
+
52
58
  /** โš™๏ธ one tab (a marker element: AbContentTabs reads its props, it renders only its children) */
53
59
  export interface AbContentTabProps {
54
60
  label: ReactNode; // ๐Ÿท๏ธ the tab's text, e.g. "pnpm"
@@ -85,6 +91,21 @@ const AbContentTabs = ({ children, label, defaultValue, onChange, className }: A
85
91
  const [selected, setSelected] = useState(() => (defaultValue && values.includes(defaultValue) ? defaultValue : values[0])); // ๐ŸŽฏ
86
92
  const current = values.includes(selected) ? selected : values[0]; // ๐Ÿ›Ÿ children changed
87
93
  const refs = useRef<Array<HTMLButtonElement | null>>([]); // ๐Ÿ“ to move focus
94
+ const panels = useRef<Array<HTMLDivElement | null>>([]); // ๐Ÿ“ the tabpanels (focusable-content check)
95
+ // โŒจ๏ธ 0.6.0: which panels already contain a focusable element. SSR + the first client render say "none"
96
+ // (every panel tabIndex 0, the APG-safe no-JS default), so hydration matches; the effect then refines it.
97
+ const [hasFocusable, setHasFocusable] = useState<boolean[]>([]);
98
+ useEffect(() => {
99
+ const check = () => {
100
+ const next = panels.current.slice(0, tabs.length).map((el) => !!el?.querySelector(AB_FOCUSABLE_SELECTOR)); // ๐Ÿ”Ž
101
+ setHasFocusable((prev) => (prev.length === next.length && prev.every((v, k) => v === next[k]) ? prev : next)); // ๐Ÿง˜ no-op when unchanged
102
+ };
103
+ check(); // ๐Ÿš€ after mount
104
+ if (typeof MutationObserver === 'undefined') return; // ๐Ÿ›Ÿ very old engines: the mount check only
105
+ const mo = new MutationObserver(check); // ๐Ÿ‘€ content changes (MDX, islands, hydration fixes)
106
+ panels.current.forEach((el) => el && mo.observe(el, { childList: true, subtree: true, attributes: true, attributeFilter: ['tabindex', 'href', 'contenteditable', 'disabled'] }));
107
+ return () => mo.disconnect(); // ๐Ÿงน
108
+ }, [tabs.length]);
88
109
  const select = (v: string) => { setSelected(v); onChange?.(v); }; // โœ…
89
110
  // โŒจ๏ธ roving keys on the tablist
90
111
  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
@@ -128,7 +149,8 @@ const AbContentTabs = ({ children, label, defaultValue, onChange, className }: A
128
149
  id={`${id}-panel-${i}`} // ๐Ÿ†”
129
150
  aria-labelledby={`${id}-tab-${i}`} // ๐Ÿ”—
130
151
  hidden={values[i] !== current} // ๐Ÿ™ˆ inactive
131
- tabIndex={0} // โŒจ๏ธ reachable even when it has no focusable content (APG)
152
+ ref={(el) => { panels.current[i] = el; }} // ๐Ÿ“
153
+ tabIndex={hasFocusable[i] ? undefined : 0} // โŒจ๏ธ 0.6.0 (APG): a stop ONLY when nothing inside is focusable
132
154
  className={styles.abContentTabsPanel} // ๐ŸŽจ
133
155
  data-ab-part="content-tab-panel" // ๐Ÿ—‚๏ธ
134
156
  >
@@ -6,34 +6,72 @@
6
6
  * Copyright (c) 2026 Abraham Ukachi. The abElements Project.
7
7
  *
8
8
  * @project: ab-nextjs-components
9
- * @name: AbDemoBox - Client (port of lyd-demo-box)
9
+ * @name: AbDemoBox (port of lyd-demo-box; 0.6.0: the G16 preview scope)
10
10
  * @file: ab-demo-box/index.tsx
11
+ * @type: Server-safe component (no 'use client', no hooks)
11
12
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
13
+ *
14
+ * Example usage:
15
+ * 1+|> <AbDemoBox label="Button preview" scheme="dark"><AbButton label="Save" /></AbDemoBox>
12
16
  */
13
17
 
14
- 'use client';
18
+ /*
19
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20
+ * MOTTO: We'll always do more ๐Ÿ˜œ!!!
21
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22
+ */
15
23
 
24
+ // โš›๏ธ React (forwardRef works in server components too)
16
25
  import type { ReactElement, ReactNode } from 'react';
17
26
  import { forwardRef } from 'react';
27
+ // ๐Ÿงต classes
18
28
  import clsx from 'clsx';
29
+ // ๐ŸŽจ styles
19
30
  import styles from './styles.module.css';
20
31
 
32
+ /** ๐ŸŒ— the preview's colour scheme: follow the page, or force one (theme `[data-theme]` tokens re-apply inside) */
33
+ export type AbDemoBoxScheme = 'inherit' | 'light' | 'dark';
34
+
35
+ /** โš™๏ธ props */
21
36
  export interface AbDemoBoxProps {
22
- className?: string;
23
- hidden?: boolean;
24
- children?: ReactNode;
37
+ className?: string; // ๐Ÿท๏ธ
38
+ hidden?: boolean; // ๐Ÿ™ˆ
39
+ children?: ReactNode; // ๐Ÿงช the live preview: real JSX (package components), never eval'd strings
40
+ label?: string; // โ™ฟ 0.6.0: names the preview as a region, e.g. "AbButton preview" (no role without it)
41
+ scheme?: AbDemoBoxScheme; // ๐ŸŒ— 0.6.0: default 'inherit'
42
+ align?: 'center' | 'start' | 'stretch'; // ๐Ÿ“ 0.6.0: how the content sits in the box (default 'center')
25
43
  }
26
44
 
45
+ /**
46
+ * ๐Ÿงช AbDemoBox โ€” the G16 **preview scope**: an isolated surface for a live component preview.
47
+ *
48
+ * - ๐ŸŒ— `scheme` forces light / dark through the theme's `[data-theme]` tokens, with matching `color-scheme`.
49
+ * - ๐Ÿ“ฆ `contain: layout paint` + `isolation: isolate`: fixed / absolute children (balloons, drawers) are positioned
50
+ * and clipped by the box, and z-indexes can't climb over the page. AbDrawer hosts its layer here (any scope).
51
+ * - ๐Ÿงฑ its own text + background from the theme tokens, so the page's prose styles don't leak in (`ab-prose-none`).
52
+ * - โ™ฟ with `label` it is a named `role="region"`. No motion (all motion lives in ab-nextjs-animations).
53
+ */
27
54
  const AbDemoBox = forwardRef<HTMLDivElement, AbDemoBoxProps>(function AbDemoBox(
28
- { className, hidden = false, children },
55
+ { className, hidden = false, children, label, scheme = 'inherit', align = 'center' },
29
56
  ref,
30
57
  ): ReactElement {
31
58
  return (
32
- <div ref={ref} hidden={hidden} className={clsx('AbDemoBox', styles.abDemoBox, className)}>
59
+ <div
60
+ ref={ref}
61
+ hidden={hidden}
62
+ className={clsx('AbDemoBox', 'ab-prose-none', styles.abDemoBox, className)} // ๐ŸŽจ + opt out of theme prose
63
+ data-ab-part="demo-box" // ๐Ÿ—‚๏ธ
64
+ data-ab-preview-scope="" // ๐Ÿ“ฆ drawers + portals inside stay inside (AbDrawer reads it)
65
+ data-theme={scheme === 'inherit' ? undefined : scheme} // ๐ŸŒ— theme tokens re-declared on this box
66
+ data-align={align === 'center' ? undefined : align} // ๐Ÿ“
67
+ role={label ? 'region' : undefined} // โ™ฟ a landmark only when it has a name
68
+ aria-label={label} // ๐Ÿท๏ธ
69
+ >
33
70
  {children}
34
71
  </div>
35
72
  );
36
73
  });
37
74
 
75
+ // ๐Ÿ“ฆ exports
38
76
  export default AbDemoBox;
39
77
  export { AbDemoBox };
@@ -30,16 +30,28 @@
30
30
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
31
31
  */
32
32
 
33
+ /* ๐Ÿงช 0.6.0 (G16): the preview scope. Theme tokens first, the old M3 names as fallbacks */
33
34
  .abDemoBox {
34
- position: relative;
35
+ position: relative; /* ๐Ÿ“Œ the drawer layer + absolute children anchor here */
36
+ contain: layout paint; /* ๐Ÿ“ฆ a containing block for position: fixed too, and clips paint to the box */
37
+ isolation: isolate; /* ๐Ÿฅž z-indexes stay inside */
35
38
  display: flex;
36
39
  flex-direction: column;
40
+ align-items: center; /* ๐Ÿ“ default: centred */
41
+ justify-content: center;
37
42
  gap: 1rem;
43
+ min-block-size: 160px; /* ๐Ÿ“ room for a drawer / menu demo */
38
44
  padding: 1.25rem;
39
- border-radius: 1rem;
40
- border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
41
- background:
42
- radial-gradient(circle at top right, color-mix(in srgb, var(--ab-primary, #6750a4) 10%, transparent), transparent 45%),
43
- var(--ab-surface, #fff);
44
- overflow: hidden;
45
+ border-radius: var(--ab-radius-code, 12px); /* ๐ŸŸข same corner as AbCodeBlock */
46
+ border: 1px solid var(--ab-color-border, color-mix(in srgb, currentColor 12%, transparent)); /* ๐Ÿ”ฒ */
47
+ background: var(--ab-color-card, var(--ab-surface, #fff)); /* ๐Ÿƒ its own surface */
48
+ color: var(--ab-color-on-background, var(--ab-color-on-surface, inherit)); /* ๐Ÿ–‹๏ธ its own text colour */
49
+ font-family: var(--ab-font-body, system-ui, sans-serif); /* ๐Ÿ”ค the page's prose font size doesn't leak in */
50
+ font-size: 1rem;
51
+ line-height: 1.5;
52
+ overflow: hidden; /* โœ‚๏ธ */
45
53
  }
54
+ .abDemoBox[data-theme='light'] { color-scheme: light; } /* ๐ŸŒž native UI follows (also without the theme) */
55
+ .abDemoBox[data-theme='dark'] { color-scheme: dark; } /* ๐ŸŒ™ */
56
+ .abDemoBox[data-align='start'] { align-items: flex-start; justify-content: flex-start; } /* ๐Ÿ“ */
57
+ .abDemoBox[data-align='stretch'] { align-items: stretch; justify-content: flex-start; } /* ๐Ÿ“ */
@@ -6,58 +6,62 @@
6
6
  * Copyright (c) 2026 Abraham Ukachi. The abElements Project.
7
7
  *
8
8
  * @project: ab-nextjs-components
9
- * @name: AbDemoCode - Client (port of lyd-demo-code; prism soft-optional)
9
+ * @name: AbDemoCode (port of lyd-demo-code; 0.6.0: built on AbCodeBlock)
10
10
  * @file: ab-demo-code/index.tsx
11
+ * @type: Server-safe component (the copy button is AbCodeBlock's client island)
11
12
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
13
+ *
14
+ * Example usage:
15
+ * 1+|> <AbDemoCode language="tsx" code={`<AbButton label="Save" />`} />
12
16
  */
13
17
 
14
- 'use client';
18
+ /*
19
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20
+ * MOTTO: We'll always do more ๐Ÿ˜œ!!!
21
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22
+ */
15
23
 
16
- import type { ReactElement } from 'react';
17
- import { forwardRef, useState } from 'react';
24
+ // โš›๏ธ React
25
+ import type { ReactElement, ReactNode } from 'react';
26
+ import { forwardRef } from 'react';
27
+ // ๐Ÿงต classes
18
28
  import clsx from 'clsx';
29
+ // ๐Ÿ’ป the docs code block (header, focusable <pre>, AbIcon copy button with a polite "Copied")
30
+ import AbCodeBlock from '../ab-code-block';
31
+ // ๐ŸŽจ styles
19
32
  import styles from './styles.module.css';
20
33
 
34
+ /** โš™๏ธ props (the 0.1.x shape, plus the AbCodeBlock options a preview pair needs) */
21
35
  export interface AbDemoCodeProps {
22
- className?: string;
23
- hidden?: boolean;
24
- language?: 'tsx' | 'css' | 'ts' | 'js' | string;
25
- code: string;
36
+ className?: string; // ๐Ÿท๏ธ
37
+ hidden?: boolean; // ๐Ÿ™ˆ
38
+ language?: 'tsx' | 'css' | 'ts' | 'js' | string; // ๐Ÿ”ค default 'tsx'
39
+ code: string; // ๐Ÿ“‹ the raw source (shown when there is no `trustedHtml` / `children`, always what Copy copies)
40
+ trustedHtml?: string; // ๐Ÿงพ 0.6.0: Shiki `codeToHtml` output, โš ๏ธ NOT sanitized: trusted HTML only, never user input (prefer children)
41
+ children?: ReactNode; // ๐Ÿ–๏ธ 0.6.0: OR an already highlighted <pre> (e.g. an MDX fenced block)
42
+ filename?: string; // ๐Ÿ“„ 0.6.0
43
+ copyLabel?: string; // โ™ฟ 0.6.0 (default "Copy code")
44
+ copiedLabel?: string; // โœ… 0.6.0 (default "Copied")
26
45
  }
27
46
 
47
+ /**
48
+ * ๐Ÿ’ป AbDemoCode โ€” the source half of a preview pair. Since 0.6.0 it is an AbCodeBlock, so it shares the
49
+ * highlighted rendering, the named + focusable <pre> and the SVG copy button (no icon font, no local timer).
50
+ * The plain fallback is a <pre><code> of `code` (React escapes it; nothing is ever evaluated).
51
+ */
28
52
  const AbDemoCode = forwardRef<HTMLDivElement, AbDemoCodeProps>(function AbDemoCode(
29
- { className, hidden = false, language = 'tsx', code },
53
+ { className, hidden = false, language = 'tsx', code, trustedHtml, children, filename, copyLabel, copiedLabel },
30
54
  ref,
31
55
  ): ReactElement {
32
- const [copied, setCopied] = useState(false);
33
-
34
- const copy = async () => {
35
- try {
36
- await navigator.clipboard.writeText(code);
37
- setCopied(true);
38
- window.setTimeout(() => setCopied(false), 1500);
39
- } catch {
40
- setCopied(false);
41
- }
42
- };
43
-
44
56
  return (
45
- <div ref={ref} hidden={hidden} className={clsx('AbDemoCode', styles.abDemoCode, className)}>
46
- <div className={styles.abDemoCodeHeader}>
47
- <span>{language}</span>
48
- <button type="button" className={styles.abDemoCodeCopy} onClick={copy} aria-label="Copy code">
49
- <span className="material-symbols-rounded" aria-hidden style={{ fontSize: 16 }}>
50
- {copied ? 'check' : 'content_copy'}
51
- </span>
52
- {copied ? 'Copied' : 'Copy'}
53
- </button>
54
- </div>
55
- <pre className={styles.abDemoCodePre}>
56
- <code className={styles.abDemoCodeCode}>{code}</code>
57
- </pre>
57
+ <div ref={ref} hidden={hidden} className={clsx('AbDemoCode', styles.abDemoCode, className)} data-ab-part="demo-code">
58
+ <AbCodeBlock code={code} trustedHtml={trustedHtml} language={language} filename={filename} copyLabel={copyLabel} copiedLabel={copiedLabel}>
59
+ {children ?? <pre><code>{code}</code></pre> /* ๐Ÿงพ plain, escaped */}
60
+ </AbCodeBlock>
58
61
  </div>
59
62
  );
60
63
  });
61
64
 
65
+ // ๐Ÿ“ฆ exports
62
66
  export default AbDemoCode;
63
67
  export { AbDemoCode };
@@ -30,44 +30,6 @@
30
30
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
31
31
  */
32
32
 
33
- .abDemoCode {
34
- position: relative;
35
- border-radius: 0.75rem;
36
- overflow: hidden;
37
- background: #1e1e2e;
38
- color: #cdd6f4;
39
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
40
- font-size: 0.8125rem;
41
- line-height: 1.5;
42
- }
43
- .abDemoCodeHeader {
44
- display: flex;
45
- align-items: center;
46
- justify-content: space-between;
47
- gap: 0.5rem;
48
- padding: 0.4rem 0.75rem;
49
- background: color-mix(in srgb, #000 25%, transparent);
50
- font-size: 0.7rem;
51
- text-transform: uppercase;
52
- letter-spacing: 0.06em;
53
- opacity: 0.85;
54
- }
55
- .abDemoCodeCopy {
56
- border: none;
57
- background: transparent;
58
- color: inherit;
59
- cursor: pointer;
60
- display: inline-flex;
61
- align-items: center;
62
- gap: 0.25rem;
63
- font: inherit;
64
- opacity: 0.8;
65
- }
66
- .abDemoCodeCopy:hover { opacity: 1; }
67
- .abDemoCodePre {
68
- margin: 0;
69
- padding: 0.85rem 1rem 1rem;
70
- overflow: auto;
71
- max-height: 24rem;
72
- }
73
- .abDemoCodeCode { white-space: pre; }
33
+ /* ๐Ÿ’ป 0.6.0: AbCodeBlock draws the block; this wrapper only drops its bottom margin inside a preview pair */
34
+ .abDemoCode { min-inline-size: 0; } /* โ†”๏ธ long lines scroll in the <pre>, never widen the page */
35
+ .abDemoCode > :global(.AbCodeBlock) { margin: 0; } /* โ†•๏ธ */
@@ -24,7 +24,7 @@
24
24
  * SOFTWARE.
25
25
  *
26
26
  * @project: ab-nextjs-components
27
- * @name: AbDocPager (0.3.4, Joseph 0.2.24 MDX docs)
27
+ * @name: AbDocPager (0.3.4, QA 0.2.24 MDX docs)
28
28
  * @file: ab-doc-pager/index.tsx
29
29
  * @type: Server-safe component (links via AbLinkProvider)
30
30
  * @authors: Abraham Ukachi <abrahamukachi@gmail.com>
@@ -36,7 +36,7 @@
36
36
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37
37
  */
38
38
 
39
- // ๐Ÿค drawers v2 (John, God 01:22): the thresholds and decisions behind every drawer swipe, as pure functions,
39
+ // ๐Ÿค drawers v2 (01:22): the thresholds and decisions behind every drawer swipe, as pure functions,
40
40
  // so the rules are unit-tested without a DOM and the components only feed them numbers.
41
41
 
42
42
  /** ๐ŸŽš๏ธ the spec numbers (drawer-spec.md "Gestures" + "Edge zones") */
@@ -90,7 +90,7 @@ export interface AbDrawerProps {
90
90
  closeLabel?: string; // ๐ŸŒ default "Close"
91
91
  noJsFallback?: boolean; // ๐Ÿงฉ D41: without JS, render the content in flow (default `true`)
92
92
  initialFocus?: 'first' | 'panel' | (string & {}); // ๐ŸŽฏ on open: the first control (default), the panel itself, or (0.2.0) a CSS selector inside the panel, e.g. `[role=radio][aria-checked=true]`
93
- // ๐Ÿ†• 0.2.0 drawers v2 (John, God 01:22): all opt-in, the defaults keep the old drawer
93
+ // ๐Ÿ†• 0.2.0 drawers v2 (01:22): all opt-in, the defaults keep the old drawer
94
94
  tier?: AbDrawerTier; // ๐Ÿฅž stacking tier: 'aside' (z 60) < 'nav' (61) < 'sheet' (62)
95
95
  swipe?: boolean; // ๐Ÿค side drawers: swipe the sheet back toward its edge to close (30% of the width or โ‰ฅ 0.5px/ms)
96
96
  snapPoints?: boolean; // ๐Ÿงฒ bottom only, below 768px: snaps at 70% (S1) and full height (S2) with a handle; gestures per the spec
@@ -122,9 +122,17 @@ const SCOPE_SELECTOR: Record<AbDrawerScope, string> = {
122
122
  */
123
123
  export function getAbDrawerHost(scope: AbDrawerScope, from?: Element | null): HTMLElement {
124
124
  const sel = SCOPE_SELECTOR[scope]; // ๐Ÿ”Ž
125
- return from?.closest<HTMLElement>(sel) ?? document.querySelector<HTMLElement>(sel) ?? document.body; // ๐ŸŽฏ
125
+ const own = from?.closest<HTMLElement>(sel) ?? null; // ๐ŸŽฏ the nearest scope box around the drawer
126
+ // ๐Ÿงช 0.6.0 (G16): inside a docs preview (AbDemoBox / AbPreviewCode) the preview box is the app: a drawer never
127
+ // escapes to the real page layout. A scope box that is itself INSIDE the preview (a layout demo) still wins.
128
+ const preview = from?.closest<HTMLElement>(AB_PREVIEW_SCOPE_SELECTOR) ?? null;
129
+ if (preview && (!own || !preview.contains(own))) return preview; // ๐Ÿ“ฆ clipped by the preview
130
+ return own ?? document.querySelector<HTMLElement>(sel) ?? document.body; // ๐ŸŽฏ
126
131
  }
127
132
 
133
+ /** ๐Ÿงช 0.6.0 (G16): the attribute that marks a preview scope (AbDemoBox sets it); drawers inside stay inside */
134
+ export const AB_PREVIEW_SCOPE_SELECTOR = '[data-ab-preview-scope]';
135
+
128
136
  // โ™ฟ everything that can take focus inside the panel
129
137
  const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
130
138
 
@@ -146,7 +154,7 @@ const isTopDrawer = (token: symbol): boolean => openStack[openStack.length - 1]
146
154
 
147
155
  // โ™ฟ reduced-motion check, read once per open / close on purpose: it only picks the unmount delay for THAT
148
156
  // toggle (the slide itself is CSS, which follows the media query live), so a listener would buy nothing
149
- /** โ†ฉ๏ธ 0.2.1 (Joseph): where focus goes after a drawer that had no focusable opener closes (an edge swipe): the
157
+ /** โ†ฉ๏ธ 0.2.1: where focus goes after a drawer that had no focusable opener closes (an edge swipe): the
150
158
  * mobile header's logo link, else AbAppBar's brand link, else AbSidebar's logo row link. `returnFocus` overrides it. */
151
159
  export const AB_DRAWER_RETURN_FOCUS = '[data-ab-part="mobile-header"] a[href], [data-ab-part="app-bar-brand"] a[href], [data-ab-part="sidebar-logo"] a[href]';
152
160
  const reducedMotion = (): boolean => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
@@ -237,7 +245,7 @@ const AbDrawer = (props: AbDrawerProps): ReactElement => {
237
245
  const had = opener.current as HTMLElement | null; // โ†ฉ๏ธ
238
246
  const usable = had && had !== document.body && had.isConnected ? had : null; // ๐Ÿค a swipe has no opener
239
247
  // โ†ฉ๏ธ 0.2.0 fallback: the first VISIBLE match (an app often renders the logo twice, one hidden per breakpoint)
240
- const pool = Array.from(document.querySelectorAll<HTMLElement>(returnFocus ?? AB_DRAWER_RETURN_FOCUS)).filter((el) => !node.contains(el)); // ๐Ÿท๏ธ 0.2.1 (Joseph): default = the header / brand logo
248
+ const pool = Array.from(document.querySelectorAll<HTMLElement>(returnFocus ?? AB_DRAWER_RETURN_FOCUS)).filter((el) => !node.contains(el)); // ๐Ÿท๏ธ 0.2.1: default = the header / brand logo
241
249
  const back = usable ?? pool.find((el) => el.getClientRects().length > 0) ?? pool[0] ?? null; // ๐Ÿ‘€ the visible one, else the first
242
250
  // โญ๏ธ a microtask later: the inert cleanup below runs after this one, and an inert opener can't take focus
243
251
  queueMicrotask(() => { if (back && back.isConnected && typeof back.focus === 'function') back.focus({ preventScroll: true }); });