@tanstack/virtual-core 3.19.7 → 3.19.9
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 +43 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/ios-gesture.cjs +3 -1
- package/dist/cjs/ios-gesture.cjs.map +1 -1
- package/dist/cjs/ios-gesture.d.cts +1 -0
- package/dist/esm/index.js +44 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ios-gesture.d.ts +1 -0
- package/dist/esm/ios-gesture.js +4 -2
- package/dist/esm/ios-gesture.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +79 -24
- package/src/ios-gesture.ts +21 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const isIOSWebKit: () => boolean;
|
|
2
2
|
export declare const iosMomentumOverridesWrites: () => boolean;
|
|
3
|
+
export declare const momentumOverridesWrites: () => boolean;
|
|
3
4
|
export declare const _resetIOSDetectionForTests: () => void;
|
|
4
5
|
type IosTouch = {
|
|
5
6
|
phase: 'down';
|
package/dist/esm/ios-gesture.js
CHANGED
|
@@ -13,6 +13,7 @@ const iosMomentumOverridesWrites = () => {
|
|
|
13
13
|
}
|
|
14
14
|
return _iosMomentumOverridesWritesResult = isIOSWebKit() && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("overflow-anchor: auto");
|
|
15
15
|
};
|
|
16
|
+
const momentumOverridesWrites = () => !isIOSWebKit() || iosMomentumOverridesWrites();
|
|
16
17
|
const _resetIOSDetectionForTests = () => {
|
|
17
18
|
_isIOSResult = void 0;
|
|
18
19
|
_iosMomentumOverridesWritesResult = void 0;
|
|
@@ -97,7 +98,7 @@ class IosGesture {
|
|
|
97
98
|
};
|
|
98
99
|
this._openTail = (moved, awaitingFling) => {
|
|
99
100
|
const win = this.host.getWindow();
|
|
100
|
-
if (
|
|
101
|
+
if (win == null) return;
|
|
101
102
|
this.end();
|
|
102
103
|
const tail = {
|
|
103
104
|
phase: "tail",
|
|
@@ -124,6 +125,7 @@ export {
|
|
|
124
125
|
IosGesture,
|
|
125
126
|
_resetIOSDetectionForTests,
|
|
126
127
|
iosMomentumOverridesWrites,
|
|
127
|
-
isIOSWebKit
|
|
128
|
+
isIOSWebKit,
|
|
129
|
+
momentumOverridesWrites
|
|
128
130
|
};
|
|
129
131
|
//# 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// 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, and after touchend on non-iOS, which arms no\n// tail. The tail record owns its timer: every replacement of the state goes\n// through `end`, which 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. On iOS 27\n // a fling's momentum overrides a write within a frame (see\n // `iosMomentumOverridesWrites`).\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. On non-iOS there is nothing to protect.\n private _openTail = (moved: boolean, awaitingFling: boolean) => {\n const win = this.host.getWindow()\n if (!isIOSWebKit() || 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,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AI,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// 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,UAAU,KAAK,OAAO;AAAA;AAK9D,SAAA,OAAO;AA1HT;AA2HI,yBAAK,WAAL,mBAAa,WAAU,SAAU,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,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;"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,11 +9,7 @@ import {
|
|
|
9
9
|
flingCaught,
|
|
10
10
|
flingSpedUp,
|
|
11
11
|
} from './scroll-classifier'
|
|
12
|
-
import {
|
|
13
|
-
IosGesture,
|
|
14
|
-
iosMomentumOverridesWrites,
|
|
15
|
-
isIOSWebKit,
|
|
16
|
-
} from './ios-gesture'
|
|
12
|
+
import { IosGesture, isIOSWebKit, momentumOverridesWrites } from './ios-gesture'
|
|
17
13
|
import type { ScrollPhase, ScrollSample } from './scroll-classifier'
|
|
18
14
|
|
|
19
15
|
export { _resetIOSDetectionForTests } from './ios-gesture'
|
|
@@ -642,6 +638,9 @@ export class Virtualizer<
|
|
|
642
638
|
private observer = (() => {
|
|
643
639
|
let _ro: ResizeObserver | null = null
|
|
644
640
|
let _frames: ReturnType<typeof createFrameQueue> | null = null
|
|
641
|
+
let delivering = false
|
|
642
|
+
let observeQueued = false
|
|
643
|
+
const pendingObservations = new Set<Element>()
|
|
645
644
|
|
|
646
645
|
const get = () => {
|
|
647
646
|
if (_ro) {
|
|
@@ -672,12 +671,23 @@ export class Virtualizer<
|
|
|
672
671
|
this._noteClampMax()
|
|
673
672
|
this._flushHoldIfReady(true)
|
|
674
673
|
this._retryClampedAdjustment()
|
|
674
|
+
// Ref-null callbacks run before the host nodes are detached.
|
|
675
|
+
// Drop them after the sync renders, before the browser gathers
|
|
676
|
+
// another round of ResizeObserver entries at their new depth.
|
|
677
|
+
this.measureElement(null)
|
|
675
678
|
}
|
|
676
679
|
}
|
|
677
680
|
}
|
|
678
|
-
this.options.useAnimationFrameWithResizeObserver
|
|
679
|
-
|
|
680
|
-
|
|
681
|
+
if (this.options.useAnimationFrameWithResizeObserver) {
|
|
682
|
+
frames.schedule(run)
|
|
683
|
+
} else {
|
|
684
|
+
delivering = true
|
|
685
|
+
try {
|
|
686
|
+
run()
|
|
687
|
+
} finally {
|
|
688
|
+
delivering = false
|
|
689
|
+
}
|
|
690
|
+
}
|
|
681
691
|
}))
|
|
682
692
|
}
|
|
683
693
|
|
|
@@ -715,12 +725,37 @@ export class Virtualizer<
|
|
|
715
725
|
disconnect: () => {
|
|
716
726
|
get()?.disconnect()
|
|
717
727
|
_frames?.cancel()
|
|
728
|
+
pendingObservations.clear()
|
|
729
|
+
observeQueued = false
|
|
718
730
|
_ro = null
|
|
719
731
|
_frames = null
|
|
720
732
|
},
|
|
721
|
-
observe: (target: Element) =>
|
|
722
|
-
|
|
723
|
-
|
|
733
|
+
observe: (target: Element) => {
|
|
734
|
+
const observer = get()
|
|
735
|
+
if (!observer) return
|
|
736
|
+
if (!delivering) {
|
|
737
|
+
observer.observe(target, { box: 'border-box' })
|
|
738
|
+
return
|
|
739
|
+
}
|
|
740
|
+
// A sync render can also mount rows at the depth being delivered.
|
|
741
|
+
// A microtask is still inside that delivery: register next frame,
|
|
742
|
+
// while measureElement continues to measure the new row immediately.
|
|
743
|
+
pendingObservations.add(target)
|
|
744
|
+
if (!observeQueued) {
|
|
745
|
+
observeQueued = true
|
|
746
|
+
_frames?.schedule(() => {
|
|
747
|
+
observeQueued = false
|
|
748
|
+
pendingObservations.forEach((node) => {
|
|
749
|
+
if (node.isConnected) _ro?.observe(node, { box: 'border-box' })
|
|
750
|
+
})
|
|
751
|
+
pendingObservations.clear()
|
|
752
|
+
})
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
unobserve: (target: Element) => {
|
|
756
|
+
pendingObservations.delete(target)
|
|
757
|
+
get()?.unobserve(target)
|
|
758
|
+
},
|
|
724
759
|
}
|
|
725
760
|
})()
|
|
726
761
|
range: { startIndex: number; endIndex: number } | null = null
|
|
@@ -2205,13 +2240,13 @@ export class Virtualizer<
|
|
|
2205
2240
|
return null
|
|
2206
2241
|
}
|
|
2207
2242
|
|
|
2208
|
-
// Stop a running
|
|
2209
|
-
//
|
|
2210
|
-
//
|
|
2211
|
-
//
|
|
2212
|
-
// Nothing moves on screen. A second call while one is in progress
|
|
2213
|
-
// for the same frames. The app's inline value comes back, unless the
|
|
2214
|
-
// set a new one meanwhile; `done` is then not called.
|
|
2243
|
+
// Stop a running fling, then call `done`: the momentum does not survive
|
|
2244
|
+
// the element losing its overflow for a frame. Hidden and restored within
|
|
2245
|
+
// one task, iOS never sees the change and the fling carries on (27.0.1
|
|
2246
|
+
// iPhone); hidden for two frames, it stops at once, there and in Chrome on
|
|
2247
|
+
// Android. Nothing moves on screen. A second call while one is in progress
|
|
2248
|
+
// waits for the same frames. The app's inline value comes back, unless the
|
|
2249
|
+
// app set a new one meanwhile; `done` is then not called.
|
|
2215
2250
|
private _momentumStop: { restore: () => boolean; done: () => void } | null =
|
|
2216
2251
|
null
|
|
2217
2252
|
private _stopMomentum = (done: () => void) => {
|
|
@@ -2231,7 +2266,17 @@ export class Virtualizer<
|
|
|
2231
2266
|
const property = this.options.horizontal ? 'overflow-x' : 'overflow-y'
|
|
2232
2267
|
const value = style.getPropertyValue(property)
|
|
2233
2268
|
const priority = style.getPropertyPriority(property)
|
|
2269
|
+
const crossSize = () =>
|
|
2270
|
+
this.options.horizontal ? scroller.clientHeight : scroller.clientWidth
|
|
2271
|
+
const crossSizeBefore = crossSize()
|
|
2234
2272
|
style.setProperty(property, 'hidden', 'important')
|
|
2273
|
+
// A classic scrollbar takes layout space, so hiding it would reflow the
|
|
2274
|
+
// content for two frames (a touchscreen laptop). Put it back before
|
|
2275
|
+
// anything paints and leave the command to the tail, as without a style.
|
|
2276
|
+
if (crossSize() !== crossSizeBefore) {
|
|
2277
|
+
style.setProperty(property, value, priority)
|
|
2278
|
+
return
|
|
2279
|
+
}
|
|
2235
2280
|
const stop = {
|
|
2236
2281
|
// False when the app replaced the hidden value: the fling may not
|
|
2237
2282
|
// have stopped.
|
|
@@ -2269,8 +2314,16 @@ export class Virtualizer<
|
|
|
2269
2314
|
}
|
|
2270
2315
|
|
|
2271
2316
|
private getVirtualDistanceFromEnd = () => {
|
|
2317
|
+
// `_getLayoutTotalSize()` measures the sizer, which starts `scrollMargin`
|
|
2318
|
+
// into the scroll content, while `getScrollOffset()` is measured from the
|
|
2319
|
+
// top of that content. Lift the total into the element's space before
|
|
2320
|
+
// subtracting, or the viewport reads `scrollMargin` px closer to the end
|
|
2321
|
+
// than it is and `getDistanceFromEnd()` disagrees by that much.
|
|
2272
2322
|
return Math.max(
|
|
2273
|
-
this._getLayoutTotalSize()
|
|
2323
|
+
this._getLayoutTotalSize() +
|
|
2324
|
+
this.options.scrollMargin -
|
|
2325
|
+
this.getSize() -
|
|
2326
|
+
this.getScrollOffset(),
|
|
2274
2327
|
0,
|
|
2275
2328
|
)
|
|
2276
2329
|
}
|
|
@@ -2443,11 +2496,13 @@ export class Virtualizer<
|
|
|
2443
2496
|
|
|
2444
2497
|
const tail = this._iosGesture.tail()
|
|
2445
2498
|
if (kind === 'absolute' && tail !== null) {
|
|
2446
|
-
if (tail === 'fling' &&
|
|
2447
|
-
//
|
|
2448
|
-
//
|
|
2449
|
-
//
|
|
2450
|
-
//
|
|
2499
|
+
if (tail === 'fling' && momentumOverridesWrites()) {
|
|
2500
|
+
// A write now would not end the fling: on iOS 27 it shows for one
|
|
2501
|
+
// frame and the fling carries on along its own path (#1307, step 3);
|
|
2502
|
+
// in Chrome on Android the fling carries on from the written
|
|
2503
|
+
// position. The command would be lost or overshot. Stop the fling
|
|
2504
|
+
// and write two frames later. Otherwise (no style to change, a
|
|
2505
|
+
// classic scrollbar, a finger down, a bounce) the tail stays open and
|
|
2451
2506
|
// the command is written when it closes, ~150ms after the last
|
|
2452
2507
|
// fling frame. The user taking over before the write (a drag, a
|
|
2453
2508
|
// second flick, a finger stopping the fling) cancels the command
|
package/src/ios-gesture.ts
CHANGED
|
@@ -32,6 +32,17 @@ export const iosMomentumOverridesWrites = (): boolean => {
|
|
|
32
32
|
CSS.supports('overflow-anchor: auto'))
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// Whether a touch fling survives a scrollTop write, so a command issued
|
|
36
|
+
// mid-fling has to stop the fling before it writes. Only iOS 26 and earlier
|
|
37
|
+
// stop the momentum on the write itself. Chrome on Android carries the fling
|
|
38
|
+
// on from the written position: on a Pixel 6 (Android 16, Chrome 156) a
|
|
39
|
+
// `scrollToIndex` issued 150ms into a fling wrote its target, then went on
|
|
40
|
+
// ~3,200px past it, 3 runs of 3. Other non-iOS engines are not measured; on
|
|
41
|
+
// one whose write does stop the fling, stopping it first costs the two
|
|
42
|
+
// frames of the stop.
|
|
43
|
+
export const momentumOverridesWrites = (): boolean =>
|
|
44
|
+
!isIOSWebKit() || iosMomentumOverridesWrites()
|
|
45
|
+
|
|
35
46
|
// Test hook: reset the iOS detection caches. Not exported.
|
|
36
47
|
export const _resetIOSDetectionForTests = () => {
|
|
37
48
|
_isIOSResult = undefined
|
|
@@ -52,9 +63,11 @@ const touchListenerOptions = {
|
|
|
52
63
|
// the whole gesture: `down` from touchstart to touchend/touchcancel, then
|
|
53
64
|
// `tail` while momentum runs. iOS fires no touch events during momentum, so
|
|
54
65
|
// every scroll event re-arms the tail and it closes ~150ms after the last
|
|
55
|
-
// one. Null between gestures
|
|
56
|
-
//
|
|
57
|
-
//
|
|
66
|
+
// one. Null between gestures. The tail is tracked on every platform, but
|
|
67
|
+
// only iOS defers anything through it; elsewhere it only tells a command
|
|
68
|
+
// that a fling may be running (`momentumOverridesWrites`). The tail record
|
|
69
|
+
// owns its timer: every replacement of the state goes through `end`, which
|
|
70
|
+
// clears it, so a live timer always has its record.
|
|
58
71
|
//
|
|
59
72
|
// `moved`: the content moved under or after the finger other than by our
|
|
60
73
|
// own write's read-back. While `down`, a scroll event that changed the
|
|
@@ -108,9 +121,9 @@ export class IosGesture {
|
|
|
108
121
|
// read-back will come. A resting finger does not: the write lands.
|
|
109
122
|
dragging = () => this._touch?.phase === 'down' && this._touch.moved
|
|
110
123
|
|
|
111
|
-
// The open tail, if any: after a tap, or after a drag or fling.
|
|
112
|
-
// a fling's momentum
|
|
113
|
-
// `
|
|
124
|
+
// The open tail, if any: after a tap, or after a drag or fling. Except on
|
|
125
|
+
// iOS 26 and earlier, a fling's momentum outlasts a write (see
|
|
126
|
+
// `momentumOverridesWrites`).
|
|
114
127
|
tail = (): 'tap' | 'fling' | null =>
|
|
115
128
|
this._touch?.phase === 'tail' ? (this._touch.moved ? 'fling' : 'tap') : null
|
|
116
129
|
|
|
@@ -203,10 +216,10 @@ export class IosGesture {
|
|
|
203
216
|
}
|
|
204
217
|
|
|
205
218
|
// (Re)open the tail after the finger lifts, closing ~150ms after the last
|
|
206
|
-
// touchend or momentum frame.
|
|
219
|
+
// touchend or momentum frame.
|
|
207
220
|
private _openTail = (moved: boolean, awaitingFling: boolean) => {
|
|
208
221
|
const win = this.host.getWindow()
|
|
209
|
-
if (
|
|
222
|
+
if (win == null) return
|
|
210
223
|
this.end()
|
|
211
224
|
const tail = {
|
|
212
225
|
phase: 'tail' as const,
|