Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 忙态 Spinner 报出正在做什么

longmeidao88bd58f1f94e
diff --git a/docs/reference-snapshots/vercel-geist-command-search-loading.md b/docs/reference-snapshots/vercel-geist-command-search-loading.md
index e20a828b0..e0b5ba660 100644
--- a/docs/reference-snapshots/vercel-geist-command-search-loading.md
+++ b/docs/reference-snapshots/vercel-geist-command-search-loading.md
@@ -3,15 +3,15 @@
> 本文是 Peach 的人工取证笔记,不在 `reference-sources.json` 里登记;同 id 来源的上游 Markdown 原文锁定在 `upstream/vercel-geist-command-menu.md`,`accept` 只覆盖那个文件。
-首次取证日期:2026-08-30;Button 补充复核:2026-09-01。
+首次取证日期:2026-08-30;Button 补充复核:2026-09-01;Spinner 与 Button 的 Best Practices 复核:2026-09-07。
## 锁定来源
- <https://vercel.com/geist/command-menu> HTML SHA-256:`0AC2CA5DBC1FC07E48700206C8E8EC21C447460C089D65CFC3324CAC9D0EC13E`
- <https://vercel.com/geist/search-input> HTML SHA-256:`55F62A034450EB68A4D2A46726A0A9A8CF806570C2E31162C6C869F4B38C21A2`
-- <https://vercel.com/geist/spinner> HTML SHA-256:`DD1B8A0742A6504D0E8852FAA61269C8720CB7C360B1B9FED6C9BF4C64772C60`
+- <https://vercel.com/geist/spinner> HTML SHA-256(2026-09-07):`8DCD5E6FE5A95A8499A1AA1EA38DCD6625F836AFB83F7073C47F6B92E376F84D`
- <https://vercel.com/geist/loading-dots> HTML SHA-256:`CB5548EF02D135DFA26DF1A9881F3E57E79F3F846C4DE3F3A94FB4AC4CEB8983`
-- <https://vercel.com/geist/button> HTML SHA-256:`29941BBD7F091FD7AA397466F243F62A420918C884255D499EFC29878D56DF99`
+- <https://vercel.com/geist/button> HTML SHA-256(2026-09-07):`8BDE0FC499385735A861F27193C55152F12215CFD2E235700B143205C7920576`
- 官方 CSS `1zsi1fomvr48z.css`:`62B3416EB6D73D86FCF284B5A9FD05A69DCBB091E3D79B6725EC83F0990E6ECE`
- 官方 CSS `328y7_b581oob.css`:`3034E6739AE0E19814DF6E53BA7FEBEFE56CF986ED0F1C3534DF9AEE1F751B87`
- 官方 CSS `3ej-07gndl9ds.css`:`587B35B6741B202EE2A7ACAFB4D2A9C6EA2A2819DA55BCF218634FA91A5617EE`
@@ -23,6 +23,10 @@
- Command Menu 是全屏覆盖层。官方 Dialog 打开时使用 `350ms cubic-bezier(.4,0,.2,1)`,内容从 `translate3d(0,-40px,0); opacity:0` 到原位;关闭反向,背景同步淡入淡出。
- Search Input 前缀是搜索图标。Peach 在请求期间原位替换为 Spinner,输入框几何不变。
- Spinner 用于用户直接触发且等待结果的动作,例如按钮与分页;容器声明 `aria-busy=true`,Spinner 自身为 `role=status`。
+- Spinner 的适用面写成三档具名场景:提交按钮、原位图标刷新(`inline icon refresh`)、行级重试,等待时长约一到三秒。图标键在忙时把自己的图标换成 Spinner 属于第二档,是官方做法。
+- 等待超过约一秒要配上说明这次在做什么的文案(`Verifying…`、`Deploying…`),让人知道被什么挡住。
+- Spinner 的尺寸对齐周围的字号或图标尺寸,不对齐父容器。
+- Spinner 只在动作开始之后挂载:预渲染再切换可见性会在静止时露出一段停住的转角,读成卡顿。
- Button 官方用 `loading` 表达请求中状态,明确要求触发器继续可聚焦并向辅助技术播报 busy;原生 `disabled` 只用于动作当前确实不可能执行的情况,而不是请求等待期。
- 官方 Spinner 由 10 根径向条组成,相隔 36°,持续 1000ms,延迟从 -900ms 到 0ms,透明度从 1 降至 .15。
- Loading Dots 用于仍在后台推进、总量未知的工作,不代替用户动作按钮的 Spinner。
@@ -35,4 +39,6 @@
- 检查、加载、保存、应用以及用户点下的“抓更早的一页”使用 Spinner;只有离开该按钮后仍在后台推进的资源扫描说明使用 Loading Dots。
- 原生页面没有 Geist React 的 `loading` prop,因此 `setActionBusy()` 同时写入 `aria-busy=true` 与 `aria-disabled=true`,全局拦截重复点击并降低饱和度/不透明度;不用原生 `disabled`,焦点留在触发器上。
- Peach 是原生 ES module,不引入 Geist React 运行时;共享实现位于 `web/js/ui-components.js`。
+- 「换一批」是 36px 的图标键,忙时把 shuffle 图标原位换成 16px Spinner,尺寸与图标一致。不给它另做一套「洗牌」动效:官方 Spinner 就是原位图标刷新这一档的做法,自研一份既没有取证也会让站内出现第二种忙态。
+- 图标键放不下进行中的文案,所以那句文案落在 Spinner 的 `aria-label` 上,写成进行中的说法(`正在换一批`)而不是按钮已有的名字;键上的 `title` 与`aria-label` 仍在,鼠标停住照样读得出这是哪一颗。
- “没有更多历史内容”是成功的终止状态,使用中性可关闭 Note,不使用红色 error Note。
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 9f179407f..dc92bfb70 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -1172,6 +1172,23 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains(prefix + "::-webkit-details-marker{display:none}")
self.assertPageContains(prefix + "{cursor:pointer;", "标题自己是 flex 容器")
+ def test_a_spinner_announces_the_work_and_not_the_button_it_sits_in(self):
+ """`spinnerHtml()` 的名字说正在做什么,不复读按钮自己的名字。
+
+ 这个 span 是 `role="status"`,装在一颗已经有可访问名的按钮里。传按钮名进去,
+ 屏幕阅读器就把同一串词念两遍——「换一批」「换一批」——读的人听不出发生了变化。
+ Geist 的 Spinner 规格把这一条写成「等待超过约 1 秒要配上说明这次在做什么的
+ 文案」,所以判据是动词形态:进行中的说法,不是动作的名字。
+ """
+ source = (Path(__file__).resolve().parents[1] / "web/app.js").read_text(
+ encoding="utf-8")
+ labels = re.findall(r"spinnerHtml\('([^']+)'\)", source)
+ self.assertGreaterEqual(len(labels), 10, "调用点少得不像全站都在用")
+ ongoing = ("正在", "中", "…")
+ for label in labels:
+ self.assertTrue(label.endswith(ongoing) or label.startswith("正在"),
+ f"「{label}」是动作名,不是进行中的说法")
+
def test_font_weights_stay_on_the_three_geist_steps(self):
"""字重只有 400/500/600 三档。
diff --git a/web/app.js b/web/app.js
index 76b6e9b8c..c7e125923 100644
--- a/web/app.js
+++ b/web/app.js
@@ -194,7 +194,7 @@ function wireCountRow(){
const batch=$('#batchAction');
if(batch)batch.onclick=async()=>{
if(batch.getAttribute('aria-busy')==='true')return;
- const old=batch.innerHTML;setActionBusy(batch);batch.innerHTML=spinnerHtml('换一批');
+ const old=batch.innerHTML;setActionBusy(batch);batch.innerHTML=spinnerHtml('正在换一批');
try{await refreshAll()}finally{setActionBusy(batch,false);batch.innerHTML=old}
};
wireJavLayoutButtons($('#count'));
@@ -4549,7 +4549,7 @@ async function loadMoreFollow(button){
if(!followData||followBusy)return;
followBusy=true;
const oldButton=button?.innerHTML;
- if(button){setActionBusy(button);button.innerHTML=`${spinnerHtml('加载更多')}<span>加载中…</span>`}
+ if(button){setActionBusy(button);button.innerHTML=`${spinnerHtml('正在加载更多')}<span>加载中…</span>`}
try{
const next=await api(followPageUrl((followData.offset||0)+FOLLOW_PAGE));
followData={...next,
diff --git a/web/js/ui-components.js b/web/js/ui-components.js
index 3fe1d1f78..d7376b141 100644
--- a/web/js/ui-components.js
+++ b/web/js/ui-components.js
@@ -70,7 +70,16 @@ export function progressHtml(label,value,max=100,{variant='active',stops=[]}={})
style="--progress-value:${percent}%;--progress-color:var(${variant==='error'?'--drop':variant==='warning'?'--meter':'--feedback-success'})"><i></i>${stops.filter(stop=>Number(stop.value)>0&&Number(stop.value)<ceiling&&stop.label).map(stop=>`<span class="geist-progress-stop" style="left:${Number(stop.value)/ceiling*100}%" role="img" aria-label="${esc(stop.label)}"></span>`).join('')}</div>`;
}
-/** Geist Spinner: immediate feedback for a user-triggered action. */
+/**
+ * Geist Spinner: immediate feedback for a user-triggered action. Geist names
+ * "inline icon refresh" as one of its three cases, so an icon-only key that
+ * swaps its glyph for these ten bars is the prescribed shape, not a fallback.
+ *
+ * `label` names the work in flight (`正在换一批`), never the action the button
+ * already carries. This span is a `role=status` region sitting inside a button
+ * that has its own accessible name: repeating that name announces the same
+ * words twice and tells the reader nothing changed.
+ */
export function spinnerHtml(label='加载中'){
const bars=Array.from({length:10},(_,index)=>
`<i aria-hidden="true" style="--spinner-angle:${index*36}deg;--spinner-delay:${index*100-900}ms"></i>`).join('');