feat(tasks): 自动适配改为滑行——展开后仍保持自适应居中,且不再瞬跳
维护者第三轮反馈:在 fit(自适应)档位下展开后,画面也应回到自适应位置, 避免节点溢出面板 / 不在中间。上一版让折叠「接管视图」正是拿这个换的平滑。 收口方式:把视图变换本身也做成补间。 - 新增 tasks-view-glide.ts:把 fit 的算术抽成纯函数 fitTransform(用 CONTENT 盒而 非含 padding 的整张画布定缩放、双轴居中、容器未测量时返回 undefined),外加 lerpTransform 与 GLIDE_MS。这两块在 jsdom 里可达,因此有了单测(居中、上下限、 未测量、滑行中点)。 - TasksGraph:fit 拆成 fitTarget(算术)+ applyFit(animate)。布局变化且视图仍属自动 适配时→**滑行**(rAF 220ms,与卡片补间同一条缓动);切会话→直接落位(内容整体 换掉);⌂ / 背景双击→滑回。任何读者手势(pointerdown / 滚轮 / 缩放按钮)立刻取消 滑行,并照旧把视图标记为「已接管」。 - 折叠不再接管视图(去掉上一版的 markTouched 包装):展开即滑到新取景,画面保持 居中且内容完整。 测试:tests/tasks-view-glide.spec.ts(4 条:居中与缩放上限/下限、未测量返回 undefined、 滑行插值)与 tests/tasks-motion.spec.ts 第 4 条改写(布局变化必须滑行、切会话必须落位、 手势必须能取消)。全套 2252 passed / 17 skipped(194 文件)、tsc 与 eslint 零告警、 构建通过;新构建已装进 sidebar-test,:3080 挂载正常(0 pageerror)。
This commit is contained in:
1 parent
e6f9eda60f
commit
d035836a51
6 files changed
+254
-73
No files matched your search
@@ -71,14 +71,18 @@ describe('Tasks page motion', () => {
|
||||
expect(source('src/client/TasksGraph.tsx')).toContain('animationDelay')
|
||||
})
|
||||
|
||||
it('stops the auto-fit once the reader drives the fold state', () => {
|
||||
const graph = source('src/client/TasksGraph.tsx')
|
||||
// Pan/zoom already claim the view; folding claims it too, so the canvas
|
||||
// never re-frames itself under the cards the reader is watching.
|
||||
expect(graph).toContain('markTouched')
|
||||
expect(graph).toContain('expandGroupTouched')
|
||||
expect(graph).toContain('foldNodeTouched')
|
||||
expect(graph).toContain('toggleFoldTouched')
|
||||
it('keeps the frame auto-fitted across a fold, by GLIDING rather than jumping', () => {
|
||||
const graph = code('src/client/TasksGraph.tsx')
|
||||
// Folding must not claim the view: while the reader has not taken over, a
|
||||
// layout change glides the frame to the new fit, so an expanded group stays
|
||||
// centred and inside the panel without yanking the view.
|
||||
expect(graph).not.toContain('markTouched')
|
||||
// The untouched-view path GLIDES to the new framing; a fresh session snaps
|
||||
// (the content changes wholesale), and the reader's own gestures cancel a
|
||||
// glide in flight.
|
||||
expect(graph).toContain('if (!touchedRef.current) fitRef.current(true)')
|
||||
expect(graph).toContain('fitRef.current(false)')
|
||||
expect(graph).toContain('stopGlide()')
|
||||
})
|
||||
|
||||
it('parks the motion host behind a WAAPI guard so tests and old hosts stay inert', () => {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Unit tests for the canvas's auto-fit arithmetic and its glide — the two
|
||||
* pieces of the view transform that a jsdom test can reach (a container there
|
||||
* measures 0×0, so the graph's own `fit` cannot be exercised).
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
fitTransform, lerpTransform, type FitInput,
|
||||
} from '../src/client/tasks-view-glide.ts'
|
||||
|
||||
/** The graph's own fit inputs, centred on a small tree in a narrow panel. */
|
||||
function input(over: Partial<FitInput> = {}): FitInput {
|
||||
return {
|
||||
containerW: 360,
|
||||
containerH: 600,
|
||||
layoutW: 430,
|
||||
layoutH: 260,
|
||||
pad: 16,
|
||||
minContentW: 190,
|
||||
minContentH: 87,
|
||||
margin: 24,
|
||||
minScale: 0.78,
|
||||
maxScale: 1.3,
|
||||
...over,
|
||||
}
|
||||
}
|
||||
|
||||
describe('fitTransform', () => {
|
||||
it('scales to the CONTENT box and centres it on both axes', () => {
|
||||
const transform = fitTransform(input())
|
||||
expect(transform).toBeDefined()
|
||||
const { x, y, k } = transform!
|
||||
// Content = 430-32 × 260-32 = 398 × 228; the panel is 360 wide, so the
|
||||
// WIDTH is what limits the scale (the height would allow 2.4×).
|
||||
expect(k).toBeCloseTo((360 - 48) / 398, 6)
|
||||
expect(x).toBeCloseTo((360 - 398 * k) / 2 - 16 * k, 6)
|
||||
expect(y).toBeCloseTo(Math.max(12, (600 - 228 * k) / 2) - 16 * k, 6)
|
||||
// …and the content really is inside the panel and centred: equal margins.
|
||||
const leftEdge = x + 16 * k
|
||||
const rightEdge = x + 16 * k + 398 * k
|
||||
expect(360 - rightEdge).toBeCloseTo(leftEdge, 6)
|
||||
})
|
||||
|
||||
it('never balloons a small tree past the cap, and never shrinks below the floor', () => {
|
||||
expect(fitTransform(input({ layoutW: 200, layoutH: 100 }))?.k).toBe(1.3)
|
||||
expect(fitTransform(input({ layoutW: 4_000, layoutH: 4_000 }))?.k).toBe(0.78)
|
||||
})
|
||||
|
||||
it('answers nothing before the container has been measured', () => {
|
||||
// The sidebar mounts hidden at zero size: a fit then must not divide by it.
|
||||
expect(fitTransform(input({ containerW: 0 }))).toBeUndefined()
|
||||
expect(fitTransform(input({ containerH: 0 }))).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('lerpTransform', () => {
|
||||
it('walks the frame between two transforms', () => {
|
||||
const from = { x: 0, y: 0, k: 1 }
|
||||
const to = { x: 100, y: -40, k: 0.5 }
|
||||
expect(lerpTransform(from, to, 0)).toEqual(from)
|
||||
expect(lerpTransform(from, to, 1)).toEqual(to)
|
||||
expect(lerpTransform(from, to, 0.5)).toEqual({ x: 50, y: -20, k: 0.75 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user