@sdxc/kit 2026.11.26 → 2026.11.29

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 (39) hide show
  1. package/changelog.jsonl +193 -0
  2. package/dist/pkg/catalog.js +1 -0
  3. package/dist/scaffold/render.js +2 -2
  4. package/package.json +2 -2
  5. package/registry/ui/anchor-heading.json +19 -0
  6. package/registry/ui/autocomplete.json +3 -3
  7. package/registry/ui/banner.json +3 -3
  8. package/registry/ui/button.json +3 -3
  9. package/registry/ui/callout.json +16 -0
  10. package/registry/ui/checkbox.json +2 -2
  11. package/registry/ui/code-block.json +18 -0
  12. package/registry/ui/confirm.json +3 -3
  13. package/registry/ui/copy-button.json +14 -0
  14. package/registry/ui/date-field.json +4 -7
  15. package/registry/ui/date-picker.json +3 -5
  16. package/registry/ui/date-range-picker.json +2 -3
  17. package/registry/ui/dialog-dismiss.json +2 -2
  18. package/registry/ui/field-parts.json +30 -0
  19. package/registry/ui/filter-links.json +16 -0
  20. package/registry/ui/form.json +3 -3
  21. package/registry/ui/lightbox.json +3 -3
  22. package/registry/ui/listbox.json +2 -2
  23. package/registry/ui/media-grid.json +3 -3
  24. package/registry/ui/pager.json +16 -0
  25. package/registry/ui/property-list.json +3 -3
  26. package/registry/ui/radio-group.json +2 -2
  27. package/registry/ui/range-calendar.json +2 -2
  28. package/registry/ui/range-months.json +3 -3
  29. package/registry/ui/rating-input.json +3 -3
  30. package/registry/ui/rating.json +3 -3
  31. package/registry/ui/review-card.json +3 -3
  32. package/registry/ui/search-field.json +6 -3
  33. package/registry/ui/section-bar.json +3 -3
  34. package/registry/ui/sidebar.json +2 -2
  35. package/registry/ui/table-of-contents.json +17 -0
  36. package/registry/ui/text-field.json +5 -9
  37. package/registry/ui/time-field.json +4 -7
  38. package/registry/ui/timeline.json +3 -3
  39. package/registry/ui/typeset.json +2 -2
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "filter-links",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "FilterLinks"
7
+ ],
8
+ "source": {
9
+ "path": "filter-links.tsx",
10
+ "content": "/**\n * A row of links that narrow one list, such as a feed filtered by post type, each a part with\n * an optional count and the current one marked with `aria-current=\"page\"`. Every filter is a plain\n * address, so a filtered view is shareable and works without script.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { outline } from \"@sdxc/u/color\";\nimport { listStyle, mergeMix, raw } from \"@sdxc/u/general\";\nimport { hstack, shrink } from \"@sdxc/u/layout\";\nimport { noScrollbar } from \"@sdxc/u/overflow\";\nimport { m, p } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { nowrap, tabularNums, textDecoration } from \"@sdxc/u/typography\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** Prop types for {@link FilterLinks} and its parts. */\nexport namespace FilterLinks {\n\t/**\n\t * Every native `<a>` attribute, plus whether this is the filter the page shows; the label\n\t * (which may lead with a mark of its own, such as a coloured dot) and a count go inside.\n\t */\n\texport type LinkProps = TagProps<\"a\"> & {\n\t\thref: string;\n\t\t/** Marks the filter the page is showing, announced as the current page. */\n\t\tcurrent?: boolean;\n\t};\n\n\t/** Every native `<span>` attribute. */\n\texport interface CountProps extends TagProps<\"span\"> {}\n\n\t/**\n\t * The custom properties the row reads, set on the root through `mix` or `style`. Each one\n\t * falls back to the default look, so a caller sets only what it changes.\n\t */\n\texport interface CustomProperties {\n\t\t/** Space between links. */\n\t\t\"--ui-filter-links-gap\"?: string;\n\t\t/**\n\t\t * A margin before every link but the first, 0 by default; with a 0 gap, minus the border\n\t\t * width joins bordered links into one segmented line, the hovered or current one on top.\n\t\t */\n\t\t\"--ui-filter-links-link-overlap\"?: string;\n\t\t/** A link's padding, block then inline. */\n\t\t\"--ui-filter-links-link-padding\"?: string;\n\t\t/** A link's corner radius; a pill by default. */\n\t\t\"--ui-filter-links-link-radius\"?: string;\n\t\t/** A link's border width; 0 by default. */\n\t\t\"--ui-filter-links-link-border-width\"?: string;\n\t\t/** A link's border style, drawn once a width is set. */\n\t\t\"--ui-filter-links-link-border-style\"?: string;\n\t\t/** A link's border colour. */\n\t\t\"--ui-filter-links-link-border-color\"?: string;\n\t\t/** A link's background. */\n\t\t\"--ui-filter-links-link-bg\"?: string;\n\t\t/** A link's text colour. */\n\t\t\"--ui-filter-links-link-fg\"?: string;\n\t\t/** A link's background under the pointer. */\n\t\t\"--ui-filter-links-link-hover-bg\"?: string;\n\t\t/** A link's text colour under the pointer. */\n\t\t\"--ui-filter-links-link-hover-fg\"?: string;\n\t\t/** A link's border colour under the pointer; its resting border colour by default. */\n\t\t\"--ui-filter-links-link-hover-border-color\"?: string;\n\t\t/** A link's typeface; the surrounding text's by default. */\n\t\t\"--ui-filter-links-link-font-family\"?: string;\n\t\t/** A link's font size. */\n\t\t\"--ui-filter-links-link-font-size\"?: string;\n\t\t/** A link's font weight. */\n\t\t\"--ui-filter-links-link-font-weight\"?: string;\n\t\t/** A link's text transform, such as `uppercase` for small-caps labels. */\n\t\t\"--ui-filter-links-link-text-transform\"?: string;\n\t\t/** A link's letter spacing. */\n\t\t\"--ui-filter-links-link-letter-spacing\"?: string;\n\t\t/** The current link's background. */\n\t\t\"--ui-filter-links-current-bg\"?: string;\n\t\t/** The current link's text colour. */\n\t\t\"--ui-filter-links-current-fg\"?: string;\n\t\t/** The current link's border colour; the other links' by default. */\n\t\t\"--ui-filter-links-current-border-color\"?: string;\n\t\t/** How strongly a count shows beside its label. */\n\t\t\"--ui-filter-links-count-opacity\"?: string;\n\t\t/** A count's typeface; the link's by default. */\n\t\t\"--ui-filter-links-count-font-family\"?: string;\n\t\t/** A count's font size, `0.85em` of the link's by default. */\n\t\t\"--ui-filter-links-count-font-size\"?: string;\n\t\t/** A count's text colour; the link's by default. */\n\t\t\"--ui-filter-links-count-fg\"?: string;\n\t}\n\n\t/**\n\t * Every native `<nav>` attribute; name the landmark with `aria-label`, such as \"Filter by\n\t * type\". The {@link FilterLinks.Link}s go inside.\n\t */\n\texport interface Props extends TagProps<\"nav\"> {\n\t\t/** Wraps the links onto more lines on a narrow screen, in place of scrolling sideways. */\n\t\twrap?: boolean;\n\t}\n}\n\n/**\n * Renders a `<nav>` holding one line of filter links. On a screen too narrow for every filter\n * the line scrolls sideways with its scrollbar hidden, or wraps onto more lines with `wrap`.\n * Restyle every link at once by setting {@link FilterLinks.CustomProperties} on the root.\n *\n * @param handle Runtime handle carrying the host `<nav>`'s props.\n * @returns The render function producing the filter row's markup.\n * @example\n * <FilterLinks aria-label=\"Filter by type\">\n * \t<FilterLinks.Link href=\"/\" current>Everything <FilterLinks.Count>42</FilterLinks.Count></FilterLinks.Link>\n * \t<FilterLinks.Link href=\"/?type=notes\">Notes <FilterLinks.Count>17</FilterLinks.Count></FilterLinks.Link>\n * </FilterLinks>\n */\nexport function FilterLinks(handle: Handle<FilterLinks.Props>) {\n\treturn () => {\n\t\tlet { children, wrap = false, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<nav\n\t\t\t\tdata-slot=\"filter-links\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\twrap\n\t\t\t\t\t\t? []\n\t\t\t\t\t\t: [raw({ overflowX: \"auto\", overscrollBehaviorInline: \"contain\" }), noScrollbar()],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<ul\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tm(0),\n\t\t\t\t\t\tp(0),\n\t\t\t\t\t\tlistStyle(\"none\"),\n\t\t\t\t\t\thstack({ align: \"center\" }),\n\t\t\t\t\t\traw({ gap: \"var(--ui-filter-links-gap, calc(var(--ui-spacing, 0.25rem) * 1.5))\" }),\n\t\t\t\t\t\twrap ? raw({ flexWrap: \"wrap\" }) : null,\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</ul>\n\t\t\t</nav>\n\t\t);\n\t};\n}\n\n/**\n * One filter as a list item holding its link; the current one is announced as the current page.\n * Native attributes and `mix` go to the `<a>`, so a caller marks each filter apart.\n *\n * @param handle Runtime handle carrying the link's props.\n * @returns The render function producing the item.\n * @example <FilterLinks.Link href=\"/?type=notes\" data-kind=\"note\">Notes</FilterLinks.Link>\n */\nFilterLinks.Link = function FilterLinksLink(handle: Handle<FilterLinks.LinkProps>) {\n\treturn () => {\n\t\tlet { current, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<li\n\t\t\t\tmix={[\n\t\t\t\t\tshrink(0),\n\t\t\t\t\twhen(\"& + &\", raw({ marginInlineStart: \"var(--ui-filter-links-link-overlap, 0)\" })),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<a\n\t\t\t\t\tdata-slot=\"filter-links-link\"\n\t\t\t\t\taria-current={current ? \"page\" : undefined}\n\t\t\t\t\t{...rest}\n\t\t\t\t\tmix={mergeMix(filterLink(), mix)}\n\t\t\t\t/>\n\t\t\t</li>\n\t\t);\n\t};\n};\n\n/**\n * How many entries the filter keeps, after its label in tabular figures and a little quieter.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the count.\n */\nFilterLinks.Count = function FilterLinksCount(handle: Handle<FilterLinks.CountProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"filter-links-count\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\ttabularNums(),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tfontFamily: \"var(--ui-filter-links-count-font-family, inherit)\",\n\t\t\t\t\t\t\tfontSize: \"var(--ui-filter-links-count-font-size, 0.85em)\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-filter-links-count-fg, inherit)\",\n\t\t\t\t\t\t\topacity: \"var(--ui-filter-links-count-opacity, 0.7)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * One filter link: a pill holding its label and count. Every visible choice reads a\n * `--ui-filter-links-*` property with the default as its fallback, so a caller restyles every\n * link from the root.\n */\nfunction filterLink() {\n\treturn [\n\t\tinteractiveTransition(),\n\t\thstack({ gap: 1.5, align: \"baseline\" }),\n\t\tnowrap(),\n\t\ttextDecoration(\"none\"),\n\t\traw({\n\t\t\tposition: \"relative\",\n\t\t\tpadding: \"var(--ui-filter-links-link-padding, 0.375rem 0.875rem)\",\n\t\t\tborderRadius: \"var(--ui-filter-links-link-radius, var(--ui-radius-full, 9999px))\",\n\t\t\tborderWidth: \"var(--ui-filter-links-link-border-width, 0)\",\n\t\t\tborderStyle: \"var(--ui-filter-links-link-border-style, solid)\",\n\t\t\tborderColor: \"var(--ui-filter-links-link-border-color, transparent)\",\n\t\t\tbackgroundColor: \"var(--ui-filter-links-link-bg, transparent)\",\n\t\t\tcolor: \"var(--ui-filter-links-link-fg, var(--ui-neutral-fg))\",\n\t\t\tfontFamily: \"var(--ui-filter-links-link-font-family, inherit)\",\n\t\t\tfontSize: \"var(--ui-filter-links-link-font-size, var(--ui-text-sm, 0.875rem))\",\n\t\t\tlineHeight: \"var(--ui-leading-sm, calc(1.25 / 0.875))\",\n\t\t\tfontWeight: \"var(--ui-filter-links-link-font-weight, 500)\",\n\t\t\ttextTransform: \"var(--ui-filter-links-link-text-transform, none)\",\n\t\t\tletterSpacing: \"var(--ui-filter-links-link-letter-spacing, normal)\",\n\t\t}),\n\t\thover(\n\t\t\traw({\n\t\t\t\tzIndex: \"1\",\n\t\t\t\tbackgroundColor: \"var(--ui-filter-links-link-hover-bg, var(--ui-neutral-bg-tint))\",\n\t\t\t\tcolor: \"var(--ui-filter-links-link-hover-fg, var(--ui-neutral-fg-emphasis))\",\n\t\t\t\tborderColor:\n\t\t\t\t\t\"var(--ui-filter-links-link-hover-border-color, var(--ui-filter-links-link-border-color, transparent))\",\n\t\t\t}),\n\t\t),\n\t\t/**\n\t\t * The row clips anything past its edges to scroll sideways, so the focus ring draws just\n\t\t * inside the link, where the clip never cuts it.\n\t\t */\n\t\twhen(\"&:focus-visible\", [outline({ color: \"brand.ring\", offset: -2 }), raw({ zIndex: \"1\" })]),\n\t\twhen(\n\t\t\t'&[aria-current=\"page\"]',\n\t\t\traw({\n\t\t\t\tzIndex: \"1\",\n\t\t\t\tbackgroundColor: \"var(--ui-filter-links-current-bg, var(--ui-neutral-bg-solid))\",\n\t\t\t\tcolor: \"var(--ui-filter-links-current-fg, var(--ui-neutral-fg-on-solid))\",\n\t\t\t\tborderColor:\n\t\t\t\t\t\"var(--ui-filter-links-current-border-color, var(--ui-filter-links-link-border-color, transparent))\",\n\t\t\t}),\n\t\t),\n\t];\n}\n"
11
+ },
12
+ "test": {
13
+ "path": "filter-links.browser.test.tsx",
14
+ "content": "/**\n * Renders `FilterLinks` in a real browser: a named landmark marking the current filter, counts\n * after labels, one line scrolling sideways on a narrow screen. Each custom property set on the\n * root restyles the links, a negative overlap joins bordered links into one segmented line, and\n * each link takes a caller's label node, styles and attributes.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { raw } from \"@sdxc/u/general\";\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { FilterLinks } from \"@sdxc/ui/filter-links\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** One filter the tests draw. */\ninterface Item {\n\tlabel: string;\n\thref: string;\n\tcount?: number;\n\tcurrent?: boolean;\n}\n\n/** Six filters, more than a phone-width row fits on one line. */\nconst ITEMS: Item[] = [\n\t{ label: \"Everything\", href: \"/\", count: 128, current: true },\n\t{ label: \"Articles\", href: \"/?type=articles\", count: 41 },\n\t{ label: \"Tutorials\", href: \"/?type=tutorials\", count: 23 },\n\t{ label: \"Notes\", href: \"/?type=notes\", count: 37 },\n\t{ label: \"Links\", href: \"/?type=links\", count: 19 },\n\t{ label: \"Glossary\", href: \"/?type=glossary\" },\n];\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts the row `width` pixels wide and returns its `<nav>`. */\nfunction mount(\n\twidth: number,\n\tprops: Partial<FilterLinks.Props> = {},\n\tchildren: JSX.Element | JSX.Element[] = ITEMS.map((item) => (\n\t\t<FilterLinks.Link href={item.href} current={item.current}>\n\t\t\t{item.label}\n\t\t\t{item.count === undefined ? null : <FilterLinks.Count>{item.count}</FilterLinks.Count>}\n\t\t</FilterLinks.Link>\n\t)),\n): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\tmounted = render(\n\t\t<FilterLinks aria-label=\"Filter by type\" {...props}>\n\t\t\t{children}\n\t\t</FilterLinks>,\n\t\t{ container: host },\n\t);\n\treturn host.querySelector(\"nav\")!;\n}\n\n/** Every custom property the row reads, each set to a value unlike its default. */\nconst OVERRIDES = {\n\t\"--ui-filter-links-gap\": \"20px\",\n\t\"--ui-filter-links-link-padding\": \"3px 9px\",\n\t\"--ui-filter-links-link-radius\": \"2px\",\n\t\"--ui-filter-links-link-border-width\": \"3px\",\n\t\"--ui-filter-links-link-border-style\": \"dashed\",\n\t\"--ui-filter-links-link-border-color\": \"rgb(1, 2, 3)\",\n\t\"--ui-filter-links-link-bg\": \"rgb(4, 5, 6)\",\n\t\"--ui-filter-links-link-fg\": \"rgb(7, 8, 9)\",\n\t\"--ui-filter-links-link-font-family\": \"monospace\",\n\t\"--ui-filter-links-link-font-size\": \"19px\",\n\t\"--ui-filter-links-link-font-weight\": \"800\",\n\t\"--ui-filter-links-link-text-transform\": \"uppercase\",\n\t\"--ui-filter-links-link-letter-spacing\": \"2px\",\n\t\"--ui-filter-links-current-bg\": \"rgb(10, 11, 12)\",\n\t\"--ui-filter-links-current-fg\": \"rgb(13, 14, 15)\",\n\t\"--ui-filter-links-current-border-color\": \"rgb(16, 17, 18)\",\n\t\"--ui-filter-links-count-opacity\": \"0.4\",\n} satisfies FilterLinks.CustomProperties;\n\ndescribe(\"FilterLinks\", () => {\n\ttest(\"names the landmark and links every filter\", () => {\n\t\tlet nav = mount(800);\n\t\tlet links = [...nav.querySelectorAll(\"a\")];\n\n\t\texpect(nav.getAttribute(\"aria-label\")).toBe(\"Filter by type\");\n\t\texpect(links.map((link) => link.getAttribute(\"href\"))).toEqual(ITEMS.map((item) => item.href));\n\t\texpect(links[1]!.textContent).toBe(\"Articles41\");\n\t\texpect(links[5]!.querySelector('[data-slot=\"filter-links-count\"]')).toBeNull();\n\t});\n\n\ttest(\"marks only the current filter as the current page\", () => {\n\t\tlet nav = mount(800);\n\t\tlet current = [...nav.querySelectorAll(\"a[aria-current]\")];\n\n\t\texpect(current).toHaveLength(1);\n\t\texpect(current[0]!.getAttribute(\"aria-current\")).toBe(\"page\");\n\t\texpect(current[0]!.textContent).toBe(\"Everything128\");\n\t});\n\n\ttest(\"keeps one line on a phone and scrolls sideways with no scrollbar\", () => {\n\t\tlet nav = mount(320);\n\t\tlet tops = new Set(\n\t\t\t[...nav.querySelectorAll(\"li\")].map((item) => Math.round(item.getBoundingClientRect().top)),\n\t\t);\n\n\t\texpect(tops.size).toBe(1);\n\t\texpect(nav.scrollWidth).toBeGreaterThan(nav.clientWidth);\n\t\texpect(nav.offsetHeight).toBe(nav.clientHeight);\n\t\texpect(getComputedStyle(nav).overflowX).toBe(\"auto\");\n\t\texpect(getComputedStyle(nav).scrollbarWidth).toBe(\"none\");\n\t});\n\n\ttest(\"lays every filter on one line without scrolling when it fits\", () => {\n\t\tlet nav = mount(1000);\n\n\t\texpect(nav.scrollWidth).toBe(nav.clientWidth);\n\t});\n\n\ttest(\"draws the default pill, padding and colours\", () => {\n\t\tlet nav = mount(1000);\n\t\tlet link = getComputedStyle(nav.querySelectorAll(\"a\")[1]!);\n\t\tlet current = getComputedStyle(nav.querySelector(\"a[aria-current]\")!);\n\n\t\texpect(link.borderTopLeftRadius).toBe(\"9999px\");\n\t\texpect(link.borderTopWidth).toBe(\"0px\");\n\t\texpect(link.paddingTop).toBe(\"6px\");\n\t\texpect(link.paddingLeft).toBe(\"14px\");\n\t\texpect(link.fontSize).toBe(\"14px\");\n\t\texpect(link.fontWeight).toBe(\"500\");\n\t\texpect(link.backgroundColor).toBe(\"rgba(0, 0, 0, 0)\");\n\t\texpect(current.color).not.toBe(link.color);\n\t\texpect(getComputedStyle(nav.querySelector(\"ul\")!).columnGap).toBe(\"6px\");\n\t});\n\n\ttest(\"restyles every link from custom properties set on the root\", () => {\n\t\tlet nav = mount(1000, { mix: [raw(OVERRIDES)] });\n\t\tlet link = getComputedStyle(nav.querySelectorAll(\"a\")[1]!);\n\t\tlet current = getComputedStyle(nav.querySelector(\"a[aria-current]\")!);\n\t\tlet count = getComputedStyle(nav.querySelector('[data-slot=\"filter-links-count\"]')!);\n\n\t\texpect(getComputedStyle(nav.querySelector(\"ul\")!).columnGap).toBe(\"20px\");\n\t\texpect(link.paddingTop).toBe(\"3px\");\n\t\texpect(link.paddingLeft).toBe(\"9px\");\n\t\texpect(link.borderTopLeftRadius).toBe(\"2px\");\n\t\texpect(link.borderTopWidth).toBe(\"3px\");\n\t\texpect(link.borderTopStyle).toBe(\"dashed\");\n\t\texpect(link.borderTopColor).toBe(\"rgb(1, 2, 3)\");\n\t\texpect(link.backgroundColor).toBe(\"rgb(4, 5, 6)\");\n\t\texpect(link.color).toBe(\"rgb(7, 8, 9)\");\n\t\texpect(link.fontFamily).toBe(\"monospace\");\n\t\texpect(link.fontSize).toBe(\"19px\");\n\t\texpect(link.fontWeight).toBe(\"800\");\n\t\texpect(link.textTransform).toBe(\"uppercase\");\n\t\texpect(link.letterSpacing).toBe(\"2px\");\n\t\texpect(current.backgroundColor).toBe(\"rgb(10, 11, 12)\");\n\t\texpect(current.color).toBe(\"rgb(13, 14, 15)\");\n\t\texpect(current.borderTopColor).toBe(\"rgb(16, 17, 18)\");\n\t\texpect(count.opacity).toBe(\"0.4\");\n\t});\n\n\ttest(\"takes a node label, styles and attributes on each link\", () => {\n\t\tlet nav = mount(1000, {}, [\n\t\t\t<FilterLinks.Link\n\t\t\t\thref=\"/?type=notes\"\n\t\t\t\tdata-kind=\"note\"\n\t\t\t\tmix={[raw({ backgroundColor: \"rgb(20, 30, 40)\" })]}\n\t\t\t>\n\t\t\t\t<span data-dot />\n\t\t\t\tNotes\n\t\t\t</FilterLinks.Link>,\n\t\t\t<FilterLinks.Link href=\"/?type=links\">Links</FilterLinks.Link>,\n\t\t]);\n\t\tlet [notes, links] = [...nav.querySelectorAll(\"a\")];\n\n\t\texpect(notes!.querySelector(\"[data-dot]\")).not.toBeNull();\n\t\texpect(notes!.textContent).toBe(\"Notes\");\n\t\texpect(notes!.dataset.kind).toBe(\"note\");\n\t\texpect(getComputedStyle(notes!).backgroundColor).toBe(\"rgb(20, 30, 40)\");\n\t\texpect(links!.dataset.kind).toBeUndefined();\n\t\texpect(links!.getAttribute(\"href\")).toBe(\"/?type=links\");\n\t});\n\n\ttest(\"wraps onto more lines instead of scrolling when asked\", () => {\n\t\tlet nav = mount(320, { wrap: true });\n\t\tlet tops = new Set(\n\t\t\t[...nav.querySelectorAll(\"li\")].map((item) => Math.round(item.getBoundingClientRect().top)),\n\t\t);\n\n\t\texpect(tops.size).toBeGreaterThan(1);\n\t\texpect(nav.scrollWidth).toBe(nav.clientWidth);\n\t\texpect(getComputedStyle(nav).overflowX).toBe(\"visible\");\n\t});\n\n\ttest(\"restyles each count's typeface, size and colour from the root\", () => {\n\t\tlet nav = mount(1000, {\n\t\t\tmix: [\n\t\t\t\traw({\n\t\t\t\t\t\"--ui-filter-links-count-font-family\": \"monospace\",\n\t\t\t\t\t\"--ui-filter-links-count-font-size\": \"11px\",\n\t\t\t\t\t\"--ui-filter-links-count-fg\": \"rgb(21, 22, 23)\",\n\t\t\t\t} satisfies FilterLinks.CustomProperties),\n\t\t\t],\n\t\t});\n\t\tlet count = getComputedStyle(nav.querySelectorAll('[data-slot=\"filter-links-count\"]')[1]!);\n\n\t\texpect(count.fontFamily).toBe(\"monospace\");\n\t\texpect(count.fontSize).toBe(\"11px\");\n\t\texpect(count.color).toBe(\"rgb(21, 22, 23)\");\n\t});\n\n\ttest(\"keeps a count in its link's colour by default\", () => {\n\t\tlet nav = mount(1000);\n\t\tlet link = nav.querySelectorAll(\"a\")[1]!;\n\n\t\texpect(getComputedStyle(link.querySelector('[data-slot=\"filter-links-count\"]')!).color).toBe(\n\t\t\tgetComputedStyle(link).color,\n\t\t);\n\t});\n\n\ttest(\"recolours a link's border under the pointer from the root\", async () => {\n\t\tlet nav = mount(1000, {\n\t\t\tmix: [\n\t\t\t\traw({\n\t\t\t\t\t\"--ui-filter-links-link-border-width\": \"1px\",\n\t\t\t\t\t\"--ui-filter-links-link-border-color\": \"rgb(1, 2, 3)\",\n\t\t\t\t\t\"--ui-filter-links-link-hover-border-color\": \"rgb(24, 25, 26)\",\n\t\t\t\t} satisfies FilterLinks.CustomProperties),\n\t\t\t],\n\t\t});\n\t\tlet link = nav.querySelectorAll(\"a\")[1]!;\n\n\t\texpect(getComputedStyle(link).borderTopColor).toBe(\"rgb(1, 2, 3)\");\n\t\tawait userEvent.hover(link);\n\t\tfor (let animation of document.getAnimations()) animation.finish();\n\t\texpect(getComputedStyle(link).borderTopColor).toBe(\"rgb(24, 25, 26)\");\n\t});\n\n\ttest(\"lets a caller's data-slot name the root\", () => {\n\t\tlet nav = mount(1000, { \"data-slot\": \"kind-filter\" } as Partial<FilterLinks.Props>);\n\n\t\texpect(nav.dataset.slot).toBe(\"kind-filter\");\n\t});\n\n\ttest(\"joins bordered links into one line with a negative overlap, the current one on top\", () => {\n\t\tlet nav = mount(1000, {\n\t\t\tmix: [\n\t\t\t\traw({\n\t\t\t\t\t\"--ui-filter-links-gap\": \"0px\",\n\t\t\t\t\t\"--ui-filter-links-link-border-width\": \"1px\",\n\t\t\t\t\t\"--ui-filter-links-link-overlap\": \"-1px\",\n\t\t\t\t} satisfies FilterLinks.CustomProperties),\n\t\t\t],\n\t\t});\n\t\tlet [first, second] = [...nav.querySelectorAll(\"li\")];\n\t\tlet links = [...nav.querySelectorAll(\"a\")];\n\n\t\texpect(getComputedStyle(first!).marginInlineStart).toBe(\"0px\");\n\t\texpect(getComputedStyle(second!).marginInlineStart).toBe(\"-1px\");\n\t\texpect(links[1]!.getBoundingClientRect().left).toBeCloseTo(\n\t\t\tlinks[0]!.getBoundingClientRect().right - 1,\n\t\t\t1,\n\t\t);\n\t\texpect(getComputedStyle(links[0]!).zIndex).toBe(\"1\");\n\t\texpect(getComputedStyle(links[1]!).zIndex).toBe(\"auto\");\n\t});\n\n\ttest(\"leaves the links apart by default\", () => {\n\t\tlet nav = mount(1000);\n\t\tlet items = [...nav.querySelectorAll(\"li\")];\n\n\t\texpect(items.map((item) => getComputedStyle(item).marginInlineStart)).toEqual(\n\t\t\titems.map(() => \"0px\"),\n\t\t);\n\t});\n});\n"
15
+ }
16
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
5
  "alert"
6
6
  ],
@@ -12,10 +12,10 @@
12
12
  ],
13
13
  "source": {
14
14
  "path": "form.tsx",
15
- "content": "/**\n * The wrapper every multi-field layout starts from: a native `<form>` laying\n * its children out in a single spaced column, and the point where a parsed\n * validation result enters the tree. Set `issues` from a `parseSafe` (or any\n * other Standard Schema compliant) result and every field beneath it can\n * pick out its own errors by name through component context, with no\n * `issues` prop threaded down by hand.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap } from \"@sdxc/u/layout\";\n\nimport { Alert } from \"@sdxc/ui/alert\";\n\n/** {@link Form.Props.issues} fallback for a first, not-yet-submitted render. */\nconst DEFAULT_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/** Shared empty result {@link Form.Context.getIssues} returns for a field with no matching issue. */\nconst NO_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/**\n * Prop types for {@link Form} and the context value it provides to\n * descendant fields.\n */\nexport namespace Form {\n\t/**\n\t * A single validation failure as reported by a Standard Schema compliant\n\t * validator. `path` locates the field the issue belongs to — a plain key,\n\t * an index, or a `{ key }` segment — or is omitted for a form-level issue.\n\t */\n\texport interface Issue {\n\t\t/** Human-readable failure message, rendered verbatim by a field's `FieldError`. */\n\t\treadonly message: string;\n\t\t/** Field location of the issue, e.g. `[\"email\"]` or `[\"address\", \"zip\"]`. Omitted for a form-level issue. */\n\t\treadonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;\n\t}\n\n\t/**\n\t * Value {@link Form} stores in component context. A field reads it with\n\t * `handle.context.get(Form)` to find its own issues by name and learn\n\t * whether it's the field that should carry `autofocus` on this render.\n\t */\n\texport interface Context {\n\t\t/**\n\t\t * Every issue whose `path` resolves to `name` (segments joined with\n\t\t * `\".\"`, e.g. `\"address.zip\"`), or an empty array when the field has\n\t\t * none.\n\t\t *\n\t\t * @param name Field name to look up, matching its `name` attribute.\n\t\t * @returns The issues addressed to that field, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetIssues(name: string): ReadonlyArray<Issue>;\n\t\t/**\n\t\t * `true` for the single field name that comes first among\n\t\t * {@link Form.Props.issues}, so exactly one invalid field renders\n\t\t * `autofocus`, landing keyboard focus on it after a server re-render.\n\t\t *\n\t\t * @param name Field name to check, matching its `name` attribute.\n\t\t * @returns Whether `name` is the first invalid field this render.\n\t\t */\n\t\tisFirstInvalid(name: string): boolean;\n\t\t/**\n\t\t * Every issue with no `path` at all — a failure that names no single\n\t\t * field, such as a server-side refusal decided before any field was\n\t\t * reached. {@link Form} already renders these through its own leading\n\t\t * `Alert`; a caller reaches for this only to render them somewhere\n\t\t * else instead.\n\t\t *\n\t\t * @returns The form-level issues, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetFormIssues(): ReadonlyArray<Issue>;\n\t}\n\n\t/**\n\t * Props accepted by {@link Form}.\n\t */\n\texport interface Props extends TagProps<\"form\"> {\n\t\t/**\n\t\t * Validation issues from a `parseSafe` (or equivalent Standard Schema)\n\t\t * result, provided to every descendant field through component\n\t\t * context. Defaults to no issues, matching a first render.\n\t\t *\n\t\t * @example\n\t\t * let result = parseSafe(ContactSchema, await request.formData());\n\t\t * if (!result.success) return ctx.render(<ContactPage issues={result.issues} />, { status: 400 });\n\t\t */\n\t\tissues?: ReadonlyArray<Issue>;\n\t}\n}\n\n/**\n * Resolves the flat field name an issue's `path` addresses, joining every\n * segment with `\".\"` (`[\"address\", \"zip\"]` becomes `\"address.zip\"`).\n *\n * @param path Issue path to resolve, or `undefined` for a form-level issue.\n * @returns The joined field name, or `undefined` when `path` is missing or empty.\n */\nfunction resolveFieldName(path: Form.Issue[\"path\"]): string | undefined {\n\tif (!path || path.length === 0) return undefined;\n\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\n/**\n * Groups `issues` by the field name each one's `path` resolves to. An issue\n * with no path names no field to group under, so {@link Form} reads those\n * separately, through {@link Form.Context.getFormIssues}.\n *\n * @param issues Issues to group, typically {@link Form.Props.issues} as-is.\n * @returns A map from field name to every issue addressed to it, in `issues` order.\n */\nfunction groupIssuesByField(issues: ReadonlyArray<Form.Issue>): Map<string, Form.Issue[]> {\n\tlet byField = new Map<string, Form.Issue[]>();\n\n\tfor (let issue of issues) {\n\t\tlet name = resolveFieldName(issue.path);\n\t\tif (name === undefined) continue;\n\n\t\tlet bucket = byField.get(name);\n\t\tif (bucket) bucket.push(issue);\n\t\telse byField.set(name, [issue]);\n\t}\n\n\treturn byField;\n}\n\n/**\n * Renders a native `<form>` laying children out in a single column, and\n * provides {@link Form.Context} so descendant fields resolve their own\n * issues by name and focus the first invalid field with no client JS. An\n * issue with no `path` names no field to attach to, so it renders as its\n * own leading `Alert` instead of being silently unreachable — a refusal\n * decided before any field was reached still reaches the person filling\n * the form in.\n *\n * @param handle Runtime handle carrying the host `<form>`'s props and providing {@link Form.Context}.\n * @returns The render function producing the form's markup.\n * @example\n * let result = parseSafe(ContactSchema, formData);\n * <Form method=\"post\" issues={result.success ? undefined : result.issues}>\n * <TextField name=\"email\" label={t(\"contact.email\")} />\n * <Button type=\"submit\">{t(\"contact.submit\")}</Button>\n * </Form>\n */\nexport function Form(handle: Handle<Form.Props, Form.Context>) {\n\treturn () => {\n\t\tlet { issues = DEFAULT_ISSUES, mix, children, ...rest } = handle.props;\n\t\tlet byField = groupIssuesByField(issues);\n\t\tlet formIssues = issues.filter((issue) => resolveFieldName(issue.path) === undefined);\n\t\tlet firstInvalidField = issues\n\t\t\t.map((issue) => resolveFieldName(issue.path))\n\t\t\t.find((name) => name !== undefined);\n\n\t\thandle.context.set({\n\t\t\tgetIssues(name) {\n\t\t\t\treturn byField.get(name) ?? NO_ISSUES;\n\t\t\t},\n\t\t\tisFirstInvalid(name) {\n\t\t\t\treturn name === firstInvalidField;\n\t\t\t},\n\t\t\tgetFormIssues() {\n\t\t\t\treturn formIssues;\n\t\t\t},\n\t\t});\n\n\t\treturn (\n\t\t\t<form {...rest} mix={mergeMix([flex(), flexCol(), gap(4)], mix)}>\n\t\t\t\t{formIssues.length > 0 && (\n\t\t\t\t\t<Alert color=\"danger\" data-slot=\"form-issues\">\n\t\t\t\t\t\t<Alert.Description>\n\t\t\t\t\t\t\t{formIssues.map((issue) => issue.message).join(\" \")}\n\t\t\t\t\t\t</Alert.Description>\n\t\t\t\t\t</Alert>\n\t\t\t\t)}\n\t\t\t\t{children}\n\t\t\t</form>\n\t\t);\n\t};\n}\n\n/**\n * What a field resolved for its own validation state this render, from its\n * own props and from whatever the enclosing {@link Form} knows about it.\n */\nexport interface FieldIssueState {\n\t/** Message the field renders through its `FieldError`, or `undefined` for a field with nothing to report. */\n\terrorMessage: RemixNode | undefined;\n\t/** Whether this is the field that should carry `autofocus`, so focus lands on the first problem after a server round-trip. */\n\tisFirstInvalid: boolean;\n}\n\n/**\n * Reads the {@link Form.Context} provided by the nearest ancestor\n * {@link Form}, resolving to `undefined` when no Form wraps the caller so\n * every field renders safely inside or outside a Form.\n *\n * @param handle Runtime handle of the field performing the lookup.\n * @returns The enclosing form's context, or `undefined` where no Form wraps the caller.\n */\nexport function readFormContext(handle: Handle<unknown, any>): Form.Context | undefined {\n\ttry {\n\t\treturn handle.context.get(Form) as Form.Context | undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the validation state a field renders: an explicit `errorMessage`\n * always wins over a matching {@link Form} issue for `name`, which is how\n * `Form`'s `issues` reach a field with no per-field prop threaded by hand.\n *\n * @param handle Runtime handle of the field resolving its state.\n * @param name The field's `name` attribute, used to look its issues up.\n * @param errorMessage An `errorMessage` passed directly to the field, if any.\n * @returns The message to render and whether this field carries `autofocus`.\n * @example\n * let { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, \"email\", handle.props.errorMessage);\n */\nexport function resolveFieldIssue(\n\thandle: Handle<unknown, any>,\n\tname: string | undefined,\n\terrorMessage?: RemixNode,\n): FieldIssueState {\n\tif (name === undefined) return { errorMessage, isFirstInvalid: false };\n\n\tlet context = readFormContext(handle);\n\tif (!context) return { errorMessage, isFirstInvalid: false };\n\n\tlet resolved = errorMessage ?? context.getIssues(name)[0]?.message;\n\n\treturn {\n\t\terrorMessage: resolved,\n\t\tisFirstInvalid: Boolean(resolved) && context.isFirstInvalid(name),\n\t};\n}\n"
15
+ "content": "/**\n * The wrapper every multi-field layout starts from: a native `<form>` laying\n * its children out in a single spaced column, and the point where a parsed\n * validation result enters the tree. Set `issues` from a `parseSafe` (or any\n * other Standard Schema compliant) result and every field beneath it can\n * pick out its own errors by name through component context, with no\n * `issues` prop threaded down by hand.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap } from \"@sdxc/u/layout\";\n\nimport { Alert } from \"@sdxc/ui/alert\";\n\n/** {@link Form.Props.issues} fallback for a first, not-yet-submitted render. */\nconst DEFAULT_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/** Shared empty result {@link Form.Context.getIssues} returns for a field with no matching issue. */\nconst NO_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/**\n * Prop types for {@link Form} and the context value it provides to\n * descendant fields.\n */\nexport namespace Form {\n\t/**\n\t * A single validation failure as reported by a Standard Schema compliant\n\t * validator. `path` locates the field the issue belongs to — a plain key,\n\t * an index, or a `{ key }` segment — or is omitted for a form-level issue.\n\t */\n\texport interface Issue {\n\t\t/** Human-readable failure message, rendered verbatim by a field's `FieldError`. */\n\t\treadonly message: string;\n\t\t/** Field location of the issue, e.g. `[\"email\"]` or `[\"address\", \"zip\"]`. Omitted for a form-level issue. */\n\t\treadonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;\n\t}\n\n\t/**\n\t * Value {@link Form} stores in component context. A field reads it with\n\t * `handle.context.get(Form)` to find its own issues by name and learn\n\t * whether it's the field that should carry `autofocus` on this render.\n\t */\n\texport interface Context {\n\t\t/**\n\t\t * Every issue whose `path` resolves to `name` (segments joined with\n\t\t * `\".\"`, e.g. `\"address.zip\"`), or an empty array when the field has\n\t\t * none.\n\t\t *\n\t\t * @param name Field name to look up, matching its `name` attribute.\n\t\t * @returns The issues addressed to that field, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetIssues(name: string): ReadonlyArray<Issue>;\n\t\t/**\n\t\t * `true` for the single field name that comes first among\n\t\t * {@link Form.Props.issues}, so exactly one invalid field renders\n\t\t * `autofocus`, landing keyboard focus on it after a server re-render.\n\t\t *\n\t\t * @param name Field name to check, matching its `name` attribute.\n\t\t * @returns Whether `name` is the first invalid field this render.\n\t\t */\n\t\tisFirstInvalid(name: string): boolean;\n\t\t/**\n\t\t * Every issue with no `path` at all — a failure that names no single\n\t\t * field, such as a server-side refusal decided before any field was\n\t\t * reached. {@link Form} already renders these through its own leading\n\t\t * `Alert`; a caller reaches for this only to render them somewhere\n\t\t * else instead.\n\t\t *\n\t\t * @returns The form-level issues, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetFormIssues(): ReadonlyArray<Issue>;\n\t}\n\n\t/**\n\t * Props accepted by {@link Form}.\n\t */\n\texport interface Props extends TagProps<\"form\"> {\n\t\t/**\n\t\t * Validation issues from a `parseSafe` (or equivalent Standard Schema)\n\t\t * result, provided to every descendant field through component\n\t\t * context. Defaults to no issues, matching a first render.\n\t\t *\n\t\t * @example\n\t\t * let result = parseSafe(ContactSchema, await request.formData());\n\t\t * if (!result.success) return ctx.render(<ContactPage issues={result.issues} />, { status: 400 });\n\t\t */\n\t\tissues?: ReadonlyArray<Issue>;\n\t}\n}\n\n/**\n * Resolves the flat field name an issue's `path` addresses, joining every\n * segment with `\".\"` (`[\"address\", \"zip\"]` becomes `\"address.zip\"`).\n *\n * @param path Issue path to resolve, or `undefined` for a form-level issue.\n * @returns The joined field name, or `undefined` when `path` is missing or empty.\n */\nfunction resolveFieldName(path: Form.Issue[\"path\"]): string | undefined {\n\tif (!path || path.length === 0) return undefined;\n\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\n/**\n * Groups `issues` by the field name each one's `path` resolves to. An issue\n * with no path names no field to group under, so {@link Form} reads those\n * separately, through {@link Form.Context.getFormIssues}.\n *\n * @param issues Issues to group, typically {@link Form.Props.issues} as-is.\n * @returns A map from field name to every issue addressed to it, in `issues` order.\n */\nfunction groupIssuesByField(issues: ReadonlyArray<Form.Issue>): Map<string, Form.Issue[]> {\n\tlet byField = new Map<string, Form.Issue[]>();\n\n\tfor (let issue of issues) {\n\t\tlet name = resolveFieldName(issue.path);\n\t\tif (name === undefined) continue;\n\n\t\tlet bucket = byField.get(name);\n\t\tif (bucket) bucket.push(issue);\n\t\telse byField.set(name, [issue]);\n\t}\n\n\treturn byField;\n}\n\n/**\n * Renders a native `<form>` laying children out in a single column, and\n * provides {@link Form.Context} so descendant fields resolve their own\n * issues by name and focus the first invalid field with no client JS. An\n * issue with no `path` names no field to attach to, so it renders as its\n * own leading `Alert` instead of being silently unreachable — a refusal\n * decided before any field was reached still reaches the person filling\n * the form in.\n *\n * @param handle Runtime handle carrying the host `<form>`'s props and providing {@link Form.Context}.\n * @returns The render function producing the form's markup.\n * @example\n * let result = parseSafe(ContactSchema, formData);\n * <Form method=\"post\" issues={result.success ? undefined : result.issues}>\n * <TextField name=\"email\">\n * <TextField.Label>{t(\"contact.email\")}</TextField.Label>\n * </TextField>\n * <Button type=\"submit\">{t(\"contact.submit\")}</Button>\n * </Form>\n */\nexport function Form(handle: Handle<Form.Props, Form.Context>) {\n\treturn () => {\n\t\tlet { issues = DEFAULT_ISSUES, mix, children, ...rest } = handle.props;\n\t\tlet byField = groupIssuesByField(issues);\n\t\tlet formIssues = issues.filter((issue) => resolveFieldName(issue.path) === undefined);\n\t\tlet firstInvalidField = issues\n\t\t\t.map((issue) => resolveFieldName(issue.path))\n\t\t\t.find((name) => name !== undefined);\n\n\t\thandle.context.set({\n\t\t\tgetIssues(name) {\n\t\t\t\treturn byField.get(name) ?? NO_ISSUES;\n\t\t\t},\n\t\t\tisFirstInvalid(name) {\n\t\t\t\treturn name === firstInvalidField;\n\t\t\t},\n\t\t\tgetFormIssues() {\n\t\t\t\treturn formIssues;\n\t\t\t},\n\t\t});\n\n\t\treturn (\n\t\t\t<form {...rest} mix={mergeMix([flex(), flexCol(), gap(4)], mix)}>\n\t\t\t\t{formIssues.length > 0 && (\n\t\t\t\t\t<Alert color=\"danger\" data-slot=\"form-issues\">\n\t\t\t\t\t\t<Alert.Description>\n\t\t\t\t\t\t\t{formIssues.map((issue) => issue.message).join(\" \")}\n\t\t\t\t\t\t</Alert.Description>\n\t\t\t\t\t</Alert>\n\t\t\t\t)}\n\t\t\t\t{children}\n\t\t\t</form>\n\t\t);\n\t};\n}\n\n/**\n * What a field resolved for its own validation state this render, from its\n * own props and from whatever the enclosing {@link Form} knows about it.\n */\nexport interface FieldIssueState {\n\t/** Message the field renders through its `FieldError`, or `undefined` for a field with nothing to report. */\n\terrorMessage: RemixNode | undefined;\n\t/** Whether this is the field that should carry `autofocus`, so focus lands on the first problem after a server round-trip. */\n\tisFirstInvalid: boolean;\n}\n\n/**\n * Reads the {@link Form.Context} provided by the nearest ancestor\n * {@link Form}, resolving to `undefined` when no Form wraps the caller so\n * every field renders safely inside or outside a Form.\n *\n * @param handle Runtime handle of the field performing the lookup.\n * @returns The enclosing form's context, or `undefined` where no Form wraps the caller.\n */\nexport function readFormContext(handle: Handle<unknown, any>): Form.Context | undefined {\n\ttry {\n\t\treturn handle.context.get(Form) as Form.Context | undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the validation state a field renders: an explicit `errorMessage`\n * always wins over a matching {@link Form} issue for `name`, which is how\n * `Form`'s `issues` reach a field with no per-field prop threaded by hand.\n *\n * @param handle Runtime handle of the field resolving its state.\n * @param name The field's `name` attribute, used to look its issues up.\n * @param errorMessage An `errorMessage` passed directly to the field, if any.\n * @returns The message to render and whether this field carries `autofocus`.\n * @example\n * let { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, \"email\", handle.props.errorMessage);\n */\nexport function resolveFieldIssue(\n\thandle: Handle<unknown, any>,\n\tname: string | undefined,\n\terrorMessage?: RemixNode,\n): FieldIssueState {\n\tif (name === undefined) return { errorMessage, isFirstInvalid: false };\n\n\tlet context = readFormContext(handle);\n\tif (!context) return { errorMessage, isFirstInvalid: false };\n\n\tlet resolved = errorMessage ?? context.getIssues(name)[0]?.message;\n\n\treturn {\n\t\terrorMessage: resolved,\n\t\tisFirstInvalid: Boolean(resolved) && context.isFirstInvalid(name),\n\t};\n}\n"
16
16
  },
17
17
  "test": {
18
18
  "path": "form.test.tsx",
19
- "content": "/**\n * Tests for the path {@link Form}'s `issues` takes to reach a field: the\n * parse-then-re-render pattern passes `issues` alone, so a field must find\n * its own message through form context or show no error. Covers lookup by\n * `name`, an explicit `errorMessage` override, the aria wiring, and the\n * `autofocus` on the first invalid field.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport type { Form as FormNamespace } from \"@sdxc/ui/form\";\n\nimport { Form } from \"@sdxc/ui/form\";\nimport { TextField } from \"@sdxc/ui/text-field\";\n\n/**\n * Strips the `<style>` block `renderToString` emits ahead of the markup: the\n * field's own stylesheet mentions `[aria-invalid=\"true\"]` as a selector, so a\n * negative assertion has to look at the rendered elements alone.\n *\n * @param html A full `renderToString` result.\n * @returns Just the markup that follows the emitted styles.\n */\nfunction markup(html: string): string {\n\treturn html.slice(html.indexOf(\"</head>\") + 1);\n}\n\n/** Issues standing in for a failed `parseSafe` over an email/password form. */\nconst ISSUES: ReadonlyArray<FormNamespace.Issue> = [\n\t{ message: \"Enter a valid email\", path: [\"email\"] },\n\t{ message: \"Password is too short\", path: [\"password\"] },\n];\n\ndescribe(Form.name, () => {\n\ttest(\"hands each field its own message from issues alone, with no per-field prop\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t\t<TextField name=\"password\" type=\"password\" label=\"Password\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).toContain(\"Enter a valid email\");\n\t\texpect(html).toContain(\"Password is too short\");\n\t});\n\n\ttest(\"marks a field found in issues invalid and points its aria-describedby at the message\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).toContain('aria-invalid=\"true\"');\n\t\texpect(html).toContain(\"-error\");\n\t\texpect(html).toContain(\"aria-describedby\");\n\t});\n\n\ttest(\"gives autofocus to the first invalid field only\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t\t<TextField name=\"password\" type=\"password\" label=\"Password\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html).match(/autofocus/gi)).toHaveLength(1);\n\t\texpect(html.indexOf(\"autofocus\")).toBeLessThan(html.indexOf('type=\"password\"'));\n\t});\n\n\ttest(\"leaves a field with no matching issue untouched\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"nickname\" label=\"Nickname\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"Enter a valid email\");\n\t\texpect(markup(html)).not.toContain('aria-invalid=\"true\"');\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n\n\ttest(\"renders no error and no autofocus for a form with no issues at all\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\">\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain('aria-invalid=\"true\"');\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n\n\ttest(\"lets an explicit errorMessage win over the one issues holds for that field\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" errorMessage=\"That address is taken\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).toContain(\"That address is taken\");\n\t\texpect(html).not.toContain(\"Enter a valid email\");\n\t});\n\n\ttest(\"lets an explicit autoFocus win over the first-invalid default\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" autoFocus={false} />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n\n\ttest(\"renders a path-less issue's own message, since no field can claim it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={[{ message: \"Something went wrong. Try again.\" }]}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).toContain(\"Something went wrong. Try again.\");\n\t\texpect(markup(html)).toContain('role=\"alert\"');\n\t});\n\n\ttest(\"joins several path-less issues into one alert, in issues order\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={[{ message: \"First problem.\" }, { message: \"Second problem.\" }]}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html.indexOf(\"First problem.\")).toBeLessThan(html.indexOf(\"Second problem.\"));\n\t});\n\n\ttest(\"renders no alert at all when every issue names a field\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t\t<TextField name=\"password\" type=\"password\" label=\"Password\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain('data-slot=\"form-issues\"');\n\t});\n\n\ttest(\"a path-less issue does not affect which field gets autofocus\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={[{ message: \"Something went wrong.\" }, ...ISSUES]}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" />\n\t\t\t\t<TextField name=\"password\" type=\"password\" label=\"Password\" />\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html).match(/autofocus/gi)).toHaveLength(1);\n\t\texpect(html.indexOf(\"autofocus\")).toBeLessThan(html.indexOf('type=\"password\"'));\n\t});\n});\n\ndescribe(\"a field outside any Form\", () => {\n\ttest(\"still renders its own errorMessage, and does not fail the lookup it can't satisfy\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<TextField name=\"email\" type=\"email\" label=\"Email\" errorMessage=\"Enter a valid email\" />,\n\t\t);\n\n\t\texpect(html).toContain(\"Enter a valid email\");\n\t\texpect(markup(html)).toContain('aria-invalid=\"true\"');\n\t});\n\n\ttest(\"renders nothing extra when it has no message of its own\", async () => {\n\t\tlet html = await renderToString(<TextField name=\"email\" type=\"email\" label=\"Email\" />);\n\n\t\texpect(markup(html)).not.toContain('aria-invalid=\"true\"');\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n});\n"
19
+ "content": "/**\n * Tests for the path {@link Form}'s `issues` takes to reach a field: the\n * parse-then-re-render pattern passes `issues` alone, so a field must find\n * its own message through form context or show no error. Covers lookup by\n * `name`, an explicit `errorMessage` override, the aria wiring, and the\n * `autofocus` on the first invalid field.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport type { Form as FormNamespace } from \"@sdxc/ui/form\";\n\nimport { Form } from \"@sdxc/ui/form\";\nimport { TextField } from \"@sdxc/ui/text-field\";\n\n/**\n * Strips the `<style>` block `renderToString` emits ahead of the markup: the\n * field's own stylesheet mentions `[aria-invalid=\"true\"]` as a selector, so a\n * negative assertion has to look at the rendered elements alone.\n *\n * @param html A full `renderToString` result.\n * @returns Just the markup that follows the emitted styles.\n */\nfunction markup(html: string): string {\n\treturn html.slice(html.indexOf(\"</head>\") + 1);\n}\n\n/** Issues standing in for a failed `parseSafe` over an email/password form. */\nconst ISSUES: ReadonlyArray<FormNamespace.Issue> = [\n\t{ message: \"Enter a valid email\", path: [\"email\"] },\n\t{ message: \"Password is too short\", path: [\"password\"] },\n];\n\ndescribe(Form.name, () => {\n\ttest(\"hands each field its own message from issues alone, with no per-field prop\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t\t<TextField name=\"password\" type=\"password\">\n\t\t\t\t\t<TextField.Label>Password</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).toContain(\"Enter a valid email\");\n\t\texpect(html).toContain(\"Password is too short\");\n\t});\n\n\ttest(\"marks a field found in issues invalid and points its aria-describedby at the message\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).toContain('aria-invalid=\"true\"');\n\t\texpect(html).toContain(\"-error\");\n\t\texpect(html).toContain(\"aria-describedby\");\n\t});\n\n\ttest(\"gives autofocus to the first invalid field only\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t\t<TextField name=\"password\" type=\"password\">\n\t\t\t\t\t<TextField.Label>Password</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html).match(/autofocus/gi)).toHaveLength(1);\n\t\texpect(html.indexOf(\"autofocus\")).toBeLessThan(html.indexOf('type=\"password\"'));\n\t});\n\n\ttest(\"leaves a field with no matching issue untouched\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"nickname\">\n\t\t\t\t\t<TextField.Label>Nickname</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"Enter a valid email\");\n\t\texpect(markup(html)).not.toContain('aria-invalid=\"true\"');\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n\n\ttest(\"renders no error and no autofocus for a form with no issues at all\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\">\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain('aria-invalid=\"true\"');\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n\n\ttest(\"lets an explicit errorMessage win over the one issues holds for that field\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t\t<TextField.Error>That address is taken</TextField.Error>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).toContain(\"That address is taken\");\n\t\texpect(html).not.toContain(\"Enter a valid email\");\n\t});\n\n\ttest(\"lets an explicit autoFocus win over the first-invalid default\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\" autoFocus={false}>\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n\n\ttest(\"renders a path-less issue's own message, since no field can claim it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={[{ message: \"Something went wrong. Try again.\" }]}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html).toContain(\"Something went wrong. Try again.\");\n\t\texpect(markup(html)).toContain('role=\"alert\"');\n\t});\n\n\ttest(\"joins several path-less issues into one alert, in issues order\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={[{ message: \"First problem.\" }, { message: \"Second problem.\" }]}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(html.indexOf(\"First problem.\")).toBeLessThan(html.indexOf(\"Second problem.\"));\n\t});\n\n\ttest(\"renders no alert at all when every issue names a field\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={ISSUES}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t\t<TextField name=\"password\" type=\"password\">\n\t\t\t\t\t<TextField.Label>Password</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain('data-slot=\"form-issues\"');\n\t});\n\n\ttest(\"a path-less issue does not affect which field gets autofocus\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Form method=\"post\" issues={[{ message: \"Something went wrong.\" }, ...ISSUES]}>\n\t\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t\t<TextField name=\"password\" type=\"password\">\n\t\t\t\t\t<TextField.Label>Password</TextField.Label>\n\t\t\t\t</TextField>\n\t\t\t</Form>,\n\t\t);\n\n\t\texpect(markup(html).match(/autofocus/gi)).toHaveLength(1);\n\t\texpect(html.indexOf(\"autofocus\")).toBeLessThan(html.indexOf('type=\"password\"'));\n\t});\n});\n\ndescribe(\"a field outside any Form\", () => {\n\ttest(\"still renders its own errorMessage, and does not fail the lookup it can't satisfy\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t\t<TextField.Error>Enter a valid email</TextField.Error>\n\t\t\t</TextField>,\n\t\t);\n\n\t\texpect(html).toContain(\"Enter a valid email\");\n\t\texpect(markup(html)).toContain('aria-invalid=\"true\"');\n\t});\n\n\ttest(\"renders nothing extra when it has no message of its own\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<TextField name=\"email\" type=\"email\">\n\t\t\t\t<TextField.Label>Email</TextField.Label>\n\t\t\t</TextField>,\n\t\t);\n\n\t\texpect(markup(html)).not.toContain('aria-invalid=\"true\"');\n\t\texpect(markup(html)).not.toContain(\"autofocus\");\n\t});\n});\n"
20
20
  }
21
21
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightbox",
3
- "changedIn": "2026.11.22",
3
+ "changedIn": "2026.11.27",
4
4
  "dependencies": [],
5
5
  "exports": [
6
6
  "Lightbox",
@@ -8,10 +8,10 @@
8
8
  ],
9
9
  "source": {
10
10
  "path": "lightbox.tsx",
11
- "content": "/**\n * A full-screen photo viewer for a gallery, as a native `<dialog>` a trigger opens through\n * Invoker Commands. Every photo sits in a scroll-snap track with its own address, so swiping\n * and the step links work without script; a small island adds arrow keys and opening at a photo.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon, XIcon } from \"@sdxc/icons\";\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { outline } from \"@sdxc/u/color\";\nimport { raw, mergeMix } from \"@sdxc/u/general\";\nimport { container } from \"@sdxc/u/layout\";\nimport { at, motionReduce, motionSafe, startingStyle } from \"@sdxc/u/responsive\";\nimport { when } from \"@sdxc/u/state\";\nimport { tabularNums } from \"@sdxc/u/typography\";\nimport { clientEntry } from \"remix/component\";\n\nimport { lightboxControls } from \"@sdxc/ui/mixins\";\n\n/** Container the viewer names, so its step buttons move beside the photo once there is room. */\nconst CONTAINER_NAME = \"ui-lightbox\";\n\n/** Width from which the step buttons sit in their own gutters instead of over the photo. */\nconst GUTTER_WIDTH = \"48rem\";\n\n/** Words the controls are named by when `labels` leaves them out. */\nconst DEFAULT_LABELS: Lightbox.Labels = {\n\tclose: \"Close\",\n\tprevious: \"Previous photo\",\n\tnext: \"Next photo\",\n};\n\n/** The round, 44px control shared by the close button and the step links. */\nconst CONTROL_STYLES = raw({\n\tdisplay: \"inline-grid\",\n\tplaceItems: \"center\",\n\tinlineSize: \"2.75rem\",\n\tblockSize: \"2.75rem\",\n\tpadding: 0,\n\tborder: 0,\n\tborderRadius: \"999px\",\n\tbackground: \"rgb(0 0 0 / 0.55)\",\n\tcolor: \"white\",\n\tcursor: \"pointer\",\n\ttextDecoration: \"none\",\n\tzIndex: 1,\n});\n\n/**\n * Prop types for {@link Lightbox} and its compound parts.\n */\nexport namespace Lightbox {\n\t/** One photo in the gallery. */\n\texport interface Photo {\n\t\t/** The image's address; leave it out to draw the photo with `art` instead. */\n\t\tsrc?: string;\n\t\t/** Candidate sources, as the native `srcset`. */\n\t\tsrcset?: string;\n\t\t/** What the photo shows, for a reader who cannot see it. */\n\t\talt: string;\n\t\t/** A line under the photo, such as the room it shows. */\n\t\tcaption?: RemixNode;\n\t\t/**\n\t\t * Drawn content standing in for `src`, such as an inline SVG with a `viewBox`; it is\n\t\t * scaled to fit the viewer as an image would be.\n\t\t */\n\t\tart?: RemixNode;\n\t}\n\n\t/** The words each control is named by. */\n\texport interface Labels {\n\t\t/** @default \"Close\" */\n\t\tclose: string;\n\t\t/** @default \"Previous photo\" */\n\t\tprevious: string;\n\t\t/** @default \"Next photo\" */\n\t\tnext: string;\n\t}\n\n\t/** Every native `<dialog>` attribute, plus the gallery. */\n\texport interface Props extends Omit<TagProps<\"dialog\">, \"children\" | \"open\"> {\n\t\t/** Targeted by each trigger's `commandfor`, and the prefix of every photo's own id. */\n\t\tid: string;\n\t\t/** The gallery's name, such as \"Photos of Fern Cabin\", read when the viewer opens. */\n\t\tlabel: string;\n\t\tphotos: Photo[];\n\t\t/**\n\t\t * Renders the viewer already open at this zero-based photo, for a page whose address\n\t\t * names one (`?photo=3`). Without script it is a non-modal dialog covering the page;\n\t\t * the island reopens it as a modal.\n\t\t */\n\t\tinitial?: number;\n\t\tlabels?: Partial<Labels>;\n\t}\n\n\t/** Every native `<button>` attribute, plus the viewer and photo it opens. */\n\texport interface TriggerProps extends Omit<TagProps<\"button\">, \"commandfor\" | \"command\"> {\n\t\t/** `id` of the {@link Lightbox} this opens. */\n\t\tlightbox: string;\n\t\t/**\n\t\t * Zero-based photo the viewer opens at once the island has loaded.\n\t\t *\n\t\t * @default 0\n\t\t */\n\t\tindex?: number;\n\t}\n}\n\n/** The id of photo `index`, one-based so it reads like the counter (`photos-photo-3`). */\nfunction slideId(id: string, index: number): string {\n\treturn `${id}-photo-${index + 1}`;\n}\n\n/**\n * Loads the viewer's script: the hidden host whose mixin wires the arrow keys, the\n * index-aware triggers and the live region. It loads from `@sdxc/ui/lightbox`, which the\n * app's browser entry maps; {@link Lightbox} renders it, so a page never places it itself.\n */\nexport const LightboxControls: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/lightbox#LightboxControls\",\n\tfunction LightboxControls() {\n\t\treturn () => <span hidden mix={[lightboxControls()]} />;\n\t},\n);\n\n/**\n * Renders the viewer: a full-screen dark `<dialog>` with a close button, one slide per photo\n * (contained, with \"n / N\" and its caption) and step links between neighbours. Opened from a\n * {@link Lightbox.Trigger}; Escape and the close button dismiss it.\n *\n * @param handle Runtime handle carrying the dialog's props.\n * @returns The render function producing the viewer's markup.\n * @example\n * <Lightbox.Trigger lightbox=\"cabin-photos\" index={2}><img src={thumb} alt=\"\" /></Lightbox.Trigger>\n * <Lightbox id=\"cabin-photos\" label=\"Photos of Fern Cabin\" photos={photos} />\n * @example\n * <Lightbox id=\"cabin-photos\" label=\"Photos\" photos={photos} initial={Number(url.searchParams.get(\"photo\")) - 1} />\n */\nexport function Lightbox(handle: Handle<Lightbox.Props>) {\n\treturn () => {\n\t\tlet { id, label, photos, initial, labels, mix, ...rest } = handle.props;\n\t\tlet words = { ...DEFAULT_LABELS, ...labels };\n\t\tlet total = photos.length;\n\t\tlet start = initial === undefined ? undefined : Math.max(0, Math.min(total - 1, initial));\n\n\t\treturn (\n\t\t\t<dialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\taria-label={label}\n\t\t\t\topen={start !== undefined}\n\t\t\t\tdata-lightbox-initial={start === undefined ? undefined : String(start)}\n\t\t\t\tdata-slot=\"lightbox\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"fixed\",\n\t\t\t\t\t\t\tinset: 0,\n\t\t\t\t\t\t\tinlineSize: \"auto\",\n\t\t\t\t\t\t\tblockSize: \"auto\",\n\t\t\t\t\t\t\tmaxInlineSize: \"none\",\n\t\t\t\t\t\t\tmaxBlockSize: \"none\",\n\t\t\t\t\t\t\tmargin: 0,\n\t\t\t\t\t\t\tpadding: 0,\n\t\t\t\t\t\t\tborder: 0,\n\t\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\t\tbackground: \"rgb(12 12 14)\",\n\t\t\t\t\t\t\tcolor: \"white\",\n\t\t\t\t\t\t\tcolorScheme: \"dark\",\n\t\t\t\t\t\t\tzIndex: 50,\n\t\t\t\t\t\t\topacity: 1,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcontainer(CONTAINER_NAME, \"inline-size\"),\n\t\t\t\t\t\twhen(\"&[open]\", raw({ display: \"block\" })),\n\t\t\t\t\t\twhen(\"&::backdrop\", raw({ background: \"rgb(0 0 0 / 0.9)\" })),\n\t\t\t\t\t\tmotionSafe([\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\ttransition:\n\t\t\t\t\t\t\t\t\t\"opacity 160ms ease-out, display 160ms allow-discrete, overlay 160ms allow-discrete\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tstartingStyle(when(\"&[open]\", raw({ opacity: 0 }))),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<LightboxControls />\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tcommandfor={id}\n\t\t\t\t\tcommand=\"close\"\n\t\t\t\t\taria-label={words.close}\n\t\t\t\t\tdata-slot=\"lightbox-close\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tCONTROL_STYLES,\n\t\t\t\t\t\traw({ position: \"absolute\", insetBlockStart: \"0.75rem\", insetInlineEnd: \"0.75rem\" }),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"white\", offset: 2, width: 2 })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<XIcon size={20} />\n\t\t\t\t</button>\n\t\t\t\t<p role=\"status\" data-lightbox-status=\"\" mix={[visuallyHidden()]} />\n\t\t\t\t<div\n\t\t\t\t\tdata-lightbox-track=\"\"\n\t\t\t\t\tdata-slot=\"lightbox-track\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\toverflowX: \"auto\",\n\t\t\t\t\t\t\toverflowY: \"hidden\",\n\t\t\t\t\t\t\tscrollSnapType: \"x mandatory\",\n\t\t\t\t\t\t\toverscrollBehaviorX: \"contain\",\n\t\t\t\t\t\t\tscrollbarWidth: \"none\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\"&::-webkit-scrollbar\", raw({ display: \"none\" })),\n\t\t\t\t\t\tmotionSafe(raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\t\tmotionReduce(raw({ scrollBehavior: \"auto\" })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{photos.map((photo, index) => (\n\t\t\t\t\t\t<LightboxSlide\n\t\t\t\t\t\t\tviewer={id}\n\t\t\t\t\t\t\tphoto={photo}\n\t\t\t\t\t\t\tindex={index}\n\t\t\t\t\t\t\ttotal={total}\n\t\t\t\t\t\t\tinitial={index === start}\n\t\t\t\t\t\t\tlabels={words}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t</dialog>\n\t\t);\n\t};\n}\n\n/** Props {@link LightboxSlide} reads. */\ninterface LightboxSlideProps {\n\tviewer: string;\n\tphoto: Lightbox.Photo;\n\tindex: number;\n\ttotal: number;\n\t/** Whether the server opened the viewer here, which snaps the track to it on first paint. */\n\tinitial: boolean;\n\tlabels: Lightbox.Labels;\n}\n\n/**\n * One photo filling the track: the picture contained in the space above its counter and\n * caption, with a link to each neighbour that addresses it by id, so the track scrolls there\n * with or without script. The first photo has no previous link and the last no next.\n *\n * @param handle Runtime handle carrying the slide's photo and position.\n * @returns The render function producing the slide's markup.\n */\nfunction LightboxSlide(handle: Handle<LightboxSlideProps>) {\n\treturn () => {\n\t\tlet { viewer, photo, index, total, initial, labels } = handle.props;\n\t\tlet hasPrevious = index > 0;\n\t\tlet hasNext = index < total - 1;\n\n\t\treturn (\n\t\t\t<figure\n\t\t\t\tid={slideId(viewer, index)}\n\t\t\t\tdata-lightbox-slide=\"\"\n\t\t\t\tdata-slot=\"lightbox-slide\"\n\t\t\t\tmix={[\n\t\t\t\t\traw({\n\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\tflex: \"0 0 100%\",\n\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\tgridTemplateRows: \"minmax(0, 1fr) auto\",\n\t\t\t\t\t\tgap: \"0.75rem\",\n\t\t\t\t\t\tmargin: 0,\n\t\t\t\t\t\tpaddingBlock: \"4rem 1rem\",\n\t\t\t\t\t\tscrollSnapAlign: \"center\",\n\t\t\t\t\t\tminInlineSize: 0,\n\t\t\t\t\t}),\n\t\t\t\t\tinitial ? raw({ scrollInitialTarget: \"nearest\" } as never) : undefined,\n\t\t\t\t\tat(GUTTER_WIDTH, CONTAINER_NAME, raw({ paddingInline: \"4.5rem\" })),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{photo.art === undefined ? (\n\t\t\t\t\t<img\n\t\t\t\t\t\tsrc={photo.src}\n\t\t\t\t\t\tsrcset={photo.srcset}\n\t\t\t\t\t\talt={photo.alt}\n\t\t\t\t\t\tloading={initial ? \"eager\" : \"lazy\"}\n\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tinlineSize: \"100%\",\n\t\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\t\tminBlockSize: 0,\n\t\t\t\t\t\t\t\tobjectFit: \"contain\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]}\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\taria-label={photo.alt}\n\t\t\t\t\t\tdata-slot=\"lightbox-art\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\t\tplaceItems: \"center\",\n\t\t\t\t\t\t\t\tminBlockSize: 0,\n\t\t\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\twhen(\"& > svg\", raw({ inlineSize: \"100%\", blockSize: \"100%\" })),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{photo.art}\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<figcaption\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tgap: \"0.75rem\",\n\t\t\t\t\t\t\talignItems: \"baseline\",\n\t\t\t\t\t\t\tjustifyContent: \"center\",\n\t\t\t\t\t\t\tflexWrap: \"wrap\",\n\t\t\t\t\t\t\tpaddingInline: \"1rem\",\n\t\t\t\t\t\t\tfontSize: \"0.875rem\",\n\t\t\t\t\t\t\tlineHeight: 1.4,\n\t\t\t\t\t\t\ttextAlign: \"center\",\n\t\t\t\t\t\t\tcolor: \"rgb(255 255 255 / 0.86)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-lightbox-announce=\"\"\n\t\t\t\t\t\tdata-slot=\"lightbox-counter\"\n\t\t\t\t\t\tmix={[tabularNums(), raw({ color: \"rgb(255 255 255 / 0.6)\" })]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{`${index + 1} / ${total}`}\n\t\t\t\t\t</span>\n\t\t\t\t\t{photo.caption === undefined ? null : (\n\t\t\t\t\t\t<span data-lightbox-announce=\"\" data-slot=\"lightbox-caption\">\n\t\t\t\t\t\t\t{photo.caption}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t)}\n\t\t\t\t</figcaption>\n\t\t\t\t{hasPrevious ? (\n\t\t\t\t\t<LightboxStep\n\t\t\t\t\t\thref={`#${slideId(viewer, index - 1)}`}\n\t\t\t\t\t\tto={index - 1}\n\t\t\t\t\t\tlabel={labels.previous}\n\t\t\t\t\t\tside=\"start\"\n\t\t\t\t\t/>\n\t\t\t\t) : null}\n\t\t\t\t{hasNext ? (\n\t\t\t\t\t<LightboxStep\n\t\t\t\t\t\thref={`#${slideId(viewer, index + 1)}`}\n\t\t\t\t\t\tto={index + 1}\n\t\t\t\t\t\tlabel={labels.next}\n\t\t\t\t\t\tside=\"end\"\n\t\t\t\t\t/>\n\t\t\t\t) : null}\n\t\t\t</figure>\n\t\t);\n\t};\n}\n\n/** Props {@link LightboxStep} reads. */\ninterface LightboxStepProps {\n\thref: string;\n\tto: number;\n\tlabel: string;\n\tside: \"start\" | \"end\";\n}\n\n/**\n * A round link to a neighbouring photo, centred on the slide's edge: over the photo on a\n * phone, in the slide's own gutter once the viewer is wide. The chevron mirrors under RTL.\n *\n * @param handle Runtime handle carrying the link's target and side.\n * @returns The render function producing the link's markup.\n */\nfunction LightboxStep(handle: Handle<LightboxStepProps>) {\n\treturn () => {\n\t\tlet { href, to, label, side } = handle.props;\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\thref={href}\n\t\t\t\taria-label={label}\n\t\t\t\tdata-lightbox-to={String(to)}\n\t\t\t\tdata-slot={side === \"start\" ? \"lightbox-previous\" : \"lightbox-next\"}\n\t\t\t\tmix={[\n\t\t\t\t\tCONTROL_STYLES,\n\t\t\t\t\traw({\n\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\tinsetBlockStart: \"50%\",\n\t\t\t\t\t\ttranslate: \"0 -50%\",\n\t\t\t\t\t\t[side === \"start\" ? \"insetInlineStart\" : \"insetInlineEnd\"]: \"0.5rem\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\":dir(rtl) > &\", raw({ scale: \"-1 1\" })),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"white\", offset: 2, width: 2 })),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{side === \"start\" ? <ChevronLeftIcon size={22} /> : <ChevronRightIcon size={22} />}\n\t\t\t</a>\n\t\t);\n\t};\n}\n\n/**\n * Renders a button that opens the viewer named by `lightbox` as a modal, at photo `index`\n * once the island has loaded. It is unstyled apart from a focus ring, so a thumbnail or a\n * \"Show all photos\" label inside it sets its look.\n *\n * @param handle Runtime handle carrying the button's props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <Lightbox.Trigger lightbox=\"cabin-photos\" index={3} aria-label=\"Open photo 4\"><img src={thumb} alt=\"\" /></Lightbox.Trigger>\n */\nLightbox.Trigger = function LightboxTrigger(handle: Handle<Lightbox.TriggerProps>) {\n\treturn () => {\n\t\tlet { lightbox, index, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\t{...rest}\n\t\t\t\tcommandfor={lightbox}\n\t\t\t\tcommand=\"show-modal\"\n\t\t\t\tdata-lightbox-index={String(index ?? 0)}\n\t\t\t\tdata-slot=\"lightbox-trigger\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\tpadding: 0,\n\t\t\t\t\t\t\tborder: 0,\n\t\t\t\t\t\t\tbackground: \"none\",\n\t\t\t\t\t\t\tcolor: \"inherit\",\n\t\t\t\t\t\t\tfont: \"inherit\",\n\t\t\t\t\t\t\ttextAlign: \"inherit\",\n\t\t\t\t\t\t\tcursor: \"zoom-in\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2, width: 2 })),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
11
+ "content": "/**\n * A full-screen photo viewer for a gallery, as a native `<dialog>` a trigger opens through\n * Invoker Commands. Every photo sits in a scroll-snap track with its own address, so swiping\n * and the step links work without script; a small island adds arrow keys and opening at a photo.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon, XIcon } from \"@sdxc/icons\";\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { outline } from \"@sdxc/u/color\";\nimport { raw, mergeMix } from \"@sdxc/u/general\";\nimport { container } from \"@sdxc/u/layout\";\nimport { at, motionReduce, motionSafe, startingStyle } from \"@sdxc/u/responsive\";\nimport { when } from \"@sdxc/u/state\";\nimport { tabularNums } from \"@sdxc/u/typography\";\nimport { clientEntry } from \"remix/component\";\n\nimport { lightboxControls } from \"@sdxc/ui/mixins\";\n\n/** Container the viewer names, so its step buttons move beside the photo once there is room. */\nconst CONTAINER_NAME = \"ui-lightbox\";\n\n/** Width from which the step buttons sit in their own gutters instead of over the photo. */\nconst GUTTER_WIDTH = \"48rem\";\n\n/** Words the controls are named by when `labels` leaves them out. */\nconst DEFAULT_LABELS: Lightbox.Labels = {\n\tclose: \"Close\",\n\tprevious: \"Previous photo\",\n\tnext: \"Next photo\",\n};\n\n/** The round, 44px control shared by the close button and the step links. */\nconst CONTROL_STYLES = raw({\n\tdisplay: \"inline-grid\",\n\tplaceItems: \"center\",\n\tinlineSize: \"2.75rem\",\n\tblockSize: \"2.75rem\",\n\tpadding: 0,\n\tborder: 0,\n\tborderRadius: \"999px\",\n\tbackground: \"rgb(0 0 0 / 0.55)\",\n\tcolor: \"white\",\n\tcursor: \"pointer\",\n\ttextDecoration: \"none\",\n\tzIndex: 1,\n});\n\n/**\n * Prop types for {@link Lightbox} and its compound parts.\n */\nexport namespace Lightbox {\n\t/** One photo in the gallery. */\n\texport interface Photo {\n\t\t/** The image's address; leave it out to draw the photo with `art` instead. */\n\t\tsrc?: string;\n\t\t/** Candidate sources, as the native `srcset`. */\n\t\tsrcset?: string;\n\t\t/** What the photo shows, for a reader who cannot see it. */\n\t\talt: string;\n\t\t/** A line under the photo, such as the room it shows. */\n\t\tcaption?: RemixNode;\n\t\t/**\n\t\t * Drawn content standing in for `src`, such as an inline SVG with a `viewBox`; it is\n\t\t * scaled to fit the viewer as an image would be.\n\t\t */\n\t\tart?: RemixNode;\n\t}\n\n\t/** The words each control is named by. */\n\texport interface Labels {\n\t\t/** @default \"Close\" */\n\t\tclose: string;\n\t\t/** @default \"Previous photo\" */\n\t\tprevious: string;\n\t\t/** @default \"Next photo\" */\n\t\tnext: string;\n\t}\n\n\t/** Every native `<dialog>` attribute, plus the gallery. */\n\texport interface Props extends Omit<TagProps<\"dialog\">, \"children\" | \"open\"> {\n\t\t/** Targeted by each trigger's `commandfor`, and the prefix of every photo's own id. */\n\t\tid: string;\n\t\t/** The gallery's name, such as \"Photos of Fern Cabin\", read when the viewer opens. */\n\t\tlabel: string;\n\t\tphotos: Photo[];\n\t\t/**\n\t\t * Renders the viewer already open at this zero-based photo, for a page whose address\n\t\t * names one (`?photo=3`). Without script it is a non-modal dialog covering the page;\n\t\t * the island reopens it as a modal.\n\t\t */\n\t\tinitial?: number;\n\t\tlabels?: Partial<Labels>;\n\t}\n\n\t/** Every native `<button>` attribute, plus the viewer and photo it opens. */\n\texport interface TriggerProps extends Omit<TagProps<\"button\">, \"commandfor\" | \"command\"> {\n\t\t/** `id` of the {@link Lightbox} this opens. */\n\t\tlightbox: string;\n\t\t/**\n\t\t * Zero-based photo the viewer opens at once the island has loaded.\n\t\t *\n\t\t * @default 0\n\t\t */\n\t\tindex?: number;\n\t}\n}\n\n/** The id of photo `index`, one-based so it reads like the counter (`photos-photo-3`). */\nfunction slideId(id: string, index: number): string {\n\treturn `${id}-photo-${index + 1}`;\n}\n\n/**\n * Loads the viewer's script: the hidden host whose mixin wires the arrow keys, the\n * index-aware triggers and the live region. It loads from `@sdxc/ui/lightbox`, which the\n * app's browser entry maps; {@link Lightbox} renders it, so a page never places it itself.\n */\nexport const LightboxControls: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/lightbox#LightboxControls\",\n\tfunction LightboxControls() {\n\t\treturn () => <span hidden mix={[lightboxControls()]} />;\n\t},\n);\n\n/**\n * Renders the viewer: a full-screen dark `<dialog>` with a close button, one slide per photo\n * (contained, with \"n / N\" and its caption) and step links between neighbours. Opened from a\n * {@link Lightbox.Trigger}; Escape and the close button dismiss it.\n *\n * @param handle Runtime handle carrying the dialog's props.\n * @returns The render function producing the viewer's markup.\n * @example\n * <Lightbox.Trigger lightbox=\"cabin-photos\" index={2}><img src={thumb} alt=\"\" /></Lightbox.Trigger>\n * <Lightbox id=\"cabin-photos\" label=\"Photos of Fern Cabin\" photos={photos} />\n * @example\n * <Lightbox id=\"cabin-photos\" label=\"Photos\" photos={photos} initial={Number(url.searchParams.get(\"photo\")) - 1} />\n */\nexport function Lightbox(handle: Handle<Lightbox.Props>) {\n\treturn () => {\n\t\tlet { id, label, photos, initial, labels, mix, ...rest } = handle.props;\n\t\tlet words = { ...DEFAULT_LABELS, ...labels };\n\t\tlet total = photos.length;\n\t\tlet start = initial === undefined ? undefined : Math.max(0, Math.min(total - 1, initial));\n\n\t\treturn (\n\t\t\t<dialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\taria-label={label}\n\t\t\t\topen={start !== undefined}\n\t\t\t\tdata-lightbox-initial={start === undefined ? undefined : String(start)}\n\t\t\t\tdata-slot=\"lightbox\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"fixed\",\n\t\t\t\t\t\t\tinset: 0,\n\t\t\t\t\t\t\tinlineSize: \"auto\",\n\t\t\t\t\t\t\tblockSize: \"auto\",\n\t\t\t\t\t\t\tmaxInlineSize: \"none\",\n\t\t\t\t\t\t\tmaxBlockSize: \"none\",\n\t\t\t\t\t\t\tmargin: 0,\n\t\t\t\t\t\t\tpadding: 0,\n\t\t\t\t\t\t\tborder: 0,\n\t\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\t\tbackground: \"rgb(12 12 14)\",\n\t\t\t\t\t\t\tcolor: \"white\",\n\t\t\t\t\t\t\tcolorScheme: \"dark\",\n\t\t\t\t\t\t\tzIndex: 50,\n\t\t\t\t\t\t\topacity: 1,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcontainer(CONTAINER_NAME, \"inline-size\"),\n\t\t\t\t\t\twhen(\"&[open]\", raw({ display: \"block\" })),\n\t\t\t\t\t\twhen(\"&::backdrop\", raw({ background: \"rgb(0 0 0 / 0.9)\" })),\n\t\t\t\t\t\tmotionSafe([\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\ttransition:\n\t\t\t\t\t\t\t\t\t\"opacity 160ms ease-out, display 160ms allow-discrete, overlay 160ms allow-discrete\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tstartingStyle(when(\"&[open]\", raw({ opacity: 0 }))),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<LightboxControls />\n\t\t\t\t<button\n\t\t\t\t\ttype=\"button\"\n\t\t\t\t\tcommandfor={id}\n\t\t\t\t\tcommand=\"close\"\n\t\t\t\t\taria-label={words.close}\n\t\t\t\t\tdata-slot=\"lightbox-close\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tCONTROL_STYLES,\n\t\t\t\t\t\traw({ position: \"absolute\", insetBlockStart: \"0.75rem\", insetInlineEnd: \"0.75rem\" }),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"white\", offset: 2, width: 2 })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<XIcon size={20} />\n\t\t\t\t</button>\n\t\t\t\t<p role=\"status\" data-lightbox-status=\"\" mix={[visuallyHidden()]} />\n\t\t\t\t<div\n\t\t\t\t\tdata-lightbox-track=\"\"\n\t\t\t\t\tdata-slot=\"lightbox-track\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\toverflowX: \"auto\",\n\t\t\t\t\t\t\toverflowY: \"hidden\",\n\t\t\t\t\t\t\tscrollSnapType: \"x mandatory\",\n\t\t\t\t\t\t\toverscrollBehaviorX: \"contain\",\n\t\t\t\t\t\t\tscrollbarWidth: \"none\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\"&::-webkit-scrollbar\", raw({ display: \"none\" })),\n\t\t\t\t\t\tmotionSafe(raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\t\tmotionReduce(raw({ scrollBehavior: \"auto\" })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{photos.map((photo, index) => (\n\t\t\t\t\t\t<LightboxSlide\n\t\t\t\t\t\t\tviewer={id}\n\t\t\t\t\t\t\tphoto={photo}\n\t\t\t\t\t\t\tindex={index}\n\t\t\t\t\t\t\ttotal={total}\n\t\t\t\t\t\t\tinitial={index === start}\n\t\t\t\t\t\t\tlabels={words}\n\t\t\t\t\t\t/>\n\t\t\t\t\t))}\n\t\t\t\t</div>\n\t\t\t</dialog>\n\t\t);\n\t};\n}\n\n/** Props {@link LightboxSlide} reads. */\ninterface LightboxSlideProps {\n\tviewer: string;\n\tphoto: Lightbox.Photo;\n\tindex: number;\n\ttotal: number;\n\t/** Whether the server opened the viewer here, which snaps the track to it on first paint. */\n\tinitial: boolean;\n\tlabels: Lightbox.Labels;\n}\n\n/**\n * One photo filling the track: the picture contained in the space above its counter and\n * caption, with a link to each neighbour that addresses it by id. On a narrow viewer the\n * counter keeps its own line, so the photo's space stays the same from slide to slide.\n *\n * @param handle Runtime handle carrying the slide's photo and position.\n * @returns The render function producing the slide's markup.\n */\nfunction LightboxSlide(handle: Handle<LightboxSlideProps>) {\n\treturn () => {\n\t\tlet { viewer, photo, index, total, initial, labels } = handle.props;\n\t\tlet hasPrevious = index > 0;\n\t\tlet hasNext = index < total - 1;\n\n\t\treturn (\n\t\t\t<figure\n\t\t\t\tid={slideId(viewer, index)}\n\t\t\t\tdata-lightbox-slide=\"\"\n\t\t\t\tdata-slot=\"lightbox-slide\"\n\t\t\t\tmix={[\n\t\t\t\t\traw({\n\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\tflex: \"0 0 100%\",\n\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\tgridTemplateRows: \"minmax(0, 1fr) auto\",\n\t\t\t\t\t\tgap: \"0.75rem\",\n\t\t\t\t\t\tmargin: 0,\n\t\t\t\t\t\tpaddingBlock: \"4rem 1rem\",\n\t\t\t\t\t\tscrollSnapAlign: \"center\",\n\t\t\t\t\t\tminInlineSize: 0,\n\t\t\t\t\t}),\n\t\t\t\t\tinitial ? raw({ scrollInitialTarget: \"nearest\" } as never) : undefined,\n\t\t\t\t\tat(GUTTER_WIDTH, CONTAINER_NAME, raw({ paddingInline: \"4.5rem\" })),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{photo.art === undefined ? (\n\t\t\t\t\t<img\n\t\t\t\t\t\tsrc={photo.src}\n\t\t\t\t\t\tsrcset={photo.srcset}\n\t\t\t\t\t\talt={photo.alt}\n\t\t\t\t\t\tloading={initial ? \"eager\" : \"lazy\"}\n\t\t\t\t\t\tdecoding=\"async\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tinlineSize: \"100%\",\n\t\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\t\tminBlockSize: 0,\n\t\t\t\t\t\t\t\tobjectFit: \"contain\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]}\n\t\t\t\t\t/>\n\t\t\t\t) : (\n\t\t\t\t\t<div\n\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\taria-label={photo.alt}\n\t\t\t\t\t\tdata-slot=\"lightbox-art\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\t\tplaceItems: \"center\",\n\t\t\t\t\t\t\t\tminBlockSize: 0,\n\t\t\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\twhen(\"& > svg\", raw({ inlineSize: \"100%\", blockSize: \"100%\" })),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{photo.art}\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<figcaption\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tflexDirection: \"column\",\n\t\t\t\t\t\t\tgap: \"0.25rem\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tpaddingInline: \"1rem\",\n\t\t\t\t\t\t\tfontSize: \"0.875rem\",\n\t\t\t\t\t\t\tlineHeight: 1.4,\n\t\t\t\t\t\t\ttextAlign: \"center\",\n\t\t\t\t\t\t\tcolor: \"rgb(255 255 255 / 0.86)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tat(\n\t\t\t\t\t\t\tGUTTER_WIDTH,\n\t\t\t\t\t\t\tCONTAINER_NAME,\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tflexDirection: \"row\",\n\t\t\t\t\t\t\t\tflexWrap: \"wrap\",\n\t\t\t\t\t\t\t\tgap: \"0.75rem\",\n\t\t\t\t\t\t\t\talignItems: \"baseline\",\n\t\t\t\t\t\t\t\tjustifyContent: \"center\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-lightbox-announce=\"\"\n\t\t\t\t\t\tdata-slot=\"lightbox-counter\"\n\t\t\t\t\t\tmix={[tabularNums(), raw({ color: \"rgb(255 255 255 / 0.6)\" })]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{`${index + 1} / ${total}`}\n\t\t\t\t\t</span>\n\t\t\t\t\t{photo.caption === undefined ? null : (\n\t\t\t\t\t\t<span data-lightbox-announce=\"\" data-slot=\"lightbox-caption\">\n\t\t\t\t\t\t\t{photo.caption}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t)}\n\t\t\t\t</figcaption>\n\t\t\t\t{hasPrevious ? (\n\t\t\t\t\t<LightboxStep\n\t\t\t\t\t\thref={`#${slideId(viewer, index - 1)}`}\n\t\t\t\t\t\tto={index - 1}\n\t\t\t\t\t\tlabel={labels.previous}\n\t\t\t\t\t\tside=\"start\"\n\t\t\t\t\t/>\n\t\t\t\t) : null}\n\t\t\t\t{hasNext ? (\n\t\t\t\t\t<LightboxStep\n\t\t\t\t\t\thref={`#${slideId(viewer, index + 1)}`}\n\t\t\t\t\t\tto={index + 1}\n\t\t\t\t\t\tlabel={labels.next}\n\t\t\t\t\t\tside=\"end\"\n\t\t\t\t\t/>\n\t\t\t\t) : null}\n\t\t\t</figure>\n\t\t);\n\t};\n}\n\n/** Props {@link LightboxStep} reads. */\ninterface LightboxStepProps {\n\thref: string;\n\tto: number;\n\tlabel: string;\n\tside: \"start\" | \"end\";\n}\n\n/**\n * A round link to a neighbouring photo, centred on the slide's edge: over the photo on a\n * phone, in the slide's own gutter once the viewer is wide. The chevron mirrors under RTL.\n *\n * @param handle Runtime handle carrying the link's target and side.\n * @returns The render function producing the link's markup.\n */\nfunction LightboxStep(handle: Handle<LightboxStepProps>) {\n\treturn () => {\n\t\tlet { href, to, label, side } = handle.props;\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\thref={href}\n\t\t\t\taria-label={label}\n\t\t\t\tdata-lightbox-to={String(to)}\n\t\t\t\tdata-slot={side === \"start\" ? \"lightbox-previous\" : \"lightbox-next\"}\n\t\t\t\tmix={[\n\t\t\t\t\tCONTROL_STYLES,\n\t\t\t\t\traw({\n\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\tinsetBlockStart: \"50%\",\n\t\t\t\t\t\ttranslate: \"0 -50%\",\n\t\t\t\t\t\t[side === \"start\" ? \"insetInlineStart\" : \"insetInlineEnd\"]: \"0.5rem\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\":dir(rtl) > &\", raw({ scale: \"-1 1\" })),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"white\", offset: 2, width: 2 })),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{side === \"start\" ? <ChevronLeftIcon size={22} /> : <ChevronRightIcon size={22} />}\n\t\t\t</a>\n\t\t);\n\t};\n}\n\n/**\n * Renders a button that opens the viewer named by `lightbox` as a modal, at photo `index`\n * once the island has loaded. It is unstyled apart from a focus ring, so a thumbnail or a\n * \"Show all photos\" label inside it sets its look.\n *\n * @param handle Runtime handle carrying the button's props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <Lightbox.Trigger lightbox=\"cabin-photos\" index={3} aria-label=\"Open photo 4\"><img src={thumb} alt=\"\" /></Lightbox.Trigger>\n */\nLightbox.Trigger = function LightboxTrigger(handle: Handle<Lightbox.TriggerProps>) {\n\treturn () => {\n\t\tlet { lightbox, index, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\t{...rest}\n\t\t\t\tcommandfor={lightbox}\n\t\t\t\tcommand=\"show-modal\"\n\t\t\t\tdata-lightbox-index={String(index ?? 0)}\n\t\t\t\tdata-slot=\"lightbox-trigger\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\tpadding: 0,\n\t\t\t\t\t\t\tborder: 0,\n\t\t\t\t\t\t\tbackground: \"none\",\n\t\t\t\t\t\t\tcolor: \"inherit\",\n\t\t\t\t\t\t\tfont: \"inherit\",\n\t\t\t\t\t\t\ttextAlign: \"inherit\",\n\t\t\t\t\t\t\tcursor: \"zoom-in\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2, width: 2 })),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
12
12
  },
13
13
  "test": {
14
14
  "path": "lightbox.browser.test.tsx",
15
- "content": "/**\n * Opens `Lightbox` in a real browser: a trigger opens it as a true modal at the photo it\n * names, arrow keys step through the photos and the announced counter follows, the step\n * links address each neighbour by id, the close button dismisses it, and nothing overflows.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { page } from \"vitest/browser\";\n\nimport { Lightbox } from \"@sdxc/ui/lightbox\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** Three drawn photos of a cabin stay. */\nconst PHOTOS: Lightbox.Photo[] = [\n\t{ alt: \"The cabin at dusk\", caption: \"Outside\", art: <svg viewBox=\"0 0 4 3\" /> },\n\t{ alt: \"The wood stove\", caption: \"Living room\", art: <svg viewBox=\"0 0 4 3\" /> },\n\t{ alt: \"A loft bed\", art: <svg viewBox=\"0 0 4 3\" /> },\n];\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts two triggers and the viewer, waits for the island, and returns the parts. */\nasync function mount(initial?: number) {\n\tmounted = render(\n\t\t<div>\n\t\t\t<Lightbox.Trigger lightbox=\"photos\">Show all photos</Lightbox.Trigger>\n\t\t\t<Lightbox.Trigger lightbox=\"photos\" index={2}>\n\t\t\t\tLoft\n\t\t\t</Lightbox.Trigger>\n\t\t\t<Lightbox id=\"photos\" label=\"Photos of Fern Cabin\" photos={PHOTOS} initial={initial} />\n\t\t</div>,\n\t);\n\tawait new Promise((resolve) => requestAnimationFrame(resolve));\n\tawait new Promise((resolve) => setTimeout(resolve, 0));\n\tlet root = mounted.container;\n\tlet triggers = [...root.querySelectorAll<HTMLButtonElement>(\"[data-slot=lightbox-trigger]\")];\n\treturn {\n\t\tdialog: root.querySelector<HTMLDialogElement>(\"dialog\")!,\n\t\ttriggers,\n\t\ttrack: root.querySelector<HTMLElement>(\"[data-lightbox-track]\")!,\n\t\tstatus: root.querySelector<HTMLElement>(\"[data-lightbox-status]\")!,\n\t};\n}\n\n/** The counter of the slide the script marks as in view. */\nfunction currentCounter(dialog: HTMLDialogElement): string | null | undefined {\n\treturn dialog.querySelector(\"[data-current] [data-slot=lightbox-counter]\")?.textContent;\n}\n\ndescribe(\"Lightbox\", () => {\n\ttest(\"a trigger opens it as a modal at the photo it names, instantly\", async () => {\n\t\tlet { dialog, triggers, track, status } = await mount();\n\t\texpect(dialog.open).toBe(false);\n\t\texpect(dialog.getAttribute(\"aria-label\")).toBe(\"Photos of Fern Cabin\");\n\n\t\ttriggers[1]!.click();\n\t\texpect(dialog.matches(\":modal\")).toBe(true);\n\t\texpect(Math.round(track.scrollLeft)).toBe(track.clientWidth * 2);\n\t\texpect(currentCounter(dialog)).toBe(\"3 / 3\");\n\t\texpect(status.textContent).toBe(\"3 / 3\");\n\t});\n\n\ttest(\"arrow keys step through the photos and the counter follows\", async () => {\n\t\tlet { dialog, triggers, status } = await mount();\n\t\ttriggers[0]!.click();\n\t\texpect(currentCounter(dialog)).toBe(\"1 / 3\");\n\t\texpect(status.textContent).toBe(\"1 / 3. Outside\");\n\n\t\tdialog.dispatchEvent(new KeyboardEvent(\"keydown\", { key: \"ArrowRight\", bubbles: true }));\n\t\tawait expect.poll(() => currentCounter(dialog)).toBe(\"2 / 3\");\n\t\texpect(status.textContent).toBe(\"2 / 3. Living room\");\n\n\t\tdialog.dispatchEvent(new KeyboardEvent(\"keydown\", { key: \"ArrowLeft\", bubbles: true }));\n\t\tawait expect.poll(() => currentCounter(dialog)).toBe(\"1 / 3\");\n\t});\n\n\ttest(\"step links address each neighbour by id, and the ends have none\", async () => {\n\t\tlet { dialog } = await mount();\n\t\tlet slides = [...dialog.querySelectorAll<HTMLElement>(\"[data-lightbox-slide]\")];\n\t\texpect(slides.map((slide) => slide.id)).toEqual([\n\t\t\t\"photos-photo-1\",\n\t\t\t\"photos-photo-2\",\n\t\t\t\"photos-photo-3\",\n\t\t]);\n\t\tlet hrefs = slides.map((slide) =>\n\t\t\t[...slide.querySelectorAll(\"a\")].map((link) => link.getAttribute(\"href\")),\n\t\t);\n\t\texpect(hrefs).toEqual([\n\t\t\t[\"#photos-photo-2\"],\n\t\t\t[\"#photos-photo-1\", \"#photos-photo-3\"],\n\t\t\t[\"#photos-photo-2\"],\n\t\t]);\n\t\texpect(slides[1]!.querySelector(\"a\")!.getAttribute(\"aria-label\")).toBe(\"Previous photo\");\n\t});\n\n\ttest(\"a step link scrolls in place without changing the address\", async () => {\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tlet before = location.hash;\n\t\tdialog.querySelector<HTMLAnchorElement>(\"#photos-photo-1 a\")!.click();\n\t\tawait expect.poll(() => currentCounter(dialog)).toBe(\"2 / 3\");\n\t\texpect(location.hash).toBe(before);\n\t});\n\n\ttest(\"the close button closes it\", async () => {\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tdialog.querySelector<HTMLButtonElement>(\"[data-slot=lightbox-close]\")!.click();\n\t\texpect(dialog.open).toBe(false);\n\t});\n\n\ttest(\"a server-opened viewer is upgraded to a modal at its initial photo\", async () => {\n\t\tlet { dialog } = await mount(1);\n\t\texpect(dialog.matches(\":modal\")).toBe(true);\n\t\texpect(currentCounter(dialog)).toBe(\"2 / 3\");\n\t});\n\n\ttest(\"fills a 320px screen without overflowing, with 44px controls\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tlet box = dialog.getBoundingClientRect();\n\t\texpect(box.left).toBe(0);\n\t\texpect(box.width).toBe(320);\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\tfor (let control of dialog.querySelectorAll(\"[data-slot=lightbox-close], a\")) {\n\t\t\tlet rect = control.getBoundingClientRect();\n\t\t\texpect(rect.width).toBe(44);\n\t\t\texpect(rect.height).toBe(44);\n\t\t}\n\t});\n});\n"
15
+ "content": "/**\n * Opens `Lightbox` in a real browser: a trigger opens it as a true modal at the photo it\n * names, arrow keys step through the photos and the announced counter follows, the step\n * links address each neighbour by id, the close button dismisses it, nothing overflows, and\n * a phone keeps the counter on its own line.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { page } from \"vitest/browser\";\n\nimport { Lightbox } from \"@sdxc/ui/lightbox\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** Three drawn photos of a cabin stay. */\nconst PHOTOS: Lightbox.Photo[] = [\n\t{ alt: \"The cabin at dusk\", caption: \"Outside\", art: <svg viewBox=\"0 0 4 3\" /> },\n\t{ alt: \"The wood stove\", caption: \"Living room\", art: <svg viewBox=\"0 0 4 3\" /> },\n\t{ alt: \"A loft bed\", art: <svg viewBox=\"0 0 4 3\" /> },\n];\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts two triggers and the viewer, waits for the island, and returns the parts. */\nasync function mount(initial?: number) {\n\tmounted = render(\n\t\t<div>\n\t\t\t<Lightbox.Trigger lightbox=\"photos\">Show all photos</Lightbox.Trigger>\n\t\t\t<Lightbox.Trigger lightbox=\"photos\" index={2}>\n\t\t\t\tLoft\n\t\t\t</Lightbox.Trigger>\n\t\t\t<Lightbox id=\"photos\" label=\"Photos of Fern Cabin\" photos={PHOTOS} initial={initial} />\n\t\t</div>,\n\t);\n\tawait new Promise((resolve) => requestAnimationFrame(resolve));\n\tawait new Promise((resolve) => setTimeout(resolve, 0));\n\tlet root = mounted.container;\n\tlet triggers = [...root.querySelectorAll<HTMLButtonElement>(\"[data-slot=lightbox-trigger]\")];\n\treturn {\n\t\tdialog: root.querySelector<HTMLDialogElement>(\"dialog\")!,\n\t\ttriggers,\n\t\ttrack: root.querySelector<HTMLElement>(\"[data-lightbox-track]\")!,\n\t\tstatus: root.querySelector<HTMLElement>(\"[data-lightbox-status]\")!,\n\t};\n}\n\n/** The counter of the slide the script marks as in view. */\nfunction currentCounter(dialog: HTMLDialogElement): string | null | undefined {\n\treturn dialog.querySelector(\"[data-current] [data-slot=lightbox-counter]\")?.textContent;\n}\n\ndescribe(\"Lightbox\", () => {\n\ttest(\"a trigger opens it as a modal at the photo it names, instantly\", async () => {\n\t\tlet { dialog, triggers, track, status } = await mount();\n\t\texpect(dialog.open).toBe(false);\n\t\texpect(dialog.getAttribute(\"aria-label\")).toBe(\"Photos of Fern Cabin\");\n\n\t\ttriggers[1]!.click();\n\t\texpect(dialog.matches(\":modal\")).toBe(true);\n\t\texpect(Math.round(track.scrollLeft)).toBe(track.clientWidth * 2);\n\t\texpect(currentCounter(dialog)).toBe(\"3 / 3\");\n\t\texpect(status.textContent).toBe(\"3 / 3\");\n\t});\n\n\ttest(\"arrow keys step through the photos and the counter follows\", async () => {\n\t\tlet { dialog, triggers, status } = await mount();\n\t\ttriggers[0]!.click();\n\t\texpect(currentCounter(dialog)).toBe(\"1 / 3\");\n\t\texpect(status.textContent).toBe(\"1 / 3. Outside\");\n\n\t\tdialog.dispatchEvent(new KeyboardEvent(\"keydown\", { key: \"ArrowRight\", bubbles: true }));\n\t\tawait expect.poll(() => currentCounter(dialog)).toBe(\"2 / 3\");\n\t\texpect(status.textContent).toBe(\"2 / 3. Living room\");\n\n\t\tdialog.dispatchEvent(new KeyboardEvent(\"keydown\", { key: \"ArrowLeft\", bubbles: true }));\n\t\tawait expect.poll(() => currentCounter(dialog)).toBe(\"1 / 3\");\n\t});\n\n\ttest(\"step links address each neighbour by id, and the ends have none\", async () => {\n\t\tlet { dialog } = await mount();\n\t\tlet slides = [...dialog.querySelectorAll<HTMLElement>(\"[data-lightbox-slide]\")];\n\t\texpect(slides.map((slide) => slide.id)).toEqual([\n\t\t\t\"photos-photo-1\",\n\t\t\t\"photos-photo-2\",\n\t\t\t\"photos-photo-3\",\n\t\t]);\n\t\tlet hrefs = slides.map((slide) =>\n\t\t\t[...slide.querySelectorAll(\"a\")].map((link) => link.getAttribute(\"href\")),\n\t\t);\n\t\texpect(hrefs).toEqual([\n\t\t\t[\"#photos-photo-2\"],\n\t\t\t[\"#photos-photo-1\", \"#photos-photo-3\"],\n\t\t\t[\"#photos-photo-2\"],\n\t\t]);\n\t\texpect(slides[1]!.querySelector(\"a\")!.getAttribute(\"aria-label\")).toBe(\"Previous photo\");\n\t});\n\n\ttest(\"a step link scrolls in place without changing the address\", async () => {\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tlet before = location.hash;\n\t\tdialog.querySelector<HTMLAnchorElement>(\"#photos-photo-1 a\")!.click();\n\t\tawait expect.poll(() => currentCounter(dialog)).toBe(\"2 / 3\");\n\t\texpect(location.hash).toBe(before);\n\t});\n\n\ttest(\"the close button closes it\", async () => {\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tdialog.querySelector<HTMLButtonElement>(\"[data-slot=lightbox-close]\")!.click();\n\t\texpect(dialog.open).toBe(false);\n\t});\n\n\ttest(\"a server-opened viewer is upgraded to a modal at its initial photo\", async () => {\n\t\tlet { dialog } = await mount(1);\n\t\texpect(dialog.matches(\":modal\")).toBe(true);\n\t\texpect(currentCounter(dialog)).toBe(\"2 / 3\");\n\t});\n\n\ttest(\"fills a 320px screen without overflowing, with 44px controls\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tlet box = dialog.getBoundingClientRect();\n\t\texpect(box.left).toBe(0);\n\t\texpect(box.width).toBe(320);\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\tfor (let control of dialog.querySelectorAll(\"[data-slot=lightbox-close], a\")) {\n\t\t\tlet rect = control.getBoundingClientRect();\n\t\t\texpect(rect.width).toBe(44);\n\t\t\texpect(rect.height).toBe(44);\n\t\t}\n\t});\n\n\ttest(\"keeps the counter on its own line on a phone, whatever the caption's length\", async () => {\n\t\tawait page.viewport(390, 640);\n\t\tlet { dialog, triggers } = await mount();\n\t\ttriggers[0]!.click();\n\t\tfor (let slide of dialog.querySelectorAll(\"[data-slot=lightbox-slide]\")) {\n\t\t\tlet counter = slide.querySelector(\"[data-slot=lightbox-counter]\")!.getBoundingClientRect();\n\t\t\tlet caption = slide.querySelector(\"[data-slot=lightbox-caption]\")?.getBoundingClientRect();\n\t\t\tif (caption) expect(caption.top).toBeGreaterThanOrEqual(counter.bottom);\n\t\t}\n\t});\n});\n"
16
16
  }
17
17
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listbox",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
5
  "sentinel-row"
6
6
  ],
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "source": {
11
11
  "path": "listbox.tsx",
12
- "content": "/**\n * A run of selectable option rows sharing one native grouping name — each\n * {@link ListBox.Item} pairs a visually hidden `<input type=\"radio\">` or\n * `<input type=\"checkbox\">` with its own visible content, so every focus,\n * keyboard, and form-submission semantic keeps coming from the platform\n * itself. The host renders as a scrollable column reading each option's\n * `:checked` and `:focus` state through a `:has()` selector to color the\n * whole row, with no selection state tracked anywhere in this module.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix } from \"@sdxc/u/general\";\nimport { flex, gap, items } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { maxBs, pb, pi } from \"@sdxc/u/size\";\nimport { active, hover, when } from \"@sdxc/u/state\";\nimport { text } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { surfaceInset } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\nimport { SentinelRow } from \"@sdxc/ui/sentinel-row\";\n\n/**\n * Default {@link ListBox.Props} selection cardinality, applied when\n * `multiple` is omitted, rendering every {@link ListBox.Item} as a native\n * `<input type=\"radio\">` limiting the group to one selected option.\n */\nconst DEFAULT_MULTIPLE = false;\n\n/**\n * Prop types for {@link ListBox} and its {@link ListBox.Item} compound part.\n */\nexport namespace ListBox {\n\t/**\n\t * Value {@link ListBox} stores in component context so every\n\t * {@link ListBox.Item} nested inside shares the same grouping name and\n\t * selection cardinality without repeating them on each option.\n\t */\n\texport interface Context {\n\t\t/** Shared `name` every {@link ListBox.Item} reads unless it sets its own. */\n\t\tname: string;\n\t\t/**\n\t\t * Whether an option's underlying input renders as a checkbox (`true`,\n\t\t * letting several options be selected at once) or a radio (`false`,\n\t\t * limiting the group to a single selected option).\n\t\t */\n\t\tmultiple: boolean;\n\t}\n\n\t/**\n\t * Props accepted by {@link ListBox}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Native grouping name shared by every {@link ListBox.Item} nested inside,\n\t\t * provided through component context. Defaults to the group's own\n\t\t * {@link Handle.id | stable instance id}, so options always group correctly.\n\t\t */\n\t\tname?: string;\n\t\t/**\n\t\t * Renders every option as a checkbox, allowing more than one selected\n\t\t * at once, instead of the default mutually exclusive radio behavior.\n\t\t * Defaults to {@link DEFAULT_MULTIPLE}.\n\t\t */\n\t\tmultiple?: boolean;\n\t}\n\n\t/**\n\t * Props accepted by {@link ListBox.Item}.\n\t */\n\texport interface ItemProps extends Omit<TagProps<\"label\">, \"children\"> {\n\t\t/** Value submitted with the enclosing form when this option is selected. */\n\t\tvalue: string;\n\t\t/**\n\t\t * Native grouping name for this option's underlying input. Defaults to\n\t\t * the name provided by the nearest ancestor {@link ListBox} — set this\n\t\t * only to opt a single option out of its group's shared name.\n\t\t */\n\t\tname?: string;\n\t\t/** Whether this option starts selected, for a form that never tracks selection itself. */\n\t\tdefaultChecked?: boolean;\n\t\t/** Whether this option is selected, for a form that tracks selection itself. */\n\t\tchecked?: boolean;\n\t\t/** Whether this option is inert and excluded from the group's tab order. */\n\t\tdisabled?: boolean;\n\t\t/**\n\t\t * Sets the underlying input's native `required` attribute. On a radio\n\t\t * input this requires at least one option in the group be selected; on\n\t\t * a checkbox input it requires this specific option be checked.\n\t\t */\n\t\trequired?: boolean;\n\t\t/** The option's visible content, associated with the input by native nesting. */\n\t\tchildren?: RemixNode;\n\t\t/**\n\t\t * Per-part styling for the option's hidden `input` element, layered\n\t\t * after its own built-in styling. Use the `mix` prop instead to style\n\t\t * the option's outer `<label>` host.\n\t\t */\n\t\tparts?: {\n\t\t\t/** Additional mixin(s) applied to the hidden native `<input>`. */\n\t\t\tinput?: TagProps<\"input\">[\"mix\"];\n\t\t};\n\t}\n\n\t/**\n\t * Props accepted by {@link ListBox.LoadMoreItem}.\n\t */\n\texport interface LoadMoreItemProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the group host: a `<div>` laying its {@link ListBox.Item} options\n * out as a scrollable column capped at a fixed block size and rounded\n * concentric with its rows, with `role` defaulting to `\"radiogroup\"` for\n * single selection or `\"group\"` for `multiple`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link ListBox.Context}.\n * @returns The render function producing the group's markup.\n * @example\n * <ListBox aria-label={t(\"settings.theme\")}>\n * \t<ListBox.Item value=\"light\" defaultChecked>{t(\"settings.themeLight\")}</ListBox.Item>\n * \t<ListBox.Item value=\"dark\">{t(\"settings.themeDark\")}</ListBox.Item>\n * \t<ListBox.Item value=\"system\">{t(\"settings.themeSystem\")}</ListBox.Item>\n * </ListBox>\n * @example\n * <ListBox aria-label={t(\"settings.notifications\")} multiple>\n * \t<Section aria-labelledby=\"notifications-heading\">\n * \t\t<Header id=\"notifications-heading\">{t(\"settings.channels\")}</Header>\n * \t\t<ListBox.Item value=\"email\" defaultChecked>{t(\"settings.email\")}</ListBox.Item>\n * \t\t<ListBox.Item value=\"sms\">{t(\"settings.sms\")}</ListBox.Item>\n * \t</Section>\n * </ListBox>\n */\nexport function ListBox(handle: Handle<ListBox.Props, ListBox.Context>) {\n\treturn () => {\n\t\tlet { name, multiple, mix, ...rest } = handle.props;\n\t\tlet resolvedName = name ?? handle.id;\n\t\tlet resolvedMultiple = multiple ?? DEFAULT_MULTIPLE;\n\n\t\thandle.context.set({ name: resolvedName, multiple: resolvedMultiple });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: resolvedMultiple ? \"group\" : \"radiogroup\" }),\n\t\t\t\t\t\tmaxBs(60),\n\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t\tsurfaceInset(),\n\t\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders a single option: a native `<label>` pairing a visually hidden\n * radio or checkbox input with the option's content. In dev mode, an\n * option with no accessible name logs a `console.warn`.\n *\n * @param handle Runtime handle carrying the host `<label>`'s props.\n * @returns The render function producing the option's markup.\n * @example\n * <ListBox.Item value=\"dog\">{t(\"pet.dog\")}</ListBox.Item>\n * @example\n * <ListBox.Item value=\"cat\" defaultChecked>{t(\"pet.cat\")}</ListBox.Item>\n * @example\n * <ListBox.Item value=\"hamster\" disabled>{t(\"pet.hamster\")}</ListBox.Item>\n */\nListBox.Item = function ListBoxItem(handle: Handle<ListBox.ItemProps>) {\n\treturn () => {\n\t\tlet {\n\t\t\tvalue,\n\t\t\tname,\n\t\t\tchecked,\n\t\t\tdefaultChecked,\n\t\t\tdisabled,\n\t\t\trequired,\n\t\t\tchildren,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet context = handle.context.get(ListBox);\n\t\tlet resolvedName = name ?? context.name;\n\t\tlet type: \"checkbox\" | \"radio\" = context.multiple ? \"checkbox\" : \"radio\";\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"ListBox.Item: an option with no visible text needs an `aria-label` describing it — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(2),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpb(2),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\twhen(\"&:has(input:focus)\", bg(\"brand.bg-tint-pressed\")),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The row the keyboard is on is where the next Enter lands, so it is shown before it is\n\t\t\t\t\t\t * chosen. The tint stops at the selected row, which keeps its stronger fill while walked past.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-highlighted=\"true\"]:not(:has(input:checked)):not([aria-selected=\"true\"])',\n\t\t\t\t\t\t\t[bg(\"brand.bg-tint-pressed\"), fg(\"brand.emphasis\")],\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen('&:has(input:checked), &[aria-selected=\"true\"]', [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&:has(input:disabled), &[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<input\n\t\t\t\t\ttype={type}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tname={resolvedName}\n\t\t\t\t\tchecked={checked}\n\t\t\t\t\tdefaultChecked={defaultChecked}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tmix={[visuallyHidden(), parts?.input]}\n\t\t\t\t/>\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n};\n\n/**\n * Renders a decorative sentinel row: a `<div>` styled as a centered, muted\n * line of small text sized to match {@link ListBox.Item}'s vertical rhythm,\n * ready to hold a loading indicator or \"load more\" trigger as `children`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the sentinel row's markup.\n * @example\n * <ListBox.LoadMoreItem>{t(\"list.loadingMore\")}</ListBox.LoadMoreItem>\n */\nListBox.LoadMoreItem = SentinelRow;\n"
12
+ "content": "/**\n * A run of selectable option rows sharing one native grouping name — each\n * {@link ListBox.Item} pairs a visually hidden `<input type=\"radio\">` or\n * `<input type=\"checkbox\">` with its own visible content, so every focus,\n * keyboard, and form-submission semantic keeps coming from the platform\n * itself. The host renders as a scrollable column reading each option's\n * `:checked` and `:focus` state through a `:has()` selector to color the\n * whole row, with no selection state tracked anywhere in this module.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix } from \"@sdxc/u/general\";\nimport { flex, gap, items } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { maxBs, pb, pi } from \"@sdxc/u/size\";\nimport { active, hover, when } from \"@sdxc/u/state\";\nimport { text } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { surfaceInset } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\nimport { SentinelRow } from \"@sdxc/ui/sentinel-row\";\n\n/**\n * Default {@link ListBox.Props} selection cardinality, applied when\n * `multiple` is omitted, rendering every {@link ListBox.Item} as a native\n * `<input type=\"radio\">` limiting the group to one selected option.\n */\nconst DEFAULT_MULTIPLE = false;\n\n/**\n * Prop types for {@link ListBox} and its {@link ListBox.Item} compound part.\n */\nexport namespace ListBox {\n\t/**\n\t * Value {@link ListBox} stores in component context so every\n\t * {@link ListBox.Item} nested inside shares the same grouping name and\n\t * selection cardinality without repeating them on each option.\n\t */\n\texport interface Context {\n\t\t/** Shared `name` every {@link ListBox.Item} reads unless it sets its own. */\n\t\tname: string;\n\t\t/**\n\t\t * Whether an option's underlying input renders as a checkbox (`true`,\n\t\t * letting several options be selected at once) or a radio (`false`,\n\t\t * limiting the group to a single selected option).\n\t\t */\n\t\tmultiple: boolean;\n\t}\n\n\t/**\n\t * Props accepted by {@link ListBox}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Native grouping name shared by every {@link ListBox.Item} nested inside,\n\t\t * provided through component context. Defaults to the group's own\n\t\t * {@link Handle.id | stable instance id}, so options always group correctly.\n\t\t */\n\t\tname?: string;\n\t\t/**\n\t\t * Renders every option as a checkbox, allowing more than one selected\n\t\t * at once, instead of the default mutually exclusive radio behavior.\n\t\t * Defaults to {@link DEFAULT_MULTIPLE}.\n\t\t */\n\t\tmultiple?: boolean;\n\t}\n\n\t/**\n\t * Props accepted by {@link ListBox.Item}.\n\t */\n\texport interface ItemProps extends Omit<TagProps<\"label\">, \"children\"> {\n\t\t/** Value submitted with the enclosing form when this option is selected. */\n\t\tvalue: string;\n\t\t/**\n\t\t * Native grouping name for this option's underlying input. Defaults to\n\t\t * the name provided by the nearest ancestor {@link ListBox} — set this\n\t\t * only to opt a single option out of its group's shared name.\n\t\t */\n\t\tname?: string;\n\t\t/** Whether this option starts selected, for a form that never tracks selection itself. */\n\t\tdefaultChecked?: boolean;\n\t\t/** Whether this option is selected, for a form that tracks selection itself. */\n\t\tchecked?: boolean;\n\t\t/** Whether this option is inert and excluded from the group's tab order. */\n\t\tdisabled?: boolean;\n\t\t/**\n\t\t * Sets the underlying input's native `required` attribute. On a radio\n\t\t * input this requires at least one option in the group be selected; on\n\t\t * a checkbox input it requires this specific option be checked.\n\t\t */\n\t\trequired?: boolean;\n\t\t/** The option's visible content, associated with the input by native nesting. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link ListBox.LoadMoreItem}.\n\t */\n\texport interface LoadMoreItemProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the group host: a `<div>` laying its {@link ListBox.Item} options\n * out as a scrollable column capped at a fixed block size and rounded\n * concentric with its rows, with `role` defaulting to `\"radiogroup\"` for\n * single selection or `\"group\"` for `multiple`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link ListBox.Context}.\n * @returns The render function producing the group's markup.\n * @example\n * <ListBox aria-label={t(\"settings.theme\")}>\n * \t<ListBox.Item value=\"light\" defaultChecked>{t(\"settings.themeLight\")}</ListBox.Item>\n * \t<ListBox.Item value=\"dark\">{t(\"settings.themeDark\")}</ListBox.Item>\n * \t<ListBox.Item value=\"system\">{t(\"settings.themeSystem\")}</ListBox.Item>\n * </ListBox>\n * @example\n * <ListBox aria-label={t(\"settings.notifications\")} multiple>\n * \t<Section aria-labelledby=\"notifications-heading\">\n * \t\t<Header id=\"notifications-heading\">{t(\"settings.channels\")}</Header>\n * \t\t<ListBox.Item value=\"email\" defaultChecked>{t(\"settings.email\")}</ListBox.Item>\n * \t\t<ListBox.Item value=\"sms\">{t(\"settings.sms\")}</ListBox.Item>\n * \t</Section>\n * </ListBox>\n */\nexport function ListBox(handle: Handle<ListBox.Props, ListBox.Context>) {\n\treturn () => {\n\t\tlet { name, multiple, mix, ...rest } = handle.props;\n\t\tlet resolvedName = name ?? handle.id;\n\t\tlet resolvedMultiple = multiple ?? DEFAULT_MULTIPLE;\n\n\t\thandle.context.set({ name: resolvedName, multiple: resolvedMultiple });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: resolvedMultiple ? \"group\" : \"radiogroup\" }),\n\t\t\t\t\t\tmaxBs(60),\n\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t\tsurfaceInset(),\n\t\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders a single option: a native `<label>` pairing a visually hidden\n * radio or checkbox input with the option's content. In dev mode, an\n * option with no accessible name logs a `console.warn`.\n *\n * @param handle Runtime handle carrying the host `<label>`'s props.\n * @returns The render function producing the option's markup.\n * @example\n * <ListBox.Item value=\"dog\">{t(\"pet.dog\")}</ListBox.Item>\n * @example\n * <ListBox.Item value=\"cat\" defaultChecked>{t(\"pet.cat\")}</ListBox.Item>\n * @example\n * <ListBox.Item value=\"hamster\" disabled>{t(\"pet.hamster\")}</ListBox.Item>\n */\nListBox.Item = function ListBoxItem(handle: Handle<ListBox.ItemProps>) {\n\treturn () => {\n\t\tlet { value, name, checked, defaultChecked, disabled, required, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet context = handle.context.get(ListBox);\n\t\tlet resolvedName = name ?? context.name;\n\t\tlet type: \"checkbox\" | \"radio\" = context.multiple ? \"checkbox\" : \"radio\";\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"ListBox.Item: an option with no visible text needs an `aria-label` describing it — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(2),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpb(2),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\twhen(\"&:has(input:focus)\", bg(\"brand.bg-tint-pressed\")),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The row the keyboard is on is where the next Enter lands, so it is shown before it is\n\t\t\t\t\t\t * chosen. The tint stops at the selected row, which keeps its stronger fill while walked past.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-highlighted=\"true\"]:not(:has(input:checked)):not([aria-selected=\"true\"])',\n\t\t\t\t\t\t\t[bg(\"brand.bg-tint-pressed\"), fg(\"brand.emphasis\")],\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen('&:has(input:checked), &[aria-selected=\"true\"]', [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&:has(input:disabled), &[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<input\n\t\t\t\t\ttype={type}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tname={resolvedName}\n\t\t\t\t\tchecked={checked}\n\t\t\t\t\tdefaultChecked={defaultChecked}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tmix={[visuallyHidden()]}\n\t\t\t\t/>\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n};\n\n/**\n * Renders a decorative sentinel row: a `<div>` styled as a centered, muted\n * line of small text sized to match {@link ListBox.Item}'s vertical rhythm,\n * ready to hold a loading indicator or \"load more\" trigger as `children`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the sentinel row's markup.\n * @example\n * <ListBox.LoadMoreItem>{t(\"list.loadingMore\")}</ListBox.LoadMoreItem>\n */\nListBox.LoadMoreItem = SentinelRow;\n"
13
13
  },
14
14
  "test": null
15
15
  }
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "media-grid",
3
- "changedIn": "2026.11.22",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [],
5
5
  "exports": [
6
6
  "MediaGrid"
7
7
  ],
8
8
  "source": {
9
9
  "path": "media-grid.tsx",
10
- "content": "/**\n * A grid of photos and videos as links, three square tiles to a row with a hairline gap, the\n * way a profile or an explore page lays out a person's pictures: a tile can stand two rows\n * tall, carry a badge in its corner and show an overlay (likes, a count) on hover or focus.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { motionReduce } from \"@sdxc/u/responsive\";\nimport { when } from \"@sdxc/u/state\";\n\n/** Prop types for {@link MediaGrid} and {@link MediaGrid.Item}. */\nexport namespace MediaGrid {\n\t/** Every native `<ul>` attribute, plus the grid's name and tiles. */\n\texport interface Props extends Omit<TagProps<\"ul\">, \"children\"> {\n\t\t/** The list's accessible name, such as \"Posts\". */\n\t\tlabel: string;\n\t\t/** How many tiles to a row. Default: `3`. */\n\t\tcolumns?: number;\n\t\t/** {@link MediaGrid.Item} elements in order. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/** Every native `<li>` attribute but `children`, plus the tile's link and content. */\n\texport interface ItemProps extends Omit<TagProps<\"li\">, \"children\"> {\n\t\t/** Where the tile leads: the post or the video. */\n\t\thref: string;\n\t\t/** The link's accessible name, such as \"Post by Mara: bowls cooling on a plank\". */\n\t\tlabel: string;\n\t\t/** The picture, drawn edge to edge and cropped to the tile: an `<img>`, an `<svg>`, a `<video>`. */\n\t\tchildren: RemixNode;\n\t\t/** Stands two rows tall, for a video among photos. */\n\t\ttall?: boolean;\n\t\t/** An icon in the top corner, such as a stack for several photos or a film for a video. */\n\t\tbadge?: RemixNode;\n\t\t/** What shows over the picture on hover or focus, such as its likes and comments. */\n\t\toverlay?: RemixNode;\n\t}\n}\n\n/** Tiles to a row when a page names no other count. */\nconst DEFAULT_COLUMNS = 3;\n\n/**\n * Renders the grid. Tiles flow densely, so a tall tile never leaves a hole; the gap reads\n * `--ui-media-grid-gap`, a hairline unless a page widens it.\n *\n * @example\n * <MediaGrid label=\"Posts\">\n * \t{posts.map((post) => (\n * \t\t<MediaGrid.Item href={post.href} label={post.alt} badge={post.many ? <LayersIcon /> : null}>\n * \t\t\t<img src={post.thumb} alt=\"\" />\n * \t\t</MediaGrid.Item>\n * \t))}\n * </MediaGrid>\n */\nexport function MediaGrid(handle: Handle<MediaGrid.Props>) {\n\treturn () => {\n\t\tlet { children, columns = DEFAULT_COLUMNS, label, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<ul\n\t\t\t\t{...rest}\n\t\t\t\taria-label={label}\n\t\t\t\tdata-slot=\"media-grid\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\tgridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,\n\t\t\t\t\t\t\tgridAutoFlow: \"dense\",\n\t\t\t\t\t\t\tgap: \"var(--ui-media-grid-gap, 2px)\",\n\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tlistStyle: \"none\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</ul>\n\t\t);\n\t};\n}\n\n/**\n * One tile: a link holding the picture, square or two rows tall, with its badge and an\n * overlay that fades in over a scrim while the tile is hovered or focused.\n */\nMediaGrid.Item = function MediaGridItem(handle: Handle<MediaGrid.ItemProps>) {\n\treturn () => {\n\t\tlet { badge, children, href, label, mix, overlay, tall = false, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<li\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media-grid-item\"\n\t\t\t\tdata-tall={tall ? \"\" : undefined}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({ minInlineSize: \"0\" }),\n\t\t\t\t\t\twhen(\"&[data-tall]\", raw({ gridRow: \"span 2\", \"--ui-media-grid-ratio\": \"auto\" })),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<a\n\t\t\t\t\thref={href}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\taspectRatio: \"var(--ui-media-grid-ratio, 1)\",\n\t\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\t\tcolor: \"oklch(0.99 0 0)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-bg-tint)\",\n\t\t\t\t\t\t\t\"& > [data-media-grid-picture] > *\": {\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tinlineSize: \"100%\",\n\t\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\t\tobjectFit: \"cover\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&:hover [data-media-grid-overlay], &:focus-visible [data-media-grid-overlay]\",\n\t\t\t\t\t\t\traw({ opacity: \"1\" }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&:focus-visible\",\n\t\t\t\t\t\t\traw({ outline: \"2px solid var(--ui-brand-ring)\", outlineOffset: \"-2px\" }),\n\t\t\t\t\t\t),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-media-grid-picture=\"\"\n\t\t\t\t\t\tmix={[raw({ position: \"absolute\", inset: \"0\", display: \"block\" })]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</span>\n\t\t\t\t\t{badge === undefined || badge === null ? null : (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\tdata-media-grid-badge=\"\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\t\t\tinsetBlockStart: \"0.5rem\",\n\t\t\t\t\t\t\t\t\tinsetInlineEnd: \"0.5rem\",\n\t\t\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\t\t\tfilter: \"drop-shadow(0 1px 2px rgb(0 0 0 / 0.5))\",\n\t\t\t\t\t\t\t\t\t\"& > svg\": { inlineSize: \"1.125rem\", blockSize: \"1.125rem\" },\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{badge}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t)}\n\t\t\t\t\t{overlay === undefined || overlay === null ? null : (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\tdata-media-grid-overlay=\"\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\t\t\tinset: \"0\",\n\t\t\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\t\t\tjustifyContent: \"center\",\n\t\t\t\t\t\t\t\t\tgap: \"1.25rem\",\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"rgb(0 0 0 / 0.35)\",\n\t\t\t\t\t\t\t\t\tfontWeight: \"700\",\n\t\t\t\t\t\t\t\t\topacity: \"0\",\n\t\t\t\t\t\t\t\t\ttransition: \"opacity 120ms ease\",\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tmotionReduce(raw({ transition: \"none\" })),\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{overlay}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t)}\n\t\t\t\t</a>\n\t\t\t</li>\n\t\t);\n\t};\n};\n"
10
+ "content": "/**\n * A grid of photos and videos as links, three square tiles to a row with a hairline gap, the\n * way a profile or an explore page lays out a person's pictures: a tile can stand two rows\n * tall, carry a badge part in its corner and show an overlay part (likes, a count) on hover or focus.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { motionReduce } from \"@sdxc/u/responsive\";\nimport { when } from \"@sdxc/u/state\";\n\n/** Prop types for {@link MediaGrid} and its parts. */\nexport namespace MediaGrid {\n\t/** Every native `<ul>` attribute, plus the column count; name the list with `aria-label`, such as \"Posts\". */\n\texport interface Props extends TagProps<\"ul\"> {\n\t\t/** How many tiles to a row. Default: `3`. */\n\t\tcolumns?: number;\n\t}\n\n\t/** Every native `<li>` attribute but `children`, plus the tile's link and content. */\n\texport interface ItemProps extends Omit<TagProps<\"li\">, \"children\"> {\n\t\t/** Where the tile leads: the post or the video. */\n\t\thref: string;\n\t\t/** The link's accessible name, such as \"Post by Mara: bowls cooling on a plank\". */\n\t\tlabel: string;\n\t\t/** The tile's {@link MediaGrid.Picture}, {@link MediaGrid.Badge} and {@link MediaGrid.Overlay}. */\n\t\tchildren: RemixNode;\n\t\t/** Stands two rows tall, for a video among photos. */\n\t\ttall?: boolean;\n\t}\n\n\t/** Every native `<span>` attribute. */\n\texport interface PartProps extends TagProps<\"span\"> {}\n}\n\n/** Tiles to a row when a page names no other count. */\nconst DEFAULT_COLUMNS = 3;\n\n/**\n * Renders the grid. Tiles flow densely, so a tall tile never leaves a hole; the gap reads\n * `--ui-media-grid-gap`, a hairline unless a page widens it.\n *\n * @example\n * <MediaGrid aria-label=\"Posts\">\n * \t{posts.map((post) => (\n * \t\t<MediaGrid.Item href={post.href} label={post.alt}>\n * \t\t\t<MediaGrid.Picture><img src={post.thumb} alt=\"\" /></MediaGrid.Picture>\n * \t\t\t{post.many ? <MediaGrid.Badge><LayersIcon /></MediaGrid.Badge> : null}\n * \t\t</MediaGrid.Item>\n * \t))}\n * </MediaGrid>\n */\nexport function MediaGrid(handle: Handle<MediaGrid.Props>) {\n\treturn () => {\n\t\tlet { children, columns = DEFAULT_COLUMNS, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<ul\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media-grid\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\tgridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,\n\t\t\t\t\t\t\tgridAutoFlow: \"dense\",\n\t\t\t\t\t\t\tgap: \"var(--ui-media-grid-gap, 2px)\",\n\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tlistStyle: \"none\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</ul>\n\t\t);\n\t};\n}\n\n/**\n * One tile: a link holding its parts, square or two rows tall; an {@link MediaGrid.Overlay}\n * fades in over a scrim while the tile is hovered or focused.\n *\n * @param handle Runtime handle carrying the list item's props, the link and its name.\n * @returns The render function producing the tile.\n */\nMediaGrid.Item = function MediaGridItem(handle: Handle<MediaGrid.ItemProps>) {\n\treturn () => {\n\t\tlet { children, href, label, mix, tall = false, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<li\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media-grid-item\"\n\t\t\t\tdata-tall={tall ? \"\" : undefined}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({ minInlineSize: \"0\" }),\n\t\t\t\t\t\twhen(\"&[data-tall]\", raw({ gridRow: \"span 2\", \"--ui-media-grid-ratio\": \"auto\" })),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<a\n\t\t\t\t\thref={href}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\taspectRatio: \"var(--ui-media-grid-ratio, 1)\",\n\t\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\t\tcolor: \"oklch(0.99 0 0)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-bg-tint)\",\n\t\t\t\t\t\t\t\"& > [data-media-grid-picture] > *\": {\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tinlineSize: \"100%\",\n\t\t\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\t\t\tobjectFit: \"cover\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&:hover [data-media-grid-overlay], &:focus-visible [data-media-grid-overlay]\",\n\t\t\t\t\t\t\traw({ opacity: \"1\" }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&:focus-visible\",\n\t\t\t\t\t\t\traw({ outline: \"2px solid var(--ui-brand-ring)\", outlineOffset: \"-2px\" }),\n\t\t\t\t\t\t),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</a>\n\t\t\t</li>\n\t\t);\n\t};\n};\n\n/**\n * The picture, drawn edge to edge and cropped to the tile: an `<img>`, an `<svg>`, a `<video>`.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the picture's frame.\n */\nMediaGrid.Picture = function MediaGridPicture(handle: Handle<MediaGrid.PartProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"media-grid-picture\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-media-grid-picture=\"\"\n\t\t\t\tmix={mergeMix([raw({ position: \"absolute\", inset: \"0\", display: \"block\" })], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * An icon in the top corner, such as a stack for several photos or a film for a video;\n * decorative, since the link's name says what the tile holds.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the badge.\n */\nMediaGrid.Badge = function MediaGridBadge(handle: Handle<MediaGrid.PartProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tdata-slot=\"media-grid-badge\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-media-grid-badge=\"\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\tinsetBlockStart: \"0.5rem\",\n\t\t\t\t\t\t\tinsetInlineEnd: \"0.5rem\",\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\tfilter: \"drop-shadow(0 1px 2px rgb(0 0 0 / 0.5))\",\n\t\t\t\t\t\t\t\"& > svg\": { inlineSize: \"1.125rem\", blockSize: \"1.125rem\" },\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * What shows over the picture on hover or focus, such as its likes and comments, on a scrim.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the overlay.\n */\nMediaGrid.Overlay = function MediaGridOverlay(handle: Handle<MediaGrid.PartProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tdata-slot=\"media-grid-overlay\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-media-grid-overlay=\"\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\tinset: \"0\",\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tjustifyContent: \"center\",\n\t\t\t\t\t\t\tgap: \"1.25rem\",\n\t\t\t\t\t\t\tbackgroundColor: \"rgb(0 0 0 / 0.35)\",\n\t\t\t\t\t\t\tfontWeight: \"700\",\n\t\t\t\t\t\t\topacity: \"0\",\n\t\t\t\t\t\t\ttransition: \"opacity 120ms ease\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tmotionReduce(raw({ transition: \"none\" })),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
11
11
  },
12
12
  "test": {
13
13
  "path": "media-grid.browser.test.tsx",
14
- "content": "/**\n * Lays the media grid out in a real page: three square tiles to a row, a tall tile spanning\n * two rows without leaving a hole, the badge in its corner, and the overlay hidden until the\n * tile is focused.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\n\nimport { MediaGrid } from \"@sdxc/ui/media-grid\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\n/** Mounts six tiles in a 302px box, the second one tall. */\nfunction mountGrid(): RenderResult {\n\treturn render(\n\t\t<div style=\"inline-size: 302px\">\n\t\t\t<MediaGrid label=\"Posts\">\n\t\t\t\t{[0, 1, 2, 3, 4, 5].map((index) => (\n\t\t\t\t\t<MediaGrid.Item\n\t\t\t\t\t\tid={`tile-${index}`}\n\t\t\t\t\t\thref={`#post-${index}`}\n\t\t\t\t\t\tlabel={`Post ${index + 1}`}\n\t\t\t\t\t\ttall={index === 1}\n\t\t\t\t\t\tbadge={index === 0 ? <svg id=\"badge\" viewBox=\"0 0 10 10\" /> : undefined}\n\t\t\t\t\t\toverlay={index === 0 ? <span>12 likes</span> : undefined}\n\t\t\t\t\t>\n\t\t\t\t\t\t<div style=\"background: #777\" />\n\t\t\t\t\t</MediaGrid.Item>\n\t\t\t\t))}\n\t\t\t</MediaGrid>\n\t\t</div>,\n\t);\n}\n\n/** A tile's box. */\nfunction box(feed: RenderResult, index: number): DOMRect {\n\treturn feed.container.querySelector(`#tile-${index} a`)!.getBoundingClientRect();\n}\n\ndescribe(\"MediaGrid\", () => {\n\ttest(\"lays three square tiles to a row with a hairline gap\", () => {\n\t\tmounted = mountGrid();\n\t\tlet first = box(mounted, 0);\n\t\texpect(first.width).toBeCloseTo(first.height, 0);\n\t\texpect(first.width).toBeCloseTo(99.33, 0);\n\t});\n\n\ttest(\"stands a tall tile two rows high and fills the hole beside it\", () => {\n\t\tmounted = mountGrid();\n\t\tlet tall = box(mounted, 1);\n\t\tlet square = box(mounted, 0);\n\t\texpect(tall.height).toBeCloseTo(square.height * 2 + 2, 0);\n\t\tlet below = box(mounted, 3);\n\t\texpect(below.top).toBeCloseTo(square.bottom + 2, 0);\n\t\texpect(below.left).toBeCloseTo(square.left, 0);\n\t});\n\n\ttest(\"hides the overlay until the tile is focused, and links each tile by name\", () => {\n\t\tmounted = mountGrid();\n\t\tlet link = mounted.container.querySelector<HTMLAnchorElement>(\"#tile-0 a\")!;\n\t\tlet overlay = mounted.container.querySelector<HTMLElement>(\"[data-media-grid-overlay]\")!;\n\t\texpect(link.getAttribute(\"aria-label\")).toBe(\"Post 1\");\n\t\texpect(getComputedStyle(overlay).opacity).toBe(\"0\");\n\t\texpect(mounted.container.querySelector(\"[data-media-grid-badge] #badge\")).not.toBeNull();\n\t});\n});\n"
14
+ "content": "/**\n * Lays the media grid out in a real page: three square tiles to a row, a tall tile spanning\n * two rows without leaving a hole, the badge in its corner, and the overlay hidden until the\n * tile is focused.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\n\nimport { MediaGrid } from \"@sdxc/ui/media-grid\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\n/** Mounts six tiles in a 302px box, the second one tall. */\nfunction mountGrid(): RenderResult {\n\treturn render(\n\t\t<div style=\"inline-size: 302px\">\n\t\t\t<MediaGrid aria-label=\"Posts\">\n\t\t\t\t{[0, 1, 2, 3, 4, 5].map((index) => (\n\t\t\t\t\t<MediaGrid.Item\n\t\t\t\t\t\tid={`tile-${index}`}\n\t\t\t\t\t\thref={`#post-${index}`}\n\t\t\t\t\t\tlabel={`Post ${index + 1}`}\n\t\t\t\t\t\ttall={index === 1}\n\t\t\t\t\t>\n\t\t\t\t\t\t{index === 0 ? (\n\t\t\t\t\t\t\t<MediaGrid.Overlay>\n\t\t\t\t\t\t\t\t<span>12 likes</span>\n\t\t\t\t\t\t\t</MediaGrid.Overlay>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t<MediaGrid.Picture>\n\t\t\t\t\t\t\t<div style=\"background: #777\" />\n\t\t\t\t\t\t</MediaGrid.Picture>\n\t\t\t\t\t\t{index === 0 ? (\n\t\t\t\t\t\t\t<MediaGrid.Badge>\n\t\t\t\t\t\t\t\t<svg id=\"badge\" viewBox=\"0 0 10 10\" />\n\t\t\t\t\t\t\t</MediaGrid.Badge>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</MediaGrid.Item>\n\t\t\t\t))}\n\t\t\t</MediaGrid>\n\t\t</div>,\n\t);\n}\n\n/** A tile's box. */\nfunction box(feed: RenderResult, index: number): DOMRect {\n\treturn feed.container.querySelector(`#tile-${index} a`)!.getBoundingClientRect();\n}\n\ndescribe(\"MediaGrid\", () => {\n\ttest(\"lays three square tiles to a row with a hairline gap\", () => {\n\t\tmounted = mountGrid();\n\t\tlet first = box(mounted, 0);\n\t\texpect(first.width).toBeCloseTo(first.height, 0);\n\t\texpect(first.width).toBeCloseTo(99.33, 0);\n\t});\n\n\ttest(\"stands a tall tile two rows high and fills the hole beside it\", () => {\n\t\tmounted = mountGrid();\n\t\tlet tall = box(mounted, 1);\n\t\tlet square = box(mounted, 0);\n\t\texpect(tall.height).toBeCloseTo(square.height * 2 + 2, 0);\n\t\tlet below = box(mounted, 3);\n\t\texpect(below.top).toBeCloseTo(square.bottom + 2, 0);\n\t\texpect(below.left).toBeCloseTo(square.left, 0);\n\t});\n\n\ttest(\"hides the overlay until the tile is focused, and links each tile by name\", () => {\n\t\tmounted = mountGrid();\n\t\tlet link = mounted.container.querySelector<HTMLAnchorElement>(\"#tile-0 a\")!;\n\t\tlet overlay = mounted.container.querySelector<HTMLElement>(\"[data-media-grid-overlay]\")!;\n\t\texpect(link.getAttribute(\"aria-label\")).toBe(\"Post 1\");\n\t\texpect(getComputedStyle(overlay).opacity).toBe(\"0\");\n\t\texpect(mounted.container.querySelector(\"[data-media-grid-badge] #badge\")).not.toBeNull();\n\t});\n});\n"
15
15
  }
16
16
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "pager",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "Pager"
7
+ ],
8
+ "source": {
9
+ "path": "pager.tsx",
10
+ "content": "/**\n * A two-link pager for a feed paged in time or a sequence read in order, built from parts:\n * \"Newer\" and \"Older\", or \"Previous\" and \"Next\", at the two ends of one row with an arrow\n * pointing each way, stacked when narrow. A missing side leaves the other link at its own end.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { ArrowLeftIcon, ArrowRightIcon } from \"@sdxc/icons\";\nimport { outline } from \"@sdxc/u/color\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { hstack, vstack } from \"@sdxc/u/layout\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { overflowWrap, text, textAlign, textDecoration } from \"@sdxc/u/typography\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** The landmark name {@link Pager} announces when `aria-label` is omitted. */\nconst DEFAULT_LABEL = \"Pagination\";\n\n/** How {@link Pager} lays out its links when `layout` is omitted. */\nconst DEFAULT_LAYOUT: Pager.Layout = \"auto\";\n\n/** The container an `\"auto\"` pager names on its root, so it answers its own width. */\nconst CONTAINER = \"ui-pager\";\n\n/** The pager's own width below which an `\"auto\"` pager stacks its links. */\nconst STACK_BELOW = \"30rem\";\n\n/** A link's width while the links share one row. */\nconst ROW_LINK = { inlineSize: \"var(--ui-pager-link-inline-size, auto)\" };\n\n/** A link's place in a stacked pager: its own full-width line, previous above next. */\nconst STACKED_LINK = { gridColumn: \"1 / -1\", justifySelf: \"stretch\", inlineSize: \"100%\" };\n\n/** Prop types for {@link Pager} and its parts. */\nexport namespace Pager {\n\t/** What the pager shares with its parts. */\n\texport interface Context {\n\t\tlayout: Layout;\n\t}\n\n\t/**\n\t * Every native `<a>` attribute; `rel` defaults to `\"prev\"` on {@link Pager.Previous} and\n\t * `\"next\"` on {@link Pager.Next}, and a feed that puts older posts first passes the\n\t * relation its order means.\n\t */\n\texport type LinkProps = TagProps<\"a\"> & { href: string };\n\n\t/** Every native `<span>` attribute. */\n\texport interface SpanProps extends TagProps<\"span\"> {}\n\n\t/**\n\t * The custom properties the pager reads, set on the root through `mix` or `style`. Each one\n\t * falls back to the default look, so a caller sets only what it changes.\n\t */\n\texport interface CustomProperties {\n\t\t/** A link's padding, block then inline. */\n\t\t\"--ui-pager-link-padding\"?: string;\n\t\t/** A link's corner radius. */\n\t\t\"--ui-pager-link-radius\"?: string;\n\t\t/** A link's border colour. */\n\t\t\"--ui-pager-link-border-color\"?: string;\n\t\t/** A link's background. */\n\t\t\"--ui-pager-link-bg\"?: string;\n\t\t/** A link's text colour. */\n\t\t\"--ui-pager-link-fg\"?: string;\n\t\t/** A link's font weight. */\n\t\t\"--ui-pager-link-font-weight\"?: string;\n\t\t/** A link's background under the pointer. */\n\t\t\"--ui-pager-link-hover-bg\"?: string;\n\t\t/** A link's text colour under the pointer; its resting colour by default. */\n\t\t\"--ui-pager-link-hover-fg\"?: string;\n\t\t/** A link's border colour under the pointer. */\n\t\t\"--ui-pager-link-hover-border-color\"?: string;\n\t\t/** A link's width in a row, where `100%` fills its half; stacked links are always full width. */\n\t\t\"--ui-pager-link-inline-size\"?: string;\n\t\t/** The caption's text colour. */\n\t\t\"--ui-pager-caption-fg\"?: string;\n\t\t/** The caption's font size. */\n\t\t\"--ui-pager-caption-font-size\"?: string;\n\t\t/** The status line's text colour. */\n\t\t\"--ui-pager-status-fg\"?: string;\n\t}\n\n\t/**\n\t * How the links sit: `\"row\"` at the two ends of one line, `\"stack\"` previous above next,\n\t * each full width, and `\"auto\"` a row that stacks when the pager itself is under 30rem.\n\t */\n\texport type Layout = \"row\" | \"stack\" | \"auto\";\n\n\t/**\n\t * Every native `<nav>` attribute; the landmark is named \"Pagination\" unless the caller\n\t * passes its own `aria-label`.\n\t */\n\texport interface Props extends TagProps<\"nav\"> {\n\t\t/**\n\t\t * How the links sit. `\"auto\"` makes the root a size container, so give it a width\n\t\t * of its own inside a shrink-to-fit parent.\n\t\t *\n\t\t * @default \"auto\"\n\t\t */\n\t\tlayout?: Layout;\n\t}\n}\n\n/**\n * Renders a `<nav>` laid out as three columns, so {@link Pager.Previous} and {@link Pager.Next}\n * each stay at their own end whether or not the other exists, with a {@link Pager.Status} centred\n * between them; under 30rem wide the links stack. Restyle through {@link Pager.CustomProperties}.\n *\n * @param handle Runtime handle carrying the host `<nav>`'s props.\n * @returns The render function producing the pager's markup.\n * @example\n * <Pager>\n * \t<Pager.Previous href=\"/?page=1\">Newer</Pager.Previous>\n * \t<Pager.Status>Page 2 of 5</Pager.Status>\n * \t<Pager.Next href=\"/?page=3\">Older</Pager.Next>\n * </Pager>\n * @example\n * <Pager layout=\"stack\">\n * \t<Pager.Previous href=\"/posts/one\"><Pager.Caption>Previous</Pager.Caption><Pager.Label>The first post</Pager.Label></Pager.Previous>\n * </Pager>\n */\nexport function Pager(handle: Handle<Pager.Props, Pager.Context>) {\n\treturn () => {\n\t\tlet { layout = DEFAULT_LAYOUT, children, mix, ...rest } = handle.props;\n\t\thandle.context.set({ layout });\n\n\t\treturn (\n\t\t\t<nav\n\t\t\t\tdata-slot=\"pager\"\n\t\t\t\taria-label={DEFAULT_LABEL}\n\t\t\t\t{...rest}\n\t\t\t\tdata-pager-layout={layout}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\tlayout === \"auto\"\n\t\t\t\t\t\t? [raw({ containerType: \"inline-size\", containerName: CONTAINER })]\n\t\t\t\t\t\t: [],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"pager-row\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({ display: \"grid\", alignItems: \"center\" }),\n\t\t\t\t\t\t...placed(\n\t\t\t\t\t\t\tlayout,\n\t\t\t\t\t\t\t{ gridTemplateColumns: \"minmax(0, 1fr) auto minmax(0, 1fr)\", gap: \"1rem\" },\n\t\t\t\t\t\t\t{ gridTemplateColumns: \"minmax(0, 1fr)\", gap: \"0.5rem\" },\n\t\t\t\t\t\t),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</nav>\n\t\t);\n\t};\n}\n\n/**\n * The link at the row's start, with an arrow pointing back; its words stack at its start.\n *\n * @param handle Runtime handle carrying the link's props.\n * @returns The render function producing the link.\n */\nPager.Previous = function PagerPrevious(handle: Handle<Pager.LinkProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet layout = (handle.context.get(Pager) as Pager.Context | undefined)?.layout ?? DEFAULT_LAYOUT;\n\t\treturn (\n\t\t\t<a\n\t\t\t\trel=\"prev\"\n\t\t\t\tdata-slot=\"pager-previous\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\t...pagerLink(),\n\t\t\t\t\t\t...placed(layout, { ...ROW_LINK, gridColumn: \"1\", justifySelf: \"start\" }, STACKED_LINK),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<ArrowLeftIcon size={16} mix={mirrored()} />\n\t\t\t\t<span\n\t\t\t\t\tdata-slot=\"pager-text\"\n\t\t\t\t\tmix={[vstack({ align: \"start\" }), raw({ minInlineSize: \"0\" })]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t</a>\n\t\t);\n\t};\n};\n\n/**\n * The link at the row's end, with an arrow pointing forward; its words stack at its end.\n *\n * @param handle Runtime handle carrying the link's props.\n * @returns The render function producing the link.\n */\nPager.Next = function PagerNext(handle: Handle<Pager.LinkProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet layout = (handle.context.get(Pager) as Pager.Context | undefined)?.layout ?? DEFAULT_LAYOUT;\n\t\treturn (\n\t\t\t<a\n\t\t\t\trel=\"next\"\n\t\t\t\tdata-slot=\"pager-next\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\t...pagerLink(),\n\t\t\t\t\t\traw({ justifyContent: \"flex-end\" }),\n\t\t\t\t\t\ttextAlign(\"end\"),\n\t\t\t\t\t\t...placed(layout, { ...ROW_LINK, gridColumn: \"3\", justifySelf: \"end\" }, STACKED_LINK),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<span data-slot=\"pager-text\" mix={[vstack({ align: \"end\" }), raw({ minInlineSize: \"0\" })]}>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t\t<ArrowRightIcon size={16} mix={mirrored()} />\n\t\t\t</a>\n\t\t);\n\t};\n};\n\n/**\n * A small line over a link's label naming the direction, such as \"Previous\" over a post title.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the caption.\n */\nPager.Caption = function PagerCaption(handle: Handle<Pager.SpanProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"pager-caption\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tcolor: \"var(--ui-pager-caption-fg, var(--ui-neutral-fg-muted))\",\n\t\t\t\t\t\t\tfontSize: \"var(--ui-pager-caption-font-size, var(--ui-text-xs, 0.75rem))\",\n\t\t\t\t\t\t\tlineHeight: \"var(--ui-leading-xs, calc(1 / 0.75))\",\n\t\t\t\t\t\t\tfontWeight: \"400\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * What a link says under its caption, such as \"Older\" or the title of the post it leads to.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the label.\n */\nPager.Label = function PagerLabel(handle: Handle<Pager.SpanProps>) {\n\treturn () => <span data-slot=\"pager-label\" {...handle.props} />;\n};\n\n/**\n * Where the reader is, centred between the links, such as \"Page 2 of 5\".\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the status line.\n */\nPager.Status = function PagerStatus(handle: Handle<Pager.SpanProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet layout = (handle.context.get(Pager) as Pager.Context | undefined)?.layout ?? DEFAULT_LAYOUT;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"pager-status\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({ color: \"var(--ui-pager-status-fg, var(--ui-neutral-fg-muted))\" }),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\t\t...placed(layout, { gridColumn: \"2\" }, { gridColumn: \"1 / -1\" }),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * An element's place in the row or in the stack, picked by `layout`; `\"auto\"` holds both\n * under mutually exclusive queries on the pager's own width, so neither overrides the other.\n *\n * @param layout The pager's layout.\n * @param row The styles while the links share one row.\n * @param stack The styles while the links stack.\n */\nfunction placed(layout: Pager.Layout, row: Record<string, string>, stack: Record<string, string>) {\n\tif (layout === \"row\") return [raw(row)];\n\tif (layout === \"stack\") return [raw(stack)];\n\treturn [\n\t\traw({\n\t\t\t[`@container ${CONTAINER} (width >= ${STACK_BELOW})`]: row,\n\t\t\t[`@container ${CONTAINER} (width < ${STACK_BELOW})`]: stack,\n\t\t}),\n\t];\n}\n\n/**\n * A pager link: a bordered target holding its label and arrow, tinted on hover. Every visible\n * choice reads a `--ui-pager-*` property with the default as its fallback.\n */\nfunction pagerLink() {\n\treturn [\n\t\tinteractiveTransition(),\n\t\thstack({ gap: 2, align: \"center\" }),\n\t\ttextDecoration(\"none\"),\n\t\toverflowWrap(\"anywhere\"),\n\t\traw({\n\t\t\tboxSizing: \"border-box\",\n\t\t\tmaxInlineSize: \"100%\",\n\t\t\tpadding: \"var(--ui-pager-link-padding, 0.5rem 0.875rem)\",\n\t\t\tborderRadius: \"var(--ui-pager-link-radius, var(--ui-radius-md, 0.375rem))\",\n\t\t\tborderWidth: \"1px\",\n\t\t\tborderStyle: \"solid\",\n\t\t\tborderColor: \"var(--ui-pager-link-border-color, var(--ui-neutral-border))\",\n\t\t\tbackgroundColor: \"var(--ui-pager-link-bg, transparent)\",\n\t\t\tcolor: \"var(--ui-pager-link-fg, var(--ui-neutral-fg-emphasis))\",\n\t\t\tfontWeight: \"var(--ui-pager-link-font-weight, 500)\",\n\t\t}),\n\t\thover(\n\t\t\traw({\n\t\t\t\tbackgroundColor: \"var(--ui-pager-link-hover-bg, var(--ui-neutral-bg-tint))\",\n\t\t\t\tcolor:\n\t\t\t\t\t\"var(--ui-pager-link-hover-fg, var(--ui-pager-link-fg, var(--ui-neutral-fg-emphasis)))\",\n\t\t\t\tborderColor:\n\t\t\t\t\t\"var(--ui-pager-link-hover-border-color, var(--ui-pager-link-border-color, var(--ui-neutral-border)))\",\n\t\t\t}),\n\t\t),\n\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t];\n}\n\n/**\n * Keeps an arrow at full size beside a long label, and flips it in a right-to-left page, so\n * \"back\" always points toward the row's start.\n */\nfunction mirrored() {\n\treturn [raw({ flexShrink: \"0\" }), when(\"&:dir(rtl)\", raw({ transform: \"scaleX(-1)\" }))];\n}\n"
11
+ },
12
+ "test": {
13
+ "path": "pager.browser.test.tsx",
14
+ "content": "/**\n * Renders `Pager` in a real browser: the links sit at the row's two ends with their relations\n * and arrows, a lone link keeps its own end, and a status line sits centred between them. A\n * caption stacks over its label, each custom property set on the root restyles the links, and\n * the links stack, each full width, in a narrow pager or with `layout=\"stack\"`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RemixNode } from \"remix/component\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { raw } from \"@sdxc/u/general\";\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { Pager } from \"@sdxc/ui/pager\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The page before this one in the feed. */\nfunction Newer() {\n\treturn () => <Pager.Previous href=\"/?page=1\">Newer</Pager.Previous>;\n}\n\n/** The page after this one in the feed. */\nfunction Older() {\n\treturn () => <Pager.Next href=\"/?page=3\">Older</Pager.Next>;\n}\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts a pager `width` pixels wide, 600 by default, and returns its `<nav>`. */\nfunction mount(node: RemixNode, width = 600): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host.querySelector(\"nav\")!;\n}\n\n/** The link in `nav` with the given slot. */\nfunction link(nav: HTMLElement, slot: \"previous\" | \"next\"): HTMLAnchorElement | null {\n\treturn nav.querySelector(`[data-slot=\"pager-${slot}\"]`);\n}\n\ndescribe(\"Pager\", () => {\n\ttest(\"names the landmark Pagination unless given its own name\", () => {\n\t\texpect(\n\t\t\tmount(\n\t\t\t\t<Pager>\n\t\t\t\t\t<Older />\n\t\t\t\t</Pager>,\n\t\t\t).getAttribute(\"aria-label\"),\n\t\t).toBe(\"Pagination\");\n\t\tmounted?.cleanup();\n\t\tdocument.body.replaceChildren();\n\t\texpect(\n\t\t\tmount(\n\t\t\t\t<Pager aria-label=\"More posts\">\n\t\t\t\t\t<Older />\n\t\t\t\t</Pager>,\n\t\t\t).getAttribute(\"aria-label\"),\n\t\t).toBe(\"More posts\");\n\t});\n\n\ttest(\"puts each link at its own end with its relation and a hidden arrow\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Newer />\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet row = nav.getBoundingClientRect();\n\t\tlet previous = link(nav, \"previous\")!;\n\t\tlet next = link(nav, \"next\")!;\n\n\t\texpect(previous.getAttribute(\"rel\")).toBe(\"prev\");\n\t\texpect(next.getAttribute(\"rel\")).toBe(\"next\");\n\t\texpect(previous.textContent).toBe(\"Newer\");\n\t\texpect(previous.querySelector(\"svg\")?.getAttribute(\"aria-hidden\")).toBe(\"true\");\n\t\texpect(previous.getBoundingClientRect().left).toBeCloseTo(row.left, 0);\n\t\texpect(next.getBoundingClientRect().right).toBeCloseTo(row.right, 0);\n\t});\n\n\ttest(\"keeps a lone next link at the row's end\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\n\t\texpect(link(nav, \"previous\")).toBeNull();\n\t\texpect(link(nav, \"next\")!.getBoundingClientRect().right).toBeCloseTo(\n\t\t\tnav.getBoundingClientRect().right,\n\t\t\t0,\n\t\t);\n\t});\n\n\ttest(\"keeps a lone previous link at the row's start\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Newer />\n\t\t\t</Pager>,\n\t\t);\n\n\t\texpect(link(nav, \"next\")).toBeNull();\n\t\texpect(link(nav, \"previous\")!.getBoundingClientRect().left).toBeCloseTo(\n\t\t\tnav.getBoundingClientRect().left,\n\t\t\t0,\n\t\t);\n\t});\n\n\ttest(\"takes the relation a link passes\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Pager.Previous href=\"/?page=3\" rel=\"next\">\n\t\t\t\t\tOlder\n\t\t\t\t</Pager.Previous>\n\t\t\t</Pager>,\n\t\t);\n\n\t\texpect(link(nav, \"previous\")!.getAttribute(\"rel\")).toBe(\"next\");\n\t});\n\n\ttest(\"centres the status between the links\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Newer />\n\t\t\t\t<Pager.Status>Page 2 of 5</Pager.Status>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet row = nav.getBoundingClientRect();\n\t\tlet status = nav.querySelector('[data-slot=\"pager-status\"]')!.getBoundingClientRect();\n\n\t\texpect(status.left + status.width / 2).toBeCloseTo(row.left + row.width / 2, 0);\n\t});\n\n\ttest(\"draws the default bordered link\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Newer />\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet style = getComputedStyle(link(nav, \"previous\")!);\n\n\t\texpect(style.borderTopLeftRadius).toBe(\"6px\");\n\t\texpect(style.borderTopWidth).toBe(\"1px\");\n\t\texpect(style.paddingTop).toBe(\"8px\");\n\t\texpect(style.paddingLeft).toBe(\"14px\");\n\t\texpect(style.backgroundColor).toBe(\"rgba(0, 0, 0, 0)\");\n\t});\n\n\ttest(\"stacks a caption over a node label\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Pager.Previous href=\"/posts/one\">\n\t\t\t\t\t<Pager.Caption>Previous</Pager.Caption>\n\t\t\t\t\t<Pager.Label>\n\t\t\t\t\t\t<em>The first post</em>\n\t\t\t\t\t</Pager.Label>\n\t\t\t\t</Pager.Previous>\n\t\t\t\t<Pager.Next href=\"/posts/three\">\n\t\t\t\t\t<Pager.Caption>Next</Pager.Caption>\n\t\t\t\t\t<Pager.Label>The third post</Pager.Label>\n\t\t\t\t</Pager.Next>\n\t\t\t</Pager>,\n\t\t);\n\t\tlet previous = link(nav, \"previous\")!;\n\t\tlet caption = previous.querySelector('[data-slot=\"pager-caption\"]')!;\n\t\tlet label = previous.querySelector('[data-slot=\"pager-label\"]')!;\n\t\tlet nextCaption = link(nav, \"next\")!.querySelector('[data-slot=\"pager-caption\"]')!;\n\t\tlet nextLabel = link(nav, \"next\")!.querySelector('[data-slot=\"pager-label\"]')!;\n\n\t\texpect(caption.textContent).toBe(\"Previous\");\n\t\texpect(label.querySelector(\"em\")?.textContent).toBe(\"The first post\");\n\t\texpect(caption.getBoundingClientRect().bottom).toBeLessThanOrEqual(\n\t\t\tlabel.getBoundingClientRect().top + 1,\n\t\t);\n\t\texpect(caption.getBoundingClientRect().left).toBeCloseTo(label.getBoundingClientRect().left, 0);\n\t\texpect(nextCaption.getBoundingClientRect().right).toBeCloseTo(\n\t\t\tnextLabel.getBoundingClientRect().right,\n\t\t\t0,\n\t\t);\n\t\texpect(getComputedStyle(caption).fontSize).toBe(\"12px\");\n\t});\n\n\ttest(\"restyles the links, caption and status from custom properties set on the root\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager\n\t\t\t\tmix={[\n\t\t\t\t\traw({\n\t\t\t\t\t\t\"--ui-pager-link-padding\": \"3px 9px\",\n\t\t\t\t\t\t\"--ui-pager-link-radius\": \"999px\",\n\t\t\t\t\t\t\"--ui-pager-link-border-color\": \"rgb(1, 2, 3)\",\n\t\t\t\t\t\t\"--ui-pager-link-bg\": \"rgb(4, 5, 6)\",\n\t\t\t\t\t\t\"--ui-pager-link-fg\": \"rgb(7, 8, 9)\",\n\t\t\t\t\t\t\"--ui-pager-link-inline-size\": \"100%\",\n\t\t\t\t\t\t\"--ui-pager-caption-fg\": \"rgb(10, 11, 12)\",\n\t\t\t\t\t\t\"--ui-pager-caption-font-size\": \"15px\",\n\t\t\t\t\t\t\"--ui-pager-status-fg\": \"rgb(13, 14, 15)\",\n\t\t\t\t\t} satisfies Pager.CustomProperties),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<Pager.Previous href=\"/?page=1\">\n\t\t\t\t\t<Pager.Caption>Previous</Pager.Caption>\n\t\t\t\t\t<Pager.Label>Newer</Pager.Label>\n\t\t\t\t</Pager.Previous>\n\t\t\t\t<Pager.Status>Page 2 of 5</Pager.Status>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet previous = link(nav, \"previous\")!;\n\t\tlet style = getComputedStyle(previous);\n\t\tlet caption = getComputedStyle(previous.querySelector('[data-slot=\"pager-caption\"]')!);\n\t\tlet status = getComputedStyle(nav.querySelector('[data-slot=\"pager-status\"]')!);\n\t\tlet column = (nav.getBoundingClientRect().width - 2 * 16) / 2;\n\n\t\texpect(style.paddingTop).toBe(\"3px\");\n\t\texpect(style.paddingLeft).toBe(\"9px\");\n\t\texpect(style.borderTopLeftRadius).toBe(\"999px\");\n\t\texpect(style.borderTopColor).toBe(\"rgb(1, 2, 3)\");\n\t\texpect(style.backgroundColor).toBe(\"rgb(4, 5, 6)\");\n\t\texpect(style.color).toBe(\"rgb(7, 8, 9)\");\n\t\texpect(previous.getBoundingClientRect().width).toBeLessThanOrEqual(column);\n\t\texpect(previous.getBoundingClientRect().width).toBeGreaterThan(column - 80);\n\t\texpect(caption.color).toBe(\"rgb(10, 11, 12)\");\n\t\texpect(caption.fontSize).toBe(\"15px\");\n\t\texpect(status.color).toBe(\"rgb(13, 14, 15)\");\n\t});\n\n\ttest(\"sets the links' weight and hover colour from custom properties on the root\", async () => {\n\t\tlet nav = mount(\n\t\t\t<Pager\n\t\t\t\tmix={[\n\t\t\t\t\traw({\n\t\t\t\t\t\t\"--ui-pager-link-fg\": \"rgb(1, 2, 3)\",\n\t\t\t\t\t\t\"--ui-pager-link-font-weight\": \"800\",\n\t\t\t\t\t\t\"--ui-pager-link-hover-fg\": \"rgb(16, 17, 18)\",\n\t\t\t\t\t} satisfies Pager.CustomProperties),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet next = link(nav, \"next\")!;\n\n\t\texpect(getComputedStyle(next).fontWeight).toBe(\"800\");\n\t\texpect(getComputedStyle(next).color).toBe(\"rgb(1, 2, 3)\");\n\t\tawait userEvent.hover(next);\n\t\tfor (let animation of document.getAnimations()) animation.finish();\n\t\texpect(getComputedStyle(next).color).toBe(\"rgb(16, 17, 18)\");\n\t});\n\n\ttest(\"keeps a medium weight and its colour under the pointer by default\", async () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet next = link(nav, \"next\")!;\n\t\tlet resting = getComputedStyle(next).color;\n\n\t\texpect(getComputedStyle(next).fontWeight).toBe(\"500\");\n\t\tawait userEvent.hover(next);\n\t\tfor (let animation of document.getAnimations()) animation.finish();\n\t\texpect(getComputedStyle(next).color).toBe(resting);\n\t});\n\n\ttest(\"lets a caller's data-slot name the root\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager {...{ \"data-slot\": \"post-pager\" }}>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\n\t\texpect(nav.dataset.slot).toBe(\"post-pager\");\n\t});\n\n\ttest(\"stacks previous above next, each full width, in a pager under 30rem\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager>\n\t\t\t\t<Newer />\n\t\t\t\t<Pager.Status>Page 2 of 5</Pager.Status>\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t\t320,\n\t\t);\n\t\tlet row = nav.getBoundingClientRect();\n\t\tlet previous = link(nav, \"previous\")!.getBoundingClientRect();\n\t\tlet status = nav.querySelector('[data-slot=\"pager-status\"]')!.getBoundingClientRect();\n\t\tlet next = link(nav, \"next\")!.getBoundingClientRect();\n\n\t\texpect(nav.dataset.pagerLayout).toBe(\"auto\");\n\t\texpect(previous.width).toBeCloseTo(row.width, 0);\n\t\texpect(next.width).toBeCloseTo(row.width, 0);\n\t\texpect(previous.bottom).toBeLessThanOrEqual(status.top);\n\t\texpect(status.bottom).toBeLessThanOrEqual(next.top);\n\t});\n\n\ttest(\"stacks the links at any width with layout stack\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager layout=\"stack\">\n\t\t\t\t<Newer />\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t);\n\t\tlet previous = link(nav, \"previous\")!.getBoundingClientRect();\n\t\tlet next = link(nav, \"next\")!.getBoundingClientRect();\n\n\t\texpect(previous.width).toBeCloseTo(600, 0);\n\t\texpect(next.width).toBeCloseTo(600, 0);\n\t\texpect(previous.bottom).toBeLessThanOrEqual(next.top);\n\t});\n\n\ttest(\"keeps one row in a narrow pager with layout row\", () => {\n\t\tlet nav = mount(\n\t\t\t<Pager layout=\"row\">\n\t\t\t\t<Newer />\n\t\t\t\t<Older />\n\t\t\t</Pager>,\n\t\t\t320,\n\t\t);\n\t\tlet previous = link(nav, \"previous\")!.getBoundingClientRect();\n\t\tlet next = link(nav, \"next\")!.getBoundingClientRect();\n\n\t\texpect(previous.top).toBeCloseTo(next.top, 0);\n\t\texpect(previous.left).toBeCloseTo(nav.getBoundingClientRect().left, 0);\n\t\texpect(next.right).toBeCloseTo(nav.getBoundingClientRect().right, 0);\n\t\texpect(getComputedStyle(nav).containerType).toBe(\"normal\");\n\t});\n\n\ttest(\"draws a link alone with the default layout's styles\", () => {\n\t\tlet host = document.createElement(\"div\");\n\t\tdocument.body.appendChild(host);\n\t\tmounted = render(<Pager.Next href=\"/next\">Next</Pager.Next>, { container: host });\n\t\tlet next = host.querySelector<HTMLAnchorElement>('[data-slot=\"pager-next\"]')!;\n\n\t\texpect(next.getAttribute(\"rel\")).toBe(\"next\");\n\t\texpect(getComputedStyle(next).borderTopWidth).toBe(\"1px\");\n\t});\n});\n"
15
+ }
16
+ }