An open source design system that's fully customizable and agent ready
TypeScript
fix(core): a press inside a scroll view highlights 150 ms after touch (#10260)
Christopher Chedeau6cbcbf846bc9
diff --git a/.changeset/press-onset-from-touch.md b/.changeset/press-onset-from-touch.mdnew file mode 100644index 0000000000..c81a76f993--- /dev/null+++ b/.changeset/press-onset-from-touch.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Inside a scroll view, a pressable's highlight now comes 150 ms after the touch, even when a busy page handles the touch late. Before, the wait started when the page handled the touch, so the highlight came late by that delay. This covers every pressable, and SegmentedControl, Switch, Slider and `usePressTracker` controls, in a scroll view.++@vjeuxdiff --git a/packages/core/src/Button/__tests__/ButtonPress.interaction.browser.spec.ts b/packages/core/src/Button/__tests__/ButtonPress.interaction.browser.spec.tsindex 3d8f9a8c62..97ce58fbb5 100644--- a/packages/core/src/Button/__tests__/ButtonPress.interaction.browser.spec.ts+++ b/packages/core/src/Button/__tests__/ButtonPress.interaction.browser.spec.ts@@ -66,7 +66,13 @@ interface Opened {log: () => Promise<LogEntry[]>;}-type LogEntry = [kind: string, t: number, value: string | null];+/** A pointer entry also carries the event's own time (its `timeStamp`). */+type LogEntry = [+ kind: string,+ t: number,+ value: string | null,+ eventTime?: number,+];async function openSurface(page: Page,@@ -87,7 +93,7 @@ async function openSurface(for (const type of ['pointerdown', 'pointerup', 'pointercancel', 'click']) {document.addEventListener(type,- () => entries.push([type, performance.now(), null]),+ event => entries.push([type, performance.now(), null, event.timeStamp]),true,);}@@ -167,8 +173,11 @@ test('inside a scroller, a held press waits UIScrollView’s content-touch delayif (!down || !on) {return;}- expect(on[1] - down[1]).toBeGreaterThanOrEqual(CONTENT_TOUCH_DELAY_MS - 5);- expect(on[1] - down[1]).toBeLessThan(CONTENT_TOUCH_DELAY_MS + 60);+ // The delay counts from the touch's own time, not from the moment a busy+ // page runs its listener.+ const touchedAt = down[3] ?? down[1];+ expect(on[1] - touchedAt).toBeGreaterThanOrEqual(CONTENT_TOUCH_DELAY_MS - 5);+ expect(on[1] - touchedAt).toBeLessThan(CONTENT_TOUCH_DELAY_MS + 60);// WebKit synthesises a click only from its own tap path, not from a raw// touch sequence (harness README, engine limits); Chromium does from both.if (opened.driver.engine === 'chromium') {diff --git a/packages/core/src/gestures/PressTracker.ts b/packages/core/src/gestures/PressTracker.tsindex c208f63c00..69e1dccb51 100644--- a/packages/core/src/gestures/PressTracker.ts+++ b/packages/core/src/gestures/PressTracker.ts@@ -14,9 +14,9 @@* UIControl semantics, event for event:** - `touchDown` when the finger lands; the highlight comes on in the same- * frame, unless the control sits in a scroller, where it waits- * `contentTouchDelay` (UIScrollView.delaysContentTouches) so a flick- * paints nothing.+ * frame, unless the control sits in a scroller. There it waits+ * `contentTouchDelay` (UIScrollView.delaysContentTouches) from the touch's+ * own time, so a flick paints nothing.* - `touchDragInside` / `touchDragOutside` on every move, `touchDragExit` /* `touchDragEnter` when the finger crosses the control's bounds EXPANDED* by `trackingExpansion` (a fingertip dragged a little off a button is@@ -49,6 +49,7 @@import {UIKIT_CONTROL, UIKIT_PAN, UIKIT_PRESS} from '../motion/uikit/gestures';// Importing the whole table bundles its curves into each press-tracking control.import {press as pressClocks} from '../motion/uikit/timing';+import {msSinceInput} from '../utils/inputAge';import {travel} from './geometry';import type {GestureRecognizer, SelectionLock} from './GestureRecognizer';import type {TapGestureRecognizer} from './TapGestureRecognizer';@@ -345,12 +346,20 @@ export function createPressTracker(options: PressTrackerOptions): PressTracker {(delay === 'always' ||(delay === 'inScrollers' && touch.scroll?.isInsideScroller === true));if (delays) {+ // The delay counts from the touch, so the time a busy main thread+ // took to deliver it comes off the wait. The touch's time is on the+ // clock of its own window, which can be an iframe's.+ const wait = Math.max(+ 0,+ PRESS.contentTouchDelay.value -+ msSinceInput(touch.time, touch.target),+ );highlightTimer = setTimeout(() => {highlightTimer = null;if (state.isTouchInside) {setHighlighted(true);}- }, PRESS.contentTouchDelay.value);+ }, wait);} else {setHighlighted(true);}diff --git a/packages/core/src/gestures/__tests__/PressTracker.test.ts b/packages/core/src/gestures/__tests__/PressTracker.test.tsindex 9b09d6276c..fe91d45d6e 100644--- a/packages/core/src/gestures/__tests__/PressTracker.test.ts+++ b/packages/core/src/gestures/__tests__/PressTracker.test.ts@@ -130,6 +130,46 @@ describe('PressTracker', () => {expect(highlights).toEqual([true, false, true, false]);});+ it("counts the content-touch delay from the touch's own time, so a touch delivered late still highlights on time", () => {+ const {highlights, tracker, h} = setup();+ const probe = scrollProbe(() => true, true);+ // The page has run a while, so the touch's time is past zero.+ vi.advanceTimersByTime(1000);+ // A busy main thread delivers the touch 60 ms after it happened.+ h.finger(1).down(150, 120, performance.now() - 60, {+ recognizers: [],+ consumer: tracker,+ scroll: probe,+ });+ vi.advanceTimersByTime(DELAY - 60 - 1);+ expect(highlights).toEqual([]);+ vi.advanceTimersByTime(1);+ expect(highlights).toEqual([true]);+ });++ it("reads a touch's time on the clock of its own window, as an iframe's touch carries", () => {+ const {highlights, tracker, h} = setup();+ const probe = scrollProbe(() => true, true);+ vi.advanceTimersByTime(1000);+ // The iframe's clock started 900 ms after this window's.+ const frameClock = {now: () => performance.now() - 900};+ const target = {+ nodeType: 1,+ ownerDocument: {defaultView: {performance: frameClock}},+ };+ // A busy main thread delivers the touch 60 ms after it happened.+ h.finger(1).down(150, 120, frameClock.now() - 60, {+ recognizers: [],+ consumer: tracker,+ scroll: probe,+ target,+ });+ vi.advanceTimersByTime(DELAY - 60 - 1);+ expect(highlights).toEqual([]);+ vi.advanceTimersByTime(1);+ expect(highlights).toEqual([true]);+ });+it('waits the content-touch delay inside a scroller, and flashes a quicker tap', () => {const {highlights, tracker, h} = setup();const probe = scrollProbe(() => true, true);diff --git a/packages/core/src/gestures/__tests__/browser/bareFixture.ts b/packages/core/src/gestures/__tests__/browser/bareFixture.tsindex 435ef316c6..4be38dcee2 100644--- a/packages/core/src/gestures/__tests__/browser/bareFixture.ts+++ b/packages/core/src/gestures/__tests__/browser/bareFixture.ts@@ -5,9 +5,9 @@* @input Nothing: bundled by esbuild and injected into a blank page* @output A page with nothing attached. `window.__api` holds the document's* gesture host and the host lookup for another document. It also holds- * the recognizers (pan, screen-edge pan, tap, long press), for a test to- * attach what it needs. `window.__pageTouch` is the count of touch- * listeners on the window and the document right now.+ * the recognizers (pan, screen-edge pan, tap, long press) and the press+ * tracker, for a test to attach what it needs. `window.__pageTouch` is+ * the count of touch listeners on the window and the document right now.* @position Browser fixture of gestures.interaction.browser.spec.ts for the* checks that need a page with no other gesture on it (FR19, FR24);* test-only@@ -17,6 +17,7 @@ import {getGestureHost} from '../../GestureHost';import {LongPressGestureRecognizer} from '../../LongPressGestureRecognizer';import {PanGestureRecognizer} from '../../PanGestureRecognizer';import {PinchGestureRecognizer} from '../../PinchGestureRecognizer';+import {createPressTracker} from '../../PressTracker';import {ScreenEdgePanGestureRecognizer} from '../../ScreenEdgePanGestureRecognizer';import {lockSelection} from '../../../utils/selectionLock';import {TapGestureRecognizer} from '../../TapGestureRecognizer';@@ -33,6 +34,7 @@ declare global {PinchGestureRecognizer: typeof PinchGestureRecognizer;ScreenEdgePanGestureRecognizer: typeof ScreenEdgePanGestureRecognizer;TapGestureRecognizer: typeof TapGestureRecognizer;+ createPressTracker: typeof createPressTracker;lockSelection: typeof lockSelection;};}@@ -102,5 +104,6 @@ window.__api = {PinchGestureRecognizer,ScreenEdgePanGestureRecognizer,TapGestureRecognizer,+ createPressTracker,lockSelection,};diff --git a/packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts b/packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.tsindex 0d76254d0c..68f0aff72b 100644--- a/packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts+++ b/packages/core/src/gestures/__tests__/browser/gestures.interaction.browser.spec.ts@@ -3201,3 +3201,76 @@ test('a pan on an element the page moves into a same-origin iframe keeps its touexpect(states).toContain('changed');expect(states.slice(-2)).toEqual(['ended', 'possible']);});++test("a press in a same-origin iframe's scroll view waits the content-touch delay from the touch, on that window's clock (spec:AST-094 FR11)", async ({+ page,+ browserName,+}) => {+ const driver = await openBare(page, browserName);+ // An iframe's clock starts when its document does, after the page's. Its+ // touches carry times on that clock.+ const {clockGap, ...start} = await page.evaluate(async () => {+ // The iframe opens well after the page, as a popup or a late iframe does.+ await new Promise(resolve => {+ setTimeout(resolve, Math.max(0, 400 - performance.now()));+ });+ const frame = document.createElement('iframe');+ frame.style.cssText =+ 'position: absolute; left: 0; top: 0; width: 320px; height: 480px; border: 0';+ document.body.append(frame);+ const doc = frame.contentDocument as Document;+ const view = doc.defaultView as Window;+ doc.body.style.margin = '0';+ doc.body.innerHTML =+ '<div style="height: 300px; overflow-y: auto"><div id="row" style="height: 80px; background: #ddd"></div><div style="height: 900px"></div></div>';+ const row = doc.getElementById('row') as HTMLElement;+ const times: {touch?: number; handled?: number; highlight?: number} = {};+ (window as unknown as {__frameTimes: typeof times}).__frameTimes = times;+ doc.addEventListener(+ 'touchstart',+ event => {+ times.touch = event.timeStamp;+ times.handled = view.performance.now();+ },+ {capture: true},+ );+ const {getGestureHost, createPressTracker} = window.__api;+ const tracker = createPressTracker({+ getBounds: () => row.getBoundingClientRect(),+ onHighlightChange: isHighlighted => {+ if (isHighlighted && times.highlight == null) {+ times.highlight = view.performance.now();+ }+ },+ });+ getGestureHost(doc).attachConsumer(row, tracker);+ const box = row.getBoundingClientRect();+ return {+ x: box.left + box.width / 2,+ y: box.top + box.height / 2,+ clockGap: view.performance.timeOrigin - performance.timeOrigin,+ };+ });+ // The case needs the clocks apart: an age read on the page's clock then+ // cuts the wait short.+ expect(clockGap).toBeGreaterThan(150);+ await driver.play([{t: 0, down: [{...start, id: 1}]}]);+ await page.waitForFunction(+ () =>+ (window as unknown as {__frameTimes: {highlight?: number}}).__frameTimes+ .highlight != null,+ );+ await driver.play([{t: 0, down: []}]);+ const times = await page.evaluate(+ () =>+ (+ window as unknown as {+ __frameTimes: {touch: number; handled: number; highlight: number};+ }+ ).__frameTimes,+ );+ // The wait counts from the touch. Chromium's driver stamps a touch ahead of+ // its delivery, and a time ahead of now counts as now.+ const touchedAt = Math.min(times.touch, times.handled);+ expect(times.highlight - touchedAt).toBeGreaterThanOrEqual(145);+});diff --git a/packages/core/src/hooks/longPressDetector.ts b/packages/core/src/hooks/longPressDetector.tsindex 868baf2530..0f67fcb968 100644--- a/packages/core/src/hooks/longPressDetector.ts+++ b/packages/core/src/hooks/longPressDetector.ts@@ -16,6 +16,7 @@ import {LONG_PRESS_ALLOWABLE_MOVEMENT_PX,LONG_PRESS_DURATION_MS,} from '../motion/uikit/longPress';+import {clockOf, timeOn, type EventClock} from '../utils/inputAge';import {claimPress} from '../utils/pressClaim';// The hold is a deadline on the touch events' timestamps, on the clock of the@@ -90,41 +91,6 @@ export interface LongPressDetector {setOptions: (options: LongPressDetectorOptions) => void;}-/** The part of a window's performance timeline a press reads. */-type EventClock = Pick<Performance, 'now'>;--function clockOf(event: LongPressTouchEvent): EventClock | null {- const view = event.view as {performance?: EventClock} | null | undefined;- return (- view?.performance ??- (typeof performance === 'undefined' ? null : performance)- );-}--/**- * An event's time on its window's clock. jsdom stamps events with- * `Date.now()`. The detector reads the age of such a stamp on that clock, so a- * frozen system time keeps the hold's length. A stamp nearer `Date.now()` than- * the window's clock is that kind of stamp.- */-function timeOn(- clock: EventClock | null,- timeStamp: number | undefined,-): number | undefined {- // A stamp of 0 means the event carries no time, so the hold falls back to- // the full delay on the page's timer.- if (timeStamp == null || !Number.isFinite(timeStamp) || timeStamp <= 0) {- return undefined;- }- if (- clock != null &&- Math.abs(Date.now() - timeStamp) < Math.abs(clock.now() - timeStamp)- ) {- return clock.now() - (Date.now() - timeStamp);- }- return timeStamp;-}-/** @internal A long-press detector with no React (see LongPressDetector). */export function createLongPressDetector(initial: LongPressDetectorOptions,diff --git a/packages/core/src/utils/inputAge.test.ts b/packages/core/src/utils/inputAge.test.tsnew file mode 100644index 0000000000..3753e165de--- /dev/null+++ b/packages/core/src/utils/inputAge.test.ts@@ -0,0 +1,74 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file inputAge.test.ts+ * @input inputAge.ts+ * @output Unit tests for msSinceInput: an input's age on its window's clock,+ * an epoch stamp's age, and zero for no time or a future one+ * @position Testing; validates inputAge.ts+ */++import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';+import {createLongPressDetector} from '../hooks/longPressDetector';+import {msSinceInput} from './inputAge';++describe('msSinceInput', () => {+ beforeEach(() => {+ vi.useFakeTimers();+ // The page has run a while, so an input's time is past zero.+ vi.advanceTimersByTime(1000);+ });+ afterEach(() => {+ vi.useRealTimers();+ });++ it("is the input's age when its time is on the page's clock", () => {+ expect(msSinceInput(performance.now() - 60)).toBe(60);+ expect(msSinceInput(performance.now())).toBe(0);+ });++ it('is zero for an input with no time, or a time ahead of now', () => {+ expect(msSinceInput(0)).toBe(0);+ expect(msSinceInput(Number.NaN)).toBe(0);+ expect(msSinceInput(performance.now() + 500)).toBe(0);+ });++ it('keeps the age of an epoch stamp, as jsdom stamps an event', () => {+ expect(msSinceInput(Date.now() - 60)).toBe(60);+ expect(msSinceInput(Date.now())).toBe(0);+ });++ it("reads the clock of the window the input landed in, as an iframe's", () => {+ // The iframe's clock reads 5000 while this window's reads about 1000.+ const frame = {performance: {now: () => 5000}};+ const element = {nodeType: 1, ownerDocument: {defaultView: frame}};+ const frameDocument = {nodeType: 9, defaultView: frame};+ const event = {view: frame};+ expect(msSinceInput(4940, element)).toBe(60);+ expect(msSinceInput(4940, frameDocument)).toBe(60);+ expect(msSinceInput(4940, event)).toBe(60);+ // On this window's clock, that time is ahead of now.+ expect(msSinceInput(4940)).toBe(0);+ });++ it('reads a 60 ms-old epoch stamp as 60 ms old for both the press onset and the long-press hold', () => {+ // A window clock that reads 1000 now and moves with the system time.+ const offset = 1000 - Date.now();+ const view = {performance: {now: () => Date.now() + offset}};+ const stamp = Date.now() - 60;+ const event = {touches: [{clientX: 0, clientY: 0}], timeStamp: stamp, view};+ expect(msSinceInput(stamp, event)).toBe(60);+ const onLongPress = vi.fn();+ createLongPressDetector({onLongPress, delayMs: 500}).touchStart(event);+ vi.advanceTimersByTime(500 - 60 - 1);+ expect(onLongPress).not.toHaveBeenCalled();+ vi.advanceTimersByTime(1);+ expect(onLongPress).toHaveBeenCalledTimes(1);+ });++ it("reads this window's clock for a target with no window", () => {+ const detached = {nodeType: 1, ownerDocument: {defaultView: null}};+ expect(msSinceInput(performance.now() - 60, detached)).toBe(60);+ expect(msSinceInput(performance.now() - 60, {})).toBe(60);+ });+});diff --git a/packages/core/src/utils/inputAge.ts b/packages/core/src/utils/inputAge.tsnew file mode 100644index 0000000000..52a65c7743--- /dev/null+++ b/packages/core/src/utils/inputAge.ts@@ -0,0 +1,66 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file inputAge.ts+ * @input An input's time stamp, and its event or the node it landed on+ * @output clockOf, timeOn and msSinceInput: the clock of the window that+ * stamped an input, its time on that clock, and how long ago it happened+ * @position Internal utility. The content-touch delay (utils/pressFeedback.ts,+ * gestures/PressTracker.ts) and the long-press hold+ * (hooks/longPressDetector.ts) count from the touch with it.+ */++import {isDocument, isNode} from './nodeType';++/** The part of a window's performance timeline an input's age reads. */+export type EventClock = Pick<Performance, 'now'>;++/**+ * The clock of the window that stamped an input: an event's `view`, or the+ * window of the node it landed on. A same-origin iframe's clock or a popup's+ * starts later than the page's. With neither, the clock is this window's.+ */+export function clockOf(source: unknown): EventClock | null {+ const view = isNode(source)+ ? (isDocument(source) ? source : source.ownerDocument)?.defaultView+ : (source as {view?: unknown} | null | undefined)?.view;+ return (+ (view as {performance?: EventClock} | null | undefined)?.performance ??+ (typeof performance === 'undefined' ? null : performance)+ );+}++/**+ * An event's time on its window's clock. jsdom stamps events with+ * `Date.now()`. Such a stamp keeps its age on that clock, so a frozen system+ * time keeps a delay's length. A stamp nearer `Date.now()` than the window's+ * clock is that kind of stamp.+ */+export function timeOn(+ clock: EventClock | null,+ timeStamp: number | undefined,+): number | undefined {+ // A stamp of 0 means the event carries no time, so a delay falls back to+ // its full length on the page's timer.+ if (timeStamp == null || !Number.isFinite(timeStamp) || timeStamp <= 0) {+ return undefined;+ }+ if (+ clock != null &&+ Math.abs(Date.now() - timeStamp) < Math.abs(clock.now() - timeStamp)+ ) {+ return clock.now() - (Date.now() - timeStamp);+ }+ return timeStamp;+}++/**+ * How long ago the input stamped `time` happened, on the clock of the window+ * that stamped it (`clockOf(source)`). A busy main thread runs a listener+ * late. An input with no time, or a time ahead of now, counts as now.+ */+export function msSinceInput(time: number, source?: unknown): number {+ const clock = clockOf(source);+ const at = timeOn(clock, time);+ return clock == null || at == null ? 0 : Math.max(0, clock.now() - at);+}diff --git a/packages/core/src/utils/pressFeedback.test.ts b/packages/core/src/utils/pressFeedback.test.tsindex 927b148730..f7b107c689 100644--- a/packages/core/src/utils/pressFeedback.test.ts+++ b/packages/core/src/utils/pressFeedback.test.ts@@ -53,6 +53,7 @@ function press(x: number,y: number,pointerType = 'touch',+ timeStamp?: number,): void {const event = new Event(type, {bubbles: true, cancelable: true});Object.assign(event, {@@ -62,6 +63,9 @@ function press(pointerId: 1,pointerType,});+ if (timeStamp != null) {+ Object.defineProperty(event, 'timeStamp', {value: timeStamp});+ }element.dispatchEvent(event);}@@ -547,6 +551,64 @@ describe('a finger waits only inside a scroller (spec:AST-094 FR11)', () => {expect(control.getAttribute(PRESSED_ATTRIBUTE)).toBe('on');});+ it("counts the content-touch delay from the touch's own timestamp, so a listener that runs late still paints on time", () => {+ const control = pressable('button');+ scroller.appendChild(control);+ // The page has run a while, so the touch's time is past zero.+ vi.advanceTimersByTime(1000);+ // A busy main thread runs the listener 60 ms after the touch.+ press(control, 'pointerdown', 10, 10, 'touch', performance.now() - 60);+ vi.advanceTimersByTime(PRESS_ONSET_MS - 60 - 1);+ expect(control.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);+ vi.advanceTimersByTime(1);+ expect(control.getAttribute(PRESSED_ATTRIBUTE)).toBe('on');+ });++ it('paints at once when the listener runs later than the content-touch delay', () => {+ const control = pressable('button');+ scroller.appendChild(control);+ vi.advanceTimersByTime(1000);+ press(+ control,+ 'pointerdown',+ 10,+ 10,+ 'touch',+ performance.now() - PRESS_ONSET_MS - 40,+ );+ vi.advanceTimersByTime(0);+ expect(control.getAttribute(PRESSED_ATTRIBUTE)).toBe('on');+ });++ it('waits the whole delay for a touch with no time, a time ahead of now, or an epoch time taken now', () => {+ vi.advanceTimersByTime(1000);+ const stamps = [() => 0, () => performance.now() + 500, () => Date.now()];+ for (const stamp of stamps) {+ const control = pressable('button');+ scroller.appendChild(control);+ press(control, 'pointerdown', 10, 10, 'touch', stamp());+ vi.advanceTimersByTime(PRESS_ONSET_MS - 1);+ expect(control.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);+ vi.advanceTimersByTime(1);+ expect(control.getAttribute(PRESSED_ATTRIBUTE)).toBe('on');+ press(control, 'pointerup', 10, 10, 'touch');+ vi.advanceTimersByTime(PRESS_FADE_MS * 2);+ control.remove();+ }+ });++ it("keeps an epoch stamp's age, as the long-press hold does", () => {+ const control = pressable('button');+ scroller.appendChild(control);+ vi.advanceTimersByTime(1000);+ // jsdom stamps an event with Date.now(); this touch is 60 ms old.+ press(control, 'pointerdown', 10, 10, 'touch', Date.now() - 60);+ vi.advanceTimersByTime(PRESS_ONSET_MS - 60 - 1);+ expect(control.hasAttribute(PRESSED_ATTRIBUTE)).toBe(false);+ vi.advanceTimersByTime(1);+ expect(control.getAttribute(PRESSED_ATTRIBUTE)).toBe('on');+ });+it('is cancelled by travel past the slop, with no fade', () => {const control = pressable('button');document.body.appendChild(control);diff --git a/packages/core/src/utils/pressFeedback.ts b/packages/core/src/utils/pressFeedback.tsindex 8a1459061b..db3378c230 100644--- a/packages/core/src/utils/pressFeedback.ts+++ b/packages/core/src/utils/pressFeedback.ts@@ -3,8 +3,9 @@/*** @file pressFeedback.ts* @input The press state machine (pressGesture.ts), the menu-press and- * press-group markers, the scroll-view test (scrollView.ts) and the document's pointer, keyboard, scroll and- * visibility events+ * press-group markers and the scroll-view test (scrollView.ts). Also the+ * input clock (inputAge.ts) and the document's pointer, keyboard, scroll+ * and visibility events* @output PRESSABLE_ATTRIBUTE, PRESSED_ATTRIBUTE, pressableProps,* pressFadeMs, installPressFeedback, cancelPress and installBoxHold* @position The DOM half of the touch press model. usePressFeedback installs@@ -28,8 +29,9 @@//// A finger waits only inside a scroller. Outside one, a surface highlights in// the frame the finger lands, as a UIControl does. Inside one, it waits the-// content-touch delay, because the touch can become a scroll. Rows follow the-// same rule.+// content-touch delay, because the touch can become a scroll. The delay counts+// from the touch's own timestamp, so a late listener does not add to it. Rows+// follow the same rule.//// A surface's hold does nothing, so it keeps the browser's long-press text// selection (AST-094). Only an element whose hold does something suppresses@@ -51,6 +53,7 @@ import {reducedMotionFadeConsts} from '../motion/reducedMotion.stylex';import {parseMotionRoleValue} from '../motion/roles';import {subscribeInput} from './inputStream';import {isInsideScrollView} from './scrollView';+import {msSinceInput} from './inputAge';import {TOUCH_QUERY} from './touchPresentation';import {holdsPressThroughDrag} from '../privateAttributes/pressHoldsDrag.stylex';import {isTrackedByGroup} from '../privateAttributes/pressGroupItem.stylex';@@ -329,7 +332,7 @@ function clearTimer(slot: Slot): void {* - The same during the fade strands `fading` and the tracking slot, which* holds an element that a virtualized list may have unmounted.*/-function apply(slot: Slot, step: PressStep): void {+function apply(slot: Slot, step: PressStep, sinceEventMs = 0): void {const live = slot.live;if (live == null) {return;@@ -368,8 +371,13 @@ function apply(slot: Slot, step: PressStep): void {} else {// A TIMER, never `requestAnimationFrame`: iOS throttles frame callbacks// while a scroll runs, so a frame-based delay would fire late, after the- // scroll, and paint a control nobody is pressing any more.- const timer = setTimeout(fire, TIMER_MS[kind]);+ // scroll, and paint a control nobody is pressing any more. The onset+ // counts from the touch, so the time the listener waited comes off it.+ const delay =+ kind === 'onset'+ ? Math.max(0, TIMER_MS.onset - sinceEventMs)+ : TIMER_MS[kind];+ const timer = setTimeout(fire, delay);live.timer = () => clearTimeout(timer);}}@@ -606,6 +614,7 @@ function onPointerDown(event: PointerEvent): void {y: event.clientY,delayed: isInsideScrollView(element),}),+ msSinceInput(event.timeStamp, event),);}