@northgraindata/dsui 0.4.1 → 0.5.0

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.
Files changed (120) hide show
  1. package/bin/dsui.mjs +1 -1
  2. package/dist/plugin-sdk.mjs +1 -1
  3. package/dist/runtime/plugins/code-repository.browser.mjs +60 -0
  4. package/dist/runtime/plugins/code-repository.mjs +2 -2
  5. package/dist/runtime/plugins/example-plugin.mjs +1 -1
  6. package/dist/runtime/plugins/health.browser.mjs +202 -68
  7. package/dist/runtime/plugins/health.mjs +97 -6
  8. package/dist/runtime/plugins/monitoring.mjs +11 -1
  9. package/dist/runtime/plugins/status-pages.browser.mjs +5033 -0
  10. package/dist/runtime/plugins/status-pages.mjs +52 -0
  11. package/dist/server.mjs +205 -188
  12. package/package.json +1 -1
  13. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/components/input.tsx +2 -5
  14. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/components/suggest-input.tsx +197 -0
  15. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/index.tsx +5 -0
  16. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/styles.css +54 -0
  17. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs +3 -2
  18. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map +1 -1
  19. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js +3 -2
  20. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -1
  21. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/package.json +2 -2
  22. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/src/index.tsx +11 -2
  23. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs +79 -26
  24. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs.map +1 -1
  25. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.d.cts +12 -1
  26. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs +14 -2
  27. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs.map +1 -1
  28. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.d.cts +3 -2
  29. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.d.ts +12 -1
  30. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js +79 -26
  31. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -1
  32. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.d.ts +3 -2
  33. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +14 -2
  34. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -1
  35. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/package.json +1 -1
  36. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/index.ts +135 -24
  37. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/scroll-classifier.ts +31 -3
  38. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/define.ts +22 -1
  39. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/index.ts +1 -0
  40. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.test.ts +73 -0
  41. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.ts +34 -0
  42. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/types.ts +23 -0
  43. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/layout/gauge.tsx +14 -2
  44. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/dataset.test.ts +134 -0
  45. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/index.ts +141 -0
  46. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/index.ts +23 -0
  47. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs +3 -2
  48. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map +1 -1
  49. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js +3 -2
  50. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -1
  51. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/package.json +2 -2
  52. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/src/index.tsx +11 -2
  53. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs +79 -26
  54. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs.map +1 -1
  55. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.d.cts +12 -1
  56. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs +14 -2
  57. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs.map +1 -1
  58. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.d.cts +3 -2
  59. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.d.ts +12 -1
  60. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js +79 -26
  61. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -1
  62. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.d.ts +3 -2
  63. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +14 -2
  64. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -1
  65. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/package.json +1 -1
  66. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/index.ts +135 -24
  67. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/scroll-classifier.ts +31 -3
  68. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/define.ts +22 -1
  69. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/index.ts +1 -0
  70. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.test.ts +73 -0
  71. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.ts +34 -0
  72. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/types.ts +23 -0
  73. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/layout/gauge.tsx +14 -2
  74. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/dataset.test.ts +134 -0
  75. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/index.ts +141 -0
  76. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/index.ts +23 -0
  77. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs +3 -2
  78. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map +1 -1
  79. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js +3 -2
  80. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -1
  81. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/package.json +2 -2
  82. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/src/index.tsx +11 -2
  83. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs +79 -26
  84. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs.map +1 -1
  85. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.d.cts +12 -1
  86. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs +14 -2
  87. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs.map +1 -1
  88. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.d.cts +3 -2
  89. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.d.ts +12 -1
  90. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js +79 -26
  91. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -1
  92. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.d.ts +3 -2
  93. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +14 -2
  94. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -1
  95. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/package.json +1 -1
  96. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/src/index.ts +135 -24
  97. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/src/scroll-classifier.ts +31 -3
  98. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/package.json +2 -1
  99. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/diagnostics.ts +24 -0
  100. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/events.ts +6 -0
  101. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/index.ts +162 -2
  102. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/modal.test.ts +76 -0
  103. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/modal.ts +200 -0
  104. package/sdk/node_modules/@northgraindata/dsui-ui/src/components/input.tsx +2 -5
  105. package/sdk/node_modules/@northgraindata/dsui-ui/src/components/suggest-input.tsx +197 -0
  106. package/sdk/node_modules/@northgraindata/dsui-ui/src/index.tsx +5 -0
  107. package/sdk/node_modules/@northgraindata/dsui-ui/src/styles.css +54 -0
  108. package/web/assets/index-DQkPkPN7.css +1 -0
  109. package/web/assets/index-w07fgRf1.js +218 -0
  110. package/web/index.html +2 -2
  111. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/keyed-items.test.ts +0 -23
  112. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/column-profile.test.ts +0 -109
  113. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/query-explorer.test.ts +0 -29
  114. package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/table-data.test.ts +0 -65
  115. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/keyed-items.test.ts +0 -23
  116. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/column-profile.test.ts +0 -109
  117. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/query-explorer.test.ts +0 -29
  118. package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/table-data.test.ts +0 -65
  119. package/web/assets/index-BBd7EEtd.js +0 -98
  120. package/web/assets/index-C16grSph.css +0 -1
@@ -104,11 +104,15 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
104
104
  private _singleLaneMeasurements;
105
105
  itemSizeCache: Map<Key, number>;
106
106
  private itemSizeCacheVersion;
107
+ private builtMeasurementOptions;
108
+ private builtItemSizeCacheVersion;
109
+ private pendingResizes;
107
110
  private laneAssignments;
108
111
  private pendingMin;
109
112
  private prevLanes;
110
113
  private lanesChangedFlag;
111
114
  private lanesSettling;
115
+ private initialMeasurementsCacheApplied;
112
116
  private pendingScrollAnchor;
113
117
  scrollRect: Rect | null;
114
118
  /**
@@ -128,9 +132,12 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
128
132
  get scrollAdjustments(): number;
129
133
  private _holdOffset;
130
134
  private _reportedOverscroll;
135
+ private _trailing;
136
+ private _drawnListEnd;
131
137
  private _iosGesture;
132
138
  private _lastElementOffset;
133
139
  private pendingWrite;
140
+ private _ownWriteAt;
134
141
  private _clampedAdjustment;
135
142
  shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
136
143
  elementsCache: Map<Key, TItemElement>;
@@ -169,7 +176,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
169
176
  startIndex: number;
170
177
  endIndex: number;
171
178
  } | null;
172
- updateDeps(newDeps: [VirtualItem[], number, number, number, number]): void;
179
+ updateDeps(newDeps: [VirtualItem[], number, number, number, number, number]): void;
173
180
  };
174
181
  getVirtualIndexes: {
175
182
  (): number[];
@@ -183,6 +190,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
183
190
  */
184
191
  private shouldMeasureDuringScroll;
185
192
  measureElement: (node: TItemElement | null) => void;
193
+ private canShiftFromPendingResizes;
186
194
  resizeItem: (index: number, size: number) => void;
187
195
  getVirtualItems: {
188
196
  (): VirtualItem[];
@@ -192,6 +200,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
192
200
  private _noteClampMax;
193
201
  private getMaxScrollOffset;
194
202
  private _toLayoutOffset;
203
+ private _readTrailing;
195
204
  private _elementMaxScrollOffset;
196
205
  private _momentumStop;
197
206
  private _stopMomentum;
@@ -224,5 +233,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
224
233
  private getCommandWrittenOffset;
225
234
  private _awaitingCommandReadBack;
226
235
  private _followOffsetTarget;
236
+ private _landedBeforeAnchor;
237
+ private _followAnchor;
227
238
  measure: () => void;
228
239
  }
@@ -8,7 +8,8 @@ function classifyScrollEvent({
8
8
  holdOffset,
9
9
  scrollOffset,
10
10
  pendingWrite,
11
- clampedMaxAtWrite
11
+ clampedMaxAtWrite,
12
+ ownWriteAt
12
13
  }) {
13
14
  var _a;
14
15
  if (isScrolling && pendingWrite === null && offset === scrollOffset) {
@@ -26,6 +27,9 @@ function classifyScrollEvent({
26
27
  if (clampedMaxAtWrite !== null && Math.abs(offset - clampedMaxAtWrite) < 1.5) {
27
28
  return "clampedEcho";
28
29
  }
30
+ if (!isScrolling && ownWriteAt !== null && Math.abs(offset - ownWriteAt) < 1.5) {
31
+ return "restEcho";
32
+ }
29
33
  return "external";
30
34
  }
31
35
  const isAnimating = (phase) => phase === "smooth" || phase === "smoothFinishing";
@@ -35,6 +39,8 @@ function externalRetiresCommand({
35
39
  command,
36
40
  target
37
41
  }) {
42
+ let fresh;
43
+ const freshTarget = () => fresh ?? (fresh = target());
38
44
  return kind !== "spurious" && kind !== "readBack" && // Our own write, clamped (`clampedReadBack`, #1310): the command is not
39
45
  // retired by it, and reconcile retargets below the new max.
40
46
  kind !== "clampedReadBack" && (command == null ? void 0 : command.index) != null && // Nothing has been written for a command waiting for the tail; these
@@ -47,7 +53,13 @@ function externalRetiresCommand({
47
53
  // keeps it reconciling (#1294). While a smooth scroll's animation may
48
54
  // still report, its events look like a user's, so it yields only once it
49
55
  // has landed.
50
- !isAnimating(command.phase) && !utils.approxEqual(offset, command.lastTargetOffset) && !utils.approxEqual(offset, target()) && // A compensation write's clamped echo (#1258) keeps the command. The
56
+ !isAnimating(command.phase) && !utils.approxEqual(offset, command.lastTargetOffset) && !utils.approxEqual(offset, freshTarget()) && // Our own write reported again at rest (`restEcho`): nothing else has
57
+ // moved the element, but reconcile writes only a target that moved. Once
58
+ // the target has moved since the command wrote it, reconcile lands the
59
+ // command there (with `scrollend`, a correction's echo arrives before
60
+ // reconcile has run on the measurements behind it); while it has not,
61
+ // nothing will bring the element back, and the command ends here.
62
+ (kind !== "restEcho" || freshTarget() === command.lastTargetOffset) && // A compensation write's clamped echo (#1258) keeps the command. The
51
63
  // order is deliberate, not tidiness: this clause stays after `target()`
52
64
  // (and `clampedReadBack` before it) because `target()` can rebuild the
53
65
  // measurements, so it must run for exactly the events it always did.
@@ -1 +1 @@
1
- {"version":3,"file":"scroll-classifier.cjs","sources":["../../src/scroll-classifier.ts"],"sourcesContent":["import { approxEqual } from './utils'\n\n// Why a scroll event arrived, decided from the virtualizer's state as it was\n// before the event, before the scroll handler mutates anything. The first\n// match in this order wins:\n// spurious Safari/Firefox re-emit at the position we hold, nothing\n// pending\n// readBack our last write reporting back (within 1.5px of its\n// target)\n// clampedReadBack our last non-smooth write, clamped at the element's\n// current max or at a smaller max the layout passed\n// through since the write\n// clampedEcho a compensation write the browser clamped (#1258)\n// reporting at the max seen at write time\n// external anything else: the user, a fling, a smooth animation\n// frame\ntype ScrollEventKind =\n | 'spurious'\n | 'readBack'\n | 'clampedReadBack'\n | 'clampedEcho'\n | 'external'\n\nexport interface ScrollEventInput {\n // The reported position in layout coordinates (the element's offset plus\n // the held correction and a pending prepend anchor's delta).\n offset: number\n isScrolling: boolean\n // The element's own scroll max, read only while scrolling (null otherwise\n // or where it cannot be read).\n elementMax: number | null\n // How far the element sits behind the layout while a correction is held.\n holdOffset: number\n // The layout position the virtualizer holds.\n scrollOffset: number | null\n // Our last write to the element, until a scroll event reports it, with\n // the scroll maxima below its target the element had since (see\n // `lowMaxes` on `pendingWrite` in the virtualizer).\n pendingWrite: {\n target: number\n smooth: boolean\n lowMaxes?: Array<number>\n } | null\n // The element's max when a clamped compensation write was made (#1258),\n // or null when none is pending.\n clampedMaxAtWrite: number | null\n}\n\nexport function classifyScrollEvent({\n offset,\n isScrolling,\n elementMax,\n holdOffset,\n scrollOffset,\n pendingWrite,\n clampedMaxAtWrite,\n}: ScrollEventInput): ScrollEventKind {\n // A scroll event that reports movement but lands on the offset we already\n // hold — and isn't a self-write read-back — is a spurious no-op re-emit\n // that Safari/Firefox fire after a re-render's layout (Chrome doesn't).\n // Treating it as scrolling re-arms `isScrolling`, which forces a render\n // that triggers another such event: an infinite re-render loop.\n if (isScrolling && pendingWrite === null && offset === scrollOffset) {\n return 'spurious'\n }\n if (pendingWrite !== null && Math.abs(offset - pendingWrite.target) < 1.5) {\n return 'readBack'\n }\n // A non-smooth write past the element's max reads back at the max: ours,\n // clamped because the sizer shrank between the write and the report (rows\n // above the target measured smaller in a same-task render, #1310). The\n // element is where it says. A finger that drags to the max while such a\n // write is pending (iOS ignored it) is read the same way; the command then\n // retires at the next frame, its target clamped to the same max.\n if (\n pendingWrite !== null &&\n !pendingWrite.smooth &&\n elementMax !== null &&\n pendingWrite.target > elementMax + holdOffset + 0.5 &&\n Math.abs(offset - (elementMax + holdOffset)) < 1.5\n ) {\n return 'clampedReadBack'\n }\n // The same, clamped to a smaller max than the element's current one: the\n // sizer shrank below the target after the write (rows measured smaller,\n // a count change) and the browser clamped there, then it grew back, all\n // before the report. The clamp lands on one of those maxima; a position\n // between them is not one.\n if (\n pendingWrite !== null &&\n !pendingWrite.smooth &&\n pendingWrite.lowMaxes?.some((max) => Math.abs(offset - max) < 1.5)\n ) {\n return 'clampedReadBack'\n }\n if (\n clampedMaxAtWrite !== null &&\n Math.abs(offset - clampedMaxAtWrite) < 1.5\n ) {\n return 'clampedEcho'\n }\n return 'external'\n}\n\n// Where an in-flight scroll command is in its lifecycle, which decides how\n// its scroll events and measurements are read:\n// queued the first write waits for the momentum tail to close\n// (iOS 27, see `_startScroll`). Nothing has been written:\n// the fling's scroll events do not retire the command, a\n// drag does, and reconcile only keeps the safety valve\n// smooth a smooth animation is travelling to the target\n// smoothLanded a smooth scroll is at its target, waiting to retire\n// smoothFinishing a smooth scroll switched to instant writes for the\n// final approach; its animation can still report positions\n// instant instant writes\nexport type ScrollPhase =\n | 'queued'\n | 'smooth'\n | 'smoothLanded'\n | 'smoothFinishing'\n | 'instant'\n\n// The smooth animation may still be reporting positions, so a scroll event\n// that isn't the read-back of our own write may not be the user.\nconst isAnimating = (phase: ScrollPhase) =>\n phase === 'smooth' || phase === 'smoothFinishing'\n\nexport interface RetireInput {\n kind: ScrollEventKind\n // The reported position in layout coordinates, as classified.\n offset: number\n // The in-flight scroll command, or null.\n command: {\n index: number | null\n phase: ScrollPhase\n lastTargetOffset: number\n } | null\n // The command's target recomputed against the current layout. Called\n // only once every cheaper clause has passed, and at most once.\n target: () => number\n}\n\n// Whether a scroll event that is not the read-back of our own write retires\n// the in-flight index command: an external scroll moved away from its\n// target. Our own measurement updates (including clamped writes) still need\n// to reconcile.\nexport function externalRetiresCommand({\n kind,\n offset,\n command,\n target,\n}: RetireInput): boolean {\n return (\n kind !== 'spurious' &&\n kind !== 'readBack' &&\n // Our own write, clamped (`clampedReadBack`, #1310): the command is not\n // retired by it, and reconcile retargets below the new max.\n kind !== 'clampedReadBack' &&\n command?.index != null &&\n // Nothing has been written for a command waiting for the tail; these\n // are the fling's events.\n command.phase !== 'queued' &&\n // A non-smooth write lands at once, so any other scroll event is the\n // user's, even before reconcile saw the target reached (the target may\n // keep moving, or iOS ignored the write under a finger). A write the\n // browser clamped because the sizer hasn't grown yet reads back at the\n // max, which is also where the fresh target clamps, so the check below\n // keeps it reconciling (#1294). While a smooth scroll's animation may\n // still report, its events look like a user's, so it yields only once it\n // has landed.\n !isAnimating(command.phase) &&\n !approxEqual(offset, command.lastTargetOffset) &&\n !approxEqual(offset, target()) &&\n // A compensation write's clamped echo (#1258) keeps the command. The\n // order is deliberate, not tidiness: this clause stays after `target()`\n // (and `clampedReadBack` before it) because `target()` can rebuild the\n // measurements, so it must run for exactly the events it always did.\n kind !== 'clampedEcho'\n )\n}\n\n// A scroll position reported at a time, in the element's own coordinates.\nexport interface ScrollSample {\n t: number\n offset: number\n}\n\nconst FLING_WINDOW_MS = 40\n\n// Whether the scroll sped up: a finger flicked again or dragged on during a\n// fling. iOS fires no touch events for a touch that lands on a fling\n// (#1307), so this, and a turn against the fling, is all that shows it.\n// Momentum only slows down. Scroll events arrive 7–26ms apart and some\n// carry two frames, so one event can read 2–3× faster than its neighbours;\n// the speed is taken over the last 40ms and compared with the 40ms before.\n// On an iPhone (27.0.1) the flicks read 2.4–6× faster than the window before\n// and at least 1.5px/ms more, momentum alone at most 1.7× (#1307).\nexport function flingSpedUp(samples: ReadonlyArray<ScrollSample>): boolean {\n const last = samples[samples.length - 1]\n if (last === undefined) return false\n let j = samples.length - 2\n while (j >= 0 && last.t - samples[j]!.t < FLING_WINDOW_MS) j--\n if (j < 0) return false\n const mid = samples[j]!\n let k = j - 1\n while (k >= 0 && mid.t - samples[k]!.t < FLING_WINDOW_MS) k--\n if (k < 0) return false\n const first = samples[k]!\n const recent = (last.offset - mid.offset) / (last.t - mid.t)\n const before = (mid.offset - first.offset) / (mid.t - first.t)\n return (\n recent * before >= 0 &&\n Math.abs(recent) >= 2 * Math.abs(before) &&\n Math.abs(recent) - Math.abs(before) >= 0.8\n )\n}\n\n// Whether a fling that sent its last scroll event was still going at\n// 0.05px/ms or more over its last 40ms: a finger caught it. A fling that\n// ends on its own fades to at most 0.015px/ms first; taps stopped one at\n// 0.21–1.43px/ms (iPhones on 27.0.1, #1307). The finger stays down with no\n// touch events, and iOS undoes a write made under it. A tap in the last\n// pixels of a fling reads as its end.\nexport function flingCaught(samples: ReadonlyArray<ScrollSample>): boolean {\n const last = samples[samples.length - 1]\n if (last === undefined) return false\n let j = samples.length - 2\n while (j >= 0 && last.t - samples[j]!.t < FLING_WINDOW_MS) j--\n if (j < 0) return false\n const from = samples[j]!\n return Math.abs(last.offset - from.offset) / (last.t - from.t) >= 0.05\n}\n"],"names":["approxEqual"],"mappings":";;;AAgDO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsC;;AAMpC,MAAI,eAAe,iBAAiB,QAAQ,WAAW,cAAc;AACnE,WAAO;AAAA,EACT;AACA,MAAI,iBAAiB,QAAQ,KAAK,IAAI,SAAS,aAAa,MAAM,IAAI,KAAK;AACzE,WAAO;AAAA,EACT;AAOA,MACE,iBAAiB,QACjB,CAAC,aAAa,UACd,eAAe,QACf,aAAa,SAAS,aAAa,aAAa,OAChD,KAAK,IAAI,UAAU,aAAa,WAAW,IAAI,KAC/C;AACA,WAAO;AAAA,EACT;AAMA,MACE,iBAAiB,QACjB,CAAC,aAAa,YACd,kBAAa,aAAb,mBAAuB,KAAK,CAAC,QAAQ,KAAK,IAAI,SAAS,GAAG,IAAI,OAC9D;AACA,WAAO;AAAA,EACT;AACA,MACE,sBAAsB,QACtB,KAAK,IAAI,SAAS,iBAAiB,IAAI,KACvC;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAsBA,MAAM,cAAc,CAAC,UACnB,UAAU,YAAY,UAAU;AAqB3B,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,SACE,SAAS,cACT,SAAS;AAAA;AAAA,EAGT,SAAS,sBACT,mCAAS,UAAS;AAAA;AAAA,EAGlB,QAAQ,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,CAAC,YAAY,QAAQ,KAAK,KAC1B,CAACA,MAAAA,YAAY,QAAQ,QAAQ,gBAAgB,KAC7C,CAACA,MAAAA,YAAY,QAAQ,QAAQ;AAAA;AAAA;AAAA;AAAA,EAK7B,SAAS;AAEb;AAQA,MAAM,kBAAkB;AAUjB,SAAS,YAAY,SAA+C;AACzE,QAAM,OAAO,QAAQ,QAAQ,SAAS,CAAC;AACvC,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI,IAAI,QAAQ,SAAS;AACzB,SAAO,KAAK,KAAK,KAAK,IAAI,QAAQ,CAAC,EAAG,IAAI,gBAAiB;AAC3D,MAAI,IAAI,EAAG,QAAO;AAClB,QAAM,MAAM,QAAQ,CAAC;AACrB,MAAI,IAAI,IAAI;AACZ,SAAO,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,EAAG,IAAI,gBAAiB;AAC1D,MAAI,IAAI,EAAG,QAAO;AAClB,QAAM,QAAQ,QAAQ,CAAC;AACvB,QAAM,UAAU,KAAK,SAAS,IAAI,WAAW,KAAK,IAAI,IAAI;AAC1D,QAAM,UAAU,IAAI,SAAS,MAAM,WAAW,IAAI,IAAI,MAAM;AAC5D,SACE,SAAS,UAAU,KACnB,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,KACvC,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,KAAK;AAE3C;AAQO,SAAS,YAAY,SAA+C;AACzE,QAAM,OAAO,QAAQ,QAAQ,SAAS,CAAC;AACvC,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI,IAAI,QAAQ,SAAS;AACzB,SAAO,KAAK,KAAK,KAAK,IAAI,QAAQ,CAAC,EAAG,IAAI,gBAAiB;AAC3D,MAAI,IAAI,EAAG,QAAO;AAClB,QAAM,OAAO,QAAQ,CAAC;AACtB,SAAO,KAAK,IAAI,KAAK,SAAS,KAAK,MAAM,KAAK,KAAK,IAAI,KAAK,MAAM;AACpE;;;;;"}
1
+ {"version":3,"file":"scroll-classifier.cjs","sources":["../../src/scroll-classifier.ts"],"sourcesContent":["import { approxEqual } from './utils'\n\n// Why a scroll event arrived, decided from the virtualizer's state as it was\n// before the event, before the scroll handler mutates anything. The first\n// match in this order wins:\n// spurious Safari/Firefox re-emit at the position we hold, nothing\n// pending\n// readBack our last write reporting back (within 1.5px of its\n// target)\n// clampedReadBack our last non-smooth write, clamped at the element's\n// current max or at a smaller max the layout passed\n// through since the write\n// clampedEcho a compensation write the browser clamped (#1258)\n// reporting at the max seen at write time\n// restEcho our own write reported again at rest, where the last\n// scroll event reported it\n// external anything else: the user, a fling, a smooth animation\n// frame\ntype ScrollEventKind =\n | 'spurious'\n | 'readBack'\n | 'clampedReadBack'\n | 'clampedEcho'\n | 'restEcho'\n | 'external'\n\nexport interface ScrollEventInput {\n // The reported position in layout coordinates (the element's offset plus\n // the held correction and a pending prepend anchor's delta).\n offset: number\n isScrolling: boolean\n // The element's own scroll max, read only while scrolling (null otherwise\n // or where it cannot be read).\n elementMax: number | null\n // How far the element sits behind the layout while a correction is held.\n holdOffset: number\n // The layout position the virtualizer holds.\n scrollOffset: number | null\n // Our last write to the element, until a scroll event reports it, with\n // the scroll maxima below its target the element had since (see\n // `lowMaxes` on `pendingWrite` in the virtualizer).\n pendingWrite: {\n target: number\n smooth: boolean\n lowMaxes?: Array<number>\n } | null\n // The element's max when a clamped compensation write was made (#1258),\n // or null when none is pending.\n clampedMaxAtWrite: number | null\n // Where the last scroll event reported our own write (read back, clamped\n // or echoed), until a report anywhere else.\n ownWriteAt: number | null\n}\n\nexport function classifyScrollEvent({\n offset,\n isScrolling,\n elementMax,\n holdOffset,\n scrollOffset,\n pendingWrite,\n clampedMaxAtWrite,\n ownWriteAt,\n}: ScrollEventInput): ScrollEventKind {\n // A scroll event that reports movement but lands on the offset we already\n // hold — and isn't a self-write read-back — is a spurious no-op re-emit\n // that Safari/Firefox fire after a re-render's layout (Chrome doesn't).\n // Treating it as scrolling re-arms `isScrolling`, which forces a render\n // that triggers another such event: an infinite re-render loop.\n if (isScrolling && pendingWrite === null && offset === scrollOffset) {\n return 'spurious'\n }\n if (pendingWrite !== null && Math.abs(offset - pendingWrite.target) < 1.5) {\n return 'readBack'\n }\n // A non-smooth write past the element's max reads back at the max: ours,\n // clamped because the sizer shrank between the write and the report (rows\n // above the target measured smaller in a same-task render, #1310). The\n // element is where it says. A finger that drags to the max while such a\n // write is pending (iOS ignored it) is read the same way; the command then\n // retires at the next frame, its target clamped to the same max.\n if (\n pendingWrite !== null &&\n !pendingWrite.smooth &&\n elementMax !== null &&\n pendingWrite.target > elementMax + holdOffset + 0.5 &&\n Math.abs(offset - (elementMax + holdOffset)) < 1.5\n ) {\n return 'clampedReadBack'\n }\n // The same, clamped to a smaller max than the element's current one: the\n // sizer shrank below the target after the write (rows measured smaller,\n // a count change) and the browser clamped there, then it grew back, all\n // before the report. The clamp lands on one of those maxima; a position\n // between them is not one.\n if (\n pendingWrite !== null &&\n !pendingWrite.smooth &&\n pendingWrite.lowMaxes?.some((max) => Math.abs(offset - max) < 1.5)\n ) {\n return 'clampedReadBack'\n }\n if (\n clampedMaxAtWrite !== null &&\n Math.abs(offset - clampedMaxAtWrite) < 1.5\n ) {\n return 'clampedEcho'\n }\n // A write is reported again when the element comes to rest: `scrollend`\n // follows its scroll event in the same frame's scroll steps, before\n // reconcile; the fallback follows it after `isScrollingResetDelay`.\n // Nothing has moved the element in between.\n if (\n !isScrolling &&\n ownWriteAt !== null &&\n Math.abs(offset - ownWriteAt) < 1.5\n ) {\n return 'restEcho'\n }\n return 'external'\n}\n\n// Where an in-flight scroll command is in its lifecycle, which decides how\n// its scroll events and measurements are read:\n// queued the first write waits for the momentum tail to close\n// (iOS 27, see `_startScroll`). Nothing has been written:\n// the fling's scroll events do not retire the command, a\n// drag does, and reconcile only keeps the safety valve\n// smooth a smooth animation is travelling to the target\n// smoothLanded a smooth scroll is at its target, waiting to retire\n// smoothFinishing a smooth scroll switched to instant writes for the\n// final approach; its animation can still report positions\n// instant instant writes\nexport type ScrollPhase =\n | 'queued'\n | 'smooth'\n | 'smoothLanded'\n | 'smoothFinishing'\n | 'instant'\n\n// The smooth animation may still be reporting positions, so a scroll event\n// that isn't the read-back of our own write may not be the user.\nconst isAnimating = (phase: ScrollPhase) =>\n phase === 'smooth' || phase === 'smoothFinishing'\n\nexport interface RetireInput {\n kind: ScrollEventKind\n // The reported position in layout coordinates, as classified.\n offset: number\n // The in-flight scroll command, or null.\n command: {\n index: number | null\n phase: ScrollPhase\n lastTargetOffset: number\n } | null\n // The command's target recomputed against the current layout. Called\n // only once every cheaper clause has passed, and at most once.\n target: () => number\n}\n\n// Whether a scroll event that is not the read-back of our own write retires\n// the in-flight index command: an external scroll moved away from its\n// target, or our own write left the element where reconcile will not move\n// it. Our own measurement updates (including clamped writes) still need to\n// reconcile.\nexport function externalRetiresCommand({\n kind,\n offset,\n command,\n target,\n}: RetireInput): boolean {\n let fresh: number | undefined\n const freshTarget = () => (fresh ??= target())\n return (\n kind !== 'spurious' &&\n kind !== 'readBack' &&\n // Our own write, clamped (`clampedReadBack`, #1310): the command is not\n // retired by it, and reconcile retargets below the new max.\n kind !== 'clampedReadBack' &&\n command?.index != null &&\n // Nothing has been written for a command waiting for the tail; these\n // are the fling's events.\n command.phase !== 'queued' &&\n // A non-smooth write lands at once, so any other scroll event is the\n // user's, even before reconcile saw the target reached (the target may\n // keep moving, or iOS ignored the write under a finger). A write the\n // browser clamped because the sizer hasn't grown yet reads back at the\n // max, which is also where the fresh target clamps, so the check below\n // keeps it reconciling (#1294). While a smooth scroll's animation may\n // still report, its events look like a user's, so it yields only once it\n // has landed.\n !isAnimating(command.phase) &&\n !approxEqual(offset, command.lastTargetOffset) &&\n !approxEqual(offset, freshTarget()) &&\n // Our own write reported again at rest (`restEcho`): nothing else has\n // moved the element, but reconcile writes only a target that moved. Once\n // the target has moved since the command wrote it, reconcile lands the\n // command there (with `scrollend`, a correction's echo arrives before\n // reconcile has run on the measurements behind it); while it has not,\n // nothing will bring the element back, and the command ends here.\n (kind !== 'restEcho' || freshTarget() === command.lastTargetOffset) &&\n // A compensation write's clamped echo (#1258) keeps the command. The\n // order is deliberate, not tidiness: this clause stays after `target()`\n // (and `clampedReadBack` before it) because `target()` can rebuild the\n // measurements, so it must run for exactly the events it always did.\n kind !== 'clampedEcho'\n )\n}\n\n// A scroll position reported at a time, in the element's own coordinates.\nexport interface ScrollSample {\n t: number\n offset: number\n}\n\nconst FLING_WINDOW_MS = 40\n\n// Whether the scroll sped up: a finger flicked again or dragged on during a\n// fling. iOS fires no touch events for a touch that lands on a fling\n// (#1307), so this, and a turn against the fling, is all that shows it.\n// Momentum only slows down. Scroll events arrive 7–26ms apart and some\n// carry two frames, so one event can read 2–3× faster than its neighbours;\n// the speed is taken over the last 40ms and compared with the 40ms before.\n// On an iPhone (27.0.1) the flicks read 2.4–6× faster than the window before\n// and at least 1.5px/ms more, momentum alone at most 1.7× (#1307).\nexport function flingSpedUp(samples: ReadonlyArray<ScrollSample>): boolean {\n const last = samples[samples.length - 1]\n if (last === undefined) return false\n let j = samples.length - 2\n while (j >= 0 && last.t - samples[j]!.t < FLING_WINDOW_MS) j--\n if (j < 0) return false\n const mid = samples[j]!\n let k = j - 1\n while (k >= 0 && mid.t - samples[k]!.t < FLING_WINDOW_MS) k--\n if (k < 0) return false\n const first = samples[k]!\n const recent = (last.offset - mid.offset) / (last.t - mid.t)\n const before = (mid.offset - first.offset) / (mid.t - first.t)\n return (\n recent * before >= 0 &&\n Math.abs(recent) >= 2 * Math.abs(before) &&\n Math.abs(recent) - Math.abs(before) >= 0.8\n )\n}\n\n// Whether a fling that sent its last scroll event was still going at\n// 0.05px/ms or more over its last 40ms: a finger caught it. A fling that\n// ends on its own fades to at most 0.015px/ms first; taps stopped one at\n// 0.21–1.43px/ms (iPhones on 27.0.1, #1307). The finger stays down with no\n// touch events, and iOS undoes a write made under it. A tap in the last\n// pixels of a fling reads as its end.\nexport function flingCaught(samples: ReadonlyArray<ScrollSample>): boolean {\n const last = samples[samples.length - 1]\n if (last === undefined) return false\n let j = samples.length - 2\n while (j >= 0 && last.t - samples[j]!.t < FLING_WINDOW_MS) j--\n if (j < 0) return false\n const from = samples[j]!\n return Math.abs(last.offset - from.offset) / (last.t - from.t) >= 0.05\n}\n"],"names":["approxEqual"],"mappings":";;;AAsDO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsC;;AAMpC,MAAI,eAAe,iBAAiB,QAAQ,WAAW,cAAc;AACnE,WAAO;AAAA,EACT;AACA,MAAI,iBAAiB,QAAQ,KAAK,IAAI,SAAS,aAAa,MAAM,IAAI,KAAK;AACzE,WAAO;AAAA,EACT;AAOA,MACE,iBAAiB,QACjB,CAAC,aAAa,UACd,eAAe,QACf,aAAa,SAAS,aAAa,aAAa,OAChD,KAAK,IAAI,UAAU,aAAa,WAAW,IAAI,KAC/C;AACA,WAAO;AAAA,EACT;AAMA,MACE,iBAAiB,QACjB,CAAC,aAAa,YACd,kBAAa,aAAb,mBAAuB,KAAK,CAAC,QAAQ,KAAK,IAAI,SAAS,GAAG,IAAI,OAC9D;AACA,WAAO;AAAA,EACT;AACA,MACE,sBAAsB,QACtB,KAAK,IAAI,SAAS,iBAAiB,IAAI,KACvC;AACA,WAAO;AAAA,EACT;AAKA,MACE,CAAC,eACD,eAAe,QACf,KAAK,IAAI,SAAS,UAAU,IAAI,KAChC;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAsBA,MAAM,cAAc,CAAC,UACnB,UAAU,YAAY,UAAU;AAsB3B,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,MAAI;AACJ,QAAM,cAAc,MAAO,kBAAU,OAAA;AACrC,SACE,SAAS,cACT,SAAS;AAAA;AAAA,EAGT,SAAS,sBACT,mCAAS,UAAS;AAAA;AAAA,EAGlB,QAAQ,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASlB,CAAC,YAAY,QAAQ,KAAK,KAC1B,CAACA,MAAAA,YAAY,QAAQ,QAAQ,gBAAgB,KAC7C,CAACA,MAAAA,YAAY,QAAQ,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAOjC,SAAS,cAAc,kBAAkB,QAAQ;AAAA;AAAA;AAAA;AAAA,EAKlD,SAAS;AAEb;AAQA,MAAM,kBAAkB;AAUjB,SAAS,YAAY,SAA+C;AACzE,QAAM,OAAO,QAAQ,QAAQ,SAAS,CAAC;AACvC,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI,IAAI,QAAQ,SAAS;AACzB,SAAO,KAAK,KAAK,KAAK,IAAI,QAAQ,CAAC,EAAG,IAAI,gBAAiB;AAC3D,MAAI,IAAI,EAAG,QAAO;AAClB,QAAM,MAAM,QAAQ,CAAC;AACrB,MAAI,IAAI,IAAI;AACZ,SAAO,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,EAAG,IAAI,gBAAiB;AAC1D,MAAI,IAAI,EAAG,QAAO;AAClB,QAAM,QAAQ,QAAQ,CAAC;AACvB,QAAM,UAAU,KAAK,SAAS,IAAI,WAAW,KAAK,IAAI,IAAI;AAC1D,QAAM,UAAU,IAAI,SAAS,MAAM,WAAW,IAAI,IAAI,MAAM;AAC5D,SACE,SAAS,UAAU,KACnB,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,IAAI,MAAM,KACvC,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,KAAK;AAE3C;AAQO,SAAS,YAAY,SAA+C;AACzE,QAAM,OAAO,QAAQ,QAAQ,SAAS,CAAC;AACvC,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI,IAAI,QAAQ,SAAS;AACzB,SAAO,KAAK,KAAK,KAAK,IAAI,QAAQ,CAAC,EAAG,IAAI,gBAAiB;AAC3D,MAAI,IAAI,EAAG,QAAO;AAClB,QAAM,OAAO,QAAQ,CAAC;AACtB,SAAO,KAAK,IAAI,KAAK,SAAS,KAAK,MAAM,KAAK,KAAK,IAAI,KAAK,MAAM;AACpE;;;;;"}
@@ -1,4 +1,4 @@
1
- type ScrollEventKind = 'spurious' | 'readBack' | 'clampedReadBack' | 'clampedEcho' | 'external';
1
+ type ScrollEventKind = 'spurious' | 'readBack' | 'clampedReadBack' | 'clampedEcho' | 'restEcho' | 'external';
2
2
  export interface ScrollEventInput {
3
3
  offset: number;
4
4
  isScrolling: boolean;
@@ -11,8 +11,9 @@ export interface ScrollEventInput {
11
11
  lowMaxes?: Array<number>;
12
12
  } | null;
13
13
  clampedMaxAtWrite: number | null;
14
+ ownWriteAt: number | null;
14
15
  }
15
- export declare function classifyScrollEvent({ offset, isScrolling, elementMax, holdOffset, scrollOffset, pendingWrite, clampedMaxAtWrite, }: ScrollEventInput): ScrollEventKind;
16
+ export declare function classifyScrollEvent({ offset, isScrolling, elementMax, holdOffset, scrollOffset, pendingWrite, clampedMaxAtWrite, ownWriteAt, }: ScrollEventInput): ScrollEventKind;
16
17
  export type ScrollPhase = 'queued' | 'smooth' | 'smoothLanded' | 'smoothFinishing' | 'instant';
17
18
  export interface RetireInput {
18
19
  kind: ScrollEventKind;
@@ -104,11 +104,15 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
104
104
  private _singleLaneMeasurements;
105
105
  itemSizeCache: Map<Key, number>;
106
106
  private itemSizeCacheVersion;
107
+ private builtMeasurementOptions;
108
+ private builtItemSizeCacheVersion;
109
+ private pendingResizes;
107
110
  private laneAssignments;
108
111
  private pendingMin;
109
112
  private prevLanes;
110
113
  private lanesChangedFlag;
111
114
  private lanesSettling;
115
+ private initialMeasurementsCacheApplied;
112
116
  private pendingScrollAnchor;
113
117
  scrollRect: Rect | null;
114
118
  /**
@@ -128,9 +132,12 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
128
132
  get scrollAdjustments(): number;
129
133
  private _holdOffset;
130
134
  private _reportedOverscroll;
135
+ private _trailing;
136
+ private _drawnListEnd;
131
137
  private _iosGesture;
132
138
  private _lastElementOffset;
133
139
  private pendingWrite;
140
+ private _ownWriteAt;
134
141
  private _clampedAdjustment;
135
142
  shouldAdjustScrollPositionOnItemSizeChange: undefined | ((item: VirtualItem, delta: number, instance: Virtualizer<TScrollElement, TItemElement>) => boolean);
136
143
  elementsCache: Map<Key, TItemElement>;
@@ -169,7 +176,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
169
176
  startIndex: number;
170
177
  endIndex: number;
171
178
  } | null;
172
- updateDeps(newDeps: [VirtualItem[], number, number, number, number]): void;
179
+ updateDeps(newDeps: [VirtualItem[], number, number, number, number, number]): void;
173
180
  };
174
181
  getVirtualIndexes: {
175
182
  (): number[];
@@ -183,6 +190,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
183
190
  */
184
191
  private shouldMeasureDuringScroll;
185
192
  measureElement: (node: TItemElement | null) => void;
193
+ private canShiftFromPendingResizes;
186
194
  resizeItem: (index: number, size: number) => void;
187
195
  getVirtualItems: {
188
196
  (): VirtualItem[];
@@ -192,6 +200,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
192
200
  private _noteClampMax;
193
201
  private getMaxScrollOffset;
194
202
  private _toLayoutOffset;
203
+ private _readTrailing;
195
204
  private _elementMaxScrollOffset;
196
205
  private _momentumStop;
197
206
  private _stopMomentum;
@@ -224,5 +233,7 @@ export declare class Virtualizer<TScrollElement extends Element | Window, TItemE
224
233
  private getCommandWrittenOffset;
225
234
  private _awaitingCommandReadBack;
226
235
  private _followOffsetTarget;
236
+ private _landedBeforeAnchor;
237
+ private _followAnchor;
227
238
  measure: () => void;
228
239
  }
@@ -202,17 +202,23 @@ class Virtualizer {
202
202
  this._singleLaneMeasurements = null;
203
203
  this.itemSizeCache = /* @__PURE__ */ new Map();
204
204
  this.itemSizeCacheVersion = 0;
205
+ this.builtMeasurementOptions = null;
206
+ this.builtItemSizeCacheVersion = -1;
207
+ this.pendingResizes = [];
205
208
  this.laneAssignments = /* @__PURE__ */ new Map();
206
209
  this.pendingMin = null;
207
210
  this.prevLanes = void 0;
208
211
  this.lanesChangedFlag = false;
209
212
  this.lanesSettling = false;
213
+ this.initialMeasurementsCacheApplied = false;
210
214
  this.pendingScrollAnchor = null;
211
215
  this.scrollRect = null;
212
216
  this.scrollOffset = null;
213
217
  this.scrollDirection = null;
214
218
  this._holdOffset = 0;
215
219
  this._reportedOverscroll = false;
220
+ this._trailing = 0;
221
+ this._drawnListEnd = Infinity;
216
222
  this._iosGesture = new IosGesture({
217
223
  getWindow: () => this.targetWindow,
218
224
  now: () => this.now(),
@@ -247,6 +253,7 @@ class Virtualizer {
247
253
  });
248
254
  this._lastElementOffset = null;
249
255
  this.pendingWrite = null;
256
+ this._ownWriteAt = null;
250
257
  this._clampedAdjustment = null;
251
258
  this.elementsCache = /* @__PURE__ */ new Map();
252
259
  this._resizeBatch = null;
@@ -455,7 +462,7 @@ class Virtualizer {
455
462
  this.pendingScrollAnchor = { kind: "anchor", delta: anchorDelta };
456
463
  } else {
457
464
  this._holdOffset += anchorDelta;
458
- this._followOffsetTarget(anchorDelta);
465
+ this._followAnchor(anchorDelta);
459
466
  }
460
467
  }
461
468
  };
@@ -501,8 +508,10 @@ class Virtualizer {
501
508
  this.scrollDirection = null;
502
509
  this._holdOffset = 0;
503
510
  this._reportedOverscroll = false;
511
+ this._trailing = 0;
504
512
  this._clampedAdjustment = null;
505
513
  this.pendingWrite = null;
514
+ this._ownWriteAt = null;
506
515
  this.scrollElement = null;
507
516
  this.targetWindow = null;
508
517
  };
@@ -539,6 +548,7 @@ class Virtualizer {
539
548
  this.options.observeElementOffset(this, (offset, isScrolling) => {
540
549
  var _a2, _b, _c, _d;
541
550
  const elementMax = isScrolling ? this._elementMaxScrollOffset() : null;
551
+ this._readTrailing(elementMax);
542
552
  const wasOverscrolled = this._reportedOverscroll;
543
553
  this._reportedOverscroll = offset < 0 || elementMax !== null && offset > elementMax + 1;
544
554
  const elementOffset = offset;
@@ -564,6 +574,11 @@ class Virtualizer {
564
574
  this.scrollState = null;
565
575
  }
566
576
  this.pendingWrite = null;
577
+ if (kind === "readBack" || kind === "clampedReadBack" || kind === "clampedEcho") {
578
+ this._ownWriteAt = offset;
579
+ } else if (kind !== "restEcho") {
580
+ this._ownWriteAt = null;
581
+ }
567
582
  if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
568
583
  this._clampedAdjustment = null;
569
584
  }
@@ -614,6 +629,8 @@ class Virtualizer {
614
629
  );
615
630
  }
616
631
  this._scrollToOffset(this.getScrollOffset());
632
+ this._readTrailing(this._elementMaxScrollOffset());
633
+ this.maybeNotify();
617
634
  }
618
635
  this._noteClampMax();
619
636
  const anchor = this.pendingScrollAnchor;
@@ -622,14 +639,11 @@ class Virtualizer {
622
639
  if (anchor.kind === "anchor") {
623
640
  if (!this._canWriteScroll()) {
624
641
  this._holdOffset += anchor.delta;
625
- this._followOffsetTarget(anchor.delta);
642
+ this._followAnchor(anchor.delta);
626
643
  this.notify(false);
627
- } else if (isSmoothScroll(this.scrollState) && !approxEqual(
628
- this.getScrollOffset() - anchor.delta,
629
- this.scrollState.lastTargetOffset
630
- )) ;
644
+ } else if (isSmoothScroll(this.scrollState) && !this._landedBeforeAnchor(this.scrollState, anchor.delta)) ;
631
645
  else {
632
- this._followOffsetTarget(anchor.delta);
646
+ this._followAnchor(anchor.delta);
633
647
  this._scrollToOffset(this.getScrollOffset());
634
648
  }
635
649
  } else {
@@ -648,7 +662,8 @@ class Virtualizer {
648
662
  holdOffset: this._holdOffset,
649
663
  scrollOffset: this.scrollOffset,
650
664
  pendingWrite: this.pendingWrite,
651
- clampedMaxAtWrite: ((_a = this._clampedAdjustment) == null ? void 0 : _a.maxAtWrite) ?? null
665
+ clampedMaxAtWrite: ((_a = this._clampedAdjustment) == null ? void 0 : _a.maxAtWrite) ?? null,
666
+ ownWriteAt: this._ownWriteAt
652
667
  });
653
668
  };
654
669
  this._retryClampedAdjustment = () => {
@@ -758,23 +773,28 @@ class Virtualizer {
758
773
  this.isIndexInRange = (index) => index >= 0 && index < this.options.count;
759
774
  this.getMeasurements = memo(
760
775
  () => [this.getMeasurementOptions(), this.itemSizeCacheVersion],
761
- ({
762
- count,
763
- paddingStart,
764
- scrollMargin,
765
- getItemKey,
766
- enabled,
767
- lanes,
768
- laneAssignmentMode,
769
- gap
770
- }, _itemSizeCacheVersion) => {
776
+ (measurementOptions, itemSizeCacheVersion) => {
771
777
  var _a;
778
+ const {
779
+ count,
780
+ paddingStart,
781
+ scrollMargin,
782
+ getItemKey,
783
+ enabled,
784
+ lanes,
785
+ laneAssignmentMode,
786
+ gap
787
+ } = measurementOptions;
788
+ this.builtMeasurementOptions = measurementOptions;
789
+ this.builtItemSizeCacheVersion = itemSizeCacheVersion;
790
+ this.pendingResizes = [];
772
791
  const itemSizeCache = this.itemSizeCache;
773
792
  if (!enabled) {
774
793
  this.measurementsCache = [];
775
794
  this._singleLaneMeasurements = null;
776
795
  this.itemSizeCache.clear();
777
796
  this.laneAssignments.clear();
797
+ this.initialMeasurementsCacheApplied = false;
778
798
  return [];
779
799
  }
780
800
  if (this.laneAssignments.size > count) {
@@ -793,7 +813,8 @@ class Virtualizer {
793
813
  this.laneAssignments.clear();
794
814
  this.pendingMin = null;
795
815
  }
796
- if (this.measurementsCache.length === 0 && !this.lanesSettling) {
816
+ if (!this.initialMeasurementsCacheApplied && this.measurementsCache.length === 0 && !this.lanesSettling) {
817
+ this.initialMeasurementsCacheApplied = true;
797
818
  this.measurementsCache = this.options.initialMeasurementsCache;
798
819
  this.measurementsCache.forEach((item) => {
799
820
  this.itemSizeCache.set(item.key, item.size);
@@ -914,14 +935,15 @@ class Virtualizer {
914
935
  this.options.lanes,
915
936
  // scrollOffset is measured in the scroll element and the layout total
916
937
  // from the list start, so the list ends scrollMargin further down.
917
- this._getLayoutTotalSize() + this.options.scrollMargin
938
+ this._getLayoutTotalSize() + this.options.scrollMargin,
939
+ this._trailing
918
940
  ],
919
- (measurements, outerSize, scrollOffset, lanes, listEnd) => {
941
+ (measurements, outerSize, scrollOffset, lanes, listEnd, trailing) => {
920
942
  if (measurements.length === 0 || outerSize === 0) {
921
943
  this.range = null;
922
944
  return null;
923
945
  }
924
- const maxScrollOffset = Math.max(listEnd - outerSize, 0);
946
+ const maxScrollOffset = Math.max(listEnd + trailing - outerSize, 0);
925
947
  this.range = calculateRangeImpl(
926
948
  measurements,
927
949
  outerSize,
@@ -1027,17 +1049,27 @@ class Virtualizer {
1027
1049
  this.resizeItem(index, this.options.measureElement(node, void 0, this));
1028
1050
  }
1029
1051
  };
1052
+ this.canShiftFromPendingResizes = () => this.options.lanes === 1 && this._singleLaneMeasurements !== null && this.shouldAdjustScrollPositionOnItemSizeChange === void 0 && !this.lanesChangedFlag && !this.lanesSettling && this.getMeasurementOptions() === this.builtMeasurementOptions && this.itemSizeCacheVersion === this.builtItemSizeCacheVersion + this.pendingResizes.length;
1030
1053
  this.resizeItem = (index, size) => {
1031
1054
  var _a, _b, _c;
1032
1055
  if (!this.isIndexInRange(index)) return;
1033
- if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) this.getMeasurements();
1056
+ let startShift = 0;
1057
+ if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) {
1058
+ if (this.canShiftFromPendingResizes()) {
1059
+ for (const resize of this.pendingResizes) {
1060
+ if (resize.index < index) startShift += resize.delta;
1061
+ }
1062
+ } else {
1063
+ this.getMeasurements();
1064
+ }
1065
+ }
1034
1066
  let cachedSize;
1035
1067
  let itemStart;
1036
1068
  let key;
1037
1069
  const flat = (_b = this._singleLaneMeasurements) == null ? void 0 : _b.flat;
1038
1070
  if (this.options.lanes === 1 && flat != null) {
1039
1071
  key = this.options.getItemKey(index);
1040
- itemStart = flat[index * 2];
1072
+ itemStart = flat[index * 2] + startShift;
1041
1073
  cachedSize = flat[index * 2 + 1];
1042
1074
  } else {
1043
1075
  const item = this.measurementsCache[index];
@@ -1087,6 +1119,7 @@ class Virtualizer {
1087
1119
  }
1088
1120
  this.itemSizeCache.set(key, size);
1089
1121
  this.itemSizeCacheVersion++;
1122
+ this.pendingResizes.push({ index, delta });
1090
1123
  let adjustedSync = false;
1091
1124
  if (!this._awaitingCommandReadBack()) {
1092
1125
  if (wasAtEnd) {
@@ -1106,6 +1139,9 @@ class Virtualizer {
1106
1139
  this._noteClampMax();
1107
1140
  this._flushHoldIfReady(true);
1108
1141
  this._retryClampedAdjustment();
1142
+ } else if (this.options.lanes > 1 && !this.options.useCachedMeasurements && !this.laneAssignments.has(index)) {
1143
+ const item = this.getMeasurements()[index];
1144
+ if (item) this.laneAssignments.set(index, item.lane);
1109
1145
  }
1110
1146
  };
1111
1147
  this.getVirtualItems = memo(
@@ -1165,6 +1201,11 @@ class Virtualizer {
1165
1201
  }
1166
1202
  return offset;
1167
1203
  };
1204
+ this._readTrailing = (elementMax) => {
1205
+ if (elementMax === null) return;
1206
+ const trailing = elementMax + this.getSize() - this._drawnListEnd;
1207
+ this._trailing = trailing > 0 ? trailing : 0;
1208
+ };
1168
1209
  this._elementMaxScrollOffset = () => {
1169
1210
  const el = this.scrollElement;
1170
1211
  if (el === null) return null;
@@ -1330,13 +1371,17 @@ class Virtualizer {
1330
1371
  }
1331
1372
  this.scrollState = null;
1332
1373
  };
1333
- this.getTotalSize = () => Math.max(this._getLayoutTotalSize() - this._holdOffset, 0);
1374
+ this.getTotalSize = () => {
1375
+ const total = Math.max(this._getLayoutTotalSize() - this._holdOffset, 0);
1376
+ this._drawnListEnd = total + this.options.scrollMargin;
1377
+ return total;
1378
+ };
1334
1379
  this._getLayoutTotalSize = () => {
1335
1380
  var _a, _b;
1336
1381
  const measurements = this.getMeasurements();
1337
1382
  let end;
1338
1383
  if (measurements.length === 0) {
1339
- end = this.options.paddingStart;
1384
+ end = this.options.scrollMargin + this.options.paddingStart;
1340
1385
  } else if (this.options.lanes === 1) {
1341
1386
  const lastIdx = measurements.length - 1;
1342
1387
  const flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
@@ -1406,6 +1451,14 @@ class Virtualizer {
1406
1451
  this.scrollState.lastTargetOffset += delta;
1407
1452
  }
1408
1453
  };
1454
+ this._landedBeforeAnchor = (state, delta) => state.phase !== "queued" && (state.stableFrames > 0 || approxEqual(this.getScrollOffset() - delta, state.lastTargetOffset));
1455
+ this._followAnchor = (delta) => {
1456
+ this._followOffsetTarget(delta);
1457
+ const state = this.scrollState;
1458
+ if ((state == null ? void 0 : state.index) != null && !state.toEnd && this._landedBeforeAnchor(state, delta)) {
1459
+ this.scrollState = null;
1460
+ }
1461
+ };
1409
1462
  this.measure = () => {
1410
1463
  this.pendingMin = null;
1411
1464
  this.itemSizeCache.clear();