/** * Runtime parts for the composition blocks: tab selection and the carousel. * `runtime.ts` emits them in the same position and order as the other core * parts, and only when a page uses the feature. * * Without scripts every panel and slide is readable: the markup ships them all * visible, and the runtime marks a container ready (`data-ak-tabs-ready`, * `data-ak-carousel-ready`) before it hides the inactive ones. Queries only * match a container's own tabs and slides, never those of a nested container. * A tab's `select` event carries the tab id as its `value`. */ export declare const TABS = "\nfunction ownTabs(container, selector) {\n return qa(selector, container).filter(function (el) { return el.closest('[data-ak-tabs]') === container; });\n}\nfunction selectTab(container, action, fireFn) {\n var tabs = ownTabs(container, '[role=\"tab\"]');\n if (!tabs.length) return;\n var index = tabs.length - 1;\n if (typeof action.index === 'number') index = Math.min(Math.max(action.index, 0), tabs.length - 1);\n else if (action.tabId) {\n for (var i = 0; i < tabs.length; i += 1) if (tabs[i].getAttribute('data-ak-tab-id') === action.tabId) index = i;\n } else {\n var active = tabs.findIndex(function (tab) { return tab.getAttribute('aria-selected') === 'true'; });\n if (active >= 0 && typeof action.index !== 'number' && !action.tabId) index = active;\n }\n activateTab(container, index, true, fireFn, true);\n}\nfunction activateTab(container, index, moveFocus, fireFn, announceChange) {\n var tabs = ownTabs(container, '[role=\"tab\"]');\n ownTabs(container, '[role=\"tabpanel\"]').forEach(function (panel, panelIndex) {\n var selected = panelIndex === index;\n panel.hidden = !selected;\n panel.setAttribute('tabindex', selected ? '0' : '-1');\n });\n tabs.forEach(function (tab, tabIndex) {\n var selected = tabIndex === index;\n tab.setAttribute('aria-selected', String(selected));\n tab.tabIndex = selected ? 0 : -1;\n });\n if (moveFocus && tabs[index]) tabs[index].focus();\n // Only a user-driven change is worth announcing. Announcing the initial\n // selection would make every page with tabs talk on load.\n if (announceChange) announce('Tab ' + (index + 1) + ' of ' + tabs.length);\n // The tab id is the event value, so a set-value binding without its own\n // value stores which tab is selected.\n if (fireFn && tabs[index]) fireFn(container, 'select', { index: index, value: tabs[index].getAttribute('data-ak-tab-id') });\n}\nfunction wireTabs() {\n qa('[data-ak-tabs]').forEach(function (container) {\n container.setAttribute('data-ak-tabs-ready', '');\n // The initial selection is the authored view, not a user choice: it fires\n // nothing, so page state keeps its declared initial values.\n activateTab(container, 0, false, null, false);\n ownTabs(container, '[role=\"tab\"]').forEach(function (tab, index) {\n tab.addEventListener('click', function () { selectTab(container, { index: index }, fire); }, false);\n tab.addEventListener('keydown', function (event) {\n var keys = ['ArrowRight', 'ArrowLeft', 'Home', 'End'];\n if (keys.indexOf(event.key) === -1) return;\n event.preventDefault();\n var total = ownTabs(container, '[role=\"tab\"]').length;\n var current = index;\n if (event.key === 'ArrowRight') current = (index + 1) % total;\n else if (event.key === 'ArrowLeft') current = (index - 1 + total) % total;\n else if (event.key === 'Home') current = 0;\n else current = total - 1;\n activateTab(container, current, true, fire, true);\n }, false);\n });\n });\n}"; export declare const CAROUSEL = "\nfunction ownSlides(carousel, selector) {\n return qa(selector, carousel).filter(function (el) { return el.closest('[data-ak-carousel-root]') === carousel; });\n}\nfunction shiftSlide(carousel, delta, fireFn) {\n var slides = ownSlides(carousel, '[data-ak-slide]');\n if (!slides.length) return;\n var current = slides.findIndex(function (slide) { return !slide.hidden; });\n if (current < 0) current = 0;\n var next = (current + delta + slides.length) % slides.length;\n showSlide(carousel, next, fireFn, false);\n}\nfunction showSlide(carousel, index, fireFn, focus) {\n var slides = ownSlides(carousel, '[data-ak-slide]');\n if (!slides.length) return;\n var bounded = Math.min(Math.max(index, 0), slides.length - 1);\n slides.forEach(function (slide, slideIndex) {\n var active = slideIndex === bounded;\n slide.hidden = !active;\n slide.setAttribute('aria-hidden', String(!active));\n });\n var buttons = ownSlides(carousel, '[data-ak-carousel]');\n buttons.forEach(function (button) {\n var isPrev = button.getAttribute('data-ak-carousel') === 'prev';\n button.disabled = !carousel.hasAttribute('data-ak-loop') && ((isPrev && bounded === 0) || (!isPrev && bounded === slides.length - 1));\n });\n var status = ownSlides(carousel, '[data-ak-carousel-status]')[0];\n if (status) status.textContent = (bounded + 1) + ' / ' + slides.length;\n if (focus && slides[bounded]) slides[bounded].focus();\n if (fireFn) fireFn(carousel, 'change', { index: bounded });\n}\nfunction wireCarousels() {\n qa('[data-ak-carousel-root]').forEach(function (carousel) {\n carousel.setAttribute('data-ak-carousel-ready', '');\n showSlide(carousel, 0, fire, false);\n ownSlides(carousel, '[data-ak-carousel]').forEach(function (button) {\n button.addEventListener('click', function () {\n shiftSlide(carousel, button.getAttribute('data-ak-carousel') === 'next' ? 1 : -1, fire);\n }, false);\n });\n carousel.addEventListener('keydown', function (event) {\n if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;\n if (event.target.closest('[data-ak-carousel-root]') !== carousel) return;\n event.preventDefault();\n var delta = event.key === 'ArrowRight' ? 1 : -1;\n var slides = ownSlides(carousel, '[data-ak-slide]');\n var current = slides.findIndex(function (slide) { return !slide.hidden; });\n showSlide(carousel, current + delta, fire, true);\n }, false);\n var startX = null;\n carousel.addEventListener('touchstart', function (event) {\n if (event.target.closest('[data-ak-carousel-root]') !== carousel) return;\n if (event.touches.length === 1) startX = event.touches[0].clientX;\n }, { passive: true });\n carousel.addEventListener('touchend', function (event) {\n if (startX === null) return;\n var endX = event.changedTouches.length ? event.changedTouches[0].clientX : startX;\n var delta = endX - startX;\n startX = null;\n if (Math.abs(delta) < 40) return;\n shiftSlide(carousel, delta < 0 ? 1 : -1, fire);\n }, false);\n });\n}"; //# sourceMappingURL=composition-runtime.d.ts.map