@astryxdesign/core 0.7.6 → 0.7.7-canary.1d04d40

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 (173) hide show
  1. package/dist/AppShell/AppShell.d.ts.map +1 -1
  2. package/dist/AppShell/AppShell.js +23 -3
  3. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  4. package/dist/BottomSheet/BottomSheetPanel.js +16 -9
  5. package/dist/Chat/ChatComposerInput.d.ts +9 -0
  6. package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
  7. package/dist/Chat/ChatComposerInput.js +2 -0
  8. package/dist/Chat/ChatMessage.js +2 -2
  9. package/dist/Chat/chatMessage.vars.stylex.d.ts +8 -8
  10. package/dist/Chat/chatMessage.vars.stylex.js +8 -8
  11. package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
  12. package/dist/CommandPalette/CommandPaletteInput.js +8 -1
  13. package/dist/DateInput/MonthScroller.d.ts.map +1 -1
  14. package/dist/DateInput/MonthScroller.js +72 -2
  15. package/dist/Drawer/Drawer.d.ts.map +1 -1
  16. package/dist/Drawer/Drawer.js +6 -0
  17. package/dist/DropdownMenu/useMenuOverflow.d.ts +13 -3
  18. package/dist/DropdownMenu/useMenuOverflow.d.ts.map +1 -1
  19. package/dist/DropdownMenu/useMenuOverflow.js +31 -8
  20. package/dist/Field/PanelSearchInput.d.ts.map +1 -1
  21. package/dist/Field/PanelSearchInput.js +8 -1
  22. package/dist/Field/textEntryTraits.d.ts +6 -6
  23. package/dist/Field/textEntryTraits.js +6 -6
  24. package/dist/Layer/layerClickBoundary.d.ts +7 -1
  25. package/dist/Layer/layerClickBoundary.d.ts.map +1 -1
  26. package/dist/Layer/layerClickBoundary.js +2 -2
  27. package/dist/Layer/usePressPin.d.ts +95 -0
  28. package/dist/Layer/usePressPin.d.ts.map +1 -0
  29. package/dist/Layer/usePressPin.js +335 -0
  30. package/dist/Layer/useTouchTrigger.d.ts +23 -1
  31. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  32. package/dist/Layer/useTouchTrigger.js +29 -2
  33. package/dist/Link/Link.d.ts.map +1 -1
  34. package/dist/Link/Link.js +1 -0
  35. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  36. package/dist/ProgressBar/ProgressBar.js +20 -9
  37. package/dist/ProgressBar/ProgressBarTouch.d.ts +29 -0
  38. package/dist/ProgressBar/ProgressBarTouch.d.ts.map +1 -0
  39. package/dist/ProgressBar/ProgressBarTouch.js +91 -0
  40. package/dist/Selector/Selector.d.ts.map +1 -1
  41. package/dist/Selector/Selector.js +25 -13
  42. package/dist/Slider/Slider.d.ts.map +1 -1
  43. package/dist/Slider/Slider.js +404 -131
  44. package/dist/Slider/sliderTouchController.d.ts +189 -0
  45. package/dist/Slider/sliderTouchController.d.ts.map +1 -0
  46. package/dist/Slider/sliderTouchController.js +1017 -0
  47. package/dist/Slider/useSliderTouch.d.ts +22 -0
  48. package/dist/Slider/useSliderTouch.d.ts.map +1 -0
  49. package/dist/Slider/useSliderTouch.js +56 -0
  50. package/dist/Tooltip/Tooltip.d.ts +30 -6
  51. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  52. package/dist/Tooltip/Tooltip.js +5 -0
  53. package/dist/Tooltip/index.d.ts +1 -1
  54. package/dist/Tooltip/index.d.ts.map +1 -1
  55. package/dist/Tooltip/useTooltip.d.ts +31 -5
  56. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  57. package/dist/Tooltip/useTooltip.js +59 -18
  58. package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
  59. package/dist/Typeahead/BaseTypeahead.js +19 -9
  60. package/dist/astryx.css +40 -6
  61. package/dist/gestures/GestureArena.d.ts +21 -2
  62. package/dist/gestures/GestureArena.d.ts.map +1 -1
  63. package/dist/gestures/GestureArena.js +23 -3
  64. package/dist/gestures/GestureHost.d.ts +123 -3
  65. package/dist/gestures/GestureHost.d.ts.map +1 -1
  66. package/dist/gestures/GestureHost.js +791 -12
  67. package/dist/gestures/GestureRecognizer.d.ts +15 -1
  68. package/dist/gestures/GestureRecognizer.d.ts.map +1 -1
  69. package/dist/gestures/GestureRecognizer.js +12 -0
  70. package/dist/gestures/PanGestureRecognizer.d.ts +8 -0
  71. package/dist/gestures/PanGestureRecognizer.d.ts.map +1 -1
  72. package/dist/gestures/PinchGestureRecognizer.d.ts +5 -1
  73. package/dist/gestures/PinchGestureRecognizer.d.ts.map +1 -1
  74. package/dist/gestures/PinchGestureRecognizer.js +10 -0
  75. package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts +3 -3
  76. package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts.map +1 -1
  77. package/dist/gestures/ScreenEdgePanGestureRecognizer.js +7 -5
  78. package/dist/gestures/nativeScroll.d.ts +16 -2
  79. package/dist/gestures/nativeScroll.d.ts.map +1 -1
  80. package/dist/gestures/nativeScroll.js +39 -8
  81. package/dist/gestures/recognizerInternals.d.ts +4 -2
  82. package/dist/gestures/recognizerInternals.d.ts.map +1 -1
  83. package/dist/gestures/types.d.ts +11 -0
  84. package/dist/gestures/types.d.ts.map +1 -1
  85. package/dist/gestures/types.js +7 -0
  86. package/dist/gestures/wheelSegmenter.d.ts +45 -0
  87. package/dist/gestures/wheelSegmenter.d.ts.map +1 -0
  88. package/dist/gestures/wheelSegmenter.js +98 -0
  89. package/dist/motion/animator.d.ts.map +1 -1
  90. package/dist/motion/animator.js +140 -19
  91. package/dist/motion/paging.d.ts +58 -0
  92. package/dist/motion/paging.d.ts.map +1 -0
  93. package/dist/motion/paging.js +128 -0
  94. package/dist/motion/uikit/index.d.ts +5 -3
  95. package/dist/motion/uikit/index.d.ts.map +1 -1
  96. package/dist/motion/uikit/index.js +5 -3
  97. package/dist/motion/uikit/paging.d.ts +160 -0
  98. package/dist/motion/uikit/paging.d.ts.map +1 -0
  99. package/dist/motion/uikit/paging.js +162 -0
  100. package/dist/motion/uikit/progressBar.d.ts +59 -0
  101. package/dist/motion/uikit/progressBar.d.ts.map +1 -0
  102. package/dist/motion/uikit/progressBar.js +82 -0
  103. package/dist/motion/uikit/scroll.d.ts +0 -19
  104. package/dist/motion/uikit/scroll.d.ts.map +1 -1
  105. package/dist/motion/uikit/scroll.js +2 -21
  106. package/dist/motion/uikit/slider.d.ts +97 -0
  107. package/dist/motion/uikit/slider.d.ts.map +1 -0
  108. package/dist/motion/uikit/slider.js +111 -0
  109. package/dist/motion/uikit/springs.d.ts +46 -1
  110. package/dist/motion/uikit/springs.d.ts.map +1 -1
  111. package/dist/motion/uikit/springs.js +48 -4
  112. package/dist/utils/selectionLock.d.ts +43 -0
  113. package/dist/utils/selectionLock.d.ts.map +1 -1
  114. package/dist/utils/selectionLock.js +394 -6
  115. package/package.json +5 -5
  116. package/src/AppShell/AppShell.doc.mjs +10 -0
  117. package/src/AppShell/AppShell.tsx +48 -2
  118. package/src/BottomSheet/BottomSheetPanel.tsx +16 -9
  119. package/src/Chat/Chat.doc.mjs +1 -0
  120. package/src/Chat/ChatComposerInput.doc.mjs +11 -0
  121. package/src/Chat/ChatComposerInput.tsx +11 -0
  122. package/src/Chat/ChatMessage.tsx +2 -2
  123. package/src/Chat/chatMessage.vars.stylex.ts +8 -8
  124. package/src/CommandPalette/CommandPaletteInput.tsx +6 -0
  125. package/src/DateInput/MonthScroller.tsx +63 -5
  126. package/src/Drawer/Drawer.tsx +6 -0
  127. package/src/DropdownMenu/useMenuOverflow.ts +44 -8
  128. package/src/Field/PanelSearchInput.tsx +6 -0
  129. package/src/Field/textEntryTraits.ts +6 -6
  130. package/src/Layer/layerClickBoundary.ts +2 -2
  131. package/src/Layer/usePressPin.ts +481 -0
  132. package/src/Layer/useTouchTrigger.ts +37 -1
  133. package/src/Link/Link.tsx +3 -0
  134. package/src/ProgressBar/ProgressBar.doc.mjs +3 -3
  135. package/src/ProgressBar/ProgressBar.tsx +82 -11
  136. package/src/ProgressBar/ProgressBarTouch.ts +109 -0
  137. package/src/Selector/Selector.tsx +29 -2
  138. package/src/Slider/Slider.doc.mjs +11 -7
  139. package/src/Slider/Slider.tsx +539 -132
  140. package/src/Slider/sliderTouchController.ts +1209 -0
  141. package/src/Slider/useSliderTouch.ts +78 -0
  142. package/src/Tooltip/Tooltip.doc.mjs +21 -6
  143. package/src/Tooltip/Tooltip.tsx +42 -5
  144. package/src/Tooltip/index.ts +1 -0
  145. package/src/Tooltip/useTooltip.doc.mjs +4 -2
  146. package/src/Tooltip/useTooltip.tsx +84 -21
  147. package/src/Typeahead/BaseTypeahead.tsx +16 -8
  148. package/src/gestures/GestureArena.ts +45 -4
  149. package/src/gestures/GestureHost.ts +949 -12
  150. package/src/gestures/GestureRecognizer.ts +28 -0
  151. package/src/gestures/PanGestureRecognizer.ts +8 -0
  152. package/src/gestures/PinchGestureRecognizer.ts +16 -1
  153. package/src/gestures/README.md +82 -3
  154. package/src/gestures/ScreenEdgePanGestureRecognizer.ts +7 -5
  155. package/src/gestures/nativeScroll.ts +49 -9
  156. package/src/gestures/recognizerInternals.ts +9 -2
  157. package/src/gestures/types.ts +12 -0
  158. package/src/gestures/wheelSegmenter.ts +114 -0
  159. package/src/motion/MEASUREMENTS.md +8 -1
  160. package/src/motion/README.md +6 -3
  161. package/src/motion/animator.ts +193 -25
  162. package/src/motion/paging.ts +138 -0
  163. package/src/motion/uikit/index.ts +5 -3
  164. package/src/motion/uikit/paging.ts +162 -0
  165. package/src/motion/uikit/progressBar.ts +82 -0
  166. package/src/motion/uikit/scroll.ts +2 -18
  167. package/src/motion/uikit/slider.ts +105 -0
  168. package/src/motion/uikit/springs.ts +37 -2
  169. package/src/utils/selectionLock.ts +501 -6
  170. package/dist/motion/selectPage.d.ts +0 -26
  171. package/dist/motion/selectPage.d.ts.map +0 -1
  172. package/dist/motion/selectPage.js +0 -55
  173. package/src/motion/selectPage.ts +0 -55
@@ -488,6 +488,42 @@ export const BANNER_SPRING = {
488
488
  damping: 500
489
489
  };
490
490
 
491
+ /**
492
+ * UISlider's release: after a finger lifts, the thumb settles on this spring
493
+ * toward 0.4 of the release's momentum projection. It is critically damped,
494
+ * so it never overshoots a target ahead of it.
495
+ * @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro. The
496
+ * `UIViewSpringAnimationBehavior` at the lift reads response 0.4 and
497
+ * damping ratio 1. Four releases fit it per frame (the UIKit slider
498
+ * table). Oct 23 2026
499
+ */
500
+ export const SLIDER_RELEASE_SPRING = {
501
+ response: 0.4,
502
+ dampingRatio: 1
503
+ };
504
+
505
+ /**
506
+ * UISlider's lift: a finger's touch-down scales the thumb up on this spring.
507
+ * @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro. The
508
+ * thumb's scale per frame after touch-down (the UIKit slider table).
509
+ * Oct 23 2026
510
+ */
511
+ export const SLIDER_LIFT_SPRING = {
512
+ response: 0.215,
513
+ dampingRatio: 0.6
514
+ };
515
+
516
+ /**
517
+ * UISlider's drop: the lift's end scales the thumb back down on this spring.
518
+ * @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro. The
519
+ * thumb's scale per frame after the lift (the UIKit slider table).
520
+ * Oct 23 2026
521
+ */
522
+ export const SLIDER_DROP_SPRING = {
523
+ response: 0.5,
524
+ dampingRatio: 0.7
525
+ };
526
+
491
527
  /**
492
528
  * Every spring above, by row name: the table the existing readers use. A
493
529
  * component imports only the rows it plays (`architecture:component-style-authoring`
@@ -527,11 +563,16 @@ export const springs = {
527
563
  switchThumbStretch: SWITCH_THUMB_STRETCH_SPRING,
528
564
  segmentedThumb: SEGMENTED_THUMB_SPRING,
529
565
  keyboard: KEYBOARD_SPRING,
530
- banner: BANNER_SPRING
566
+ banner: BANNER_SPRING,
567
+ sliderRelease: SLIDER_RELEASE_SPRING,
568
+ sliderLift: SLIDER_LIFT_SPRING,
569
+ sliderDrop: SLIDER_DROP_SPRING
531
570
  };
532
571
 
533
572
  /**
534
- * The springs spec:AST-094 FR4 names: the only ones that are motion roles.
573
+ * The only springs that are motion roles. The touch presentations' record
574
+ * names some, and a component's own record names others, such as Slider's
575
+ * three. The generated motion role table lists each with its record.
535
576
  * The registry takes these rows alone, so registering ships no other spring.
536
577
  */
537
578
  const SPRING_ROLES = {
@@ -549,11 +590,14 @@ const SPRING_ROLES = {
549
590
  subMenuBack: SUB_MENU_BACK_SPRING,
550
591
  contextMenuLift: CONTEXT_MENU_LIFT_SPRING,
551
592
  contextMenuDismiss: CONTEXT_MENU_DISMISS_SPRING,
552
- contextMenuMorph: CONTEXT_MENU_MORPH_SPRING
593
+ contextMenuMorph: CONTEXT_MENU_MORPH_SPRING,
594
+ sliderRelease: SLIDER_RELEASE_SPRING,
595
+ sliderLift: SLIDER_LIFT_SPRING,
596
+ sliderDrop: SLIDER_DROP_SPRING
553
597
  };
554
598
 
555
599
  /**
556
- * Registers the springs spec:AST-094 FR4 names as internal motion roles
600
+ * Registers the role springs (`SPRING_ROLES`) as internal motion roles
557
601
  * (motion/roles.ts), by their row names (`springs.settle`). Every other
558
602
  * spring, UIKit's menu spring under Reduce Motion and the keyboard's
559
603
  * included, is not a role. Nothing registers on import: the touch code that
@@ -10,4 +10,47 @@ export declare function locksSelectionFor(pointerType: string): boolean;
10
10
  * any holder holds. Idempotent release.
11
11
  */
12
12
  export declare function lockSelection(elements: Iterable<Element>, target: EventTarget | null): () => void;
13
+ /** How a drag's selection hold ends: at a lift, or at a cancel. */
14
+ export interface DragSelectionReleaseOptions {
15
+ /**
16
+ * The press was cancelled (a pointercancel, a blur, a detach), so no
17
+ * mouseup or click follows: the hold ends at once. Called again after a
18
+ * lift, it ends the hold's last task at once too.
19
+ */
20
+ isCancel?: boolean;
21
+ }
22
+ /**
23
+ * Refuse a new selection while a mouse or pen drag that a recognizer claimed
24
+ * runs, until the returned function runs. `kept` is the page's selection
25
+ * when the press began, and it stays. Anything that replaces it while the
26
+ * drag runs is put back to it. That includes the press's own collapse and a
27
+ * selection the drag started before its claim. So the drag takes no new
28
+ * selection and never clears an existing one. `elements` refuse a
29
+ * selection with inline styles, on every engine. The document refuses one
30
+ * too, because WebKit extends a drag's selection over text outside the
31
+ * elements without another `selectstart`. So a `selectstart` anywhere is
32
+ * refused, and the selection is put back. A `selectstart` does not leave its
33
+ * shadow tree. So the document refuses only one that starts outside every
34
+ * shadow tree, and a claiming element inside one refuses its own. The
35
+ * press's own `mouseup` and `click` come after its `pointerup` in the same
36
+ * task, and WebKit settles the drag's selection there. So the document's
37
+ * hold ends a task after a lift. A cancel ends it at once, because nothing
38
+ * follows a cancel. `onReleased` runs once the document's hold has ended.
39
+ * The page listeners exist only during a press. Idempotent.
40
+ */
41
+ export declare function lockDragSelection(elements: Iterable<Element>, view: Window | null | undefined, kept: ReadonlyArray<AbstractRange>, onReleased?: () => void): (options?: DragSelectionReleaseOptions) => void;
42
+ /**
43
+ * The page's selection now, its ranges copied; none for a collapsed or empty
44
+ * one. A drag's hold keeps what this read when the press began.
45
+ */
46
+ export declare function selectionRangesOf(view: Window | null | undefined): ReadonlyArray<AbstractRange>;
47
+ /**
48
+ * Whether a press at (`x`, `y`) lands on text a drag would select. That is a
49
+ * text field, or a character of non-empty text whose element allows a
50
+ * selection. A native button's label, slotted or not, is not selectable text,
51
+ * because the engine starts no selection from a drag inside a button. A point
52
+ * beside text, which a caret query snaps to the nearest character, lands on
53
+ * none. Where the engine has no caret query, nothing is selectable text.
54
+ */
55
+ export declare function startsOnSelectableText(doc: Document, x: number, y: number, target: EventTarget | null): boolean;
13
56
  //# sourceMappingURL=selectionLock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"selectionLock.d.ts","sourceRoot":"","sources":["../../src/utils/selectionLock.ts"],"names":[],"mappings":"AAkDA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE9D;AAWD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC3B,MAAM,EAAE,WAAW,GAAG,IAAI,GACzB,MAAM,IAAI,CAyEZ"}
1
+ {"version":3,"file":"selectionLock.d.ts","sourceRoot":"","sources":["../../src/utils/selectionLock.ts"],"names":[],"mappings":"AAoDA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE9D;AAWD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC3B,MAAM,EAAE,WAAW,GAAG,IAAI,GACzB,MAAM,IAAI,CA4BZ;AAED,mEAAmE;AACnE,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,EAClC,UAAU,CAAC,EAAE,MAAM,IAAI,GACtB,CAAC,OAAO,CAAC,EAAE,2BAA2B,KAAK,IAAI,CA+EjD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC9B,aAAa,CAAC,aAAa,CAAC,CAiB9B;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,QAAQ,EACb,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,WAAW,GAAG,IAAI,GACzB,OAAO,CA+CT"}
@@ -3,11 +3,12 @@
3
3
  /**
4
4
  * @file selectionLock.ts
5
5
  * @input The elements a held touch contact presses, and the touch's target
6
- * @output lockSelection: no text selection and no touch callout under the
7
- * held finger until the release runs; and locksSelectionFor: which contacts
8
- * take it
9
- * @position Brought by the recognizers whose hold does something. The gesture
10
- * host calls it and never imports it.
6
+ * @output lockSelection and locksSelectionFor give a held finger's lock.
7
+ * lockDragSelection gives a claimed mouse or pen drag's hold, which keeps
8
+ * the page's selection. startsOnSelectableText and selectionRangesOf are
9
+ * what a mouse or pen press reads.
10
+ * @position Recognizers whose hold does something bring lockSelection; the
11
+ * gesture host imports the drag hold and the press reads.
11
12
  *
12
13
  * SYNC: When modified, update GestureHost.ts and utils/pressFeedback.ts; the
13
14
  * iOS query matches utils/touchPresentation.ts.
@@ -27,7 +28,8 @@
27
28
  //
28
29
  // A mouse never takes the lock, so its released behavior stays (AST-017).
29
30
 
30
- import { containsAlongFlatTree } from "./flatTree.js";
31
+ import { containsAlongFlatTree, parentAcrossShadow } from "./flatTree.js";
32
+ import { subscribeInput } from "./inputStream.js";
31
33
  import { isIosWebKit } from "./touchQueries.js";
32
34
 
33
35
  /** What a held finger must not start on a control or a cell. */
@@ -77,6 +79,392 @@ export function lockSelection(elements, target) {
77
79
  }
78
80
  };
79
81
  }
82
+ return lockStyles(set);
83
+ }
84
+
85
+ /** How a drag's selection hold ends: at a lift, or at a cancel. */
86
+
87
+ /**
88
+ * Refuse a new selection while a mouse or pen drag that a recognizer claimed
89
+ * runs, until the returned function runs. `kept` is the page's selection
90
+ * when the press began, and it stays. Anything that replaces it while the
91
+ * drag runs is put back to it. That includes the press's own collapse and a
92
+ * selection the drag started before its claim. So the drag takes no new
93
+ * selection and never clears an existing one. `elements` refuse a
94
+ * selection with inline styles, on every engine. The document refuses one
95
+ * too, because WebKit extends a drag's selection over text outside the
96
+ * elements without another `selectstart`. So a `selectstart` anywhere is
97
+ * refused, and the selection is put back. A `selectstart` does not leave its
98
+ * shadow tree. So the document refuses only one that starts outside every
99
+ * shadow tree, and a claiming element inside one refuses its own. The
100
+ * press's own `mouseup` and `click` come after its `pointerup` in the same
101
+ * task, and WebKit settles the drag's selection there. So the document's
102
+ * hold ends a task after a lift. A cancel ends it at once, because nothing
103
+ * follows a cancel. `onReleased` runs once the document's hold has ended.
104
+ * The page listeners exist only during a press. Idempotent.
105
+ */
106
+ export function lockDragSelection(elements, view, kept, onReleased) {
107
+ const doc = view?.document ?? null;
108
+ const roots = shadowRootsOfRanges(kept);
109
+ const restore = () => {
110
+ const selection = view?.getSelection();
111
+ // The focused field keeps its own selection (a drag never starts in one).
112
+ if (selection == null || isTextEntry(deepActiveElement(doc))) {
113
+ return;
114
+ }
115
+ const held = heldRanges(selection, roots);
116
+ if (kept.length === 0) {
117
+ if (held.some(range => !range.collapsed)) {
118
+ selection.removeAllRanges();
119
+ }
120
+ return;
121
+ }
122
+ // A render can remove what the kept selection held: then there is
123
+ // nothing to put back.
124
+ if (sameRanges(held, kept) || !kept.every(isValidRange)) {
125
+ return;
126
+ }
127
+ selectRanges(selection, kept);
128
+ };
129
+ restore();
130
+ const set = new Set(elements);
131
+ const refuse = event => {
132
+ if (!isTextEntry(event.target)) {
133
+ event.preventDefault();
134
+ }
135
+ };
136
+ for (const element of set) {
137
+ element.addEventListener('selectstart', refuse);
138
+ }
139
+ const stopDocument = view == null ? [] : [subscribeInput(view, 'selectstart', refuse, {
140
+ cancels: true
141
+ }), subscribeInput(view, 'selectionchange', restore)];
142
+ const unlockStyles = lockStyles(set);
143
+ let stage = 'held';
144
+ let timer = null;
145
+ const releaseDocument = () => {
146
+ if (stage === 'done') {
147
+ return;
148
+ }
149
+ stage = 'done';
150
+ if (timer != null) {
151
+ view?.clearTimeout(timer);
152
+ timer = null;
153
+ }
154
+ try {
155
+ restore();
156
+ } finally {
157
+ for (const stop of stopDocument) {
158
+ stop();
159
+ }
160
+ onReleased?.();
161
+ }
162
+ };
163
+ return ({
164
+ isCancel = false
165
+ } = {}) => {
166
+ if (stage === 'held') {
167
+ stage = 'lifted';
168
+ for (const element of set) {
169
+ element.removeEventListener('selectstart', refuse);
170
+ }
171
+ unlockStyles();
172
+ // A lift's own mouseup and click follow in its task and must still
173
+ // meet the hold; nothing follows a cancel, which ends it at once.
174
+ if (view == null || isCancel) {
175
+ releaseDocument();
176
+ } else {
177
+ timer = view.setTimeout(releaseDocument, 0);
178
+ }
179
+ } else if (stage === 'lifted' && isCancel) {
180
+ releaseDocument();
181
+ }
182
+ };
183
+ }
184
+
185
+ /**
186
+ * The page's selection now, its ranges copied; none for a collapsed or empty
187
+ * one. A drag's hold keeps what this read when the press began.
188
+ */
189
+ export function selectionRangesOf(view) {
190
+ const selection = view?.getSelection();
191
+ if (selection == null) {
192
+ return [];
193
+ }
194
+ const composed = composedRangesOf(selection, []);
195
+ if (composed != null) {
196
+ return composed.filter(range => !range.collapsed).map(liveWhereItCan);
197
+ }
198
+ if (selection.isCollapsed) {
199
+ return [];
200
+ }
201
+ const ranges = [];
202
+ for (let index = 0; index < selection.rangeCount; index++) {
203
+ ranges.push(selection.getRangeAt(index).cloneRange());
204
+ }
205
+ return ranges;
206
+ }
207
+
208
+ /**
209
+ * Whether a press at (`x`, `y`) lands on text a drag would select. That is a
210
+ * text field, or a character of non-empty text whose element allows a
211
+ * selection. A native button's label, slotted or not, is not selectable text,
212
+ * because the engine starts no selection from a drag inside a button. A point
213
+ * beside text, which a caret query snaps to the nearest character, lands on
214
+ * none. Where the engine has no caret query, nothing is selectable text.
215
+ */
216
+ export function startsOnSelectableText(doc, x, y, target) {
217
+ if (isTextEntry(target)) {
218
+ return true;
219
+ }
220
+ const caret = caretAt(doc, x, y, [...ownShadowRoot(target), ...openShadowRootsOf(target)]);
221
+ if (caret == null) {
222
+ return false;
223
+ }
224
+ const {
225
+ node,
226
+ offset
227
+ } = caret;
228
+ if (node.nodeType !== 3 || (node.textContent ?? '').trim() === '') {
229
+ return false;
230
+ }
231
+ // Text directly under a shadow root takes its host's style.
232
+ const element = node.parentElement ?? (node.parentNode?.nodeType === 11 ? node.parentNode.host : null);
233
+ if (element == null || !allowsSelection(element) || isInButton(node)) {
234
+ return false;
235
+ }
236
+ const length = (node.textContent ?? '').length;
237
+ const range = doc.createRange();
238
+ if (typeof range.getClientRects !== 'function') {
239
+ return false;
240
+ }
241
+ for (const start of [offset - 1, offset]) {
242
+ if (start < 0 || start >= length) {
243
+ continue;
244
+ }
245
+ range.setStart(node, start);
246
+ range.setEnd(node, start + 1);
247
+ for (const rect of Array.from(range.getClientRects())) {
248
+ if (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom) {
249
+ return true;
250
+ }
251
+ }
252
+ }
253
+ return false;
254
+ }
255
+
256
+ /** Whether `node` is inside a native button, along the flat tree. */
257
+ function isInButton(node) {
258
+ for (let at = node; at != null; at = parentAcrossShadow(at)) {
259
+ if (at.nodeType === 1 && at.localName === 'button') {
260
+ return true;
261
+ }
262
+ }
263
+ return false;
264
+ }
265
+
266
+ /** The caret position the engine puts at a point, by either query. */
267
+ function caretAt(doc, x, y, shadowRoots) {
268
+ const queries = doc;
269
+ if (typeof queries.caretPositionFromPoint === 'function') {
270
+ // Without the roots, a point over shadow text answers at its host.
271
+ const position = shadowRoots.length > 0 ? queries.caretPositionFromPoint(x, y, {
272
+ shadowRoots: [...shadowRoots]
273
+ }) : queries.caretPositionFromPoint(x, y);
274
+ return position == null ? null : {
275
+ node: position.offsetNode,
276
+ offset: position.offset
277
+ };
278
+ }
279
+ if (typeof queries.caretRangeFromPoint === 'function') {
280
+ const range = queries.caretRangeFromPoint(x, y);
281
+ return range == null ? null : {
282
+ node: range.startContainer,
283
+ offset: range.startOffset
284
+ };
285
+ }
286
+ return null;
287
+ }
288
+
289
+ /** Whether an element's text can be selected (`user-select` is not none). */
290
+ function allowsSelection(element) {
291
+ const style = element.ownerDocument.defaultView?.getComputedStyle(element);
292
+ if (style == null) {
293
+ return false;
294
+ }
295
+ return style.getPropertyValue('user-select') !== 'none' && style.getPropertyValue('-webkit-user-select') !== 'none';
296
+ }
297
+
298
+ /**
299
+ * The ranges `selection` holds, with boundaries inside `shadowRoots` where the
300
+ * engine reads composed ranges.
301
+ */
302
+ function heldRanges(selection, shadowRoots) {
303
+ const composed = composedRangesOf(selection, shadowRoots);
304
+ if (composed != null) {
305
+ return composed;
306
+ }
307
+ const ranges = [];
308
+ for (let index = 0; index < selection.rangeCount; index++) {
309
+ ranges.push(selection.getRangeAt(index));
310
+ }
311
+ return ranges;
312
+ }
313
+
314
+ /**
315
+ * A live copy of `range` when both boundaries share a root, so it follows
316
+ * DOM changes. A range across roots stays static: no live range holds it.
317
+ */
318
+ function liveWhereItCan(range) {
319
+ const live = range.startContainer.ownerDocument?.createRange();
320
+ if (live == null || range.startContainer.getRootNode() !== range.endContainer.getRootNode()) {
321
+ return range;
322
+ }
323
+ live.setStart(range.startContainer, range.startOffset);
324
+ live.setEnd(range.endContainer, range.endOffset);
325
+ return live;
326
+ }
327
+
328
+ /** Whether both of `range`'s boundaries still exist in the document. */
329
+ function isValidRange(range) {
330
+ return isValidBoundary(range.startContainer, range.startOffset) && isValidBoundary(range.endContainer, range.endOffset);
331
+ }
332
+ function isValidBoundary(node, offset) {
333
+ const length = node.nodeType === 3 || node.nodeType === 4 || node.nodeType === 8 ? node.length : node.childNodes.length;
334
+ return node.isConnected && offset >= 0 && offset <= length;
335
+ }
336
+
337
+ /** Whether two range lists have the same boundaries, in order. */
338
+ function sameRanges(held, kept) {
339
+ return held.length === kept.length && kept.every((range, index) => {
340
+ const other = held[index];
341
+ return other.startContainer === range.startContainer && other.startOffset === range.startOffset && other.endContainer === range.endContainer && other.endOffset === range.endOffset;
342
+ });
343
+ }
344
+
345
+ /**
346
+ * Put `ranges` back as the selection. One range goes through
347
+ * `setBaseAndExtent`, which also reaches inside a shadow root.
348
+ */
349
+ function selectRanges(selection, ranges) {
350
+ const [only] = ranges;
351
+ if (ranges.length === 1 && typeof selection.setBaseAndExtent === 'function') {
352
+ selection.setBaseAndExtent(only.startContainer, only.startOffset, only.endContainer, only.endOffset);
353
+ return;
354
+ }
355
+ selection.removeAllRanges();
356
+ for (const range of ranges) {
357
+ const copy = range.startContainer.ownerDocument?.createRange();
358
+ if (copy == null) {
359
+ continue;
360
+ }
361
+ copy.setStart(range.startContainer, range.startOffset);
362
+ copy.setEnd(range.endContainer, range.endOffset);
363
+ selection.addRange(copy);
364
+ }
365
+ }
366
+
367
+ /**
368
+ * The selection's composed ranges, reaching into each open shadow root a
369
+ * boundary lands on; null where the engine has no `getComposedRanges`.
370
+ * Without the roots, a selection inside a shadow root reads as one around
371
+ * its host.
372
+ */
373
+ function composedRangesOf(selection, known) {
374
+ const query = selection.getComposedRanges;
375
+ if (typeof query !== 'function') {
376
+ return null;
377
+ }
378
+ // Engines take the roots as a dictionary, or, in older releases, as
379
+ // arguments.
380
+ const read = roots => {
381
+ try {
382
+ return query.call(selection, {
383
+ shadowRoots: roots
384
+ });
385
+ } catch {
386
+ try {
387
+ return query.call(selection, ...roots);
388
+ } catch {
389
+ return null;
390
+ }
391
+ }
392
+ };
393
+ const roots = [...known];
394
+ for (;;) {
395
+ const ranges = read([...roots]);
396
+ if (ranges == null) {
397
+ return null;
398
+ }
399
+ const found = new Set();
400
+ for (const range of ranges) {
401
+ for (const [node, offset] of [[range.startContainer, range.startOffset], [range.endContainer, range.endOffset]]) {
402
+ for (const child of [node.childNodes[offset], node.childNodes[offset - 1]]) {
403
+ const root = child?.nodeType === 1 ? child.shadowRoot : null;
404
+ if (root != null && !roots.includes(root)) {
405
+ found.add(root);
406
+ }
407
+ }
408
+ }
409
+ }
410
+ if (found.size === 0) {
411
+ return ranges;
412
+ }
413
+ roots.push(...found);
414
+ }
415
+ }
416
+
417
+ /** The open shadow roots on the root chains of `ranges`' boundaries. */
418
+ function shadowRootsOfRanges(ranges) {
419
+ const roots = new Set();
420
+ for (const range of ranges) {
421
+ for (const root of [...openShadowRootsOf(range.startContainer), ...openShadowRootsOf(range.endContainer)]) {
422
+ roots.add(root);
423
+ }
424
+ }
425
+ return [...roots];
426
+ }
427
+
428
+ /**
429
+ * The open shadow root `target` hosts, if any. A press on text directly under
430
+ * a shadow root targets its host.
431
+ */
432
+ function ownShadowRoot(target) {
433
+ const root = target?.nodeType === 1 ? target.shadowRoot : null;
434
+ return root == null ? [] : [root];
435
+ }
436
+
437
+ /** The open shadow roots on `target`'s root chain, innermost first. */
438
+ function openShadowRootsOf(target) {
439
+ const roots = [];
440
+ let root = target != null && typeof target.nodeType === 'number' ? target.getRootNode() : null;
441
+ while (root != null && root.nodeType === 11) {
442
+ const host = root.host;
443
+ if (host == null) {
444
+ break;
445
+ }
446
+ if (root.mode === 'open') {
447
+ roots.push(root);
448
+ }
449
+ root = host.getRootNode();
450
+ }
451
+ return roots;
452
+ }
453
+
454
+ /** The focused element, inside open shadow roots too. */
455
+ function deepActiveElement(doc) {
456
+ let active = doc?.activeElement ?? null;
457
+ while (active?.shadowRoot?.activeElement != null) {
458
+ active = active.shadowRoot.activeElement;
459
+ }
460
+ return active;
461
+ }
462
+
463
+ /**
464
+ * The selection-lock styles on `set`, refcounted per element; idempotent
465
+ * release.
466
+ */
467
+ function lockStyles(set) {
80
468
  const locked = [];
81
469
  for (const element of set) {
82
470
  const style = styleOf(element);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/core",
3
- "version": "0.7.6",
3
+ "version": "0.7.7-canary.1d04d40",
4
4
  "displayName": "Astryx Core",
5
5
  "description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
6
6
  "author": "Meta Open Source",
@@ -860,6 +860,9 @@
860
860
  "react-dom": ">=19.0.0"
861
861
  },
862
862
  "devDependencies": {
863
+ "@astryxdesign/a11y-spec": "0.7.7-canary.1d04d40",
864
+ "@astryxdesign/cli": "0.7.7-canary.1d04d40",
865
+ "@astryxdesign/interaction-harness": "0.7.7-canary.1d04d40",
863
866
  "@babel/cli": "^7.29.7",
864
867
  "@babel/core": "^7.29.7",
865
868
  "@babel/preset-react": "^7.29.7",
@@ -870,10 +873,7 @@
870
873
  "@testing-library/jest-dom": "^6.6.0",
871
874
  "@testing-library/react": "^16.3.2",
872
875
  "@types/babel__core": "^7.20.5",
873
- "tailwindcss": "^4.3.2",
874
- "@astryxdesign/cli": "0.7.6",
875
- "@astryxdesign/a11y-spec": "0.0.0",
876
- "@astryxdesign/interaction-harness": "0.0.0"
876
+ "tailwindcss": "^4.3.2"
877
877
  },
878
878
  "dependencies": {
879
879
  "intl-messageformat": "^11.2.9"
@@ -45,6 +45,11 @@ export const docs = {
45
45
  description:
46
46
  'Start the page heading inside `children`. AppShell owns the skip link, the banner landmark and the main landmark, but it renders no heading, so the first heading in the content area is the page h1.',
47
47
  },
48
+ {
49
+ guidance: true,
50
+ description:
51
+ 'On phones, opt the page into the full screen with `viewport-fit=cover` in the viewport meta tag (`width=device-width, initial-scale=1, viewport-fit=cover`). AppShell then extends its header under the status bar and out to the screen sides, and keeps the header\'s items and the end of the content inside the device\'s safe area. An installed web app can also draw under the status bar with `<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">`. In landscape only the header is inset: an inline SideNav and the content\'s sides still reach under a notch, so keep content padding there. A shell with no header region or phone top bar keeps no top inset; keep top padding there.',
52
+ },
48
53
  {
49
54
  guidance: false,
50
55
  description:
@@ -343,6 +348,11 @@ export const docsDense = {
343
348
  description:
344
349
  'Give every nav slot an accessible name: TopNav and SideNav are separate navigation landmarks, so pass `label` to each.',
345
350
  },
351
+ {
352
+ guidance: true,
353
+ description:
354
+ 'Phones: add `viewport-fit=cover` to the viewport meta; the header then reaches under the status bar while its items and the content end stay in the safe area. Landscape: only the header is inset (not an inline SideNav or the content sides). No header region or phone top bar: no top inset, so keep top padding. Installed web apps: `apple-mobile-web-app-status-bar-style` `black-translucent`.',
355
+ },
346
356
  {
347
357
  guidance: true,
348
358
  description:
@@ -471,6 +471,38 @@ const styles = stylex.create({
471
471
  top: 0,
472
472
  zIndex: 1,
473
473
  },
474
+ // The insets are zero unless the page sets `viewport-fit=cover`. The header
475
+ // background goes under the status bar and to the screen sides, as a UIKit
476
+ // bar does.
477
+ headerSafeAreaTop: {
478
+ paddingBlockStart: 'env(safe-area-inset-top, 0px)',
479
+ },
480
+ // The insets are physical sides, so a right-to-left context swaps them on
481
+ // the inline sides.
482
+ headerSafeAreaSides: {
483
+ paddingInlineStart: {
484
+ default: 'env(safe-area-inset-left, 0px)',
485
+ ':is([dir="rtl"] *)': 'env(safe-area-inset-right, 0px)',
486
+ },
487
+ paddingInlineEnd: {
488
+ default: 'env(safe-area-inset-right, 0px)',
489
+ ':is([dir="rtl"] *)': 'env(safe-area-inset-left, 0px)',
490
+ },
491
+ },
492
+ // In `auto`, the banner's wrapper and the phone top bar both stick. Below a
493
+ // banner, the bar sticks under the top inset, so its items stay clear of the
494
+ // status bar.
495
+ headerStickyBelowTopInset: {
496
+ top: 'env(safe-area-inset-top, 0px)',
497
+ },
498
+ // Main adds the bottom inset to the padding that LayoutContent publishes for
499
+ // `contentPadding`. The published value excludes the inset, so a bleed child
500
+ // subtracts only `contentPadding`. Main is border-box, so a child that fills
501
+ // it ends above the inset.
502
+ mainSafeAreaEnd: {
503
+ paddingBlockEnd:
504
+ 'calc(var(--container-padding-block-end, 0px) + env(safe-area-inset-bottom, 0px))',
505
+ },
474
506
  // Sticky sideNav for auto height mode — sticks within the wrapper.
475
507
  // This div replaces the panel as the direct flex child of the middle
476
508
  // (horizontal) container, so it needs the same flex properties that
@@ -891,7 +923,12 @@ export function AppShell({
891
923
  role="banner"
892
924
  {...mergeProps(
893
925
  themeProps('app-shell-header', {variant}),
894
- stylex.props(headerAreaStyle, isAuto && styles.headerSticky),
926
+ stylex.props(
927
+ headerAreaStyle,
928
+ isAuto && styles.headerSticky,
929
+ styles.headerSafeAreaTop,
930
+ styles.headerSafeAreaSides,
931
+ ),
895
932
  )}>
896
933
  {headerInner}
897
934
  </div>
@@ -1184,6 +1221,7 @@ export function AppShell({
1184
1221
  drawsMainFocusRing
1185
1222
  ? [focusOutlineStyles.focusVisible, styles.mainScrollRegionInset]
1186
1223
  : styles.mainFocusTarget,
1224
+ styles.mainSafeAreaEnd,
1187
1225
  ]}>
1188
1226
  {children}
1189
1227
  </LayoutContent>
@@ -1230,7 +1268,15 @@ export function AppShell({
1230
1268
  role={headerContent == null ? 'banner' : undefined}
1231
1269
  {...mergeProps(
1232
1270
  themeProps('app-shell-header', {variant}),
1233
- stylex.props(headerAreaStyle, isAuto && styles.headerSticky),
1271
+ stylex.props(
1272
+ headerAreaStyle,
1273
+ isAuto && styles.headerSticky,
1274
+ styles.headerSafeAreaSides,
1275
+ // Under a banner, the banner's wrapper pads the top inset. This top
1276
+ // bar takes only the side insets.
1277
+ headerContent == null && styles.headerSafeAreaTop,
1278
+ isAuto && headerContent != null && styles.headerStickyBelowTopInset,
1279
+ ),
1234
1280
  )}>
1235
1281
  <LayoutHeader padding={0} hasDivider={navHasDividers}>
1236
1282
  <div