@fragiola/primitives 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +21 -0
  3. package/README.md +50 -2
  4. package/dist/async-list-Bv6ff5Oj.js +81 -0
  5. package/dist/async-list-Bv6ff5Oj.js.map +1 -0
  6. package/dist/async-list.d.ts +2 -0
  7. package/dist/async-list.js +1 -0
  8. package/dist/calendar-keys-DGYpjLwv.d.ts +12 -0
  9. package/dist/calendar-system-B5U5HcPQ.d.ts +415 -0
  10. package/dist/calendar-systems-Daa6Q_ca.js +659 -0
  11. package/dist/calendar-systems-Daa6Q_ca.js.map +1 -0
  12. package/dist/calendar-systems.d.ts +3 -0
  13. package/dist/calendar-systems.js +1 -0
  14. package/dist/carousel-LRbWqbAx.js +375 -0
  15. package/dist/carousel-LRbWqbAx.js.map +1 -0
  16. package/dist/carousel.d.ts +2 -0
  17. package/dist/carousel.js +1 -0
  18. package/dist/cascade-B155Xvvv.js +64 -0
  19. package/dist/cascade-B155Xvvv.js.map +1 -0
  20. package/dist/cascade.d.ts +2 -0
  21. package/dist/cascade.js +1 -0
  22. package/dist/clipboard-Cy2cbGEW.js +33 -0
  23. package/dist/clipboard-Cy2cbGEW.js.map +1 -0
  24. package/dist/clipboard.d.ts +2 -0
  25. package/dist/clipboard.js +1 -0
  26. package/dist/collection-Dbk-PB5S.js +609 -0
  27. package/dist/collection-Dbk-PB5S.js.map +1 -0
  28. package/dist/collection.d.ts +2 -0
  29. package/dist/collection.js +3 -0
  30. package/dist/color-sURV5Irg.js +699 -0
  31. package/dist/color-sURV5Irg.js.map +1 -0
  32. package/dist/color.d.ts +2 -0
  33. package/dist/color.js +1 -0
  34. package/dist/command-DueCXi65.js +104 -0
  35. package/dist/command-DueCXi65.js.map +1 -0
  36. package/dist/command.d.ts +2 -0
  37. package/dist/command.js +1 -0
  38. package/dist/date-CrbFSJKQ.js +215 -0
  39. package/dist/date-CrbFSJKQ.js.map +1 -0
  40. package/dist/date.d.ts +4 -0
  41. package/dist/date.js +1 -0
  42. package/dist/direction-CTnVLpmd.d.ts +8 -0
  43. package/dist/direction-DJDPvnxJ.js +13 -0
  44. package/dist/direction-DJDPvnxJ.js.map +1 -0
  45. package/dist/direction.d.ts +2 -0
  46. package/dist/direction.js +1 -0
  47. package/dist/drag-session-CSr06B5v.js +41 -0
  48. package/dist/drag-session-CSr06B5v.js.map +1 -0
  49. package/dist/file-DSLtfzbi.js +263 -0
  50. package/dist/file-DSLtfzbi.js.map +1 -0
  51. package/dist/file.d.ts +2 -0
  52. package/dist/file.js +1 -0
  53. package/dist/focus-BI-VvM0f.js +75 -0
  54. package/dist/focus-BI-VvM0f.js.map +1 -0
  55. package/dist/focus.d.ts +2 -0
  56. package/dist/focus.js +3 -0
  57. package/dist/form-DovwKtqz.js +501 -0
  58. package/dist/form-DovwKtqz.js.map +1 -0
  59. package/dist/form.d.ts +2 -0
  60. package/dist/form.js +1 -0
  61. package/dist/hover-BakyPYnC.js +62 -0
  62. package/dist/hover-BakyPYnC.js.map +1 -0
  63. package/dist/hover.d.ts +2 -0
  64. package/dist/hover.js +1 -0
  65. package/dist/id-B0Y8iZrc.js +13 -0
  66. package/dist/id-B0Y8iZrc.js.map +1 -0
  67. package/dist/id.d.ts +2 -0
  68. package/dist/id.js +1 -0
  69. package/dist/image-D4X_yRYw.js +44 -0
  70. package/dist/image-D4X_yRYw.js.map +1 -0
  71. package/dist/image.d.ts +2 -0
  72. package/dist/image.js +1 -0
  73. package/dist/index-B0rwIZw9.d.ts +51 -0
  74. package/dist/index-B4wF1isn.d.ts +128 -0
  75. package/dist/index-BHiBRE01.d.ts +20 -0
  76. package/dist/index-BNlMm-0u.d.ts +17 -0
  77. package/dist/index-BapNrjY9.d.ts +48 -0
  78. package/dist/index-Bd-tVb7C.d.ts +6 -0
  79. package/dist/index-BjE8nDiX.d.ts +125 -0
  80. package/dist/index-BpbT-FsX.d.ts +117 -0
  81. package/dist/index-CBgGcTeX.d.ts +37 -0
  82. package/dist/index-CGThV_Md.d.ts +100 -0
  83. package/dist/index-CMig3TXL.d.ts +28 -0
  84. package/dist/index-CWFRduRd.d.ts +212 -0
  85. package/dist/index-CkrHWyU_.d.ts +33 -0
  86. package/dist/index-Cwu6f7y1.d.ts +18 -0
  87. package/dist/index-D10LDdR6.d.ts +139 -0
  88. package/dist/index-D146vm21.d.ts +104 -0
  89. package/dist/index-DGKhEvNr.d.ts +107 -0
  90. package/dist/index-DbAu4s16.d.ts +48 -0
  91. package/dist/index-DdaCj6IO.d.ts +54 -0
  92. package/dist/index-DeHcNdjC.d.ts +68 -0
  93. package/dist/index-DeR4ncrW.d.ts +93 -0
  94. package/dist/index-HIksgK0e.d.ts +70 -0
  95. package/dist/index-IZB0mlZl.d.ts +71 -0
  96. package/dist/index-IfDZj87U.d.ts +28 -0
  97. package/dist/index-SrTuVBms.d.ts +75 -0
  98. package/dist/index-T9UcYvkf.d.ts +339 -0
  99. package/dist/index-fRTojAoR.d.ts +31 -0
  100. package/dist/index-fuLUke9n.d.ts +6 -0
  101. package/dist/index-l63esAck.d.ts +104 -0
  102. package/dist/index-raSUg9U7.d.ts +38 -0
  103. package/dist/index-twgzPKvZ.d.ts +278 -0
  104. package/dist/index-wBpjRykh.d.ts +125 -0
  105. package/dist/index.d.ts +39 -0
  106. package/dist/index.js +42 -0
  107. package/dist/inert-DlGToy3q.js +80 -0
  108. package/dist/inert-DlGToy3q.js.map +1 -0
  109. package/dist/inert.d.ts +2 -0
  110. package/dist/inert.js +1 -0
  111. package/dist/layer-stack-BEtzaFC1.js +118 -0
  112. package/dist/layer-stack-BEtzaFC1.js.map +1 -0
  113. package/dist/layers-C-N4rrZX.js +24 -0
  114. package/dist/layers-C-N4rrZX.js.map +1 -0
  115. package/dist/layers.d.ts +2 -0
  116. package/dist/layers.js +3 -0
  117. package/dist/list-navigation-CbWv4DK5.js +40 -0
  118. package/dist/list-navigation-CbWv4DK5.js.map +1 -0
  119. package/dist/month-year-BG5imFUq.js +108 -0
  120. package/dist/month-year-BG5imFUq.js.map +1 -0
  121. package/dist/month-year.d.ts +3 -0
  122. package/dist/month-year.js +1 -0
  123. package/dist/number-BFUio97d.js +316 -0
  124. package/dist/number-BFUio97d.js.map +1 -0
  125. package/dist/number.d.ts +2 -0
  126. package/dist/number.js +1 -0
  127. package/dist/overlay-BwPyiM3T.js +78 -0
  128. package/dist/overlay-BwPyiM3T.js.map +1 -0
  129. package/dist/overlay.d.ts +2 -0
  130. package/dist/overlay.js +1 -0
  131. package/dist/pagination-BkVzaIGP.js +51 -0
  132. package/dist/pagination-BkVzaIGP.js.map +1 -0
  133. package/dist/pagination.d.ts +2 -0
  134. package/dist/pagination.js +1 -0
  135. package/dist/plain-date-idQH1P6X.d.ts +29 -0
  136. package/dist/plain-date-time-B8PGahhe.d.ts +99 -0
  137. package/dist/pointer-CuDtD9XA.js +189 -0
  138. package/dist/pointer-CuDtD9XA.js.map +1 -0
  139. package/dist/pointer.d.ts +2 -0
  140. package/dist/pointer.js +3 -0
  141. package/dist/positioning-DDUQ75mB.js +148 -0
  142. package/dist/positioning-DDUQ75mB.js.map +1 -0
  143. package/dist/positioning.d.ts +2 -0
  144. package/dist/positioning.js +1 -0
  145. package/dist/presence-BhKDOmII.js +86 -0
  146. package/dist/presence-BhKDOmII.js.map +1 -0
  147. package/dist/presence.d.ts +2 -0
  148. package/dist/presence.js +1 -0
  149. package/dist/range-o0_GBhyY.js +158 -0
  150. package/dist/range-o0_GBhyY.js.map +1 -0
  151. package/dist/range.d.ts +2 -0
  152. package/dist/range.js +1 -0
  153. package/dist/scroll-area-BYNhv36t.js +447 -0
  154. package/dist/scroll-area-BYNhv36t.js.map +1 -0
  155. package/dist/scroll-area.d.ts +2 -0
  156. package/dist/scroll-area.js +1 -0
  157. package/dist/scroll-lock-JzRNOA1O.js +42 -0
  158. package/dist/scroll-lock-JzRNOA1O.js.map +1 -0
  159. package/dist/scroll-lock.d.ts +2 -0
  160. package/dist/scroll-lock.js +1 -0
  161. package/dist/segments-eRu5G_Bd.js +587 -0
  162. package/dist/segments-eRu5G_Bd.js.map +1 -0
  163. package/dist/segments.d.ts +3 -0
  164. package/dist/segments.js +1 -0
  165. package/dist/selection-Cor67w_V.js +287 -0
  166. package/dist/selection-Cor67w_V.js.map +1 -0
  167. package/dist/selection.d.ts +2 -0
  168. package/dist/selection.js +1 -0
  169. package/dist/swipe.d.ts +2 -0
  170. package/dist/swipe.js +1 -0
  171. package/dist/tabbable-BPiLssIv.js +35 -0
  172. package/dist/tabbable-BPiLssIv.js.map +1 -0
  173. package/dist/time-Ct6oq9kt.js +208 -0
  174. package/dist/time-Ct6oq9kt.js.map +1 -0
  175. package/dist/time-zone-DegkzwST.js +305 -0
  176. package/dist/time-zone-DegkzwST.js.map +1 -0
  177. package/dist/time-zone.d.ts +2 -0
  178. package/dist/time-zone.js +1 -0
  179. package/dist/time.d.ts +2 -0
  180. package/dist/time.js +1 -0
  181. package/dist/toast-BjRpJalM.js +400 -0
  182. package/dist/toast-BjRpJalM.js.map +1 -0
  183. package/dist/toast.d.ts +2 -0
  184. package/dist/toast.js +1 -0
  185. package/dist/unit-grid-DJy8lb5D.d.ts +21 -0
  186. package/dist/virtual-BlX1RuHD.js +306 -0
  187. package/dist/virtual-BlX1RuHD.js.map +1 -0
  188. package/dist/virtual.d.ts +2 -0
  189. package/dist/virtual.js +1 -0
  190. package/dist/watch-swipe-BIucfr9O.js +301 -0
  191. package/dist/watch-swipe-BIucfr9O.js.map +1 -0
  192. package/package.json +234 -3
@@ -0,0 +1,99 @@
1
+ import { n as PlainDate } from "./plain-date-idQH1P6X.js";
2
+ /**
3
+ * A wall-clock time with no date and no time zone (spec/date-field.md, "Values"). `hour` is
4
+ * 0–23, `minute` and `second` 0–59, `millisecond` 0–999. Values are plain, immutable objects:
5
+ * every function returns a new one.
6
+ */
7
+ interface PlainTime {
8
+ readonly hour: number;
9
+ readonly minute: number;
10
+ readonly second: number;
11
+ readonly millisecond: number;
12
+ }
13
+ /** A field of a time, the unit of {@link addTime} and {@link cycleTime}. */
14
+ type TimeField = "hour" | "minute" | "second" | "millisecond";
15
+ /** An amount to add to a time, field by field (each may be negative). */
16
+ /**
17
+ * A range of times of day, `{ start, end }` (a TimeRangeField's value, spec/date-range-field.md):
18
+ * the time counterpart of `/date`'s `DateRange`. An end before its start is a value too, an
19
+ * invalid one (no range across midnight).
20
+ */
21
+ interface TimeRange {
22
+ readonly start: PlainTime;
23
+ readonly end: PlainTime;
24
+ }
25
+ interface TimeDuration {
26
+ readonly hours?: number;
27
+ readonly minutes?: number;
28
+ readonly seconds?: number;
29
+ readonly milliseconds?: number;
30
+ }
31
+ /**
32
+ * Builds a time, wrapping overflow around midnight (`plainTime(25)` is 01:00, `plainTime(0, -1)`
33
+ * is 23:59), as a clock does.
34
+ */
35
+ declare function plainTime(hour: number, minute?: number, second?: number, millisecond?: number): PlainTime;
36
+ /** The local time of `now` (the clock the page sees). */
37
+ declare function currentTime(now?: Date): PlainTime;
38
+ /** Negative when `a` is earlier than `b`, positive when later, 0 when the same time. */
39
+ declare function compareTimes(a: PlainTime, b: PlainTime): number;
40
+ declare function isSameTime(a: PlainTime | null | undefined, b: PlainTime | null | undefined): boolean;
41
+ /** Adds a duration, carrying between fields and wrapping around midnight (23:30 + 1 h = 00:30). */
42
+ declare function addTime(time: PlainTime, duration: TimeDuration): PlainTime;
43
+ /**
44
+ * Adds `amount` to one field only, wrapping within it and carrying nothing (10:59 + 1 minute is
45
+ * 10:00): the way a time field's segment steps (spec/date-field.md, "Keyboard").
46
+ */
47
+ declare function cycleTime(time: PlainTime, field: TimeField, amount: number): PlainTime;
48
+ /** How many fields an ISO time writes: `auto` writes the shortest exact form. */
49
+ type IsoTimePrecision = "auto" | "minute" | "second" | "millisecond";
50
+ /**
51
+ * `14:30`, `14:30:05`, `14:30:05.120` (ISO 8601, as `<input type="time">` writes it). `auto`
52
+ * (the default) leaves out the seconds and milliseconds when they are 0; the other precisions
53
+ * write exactly their fields, dropping the smaller ones.
54
+ */
55
+ declare function toIsoTime(time: PlainTime, precision?: IsoTimePrecision): string;
56
+ /**
57
+ * Parses `HH:MM`, `HH:MM:SS` or `HH:MM:SS.s` (one to three fraction digits); `null` when the text
58
+ * is not a valid time.
59
+ */
60
+ declare function fromIsoTime(text: string): PlainTime | null;
61
+ /**
62
+ * A date and a wall-clock time with no time zone (spec/date-field.md, "Values"): a
63
+ * {@link PlainDate} and a {@link PlainTime} in one flat object, so it is also a `PlainDate` (the
64
+ * date math and the calendars take it) and a `PlainTime`.
65
+ */
66
+ interface PlainDateTime extends PlainDate, PlainTime {}
67
+ /** An amount to add to a date and time, field by field (each may be negative). */
68
+ interface DateTimeDuration extends TimeDuration {
69
+ readonly years?: number;
70
+ readonly months?: number;
71
+ readonly days?: number;
72
+ }
73
+ /**
74
+ * Builds a date and time from a date and a time (midnight when `time` is left out), normalizing
75
+ * overflow (`{ hour: 24 }` is midnight of the next day).
76
+ */
77
+ declare function plainDateTime(date: PlainDate, time?: Partial<PlainTime>): PlainDateTime;
78
+ /** The local date and time of `now` (the clock the page sees). */
79
+ declare function currentDateTime(now?: Date): PlainDateTime;
80
+ /** The date of a date and time. */
81
+ declare function toPlainDate(value: PlainDate): PlainDate;
82
+ /** The time of a date and time. */
83
+ declare function toPlainTime(value: PlainTime): PlainTime;
84
+ /**
85
+ * Negative when `a` is before `b`, positive when after, 0 when the same instant of the wall
86
+ * clock. A `PlainDate` counts as its midnight, so a date and time compares with a date bound.
87
+ */
88
+ declare function compareDateTimes(a: PlainDate & Partial<PlainTime>, b: PlainDate & Partial<PlainTime>): number;
89
+ declare function isSameDateTime(a: PlainDateTime | null | undefined, b: PlainDateTime | null | undefined): boolean;
90
+ /**
91
+ * Adds a duration: the years and months first (the day clamped to the month's last day, as the
92
+ * calendars' `addMonths`), then the days and the time, carrying across midnight.
93
+ */
94
+ declare function addDateTime(value: PlainDateTime, duration: DateTimeDuration): PlainDateTime;
95
+ /** `2026-11-23T14:30` (ISO 8601, as `<input type="datetime-local">` writes it); see `toIsoTime`. */
96
+ declare function toIsoDateTime(value: PlainDateTime, precision?: IsoTimePrecision): string;
97
+ /** Parses `YYYY-MM-DDTHH:MM[:SS[.sss]]`; `null` when the text is not a valid date and time. */
98
+ declare function fromIsoDateTime(text: string): PlainDateTime | null;
99
+ export { plainTime as C, isSameTime as S, addTime as _, currentDateTime as a, cycleTime as b, plainDateTime as c, toPlainTime as d, IsoTimePrecision as f, TimeRange as g, TimeField as h, compareDateTimes as i, toIsoDateTime as l, TimeDuration as m, PlainDateTime as n, fromIsoDateTime as o, PlainTime as p, addDateTime as r, isSameDateTime as s, DateTimeDuration as t, toPlainDate as u, compareTimes as v, toIsoTime as w, fromIsoTime as x, currentTime as y };
@@ -0,0 +1,189 @@
1
+ // src/pointer/hover-bridge.ts
2
+ /**
3
+ * Whether `point` is over `trigger`, over `popup`, or in the box that spans both (the gap the
4
+ * pointer crosses from a tooltip's trigger to its popup: spec/tooltip.md, "Pointer").
5
+ */
6
+ function isInHoverBridge(point, trigger, popup) {
7
+ const a = trigger.getBoundingClientRect();
8
+ const b = popup.getBoundingClientRect();
9
+ const left = Math.min(a.left, b.left);
10
+ const right = Math.max(a.right, b.right);
11
+ const top = Math.min(a.top, b.top);
12
+ const bottom = Math.max(a.bottom, b.bottom);
13
+ return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom;
14
+ }
15
+ // src/pointer/long-press.ts
16
+ /**
17
+ * Watches `element` for a long press (spec/context-menu.md, "Pointer"): a pointer of one of
18
+ * `pointerTypes` held down for `delay` without moving beyond `moveTolerance`. A release, a cancel
19
+ * or a larger move before then cancels it. Once a long press fired, the `click` and the
20
+ * `contextmenu` event that follow its release are swallowed (stopped, their default prevented), so
21
+ * they neither activate what is under the finger nor open the browser's menu. Returns the cleanup.
22
+ */
23
+ function watchLongPress(element, options) {
24
+ const { delay = 500, moveTolerance = 10, pointerTypes = ["touch"] } = options;
25
+ const doc = element.ownerDocument;
26
+ const view = doc.defaultView;
27
+ let timer;
28
+ let start = null;
29
+ let swallowing = false;
30
+ let release;
31
+ const stopSwallowing = () => {
32
+ swallowing = false;
33
+ if (release !== void 0) {
34
+ view?.clearTimeout(release);
35
+ release = void 0;
36
+ }
37
+ doc.removeEventListener("pointerup", onRelease, true);
38
+ doc.removeEventListener("pointercancel", onRelease, true);
39
+ };
40
+ const onRelease = () => {
41
+ doc.removeEventListener("pointerup", onRelease, true);
42
+ doc.removeEventListener("pointercancel", onRelease, true);
43
+ release = view?.setTimeout(stopSwallowing, 1e3);
44
+ };
45
+ const cancel = () => {
46
+ if (timer !== void 0) {
47
+ view?.clearTimeout(timer);
48
+ timer = void 0;
49
+ }
50
+ start = null;
51
+ doc.removeEventListener("pointermove", onMove, true);
52
+ doc.removeEventListener("pointerup", cancel, true);
53
+ doc.removeEventListener("pointercancel", cancel, true);
54
+ };
55
+ const onMove = (event) => {
56
+ if (start === null || event.pointerId !== start.pointerId) return;
57
+ if (Math.abs(event.clientX - start.x) > moveTolerance || Math.abs(event.clientY - start.y) > moveTolerance) cancel();
58
+ };
59
+ const onDown = (event) => {
60
+ stopSwallowing();
61
+ cancel();
62
+ if (!pointerTypes.includes(event.pointerType) || !event.isPrimary) return;
63
+ start = {
64
+ x: event.clientX,
65
+ y: event.clientY,
66
+ pointerId: event.pointerId
67
+ };
68
+ const point = {
69
+ x: event.clientX,
70
+ y: event.clientY
71
+ };
72
+ doc.addEventListener("pointermove", onMove, true);
73
+ doc.addEventListener("pointerup", cancel, true);
74
+ doc.addEventListener("pointercancel", cancel, true);
75
+ timer = view?.setTimeout(() => {
76
+ timer = void 0;
77
+ cancel();
78
+ swallowing = true;
79
+ doc.addEventListener("pointerup", onRelease, true);
80
+ doc.addEventListener("pointercancel", onRelease, true);
81
+ options.onLongPress(point, event);
82
+ }, delay);
83
+ };
84
+ const swallow = (event) => {
85
+ if (!swallowing) return;
86
+ if (event.type === "click") stopSwallowing();
87
+ event.preventDefault();
88
+ event.stopPropagation();
89
+ };
90
+ element.addEventListener("pointerdown", onDown);
91
+ doc.addEventListener("click", swallow, true);
92
+ doc.addEventListener("contextmenu", swallow, true);
93
+ return () => {
94
+ cancel();
95
+ stopSwallowing();
96
+ element.removeEventListener("pointerdown", onDown);
97
+ doc.removeEventListener("click", swallow, true);
98
+ doc.removeEventListener("contextmenu", swallow, true);
99
+ };
100
+ }
101
+ // src/pointer/safe-area.ts
102
+ /**
103
+ * Whether `point` is in the triangle between where the pointer left a submenu's trigger and the
104
+ * near edge of the submenu (spec/menu.md, "Pointer": crossing sibling items on the way does not
105
+ * close the submenu).
106
+ */
107
+ function isInSafeArea(point, from, submenu) {
108
+ const rect = submenu.getBoundingClientRect();
109
+ const edgeX = from.x <= rect.left ? rect.left : rect.right;
110
+ const b = {
111
+ x: edgeX,
112
+ y: rect.top - 4
113
+ };
114
+ const c = {
115
+ x: edgeX,
116
+ y: rect.bottom + 4
117
+ };
118
+ const sign = (p, q, r) => (p.x - r.x) * (q.y - r.y) - (q.x - r.x) * (p.y - r.y);
119
+ const d1 = sign(point, from, b);
120
+ const d2 = sign(point, b, c);
121
+ const d3 = sign(point, c, from);
122
+ return !((d1 < 0 || d2 < 0 || d3 < 0) && (d1 > 0 || d2 > 0 || d3 > 0));
123
+ }
124
+ // src/pointer/watch-pointer-exit.ts
125
+ /**
126
+ * Calls `onExit` when a mouse or pen pointer leaves the document: the window, or the iframe the
127
+ * document is in (a `pointerout` with no `relatedTarget`). A pointer that leaves at once sends no
128
+ * move outside a hover bridge first, so a hover-opened overlay listens to this too (Epic #49:
129
+ * spec/tooltip.md and navigation-menu.md, "Pointer"). A touch's `pointerout` after its release
130
+ * is no exit, nor is the pointer entering an iframe of the page (its `pointerout` has no
131
+ * `relatedTarget` either: the point is then inside the viewport, over the frame). Returns the
132
+ * cleanup.
133
+ */
134
+ function watchPointerExit(doc, onExit) {
135
+ const onOut = (event) => {
136
+ const pointer = event;
137
+ if (pointer.relatedTarget === null && pointer.pointerType !== "touch" && !entersFrame(doc, pointer)) onExit(pointer);
138
+ };
139
+ doc.addEventListener("pointerout", onOut);
140
+ return () => doc.removeEventListener("pointerout", onOut);
141
+ }
142
+ /** The elements whose own document a pointer enters (no `relatedTarget` in the page's). */
143
+ const FRAMES = [
144
+ "IFRAME",
145
+ "FRAME",
146
+ "OBJECT",
147
+ "EMBED"
148
+ ];
149
+ /**
150
+ * Whether a `pointerout` with no `relatedTarget` is the pointer entering a frame of the page:
151
+ * its point is inside the viewport, over a frame element. A point outside the viewport, or over
152
+ * anything else (a quick exit reports the last point inside), is the pointer leaving.
153
+ */
154
+ function entersFrame(doc, event) {
155
+ const view = doc.defaultView;
156
+ const { clientX: x, clientY: y } = event;
157
+ if (view === null || typeof doc.elementFromPoint !== "function" || x < 0 || y < 0 || x >= view.innerWidth || y >= view.innerHeight) return false;
158
+ const element = doc.elementFromPoint(x, y);
159
+ return element !== null && FRAMES.includes(element.tagName);
160
+ }
161
+ // src/pointer/track-hover-bridge.ts
162
+ /**
163
+ * Follows the pointer while a hover-opened tooltip is open (spec/tooltip.md, "Pointer"): every
164
+ * move of the document's pointer reports whether it is in the hover bridge of `trigger` and
165
+ * `popup` (`isInHoverBridge`), or over the trigger alone while there is no popup yet; the pointer
166
+ * leaving the document at once (`watchPointerExit`) is outside. It holds no
167
+ * state: the framework decides what a move means (cancel or start the close delay). Returns the
168
+ * cleanup.
169
+ */
170
+ function trackHoverBridge(trigger, popup, callbacks) {
171
+ const doc = trigger.ownerDocument;
172
+ const onMove = (event) => {
173
+ const point = {
174
+ x: event.clientX,
175
+ y: event.clientY
176
+ };
177
+ if (popup !== null ? isInHoverBridge(point, trigger, popup) : event.target instanceof Node && trigger.contains(event.target)) callbacks.inside();
178
+ else callbacks.outside();
179
+ };
180
+ doc.addEventListener("pointermove", onMove);
181
+ const stopExit = watchPointerExit(doc, () => callbacks.outside());
182
+ return () => {
183
+ doc.removeEventListener("pointermove", onMove);
184
+ stopExit();
185
+ };
186
+ }
187
+ export { isInHoverBridge as a, watchLongPress as i, watchPointerExit as n, isInSafeArea as r, trackHoverBridge as t };
188
+
189
+ //# sourceMappingURL=pointer-CuDtD9XA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pointer-CuDtD9XA.js","names":[],"sources":["../src/pointer/hover-bridge.ts","../src/pointer/long-press.ts","../src/pointer/safe-area.ts","../src/pointer/watch-pointer-exit.ts","../src/pointer/track-hover-bridge.ts"],"sourcesContent":["import type { Point } from \"./safe-area.ts\";\n\n/**\n * Whether `point` is over `trigger`, over `popup`, or in the box that spans both (the gap the\n * pointer crosses from a tooltip's trigger to its popup: spec/tooltip.md, \"Pointer\").\n */\nexport function isInHoverBridge(\n point: Point,\n trigger: Element,\n popup: Element,\n): boolean {\n const a = trigger.getBoundingClientRect();\n const b = popup.getBoundingClientRect();\n const left = Math.min(a.left, b.left);\n const right = Math.max(a.right, b.right);\n const top = Math.min(a.top, b.top);\n const bottom = Math.max(a.bottom, b.bottom);\n return (\n point.x >= left &&\n point.x <= right &&\n point.y >= top &&\n point.y <= bottom\n );\n}\n","import type { Point } from \"./safe-area.ts\";\n\nexport interface LongPressOptions {\n /** How long the pointer must stay down, in ms (default 500: spec/context-menu.md). */\n delay?: number;\n /** How far it may move from where it went down before the press is canceled, in px (default 10). */\n moveTolerance?: number;\n /** The pointer types that long-press (default `[\"touch\"]`: the mouse has its right button). */\n pointerTypes?: readonly string[];\n /** The press lasted `delay`: where it went down, and its `pointerdown`. */\n onLongPress: (point: Point, event: PointerEvent) => void;\n}\n\n/**\n * Watches `element` for a long press (spec/context-menu.md, \"Pointer\"): a pointer of one of\n * `pointerTypes` held down for `delay` without moving beyond `moveTolerance`. A release, a cancel\n * or a larger move before then cancels it. Once a long press fired, the `click` and the\n * `contextmenu` event that follow its release are swallowed (stopped, their default prevented), so\n * they neither activate what is under the finger nor open the browser's menu. Returns the cleanup.\n */\nexport function watchLongPress(\n element: Element,\n options: LongPressOptions,\n): () => void {\n const {\n delay = 500,\n moveTolerance = 10,\n pointerTypes = [\"touch\"],\n } = options;\n const doc = element.ownerDocument;\n const view = doc.defaultView;\n let timer: number | undefined;\n let start: { x: number; y: number; pointerId: number } | null = null;\n // after a long press: the events its release sends (within a second of it), until the next\n // press\n let swallowing = false;\n let release: number | undefined;\n const stopSwallowing = () => {\n swallowing = false;\n if (release !== undefined) {\n view?.clearTimeout(release);\n release = undefined;\n }\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n };\n const onRelease = () => {\n doc.removeEventListener(\"pointerup\", onRelease, true);\n doc.removeEventListener(\"pointercancel\", onRelease, true);\n release = view?.setTimeout(stopSwallowing, 1000);\n };\n\n const cancel = () => {\n if (timer !== undefined) {\n view?.clearTimeout(timer);\n timer = undefined;\n }\n start = null;\n doc.removeEventListener(\"pointermove\", onMove, true);\n doc.removeEventListener(\"pointerup\", cancel, true);\n doc.removeEventListener(\"pointercancel\", cancel, true);\n };\n const onMove = (event: PointerEvent) => {\n if (start === null || event.pointerId !== start.pointerId) {\n return;\n }\n if (\n Math.abs(event.clientX - start.x) > moveTolerance ||\n Math.abs(event.clientY - start.y) > moveTolerance\n ) {\n cancel();\n }\n };\n const onDown = (event: PointerEvent) => {\n stopSwallowing();\n cancel();\n if (!pointerTypes.includes(event.pointerType) || !event.isPrimary) {\n return;\n }\n start = {\n x: event.clientX,\n y: event.clientY,\n pointerId: event.pointerId,\n };\n const point = { x: event.clientX, y: event.clientY };\n doc.addEventListener(\"pointermove\", onMove, true);\n doc.addEventListener(\"pointerup\", cancel, true);\n doc.addEventListener(\"pointercancel\", cancel, true);\n timer = view?.setTimeout(() => {\n timer = undefined;\n cancel();\n swallowing = true;\n doc.addEventListener(\"pointerup\", onRelease, true);\n doc.addEventListener(\"pointercancel\", onRelease, true);\n options.onLongPress(point, event);\n }, delay);\n };\n const swallow = (event: Event) => {\n if (!swallowing) {\n return;\n }\n if (event.type === \"click\") {\n stopSwallowing();\n }\n event.preventDefault();\n event.stopPropagation();\n };\n element.addEventListener(\"pointerdown\", onDown as EventListener);\n doc.addEventListener(\"click\", swallow, true);\n doc.addEventListener(\"contextmenu\", swallow, true);\n return () => {\n cancel();\n stopSwallowing();\n element.removeEventListener(\"pointerdown\", onDown as EventListener);\n doc.removeEventListener(\"click\", swallow, true);\n doc.removeEventListener(\"contextmenu\", swallow, true);\n };\n}\n","export interface Point {\n x: number;\n y: number;\n}\n\n/**\n * Whether `point` is in the triangle between where the pointer left a submenu's trigger and the\n * near edge of the submenu (spec/menu.md, \"Pointer\": crossing sibling items on the way does not\n * close the submenu).\n */\nexport function isInSafeArea(\n point: Point,\n from: Point,\n submenu: Element,\n): boolean {\n const rect = submenu.getBoundingClientRect();\n const edgeX = from.x <= rect.left ? rect.left : rect.right;\n const b = { x: edgeX, y: rect.top - 4 };\n const c = { x: edgeX, y: rect.bottom + 4 };\n const sign = (p: Point, q: Point, r: Point) =>\n (p.x - r.x) * (q.y - r.y) - (q.x - r.x) * (p.y - r.y);\n const d1 = sign(point, from, b);\n const d2 = sign(point, b, c);\n const d3 = sign(point, c, from);\n const negative = d1 < 0 || d2 < 0 || d3 < 0;\n const positive = d1 > 0 || d2 > 0 || d3 > 0;\n return !(negative && positive);\n}\n","/**\n * Calls `onExit` when a mouse or pen pointer leaves the document: the window, or the iframe the\n * document is in (a `pointerout` with no `relatedTarget`). A pointer that leaves at once sends no\n * move outside a hover bridge first, so a hover-opened overlay listens to this too (Epic #49:\n * spec/tooltip.md and navigation-menu.md, \"Pointer\"). A touch's `pointerout` after its release\n * is no exit, nor is the pointer entering an iframe of the page (its `pointerout` has no\n * `relatedTarget` either: the point is then inside the viewport, over the frame). Returns the\n * cleanup.\n */\nexport function watchPointerExit(\n doc: Document,\n onExit: (event: PointerEvent) => void,\n): () => void {\n const onOut = (event: Event) => {\n const pointer = event as PointerEvent;\n if (\n pointer.relatedTarget === null &&\n pointer.pointerType !== \"touch\" &&\n !entersFrame(doc, pointer)\n ) {\n onExit(pointer);\n }\n };\n doc.addEventListener(\"pointerout\", onOut);\n return () => doc.removeEventListener(\"pointerout\", onOut);\n}\n\n/** The elements whose own document a pointer enters (no `relatedTarget` in the page's). */\nconst FRAMES: readonly string[] = [\"IFRAME\", \"FRAME\", \"OBJECT\", \"EMBED\"];\n\n/**\n * Whether a `pointerout` with no `relatedTarget` is the pointer entering a frame of the page:\n * its point is inside the viewport, over a frame element. A point outside the viewport, or over\n * anything else (a quick exit reports the last point inside), is the pointer leaving.\n */\nfunction entersFrame(doc: Document, event: PointerEvent): boolean {\n const view = doc.defaultView;\n const { clientX: x, clientY: y } = event;\n if (\n view === null ||\n typeof doc.elementFromPoint !== \"function\" ||\n x < 0 ||\n y < 0 ||\n x >= view.innerWidth ||\n y >= view.innerHeight\n ) {\n return false;\n }\n const element = doc.elementFromPoint(x, y);\n return element !== null && FRAMES.includes(element.tagName);\n}\n","import { isInHoverBridge } from \"./hover-bridge.ts\";\nimport { watchPointerExit } from \"./watch-pointer-exit.ts\";\n\nexport interface HoverBridgeCallbacks {\n /** The pointer moved over the trigger, the popup or the gap between them. */\n inside: () => void;\n /** The pointer moved anywhere else, or left the document (the window or the iframe). */\n outside: () => void;\n}\n\n/**\n * Follows the pointer while a hover-opened tooltip is open (spec/tooltip.md, \"Pointer\"): every\n * move of the document's pointer reports whether it is in the hover bridge of `trigger` and\n * `popup` (`isInHoverBridge`), or over the trigger alone while there is no popup yet; the pointer\n * leaving the document at once (`watchPointerExit`) is outside. It holds no\n * state: the framework decides what a move means (cancel or start the close delay). Returns the\n * cleanup.\n */\nexport function trackHoverBridge(\n trigger: Element,\n popup: Element | null,\n callbacks: HoverBridgeCallbacks,\n): () => void {\n const doc = trigger.ownerDocument;\n const onMove = (event: PointerEvent) => {\n const point = { x: event.clientX, y: event.clientY };\n const inside =\n popup !== null\n ? isInHoverBridge(point, trigger, popup)\n : event.target instanceof Node &&\n trigger.contains(event.target);\n if (inside) {\n callbacks.inside();\n } else {\n callbacks.outside();\n }\n };\n doc.addEventListener(\"pointermove\", onMove);\n const stopExit = watchPointerExit(doc, () => callbacks.outside());\n return () => {\n doc.removeEventListener(\"pointermove\", onMove);\n stopExit();\n };\n}\n"],"mappings":";;;;;AAMA,SAAgB,gBACZ,OACA,SACA,OACO;CACP,MAAM,IAAI,QAAQ,sBAAsB;CACxC,MAAM,IAAI,MAAM,sBAAsB;CACtC,MAAM,OAAO,KAAK,IAAI,EAAE,MAAM,EAAE,IAAI;CACpC,MAAM,QAAQ,KAAK,IAAI,EAAE,OAAO,EAAE,KAAK;CACvC,MAAM,MAAM,KAAK,IAAI,EAAE,KAAK,EAAE,GAAG;CACjC,MAAM,SAAS,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM;CAC1C,OACI,MAAM,KAAK,QACX,MAAM,KAAK,SACX,MAAM,KAAK,OACX,MAAM,KAAK;AAEnB;;;;;;;;;ACHA,SAAgB,eACZ,SACA,SACU;CACV,MAAM,EACF,QAAQ,KACR,gBAAgB,IAChB,eAAe,CAAC,OAAO,MACvB;CACJ,MAAM,MAAM,QAAQ;CACpB,MAAM,OAAO,IAAI;CACjB,IAAI;CACJ,IAAI,QAA4D;CAGhE,IAAI,aAAa;CACjB,IAAI;CACJ,MAAM,uBAAuB;EACzB,aAAa;EACb,IAAI,YAAY,KAAA,GAAW;GACvB,MAAM,aAAa,OAAO;GAC1B,UAAU,KAAA;EACd;EACA,IAAI,oBAAoB,aAAa,WAAW,IAAI;EACpD,IAAI,oBAAoB,iBAAiB,WAAW,IAAI;CAC5D;CACA,MAAM,kBAAkB;EACpB,IAAI,oBAAoB,aAAa,WAAW,IAAI;EACpD,IAAI,oBAAoB,iBAAiB,WAAW,IAAI;EACxD,UAAU,MAAM,WAAW,gBAAgB,GAAI;CACnD;CAEA,MAAM,eAAe;EACjB,IAAI,UAAU,KAAA,GAAW;GACrB,MAAM,aAAa,KAAK;GACxB,QAAQ,KAAA;EACZ;EACA,QAAQ;EACR,IAAI,o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AAG,CAAC;CACzC,OAAO,YAAY,QAAQ,OAAO,SAAS,QAAQ,OAAO;AAC9D;;;;;;;;;;AChCA,SAAgB,iBACZ,SACA,OACA,WACU;CACV,MAAM,MAAM,QAAQ;CACpB,MAAM,UAAU,UAAwB;EACpC,MAAM,QAAQ;GAAE,GAAG,MAAM;GAAS,GAAG,MAAM;EAAQ;EAMnD,IAJI,UAAU,OACJ,gBAAgB,OAAO,SAAS,KAAK,IACrC,MAAM,kBAAkB,QACxB,QAAQ,SAAS,MAAM,MAAM,GAEnC,UAAU,OAAO;OAEjB,UAAU,QAAQ;CAE1B;CACA,IAAI,iBAAiB,eAAe,MAAM;CAC1C,MAAM,WAAW,iBAAiB,WAAW,UAAU,QAAQ,CAAC;CAChE,aAAa;EACT,IAAI,oBAAoB,eAAe,MAAM;EAC7C,SAAS;CACb;AACJ"}
@@ -0,0 +1,2 @@
1
+ import { a as watchLongPress, c as isInSafeArea, i as LongPressOptions, l as DragSessionOptions, n as HoverBridgeCallbacks, o as isInHoverBridge, r as trackHoverBridge, s as Point, t as watchPointerExit, u as startDrag } from "./index-IZB0mlZl.js";
2
+ export { type DragSessionOptions, type HoverBridgeCallbacks, type LongPressOptions, type Point, isInHoverBridge, isInSafeArea, startDrag, trackHoverBridge, watchLongPress, watchPointerExit };
@@ -0,0 +1,3 @@
1
+ import { t as startDrag } from "./drag-session-CSr06B5v.js";
2
+ import { a as isInHoverBridge, i as watchLongPress, n as watchPointerExit, r as isInSafeArea, t as trackHoverBridge } from "./pointer-CuDtD9XA.js";
3
+ export { isInHoverBridge, isInSafeArea, startDrag, trackHoverBridge, watchLongPress, watchPointerExit };
@@ -0,0 +1,148 @@
1
+ import { t as getDirection } from "./direction-DJDPvnxJ.js";
2
+ import { arrow, autoUpdate, computePosition, flip, offset, platform, shift, size } from "@floating-ui/dom";
3
+ // src/positioning/placement.ts
4
+ function physicalSide(side, direction) {
5
+ switch (side) {
6
+ case "inline-start": return direction === "rtl" ? "right" : "left";
7
+ case "inline-end": return direction === "rtl" ? "left" : "right";
8
+ default: return side;
9
+ }
10
+ }
11
+ /** The Floating UI placement of a side and align, in a direction. */
12
+ function toPlacement(side, align, direction) {
13
+ const physical = physicalSide(side, direction);
14
+ if (align === "center") return physical;
15
+ return `${physical}-${direction === "rtl" && (physical === "top" || physical === "bottom") ? align === "start" ? "end" : "start" : align}`;
16
+ }
17
+ /**
18
+ * The side and align of a resolved Floating UI placement. A horizontal side is named as it was
19
+ * asked: logically (`inline-start` / `inline-end`) when `requested` is a logical side, physically
20
+ * (`left` / `right`) otherwise, so a flipped `inline-end` reports `inline-start`.
21
+ */
22
+ function fromPlacement(placement, direction, requested = "bottom") {
23
+ const [physical, edge] = placement.split("-");
24
+ const side = (requested === "inline-start" || requested === "inline-end") && (physical === "left" || physical === "right") ? physical === "left" === (direction === "rtl") ? "inline-end" : "inline-start" : physical;
25
+ if (edge === void 0) return {
26
+ side,
27
+ align: "center"
28
+ };
29
+ return {
30
+ side,
31
+ align: direction === "rtl" && (physical === "top" || physical === "bottom") ? edge === "start" ? "end" : "start" : edge
32
+ };
33
+ }
34
+ // src/positioning/virtual-anchor.ts
35
+ /**
36
+ * A virtual anchor at a fixed point or rectangle of the viewport (the pointer of a right-click): a
37
+ * zero-size rectangle for a point. It does not follow the page's scroll.
38
+ */
39
+ function virtualAnchor(rect, contextElement) {
40
+ const { x, y, width = 0, height = 0 } = rect;
41
+ const box = {
42
+ x,
43
+ y,
44
+ width,
45
+ height,
46
+ top: y,
47
+ left: x,
48
+ right: x + width,
49
+ bottom: y + height
50
+ };
51
+ return {
52
+ getBoundingClientRect: () => ({
53
+ ...box,
54
+ toJSON: () => box
55
+ }),
56
+ ...contextElement ? { contextElement } : {}
57
+ };
58
+ }
59
+ /** Whether an anchor is an element (else a virtual anchor). */
60
+ function isElementAnchor(anchor) {
61
+ return typeof anchor.nodeType === "number";
62
+ }
63
+ // src/positioning/anchor-floating.ts
64
+ /**
65
+ * Keeps `floating` next to `anchor` (spec/popover.md, "Positioning"): flip, shift, logical and
66
+ * physical sides, and it follows scroll and resize until the returned function is called. The
67
+ * anchor is an element, or a virtual anchor (`virtualAnchor`: a point or a rectangle, as a context
68
+ * menu's pointer; its direction is its `contextElement`'s, else the floating element's). It
69
+ * writes structural inline style only (`position`, `top`, `left`), the CSS variables
70
+ * `--anchor-width`, `--anchor-height`, `--available-width`, `--available-height`,
71
+ * `--transform-origin`, and the arrow's offset.
72
+ */
73
+ function anchorFloating(anchor, floating, options = {}) {
74
+ const { side = "bottom", align = "center", sideOffset = 0, alignOffset = 0, collisionPadding = 8 } = options;
75
+ floating.style.position = "fixed";
76
+ floating.style.top = "0";
77
+ floating.style.left = "0";
78
+ const update = async () => {
79
+ const provided = typeof options.direction === "function" ? options.direction() : options.direction;
80
+ const direction = getDirection(isElementAnchor(anchor) ? anchor : anchor.contextElement ?? floating, provided);
81
+ const middleware = [
82
+ offset({
83
+ mainAxis: sideOffset,
84
+ alignmentAxis: alignOffset
85
+ }),
86
+ flip({ padding: collisionPadding }),
87
+ shift({ padding: collisionPadding }),
88
+ size({
89
+ padding: collisionPadding,
90
+ apply({ availableWidth, availableHeight, rects }) {
91
+ floating.style.setProperty("--available-width", `${availableWidth}px`);
92
+ floating.style.setProperty("--available-height", `${availableHeight}px`);
93
+ floating.style.setProperty("--anchor-width", `${rects.reference.width}px`);
94
+ floating.style.setProperty("--anchor-height", `${rects.reference.height}px`);
95
+ }
96
+ })
97
+ ];
98
+ if (options.arrow) middleware.push(arrow({
99
+ element: options.arrow,
100
+ padding: 4
101
+ }));
102
+ const result = await computePosition(anchor, floating, {
103
+ strategy: "fixed",
104
+ platform: {
105
+ ...platform,
106
+ isRTL: () => false
107
+ },
108
+ placement: toPlacement(side, align, direction),
109
+ middleware
110
+ });
111
+ floating.style.left = `${result.x}px`;
112
+ floating.style.top = `${result.y}px`;
113
+ const placed = fromPlacement(result.placement, direction, side);
114
+ floating.style.setProperty("--transform-origin", transformOrigin(result.placement));
115
+ const arrowData = result.middlewareData.arrow;
116
+ if (options.arrow && arrowData) {
117
+ const physical = result.placement.split("-")[0];
118
+ const style = options.arrow.style;
119
+ style.position = "absolute";
120
+ style.left = arrowData.x != null ? `${arrowData.x}px` : "";
121
+ style.top = arrowData.y != null ? `${arrowData.y}px` : "";
122
+ const edge = {
123
+ top: "bottom",
124
+ bottom: "top",
125
+ left: "right",
126
+ right: "left"
127
+ }[physical];
128
+ style.setProperty(edge, `${-options.arrow.offsetWidth / 2}px`);
129
+ }
130
+ options.onPlaced?.(placed);
131
+ };
132
+ return autoUpdate(anchor, floating, () => {
133
+ update();
134
+ });
135
+ }
136
+ function transformOrigin(placement) {
137
+ const [physical, edge] = placement.split("-");
138
+ const cross = edge === "start" ? "0%" : edge === "end" ? "100%" : "50%";
139
+ switch (physical) {
140
+ case "top": return `${cross} 100%`;
141
+ case "bottom": return `${cross} 0%`;
142
+ case "left": return `100% ${cross}`;
143
+ default: return `0% ${cross}`;
144
+ }
145
+ }
146
+ export { toPlacement as i, virtualAnchor as n, fromPlacement as r, anchorFloating as t };
147
+
148
+ //# sourceMappingURL=positioning-DDUQ75mB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positioning-DDUQ75mB.js","names":[],"sources":["../src/positioning/placement.ts","../src/positioning/virtual-anchor.ts","../src/positioning/anchor-floating.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/dom\";\nimport type { Direction } from \"../direction/direction.ts\";\n\n/**\n * The side of the anchor an overlay sits on (spec/README.md, `data-side`; Base UI's names, D4 §3\n * \"Naming\"): `inline-start` and `inline-end` follow the direction (`inline-end` is the right in\n * LTR, the left in RTL), `left` and `right` are physical.\n */\nexport type Side =\n | \"top\"\n | \"bottom\"\n | \"left\"\n | \"right\"\n | \"inline-start\"\n | \"inline-end\";\nexport type Align = \"start\" | \"center\" | \"end\";\n\ntype PhysicalSide = \"top\" | \"bottom\" | \"left\" | \"right\";\n\nfunction physicalSide(side: Side, direction: Direction): PhysicalSide {\n switch (side) {\n case \"inline-start\":\n return direction === \"rtl\" ? \"right\" : \"left\";\n case \"inline-end\":\n return direction === \"rtl\" ? \"left\" : \"right\";\n default:\n return side;\n }\n}\n\n/** The Floating UI placement of a side and align, in a direction. */\nexport function toPlacement(\n side: Side,\n align: Align,\n direction: Direction,\n): Placement {\n const physical = physicalSide(side, direction);\n if (align === \"center\") {\n return physical;\n }\n // Floating UI's -start/-end follow the physical axis: on top/bottom, -start is the left edge\n const flipAlign =\n direction === \"rtl\" && (physical === \"top\" || physical === \"bottom\");\n const physicalAlign = flipAlign\n ? align === \"start\"\n ? \"end\"\n : \"start\"\n : align;\n return `${physical}-${physicalAlign}`;\n}\n\n/**\n * The side and align of a resolved Floating UI placement. A horizontal side is named as it was\n * asked: logically (`inline-start` / `inline-end`) when `requested` is a logical side, physically\n * (`left` / `right`) otherwise, so a flipped `inline-end` reports `inline-start`.\n */\nexport function fromPlacement(\n placement: Placement,\n direction: Direction,\n requested: Side = \"bottom\",\n): { side: Side; align: Align } {\n const [physical, edge] = placement.split(\"-\") as [\n PhysicalSide,\n \"start\" | \"end\" | undefined,\n ];\n const logical = requested === \"inline-start\" || requested === \"inline-end\";\n const side: Side =\n logical && (physical === \"left\" || physical === \"right\")\n ? (physical === \"left\") === (direction === \"rtl\")\n ? \"inline-end\"\n : \"inline-start\"\n : physical;\n if (edge === undefined) {\n return { side, align: \"center\" };\n }\n const flipAlign =\n direction === \"rtl\" && (physical === \"top\" || physical === \"bottom\");\n return {\n side,\n align: flipAlign ? (edge === \"start\" ? \"end\" : \"start\") : edge,\n };\n}\n","/**\n * A rectangle to anchor a floating element to, instead of an element (spec/context-menu.md,\n * \"Positioning\"): Floating UI's virtual element. `contextElement` is the element it belongs to\n * (the area a context menu opened from): its scroll ancestors and its direction are read.\n */\nexport interface VirtualAnchor {\n getBoundingClientRect: () => DOMRect;\n contextElement?: Element;\n}\n\n/** A point, or a rectangle, in the viewport's (client) coordinates. */\nexport interface AnchorRect {\n x: number;\n y: number;\n width?: number;\n height?: number;\n}\n\n/**\n * A virtual anchor at a fixed point or rectangle of the viewport (the pointer of a right-click): a\n * zero-size rectangle for a point. It does not follow the page's scroll.\n */\nexport function virtualAnchor(\n rect: AnchorRect,\n contextElement?: Element | null,\n): VirtualAnchor {\n const { x, y, width = 0, height = 0 } = rect;\n const box = {\n x,\n y,\n width,\n height,\n top: y,\n left: x,\n right: x + width,\n bottom: y + height,\n };\n return {\n getBoundingClientRect: () => ({ ...box, toJSON: () => box }) as DOMRect,\n ...(contextElement ? { contextElement } : {}),\n };\n}\n\n/** Whether an anchor is an element (else a virtual anchor). */\nexport function isElementAnchor(\n anchor: Element | VirtualAnchor,\n): anchor is Element {\n return typeof (anchor as Element).nodeType === \"number\";\n}\n","import {\n arrow,\n autoUpdate,\n computePosition,\n flip,\n offset,\n platform,\n shift,\n size,\n} from \"@floating-ui/dom\";\nimport { type Direction, getDirection } from \"../direction/direction.ts\";\nimport {\n type Align,\n fromPlacement,\n type Side,\n toPlacement,\n} from \"./placement.ts\";\nimport { isElementAnchor, type VirtualAnchor } from \"./virtual-anchor.ts\";\n\nexport interface AnchorOptions {\n side?: Side;\n align?: Align;\n /** Distance from the anchor, in px. */\n sideOffset?: number;\n /** Shift along the anchor's edge, in px. */\n alignOffset?: number;\n /** Space kept from the viewport's edges when flipping and shifting, in px. */\n collisionPadding?: number;\n /** An arrow element inside the floating element, placed along its edge. */\n arrow?: HTMLElement | null;\n /**\n * The reading direction a DirectionProvider gives (spec/direction.md): the logical sides follow\n * it. Without it, the anchor's computed direction, read at every placement. A getter is read at\n * every placement too.\n */\n direction?: Direction | null | (() => Direction | null | undefined);\n /** Called after every placement with the side and align it ended up on. */\n onPlaced?: (placed: { side: Side; align: Align }) => void;\n}\n\n/**\n * Keeps `floating` next to `anchor` (spec/popover.md, \"Positioning\"): flip, shift, logical and\n * physical sides, and it follows scroll and resize until the returned function is called. The\n * anchor is an element, or a virtual anchor (`virtualAnchor`: a point or a rectangle, as a context\n * menu's pointer; its direction is its `contextElement`'s, else the floating element's). It\n * writes structural inline style only (`position`, `top`, `left`), the CSS variables\n * `--anchor-width`, `--anchor-height`, `--available-width`, `--available-height`,\n * `--transform-origin`, and the arrow's offset.\n */\nexport function anchorFloating(\n anchor: Element | VirtualAnchor,\n floating: HTMLElement,\n options: AnchorOptions = {},\n): () => void {\n const {\n side = \"bottom\",\n align = \"center\",\n sideOffset = 0,\n alignOffset = 0,\n collisionPadding = 8,\n } = options;\n floating.style.position = \"fixed\";\n floating.style.top = \"0\";\n floating.style.left = \"0\";\n\n const update = async () => {\n const provided =\n typeof options.direction === \"function\"\n ? options.direction()\n : options.direction;\n const direction = getDirection(\n isElementAnchor(anchor)\n ? anchor\n : (anchor.contextElement ?? floating),\n provided,\n );\n const middleware = [\n offset({ mainAxis: sideOffset, alignmentAxis: alignOffset }),\n flip({ padding: collisionPadding }),\n shift({ padding: collisionPadding }),\n size({\n padding: collisionPadding,\n apply({ availableWidth, availableHeight, rects }) {\n floating.style.setProperty(\n \"--available-width\",\n `${availableWidth}px`,\n );\n floating.style.setProperty(\n \"--available-height\",\n `${availableHeight}px`,\n );\n floating.style.setProperty(\n \"--anchor-width\",\n `${rects.reference.width}px`,\n );\n floating.style.setProperty(\n \"--anchor-height\",\n `${rects.reference.height}px`,\n );\n },\n }),\n ];\n if (options.arrow) {\n middleware.push(arrow({ element: options.arrow, padding: 4 }));\n }\n const result = await computePosition(anchor, floating, {\n strategy: \"fixed\",\n // the placement is physical already (toPlacement applies the direction): Floating UI\n // must not flip a top or bottom `-start` / `-end` again for an RTL floating element\n platform: { ...platform, isRTL: () => false },\n placement: toPlacement(side, align, direction),\n middleware,\n });\n floating.style.left = `${result.x}px`;\n floating.style.top = `${result.y}px`;\n const placed = fromPlacement(result.placement, direction, side);\n floating.style.setProperty(\n \"--transform-origin\",\n transformOrigin(result.placement),\n );\n const arrowData = result.middlewareData.arrow;\n if (options.arrow && arrowData) {\n const physical = result.placement.split(\"-\")[0];\n const style = options.arrow.style;\n style.position = \"absolute\";\n style.left = arrowData.x != null ? `${arrowData.x}px` : \"\";\n style.top = arrowData.y != null ? `${arrowData.y}px` : \"\";\n const edge = {\n top: \"bottom\",\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n }[physical as \"top\" | \"bottom\" | \"left\" | \"right\"];\n style.setProperty(edge, `${-options.arrow.offsetWidth / 2}px`);\n }\n options.onPlaced?.(placed);\n };\n\n return autoUpdate(anchor, floating, () => {\n void update();\n });\n}\n\nfunction transformOrigin(placement: string): string {\n const [physical, edge] = placement.split(\"-\");\n const cross = edge === \"start\" ? \"0%\" : edge === \"end\" ? \"100%\" : \"50%\";\n switch (physical) {\n case \"top\":\n return `${cross} 100%`;\n case \"bottom\":\n return `${cross} 0%`;\n case \"left\":\n return `100% ${cross}`;\n default:\n return `0% ${cross}`;\n }\n}\n"],"mappings":";;;AAmBA,SAAS,aAAa,MAAY,WAAoC;CAClE,QAAQ,MAAR;EACI,KAAK,gBACD,OAAO,cAAc,QAAQ,UAAU;EAC3C,KAAK,cACD,OAAO,cAAc,QAAQ,SAAS;EAC1C,SACI,OAAO;CACf;AACJ;;AAGA,SAAgB,YACZ,MACA,OACA,WACS;CACT,MAAM,WAAW,aAAa,MAAM,SAAS;CAC7C,IAAI,UAAU,UACV,OAAO;CAUX,OAAO,GAAG,SAAS,GANf,cAAc,UAAU,aAAa,SAAS,aAAa,YAEzD,UAAU,UACN,QACA,UACJ;AAEV;;;;;;AAOA,SAAgB,cACZ,WACA,WACA,YAAkB,UACU;CAC5B,MAAM,CAAC,UAAU,QAAQ,UAAU,MAAM,GAAG;CAK5C,MAAM,QADU,cAAc,kBAAkB,cAAc,kBAE9C,aAAa,UAAU,aAAa,WACzC,aAAa,YAAa,cAAc,SACrC,eACA,iBACJ;CACV,IAAI,SAAS,KAAA,GACT,OAAO;EAAE;EAAM,OAAO;CAAS;CAInC,OAAO;EACH;EACA,OAHA,cAAc,UAAU,aAAa,SAAS,aAAa,YAGvC,SAAS,UAAU,QAAQ,UA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0,0 +1,2 @@
1
+ import { a as virtualAnchor, c as fromPlacement, i as VirtualAnchor, l as toPlacement, n as anchorFloating, o as Align, r as AnchorRect, s as Side, t as AnchorOptions } from "./index-SrTuVBms.js";
2
+ export { type Align, type AnchorOptions, type AnchorRect, type Side, type VirtualAnchor, anchorFloating, fromPlacement, toPlacement, virtualAnchor };
@@ -0,0 +1 @@
1
+ export { t as anchorFloating, r as fromPlacement, i as toPlacement, n as virtualAnchor } from "./positioning-DDUQ75mB.js";
@@ -0,0 +1,86 @@
1
+ // src/presence/panel-size.ts
2
+ /**
3
+ * The size of a panel's content: its `scrollHeight` and `scrollWidth`, which a panel held at
4
+ * `height: 0` by its starting style (with `overflow: hidden`) still reports. The panel must not be
5
+ * `hidden` (a `display: none` element measures 0).
6
+ */
7
+ function measurePanelSize(element) {
8
+ return {
9
+ height: element.scrollHeight,
10
+ width: element.scrollWidth
11
+ };
12
+ }
13
+ /**
14
+ * Writes a panel's size into its size variables (`--<prefix>-panel-height` and `-width`, in
15
+ * pixels) and applies the styles at once (a style flush), so a transition that starts next (the
16
+ * opening frame without `data-starting-style`, or `data-ending-style`) starts from a length,
17
+ * never from `auto` (spec/collapsible.md, "Animation"). Returns the size, for the framework's
18
+ * state to render the same values.
19
+ */
20
+ function freezePanelSize(element, prefix) {
21
+ const size = measurePanelSize(element);
22
+ element.style.setProperty(`--${prefix}-panel-height`, `${size.height}px`);
23
+ element.style.setProperty(`--${prefix}-panel-width`, `${size.width}px`);
24
+ element.ownerDocument.defaultView?.getComputedStyle(element).height;
25
+ return size;
26
+ }
27
+ /** The size variables' values (`auto` for no size): what a panel renders. */
28
+ function panelSizeVariables(prefix, size) {
29
+ return {
30
+ [`--${prefix}-panel-height`]: size === null ? "auto" : `${size.height}px`,
31
+ [`--${prefix}-panel-width`]: size === null ? "auto" : `${size.width}px`
32
+ };
33
+ }
34
+ /**
35
+ * Opens a `hidden="until-found"` panel on a find-in-page match (spec/collapsible.md, "Find in
36
+ * page"): the browser fires `beforematch` and removes `hidden`; `onMatch` opens the component.
37
+ * When the component is still closed a task later (a controlled `open` the app kept `false`), the
38
+ * panel gets `hidden="until-found"` back. Returns the cleanup.
39
+ */
40
+ function watchBeforeMatch(element, options) {
41
+ const view = element.ownerDocument.defaultView;
42
+ let timer;
43
+ const onBeforeMatch = (event) => {
44
+ options.onMatch(event);
45
+ if (view === null) return;
46
+ view.clearTimeout(timer);
47
+ timer = view.setTimeout(() => {
48
+ if (!options.isOpen()) element.setAttribute("hidden", "until-found");
49
+ }, 0);
50
+ };
51
+ element.addEventListener("beforematch", onBeforeMatch);
52
+ return () => {
53
+ element.removeEventListener("beforematch", onBeforeMatch);
54
+ view?.clearTimeout(timer);
55
+ };
56
+ }
57
+ // src/presence/presence.ts
58
+ /** Runs `callback` on the next animation frame of the element's window. Returns the cancel. */
59
+ function nextFrame(element, callback) {
60
+ const view = element.ownerDocument.defaultView;
61
+ if (view === null) {
62
+ callback();
63
+ return () => {};
64
+ }
65
+ const id = view.requestAnimationFrame(() => callback());
66
+ return () => view.cancelAnimationFrame(id);
67
+ }
68
+ /**
69
+ * Resolves when every animation and transition running on the element has finished, or at once
70
+ * when there is none (spec/dialog.md, "Animation": unmount after the exit animation).
71
+ */
72
+ async function waitForAnimations(element) {
73
+ const animations = typeof element.getAnimations === "function" ? element.getAnimations() : [];
74
+ await Promise.allSettled(animations.map((animation) => animation.finished));
75
+ }
76
+ /**
77
+ * Whether an animation or a transition runs on the element now (reading them applies its pending
78
+ * styles): an exit with none ends at once, in the render that started it, never a painted frame
79
+ * later (spec/collapsible.md and tabs.md, "Animation").
80
+ */
81
+ function isAnimating(element) {
82
+ return typeof element.getAnimations === "function" && element.getAnimations().length > 0;
83
+ }
84
+ export { measurePanelSize as a, freezePanelSize as i, nextFrame as n, panelSizeVariables as o, waitForAnimations as r, watchBeforeMatch as s, isAnimating as t };
85
+
86
+ //# sourceMappingURL=presence-BhKDOmII.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence-BhKDOmII.js","names":[],"sources":["../src/presence/panel-size.ts","../src/presence/presence.ts"],"sourcesContent":["/** A panel's content size in pixels (spec/collapsible.md, \"Animation\"). */\nexport interface PanelSize {\n height: number;\n width: number;\n}\n\n/**\n * The size of a panel's content: its `scrollHeight` and `scrollWidth`, which a panel held at\n * `height: 0` by its starting style (with `overflow: hidden`) still reports. The panel must not be\n * `hidden` (a `display: none` element measures 0).\n */\nexport function measurePanelSize(element: HTMLElement): PanelSize {\n return { height: element.scrollHeight, width: element.scrollWidth };\n}\n\n/**\n * Writes a panel's size into its size variables (`--<prefix>-panel-height` and `-width`, in\n * pixels) and applies the styles at once (a style flush), so a transition that starts next (the\n * opening frame without `data-starting-style`, or `data-ending-style`) starts from a length,\n * never from `auto` (spec/collapsible.md, \"Animation\"). Returns the size, for the framework's\n * state to render the same values.\n */\nexport function freezePanelSize(\n element: HTMLElement,\n prefix: string,\n): PanelSize {\n const size = measurePanelSize(element);\n element.style.setProperty(`--${prefix}-panel-height`, `${size.height}px`);\n element.style.setProperty(`--${prefix}-panel-width`, `${size.width}px`);\n // reading a computed length applies the pending styles: the next change transitions from it\n element.ownerDocument.defaultView?.getComputedStyle(element).height;\n return size;\n}\n\n/** The size variables' values (`auto` for no size): what a panel renders. */\nexport function panelSizeVariables(\n prefix: string,\n size: PanelSize | null,\n): Record<string, string> {\n return {\n [`--${prefix}-panel-height`]:\n size === null ? \"auto\" : `${size.height}px`,\n [`--${prefix}-panel-width`]: size === null ? \"auto\" : `${size.width}px`,\n };\n}\n\nexport interface BeforeMatchOptions {\n /** Called when the browser's find-in-page matched the panel's content (`beforematch`). */\n onMatch: (event: Event) => void;\n /** Whether the panel is open now: read after the match, to hide a panel the app kept closed. */\n isOpen: () => boolean;\n}\n\n/**\n * Opens a `hidden=\"until-found\"` panel on a find-in-page match (spec/collapsible.md, \"Find in\n * page\"): the browser fires `beforematch` and removes `hidden`; `onMatch` opens the component.\n * When the component is still closed a task later (a controlled `open` the app kept `false`), the\n * panel gets `hidden=\"until-found\"` back. Returns the cleanup.\n */\nexport function watchBeforeMatch(\n element: HTMLElement,\n options: BeforeMatchOptions,\n): () => void {\n const view = element.ownerDocument.defaultView;\n let timer: number | undefined;\n const onBeforeMatch = (event: Event) => {\n options.onMatch(event);\n if (view === null) {\n return;\n }\n view.clearTimeout(timer);\n timer = view.setTimeout(() => {\n if (!options.isOpen()) {\n element.setAttribute(\"hidden\", \"until-found\");\n }\n }, 0);\n };\n element.addEventListener(\"beforematch\", onBeforeMatch);\n return () => {\n element.removeEventListener(\"beforematch\", onBeforeMatch);\n view?.clearTimeout(timer);\n };\n}\n","/** Runs `callback` on the next animation frame of the element's window. Returns the cancel. */\nexport function nextFrame(element: Element, callback: () => void): () => void {\n const view = element.ownerDocument.defaultView;\n if (view === null) {\n callback();\n return () => {};\n }\n const id = view.requestAnimationFrame(() => callback());\n return () => view.cancelAnimationFrame(id);\n}\n\n/**\n * Resolves when every animation and transition running on the element has finished, or at once\n * when there is none (spec/dialog.md, \"Animation\": unmount after the exit animation).\n */\nexport async function waitForAnimations(element: Element): Promise<void> {\n const animations =\n typeof element.getAnimations === \"function\"\n ? element.getAnimations()\n : [];\n await Promise.allSettled(animations.map((animation) => animation.finished));\n}\n\n/**\n * Whether an animation or a transition runs on the element now (reading them applies its pending\n * styles): an exit with none ends at once, in the render that started it, never a painted frame\n * later (spec/collapsible.md and tabs.md, \"Animation\").\n */\nexport function isAnimating(element: Element): boolean {\n return (\n typeof element.getAnimations === \"function\" &&\n element.getAnimations().length > 0\n );\n}\n"],"mappings":";;;;;;AAWA,SAAgB,iBAAiB,SAAiC;CAC9D,OAAO;EAAE,QAAQ,QAAQ;EAAc,OAAO,QAAQ;CAAY;AACtE;;;;;;;;AASA,SAAgB,gBACZ,SACA,QACS;CACT,MAAM,OAAO,iBAAiB,OAAO;CACrC,QAAQ,MAAM,YAAY,KAAK,OAAO,gBAAgB,GAAG,KAAK,OAAO,GAAG;CACxE,QAAQ,MAAM,YAAY,KAAK,OA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SizeVariables, i as BeforeMatchOptions, l as watchBeforeMatch, n as nextFrame, o as freezePanelSize, r as waitForAnimations, s as measurePanelSize, t as isAnimating } from "./index-DbAu4s16.js";
2
+ export { type BeforeMatchOptions, type PanelSize, freezePanelSize, isAnimating, measurePanelSize, nextFrame, panelSizeVariables, waitForAnimations, watchBeforeMatch };
@@ -0,0 +1 @@
1
+ export { i as freezePanelSize, t as isAnimating, a as measurePanelSize, n as nextFrame, o as panelSizeVariables, r as waitForAnimations, s as watchBeforeMatch } from "./presence-BhKDOmII.js";