@tanstack/virtual-core 3.19.8 → 3.19.10
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 +49 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +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.d.ts +1 -1
- package/dist/esm/index.js +50 -9
- 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 -25
- package/src/ios-gesture.ts +21 -8
package/dist/cjs/index.d.cts
CHANGED
|
@@ -169,7 +169,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
169
169
|
startIndex: number;
|
|
170
170
|
endIndex: number;
|
|
171
171
|
} | null;
|
|
172
|
-
updateDeps(newDeps: [VirtualItem[], number, number, number]): void;
|
|
172
|
+
updateDeps(newDeps: [VirtualItem[], number, number, number, number]): void;
|
|
173
173
|
};
|
|
174
174
|
getVirtualIndexes: {
|
|
175
175
|
(): number[];
|
package/dist/cjs/ios-gesture.cjs
CHANGED
|
@@ -15,6 +15,7 @@ const iosMomentumOverridesWrites = () => {
|
|
|
15
15
|
}
|
|
16
16
|
return _iosMomentumOverridesWritesResult = isIOSWebKit() && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("overflow-anchor: auto");
|
|
17
17
|
};
|
|
18
|
+
const momentumOverridesWrites = () => !isIOSWebKit() || iosMomentumOverridesWrites();
|
|
18
19
|
const _resetIOSDetectionForTests = () => {
|
|
19
20
|
_isIOSResult = void 0;
|
|
20
21
|
_iosMomentumOverridesWritesResult = void 0;
|
|
@@ -99,7 +100,7 @@ class IosGesture {
|
|
|
99
100
|
};
|
|
100
101
|
this._openTail = (moved, awaitingFling) => {
|
|
101
102
|
const win = this.host.getWindow();
|
|
102
|
-
if (
|
|
103
|
+
if (win == null) return;
|
|
103
104
|
this.end();
|
|
104
105
|
const tail = {
|
|
105
106
|
phase: "tail",
|
|
@@ -126,4 +127,5 @@ exports.IosGesture = IosGesture;
|
|
|
126
127
|
exports._resetIOSDetectionForTests = _resetIOSDetectionForTests;
|
|
127
128
|
exports.iosMomentumOverridesWrites = iosMomentumOverridesWrites;
|
|
128
129
|
exports.isIOSWebKit = isIOSWebKit;
|
|
130
|
+
exports.momentumOverridesWrites = momentumOverridesWrites;
|
|
129
131
|
//# sourceMappingURL=ios-gesture.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios-gesture.cjs","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 }\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,CAAC,YAAA,KAAiB,OAAO,KAAM;AACnC,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.cjs","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,WA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,aAAa,MAAM,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,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/index.d.ts
CHANGED
|
@@ -169,7 +169,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
|
|
|
169
169
|
startIndex: number;
|
|
170
170
|
endIndex: number;
|
|
171
171
|
} | null;
|
|
172
|
-
updateDeps(newDeps: [VirtualItem[], number, number, number]): void;
|
|
172
|
+
updateDeps(newDeps: [VirtualItem[], number, number, number, number]): void;
|
|
173
173
|
};
|
|
174
174
|
getVirtualIndexes: {
|
|
175
175
|
(): number[];
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLazyMeasurementsView, getMeasurementKey } from "./lazy-measurements.js";
|
|
2
2
|
import { memo, approxEqual, notUndefined, debounce } from "./utils.js";
|
|
3
3
|
import { flingCaught, externalRetiresCommand, flingSpedUp, classifyScrollEvent } from "./scroll-classifier.js";
|
|
4
|
-
import { IosGesture, isIOSWebKit,
|
|
4
|
+
import { IosGesture, isIOSWebKit, momentumOverridesWrites } from "./ios-gesture.js";
|
|
5
5
|
import { _resetIOSDetectionForTests } from "./ios-gesture.js";
|
|
6
6
|
const getRect = (element) => {
|
|
7
7
|
const { clientWidth, clientHeight } = element;
|
|
@@ -254,6 +254,9 @@ class Virtualizer {
|
|
|
254
254
|
this.observer = /* @__PURE__ */ (() => {
|
|
255
255
|
let _ro = null;
|
|
256
256
|
let _frames = null;
|
|
257
|
+
let delivering = false;
|
|
258
|
+
let observeQueued = false;
|
|
259
|
+
const pendingObservations = /* @__PURE__ */ new Set();
|
|
257
260
|
const get = () => {
|
|
258
261
|
if (_ro) {
|
|
259
262
|
return _ro;
|
|
@@ -276,10 +279,20 @@ class Virtualizer {
|
|
|
276
279
|
this._noteClampMax();
|
|
277
280
|
this._flushHoldIfReady(true);
|
|
278
281
|
this._retryClampedAdjustment();
|
|
282
|
+
this.measureElement(null);
|
|
279
283
|
}
|
|
280
284
|
}
|
|
281
285
|
};
|
|
282
|
-
this.options.useAnimationFrameWithResizeObserver
|
|
286
|
+
if (this.options.useAnimationFrameWithResizeObserver) {
|
|
287
|
+
frames.schedule(run);
|
|
288
|
+
} else {
|
|
289
|
+
delivering = true;
|
|
290
|
+
try {
|
|
291
|
+
run();
|
|
292
|
+
} finally {
|
|
293
|
+
delivering = false;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
283
296
|
});
|
|
284
297
|
};
|
|
285
298
|
const measureEntry = (entry) => {
|
|
@@ -305,16 +318,34 @@ class Virtualizer {
|
|
|
305
318
|
var _a;
|
|
306
319
|
(_a = get()) == null ? void 0 : _a.disconnect();
|
|
307
320
|
_frames == null ? void 0 : _frames.cancel();
|
|
321
|
+
pendingObservations.clear();
|
|
322
|
+
observeQueued = false;
|
|
308
323
|
_ro = null;
|
|
309
324
|
_frames = null;
|
|
310
325
|
},
|
|
311
326
|
observe: (target) => {
|
|
312
|
-
|
|
313
|
-
|
|
327
|
+
const observer = get();
|
|
328
|
+
if (!observer) return;
|
|
329
|
+
if (!delivering) {
|
|
330
|
+
observer.observe(target, { box: "border-box" });
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
pendingObservations.add(target);
|
|
334
|
+
if (!observeQueued) {
|
|
335
|
+
observeQueued = true;
|
|
336
|
+
_frames == null ? void 0 : _frames.schedule(() => {
|
|
337
|
+
observeQueued = false;
|
|
338
|
+
pendingObservations.forEach((node) => {
|
|
339
|
+
if (node.isConnected) _ro == null ? void 0 : _ro.observe(node, { box: "border-box" });
|
|
340
|
+
});
|
|
341
|
+
pendingObservations.clear();
|
|
342
|
+
});
|
|
343
|
+
}
|
|
314
344
|
},
|
|
315
345
|
unobserve: (target) => {
|
|
316
346
|
var _a;
|
|
317
|
-
|
|
347
|
+
pendingObservations.delete(target);
|
|
348
|
+
(_a = get()) == null ? void 0 : _a.unobserve(target);
|
|
318
349
|
}
|
|
319
350
|
};
|
|
320
351
|
})();
|
|
@@ -877,17 +908,21 @@ class Virtualizer {
|
|
|
877
908
|
this.getMeasurements(),
|
|
878
909
|
this.getSize(),
|
|
879
910
|
this.getScrollOffset(),
|
|
880
|
-
this.options.lanes
|
|
911
|
+
this.options.lanes,
|
|
912
|
+
// scrollOffset is measured in the scroll element and the layout total
|
|
913
|
+
// from the list start, so the list ends scrollMargin further down.
|
|
914
|
+
this._getLayoutTotalSize() + this.options.scrollMargin
|
|
881
915
|
],
|
|
882
|
-
(measurements, outerSize, scrollOffset, lanes) => {
|
|
916
|
+
(measurements, outerSize, scrollOffset, lanes, listEnd) => {
|
|
883
917
|
if (measurements.length === 0 || outerSize === 0) {
|
|
884
918
|
this.range = null;
|
|
885
919
|
return null;
|
|
886
920
|
}
|
|
921
|
+
const maxScrollOffset = Math.max(listEnd - outerSize, 0);
|
|
887
922
|
this.range = calculateRangeImpl(
|
|
888
923
|
measurements,
|
|
889
924
|
outerSize,
|
|
890
|
-
scrollOffset,
|
|
925
|
+
Math.min(scrollOffset, maxScrollOffset),
|
|
891
926
|
lanes,
|
|
892
927
|
// Pass the typed array so binary search + forward-walk can read
|
|
893
928
|
// start/end directly from Float64Array, skipping the Proxy traps.
|
|
@@ -1154,7 +1189,13 @@ class Virtualizer {
|
|
|
1154
1189
|
const property = this.options.horizontal ? "overflow-x" : "overflow-y";
|
|
1155
1190
|
const value = style.getPropertyValue(property);
|
|
1156
1191
|
const priority = style.getPropertyPriority(property);
|
|
1192
|
+
const crossSize = () => this.options.horizontal ? scroller.clientHeight : scroller.clientWidth;
|
|
1193
|
+
const crossSizeBefore = crossSize();
|
|
1157
1194
|
style.setProperty(property, "hidden", "important");
|
|
1195
|
+
if (crossSize() !== crossSizeBefore) {
|
|
1196
|
+
style.setProperty(property, value, priority);
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1158
1199
|
const stop = {
|
|
1159
1200
|
// False when the app replaced the hidden value: the fling may not
|
|
1160
1201
|
// have stopped.
|
|
@@ -1490,7 +1531,7 @@ class Virtualizer {
|
|
|
1490
1531
|
this._clampedAdjustment = null;
|
|
1491
1532
|
const tail = this._iosGesture.tail();
|
|
1492
1533
|
if (kind === "absolute" && tail !== null) {
|
|
1493
|
-
if (tail === "fling" &&
|
|
1534
|
+
if (tail === "fling" && momentumOverridesWrites()) {
|
|
1494
1535
|
this._stopMomentum(() => {
|
|
1495
1536
|
const state = this.scrollState;
|
|
1496
1537
|
if ((state == null ? void 0 : state.phase) !== "queued" || // A finger came down: it owns the scroll until it lifts.
|