@sdxc/kit 2026.10.30 → 2026.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.jsonl +89 -0
- package/dist/make/declare.js +32 -11
- package/package.json +2 -2
- package/registry/ui/accordion.json +2 -2
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/alert.json +2 -2
- package/registry/ui/aspect-ratio.json +2 -2
- package/registry/ui/avatar.json +6 -3
- package/registry/ui/badge.json +2 -2
- package/registry/ui/breadcrumbs.json +2 -2
- package/registry/ui/button.json +5 -3
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/card.json +2 -2
- package/registry/ui/carousel.json +2 -2
- package/registry/ui/checkbox-group.json +2 -2
- package/registry/ui/checkbox.json +2 -2
- package/registry/ui/combobox.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/cta-group.json +2 -2
- package/registry/ui/date-field.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/description.json +2 -2
- package/registry/ui/dialog-dismiss.json +13 -0
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/disclosure.json +2 -2
- package/registry/ui/drawer.json +2 -2
- package/registry/ui/field-error.json +2 -2
- package/registry/ui/form.json +2 -2
- package/registry/ui/group.json +2 -2
- package/registry/ui/header.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/heading.json +3 -3
- package/registry/ui/highlight.json +3 -3
- package/registry/ui/hover-card.json +2 -2
- package/registry/ui/image-placeholder.json +2 -2
- package/registry/ui/input.json +2 -2
- package/registry/ui/item.json +2 -2
- package/registry/ui/keyboard.json +2 -2
- package/registry/ui/label.json +2 -2
- package/registry/ui/link-button.json +5 -3
- package/registry/ui/link.json +2 -2
- package/registry/ui/listbox.json +2 -2
- package/registry/ui/menu.json +2 -2
- package/registry/ui/meter.json +2 -2
- package/registry/ui/modal.json +2 -2
- package/registry/ui/nav-link.json +2 -2
- package/registry/ui/navigation-menu.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/otp-field.json +2 -2
- package/registry/ui/overlay-arrow.json +2 -2
- package/registry/ui/pagination.json +2 -2
- package/registry/ui/popover.json +2 -2
- package/registry/ui/progress-bar.json +2 -2
- package/registry/ui/radio-group.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/scroll-area.json +2 -2
- package/registry/ui/search-field.json +2 -2
- package/registry/ui/section.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/selection-indicator.json +2 -2
- package/registry/ui/sentinel-row.json +2 -2
- package/registry/ui/separator.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/registry/ui/sheet.json +2 -2
- package/registry/ui/sidebar.json +2 -2
- package/registry/ui/slider.json +2 -2
- package/registry/ui/spinner.json +2 -2
- package/registry/ui/switch.json +2 -2
- package/registry/ui/tabs.json +2 -2
- package/registry/ui/tag-group.json +2 -2
- package/registry/ui/text-field.json +2 -2
- package/registry/ui/text.json +2 -2
- package/registry/ui/textarea.json +2 -2
- package/registry/ui/time-field.json +2 -2
- package/registry/ui/toggle-button.json +2 -2
- package/registry/ui/tooltip.json +2 -2
- package/registry/ui/typeset.json +2 -2
- package/registry/ui/youtube-embed.json +2 -2
- package/stubs/scaffold.controller.index.stub +1 -1
- package/registry/ui/attachment.json +0 -15
- package/registry/ui/bubble.json +0 -13
- package/registry/ui/chart.json +0 -13
- package/registry/ui/color-area.json +0 -13
- package/registry/ui/color-field.json +0 -20
- package/registry/ui/color-picker.json +0 -17
- package/registry/ui/color-slider.json +0 -13
- package/registry/ui/color-swatch-picker.json +0 -15
- package/registry/ui/color-swatch.json +0 -13
- package/registry/ui/color-wheel.json +0 -13
- package/registry/ui/context-menu.json +0 -16
- package/registry/ui/drop-indicator.json +0 -13
- package/registry/ui/drop-zone.json +0 -13
- package/registry/ui/empty.json +0 -15
- package/registry/ui/feature.json +0 -18
- package/registry/ui/file-trigger.json +0 -13
- package/registry/ui/grid-list.json +0 -18
- package/registry/ui/logo-cloud.json +0 -16
- package/registry/ui/marker.json +0 -13
- package/registry/ui/marketing-header.json +0 -18
- package/registry/ui/marketing-section.json +0 -16
- package/registry/ui/menubar.json +0 -13
- package/registry/ui/message-scroller.json +0 -16
- package/registry/ui/message.json +0 -13
- package/registry/ui/resizable.json +0 -13
- package/registry/ui/shortcut-list.json +0 -18
- package/registry/ui/skeleton.json +0 -13
- package/registry/ui/split.json +0 -16
- package/registry/ui/stat-strip.json +0 -16
- package/registry/ui/table.json +0 -16
- package/registry/ui/toast.json +0 -16
- package/registry/ui/toolbar.json +0 -13
- package/registry/ui/tree.json +0 -18
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toggle-button",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"ToggleButton",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
],
|
|
9
9
|
"source": {
|
|
10
10
|
"path": "toggle-button.tsx",
|
|
11
|
-
"content": "/**\n * A native `<button>` that reflects an on/off state through its own\n * `aria-pressed` attribute instead of a separate boolean prop — muting a\n * track, toggling bold text, filtering a view. Shares {@link Button}'s\n * semantic color role, visual weight variant, and size, and layers a tinted\n * background on top of the outline and ghost variants once pressed, so a\n * toggled control reads as active without a fourth variant of its own.\n * {@link ToggleButtonGroup} lays a run of these out along a shared axis.\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 { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, opacity } from \"@sdxc/u/effects\";\nimport { cursor, userSelect } from \"@sdxc/u/general\";\nimport { flex, flexCol, inlineFlex, items, justify, gap, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minBs, pi, pb, pie, pis } from \"@sdxc/u/size\";\nimport { when, hover, active, data } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { glyphEdges } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link ToggleButton} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: ToggleButton.Color = \"neutral\";\n\n/** Visual weight {@link ToggleButton} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: ToggleButton.Variant = \"outline\";\n\n/** Size variant {@link ToggleButton} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: ToggleButton.Size = \"md\";\n\n/** Role {@link ToggleButtonGroup} carries by default, matching the arrow-key-navigable pattern a row of grouped toggle buttons follows. */\nconst DEFAULT_GROUP_ROLE = \"toolbar\";\n\n/** Layout axis {@link ToggleButtonGroup} falls back to when `orientation` is omitted. */\nconst DEFAULT_GROUP_ORIENTATION: ToggleButtonGroup.Orientation = \"horizontal\";\n\n/**\n * Folds the pressed state a consumer passed into the token the host renders.\n * ARIA reads text, so a boolean `true`/`false` would serialize as the bare\n * name or vanish; `\"false\"` stays explicit since its absence would leave the button with no toggle semantics at all.\n *\n * @param pressed The state as the consumer expressed it.\n * @returns The token to render.\n */\nfunction resolveAriaPressed(\n\tpressed: ToggleButton.Props[\"aria-pressed\"],\n): \"true\" | \"false\" | \"mixed\" {\n\tif (pressed === \"mixed\") return \"mixed\";\n\tif (pressed === true || pressed === \"true\") return \"true\";\n\treturn \"false\";\n}\n\n/**\n * Prop types for {@link ToggleButton}.\n */\nexport namespace ToggleButton {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Visual weight: a solid fill with an on-solid foreground, a transparent\n\t * fill with a strong colored border, or a fully transparent fill with\n\t * just a colored label. Pressing tints `\"outline\"`/`\"ghost\"`; `\"solid\"` already reads filled.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\";\n\n\t/**\n\t * Size variant controlling the button's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Props accepted by {@link ToggleButton}, with `aria-pressed` made\n\t * required: it carries the entire pressed state, read straight off the\n\t * rendered attribute by this component's styling and the `pressToggle()` mixin.\n\t */\n\texport interface Props extends Omit<TagProps<\"button\">, \"aria-pressed\"> {\n\t\t/** The button's pressed state, reflected directly onto the host's own `aria-pressed` attribute. */\n\t\t\"aria-pressed\": NonNullable<TagProps<\"button\">[\"aria-pressed\"]>;\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t}\n}\n\n/**\n * Renders a native `<button aria-pressed>` host clicking which submits its\n * enclosing form by default, flipping the state through a server round-trip\n * with no script required; pair `pressToggle()` through `mix` in a hydrated island to skip the round-trip.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the toggle button's markup.\n * @example\n * <ToggleButton aria-pressed={isMuted} aria-label={t(\"player.mute\")}>\n * \t<VolumeXIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={isBold} variant=\"ghost\" size=\"sm\" aria-label={t(\"editor.bold\")}>\n * \t<BoldIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={filter === \"active\"} color=\"brand\" name=\"filter\" value=\"active\">\n * \t{t(\"tasks.filterActive\")}\n * </ToggleButton>\n */\nexport function ToggleButton(handle: Handle<ToggleButton.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, children, mix, \"aria-pressed\": pressed, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\t\tlet resolvedPressed = resolveAriaPressed(pressed);\n\t\tlet edges = glyphEdges(children);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"ToggleButton: an icon-only toggle needs an `aria-label` describing what it does — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\t{...rest}\n\t\t\t\taria-pressed={resolvedPressed}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tdata-glyph-start={edges.start || undefined}\n\t\t\t\tdata-glyph-end={edges.end || undefined}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t]),\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tgap(\"0.5rem\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph is sized against the label beside it and holds that size, so the row keeps the\n\t\t\t\t\t * height its text and padding ask for; the default `flex-shrink: 1` would squash the glyph\n\t\t\t\t\t * ahead of the words.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t/** A small control reaches `--ui-target-size` however a consumer positions it. */\n\t\t\t\t\thitArea({ anchor: \"flex-center\" }),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The row measure is stated, so the control lines up with a field of the same size when\n\t\t\t\t\t * a Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t */\n\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\twhen('&[data-size=\"sm\"]', [\n\t\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\t\tpb(\"0.375rem\"),\n\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-size=\"lg\"]', [\n\t\t\t\t\t\tpi(\"1.25rem\"),\n\t\t\t\t\t\tpb(\"0.625rem\"),\n\t\t\t\t\t\tminBs(\"3rem\"),\n\t\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\t]),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph beside a label carries its own side bearing, so the padding on that\n\t\t\t\t\t * side drops one step and the glyph and the words read as evenly inset.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&[data-glyph-start]:has(> svg:first-child)\", [\n\t\t\t\t\t\tpis(\"0.75rem\"),\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pis(\"0.5rem\")),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pis(\"1rem\")),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&[data-glyph-end]:has(> svg:last-child)\", [\n\t\t\t\t\t\tpie(\"0.75rem\"),\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pie(\"0.5rem\")),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pie(\"1rem\")),\n\t\t\t\t\t]),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tdata(\"size\", \"sm\", text(\"xs\")),\n\t\t\t\t\tdata(\"size\", \"lg\", text(\"base\")),\n\t\t\t\t\twhen('&[data-variant=\"solid\"]', [\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tbg(\"brand.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"brand.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\tbg(\"neutral.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"neutral.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tbg(\"success.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"success.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"success.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tbg(\"warning.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"warning.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"warning.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tbg(\"danger.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"danger.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"danger.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-variant=\"ghost\"]', bg(\"transparent\")),\n\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tborder(\"brand.border\"),\n\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\thover([bg(\"brand.bg-tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\tborder(\"neutral.border\"),\n\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\thover([bg(\"neutral.bg-tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tborder(\"success.border\"),\n\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\thover([bg(\"success.bg-tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tborder(\"danger.border\"),\n\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\thover([bg(\"danger.bg-tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tborder(\"warning.border\"),\n\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\thover([bg(\"warning.bg-tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-variant=\"ghost\"]', [\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\thover(bg(\"brand.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\thover(bg(\"success.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\thover(bg(\"danger.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\thover(bg(\"warning.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-pressed=\"true\"]', [\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"brand\"], &[data-variant=\"ghost\"][data-color=\"brand\"]',\n\t\t\t\t\t\t\tbg(\"brand.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"neutral\"], &[data-variant=\"ghost\"][data-color=\"neutral\"]',\n\t\t\t\t\t\t\tbg(\"neutral.bg-tint-pressed\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"success\"], &[data-variant=\"ghost\"][data-color=\"success\"]',\n\t\t\t\t\t\t\tbg(\"success.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"danger\"], &[data-variant=\"ghost\"][data-color=\"danger\"]',\n\t\t\t\t\t\t\tbg(\"danger.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"warning\"], &[data-variant=\"ghost\"][data-color=\"warning\"]',\n\t\t\t\t\t\t\tbg(\"warning.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\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</button>\n\t\t);\n\t};\n}\n\n/**\n * Prop types for {@link ToggleButtonGroup}.\n */\nexport namespace ToggleButtonGroup {\n\t/**\n\t * Axis a group's toggle buttons lay out along: a single row, or a single\n\t * column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus `mix`. Each nested\n\t * {@link ToggleButton} tracks its own `aria-pressed` and `name`/`value`\n\t * independently; this host only contributes shared grouping and layout.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_GROUP_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n}\n\n/**\n * Renders a `role=\"toolbar\"` `<div>` laying a run of independently pressed\n * {@link ToggleButton} children out in a row, or a column when `orientation`\n * is `\"vertical\"`; each toggle button owns its own `aria-pressed` state, and this host contributes only shared layout and grouping.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.textStyle\")}>\n * \t<ToggleButton aria-pressed={isBold} aria-label={t(\"editor.bold\")}>\n * \t\t<BoldIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={isItalic} aria-label={t(\"editor.italic\")}>\n * \t\t<ItalicIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.alignment\")} orientation=\"vertical\">\n * \t<ToggleButton aria-pressed={align === \"start\"} aria-label={t(\"editor.alignStart\")}>\n * \t\t<AlignStartIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={align === \"center\"} aria-label={t(\"editor.alignCenter\")}>\n * \t\t<AlignCenterIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n */\nexport function ToggleButtonGroup(handle: Handle<ToggleButtonGroup.Props>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_GROUP_ORIENTATION;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_GROUP_ROLE }),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(\"0.25rem\"),\n\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [flexCol(), items(\"start\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
"content": "/**\n * A native `<button>` that reflects an on/off state through its own\n * `aria-pressed` attribute instead of a separate boolean prop — muting a\n * track, toggling bold text, filtering a view. Shares {@link Button}'s\n * semantic color role, visual weight variant, and size, and layers a tinted\n * background on top of the outline and ghost variants once pressed, so a\n * toggled control reads as active without a fourth variant of its own.\n * {@link ToggleButtonGroup} lays a run of these out along a shared axis.\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 { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, opacity } from \"@sdxc/u/effects\";\nimport { cursor, userSelect, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, inlineFlex, items, justify, gap, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minBs, pi, pb, pie, pis } from \"@sdxc/u/size\";\nimport { when, hover, active, data } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { glyphEdges } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link ToggleButton} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: ToggleButton.Color = \"neutral\";\n\n/** Visual weight {@link ToggleButton} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: ToggleButton.Variant = \"outline\";\n\n/** Size variant {@link ToggleButton} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: ToggleButton.Size = \"md\";\n\n/** Role {@link ToggleButtonGroup} carries by default, matching the arrow-key-navigable pattern a row of grouped toggle buttons follows. */\nconst DEFAULT_GROUP_ROLE = \"toolbar\";\n\n/** Layout axis {@link ToggleButtonGroup} falls back to when `orientation` is omitted. */\nconst DEFAULT_GROUP_ORIENTATION: ToggleButtonGroup.Orientation = \"horizontal\";\n\n/**\n * Folds the pressed state a consumer passed into the token the host renders.\n * ARIA reads text, so a boolean `true`/`false` would serialize as the bare\n * name or vanish; `\"false\"` stays explicit since its absence would leave the button with no toggle semantics at all.\n *\n * @param pressed The state as the consumer expressed it.\n * @returns The token to render.\n */\nfunction resolveAriaPressed(\n\tpressed: ToggleButton.Props[\"aria-pressed\"],\n): \"true\" | \"false\" | \"mixed\" {\n\tif (pressed === \"mixed\") return \"mixed\";\n\tif (pressed === true || pressed === \"true\") return \"true\";\n\treturn \"false\";\n}\n\n/**\n * Prop types for {@link ToggleButton}.\n */\nexport namespace ToggleButton {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Visual weight: a solid fill with an on-solid foreground, a transparent\n\t * fill with a strong colored border, or a fully transparent fill with\n\t * just a colored label. Pressing tints `\"outline\"`/`\"ghost\"`; `\"solid\"` already reads filled.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\";\n\n\t/**\n\t * Size variant controlling the button's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Props accepted by {@link ToggleButton}, with `aria-pressed` made\n\t * required: it carries the entire pressed state, read straight off the\n\t * rendered attribute by this component's styling and the `pressToggle()` mixin.\n\t */\n\texport interface Props extends Omit<TagProps<\"button\">, \"aria-pressed\"> {\n\t\t/** The button's pressed state, reflected directly onto the host's own `aria-pressed` attribute. */\n\t\t\"aria-pressed\": NonNullable<TagProps<\"button\">[\"aria-pressed\"]>;\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t}\n}\n\n/**\n * Renders a native `<button aria-pressed>` host clicking which submits its\n * enclosing form by default, flipping the state through a server round-trip\n * with no script required; pair `pressToggle()` through `mix` in a hydrated island to skip the round-trip.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the toggle button's markup.\n * @example\n * <ToggleButton aria-pressed={isMuted} aria-label={t(\"player.mute\")}>\n * \t<VolumeXIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={isBold} variant=\"ghost\" size=\"sm\" aria-label={t(\"editor.bold\")}>\n * \t<BoldIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={filter === \"active\"} color=\"brand\" name=\"filter\" value=\"active\">\n * \t{t(\"tasks.filterActive\")}\n * </ToggleButton>\n */\nexport function ToggleButton(handle: Handle<ToggleButton.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, children, mix, \"aria-pressed\": pressed, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\t\tlet resolvedPressed = resolveAriaPressed(pressed);\n\t\tlet edges = glyphEdges(children);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"ToggleButton: an icon-only toggle needs an `aria-label` describing what it does — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\t{...rest}\n\t\t\t\taria-pressed={resolvedPressed}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tdata-glyph-start={edges.start || undefined}\n\t\t\t\tdata-glyph-end={edges.end || undefined}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tinlineFlex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tgap(\"0.5rem\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph is sized against the label beside it and holds that size, so the row keeps the\n\t\t\t\t\t\t * height its text and padding ask for; the default `flex-shrink: 1` would squash the glyph\n\t\t\t\t\t\t * ahead of the words.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\t/** A small control reaches `--ui-target-size` however a consumer positions it. */\n\t\t\t\t\t\thitArea({ anchor: \"flex-center\" }),\n\t\t\t\t\t\tuserSelect(),\n\t\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The row measure is stated, so the control lines up with a field of the same size when\n\t\t\t\t\t\t * a Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', [\n\t\t\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\t\t\tpb(\"0.375rem\"),\n\t\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', [\n\t\t\t\t\t\t\tpi(\"1.25rem\"),\n\t\t\t\t\t\t\tpb(\"0.625rem\"),\n\t\t\t\t\t\t\tminBs(\"3rem\"),\n\t\t\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph beside a label carries its own side bearing, so the padding on that\n\t\t\t\t\t\t * side drops one step and the glyph and the words read as evenly inset.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-glyph-start]:has(> svg:first-child)\", [\n\t\t\t\t\t\t\tpis(\"0.75rem\"),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pis(\"0.5rem\")),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pis(\"1rem\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[data-glyph-end]:has(> svg:last-child)\", [\n\t\t\t\t\t\t\tpie(\"0.75rem\"),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pie(\"0.5rem\")),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pie(\"1rem\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tdata(\"size\", \"sm\", text(\"xs\")),\n\t\t\t\t\t\tdata(\"size\", \"lg\", text(\"base\")),\n\t\t\t\t\t\twhen('&[data-variant=\"solid\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tbg(\"brand.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"brand.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"brand.bg-solid-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tbg(\"neutral.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"neutral.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"neutral.bg-solid-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tbg(\"success.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"success.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"success.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"success.bg-solid-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tbg(\"warning.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"warning.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"warning.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"warning.bg-solid-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tbg(\"danger.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"danger.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"danger.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"danger.bg-solid-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-variant=\"ghost\"]', bg(\"transparent\")),\n\t\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tborder(\"brand.border\"),\n\t\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"brand.bg-tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tborder(\"neutral.border\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"neutral.bg-tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tborder(\"success.border\"),\n\t\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"success.bg-tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tborder(\"danger.border\"),\n\t\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"danger.bg-tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tborder(\"warning.border\"),\n\t\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"warning.bg-tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-variant=\"ghost\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"brand.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"success.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"danger.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"warning.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[aria-pressed=\"true\"]', [\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"brand\"], &[data-variant=\"ghost\"][data-color=\"brand\"]',\n\t\t\t\t\t\t\t\tbg(\"brand.bg-tint\"),\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'&[data-variant=\"outline\"][data-color=\"neutral\"], &[data-variant=\"ghost\"][data-color=\"neutral\"]',\n\t\t\t\t\t\t\t\tbg(\"neutral.bg-tint-pressed\"),\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'&[data-variant=\"outline\"][data-color=\"success\"], &[data-variant=\"ghost\"][data-color=\"success\"]',\n\t\t\t\t\t\t\t\tbg(\"success.bg-tint\"),\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'&[data-variant=\"outline\"][data-color=\"danger\"], &[data-variant=\"ghost\"][data-color=\"danger\"]',\n\t\t\t\t\t\t\t\tbg(\"danger.bg-tint\"),\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'&[data-variant=\"outline\"][data-color=\"warning\"], &[data-variant=\"ghost\"][data-color=\"warning\"]',\n\t\t\t\t\t\t\t\tbg(\"warning.bg-tint\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\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</button>\n\t\t);\n\t};\n}\n\n/**\n * Prop types for {@link ToggleButtonGroup}.\n */\nexport namespace ToggleButtonGroup {\n\t/**\n\t * Axis a group's toggle buttons lay out along: a single row, or a single\n\t * column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus `mix`. Each nested\n\t * {@link ToggleButton} tracks its own `aria-pressed` and `name`/`value`\n\t * independently; this host only contributes shared grouping and layout.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_GROUP_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n}\n\n/**\n * Renders a `role=\"toolbar\"` `<div>` laying a run of independently pressed\n * {@link ToggleButton} children out in a row, or a column when `orientation`\n * is `\"vertical\"`; each toggle button owns its own `aria-pressed` state, and this host contributes only shared layout and grouping.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.textStyle\")}>\n * \t<ToggleButton aria-pressed={isBold} aria-label={t(\"editor.bold\")}>\n * \t\t<BoldIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={isItalic} aria-label={t(\"editor.italic\")}>\n * \t\t<ItalicIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.alignment\")} orientation=\"vertical\">\n * \t<ToggleButton aria-pressed={align === \"start\"} aria-label={t(\"editor.alignStart\")}>\n * \t\t<AlignStartIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={align === \"center\"} aria-label={t(\"editor.alignCenter\")}>\n * \t\t<AlignCenterIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n */\nexport function ToggleButtonGroup(handle: Handle<ToggleButtonGroup.Props>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_GROUP_ORIENTATION;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_GROUP_ROLE }),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(\"0.25rem\"),\n\t\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [flexCol(), items(\"start\")]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
12
12
|
},
|
|
13
13
|
"test": {
|
|
14
14
|
"path": "toggle-button.test.tsx",
|
package/registry/ui/tooltip.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tooltip",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"overlay-arrow",
|
|
6
6
|
"popover"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "tooltip.tsx",
|
|
13
|
-
"content": "/**\n * A small floating label identifying an otherwise unlabeled control or\n * adding a supplementary hint, riding the same `popover`-attributed host and\n * CSS anchor positioning contract as {@link Popover}. Its reveal is plain\n * `:hover`/`:focus-visible` state read off the sibling immediately before it\n * in the DOM — the trigger — so pointing at or tabbing to that trigger\n * surfaces the hint with no script anywhere in the path.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle } from \"remix/component\";\n\nimport { bg, fg, fill } from \"@sdxc/u/color\";\nimport { opacity, rounded, shadow, transition, transitionBehavior } from \"@sdxc/u/effects\";\nimport { block } from \"@sdxc/u/layout\";\nimport { media, startingStyle } from \"@sdxc/u/responsive\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { scaleProperty } from \"@sdxc/u/transform\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\n\nimport { OverlayArrow } from \"@sdxc/ui/overlay-arrow\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Side of the trigger {@link Tooltip} renders against when `placement` is\n * left unset — above the trigger, the most common resting spot for a hint\n * that shouldn't cover the control it describes.\n */\nconst DEFAULT_PLACEMENT: Popover.Placement = \"top\";\n\n/**\n * Whether {@link Tooltip} renders its pointer-arrow child when a consumer\n * leaves `showArrow` unset.\n */\nconst DEFAULT_SHOW_ARROW = true;\n\n/**\n * Selector matching the pointer-hovered trigger — the sibling immediately\n * before {@link Tooltip}'s host — for use only inside `@media (hover: hover)`,\n * wrapped in `:is()` since the style serializer treats a bare selector starting with `*` as a plain declaration.\n */\nconst HOVERED_TRIGGER_SELECTOR = \":is(*:hover) ~ &\";\n\n/**\n * Selector matching {@link Tooltip}'s entered state: native `:popover-open` —\n * set by a `popovertarget` (or `commandfor`/`command=\"toggle-popover\"`)\n * invoker, or an `interestfor` attribute — or keyboard focus on the trigger sibling immediately before it.\n */\nconst ENTERED_SELECTOR = \"&:popover-open, *:focus-visible ~ &\";\n\n/**\n * Prop types for {@link Tooltip}.\n */\nexport namespace Tooltip {\n\t/**\n\t * Every prop {@link Popover.Props} accepts except `popover` and `role`,\n\t * fixed here: `popover` is always `\"hint\"` so the tooltip layers over an\n\t * open `\"auto\"` popover, and `role` is always `\"tooltip\"` per WAI-ARIA.\n\t */\n\texport interface Props extends Omit<Popover.Props, \"popover\" | \"role\"> {\n\t\t/**\n\t\t * Whether to render a pointer-arrow child pointing back at the trigger,\n\t\t * filled to match this host's own solid background so the two read as\n\t\t * one continuous shape. Defaults to {@link DEFAULT_SHOW_ARROW}.\n\t\t */\n\t\tshowArrow?: boolean;\n\t}\n}\n\n/**\n * Renders the hint through {@link Popover}, fixing `popover` to `\"hint\"` and\n * `role` to `\"tooltip\"`. The host stays present in the DOM, entering on\n * `:popover-open`, `:focus-visible`, or the trigger's hover, animated via `@starting-style`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the hint's markup.\n * @example\n * <button popovertarget=\"save-tooltip\" aria-describedby=\"save-tooltip\">\n * \t{t(\"actions.save\")}\n * </button>\n * <Tooltip id=\"save-tooltip\">{t(\"actions.saveDescription\")}</Tooltip>\n * @example\n * <a href=\"/settings\" popovertarget=\"settings-tooltip\" aria-describedby=\"settings-tooltip\">\n * \t<GearIcon aria-hidden />\n * </a>\n * <Tooltip id=\"settings-tooltip\" placement=\"right\" showArrow={false}>\n * \t{t(\"nav.settings\")}\n * </Tooltip>\n */\nexport function Tooltip(handle: Handle<Tooltip.Props>) {\n\treturn () => {\n\t\tlet { placement, showArrow, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_PLACEMENT;\n\t\tlet resolvedShowArrow = showArrow ?? DEFAULT_SHOW_ARROW;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tpopover=\"hint\"\n\t\t\t\trole=\"tooltip\"\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(2),\n\t\t\t\t\tpb(1),\n\t\t\t\t\tshadow(\"md\"),\n\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\topacity(0),\n\t\t\t\t\ttransition(\"opacity, scale, display, overlay\", {\n\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t}),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\twhen(ENTERED_SELECTOR, [block(), opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\tstartingStyle(when(ENTERED_SELECTOR, [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\tmedia(\"(hover: hover)\", [\n\t\t\t\t\t\twhen(HOVERED_TRIGGER_SELECTOR, [block(), opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\t\tstartingStyle(when(HOVERED_TRIGGER_SELECTOR, [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\t]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tscaleProperty(\"none\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t
|
|
13
|
+
"content": "/**\n * A small floating label identifying an otherwise unlabeled control or\n * adding a supplementary hint, riding the same `popover`-attributed host and\n * CSS anchor positioning contract as {@link Popover}. Its reveal is plain\n * `:hover`/`:focus-visible` state read off the sibling immediately before it\n * in the DOM — the trigger — so pointing at or tabbing to that trigger\n * surfaces the hint with no script anywhere in the path.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle } from \"remix/component\";\n\nimport { bg, fg, fill } from \"@sdxc/u/color\";\nimport { opacity, rounded, shadow, transition, transitionBehavior } from \"@sdxc/u/effects\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { block } from \"@sdxc/u/layout\";\nimport { media, startingStyle } from \"@sdxc/u/responsive\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { scaleProperty } from \"@sdxc/u/transform\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\n\nimport { OverlayArrow } from \"@sdxc/ui/overlay-arrow\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Side of the trigger {@link Tooltip} renders against when `placement` is\n * left unset — above the trigger, the most common resting spot for a hint\n * that shouldn't cover the control it describes.\n */\nconst DEFAULT_PLACEMENT: Popover.Placement = \"top\";\n\n/**\n * Whether {@link Tooltip} renders its pointer-arrow child when a consumer\n * leaves `showArrow` unset.\n */\nconst DEFAULT_SHOW_ARROW = true;\n\n/**\n * Selector matching the pointer-hovered trigger — the sibling immediately\n * before {@link Tooltip}'s host — for use only inside `@media (hover: hover)`,\n * wrapped in `:is()` since the style serializer treats a bare selector starting with `*` as a plain declaration.\n */\nconst HOVERED_TRIGGER_SELECTOR = \":is(*:hover) ~ &\";\n\n/**\n * Selector matching {@link Tooltip}'s entered state: native `:popover-open` —\n * set by a `popovertarget` (or `commandfor`/`command=\"toggle-popover\"`)\n * invoker, or an `interestfor` attribute — or keyboard focus on the trigger sibling immediately before it.\n */\nconst ENTERED_SELECTOR = \"&:popover-open, *:focus-visible ~ &\";\n\n/**\n * Prop types for {@link Tooltip}.\n */\nexport namespace Tooltip {\n\t/**\n\t * Every prop {@link Popover.Props} accepts except `popover` and `role`,\n\t * fixed here: `popover` is always `\"hint\"` so the tooltip layers over an\n\t * open `\"auto\"` popover, and `role` is always `\"tooltip\"` per WAI-ARIA.\n\t */\n\texport interface Props extends Omit<Popover.Props, \"popover\" | \"role\"> {\n\t\t/**\n\t\t * Whether to render a pointer-arrow child pointing back at the trigger,\n\t\t * filled to match this host's own solid background so the two read as\n\t\t * one continuous shape. Defaults to {@link DEFAULT_SHOW_ARROW}.\n\t\t */\n\t\tshowArrow?: boolean;\n\t}\n}\n\n/**\n * Renders the hint through {@link Popover}, fixing `popover` to `\"hint\"` and\n * `role` to `\"tooltip\"`. The host stays present in the DOM, entering on\n * `:popover-open`, `:focus-visible`, or the trigger's hover, animated via `@starting-style`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the hint's markup.\n * @example\n * <button popovertarget=\"save-tooltip\" aria-describedby=\"save-tooltip\">\n * \t{t(\"actions.save\")}\n * </button>\n * <Tooltip id=\"save-tooltip\">{t(\"actions.saveDescription\")}</Tooltip>\n * @example\n * <a href=\"/settings\" popovertarget=\"settings-tooltip\" aria-describedby=\"settings-tooltip\">\n * \t<GearIcon aria-hidden />\n * </a>\n * <Tooltip id=\"settings-tooltip\" placement=\"right\" showArrow={false}>\n * \t{t(\"nav.settings\")}\n * </Tooltip>\n */\nexport function Tooltip(handle: Handle<Tooltip.Props>) {\n\treturn () => {\n\t\tlet { placement, showArrow, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_PLACEMENT;\n\t\tlet resolvedShowArrow = showArrow ?? DEFAULT_SHOW_ARROW;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tpopover=\"hint\"\n\t\t\t\trole=\"tooltip\"\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tpi(2),\n\t\t\t\t\t\tpb(1),\n\t\t\t\t\t\tshadow(\"md\"),\n\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\t\topacity(0),\n\t\t\t\t\t\ttransition(\"opacity, scale, display, overlay\", {\n\t\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\t\twhen(ENTERED_SELECTOR, [block(), opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\t\tstartingStyle(when(ENTERED_SELECTOR, [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\t\tmedia(\"(hover: hover)\", [\n\t\t\t\t\t\t\twhen(HOVERED_TRIGGER_SELECTOR, [block(), opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\t\t\tstartingStyle(when(HOVERED_TRIGGER_SELECTOR, [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tscaleProperty(\"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\t{resolvedShowArrow && (\n\t\t\t\t\t<OverlayArrow placement={resolvedPlacement} mix={fill(\"neutral.solid\")}>\n\t\t\t\t\t\t<svg width={8} height={8} viewBox=\"0 0 8 8\">\n\t\t\t\t\t\t\t<path d=\"M0 0 L4 4 L8 0\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t</OverlayArrow>\n\t\t\t\t)}\n\t\t\t</Popover>\n\t\t);\n\t};\n}\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|
package/registry/ui/typeset.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeset",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Typeset"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "typeset.tsx",
|
|
10
|
-
"content": "/**\n * A typography layer wrapping already-rendered markdown or HTML content and\n * supplying every size, weight, spacing, and color decision through three\n * custom properties: `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`. `data-preset` swaps all three for a different rhythm\n * context; `data-not-typeset` opts a subtree out of the whole layer.\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 { keyframes } from \"@sdxc/u/animation\";\nimport { bg, border, borderEdge, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport { block, container } from \"@sdxc/u/layout\";\nimport { overflow, overflowBlock, overflowInline } from \"@sdxc/u/overflow\";\nimport { at } from \"@sdxc/u/responsive\";\nimport { is, maxIs, pb, pi, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tleading,\n\tpretty,\n\ttabularNums,\n\ttextAlign,\n\ttextDecoration,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { css } from \"remix/component\";\n\nimport { easings } from \"@sdxc/ui/animations\";\n\n/**\n * Named container {@link Typeset} declares on its own host, so its wide-table\n * handling can grant roomier cell and code-block padding once there's enough\n * space, instead of reading the viewport.\n */\nconst CONTAINER_NAME = \"ui-typeset\";\n\n/** Rhythm context {@link Typeset} falls back to when `preset` is omitted. */\nconst DEFAULT_PRESET: Typeset.Preset = \"docs\";\n\n/**\n * Body size each preset writes to `--ui-typeset-size`. On a 16px root, `docs`\n * is 18px and `reading` is 20px, so long-form copy is large enough to read;\n * `chat` is 15px for a turn taken in a denser column.\n */\nconst PRESET_BODY_SIZE: Record<Typeset.Preset, string> = {\n\tdocs: \"1.125rem\",\n\tchat: \"0.9375rem\",\n\treading: \"1.25rem\",\n};\n\n/**\n * Size body copy and headings compute from. Clearing `--ui-typeset-size`\n * still leaves the docs body, which is the preset a host uses by default.\n */\nconst TYPESET_SIZE = `var(--ui-typeset-size, ${PRESET_BODY_SIZE.docs})`;\n\n/** CSS length each edge of a wide table's own fade tapers over. */\nconst TABLE_FADE_SIZE = \"2.5rem\";\n\n/**\n * Custom property carrying the gradient direction a wide table's edge fade\n * paints along, mirrored under `:dir(rtl)` so the same mask string works in\n * both writing directions without a second, mirrored gradient.\n */\nconst TABLE_FADE_DIRECTION_PROPERTY = \"--ui-typeset-table-fade-direction\";\n\n/**\n * `@keyframes` name backing a wide table's scroll-linked edge fade; the\n * `keyframes()` call using it must stay a top-level mixin rather than nested\n * under the table selector, since the serializer only recognizes stops there.\n */\nconst TABLE_FADE_KEYFRAMES_NAME = \"ui-typeset-table-fade\";\n\n/** Proportion of a wide table's own scroll range its edge fade ramps across. */\nconst TABLE_FADE_RAMP_PERCENT = 10;\n\n/** The style shape {@link css} accepts, reused so a keyframes block can be built ahead of the call. */\ntype Styles = Parameters<typeof css>[0];\n\n/**\n * Builds the four-stop mask-image gradient a wide table's edge fade paints:\n * a leading stop, two middle stops marking where the faded band meets the\n * fully opaque middle, and a trailing stop; only the middle stops move.\n */\nfunction tableFadeMask(startStop: string, endStop: string): string {\n\treturn `linear-gradient(to var(${TABLE_FADE_DIRECTION_PROPERTY}, right), transparent 0%, black ${startStop}, black ${endStop}, transparent 100%)`;\n}\n\nconst TABLE_FADE_SETTLED_STOP = `calc(100% - ${TABLE_FADE_SIZE})`;\nconst TABLE_FADE_SETTLED_MASK = tableFadeMask(TABLE_FADE_SIZE, TABLE_FADE_SETTLED_STOP);\n\n/**\n * Stops the wide-table edge fade animates through: fully faded on the leading\n * edge at rest, settled on both edges across the long middle of the scroll\n * range, and fully faded on the trailing edge at the end.\n */\nconst TABLE_FADE_KEYFRAMES: Record<string, Styles> = {\n\t\"0%\": { maskImage: tableFadeMask(\"0%\", TABLE_FADE_SETTLED_STOP) },\n\t[`${TABLE_FADE_RAMP_PERCENT}%, ${100 - TABLE_FADE_RAMP_PERCENT}%`]: {\n\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t},\n\t\"100%\": { maskImage: tableFadeMask(TABLE_FADE_SIZE, \"100%\") },\n};\n\n/**\n * Prop types for {@link Typeset}.\n */\nexport namespace Typeset {\n\t/**\n\t * Rhythm context. `\"docs\"` sets the body at 18px, the size for a page meant\n\t * to be read. `\"reading\"` sets it at 20px for a long-form article. `\"chat\"`\n\t * sets it at 15px for a turn in a denser column.\n\t */\n\texport type Preset = \"docs\" | \"chat\" | \"reading\";\n\n\t/**\n\t * Every native `<div>` attribute plus `mix`. `preset` defaults to\n\t * {@link DEFAULT_PRESET}; setting a `--ui-typeset-*` property directly\n\t * overrides it, and `data-not-typeset` opts a subtree out entirely.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Rhythm context. Defaults to {@link DEFAULT_PRESET}. */\n\t\tpreset?: Preset;\n\t}\n}\n\n/**\n * Renders a `<div>` that sizes and colors already-rendered markdown or HTML\n * content through `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`, computing heading sizes via `calc()` off one shared value.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the typeset layer's markup.\n * @example\n * <Typeset preset=\"reading\">{renderedArticleHtml}</Typeset>\n * @example\n * <Typeset preset=\"chat\">\n * \t<p>{t(\"assistant.reply\")}</p>\n * </Typeset>\n * @example\n * <Typeset>\n * \t<p>{t(\"docs.intro\")}</p>\n * \t<div data-not-typeset>\n * \t\t<EmbeddedWidget />\n * \t</div>\n * </Typeset>\n */\nexport function Typeset(handle: Handle<Typeset.Props>) {\n\treturn () => {\n\t\tlet { preset, mix, ...rest } = handle.props;\n\t\tlet resolvedPreset = preset ?? DEFAULT_PRESET;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-preset={resolvedPreset}\n\t\t\t\tdata-slot=\"typeset\"\n\t\t\t\tmix={[\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\tkeyframes(TABLE_FADE_KEYFRAMES_NAME, TABLE_FADE_KEYFRAMES),\n\t\t\t\t\traw({\n\t\t\t\t\t\tfontSize: TYPESET_SIZE,\n\t\t\t\t\t\tlineHeight: \"var(--ui-typeset-leading, 1.75)\",\n\n\t\t\t\t\t\t'&[data-preset=\"docs\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.docs,\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.75\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.25em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'&[data-preset=\"chat\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.chat,\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.5\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"0.75em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'&[data-preset=\"reading\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.reading,\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.8\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.5em\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& > * + *\": {\n\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(blockquote, li) > * + *\": {\n\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(h1)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 2)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h2)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.5)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h3)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.25)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h4)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.125)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h5)\": {\n\t\t\t\t\t\t\tfontSize: TYPESET_SIZE,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h6)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 0.875)`,\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(ul)\": {\n\t\t\t\t\t\t\tlistStyleType: \"disc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(ol)\": {\n\t\t\t\t\t\t\tlistStyleType: \"decimal\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(ul, ol) :where(ul)\": {\n\t\t\t\t\t\t\tlistStyleType: \"circle\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(blockquote)\": {\n\t\t\t\t\t\t\tfontStyle: \"italic\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(a)\": {\n\t\t\t\t\t\t\ttextUnderlineOffset: \"0.15em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(a):hover\": {\n\t\t\t\t\t\t\ttextDecorationThickness: \"2px\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(em, i)\": {\n\t\t\t\t\t\t\tfontStyle: \"italic\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(code)\": {\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(pre)\": {\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(pre code)\": {\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tfontSize: \"1em\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(table)\": {\n\t\t\t\t\t\t\tborderCollapse: \"collapse\",\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t\tscrollbarWidth: \"thin\",\n\t\t\t\t\t\t\tscrollbarGutter: \"stable\",\n\n\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"right\",\n\t\t\t\t\t\t\tmaskImage: \"none\",\n\t\t\t\t\t\t\t\"-webkit-mask-image\": \"none\",\n\n\t\t\t\t\t\t\t\"&:dir(rtl)\": {\n\t\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"left\",\n\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar\": {\n\t\t\t\t\t\t\t\twidth: \"0.75rem\",\n\t\t\t\t\t\t\t\theight: \"0.75rem\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-track\": {\n\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb\": {\n\t\t\t\t\t\t\t\tborderRadius: \"var(--ui-radius-full, 9999px)\",\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border)\",\n\t\t\t\t\t\t\t\tborderWidth: \"3px\",\n\t\t\t\t\t\t\t\tborderStyle: \"solid\",\n\t\t\t\t\t\t\t\tborderColor: \"transparent\",\n\t\t\t\t\t\t\t\tbackgroundClip: \"content-box\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb:hover\": {\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border-strong)\",\n\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\"@supports (animation-timeline: scroll())\": {\n\t\t\t\t\t\t\t\tanimationName: TABLE_FADE_KEYFRAMES_NAME,\n\t\t\t\t\t\t\t\tanimationDuration: \"auto\",\n\t\t\t\t\t\t\t\tanimationTimingFunction: easings.linear,\n\t\t\t\t\t\t\t\tanimationFillMode: \"both\",\n\t\t\t\t\t\t\t\tanimationTimeline: \"scroll(self inline)\",\n\t\t\t\t\t\t\t\t\"@media (prefers-reduced-motion: reduce)\": {\n\t\t\t\t\t\t\t\t\tanimationName: \"none\",\n\t\t\t\t\t\t\t\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t\t\"-webkit-mask-image\": TABLE_FADE_SETTLED_MASK,\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\"& :where([data-not-typeset], [data-not-typeset] *)\": {\n\t\t\t\t\t\t\tall: \"revert-layer\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\n\t\t\t\t\tat(\n\t\t\t\t\t\t\"30rem\",\n\t\t\t\t\t\tCONTAINER_NAME,\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"& :where(th, td)\": {\n\t\t\t\t\t\t\t\tpaddingInline: \"1em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& :where(pre)\": {\n\t\t\t\t\t\t\t\tpaddingInline: \"1.25em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\n\t\t\t\t\twhen(\"& :where(pre)\", leading(1.6)),\n\n\t\t\t\t\twhen(\"& :where(h1, h2, h3, h4, h5, h6)\", [\n\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\tleading(1.25),\n\t\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tbalance(),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(h6)\", fg(\"neutral\")),\n\n\t\t\t\t\twhen(\"& :where(p, li, blockquote, dd)\", pretty()),\n\n\t\t\t\t\twhen(\"& :where(ul, ol)\", pis(\"1.5em\")),\n\t\t\t\t\twhen(\"& :where(li)::marker\", fg(\"neutral.muted\")),\n\n\t\t\t\t\twhen(\"& :where(blockquote)\", [\n\t\t\t\t\t\tpis(\"1em\"),\n\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\tborderEdge(\"inline-start\", { color: \"neutral\", width: \"0.25em\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(hr)\", borderEdge(\"block-start\", { color: \"neutral\", width: \"1px\" })),\n\n\t\t\t\t\twhen(\"& :where(a)\", [fg(\"brand\"), textDecoration(\"underline\")]),\n\t\t\t\t\twhen(\"& :where(a):focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\trounded(\"xs\"),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(strong, b)\", [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\n\t\t\t\t\twhen(\"& :where(code)\", [\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tpi(\"0.3em\"),\n\t\t\t\t\t\tpb(\"0.15em\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(pre)\", [\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ color: \"neutral.border\", width: 1 }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tpi(\"1em\"),\n\t\t\t\t\t\tpb(\"0.875em\"),\n\t\t\t\t\t\toverflowInline(\"auto\"),\n\t\t\t\t\t\toverflowBlock(\"hidden\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\t\toverscrollBehaviorX: \"contain\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\t/**\n\t\t\t\t\t * A fenced block's `code` is an inline box, so the chip padding above would\n\t\t\t\t\t * apply at the start of the box alone and indent the block's first line\n\t\t\t\t\t * past every line under it. The block's own padding is the `pre`'s.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& :where(pre code)\", [\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\tpi(0),\n\t\t\t\t\t\tpb(0),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(table)\", [\n\t\t\t\t\t\tblock(),\n\t\t\t\t\t\tis(\"max(100%, max-content)\"),\n\t\t\t\t\t\tmaxIs(\"full\"),\n\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(th, td):not([align])\", textAlign(\"start\")),\n\t\t\t\t\twhen(\"& :where(th)\", [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen(\"& :where(th, td)\", [\n\t\t\t\t\t\ttabularNums(),\n\t\t\t\t\t\tpi(\"0.75em\"),\n\t\t\t\t\t\tpb(\"0.5em\"),\n\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral\", width: \"1px\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
10
|
+
"content": "/**\n * A typography layer wrapping already-rendered markdown or HTML content and\n * supplying every size, weight, spacing, and color decision through three\n * custom properties: `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`. `data-preset` swaps all three for a different rhythm\n * context; `data-not-typeset` opts a subtree out of the whole layer.\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 { keyframes } from \"@sdxc/u/animation\";\nimport { bg, border, borderEdge, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { raw, mergeMix } from \"@sdxc/u/general\";\nimport { block, container } from \"@sdxc/u/layout\";\nimport { overflow, overflowBlock, overflowInline } from \"@sdxc/u/overflow\";\nimport { at } from \"@sdxc/u/responsive\";\nimport { is, maxIs, pb, pi, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tleading,\n\tpretty,\n\ttabularNums,\n\ttextAlign,\n\ttextDecoration,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { css } from \"remix/component\";\n\nimport { easings } from \"@sdxc/ui/animations\";\n\n/**\n * Named container {@link Typeset} declares on its own host, so its wide-table\n * handling can grant roomier cell and code-block padding once there's enough\n * space, instead of reading the viewport.\n */\nconst CONTAINER_NAME = \"ui-typeset\";\n\n/** Matches an element that is neither a `data-not-typeset` subtree's root nor inside one. */\nconst OUTSIDE_OPT_OUT = \":not(:where([data-not-typeset], [data-not-typeset] *))\";\n\n/** Rhythm context {@link Typeset} falls back to when `preset` is omitted. */\nconst DEFAULT_PRESET: Typeset.Preset = \"docs\";\n\n/**\n * Body size each preset writes to `--ui-typeset-size`. On a 16px root, `docs`\n * is 18px and `reading` is 20px, so long-form copy is large enough to read;\n * `chat` is 15px for a turn taken in a denser column.\n */\nconst PRESET_BODY_SIZE: Record<Typeset.Preset, string> = {\n\tdocs: \"1.125rem\",\n\tchat: \"0.9375rem\",\n\treading: \"1.25rem\",\n};\n\n/**\n * Size body copy and headings compute from. Clearing `--ui-typeset-size`\n * still leaves the docs body, which is the preset a host uses by default.\n */\nconst TYPESET_SIZE = `var(--ui-typeset-size, ${PRESET_BODY_SIZE.docs})`;\n\n/** CSS length each edge of a wide table's own fade tapers over. */\nconst TABLE_FADE_SIZE = \"2.5rem\";\n\n/**\n * Custom property carrying the gradient direction a wide table's edge fade\n * paints along, mirrored under `:dir(rtl)` so the same mask string works in\n * both writing directions without a second, mirrored gradient.\n */\nconst TABLE_FADE_DIRECTION_PROPERTY = \"--ui-typeset-table-fade-direction\";\n\n/**\n * `@keyframes` name backing a wide table's scroll-linked edge fade; the\n * `keyframes()` call using it must stay a top-level mixin rather than nested\n * under the table selector, since the serializer only recognizes stops there.\n */\nconst TABLE_FADE_KEYFRAMES_NAME = \"ui-typeset-table-fade\";\n\n/** Proportion of a wide table's own scroll range its edge fade ramps across. */\nconst TABLE_FADE_RAMP_PERCENT = 10;\n\n/** The style shape {@link css} accepts, reused so a keyframes block can be built ahead of the call. */\ntype Styles = Parameters<typeof css>[0];\n\n/**\n * Builds the four-stop mask-image gradient a wide table's edge fade paints:\n * a leading stop, two middle stops marking where the faded band meets the\n * fully opaque middle, and a trailing stop; only the middle stops move.\n */\nfunction tableFadeMask(startStop: string, endStop: string): string {\n\treturn `linear-gradient(to var(${TABLE_FADE_DIRECTION_PROPERTY}, right), transparent 0%, black ${startStop}, black ${endStop}, transparent 100%)`;\n}\n\nconst TABLE_FADE_SETTLED_STOP = `calc(100% - ${TABLE_FADE_SIZE})`;\nconst TABLE_FADE_SETTLED_MASK = tableFadeMask(TABLE_FADE_SIZE, TABLE_FADE_SETTLED_STOP);\n\n/**\n * Stops the wide-table edge fade animates through: fully faded on the leading\n * edge at rest, settled on both edges across the long middle of the scroll\n * range, and fully faded on the trailing edge at the end.\n */\nconst TABLE_FADE_KEYFRAMES: Record<string, Styles> = {\n\t\"0%\": { maskImage: tableFadeMask(\"0%\", TABLE_FADE_SETTLED_STOP) },\n\t[`${TABLE_FADE_RAMP_PERCENT}%, ${100 - TABLE_FADE_RAMP_PERCENT}%`]: {\n\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t},\n\t\"100%\": { maskImage: tableFadeMask(TABLE_FADE_SIZE, \"100%\") },\n};\n\n/**\n * Prop types for {@link Typeset}.\n */\nexport namespace Typeset {\n\t/**\n\t * Rhythm context. `\"docs\"` sets the body at 18px, the size for a page meant\n\t * to be read. `\"reading\"` sets it at 20px for a long-form article. `\"chat\"`\n\t * sets it at 15px for a turn in a denser column.\n\t */\n\texport type Preset = \"docs\" | \"chat\" | \"reading\";\n\n\t/**\n\t * Every native `<div>` attribute plus `mix`. `preset` defaults to\n\t * {@link DEFAULT_PRESET}; setting a `--ui-typeset-*` property directly\n\t * overrides it, and `data-not-typeset` opts a subtree out entirely.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Rhythm context. Defaults to {@link DEFAULT_PRESET}. */\n\t\tpreset?: Preset;\n\t}\n}\n\n/**\n * Narrows a descendant rule to elements outside every `data-not-typeset` subtree. Each rule\n * the layer writes lands in a cascade layer of its own, so an opt-out has to be part of the\n * rule's selector; the exclusion adds no specificity, and it sits ahead of a pseudo-element.\n */\nfunction prose(selector: `&${string}`): `&${string}` {\n\tlet pseudoElement = selector.indexOf(\"::\");\n\tif (pseudoElement === -1) return `${selector}${OUTSIDE_OPT_OUT}`;\n\treturn `&${selector.slice(1, pseudoElement)}${OUTSIDE_OPT_OUT}${selector.slice(pseudoElement)}`;\n}\n\n/**\n * Renders a `<div>` that sizes and colors already-rendered markdown or HTML\n * content through `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`, computing heading sizes via `calc()` off one shared value.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the typeset layer's markup.\n * @example\n * <Typeset preset=\"reading\">{renderedArticleHtml}</Typeset>\n * @example\n * <Typeset preset=\"chat\">\n * \t<p>{t(\"assistant.reply\")}</p>\n * </Typeset>\n * @example\n * <Typeset>\n * \t<p>{t(\"docs.intro\")}</p>\n * \t<div data-not-typeset>\n * \t\t<EmbeddedWidget />\n * \t</div>\n * </Typeset>\n */\nexport function Typeset(handle: Handle<Typeset.Props>) {\n\treturn () => {\n\t\tlet { preset, mix, ...rest } = handle.props;\n\t\tlet resolvedPreset = preset ?? DEFAULT_PRESET;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-preset={resolvedPreset}\n\t\t\t\tdata-slot=\"typeset\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\t\tkeyframes(TABLE_FADE_KEYFRAMES_NAME, TABLE_FADE_KEYFRAMES),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tfontSize: TYPESET_SIZE,\n\t\t\t\t\t\t\tlineHeight: \"var(--ui-typeset-leading, 1.75)\",\n\n\t\t\t\t\t\t\t'&[data-preset=\"docs\"]': {\n\t\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.docs,\n\t\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.75\",\n\t\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.25em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t'&[data-preset=\"chat\"]': {\n\t\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.chat,\n\t\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.5\",\n\t\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"0.75em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t'&[data-preset=\"reading\"]': {\n\t\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.reading,\n\t\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.8\",\n\t\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.5em\",\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\tprose(\"& > * + *\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\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\tprose(\"& :where(blockquote, li) > * + *\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\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\tprose(\"& :where(h1)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 2)`,\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\tprose(\"& :where(h2)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.5)`,\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\tprose(\"& :where(h3)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.25)`,\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\tprose(\"& :where(h4)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.125)`,\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\tprose(\"& :where(h5)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: TYPESET_SIZE,\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\tprose(\"& :where(h6)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 0.875)`,\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\tprose(\"& :where(ul)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tlistStyleType: \"disc\",\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\tprose(\"& :where(ol)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tlistStyleType: \"decimal\",\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\tprose(\"& :where(ul, ol) :where(ul)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tlistStyleType: \"circle\",\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\tprose(\"& :where(blockquote)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontStyle: \"italic\",\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\tprose(\"& :where(a)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\ttextUnderlineOffset: \"0.15em\",\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\tprose(\"& :where(a):hover\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\ttextDecorationThickness: \"2px\",\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\tprose(\"& :where(em, i)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontStyle: \"italic\",\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\tprose(\"& :where(code)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: \"0.875em\",\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\tprose(\"& :where(pre)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontSize: \"0.875em\",\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\tprose(\"& :where(pre code)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\t\tfontSize: \"1em\",\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\tprose(\"& :where(table)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tborderCollapse: \"collapse\",\n\t\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t\t\tscrollbarWidth: \"thin\",\n\t\t\t\t\t\t\t\tscrollbarGutter: \"stable\",\n\n\t\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"right\",\n\t\t\t\t\t\t\t\tmaskImage: \"none\",\n\t\t\t\t\t\t\t\t\"-webkit-mask-image\": \"none\",\n\n\t\t\t\t\t\t\t\t\"&:dir(rtl)\": {\n\t\t\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"left\",\n\t\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\t\"&::-webkit-scrollbar\": {\n\t\t\t\t\t\t\t\t\twidth: \"0.75rem\",\n\t\t\t\t\t\t\t\t\theight: \"0.75rem\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\"&::-webkit-scrollbar-track\": {\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb\": {\n\t\t\t\t\t\t\t\t\tborderRadius: \"var(--ui-radius-full, 9999px)\",\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border)\",\n\t\t\t\t\t\t\t\t\tborderWidth: \"3px\",\n\t\t\t\t\t\t\t\t\tborderStyle: \"solid\",\n\t\t\t\t\t\t\t\t\tborderColor: \"transparent\",\n\t\t\t\t\t\t\t\t\tbackgroundClip: \"content-box\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb:hover\": {\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border-strong)\",\n\t\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\t\"@supports (animation-timeline: scroll())\": {\n\t\t\t\t\t\t\t\t\tanimationName: TABLE_FADE_KEYFRAMES_NAME,\n\t\t\t\t\t\t\t\t\tanimationDuration: \"auto\",\n\t\t\t\t\t\t\t\t\tanimationTimingFunction: easings.linear,\n\t\t\t\t\t\t\t\t\tanimationFillMode: \"both\",\n\t\t\t\t\t\t\t\t\tanimationTimeline: \"scroll(self inline)\",\n\t\t\t\t\t\t\t\t\t\"@media (prefers-reduced-motion: reduce)\": {\n\t\t\t\t\t\t\t\t\t\tanimationName: \"none\",\n\t\t\t\t\t\t\t\t\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t\t\t\"-webkit-mask-image\": TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t\t},\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\n\t\t\t\t\t\tat(\"30rem\", CONTAINER_NAME, [\n\t\t\t\t\t\t\twhen(prose(\"& :where(th, td)\"), raw({ paddingInline: \"1em\" })),\n\t\t\t\t\t\t\twhen(prose(\"& :where(pre)\"), raw({ paddingInline: \"1.25em\" })),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen(prose(\"& :where(pre)\"), leading(1.6)),\n\n\t\t\t\t\t\twhen(prose(\"& :where(h1, h2, h3, h4, h5, h6)\"), [\n\t\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\t\tleading(1.25),\n\t\t\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\tbalance(),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(prose(\"& :where(h6)\"), fg(\"neutral\")),\n\n\t\t\t\t\t\twhen(prose(\"& :where(p, li, blockquote, dd)\"), pretty()),\n\n\t\t\t\t\t\twhen(prose(\"& :where(ul, ol)\"), pis(\"1.5em\")),\n\t\t\t\t\t\twhen(prose(\"& :where(li)::marker\"), fg(\"neutral.muted\")),\n\n\t\t\t\t\t\twhen(prose(\"& :where(blockquote)\"), [\n\t\t\t\t\t\t\tpis(\"1em\"),\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\tborderEdge(\"inline-start\", { color: \"neutral\", width: \"0.25em\" }),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\tprose(\"& :where(hr)\"),\n\t\t\t\t\t\t\tborderEdge(\"block-start\", { color: \"neutral\", width: \"1px\" }),\n\t\t\t\t\t\t),\n\n\t\t\t\t\t\twhen(prose(\"& :where(a)\"), [fg(\"brand\"), textDecoration(\"underline\")]),\n\t\t\t\t\t\twhen(prose(\"& :where(a):focus-visible\"), [\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t\trounded(\"xs\"),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen(prose(\"& :where(strong, b)\"), [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\n\t\t\t\t\t\twhen(prose(\"& :where(code)\"), [\n\t\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\tpi(\"0.3em\"),\n\t\t\t\t\t\t\tpb(\"0.15em\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(prose(\"& :where(pre)\"), [\n\t\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\t\tborder({ color: \"neutral.border\", width: 1 }),\n\t\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\tpi(\"1em\"),\n\t\t\t\t\t\t\tpb(\"0.875em\"),\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\traw({\n\t\t\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\t\t\toverscrollBehaviorX: \"contain\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A fenced block's `code` is an inline box, so the chip padding above would\n\t\t\t\t\t\t * apply at the start of the box alone and indent the block's first line\n\t\t\t\t\t\t * past every line under it. The block's own padding is the `pre`'s.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(prose(\"& :where(pre code)\"), [\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\t\tpi(0),\n\t\t\t\t\t\t\tpb(0),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen(prose(\"& :where(table)\"), [\n\t\t\t\t\t\t\tblock(),\n\t\t\t\t\t\t\tis(\"max(100%, max-content)\"),\n\t\t\t\t\t\t\tmaxIs(\"full\"),\n\t\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(prose(\"& :where(th, td):not([align])\"), textAlign(\"start\")),\n\t\t\t\t\t\twhen(prose(\"& :where(th)\"), [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\t\twhen(prose(\"& :where(th, td)\"), [\n\t\t\t\t\t\t\ttabularNums(),\n\t\t\t\t\t\t\tpi(\"0.75em\"),\n\t\t\t\t\t\t\tpb(\"0.5em\"),\n\t\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral\", width: \"1px\" }),\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"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "typeset.test.tsx",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "youtube-embed",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"YouTubeEmbed"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "youtube-embed.tsx",
|
|
10
|
-
"content": "/**\n * A YouTube player sized to its container: a 16:9 `<iframe>` served from YouTube's\n * privacy-enhanced host, so a visitor receives no YouTube cookies until they press play,\n * and lazy-loaded so a video below the fold costs nothing until it scrolls into view.\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 { border } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { block } from \"@sdxc/u/layout\";\nimport { aspect, is } from \"@sdxc/u/size\";\n\n/** The host every player loads from; a page's `frame-src` has to allow it. */\nconst EMBED_ORIGIN = \"https://www.youtube-nocookie.com\";\n\n/** Loading strategy {@link YouTubeEmbed} falls back to when `loading` is omitted. */\nconst DEFAULT_LOADING: YouTubeEmbed.Props[\"loading\"] = \"lazy\";\n\n/** The player features YouTube asks an embedding page to delegate. */\nconst ALLOWED_FEATURES =\n\t\"accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\";\n\n/**\n * Prop types for {@link YouTubeEmbed}.\n */\nexport namespace YouTubeEmbed {\n\t/**\n\t * Props accepted by {@link YouTubeEmbed}.\n\t */\n\texport interface Props extends Omit<\n\t\tTagProps<\"iframe\">,\n\t\t\"src\" | \"title\" | \"allow\" | \"referrerpolicy\" | \"referrerPolicy\"\n\t> {\n\t\t/** The eleven-character id from the video's `watch?v=` or `youtu.be/` URL. */\n\t\tvideoId: string;\n\t\t/** Seconds into the video the player starts at; zero or less starts at the beginning. */\n\t\tstart?: number;\n\t\t/** The frame's accessible name, announced before a reader enters the player. */\n\t\ttitle: string;\n\t}\n}\n\n/**\n * Renders the player filling its container's inline axis at 16:9. The frame always sends\n * the embedding page's origin as referrer, without which YouTube refuses to play.\n *\n * @param handle Runtime handle carrying the host `<iframe>`'s props.\n * @returns The render function producing the player's markup.\n * @example <YouTubeEmbed videoId=\"dQw4w9WgXcQ\" title={t(\"video.title\")} />\n * @example <YouTubeEmbed videoId=\"dQw4w9WgXcQ\" start={90} title={t(\"video.title\")} />\n */\nexport function YouTubeEmbed(handle: Handle<YouTubeEmbed.Props>) {\n\treturn () => {\n\t\tlet { videoId, start, title, loading, mix, ...rest } = handle.props;\n\t\tlet src = new URL(`/embed/${encodeURIComponent(videoId)}`, EMBED_ORIGIN);\n\t\tif (start !== undefined && start >= 1) src.searchParams.set(\"start\", String(Math.floor(start)));\n\n\t\treturn (\n\t\t\t<iframe\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"youtube-embed\"\n\t\t\t\tsrc={src.href}\n\t\t\t\ttitle={title}\n\t\t\t\tloading={loading ?? DEFAULT_LOADING}\n\t\t\t\treferrerpolicy=\"strict-origin-when-cross-origin\"\n\t\t\t\tallow={ALLOWED_FEATURES}\n\t\t\t\tallowFullScreen\n\t\t\t\tmix={[block(), is(\"full\"), aspect(\"video\"), border(\"none\"), rounded(\"lg\"), mix
|
|
10
|
+
"content": "/**\n * A YouTube player sized to its container: a 16:9 `<iframe>` served from YouTube's\n * privacy-enhanced host, so a visitor receives no YouTube cookies until they press play,\n * and lazy-loaded so a video below the fold costs nothing until it scrolls into view.\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 { border } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { block } from \"@sdxc/u/layout\";\nimport { aspect, is } from \"@sdxc/u/size\";\n\n/** The host every player loads from; a page's `frame-src` has to allow it. */\nconst EMBED_ORIGIN = \"https://www.youtube-nocookie.com\";\n\n/** Loading strategy {@link YouTubeEmbed} falls back to when `loading` is omitted. */\nconst DEFAULT_LOADING: YouTubeEmbed.Props[\"loading\"] = \"lazy\";\n\n/** The player features YouTube asks an embedding page to delegate. */\nconst ALLOWED_FEATURES =\n\t\"accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\";\n\n/**\n * Prop types for {@link YouTubeEmbed}.\n */\nexport namespace YouTubeEmbed {\n\t/**\n\t * Props accepted by {@link YouTubeEmbed}.\n\t */\n\texport interface Props extends Omit<\n\t\tTagProps<\"iframe\">,\n\t\t\"src\" | \"title\" | \"allow\" | \"referrerpolicy\" | \"referrerPolicy\"\n\t> {\n\t\t/** The eleven-character id from the video's `watch?v=` or `youtu.be/` URL. */\n\t\tvideoId: string;\n\t\t/** Seconds into the video the player starts at; zero or less starts at the beginning. */\n\t\tstart?: number;\n\t\t/** The frame's accessible name, announced before a reader enters the player. */\n\t\ttitle: string;\n\t}\n}\n\n/**\n * Renders the player filling its container's inline axis at 16:9. The frame always sends\n * the embedding page's origin as referrer, without which YouTube refuses to play.\n *\n * @param handle Runtime handle carrying the host `<iframe>`'s props.\n * @returns The render function producing the player's markup.\n * @example <YouTubeEmbed videoId=\"dQw4w9WgXcQ\" title={t(\"video.title\")} />\n * @example <YouTubeEmbed videoId=\"dQw4w9WgXcQ\" start={90} title={t(\"video.title\")} />\n */\nexport function YouTubeEmbed(handle: Handle<YouTubeEmbed.Props>) {\n\treturn () => {\n\t\tlet { videoId, start, title, loading, mix, ...rest } = handle.props;\n\t\tlet src = new URL(`/embed/${encodeURIComponent(videoId)}`, EMBED_ORIGIN);\n\t\tif (start !== undefined && start >= 1) src.searchParams.set(\"start\", String(Math.floor(start)));\n\n\t\treturn (\n\t\t\t<iframe\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"youtube-embed\"\n\t\t\t\tsrc={src.href}\n\t\t\t\ttitle={title}\n\t\t\t\tloading={loading ?? DEFAULT_LOADING}\n\t\t\t\treferrerpolicy=\"strict-origin-when-cross-origin\"\n\t\t\t\tallow={ALLOWED_FEATURES}\n\t\t\t\tallowFullScreen\n\t\t\t\tmix={mergeMix([block(), is(\"full\"), aspect(\"video\"), border(\"none\"), rounded(\"lg\")], mix)}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "youtube-embed.browser.test.tsx",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { Link } from "@sdxc/ui/link";
|
|
10
10
|
import { LinkButton } from "@sdxc/ui/link-button";
|
|
11
|
-
import { Table } from "@sdxc/ui/table";
|
|
11
|
+
import { Table } from "@sdxc/ui/app/table";
|
|
12
12
|
import { createAction } from "remix/router";
|
|
13
13
|
|
|
14
14
|
import page from "~/app/http/middleware/page";
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "attachment",
|
|
3
|
-
"changedIn": "2026.10.23",
|
|
4
|
-
"dependencies": [
|
|
5
|
-
"button"
|
|
6
|
-
],
|
|
7
|
-
"exports": [
|
|
8
|
-
"Attachment"
|
|
9
|
-
],
|
|
10
|
-
"source": {
|
|
11
|
-
"path": "attachment.tsx",
|
|
12
|
-
"content": "/**\n * A compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\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 { iife } from \"@sdxc/iife\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\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<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\n\treturn () => {\n\t\tlet { children, 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=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\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</div>\n\t\t);\n\t};\n};\n\n/**\n * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.ContentProps>) {\n\treturn () => {\n\t\tlet { children, 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=\"content\"\n\t\t\t\tmix={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\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</div>\n\t\t);\n\t};\n};\n\n/**\n * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\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</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet inferredRole = iife((): \"link\" | \"button\" | undefined => {\n\t\t\tif (href !== undefined) return \"link\";\n\t\t\tif (isConfigured) return \"button\";\n\t\t\treturn undefined;\n\t\t});\n\t\tlet resolvedRole = role ?? inferredRole;\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env?.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\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</div>\n\t\t);\n\t};\n};\n\n/**\n * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.GroupProps>) {\n\treturn () => {\n\t\tlet { children, 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=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\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</div>\n\t\t);\n\t};\n};\n"
|
|
13
|
-
},
|
|
14
|
-
"test": null
|
|
15
|
-
}
|
package/registry/ui/bubble.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bubble",
|
|
3
|
-
"changedIn": "2026.10.13",
|
|
4
|
-
"dependencies": [],
|
|
5
|
-
"exports": [
|
|
6
|
-
"Bubble"
|
|
7
|
-
],
|
|
8
|
-
"source": {
|
|
9
|
-
"path": "bubble.tsx",
|
|
10
|
-
"content": "/**\n * The framed message surface inside a conversational row's content slot,\n * sized to its own content up to a share of the row's width. Variants cover\n * tones from a solid fill to fully unframed, and `align` hugs either row\n * edge. `Bubble.Content`, `Bubble.Reactions`, and `Bubble.Group` compose the\n * turn's text, its reaction toggles, and multi-bubble runs.\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 { bg, border, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { raw, vars } from \"@sdxc/u/general\";\nimport { block, flex, flexWrap, gap, items, vstack } from \"@sdxc/u/layout\";\nimport { maxIs, mie, mis, pb, pbe, pi, width } from \"@sdxc/u/size\";\nimport { data, when } from \"@sdxc/u/state\";\nimport { pretty, wordBreak } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\n/** Selector matching every framed variant, the ones that hug their own text. */\nconst FRAMED = '&:not([data-variant=\"ghost\"])';\n\n/** Visual weight {@link Bubble} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: Bubble.Variant = \"default\";\n\n/** Edge of the row {@link Bubble} falls back to when `align` is omitted. */\nconst DEFAULT_ALIGN: Bubble.Align = \"start\";\n\n/**\n * ARIA role applied to {@link Bubble.Reactions} through {@link attrs},\n * announcing the row as one related set of pressed toggles.\n */\nconst DEFAULT_REACTIONS_ROLE = \"group\";\n\n/**\n * Prop types for {@link Bubble} and its compound parts.\n */\nexport namespace Bubble {\n\t/**\n\t * Visual weight the frame renders with: solid `\"default\"`/`\"secondary\"` fills,\n\t * soft `\"muted\"`/`\"tinted\"` tints, a bordered `\"outline\"`, an unframed\n\t * `\"ghost\"`, and a solid danger fill for `\"destructive\"`.\n\t */\n\texport type Variant =\n\t\t| \"default\"\n\t\t| \"secondary\"\n\t\t| \"muted\"\n\t\t| \"tinted\"\n\t\t| \"outline\"\n\t\t| \"ghost\"\n\t\t| \"destructive\";\n\n\t/**\n\t * Edge of the row the frame hugs: `\"start\"` stays flush with the row's\n\t * leading edge (flipping under `dir=\"rtl\"`), `\"end\"` stays flush with the\n\t * trailing edge, typically paired with the reader's own turns vs everyone else's.\n\t */\n\texport type Align = \"start\" | \"end\";\n\n\t/**\n\t * Props accepted by {@link Bubble}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Edge of the row the frame hugs. Defaults to {@link DEFAULT_ALIGN}. */\n\t\talign?: Align;\n\t\t/** The frame's compound parts: {@link Bubble.Content}, an optional {@link Bubble.Reactions}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Bubble.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** The turn's text — plain, or wrapped in a typography layer for rendered markdown. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Bubble.Reactions}. `aria-label` is required so\n\t * assistive technology has an accessible name to announce for this row.\n\t */\n\texport interface ReactionsProps extends Omit<TagProps<\"div\">, \"aria-label\"> {\n\t\t/** Accessible label describing the row as a set of reactions. */\n\t\t\"aria-label\": string;\n\t\t/** One or more already-pressed toggle controls, each scoped to a single reaction. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Bubble.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** Two or more {@link Bubble} frames from the same turn, stacked into one run. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders the frame, pushed to the edge `align` names via auto margins so it\n * aligns correctly regardless of its row's layout. Its nearest corner falls\n * back to a literal `0.125rem`, since `roundedCorner()` has no `\"xs\"` step.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the frame's markup.\n * @example\n * <Bubble align=\"end\">\n * \t<Bubble.Content>{turn.text}</Bubble.Content>\n * </Bubble>\n * @example\n * <Bubble variant=\"muted\" align=\"start\">\n * \t<Bubble.Content>{turn.text}</Bubble.Content>\n * </Bubble>\n * @example\n * <Bubble variant=\"ghost\" align=\"start\">\n * \t<Bubble.Content>\n * \t\t<Typeset preset=\"chat\">{renderedMarkdownHtml}</Typeset>\n * \t</Bubble.Content>\n * </Bubble>\n */\nexport function Bubble(handle: Handle<Bubble.Props>) {\n\treturn () => {\n\t\tlet { variant, align, children, mix, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedAlign = align ?? DEFAULT_ALIGN;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"bubble\"\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-align={resolvedAlign}\n\t\t\t\tmix={[\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"xl\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"transparent\"),\n\n\t\t\t\t\twhen(FRAMED, [width(\"fit-content\"), maxIs(\"80%\")]),\n\t\t\t\t\twhen(`${FRAMED}[data-align=\"start\"]`, mie(\"auto\")),\n\t\t\t\t\twhen(`${FRAMED}[data-align=\"end\"]`, mis(\"auto\")),\n\n\t\t\t\t\tdata(\"align\", \"start\", [\n\t\t\t\t\t\traw({ borderEndStartRadius: \"var(--ui-radius-xs, 0.125rem)\" }),\n\t\t\t\t\t\tvars({ \"ui-bubble-reactions-justify\": \"flex-start\" }),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"align\", \"end\", [\n\t\t\t\t\t\traw({ borderEndEndRadius: \"var(--ui-radius-xs, 0.125rem)\" }),\n\t\t\t\t\t\tvars({ \"ui-bubble-reactions-justify\": \"flex-end\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"variant\", \"default\", [bg(\"brand.solid\"), fg(\"brand.onSolid\")]),\n\t\t\t\t\tdata(\"variant\", \"secondary\", [bg(\"neutral.solid\"), fg(\"neutral.onSolid\")]),\n\t\t\t\t\tdata(\"variant\", \"muted\", [bg(\"neutral.tint\"), fg(\"neutral.emphasis\"), border(\"neutral\")]),\n\t\t\t\t\tdata(\"variant\", \"tinted\", [bg(\"brand.tint\"), fg(\"brand.emphasis\"), border(\"brand\")]),\n\t\t\t\t\tdata(\"variant\", \"outline\", [\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tborder(\"neutral.strong\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"variant\", \"ghost\", [\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tborder(\"transparent\"),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"variant\", \"destructive\", [bg(\"danger.solid\"), fg(\"danger.onSolid\")]),\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</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Bubble.ContentProps.children} as the frame's padded text\n * slot, breaking long unbroken runs at the inline box edge and taking its\n * text color from the ancestor {@link Bubble}'s `variant` via CSS inheritance.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text slot's markup.\n * @example\n * <Bubble.Content>{turn.text}</Bubble.Content>\n * @example\n * <Bubble.Content>\n * \t<p>{turn.summary}</p>\n * \t<Disclosure>\n * \t\t<Disclosure.Trigger>{t(\"message.showMore\")}</Disclosure.Trigger>\n * \t\t<Disclosure.Panel>{turn.rest}</Disclosure.Panel>\n * \t</Disclosure>\n * </Bubble.Content>\n * @example\n * <Bubble.Content>\n * \t{turn.text}\n * \t<button popovertarget={`${turn.id}-meta`} aria-label={t(\"message.details\")}>\n * \t\t<InfoIcon aria-hidden />\n * \t</button>\n * \t<Popover id={`${turn.id}-meta`} popover=\"hint\" placement=\"top-end\">\n * \t\t{t(\"message.model\", { model: turn.model })}\n * \t</Popover>\n * </Bubble.Content>\n */\nBubble.Content = function BubbleContent(handle: Handle<Bubble.ContentProps>) {\n\treturn () => {\n\t\tlet { children, 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=\"content\"\n\t\t\t\tmix={[\n\t\t\t\t\tpb(2.5),\n\t\t\t\t\tpi(3.5),\n\t\t\t\t\traw({\n\t\t\t\t\t\tfontSize: \"0.9375rem\",\n\t\t\t\t\t\tlineHeight: \"1.5\",\n\t\t\t\t\t\toverflowWrap: \"break-word\",\n\t\t\t\t\t}),\n\t\t\t\t\twordBreak(\"break-word\"),\n\t\t\t\t\tpretty(),\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</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Bubble.ReactionsProps.children} as a `role=\"group\"` row: a\n * negative block-start margin pins it into the frame's lower padding, aligned\n * via the `--ui-bubble-reactions-justify` property the frame sets from `align`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the reaction row's markup.\n * @example\n * <Bubble.Reactions aria-label={t(\"message.reactions\")}>\n * \t<ToggleButton\n * \t\taria-pressed={reactions.thumbsUp}\n * \t\taria-label={t(\"message.reactThumbsUp\")}\n * \t\tsize=\"sm\"\n * \t\tname=\"reaction\"\n * \t\tvalue=\"thumbs-up\"\n * \t>\n * \t\t👍\n * \t</ToggleButton>\n * \t<ToggleButton\n * \t\taria-pressed={reactions.heart}\n * \t\taria-label={t(\"message.reactHeart\")}\n * \t\tsize=\"sm\"\n * \t\tname=\"reaction\"\n * \t\tvalue=\"heart\"\n * \t>\n * \t\t❤️\n * \t</ToggleButton>\n * </Bubble.Reactions>\n */\nBubble.Reactions = function BubbleReactions(handle: Handle<Bubble.ReactionsProps>) {\n\treturn () => {\n\t\tlet { children, 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=\"reactions\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_REACTIONS_ROLE }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexWrap(\"wrap\"),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(1),\n\t\t\t\t\t/**\n\t\t\t\t\t * The row sits on the line the turn's own text sits on and clears the frame's lower\n\t\t\t\t\t * edge, inset to match the content beside it, so the reactions stay clear of the\n\t\t\t\t\t * message's last line.\n\t\t\t\t\t */\n\t\t\t\t\tpi(3.5),\n\t\t\t\t\tpbe(2.5),\n\t\t\t\t\traw({ justifyContent: \"var(--ui-bubble-reactions-justify, flex-start)\" }),\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</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Bubble.GroupProps.children} as a tightly spaced column of\n * consecutive {@link Bubble} frames, softening only the corners touching a\n * neighbor to a smaller radius, so the run reads as one continuous shape.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the run's markup.\n * @example\n * <Bubble.Group>\n * \t<Bubble align=\"end\"><Bubble.Content>{turnOne.text}</Bubble.Content></Bubble>\n * \t<Bubble align=\"end\"><Bubble.Content>{turnTwo.text}</Bubble.Content></Bubble>\n * </Bubble.Group>\n */\nBubble.Group = function BubbleGroup(handle: Handle<Bubble.GroupProps>) {\n\treturn () => {\n\t\tlet { children, 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=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\twhen('& > [data-slot=\"bubble\"]:not(:first-child)', [\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tborderStartStartRadius: \"var(--ui-radius-xs, 0.125rem)\",\n\t\t\t\t\t\t\tborderStartEndRadius: \"var(--ui-radius-xs, 0.125rem)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('& > [data-slot=\"bubble\"]:not(:last-child)', [\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tborderEndStartRadius: \"var(--ui-radius-xs, 0.125rem)\",\n\t\t\t\t\t\t\tborderEndEndRadius: \"var(--ui-radius-xs, 0.125rem)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n"
|
|
11
|
-
},
|
|
12
|
-
"test": null
|
|
13
|
-
}
|
package/registry/ui/chart.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chart",
|
|
3
|
-
"changedIn": "2026.10.13",
|
|
4
|
-
"dependencies": [],
|
|
5
|
-
"exports": [
|
|
6
|
-
"Chart"
|
|
7
|
-
],
|
|
8
|
-
"source": {
|
|
9
|
-
"path": "chart.tsx",
|
|
10
|
-
"content": "/**\n * The `Chart` namespace's compound parts, covering Cartesian series\n * ({@link Chart}, {@link Chart.Line}, {@link Chart.Area}, {@link Chart.Bar})\n * and the independent {@link Chart.Pie} root, each pairing with\n * {@link Chart.Legend} for a script-free series switcher and\n * {@link Chart.Tooltip} for a richer hover surface.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport {\n\tbg,\n\tfg,\n\tfill,\n\tfillOpacity,\n\toutline,\n\tstroke,\n\tstrokeLinecap,\n\tstrokeLinejoin,\n\tstrokeWidth,\n\tvectorEffect,\n} from \"@sdxc/u/color\";\nimport { opacity, rounded, shadow, transition, transitionDuration } from \"@sdxc/u/effects\";\nimport { cursor, pointerEvents, raw, userSelect } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tblock,\n\tflex,\n\tflexWrap,\n\tgap,\n\tinlineBlock,\n\tinlineFlex,\n\titems,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, pb, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { focusVisible, hover, when } from \"@sdxc/u/state\";\nimport { scaleProperty, translateProperty } from \"@sdxc/u/transform\";\nimport { fontSize, leading, nowrap, tabularNums, textDecoration, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { Point } from \"@sdxc/ui/utils\";\nimport type { PieAngles } from \"@sdxc/ui/utils\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { CHART_COLOR_SLOT_COUNT, chartPalette } from \"@sdxc/ui/styles\";\nimport { legendToggle } from \"@sdxc/ui/styles\";\nimport { computeMarkerIndices } from \"@sdxc/ui/utils\";\nimport { arcPath, areaPath, linePath } from \"@sdxc/ui/utils\";\nimport { bandScale, linearScale, pieAngles, ticks } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\n/** Categorical color {@link Chart.Line} falls back to when `color` is omitted. */\nconst DEFAULT_LINE_COLOR: Chart.Color = 1;\n\n/** Categorical color {@link Chart.Area} falls back to when `color` is omitted. */\nconst DEFAULT_AREA_COLOR: Chart.Color = 1;\n\n/**\n * `yDomain` value {@link Chart.Area} falls back to closing a series' filled\n * region down (or up) to when `baseline` is omitted.\n */\nconst DEFAULT_AREA_BASELINE = 0;\n\n/**\n * Approximate marker count {@link Chart.Line} and {@link Chart.Area} fall\n * back to for `markerCount`, giving keyboard and screen-reader users a\n * representative spread of stops instead of one per raw sample.\n */\nconst DEFAULT_MARKER_COUNT = 6;\n\n/**\n * `aria-hidden=\"true\"` applied to {@link Chart.Line}'s and {@link Chart.Area}'s\n * plotted `<path>` through {@link attrs} — a series' accessible name and\n * hover tooltip live on its point markers instead.\n */\nconst DEFAULT_PATH_ARIA_HIDDEN = \"true\";\n\n/**\n * Pixel distance from center to every wedge's inner edge {@link Chart.Pie}\n * falls back to when `innerRadius` is omitted — a solid pie reaching the\n * center, with no donut hole.\n */\nconst DEFAULT_PIE_INNER_RADIUS = 0;\n\n/**\n * {@link Chart.Color} {@link Chart.Tooltip.Swatch} falls back to when\n * `color` is omitted, matching {@link DEFAULT_LINE_COLOR}'s own default.\n */\nconst DEFAULT_SWATCH_COLOR: Chart.Color = 1;\n\n/**\n * `aria-hidden` value applied to {@link Chart.Tooltip} through\n * {@link attrs} unless overridden — the surface only restates the label,\n * value, and color a hovered point's native `<title>` already carries.\n */\nconst DEFAULT_TOOLTIP_ARIA_HIDDEN = \"true\";\n\n/** Approximate gridline count {@link Chart.Bar} falls back to when `tickCount` is omitted. */\nconst DEFAULT_BAR_TICK_COUNT = 5;\n\n/** Fraction of each category band reserved as a gap from its neighbors, {@link Chart.Bar} falls back to when `categoryGap` is omitted. */\nconst DEFAULT_CATEGORY_GAP = 0.2;\n\n/**\n * Fraction of a category's own band reserved as a gap between its series'\n * bars, {@link Chart.Bar} falls back to when `seriesGap` is omitted —\n * packing bars edge to edge, since most rows plot a single series.\n */\nconst DEFAULT_SERIES_GAP = 0;\n\n/**\n * `role=\"group\"` applied to {@link Chart.Legend}'s host through\n * {@link attrs} unless a consumer supplies its own `role`, announcing the\n * series switcher as a related set of controls to assistive technology.\n */\nconst DEFAULT_LEGEND_ROLE = \"group\";\n\n/**\n * `defaultChecked` {@link Chart.LegendItemProps} falls back to when\n * omitted, so a series renders visible until a reader explicitly hides it.\n */\nconst DEFAULT_LEGEND_ITEM_CHECKED = true;\n\n/**\n * Renders the series switcher's host: a `role=\"group\"` `<div>` laying its\n * {@link Chart.Legend.Item} children in a wrapping row. Must render as a\n * later sibling of the chart root, with items in that chart's series order.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the legend's markup.\n * @example\n * <Chart width={480} height={240} xDomain={[0, 11]} yDomain={[0, 1000]} aria-label={t(\"chart.revenue.label\")}>\n * \t<Chart.Line points={points} color={1} />\n * </Chart>\n * <Chart.Legend aria-label={t(\"chart.legend\")}>\n * \t<Chart.Legend.Item color={1}>{t(\"chart.series.revenue\")}</Chart.Legend.Item>\n * </Chart.Legend>\n */\nfunction ChartLegend(handle: Handle<Chart.LegendProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Chart.Legend: needs an \"aria-label\" or \"aria-labelledby\" identifying this legend for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"legend\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_LEGEND_ROLE }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexWrap(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(4),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders one series' entry: a native `<label>` wrapping a visually hidden,\n * `defaultChecked` checkbox, a `data-color` swatch matching its series, and\n * its name — unchecking hides the series via the paired chart root's `css()`.\n *\n * @param handle Runtime handle carrying the host `<label>`'s props, plus\n * the underlying `<input>`'s own attributes and per-part `swatch` styling.\n * @returns The render function producing the item's markup.\n * @example\n * <Chart.Legend.Item color={1}>{t(\"chart.series.revenue\")}</Chart.Legend.Item>\n * @example\n * <Chart.Legend.Item color={3} defaultChecked={false}>\n * \t{t(\"chart.series.archived\")}\n * </Chart.Legend.Item>\n */\nfunction ChartLegendItem(handle: Handle<Chart.LegendItemProps>) {\n\treturn () => {\n\t\tlet { color, defaultChecked, children, parts, mix, ...rest } = handle.props;\n\t\tlet resolvedChecked = defaultChecked ?? DEFAULT_LEGEND_ITEM_CHECKED;\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\tdata-slot=\"legend-item\"\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"&:has(input:focus-visible)\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tgap(2),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\ttransition(\"opacity, color\"),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\tleading(1.25),\n\t\t\t\t\twhen(\"&:has(input:not(:checked))\", [opacity(50), textDecoration(\"line-through\")]),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\tdata-slot=\"swatch\"\n\t\t\t\t\tdata-color={String(color)}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tchartPalette(\"color\"),\n\t\t\t\t\t\tinlineBlock(),\n\t\t\t\t\t\tis(2.5),\n\t\t\t\t\t\tbs(2.5),\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tshrink(),\n\t\t\t\t\t\tbg(\"currentColor\"),\n\t\t\t\t\t\tparts?.swatch,\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"checkbox\"\n\t\t\t\t\tdefaultChecked={resolvedChecked}\n\t\t\t\t\t{...rest}\n\t\t\t\t\tmix={[visuallyHidden(), mix]}\n\t\t\t\t/>\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n}\n\nChartLegend.Item = ChartLegendItem;\n\n/**\n * Prop and context types for {@link Chart} and its {@link Chart.Line},\n * {@link Chart.Area}, {@link Chart.Pie}, and {@link Chart.Legend} compound\n * parts.\n */\nexport namespace Chart {\n\t/**\n\t * Props accepted by {@link Chart.Legend}. Every native `<div>` attribute is\n\t * available unchanged, so `aria-label`, `aria-labelledby`, and `mix` style\n\t * the host exactly as they would on a bare grouping `<div>`.\n\t */\n\texport interface LegendProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Per-part styling for the color swatch {@link Chart.Legend.Item}\n\t * composes internally alongside its own host `<input>`.\n\t */\n\texport interface LegendItemPartsProps {\n\t\t/** Styling for the small swatch identifying this series' color. */\n\t\tswatch?: TagProps<\"span\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link Chart.Legend.Item}. Every native `<input>`\n\t * attribute is available unchanged — aside from `type`, always\n\t * `\"checkbox\"` — and `mix` styles that same `<input>` host.\n\t */\n\texport interface LegendItemProps extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {\n\t\t/** ARIA role override, restricted to what a checkbox input may carry. */\n\t\trole?: \"checkbox\" | \"button\" | \"menuitemcheckbox\" | \"option\" | \"switch\";\n\t\t/**\n\t\t * This series' categorical color — the identical {@link Color} its\n\t\t * matching plotted series was given as its own `color`, so this\n\t\t * swatch always matches the series it labels.\n\t\t */\n\t\tcolor: Color;\n\t\t/**\n\t\t * The series' visible name, read aloud as this checkbox's\n\t\t * accessible name through native `<label>` association. Required —\n\t\t * this module ships no built-in copy of its own.\n\t\t */\n\t\tchildren: RemixNode;\n\t\t/** Per-part styling for this item's internally composed swatch. */\n\t\tparts?: LegendItemPartsProps;\n\t}\n\n\t/**\n\t * Value {@link Chart} stores in component context: the pixel dimensions of\n\t * its coordinate space and the data domains mapped across them, shared with\n\t * every nested series compound part.\n\t */\n\texport interface Context {\n\t\t/** Pixel width of the coordinate space, matching {@link Props.width}. */\n\t\twidth: number;\n\t\t/** Pixel height of the coordinate space, matching {@link Props.height}. */\n\t\theight: number;\n\t\t/** `[start, end]` domain bounds mapped across `width`, matching {@link Props.xDomain}. */\n\t\txDomain: readonly [number, number];\n\t\t/** `[start, end]` domain bounds mapped across `height`, matching {@link Props.yDomain}. */\n\t\tyDomain: readonly [number, number];\n\t}\n\n\t/**\n\t * Props accepted by {@link Chart}. Every native `<svg>` attribute still\n\t * applies except `viewBox`, `width`, and `height`, computed from the props\n\t * of the same name below so every nested series' pixel math matches.\n\t */\n\texport interface Props extends Omit<TagProps<\"svg\">, \"viewBox\" | \"width\" | \"height\"> {\n\t\t/**\n\t\t * Pixel width of the chart's internal coordinate space — the value every\n\t\t * nested series' `x` positions are mapped onto. The `<svg>` renders at its\n\t\t * container's full size, scaling this space while preserving aspect ratio.\n\t\t */\n\t\twidth: number;\n\t\t/**\n\t\t * Pixel height of the chart's internal coordinate space — the value\n\t\t * every nested series' `y` positions are mapped onto.\n\t\t */\n\t\theight: number;\n\t\t/**\n\t\t * `[start, end]` bounds of every nested series' horizontal data\n\t\t * values, mapped across `width` and shared through context so every\n\t\t * series lines up on the same horizontal scale.\n\t\t */\n\t\txDomain: readonly [number, number];\n\t\t/**\n\t\t * `[start, end]` bounds of every nested series' vertical data values, mapped\n\t\t * across `height`. `start` maps to the coordinate space's bottom edge and\n\t\t * `end` to its top, matching a value axis growing upward against SVG's `y`.\n\t\t */\n\t\tyDomain: readonly [number, number];\n\t}\n\n\t/**\n\t * One categorical color a {@link Chart.Line}, {@link Chart.Area}, or any\n\t * further series picks up through the `--ui-chart-1` through `--ui-chart-8`\n\t * semantic variables, rotating a fixed palette across several series.\n\t */\n\texport type Color = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;\n\n\t/**\n\t * One data point plotted by {@link Chart.Line}, in data space — the\n\t * values a consumer's own domain uses, not yet mapped to pixels.\n\t */\n\texport interface LinePoint {\n\t\t/** Horizontal data value, mapped across the ancestor {@link Chart}'s `xDomain`. */\n\t\tx: number;\n\t\t/** Vertical data value, mapped across the ancestor {@link Chart}'s `yDomain`. */\n\t\ty: number;\n\t\t/**\n\t\t * Accessible name and hover tooltip text for this point, read by the\n\t\t * native `<title>` nested in its marker when the point falls among the\n\t\t * representative spread {@link Chart.Line} renders a marker for.\n\t\t */\n\t\tlabel: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link Chart.Line}. Extends every native `<g>`\n\t * attribute except `children` and `points`, redefined below with this\n\t * series' own data-space shape in place of the native `<polyline>` attribute.\n\t */\n\texport interface LineProps extends Omit<TagProps<\"g\">, \"children\" | \"points\"> {\n\t\t/**\n\t\t * The series' data points, in draw order along `x`. The plotted path\n\t\t * connects every point given here; the accessible markers render on\n\t\t * only a representative spread of them, chosen through `markerCount`.\n\t\t */\n\t\tpoints: readonly LinePoint[];\n\t\t/** Categorical color. Defaults to {@link DEFAULT_LINE_COLOR}. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * Approximate number of accessible, hoverable markers placed along\n\t\t * `points`. Each marker snaps to the point closest to one of this many\n\t\t * evenly spread \"nice\" values across the ancestor {@link Chart}'s `xDomain`.\n\t\t *\n\t\t * @default {@link DEFAULT_MARKER_COUNT}\n\t\t */\n\t\tmarkerCount?: number;\n\t\t/**\n\t\t * Per-part styling for the plotted `path` and each point `marker`,\n\t\t * layered after each part's own built-in styling. Use the `mix` prop\n\t\t * instead to style the series' outer host.\n\t\t */\n\t\tparts?: {\n\t\t\t/** Additional mixin(s) applied to the stroked `<path>`. */\n\t\t\tpath?: TagProps<\"path\">[\"mix\"];\n\t\t\t/** Additional mixin(s) applied to each point's `<circle>` marker. */\n\t\t\tmarker?: TagProps<\"circle\">[\"mix\"];\n\t\t};\n\t}\n\n\t/**\n\t * One data point plotted by {@link Chart.Area}, in data space — the\n\t * values a consumer's own domain uses, not yet mapped to pixels.\n\t */\n\texport interface AreaPoint {\n\t\t/** Horizontal data value, mapped across the ancestor {@link Chart}'s `xDomain`. */\n\t\tx: number;\n\t\t/** Vertical data value, mapped across the ancestor {@link Chart}'s `yDomain`. */\n\t\ty: number;\n\t\t/**\n\t\t * Accessible name and hover tooltip text for this point, read by the\n\t\t * native `<title>` nested in its marker when the point falls among the\n\t\t * representative spread {@link Chart.Area} renders a marker for.\n\t\t */\n\t\tlabel: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link Chart.Area}. Extends every native `<g>`\n\t * attribute except `children` and `points`, redefined below with this\n\t * series' own data-space shape in place of the native `<polyline>` attribute.\n\t */\n\texport interface AreaProps extends Omit<TagProps<\"g\">, \"children\" | \"points\"> {\n\t\t/**\n\t\t * The series' data points, in draw order along `x`. The filled region\n\t\t * traces every point given here before closing down to `baseline`; markers\n\t\t * render on a representative spread of them, chosen through `markerCount`.\n\t\t */\n\t\tpoints: readonly AreaPoint[];\n\t\t/** Categorical color. Defaults to {@link DEFAULT_AREA_COLOR}. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * The `yDomain` value the filled region closes down (or up) to —\n\t\t * typically the value axis' zero line. Defaults to\n\t\t * {@link DEFAULT_AREA_BASELINE}.\n\t\t */\n\t\tbaseline?: number;\n\t\t/**\n\t\t * Approximate number of accessible, hoverable markers placed along\n\t\t * `points`. Each marker snaps to the point closest to one of this many\n\t\t * evenly spread \"nice\" values across the ancestor {@link Chart}'s `xDomain`.\n\t\t *\n\t\t * @default {@link DEFAULT_MARKER_COUNT}\n\t\t */\n\t\tmarkerCount?: number;\n\t\t/**\n\t\t * Per-part styling for the filled `path` and each point `marker`,\n\t\t * layered after each part's own built-in styling. Use the `mix` prop\n\t\t * instead to style the series' outer host.\n\t\t */\n\t\tparts?: {\n\t\t\t/** Additional mixin(s) applied to the filled `<path>`. */\n\t\t\tpath?: TagProps<\"path\">[\"mix\"];\n\t\t\t/** Additional mixin(s) applied to each point's `<circle>` marker. */\n\t\t\tmarker?: TagProps<\"circle\">[\"mix\"];\n\t\t};\n\t}\n\n\t/**\n\t * One wedge's input for {@link Chart.Pie}: a magnitude and its required\n\t * accessible label. {@link pieAngles} turns `value` into a proportional\n\t * angle span, treating a negative value as zero and an all-zero total as even.\n\t */\n\texport interface PieDatum {\n\t\t/** The magnitude this wedge represents. */\n\t\tvalue: number;\n\t\t/**\n\t\t * Accessible name and hover tooltip text for this wedge, read by the\n\t\t * native `<title>` nested inside it — required, since a wedge with no\n\t\t * label has nothing for assistive technology to announce.\n\t\t */\n\t\tlabel: string;\n\t\t/**\n\t\t * Categorical color for this wedge, defaulting to its position in `data`\n\t\t * modulo the palette's slot count. Set explicitly to pin a category's\n\t\t * color across several charts or a paired legend.\n\t\t */\n\t\tcolor?: Color;\n\t}\n\n\t/**\n\t * Props accepted by {@link Chart.Pie}. Every native `<svg>` attribute still\n\t * applies except `children`, `viewBox`, `width`, and `height` — the latter\n\t * two take plain numbers for this component's own math, computing `viewBox`.\n\t */\n\texport interface PieProps\n\t\textends PieAngles.Options, Omit<TagProps<\"svg\">, \"children\" | \"viewBox\" | \"width\" | \"height\"> {\n\t\t/**\n\t\t * The wedges to draw, in draw order. Each entry's position in this\n\t\t * list picks its default color when its own `color` is omitted.\n\t\t */\n\t\tdata: readonly PieDatum[];\n\t\t/**\n\t\t * Pixel width of the chart's internal coordinate space that `viewBox` maps\n\t\t * onto. The rendered `<svg>` fills `100%` of the host's own inline size,\n\t\t * scaled to fit while preserving this aspect ratio against `height`.\n\t\t */\n\t\twidth: number;\n\t\t/**\n\t\t * Pixel height of the chart's internal coordinate space, on the same\n\t\t * terms as `width`.\n\t\t */\n\t\theight: number;\n\t\t/**\n\t\t * Pixel distance from center to every wedge's inner edge, in the same\n\t\t * coordinate space as `width`/`height`. A positive value smaller than the\n\t\t * chart's outer radius produces a donut with a hole that size.\n\t\t *\n\t\t * @default {@link DEFAULT_PIE_INNER_RADIUS}\n\t\t */\n\t\tinnerRadius?: number;\n\t\t/**\n\t\t * Per-part styling for every wedge `segment`, layered after its own\n\t\t * built-in styling. Use the `mix` prop instead to style the chart's\n\t\t * outer host.\n\t\t */\n\t\tparts?: {\n\t\t\t/** Additional mixin(s) applied to every wedge's `<path>`. */\n\t\t\tsegment?: TagProps<\"path\">[\"mix\"];\n\t\t};\n\t}\n\n\t/**\n\t * Prop types for {@link Chart.Tooltip} and its own compound parts.\n\t */\n\texport namespace Tooltip {\n\t\t/**\n\t\t * Every native `<div>` attribute, plus the `mix` passthrough. A\n\t\t * `chartTooltip()` mixin writes this host's position and open state\n\t\t * directly at runtime, as CSS custom properties and a `data-open` attribute.\n\t\t */\n\t\texport interface Props extends TagProps<\"div\"> {}\n\n\t\t/**\n\t\t * Props accepted by {@link Chart.Tooltip.Swatch}.\n\t\t */\n\t\texport interface SwatchProps extends TagProps<\"span\"> {\n\t\t\t/**\n\t\t\t * Categorical color matching the hovered point or wedge's own\n\t\t\t * series — the same {@link Chart.Color} any series or {@link Chart.Pie}\n\t\t\t * wedge renders with. Defaults to {@link DEFAULT_SWATCH_COLOR}.\n\t\t\t */\n\t\t\tcolor?: Color;\n\t\t}\n\n\t\t/**\n\t\t * Every native `<span>` attribute, plus the `mix` passthrough.\n\t\t */\n\t\texport interface LabelProps extends TagProps<\"span\"> {}\n\n\t\t/**\n\t\t * Every native `<span>` attribute, plus the `mix` passthrough.\n\t\t */\n\t\texport interface ValueProps extends TagProps<\"span\"> {}\n\t}\n\n\t/**\n\t * A single series' plotted value at one {@link Chart.BarRow}'s category.\n\t */\n\texport interface BarValue {\n\t\t/** Numeric magnitude this bar represents, mapped across {@link Chart.BarProps.domain}. */\n\t\tvalue: number;\n\t\t/**\n\t\t * Accessible name and hover tooltip text for this bar, read by the\n\t\t * native `<title>` nested inside it — typically a formatted description of\n\t\t * the category, series, and value together (e.g. `\"March revenue: $1,240\"`).\n\t\t */\n\t\tlabel: string;\n\t}\n\n\t/**\n\t * One category's row of plotted values, one {@link Chart.BarValue} per key\n\t * listed in {@link Chart.BarProps.series}.\n\t */\n\texport interface BarRow {\n\t\t/**\n\t\t * Category key positioning this row's bars along the shared band axis.\n\t\t * Keep every row's category unique — a repeated category shares its first\n\t\t * occurrence's band position, overlapping its bars there.\n\t\t */\n\t\tcategory: string;\n\t\t/**\n\t\t * This row's value for every key listed in {@link Chart.BarProps.series},\n\t\t * keyed the same way. A row missing one of those keys renders no bar\n\t\t * for that series at this category.\n\t\t */\n\t\tvalues: Readonly<Record<string, BarValue>>;\n\t}\n\n\t/**\n\t * Props accepted by {@link Chart.Bar}. Every native `<svg>` attribute still\n\t * applies except `children`, `viewBox`, `width`, and `height` — the latter\n\t * two take plain numbers for this component's own math, computing `viewBox`.\n\t */\n\texport interface BarProps extends Omit<\n\t\tTagProps<\"svg\">,\n\t\t\"children\" | \"viewBox\" | \"width\" | \"height\"\n\t> {\n\t\t/** Rows to plot, one band per row along the category axis, in draw order. */\n\t\tdata: readonly BarRow[];\n\t\t/**\n\t\t * Ordered series keys plotted within every row's band. A key's position in\n\t\t * this list is both the stable index stamped onto `data-series-index` and\n\t\t * its slot in the `--ui-chart-1`–`--ui-chart-8` palette, wrapping past it.\n\t\t */\n\t\tseries: readonly string[];\n\t\t/**\n\t\t * Pixel width of the chart's internal coordinate space that `viewBox` maps\n\t\t * onto. The rendered `<svg>` fills `100%` of the host's own inline size,\n\t\t * scaled to fit while preserving this aspect ratio against `height`.\n\t\t */\n\t\twidth: number;\n\t\t/**\n\t\t * Pixel height of the chart's internal coordinate space, on the same\n\t\t * terms as `width`.\n\t\t */\n\t\theight: number;\n\t\t/**\n\t\t * `[start, end]` bounds of every bar's value, mapped across `height`.\n\t\t * `start` maps to the bottom edge and `end` to the top, matching the same\n\t\t * upward-value convention {@link Chart.Props.yDomain} uses against SVG's `y`.\n\t\t */\n\t\tdomain: readonly [number, number];\n\t\t/** Approximate number of horizontal gridlines spanning `domain`. Defaults to {@link DEFAULT_BAR_TICK_COUNT}. */\n\t\ttickCount?: number;\n\t\t/** Fraction of each category band reserved as a gap from its neighbors. Defaults to {@link DEFAULT_CATEGORY_GAP}. */\n\t\tcategoryGap?: number;\n\t\t/**\n\t\t * Fraction of each category's own band reserved as a gap between its\n\t\t * series' bars — most bar charts plot a single series per category, with\n\t\t * no neighboring bar to gap against.\n\t\t *\n\t\t * @default {@link DEFAULT_SERIES_GAP}\n\t\t */\n\t\tseriesGap?: number;\n\t\t/**\n\t\t * Per-part styling for the gridlines and bars, layered after each\n\t\t * part's own built-in styling. Use the `mix` prop instead to style\n\t\t * the chart's outer host.\n\t\t */\n\t\tparts?: {\n\t\t\t/** Additional mixin(s) applied to each horizontal gridline. */\n\t\t\tgridline?: TagProps<\"line\">[\"mix\"];\n\t\t\t/** Additional mixin(s) applied to each plotted bar. */\n\t\t\tbar?: TagProps<\"rect\">[\"mix\"];\n\t\t};\n\t}\n}\n\n/**\n * Renders a chart's coordinate space: a responsive `<svg>` whose `viewBox`\n * comes from `width`/`height`, shared via context so nested series share one\n * scale. A paired {@link Chart.Legend} must render as this root's later sibling.\n *\n * @param handle Runtime handle carrying the host `<svg>`'s props and providing {@link Chart.Context}.\n * @returns The render function producing the chart's coordinate space.\n * @example\n * <Chart width={480} height={240} xDomain={[0, 11]} yDomain={[0, 1000]} aria-label={t(\"chart.revenue.label\")}>\n * \t<Chart.Line\n * \t\tpoints={months.map((month) => ({\n * \t\t\tx: month.index,\n * \t\t\ty: month.revenue,\n * \t\t\tlabel: t(\"chart.revenue.point\", { month: month.name, amount: month.revenue }),\n * \t\t}))}\n * \t/>\n * </Chart>\n * <Chart.Legend aria-label={t(\"chart.legend\")}>\n * \t<Chart.Legend.Item color={1}>{t(\"chart.series.revenue\")}</Chart.Legend.Item>\n * </Chart.Legend>\n */\nexport function Chart(handle: Handle<Chart.Props, Chart.Context>) {\n\treturn () => {\n\t\tlet { width, height, xDomain, yDomain, mix, ...rest } = handle.props;\n\n\t\thandle.context.set({ width, height, xDomain, yDomain });\n\n\t\treturn (\n\t\t\t<svg\n\t\t\t\tviewBox={`0 0 ${width} ${height}`}\n\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[legendToggle(), block(), is(\"full\"), bs(\"auto\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\nChart.Legend = ChartLegend;\n\n/**\n * Renders one series' representative point markers: a small focusable\n * `<circle>` at each of `markerIndices`' scaled positions, nested with a\n * `<title>` carrying that point's own `label`.\n *\n * @param points The series' original data points, read for each marker's label.\n * @param scaledPoints Each point's already-scaled pixel position, in the same order as `points`.\n * @param markerIndices Which of `points`' indices to render a marker for.\n * @param markerMix Additional mixin(s) layered after each marker's own built-in styling.\n * @returns The rendered `<circle>` markers.\n */\nfunction renderChartMarkers(\n\tpoints: readonly { label: string }[],\n\tscaledPoints: readonly Point[],\n\tmarkerIndices: readonly number[],\n\tmarkerMix: TagProps<\"circle\">[\"mix\"],\n): RemixNode {\n\treturn markerIndices.map((index) => {\n\t\tlet point = points[index];\n\t\tlet position = scaledPoints[index];\n\n\t\tif (point === undefined || position === undefined) return null;\n\n\t\treturn (\n\t\t\t<circle\n\t\t\t\tkey={index}\n\t\t\t\tcx={position.x}\n\t\t\t\tcy={position.y}\n\t\t\t\ttabIndex={0}\n\t\t\t\trole=\"img\"\n\t\t\t\tmix={[\n\t\t\t\t\tfocusVisible(outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\tfill(\"currentColor\"),\n\t\t\t\t\traw({ r: \"var(--ui-chart-point-radius, 0.1875rem)\" }),\n\t\t\t\t\tmarkerMix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<title>{point.label}</title>\n\t\t\t</circle>\n\t\t);\n\t});\n}\n\n/**\n * Renders a line series: a stroked, `aria-hidden` `<path>` connecting\n * `points` via {@link linearScale} and {@link linePath}, plus a focusable\n * marker with a `<title>`, sampled via {@link ticks} for manageable density.\n *\n * @param handle Runtime handle carrying the host `<g>`'s props.\n * @returns The render function producing the series' markup.\n * @example\n * <Chart.Line\n * \tcolor={2}\n * \tpoints={[\n * \t\t{ x: 0, y: 12, label: t(\"chart.point\", { x: 0, y: 12 }) },\n * \t\t{ x: 1, y: 18, label: t(\"chart.point\", { x: 1, y: 18 }) },\n * \t\t{ x: 2, y: 9, label: t(\"chart.point\", { x: 2, y: 9 }) },\n * \t]}\n * />\n * @example\n * <Chart.Line points={points} markerCount={3} parts={{ path: css({ strokeDasharray: \"4 4\" }) }} />\n */\nChart.Line = function ChartLine(handle: Handle<Chart.LineProps>) {\n\treturn () => {\n\t\tlet { points, color, markerCount, parts, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Chart);\n\t\tlet resolvedColor = color ?? DEFAULT_LINE_COLOR;\n\t\tlet resolvedMarkerCount = markerCount ?? DEFAULT_MARKER_COUNT;\n\n\t\tlet x = linearScale(context.xDomain, [0, context.width]);\n\t\tlet y = linearScale(context.yDomain, [context.height, 0]);\n\t\tlet scaledPoints: Point[] = points.map((point) => ({ x: x(point.x), y: y(point.y) }));\n\t\tlet d = linePath(scaledPoints);\n\n\t\tlet markerIndices = computeMarkerIndices(points, context.xDomain, resolvedMarkerCount);\n\n\t\treturn (\n\t\t\t<g data-color={String(resolvedColor)} {...rest} mix={[chartPalette(\"color\"), mix]}>\n\t\t\t\t<path\n\t\t\t\t\td={d}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tattrs({ \"aria-hidden\": DEFAULT_PATH_ARIA_HIDDEN }),\n\t\t\t\t\t\tfill(\"none\"),\n\t\t\t\t\t\tstroke(\"currentColor\"),\n\t\t\t\t\t\tstrokeWidth(\"var(--ui-chart-line-width, 2px)\"),\n\t\t\t\t\t\tstrokeLinejoin(\"round\"),\n\t\t\t\t\t\tstrokeLinecap(\"round\"),\n\t\t\t\t\t\tparts?.path,\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t\t{renderChartMarkers(points, scaledPoints, markerIndices, parts?.marker)}\n\t\t\t</g>\n\t\t);\n\t};\n};\n\n/**\n * Renders the tooltip's floating host: an absolutely positioned `<div>`\n * reading position and `data-open` state a `chartTooltip()` mixin writes\n * onto it. Visibility requires pairing that mixin with the chart root.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the surface's markup.\n * @example\n * <div style={{ position: \"relative\" }} mix={chartTooltip()}>\n * \t<Chart width={480} height={240} xDomain={[0, 11]} yDomain={[0, 1000]} aria-label={t(\"chart.revenue.label\")}>\n * \t\t<Chart.Line points={points} />\n * \t</Chart>\n * \t<Chart.Tooltip>\n * \t\t<Chart.Tooltip.Swatch color={2} />\n * \t\t<Chart.Tooltip.Label>{t(\"chart.months.march\")}</Chart.Tooltip.Label>\n * \t\t<Chart.Tooltip.Value>42</Chart.Tooltip.Value>\n * \t</Chart.Tooltip>\n * </div>\n */\nfunction ChartTooltip(handle: Handle<Chart.Tooltip.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"tooltip\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ \"aria-hidden\": DEFAULT_TOOLTIP_ARIA_HIDDEN }),\n\t\t\t\t\tabsolute(),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(2),\n\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\tshadow(\"md\"),\n\t\t\t\t\tz(10),\n\t\t\t\t\tgap(1.5),\n\t\t\t\t\tpb(1.5),\n\t\t\t\t\tnowrap(),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\topacity(0),\n\t\t\t\t\ttransition(\"opacity, scale\", { duration: durations.fast, easing: easings.standard }),\n\t\t\t\t\twhen(\"&[data-open]\", [opacity(100), scaleProperty(1)]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\tscaleProperty(\"none\"),\n\t\t\t\t\t\traw({ transitionProperty: \"opacity\" }),\n\t\t\t\t\t]),\n\t\t\t\t\traw({\n\t\t\t\t\t\tleft: \"var(--ui-chart-tooltip-x, 0px)\",\n\t\t\t\t\t\ttop: \"var(--ui-chart-tooltip-y, 0px)\",\n\t\t\t\t\t\tfontSize: \"0.8125rem\",\n\t\t\t\t\t}),\n\t\t\t\t\ttranslateProperty(\"-50% calc(-100% - var(--ui-chart-tooltip-gap, 0.5rem))\"),\n\t\t\t\t\tleading(1.2),\n\t\t\t\t\tpointerEvents(),\n\t\t\t\t\tscaleProperty(0.95),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders a small circular color chip identifying the tooltip's current\n * point or wedge: a native `<span>` colored through the `data-color`\n * attribute, on the same eight-slot palette every series already renders with.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the swatch's markup.\n * @example\n * <Chart.Tooltip.Swatch color={2} />\n */\nChartTooltip.Swatch = function ChartTooltipSwatch(handle: Handle<Chart.Tooltip.SwatchProps>) {\n\treturn () => {\n\t\tlet { color, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_SWATCH_COLOR;\n\n\t\treturn (\n\t\t\t<span\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"swatch\"\n\t\t\t\tdata-color={String(resolvedColor)}\n\t\t\t\tmix={[\n\t\t\t\t\tchartPalette(\"backgroundColor\"),\n\t\t\t\t\tinlineBlock(),\n\t\t\t\t\tis(2),\n\t\t\t\t\tbs(2),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tshrink(),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the tooltip's label slot: a native `<span>` showing the hovered\n * point or wedge's own label — the same string rendered into its native\n * `<title>` — muted to read as secondary against {@link Chart.Tooltip.Value}.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the label's markup.\n * @example\n * <Chart.Tooltip.Label>{t(\"chart.months.march\")}</Chart.Tooltip.Label>\n */\nChartTooltip.Label = function ChartTooltipLabel(handle: Handle<Chart.Tooltip.LabelProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <span {...rest} data-slot=\"label\" mix={[opacity(75), mix]} />;\n\t};\n};\n\n/**\n * Renders the tooltip's value slot: a native `<span>` showing the hovered\n * point or wedge's own value, weighted as the surface's most prominent figure\n * and set in tabular digits, so the surface holds its width as the value changes.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the value's markup.\n * @example\n * <Chart.Tooltip.Value>42</Chart.Tooltip.Value>\n */\nChartTooltip.Value = function ChartTooltipValue(handle: Handle<Chart.Tooltip.ValueProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <span {...rest} data-slot=\"value\" mix={[weight(\"semibold\"), tabularNums(), mix]} />;\n\t};\n};\n\n// @ts-ignore\nChart.Tooltip = ChartTooltip;\n\n/**\n * Renders an area series: a filled, `aria-hidden` `<path>` tracing `points`\n * and closing down to `baseline`, mapped through {@link linearScale} and\n * {@link areaPath}, plus a focusable marker sampled via {@link ticks}.\n *\n * @param handle Runtime handle carrying the host `<g>`'s props.\n * @returns The render function producing the series' markup.\n * @example\n * <Chart.Area\n * \tcolor={3}\n * \tpoints={[\n * \t\t{ x: 0, y: 12, label: t(\"chart.point\", { x: 0, y: 12 }) },\n * \t\t{ x: 1, y: 18, label: t(\"chart.point\", { x: 1, y: 18 }) },\n * \t\t{ x: 2, y: 9, label: t(\"chart.point\", { x: 2, y: 9 }) },\n * \t]}\n * />\n * @example\n * <Chart.Area\n * \tpoints={points}\n * \tbaseline={20}\n * \tmarkerCount={3}\n * \tparts={{ path: css({ fillOpacity: 0.4 }) }}\n * />\n */\nChart.Area = function ChartArea(handle: Handle<Chart.AreaProps>) {\n\treturn () => {\n\t\tlet { points, color, baseline, markerCount, parts, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Chart);\n\t\tlet resolvedColor = color ?? DEFAULT_AREA_COLOR;\n\t\tlet resolvedBaseline = baseline ?? DEFAULT_AREA_BASELINE;\n\t\tlet resolvedMarkerCount = markerCount ?? DEFAULT_MARKER_COUNT;\n\n\t\tlet x = linearScale(context.xDomain, [0, context.width]);\n\t\tlet y = linearScale(context.yDomain, [context.height, 0]);\n\t\tlet scaledPoints: Point[] = points.map((point) => ({ x: x(point.x), y: y(point.y) }));\n\t\tlet d = areaPath(scaledPoints, y(resolvedBaseline));\n\n\t\tlet markerIndices = computeMarkerIndices(points, context.xDomain, resolvedMarkerCount);\n\n\t\treturn (\n\t\t\t<g data-color={String(resolvedColor)} {...rest} mix={[chartPalette(\"color\"), mix]}>\n\t\t\t\t<path\n\t\t\t\t\td={d}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tattrs({ \"aria-hidden\": DEFAULT_PATH_ARIA_HIDDEN }),\n\t\t\t\t\t\tfill(\"currentColor\"),\n\t\t\t\t\t\tfillOpacity(\"var(--ui-chart-area-fill-opacity, 0.25)\"),\n\t\t\t\t\t\tstroke(\"currentColor\"),\n\t\t\t\t\t\tstrokeWidth(\"var(--ui-chart-area-width, 2px)\"),\n\t\t\t\t\t\tstrokeLinejoin(\"round\"),\n\t\t\t\t\t\tstrokeLinecap(\"round\"),\n\t\t\t\t\t\tparts?.path,\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t\t{renderChartMarkers(points, scaledPoints, markerIndices, parts?.marker)}\n\t\t\t</g>\n\t\t);\n\t};\n};\n\n/**\n * Renders a pie or donut chart: an independent `<svg>` root, since a\n * circular layout shares no domain with a Cartesian {@link Chart}. A paired\n * {@link Chart.Legend} must render as this root's later sibling.\n *\n * @param handle Runtime handle carrying the host `<svg>`'s props.\n * @returns The render function producing the chart's markup.\n * @example\n * <Chart.Pie\n * \twidth={200}\n * \theight={200}\n * \taria-label={t(\"chart.revenueByRegion\")}\n * \tdata={[\n * \t\t{ value: 45, label: t(\"region.americas\", { percent: 45 }) },\n * \t\t{ value: 30, label: t(\"region.emea\", { percent: 30 }) },\n * \t\t{ value: 25, label: t(\"region.apac\", { percent: 25 }) },\n * \t]}\n * />\n * @example\n * <Chart.Pie\n * \twidth={200}\n * \theight={200}\n * \tinnerRadius={60}\n * \taria-label={t(\"chart.storageByType\")}\n * \tdata={rows.map((row) => ({ value: row.bytes, label: row.name }))}\n * />\n */\nChart.Pie = function ChartPie(handle: Handle<Chart.PieProps>) {\n\treturn () => {\n\t\tlet { data, width, height, innerRadius, startAngle, endAngle, padAngle, parts, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet resolvedInnerRadius = innerRadius ?? DEFAULT_PIE_INNER_RADIUS;\n\n\t\tlet cx = width / 2;\n\t\tlet cy = height / 2;\n\t\tlet outerRadius = Math.min(width, height) / 2;\n\n\t\tlet slices = pieAngles(\n\t\t\tdata.map((datum) => datum.value),\n\t\t\t{ startAngle, endAngle, padAngle },\n\t\t);\n\n\t\treturn (\n\t\t\t<svg\n\t\t\t\tviewBox={`0 0 ${width} ${height}`}\n\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[chartPalette(\"fill\", \" \"), legendToggle(), block(), is(\"full\"), bs(\"auto\"), mix]}\n\t\t\t>\n\t\t\t\t{slices.map((slice, index) => {\n\t\t\t\t\tlet datum = data[index];\n\t\t\t\t\tif (datum === undefined) return null;\n\n\t\t\t\t\tlet d = arcPath({\n\t\t\t\t\t\tcx,\n\t\t\t\t\t\tcy,\n\t\t\t\t\t\tinnerRadius: resolvedInnerRadius,\n\t\t\t\t\t\touterRadius,\n\t\t\t\t\t\tstartAngle: slice.startAngle,\n\t\t\t\t\t\tendAngle: slice.endAngle,\n\t\t\t\t\t});\n\t\t\t\t\tif (d === \"\") return null;\n\n\t\t\t\t\tlet resolvedColor: Chart.Color =\n\t\t\t\t\t\tdatum.color ?? (((index % CHART_COLOR_SLOT_COUNT) + 1) as Chart.Color);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<path\n\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\td={d}\n\t\t\t\t\t\t\tdata-color={String(resolvedColor)}\n\t\t\t\t\t\t\ttabIndex={0}\n\t\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tfocusVisible(outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\t\t\tparts?.segment,\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<title>{datum.label}</title>\n\t\t\t\t\t\t</path>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t</svg>\n\t\t);\n\t};\n};\n\n/**\n * Renders a categorical bar chart: an independent `<svg>` root, since a\n * band axis shares no continuous domain with a Cartesian {@link Chart}. A\n * paired {@link Chart.Legend} must render as this root's later sibling.\n *\n * @param handle Runtime handle carrying the host `<svg>`'s props.\n * @returns The render function producing the chart's markup.\n * @example\n * <Chart.Bar\n * \twidth={480}\n * \theight={240}\n * \tdomain={[0, 5000]}\n * \taria-label={t(\"chart.revenue.label\")}\n * \tdata={[\n * \t\t{\n * \t\t\tcategory: \"Jan\",\n * \t\t\tvalues: { revenue: { value: 4000, label: t(\"chart.revenuePoint\", { month: \"Jan\", value: 4000 }) } },\n * \t\t},\n * \t\t{\n * \t\t\tcategory: \"Feb\",\n * \t\t\tvalues: { revenue: { value: 3000, label: t(\"chart.revenuePoint\", { month: \"Feb\", value: 3000 }) } },\n * \t\t},\n * \t]}\n * \tseries={[\"revenue\"]}\n * />\n * @example\n * <Chart.Bar\n * \twidth={480}\n * \theight={240}\n * \tdomain={[0, 5000]}\n * \taria-label={t(\"chart.revenue.label\")}\n * \tdata={quarters.map((quarter) => ({\n * \t\tcategory: quarter.name,\n * \t\tvalues: {\n * \t\t\trevenue: {\n * \t\t\t\tvalue: quarter.revenue,\n * \t\t\t\tlabel: t(\"chart.revenuePoint\", { quarter: quarter.name, value: quarter.revenue }),\n * \t\t\t},\n * \t\t\trefunds: {\n * \t\t\t\tvalue: quarter.refunds,\n * \t\t\t\tlabel: t(\"chart.refundsPoint\", { quarter: quarter.name, value: quarter.refunds }),\n * \t\t\t},\n * \t\t},\n * \t}))}\n * \tseries={[\"revenue\", \"refunds\"]}\n * \tseriesGap={0.15}\n * />\n */\nChart.Bar = function ChartBar(handle: Handle<Chart.BarProps>) {\n\treturn () => {\n\t\tlet {\n\t\t\tdata,\n\t\t\tseries,\n\t\t\twidth,\n\t\t\theight,\n\t\t\tdomain,\n\t\t\ttickCount,\n\t\t\tcategoryGap,\n\t\t\tseriesGap,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedTickCount = tickCount ?? DEFAULT_BAR_TICK_COUNT;\n\t\tlet resolvedCategoryGap = categoryGap ?? DEFAULT_CATEGORY_GAP;\n\t\tlet resolvedSeriesGap = seriesGap ?? DEFAULT_SERIES_GAP;\n\n\t\tlet categories = data.map((row) => row.category);\n\t\tlet outer = bandScale(categories, [0, width], {\n\t\t\tpaddingInner: resolvedCategoryGap,\n\t\t\tpaddingOuter: resolvedCategoryGap / 2,\n\t\t});\n\t\tlet inner = bandScale(series, [0, outer.bandwidth], { paddingInner: resolvedSeriesGap });\n\t\tlet y = linearScale(domain, [height, 0]);\n\t\tlet baselineY = y(0);\n\t\tlet gridlineValues = ticks(domain, resolvedTickCount);\n\n\t\treturn (\n\t\t\t<svg\n\t\t\t\tviewBox={`0 0 ${width} ${height}`}\n\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[chartPalette(\"fill\", \" \"), legendToggle(), block(), is(\"full\"), bs(\"auto\"), mix]}\n\t\t\t>\n\t\t\t\t<g mix={[attrs({ \"aria-hidden\": DEFAULT_PATH_ARIA_HIDDEN })]}>\n\t\t\t\t\t{gridlineValues.map((value) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={value}\n\t\t\t\t\t\t\tx1={0}\n\t\t\t\t\t\t\tx2={width}\n\t\t\t\t\t\t\ty1={y(value)}\n\t\t\t\t\t\t\ty2={y(value)}\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tstroke(\"var(--ui-neutral-border)\"),\n\t\t\t\t\t\t\t\tstrokeWidth(\"1\"),\n\t\t\t\t\t\t\t\tvectorEffect(\"non-scaling-stroke\"),\n\t\t\t\t\t\t\t\tparts?.gridline,\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</g>\n\t\t\t\t{data.map((row) => {\n\t\t\t\t\tlet categoryX = outer.position(row.category);\n\t\t\t\t\tif (categoryX === undefined) return null;\n\n\t\t\t\t\treturn series.map((key, index) => {\n\t\t\t\t\t\tlet entry = row.values[key];\n\t\t\t\t\t\tif (entry === undefined) return null;\n\n\t\t\t\t\t\tlet barX = categoryX + (inner.position(key) ?? 0);\n\t\t\t\t\t\tlet barValueY = y(entry.value);\n\t\t\t\t\t\tlet rectY = Math.min(baselineY, barValueY);\n\t\t\t\t\t\tlet rectHeight = Math.abs(barValueY - baselineY);\n\t\t\t\t\t\tlet resolvedColor: Chart.Color = ((index % CHART_COLOR_SLOT_COUNT) + 1) as Chart.Color;\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<rect\n\t\t\t\t\t\t\t\tkey={`${row.category}:${key}`}\n\t\t\t\t\t\t\t\tx={barX}\n\t\t\t\t\t\t\t\ty={rectY}\n\t\t\t\t\t\t\t\twidth={inner.bandwidth}\n\t\t\t\t\t\t\t\theight={rectHeight}\n\t\t\t\t\t\t\t\tdata-color={String(resolvedColor)}\n\t\t\t\t\t\t\t\tdata-series-index={String(index)}\n\t\t\t\t\t\t\t\ttabIndex={0}\n\t\t\t\t\t\t\t\trole=\"img\"\n\t\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\t\thover(opacity(85)),\n\t\t\t\t\t\t\t\t\tfocusVisible(outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\t\t\t\ttransition(\"opacity\"),\n\t\t\t\t\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", transitionDuration(\"0s\")),\n\t\t\t\t\t\t\t\t\tparts?.bar,\n\t\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<title>{entry.label}</title>\n\t\t\t\t\t\t\t</rect>\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t})}\n\t\t\t</svg>\n\t\t);\n\t};\n};\n"
|
|
11
|
-
},
|
|
12
|
-
"test": null
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "color-area",
|
|
3
|
-
"changedIn": "2026.10.2",
|
|
4
|
-
"dependencies": [],
|
|
5
|
-
"exports": [
|
|
6
|
-
"ColorArea"
|
|
7
|
-
],
|
|
8
|
-
"source": {
|
|
9
|
-
"path": "color-area.tsx",
|
|
10
|
-
"content": "/**\n * A two-dimensional saturation/brightness picking square for a given hue,\n * built from two overlaid native `<input type=\"range\">` elements — one\n * horizontal for saturation, one rotated vertical for brightness — whose\n * native thumbs, each reshaped into a thin line, cross at the picked point.\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 { bg, border, linearGradient, outline, outlineStyle } from \"@sdxc/u/color\";\nimport { opacity, ringShadow, rounded, transition, transitionDuration } from \"@sdxc/u/effects\";\nimport { cursor, pointerEvents, raw } from \"@sdxc/u/general\";\nimport { absolute, appearance, inlineBlock, inset, relative } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, m } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { scaleProperty } from \"@sdxc/u/transform\";\nimport { attrs } from \"remix/component\";\n\nimport { mergeStyle } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\n/** Hue, in degrees, {@link ColorArea} falls back to when `hue` is omitted. */\nconst DEFAULT_HUE = 0;\n\n/** Lower bound shared by both axis inputs' native `min`. */\nconst DEFAULT_MIN = 0;\n\n/** Upper bound shared by both axis inputs' native `max`. */\nconst DEFAULT_MAX = 100;\n\n/** Step shared by both axis inputs' native `step`, applied when a thumb's own `step` is omitted. */\nconst DEFAULT_STEP = 1;\n\n/**\n * Saturation (x-axis) {@link ColorArea} falls back to when neither\n * `saturation` nor `defaultSaturation` is set — full saturation, so the\n * default picked point starts at the pure-hue edge of the square.\n */\nconst DEFAULT_SATURATION = 100;\n\n/**\n * Brightness (y-axis) {@link ColorArea} falls back to when neither `value`\n * nor `defaultValue` is set — full brightness, pairing with\n * {@link DEFAULT_SATURATION} for a default picked point at the pure-hue corner.\n */\nconst DEFAULT_VALUE = 100;\n\n/**\n * `role=\"group\"` applied through {@link attrs} unless a consumer supplies\n * its own `role`, announcing the root as one grouped control to assistive\n * technology despite its two axes riding two separate native inputs.\n */\nconst DEFAULT_ROLE = \"group\";\n\n/**\n * Prop types for {@link ColorArea} and its compound parts.\n */\nexport namespace ColorArea {\n\t/**\n\t * Value {@link ColorArea} stores in component context so its\n\t * {@link ColorArea.SaturationThumb} and {@link ColorArea.ValueThumb} share\n\t * the same resolved hue, position, and stable ids without repeating them.\n\t */\n\texport interface Context {\n\t\t/** Resolved hue, in degrees, the square's background paints for. */\n\t\thue: number;\n\t\t/** Resolved saturation (x-axis position), `0`–`100`. */\n\t\tsaturation: number;\n\t\t/** Resolved brightness (y-axis position), `0`–`100`. */\n\t\tvalue: number;\n\t\t/** Id shared by {@link ColorArea.SaturationThumb} as its own `id`. */\n\t\tsaturationThumbId: string;\n\t\t/** Id shared by {@link ColorArea.ValueThumb} as its own `id`. */\n\t\tvalueThumbId: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link ColorArea}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Hue, in degrees `0`–`360`, the square's background renders every reachable\n\t\t * saturation/brightness combination for. Defaults to {@link DEFAULT_HUE}.\n\t\t * Typically driven by a hue control alongside this one, re-rendering on change.\n\t\t */\n\t\thue?: number;\n\t\t/** Current saturation (x-axis position), `0`–`100`, for a square whose position the consumer tracks itself. */\n\t\tsaturation?: number;\n\t\t/** Starting saturation (x-axis position), `0`–`100`, for a square that never tracks its own position. */\n\t\tdefaultSaturation?: number;\n\t\t/** Current brightness (y-axis position), `0`–`100`, for a square whose position the consumer tracks itself. */\n\t\tvalue?: number;\n\t\t/** Starting brightness (y-axis position), `0`–`100`, for a square that never tracks its own position. */\n\t\tdefaultValue?: number;\n\t}\n\n\t/**\n\t * Every native `<input>` attribute except `type` (fixed to `\"range\"`) and\n\t * `role` (the platform's implicit `\"slider\"`), plus `mix`. Use\n\t * `value`/`defaultValue`, `min`/`max`/`step`, and `aria-label` as usual.\n\t */\n\texport interface SaturationThumbProps extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {}\n\n\t/**\n\t * Every native `<input>` attribute except `type` (fixed to `\"range\"`) and\n\t * `role` (the platform's implicit `\"slider\"`), plus `mix`. Use\n\t * `value`/`defaultValue`, `min`/`max`/`step`, and `aria-label` as usual.\n\t */\n\texport interface ValueThumbProps extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {}\n}\n\n/**\n * Renders the root `<div>`'s picking-square background: literal `black`/`white`\n * gradient stops are the fixed brightness/saturation math primaries, and the\n * hue's `hsl()` composes through `bg()`, since it passes `(`-values unchanged.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link ColorArea.Context}.\n * @returns The render function producing the root's markup.\n * @example\n * <ColorArea aria-label={t(\"colorPicker.area\")} hue={210} defaultSaturation={80} defaultValue={70}>\n * \t<ColorArea.SaturationThumb aria-label={t(\"colorPicker.saturation\")} />\n * \t<ColorArea.ValueThumb aria-label={t(\"colorPicker.brightness\")} />\n * </ColorArea>\n */\nexport function ColorArea(handle: Handle<ColorArea.Props, ColorArea.Context>) {\n\treturn () => {\n\t\tlet { hue, saturation, defaultSaturation, value, defaultValue, mix, style, ...rest } =\n\t\t\thandle.props;\n\t\tlet resolvedHue = hue ?? DEFAULT_HUE;\n\t\tlet resolvedSaturation = saturation ?? defaultSaturation ?? DEFAULT_SATURATION;\n\t\tlet resolvedValue = value ?? defaultValue ?? DEFAULT_VALUE;\n\t\tlet resolvedStyle = mergeStyle(style, { \"--ui-color-area-hue\": resolvedHue });\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorArea: this group needs an `aria-label` describing what it picks — assistive technology has no accessible name for the group its two axis inputs are announced under otherwise.\",\n\t\t);\n\n\t\thandle.context.set({\n\t\t\thue: resolvedHue,\n\t\t\tsaturation: resolvedSaturation,\n\t\t\tvalue: resolvedValue,\n\t\t\tsaturationThumbId: `${handle.id}-saturation`,\n\t\t\tvalueThumbId: `${handle.id}-value`,\n\t\t});\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"area\"\n\t\t\t\t{...rest}\n\t\t\t\tstyle={resolvedStyle}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_ROLE }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineBlock(),\n\t\t\t\t\tis(\"var(--ui-color-area-size, 16rem)\"),\n\t\t\t\t\tbs(\"var(--ui-color-area-size, 16rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tborder({ width: 1, color: \"neutral\" }),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tbg({\n\t\t\t\t\t\timage: `${linearGradient(\"to top\", \"black\", \"transparent\")}, ${linearGradient(\"to right\", \"white\", \"transparent\")}`,\n\t\t\t\t\t}),\n\t\t\t\t\tbg(\"hsl(var(--ui-color-area-hue, 0) 100% 50%)\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * `direction` stays fixed left-to-right regardless of the page's own `dir`,\n * matching the root gradient's physical axes; only this thumb's own line\n * accepts pointer input, so elsewhere a click reaches the axis line beneath it.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the thumb's markup.\n * @example\n * <ColorArea.SaturationThumb aria-label={t(\"colorPicker.saturation\")} />\n */\nColorArea.SaturationThumb = function ColorAreaSaturationThumb(\n\thandle: Handle<ColorArea.SaturationThumbProps>,\n) {\n\treturn () => {\n\t\tlet { id, min, max, step, value, defaultValue, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(ColorArea);\n\t\tlet resolvedStep = step ?? DEFAULT_STEP;\n\t\tlet resolvedValue = value ?? defaultValue ?? context.saturation;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorArea.SaturationThumb: this thumb needs an `aria-label` describing the saturation axis — assistive technology has no accessible name for it otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<input\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"range\"\n\t\t\t\tid={id ?? context.saturationThumbId}\n\t\t\t\tmin={min ?? DEFAULT_MIN}\n\t\t\t\tmax={max ?? DEFAULT_MAX}\n\t\t\t\tstep={resolvedStep}\n\t\t\t\tdefaultValue={resolvedValue}\n\t\t\t\tmix={[\n\t\t\t\t\tabsolute(),\n\t\t\t\t\tz(10),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\tbs(\"full\"),\n\n\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", [\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tborder({ width: 2, color: \"neutral.tint\" }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\ttransition(\"scale\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&::-moz-range-thumb\", [\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tborder({ width: 2, color: \"neutral.tint\" }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\ttransition(\"scale\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t\"&:focus-visible::-webkit-slider-thumb\",\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t),\n\t\t\t\t\twhen(\"&:focus-visible::-moz-range-thumb\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen(\"&:disabled::-webkit-slider-thumb\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"&:disabled::-moz-range-thumb\", [cursor(\"not-allowed\"), opacity(50)]),\n\n\t\t\t\t\tinset(\"0\"),\n\t\t\t\t\tm(\"0\"),\n\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\tappearance(\"none\", { moz: false }),\n\t\t\t\t\traw({ direction: \"ltr\" }),\n\t\t\t\t\tpointerEvents(),\n\t\t\t\t\toutlineStyle(\"none\"),\n\n\t\t\t\t\twhen(\"&::-webkit-slider-runnable-track\", [\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tappearance(\"none\", { moz: false }),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&::-moz-range-track\", [\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tappearance(\"none\", { webkit: false, moz: false }),\n\t\t\t\t\t\tborder({ style: \"none\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", [\n\t\t\t\t\t\tis(\"var(--ui-color-area-thumb-thickness, 0.1875rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-color-area-size, 16rem)\"),\n\t\t\t\t\t\tappearance(\"none\", { moz: false }),\n\t\t\t\t\t\tpointerEvents(\"auto\"),\n\t\t\t\t\t\tringShadow(\"rgb(0 0 0 / 0.4)\", 1),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&::-moz-range-thumb\", [\n\t\t\t\t\t\tis(\"var(--ui-color-area-thumb-thickness, 0.1875rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-color-area-size, 16rem)\"),\n\t\t\t\t\t\tpointerEvents(\"auto\"),\n\t\t\t\t\t\tringShadow(\"rgb(0 0 0 / 0.4)\", 1),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"&:active::-webkit-slider-thumb\", scaleProperty(1.2)),\n\t\t\t\t\twhen(\"&:active::-moz-range-thumb\", scaleProperty(1.2)),\n\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", transitionDuration(\"0s\")),\n\t\t\t\t\t\twhen(\"&::-moz-range-thumb\", transitionDuration(\"0s\")),\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 * `writing-mode`/`direction` stay fixed regardless of the page's own `dir`,\n * so this line travels block-end (black) to block-start, the low-at-the-\n * bottom convention; pointer layering matches {@link ColorArea.SaturationThumb}.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the thumb's markup.\n * @example\n * <ColorArea.ValueThumb aria-label={t(\"colorPicker.brightness\")} />\n */\nColorArea.ValueThumb = function ColorAreaValueThumb(handle: Handle<ColorArea.ValueThumbProps>) {\n\treturn () => {\n\t\tlet { id, min, max, step, value, defaultValue, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(ColorArea);\n\t\tlet resolvedStep = step ?? DEFAULT_STEP;\n\t\tlet resolvedValue = value ?? defaultValue ?? context.value;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorArea.ValueThumb: this thumb needs an `aria-label` describing the brightness axis — assistive technology has no accessible name for it otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<input\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"range\"\n\t\t\t\tid={id ?? context.valueThumbId}\n\t\t\t\tmin={min ?? DEFAULT_MIN}\n\t\t\t\tmax={max ?? DEFAULT_MAX}\n\t\t\t\tstep={resolvedStep}\n\t\t\t\tdefaultValue={resolvedValue}\n\t\t\t\taria-orientation=\"vertical\"\n\t\t\t\tmix={[\n\t\t\t\t\tabsolute(),\n\t\t\t\t\tz(10),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\tbs(\"full\"),\n\n\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", [\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tborder({ width: 2, color: \"neutral.tint\" }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\ttransition(\"scale\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&::-moz-range-thumb\", [\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tborder({ width: 2, color: \"neutral.tint\" }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\ttransition(\"scale\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t\"&:focus-visible::-webkit-slider-thumb\",\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t),\n\t\t\t\t\twhen(\"&:focus-visible::-moz-range-thumb\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen(\"&:disabled::-webkit-slider-thumb\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"&:disabled::-moz-range-thumb\", [cursor(\"not-allowed\"), opacity(50)]),\n\n\t\t\t\t\tinset(\"0\"),\n\t\t\t\t\tm(\"0\"),\n\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\tappearance(\"none\", { moz: false }),\n\t\t\t\t\traw({ writingMode: \"vertical-lr\", direction: \"rtl\" }),\n\t\t\t\t\tpointerEvents(),\n\t\t\t\t\toutlineStyle(\"none\"),\n\n\t\t\t\t\twhen(\"&::-webkit-slider-runnable-track\", [\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tappearance(\"none\", { moz: false }),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&::-moz-range-track\", [\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tappearance(\"none\", { webkit: false, moz: false }),\n\t\t\t\t\t\tborder({ style: \"none\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", [\n\t\t\t\t\t\tis(\"var(--ui-color-area-thumb-thickness, 0.1875rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-color-area-size, 16rem)\"),\n\t\t\t\t\t\tappearance(\"none\", { moz: false }),\n\t\t\t\t\t\tpointerEvents(\"auto\"),\n\t\t\t\t\t\tringShadow(\"rgb(0 0 0 / 0.4)\", 1),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&::-moz-range-thumb\", [\n\t\t\t\t\t\tis(\"var(--ui-color-area-thumb-thickness, 0.1875rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-color-area-size, 16rem)\"),\n\t\t\t\t\t\tpointerEvents(\"auto\"),\n\t\t\t\t\t\tringShadow(\"rgb(0 0 0 / 0.4)\", 1),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"&:active::-webkit-slider-thumb\", scaleProperty(1.2)),\n\t\t\t\t\twhen(\"&:active::-moz-range-thumb\", scaleProperty(1.2)),\n\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\twhen(\"&::-webkit-slider-thumb\", transitionDuration(\"0s\")),\n\t\t\t\t\t\twhen(\"&::-moz-range-thumb\", transitionDuration(\"0s\")),\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": null
|
|
13
|
-
}
|