@sdxc/kit 2026.11.18 → 2026.11.24

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.
@@ -28,8 +28,8 @@ export declare const LAYER_ORDER: readonly Layer[];
28
28
  export declare function layerOf(path: string): Layer | null;
29
29
  /**
30
30
  * Whether an import from `from` to `to` obeys the dependency rule. Unranked endpoints are left
31
- * alone so config and packages stay free to import, any layer reads a declaration module, and
32
- * an initializer reads the middleware its router's global chain lists.
31
+ * alone so config and packages stay free to import, any layer reads a declaration module or a
32
+ * message bundle, and an initializer reads the middleware its router's global chain lists.
33
33
  */
34
34
  export declare function allowsDependency(from: string, to: string): boolean;
35
35
  /** Whether `path` is a module that declares a runtime's jobs, commands, emails or MCP handlers. */
@@ -54,6 +54,11 @@ const DECLARATIONS = new Set([
54
54
  "app/mcp/tools/index.ts",
55
55
  "app/mcp/resources/index.ts",
56
56
  ]);
57
+ /**
58
+ * Where an app keeps its message bundles: data with no imports of their own, which the
59
+ * initializer that builds the translator and the code that types its keys both read.
60
+ */
61
+ const LOCALES = "resources/locales/";
57
62
  /** Where an app's own middleware lives, which the router initializer composes into its chain. */
58
63
  const MIDDLEWARE = "app/http/middleware/";
59
64
  /** Prefixes that assign a path to a layer, most specific first. */
@@ -88,14 +93,16 @@ export function layerOf(path) {
88
93
  }
89
94
  /**
90
95
  * Whether an import from `from` to `to` obeys the dependency rule. Unranked endpoints are left
91
- * alone so config and packages stay free to import, any layer reads a declaration module, and
92
- * an initializer reads the middleware its router's global chain lists.
96
+ * alone so config and packages stay free to import, any layer reads a declaration module or a
97
+ * message bundle, and an initializer reads the middleware its router's global chain lists.
93
98
  */
94
99
  export function allowsDependency(from, to) {
95
100
  let source = layerOf(from);
96
101
  let target = layerOf(to);
97
102
  if (source === null || target === null || isDeclaration(to))
98
103
  return true;
104
+ if (normalize(to).startsWith(LOCALES))
105
+ return true;
99
106
  if (source === "initializers" && normalize(to).startsWith(MIDDLEWARE))
100
107
  return true;
101
108
  return LAYER_RANK[source] <= LAYER_RANK[target];
@@ -78,7 +78,9 @@ export const PACKAGES_WITHOUT_COMMAND_LINES = [
78
78
  "diff",
79
79
  "digest-fields",
80
80
  "duration",
81
+ "emoji",
81
82
  "expression",
83
+ "facets",
82
84
  "feed",
83
85
  "file-storage-r2",
84
86
  "flags",
@@ -111,8 +113,11 @@ export const PACKAGES_WITHOUT_COMMAND_LINES = [
111
113
  "messaging",
112
114
  "microformats",
113
115
  "micropub",
116
+ "money",
117
+ "natural-dates",
114
118
  "newsletter",
115
119
  "no-www-middleware",
120
+ "novel",
116
121
  "opml",
117
122
  "outbound",
118
123
  "pagination",
@@ -139,6 +144,7 @@ export const PACKAGES_WITHOUT_COMMAND_LINES = [
139
144
  "spam",
140
145
  "strings",
141
146
  "structured-fields",
147
+ "synth",
142
148
  "trace-context",
143
149
  "trailing-slash-middleware",
144
150
  "types",
@@ -34,6 +34,8 @@ const OPENAPI_INITIALIZER = "app/initializers/openapi.ts";
34
34
  const STAGED = ["app", "routes", "tsconfig.json"];
35
35
  /** The copy a scaffold adds to, one file per language. */
36
36
  const LOCALES = "resources/locales";
37
+ /** A bundle file named by its language: JSON, or a module the app imports. */
38
+ const LOCALE_BUNDLE = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*\.(?:json|ts)$/;
37
39
  /**
38
40
  * Plans and writes the scaffold `input` describes in `project`, printing each file written and
39
41
  * edited and each package added; under `dryRun` it prints every file and the diff of every edit
@@ -605,8 +607,9 @@ function addOperations(source, names) {
605
607
  return withImport.replace(/\.add\(([^)]*)\)/, `.add(${[...args, ...names].join(", ")})`);
606
608
  }
607
609
  /**
608
- * The edit of every `resources/locales/*.json` that adds the resource's copy under its plural
609
- * key. A file that already has that key, or does not parse, stops the scaffold.
610
+ * The edit of every bundle in `resources/locales/`, JSON or a module default-exporting an
611
+ * object literal, that adds the resource's copy under its plural key. A file that already has
612
+ * that key, or whose object cannot be found, stops the scaffold.
610
613
  */
611
614
  async function localeEdits(root, resource) {
612
615
  let names = await wrap(() => readdir(join(root, LOCALES)));
@@ -614,19 +617,57 @@ async function localeEdits(root, resource) {
614
617
  return success([]);
615
618
  let key = resource.plural.key;
616
619
  let edits = [];
617
- for (let name of names.data.filter((entry) => entry.endsWith(".json")).sort()) {
620
+ for (let name of names.data.filter((entry) => LOCALE_BUNDLE.test(entry)).sort()) {
618
621
  let path = `${LOCALES}/${name}`;
619
622
  let before = await wrap(() => readFile(join(root, path), "utf8"));
620
623
  if (isFailure(before))
621
624
  return before;
622
- let parsed = wrap(() => JSON.parse(before.data));
623
- if (isFailure(parsed))
624
- return failure(new Error(`${path}: ${parsed.error.message}`));
625
- if (Object.hasOwn(parsed.data, key)) {
626
- return failure(new Error(`${path} already has "${key}"; sdxc scaffold leaves it as it is`));
627
- }
628
- let after = { ...parsed.data, [key]: localeBlock(resource) };
629
- edits.push({ path, before: before.data, after: `${JSON.stringify(after, null, "\t")}\n` });
625
+ let after = name.endsWith(".json")
626
+ ? jsonLocaleEdit(before.data, key, resource)
627
+ : moduleLocaleEdit(before.data, key, resource);
628
+ if (isFailure(after))
629
+ return failure(new Error(`${path}${after.error.message}`));
630
+ edits.push({ path, before: before.data, after: after.data });
630
631
  }
631
632
  return success(edits);
632
633
  }
634
+ /** A JSON bundle with the resource's copy added under `key`, or why it cannot take it. */
635
+ function jsonLocaleEdit(source, key, resource) {
636
+ let parsed = wrap(() => JSON.parse(source));
637
+ if (isFailure(parsed))
638
+ return failure(new Error(`: ${parsed.error.message}`));
639
+ if (Object.hasOwn(parsed.data, key))
640
+ return failure(alreadyHas(key));
641
+ let after = { ...parsed.data, [key]: localeBlock(resource) };
642
+ return success(`${JSON.stringify(after, null, "\t")}\n`);
643
+ }
644
+ /**
645
+ * A module bundle with the resource's copy added as the default-exported object's last
646
+ * property, before its closing brace and whatever `as const` or `satisfies` follows it.
647
+ */
648
+ function moduleLocaleEdit(source, key, resource) {
649
+ if (new RegExp(`^\\t(?:${key}|"${key}"):`, "m").test(source))
650
+ return failure(alreadyHas(key));
651
+ let closing = [...source.matchAll(/^\}(?: as const)?(?: satisfies [^;]+)?;$/gm)].at(-1);
652
+ if (closing?.index === undefined) {
653
+ return failure(new Error(" has no default-exported object to add the copy to"));
654
+ }
655
+ let property = `\t${propertyName(key)}: ${objectLiteral(localeBlock(resource), 1)},\n`;
656
+ return success(`${source.slice(0, closing.index)}${property}${source.slice(closing.index)}`);
657
+ }
658
+ /** The refusal for a bundle that already has the resource's key. */
659
+ function alreadyHas(key) {
660
+ return new Error(` already has "${key}"; sdxc scaffold leaves it as it is`);
661
+ }
662
+ /** `value` as a TypeScript object literal nested `depth` tabs deep, its strings as JSON writes them. */
663
+ function objectLiteral(value, depth) {
664
+ if (typeof value !== "object" || value === null)
665
+ return JSON.stringify(value);
666
+ let indent = "\t".repeat(depth + 1);
667
+ let entries = Object.entries(value).map(([name, entry]) => `${indent}${propertyName(name)}: ${objectLiteral(entry, depth + 1)},\n`);
668
+ return `{\n${entries.join("")}${"\t".repeat(depth)}}`;
669
+ }
670
+ /** `name` as an object literal writes it: bare when it is an identifier, quoted otherwise. */
671
+ function propertyName(name) {
672
+ return /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
673
+ }
@@ -48,7 +48,7 @@ export declare function apiOperations(resource: Resource, locals: OperationLocal
48
48
  /** The operation names `apiOperations` exports, in the order it writes them. */
49
49
  export declare function apiOperationNames(resource: Resource): string[];
50
50
  /**
51
- * The copy every `resources/locales/*.json` gains under the plural key: each page's title and
51
+ * The copy every bundle in `resources/locales/` gains under the plural key: each page's title and
52
52
  * buttons, a label per field, and the words a ticked and an unticked box read as.
53
53
  */
54
54
  export declare function localeBlock(resource: Resource): Record<string, unknown>;
@@ -272,7 +272,7 @@ export function apiOperationNames(resource) {
272
272
  return [`${many}_INDEX`, `${one}_SHOW`, `${one}_CREATE`, `${one}_UPDATE`, `${one}_DESTROY`];
273
273
  }
274
274
  /**
275
- * The copy every `resources/locales/*.json` gains under the plural key: each page's title and
275
+ * The copy every bundle in `resources/locales/` gains under the plural key: each page's title and
276
276
  * buttons, a label per field, and the words a ticked and an unticked box read as.
277
277
  */
278
278
  export function localeBlock(resource) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/kit",
3
- "version": "2026.11.18",
3
+ "version": "2026.11.24",
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": {
@@ -18,13 +18,13 @@
18
18
  "@sdxc/ci": "2026.11.10",
19
19
  "@sdxc/cli": "2026.11.10",
20
20
  "@sdxc/codemod": "2026.10.29",
21
- "@sdxc/cron": "2026.11.10",
21
+ "@sdxc/cron": "2026.11.22",
22
22
  "@sdxc/diagram": "2026.11.10",
23
23
  "@sdxc/iife": "2026.10.23",
24
24
  "@sdxc/json-schema": "2026.11.10",
25
25
  "@sdxc/jsonc": "2026.11.10",
26
26
  "@sdxc/jsonl": "2026.11.3",
27
- "@sdxc/messageformat": "2026.10.23",
27
+ "@sdxc/messageformat": "2026.11.22",
28
28
  "@sdxc/result": "2026.10.13",
29
29
  "@sdxc/semver": "2026.11.10",
30
30
  "@sdxc/strings": "2026.10.16",
@@ -33,7 +33,7 @@
33
33
  "peerDependencies": {
34
34
  "remix": "3.2.0"
35
35
  },
36
- "gitHead": "e298b0e963bc3012e6b6982bfee40a237fc93d1e",
36
+ "gitHead": "1f8a5df41e5beeb1ef28a5815a2d29cc67578845",
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "amount",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "Amount"
7
+ ],
8
+ "source": {
9
+ "path": "amount.tsx",
10
+ "content": "/**\n * An amount of money given as integer minor units and an ISO 4217 code, written by\n * `@sdxc/money` in any locale: the currency's own decimals (none for yen), a true minus, an\n * incoming-money tone, and smaller cents for a balance that leads a screen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { SignDisplay } from \"@sdxc/money\";\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { amountParts, currencyExponent } from \"@sdxc/money\";\nimport { fg } from \"@sdxc/u/color\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { when } from \"@sdxc/u/state\";\nimport { nowrap, tabularNums } from \"@sdxc/u/typography\";\n\n/** Prop types for {@link Amount}. */\nexport namespace Amount {\n\t/**\n\t * How the sign shows: `auto` marks a negative amount, `always` marks both directions,\n\t * `never` shows the magnitude alone, and `ledger` marks money in with a plus and the\n\t * success tone while money out reads as a plain figure, the way a statement lists them.\n\t */\n\texport type Sign = SignDisplay;\n\n\t/** Props accepted by {@link Amount}. */\n\texport interface Props extends Omit<TagProps<\"data\">, \"value\" | \"children\"> {\n\t\t/** The amount in the currency's minor units (cents, pence; whole yen), as an integer. */\n\t\tvalue: number;\n\t\t/** The ISO 4217 code, such as `EUR` or `JPY`. */\n\t\tcurrency: string;\n\t\t/** @default \"en-US\" */\n\t\tlocale?: string;\n\t\t/** @default \"auto\" */\n\t\tsign?: Sign;\n\t\t/** Sets the decimals in a smaller size, for a balance that heads a screen. @default false */\n\t\tsmallMinor?: boolean;\n\t\t/** Abbreviates large amounts (`€12K`), for a chart axis or a tight tile. @default false */\n\t\tcompact?: boolean;\n\t\t/** `symbol` (`$`), `narrowSymbol` (`$` for every dollar) or `code` (`USD`). @default \"narrowSymbol\" */\n\t\tdisplay?: \"symbol\" | \"narrowSymbol\" | \"code\";\n\t}\n}\n\n/** Which way money moved, for styling a row by direction: `in`, `out`, or `zero`. */\nfunction direction(value: number): \"in\" | \"out\" | \"zero\" {\n\tif (value > 0) return \"in\";\n\tif (value < 0) return \"out\";\n\treturn \"zero\";\n}\n\n/**\n * Renders an amount in a native `<data>` element whose `value` is the decimal figure, so a\n * script or a crawler reads the number while a person reads the formatted one. Figures are\n * tabular, so a column of amounts lines up, and the amount never wraps.\n *\n * @example <Amount value={-1299} currency=\"EUR\" locale=\"en-IE\" />\n * @example <Amount value={4500} currency=\"GBP\" sign=\"ledger\" />\n * @example <Amount value={1284056} currency=\"EUR\" smallMinor />\n */\nexport function Amount(handle: Handle<Amount.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tvalue,\n\t\t\tcurrency,\n\t\t\tlocale,\n\t\t\tsign = \"auto\",\n\t\t\tsmallMinor = false,\n\t\t\tcompact = false,\n\t\t\tdisplay,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet exponent = currencyExponent(currency);\n\t\tlet parts = amountParts(value, currency, { locale: locale ?? \"en-US\", sign, compact, display });\n\t\tlet credit = sign === \"ledger\" && value > 0;\n\t\treturn (\n\t\t\t<data\n\t\t\t\t{...rest}\n\t\t\t\tvalue={(value / 10 ** exponent).toFixed(exponent)}\n\t\t\t\tdata-slot=\"amount\"\n\t\t\t\tdata-currency={currency}\n\t\t\t\tdata-direction={direction(value)}\n\t\t\t\tdata-credit={credit ? \"\" : undefined}\n\t\t\t\tmix={mergeMix([tabularNums(), nowrap(), when(\"&[data-credit]\", fg(\"success\"))], mix)}\n\t\t\t>\n\t\t\t\t{smallMinor\n\t\t\t\t\t? parts.map((part) =>\n\t\t\t\t\t\t\tpart.type === \"fraction\" || part.type === \"decimal\" ? (\n\t\t\t\t\t\t\t\t<span data-slot=\"amount-minor\" mix={raw({ fontSize: \"0.62em\" })}>\n\t\t\t\t\t\t\t\t\t{part.value}\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\tpart.value\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t\t: parts.map((part) => part.value).join(\"\")}\n\t\t\t</data>\n\t\t);\n\t};\n}\n"
11
+ },
12
+ "test": {
13
+ "path": "amount.browser.test.tsx",
14
+ "content": "/**\n * Draws amounts in a real browser: the machine-readable value, tabular unwrapped figures,\n * the ledger sign's tone, and smaller cents that leave the text whole, yen included.\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\";\n\nimport { Amount } from \"@sdxc/ui/amount\";\n\nimport \"@sdxc/ui/reset.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts `node` and returns the amount element. */\nfunction mount(node: JSX.Element): HTMLDataElement {\n\tlet host = document.createElement(\"div\");\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host.querySelector<HTMLDataElement>('[data-slot=\"amount\"]')!;\n}\n\ndescribe(\"Amount\", () => {\n\ttest(\"carries the decimal figure as its machine-readable value\", () => {\n\t\tlet amount = mount(<Amount value={-1299} currency=\"EUR\" />);\n\t\texpect(amount.tagName).toBe(\"DATA\");\n\t\texpect(amount.value).toBe(\"-12.99\");\n\t\texpect(amount.textContent).toBe(\"−€12.99\");\n\t\texpect(amount.dataset.direction).toBe(\"out\");\n\t\texpect(getComputedStyle(amount).fontVariantNumeric).toBe(\"tabular-nums\");\n\t\texpect(getComputedStyle(amount).whiteSpace).toBe(\"nowrap\");\n\t});\n\n\ttest(\"tones money in on a ledger and leaves money out in the text color\", () => {\n\t\tdocument.documentElement.style.setProperty(\"--ui-success-fg\", \"rgb(0, 128, 0)\");\n\t\tlet credit = mount(<Amount value={4500} currency=\"EUR\" sign=\"ledger\" />);\n\t\texpect(credit.hasAttribute(\"data-credit\")).toBe(true);\n\t\texpect(getComputedStyle(credit).color).toBe(\"rgb(0, 128, 0)\");\n\t\tmounted?.cleanup();\n\t\tdocument.body.replaceChildren();\n\t\tlet debit = mount(<Amount value={-4500} currency=\"EUR\" sign=\"ledger\" />);\n\t\texpect(debit.hasAttribute(\"data-credit\")).toBe(false);\n\t\texpect(getComputedStyle(debit).color).not.toBe(\"rgb(0, 128, 0)\");\n\t\tdocument.documentElement.removeAttribute(\"style\");\n\t});\n\n\ttest(\"sets the decimals smaller for a balance and keeps the whole text intact\", () => {\n\t\tlet amount = mount(<Amount value={1284056} currency=\"EUR\" smallMinor />);\n\t\texpect(amount.textContent).toBe(\"€12,840.56\");\n\t\tlet minor = [...amount.querySelectorAll<HTMLElement>('[data-slot=\"amount-minor\"]')];\n\t\texpect(minor.map((part) => part.textContent).join(\"\")).toBe(\".56\");\n\t\tlet whole = Number.parseFloat(getComputedStyle(amount).fontSize);\n\t\texpect(Number.parseFloat(getComputedStyle(minor[1]!).fontSize)).toBeLessThan(whole);\n\t});\n\n\ttest(\"draws yen without a fraction even with smaller decimals asked for\", () => {\n\t\tlet amount = mount(<Amount value={128000} currency=\"JPY\" smallMinor />);\n\t\texpect(amount.value).toBe(\"128000\");\n\t\texpect(amount.textContent).toBe(\"¥128,000\");\n\t\texpect(amount.querySelector('[data-slot=\"amount-minor\"]')).toBeNull();\n\t});\n});\n"
15
+ }
16
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "autocomplete",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [
5
+ "input"
6
+ ],
7
+ "exports": [
8
+ "Autocomplete",
9
+ "AutocompleteSync"
10
+ ],
11
+ "source": {
12
+ "path": "autocomplete.tsx",
13
+ "content": "/**\n * A text field with a styled suggestion list under it, for a \"Where are you going?\" box or an\n * address field. The server renders a plain input with a native `<datalist>`, and the\n * {@link AutocompleteSync} island upgrades it to a combobox over a filtered, iconed listbox.\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 { bg, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix, raw } from \"@sdxc/u/general\";\nimport { hstack } from \"@sdxc/u/layout\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { text, truncate } from \"@sdxc/u/typography\";\nimport { clientEntry } from \"remix/component\";\n\nimport { autocomplete } from \"@sdxc/ui/mixins\";\nimport { floatingSurface, surfaceInset } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { Input } from \"@sdxc/ui/input\";\n\nexport { AUTOCOMPLETE_SELECT_EVENT } from \"@sdxc/ui/mixins\";\nexport type { AutocompleteSelectDetail } from \"@sdxc/ui/mixins\";\n\n/** What the list says when the typed text matches no option and the caller names nothing. */\nconst DEFAULT_EMPTY_LABEL = \"No matches\";\n\n/** Prop types for {@link Autocomplete}. */\nexport namespace Autocomplete {\n\t/** One suggestion: what the hidden field submits, what the field shows, and how it reads. */\n\texport interface Option {\n\t\t/** Submitted through `valueName` when picked, such as a place id. */\n\t\tvalue: string;\n\t\t/** Shown in the list and written into the field when picked. */\n\t\tlabel: string;\n\t\t/** A second line under the label, also searched as the reader types. */\n\t\tdescription?: string;\n\t\t/** A glyph before the label, such as an icon from `@sdxc/icons`. */\n\t\ticon?: RemixNode;\n\t}\n\n\t/** Per-part styling for the elements the autocomplete composes. */\n\texport interface PartsProps {\n\t\t/** The text field. */\n\t\tinput?: TagProps<\"input\">[\"mix\"];\n\t\t/** The floating list surface. */\n\t\tlist?: TagProps<\"div\">[\"mix\"];\n\t\t/** Every option row. */\n\t\toption?: TagProps<\"div\">[\"mix\"];\n\t}\n\n\t/**\n\t * Every native `<input>` attribute but the ones the combobox owns, which land on the field;\n\t * `mix` styles the wrapper around the field and its list.\n\t */\n\texport interface Props extends Omit<\n\t\tTagProps<\"input\">,\n\t\t\"type\" | \"list\" | \"role\" | \"children\" | \"mix\" | \"value\" | \"color\"\n\t> {\n\t\t/** The field's `id`, from which every other id the autocomplete needs derives. */\n\t\tid: string;\n\t\t/** The field's accessible name; pass `aria-labelledby` instead to point at a visible label. */\n\t\tlabel?: string;\n\t\t/** The suggestions, in the order the list shows them. */\n\t\toptions: Array<Option>;\n\t\t/** Shown at the top of the list while the field is empty, such as \"Suggested destinations\". */\n\t\theading?: RemixNode;\n\t\t/** Shown in the list when nothing matches. @default \"No matches\" */\n\t\temptyLabel?: RemixNode;\n\t\t/** Names a hidden field carrying the picked option's `value`, emptied once the text is edited. */\n\t\tvalueName?: string;\n\t\t/**\n\t\t * `\"field\"` draws the bordered input; `\"bare\"` drops its border, background, padding and focus\n\t\t * ring, for a field set inside a pill that draws them with `:focus-within`.\n\t\t * @default \"field\"\n\t\t */\n\t\tvariant?: \"field\" | \"bare\";\n\t\t/** Styling for the wrapper. */\n\t\tmix?: TagProps<\"div\">[\"mix\"];\n\t\t/** Per-part styling. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Renders the field, its `<datalist>`, a hidden list of styled options and the island that\n * swaps one for the other. Picking fires `change` and an `autocomplete-select` event on the\n * field with `{ value, label }`; Enter on an option never submits the form.\n *\n * @example\n * <Autocomplete id=\"where\" name=\"where\" label=\"Where to?\" heading=\"Suggested destinations\"\n * \tvalueName=\"placeId\" options={[{ value: \"lis\", label: \"Lisbon\", description: \"Portugal\" }]} />\n * @example\n * <Autocomplete id=\"q\" name=\"q\" variant=\"bare\" aria-labelledby=\"where-label\" options={places} />\n */\nexport function Autocomplete(handle: Handle<Autocomplete.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\toptions,\n\t\t\theading,\n\t\t\temptyLabel = DEFAULT_EMPTY_LABEL,\n\t\t\tvalueName,\n\t\t\tvariant = \"field\",\n\t\t\tmix,\n\t\t\tparts,\n\t\t\tautoComplete = \"off\",\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet labelledBy = rest[\"aria-labelledby\"];\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\t{ \"aria-label\": label, \"aria-labelledby\": labelledBy },\n\t\t\t\"Autocomplete: pass `label` or `aria-labelledby` so the field and its list have a name.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"autocomplete\"\n\t\t\t\tdata-variant={variant}\n\t\t\t\tmix={mergeMix([raw({ position: \"relative\", inlineSize: \"100%\", minInlineSize: \"0\" })], mix)}\n\t\t\t>\n\t\t\t\t<Input\n\t\t\t\t\t{...rest}\n\t\t\t\t\tid={id}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tlist={`${id}-suggestions`}\n\t\t\t\t\tdata-autocomplete-input=\"\"\n\t\t\t\t\tmix={mergeMix(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\traw({ minInlineSize: \"0\", textOverflow: \"ellipsis\" }),\n\t\t\t\t\t\t\twhen('[data-variant=\"bare\"] > &', [\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tborderWidth: \"0\",\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t\t\tpaddingInline: \"0\",\n\t\t\t\t\t\t\t\t\toutline: \"none\",\n\t\t\t\t\t\t\t\t\tboxShadow: \"none\",\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\tparts?.input,\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t{valueName ? (\n\t\t\t\t\t<input type=\"hidden\" name={valueName} value=\"\" data-autocomplete-value=\"\" />\n\t\t\t\t) : null}\n\t\t\t\t<datalist id={`${id}-suggestions`}>\n\t\t\t\t\t{options.map((option) => (\n\t\t\t\t\t\t<option value={option.label} />\n\t\t\t\t\t))}\n\t\t\t\t</datalist>\n\t\t\t\t<div\n\t\t\t\t\tid={`${id}-popup`}\n\t\t\t\t\tpopover=\"manual\"\n\t\t\t\t\tdata-autocomplete-popup=\"\"\n\t\t\t\t\tmix={mergeMix(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\t\t\tsurfaceInset(),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tposition: \"fixed\",\n\t\t\t\t\t\t\t\tinset: \"auto\",\n\t\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\t\tboxSizing: \"border-box\",\n\t\t\t\t\t\t\t\toverflowY: \"auto\",\n\t\t\t\t\t\t\t\toverscrollBehavior: \"contain\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\twhen(\"&:not(:popover-open)\", raw({ display: \"none !important\" })),\n\t\t\t\t\t\t],\n\t\t\t\t\t\tparts?.list,\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t{heading ? (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid={`${id}-heading`}\n\t\t\t\t\t\t\tdata-autocomplete-heading=\"\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tpaddingBlock: \"0.375rem\",\n\t\t\t\t\t\t\t\t\tfontSize: \"0.75rem\",\n\t\t\t\t\t\t\t\t\tfontWeight: \"600\",\n\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\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{heading}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={`${id}-listbox`}\n\t\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\t\taria-label={label}\n\t\t\t\t\t\taria-labelledby={labelledBy}\n\t\t\t\t\t\tdata-autocomplete-listbox=\"\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{options.map((option, index) => (\n\t\t\t\t\t\t\t<AutocompleteOption\n\t\t\t\t\t\t\t\tid={`${id}-option-${index}`}\n\t\t\t\t\t\t\t\toption={option}\n\t\t\t\t\t\t\t\tmix={parts?.option}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-autocomplete-empty=\"\"\n\t\t\t\t\t\thidden\n\t\t\t\t\t\tmix={[pi(3), pb(2), text(\"sm\"), fg(\"neutral.muted\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{emptyLabel}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<AutocompleteSync />\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * One row of the list: the icon in a tinted square, the label over its description, both\n * truncating so a long place name never widens the list. A row is at least the pointer\n * target size tall, which grows to 44px on a touch screen.\n */\nfunction AutocompleteOption(\n\thandle: Handle<{ id: string; option: Autocomplete.Option; mix?: TagProps<\"div\">[\"mix\"] }>,\n) {\n\treturn () => {\n\t\tlet { id, option, mix } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tid={id}\n\t\t\t\trole=\"option\"\n\t\t\t\taria-selected=\"false\"\n\t\t\t\tdata-autocomplete-option=\"\"\n\t\t\t\tdata-value={option.value}\n\t\t\t\tdata-label={option.label}\n\t\t\t\tdata-description={option.description}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\thstack({ align: \"center\", gap: 3 }),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpb(1.5),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tminBlockSize: \"max(2.75rem, var(--ui-target-size))\",\n\t\t\t\t\t\t\tscrollMarginBlock: \"0.25rem\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.bg-tint-pressed\")]),\n\t\t\t\t\t\twhen(\"&[hidden]\", raw({ display: \"none\" })),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"& mark\",\n\t\t\t\t\t\t\traw({ backgroundColor: \"transparent\", color: \"inherit\", fontWeight: \"700\" }),\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{option.icon ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\t\t\tfg(\"neutral\"),\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\tflexShrink: \"0\",\n\t\t\t\t\t\t\t\tinlineSize: \"2rem\",\n\t\t\t\t\t\t\t\tblockSize: \"2rem\",\n\t\t\t\t\t\t\t\t\"& svg\": { inlineSize: \"1rem\", blockSize: \"1rem\" },\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\t\t{option.icon}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t\t<span mix={[raw({ display: \"grid\", minInlineSize: \"0\", flex: \"1\" })]}>\n\t\t\t\t\t<span data-autocomplete-label=\"\" mix={[truncate(), text(\"sm\"), fg(\"neutral.emphasis\")]}>\n\t\t\t\t\t\t{option.label}\n\t\t\t\t\t</span>\n\t\t\t\t\t{option.description ? (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tdata-autocomplete-description=\"\"\n\t\t\t\t\t\t\tmix={[truncate(), text(\"xs\"), fg(\"neutral.muted\")]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{option.description}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The island inside every {@link Autocomplete}: once hydrated it drops the field's datalist,\n * makes the field a combobox and opens the styled list on focus and typing. It renders only a\n * hidden marker, so the field and options stay server markup styled by the caller's mixins.\n *\n * @example <AutocompleteSync />\n */\nexport const AutocompleteSync: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/autocomplete#AutocompleteSync\",\n\tfunction AutocompleteSync() {\n\t\treturn () => <span hidden mix={[autocomplete()]} />;\n\t},\n);\n"
14
+ },
15
+ "test": {
16
+ "path": "autocomplete.browser.test.tsx",
17
+ "content": "/**\n * Types into an autocomplete in a real browser: the server markup suggests through a native\n * datalist, and once its island mounts the field opens a styled list with a heading, filters\n * as it is typed in, walks with the arrows, picks on Enter or a press without submitting the\n * form, closes on Escape, carries the picked value in a hidden field and fits a 320px screen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { renderToString } from \"remix/component/server\";\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test, vi } from \"vitest\";\nimport { page, userEvent } from \"vitest/browser\";\n\nimport type { AutocompleteSelectDetail } from \"@sdxc/ui/autocomplete\";\n\nimport { Autocomplete } from \"@sdxc/ui/autocomplete\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The destinations every test searches. */\nconst OPTIONS: Array<Autocomplete.Option> = [\n\t{ value: \"lis\", label: \"Lisbon\", description: \"Portugal\", icon: <svg viewBox=\"0 0 16 16\" /> },\n\t{ value: \"por\", label: \"Porto\", description: \"Portugal\" },\n\t{ value: \"mad\", label: \"Madrid\", description: \"Spain\" },\n\t{ value: \"bcn\", label: \"Barcelona\", description: \"Catalonia, Spain\" },\n];\n\nlet mounted: RenderResult | undefined;\n\nafterEach(async () => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n\tawait page.viewport(1024, 768);\n});\n\n/** Mounts the autocomplete in a form, letting the island enhance it. */\nasync function mount(props: Partial<Autocomplete.Props> = {}) {\n\tlet submit = vi.fn((event: SubmitEvent) => event.preventDefault());\n\tmounted = render(\n\t\t<form>\n\t\t\t<Autocomplete\n\t\t\t\tid=\"where\"\n\t\t\t\tname=\"where\"\n\t\t\t\tlabel=\"Where to?\"\n\t\t\t\theading=\"Suggested destinations\"\n\t\t\t\tplaceholder=\"Search destinations\"\n\t\t\t\toptions={OPTIONS}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<button type=\"submit\">Search</button>\n\t\t</form>,\n\t);\n\tawait new Promise((resolve) => requestAnimationFrame(resolve));\n\tlet root = mounted.container;\n\troot.querySelector(\"form\")!.addEventListener(\"submit\", submit);\n\treturn {\n\t\troot,\n\t\tsubmit,\n\t\tinput: root.querySelector<HTMLInputElement>(\"#where\")!,\n\t\tpopup: root.querySelector<HTMLElement>(\"#where-popup\")!,\n\t\theading: root.querySelector<HTMLElement>(\"[data-autocomplete-heading]\")!,\n\t\tempty: root.querySelector<HTMLElement>(\"[data-autocomplete-empty]\")!,\n\t};\n}\n\n/** The labels of the options the list shows. */\nfunction shownLabels(root: HTMLElement): Array<string> {\n\treturn Array.from(root.querySelectorAll<HTMLElement>('[role=\"option\"]'))\n\t\t.filter((option) => !option.hidden)\n\t\t.map((option) => option.dataset.label ?? \"\");\n}\n\ndescribe(\"Autocomplete\", () => {\n\ttest(\"renders a plain field suggesting through a native datalist before any script\", async () => {\n\t\tdocument.body.innerHTML = await renderToString(\n\t\t\t<Autocomplete id=\"where\" name=\"where\" label=\"Where to?\" options={OPTIONS} />,\n\t\t);\n\t\tlet input = document.querySelector<HTMLInputElement>(\"#where\")!;\n\t\tlet datalist = document.getElementById(input.getAttribute(\"list\") ?? \"\");\n\n\t\texpect(input.getAttribute(\"role\")).toBeNull();\n\t\texpect(datalist?.tagName).toBe(\"DATALIST\");\n\t\texpect(Array.from(datalist!.querySelectorAll(\"option\")).map((o) => o.value)).toEqual([\n\t\t\t\"Lisbon\",\n\t\t\t\"Porto\",\n\t\t\t\"Madrid\",\n\t\t\t\"Barcelona\",\n\t\t]);\n\t\texpect(document.querySelector<HTMLElement>(\"#where-popup\")!.matches(\":popover-open\")).toBe(\n\t\t\tfalse,\n\t\t);\n\t});\n\n\ttest(\"becomes a combobox that opens its list with the heading on focus\", async () => {\n\t\tlet { input, popup, heading } = await mount();\n\n\t\texpect(input.hasAttribute(\"list\")).toBe(false);\n\t\texpect(input.getAttribute(\"role\")).toBe(\"combobox\");\n\t\texpect(input.getAttribute(\"aria-autocomplete\")).toBe(\"list\");\n\t\texpect(input.getAttribute(\"aria-controls\")).toBe(\"where-listbox\");\n\t\texpect(input.getAttribute(\"aria-expanded\")).toBe(\"false\");\n\n\t\tinput.focus();\n\t\texpect(popup.matches(\":popover-open\")).toBe(true);\n\t\texpect(input.getAttribute(\"aria-expanded\")).toBe(\"true\");\n\t\texpect(heading.hidden).toBe(false);\n\t\texpect(popup.getBoundingClientRect().top).toBeGreaterThanOrEqual(\n\t\t\tinput.getBoundingClientRect().bottom,\n\t\t);\n\t});\n\n\ttest(\"filters by label and description as the reader types, marking the match\", async () => {\n\t\tlet { root, input, heading, empty } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"spain\");\n\t\texpect(shownLabels(root)).toEqual([\"Madrid\", \"Barcelona\"]);\n\t\texpect(heading.hidden).toBe(true);\n\n\t\tawait userEvent.clear(input);\n\t\tawait userEvent.keyboard(\"POR\");\n\t\texpect(shownLabels(root)).toEqual([\"Lisbon\", \"Porto\"]);\n\t\texpect(root.querySelector(\"#where-option-1 [data-autocomplete-label] mark\")?.textContent).toBe(\n\t\t\t\"Por\",\n\t\t);\n\n\t\tawait userEvent.keyboard(\"xyz\");\n\t\texpect(shownLabels(root)).toEqual([]);\n\t\texpect(empty.hidden).toBe(false);\n\t\texpect(empty.textContent).toBe(\"No matches\");\n\t});\n\n\ttest(\"walks the shown options with the arrows through aria-activedescendant\", async () => {\n\t\tlet { input } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"spain\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-2\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-3\");\n\t\texpect(document.getElementById(\"where-option-3\")?.getAttribute(\"aria-selected\")).toBe(\"true\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-2\");\n\t\tawait userEvent.keyboard(\"{ArrowUp}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-3\");\n\t});\n\n\ttest(\"picks on Enter, firing change and autocomplete-select, without submitting\", async () => {\n\t\tlet { root, input, popup, submit } = await mount();\n\t\tlet change = vi.fn();\n\t\tlet select = vi.fn((event: CustomEvent<AutocompleteSelectDetail>) => event.detail);\n\t\troot.addEventListener(\"change\", change);\n\t\troot.addEventListener(\"autocomplete-select\", select);\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"{ArrowDown}{ArrowDown}{Enter}\");\n\n\t\texpect(input.value).toBe(\"Porto\");\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t\texpect(change).toHaveBeenCalledTimes(1);\n\t\texpect(select).toHaveReturnedWith({ value: \"por\", label: \"Porto\" });\n\t\texpect(submit).not.toHaveBeenCalled();\n\t});\n\n\ttest(\"closes on the first Escape and clears the field on the second\", async () => {\n\t\tlet { input, popup } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"Lis\");\n\t\tawait userEvent.keyboard(\"{Escape}\");\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t\texpect(input.value).toBe(\"Lis\");\n\t\tawait userEvent.keyboard(\"{Escape}\");\n\t\texpect(input.value).toBe(\"\");\n\t});\n\n\ttest(\"picks an option pressed with the pointer, and closes on a press elsewhere\", async () => {\n\t\tlet { input, popup } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.click(page.getByRole(\"option\", { name: /Madrid/ }));\n\t\texpect(input.value).toBe(\"Madrid\");\n\t\texpect(document.activeElement).toBe(input);\n\n\t\tawait userEvent.click(input);\n\t\texpect(popup.matches(\":popover-open\")).toBe(true);\n\t\tawait userEvent.click(document.body, { position: { x: 5, y: 700 } });\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t});\n\n\ttest(\"carries the picked value in a hidden field until the text is edited\", async () => {\n\t\tlet { root, input } = await mount({ valueName: \"placeId\" });\n\t\tlet hidden = root.querySelector<HTMLInputElement>('input[name=\"placeId\"]')!;\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"Barc{ArrowDown}{Enter}\");\n\t\texpect(input.value).toBe(\"Barcelona\");\n\t\texpect(hidden.value).toBe(\"bcn\");\n\t\texpect(new FormData(root.querySelector(\"form\")!).get(\"where\")).toBe(\"Barcelona\");\n\n\t\tawait userEvent.keyboard(\"{Backspace}\");\n\t\texpect(hidden.value).toBe(\"\");\n\t});\n\n\ttest(\"draws a bare field with no border or background\", async () => {\n\t\tlet { input } = await mount({ variant: \"bare\" });\n\t\tlet style = getComputedStyle(input);\n\n\t\texpect(style.borderTopWidth).toBe(\"0px\");\n\t\texpect(style.backgroundColor).toBe(\"rgba(0, 0, 0, 0)\");\n\t});\n\n\ttest(\"fits a 320px screen, field and open list alike\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet { input, popup } = await mount();\n\n\t\tinput.focus();\n\t\tlet list = popup.getBoundingClientRect();\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(input.getBoundingClientRect().right).toBeLessThanOrEqual(320);\n\t\texpect(list.left).toBeGreaterThanOrEqual(0);\n\t\texpect(list.right).toBeLessThanOrEqual(320);\n\t});\n});\n"
18
+ }
19
+ }
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "carousel",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.22",
4
4
  "dependencies": [
5
5
  "button"
6
6
  ],
7
7
  "exports": [
8
- "Carousel"
8
+ "Carousel",
9
+ "CarouselSync"
9
10
  ],
10
11
  "source": {
11
12
  "path": "carousel.tsx",
12
- "content": "/**\n * A horizontally scrolling collection of slides riding native CSS scroll snap,\n * so swiping or scrolling advances between slides with no script in the\n * baseline. {@link Carousel.Viewport} is the scrolling surface,\n * {@link Carousel.Track} rows up its {@link Carousel.Slide} children, and\n * {@link Carousel.Previous}/{@link Carousel.Next} are invoker buttons a paired\n * mixin wires into working controls.\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 { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { outline } from \"@sdxc/u/color\";\nimport { raw, vars, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, grow, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, minIs, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\n/** Native ARIA role applied to {@link Carousel.Viewport} unless a consumer overrides it. */\nconst DEFAULT_VIEWPORT_ROLE = \"group\";\n\n/**\n * Native tab-stop index applied to {@link Carousel.Viewport} unless a consumer\n * overrides it, so the scrollable region is reachable by keyboard even before\n * any control is wired up.\n */\nconst DEFAULT_VIEWPORT_TAB_INDEX = 0;\n\n/** Native ARIA role applied to {@link Carousel.Slide} unless a consumer overrides it. */\nconst DEFAULT_SLIDE_ROLE = \"group\";\n\n/**\n * Visual weight {@link Carousel.Previous} and {@link Carousel.Next} fall back\n * to when `variant` is omitted.\n */\nconst DEFAULT_CONTROL_VARIANT: Button.Variant = \"ghost\";\n\n/**\n * Semantic color role {@link Carousel.Previous} and {@link Carousel.Next} fall\n * back to when `color` is omitted.\n */\nconst DEFAULT_CONTROL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Size variant {@link Carousel.Previous} and {@link Carousel.Next} fall back to\n * when `size` is omitted.\n */\nconst DEFAULT_CONTROL_SIZE: Button.Size = \"sm\";\n\n/** Invoker Commands verb {@link Carousel.Previous} falls back to when `command` is omitted. */\nconst DEFAULT_PREVIOUS_COMMAND = \"--ui-prev\";\n\n/** Invoker Commands verb {@link Carousel.Next} falls back to when `command` is omitted. */\nconst DEFAULT_NEXT_COMMAND = \"--ui-next\";\n\n/**\n * Prop types for {@link Carousel} and its compound parts.\n */\nexport namespace Carousel {\n\t/**\n\t * Every native `<section>` attribute, unchanged, plus the `mix`\n\t * passthrough. Override `--ui-carousel-gap`, `--ui-carousel-slide-size`, or\n\t * `--ui-carousel-padding` per instance through the inherited `style` prop.\n\t */\n\texport interface Props extends TagProps<\"section\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * Give it an `id` for the controls' `commandfor` prop to target, and pair a\n\t * `carouselControls()` mixin on it to make those controls scroll it.\n\t */\n\texport interface ViewportProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface TrackProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface SlideProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ControlsProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every {@link Button.Props} field, with `commandfor` required and `command`\n\t * narrowed to the verb the paired mixin listens for.\n\t */\n\texport interface PreviousProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/** `id` of the {@link Carousel.Viewport} this control scrolls back through. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb a `carouselControls()` mixin listens for. Defaults to `\"--ui-prev\"`. */\n\t\tcommand?: \"--ui-prev\";\n\t}\n\n\t/**\n\t * Every {@link Button.Props} field, with `commandfor` required and `command`\n\t * narrowed to the verb the paired mixin listens for.\n\t */\n\texport interface NextProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/** `id` of the {@link Carousel.Viewport} this control scrolls forward through. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb a `carouselControls()` mixin listens for. Defaults to `\"--ui-next\"`. */\n\t\tcommand?: \"--ui-next\";\n\t}\n}\n\n/**\n * The carousel root: a `<section>` stacking {@link Carousel.Viewport} and\n * {@link Carousel.Controls} in a column, declaring the `--ui-carousel-*`\n * custom properties its descendants read with per-instance defaults.\n *\n * @param handle Runtime handle carrying the host `<section>`'s props.\n * @returns The render function producing the carousel's markup.\n * @example\n * <Carousel aria-label={t(\"gallery.label\")}>\n * \t<Carousel.Viewport id=\"gallery-viewport\">\n * \t\t<Carousel.Track>\n * \t\t\t<Carousel.Slide><img src={photo.src} alt={photo.alt} /></Carousel.Slide>\n * \t\t</Carousel.Track>\n * \t</Carousel.Viewport>\n * \t<Carousel.Controls>\n * \t\t<Carousel.Previous commandfor=\"gallery-viewport\" aria-label={t(\"gallery.previous\")} />\n * \t\t<Carousel.Next commandfor=\"gallery-viewport\" aria-label={t(\"gallery.next\")} />\n * \t</Carousel.Controls>\n * </Carousel>\n * @example\n * // Landing browser-flow strip: widen `--ui-carousel-slide-size` for product\n * // frames and keep Previous/Next on `size=\"sm\"` so controls stay quiet.\n * <Carousel\n * \taria-label={t(\"flows.label\")}\n * \tstyle={{ \"--ui-carousel-slide-size\": \"28rem\" }}\n * >\n * \t<Carousel.Viewport id=\"flows\" mix={[carouselControls()]}>\n * \t\t<Carousel.Track>{slides}</Carousel.Track>\n * \t</Carousel.Viewport>\n * \t<Carousel.Controls>\n * \t\t<Carousel.Previous commandfor=\"flows\" aria-label={t(\"flows.previous\")} />\n * \t\t<Carousel.Next commandfor=\"flows\" aria-label={t(\"flows.next\")} />\n * \t</Carousel.Controls>\n * </Carousel>\n */\nexport function Carousel(handle: Handle<Carousel.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<section\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"carousel\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\tgap(3),\n\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\"ui-carousel-gap\": \"1rem\",\n\t\t\t\t\t\t\t\"ui-carousel-slide-size\": \"18rem\",\n\t\t\t\t\t\t\t\"ui-carousel-padding\": \"0px\",\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 * A `<div>` scrolling {@link Carousel.Track} along the inline axis via logical\n * properties for correct writing direction, with mandatory scroll-snap stops;\n * scroll padding reads `--ui-carousel-padding` to clear the track's own padding.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the viewport's markup.\n * @example\n * <Carousel.Viewport id=\"gallery-viewport\">\n * \t<Carousel.Track>{slides}</Carousel.Track>\n * </Carousel.Viewport>\n */\nCarousel.Viewport = function CarouselViewport(handle: Handle<Carousel.ViewportProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"viewport\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_VIEWPORT_ROLE, tabIndex: DEFAULT_VIEWPORT_TAB_INDEX }),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\toverflowInline: \"auto\",\n\t\t\t\t\t\t\toverflowBlock: \"hidden\",\n\t\t\t\t\t\t\tscrollBehavior: \"smooth\",\n\t\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\t\tscrollPaddingInline: \"var(--ui-carousel-padding, 0px)\",\n\t\t\t\t\t\t\t\"-webkit-overflow-scrolling\": \"touch\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", raw({ scrollBehavior: \"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);\n\t};\n};\n\n/**\n * The carousel's slide row: a `<div>` laying its {@link Carousel.Slide}\n * children out in one inline row, gapped by `--ui-carousel-gap` and padded by\n * `--ui-carousel-padding` so the first and last slide can still center.\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 * <Carousel.Track>\n * \t<Carousel.Slide>{firstSlide}</Carousel.Slide>\n * \t<Carousel.Slide>{secondSlide}</Carousel.Slide>\n * </Carousel.Track>\n */\nCarousel.Track = function CarouselTrack(handle: Handle<Carousel.TrackProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"track\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[flex(), gap(\"var(--ui-carousel-gap, 1rem)\"), pi(\"var(--ui-carousel-padding, 0px)\")],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A single slide: a `<div>` held at `--ui-carousel-slide-size` along the\n * inline axis, snapping to its inline-start edge so the viewport settles on a\n * slide boundary.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the slide's markup.\n * @example\n * <Carousel.Slide><img src={photo.src} alt={photo.alt} /></Carousel.Slide>\n */\nCarousel.Slide = function CarouselSlide(handle: Handle<Carousel.SlideProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"slide\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_SLIDE_ROLE }),\n\t\t\t\t\t\tgrow(0),\n\t\t\t\t\t\tshrink(0),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The slide snaps to the viewport's start edge and leaves the scroll free to pass it:\n\t\t\t\t\t\t * `scroll-snap-stop: always` clamps programmatic scrolls too, so every dot would move\n\t\t\t\t\t\t * one slide and none would reach the slide it names.\n\t\t\t\t\t\t */\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tflexBasis: \"var(--ui-carousel-slide-size, 18rem)\",\n\t\t\t\t\t\t\tscrollSnapAlign: \"start\",\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 * The carousel's control row: a `<div>` laying {@link Carousel.Previous} and\n * {@link Carousel.Next} out as an end-aligned, vertically centered row.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the control row's markup.\n * @example\n * <Carousel.Controls>\n * \t<Carousel.Previous commandfor=\"gallery-viewport\" aria-label={t(\"gallery.previous\")} />\n * \t<Carousel.Next commandfor=\"gallery-viewport\" aria-label={t(\"gallery.next\")} />\n * </Carousel.Controls>\n */\nCarousel.Controls = function CarouselControls(handle: Handle<Carousel.ControlsProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"controls\"\n\t\t\t\tmix={mergeMix([flex(), items(\"center\"), gap(2), justify(\"end\")], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A static control scrolling {@link Carousel.Viewport} named by `commandfor` back\n * one slide when a hydrated `carouselControls()` mixin handles `\"--ui-prev\"`; custom\n * `children` replacing the chevron still need their own `aria-label`.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the control's markup.\n * @example\n * <Carousel.Previous commandfor=\"gallery-viewport\" aria-label={t(\"gallery.previous\")} />\n */\nCarousel.Previous = function CarouselPrevious(handle: Handle<Carousel.PreviousProps>) {\n\treturn () => {\n\t\tlet { variant, color, size, command, children, mix, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CONTROL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CONTROL_COLOR;\n\t\tlet resolvedSize = size ?? DEFAULT_CONTROL_SIZE;\n\t\tlet resolvedCommand = command ?? DEFAULT_PREVIOUS_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tsize={resolvedSize}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"previous\"\n\t\t\t\tmix={mergeMix([minIs(0), when(\"& > svg\", [is(4), bs(4)])], mix)}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronLeftIcon />}\n\t\t\t</Button>\n\t\t);\n\t};\n};\n\n/**\n * A static control scrolling {@link Carousel.Viewport} named by `commandfor` forward\n * one slide when a hydrated `carouselControls()` mixin handles `\"--ui-next\"`; custom\n * `children` replacing the chevron still need their own `aria-label`.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the control's markup.\n * @example\n * <Carousel.Next commandfor=\"gallery-viewport\" aria-label={t(\"gallery.next\")} />\n */\nCarousel.Next = function CarouselNext(handle: Handle<Carousel.NextProps>) {\n\treturn () => {\n\t\tlet { variant, color, size, command, children, mix, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CONTROL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CONTROL_COLOR;\n\t\tlet resolvedSize = size ?? DEFAULT_CONTROL_SIZE;\n\t\tlet resolvedCommand = command ?? DEFAULT_NEXT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tsize={resolvedSize}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"next\"\n\t\t\t\tmix={mergeMix([minIs(0), when(\"& > svg\", [is(4), bs(4)])], mix)}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronRightIcon />}\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
13
+ "content": "/**\n * A horizontally scrolling collection of slides riding native CSS scroll snap,\n * so swiping or scrolling advances between slides with no script in the\n * baseline. {@link Carousel.Viewport} is the scrolling surface,\n * {@link Carousel.Track} rows up its {@link Carousel.Slide} children, and\n * {@link Carousel.Previous}/{@link Carousel.Next} are invoker buttons a paired\n * mixin wires into working controls.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { outline } from \"@sdxc/u/color\";\nimport { raw, vars, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, grow, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, minIs, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs, clientEntry } from \"remix/component\";\n\nimport { carouselSync } from \"@sdxc/ui/mixins\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\n/** Native ARIA role applied to {@link Carousel.Viewport} unless a consumer overrides it. */\nconst DEFAULT_VIEWPORT_ROLE = \"group\";\n\n/**\n * Native tab-stop index applied to {@link Carousel.Viewport} unless a consumer\n * overrides it, so the scrollable region is reachable by keyboard even before\n * any control is wired up.\n */\nconst DEFAULT_VIEWPORT_TAB_INDEX = 0;\n\n/** Native ARIA role applied to {@link Carousel.Slide} unless a consumer overrides it. */\nconst DEFAULT_SLIDE_ROLE = \"group\";\n\n/**\n * Visual weight {@link Carousel.Previous} and {@link Carousel.Next} fall back\n * to when `variant` is omitted.\n */\nconst DEFAULT_CONTROL_VARIANT: Button.Variant = \"ghost\";\n\n/**\n * Semantic color role {@link Carousel.Previous} and {@link Carousel.Next} fall\n * back to when `color` is omitted.\n */\nconst DEFAULT_CONTROL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Size variant {@link Carousel.Previous} and {@link Carousel.Next} fall back to\n * when `size` is omitted.\n */\nconst DEFAULT_CONTROL_SIZE: Button.Size = \"sm\";\n\n/** Invoker Commands verb {@link Carousel.Previous} falls back to when `command` is omitted. */\nconst DEFAULT_PREVIOUS_COMMAND = \"--ui-prev\";\n\n/** Invoker Commands verb {@link Carousel.Next} falls back to when `command` is omitted. */\nconst DEFAULT_NEXT_COMMAND = \"--ui-next\";\n\n/**\n * Prop types for {@link Carousel} and its compound parts.\n */\nexport namespace Carousel {\n\t/**\n\t * Every native `<section>` attribute, unchanged, plus the `mix`\n\t * passthrough. Override `--ui-carousel-gap`, `--ui-carousel-slide-size`, or\n\t * `--ui-carousel-padding` per instance through the inherited `style` prop.\n\t */\n\texport interface Props extends TagProps<\"section\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * Give it an `id` for the controls' `commandfor` prop to target, and pair a\n\t * `carouselControls()` mixin on it to make those controls scroll it.\n\t */\n\texport interface ViewportProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface TrackProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface SlideProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ControlsProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every {@link Button.Props} field, with `commandfor` required and `command`\n\t * narrowed to the verb the paired mixin listens for.\n\t */\n\texport interface PreviousProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/** `id` of the {@link Carousel.Viewport} this control scrolls back through. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb a `carouselControls()` mixin listens for. Defaults to `\"--ui-prev\"`. */\n\t\tcommand?: \"--ui-prev\";\n\t}\n\n\t/**\n\t * Every {@link Button.Props} field, with `commandfor` required and `command`\n\t * narrowed to the verb the paired mixin listens for.\n\t */\n\t/** Every native `<div>` attribute, plus the dots' viewport, count and names. */\n\texport interface DotsProps extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** `id` of the {@link Carousel.Viewport} the dots move. */\n\t\tcommandfor: string;\n\t\t/** How many slides the viewport holds, one dot each. */\n\t\tcount: number;\n\t\t/** Each dot's accessible name, from its zero-based index, such as \"Photo 2 of 3\". */\n\t\tlabel: (index: number) => string;\n\t\t/** The slide the page renders in view, marked before script runs. @default 0 */\n\t\tcurrent?: number;\n\t}\n\n\t/** Every native `<span>` attribute, plus the viewport it reads and its size. */\n\texport interface CountProps extends Omit<TagProps<\"span\">, \"children\"> {\n\t\t/** `id` of the {@link Carousel.Viewport} whose position it shows. */\n\t\tviewport: string;\n\t\t/** How many slides the viewport holds. */\n\t\ttotal: number;\n\t\t/** The slide the page renders in view. @default 0 */\n\t\tcurrent?: number;\n\t}\n\n\texport interface NextProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/** `id` of the {@link Carousel.Viewport} this control scrolls forward through. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb a `carouselControls()` mixin listens for. Defaults to `\"--ui-next\"`. */\n\t\tcommand?: \"--ui-next\";\n\t}\n}\n\n/**\n * The carousel root: a `<section>` stacking {@link Carousel.Viewport} and\n * {@link Carousel.Controls} in a column, declaring the `--ui-carousel-*`\n * custom properties its descendants read with per-instance defaults.\n *\n * @param handle Runtime handle carrying the host `<section>`'s props.\n * @returns The render function producing the carousel's markup.\n * @example\n * <Carousel aria-label={t(\"gallery.label\")}>\n * \t<Carousel.Viewport id=\"gallery-viewport\">\n * \t\t<Carousel.Track>\n * \t\t\t<Carousel.Slide><img src={photo.src} alt={photo.alt} /></Carousel.Slide>\n * \t\t</Carousel.Track>\n * \t</Carousel.Viewport>\n * \t<Carousel.Controls>\n * \t\t<Carousel.Previous commandfor=\"gallery-viewport\" aria-label={t(\"gallery.previous\")} />\n * \t\t<Carousel.Next commandfor=\"gallery-viewport\" aria-label={t(\"gallery.next\")} />\n * \t</Carousel.Controls>\n * </Carousel>\n * @example\n * // Landing browser-flow strip: widen `--ui-carousel-slide-size` for product\n * // frames and keep Previous/Next on `size=\"sm\"` so controls stay quiet.\n * <Carousel\n * \taria-label={t(\"flows.label\")}\n * \tstyle={{ \"--ui-carousel-slide-size\": \"28rem\" }}\n * >\n * \t<Carousel.Viewport id=\"flows\" mix={[carouselControls()]}>\n * \t\t<Carousel.Track>{slides}</Carousel.Track>\n * \t</Carousel.Viewport>\n * \t<Carousel.Controls>\n * \t\t<Carousel.Previous commandfor=\"flows\" aria-label={t(\"flows.previous\")} />\n * \t\t<Carousel.Next commandfor=\"flows\" aria-label={t(\"flows.next\")} />\n * \t</Carousel.Controls>\n * </Carousel>\n */\nexport function Carousel(handle: Handle<Carousel.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<section\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"carousel\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\tgap(3),\n\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\"ui-carousel-gap\": \"1rem\",\n\t\t\t\t\t\t\t\"ui-carousel-slide-size\": \"18rem\",\n\t\t\t\t\t\t\t\"ui-carousel-padding\": \"0px\",\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 * A `<div>` scrolling {@link Carousel.Track} along the inline axis via logical\n * properties for correct writing direction, with mandatory scroll-snap stops;\n * scroll padding reads `--ui-carousel-padding` to clear the track's own padding.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the viewport's markup.\n * @example\n * <Carousel.Viewport id=\"gallery-viewport\">\n * \t<Carousel.Track>{slides}</Carousel.Track>\n * </Carousel.Viewport>\n */\nCarousel.Viewport = function CarouselViewport(handle: Handle<Carousel.ViewportProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"viewport\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_VIEWPORT_ROLE, tabIndex: DEFAULT_VIEWPORT_TAB_INDEX }),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\toverflowInline: \"auto\",\n\t\t\t\t\t\t\toverflowBlock: \"hidden\",\n\t\t\t\t\t\t\tscrollBehavior: \"smooth\",\n\t\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\t\tscrollPaddingInline: \"var(--ui-carousel-padding, 0px)\",\n\t\t\t\t\t\t\t\"-webkit-overflow-scrolling\": \"touch\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", raw({ scrollBehavior: \"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);\n\t};\n};\n\n/**\n * The carousel's slide row: a `<div>` laying its {@link Carousel.Slide}\n * children out in one inline row, gapped by `--ui-carousel-gap` and padded by\n * `--ui-carousel-padding` so the first and last slide can still center.\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 * <Carousel.Track>\n * \t<Carousel.Slide>{firstSlide}</Carousel.Slide>\n * \t<Carousel.Slide>{secondSlide}</Carousel.Slide>\n * </Carousel.Track>\n */\nCarousel.Track = function CarouselTrack(handle: Handle<Carousel.TrackProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"track\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[flex(), gap(\"var(--ui-carousel-gap, 1rem)\"), pi(\"var(--ui-carousel-padding, 0px)\")],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A single slide: a `<div>` held at `--ui-carousel-slide-size` along the\n * inline axis, snapping to its inline-start edge so the viewport settles on a\n * slide boundary.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the slide's markup.\n * @example\n * <Carousel.Slide><img src={photo.src} alt={photo.alt} /></Carousel.Slide>\n */\nCarousel.Slide = function CarouselSlide(handle: Handle<Carousel.SlideProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"slide\"\n\t\t\t\tdata-carousel-slide=\"\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_SLIDE_ROLE }),\n\t\t\t\t\t\tgrow(0),\n\t\t\t\t\t\tshrink(0),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The slide snaps to the viewport's start edge and leaves the scroll free to pass it:\n\t\t\t\t\t\t * `scroll-snap-stop: always` clamps programmatic scrolls too, so every dot would move\n\t\t\t\t\t\t * one slide and none would reach the slide it names.\n\t\t\t\t\t\t */\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tflexBasis: \"var(--ui-carousel-slide-size, 18rem)\",\n\t\t\t\t\t\t\tscrollSnapAlign: \"start\",\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 * The carousel's control row: a `<div>` laying {@link Carousel.Previous} and\n * {@link Carousel.Next} out as an end-aligned, vertically centered row.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the control row's markup.\n * @example\n * <Carousel.Controls>\n * \t<Carousel.Previous commandfor=\"gallery-viewport\" aria-label={t(\"gallery.previous\")} />\n * \t<Carousel.Next commandfor=\"gallery-viewport\" aria-label={t(\"gallery.next\")} />\n * </Carousel.Controls>\n */\nCarousel.Controls = function CarouselControls(handle: Handle<Carousel.ControlsProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"controls\"\n\t\t\t\tmix={mergeMix([flex(), items(\"center\"), gap(2), justify(\"end\")], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A static control scrolling {@link Carousel.Viewport} named by `commandfor` back\n * one slide when a hydrated `carouselControls()` mixin handles `\"--ui-prev\"`; custom\n * `children` replacing the chevron still need their own `aria-label`.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the control's markup.\n * @example\n * <Carousel.Previous commandfor=\"gallery-viewport\" aria-label={t(\"gallery.previous\")} />\n */\nCarousel.Previous = function CarouselPrevious(handle: Handle<Carousel.PreviousProps>) {\n\treturn () => {\n\t\tlet { variant, color, size, command, children, mix, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CONTROL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CONTROL_COLOR;\n\t\tlet resolvedSize = size ?? DEFAULT_CONTROL_SIZE;\n\t\tlet resolvedCommand = command ?? DEFAULT_PREVIOUS_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tsize={resolvedSize}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"previous\"\n\t\t\t\tmix={mergeMix([minIs(0), when(\"& > svg\", [is(4), bs(4)])], mix)}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronLeftIcon />}\n\t\t\t</Button>\n\t\t);\n\t};\n};\n\n/**\n * A static control scrolling {@link Carousel.Viewport} named by `commandfor` forward\n * one slide when a hydrated `carouselControls()` mixin handles `\"--ui-next\"`; custom\n * `children` replacing the chevron still need their own `aria-label`.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the control's markup.\n * @example\n * <Carousel.Next commandfor=\"gallery-viewport\" aria-label={t(\"gallery.next\")} />\n */\nCarousel.Next = function CarouselNext(handle: Handle<Carousel.NextProps>) {\n\treturn () => {\n\t\tlet { variant, color, size, command, children, mix, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CONTROL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CONTROL_COLOR;\n\t\tlet resolvedSize = size ?? DEFAULT_CONTROL_SIZE;\n\t\tlet resolvedCommand = command ?? DEFAULT_NEXT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tsize={resolvedSize}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"next\"\n\t\t\t\tmix={mergeMix([minIs(0), when(\"& > svg\", [is(4), bs(4)])], mix)}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronRightIcon />}\n\t\t\t</Button>\n\t\t);\n\t};\n};\n\n/**\n * A row of dots, one `--ui-goto` invoker per slide, the one in view marked with\n * `aria-current`. Each dot draws 6px inside a 24px target, so a row reads as a position\n * indicator and still takes a thumb; it needs `carouselControls()` or {@link CarouselSync}.\n *\n * @example <Carousel.Dots commandfor=\"photos\" count={3} label={(i) => `Photo ${i + 1} of 3`} />\n */\nCarousel.Dots = function CarouselDots(handle: Handle<Carousel.DotsProps>) {\n\treturn () => {\n\t\tlet { commandfor, count, current = 0, label, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"dots\"\n\t\t\t\tmix={mergeMix([flex(), justify(\"center\"), items(\"center\")], mix)}\n\t\t\t>\n\t\t\t\t{Array.from({ length: count }, (_, index) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tcommandfor={commandfor}\n\t\t\t\t\t\tcommand=\"--ui-goto\"\n\t\t\t\t\t\tdata-slide={String(index)}\n\t\t\t\t\t\taria-label={label(index)}\n\t\t\t\t\t\taria-current={index === current ? \"true\" : undefined}\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\tinlineSize: \"var(--ui-carousel-dot-target, 1.5rem)\",\n\t\t\t\t\t\t\t\tblockSize: \"var(--ui-carousel-dot-target, 1.5rem)\",\n\t\t\t\t\t\t\t\tmarginInline: \"calc((var(--ui-carousel-dot-target, 1.5rem) - 0.75rem) / -2)\",\n\t\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\t\tborder: \"0\",\n\t\t\t\t\t\t\t\tbackground: \"transparent\",\n\t\t\t\t\t\t\t\tcursor: \"pointer\",\n\t\t\t\t\t\t\t\t\"&::before\": {\n\t\t\t\t\t\t\t\t\tcontent: '\"\"',\n\t\t\t\t\t\t\t\t\tinlineSize: \"0.375rem\",\n\t\t\t\t\t\t\t\t\tblockSize: \"0.375rem\",\n\t\t\t\t\t\t\t\t\tborderRadius: \"999px\",\n\t\t\t\t\t\t\t\t\tbackgroundColor:\n\t\t\t\t\t\t\t\t\t\t\"var(--ui-carousel-dot, color-mix(in oklch, currentColor 45%, transparent))\",\n\t\t\t\t\t\t\t\t\ttransition: \"background-color 150ms ease, scale 150ms ease\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[aria-current=\"true\"]::before',\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-carousel-dot-current, currentColor)\",\n\t\t\t\t\t\t\t\t\tscale: \"1.25\",\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 0 })),\n\t\t\t\t\t\t\tmedia(\n\t\t\t\t\t\t\t\t\"(prefers-reduced-motion: reduce)\",\n\t\t\t\t\t\t\t\traw({ \"&::before\": { transition: \"none\" } }),\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</div>\n\t\t);\n\t};\n};\n\n/**\n * The position as `n / N` in tabular figures, rewritten as the viewport scrolls by\n * `carouselControls()` or {@link CarouselSync}. It is hidden from assistive tech, since\n * the dots' current marker already says the same.\n *\n * @example <Carousel.Count viewport=\"photos\" total={3} />\n */\nCarousel.Count = function CarouselCount(handle: Handle<Carousel.CountProps>) {\n\treturn () => {\n\t\tlet { current = 0, mix, total, viewport, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\t{...rest}\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tdata-slot=\"count\"\n\t\t\t\tdata-carousel-count-for={viewport}\n\t\t\t\tmix={mergeMix([raw({ fontVariantNumeric: \"tabular-nums\" })], mix)}\n\t\t\t>\n\t\t\t\t{current + 1} / {total}\n\t\t\t</span>\n\t\t);\n\t};\n};\n\n/**\n * The island that runs a Carousel without a page-written island around its viewport: a\n * hidden marker placed anywhere inside the {@link Carousel} root. It loads from\n * `@sdxc/ui/carousel`, which the app's browser entry maps to an import.\n *\n * @example <Carousel>…<CarouselSync /></Carousel>\n */\nexport const CarouselSync: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/carousel#CarouselSync\",\n\tfunction CarouselSync() {\n\t\treturn () => <span hidden mix={[carouselSync()]} />;\n\t},\n);\n"
13
14
  },
14
15
  "test": null
15
16
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "letterbox",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "Letterbox"
7
+ ],
8
+ "source": {
9
+ "path": "letterbox.tsx",
10
+ "content": "/**\n * A frame that fills whatever box holds it and centres a fixed-ratio surface inside, with bars\n * on the two sides the ratio leaves empty. The surface is a size container, so content drawn on\n * it in `cqw`/`cqh` scales with it: a slide, a game screen or a player at any window size.\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 { mergeMix } from \"@sdxc/u/general\";\nimport { css } from \"remix/component\";\n\nimport { mergeStyle } from \"@sdxc/ui/utils\";\n\n/** 16:9, the widescreen ratio a frame keeps without a `ratio` prop. */\nconst DEFAULT_RATIO = 16 / 9;\n\n/**\n * Prop types for {@link Letterbox}.\n */\nexport namespace Letterbox {\n\t/**\n\t * Props accepted by {@link Letterbox}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Width divided by height of the surface, as a number so the frame can size the surface\n\t\t * with it (`4 / 3`, `1`).\n\t\t *\n\t\t * @default 16 / 9\n\t\t */\n\t\tratio?: number;\n\t}\n\n\t/**\n\t * Props accepted by {@link Letterbox.Surface}.\n\t */\n\texport interface SurfaceProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Fills its container and paints the bars in `--ui-letterbox-bars` (black by default). In a\n * container with no definite height the frame takes its height from its width at the ratio, so\n * the surface fills it with no bars. The ratio rides on `--ui-letterbox-ratio`.\n *\n * @param handle Runtime handle carrying the frame's props.\n * @returns The render function producing the frame's markup.\n * @example\n * <Letterbox ratio={16 / 9}>\n * \t<Letterbox.Surface mix={css({ fontSize: \"4cqh\" })}>Slide one</Letterbox.Surface>\n * </Letterbox>\n */\nexport function Letterbox(handle: Handle<Letterbox.Props>) {\n\treturn () => {\n\t\tlet { ratio, style, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"letterbox\"\n\t\t\t\tstyle={mergeStyle(style, { \"--ui-letterbox-ratio\": String(ratio ?? DEFAULT_RATIO) })}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\tcss({\n\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\tinlineSize: \"100%\",\n\t\t\t\t\t\tblockSize: \"100%\",\n\t\t\t\t\t\taspectRatio: \"var(--ui-letterbox-ratio)\",\n\t\t\t\t\t\tcontainerType: \"size\",\n\t\t\t\t\t\toverflow: \"hidden\",\n\t\t\t\t\t\tbackground: \"var(--ui-letterbox-bars, #000)\",\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 * The fixed-ratio area inside a {@link Letterbox}: as large as fits the frame, centred on both\n * axes, and a size container, so its children size in `cqw`/`cqh` of the surface itself. Name\n * the container through `mix` to target it from an `@container` query.\n *\n * @param handle Runtime handle carrying the surface's props.\n * @returns The render function producing the surface's markup.\n * @example\n * <Letterbox.Surface mix={css({ containerName: \"slide\" })}>{slide}</Letterbox.Surface>\n */\nLetterbox.Surface = function LetterboxSurface(handle: Handle<Letterbox.SurfaceProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"surface\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\tcss({\n\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\tinset: 0,\n\t\t\t\t\t\tmargin: \"auto\",\n\t\t\t\t\t\tinlineSize: \"min(100cqw, calc(100cqh * var(--ui-letterbox-ratio)))\",\n\t\t\t\t\t\tblockSize: \"min(100cqh, calc(100cqw / var(--ui-letterbox-ratio)))\",\n\t\t\t\t\t\tcontainerType: \"size\",\n\t\t\t\t\t\toverflow: \"clip\",\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
+ },
12
+ "test": {
13
+ "path": "letterbox.browser.test.tsx",
14
+ "content": "/**\n * Holds the letterbox to its layout in a real browser: the surface keeps its ratio in any box,\n * barred top and bottom in a tall one and left and right in a wide one, takes its height from\n * its width in a box without one, and lets its children size in its own container units.\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 { css } from \"remix/component\";\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\n\nimport { Letterbox } from \"@sdxc/ui/letterbox\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\n/** Mounts a node in a box of the given size; a box without `height` takes its content's. */\nfunction mount(node: RemixNode, box: { width: number; height?: number }) {\n\tlet container = document.createElement(\"div\");\n\tcontainer.style.width = `${box.width}px`;\n\tif (box.height !== undefined) container.style.height = `${box.height}px`;\n\tdocument.body.appendChild(container);\n\tmounted = render(node, { container });\n\treturn mounted;\n}\n\n/** The surface's box relative to the frame's. */\nfunction surface(result: RenderResult) {\n\tlet outer = result.$('[data-slot=\"letterbox\"]')!.getBoundingClientRect();\n\tlet inner = result.$('[data-slot=\"surface\"]')!.getBoundingClientRect();\n\treturn {\n\t\tleft: inner.left - outer.left,\n\t\ttop: inner.top - outer.top,\n\t\twidth: inner.width,\n\t\theight: inner.height,\n\t};\n}\n\ndescribe(\"Letterbox\", () => {\n\ttest(\"bars a 16:9 surface top and bottom in a tall box\", () => {\n\t\tlet result = mount(\n\t\t\t<Letterbox>\n\t\t\t\t<Letterbox.Surface />\n\t\t\t</Letterbox>,\n\t\t\t{ width: 800, height: 600 },\n\t\t);\n\t\texpect(surface(result)).toEqual({ left: 0, top: 75, width: 800, height: 450 });\n\t});\n\n\ttest(\"bars the surface left and right in a wide box\", () => {\n\t\tlet result = mount(\n\t\t\t<Letterbox>\n\t\t\t\t<Letterbox.Surface />\n\t\t\t</Letterbox>,\n\t\t\t{ width: 1000, height: 450 },\n\t\t);\n\t\texpect(surface(result)).toEqual({ left: 100, top: 0, width: 800, height: 450 });\n\t});\n\n\ttest(\"keeps the ratio it is given\", () => {\n\t\tlet result = mount(\n\t\t\t<Letterbox ratio={4 / 3}>\n\t\t\t\t<Letterbox.Surface />\n\t\t\t</Letterbox>,\n\t\t\t{ width: 800, height: 300 },\n\t\t);\n\t\texpect(surface(result)).toEqual({ left: 200, top: 0, width: 400, height: 300 });\n\t});\n\n\ttest(\"takes its height from its width when its box has none\", () => {\n\t\tlet result = mount(\n\t\t\t<Letterbox>\n\t\t\t\t<Letterbox.Surface />\n\t\t\t</Letterbox>,\n\t\t\t{ width: 640 },\n\t\t);\n\t\texpect(surface(result)).toEqual({ left: 0, top: 0, width: 640, height: 360 });\n\t});\n\n\ttest(\"sizes its children in the surface's container units\", () => {\n\t\tlet result = mount(\n\t\t\t<Letterbox>\n\t\t\t\t<Letterbox.Surface>\n\t\t\t\t\t<div data-testid=\"half\" mix={css({ inlineSize: \"50cqw\", blockSize: \"10cqh\" })} />\n\t\t\t\t</Letterbox.Surface>\n\t\t\t</Letterbox>,\n\t\t\t{ width: 1000, height: 450 },\n\t\t);\n\t\tlet half = result.$('[data-testid=\"half\"]')!.getBoundingClientRect();\n\t\texpect({ width: half.width, height: half.height }).toEqual({ width: 400, height: 45 });\n\t});\n\n\ttest(\"paints the bars in the color `--ui-letterbox-bars` names\", () => {\n\t\tlet result = mount(\n\t\t\t<Letterbox style={{ \"--ui-letterbox-bars\": \"rgb(255, 0, 0)\" }}>\n\t\t\t\t<Letterbox.Surface />\n\t\t\t</Letterbox>,\n\t\t\t{ width: 800, height: 600 },\n\t\t);\n\t\texpect(getComputedStyle(result.$('[data-slot=\"letterbox\"]')!).backgroundColor).toBe(\n\t\t\t\"rgb(255, 0, 0)\",\n\t\t);\n\t});\n});\n"
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "lightbox",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "Lightbox",
7
+ "LightboxControls"
8
+ ],
9
+ "source": {
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"
12
+ },
13
+ "test": {
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"
16
+ }
17
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "media-grid",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "MediaGrid"
7
+ ],
8
+ "source": {
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"
11
+ },
12
+ "test": {
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"
15
+ }
16
+ }