@astryxdesign/core 0.7.14 → 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.
Files changed (131) hide show
  1. package/dist/Calendar/Calendar.d.ts.map +1 -1
  2. package/dist/Calendar/Calendar.js +11 -2
  3. package/dist/Calendar/getInitialFocusDate.d.ts +8 -3
  4. package/dist/Calendar/getInitialFocusDate.d.ts.map +1 -1
  5. package/dist/Calendar/getInitialFocusDate.js +42 -7
  6. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  7. package/dist/CheckboxInput/CheckboxInput.js +9 -4
  8. package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
  9. package/dist/CheckboxList/CheckboxListItem.js +3 -8
  10. package/dist/DateInput/useTypedDate.d.ts.map +1 -1
  11. package/dist/DateInput/useTypedDate.js +3 -2
  12. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  13. package/dist/DateTimeInput/DateTimeInput.js +6 -3
  14. package/dist/DateTimeInput/NativeDateSegment.d.ts.map +1 -1
  15. package/dist/DateTimeInput/NativeDateSegment.js +23 -9
  16. package/dist/DateTimeInput/NativeTimeSegment.d.ts.map +1 -1
  17. package/dist/DateTimeInput/NativeTimeSegment.js +22 -8
  18. package/dist/Drawer/Drawer.d.ts.map +1 -1
  19. package/dist/Drawer/Drawer.js +7 -5
  20. package/dist/DropdownMenu/MenuBottomSheetActionList.d.ts.map +1 -1
  21. package/dist/DropdownMenu/MenuBottomSheetActionList.js +5 -1
  22. package/dist/Item/Item.d.ts +1 -1
  23. package/dist/Item/Item.d.ts.map +1 -1
  24. package/dist/Item/Item.js +4 -2
  25. package/dist/Link/useLinkify.d.ts.map +1 -1
  26. package/dist/Link/useLinkify.js +3 -2
  27. package/dist/List/List.d.ts +4 -1
  28. package/dist/List/List.d.ts.map +1 -1
  29. package/dist/Markdown/Markdown.d.ts.map +1 -1
  30. package/dist/Markdown/Markdown.js +8 -0
  31. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  32. package/dist/RadioList/RadioListItem.js +19 -4
  33. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts +43 -15
  34. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
  35. package/dist/SegmentedControl/useSegmentedSelectionMotion.js +108 -18
  36. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -1
  37. package/dist/SegmentedControl/useSegmentedTouchTracking.js +5 -0
  38. package/dist/Table/plugins/sortable/useTableSortableState.d.ts.map +1 -1
  39. package/dist/Table/plugins/sortable/useTableSortableState.js +7 -3
  40. package/dist/Token/Token.d.ts.map +1 -1
  41. package/dist/Token/Token.js +2 -0
  42. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  43. package/dist/Tokenizer/Tokenizer.js +85 -12
  44. package/dist/astryx.css +11 -10
  45. package/dist/gestures/GestureHost.d.ts +5 -0
  46. package/dist/gestures/GestureHost.d.ts.map +1 -1
  47. package/dist/gestures/GestureHost.js +54 -28
  48. package/dist/hooks/menuPressGesture.d.ts +39 -2
  49. package/dist/hooks/menuPressGesture.d.ts.map +1 -1
  50. package/dist/hooks/menuPressGesture.js +92 -5
  51. package/dist/hooks/scrollOwnerRegistry.d.ts +0 -1
  52. package/dist/hooks/scrollOwnerRegistry.d.ts.map +1 -1
  53. package/dist/hooks/scrollOwnerRegistry.js +4 -1
  54. package/dist/hooks/useClickableContainer.d.ts +6 -4
  55. package/dist/hooks/useClickableContainer.d.ts.map +1 -1
  56. package/dist/hooks/useClickableContainer.js +11 -8
  57. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  58. package/dist/hooks/useFocusTrap.js +6 -0
  59. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  60. package/dist/hooks/useMenuPress.js +35 -2
  61. package/dist/hooks/useStreamingText.d.ts.map +1 -1
  62. package/dist/hooks/useStreamingText.js +38 -23
  63. package/dist/i18n/generated-english/DateInput/useTypedDate.generated.js +2 -2
  64. package/dist/i18n/generated-locales/en.generated.js +2 -2
  65. package/dist/i18n/generated-locales/pseudo.generated.js +2 -2
  66. package/dist/motion/uikit/segmented.d.ts +35 -7
  67. package/dist/motion/uikit/segmented.d.ts.map +1 -1
  68. package/dist/motion/uikit/segmented.js +39 -11
  69. package/dist/privateAttributes/press.stylex.d.ts.map +1 -1
  70. package/dist/privateAttributes/press.stylex.js +1 -1
  71. package/dist/privateAttributes/pressBox.stylex.d.ts +12 -4
  72. package/dist/privateAttributes/pressBox.stylex.d.ts.map +1 -1
  73. package/dist/privateAttributes/pressBox.stylex.js +21 -4
  74. package/dist/privateAttributes/tokenRemove.stylex.d.ts +5 -0
  75. package/dist/privateAttributes/tokenRemove.stylex.d.ts.map +1 -0
  76. package/dist/privateAttributes/tokenRemove.stylex.js +25 -0
  77. package/dist/theme/defineTheme.d.ts +0 -1
  78. package/dist/theme/defineTheme.d.ts.map +1 -1
  79. package/dist/utils/inputAge.d.ts +5 -2
  80. package/dist/utils/inputAge.d.ts.map +1 -1
  81. package/dist/utils/inputAge.js +4 -1
  82. package/dist/utils/pressFeedback.d.ts.map +1 -1
  83. package/dist/utils/pressFeedback.js +60 -9
  84. package/locales/en.json +3 -3
  85. package/locales/pseudo.json +2 -2
  86. package/package.json +5 -5
  87. package/src/Calendar/Calendar.tsx +11 -1
  88. package/src/Calendar/getInitialFocusDate.ts +70 -8
  89. package/src/CheckboxInput/CheckboxInput.doc.mjs +16 -2
  90. package/src/CheckboxInput/CheckboxInput.tsx +32 -23
  91. package/src/CheckboxList/CheckboxList.doc.mjs +1 -1
  92. package/src/CheckboxList/CheckboxListItem.tsx +3 -6
  93. package/src/DateInput/useTypedDate.ts +9 -6
  94. package/src/DateTimeInput/DateTimeInput.tsx +7 -3
  95. package/src/DateTimeInput/NativeDateSegment.tsx +28 -10
  96. package/src/DateTimeInput/NativeTimeSegment.tsx +19 -9
  97. package/src/Drawer/Drawer.tsx +7 -5
  98. package/src/DropdownMenu/MenuBottomSheetActionList.tsx +3 -0
  99. package/src/Item/Item.doc.mjs +2 -1
  100. package/src/Item/Item.tsx +7 -3
  101. package/src/Link/useLinkify.tsx +7 -9
  102. package/src/List/List.doc.mjs +9 -21
  103. package/src/List/List.tsx +4 -1
  104. package/src/List/ListItem.doc.mjs +4 -2
  105. package/src/Markdown/Markdown.tsx +7 -0
  106. package/src/RadioList/RadioListItem.tsx +60 -30
  107. package/src/SegmentedControl/SegmentedControl.doc.mjs +3 -3
  108. package/src/SegmentedControl/useSegmentedSelectionMotion.ts +115 -19
  109. package/src/SegmentedControl/useSegmentedTouchTracking.ts +5 -0
  110. package/src/Table/plugins/sortable/useTableSortableState.tsx +5 -1
  111. package/src/Token/Token.tsx +2 -0
  112. package/src/Tokenizer/Tokenizer.tsx +102 -7
  113. package/src/gestures/GestureHost.ts +62 -32
  114. package/src/hooks/menuPressGesture.ts +116 -9
  115. package/src/hooks/scrollOwnerRegistry.ts +8 -1
  116. package/src/hooks/useClickableContainer.ts +11 -8
  117. package/src/hooks/useFocusTrap.ts +6 -0
  118. package/src/hooks/useMenuPress.ts +32 -2
  119. package/src/hooks/useStreamingText.ts +30 -25
  120. package/src/i18n/generated-english/DateInput/useTypedDate.generated.ts +2 -2
  121. package/src/i18n/generated-locales/en.generated.ts +2 -2
  122. package/src/i18n/generated-locales/pseudo.generated.ts +2 -2
  123. package/src/motion/MEASUREMENTS.md +2 -3
  124. package/src/motion/uikit/segmented.ts +35 -10
  125. package/src/privateAttributes/press.stylex.ts +2 -8
  126. package/src/privateAttributes/pressBox.stylex.ts +23 -4
  127. package/src/privateAttributes/tokenRemove.stylex.ts +27 -0
  128. package/src/theme/defineTheme.ts +0 -1
  129. package/src/theme/useThemeName.doc.mjs +69 -0
  130. package/src/utils/inputAge.ts +5 -2
  131. package/src/utils/pressFeedback.ts +80 -9
@@ -179,6 +179,7 @@ import {
179
179
  disarmClickGuard,
180
180
  withoutClickGuard,
181
181
  } from '../utils/clickGuard';
182
+ import {clockOf, type EventClock} from '../utils/inputAge';
182
183
  import {subscribeInput} from '../utils/inputStream';
183
184
  import {isPrimaryClick} from '../utils/primaryClick';
184
185
  import {
@@ -662,21 +663,35 @@ function panTakesMove(
662
663
  }
663
664
 
664
665
  /**
665
- * An event's time on the arena's clock (`performance.now()`). Some engines
666
- * and DOM emulators stamp events in epoch milliseconds instead.
666
+ * An event's time on the arena's clock: `timing.now()`, with `timing` the
667
+ * clock of the event's own window. Some engines and DOM emulators stamp
668
+ * events in epoch milliseconds instead.
667
669
  */
668
- function eventTime(event: Event): number {
670
+ function eventTime(event: Event, timing: EventClock | null): number {
669
671
  const time = event.timeStamp;
670
- if (
671
- time > 1e12 &&
672
- typeof performance !== 'undefined' &&
673
- performance.timeOrigin > 0
674
- ) {
675
- return time - performance.timeOrigin;
672
+ if (time > 1e12 && timing != null && timing.timeOrigin > 0) {
673
+ return time - timing.timeOrigin;
676
674
  }
677
675
  return time;
678
676
  }
679
677
 
678
+ /**
679
+ * The arena clock for `doc`. The page's own document keeps the page's clock.
680
+ * A same-origin iframe or a Picture-in-Picture window stamps its events from
681
+ * its own start, so its clock reads that window's `performance`. A page can
682
+ * replace that object after the host exists, so each reading looks it up.
683
+ */
684
+ function documentClock(doc: Document): GestureClock {
685
+ const view = doc.defaultView;
686
+ if (view == null || view === globalThis) {
687
+ return browserClock;
688
+ }
689
+ return {
690
+ ...browserClock,
691
+ now: () => clockOf(doc)?.now() ?? browserClock.now(),
692
+ };
693
+ }
694
+
680
695
  /** A touch list as an array; a synthetic event may carry none. */
681
696
  function touchesOf(list: TouchList | null | undefined): Touch[] {
682
697
  return list == null ? [] : Array.from(list);
@@ -812,6 +827,13 @@ export class GestureHost {
812
827
  private claimedLiftTimer: unknown = null;
813
828
  /** The arena's clock, which the claimed lifts' timer runs on too. */
814
829
  private readonly clock: GestureClock;
830
+ /**
831
+ * The clock of the document's own window, which stamps its events. A page
832
+ * can replace it after the host exists, so each read looks it up.
833
+ */
834
+ private get timing(): EventClock | null {
835
+ return clockOf(this.doc);
836
+ }
815
837
  /** Fingers still waiting for their pointerdown, by arena id. */
816
838
  private readonly unpairedTouches = new Map<number, PlacedContact>();
817
839
  private readonly isPrimaryPointerCoarse: () => boolean;
@@ -910,7 +932,7 @@ export class GestureHost {
910
932
  return {left, top, width, height};
911
933
  },
912
934
  };
913
- this.clock = options.clock ?? browserClock;
935
+ this.clock = options.clock ?? documentClock(doc);
914
936
  this.arena = new GestureArena({
915
937
  clock: this.clock,
916
938
  environment,
@@ -2285,7 +2307,7 @@ export class GestureHost {
2285
2307
  return;
2286
2308
  }
2287
2309
  this.wheelsSeen.add(wheel);
2288
- const time = eventTime(wheel);
2310
+ const time = eventTime(wheel, this.timing);
2289
2311
  const kind = wheel.ctrlKey ? 'pinch' : 'pan';
2290
2312
  let gesture = this.wheel;
2291
2313
  if (
@@ -2986,7 +3008,7 @@ export class GestureHost {
2986
3008
  }
2987
3009
 
2988
3010
  private readonly onTouchStart = (event: TouchEvent): void => {
2989
- this.endWheel(eventTime(event));
3011
+ this.endWheel(eventTime(event, this.timing));
2990
3012
  this.noteFingersDown(event);
2991
3013
  // Where the host reads a finger from its pointer events (no ontouchstart,
2992
3014
  // as after touch emulation turns on), its Touch Events would track it twice.
@@ -2996,7 +3018,7 @@ export class GestureHost {
2996
3018
  if (this.fingerTargets.length > 1) {
2997
3019
  this.failUnclaimedLoneFingerPans();
2998
3020
  }
2999
- const time = eventTime(event);
3021
+ const time = eventTime(event, this.timing);
3000
3022
  const inputs: ArenaBeganInput[] = [];
3001
3023
  const untracked: TouchBeganInput[] = [];
3002
3024
  const stale: number[] = [];
@@ -3117,7 +3139,7 @@ export class GestureHost {
3117
3139
  return;
3118
3140
  }
3119
3141
  this.dropFingersNotDown(event);
3120
- const time = eventTime(event);
3142
+ const time = eventTime(event, this.timing);
3121
3143
  const ids: number[] = [];
3122
3144
  const inputs: TouchInput[] = [];
3123
3145
  for (const touch of touchesOf(event.changedTouches)) {
@@ -3225,7 +3247,7 @@ export class GestureHost {
3225
3247
  */
3226
3248
  private readonly onClaimedTouchEnd = (event: Event): void => {
3227
3249
  const end = event as TouchEvent;
3228
- const time = eventTime(end);
3250
+ const time = eventTime(end, this.timing);
3229
3251
  for (let i = this.claimedLifts.length - 1; i >= 0; i--) {
3230
3252
  if (time - this.claimedLifts[i].time > CLAIMED_LIFT_MS) {
3231
3253
  this.claimedLifts.splice(i, 1);
@@ -3308,7 +3330,7 @@ export class GestureHost {
3308
3330
  return;
3309
3331
  }
3310
3332
  this.dropFingersNotDown(event);
3311
- const time = eventTime(event);
3333
+ const time = eventTime(event, this.timing);
3312
3334
  const inputs: TouchInput[] = [];
3313
3335
  const retargetedEnds: {
3314
3336
  id: number;
@@ -3428,7 +3450,7 @@ export class GestureHost {
3428
3450
  }
3429
3451
  }
3430
3452
  if (ids.length > 0) {
3431
- this.arena.cancelled(ids, eventTime(event));
3453
+ this.arena.cancelled(ids, eventTime(event, this.timing));
3432
3454
  }
3433
3455
  };
3434
3456
 
@@ -3491,7 +3513,7 @@ export class GestureHost {
3491
3513
  }
3492
3514
  }
3493
3515
  if (ids.length > 0) {
3494
- this.arena.cancelled(ids, eventTime(event));
3516
+ this.arena.cancelled(ids, eventTime(event, this.timing));
3495
3517
  }
3496
3518
  }
3497
3519
 
@@ -3703,7 +3725,7 @@ export class GestureHost {
3703
3725
  // --- Pointer events --------------------------------------------------------
3704
3726
 
3705
3727
  private readonly onPointerDown = (event: PointerEvent): void => {
3706
- this.endWheel(eventTime(event));
3728
+ this.endWheel(eventTime(event, this.timing));
3707
3729
  // A new press: whatever click is still owed to the last one is not this.
3708
3730
  disarmClickGuard(this.doc);
3709
3731
  if (!isPointerKind(event.pointerType)) {
@@ -3760,7 +3782,7 @@ export class GestureHost {
3760
3782
  id,
3761
3783
  x: event.clientX,
3762
3784
  y: event.clientY,
3763
- time: eventTime(event),
3785
+ time: eventTime(event, this.timing),
3764
3786
  pointerType: event.pointerType,
3765
3787
  target,
3766
3788
  scroll: createNativeScrollProbe(target),
@@ -3803,8 +3825,8 @@ export class GestureHost {
3803
3825
  id,
3804
3826
  x: event.clientX,
3805
3827
  y: event.clientY,
3806
- time: eventTime(event),
3807
- history: coalescedHistory(event),
3828
+ time: eventTime(event, this.timing),
3829
+ history: coalescedHistory(event, this.timing),
3808
3830
  },
3809
3831
  ]);
3810
3832
  }
@@ -3817,8 +3839,8 @@ export class GestureHost {
3817
3839
  id,
3818
3840
  x: event.clientX,
3819
3841
  y: event.clientY,
3820
- time: eventTime(event),
3821
- history: coalescedHistory(event),
3842
+ time: eventTime(event, this.timing),
3843
+ history: coalescedHistory(event, this.timing),
3822
3844
  },
3823
3845
  ]);
3824
3846
  return;
@@ -3835,7 +3857,7 @@ export class GestureHost {
3835
3857
  this.liftStamps.set(id, {
3836
3858
  x: event.clientX,
3837
3859
  y: event.clientY,
3838
- time: eventTime(event),
3860
+ time: eventTime(event, this.timing),
3839
3861
  });
3840
3862
  }
3841
3863
  this.fingerPointers.delete(event.pointerId);
@@ -3855,7 +3877,12 @@ export class GestureHost {
3855
3877
  const hold = this.claimHolds.get(id);
3856
3878
  this.unlockSelection(id);
3857
3879
  const dispositions = this.arena.ended([
3858
- {id, x: event.clientX, y: event.clientY, time: eventTime(event)},
3880
+ {
3881
+ id,
3882
+ x: event.clientX,
3883
+ y: event.clientY,
3884
+ time: eventTime(event, this.timing),
3885
+ },
3859
3886
  ]);
3860
3887
  // A selection the lift's own handlers made stays, as a click's does.
3861
3888
  hold?.keepLiftSelection();
@@ -3903,7 +3930,7 @@ export class GestureHost {
3903
3930
  x: event.clientX,
3904
3931
  y: event.clientY,
3905
3932
  target: landedOn(event),
3906
- time: eventTime(event),
3933
+ time: eventTime(event, this.timing),
3907
3934
  });
3908
3935
  if (this.claimedLifts.length > CLAIMED_LIFT_LIMIT) {
3909
3936
  this.claimedLifts.shift();
@@ -3954,7 +3981,7 @@ export class GestureHost {
3954
3981
  // browser scrolls with it): its touch events, now the only channel,
3955
3982
  // sample it, as a watcher following the scroll to the lift needs.
3956
3983
  this.pointerFed.delete(id);
3957
- this.browserTook([id], eventTime(event));
3984
+ this.browserTook([id], eventTime(event, this.timing));
3958
3985
  }
3959
3986
  return;
3960
3987
  }
@@ -3966,7 +3993,7 @@ export class GestureHost {
3966
3993
  this.pointerKinds.delete(event.pointerId);
3967
3994
  this.unlockSelection(id, true);
3968
3995
  this.retargeted.delete(id);
3969
- this.arena.cancelled([id], eventTime(event));
3996
+ this.arena.cancelled([id], eventTime(event, this.timing));
3970
3997
  }
3971
3998
  };
3972
3999
 
@@ -4083,7 +4110,7 @@ export class GestureHost {
4083
4110
  }
4084
4111
 
4085
4112
  private readonly onScroll = (event: Event): void => {
4086
- const time = eventTime(event);
4113
+ const time = eventTime(event, this.timing);
4087
4114
  const scroller = event.target === this.doc ? this.doc : event.target;
4088
4115
  if (!isNode(scroller) || this.ownedScrolls.has(scroller)) {
4089
4116
  return;
@@ -4271,7 +4298,10 @@ function needsSuppression(
4271
4298
  return false;
4272
4299
  }
4273
4300
 
4274
- function coalescedHistory(event: PointerEvent): TouchSample[] {
4301
+ function coalescedHistory(
4302
+ event: PointerEvent,
4303
+ timing: EventClock | null,
4304
+ ): TouchSample[] {
4275
4305
  if (typeof event.getCoalescedEvents !== 'function') {
4276
4306
  return [];
4277
4307
  }
@@ -4279,7 +4309,7 @@ function coalescedHistory(event: PointerEvent): TouchSample[] {
4279
4309
  return coalesced.slice(0, -1).map(sample => ({
4280
4310
  x: sample.clientX,
4281
4311
  y: sample.clientY,
4282
- time: eventTime(sample),
4312
+ time: eventTime(sample, timing),
4283
4313
  }));
4284
4314
  }
4285
4315
 
@@ -55,6 +55,21 @@ export type MenuPressState<T> =
55
55
  origin: 'trigger' | 'menu';
56
56
  /** The enabled row currently under the pointer, if any. */
57
57
  row: T | null;
58
+ }
59
+ /**
60
+ * The window lost focus under a finger. The gesture is still tracked, so its
61
+ * document listeners stay its own until its release or cancel. Nothing it
62
+ * does highlights or acts.
63
+ * @internal Not public contract.
64
+ */
65
+ | {
66
+ phase: 'withdrawn';
67
+ pointerType: MenuPressPointerType;
68
+ /**
69
+ * Withdrawn while it was still a press on the trigger: its tap's click
70
+ * is what opens the menu, so its release lets that click through.
71
+ */
72
+ fromTrigger?: true;
58
73
  };
59
74
 
60
75
  /** @internal */
@@ -97,7 +112,14 @@ export type MenuPressInput<T> =
97
112
  y?: number;
98
113
  }
99
114
  /** The browser took the gesture: pointercancel, a second pointer, a scroll. */
100
- | {type: 'cancel'};
115
+ | {type: 'cancel'}
116
+ /**
117
+ * The window lost focus mid-press. A finger's or pen's gesture is withdrawn,
118
+ * tracked to its release with nothing acting; a mouse's ends as a cancel
119
+ * does.
120
+ * @internal Not public contract.
121
+ */
122
+ | {type: 'withdraw'};
101
123
 
102
124
  /** @internal */
103
125
  export type MenuPressOutcome<T> =
@@ -110,9 +132,18 @@ export type MenuPressOutcome<T> =
110
132
  /**
111
133
  * The gesture ended without a row acting. `stray` says whether the browser
112
134
  * will still report a `click` for this gesture that must not act; `dismiss`
113
- * says the menu should close: a mouse released outside it.
135
+ * says the menu should close: a mouse released outside it. `clear`
136
+ * (@internal) says a row a finger lit loses its highlight (the browser took
137
+ * the press).
114
138
  */
115
- | {type: 'settle'; stray: boolean; dismiss: boolean};
139
+ | {type: 'settle'; stray: boolean; dismiss: boolean; clear?: true}
140
+ /**
141
+ * The gesture was withdrawn and is still live: stop what drives it (the
142
+ * hold, the autoscroll, the page lock). `clear` says a row a finger lit
143
+ * loses its highlight.
144
+ * @internal Not public contract.
145
+ */
146
+ | {type: 'withdraw'; clear?: true};
116
147
 
117
148
  /** @internal */
118
149
  export interface MenuPressTransition<T> {
@@ -120,7 +151,9 @@ export interface MenuPressTransition<T> {
120
151
  effect: MenuPressOutcome<T>;
121
152
  }
122
153
 
123
- export const IDLE_MENU_PRESS: MenuPressState<never> = {phase: 'idle'};
154
+ // The idle gesture: both the released and the internal shape.
155
+ export const IDLE_MENU_PRESS: MenuPressGesture<never> & MenuPressState<never> =
156
+ {phase: 'idle'};
124
157
 
125
158
  const NONE: MenuPressOutcome<never> = {type: 'none'};
126
159
 
@@ -215,6 +248,55 @@ export function menuPressTransition<T>(
215
248
  return stepOpen(gesture, event);
216
249
  case 'tracking':
217
250
  return stepTracking(gesture, event);
251
+ case 'withdrawn':
252
+ return stepWithdrawn(gesture, event);
253
+ }
254
+ }
255
+
256
+ /**
257
+ * A finger's or pen's gesture withdrawn by the window's blur, or a mouse's
258
+ * ended as a cancel, which keeps its click.
259
+ */
260
+ function withdraw<T>(
261
+ pointerType: MenuPressPointerType,
262
+ litRow: T | null,
263
+ fromTrigger = false,
264
+ ): MenuPressTransition<T> {
265
+ if (!isFinger(pointerType)) {
266
+ return idle({type: 'settle', stray: false, dismiss: false});
267
+ }
268
+ return {
269
+ gesture: fromTrigger
270
+ ? {phase: 'withdrawn', pointerType, fromTrigger: true}
271
+ : {phase: 'withdrawn', pointerType},
272
+ effect:
273
+ litRow != null ? {type: 'withdraw', clear: true} : {type: 'withdraw'},
274
+ };
275
+ }
276
+
277
+ function stepWithdrawn<T>(
278
+ gesture: Extract<MenuPressState<T>, {phase: 'withdrawn'}>,
279
+ event: MenuPressInput<T>,
280
+ ): MenuPressTransition<T> {
281
+ switch (event.type) {
282
+ case 'up':
283
+ // The withdrawn finger lifts: nothing acts, and the click the browser
284
+ // reports for it is still this gesture's, so it is swallowed. Its
285
+ // listeners come off as the gesture ends. A tap on the trigger keeps
286
+ // its click, which opens the menu: the pointer model's open, or a
287
+ // scroll view's open at the lift.
288
+ return idle({
289
+ type: 'settle',
290
+ stray: gesture.fromTrigger !== true,
291
+ dismiss: false,
292
+ });
293
+ case 'cancel':
294
+ return idle({type: 'settle', stray: false, dismiss: false});
295
+ case 'down':
296
+ case 'move':
297
+ case 'opened':
298
+ case 'withdraw':
299
+ return {gesture, effect: NONE};
218
300
  }
219
301
  }
220
302
 
@@ -280,6 +362,8 @@ function stepTriggerPress<T>(
280
362
  // touchmove preventer, and only the end of a gesture removes it. No
281
363
  // click follows a cancelled pointer.
282
364
  return idle({type: 'settle', stray: false, dismiss: false});
365
+ case 'withdraw':
366
+ return withdraw<T>(gesture.pointerType, null, true);
283
367
  case 'down':
284
368
  case 'move':
285
369
  return {gesture, effect: NONE};
@@ -348,6 +432,8 @@ function stepOpen<T>(
348
432
  // As above: the gesture ends, so its document listeners come off. The
349
433
  // menu stays open: a cancelled pointer did not ask to close it.
350
434
  return idle({type: 'settle', stray: false, dismiss: false});
435
+ case 'withdraw':
436
+ return withdraw<T>(gesture.pointerType, null);
351
437
  case 'down':
352
438
  case 'opened':
353
439
  return {gesture, effect: NONE};
@@ -371,8 +457,19 @@ function stepTracking<T>(
371
457
  return release(gesture.pointerType, event);
372
458
  case 'cancel':
373
459
  // The browser took the gesture (a scroll, a second finger): nothing
374
- // acts, the menu stays, and no click follows a cancelled pointer.
375
- return idle({type: 'settle', stray: false, dismiss: false});
460
+ // acts, the menu stays, and no click follows a cancelled pointer. A
461
+ // row a finger lit loses its highlight, as UIKit clears it when the
462
+ // list starts scrolling. A mouse's highlight stays where it was.
463
+ return idle({
464
+ type: 'settle',
465
+ stray: false,
466
+ dismiss: false,
467
+ ...(gesture.row != null && isFinger(gesture.pointerType)
468
+ ? {clear: true as const}
469
+ : {}),
470
+ });
471
+ case 'withdraw':
472
+ return withdraw(gesture.pointerType, gesture.row);
376
473
  case 'down':
377
474
  case 'opened':
378
475
  return {gesture, effect: NONE};
@@ -382,8 +479,8 @@ function stepTracking<T>(
382
479
  // ---------------------------------------------------------------------------
383
480
  // The released public shape (`@astryxdesign/core/hooks`). The machine's own
384
481
  // types above carry the finger's handoff and are not public contract. The
385
- // handoff positions and `handoffFrom` stay internal: a caller of
386
- // `menuPressStep` keeps the settle rule, as released.
482
+ // handoff positions, `handoffFrom` and the settle `clear` stay internal: a
483
+ // caller of `menuPressStep` keeps the settle rule, as released.
387
484
  // ---------------------------------------------------------------------------
388
485
 
389
486
  export type MenuPressGesture<T> =
@@ -470,11 +567,21 @@ export function menuPressStep<T>(
470
567
  );
471
568
  return {
472
569
  gesture: publicGesture(next),
473
- effect,
570
+ effect:
571
+ effect.type === 'settle'
572
+ ? {type: 'settle', stray: effect.stray, dismiss: effect.dismiss}
573
+ : effect.type === 'withdraw'
574
+ ? // Unreachable from the released events, which carry no `withdraw`.
575
+ {type: 'none'}
576
+ : effect,
474
577
  };
475
578
  }
476
579
 
477
580
  function publicGesture<T>(gesture: MenuPressState<T>): MenuPressGesture<T> {
581
+ if (gesture.phase === 'withdrawn') {
582
+ // Unreachable from the released events, which carry no `withdraw`.
583
+ return {phase: 'idle'};
584
+ }
478
585
  if (gesture.phase !== 'open') {
479
586
  return gesture;
480
587
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  /** Private DOM registry used by future axis-aware Sticky consumers. */
4
4
 
5
+ import {sharedWeakMap} from '../utils/sharedRealm';
6
+
5
7
  export interface RegisteredScrollAxisState {
6
8
  isScrollable: boolean;
7
9
  atStart: boolean;
@@ -13,7 +15,12 @@ export interface RegisteredScrollOwnerState {
13
15
  block: RegisteredScrollAxisState;
14
16
  }
15
17
 
16
- const owners = new WeakMap<HTMLElement, RegisteredScrollOwnerState>();
18
+ // Every copy of Core uses this one map. A copied AppShell then sees the
19
+ // scroll regions that package components register, and the reverse.
20
+ const owners = sharedWeakMap<HTMLElement, RegisteredScrollOwnerState>(
21
+ 'hooks/scroll-owner-registry/owners',
22
+ 1,
23
+ );
17
24
 
18
25
  export function registerScrollOwner(
19
26
  element: HTMLElement,
@@ -28,6 +28,7 @@ import {
28
28
  import {isLayerSurface} from '../Layer/layerSurfacePress';
29
29
  import {isSafeUrl} from '../utils/safeUrl';
30
30
  import {cancelPress} from '../utils/pressFeedback';
31
+ import {pressBoxesIn} from '../privateAttributes/pressBox.stylex';
31
32
 
32
33
  /**
33
34
  * The attribute this hook sets on the container it makes clickable. A click
@@ -129,10 +130,12 @@ function belongsToSomethingElse(element: Element): boolean {
129
130
  }
130
131
 
131
132
  /**
132
- * The touch half of a container's press rule: a finger press that starts on a nested interactive element
133
- * other than the container's own action does not activate the container, so
134
- * it ends the press controller's paint on `container`. A mouse or pen press,
135
- * and a press on the container's surface or on `ownAction`, are left alone.
133
+ * The press half of a container's press rule. A press that starts on a nested
134
+ * interactive element other than the container's own action does not activate
135
+ * the container. So it ends the press controller's paint on `container`. The
136
+ * rule covers a finger's press on every container. On a container that owns a
137
+ * control's box (pressBox.stylex.ts), it covers a mouse's and a pen's press
138
+ * too. A press on the container's surface or on `ownAction` is left alone.
136
139
  * Not part of the package's public API.
137
140
  */
138
141
  export function cancelNestedTouchPress(
@@ -142,8 +145,8 @@ export function cancelNestedTouchPress(
142
145
  ): void {
143
146
  const target = event.target;
144
147
  if (
145
- event.pointerType !== 'touch' ||
146
148
  container == null ||
149
+ (event.pointerType !== 'touch' && pressBoxesIn(container).length === 0) ||
147
150
  !(target instanceof Element) ||
148
151
  target === event.currentTarget ||
149
152
  !hasInteractiveAncestor(target, container) ||
@@ -366,9 +369,9 @@ export function useClickableContainerProxy({
366
369
  [containerRef, href, disabled],
367
370
  );
368
371
 
369
- // The press-state counterpart of onClick's rule, for touch: a finger press
370
- // that would not activate the container shows no press on it. A mouse or
371
- // pen press keeps its `:active` paint.
372
+ // The press-state counterpart of onClick's rule: a press that would not
373
+ // activate the container shows no press on it. That holds for a finger on
374
+ // every container, and for a mouse or a pen on one that owns a control's box.
372
375
  const onPointerDown = useCallback(
373
376
  (event: PointerEvent<HTMLElement>) => {
374
377
  if (disabled) {
@@ -399,6 +399,12 @@ export function useFocusRegionContainment(
399
399
  }
400
400
 
401
401
  if (event.key === 'Tab') {
402
+ if (event.ctrlKey || event.metaKey) {
403
+ // Ctrl+Tab and Meta+Tab switch tabs or apps. They do not move
404
+ // focus, so the region leaves them to the browser and the page.
405
+ // Alt+Tab stays: Safari moves focus to each item on Option+Tab.
406
+ return;
407
+ }
402
408
  if (event.defaultPrevented) {
403
409
  // A control that handles Tab itself (an editor that indents) keeps
404
410
  // focus where it is.
@@ -654,7 +654,26 @@ export function useMenuPress(input: UseMenuPressOptions): UseMenuPressReturn {
654
654
  }
655
655
  return;
656
656
  }
657
+ case 'withdraw': {
658
+ // The window's blur withdrew a finger's gesture. It stays tracked to
659
+ // its release, but nothing drives the menu any more (the hold, the
660
+ // autoscroll, the page lock). A row a finger lit clears.
661
+ longPressApiRef.current?.cancel();
662
+ stopAutoscroll();
663
+ touchMovePreventerRef.current?.();
664
+ touchMovePreventerRef.current = null;
665
+ if (effect.clear === true) {
666
+ highlight(null);
667
+ }
668
+ return;
669
+ }
657
670
  case 'settle': {
671
+ // A finger's lit row clears on a cancel, on every surface. The
672
+ // machine sets `clear` only for a finger or pen, so a mouse keeps its
673
+ // highlight.
674
+ if (effect.clear === true) {
675
+ highlight(null);
676
+ }
658
677
  endGesture();
659
678
  if (effect.stray) {
660
679
  armClickGuard(doc, {
@@ -669,7 +688,7 @@ export function useMenuPress(input: UseMenuPressOptions): UseMenuPressReturn {
669
688
  }
670
689
  }
671
690
  },
672
- [activate, endGesture, getDocument, highlight],
691
+ [activate, endGesture, getDocument, highlight, stopAutoscroll],
673
692
  );
674
693
 
675
694
  const step = useCallback(
@@ -817,6 +836,12 @@ export function useMenuPress(input: UseMenuPressOptions): UseMenuPressReturn {
817
836
  stepRef.current({type: 'cancel'});
818
837
  };
819
838
  const onOtherPointerDown = (event: PointerEvent) => {
839
+ // Any press ends a withdrawn gesture: its finger lifted where the
840
+ // page could not see it, and the new press's click must act.
841
+ if (gestureRef.current.phase === 'withdrawn') {
842
+ stepRef.current({type: 'cancel'});
843
+ return;
844
+ }
820
845
  // A second pointer ends the gesture: two fingers are a pinch or a
821
846
  // scroll, never a pick.
822
847
  if (event.pointerId !== pointerIdRef.current) {
@@ -825,7 +850,12 @@ export function useMenuPress(input: UseMenuPressOptions): UseMenuPressReturn {
825
850
  }
826
851
  };
827
852
  const onBlur = () => {
828
- stepRef.current({type: 'cancel'});
853
+ // A finger's or pen's gesture is withdrawn, not ended. The browser can
854
+ // keep the touch alive past the blur, so the gesture stays tracked on
855
+ // these listeners until its release. That release acts on nothing, and
856
+ // its click is swallowed. A mouse press ends as a cancel and keeps its
857
+ // click.
858
+ stepRef.current({type: 'withdraw'});
829
859
  };
830
860
 
831
861
  doc.addEventListener('pointermove', onMove, true);