@sdxc/kit 2026.11.25 → 2026.11.27
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.
- package/changelog.jsonl +16 -0
- package/package.json +2 -2
- package/registry/ui/lightbox.json +3 -3
- package/registry/ui/slider.json +2 -2
package/changelog.jsonl
CHANGED
|
@@ -465,6 +465,7 @@
|
|
|
465
465
|
{"release":"2026.10.2","package":"@sdxc/billing","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
466
466
|
{"release":"2026.10.2","package":"@sdxc/blueprint","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
467
467
|
{"release":"2026.10.2","package":"@sdxc/bracket-params","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
468
|
+
{"release":"2026.10.2","package":"@sdxc/bytes","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
468
469
|
{"release":"2026.10.2","package":"@sdxc/cache","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
469
470
|
{"release":"2026.10.2","package":"@sdxc/captcha","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
470
471
|
{"release":"2026.10.2","package":"@sdxc/catch-response-middleware","type":"chore","breaking":false,"title":"Update Remix to 3.0.0","body":"Remix 3 is stable. Every workspace now pins `remix@3.0.0`, and\n`@remix-run/data-schema` moves to `^1.0.0`.\n\nThe component runtime moved from `remix/ui` to `remix/component`, along with\nits subpaths (`remix/component/server`, `remix/component/test`, the JSX\nruntimes), so every import and every `jsxImportSource` now points there.\n\nThe headless primitives (`anchor`, `combobox`, `listbox`, `tabs`) are no\nlonger part of `remix`. They ship in the standalone `@remix-run/ui` package,\npinned at 0.12.1, which `@sdxc/ui` and the sdxc app now depend on directly."}
|
|
@@ -2233,3 +2234,18 @@
|
|
|
2233
2234
|
{"release":"2026.11.24","package":"@sdxc/seo","type":"fix","breaking":false,"title":"Write the card image's alt text for X as well","body":"Before: Seo.Meta wrote og.imageAlt only as og:image:alt, which X does not read, so a card\nshared there had no description for screen-reader users. After: the same text is also written as\ntwitter:image:alt whenever the card has an image. Consumers that already pass og.imageAlt get the\nextra tag with no change; nothing else in the output changes."}
|
|
2234
2235
|
{"release":"2026.11.25","package":"@sdxc/novel","type":"feat","breaking":false,"title":"Describe the cast and show it on a Characters screen","body":"`character()` takes a `description` message key, and a new `Characters`\nlibrary screen lists the cast beside the chosen character's portrait, name,\ndescription and every look the stage drew them in:\n\n export const CAST = cast({\n mika: character({\n name: \"cast.mika\",\n description: \"cast.mikaAbout\",\n sprites: { smile: \"/mika/smile.webp\", sad: \"/mika/sad.webp\" },\n }),\n });\n\n <NovelPlayer.Extras>\n <Gallery />\n <Characters />\n </NovelPlayer.Extras>\n\nA character shows as the `unknownName` label, and cannot be picked, until\nthey are `known` or a play introduces them. A sprite stays a locked\nplaceholder until the stage draws the character in it once, in any\nplaythrough; a layered character lists each combination of variants the\nstage drew. Its dialog is wider than the other library screens'.\n\n`NovelPlayer.Default` offers the screen in its Extras menu, and\n`NovelPlayer.Title` adds it to its default screens (Chapters, Gallery,\nCharacters, Memories). When the player offers the screen, a named speaker's\nname on the textbox is a button that opens it on them, through the new\n`showCharacter(id)` on the player context (`character` reads the id it asked\nfor).\n\n`Persistent.unlocked` gains `sprites`, the looks the stage drew, keyed\n`<character>:<sprite>` or `<character>:<layer>=<variant>,…`; stored data\nwithout it reads as none seen. `NovelLibrary` gains `characters`, and\n`NovelLabels` gains `characters` and `characterLooks`. A custom title that\npasses its own screens is unchanged; one relying on the defaults now shows a\nCharacters button."}
|
|
2235
2236
|
{"release":"2026.11.25","package":"@sdxc/workers-cache","type":"fix","breaking":false,"title":"Downgrade session-bearing requests without throwing in development","body":"Before: in development (`NODE_ENV=development`, or a request to a local host), the\n`@sdxc/workers-cache` middleware threw `UnsafeCachePolicyError` whenever a page that\ndeclared a public policy, or a targeted CDN lifetime, was requested with a session. A\ndeveloper signed in to their own app saw an error overlay over every public page.\n\nAfter: only a declared response that carries its own `Set-Cookie` throws in development.\nA request that brings a session is downgraded to `private, no-store` and logged as\n`cache.downgraded` (reason `session-with-public-policy` or\n`session-with-shared-targeted-policy`), the same way it always was in production, so the\npage renders uncached for the signed-in visitor.\n\nProduction behavior is unchanged and consumers need no action. Code that caught\n`UnsafeCachePolicyError` in development to detect a session refusal should read the\n`cache.downgraded` log field instead."}
|
|
2237
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"feat","breaking":false,"title":"Tab the settings screen and add a way back to the title","body":"The settings screen is now a wide dialog with Text, Sound and Accessibility tabs. Each row shows the setting's name, its current value (`40/s`, `1 sec`, `80%`) and its control. Under the text speed, a sample line types at the chosen speed, and Reset settings and Back buttons close the screen. `NovelPlayer.Settings` keeps its props, so no change is needed to use it.\n\nThe quick menu also gains a Title button whenever the player has a title screen (`NovelPlayer.Default` with `titleScreen`). It leaves the play and returns to the title, where Continue picks up from the latest save.\n\nRestyle the settings screen through new theme variables: `--novel-settings-panel-background`, `-panel-color`, `-panel-padding`, `-divider`, `-readout-color`, `-tab-background`, `-tab-selected-background`, `-tab-color`, `-tab-selected-color`, `-tab-border`, `-tab-radius`, `-tab-font`, `-preview-background` and `-preview-color`. Its parts carry `data-novel-settings-tab`, `data-novel-settings-panel`, `data-novel-setting`, `data-novel-setting-readout`, `data-novel-settings-preview`, `data-novel-settings-reset` and `data-novel-settings-back`:\n\n css({\n \"--novel-settings-panel-background\": \"#f3ead6\",\n \"--novel-settings-tab-border\": \"1px solid #d4b06a\",\n })\n\nNew labels translate the new words: `settingsText`, `settingsSound`, `settingsAccessibility`, `textPreview`, `textInstant`, `resetSettings`, `back` and `toTitle`. `SettingRow` is exported for a custom screen, and `RangeSetting` takes an optional `readout` and now renders a full row.\n\nA settings screen test that clicks a control must first open that control's tab, since only the open tab's rows are visible."}
|
|
2238
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"feat","breaking":false,"title":"Keep an encyclopedia of what the reader has learned","body":"A novel can now declare an encyclopedia of topics, such as places, magic or terms. Each topic holds entries the reader learns as the story goes. The new `Encyclopedia` screen gathers them in one book, along with the cast, the CGs and the music.\n\nDeclare it with `encyclopedia()`, `topic()` and `entry()`, and pass it to `createNovel`:\n\n export const LORE = encyclopedia({\n places: topic({\n name: \"lore.places\",\n entries: {\n pier: entry({\n title: \"lore.pier.title\",\n summary: \"lore.pier.summary\",\n body: \"lore.pier.body\",\n sections: [{ title: \"lore.pier.historyTitle\", body: \"lore.pier.history\" }],\n }),\n },\n }),\n });\n createNovel({ ..., encyclopedia: LORE });\n\nAn entry stays hidden until a scene runs `ctx.learn(LORE.places.entries.pier)`, unless it is declared with `known: true`. Persistent data records it in the new `unlocked.entries` list, and the novel emits `unlock` with `kind: \"entry\"`, which the player shows as a \"New entry: <title>\" toast. `check()` reports an entry the novel does not declare.\n\n`<Encyclopedia />` has pages for every learned entry (with its topic), the characters, each topic, the gallery and the music room. `pages` picks and orders them, for example `pages={[\"characters\", \"places\", \"gallery\"]}`. A topic page has a search field and opens the chosen entry beside the list: its topic, title, summary, a Contents disclosure and numbered sections.\n\nThe default menus change:\n- `NovelPlayer.Default`'s extras menu offers Memories, Encyclopedia, Endings, Chapters and Scene replay. Gallery, Characters and the Music room now live inside the encyclopedia.\n- The title screen's defaults are Chapters, Encyclopedia and Memories.\n- A speaker's name in the textbox opens the encyclopedia on that character.\n\nTo keep the old screens, pass them as children of `NovelPlayer.Extras` or `screens` on the title.\n\nNew labels: `encyclopedia`, `encyclopediaAll`, `search`, `contents`, `noEntries` and `entryUnlocked`. New theme variables: `--novel-encyclopedia-page-padding`, `--novel-encyclopedia-current-background` and `--novel-encyclopedia-current-color`. Code that builds a `Persistent` value by hand must add `entries: []` to `unlocked`."}
|
|
2239
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"fix","breaking":false,"title":"Leave the empty All entries page out of an encyclopedia without topics","body":"Before, a novel that declared no encyclopedia still opened the Encyclopedia on an All entries page that could only say \"Nothing learned yet.\" Now that page appears only when the novel declares topics, so such a novel's encyclopedia opens on Characters, then Gallery and Music room. No consumer action is needed."}
|
|
2240
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"feat","breaking":false,"title":"Grow a character's bio as the story reveals them","body":"A character can now declare a `bio` of titled sections. The characters screen, inside the encyclopedia or on its own, lists them numbered below the description. Each section stays hidden until a scene teaches it, so a character's page fills in as the story reveals who they are:\n\n harry: character({\n name: \"cast.harry\",\n description: \"about.harry\",\n bio: {\n raised: { title: \"bio.harry.raised\", body: \"bio.harry.raisedText\", known: true },\n scar: { title: \"bio.harry.scar\", body: \"bio.harry.scarText\" },\n },\n sprites: { … },\n })\n\n ctx.learn(CAST.harry, \"scar\")\n\n`learn(character, section)` works like `learn(entry)`. It records `harry:scar` in the new `unlocked.bios` list of persistent data, emits `unlock` with `kind: \"bio\"`, and shows a \"New entry: Harry\" toast the first time. A section declared `known: true` shows as soon as the reader meets the character. `check()` and the play both report a section the character does not declare. The new `bioKey(character, section)` names a section as persistent data records it.\n\nCode that builds a `Persistent` value by hand must add `bios: []` to `unlocked`. Code that switches over every `Directive` gets a new `LearnBioDirective` (`type: \"learnBio\"`), and `UnlockEvent.kind` gains `\"bio\"`."}
|
|
2241
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"fix","breaking":false,"title":"Include the Encyclopedia component in the package","body":"Before, @sdxc/novel/ui exported Encyclopedia from a module the package did not include, so importing @sdxc/novel/ui failed to resolve ./ui/encyclopedia.js and any app that bundled it failed to build. The package now ships the module, and importing @sdxc/novel/ui works again. Consumers need only upgrade."}
|
|
2242
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"fix","breaking":false,"title":"Show the settings sliders' rail and keep a chosen look's outline whole","body":"Before, the settings screen's sliders drew their rail in the UI theme's border token, which\nunder a dark system theme is a faint white that disappears on a light settings panel, so a\nslider at zero showed only its thumb. The encyclopedia's character page also clipped the\noutline around the chosen look at the edge of its scrolling column.\n\nNow each slider draws its rail in `--novel-settings-slider-track` and its filled part in\n`--novel-settings-slider-fill` (the accent color by default), and the looks list leaves room\nfor the outline. Set the two variables to match a custom settings panel:\n\n css({\n \"--novel-settings-slider-track\": \"rgb(122 96 52 / 0.25)\",\n \"--novel-settings-slider-fill\": \"#9c7630\",\n })\n\nNo other action is needed."}
|
|
2243
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"feat","breaking":false,"title":"Play hover and select sounds on the interface","body":"The player and the title screen can now play a sound as the reader reaches an option, by\npointer, keyboard or gamepad, and another as they pick one. Pass any declared sound assets:\n\n <NovelPlayer.Default\n novel={novel}\n sounds={{ hover: ASSETS.sounds.hover, select: ASSETS.sounds.select }}\n />\n\n`NovelPlayer.Title` takes the same `sounds` prop. Clicking the stage to advance stays silent,\nand a pick that opens a dialog or swaps the screen sounds once. The sounds play on a new\n`interface` mixer channel, which the settings screen lists as \"Interface\" (label\n`volumeInterface`, default volume 0.6), and `AudioMixer#playInterface(source)` plays one.\n\n`AudioChannel` and `NovelSettings[\"volume\"]` gain `interface`: code that builds a full volume\nrecord by hand adds `interface: <0..1>`. Stored settings without it take the default."}
|
|
2244
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"feat","breaking":true,"title":"Group a character's known and listed flags under lore, and polish the encyclopedia","body":"`character()` takes `known` inside a new `lore` option, beside a new `listed` flag:\n\nBefore:\n\n mika: character({ name: \"cast.mika\", known: true, sprites })\n\nAfter:\n\n mika: character({ name: \"cast.mika\", lore: { known: true }, sprites })\n\nMigrate every `known: true` on a character to `lore: { known: true }`. Encyclopedia entries and\nbio sections keep their own `known`. `lore: { listed: false }` leaves a passer-by, such as \"a\nprefect\", off the Characters page.\n\nThe encyclopedia and the library screens also change:\n\n- The Characters page lists only the characters the reader met in any play: introduced, heard\n speaking a line the reader read, or drawn on stage. `LibraryCharacter.met` follows the same\n rule, so a character declared `lore: { known: true }` who never appeared is no longer listed,\n and unmet characters no longer show as \"???\" rows.\n- On the Characters page only the list and the bio column scroll; the portrait stays in view.\n- The Gallery and the Music room (and `readLibrary`'s `images` and `music`) follow the order the\n story first shows and plays them, with unused assets last.\n- The encyclopedia leaves out its Gallery and Music room pages when the novel declares no images\n or no tracks.\n- CG tiles, a character's looks and chapter cards share one frame, locked or not, drawn from\n `--novel-library-frame`, `--novel-library-radius`, `--novel-library-locked-background` and\n `--novel-library-locked-color`.\n- Entry section headings are aligned with the text instead of centred.\n- Clicking a \"New entry\" toast opens that entry, and a bio toast that character's page. A toast\n takes `opens: { entry }` or `opens: { character }`, and the player context gains\n `showEntry(id)` and `entry`.\n- A right click on the stage hides the interface, and another brings it back.\n- The settings sliders draw their empty part as a thin line in `--novel-settings-slider-track`,\n `--novel-settings-slider-track-thickness` (default `2px`) thick.\n\n`Characters`' `labels` no longer takes `unknownName`."}
|
|
2245
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"fix","breaking":false,"title":"Keep the settings screen one size across tabs, and show its switches","body":"Before, the settings screen took each tab's height, so switching tabs resized the dialog and\nmoved the tab buttons under the pointer. Its switches also drew their track in the UI theme's\ntokens, which a dark theme turned into a faint white that vanished on a light settings panel,\nleaving only the thumb.\n\nNow every tab shares the tallest tab's size, so the tabs never move, and the switches draw their\ntrack in `--novel-settings-switch-off` and `--novel-settings-switch-on` and their thumb in\n`--novel-settings-switch-thumb`. No action is needed; set the three variables to match a custom\nsettings panel."}
|
|
2246
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"feat","breaking":false,"title":"Add a full screen button to the title screen","body":"`NovelPlayer.Title`, and so `NovelPlayer.Default`'s title screen, shows a button in its bottom\ncorner that enters and leaves full screen, where the browser allows it. It fills the screen with\nthe box the title sits in; a player with a title screen now does the same from its quick menu,\nso starting a game or going back to the title stays in full screen.\n\nRestyle the button with `--novel-title-fullscreen-inset`, `-size`, `-border`, `-radius`,\n`-background` and `-color`, or through `[data-novel-title-fullscreen]`. No action is needed."}
|
|
2247
|
+
{"release":"2026.11.26","package":"@sdxc/novel","type":"fix","breaking":false,"title":"Start the settings preview's typing once it is on the page","body":"Before, the settings screen's text preview started its typing timer while rendering, so a\nserver render of a player (a docs page that embeds one, for example) left a timer running\nthat later tried to update a component that never mounted, logging \"Cannot call\nhandle.update() before TextPreview's initial render commits\".\n\nNow the preview starts typing after it mounts in the browser, and a server render draws the\nline at rest with no timer. No action is needed."}
|
|
2248
|
+
{"release":"2026.11.26","package":"@sdxc/ui","type":"fix","breaking":false,"title":"Center the slider thumb on its rail in Chrome and Safari","body":"Before, a `Slider` whose pointer target (`--ui-target-size`, 1.5rem by default) was taller than\nits thumb drew the thumb high in Chrome and Safari: WebKit placed it at the top of the grown\nnative input, about 2px above the rail at the default sizes and more for larger targets.\n\nNow the thumb sits on the rail's centre line in every browser, at any thumb and target size. No\naction is needed."}
|
|
2249
|
+
{"release":"2026.11.27","package":"@sdxc/bytes","type":"feat","breaking":false,"title":"Add typed byte size strings converted to bytes","body":"New package @sdxc/bytes. Write a size limit as \"10 MiB\" instead of\n10 * 1024 * 1024, with the unit checked at compile time:\n\n import { toBytes, toBytesBigInt, parse } from \"@sdxc/bytes\";\n\n const MAX_UPLOAD_BYTES = toBytes(\"10 MiB\"); // 10485760\n toBytes(\"10 MB\"); // 10000000\n toBytes(\"10 klobyes\"); // type error\n toBytesBigInt(\"2 EiB\"); // 2305843009213693952n\n\n let result = parse(env.MAX_UPLOAD_SIZE ?? \"\"); // Result<number, InvalidByteSizeError>\n\nMB, GB and the other plain symbols count in powers of 1000, and MiB, GiB\nand the other \"i\" symbols in powers of 1024. KB is rejected because it\nmeans either, so write kB or KiB. Symbols take an optional space (\"10MB\",\n\"10 MB\"), unit names need one (\"10 megabytes\"), and amounts are whole.\n\ntoBytes() and parse() cover B through PB/PiB and fail past\nNumber.MAX_SAFE_INTEGER. toBytesBigInt() and parseBigInt() are exact at\nany size and add EB, ZB, YB, EiB, ZiB and YiB. Declare ByteSizeInput or\nBigByteSizeInput in your own APIs to accept either a string or a raw count."}
|
|
2250
|
+
{"release":"2026.11.27","package":"@sdxc/novel","type":"fix","breaking":false,"title":"Draw the dialogs' close button in the dialog's text color","body":"Before, the close button of every player dialog (settings, saves, backlog and the library\nscreens) drew its X in the default neutral ink, so on a dark `--novel-dialog-background` the\nglyph stayed invisible until the pointer hovered it. Now the X takes `--novel-dialog-color`, and\nits hover and press tints mix from that color, so the button reads on light and dark themes\nalike. No action is needed: a theme that already sets `--novel-dialog-color` gets a visible\nclose button on upgrade."}
|
|
2251
|
+
{"release":"2026.11.27","package":"@sdxc/ui","type":"fix","breaking":false,"title":"Keep Lightbox's counter on its own line on a narrow viewer","body":"Before, on a viewer narrower than 48rem a slide's counter and caption shared\none wrapping row: a short caption sat beside the counter and a long one\ndropped below it, so the footer changed from one line to two between slides\nand the photo above resized as the reader stepped through. Now a narrow\nviewer always sets the counter above the caption, and a wider one keeps them\nside by side. No action needed."}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/kit",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.27",
|
|
4
4
|
"description": "The sdxc command line: start a Remix v3 app, generate its files, copy UI components into it and upgrade it",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"remix": "3.2.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a02e72f0baabdf2cda53d1a3f32ef2449a59650d",
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightbox",
|
|
3
|
-
"changedIn": "2026.11.
|
|
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
|
|
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
|
}
|
package/registry/ui/slider.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slider",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.26",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Slider"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "slider.tsx",
|
|
10
|
-
"content": "/**\n * A single-value range control built on a native `<input type=\"range\">`,\n * paired with a track that draws its own background rail and a live fill\n * bar, plus an `<output>` for reporting the current value. The root shares\n * the resolved range and value with every part through component context,\n * so a track's fill bar and a thumb's native attributes always agree\n * without a consumer repeating the same numbers twice.\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 {\n\tabsolute,\n\tafter,\n\tappearance,\n\tbasis,\n\tbefore,\n\tbg,\n\tborder,\n\tbs,\n\tcursor,\n\tgrow,\n\tinsBe,\n\tinsBs,\n\tinsIe,\n\tinsIs,\n\tinset,\n\tis,\n\titems,\n\tm,\n\tminBs,\n\tminIs,\n\toutlineStyle,\n\tpseudoContent,\n\traw,\n\trelative,\n\trounded,\n\tshrink,\n\ttabularNums,\n\ttranslateX,\n\ttranslateY,\n\tvstack,\n\twhen,\n\tz,\n} from \"@sdxc/u\";\nimport { mergeMix } from \"@sdxc/u/general\";\n\nimport { outputCaptionText } from \"@sdxc/ui/styles\";\nimport { rangeThumbAppearance } from \"@sdxc/ui/styles\";\nimport { mergeStyle } from \"@sdxc/ui/utils\";\nimport { resolveFillPercent } from \"@sdxc/ui/utils\";\n\n/** Default {@link Slider.Props} orientation, applied when `orientation` is omitted. */\nconst DEFAULT_ORIENTATION: Slider.Orientation = \"horizontal\";\n\n/** Default {@link Slider.Props} lower bound, applied when `min` is omitted. */\nconst DEFAULT_MIN = 0;\n\n/** Default {@link Slider.Props} upper bound, applied when `max` is omitted. */\nconst DEFAULT_MAX = 100;\n\n/** Default {@link Slider.ThumbProps} step, applied when `step` is omitted. */\nconst DEFAULT_STEP = 1;\n\n/**\n * Negative inset growing {@link Slider.Thumb}'s native input across the track's thin\n * axis to the larger of the thumb and `--ui-target-size`, clamped at zero so a track\n * already that thick keeps its own box.\n */\nconst THUMB_HIT_INSET =\n\t\"min(0px, calc((100% - max(var(--ui-slider-thumb-size, 1.25rem), var(--ui-target-size, 1.5rem))) / 2))\";\n\n/**\n * Prop types for {@link Slider} and its compound parts.\n */\nexport namespace Slider {\n\t/**\n\t * Axis the track's fill bar and thumb travel along: a full-width row, or\n\t * a full-height column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Value {@link Slider} shares through component context so every nested\n\t * {@link Slider.Track}, {@link Slider.Thumb}, and {@link Slider.Output}\n\t * reads the same resolved range, value, orientation, and thumb id.\n\t */\n\texport interface Context {\n\t\t/** Resolved lower bound of the range, shared with {@link Slider.Thumb}. */\n\t\tmin: number;\n\t\t/** Resolved upper bound of the range, shared with {@link Slider.Thumb}. */\n\t\tmax: number;\n\t\t/** Resolved current value, used to compute {@link Slider.Track}'s fill bar and default {@link Slider.Thumb}'s own value. */\n\t\tvalue: number;\n\t\t/** Layout axis, read by {@link Slider.Thumb} to set its accessible orientation. */\n\t\torientation: Orientation;\n\t\t/**\n\t\t * Id shared by {@link Slider.Thumb} (as its own `id`) and\n\t\t * {@link Slider.Output} (as its `htmlFor`) so the two associate\n\t\t * natively without either needing an explicit id from the consumer.\n\t\t */\n\t\tthumbId: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link Slider}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t\t/** Lower bound of the range. Defaults to {@link DEFAULT_MIN}. */\n\t\tmin?: number;\n\t\t/** Upper bound of the range. Defaults to {@link DEFAULT_MAX}. */\n\t\tmax?: number;\n\t\t/** Current value, for a slider whose value the consumer tracks itself. */\n\t\tvalue?: number;\n\t\t/** Starting value, for a slider that never tracks its own value. */\n\t\tdefaultValue?: number;\n\t}\n\n\t/**\n\t * Props accepted by {@link Slider.Track}.\n\t */\n\texport interface TrackProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<input>` attribute except `type` and `role`, fixed to\n\t * `\"range\"` and the platform's implicit `\"slider\"` role. `min`/`max`/`step`\n\t * override the range inherited from the nearest ancestor {@link Slider}.\n\t */\n\texport interface ThumbProps extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {}\n\n\t/**\n\t * Props accepted by {@link Slider.Output}.\n\t */\n\texport interface OutputProps extends TagProps<\"output\"> {}\n}\n\n/**\n * Renders the root `<div>`, stacking its children and resolving range, value, orientation\n * and thumb id into context. Nested parts scope orientation rules to its `data-slot`, so an\n * ancestor carrying `data-orientation` (a toolbar, a scroll viewport) leaves its layout alone.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link Slider.Context}.\n * @returns The render function producing the root's markup.\n * @example\n * <Slider aria-label={t(\"settings.volume\")} min={0} max={100} defaultValue={40}>\n * \t<Slider.Output />\n * \t<Slider.Track>\n * \t\t<Slider.Thumb />\n * \t</Slider.Track>\n * </Slider>\n * @example\n * <Slider orientation=\"vertical\" min={0} max={10} defaultValue={6}>\n * \t<Slider.Track>\n * \t\t<Slider.Thumb aria-label={t(\"equalizer.band\", { hz: 250 })} />\n * \t</Slider.Track>\n * </Slider>\n */\nexport function Slider(handle: Handle<Slider.Props, Slider.Context>) {\n\treturn () => {\n\t\tlet { orientation, min, max, value, defaultValue, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\t\tlet resolvedMin = min ?? DEFAULT_MIN;\n\t\tlet resolvedMax = max ?? DEFAULT_MAX;\n\t\tlet resolvedValue = value ?? defaultValue ?? resolvedMin;\n\n\t\thandle.context.set({\n\t\t\tmin: resolvedMin,\n\t\t\tmax: resolvedMax,\n\t\t\tvalue: resolvedValue,\n\t\t\torientation: resolvedOrientation,\n\t\t\tthumbId: handle.id,\n\t\t});\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"slider\"\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tvstack({ gap: \"0.5rem\" }),\n\t\t\t\t\t\twhen('&[data-orientation=\"horizontal\"]', [is(\"100%\"), minIs(\"10rem\")]),\n\t\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [bs(\"10rem\"), items(\"center\")]),\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 the visual track: a `position: relative` `<div>` that draws a rail\n * and fill bar as pseudo-elements sized from context's resolved value, and\n * overlays a nested {@link Slider.Thumb} so native drag spans its full length.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the track's markup.\n * @example\n * <Slider.Track>\n * \t<Slider.Thumb />\n * </Slider.Track>\n */\nSlider.Track = function SliderTrack(handle: Handle<Slider.TrackProps>) {\n\treturn () => {\n\t\tlet { mix, style, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Slider);\n\t\tlet fillPercent = resolveFillPercent(context.min, context.max, context.value);\n\t\tlet resolvedStyle = mergeStyle(style, { \"--ui-slider-fill\": `${fillPercent}%` });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tstyle={resolvedStyle}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\twhen('[data-orientation=\"horizontal\"] &', [\n\t\t\t\t\t\t\tis(\"100%\"),\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-thumb-size, 1.25rem)\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &', [\n\t\t\t\t\t\t\tis(\"var(--ui-slider-thumb-size, 1.25rem)\"),\n\t\t\t\t\t\t\tminBs(\"0\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tbefore([absolute(), rounded(\"full\"), bg(\"neutral.border\"), pseudoContent('\"\"')]),\n\t\t\t\t\t\tafter([absolute(), rounded(\"full\"), bg(\"brand.solid\"), pseudoContent('\"\"')]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &', [\n\t\t\t\t\t\t\tgrow(),\n\t\t\t\t\t\t\tshrink(1),\n\t\t\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-orientation=\"horizontal\"] &::before', [\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\t\tinsIe(\"0\"),\n\t\t\t\t\t\t\tinsBs(\"50%\"),\n\t\t\t\t\t\t\ttranslateY(\"-50%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-orientation=\"horizontal\"] &::after', [\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tis(\"var(--ui-slider-fill, 0%)\"),\n\t\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\t\tinsBs(\"50%\"),\n\t\t\t\t\t\t\ttranslateY(\"-50%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &::before', [\n\t\t\t\t\t\t\tis(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tbs(\"100%\"),\n\t\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\t\tinsIs(\"50%\"),\n\t\t\t\t\t\t\ttranslateX(\"-50%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &::after', [\n\t\t\t\t\t\t\tis(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-fill, 0%)\"),\n\t\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\t\tinsIs(\"50%\"),\n\t\t\t\t\t\t\ttranslateX(\"-50%\"),\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 * Renders the interactive thumb: a native `<input type=\"range\">` reset to\n * cover {@link Slider.Track}'s full box so native drag and keyboard control\n * span its whole length, rotating with `writing-mode` when vertical.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the thumb's markup.\n * @example\n * <Slider.Thumb aria-label={t(\"settings.volume\")} />\n * @example\n * <Slider.Thumb aria-label={t(\"settings.brightness\")} disabled />\n */\nSlider.Thumb = function SliderThumb(handle: Handle<Slider.ThumbProps>) {\n\treturn () => {\n\t\tlet { id, min, max, step, value, defaultValue, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Slider);\n\t\tlet resolvedStep = step ?? DEFAULT_STEP;\n\t\tlet resolvedValue = value ?? defaultValue ?? context.value;\n\n\t\treturn (\n\t\t\t<input\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"range\"\n\t\t\t\tid={id ?? context.thumbId}\n\t\t\t\tmin={min ?? context.min}\n\t\t\t\tmax={max ?? context.max}\n\t\t\t\tstep={resolvedStep}\n\t\t\t\tdefaultValue={resolvedValue}\n\t\t\t\taria-orientation={context.orientation === \"vertical\" ? \"vertical\" : undefined}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trangeThumbAppearance(\"--ui-slider-thumb-size\", \"--ui-slider-thumb-border-width\"),\n\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\tinset(\"0\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The native input reaches past the track across its thin axis to a full pointer\n\t\t\t\t\t\t * target, centred so the thumb stays on the visible rail. Its block axis is that\n\t\t\t\t\t\t * thin axis in both orientations, since a vertical input runs `vertical-lr`.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tinsBs(THUMB_HIT_INSET),\n\t\t\t\t\t\tinsBe(THUMB_HIT_INSET),\n\t\t\t\t\t\tz(10),\n\t\t\t\t\t\tm(\"0\"),\n\t\t\t\t\t\tappearance(),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\n\t\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\t\twhen(\"&::-webkit-slider-runnable-track\", [appearance(), bs(\"100%\"), bg(\"transparent\")]),\n\t\t\t\t\t\twhen(\"&::-moz-range-track\", [\n\t\t\t\t\t\t\tappearance(),\n\t\t\t\t\t\t\tbs(\"100%\"),\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\tborder({ style: \"none\" }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'[data-slot=\"slider\"][data-orientation=\"vertical\"] &',\n\t\t\t\t\t\t\traw({ writingMode: \"vertical-lr\", direction: \"rtl\" }),\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 * Renders a live readout: a native `<output>` associated by default with\n * the nearest ancestor {@link Slider}'s thumb via `htmlFor`, so assistive\n * technology knows which control it reports on. Pass the value as `children`.\n *\n * @param handle Runtime handle carrying the host `<output>`'s props.\n * @returns The render function producing the readout's markup.\n * @example\n * <Slider.Output>{new Intl.NumberFormat(locale, { style: \"percent\" }).format(0.4)}</Slider.Output>\n */\nSlider.Output = function SliderOutput(handle: Handle<Slider.OutputProps>) {\n\treturn () => {\n\t\tlet { htmlFor, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Slider);\n\n\t\treturn (\n\t\t\t<output\n\t\t\t\t{...rest}\n\t\t\t\thtmlFor={htmlFor ?? context.thumbId}\n\t\t\t\tmix={mergeMix([outputCaptionText(), tabularNums()], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
10
|
+
"content": "/**\n * A single-value range control built on a native `<input type=\"range\">`,\n * paired with a track that draws its own background rail and a live fill\n * bar, plus an `<output>` for reporting the current value. The root shares\n * the resolved range and value with every part through component context,\n * so a track's fill bar and a thumb's native attributes always agree\n * without a consumer repeating the same numbers twice.\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 {\n\tabsolute,\n\tafter,\n\tappearance,\n\tbasis,\n\tbefore,\n\tbg,\n\tborder,\n\tbs,\n\tcursor,\n\tgrow,\n\tinsBe,\n\tinsBs,\n\tinsIe,\n\tinsIs,\n\tinset,\n\tis,\n\titems,\n\tm,\n\tminBs,\n\tminIs,\n\toutlineStyle,\n\tpseudoContent,\n\traw,\n\trelative,\n\trounded,\n\tshrink,\n\ttabularNums,\n\ttranslateX,\n\ttranslateY,\n\tvstack,\n\twhen,\n\tz,\n} from \"@sdxc/u\";\nimport { mergeMix } from \"@sdxc/u/general\";\n\nimport { outputCaptionText } from \"@sdxc/ui/styles\";\nimport { rangeThumbAppearance } from \"@sdxc/ui/styles\";\nimport { mergeStyle } from \"@sdxc/ui/utils\";\nimport { resolveFillPercent } from \"@sdxc/ui/utils\";\n\n/** Default {@link Slider.Props} orientation, applied when `orientation` is omitted. */\nconst DEFAULT_ORIENTATION: Slider.Orientation = \"horizontal\";\n\n/** Default {@link Slider.Props} lower bound, applied when `min` is omitted. */\nconst DEFAULT_MIN = 0;\n\n/** Default {@link Slider.Props} upper bound, applied when `max` is omitted. */\nconst DEFAULT_MAX = 100;\n\n/** Default {@link Slider.ThumbProps} step, applied when `step` is omitted. */\nconst DEFAULT_STEP = 1;\n\n/**\n * Negative inset growing {@link Slider.Thumb}'s native input across the track's thin\n * axis to the larger of the thumb and `--ui-target-size`, clamped at zero so a track\n * already that thick keeps its own box.\n */\nconst THUMB_HIT_INSET =\n\t\"min(0px, calc((100% - max(var(--ui-slider-thumb-size, 1.25rem), var(--ui-target-size, 1.5rem))) / 2))\";\n\n/**\n * How far WebKit's thumb moves down its input to sit on the rail's centre line: WebKit draws it at\n * the start of an input that {@link THUMB_HIT_INSET} grew past the thumb, so it takes half the\n * growth as margin. Firefox centres its thumb on its own.\n */\nconst THUMB_CENTER_OFFSET =\n\t\"calc((max(var(--ui-slider-thumb-size, 1.25rem), var(--ui-target-size, 1.5rem)) - var(--ui-slider-thumb-size, 1.25rem)) / 2)\";\n\n/**\n * Prop types for {@link Slider} and its compound parts.\n */\nexport namespace Slider {\n\t/**\n\t * Axis the track's fill bar and thumb travel along: a full-width row, or\n\t * a full-height column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Value {@link Slider} shares through component context so every nested\n\t * {@link Slider.Track}, {@link Slider.Thumb}, and {@link Slider.Output}\n\t * reads the same resolved range, value, orientation, and thumb id.\n\t */\n\texport interface Context {\n\t\t/** Resolved lower bound of the range, shared with {@link Slider.Thumb}. */\n\t\tmin: number;\n\t\t/** Resolved upper bound of the range, shared with {@link Slider.Thumb}. */\n\t\tmax: number;\n\t\t/** Resolved current value, used to compute {@link Slider.Track}'s fill bar and default {@link Slider.Thumb}'s own value. */\n\t\tvalue: number;\n\t\t/** Layout axis, read by {@link Slider.Thumb} to set its accessible orientation. */\n\t\torientation: Orientation;\n\t\t/**\n\t\t * Id shared by {@link Slider.Thumb} (as its own `id`) and\n\t\t * {@link Slider.Output} (as its `htmlFor`) so the two associate\n\t\t * natively without either needing an explicit id from the consumer.\n\t\t */\n\t\tthumbId: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link Slider}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t\t/** Lower bound of the range. Defaults to {@link DEFAULT_MIN}. */\n\t\tmin?: number;\n\t\t/** Upper bound of the range. Defaults to {@link DEFAULT_MAX}. */\n\t\tmax?: number;\n\t\t/** Current value, for a slider whose value the consumer tracks itself. */\n\t\tvalue?: number;\n\t\t/** Starting value, for a slider that never tracks its own value. */\n\t\tdefaultValue?: number;\n\t}\n\n\t/**\n\t * Props accepted by {@link Slider.Track}.\n\t */\n\texport interface TrackProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<input>` attribute except `type` and `role`, fixed to\n\t * `\"range\"` and the platform's implicit `\"slider\"` role. `min`/`max`/`step`\n\t * override the range inherited from the nearest ancestor {@link Slider}.\n\t */\n\texport interface ThumbProps extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {}\n\n\t/**\n\t * Props accepted by {@link Slider.Output}.\n\t */\n\texport interface OutputProps extends TagProps<\"output\"> {}\n}\n\n/**\n * Renders the root `<div>`, stacking its children and resolving range, value, orientation\n * and thumb id into context. Nested parts scope orientation rules to its `data-slot`, so an\n * ancestor carrying `data-orientation` (a toolbar, a scroll viewport) leaves its layout alone.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link Slider.Context}.\n * @returns The render function producing the root's markup.\n * @example\n * <Slider aria-label={t(\"settings.volume\")} min={0} max={100} defaultValue={40}>\n * \t<Slider.Output />\n * \t<Slider.Track>\n * \t\t<Slider.Thumb />\n * \t</Slider.Track>\n * </Slider>\n * @example\n * <Slider orientation=\"vertical\" min={0} max={10} defaultValue={6}>\n * \t<Slider.Track>\n * \t\t<Slider.Thumb aria-label={t(\"equalizer.band\", { hz: 250 })} />\n * \t</Slider.Track>\n * </Slider>\n */\nexport function Slider(handle: Handle<Slider.Props, Slider.Context>) {\n\treturn () => {\n\t\tlet { orientation, min, max, value, defaultValue, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\t\tlet resolvedMin = min ?? DEFAULT_MIN;\n\t\tlet resolvedMax = max ?? DEFAULT_MAX;\n\t\tlet resolvedValue = value ?? defaultValue ?? resolvedMin;\n\n\t\thandle.context.set({\n\t\t\tmin: resolvedMin,\n\t\t\tmax: resolvedMax,\n\t\t\tvalue: resolvedValue,\n\t\t\torientation: resolvedOrientation,\n\t\t\tthumbId: handle.id,\n\t\t});\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"slider\"\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tvstack({ gap: \"0.5rem\" }),\n\t\t\t\t\t\twhen('&[data-orientation=\"horizontal\"]', [is(\"100%\"), minIs(\"10rem\")]),\n\t\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [bs(\"10rem\"), items(\"center\")]),\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 the visual track: a `position: relative` `<div>` that draws a rail\n * and fill bar as pseudo-elements sized from context's resolved value, and\n * overlays a nested {@link Slider.Thumb} so native drag spans its full length.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the track's markup.\n * @example\n * <Slider.Track>\n * \t<Slider.Thumb />\n * </Slider.Track>\n */\nSlider.Track = function SliderTrack(handle: Handle<Slider.TrackProps>) {\n\treturn () => {\n\t\tlet { mix, style, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Slider);\n\t\tlet fillPercent = resolveFillPercent(context.min, context.max, context.value);\n\t\tlet resolvedStyle = mergeStyle(style, { \"--ui-slider-fill\": `${fillPercent}%` });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tstyle={resolvedStyle}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\twhen('[data-orientation=\"horizontal\"] &', [\n\t\t\t\t\t\t\tis(\"100%\"),\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-thumb-size, 1.25rem)\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &', [\n\t\t\t\t\t\t\tis(\"var(--ui-slider-thumb-size, 1.25rem)\"),\n\t\t\t\t\t\t\tminBs(\"0\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tbefore([absolute(), rounded(\"full\"), bg(\"neutral.border\"), pseudoContent('\"\"')]),\n\t\t\t\t\t\tafter([absolute(), rounded(\"full\"), bg(\"brand.solid\"), pseudoContent('\"\"')]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &', [\n\t\t\t\t\t\t\tgrow(),\n\t\t\t\t\t\t\tshrink(1),\n\t\t\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-orientation=\"horizontal\"] &::before', [\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\t\tinsIe(\"0\"),\n\t\t\t\t\t\t\tinsBs(\"50%\"),\n\t\t\t\t\t\t\ttranslateY(\"-50%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-orientation=\"horizontal\"] &::after', [\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tis(\"var(--ui-slider-fill, 0%)\"),\n\t\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\t\tinsBs(\"50%\"),\n\t\t\t\t\t\t\ttranslateY(\"-50%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &::before', [\n\t\t\t\t\t\t\tis(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tbs(\"100%\"),\n\t\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\t\tinsIs(\"50%\"),\n\t\t\t\t\t\t\ttranslateX(\"-50%\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('[data-slot=\"slider\"][data-orientation=\"vertical\"] &::after', [\n\t\t\t\t\t\t\tis(\"var(--ui-slider-track-thickness, 0.5rem)\"),\n\t\t\t\t\t\t\tbs(\"var(--ui-slider-fill, 0%)\"),\n\t\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\t\tinsIs(\"50%\"),\n\t\t\t\t\t\t\ttranslateX(\"-50%\"),\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 * Renders the interactive thumb: a native `<input type=\"range\">` reset to\n * cover {@link Slider.Track}'s full box so native drag and keyboard control\n * span its whole length, rotating with `writing-mode` when vertical.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the thumb's markup.\n * @example\n * <Slider.Thumb aria-label={t(\"settings.volume\")} />\n * @example\n * <Slider.Thumb aria-label={t(\"settings.brightness\")} disabled />\n */\nSlider.Thumb = function SliderThumb(handle: Handle<Slider.ThumbProps>) {\n\treturn () => {\n\t\tlet { id, min, max, step, value, defaultValue, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Slider);\n\t\tlet resolvedStep = step ?? DEFAULT_STEP;\n\t\tlet resolvedValue = value ?? defaultValue ?? context.value;\n\n\t\treturn (\n\t\t\t<input\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"range\"\n\t\t\t\tid={id ?? context.thumbId}\n\t\t\t\tmin={min ?? context.min}\n\t\t\t\tmax={max ?? context.max}\n\t\t\t\tstep={resolvedStep}\n\t\t\t\tdefaultValue={resolvedValue}\n\t\t\t\taria-orientation={context.orientation === \"vertical\" ? \"vertical\" : undefined}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trangeThumbAppearance(\"--ui-slider-thumb-size\", \"--ui-slider-thumb-border-width\"),\n\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\tinset(\"0\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The native input reaches past the track across its thin axis to a full pointer\n\t\t\t\t\t\t * target, centred so the thumb stays on the visible rail. Its block axis is that\n\t\t\t\t\t\t * thin axis in both orientations, since a vertical input runs `vertical-lr`.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tinsBs(THUMB_HIT_INSET),\n\t\t\t\t\t\tinsBe(THUMB_HIT_INSET),\n\t\t\t\t\t\tz(10),\n\t\t\t\t\t\tm(\"0\"),\n\t\t\t\t\t\tappearance(),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\n\t\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\t\twhen(\"&::-webkit-slider-runnable-track\", [appearance(), bs(\"100%\"), bg(\"transparent\")]),\n\t\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", raw({ marginBlockStart: THUMB_CENTER_OFFSET })),\n\t\t\t\t\t\twhen(\"&::-moz-range-track\", [\n\t\t\t\t\t\t\tappearance(),\n\t\t\t\t\t\t\tbs(\"100%\"),\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\tborder({ style: \"none\" }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'[data-slot=\"slider\"][data-orientation=\"vertical\"] &',\n\t\t\t\t\t\t\traw({ writingMode: \"vertical-lr\", direction: \"rtl\" }),\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 * Renders a live readout: a native `<output>` associated by default with\n * the nearest ancestor {@link Slider}'s thumb via `htmlFor`, so assistive\n * technology knows which control it reports on. Pass the value as `children`.\n *\n * @param handle Runtime handle carrying the host `<output>`'s props.\n * @returns The render function producing the readout's markup.\n * @example\n * <Slider.Output>{new Intl.NumberFormat(locale, { style: \"percent\" }).format(0.4)}</Slider.Output>\n */\nSlider.Output = function SliderOutput(handle: Handle<Slider.OutputProps>) {\n\treturn () => {\n\t\tlet { htmlFor, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Slider);\n\n\t\treturn (\n\t\t\t<output\n\t\t\t\t{...rest}\n\t\t\t\thtmlFor={htmlFor ?? context.thumbId}\n\t\t\t\tmix={mergeMix([outputCaptionText(), tabularNums()], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "slider.test.tsx",
|