@astryxdesign/lab 0.7.14-canary.gfdb9213 → 0.7.15-canary.g79b95eb

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ChatVirtualizer.d.ts","sourceRoot":"","sources":["../../src/Chat/ChatVirtualizer.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA8F/B,8EAA8E;AAC9E,MAAM,WAAW,qBAAqB;IACpC,mEAAmE;IACnE,4BAA4B,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD;;;;;;;;OAQG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,2EAA2E;IAC3E,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;IACnB;;;;OAIG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,UAAU,EAAE,CAAC,IAAI,EAAE;QAAC,IAAI,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,KAAK,KAAK,CAAC,SAAS,CAAC;IAChE;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IAClE,2DAA2D;IAC3D,SAAS,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC7C;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACjD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,aAAa,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiBD,wBAAgB,eAAe,CAAC,CAAC,EAC/B,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC7B,KAAK,CAAC,SAAS,CAm4CjB"}
1
+ {"version":3,"file":"ChatVirtualizer.d.ts","sourceRoot":"","sources":["../../src/Chat/ChatVirtualizer.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkG/B,8EAA8E;AAC9E,MAAM,WAAW,qBAAqB;IACpC,mEAAmE;IACnE,4BAA4B,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD;;;;;;;;OAQG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,2EAA2E;IAC3E,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC;IACnB;;;;OAIG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,UAAU,EAAE,CAAC,IAAI,EAAE;QAAC,IAAI,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,KAAK,KAAK,CAAC,SAAS,CAAC;IAChE;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IAClE,2DAA2D;IAC3D,SAAS,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC7C;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACjD;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,aAAa,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAiBD,wBAAgB,eAAe,CAAC,CAAC,EAC/B,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC7B,KAAK,CAAC,SAAS,CAk9CjB"}
@@ -79,6 +79,10 @@ const addViewportProbe = doc => {
79
79
  return probe;
80
80
  };
81
81
 
82
+ // A scroll soon after a window resize, with no finger, is the browser's.
83
+ // Safari's last rotation scroll lands inside this time. Reader input ends it.
84
+ const VIEWPORT_SETTLE_MS = 500;
85
+
82
86
  // While a finger scroll ends in an elastic overscroll, a write would snap the
83
87
  // bounce onto the clamp; the flush waits a frame at a time until it is over.
84
88
  const isBouncing = vp => vp.scrollTop < 0 || vp.scrollTop > Math.max(0, vp.scrollHeight - vp.clientHeight) + 1;
@@ -212,6 +216,15 @@ export function ChatVirtualizer(props) {
212
216
  // passes run between two scroll events, and clearing per pass re-created
213
217
  // the staleness class mid-gesture (measured: 5.2% jitter at 60px steps).
214
218
  const userScrolledRef = React.useRef(false);
219
+ // A rotating phone moves the page's scrollTop to keep the reader's place.
220
+ // The new row heights are not measured yet. Safari can move it before the
221
+ // resize event or after the pass. The list restores the held row instead,
222
+ // with at most one extra pass before the viewport's pass and one after it.
223
+ const isPageViewport = React.useRef(false);
224
+ const viewportChangedAt = React.useRef(-Infinity);
225
+ const passViewportHeight = React.useRef(null);
226
+ const isRestoreArmed = React.useRef(false);
227
+ const restoreFrame = React.useRef(null);
215
228
  // Last scrollTop observed by a scroll event, and the px the user has moved
216
229
  // away from where the machinery last placed them — the end→anchor decision
217
230
  // runs on the latter (see onScroll).
@@ -603,6 +616,11 @@ export function ChatVirtualizer(props) {
603
616
  // where the content starts, and rows not measured yet (below).
604
617
  const vp = readViewport(el);
605
618
  const entryScrollTop = vp.scrollTop;
619
+ if (isPageViewport.current && passViewportHeight.current !== null && vp.clientHeight !== passViewportHeight.current) {
620
+ // A browser scroll write can still follow this viewport pass.
621
+ isRestoreArmed.current = true;
622
+ }
623
+ passViewportHeight.current = vp.clientHeight;
606
624
  measureOrigin(el, vp);
607
625
  // Refresh the anchor from the LIVE scrollTop against the pre-measure
608
626
  // geometry (= what's currently painted). scroll events lag rAF-driven
@@ -1031,7 +1049,24 @@ export function ChatVirtualizer(props) {
1031
1049
  // and against the previous event's value that net can still read as
1032
1050
  // "moved down" — the user's own upward step erased by the re-pin.
1033
1051
  const lastWrite = progTarget.current;
1034
- const isEcho = lastWrite !== null && Math.abs(vp.scrollTop - lastWrite) <= 1;
1052
+ // A finger owns the position even while the viewport changes size.
1053
+ // The browser writes its scroll for a viewport change before that
1054
+ // change's pass, at a height the pass has not read, or once soon after it.
1055
+ // The list's own write is neither. Any other scroll is the reader's.
1056
+ const isOwnEcho = lastWrite !== null && Math.abs(vp.scrollTop - lastWrite) <= 1;
1057
+ const isViewportMove = isPageViewport.current && !isFingerScroll() && !isOwnEcho && (passViewportHeight.current !== null && vp.clientHeight !== passViewportHeight.current || isRestoreArmed.current && performance.now() - viewportChangedAt.current < VIEWPORT_SETTLE_MS);
1058
+ const isEcho = isViewportMove || isOwnEcho;
1059
+ if (isViewportMove) {
1060
+ userScrolledRef.current = false;
1061
+ if (isRestoreArmed.current && restoreFrame.current === null) {
1062
+ isRestoreArmed.current = false;
1063
+ geoChanged.current = true;
1064
+ restoreFrame.current = requestAnimationFrame(() => {
1065
+ restoreFrame.current = null;
1066
+ syncRef.current();
1067
+ });
1068
+ }
1069
+ }
1035
1070
  // STICKY echo: k offset changes within one frame queue up to k scroll
1036
1071
  // events, dispatched across successive frames, EACH reading the same
1037
1072
  // final scrollTop. A consume-once slot matches the first and misreads
@@ -1148,9 +1183,15 @@ export function ChatVirtualizer(props) {
1148
1183
  // Whether the container moved is what onScroll measures, against the
1149
1184
  // position the machinery last wrote, so a wheel the next write outruns
1150
1185
  // still shows there.
1186
+ // Reader input ends the time in which a scroll counts as the browser's.
1187
+ const endViewportMove = () => {
1188
+ viewportChangedAt.current = -Infinity;
1189
+ isRestoreArmed.current = false;
1190
+ };
1151
1191
  const onWheel = () => {
1152
1192
  converging.current = false;
1153
1193
  priceFreeze.current = false;
1194
+ endViewportMove();
1154
1195
  };
1155
1196
  setScrollAnchoringOff(el, true);
1156
1197
  const scrollHandler = () => onScrollRef.current();
@@ -1170,6 +1211,28 @@ export function ChatVirtualizer(props) {
1170
1211
  if (viewportProbe !== null) {
1171
1212
  observeSize(viewportProbe);
1172
1213
  }
1214
+ // Capture phase: a key whose handler stops propagation still scrolls.
1215
+ const doc = el.ownerDocument;
1216
+ if (viewportProbe !== null) {
1217
+ doc.addEventListener('keydown', endViewportMove, {
1218
+ capture: true,
1219
+ passive: true
1220
+ });
1221
+ doc.addEventListener('pointerdown', endViewportMove, {
1222
+ capture: true,
1223
+ passive: true
1224
+ });
1225
+ }
1226
+ isPageViewport.current = viewportProbe !== null;
1227
+ const view = viewportProbe !== null ? el.ownerDocument.defaultView : null;
1228
+ // Reads nothing.
1229
+ const onViewportResize = () => {
1230
+ viewportChangedAt.current = performance.now();
1231
+ isRestoreArmed.current = true;
1232
+ };
1233
+ view?.addEventListener('resize', onViewportResize, {
1234
+ passive: true
1235
+ });
1173
1236
  // Observe the CONTAINER too (rows alone miss clientHeight changes): a
1174
1237
  // window resize or a growing composer moves the end-mode target and the
1175
1238
  // window coverage without any row changing size. Container entries have
@@ -1179,10 +1242,25 @@ export function ChatVirtualizer(props) {
1179
1242
  setScrollAnchoringOff(el, false);
1180
1243
  scrollTarget.removeEventListener('scroll', scrollHandler);
1181
1244
  el.removeEventListener('wheel', onWheel);
1245
+ doc.removeEventListener('keydown', endViewportMove, {
1246
+ capture: true
1247
+ });
1248
+ doc.removeEventListener('pointerdown', endViewportMove, {
1249
+ capture: true
1250
+ });
1182
1251
  if (viewportProbe !== null) {
1183
1252
  unobserveSize(viewportProbe);
1184
1253
  viewportProbe.remove();
1185
1254
  }
1255
+ view?.removeEventListener('resize', onViewportResize);
1256
+ isPageViewport.current = false;
1257
+ viewportChangedAt.current = -Infinity;
1258
+ passViewportHeight.current = null;
1259
+ isRestoreArmed.current = false;
1260
+ if (restoreFrame.current !== null) {
1261
+ cancelAnimationFrame(restoreFrame.current);
1262
+ restoreFrame.current = null;
1263
+ }
1186
1264
  // A replaced or unmounted scroller ends the gesture with it: the
1187
1265
  // finger-scroll watch moves to the new element and reports no end for
1188
1266
  // the old one. The adjustment is dropped rather than folded — the
@@ -1 +1 @@
1
- {"version":3,"file":"CircleCheckIndicator.d.ts","sourceRoot":"","sources":["../../src/CircleCheckIndicator/CircleCheckIndicator.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AA4HjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,IAAW,EACX,UAAkB,EAClB,QAAQ,EACR,GAAG,EACH,SAAS,EACT,KAAK,EACL,MAAM,EACN,GAAG,IAAI,EACR,EAAE,cAAc,CAAC,gBAAgB,CAAC,+BA2ElC;yBArFe,oBAAoB"}
1
+ {"version":3,"file":"CircleCheckIndicator.d.ts","sourceRoot":"","sources":["../../src/CircleCheckIndicator/CircleCheckIndicator.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAyHjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,IAAW,EACX,UAAkB,EAClB,QAAQ,EACR,GAAG,EACH,SAAS,EACT,KAAK,EACL,MAAM,EACN,GAAG,IAAI,EACR,EAAE,cAAc,CAAC,gBAAgB,CAAC,+BA2ElC;yBArFe,oBAAoB"}
@@ -56,8 +56,8 @@ const styles = {
56
56
  kv0HGH: "xarstr8",
57
57
  kUfP38: "xq94oqs",
58
58
  kloYau: "x2q1x1w",
59
- ks3ayO: "xyhc2n1 xzywxsk x1gybruy",
60
- kNctxI: "x1ygld8r",
59
+ ks3ayO: "xyhc2n1 x13rvwb2 x1gybruy",
60
+ kNctxI: "x1eflz5e",
61
61
  $$css: true
62
62
  },
63
63
  checkmark: {
package/dist/lab.css CHANGED
@@ -875,6 +875,7 @@
875
875
  .x19jfor0:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{background-color:var(--color-border-orange)}
876
876
  .xvgeimn:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::after{background-color:var(--color-border-orange)}
877
877
  .x1oxe2tr:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{background-color:var(--color-overlay-pressed)}
878
+ .x1eflz5e:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::after{background-image:var(--_indicator-press-image,none)}
878
879
  .x1xztnng:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--color-text-primary) 10%,transparent)}
879
880
  .xy0bsvc:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{box-shadow:var(--shadow-med)}
880
881
  .x1cpjm7i:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{content:""}
@@ -891,10 +892,9 @@
891
892
  .x1de4urk:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{transition-property:opacity}
892
893
  .xm5wvc0:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{transition-timing-function:var(--ease-exit)}
893
894
  .xwrs98t:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{will-change:var(--astryx-motion-will-change-before,auto)}
894
- .xzywxsk.xzywxsk:where(.x1odsvnm:active *):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::after{background-color:var(--color-overlay-pressed)}
895
+ .x13rvwb2.x13rvwb2:where(.x1odsvnm:active *):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::after{background-color:var(--_indicator-active-press,var(--color-overlay-pressed))}
895
896
  .x2btlgv.x2btlgv:where(.x6z01md[data-tab-bar-pressed] *):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{opacity:1}
896
897
  .x1mgx6nz.x1mgx6nz:where(.x6z01md[data-tab-bar-pressed] *):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{transition-duration:0s}
897
- @media (pointer: coarse){.x1ygld8r.x1ygld8r:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::after{background-image:var(--_indicator-press-image,none)}}
898
898
  @media (prefers-reduced-motion: reduce){.xmuupwu.xmuupwu:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{transition-duration:min(var(--duration-exit),.2s)}}
899
899
  @media (pointer: coarse){.x1gybruy.x1gybruy.x1gybruy:where(.x1odsvnm:active *):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::after{background-color:transparent}}
900
900
  @media (prefers-reduced-motion: reduce){.x1au10kd.x1au10kd.x1au10kd:where(.x6z01md[data-tab-bar-pressed] *):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#)::before{transition-duration:0s}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/lab",
3
- "version": "0.7.14-canary.gfdb9213",
3
+ "version": "0.7.15-canary.g79b95eb",
4
4
  "description": "Experimental Astryx components — published to npm only under the @canary dist-tag for early testing; never released as a stable (latest) version.",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@stylexjs/stylex": ">=0.10.0",
52
- "@astryxdesign/core": "0.7.14-canary.gfdb9213",
52
+ "@astryxdesign/core": "0.7.15-canary.g79b95eb",
53
53
  "react": ">=19.0.0",
54
54
  "react-dom": ">=19.0.0"
55
55
  },
@@ -59,9 +59,9 @@
59
59
  "d3-shape": "^3.2.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@astryxdesign/a11y-spec": "0.7.14-canary.gfdb9213",
63
- "@astryxdesign/cli": "0.7.14-canary.gfdb9213",
64
- "@astryxdesign/interaction-harness": "0.7.14-canary.gfdb9213",
62
+ "@astryxdesign/a11y-spec": "0.7.15-canary.g79b95eb",
63
+ "@astryxdesign/cli": "0.7.15-canary.g79b95eb",
64
+ "@astryxdesign/interaction-harness": "0.7.15-canary.g79b95eb",
65
65
  "@babel/cli": "^7.29.7",
66
66
  "@babel/core": "^7.29.7",
67
67
  "@babel/preset-react": "^7.29.7",
@@ -89,6 +89,10 @@ const addViewportProbe = (doc: Document): HTMLElement => {
89
89
  return probe;
90
90
  };
91
91
 
92
+ // A scroll soon after a window resize, with no finger, is the browser's.
93
+ // Safari's last rotation scroll lands inside this time. Reader input ends it.
94
+ const VIEWPORT_SETTLE_MS = 500;
95
+
92
96
  // While a finger scroll ends in an elastic overscroll, a write would snap the
93
97
  // bounce onto the clamp; the flush waits a frame at a time until it is over.
94
98
  const isBouncing = (vp: ViewportRead): boolean =>
@@ -352,6 +356,15 @@ export function ChatVirtualizer<T>(
352
356
  // passes run between two scroll events, and clearing per pass re-created
353
357
  // the staleness class mid-gesture (measured: 5.2% jitter at 60px steps).
354
358
  const userScrolledRef = React.useRef(false);
359
+ // A rotating phone moves the page's scrollTop to keep the reader's place.
360
+ // The new row heights are not measured yet. Safari can move it before the
361
+ // resize event or after the pass. The list restores the held row instead,
362
+ // with at most one extra pass before the viewport's pass and one after it.
363
+ const isPageViewport = React.useRef(false);
364
+ const viewportChangedAt = React.useRef(-Infinity);
365
+ const passViewportHeight = React.useRef<number | null>(null);
366
+ const isRestoreArmed = React.useRef(false);
367
+ const restoreFrame = React.useRef<number | null>(null);
355
368
  // Last scrollTop observed by a scroll event, and the px the user has moved
356
369
  // away from where the machinery last placed them — the end→anchor decision
357
370
  // runs on the latter (see onScroll).
@@ -765,6 +778,15 @@ export function ChatVirtualizer<T>(
765
778
  // where the content starts, and rows not measured yet (below).
766
779
  const vp = readViewport(el);
767
780
  const entryScrollTop = vp.scrollTop;
781
+ if (
782
+ isPageViewport.current &&
783
+ passViewportHeight.current !== null &&
784
+ vp.clientHeight !== passViewportHeight.current
785
+ ) {
786
+ // A browser scroll write can still follow this viewport pass.
787
+ isRestoreArmed.current = true;
788
+ }
789
+ passViewportHeight.current = vp.clientHeight;
768
790
  measureOrigin(el, vp);
769
791
  // Refresh the anchor from the LIVE scrollTop against the pre-measure
770
792
  // geometry (= what's currently painted). scroll events lag rAF-driven
@@ -1226,8 +1248,32 @@ export function ChatVirtualizer<T>(
1226
1248
  // and against the previous event's value that net can still read as
1227
1249
  // "moved down" — the user's own upward step erased by the re-pin.
1228
1250
  const lastWrite = progTarget.current;
1229
- const isEcho =
1251
+ // A finger owns the position even while the viewport changes size.
1252
+ // The browser writes its scroll for a viewport change before that
1253
+ // change's pass, at a height the pass has not read, or once soon after it.
1254
+ // The list's own write is neither. Any other scroll is the reader's.
1255
+ const isOwnEcho =
1230
1256
  lastWrite !== null && Math.abs(vp.scrollTop - lastWrite) <= 1;
1257
+ const isViewportMove =
1258
+ isPageViewport.current &&
1259
+ !isFingerScroll() &&
1260
+ !isOwnEcho &&
1261
+ ((passViewportHeight.current !== null &&
1262
+ vp.clientHeight !== passViewportHeight.current) ||
1263
+ (isRestoreArmed.current &&
1264
+ performance.now() - viewportChangedAt.current < VIEWPORT_SETTLE_MS));
1265
+ const isEcho = isViewportMove || isOwnEcho;
1266
+ if (isViewportMove) {
1267
+ userScrolledRef.current = false;
1268
+ if (isRestoreArmed.current && restoreFrame.current === null) {
1269
+ isRestoreArmed.current = false;
1270
+ geoChanged.current = true;
1271
+ restoreFrame.current = requestAnimationFrame(() => {
1272
+ restoreFrame.current = null;
1273
+ syncRef.current();
1274
+ });
1275
+ }
1276
+ }
1231
1277
  // STICKY echo: k offset changes within one frame queue up to k scroll
1232
1278
  // events, dispatched across successive frames, EACH reading the same
1233
1279
  // final scrollTop. A consume-once slot matches the first and misreads
@@ -1341,9 +1387,15 @@ export function ChatVirtualizer<T>(
1341
1387
  // Whether the container moved is what onScroll measures, against the
1342
1388
  // position the machinery last wrote, so a wheel the next write outruns
1343
1389
  // still shows there.
1390
+ // Reader input ends the time in which a scroll counts as the browser's.
1391
+ const endViewportMove = (): void => {
1392
+ viewportChangedAt.current = -Infinity;
1393
+ isRestoreArmed.current = false;
1394
+ };
1344
1395
  const onWheel = (): void => {
1345
1396
  converging.current = false;
1346
1397
  priceFreeze.current = false;
1398
+ endViewportMove();
1347
1399
  };
1348
1400
  setScrollAnchoringOff(el, true);
1349
1401
  const scrollHandler = (): void => onScrollRef.current();
@@ -1361,6 +1413,26 @@ export function ChatVirtualizer<T>(
1361
1413
  if (viewportProbe !== null) {
1362
1414
  observeSize(viewportProbe);
1363
1415
  }
1416
+ // Capture phase: a key whose handler stops propagation still scrolls.
1417
+ const doc = el.ownerDocument;
1418
+ if (viewportProbe !== null) {
1419
+ doc.addEventListener('keydown', endViewportMove, {
1420
+ capture: true,
1421
+ passive: true,
1422
+ });
1423
+ doc.addEventListener('pointerdown', endViewportMove, {
1424
+ capture: true,
1425
+ passive: true,
1426
+ });
1427
+ }
1428
+ isPageViewport.current = viewportProbe !== null;
1429
+ const view = viewportProbe !== null ? el.ownerDocument.defaultView : null;
1430
+ // Reads nothing.
1431
+ const onViewportResize = (): void => {
1432
+ viewportChangedAt.current = performance.now();
1433
+ isRestoreArmed.current = true;
1434
+ };
1435
+ view?.addEventListener('resize', onViewportResize, {passive: true});
1364
1436
  // Observe the CONTAINER too (rows alone miss clientHeight changes): a
1365
1437
  // window resize or a growing composer moves the end-mode target and the
1366
1438
  // window coverage without any row changing size. Container entries have
@@ -1370,10 +1442,21 @@ export function ChatVirtualizer<T>(
1370
1442
  setScrollAnchoringOff(el, false);
1371
1443
  scrollTarget.removeEventListener('scroll', scrollHandler);
1372
1444
  el.removeEventListener('wheel', onWheel);
1445
+ doc.removeEventListener('keydown', endViewportMove, {capture: true});
1446
+ doc.removeEventListener('pointerdown', endViewportMove, {capture: true});
1373
1447
  if (viewportProbe !== null) {
1374
1448
  unobserveSize(viewportProbe);
1375
1449
  viewportProbe.remove();
1376
1450
  }
1451
+ view?.removeEventListener('resize', onViewportResize);
1452
+ isPageViewport.current = false;
1453
+ viewportChangedAt.current = -Infinity;
1454
+ passViewportHeight.current = null;
1455
+ isRestoreArmed.current = false;
1456
+ if (restoreFrame.current !== null) {
1457
+ cancelAnimationFrame(restoreFrame.current);
1458
+ restoreFrame.current = null;
1459
+ }
1377
1460
  // A replaced or unmounted scroller ends the gesture with it: the
1378
1461
  // finger-scroll watch moves to the new element and reports no end for
1379
1462
  // the old one. The adjustment is dropped rather than folded — the
@@ -0,0 +1,515 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file ChatVirtualizerRotation.test.tsx
5
+ * @input ChatVirtualizer attached to the page scroller, a coarse pointer, and
6
+ * the events and ResizeObserver entries a phone sends when it rotates
7
+ * @output Which row the view holds after a rotation, whether follow-at-end
8
+ * survives it, and whether a finger scroll still owns the position
9
+ * @position Unit coverage for rotation on the page scroller; jsdom has no
10
+ * layout and no ResizeObserver, so the test plays the browser's part
11
+ */
12
+
13
+ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
14
+ import {act, render} from '@testing-library/react';
15
+ import {TOUCH_QUERY} from '@astryxdesign/core/internal/touch';
16
+ import {ChatVirtualizer} from './ChatVirtualizer';
17
+
18
+ const observed = new Map<Element, (entry: ResizeObserverEntry) => void>();
19
+ /** The layout model's height for a row, or null for anything else. */
20
+ let rowSizeOf: (element: Element) => number | null = () => null;
21
+ vi.mock('@astryxdesign/core/utils', async importOriginal => {
22
+ const actual =
23
+ await importOriginal<typeof import('@astryxdesign/core/utils')>();
24
+ return {
25
+ ...actual,
26
+ observeResize: (
27
+ element: Element,
28
+ callback: (entry: ResizeObserverEntry) => void,
29
+ ) => {
30
+ observed.set(element, callback);
31
+ // The registration's own call carries no box.
32
+ callback({target: element} as ResizeObserverEntry);
33
+ // As in a browser, a newly observed row reports its size after the
34
+ // next layout.
35
+ requestAnimationFrame(() => {
36
+ const blockSize = rowSizeOf(element);
37
+ if (blockSize === null || observed.get(element) !== callback) {
38
+ return;
39
+ }
40
+ callback({
41
+ target: element,
42
+ borderBoxSize: [{blockSize, inlineSize: 400}],
43
+ contentRect: {height: blockSize, width: 400},
44
+ } as unknown as ResizeObserverEntry);
45
+ });
46
+ return () => {
47
+ observed.delete(element);
48
+ };
49
+ },
50
+ };
51
+ });
52
+
53
+ type Row = {id: number; text: string};
54
+ const rows = (n: number): Row[] =>
55
+ Array.from({length: n}, (_, id) => ({id, text: `Message ${id}`}));
56
+
57
+ const ROW = 100;
58
+ const PORTRAIT_ROW = 150;
59
+
60
+ const nextFrame = (): Promise<void> =>
61
+ act(
62
+ () =>
63
+ new Promise<void>(resolve => {
64
+ requestAnimationFrame(() => resolve());
65
+ }),
66
+ );
67
+
68
+ const settled = (): Promise<void> =>
69
+ act(async () => {
70
+ await new Promise(resolve => setTimeout(resolve, 40));
71
+ });
72
+
73
+ describe('ChatVirtualizer on the page scroller: rotation', () => {
74
+ let el: HTMLElement;
75
+ let viewHeight = 400;
76
+ let rowHeight = ROW;
77
+ // scrollTop writes the list makes, not the browser's in pageScroll().
78
+ let listWrites = 0;
79
+ let isBrowserWrite = false;
80
+ let scrolling: PropertyDescriptor | undefined;
81
+ let restorePointer: () => void = () => {};
82
+ let restoreRects: () => void = () => {};
83
+
84
+ /** How tall a child of the list's content block is in the layout model. */
85
+ const heightOfChild = (node: Element): number => {
86
+ if ((node as HTMLElement).dataset.pkey !== undefined) {
87
+ return rowHeight;
88
+ }
89
+ const style = (node as HTMLElement).style;
90
+ return parseFloat(style.height) || parseFloat(style.minHeight) || 0;
91
+ };
92
+
93
+ beforeEach(() => {
94
+ viewHeight = 400;
95
+ rowHeight = ROW;
96
+ rowSizeOf = element =>
97
+ (element as HTMLElement).dataset.pkey !== undefined ? rowHeight : null;
98
+ el = document.createElement('div');
99
+ listWrites = 0;
100
+ let top = 0;
101
+ Object.defineProperty(el, 'scrollTop', {
102
+ configurable: true,
103
+ get: () => top,
104
+ set: (value: number) => {
105
+ const moved = value !== top;
106
+ top = value;
107
+ if (isBrowserWrite) {
108
+ return;
109
+ }
110
+ listWrites++;
111
+ // As in a browser, the list's own write that moves the position
112
+ // fires a scroll event on the next frame.
113
+ if (moved) {
114
+ requestAnimationFrame(() => {
115
+ const target = document.scrollingElement === el ? document : el;
116
+ target.dispatchEvent(new Event('scroll'));
117
+ });
118
+ }
119
+ },
120
+ });
121
+ Object.defineProperty(el, 'clientHeight', {
122
+ configurable: true,
123
+ get: () => viewHeight,
124
+ });
125
+ // The page is as tall as the list's content, and never shorter than the
126
+ // view.
127
+ Object.defineProperty(el, 'scrollHeight', {
128
+ configurable: true,
129
+ get: () => {
130
+ const block = [...document.querySelectorAll('[data-pkey]')][0]
131
+ ?.parentElement;
132
+ let total = 0;
133
+ for (const child of block?.children ?? []) {
134
+ total += heightOfChild(child);
135
+ }
136
+ return Math.max(viewHeight, total);
137
+ },
138
+ });
139
+ document.body.appendChild(el);
140
+ scrolling = Object.getOwnPropertyDescriptor(
141
+ Document.prototype,
142
+ 'scrollingElement',
143
+ );
144
+ Object.defineProperty(document, 'scrollingElement', {
145
+ configurable: true,
146
+ get: () => el,
147
+ });
148
+ // A phone: Core's finger-scroll watch listens only where the primary
149
+ // pointer is coarse.
150
+ const matchMedia = window.matchMedia;
151
+ const coarse = {
152
+ matches: true,
153
+ media: TOUCH_QUERY,
154
+ onchange: null,
155
+ addEventListener: () => {},
156
+ removeEventListener: () => {},
157
+ addListener: () => {},
158
+ removeListener: () => {},
159
+ dispatchEvent: () => false,
160
+ } as unknown as MediaQueryList;
161
+ window.matchMedia = (media: string) =>
162
+ media.trim() === TOUCH_QUERY ? coarse : matchMedia(media);
163
+ restorePointer = () => {
164
+ window.matchMedia = matchMedia;
165
+ };
166
+ // A layout model for jsdom: the list's content starts at the top of the
167
+ // page, its spacers are as tall as the list sets them, and every row is
168
+ // rowHeight tall. Each child of the content block sits one scroll offset
169
+ // above where it starts.
170
+ const heightOf = heightOfChild;
171
+ const isContentBlock = (node: Element | null): node is Element =>
172
+ node !== null &&
173
+ node !== document.body &&
174
+ node.firstElementChild?.getAttribute('aria-hidden') === 'true';
175
+ const rect = Element.prototype.getBoundingClientRect;
176
+ Element.prototype.getBoundingClientRect = function (this: Element) {
177
+ const parent = this.parentElement;
178
+ if (!isContentBlock(parent)) {
179
+ return rect.call(this);
180
+ }
181
+ let start = 0;
182
+ for (const child of parent.children) {
183
+ if (child === this) {
184
+ break;
185
+ }
186
+ start += heightOf(child);
187
+ }
188
+ const top = start - el.scrollTop;
189
+ const height = heightOf(this);
190
+ return {top, bottom: top + height, left: 0, right: 0, height} as DOMRect;
191
+ };
192
+ const offsetHeight = Object.getOwnPropertyDescriptor(
193
+ HTMLElement.prototype,
194
+ 'offsetHeight',
195
+ );
196
+ Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
197
+ configurable: true,
198
+ get(this: HTMLElement) {
199
+ return this.dataset.pkey !== undefined
200
+ ? rowHeight
201
+ : (offsetHeight?.get?.call(this) ?? 0);
202
+ },
203
+ });
204
+ restoreRects = () => {
205
+ Element.prototype.getBoundingClientRect = rect;
206
+ if (offsetHeight !== undefined) {
207
+ Object.defineProperty(
208
+ HTMLElement.prototype,
209
+ 'offsetHeight',
210
+ offsetHeight,
211
+ );
212
+ }
213
+ };
214
+ });
215
+
216
+ afterEach(() => {
217
+ rowSizeOf = () => null;
218
+ restorePointer();
219
+ restoreRects();
220
+ delete (document as unknown as Record<string, unknown>).scrollingElement;
221
+ if (scrolling !== undefined) {
222
+ Object.defineProperty(Document.prototype, 'scrollingElement', scrolling);
223
+ }
224
+ el.remove();
225
+ });
226
+
227
+ const list = (data: Row[]) => (
228
+ <ChatVirtualizer<Row>
229
+ data={data}
230
+ getRowKey={m => String(m.id)}
231
+ renderItem={({item}) => <span>{item.text}</span>}
232
+ estimatedItemSize={ROW}
233
+ scrollElement={el}
234
+ />
235
+ );
236
+
237
+ /** The row painted at the top of the view. */
238
+ function topRow(): number {
239
+ for (const row of document.querySelectorAll<HTMLElement>('[data-pkey]')) {
240
+ const {top, bottom} = row.getBoundingClientRect();
241
+ if (top <= 0 && bottom > 0) {
242
+ return Number(row.dataset.pkey);
243
+ }
244
+ }
245
+ return -1;
246
+ }
247
+
248
+ /**
249
+ * Where a row's top edge is painted, relative to the top of the view, or
250
+ * null when it is not mounted.
251
+ */
252
+ function rowTop(key: number): number | null {
253
+ const row = document.querySelector<HTMLElement>(`[data-pkey="${key}"]`);
254
+ return row === null ? null : row.getBoundingClientRect().top;
255
+ }
256
+
257
+ /** Whether the row's top edge sits at the top of the view. */
258
+ function isAtTop(key: number): boolean {
259
+ const top = rowTop(key);
260
+ return top !== null && Math.abs(top) < 2;
261
+ }
262
+
263
+ /** The page scrolls: its scroll event fires at the document. */
264
+ function pageScroll(at: number): void {
265
+ isBrowserWrite = true;
266
+ el.scrollTop = at;
267
+ isBrowserWrite = false;
268
+ act(() => {
269
+ document.dispatchEvent(new Event('scroll'));
270
+ });
271
+ }
272
+
273
+ /** A finger landing on or lifting from the page's content. */
274
+ function finger(type: string, down: boolean): void {
275
+ const target = el.firstElementChild ?? el;
276
+ const e = new Event(type, {bubbles: true, cancelable: true});
277
+ const entry = {identifier: 1, clientX: 5, clientY: 5, target};
278
+ Object.defineProperty(e, 'changedTouches', {value: [entry]});
279
+ Object.defineProperty(e, 'touches', {value: down ? [entry] : []});
280
+ act(() => {
281
+ target.dispatchEvent(e);
282
+ });
283
+ }
284
+
285
+ /**
286
+ * The phone rotates. The window fires resize. A browser that keeps the
287
+ * reader's place moves the page's scrollTop itself and fires a scroll
288
+ * event. After layout, the observer reports the scroller, the viewport box
289
+ * and every mounted row at its new height.
290
+ */
291
+ async function rotate(change: {
292
+ viewHeight: number;
293
+ rowHeight: number;
294
+ browserScrollTop?: number;
295
+ }): Promise<void> {
296
+ viewHeight = change.viewHeight;
297
+ rowHeight = change.rowHeight;
298
+ act(() => {
299
+ window.dispatchEvent(new Event('resize'));
300
+ });
301
+ if (change.browserScrollTop !== undefined) {
302
+ pageScroll(change.browserScrollTop);
303
+ }
304
+ await nextFrame();
305
+ act(() => {
306
+ for (const [target, callback] of observed) {
307
+ const key = (target as HTMLElement).dataset.pkey;
308
+ const blockSize = key === undefined ? viewHeight : change.rowHeight;
309
+ callback({
310
+ target,
311
+ borderBoxSize: [{blockSize, inlineSize: 400}],
312
+ contentRect: {height: blockSize, width: 400},
313
+ } as unknown as ResizeObserverEntry);
314
+ }
315
+ });
316
+ await act(async () => {
317
+ await Promise.resolve();
318
+ });
319
+ await nextFrame();
320
+ await nextFrame();
321
+ }
322
+
323
+ it('keeps the row that was at the top of the view after a rotation to portrait, in history', async () => {
324
+ render(list(rows(200)));
325
+ await settled();
326
+ // The reader scrolls into history: row 50 is at the top.
327
+ pageScroll(50 * ROW);
328
+ await nextFrame();
329
+ expect(topRow()).toBe(50);
330
+ // The browser keeps the reader's place by scaling scrollTop with the
331
+ // content, which no longer matches the list's own row heights.
332
+ await rotate({
333
+ viewHeight: 700,
334
+ rowHeight: PORTRAIT_ROW,
335
+ browserScrollTop: 50 * ROW * (PORTRAIT_ROW / ROW),
336
+ });
337
+ expect(isAtTop(50)).toBe(true);
338
+ });
339
+
340
+ it('keeps the row that was at the top of the view after a rotation to portrait, when the browser keeps scrollTop', async () => {
341
+ render(list(rows(200)));
342
+ await settled();
343
+ pageScroll(50 * ROW);
344
+ await nextFrame();
345
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
346
+ expect(isAtTop(50)).toBe(true);
347
+ });
348
+
349
+ it('keeps the row that was at the top of the view after a rotation back to landscape', async () => {
350
+ render(list(rows(200)));
351
+ await settled();
352
+ pageScroll(50 * ROW);
353
+ await nextFrame();
354
+ await rotate({
355
+ viewHeight: 700,
356
+ rowHeight: PORTRAIT_ROW,
357
+ browserScrollTop: 50 * PORTRAIT_ROW,
358
+ });
359
+ expect(isAtTop(50)).toBe(true);
360
+ await rotate({
361
+ viewHeight: 400,
362
+ rowHeight: ROW,
363
+ browserScrollTop: Math.round(el.scrollTop * (ROW / PORTRAIT_ROW)),
364
+ });
365
+ expect(isAtTop(50)).toBe(true);
366
+ });
367
+
368
+ it('keeps the row at the top when Safari writes its scroll position after the pass settles', async () => {
369
+ render(list(rows(200)));
370
+ await settled();
371
+ pageScroll(50 * ROW);
372
+ await nextFrame();
373
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
374
+ expect(isAtTop(50)).toBe(true);
375
+ // Safari's last scroll write of the rotation lands after the pass has
376
+ // settled.
377
+ await settled();
378
+ pageScroll(el.scrollTop + 125);
379
+ await nextFrame();
380
+ await nextFrame();
381
+ expect(isAtTop(50)).toBe(true);
382
+ });
383
+
384
+ it('keeps the row at the top when Safari scrolls before the resize event', async () => {
385
+ render(list(rows(200)));
386
+ await settled();
387
+ pageScroll(50 * ROW);
388
+ await nextFrame();
389
+ // The viewport is already portrait when Safari's scroll event arrives,
390
+ // and the resize event follows it.
391
+ viewHeight = 700;
392
+ rowHeight = PORTRAIT_ROW;
393
+ pageScroll(50 * PORTRAIT_ROW + 300);
394
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
395
+ expect(isAtTop(50)).toBe(true);
396
+ });
397
+
398
+ it('follows a wheel scroll right after a rotation', async () => {
399
+ render(list(rows(200)));
400
+ await settled();
401
+ pageScroll(50 * ROW);
402
+ await nextFrame();
403
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
404
+ const before = topRow();
405
+ act(() => {
406
+ el.dispatchEvent(new Event('wheel'));
407
+ });
408
+ pageScroll(el.scrollTop + 10 * PORTRAIT_ROW);
409
+ await nextFrame();
410
+ await nextFrame();
411
+ expect(topRow()).toBeGreaterThanOrEqual(before + 9);
412
+ });
413
+
414
+ it('keeps following the end through a rotation to landscape', async () => {
415
+ const {rerender} = render(list(rows(60)));
416
+ await settled();
417
+ const atBottom = (): boolean =>
418
+ Math.abs(el.scrollTop - (el.scrollHeight - el.clientHeight)) <= 1;
419
+ expect(atBottom()).toBe(true);
420
+ // Landscape: rows get shorter, and the browser scales scrollTop down.
421
+ await rotate({
422
+ viewHeight: 300,
423
+ rowHeight: 70,
424
+ browserScrollTop: Math.round(el.scrollTop * 0.7),
425
+ });
426
+ act(() => {
427
+ rerender(list(rows(70)));
428
+ });
429
+ await settled();
430
+ expect(atBottom()).toBe(true);
431
+ });
432
+
433
+ it('follows a keyboard scroll right after a rotation', async () => {
434
+ render(list(rows(200)));
435
+ await settled();
436
+ pageScroll(50 * ROW);
437
+ await nextFrame();
438
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
439
+ const before = topRow();
440
+ // PageDown on a control whose handler stops the key's propagation: the
441
+ // browser still scrolls the page.
442
+ const control = document.createElement('button');
443
+ control.addEventListener('keydown', event => event.stopPropagation());
444
+ document.body.append(control);
445
+ act(() => {
446
+ control.dispatchEvent(
447
+ new KeyboardEvent('keydown', {key: 'PageDown', bubbles: true}),
448
+ );
449
+ });
450
+ control.remove();
451
+ pageScroll(el.scrollTop + 10 * PORTRAIT_ROW);
452
+ await nextFrame();
453
+ await nextFrame();
454
+ expect(topRow()).toBeGreaterThanOrEqual(before + 9);
455
+ });
456
+
457
+ it('writes the scroll position at most once for a run of scroll events after a rotation', async () => {
458
+ render(list(rows(200)));
459
+ await settled();
460
+ pageScroll(50 * ROW);
461
+ await nextFrame();
462
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
463
+ await settled();
464
+ // A scripted smooth scroll right after the rotation, one step a frame.
465
+ listWrites = 0;
466
+ const start = el.scrollTop;
467
+ for (let step = 1; step <= 8; step++) {
468
+ pageScroll(start + step * 50);
469
+ await nextFrame();
470
+ }
471
+ expect(listWrites).toBeLessThanOrEqual(1);
472
+ });
473
+
474
+ it('follows a scroll on its own scroller in the frame its height changes', async () => {
475
+ // The list scrolls its own box, not the page.
476
+ Object.defineProperty(document, 'scrollingElement', {
477
+ configurable: true,
478
+ get: () => document.documentElement,
479
+ });
480
+ render(list(rows(200)));
481
+ await settled();
482
+ act(() => {
483
+ el.scrollTop = 50 * ROW;
484
+ el.dispatchEvent(new Event('scroll'));
485
+ });
486
+ await nextFrame();
487
+ await nextFrame();
488
+ const before = topRow();
489
+ // A growing composer shrinks the scroller; its observer entry has not
490
+ // arrived yet when the reader's scroll does.
491
+ viewHeight = 300;
492
+ act(() => {
493
+ el.scrollTop = el.scrollTop - 10 * ROW;
494
+ el.dispatchEvent(new Event('scroll'));
495
+ });
496
+ await nextFrame();
497
+ await nextFrame();
498
+ expect(topRow()).toBeLessThanOrEqual(before - 9);
499
+ });
500
+
501
+ it('writes no scroll position during a rotation while a finger scrolls', async () => {
502
+ render(list(rows(200)));
503
+ await settled();
504
+ finger('touchstart', true);
505
+ pageScroll(5000);
506
+ await rotate({viewHeight: 700, rowHeight: PORTRAIT_ROW});
507
+ expect(el.scrollTop).toBe(5000);
508
+ finger('touchend', false);
509
+ act(() => {
510
+ document.dispatchEvent(new Event('scrollend'));
511
+ });
512
+ await settled();
513
+ expect(el.scrollTop).not.toBe(5000);
514
+ });
515
+ });
@@ -66,9 +66,9 @@ const styles = stylex.create({
66
66
  opacity: 0.5,
67
67
  },
68
68
  // The press paints on the circle itself. The host's rounded-square layer
69
- // would tint past the circle, so the host leaves it off here. A touch
70
- // press arrives as `--_indicator-press-image`, which only a CheckboxInput
71
- // row declares, so a menu row's own press never paints twice.
69
+ // would tint past the circle, so the host leaves it off here. A press the
70
+ // controller paints arrives as `--_indicator-press-image`, which only a
71
+ // CheckboxInput row declares, so a menu row's own press never paints twice.
72
72
  ownPress: {
73
73
  position: 'relative',
74
74
  '::after': {
@@ -79,20 +79,17 @@ const styles = stylex.create({
79
79
  pointerEvents: 'none',
80
80
  backgroundColor: {
81
81
  default: 'transparent',
82
+ // A press the controller does not paint. While the controller paints
83
+ // the row's press, the row hands down `--_indicator-active-press` as
84
+ // transparent and the image below paints it.
82
85
  [stylex.when.ancestor(':active', indicatorScope)]: {
83
- default: colorVars['--color-overlay-pressed'],
86
+ default: `var(--_indicator-active-press, ${colorVars['--color-overlay-pressed']})`,
84
87
  '@media (pointer: coarse)': 'transparent',
85
88
  },
86
89
  },
87
- // The image paints under a coarse pointer only, as CheckboxInput's own
88
- // layer does. A held pen on a fine-pointer page already draws the
89
- // `:active` fill, and the image would paint a second press. StyleX puts
90
- // a constant media key in a later priority layer than a literal one. So
91
- // the key stays literal.
92
- backgroundImage: {
93
- default: null,
94
- '@media (pointer: coarse)': 'var(--_indicator-press-image, none)',
95
- },
90
+ // The controller's press on every pointer, as CheckboxInput's own layer
91
+ // paints it.
92
+ backgroundImage: 'var(--_indicator-press-image, none)',
96
93
  },
97
94
  },
98
95
  checkmark: {
@@ -471,7 +471,10 @@ test.describe('CircleCheckIndicator press', () => {
471
471
  const held = await readPress(page, 'Mountains');
472
472
  await page.mouse.up();
473
473
  expect(held.hostContent).toBe('none');
474
- expect(held.circleColour).not.toBe('rgba(0, 0, 0, 0)');
474
+ // The press controller paints the press as an image, and the `:active`
475
+ // fill stays off, so the circle paints it once.
476
+ expect(held.circleImage).toContain('gradient');
477
+ expect(held.circleColour).toBe('rgba(0, 0, 0, 0)');
475
478
  expect(held.circleLayerRadius).toBe(held.circleRadius);
476
479
  } finally {
477
480
  await context.close();
@@ -108,19 +108,46 @@ describe('CircleCheckIndicator ships the table', () => {
108
108
  return el;
109
109
  }
110
110
 
111
- it('paints the touch press image only under a coarse pointer, so a held pen draws its press once', () => {
112
- // A pen on a fine-pointer page draws the mouse `:active` fill; the press
113
- // image as well would paint the press twice. CheckboxInput's own layer
114
- // gates its image the same way.
111
+ it('paints the press image on every pointer, and its :active fill yields to it, so a held press paints once', () => {
112
+ // A CheckboxInput row hands the image down only while the press
113
+ // controller paints its press, and then sets `--_indicator-active-press`
114
+ // to transparent. So a mouse's or a pen's press paints the image alone.
115
+ const el = circle('md');
115
116
  const images = [
116
- ...(declarationsOf(circle('md')).get('background-image') ??
117
+ ...(declarationsOf(el).get('background-image') ??
117
118
  new Map<string | null, string>()),
118
119
  ];
119
120
  expect(images.length).toBeGreaterThan(0);
120
121
  for (const [media, value] of images) {
121
- expect(media).toContain('(pointer: coarse)');
122
+ expect(media ?? '').not.toContain('pointer');
122
123
  expect(value).toContain('--_indicator-press-image');
123
124
  }
125
+ const classes = el.className
126
+ .split(/\s+/)
127
+ .filter(Boolean)
128
+ .map(name => `.${name}`);
129
+ const activeFills: string[] = [];
130
+ const walk = (rules: CSSRuleList, media: string | null) => {
131
+ for (const rule of Array.from(rules)) {
132
+ if (rule instanceof CSSMediaRule) {
133
+ walk(rule.cssRules, rule.media.mediaText);
134
+ } else if (
135
+ rule instanceof CSSStyleRule &&
136
+ media == null &&
137
+ rule.selectorText.includes(':active') &&
138
+ classes.some(cls => rule.selectorText.startsWith(cls))
139
+ ) {
140
+ activeFills.push(rule.style.getPropertyValue('background-color'));
141
+ }
142
+ }
143
+ };
144
+ for (const sheet of Array.from(document.styleSheets)) {
145
+ walk(sheet.cssRules, null);
146
+ }
147
+ expect(activeFills.length).toBeGreaterThan(0);
148
+ for (const fill of activeFills) {
149
+ expect(fill).toMatch(/^var\(--_indicator-active-press,/);
150
+ }
124
151
  });
125
152
 
126
153
  it("reads only the touch press image a CheckboxInput row hands down, so a mapped menu row's own press paints once", () => {
@@ -2731,3 +2731,61 @@ test(
2731
2731
  expect(Math.max(...frames.map(f => f.top))).toBeGreaterThan(width * 0.5);
2732
2732
  },
2733
2733
  );
2734
+
2735
+ test.describe('a tap that wobbles keeps its click', () => {
2736
+ test('a tap on a pushed screen\u2019s row that drifts 3 px toward the back swipe keeps every move, and Chromium runs its click: the content back swipe waits out a tap\u2019s wobble (spec:AST-094 FR19, DEC-30)', async ({
2737
+ page,
2738
+ }) => {
2739
+ // A pushed screen: the content back swipe can pop it.
2740
+ const {driver, topTitle} = await openStack(page, 'pushed');
2741
+ expect(await topTitle()).toBe('About');
2742
+ await page.evaluate(() => {
2743
+ const moves: {travel: number; cancelled: boolean}[] = [];
2744
+ (window as unknown as {__wobble: typeof moves}).__wobble = moves;
2745
+ let startX = 0;
2746
+ window.addEventListener(
2747
+ 'touchstart',
2748
+ event => {
2749
+ startX = event.touches[0]?.clientX ?? 0;
2750
+ },
2751
+ {passive: true},
2752
+ );
2753
+ window.addEventListener(
2754
+ 'touchmove',
2755
+ event => {
2756
+ moves.push({
2757
+ travel: Math.round((event.touches[0]?.clientX ?? 0) - startX),
2758
+ cancelled: event.defaultPrevented,
2759
+ });
2760
+ },
2761
+ {passive: true},
2762
+ );
2763
+ });
2764
+ const at = await rowCenter(page, 'Done');
2765
+ await driver.play([
2766
+ {t: 0, fingers: [{id: 0, x: at.x, y: at.y}]},
2767
+ {t: 30, fingers: [{id: 0, x: at.x + 2, y: at.y}]},
2768
+ {t: 60, fingers: [{id: 0, x: at.x + 3, y: at.y}]},
2769
+ {t: 90, fingers: []},
2770
+ ]);
2771
+ // WebKit ends a touch's click when one of its moves is cancelled;
2772
+ // Chromium sends no move inside its 15 px slop.
2773
+ const moves = await page.evaluate(
2774
+ () =>
2775
+ (
2776
+ window as unknown as {
2777
+ __wobble: {travel: number; cancelled: boolean}[];
2778
+ }
2779
+ ).__wobble,
2780
+ );
2781
+ if (driver.engine === 'webkit') {
2782
+ // WebKit sends the wobble's moves; each reaches the page uncancelled.
2783
+ expect(moves.length, JSON.stringify(moves)).toBeGreaterThan(0);
2784
+ }
2785
+ expect(moves.filter(({cancelled}) => cancelled)).toEqual([]);
2786
+ if (driver.engine === 'chromium') {
2787
+ // Chromium makes the play's click: Done pops to the root.
2788
+ await expect.poll(topTitle).toBe('Settings');
2789
+ }
2790
+ });
2791
+ });
@@ -1535,3 +1535,54 @@ test('the end slides from its start, even when the page is busy as the refresh e
1535
1535
  expect(typeof blockEnd).toBe('number');
1536
1536
  expect(end?.start ?? 0).toBeGreaterThanOrEqual(blockEnd - START_SLACK_MS);
1537
1537
  });
1538
+
1539
+ test.describe('a tap that wobbles keeps its click', () => {
1540
+ test('a tap at the top that drifts 3 px down keeps every move: the pull never cancels a tap\u2019s wobble (spec:AST-094 FR19, DEC-30)', async ({
1541
+ page,
1542
+ }) => {
1543
+ const {driver, start} = await openRefresh(page);
1544
+ await page.evaluate(() => {
1545
+ const moves: {travel: number; cancelled: boolean}[] = [];
1546
+ (window as unknown as {__wobble: typeof moves}).__wobble = moves;
1547
+ let startY = 0;
1548
+ window.addEventListener(
1549
+ 'touchstart',
1550
+ event => {
1551
+ startY = event.touches[0]?.clientY ?? 0;
1552
+ },
1553
+ {passive: true},
1554
+ );
1555
+ window.addEventListener(
1556
+ 'touchmove',
1557
+ event => {
1558
+ moves.push({
1559
+ travel: Math.round((event.touches[0]?.clientY ?? 0) - startY),
1560
+ cancelled: event.defaultPrevented,
1561
+ });
1562
+ },
1563
+ {passive: true},
1564
+ );
1565
+ });
1566
+ await driver.play([
1567
+ {t: 0, fingers: [{id: 0, x: start.x, y: start.y}]},
1568
+ {t: 30, fingers: [{id: 0, x: start.x, y: start.y + 2}]},
1569
+ {t: 60, fingers: [{id: 0, x: start.x, y: start.y + 3}]},
1570
+ {t: 90, fingers: []},
1571
+ ]);
1572
+ // WebKit ends a touch's click when one of its moves is cancelled;
1573
+ // Chromium sends no move inside its 15 px slop.
1574
+ const moves = await page.evaluate(
1575
+ () =>
1576
+ (
1577
+ window as unknown as {
1578
+ __wobble: {travel: number; cancelled: boolean}[];
1579
+ }
1580
+ ).__wobble,
1581
+ );
1582
+ if (driver.engine === 'webkit') {
1583
+ // WebKit sends the wobble's moves; each reaches the page uncancelled.
1584
+ expect(moves.length, JSON.stringify(moves)).toBeGreaterThan(0);
1585
+ }
1586
+ expect(moves.filter(({cancelled}) => cancelled)).toEqual([]);
1587
+ });
1588
+ });