From 92aef441d4dbbb3fdcc8dd0d3541175e9126aa95 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 29 Sep 2026 01:38:38 +0800 Subject: [PATCH] =?UTF-8?q?providers:=20=E6=B7=BB=E5=8A=A0=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86=20scrolls=20down=20to=20the=20sheet=20on=20t?= =?UTF-8?q?he=20first=20click,=20and=20the=20sheet=20unrolls=20with=20the?= =?UTF-8?q?=20view=20going=20down=20along=20with=20it=20(=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E7=82=B9=E5=87=BB=E6=B7=BB=E5=8A=A0=E4=BE=9B?= =?UTF-8?q?=E5=BA=94=E5=95=86=E2=80=A6=E5=B9=B6=E4=B8=8D=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=90=91=E4=B8=8B=E6=BB=9A=E5=8A=A8=EF=BC=8C=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E6=89=8D=E4=BC=9A=EF=BC=9B=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E8=B7=9F=E5=B1=95=E5=BC=80=E9=83=BD=E6=B2=A1=E6=9C=89=E4=B8=9D?= =?UTF-8?q?=E6=BB=91=E7=9A=84=E5=8A=A8=E7=94=BB)=20=E2=80=94=20the=20view'?= =?UTF-8?q?s=20guard=20against=20scrolls=20nobody=20asked=20for=20(backToR?= =?UTF-8?q?eader)=20put=20back=20the=20smooth=20scrollIntoView=20the=20but?= =?UTF-8?q?ton=20started,=20as=20it=20never=20said=20scrollOnPurpose;=20it?= =?UTF-8?q?=20only=20got=20through=20when=20something=20else=20happened=20?= =?UTF-8?q?to=20have.=20Now=20the=20button=20says=20so,=20and=20the=20shee?= =?UTF-8?q?t=20opens=20from=20nothing=20to=20its=20height=20on=20the=20row?= =?UTF-8?q?s'=20spring=20(ROW=5FOPEN),=20its=20head=20and=20tiles=20easing?= =?UTF-8?q?=20down=20into=20place,=20while=20the=20view's=20scrollTop=20is?= =?UTF-8?q?=20set=20frame=20by=20frame=20from=20the=20sheet's=20height:=20?= =?UTF-8?q?from=20when=20the=20sheet=20reaches=20the=20view's=20foot=20to?= =?UTF-8?q?=20when=20it=20is=20whole,=20into=20room=20the=20sheet=20has=20?= =?UTF-8?q?made,=20so=20it=20neither=20jumps=20nor=20stops=20short,=20unti?= =?UTF-8?q?l=20the=20sheet's=20top=20is=2012px=20under=20the=20view's=20?= =?UTF-8?q?=E2=80=94=20scrollTop=20set=20directly,=20which=20WebKit=20anim?= =?UTF-8?q?ates=20where=20a=20smooth=20scrollIntoView=20may=20not.=20Scrol?= =?UTF-8?q?ling=20meanwhile=20hands=20the=20view=20back=20to=20the=20reade?= =?UTF-8?q?r.=20=E5=85=B3=E9=97=AD=20rolls=20it=20up=20the=20other=20way?= =?UTF-8?q?=20before=20it=20is=20hidden.=20Reduced=20motion=20jumps=20ther?= =?UTF-8?q?e=20as=20before.=20Checked=20in=20a=20sandbox=20HOME=20with=20s?= =?UTF-8?q?ix=20providers=20in=20headless=20Chrome:=20on=20the=20first=20c?= =?UTF-8?q?lick=20scrollTop=20went=200=20=E2=86=92=20301=20over=20~550=20m?= =?UTF-8?q?s=20along=20with=20the=20height=20(0=20=E2=86=92=20868),=20no?= =?UTF-8?q?=20jump;=20closed=20and=20reopened=20the=20same;=20reduced=20mo?= =?UTF-8?q?tion=20lands=20at=20301=20with=20no=20animation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.js | 63 +++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index a1a63a647..f0779f032 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -2102,7 +2102,7 @@ function renderAdd() { head.append(imp); if (providers.providers.length) { const x = el("button", "text", t("Close")); - x.onclick = () => { adding = false; editing = null; draft = null; presetQuery = ""; renderProviders(); }; + x.onclick = () => rollUpSheet(sheet, () => { adding = false; editing = null; draft = null; presetQuery = ""; renderProviders(); }); head.append(x); } sheet.append(head); @@ -4247,13 +4247,68 @@ function editorError(msg, kind = "err") { function slug(s) { return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""); } function hostOf(u) { try { return new URL(u.includes("://") ? u : "https://" + u).host; } catch { return ""; } } -// the sheet opens below the list: the view goes down to its top with it +// the sheet opens below the list: it unrolls on the rows' spring and the +// view goes down with it $("#addProvider").onclick = () => { adding = true; editing = null; draft = null; renderProviders(); - const smooth = !matchMedia("(prefers-reduced-motion: reduce)").matches; - requestAnimationFrame(() => $("#addSheet").scrollIntoView({ behavior: smooth ? "smooth" : "auto", block: "start" })); + unrollSheet($("#view-providers"), $("#addSheet")); }; +// unrollSheet opens a sheet just drawn at the foot of a view from nothing to +// its height, what's in it easing down into place, and takes the view down +// with it until the sheet's top is 12px under the view's. The scroll is led +// by the height, frame by frame, from when the sheet reaches the view's foot +// to when it is whole: it scrolls only into room the sheet has made, so it +// never runs ahead to be held back and jump, nor stops short; and it is +// the view's own scrollTop, which WebKit animates where it won't a smooth +// scrollIntoView. The reader scrolling meanwhile has the view from then on. +function unrollSheet(view, sheet) { + const from = view.scrollTop, room = view.scrollHeight - view.clientHeight; + const to = Math.max(from, Math.min(from + sheet.getBoundingClientRect().top - view.getBoundingClientRect().top - 12, room)); + const h = sheet.offsetHeight; + // how tall the sheet is when it reaches the view's foot, where the view + // can start to move: from there the view goes down as it grows + const x0 = Math.max(0, h - (room - from)); + scrollOnPurpose(ROW_OPEN.ms + 300); + if (!h || matchMedia("(prefers-reduced-motion: reduce)").matches) { view.scrollTop = to; return; } + const pad = getComputedStyle(sheet); + sheet.style.overflow = "hidden"; + const grow = sheet.animate([ + { height: "0px", paddingTop: "0px", paddingBottom: "0px" }, + { height: h + "px", paddingTop: pad.paddingTop, paddingBottom: pad.paddingBottom }, + ], { duration: ROW_OPEN.ms + 60, easing: `cubic-bezier(${ROW_OPEN.ease})` }); + for (const c of sheet.children) { + c.animate([{ opacity: 0, transform: "translateY(-6px)" }, { opacity: 1, transform: "none" }], + { duration: 340, delay: 60, easing: "cubic-bezier(.22, 1, .36, 1)", fill: "backwards" }); + } + let set = from; + const follow = () => { + if (Math.abs(view.scrollTop - set) > 2) return; // the reader took it + const done = grow.playState === "finished"; + view.scrollTop = Math.round(from + (to - from) * (done ? 1 : Math.min(1, Math.max(0, sheet.offsetHeight - x0) / (h - x0)))); + set = view.scrollTop; // as far as there was room for + if (!done) requestAnimationFrame(follow); + }; + const end = () => { sheet.style.overflow = ""; }; + grow.finished.then(() => { end(); follow(); }, end); + requestAnimationFrame(follow); +} + +// rollUpSheet closes it the other way, quicker, and then does what closing +// it does. +function rollUpSheet(sheet, then) { + if (matchMedia("(prefers-reduced-motion: reduce)").matches) return then(); + const pad = getComputedStyle(sheet); + sheet.style.overflow = "hidden"; + const a = sheet.animate([ + { height: sheet.offsetHeight + "px", paddingTop: pad.paddingTop, paddingBottom: pad.paddingBottom, opacity: 1 }, + { height: "0px", paddingTop: "0px", paddingBottom: "0px", opacity: 0 }, + ], { duration: ROLLUP.ms - 80, easing: `cubic-bezier(${ROLLUP.ease})`, fill: "forwards" }); + // held shut until it is hidden, then let go, so it is never seen whole again + const done = () => { then(); a.cancel(); sheet.style.overflow = ""; }; + a.finished.then(done, done); +} + // ---------- usage ---------- const PERIODS = [["today", "Today"], ["7d", "7 days"], ["30d", "30 days"], ["all", "All"]];