An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Respect floating panel transition timing https://github.com/siyuan-note/siyuan/issues/20833
Daniel33f42e3a9be1
diff --git a/app/src/layout/dock/barVisibility.ts b/app/src/layout/dock/barVisibility.tsindex cc2538a9be..c36e54121b 100644--- a/app/src/layout/dock/barVisibility.ts+++ b/app/src/layout/dock/barVisibility.ts@@ -34,11 +34,12 @@ const animateFloatingBar = (element: HTMLElement, from: number, to: number, closelement.classList.toggle("dock--closing", closing);element.inert = closing;effects.animations = [element, effects.backdrop].flatMap(target => [- target.animate([{transform: `translateX(${from}px)`}, {transform: `translateX(${to}px)`}], {- duration: 200, easing: "cubic-bezier(0, 0, .2, 1)", fill: "forwards",+ target.animate(panel ? [{transform: `translateX(${from}px)`}] :+ [{transform: `translateX(${from}px)`}, {transform: `translateX(${to}px)`}], {+ duration: panel ? 0 : 200, easing: "cubic-bezier(0, 0, .2, 1)", fill: "both",}),- target.animate([{opacity}, {opacity: closing ? "0" : "1"}], {- duration: 300, easing: "cubic-bezier(0, 0, .2, 1)", fill: "forwards",+ target.animate(panel ? [{opacity}] : [{opacity}, {opacity: closing ? "0" : "1"}], {+ duration: panel ? 0 : 300, easing: "cubic-bezier(0, 0, .2, 1)", fill: "both",}),]);const finish = () => {@@ -50,33 +51,49 @@ const animateFloatingBar = (element: HTMLElement, from: number, to: number, closeffects.animations = [];}};- effects.animations[effects.animations.length - 1].onfinish = finish;+ const finishAnimations = () => {+ const animations = effects.animations;+ // 位移与透明度可使用不同的时长和延迟;反向操作取消的动画不能清理新一轮动画。+ Promise.all(animations.map(animation => animation.finished)).then(() => {+ if (floatingBarEffects.get(element) === effects && effects.animations === animations) {+ finish();+ }+ }).catch(() => {+ // 取消动画时 finished 会拒绝,当前显隐状态由接替的动画负责。+ });+ };if (panel) {// 原生过渡在反向播放时会缩短时长,复制其关键帧和时间轴以保持边缘贴合。effects.frame = requestAnimationFrame(() => {const offset = (element.id === "dockLeft" ? -1 : 1) * element.clientWidth;- for (const source of panel.getAnimations()) {- if (!(source instanceof CSSTransition) || !["transform", "opacity"].includes(source.transitionProperty)) {- continue;- }- const transform = source.transitionProperty === "transform";- const frames = (source.effect as KeyframeEffect).getKeyframes().map(frame => ({+ const panelStyle = getComputedStyle(panel);+ const sources = panel.getAnimations();+ effects.animations.forEach(animation => animation.cancel());+ effects.animations = ["transform", "opacity"].flatMap(property => {+ const source = sources.find(animation => animation instanceof CSSTransition &&+ animation.transitionProperty === property);+ const transform = property === "transform";+ const frames = source ? (source.effect as KeyframeEffect).getKeyframes().map(frame => ({offset: frame.offset, easing: frame.easing,...(transform ? {transform: `translateX(${new DOMMatrixReadOnly(frame.transform as string).m41 + offset}px)`} :{opacity: frame.opacity}),- }));- [element, effects.backdrop].forEach((target, index) => {- const slot = index * 2 + (transform ? 0 : 1);- effects.animations[slot].cancel();- const animation = target.animate(frames, {...source.effect.getTiming(), fill: "forwards"});- if (typeof source.startTime === "number") {+ })) : [transform ? {transform: `translateX(${new DOMMatrixReadOnly(panelStyle.transform).m41 + offset}px)`} :+ {opacity: panelStyle.opacity}];+ // 无过渡的属性直接使用面板当前值;延迟开始的过渡也要保持起始帧。+ return [element, effects.backdrop].map(target => {+ const animation = target.animate(frames, {+ ...(source ? source.effect.getTiming() : {duration: 0}), fill: "both",+ });+ if (typeof source?.startTime === "number") {animation.startTime = source.startTime;}- effects.animations[slot] = animation;+ return animation;});- }- effects.animations[effects.animations.length - 1].onfinish = finish;+ });+ finishAnimations();});+ } else {+ finishAnimations();}};diff --git a/app/tests/dockBarVisibility.test.js b/app/tests/dockBarVisibility.test.jsindex 06417eb0f3..a77031df10 100644--- a/app/tests/dockBarVisibility.test.js+++ b/app/tests/dockBarVisibility.test.js@@ -6,7 +6,7 @@ const {test} = require("node:test");const {ModuleKind, ScriptTarget, transpileModule} = require("typescript");const sass = require("sass");-const browserCases = async (sources, css, template) => {+const browserCases = async (sources, css, template, animationOnly = false) => {const check = require("node:assert/strict");const load = (name, dependencies = {}) => {const exports = {};@@ -103,6 +103,80 @@ const browserCases = async (sources, css, template) => {check.equal(rightDockSpace(), reserved ? "var(--b3-ui-dock-width, 42px)" : "0px", message);};checkRightDockSpace("a hidden right bar reserves no space for fixed overlays");+ if (animationOnly) {+ const nextFrames = async () => {+ for (let index = 0; index < 3; index++) {+ await new Promise(resolve => requestAnimationFrame(resolve));+ }+ };+ for (const position of ["Left", "Right"]) {+ const dock = docks[position];+ const panel = dock.layout.element;+ const element = position === "Left" ? leftBar : rightBar;+ open(position);+ await settle();+ dock.hideDock();+ await settle();+ const checkAttached = (message) => {+ const panelRect = panel.getBoundingClientRect();+ const barRect = element.getBoundingClientRect();+ const gap = position === "Left" ? panelRect.left - barRect.right : barRect.left - panelRect.right;+ check.ok(Math.abs(gap) < 2, `${position} ${message}: gap=${gap}`);+ check.ok(Math.abs(Number(getComputedStyle(panel).opacity) - Number(getComputedStyle(element).opacity)) < .02,+ `${position} ${message}: opacity follows the panel`);+ check.deepEqual(rect(center.element), initialEditor, "custom animations do not resize the editor");+ };+ const finish = async () => {+ await Promise.all([...panel.getAnimations(), ...element.getAnimations()].map(animation => animation.finished));+ await nextFrames();+ };+ for (const transition of ["none", "transform 600ms linear, opacity 50ms linear",+ "transform 600ms linear", "opacity 300ms linear", "transform 350ms linear 120ms, opacity 50ms linear 120ms"]) {+ panel.style.transition = transition;+ dock.showDock();+ await nextFrames();+ checkAttached(`entry with ${transition}`);+ if (transition === "none") {+ check.equal(element.getAnimations().length, 0, "disabled panel transitions create no standalone bar animation");+ } else {+ await new Promise(resolve => setTimeout(resolve, 180));+ checkAttached(`entry after opacity completes with ${transition}`);+ }+ await finish();+ dock.hideDock();+ await nextFrames();+ if (transition === "none") {+ check.ok(hidden(element), "disabled transitions hide the bar without a trailing animation");+ } else {+ checkAttached(`exit with ${transition}`);+ await new Promise(resolve => setTimeout(resolve, 180));+ if (transition.startsWith("transform")) {+ check.ok(!hidden(element), "short opacity transitions do not end the longer transform");+ checkAttached(`exit after opacity completes with ${transition}`);+ }+ }+ await finish();+ check.ok(hidden(element), "all animations complete before the temporary bar is removed");+ }+ panel.style.transition = "transform 600ms linear, opacity 50ms linear";+ dock.showDock();+ await nextFrames();+ await new Promise(resolve => setTimeout(resolve, 160));+ dock.hideDock();+ await nextFrames();+ dock.showDock();+ await nextFrames();+ checkAttached("reversing custom transitions");+ await finish();+ check.ok(!hidden(element) && !element.inert, "canceled animations cannot clean up the reopened bar");+ dock.hideDock();+ await nextFrames();+ await finish();+ check.ok(hidden(element));+ panel.style.transition = "";+ }+ return "Floating dock bar cases passed";+ }const {windowMouseMove} = load("mousemove", dependencies);const move = event => windowMouseMove(event);document.addEventListener("mousemove", move);@@ -406,15 +480,16 @@ if (process.versions.electron && process.type === "browser") {.split('<div class="fn__flex-1 fn__flex">')[1].split('<div id="status"')[0];const html = '<div class="fn__flex-1 fn__flex">' + template;const styles = sass.compile(path.join(__dirname, "../src/assets/scss/base.scss"), {logger: sass.Logger.silent}).css;+ const animationOnly = process.env.SIYUAN_DOCK_ANIMATION_CASES === "1";for (const theme of ["daylight", "midnight"]) {const css = readFileSync(path.join(__dirname, `../appearance/themes/${theme}/theme.css`), "utf8") + styles;- for (const width of [1200, 700]) {- for (const hideToolbar of [false, true]) {+ for (const width of animationOnly ? [1200] : [1200, 700]) {+ for (const hideToolbar of animationOnly ? [false] : [false, true]) {captureName = `${theme}-${width}-${hideToolbar ? "hidden-toolbar" : "toolbar"}`;win.setContentSize(width, 800);await win.loadURL(`data:text/html,<html><body class='fn__flex-column${hideToolbar ? " body--toolbar-hide" : ""}'></body></html>`);const result = await win.webContents.executeJavaScript(`(${browserCases.toString()})(${[- sources, css, html,+ sources, css, html, animationOnly,].map(value => JSON.stringify(value)).join(",")})`);assert.equal(result, "Floating dock bar cases passed", captureName);}@@ -430,11 +505,8 @@ if (process.versions.electron && process.type === "browser") {}});} else {- test("floating dock bars preserve editor width and remain accessible when every panel is closed", {- skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,- timeout: 180000,- }, async () => {- const env = {...process.env};+ const runCases = async (animationOnly) => {+ const env = {...process.env, SIYUAN_DOCK_ANIMATION_CASES: animationOnly ? "1" : "0"};delete env.ELECTRON_RUN_AS_NODE;const profile = mkdtempSync(path.join(os.tmpdir(), "siyuan-dock-bar-"));try {@@ -446,5 +518,11 @@ if (process.versions.electron && process.type === "browser") {assert.ok(path.basename(profile).startsWith("siyuan-dock-bar-"));rmSync(profile, {recursive: true, force: true, maxRetries: 5, retryDelay: 100});}- });+ };+ const options = {+ skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,+ timeout: 180000,+ };+ test("floating dock bars follow disabled, partial, delayed and interrupted panel transitions", options, () => runCases(true));+ test("floating dock bars preserve editor width and remain accessible when every panel is closed", options, () => runCases(false));}