@tanstack/virtual-core 3.19.13 → 3.19.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +67 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +5 -1
- package/dist/cjs/ios-gesture.cjs +9 -0
- package/dist/cjs/ios-gesture.cjs.map +1 -1
- package/dist/cjs/ios-gesture.d.cts +1 -0
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.js +68 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ios-gesture.d.ts +1 -0
- package/dist/esm/ios-gesture.js +9 -0
- package/dist/esm/ios-gesture.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +145 -22
- package/src/ios-gesture.ts +15 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const isIOSWebKit: () => boolean;
|
|
2
2
|
export declare const iosMomentumOverridesWrites: () => boolean;
|
|
3
3
|
export declare const momentumOverridesWrites: () => boolean;
|
|
4
|
+
export declare const isWebKit: () => boolean;
|
|
4
5
|
export declare const _resetIOSDetectionForTests: () => void;
|
|
5
6
|
type IosTouch = {
|
|
6
7
|
phase: 'down';
|
package/dist/esm/ios-gesture.js
CHANGED
|
@@ -14,8 +14,16 @@ const iosMomentumOverridesWrites = () => {
|
|
|
14
14
|
return _iosMomentumOverridesWritesResult = isIOSWebKit() && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("overflow-anchor: auto");
|
|
15
15
|
};
|
|
16
16
|
const momentumOverridesWrites = () => !isIOSWebKit() || iosMomentumOverridesWrites();
|
|
17
|
+
let _isWebKitResult;
|
|
18
|
+
const isWebKit = () => {
|
|
19
|
+
if (_isWebKitResult !== void 0) return _isWebKitResult;
|
|
20
|
+
if (typeof navigator === "undefined") return _isWebKitResult = false;
|
|
21
|
+
const ua = navigator.userAgent;
|
|
22
|
+
return _isWebKitResult = /AppleWebKit/.test(ua) && !/Chrome|Chromium|Android|jsdom|HappyDOM/.test(ua);
|
|
23
|
+
};
|
|
17
24
|
const _resetIOSDetectionForTests = () => {
|
|
18
25
|
_isIOSResult = void 0;
|
|
26
|
+
_isWebKitResult = void 0;
|
|
19
27
|
_iosMomentumOverridesWritesResult = void 0;
|
|
20
28
|
};
|
|
21
29
|
const touchListenerOptions = {
|
|
@@ -126,6 +134,7 @@ export {
|
|
|
126
134
|
_resetIOSDetectionForTests,
|
|
127
135
|
iosMomentumOverridesWrites,
|
|
128
136
|
isIOSWebKit,
|
|
137
|
+
isWebKit,
|
|
129
138
|
momentumOverridesWrites
|
|
130
139
|
};
|
|
131
140
|
//# sourceMappingURL=ios-gesture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios-gesture.js","sources":["../../src/ios-gesture.ts"],"sourcesContent":["// Browser-aware iOS detection. Programmatic `scrollTo`/`scrollTop` writes\n// during a momentum-scroll cancel the momentum on iOS WebKit, so we defer\n// scroll-position adjustments triggered by mid-scroll resizes until the\n// scroll settles. SSR-safe (returns false when navigator is unavailable).\nlet _isIOSResult: boolean | undefined\nexport const isIOSWebKit = (): boolean => {\n if (_isIOSResult !== undefined) return _isIOSResult\n if (typeof navigator === 'undefined') return (_isIOSResult = false)\n if (/iP(hone|od|ad)/.test(navigator.userAgent)) return (_isIOSResult = true)\n // iPadOS 13+ reports as MacIntel; touch-points distinguishes it from desktop.\n const mtp = (navigator as Navigator & { maxTouchPoints?: number })\n .maxTouchPoints\n return (_isIOSResult =\n navigator.platform === 'MacIntel' && mtp !== undefined && mtp > 0)\n}\n\n// iOS 27 changed what a scrollTop write does to a fling: it no longer stops\n// the momentum, the fling carries on along its own path and the write shows\n// for one frame (measured on the 27.0 simulator in #1307, device check still\n// open). WebKit shipped `overflow-anchor` in the same release, so that is\n// the feature check; iOS 26 and earlier report false. Cached like the iOS\n// check; SSR-safe.\nlet _iosMomentumOverridesWritesResult: boolean | undefined\nexport const iosMomentumOverridesWrites = (): boolean => {\n if (_iosMomentumOverridesWritesResult !== undefined) {\n return _iosMomentumOverridesWritesResult\n }\n return (_iosMomentumOverridesWritesResult =\n isIOSWebKit() &&\n typeof CSS !== 'undefined' &&\n typeof CSS.supports === 'function' &&\n CSS.supports('overflow-anchor: auto'))\n}\n\n// Whether a touch fling survives a scrollTop write, so a command issued\n// mid-fling has to stop the fling before it writes. Only iOS 26 and earlier\n// stop the momentum on the write itself. Chrome on Android carries the fling\n// on from the written position: on a Pixel 6 (Android 16, Chrome 156) a\n// `scrollToIndex` issued 150ms into a fling wrote its target, then went on\n// ~3,200px past it, 3 runs of 3. Other non-iOS engines are not measured; on\n// one whose write does stop the fling, stopping it first costs the two\n// frames of the stop.\nexport const momentumOverridesWrites = (): boolean =>\n !isIOSWebKit() || iosMomentumOverridesWrites()\n\n// Test hook: reset the iOS detection caches. Not exported.\nexport const _resetIOSDetectionForTests = () => {\n _isIOSResult = undefined\n _iosMomentumOverridesWritesResult = undefined\n}\n\n// Touch listeners on the scroll element run in the capture phase, so a row\n// that stops a touch event's propagation cannot hide the gesture from the\n// iOS deferral.\nconst touchListenerOptions = {\n capture: true,\n passive: true,\n}\n\n// The touch gesture in progress. iOS WebKit ignores a scrollTop write while\n// a finger drags the content (one resting on it does not stop the write)\n// and cancels momentum on one after it, so adjustments are deferred through\n// the whole gesture: `down` from touchstart to touchend/touchcancel, then\n// `tail` while momentum runs. iOS fires no touch events during momentum, so\n// every scroll event re-arms the tail and it closes ~150ms after the last\n// one. Null between gestures. The tail is tracked on every platform, but\n// only iOS defers anything through it; elsewhere it only tells a command\n// that a fling may be running (`momentumOverridesWrites`). The tail record\n// owns its timer: every replacement of the state goes through `end`, which\n// clears it, so a live timer always has its record.\n//\n// `moved`: the content moved under or after the finger other than by our\n// own write's read-back. While `down`, a scroll event that changed the\n// position sets it: the finger is dragging. The tail inherits it from the\n// drag, and any other scroll event re-arming the tail sets it: a fling can\n// be running. A tap's tail has it unset.\n//\n// `awaitingFling`: the tail follows a drag whose fling has not reported\n// yet. The first frame of a fling can come 150–250ms after touchend when\n// the main thread is busy (27.0 simulator, #1307); if the tail closes\n// first, `lateFling` waits until `until` for that frame to reopen it. It\n// defers nothing: other scroll events with no touch before them must not\n// defer corrections (#1250).\ntype IosTouch =\n | { phase: 'down'; moved: boolean }\n | { phase: 'tail'; moved: boolean; awaitingFling: boolean; timerId: number }\n | { phase: 'lateFling'; until: number }\n | null\n\ntype TimerWindow = Pick<Window, 'setTimeout' | 'clearTimeout'>\n\nexport class IosGesture {\n private _touch: IosTouch = null\n\n constructor(\n private readonly host: {\n // The scroll element's window, which runs the tail timer; null when\n // there is no element.\n getWindow: () => TimerWindow | null\n now: () => number\n // Asked when the tail's timer fires: true keeps it open another\n // 150ms (the fling still moves between scroll events).\n tailStillMoving: () => boolean\n // The tail closed on its own: a write is possible again.\n onTailClosed: () => void\n },\n ) {}\n\n get touch(): IosTouch {\n return this._touch\n }\n\n // A touch gesture owns the scroll: on iOS a write now would be ignored or\n // would cancel the momentum, so adjustments wait for the tail to close.\n // `isScrolling` is not part of it: any scroll event sets it, including\n // the read-back of our own write, and a programmatic scroll has no\n // momentum to protect (#1250).\n inMotion = () => this._touch !== null && this._touch.phase !== 'lateFling'\n\n // A finger is dragging the content, so iOS ignores our writes and no\n // read-back will come. A resting finger does not: the write lands.\n dragging = () => this._touch?.phase === 'down' && this._touch.moved\n\n // The open tail, if any: after a tap, or after a drag or fling. Except on\n // iOS 26 and earlier, a fling's momentum outlasts a write (see\n // `momentumOverridesWrites`).\n tail = (): 'tap' | 'fling' | null =>\n this._touch?.phase === 'tail' ? (this._touch.moved ? 'fling' : 'tap') : null\n\n // A scroll event reached the handler. `ownReadBack`: it is our own\n // write's read-back; `moved`: it changed the layout position; `external`:\n // the user or a fling moved it (not our write nor our smooth animation).\n // Returns whether it shows a finger dragging the content.\n onScroll = ({\n isScrolling,\n ownReadBack,\n moved,\n external,\n }: {\n isScrolling: boolean\n ownReadBack: boolean\n moved: boolean\n external: boolean\n }): boolean => {\n // Momentum after touchend fires a scroll event per frame but no touch\n // events, so each one re-arms the tail to span the fling. Only an open\n // tail is extended: a scroll event with no touch before it (our own\n // write's read-back) never opens one.\n if (isScrolling && this._touch?.phase === 'tail') {\n this._openTail(this._touch.moved || !ownReadBack, false)\n } else if (this._touch?.phase === 'lateFling') {\n // A drag's fling reporting after its tail closed reopens it.\n if (this.host.now() > this._touch.until) {\n this._touch = null\n } else if (external && isScrolling && moved) {\n this._openTail(true, false)\n }\n }\n // A finger that moved the content is dragging. Our own write landing\n // under a resting finger is not, and neither is a report at rest that\n // leaves the position where it was.\n if (!ownReadBack && isScrolling && moved && this._touch?.phase === 'down') {\n this._touch.moved = true\n return true\n }\n return false\n }\n\n touchStart = () => {\n // A finger back down inside the grace window cancels its tail.\n this.end()\n this._touch = { phase: 'down', moved: false }\n }\n\n touchEnd = () => {\n const moved = this._touch?.phase === 'down' && this._touch.moved\n this.end()\n this._openTail(moved, moved)\n }\n\n // Drop the gesture, and the tail's timer with it.\n end = () => {\n const win = this.host.getWindow()\n if (this._touch?.phase === 'tail' && win != null) {\n win.clearTimeout(this._touch.timerId)\n }\n this._touch = null\n }\n\n // Follow the touch events on `target`; the returned function stops and\n // drops the gesture. Listening is unconditional: the listeners are\n // passive and cheap, and on non-touch devices they never fire. The gating\n // by `isIOSWebKit()` lives where a write is decided.\n listen = (target: EventTarget) => {\n const onTouchStart = () => this.touchStart()\n const onTouchEnd = () => this.touchEnd()\n target.addEventListener('touchstart', onTouchStart, touchListenerOptions)\n target.addEventListener('touchend', onTouchEnd, touchListenerOptions)\n // Same handler as touchend: iOS can end a touch with touchcancel (system\n // gesture, interrupted scroll) and never fire touchend.\n target.addEventListener('touchcancel', onTouchEnd, touchListenerOptions)\n return () => {\n target.removeEventListener(\n 'touchstart',\n onTouchStart,\n touchListenerOptions,\n )\n target.removeEventListener('touchend', onTouchEnd, touchListenerOptions)\n target.removeEventListener(\n 'touchcancel',\n onTouchEnd,\n touchListenerOptions,\n )\n this.end()\n }\n }\n\n // (Re)open the tail after the finger lifts, closing ~150ms after the last\n // touchend or momentum frame.\n private _openTail = (moved: boolean, awaitingFling: boolean) => {\n const win = this.host.getWindow()\n if (win == null) return\n this.end()\n const tail = {\n phase: 'tail' as const,\n moved,\n awaitingFling,\n // Only fires while this tail is current: `end` clears it otherwise.\n timerId: win.setTimeout(() => {\n if (this.host.tailStillMoving()) {\n this._openTail(tail.moved, tail.awaitingFling)\n return\n }\n this._touch = tail.awaitingFling\n ? { phase: 'lateFling', until: this.host.now() + 1000 }\n : null\n this.host.onTailClosed()\n }, 150),\n }\n this._touch = tail\n }\n}\n"],"names":[],"mappings":"AAIA,IAAI;AACG,MAAM,cAAc,MAAe;AACxC,MAAI,iBAAiB,OAAW,QAAO;AACvC,MAAI,OAAO,cAAc,YAAa,QAAQ,eAAe;AAC7D,MAAI,iBAAiB,KAAK,UAAU,SAAS,UAAW,eAAe;AAEvE,QAAM,MAAO,UACV;AACH,SAAQ,eACN,UAAU,aAAa,cAAc,QAAQ,UAAa,MAAM;AACpE;AAQA,IAAI;AACG,MAAM,6BAA6B,MAAe;AACvD,MAAI,sCAAsC,QAAW;AACnD,WAAO;AAAA,EACT;AACA,SAAQ,oCACN,iBACA,OAAO,QAAQ,eACf,OAAO,IAAI,aAAa,cACxB,IAAI,SAAS,uBAAuB;AACxC;AAUO,MAAM,0BAA0B,MACrC,CAAC,YAAA,KAAiB,2BAAA;AAGb,MAAM,6BAA6B,MAAM;AAC9C,iBAAe;AACf,sCAAoC;AACtC;AAKA,MAAM,uBAAuB;AAAA,EAC3B,SAAS;AAAA,EACT,SAAS;AACX;AAkCO,MAAM,WAAW;AAAA,EAGtB,YACmB,MAWjB;AAXiB,SAAA,OAAA;AAHnB,SAAQ,SAAmB;AAyB3B,SAAA,WAAW,MAAM,KAAK,WAAW,QAAQ,KAAK,OAAO,UAAU;AAI/D,SAAA,WAAW,MAAA;AArHb;AAqHmB,yBAAK,WAAL,mBAAa,WAAU,U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AM,KAAK,SAAA;AAC9B,aAAO,iBAAiB,cAAc,cAAc,oBAAoB;AACxE,aAAO,iBAAiB,YAAY,YAAY,oBAAoB;AAGpE,aAAO,iBAAiB,eAAe,YAAY,oBAAoB;AACvE,aAAO,MAAM;AACX,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,eAAO,oBAAoB,YAAY,YAAY,oBAAoB;AACvE,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,aAAK,IAAA;AAAA,MACP;AAAA,IACF;AAIA,SAAQ,YAAY,CAAC,OAAgB,kBAA2B;AAC9D,YAAM,MAAM,KAAK,KAAK,UAAA;AACtB,UAAI,OAAO,KAAM;AACjB,WAAK,IAAA;AACL,YAAM,OAAO;AAAA,QACX,OAAO;AAAA,QACP;AAAA,QACA;AAAA;AAAA,QAEA,SAAS,IAAI,WAAW,MAAM;AAC5B,cAAI,KAAK,KAAK,mBAAmB;AAC/B,iBAAK,UAAU,KAAK,OAAO,KAAK,aAAa;AAC7C;AAAA,UACF;AACA,eAAK,SAAS,KAAK,gBACf,EAAE,OAAO,aAAa,OAAO,KAAK,KAAK,IAAA,IAAQ,IAAA,IAC/C;AACJ,eAAK,KAAK,aAAA;AAAA,QACZ,GAAG,GAAG;AAAA,MAAA;AAER,WAAK,SAAS;AAAA,IAChB;AAAA,EAtIG;AAAA,EAEH,IAAI,QAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAmIF;"}
|
|
1
|
+
{"version":3,"file":"ios-gesture.js","sources":["../../src/ios-gesture.ts"],"sourcesContent":["// Browser-aware iOS detection. Programmatic `scrollTo`/`scrollTop` writes\n// during a momentum-scroll cancel the momentum on iOS WebKit, so we defer\n// scroll-position adjustments triggered by mid-scroll resizes until the\n// scroll settles. SSR-safe (returns false when navigator is unavailable).\nlet _isIOSResult: boolean | undefined\nexport const isIOSWebKit = (): boolean => {\n if (_isIOSResult !== undefined) return _isIOSResult\n if (typeof navigator === 'undefined') return (_isIOSResult = false)\n if (/iP(hone|od|ad)/.test(navigator.userAgent)) return (_isIOSResult = true)\n // iPadOS 13+ reports as MacIntel; touch-points distinguishes it from desktop.\n const mtp = (navigator as Navigator & { maxTouchPoints?: number })\n .maxTouchPoints\n return (_isIOSResult =\n navigator.platform === 'MacIntel' && mtp !== undefined && mtp > 0)\n}\n\n// iOS 27 changed what a scrollTop write does to a fling: it no longer stops\n// the momentum, the fling carries on along its own path and the write shows\n// for one frame (measured on the 27.0 simulator in #1307, device check still\n// open). WebKit shipped `overflow-anchor` in the same release, so that is\n// the feature check; iOS 26 and earlier report false. Cached like the iOS\n// check; SSR-safe.\nlet _iosMomentumOverridesWritesResult: boolean | undefined\nexport const iosMomentumOverridesWrites = (): boolean => {\n if (_iosMomentumOverridesWritesResult !== undefined) {\n return _iosMomentumOverridesWritesResult\n }\n return (_iosMomentumOverridesWritesResult =\n isIOSWebKit() &&\n typeof CSS !== 'undefined' &&\n typeof CSS.supports === 'function' &&\n CSS.supports('overflow-anchor: auto'))\n}\n\n// Whether a touch fling survives a scrollTop write, so a command issued\n// mid-fling has to stop the fling before it writes. Only iOS 26 and earlier\n// stop the momentum on the write itself. Chrome on Android carries the fling\n// on from the written position: on a Pixel 6 (Android 16, Chrome 156) a\n// `scrollToIndex` issued 150ms into a fling wrote its target, then went on\n// ~3,200px past it, 3 runs of 3. Other non-iOS engines are not measured; on\n// one whose write does stop the fling, stopping it first costs the two\n// frames of the stop.\nexport const momentumOverridesWrites = (): boolean =>\n !isIOSWebKit() || iosMomentumOverridesWrites()\n\n// Any WebKit: Safari, a WKWebView app, every browser on iOS. Chromium's\n// user agent names AppleWebKit too, and so do jsdom's and happy-dom's, where\n// a consumer's test must see the same writes as before. Cached like the iOS\n// check; SSR-safe.\nlet _isWebKitResult: boolean | undefined\nexport const isWebKit = (): boolean => {\n if (_isWebKitResult !== undefined) return _isWebKitResult\n if (typeof navigator === 'undefined') return (_isWebKitResult = false)\n const ua = navigator.userAgent\n return (_isWebKitResult =\n /AppleWebKit/.test(ua) &&\n !/Chrome|Chromium|Android|jsdom|HappyDOM/.test(ua))\n}\n\n// Test hook: reset the iOS detection caches. Not exported.\nexport const _resetIOSDetectionForTests = () => {\n _isIOSResult = undefined\n _isWebKitResult = undefined\n _iosMomentumOverridesWritesResult = undefined\n}\n\n// Touch listeners on the scroll element run in the capture phase, so a row\n// that stops a touch event's propagation cannot hide the gesture from the\n// iOS deferral.\nconst touchListenerOptions = {\n capture: true,\n passive: true,\n}\n\n// The touch gesture in progress. iOS WebKit ignores a scrollTop write while\n// a finger drags the content (one resting on it does not stop the write)\n// and cancels momentum on one after it, so adjustments are deferred through\n// the whole gesture: `down` from touchstart to touchend/touchcancel, then\n// `tail` while momentum runs. iOS fires no touch events during momentum, so\n// every scroll event re-arms the tail and it closes ~150ms after the last\n// one. Null between gestures. The tail is tracked on every platform, but\n// only iOS defers anything through it; elsewhere it only tells a command\n// that a fling may be running (`momentumOverridesWrites`). The tail record\n// owns its timer: every replacement of the state goes through `end`, which\n// clears it, so a live timer always has its record.\n//\n// `moved`: the content moved under or after the finger other than by our\n// own write's read-back. While `down`, a scroll event that changed the\n// position sets it: the finger is dragging. The tail inherits it from the\n// drag, and any other scroll event re-arming the tail sets it: a fling can\n// be running. A tap's tail has it unset.\n//\n// `awaitingFling`: the tail follows a drag whose fling has not reported\n// yet. The first frame of a fling can come 150–250ms after touchend when\n// the main thread is busy (27.0 simulator, #1307); if the tail closes\n// first, `lateFling` waits until `until` for that frame to reopen it. It\n// defers nothing: other scroll events with no touch before them must not\n// defer corrections (#1250).\ntype IosTouch =\n | { phase: 'down'; moved: boolean }\n | { phase: 'tail'; moved: boolean; awaitingFling: boolean; timerId: number }\n | { phase: 'lateFling'; until: number }\n | null\n\ntype TimerWindow = Pick<Window, 'setTimeout' | 'clearTimeout'>\n\nexport class IosGesture {\n private _touch: IosTouch = null\n\n constructor(\n private readonly host: {\n // The scroll element's window, which runs the tail timer; null when\n // there is no element.\n getWindow: () => TimerWindow | null\n now: () => number\n // Asked when the tail's timer fires: true keeps it open another\n // 150ms (the fling still moves between scroll events).\n tailStillMoving: () => boolean\n // The tail closed on its own: a write is possible again.\n onTailClosed: () => void\n },\n ) {}\n\n get touch(): IosTouch {\n return this._touch\n }\n\n // A touch gesture owns the scroll: on iOS a write now would be ignored or\n // would cancel the momentum, so adjustments wait for the tail to close.\n // `isScrolling` is not part of it: any scroll event sets it, including\n // the read-back of our own write, and a programmatic scroll has no\n // momentum to protect (#1250).\n inMotion = () => this._touch !== null && this._touch.phase !== 'lateFling'\n\n // A finger is dragging the content, so iOS ignores our writes and no\n // read-back will come. A resting finger does not: the write lands.\n dragging = () => this._touch?.phase === 'down' && this._touch.moved\n\n // The open tail, if any: after a tap, or after a drag or fling. Except on\n // iOS 26 and earlier, a fling's momentum outlasts a write (see\n // `momentumOverridesWrites`).\n tail = (): 'tap' | 'fling' | null =>\n this._touch?.phase === 'tail' ? (this._touch.moved ? 'fling' : 'tap') : null\n\n // A scroll event reached the handler. `ownReadBack`: it is our own\n // write's read-back; `moved`: it changed the layout position; `external`:\n // the user or a fling moved it (not our write nor our smooth animation).\n // Returns whether it shows a finger dragging the content.\n onScroll = ({\n isScrolling,\n ownReadBack,\n moved,\n external,\n }: {\n isScrolling: boolean\n ownReadBack: boolean\n moved: boolean\n external: boolean\n }): boolean => {\n // Momentum after touchend fires a scroll event per frame but no touch\n // events, so each one re-arms the tail to span the fling. Only an open\n // tail is extended: a scroll event with no touch before it (our own\n // write's read-back) never opens one.\n if (isScrolling && this._touch?.phase === 'tail') {\n this._openTail(this._touch.moved || !ownReadBack, false)\n } else if (this._touch?.phase === 'lateFling') {\n // A drag's fling reporting after its tail closed reopens it.\n if (this.host.now() > this._touch.until) {\n this._touch = null\n } else if (external && isScrolling && moved) {\n this._openTail(true, false)\n }\n }\n // A finger that moved the content is dragging. Our own write landing\n // under a resting finger is not, and neither is a report at rest that\n // leaves the position where it was.\n if (!ownReadBack && isScrolling && moved && this._touch?.phase === 'down') {\n this._touch.moved = true\n return true\n }\n return false\n }\n\n touchStart = () => {\n // A finger back down inside the grace window cancels its tail.\n this.end()\n this._touch = { phase: 'down', moved: false }\n }\n\n touchEnd = () => {\n const moved = this._touch?.phase === 'down' && this._touch.moved\n this.end()\n this._openTail(moved, moved)\n }\n\n // Drop the gesture, and the tail's timer with it.\n end = () => {\n const win = this.host.getWindow()\n if (this._touch?.phase === 'tail' && win != null) {\n win.clearTimeout(this._touch.timerId)\n }\n this._touch = null\n }\n\n // Follow the touch events on `target`; the returned function stops and\n // drops the gesture. Listening is unconditional: the listeners are\n // passive and cheap, and on non-touch devices they never fire. The gating\n // by `isIOSWebKit()` lives where a write is decided.\n listen = (target: EventTarget) => {\n const onTouchStart = () => this.touchStart()\n const onTouchEnd = () => this.touchEnd()\n target.addEventListener('touchstart', onTouchStart, touchListenerOptions)\n target.addEventListener('touchend', onTouchEnd, touchListenerOptions)\n // Same handler as touchend: iOS can end a touch with touchcancel (system\n // gesture, interrupted scroll) and never fire touchend.\n target.addEventListener('touchcancel', onTouchEnd, touchListenerOptions)\n return () => {\n target.removeEventListener(\n 'touchstart',\n onTouchStart,\n touchListenerOptions,\n )\n target.removeEventListener('touchend', onTouchEnd, touchListenerOptions)\n target.removeEventListener(\n 'touchcancel',\n onTouchEnd,\n touchListenerOptions,\n )\n this.end()\n }\n }\n\n // (Re)open the tail after the finger lifts, closing ~150ms after the last\n // touchend or momentum frame.\n private _openTail = (moved: boolean, awaitingFling: boolean) => {\n const win = this.host.getWindow()\n if (win == null) return\n this.end()\n const tail = {\n phase: 'tail' as const,\n moved,\n awaitingFling,\n // Only fires while this tail is current: `end` clears it otherwise.\n timerId: win.setTimeout(() => {\n if (this.host.tailStillMoving()) {\n this._openTail(tail.moved, tail.awaitingFling)\n return\n }\n this._touch = tail.awaitingFling\n ? { phase: 'lateFling', until: this.host.now() + 1000 }\n : null\n this.host.onTailClosed()\n }, 150),\n }\n this._touch = tail\n }\n}\n"],"names":[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L;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,eAAO,oBAAoB,YAAY,YAAY,oBAAoB;AACvE,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,QAAA;AAEF,aAAK,IAAA;AAAA,MACP;AAAA,IACF;AAIA,SAAQ,YAAY,CAAC,OAAgB,kBAA2B;AAC9D,YAAM,MAAM,KAAK,KAAK,UAAA;AACtB,UAAI,OAAO,KAAM;AACjB,WAAK,IAAA;AACL,YAAM,OAAO;AAAA,QACX,OAAO;AAAA,QACP;AAAA,QACA;AAAA;AAAA,QAEA,SAAS,IAAI,WAAW,MAAM;AAC5B,cAAI,KAAK,KAAK,mBAAmB;AAC/B,iBAAK,UAAU,KAAK,OAAO,KAAK,aAAa;AAC7C;AAAA,UACF;AACA,eAAK,SAAS,KAAK,gBACf,EAAE,OAAO,aAAa,OAAO,KAAK,KAAK,IAAA,IAAQ,IAAA,IAC/C;AACJ,eAAK,KAAK,aAAA;AAAA,QACZ,GAAG,GAAG;AAAA,MAAA;AAER,WAAK,SAAS;AAAA,IAChB;AAAA,EAtIG;AAAA,EAEH,IAAI,QAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAmIF;"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,7 +9,12 @@ import {
|
|
|
9
9
|
flingCaught,
|
|
10
10
|
flingSpedUp,
|
|
11
11
|
} from './scroll-classifier'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
IosGesture,
|
|
14
|
+
isIOSWebKit,
|
|
15
|
+
isWebKit,
|
|
16
|
+
momentumOverridesWrites,
|
|
17
|
+
} from './ios-gesture'
|
|
13
18
|
import type { ScrollPhase, ScrollSample } from './scroll-classifier'
|
|
14
19
|
|
|
15
20
|
export { _resetIOSDetectionForTests } from './ios-gesture'
|
|
@@ -382,7 +387,9 @@ export interface VirtualizerOptions<
|
|
|
382
387
|
paddingEnd?: number
|
|
383
388
|
scrollPaddingStart?: number
|
|
384
389
|
scrollPaddingEnd?: number
|
|
385
|
-
initialOffset?:
|
|
390
|
+
initialOffset?:
|
|
391
|
+
| number
|
|
392
|
+
| ((instance: Virtualizer<TScrollElement, TItemElement>) => number)
|
|
386
393
|
getItemKey?: (index: number) => Key
|
|
387
394
|
rangeExtractor?: (range: Range) => Array<number>
|
|
388
395
|
scrollMargin?: number
|
|
@@ -540,6 +547,12 @@ export class Virtualizer<
|
|
|
540
547
|
// `_flushHoldIfReady`: the rows re-render in layout coordinates and the
|
|
541
548
|
// element moves by the same amount in one paint.
|
|
542
549
|
private _holdOffset = 0
|
|
550
|
+
// Set in WebKit from a wheel event until 150ms pass without one, whether
|
|
551
|
+
// or not that event scrolled this element. Corrections are held meanwhile
|
|
552
|
+
// (see `_canWriteScroll`).
|
|
553
|
+
private _wheelTimer: number | null = null
|
|
554
|
+
// The frame a hold at the top is written in (`_flushHoldAtTop`).
|
|
555
|
+
private _edgeFlushFrame: number | null = null
|
|
543
556
|
// Whether the element's last scroll event reported a position past either
|
|
544
557
|
// edge (the rubber-band bounce). Judged at report time against the
|
|
545
558
|
// element's own max, with a 1px tolerance for a fractional scrollTop: a
|
|
@@ -963,10 +976,11 @@ export class Virtualizer<
|
|
|
963
976
|
if (this._canWriteScroll()) {
|
|
964
977
|
this.pendingScrollAnchor = { kind: 'anchor', delta: anchorDelta }
|
|
965
978
|
} else {
|
|
966
|
-
// The element cannot take the write (a touch owns it on iOS,
|
|
967
|
-
// overscrolled). Hold the delta
|
|
968
|
-
//
|
|
969
|
-
//
|
|
979
|
+
// The element cannot take the write (a touch owns it on iOS, it is
|
|
980
|
+
// overscrolled, or wheel input runs in WebKit). Hold the delta
|
|
981
|
+
// instead: this render already exposes the rows and the total
|
|
982
|
+
// shifted back by it, so the reader's row stays put, and the flush
|
|
983
|
+
// writes it once a write is possible.
|
|
970
984
|
this._holdOffset += anchorDelta
|
|
971
985
|
this._followAnchor(anchorDelta)
|
|
972
986
|
}
|
|
@@ -1087,6 +1101,16 @@ export class Virtualizer<
|
|
|
1087
1101
|
// just removed), deferring every adjustment on the new element until
|
|
1088
1102
|
// its next touch cycle.
|
|
1089
1103
|
this._holdOffset = 0
|
|
1104
|
+
if (this.targetWindow) {
|
|
1105
|
+
if (this._wheelTimer !== null) {
|
|
1106
|
+
this.targetWindow.clearTimeout(this._wheelTimer)
|
|
1107
|
+
}
|
|
1108
|
+
if (this._edgeFlushFrame !== null) {
|
|
1109
|
+
this.targetWindow.cancelAnimationFrame(this._edgeFlushFrame)
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
this._wheelTimer = null
|
|
1113
|
+
this._edgeFlushFrame = null
|
|
1090
1114
|
this._reportedOverscroll = false
|
|
1091
1115
|
this._trailing = 0
|
|
1092
1116
|
// (The gesture was ended with its listeners, in the unsubs above.)
|
|
@@ -1276,6 +1300,7 @@ export class Virtualizer<
|
|
|
1276
1300
|
|
|
1277
1301
|
// A held correction is written once a write is possible.
|
|
1278
1302
|
this._flushHoldIfReady(true)
|
|
1303
|
+
this._flushHoldAtTop()
|
|
1279
1304
|
|
|
1280
1305
|
if (this.scrollState) {
|
|
1281
1306
|
this.scheduleScrollReconcile()
|
|
@@ -1286,9 +1311,24 @@ export class Virtualizer<
|
|
|
1286
1311
|
|
|
1287
1312
|
// Touch event listeners (iOS-aware deferral).
|
|
1288
1313
|
if ('addEventListener' in this.scrollElement) {
|
|
1289
|
-
this.
|
|
1290
|
-
|
|
1291
|
-
)
|
|
1314
|
+
const target = this.scrollElement as unknown as EventTarget
|
|
1315
|
+
this.unsubs.push(this._iosGesture.listen(target))
|
|
1316
|
+
if (isWebKit()) {
|
|
1317
|
+
const onWheel = () => {
|
|
1318
|
+
const win = this.targetWindow
|
|
1319
|
+
if (win === null) return
|
|
1320
|
+
if (this._wheelTimer !== null) win.clearTimeout(this._wheelTimer)
|
|
1321
|
+
this._wheelTimer = win.setTimeout(() => {
|
|
1322
|
+
this._wheelTimer = null
|
|
1323
|
+
this._flushHoldIfReady(true)
|
|
1324
|
+
this._retryClampedAdjustment()
|
|
1325
|
+
}, 150)
|
|
1326
|
+
// At the top the element stops moving, so no scroll event comes.
|
|
1327
|
+
this._flushHoldAtTop()
|
|
1328
|
+
}
|
|
1329
|
+
target.addEventListener('wheel', onWheel, addEventListenerOptions)
|
|
1330
|
+
this.unsubs.push(() => target.removeEventListener('wheel', onWheel))
|
|
1331
|
+
}
|
|
1292
1332
|
}
|
|
1293
1333
|
|
|
1294
1334
|
this._scrollToOffset(this.getScrollOffset())
|
|
@@ -1443,19 +1483,82 @@ export class Virtualizer<
|
|
|
1443
1483
|
// #1307), so a correction is held through the tail on every version;
|
|
1444
1484
|
// - not while the element is overscrolled past either edge (the
|
|
1445
1485
|
// rubber-band bounce): WebKit discards the write and the bounce can
|
|
1446
|
-
// stall where it was (#1287)
|
|
1486
|
+
// stall where it was (#1287);
|
|
1487
|
+
// - not in WebKit within 150ms of a wheel event: the write lands, but
|
|
1488
|
+
// WebKit then discards the distance of the next wheel event, and a list
|
|
1489
|
+
// of rows measured on the way up writes on most frames. In Playwright
|
|
1490
|
+
// WebKit 26.0 a wheel event per frame lost about a third of its
|
|
1491
|
+
// distance that way (#1398, #1400); a prepend's anchor write could be
|
|
1492
|
+
// undone whole. With the hold, Safari 26.5.2 itself lost nothing on
|
|
1493
|
+
// trackpad momentum and about 2.5% on a continuous mouse wheel, at the
|
|
1494
|
+
// writes at the top (#1400); without it only Playwright is measured.
|
|
1447
1495
|
// A write that is unwanted for another reason (a travelling smooth scroll
|
|
1448
1496
|
// owns the position) is a separate check at the call sites.
|
|
1449
1497
|
private _canWriteScroll = () =>
|
|
1450
|
-
!(isIOSWebKit() && this._iosGesture.inMotion()) &&
|
|
1498
|
+
!(isIOSWebKit() && this._iosGesture.inMotion()) &&
|
|
1499
|
+
!this._reportedOverscroll &&
|
|
1500
|
+
this._wheelTimer === null
|
|
1501
|
+
|
|
1502
|
+
// A hold shifts the rows and leaves the element where it is, so the
|
|
1503
|
+
// element reaches its top while the layout has `_holdOffset` further to
|
|
1504
|
+
// go (or, for a negative hold, the layout reaches the top first). Wheel
|
|
1505
|
+
// input that never pauses would park the reader there, so there the wheel
|
|
1506
|
+
// hold ends early and the hold is written, two frames later (a prepend's
|
|
1507
|
+
// anchor written at once can be undone, #1398). The next wheel event
|
|
1508
|
+
// starts the wheel hold again. Not before the top: while the element
|
|
1509
|
+
// still moves, WebKit applies the write about two frames after the rows
|
|
1510
|
+
// have gone back to layout coordinates, and they show `_holdOffset` away
|
|
1511
|
+
// for those frames (measured with a 1200px and a one-viewport margin in
|
|
1512
|
+
// Playwright WebKit 26.0; not seen in 27.2, #1400). The list's top is
|
|
1513
|
+
// `scrollMargin` down the element, where held rows would be drawn over
|
|
1514
|
+
// what is above the list; the element still moves there, so those frames
|
|
1515
|
+
// are the lesser evil. Past the top (a bounce) the write waits: the next
|
|
1516
|
+
// wheel or scroll event tries again.
|
|
1517
|
+
// The end needs none of this: the total size is exposed short by the
|
|
1518
|
+
// hold, so the element and the layout reach it together.
|
|
1519
|
+
private _holdAtTop = () => {
|
|
1520
|
+
if (this._holdOffset === 0) return false
|
|
1521
|
+
const offset = this._readElementOffset()
|
|
1522
|
+
// 1px for a fractional scrollTop.
|
|
1523
|
+
return (
|
|
1524
|
+
offset !== null &&
|
|
1525
|
+
Math.min(offset, offset + this._holdOffset) <
|
|
1526
|
+
this.options.scrollMargin + 1
|
|
1527
|
+
)
|
|
1528
|
+
}
|
|
1529
|
+
private _flushHoldAtTop = () => {
|
|
1530
|
+
const win = this.targetWindow
|
|
1531
|
+
if (
|
|
1532
|
+
win === null ||
|
|
1533
|
+
this._wheelTimer === null ||
|
|
1534
|
+
this._edgeFlushFrame !== null ||
|
|
1535
|
+
!this._holdAtTop()
|
|
1536
|
+
) {
|
|
1537
|
+
return
|
|
1538
|
+
}
|
|
1539
|
+
this._edgeFlushFrame = win.requestAnimationFrame(() => {
|
|
1540
|
+
this._edgeFlushFrame = win.requestAnimationFrame(() => {
|
|
1541
|
+
this._edgeFlushFrame = null
|
|
1542
|
+
// The reader can have turned back within the two frames.
|
|
1543
|
+
if (this._wheelTimer === null || !this._holdAtTop()) return
|
|
1544
|
+
win.clearTimeout(this._wheelTimer)
|
|
1545
|
+
this._wheelTimer = null
|
|
1546
|
+
this._flushHoldIfReady(true)
|
|
1547
|
+
this._retryClampedAdjustment()
|
|
1548
|
+
})
|
|
1549
|
+
})
|
|
1550
|
+
}
|
|
1451
1551
|
|
|
1452
1552
|
// Write a held correction once a write is possible, from the scroll
|
|
1453
|
-
// handler, the touch tail timer,
|
|
1454
|
-
//
|
|
1455
|
-
// notify
|
|
1456
|
-
//
|
|
1457
|
-
//
|
|
1458
|
-
// where
|
|
1553
|
+
// handler, the touch tail timer, the wheel timer, the frame at the top
|
|
1554
|
+
// (`_flushHoldAtTop`), a command's start, `_willUpdate` and a resize
|
|
1555
|
+
// notify. The rows go back to layout coordinates and the total grows by
|
|
1556
|
+
// the hold in a notify issued before the write, so the sizer can take the
|
|
1557
|
+
// position and both commit in the paint the write lands in. `sync` is
|
|
1558
|
+
// false only where the caller already runs inside the consumer's commit
|
|
1559
|
+
// (`_willUpdate`), where an update it schedules commits before paint
|
|
1560
|
+
// anyway. A command's start passes true, although `_willUpdate` can reach
|
|
1561
|
+
// it too (a follow on append).
|
|
1459
1562
|
private _flushHoldIfReady = (sync: boolean) => {
|
|
1460
1563
|
if (this._holdOffset === 0) return
|
|
1461
1564
|
if (!this.scrollElement || !this.options.enabled) return
|
|
@@ -1623,7 +1726,7 @@ export class Virtualizer<
|
|
|
1623
1726
|
this.scrollOffset =
|
|
1624
1727
|
this.scrollOffset ??
|
|
1625
1728
|
(typeof this.options.initialOffset === 'function'
|
|
1626
|
-
? this.options.initialOffset()
|
|
1729
|
+
? this.options.initialOffset(this)
|
|
1627
1730
|
: this.options.initialOffset)
|
|
1628
1731
|
|
|
1629
1732
|
return this.scrollOffset
|
|
@@ -2086,6 +2189,13 @@ export class Virtualizer<
|
|
|
2086
2189
|
resizeItem = (index: number, size: number) => {
|
|
2087
2190
|
if (!this.isIndexInRange(index)) return
|
|
2088
2191
|
|
|
2192
|
+
// Options can change before the next render rebuilds the measurements.
|
|
2193
|
+
// Use the current item position and estimate when deciding whether this
|
|
2194
|
+
// resize needs a scroll correction.
|
|
2195
|
+
if (this.getMeasurementOptions() !== this.builtMeasurementOptions) {
|
|
2196
|
+
this.getMeasurements()
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2089
2199
|
// An earlier entry in this ResizeObserver batch moved `scrollOffset`.
|
|
2090
2200
|
// Outside a batch its sync notify would have re-rendered and rebuilt the
|
|
2091
2201
|
// caches read below; rebuild them here so the anchoring check compares
|
|
@@ -2578,10 +2688,11 @@ export class Virtualizer<
|
|
|
2578
2688
|
// Every scroll command starts here: it becomes the in-flight command,
|
|
2579
2689
|
// writes its first target and leaves reconcile to retarget and retire it.
|
|
2580
2690
|
//
|
|
2581
|
-
// Targets are layout offsets. A held
|
|
2582
|
-
//
|
|
2583
|
-
//
|
|
2584
|
-
//
|
|
2691
|
+
// Targets are layout offsets. A correction held for the wheel is written
|
|
2692
|
+
// before the command (below). One held for a touch or a bounce is not
|
|
2693
|
+
// dropped by a command: the write lands the element `_holdOffset` short
|
|
2694
|
+
// of the target, under the rows exposed shifted by the same amount, and
|
|
2695
|
+
// the flush moves both together once a write is possible.
|
|
2585
2696
|
//
|
|
2586
2697
|
// An index or end target that is already at its offset starts a smooth
|
|
2587
2698
|
// scroll as landed; an offset target never does, so its first scroll
|
|
@@ -2592,6 +2703,18 @@ export class Virtualizer<
|
|
|
2592
2703
|
behavior: ScrollBehavior,
|
|
2593
2704
|
kind: 'absolute' | 'relative',
|
|
2594
2705
|
) {
|
|
2706
|
+
// The command takes over from the wheel: end the wheel hold and write
|
|
2707
|
+
// what it held first. The command is written `_holdOffset` short of its
|
|
2708
|
+
// target, so under a hold larger than the target the element clamps at
|
|
2709
|
+
// 0, the command never sees its target and the flush after it writes
|
|
2710
|
+
// the old position. The command this one replaces must not keep the
|
|
2711
|
+
// hold back (`_flushHoldIfReady` waits for a smooth one).
|
|
2712
|
+
if (this._wheelTimer !== null && this.targetWindow) {
|
|
2713
|
+
this.targetWindow.clearTimeout(this._wheelTimer)
|
|
2714
|
+
this._wheelTimer = null
|
|
2715
|
+
this.scrollState = null
|
|
2716
|
+
this._flushHoldIfReady(true)
|
|
2717
|
+
}
|
|
2595
2718
|
// A new explicit command supersedes layout-driven work queued before it.
|
|
2596
2719
|
// Clear both before any iOS deferral so a later commit/retry cannot
|
|
2597
2720
|
// overwrite the user's newer scroll intent.
|
package/src/ios-gesture.ts
CHANGED
|
@@ -43,9 +43,24 @@ export const iosMomentumOverridesWrites = (): boolean => {
|
|
|
43
43
|
export const momentumOverridesWrites = (): boolean =>
|
|
44
44
|
!isIOSWebKit() || iosMomentumOverridesWrites()
|
|
45
45
|
|
|
46
|
+
// Any WebKit: Safari, a WKWebView app, every browser on iOS. Chromium's
|
|
47
|
+
// user agent names AppleWebKit too, and so do jsdom's and happy-dom's, where
|
|
48
|
+
// a consumer's test must see the same writes as before. Cached like the iOS
|
|
49
|
+
// check; SSR-safe.
|
|
50
|
+
let _isWebKitResult: boolean | undefined
|
|
51
|
+
export const isWebKit = (): boolean => {
|
|
52
|
+
if (_isWebKitResult !== undefined) return _isWebKitResult
|
|
53
|
+
if (typeof navigator === 'undefined') return (_isWebKitResult = false)
|
|
54
|
+
const ua = navigator.userAgent
|
|
55
|
+
return (_isWebKitResult =
|
|
56
|
+
/AppleWebKit/.test(ua) &&
|
|
57
|
+
!/Chrome|Chromium|Android|jsdom|HappyDOM/.test(ua))
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
// Test hook: reset the iOS detection caches. Not exported.
|
|
47
61
|
export const _resetIOSDetectionForTests = () => {
|
|
48
62
|
_isIOSResult = undefined
|
|
63
|
+
_isWebKitResult = undefined
|
|
49
64
|
_iosMomentumOverridesWritesResult = undefined
|
|
50
65
|
}
|
|
51
66
|
|