diff --git a/src/components/timeline/interaction/interaction-controller.ts b/src/components/timeline/interaction/interaction-controller.ts index 30a2ec61..d9970cef 100644 --- a/src/components/timeline/interaction/interaction-controller.ts +++ b/src/components/timeline/interaction/interaction-controller.ts @@ -368,6 +368,8 @@ export class InteractionController implements TimelineInteractionRegistration { clipElement.style.height = `${clipRect.height}px`; clipElement.style.zIndex = "18"; clipElement.style.pointerEvents = "none"; + // A finger held still shows nothing else to say the clip was lifted + if (this.liftPoint) clipElement.classList.add("ss-clip--lifted"); // Create ghost as drop preview (shows where clip will land) const pps = this.stateManager.getViewport().pixelsPerSecond; @@ -645,6 +647,7 @@ export class InteractionController implements TimelineInteractionRegistration { } private setIdle(): void { + if (this.liftPoint && this.state.type === "dragging") this.state.clipElement.classList.remove("ss-clip--lifted"); this.state = IDLE_STATE; this.activePointerId = -1; this.activePointerType = ""; diff --git a/src/styles/timeline/timeline.css b/src/styles/timeline/timeline.css index 6ab5e7b8..ac0f0db1 100644 --- a/src/styles/timeline/timeline.css +++ b/src/styles/timeline/timeline.css @@ -734,6 +734,22 @@ .ss-clip.selected .ss-clip-content { padding-right: calc(var(--ss-touch-edge) + 24px); } + + /* Same specificity as .selected and .dragging, so it must stay after them to win */ + .ss-clip.ss-clip--lifted { + transform: scale(1.04); + outline: 2px solid var(--clip-border, #3b82f6); + box-shadow: + 0 10px 24px rgba(0, 0, 0, 0.28), + 0 2px 6px rgba(0, 0, 0, 0.2); + transition: transform 0.15s ease-out; + } +} + +@media (pointer: coarse) and (prefers-reduced-motion: reduce) { + .ss-clip.ss-clip--lifted { + transition: none; + } } /* Playhead */ diff --git a/tests/interaction-controller.test.ts b/tests/interaction-controller.test.ts index c4759b12..bbe7b917 100644 --- a/tests/interaction-controller.test.ts +++ b/tests/interaction-controller.test.ts @@ -1519,6 +1519,67 @@ describe("InteractionController", () => { jest.advanceTimersByTime(500); expect(controller.isDragging(0, 0)).toBe(false); }); + + describe("lifted look", () => { + const raised = (clip: Element) => clip.classList.contains("ss-clip--lifted"); + const lift = () => { + touch("pointerdown", 50, { target: firstClip() }); + jest.advanceTimersByTime(450); + }; + + it("raises the clip at 450 ms of a still touch, not at 449", () => { + touch("pointerdown", 50, { target: firstClip() }); + jest.advanceTimersByTime(449); + expect(raised(firstClip())).toBe(false); + + jest.advanceTimersByTime(1); + expect(raised(firstClip())).toBe(true); + }); + + it.each([ + ["a release", () => touch("pointerup", 50)], + ["pointercancel", () => touch("pointercancel", 50)], + ["a second pointer", () => touch("pointerdown", 300, { target: mockDOM.tracksContainer, pointerId: 2 })], + ["dispose", () => controller.dispose()] + ])("lowers it on %s", (_, end) => { + lift(); + end(); + expect(raised(firstClip())).toBe(false); + }); + + it("keeps it raised while dragged and lowers it when the drag commits", () => { + // Alone on its track, so the drag lands as a move + mockStateManager.setTestTracks([createMockTrack(0, [{ start: 0, length: 2 }])] as MockTrack[]); + lift(); + touch("pointermove", 150); + expect(raised(firstClip())).toBe(true); + + touch("pointerup", 150); + expect(mockEdit.executeEditCommand).toHaveBeenCalled(); + expect(raised(firstClip())).toBe(false); + }); + + it("lowers the element it raised after a re-render hands its place to another clip", () => { + lift(); + const [lifted, neighbour] = mockDOM.tracksContainer.querySelectorAll(".ss-clip"); + lifted.dataset["clipIndex"] = "1"; + neighbour.dataset["clipIndex"] = "0"; + touch("pointerup", 50); + + expect([lifted, neighbour].filter(raised)).toEqual([]); + }); + + it.each(["mouse", "pen"])("never raises a clip for a %s, held 600 ms or dragged", pointerType => { + firstClip().classList.add("selected"); + firstClip().dispatchEvent(createPointerEvent("pointerdown", { clientX: 50, clientY: 20, pointerType })); + jest.advanceTimersByTime(600); + expect(raised(firstClip())).toBe(false); + + document.dispatchEvent(createPointerEvent("pointermove", { clientX: 100, clientY: 20, pointerType })); + expect(controller.isDragging(0, 0)).toBe(true); + expect(raised(firstClip())).toBe(false); + }); + }); }); }); diff --git a/tests/touch-hit-areas.test.ts b/tests/touch-hit-areas.test.ts index bf73a99d..ad5fd698 100644 --- a/tests/touch-hit-areas.test.ts +++ b/tests/touch-hit-areas.test.ts @@ -144,3 +144,27 @@ describe("touch hit areas", () => { expect(declared(primaryCoarse, ".ss-clip-menu-trigger")["right"]).toBe("var(--ss-touch-edge)"); }); }); + +describe("lifted clip look", () => { + const lifted = (rules: Rule[]) => rules.filter(rule => rule.selector.includes("ss-clip--lifted")); + + it("styles a lifted clip only where the primary pointer is coarse", () => { + expect(lifted(primaryCoarse).length).toBeGreaterThan(0); + expect(lifted(rulesIn([styles]))).toEqual(lifted(primaryCoarse)); + }); + + it("animates only its scale, and not for reduced motion", () => { + const reduced = lifted(rulesIn(mediaBlocks(styles, "@media (pointer: coarse) and (prefers-reduced-motion: reduce)"))); + + expect(lifted(primaryCoarse)[0].declarations["transition"]).toMatch(/^transform [^,]+$/); + expect(reduced.map(rule => rule.declarations["transition"])).toEqual(["none"]); + }); + + it("comes after the selected and dragging rules, which share its specificity", () => { + const order = rulesIn([styles]).map(rule => rule.selector); + + expect(order.indexOf(".ss-clip.ss-clip--lifted")).toBeGreaterThan( + Math.max(order.lastIndexOf(".ss-clip.selected"), order.lastIndexOf(".ss-clip.dragging")) + ); + }); +});