导航

v2.1.0
结构

滚动区域

可滚动的区域。对应方向还有内容时,边缘渐隐。

本页内容

滚动区域是页面内可独立滚动的区域,可用于面板中的长列表、宽表格或日志。它保留平台原生的滚动行为,使用纤细低调的滚动条。内容延伸到哪一侧的边缘之外,哪一侧就显示渐隐效果。内容到头时,对应边缘清晰可见。在阅读过程中末尾不断增长的区域,例如聊天或构建日志,还可以跟随新内容。

滚动区域

<div class="sheet max-w(360) mx-auto">  <div class="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabindex="0" role="region" aria-label="Release notes">    <p class="m(0)">2.1 adds overlays that need no script.</p>    <p class="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>    <p class="m(0) mt-sm">      Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.    </p>    <p class="m(0) mt-sm">      The select draws its option list in the same material where the browser allows it.    </p>    <p class="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>    <p class="m(0) mt-sm">      Corners turn with continuous curvature where corner-shape is supported.    </p>    <p class="m(0) mt-sm">Every one of these falls back to a working component.</p>  </div></div>
<div className="sheet max-w(360) mx-auto">  <div className="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabIndex={0} role="region" aria-label="Release notes">    <p className="m(0)">2.1 adds overlays that need no script.</p>    <p className="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>    <p className="m(0) mt-sm">      Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.    </p>    <p className="m(0) mt-sm">      The select draws its option list in the same material where the browser allows it.    </p>    <p className="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>    <p className="m(0) mt-sm">      Corners turn with continuous curvature where corner-shape is supported.    </p>    <p className="m(0) mt-sm">Every one of these falls back to a working component.</p>  </div></div>
<div class="sheet max-w(360) mx-auto">  <div class="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabindex="0" role="region" aria-label="Release notes">    <p class="m(0)">2.1 adds overlays that need no script.</p>    <p class="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>    <p class="m(0) mt-sm">      Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.    </p>    <p class="m(0) mt-sm">      The select draws its option list in the same material where the browser allows it.    </p>    <p class="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>    <p class="m(0) mt-sm">      Corners turn with continuous curvature where corner-shape is supported.    </p>    <p class="m(0) mt-sm">Every one of these falls back to a working component.</p>  </div></div>
<template>  <div class="sheet max-w(360) mx-auto">    <div class="scroll-area h(200) p-md text-sm fg-text-body leading-md" tabindex="0" role="region" aria-label="Release notes">      <p class="m(0)">2.1 adds overlays that need no script.</p>      <p class="m(0) mt-sm">Dialogs open with invoker commands and trap focus on their own.</p>      <p class="m(0) mt-sm">        Popovers, menus and tooltips are placed with anchor positioning and flip at the viewport edge.      </p>      <p class="m(0) mt-sm">        The select draws its option list in the same material where the browser allows it.      </p>      <p class="m(0) mt-sm">Segmented controls and tabs glide one indicator between options.</p>      <p class="m(0) mt-sm">        Corners turn with continuous curvature where corner-shape is supported.      </p>      <p class="m(0) mt-sm">Every one of these falls back to a working component.</p>    </div>  </div></template>
滚动笔记:有内容滚出区域的上边缘时,上边缘会出现渐隐效果。滚动到底时,下边缘的渐隐效果消失。

#渐隐效果如何随滚动变化

渐隐效果由遮罩实现,遮罩的两个渐变色标由自定义属性 --scroll-area-start 和 --scroll-area-end 控制。区域自身的滚动时间轴驱动两段动画:第一段在滚动范围的前 1.5rem 内逐渐显现起始边缘的渐隐效果,第二段在最后 1.5rem 内逐渐消除末端边缘的渐隐效果。整个过程无需脚本或哨兵元素。内容没有溢出时,时间轴处于非活动状态,两侧边缘都清晰可见。

浏览器不支持滚动驱动动画时,区域仍可照常滚动,边缘始终清晰可见。

#滚动到边界后

沿块轴滚动到区域边界后,可以接着滚动页面。在已无法继续滚动的区域上使用滚轮或滑动时,页面会像在其他内容上操作一样滚动。只有行内轴会限制滚动传递,因此横向滑动到一行的末端时,手势会在那里停止,避免触发浏览器的返回操作。

#沿行内轴滚动

scroll-area-inline 可横向滚动,并在行内轴的起始边缘和末端边缘显示渐隐效果,适用于一排卡片或比所在列更宽的表格。

沿行内轴滚动

<div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Regions">  <div class="flex gap-sm w-fit py(4) px(2)">    <span class="chip">Tokyo</span>    <span class="chip">Singapore</span>    <span class="chip">Sydney</span>    <span class="chip">Mumbai</span>    <span class="chip">Frankfurt</span>    <span class="chip">London</span>    <span class="chip">Paris</span>    <span class="chip">Stockholm</span>    <span class="chip">Virginia</span>    <span class="chip">Oregon</span>    <span class="chip">São Paulo</span>    <span class="chip">Cape Town</span>  </div></div>
<div className="scroll-area scroll-area-inline" tabIndex={0} role="region" aria-label="Regions">  <div className="flex gap-sm w-fit py(4) px(2)">    <span className="chip">Tokyo</span>    <span className="chip">Singapore</span>    <span className="chip">Sydney</span>    <span className="chip">Mumbai</span>    <span className="chip">Frankfurt</span>    <span className="chip">London</span>    <span className="chip">Paris</span>    <span className="chip">Stockholm</span>    <span className="chip">Virginia</span>    <span className="chip">Oregon</span>    <span className="chip">São Paulo</span>    <span className="chip">Cape Town</span>  </div></div>
<div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Regions">  <div class="flex gap-sm w-fit py(4) px(2)">    <span class="chip">Tokyo</span>    <span class="chip">Singapore</span>    <span class="chip">Sydney</span>    <span class="chip">Mumbai</span>    <span class="chip">Frankfurt</span>    <span class="chip">London</span>    <span class="chip">Paris</span>    <span class="chip">Stockholm</span>    <span class="chip">Virginia</span>    <span class="chip">Oregon</span>    <span class="chip">São Paulo</span>    <span class="chip">Cape Town</span>  </div></div>
<template>  <div class="scroll-area scroll-area-inline" tabindex="0" role="region" aria-label="Regions">    <div class="flex gap-sm w-fit py(4) px(2)">      <span class="chip">Tokyo</span>      <span class="chip">Singapore</span>      <span class="chip">Sydney</span>      <span class="chip">Mumbai</span>      <span class="chip">Frankfurt</span>      <span class="chip">London</span>      <span class="chip">Paris</span>      <span class="chip">Stockholm</span>      <span class="chip">Virginia</span>      <span class="chip">Oregon</span>      <span class="chip">São Paulo</span>      <span class="chip">Cape Town</span>    </div>  </div></template>

#跟随新内容

聊天、构建日志或流式输出的回答会在阅读过程中从末尾不断增长。为区域设置 role="log",并挂载 follow 行为脚本:新内容到达时,它让末尾保持可见;读者一旦从末尾滚开,就停止跟随;读者回到末尾时,再次跟随。在内容之后放一个带有 hidden 的 scroll-area-latest 按钮:它只在区域未跟随时出现,按下后会滚动到末尾并重新跟随。

跟随构建日志

<div class="sheet max-w(440) mx-auto">  <div class="scroll-area h(240) p-md font-mono text-xs fg-text-body leading-md" tabindex="0" role="log" aria-label="Build log">    <div id="build-lines">      <p class="m(0)">Cloning master-co/ui at 3041b1c</p>      <p class="m(0)">Installing 596 packages</p>      <p class="m(0)">Compiling 112 stylesheets</p>    </div>    <button type="button" class="btn btn-sm btn-pill scroll-area-latest" hidden>      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" />      </svg>Jump to latest    </button>  </div></div><script>const steps = ['Checking contracts', 'Rendering /components', 'Rendering /blocks', 'Rendering /pages', 'Writing llms.txt', 'Writing the registry', 'Checking 2,914 links', 'Compressing assets', 'Uploading 71 pages']const lines = document.getElementById('build-lines')let count = 0const timer = setInterval(() => {  const line = document.createElement('p')  line.className = 'm(0)'  line.textContent = steps[count % steps.length] + (count >= steps.length ? ' (pass ' + (Math.floor(count / steps.length) + 1) + ')' : '')  lines.append(line)  if (++count >= 120) clearInterval(timer)}, 800)</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
日志行不断到达,日志随之滚动。在运行时向上滚动:日志停在你所在的位置,并出现“Jump to latest”。按下该按钮,或滚回末尾,日志会再次跟随。

判断方式如下:

  • 跟随。 从挂载行为脚本的那一刻起,区域就开始跟随:它会滚动到末尾,此后只要内容增长,无论是新增一行、流式输出的词语落入最后一条消息,还是一张图片加载完成,都会再次滚动到末尾。
  • 停止。 向开头方向滚动会停止跟随,无论由什么引起:滚轮、手指、滚动条、↑、Page Up 或 Home。向开头方向转动滚轮会在区域移动之前立即停止跟随,因此恰在此刻到达的词语也不会把读者拉回去。
  • 再次跟随。 通过 End、滚动条或按钮重新到达末尾,就会再次跟随。距离末尾只差几个像素也算作到达末尾。
  • 事件。 每当读者使区域开始或停止跟随,区域都会派发 change。行为脚本的 value 表示是否正在跟随;将其设为 true 可把读者带到末尾,例如应用在读者发送消息时就会这样做。设置它不会派发事件。
app.js
import { follow } from '@master/ui/behaviors/follow.js'const log = document.querySelector('.scroll-area[role="log"]')const following = follow(log)form.addEventListener('submit', () => { following.value = true })

没有行为脚本时,该区域就是普通的滚动区域:停留在读者离开的位置,按钮保持隐藏。按钮粘性定位在区域底部,位于内容和渐隐边缘之上,并叠放在最后一行上方,而不是排在其后,因此显示按钮不会让内容变高。

#保持阅读位置

在读者正在查看的内容上方插入内容,例如在顶部加载更早的消息,会把正在阅读的内容往下推。浏览器会通过滚动锚定自行避免这一点:区域内的滚动位置会随上方内容的位移相应调整,正在阅读的消息保持在原位。样式表在区域上保留 overflow-anchor: auto,在其按钮上设置 none,因此浏览器不会把按钮当作固定不动的元素。在不支持滚动锚定的浏览器中,follow 行为脚本会按上方内容移动的距离自行完成同样的调整。位于顶部、其下方会插入新行的一行文字,例如提示正在加载更多内容的说明,也要设置 overflow-anchor: none,让浏览器固定的是某一行内容,而不是这行文字。

更早的消息和流式回答

<div class="sheet max-w(440) mx-auto">  <div class="scroll-area h(320) p-md" tabindex="0" role="log" aria-label="Conversation with Ada">    <p class="m(0) pb-sm text-center text-xs fg-text-muted" style="overflow-anchor: none" id="earlier">      Earlier messages load as you scroll up    </p>    <ol class="m(0) p(0)" id="turns">      <li class="message message-sent">        <div class="message-bubble">Can the docs build run on every push?</div>      </li>      <li class="message">        <div class="message-bubble">Yes. It takes about two minutes.</div>      </li>    </ol>    <button type="button" class="btn btn-sm btn-pill scroll-area-latest" hidden>      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" />      </svg>Jump to latest    </button>  </div></div><script>const turns = document.getElementById('turns')const turn = (text, sent) => {  const item = document.createElement('li')  item.className = sent ? 'message message-sent' : 'message'  const bubble = document.createElement('div')  bubble.className = 'message-bubble'  bubble.textContent = text  item.append(bubble)  return item}const older = [['Morning! Is the release still today?', false], ['It is, once the docs build passes.', true], ['Which build?', false], ['The one that checks every page and link.', true], ['Do we wait for it?', false], ['No, it reports here when it is done.', true]]const log = turns.closest('.scroll-area')log.addEventListener('scroll', () => {  if (log.scrollTop > 48 || !older.length) return  for (const [text, sent] of older.splice(-2).reverse()) turns.prepend(turn(text, sent))  if (!older.length) document.getElementById('earlier').textContent = 'The start of the conversation'})const exchanges = [  ['What does it check?', 'It renders every page in five languages, checks each preview against the contracts, follows every link and compares the registry with the package, then writes the search index.'],  ['And if a link is broken?', 'The build stops and names the page and the link, so nothing half checked reaches the site. Fix it and push again; the next run starts from the beginning.'],  ['Thanks!', 'Any time. I will post here when this one is done.']]let at = 0const next = () => {  if (at >= exchanges.length) return  const [question, answer] = exchanges[at++]  turns.append(turn(question, true))  const reply = turn('', false)  const bubble = reply.firstChild  bubble.setAttribute('aria-busy', 'true')  turns.append(reply)  const words = answer.split(' ')  const stream = setInterval(() => {    bubble.textContent += (bubble.textContent ? ' ' : '') + words.shift()    if (words.length) return    clearInterval(stream)    bubble.removeAttribute('aria-busy')    setTimeout(next, 2500)  }, 140)}setTimeout(next, 1200)</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
回答以流式方式输出,对话随之跟随。向上滚动:接近顶部时,更早的对话会加载到上方,而你正在阅读的那条保持在原位。

#无障碍

  • 滚动区域必须能通过键盘访问。如果区域内没有可聚焦的内容,为区域设置 tabindex="0"、一个 role(如 region)以及无障碍名称。
  • 遮罩也会让区域自身的滚动条在相同的边缘渐隐。强制颜色模式下会移除遮罩。
  • 为区域设置高度或最大高度。两者都未设置时,区域会随内容撑开,始终不会滚动。
  • role="log" 是礼貌型实时区域:添加到其中的内容会被播报,而不会移动焦点。回答以流式方式写入某条消息时,为该消息设置 aria-busy="true",回答完成后再移除,使它完整地播报一次,而不是逐词播报。
  • scroll-area-latest 按钮显示时是 Tab 键顺序中的真正按钮。按下后按钮隐藏,焦点移到区域上,之后可用按键滚动区域。
  • 跟随从不移动焦点,并且读者一滚开就停止,因此不断到达的内容永远不会把页面从正在阅读的人眼前抽走。

#键盘操作

滚动沿用浏览器的原生键盘操作。行为脚本只监听这些操作引起的滚动。

按键操作
ArrowUp, ArrowDown, PageUp, PageDown, Home, End按浏览器默认方式滚动当前聚焦的区域
ArrowUp, PageUp, Home使用 follow 行为脚本时:朝开头滚动会停止跟随,并显示 scroll-area-latest 按钮
End使用 follow 行为脚本时:回到末尾后,区域恢复跟随
Enter, Space在 scroll-area-latest 上:滚动到末尾并恢复跟随,行为与按钮一致

#React、Svelte 和 Vue

log 组件在其子元素外渲染一个会跟随的滚动区域,并附带按钮,挂载行为脚本,接收和传出 following。使用 npx master-ui add log 将组件复制到项目中。React、Svelte 和 Vue 介绍这些组件的实现和用法。

ui/log.tsx
'use client'import { useState, type ComponentProps } from 'react'import { follow } from '@master/ui/behaviors/follow.js'import { useBehavior } from './use-behavior'export interface LogProps extends Omit<ComponentProps<'div'>, 'ref'> {  /** Whether the region keeps its end in view. It stops when the reader scrolls away and starts again at the end. */  following?: boolean  defaultFollowing?: boolean  onFollowingChange?: (following: boolean) => void  /** The words of the button that leads back to the end, such as "Jump to latest". */  latestLabel: string}/** * A scroll area that follows what arrives at its end: a chat, a build log, a streamed answer. Its children * are the content; name it with `aria-label` and give it a height. Set `following` to true to bring the * reader back to the end, as when they send a message. */export function Log({ following, defaultFollowing = true, onFollowingChange, latestLabel, className, children, ...root }: LogProps) {  const ref = useBehavior(follow, undefined, { value: following, defaultValue: defaultFollowing, onValueChange: onFollowingChange })  const [first] = useState(following ?? defaultFollowing)  return (    <div className={className ? `scroll-area ${className}` : 'scroll-area'} role="log" tabIndex={0} ref={ref} {...root}>      {children}      <button type="button" className="btn btn-sm btn-pill scroll-area-latest" hidden={first}>        <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fillRule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" /></svg>        {latestLabel}      </button>    </div>  )}
ui/Log.svelte
<script lang="ts" module>  import type { Snippet } from 'svelte'  import type { HTMLAttributes } from 'svelte/elements'  export interface LogProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    /** What the region holds. */    children?: Snippet    /**     * Whether the region keeps its end in view. It stops when the reader scrolls away and starts again at the     * end. Bind it, or leave it out: it starts following.     */    following?: boolean    onFollowingChange?: (following: boolean) => void    /** The words of the button that leads back to the end, such as "Jump to latest". */    latestLabel: string  }</script><script lang="ts">  import { untrack } from 'svelte'  import { follow } from '@master/ui/behaviors/follow.js'  import { behavior } from './behavior.svelte.js'  let { children, following = $bindable(), onFollowingChange, latestLabel, class: className, ...root }: LogProps = $props()  const first = untrack(() => following) ?? true  const attach = behavior(follow, undefined, {    value: () => following,    change: (next) => { following = next; onFollowingChange?.(next) },  })</script><!--  @component  A scroll area that follows what arrives at its end: a chat, a build log, a streamed answer. Its children  are the content; name it with `aria-label` and give it a height. Set `following` to true to bring the  reader back to the end, as when they send a message.--><!-- A region that scrolls takes the focus, so the keys scroll it. --><!-- svelte-ignore a11y_no_noninteractive_tabindex --><div class={['scroll-area', className]} role="log" tabindex={0} {@attach attach} {...root}>  {@render children?.()}  <button type="button" class="btn btn-sm btn-pill scroll-area-latest" hidden={first}>    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" /></svg>    {latestLabel}  </button></div>
ui/Log.vue
<script setup lang="ts">import { useTemplateRef } from 'vue'import { follow } from '@master/ui/behaviors/follow.js'import { useBehavior } from './use-behavior'defineProps<{  /** The words of the button that leads back to the end, such as "Jump to latest". */  latestLabel: string}>()/** * Whether the region keeps its end in view: `v-model:following`. It stops when the reader scrolls away and * starts again at the end. */const following = defineModel<boolean>('following', { default: true })defineSlots<{  /** What the region holds. */  default?: () => unknown}>()/* * A scroll area that follows what arrives at its end: a chat, a build log, a streamed answer. Name it with * `aria-label` and give it a height. Set `following` to true to bring the reader back to the end, as when * they send a message. */// The button's hidden is the first state's attribute: after that it is the behavior's to move.const first = following.valueconst root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, follow, undefined, following)</script><template>  <div class="scroll-area" role="log" tabindex="0" ref="root">    <slot />    <button type="button" class="btn btn-sm btn-pill scroll-area-latest" :hidden="first">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(90 8 8)" /></svg>      {{ latestLabel }}    </button>  </div></template>

#类名

类名说明
scroll-area沿块轴滚动的区域,使用细滚动条,内容仍有延伸的边缘渐隐
scroll-area-inline沿行内轴滚动,起始边缘和末端边缘渐隐与 scroll-area 一同使用
scroll-area-latest用于区域内容之后的 btn:返回跟随区域末尾的入口。粘附在底部、覆盖内容并位于渐隐层之上;区域处于跟随状态时,行为脚本为其设置 hidden

#自定义属性

属性默认值说明
--scroll-area-fade1.5rem各边缘的渐隐长度

#源码

@master/ui/components/scroll-area.css
/* * Scroll area: a region that scrolls inside the page, with a thin quiet scrollbar. * Where content continues past an edge, that edge fades out; where it ends, the edge is clean. The fade is * read from the scroll position itself by a scroll-driven animation, with no script and no sentinel elements. * Without scroll-driven animations the region scrolls the same and its edges stay clean. * A region that follows what arrives (role="log", with the follow behavior) keeps its end in view. Its * scroll-area-latest button is the way back to the end once the reader has scrolled away: a small raised pill * that stands over the content at the foot of the region, above the faded edge, and takes no room of its own. */@property --scroll-area-start {  syntax: '<length>';  inherits: false;  initial-value: 0px;}@property --scroll-area-end {  syntax: '<length>';  inherits: false;  initial-value: 0px;}@layer components.ui {  .scroll-area {    --scroll-area-fade: 1.5rem;    /* The latest button stands over the content inside the region, not over a sticky header outside it. */    isolation: isolate;    min-width: 0;    min-height: 0;    overflow: auto;    /*     * Only the inline axis keeps its scrolling to itself, so a sideways swipe never turns into the browser's back     * gesture. Along the block axis the page goes on scrolling past the region: a contained axis stops the wheel     * even where nothing overflows, which would leave a short region as a dead patch in the page.     */    overscroll-behavior-inline: contain;    scrollbar-width: thin;    scrollbar-color: var(--color-line-strong) transparent;    /* Content inserted above what the reader is looking at moves the region with it, so the reader's place holds. */    overflow-anchor: auto;    &:focus-visible {      @apply --focus-ring;    }    /* Scrolls along the inline axis: a row of cards, a wide table. */    &.scroll-area-inline {      overflow: auto hidden;    }    /*     * Two animations on the region's own scroll timeline. The first runs over the first stretch of scrolling     * and opens the fade at the start edge; the second runs over the last stretch and closes the fade at the     * end edge. While nothing overflows the timeline is inactive and both lengths stay 0.     */    @supports (animation-timeline: scroll()) {      /* The way the mask runs, from the start edge to the end edge of the scrolling axis. */      --scroll-area-run: to bottom;      mask-image: linear-gradient(var(--scroll-area-run), transparent, black var(--scroll-area-start), black calc(100% - var(--scroll-area-end)), transparent);      /* Longhands: tools that fold the timeline into the shorthand write a value no browser reads. */      animation-name: scroll-area-start, scroll-area-end;      animation-timing-function: linear;      animation-fill-mode: both;      animation-timeline: scroll(self block), scroll(self block);      animation-range: 0 var(--scroll-area-fade), calc(100% - var(--scroll-area-fade)) 100%;      /*       * What the keys or a link bring into view stops clear of the fade, so a focused control and its ring are       * never dimmed at the edge it was scrolled to.       */      scroll-padding-block: var(--scroll-area-fade);      /* Right to left, the start edge is on the right, so the mask runs the other way. */      &.scroll-area-inline {        --scroll-area-run: to right;        scroll-padding-block: 0;        scroll-padding-inline: var(--scroll-area-fade);        animation-timeline: scroll(self inline), scroll(self inline);        &:dir(rtl) {          --scroll-area-run: to left;        }      }      /* A mask cuts the region's own focus ring, which stands outside it: while the keys hold it, the fade steps aside. */      &:focus-visible {        mask-image: none;      }    }    /*     * While the way back to the end stands over the last rows, what the keys bring into view at the foot stops     * above it instead of under it: the room it stands in, a small button's 32px and a few pixels more.     */    &:has(.scroll-area-latest:not([hidden])) {      scroll-padding-block-end: calc(max(.75rem, var(--scroll-area-fade)) + 2.25rem);    }    @media (forced-colors: active) {      scrollbar-color: auto;      mask-image: none;    }    /*     * On a btn inside the region, after its content, and written inside the region so it outweighs the btn's     * own rules. Sticky at the foot, it stands above the fade, where nothing dims it; a negative margin of its     * own height lays it over the last row instead of after it, so showing it never makes the content taller.     * It is never the element scroll anchoring holds still.     */    .scroll-area-latest {      position: sticky;      inset-block-end: max(.75rem, var(--scroll-area-fade));      z-index: 1;      display: flex;      width: fit-content;      margin: calc(-1 * var(--btn-height, 2rem)) auto 0;      overflow-anchor: none;      transition-property: box-shadow, translate, color, opacity, display;      transition-behavior: allow-discrete;      &[hidden] {        display: none;        opacity: 0;        translate: 0 .375rem;      }      @starting-style {        opacity: 0;        translate: 0 .375rem;      }      @media (prefers-reduced-motion: reduce) {        &[hidden] {          translate: none;        }        @starting-style {          translate: none;        }      }    }  }}@keyframes scroll-area-start {  from {    --scroll-area-start: 0px;  }  to {    --scroll-area-start: var(--scroll-area-fade);  }}@keyframes scroll-area-end {  from {    --scroll-area-end: var(--scroll-area-fade);  }  to {    --scroll-area-end: 0px;  }}