Constant INDEX_SCRIPT
Source const INDEX_SCRIPT: &str = "// Storybook index cockpit (DEV-03 / DEV-08).\n// Vanilla JS, no framework. Loaded inline from export_stories.rs.\n\n(function () {\n var frame = document.getElementById(\'storybook-index-frame\');\n var current = document.getElementById(\'storybook-index-current\');\n var openLink = document.getElementById(\'storybook-index-open\');\n var filter = document.getElementById(\'storybook-index-filter\');\n var list = document.querySelector(\'.storybook-index-list\');\n var FILTER_KEY = \'storybook-index-filter\';\n\n function pick(id) {\n if (!id) {\n id = (document.body.getAttribute(\'data-first-story\') || \'\').trim();\n }\n if (!id) return;\n var safeId = id.replace(/[^a-zA-Z0-9_-]/g, \'\');\n if (safeId !== id) return;\n var href = \'./\' + safeId + \'.html\';\n if (frame.getAttribute(\'src\') !== href) {\n frame.setAttribute(\'src\', href);\n }\n if (current) current.textContent = safeId;\n if (openLink) openLink.setAttribute(\'href\', href);\n document.querySelectorAll(\'.storybook-index-row\').forEach(function (row) {\n if (row.getAttribute(\'data-id\') === safeId) {\n row.classList.add(\'is-active\');\n } else {\n row.classList.remove(\'is-active\');\n }\n });\n }\n\n function readHash() {\n return decodeURIComponent((location.hash || \'\').replace(/^#/, \'\'));\n }\n\n window.addEventListener(\'hashchange\', function () {\n pick(readHash());\n });\n\n pick(readHash());\n\n if (list) {\n list.addEventListener(\'click\', function (e) {\n var target = e.target;\n while (target && target !== list && target.tagName !== \'A\') {\n target = target.parentNode;\n }\n if (!target || target === list) return;\n var id = target.getAttribute(\'data-id\');\n if (!id) return;\n // Allow native anchor to update the hash; pick() runs from hashchange.\n });\n }\n\n function applyFilter(query) {\n var q = (query || \'\').trim().toLowerCase();\n var anyVisible = false;\n document.querySelectorAll(\'.storybook-index-row\').forEach(function (row) {\n var match =\n !q ||\n (row.getAttribute(\'data-id\') || \'\').indexOf(q) !== -1 ||\n (row.getAttribute(\'data-title\') || \'\').indexOf(q) !== -1 ||\n (row.getAttribute(\'data-category\') || \'\').indexOf(q) !== -1;\n if (match) {\n row.classList.remove(\'is-hidden\');\n anyVisible = true;\n } else {\n row.classList.add(\'is-hidden\');\n }\n });\n document.querySelectorAll(\'.storybook-index-category\').forEach(function (cat) {\n var rows = cat.querySelectorAll(\'.storybook-index-row\');\n var visible = 0;\n rows.forEach(function (r) {\n if (!r.classList.contains(\'is-hidden\')) visible += 1;\n });\n if (visible === 0) {\n cat.classList.add(\'is-hidden\');\n } else {\n cat.classList.remove(\'is-hidden\');\n }\n });\n try {\n window.sessionStorage.setItem(FILTER_KEY, q);\n } catch (_e) {\n /* sessionStorage may be unavailable (private mode) */\n }\n return anyVisible;\n }\n\n if (filter) {\n try {\n var stored = window.sessionStorage.getItem(FILTER_KEY) || \'\';\n if (stored) {\n filter.value = stored;\n applyFilter(stored);\n }\n } catch (_e) {\n /* ignore */\n }\n filter.addEventListener(\'input\', function () {\n applyFilter(filter.value);\n });\n document.addEventListener(\'keydown\', function (e) {\n var inField =\n e.target &&\n (e.target.tagName === \'INPUT\' ||\n e.target.tagName === \'TEXTAREA\' ||\n e.target.isContentEditable);\n if (e.key === \'/\' && !inField) {\n e.preventDefault();\n filter.focus();\n filter.select();\n } else if (e.key === \'Escape\' && document.activeElement === filter) {\n filter.value = \'\';\n applyFilter(\'\');\n filter.blur();\n }\n });\n }\n})();\n";