Accessible Components
bonsai 27b · typescript

Reviews & generation details
Reviews
No human review yet. Unreviewed does not mean unsuccessful.
Generation context
Imported historical artifact. Its exact original instructions and lineage are not known.
Generation prompt · exact text unavailable
See the current prompt for reference. It may differ from the instructions used to generate this artifact.
Inspect original source 25,779 bytes · SHA-256 d55054694dfd
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Accessible Component Showcase</parameter>
</function>
</tool_call>
<tool_call>
<function=ts_dom_edit>
<parameter=op>
replace</title>
<style>
/* ── css: layout ── */
:root {
--color-bg: #f8f9fa;
--color-surface: #ffffff;
--color-text: #1a1a2e;
--color-text-muted: #6b7280;
--color-border: #e5e7eb;
--color-accent: #4f46e5;
--color-accent-hover: #4338ca;
--color-focus-ring: #4f46e5;
--radius: 8px;
--spacing-xs: 0.25rem;
--spacing-sm: 0.5rem;
--spacing-md: 1rem;
--spacing-lg: 1.5rem;
--spacing-xl: 2rem;
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: var(--font-sans);
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
min-height: 100vh;
}
.skip-link {
position: absolute;
top: -40px;
left: var(--spacing-md);
background: var(--color-accent);
color: white;
padding: var(--spacing-sm) var(--spacing-md);
border-radius: 0 0 var(--radius) var(--radius);
z-index: 10000;
text-decoration: none;
font-weight: 600;
}
.skip-link:focus {
top: 0;
outline: 3px solid var(--color-focus-ring);
outline-offset: 2px;
}
.sidebar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
width: 240px;
background: var(--color-surface);
border-right: 1px solid var(--color-border);
padding: var(--spacing-lg) var(--spacing-md);
z-index: 100;
}
.sidebar ul { list-style: none; }
.nav-link {
display: block;
padding: var(--spacing-sm) var(--spacing-md);
margin-bottom: var(--spacing-xs);
color: var(--color-text-muted);
text-decoration: none;
border-radius: var(--radius);
font-weight: 500;
transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
background: #f3f4f6;
color: var(--color-text);
}
.nav-link:focus-visible {
outline: 3px solid var(--color-focus-ring);
outline-offset: -2px;
}
.nav-link.active {
background: var(--color-accent);
color: white;
}
.main-content {
max-width: 800px;
margin: 0 auto;
padding: var(--spacing-xl) var(--spacing-lg);
min-height: calc(100vh - 240px);
}
.component-section {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
padding: var(--spacing-lg) var(--spacing-xl);
margin-bottom: var(--spacing-lg);
}
.component-section h2 {
font-size: 1.375rem;
margin-bottom: var(--spacing-sm);
color: var(--color-text);
}
.caption {
color: var(--color-text-muted);
font-size: 0.875rem;
margin-bottom: var(--spacing-lg);
font-style: italic;
}
.widget-container {
min-height: 120px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--radius);
background: #fafbfc;
border: 1px dashed var(--color-border);
}
/* Focus styles - always visible */
button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
outline: 3px solid var(--color-focus-ring);
outline-offset: 2px;
}
/* Modal styles */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
}
.modal-dialog {
position: relative;
width: 90%;
max-width: 480px;
background: var(--color-surface);
border-radius: var(--radius);
padding: var(--spacing-lg);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-dialog h3 { margin-bottom: var(--spacing-md); }
.modal-actions { display: flex; gap: var(--spacing-sm); justify-content: flex-end; margin-top: var(--spacing-lg); }
/* Dropdown styles */
.dropdown-trigger {
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--color-border);
border-radius: var(--radius);
background: var(--color-surface);
cursor: pointer;
font-weight: 500;
}
.dropdown-menu {
position: absolute;
top: calc(100% + var(--spacing-sm));
left: 0;
min-width: 240px;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
z-index: 999;
}
.dropdown-menu li { list-style: none; }
.dropdown-menu li a,
.dropdown-menu li button {
display: block;
padding: var(--spacing-sm) var(--spacing-md);
color: var(--color-text);
text-decoration: none;
border-bottom: 1px solid var(--color-border);
}
.dropdown-menu li:last-child { border-bottom: none; }
.dropdown-menu li:hover,
.dropdown-menu li:focus-visible {
background: #f3f4f6;
}
/* Tabs styles */
.tablist { display: flex; gap: 0; border-bottom: 1px solid var(--color-border); margin-bottom: var(--spacing-lg); }
.tab {
padding: var(--spacing-sm) var(--spacing-md);
background: none;
border: none;
cursor: pointer;
font-weight: 500;
color: var(--color-text-muted);
position: relative;
}
.tab[aria-selected="true"] {
color: var(--color-accent);
}
.tab[aria-selected="true"]:after {
content: "";
position: absolute;
bottom: -1px;
left: 0;
right: 0;
height: 2px;
background: var(--color-accent);
}
.tab:focus-visible { outline: none; }
.tab[aria-selected="true"]:focus-visible {
outline: 3px solid var(--color-focus-ring);
outline-offset: -2px;
}
.tabpanel { display: block; padding: var(--spacing-md); }
.tabpanel[hidden] { display: none !important; }
/* Combobox styles */
.combobox-input {
width: 100%;
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--color-border);
border-radius: var(--radius);
font-size: 1rem;
}
.combobox-listbox {
position: absolute;
top: calc(100% + var(--spacing-sm));
left: 0;
right: 0;
max-height: 240px;
overflow-y: auto;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
z-index: 999;
}
.combobox-listbox li {
padding: var(--spacing-sm) var(--spacing-md);
cursor: pointer;
border-bottom: 1px solid var(--color-border);
}
.combobox-listbox li:last-child { border-bottom: none; }
.combobox-listbox li:hover,
.combobox-listbox li[aria-selected="true"] {
background: #f3f4f6;
}
/* Accordion styles */
.accordion-trigger {
width: 100%;
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--color-border);
border-radius: var(--radius);
background: var(--color-surface);
cursor: pointer;
font-weight: 500;
display: flex;
justify-content: space-between;
align-items: center;
}
.accordion-trigger[aria-expanded="true"] {
border-color: var(--color-accent);
}
.accordion-panel-inner {
padding: var(--spacing-md);
margin-top: -1px;
border-top: 1px solid var(--color-border);
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div id="app"></div>
:root {
--color-bg: #f8f9fa;
--color-surface: #ffffff;
--color-text: #1a1a2e;
--color-text-muted: #6b7280;
--color-border: #e5e7eb;
--color-accent: #4f46e5;
--color-accent-hover: #4338ca;
--color-focus-ring: #4f46e5;
--radius: 8px;
--spacing-xs: 0.25rem;
--spacing-sm: 0.5rem;
--spacing-md: 1rem;
--spacing-lg: 1.5rem;
--spacing-xl: 2rem;
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: var(--font-sans);
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
min-height: 100vh;
}
.skip-link {
position: absolute;
top: -40px;
left: var(--spacing-md);
background: var(--color-accent);
color: white;
padding: var(--spacing-sm) var(--spacing-md);
border-radius: 0 0 var(--radius) var(--radius);
z-index: 10000;
text-decoration: none;
font-weight: 600;
}
.skip-link:focus {
top: 0;
outline: 3px solid var(--color-focus-ring);
outline-offset: 2px;
}
.sidebar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
width: 240px;
background: var(--color-surface);
border-right: 1px solid var(--color-border);
padding: var(--spacing-lg) var(--spacing-md);
z-index: 100;
}
.sidebar ul { list-style: none; }
.nav-link {
display: block;
padding: var(--spacing-sm) var(--spacing-md);
margin-bottom: var(--spacing-xs);
color: var(--color-text-muted);
text-decoration: none;
border-radius: var(--radius);
font-weight: 500;
transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
background: #f3f4f6;
color: var(--color-text);
}
.nav-link:focus-visible {
outline: 3px solid var(--color-focus-ring);
outline-offset: -2px;
}
.nav-link.active {
background: var(--color-accent);
color: white;
}
.main-content {
max-width: 800px;
margin: 0 auto;
padding: var(--spacing-xl) var(--spacing-lg);
min-height: calc(100vh - 240px);
}
.component-section {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
padding: var(--spacing-lg) var(--spacing-xl);
margin-bottom: var(--spacing-lg);
}
.component-section h2 {
font-size: 1.375rem;
margin-bottom: var(--spacing-sm);
color: var(--color-text);
}
.caption {
color: var(--color-text-muted);
font-size: 0.875rem;
margin-bottom: var(--spacing-lg);
font-style: italic;
}
.widget-container {
min-height: 120px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--radius);
background: #fafbfc;
border: 1px dashed var(--color-border);
}
/* Focus styles - always visible */
button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
outline: 3px solid var(--color-focus-ring);
outline-offset: 2px;
}
/* Modal styles */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
display: flex;
align-items: center;
justify-content: center;
}
.modal-dialog {
position: relative;
width: 90%;
max-width: 480px;
background: var(--color-surface);
border-radius: var(--radius);
padding: var(--spacing-lg);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-dialog h3 { margin-bottom: var(--spacing-md); }
.modal-actions { display: flex; gap: var(--spacing-sm); justify-content: flex-end; margin-top: var(--spacing-lg); }
/* Dropdown styles */
.dropdown-trigger {
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--color-border);
border-radius: var(--radius);
background: var(--color-surface);
cursor: pointer;
font-weight: 500;
}
.dropdown-menu {
position: absolute;
top: calc(100% + var(--spacing-sm));
left: 0;
min-width: 240px;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
z-index: 999;
}
.dropdown-menu li { list-style: none; }
.dropdown-menu li a,
.dropdown-menu li button {
display: block;
padding: var(--spacing-sm) var(--spacing-md);
color: var(--color-text);
text-decoration: none;
border-bottom: 1px solid var(--color-border);
}
.dropdown-menu li:last-child { border-bottom: none; }
.dropdown-menu li:hover,
.dropdown-menu li:focus-visible {
background: #f3f4f6;
}
/* Tabs styles */
.tablist { display: flex; gap: 0; border-bottom: 1px solid var(--color-border); margin-bottom: var(--spacing-lg); }
.tab {
padding: var(--spacing-sm) var(--spacing-md);
background: none;
border: none;
cursor: pointer;
font-weight: 500;
color: var(--color-text-muted);
position: relative;
}
.tab[aria-selected="true"] {
color: var(--color-accent);
}
.tab[aria-selected="true"]:after {
content: "";
position: absolute;
bottom: -1px;
left: 0;
right: 0;
height: 2px;
background: var(--color-accent);
}
.tab:focus-visible { outline: none; }
.tab[aria-selected="true"]:focus-visible {
outline: 3px solid var(--color-focus-ring);
outline-offset: -2px;
}
.tabpanel { display: block; padding: var(--spacing-md); }
.tabpanel[hidden] { display: none !important; }
/* Combobox styles */
.combobox-input {
width: 100%;
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--color-border);
border-radius: var(--radius);
font-size: 1rem;
}
.combobox-listbox {
position: absolute;
top: calc(100% + var(--spacing-sm));
left: 0;
right: 0;
max-height: 240px;
overflow-y: auto;
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
z-index: 999;
}
.combobox-listbox li {
padding: var(--spacing-sm) var(--spacing-md);
cursor: pointer;
border-bottom: 1px solid var(--color-border);
}
.combobox-listbox li:last-child { border-bottom: none; }
.combobox-listbox li:hover,
.combobox-listbox li[aria-selected="true"] {
background: #f3f4f6;
}
/* Accordion styles */
.accordion-trigger {
width: 100%;
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--color-border);
border-radius: var(--radius);
background: var(--color-surface);
cursor: pointer;
font-weight: 500;
display: flex;
justify-content: space-between;
align-items: center;
}
.accordion-trigger[aria-expanded="true"] {
border-color: var(--color-accent);
}
.accordion-panel-inner {
padding: var(--spacing-md);
margin-top: -1px;
border-top: 1px solid var(--color-border);
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
<div id="app">
<a href="#main" class="skip-link">Skip to main content</a>
<aside id="sidebar" class="sidebar" aria-label="Navigation">
<nav>
<ul>
<li><a href="#modal-section" class="nav-link active" data-section="modal">Modal Dialog</a></li>
<li><a href="#dropdown-section" class="nav-link" data-section="dropdown">Dropdown Menu</a></li>
<li><a href="#tabs-section" class="nav-link" data-section="tabs">Tabs</a></li>
<li><a href="#combobox-section" class="nav-link" data-section="combobox">Combobox</a></li>
<li><a href="#accordion-section" class="nav-link" data-section="accordion">Accordion</a></li>
</ul>
</nav>
</aside>
<main id="main" class="main-content">
<!-- Modal Dialog Section -->
<section id="modal-section" class="component-section">
<h2>Modal Dialog</h2>
<p class="caption">↑↓ navigate · Enter/Space select · Esc close · Click backdrop to dismiss</p>
<div class="widget-container">
<button id="modal-trigger" aria-haspopup="dialog" aria-label="Open modal dialog">Open Modal</button>
</div>
</section>
<!-- Dropdown Menu Section -->
<section id="dropdown-section" class="component-section">
<h2>Dropdown Menu</h2>
<p class="caption">Click/Enter/Space open · ↑↓ navigate · Home/End jump · Tab close · Esc close</p>
<div class="widget-container">
<button id="dropdown-trigger" aria-haspopup="menu" aria-expanded="false" aria-label="Open dropdown menu">Select an option...</button>
<ul id="dropdown-menu" role="menu" aria-labelledby="dropdown-trigger"></ul>
</div>
</section>
<!-- Tabs Section -->
<section id="tabs-section" class="component-section">
<h2>Tabs</h2>
<p class="caption">←→ switch tabs · Enter/Space activate panel · Tab within panels</p>
<div class="widget-container">
<div role="tablist" aria-label="Content tabs" id="tabs-tablist">
<button role="tab" tabindex="0" aria-selected="true" aria-controls="panel-1" id="tab-1">Overview</button>
<button role="tab" tabindex="-1" aria-selected="false" aria-controls="panel-2" id="tab-2">Details</button>
<button role="tab" tabindex="-1" aria-selected="false" aria-controls="panel-3" id="tab-3">Settings</button>
</div>
<div role="tabpanel" id="panel-1" aria-labelledby="tab-1" tabindex="0">
<p>This is the overview panel content. It contains descriptive information about the product.</p>
</div>
<div role="tabpanel" id="panel-2" aria-labelledby="tab-2" tabindex="-1" hidden="">
<p>This is the details panel content. It provides in-depth specifications and technical data.</p>
</div>
<div role="tabpanel" id="panel-3" aria-labelledby="tab-3" tabindex="-1" hidden="">
<p>This is the settings panel content. Configure your preferences here to customize your experience.</p>
</div>
</div>
</section>
<!-- Combobox Section -->
<section id="combobox-section" class="component-section">
<h2>Combobox (Autocomplete)</h2>
<p class="caption">Type to filter · ↑↓ navigate options · Enter/Space select · Esc close · Tab close</p>
<div class="widget-container">
<input id="combobox-input" type="text" role="combobox" aria-expanded="false" aria-controls="combobox-listbox" aria-activedescendant="" placeholder="Search options..." autocomplete="off">
<ul id="combobox-listbox" role="listbox" aria-labelledby="combobox-input" hidden=""></ul>
</div>
</section>
<!-- Accordion Section -->
<section id="accordion-section" class="component-section">
<h2>Accordion (Disclosure)</h2>
<p class="caption">Click/Enter/Space toggle · Multiple open simultaneously</p>
<div class="widget-container">
<button id="acc-trigger-1" aria-expanded="false" aria-controls="acc-panel-1">What is this component?</button>
<div id="acc-panel-1" role="region" aria-labelledby="acc-trigger-1" hidden="">
<p>This is an accordion component that allows multiple sections to be open simultaneously. Each section can be toggled independently using keyboard navigation.</p>
</div>
<button id="acc-trigger-2" aria-expanded="false" aria-controls="acc-panel-2">How do I use it?</button>
<div id="acc-panel-2" role="region" aria-labelledby="acc-trigger-2" hidden="">
<p>Use keyboard navigation: Tab to focus a trigger, Enter or Space to toggle. Arrow keys move between triggers. All open panels remain visible and accessible.</p>
</div>
<button id="acc-trigger-3" aria-expanded="false" aria-controls="acc-panel-3">What's the accessibility model?</button>
<div id="acc-panel-3" role="region" aria-labelledby="acc-trigger-3" hidden="">
<p>This component follows WAI-ARIA Authoring Practices for Disclosure Groups. It uses aria-expanded, aria-controls, and proper heading structure to ensure screen reader compatibility.</p>
</div>
</div>
</section>
</main>
</div>
<script>
(function () {
'use strict';
var __mods = {};
var __cache = {};
var __map = {};
function __require(id) {
if (__cache[id]) return __cache[id].exports;
var module = __cache[id] = { exports: {} };
var factory = __mods[id];
if (!factory) throw new Error("Module not found: " + id);
factory(module.exports, function (spec) {
var target = (__map[id] && __map[id][spec]) || spec;
return __require(target);
}, module);
return module.exports;
}
// ── module: src/main.ts ──
__mods["src/main.ts"] = function (exports, require, module) {
"use strict";
// Entry point. Runs after the DOM is parsed and after any classic
// <script> imports, so document queries and CDN globals are available.
// Import your other modules from here.
Object.defineProperty(exports, "__esModule", { value: true });
exports.start = start;
function start() {
// Replace this with the real startup sequence.
}
start();
};
// ── module: src/utils.ts ──
__mods["src/utils.ts"] = function (exports, require, module) {
"use strict";
// ============================================================
// Shared utilities for accessibility components
// ============================================================
Object.defineProperty(exports, "__esModule", { value: true });
exports.RovingTabindexManager = void 0;
exports.getFocusableElements = getFocusableElements;
exports.trapFocus = trapFocus;
exports.animatePanel = animatePanel;
exports.findNearestAncestor = findNearestAncestor;
exports.isVisible = isVisible;
exports.debounce = debounce;
exports.getNextFocusable = getNextFocusable;
exports.getPrevFocusable = getPrevFocusable;
function getFocusableElements(container) {
return Array.from(container.querySelectorAll('button, [href], input:not([disabled]):not([type="submit"]), select, textarea, [tabindex]:not([tabindex="-1"])'));
}
/**
* Trap focus within a container. Returns true if focus is trapped (i.e., the element
* that receives focus is inside the container).
*/
function trapFocus(container) {
const focusable = getFocusableElements(container);
if (focusable.length === 0)
return false;
const first = focusable[0];
const last = focusable[focusable.length - 1];
// Check if current focus is inside container
const activeEl = document.activeElement;
if (!container.contains(activeEl)) {
activeEl?.focus();
return false;
}
// If we're on the last element and Tab is pressed, wrap to first
if (activeEl === last && document.event?.key === 'Tab') {
first.focus();
return true;
}
// If we're on the first element and Shift+Tab is pressed, wrap to last
if (activeEl === first && document.event?.key === 'Tab' && !document.event?.shiftKey) {
last.focus();
return true;
}
return false;
}
/**
* Roving tabindex manager for combobox-style lists.
* Manages aria-activedescendant and tabindex on list items.
*/
class RovingTabindexManager {
constructor(listbox) {
this.activeIndex = -1;
this.listbox = listbox;
}
setItems(items) {
this.activeIndex = -1;
items.forEach((item, i) => {
item.setAttribute('tabindex', '-1');
item.removeAttribute('aria-selected');
});
this.update();
}
setActive(index) {
const items = Array.from(this.listbox.querySelectorAll('li'));
if (index < 0 || index >= items.length)
return;
items.forEach((item, i) => {
item.setAttribute('tabindex', i === index ? '0' : '-1');
item.setAttribute('aria-selected', i === index ? 'true' : 'false');
});
this.activeIndex = index;
this.update();
}
setActiveByText(text) {
const items = Array.from(this.listbox.querySelectorAll('li'));
for (let i = 0; i < items.length; i++) {
if (items[i].textContent.toLowerCase().includes(text.toLowerCase())) {
this.setActive(i);
break;
}
}
}
update() {
const listboxId = this.listbox.id;
const activeItem = Array.from(this.listbox.querySelectorAll('li'))[this.activeIndex];
if (activeItem) {
document.getElementById(listboxId)?.setAttribute('aria-activedescendant', activeItem.id || '');
}
else {
document.getElementById(listboxId)?.setAttribute('aria-activedescendant', '');
}
}
getActiveIndex() {
return this.activeIndex;
}
}
exports.RovingTabindexManager = RovingTabindexManager;
/**
* Utility to animate a panel open/closed with smooth height transition.
* Uses requestAnimationFrame for performance and respects prefers-reduced-motion.
*/
function animatePanel(panel, isOpen) {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (isOpen) {
panel.classList.add('open');
// Ensure the element is visible after animation
requestAnimationFrame(() => {
panel.removeAttribute('hidden');
});
}
else {
panel.classList.remove('open');
panel.setAttribute('hidden', '');
}
}
/**
* Utility to get the nearest ancestor with a specific class.
*/
function findNearestAncestor(element, className) {
let current = element;
while (current !== document.body) {
if (current.classList.contains(className))
return current;
current = current.parentElement;
}
return null;
}
/**
* Utility to check if an element is visible on screen.
*/
function isVisible(element) {
const rect = element.getBoundingClientRect();
return (rect.width > 0 &&
rect.height > 0 &&
rect.left >= -10 &&
rect.right <= window.innerWidth + 10 &&
rect.top >= -10 &&
rect.bottom <= window.innerHeight + 10);
}
/**
* Utility to debounce a function.
*/
function debounce(fn, delay) {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), delay);
};
}
/**
* Utility to get the next/previous focusable element in a container.
*/
function getNextFocusable(container, current) {
const focusable = getFocusableElements(container);
const currentIndex = focusable.indexOf(current);
if (currentIndex === -1)
return null;
const nextIndex = (currentIndex + 1) % focusable.length;
return focusable[nextIndex];
}
function getPrevFocusable(container, current) {
const focusable = getFocusableElements(container);
const currentIndex = focusable.indexOf(current);
if (currentIndex === -1)
return null;
const prevIndex = (currentIndex - 1 + focusable.length) % focusable.length;
return focusable[prevIndex];
}
};
// ── entry ──
__require("src/main.ts");
})();
</script>
</body>
</html>