@fragiola/primitives 0.0.0-stage → 0.0.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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/async-list-Bv6ff5Oj.js +81 -0
  4. package/dist/async-list-Bv6ff5Oj.js.map +1 -0
  5. package/dist/async-list.d.ts +2 -0
  6. package/dist/async-list.js +1 -0
  7. package/dist/calendar-keys-DGYpjLwv.d.ts +12 -0
  8. package/dist/calendar-system-B5U5HcPQ.d.ts +415 -0
  9. package/dist/calendar-systems-Daa6Q_ca.js +659 -0
  10. package/dist/calendar-systems-Daa6Q_ca.js.map +1 -0
  11. package/dist/calendar-systems.d.ts +3 -0
  12. package/dist/calendar-systems.js +1 -0
  13. package/dist/carousel-LRbWqbAx.js +375 -0
  14. package/dist/carousel-LRbWqbAx.js.map +1 -0
  15. package/dist/carousel.d.ts +2 -0
  16. package/dist/carousel.js +1 -0
  17. package/dist/cascade-B155Xvvv.js +64 -0
  18. package/dist/cascade-B155Xvvv.js.map +1 -0
  19. package/dist/cascade.d.ts +2 -0
  20. package/dist/cascade.js +1 -0
  21. package/dist/clipboard-Cy2cbGEW.js +33 -0
  22. package/dist/clipboard-Cy2cbGEW.js.map +1 -0
  23. package/dist/clipboard.d.ts +2 -0
  24. package/dist/clipboard.js +1 -0
  25. package/dist/collection-Dbk-PB5S.js +609 -0
  26. package/dist/collection-Dbk-PB5S.js.map +1 -0
  27. package/dist/collection.d.ts +2 -0
  28. package/dist/collection.js +3 -0
  29. package/dist/color-sURV5Irg.js +699 -0
  30. package/dist/color-sURV5Irg.js.map +1 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +1 -0
  33. package/dist/command-DueCXi65.js +104 -0
  34. package/dist/command-DueCXi65.js.map +1 -0
  35. package/dist/command.d.ts +2 -0
  36. package/dist/command.js +1 -0
  37. package/dist/date-CrbFSJKQ.js +215 -0
  38. package/dist/date-CrbFSJKQ.js.map +1 -0
  39. package/dist/date.d.ts +4 -0
  40. package/dist/date.js +1 -0
  41. package/dist/direction-CTnVLpmd.d.ts +8 -0
  42. package/dist/direction-DJDPvnxJ.js +13 -0
  43. package/dist/direction-DJDPvnxJ.js.map +1 -0
  44. package/dist/direction.d.ts +2 -0
  45. package/dist/direction.js +1 -0
  46. package/dist/drag-session-CSr06B5v.js +41 -0
  47. package/dist/drag-session-CSr06B5v.js.map +1 -0
  48. package/dist/file-DSLtfzbi.js +263 -0
  49. package/dist/file-DSLtfzbi.js.map +1 -0
  50. package/dist/file.d.ts +2 -0
  51. package/dist/file.js +1 -0
  52. package/dist/focus-BI-VvM0f.js +75 -0
  53. package/dist/focus-BI-VvM0f.js.map +1 -0
  54. package/dist/focus.d.ts +2 -0
  55. package/dist/focus.js +3 -0
  56. package/dist/form-DovwKtqz.js +501 -0
  57. package/dist/form-DovwKtqz.js.map +1 -0
  58. package/dist/form.d.ts +2 -0
  59. package/dist/form.js +1 -0
  60. package/dist/hover-BakyPYnC.js +62 -0
  61. package/dist/hover-BakyPYnC.js.map +1 -0
  62. package/dist/hover.d.ts +2 -0
  63. package/dist/hover.js +1 -0
  64. package/dist/id-B0Y8iZrc.js +13 -0
  65. package/dist/id-B0Y8iZrc.js.map +1 -0
  66. package/dist/id.d.ts +2 -0
  67. package/dist/id.js +1 -0
  68. package/dist/image-D4X_yRYw.js +44 -0
  69. package/dist/image-D4X_yRYw.js.map +1 -0
  70. package/dist/image.d.ts +2 -0
  71. package/dist/image.js +1 -0
  72. package/dist/index-B0rwIZw9.d.ts +51 -0
  73. package/dist/index-B4wF1isn.d.ts +128 -0
  74. package/dist/index-BHiBRE01.d.ts +20 -0
  75. package/dist/index-BNlMm-0u.d.ts +17 -0
  76. package/dist/index-BapNrjY9.d.ts +48 -0
  77. package/dist/index-Bd-tVb7C.d.ts +6 -0
  78. package/dist/index-BjE8nDiX.d.ts +125 -0
  79. package/dist/index-BpbT-FsX.d.ts +117 -0
  80. package/dist/index-CBgGcTeX.d.ts +37 -0
  81. package/dist/index-CGThV_Md.d.ts +100 -0
  82. package/dist/index-CMig3TXL.d.ts +28 -0
  83. package/dist/index-CWFRduRd.d.ts +212 -0
  84. package/dist/index-CkrHWyU_.d.ts +33 -0
  85. package/dist/index-Cwu6f7y1.d.ts +18 -0
  86. package/dist/index-D10LDdR6.d.ts +139 -0
  87. package/dist/index-D146vm21.d.ts +104 -0
  88. package/dist/index-DGKhEvNr.d.ts +107 -0
  89. package/dist/index-DbAu4s16.d.ts +48 -0
  90. package/dist/index-DdaCj6IO.d.ts +54 -0
  91. package/dist/index-DeHcNdjC.d.ts +68 -0
  92. package/dist/index-DeR4ncrW.d.ts +93 -0
  93. package/dist/index-HIksgK0e.d.ts +70 -0
  94. package/dist/index-IZB0mlZl.d.ts +71 -0
  95. package/dist/index-IfDZj87U.d.ts +28 -0
  96. package/dist/index-SrTuVBms.d.ts +75 -0
  97. package/dist/index-T9UcYvkf.d.ts +339 -0
  98. package/dist/index-fRTojAoR.d.ts +31 -0
  99. package/dist/index-fuLUke9n.d.ts +6 -0
  100. package/dist/index-l63esAck.d.ts +104 -0
  101. package/dist/index-raSUg9U7.d.ts +38 -0
  102. package/dist/index-twgzPKvZ.d.ts +278 -0
  103. package/dist/index-wBpjRykh.d.ts +125 -0
  104. package/dist/index.d.ts +39 -0
  105. package/dist/index.js +42 -0
  106. package/dist/inert-DlGToy3q.js +80 -0
  107. package/dist/inert-DlGToy3q.js.map +1 -0
  108. package/dist/inert.d.ts +2 -0
  109. package/dist/inert.js +1 -0
  110. package/dist/layer-stack-BEtzaFC1.js +118 -0
  111. package/dist/layer-stack-BEtzaFC1.js.map +1 -0
  112. package/dist/layers-C-N4rrZX.js +24 -0
  113. package/dist/layers-C-N4rrZX.js.map +1 -0
  114. package/dist/layers.d.ts +2 -0
  115. package/dist/layers.js +3 -0
  116. package/dist/list-navigation-CbWv4DK5.js +40 -0
  117. package/dist/list-navigation-CbWv4DK5.js.map +1 -0
  118. package/dist/month-year-BG5imFUq.js +108 -0
  119. package/dist/month-year-BG5imFUq.js.map +1 -0
  120. package/dist/month-year.d.ts +3 -0
  121. package/dist/month-year.js +1 -0
  122. package/dist/number-BFUio97d.js +316 -0
  123. package/dist/number-BFUio97d.js.map +1 -0
  124. package/dist/number.d.ts +2 -0
  125. package/dist/number.js +1 -0
  126. package/dist/overlay-BwPyiM3T.js +78 -0
  127. package/dist/overlay-BwPyiM3T.js.map +1 -0
  128. package/dist/overlay.d.ts +2 -0
  129. package/dist/overlay.js +1 -0
  130. package/dist/pagination-BkVzaIGP.js +51 -0
  131. package/dist/pagination-BkVzaIGP.js.map +1 -0
  132. package/dist/pagination.d.ts +2 -0
  133. package/dist/pagination.js +1 -0
  134. package/dist/plain-date-idQH1P6X.d.ts +29 -0
  135. package/dist/plain-date-time-B8PGahhe.d.ts +99 -0
  136. package/dist/pointer-CuDtD9XA.js +189 -0
  137. package/dist/pointer-CuDtD9XA.js.map +1 -0
  138. package/dist/pointer.d.ts +2 -0
  139. package/dist/pointer.js +3 -0
  140. package/dist/positioning-DDUQ75mB.js +148 -0
  141. package/dist/positioning-DDUQ75mB.js.map +1 -0
  142. package/dist/positioning.d.ts +2 -0
  143. package/dist/positioning.js +1 -0
  144. package/dist/presence-BhKDOmII.js +86 -0
  145. package/dist/presence-BhKDOmII.js.map +1 -0
  146. package/dist/presence.d.ts +2 -0
  147. package/dist/presence.js +1 -0
  148. package/dist/range-o0_GBhyY.js +158 -0
  149. package/dist/range-o0_GBhyY.js.map +1 -0
  150. package/dist/range.d.ts +2 -0
  151. package/dist/range.js +1 -0
  152. package/dist/scroll-area-BYNhv36t.js +447 -0
  153. package/dist/scroll-area-BYNhv36t.js.map +1 -0
  154. package/dist/scroll-area.d.ts +2 -0
  155. package/dist/scroll-area.js +1 -0
  156. package/dist/scroll-lock-JzRNOA1O.js +42 -0
  157. package/dist/scroll-lock-JzRNOA1O.js.map +1 -0
  158. package/dist/scroll-lock.d.ts +2 -0
  159. package/dist/scroll-lock.js +1 -0
  160. package/dist/segments-eRu5G_Bd.js +587 -0
  161. package/dist/segments-eRu5G_Bd.js.map +1 -0
  162. package/dist/segments.d.ts +3 -0
  163. package/dist/segments.js +1 -0
  164. package/dist/selection-Cor67w_V.js +287 -0
  165. package/dist/selection-Cor67w_V.js.map +1 -0
  166. package/dist/selection.d.ts +2 -0
  167. package/dist/selection.js +1 -0
  168. package/dist/swipe.d.ts +2 -0
  169. package/dist/swipe.js +1 -0
  170. package/dist/tabbable-BPiLssIv.js +35 -0
  171. package/dist/tabbable-BPiLssIv.js.map +1 -0
  172. package/dist/time-Ct6oq9kt.js +208 -0
  173. package/dist/time-Ct6oq9kt.js.map +1 -0
  174. package/dist/time-zone-DegkzwST.js +305 -0
  175. package/dist/time-zone-DegkzwST.js.map +1 -0
  176. package/dist/time-zone.d.ts +2 -0
  177. package/dist/time-zone.js +1 -0
  178. package/dist/time.d.ts +2 -0
  179. package/dist/time.js +1 -0
  180. package/dist/toast-BjRpJalM.js +400 -0
  181. package/dist/toast-BjRpJalM.js.map +1 -0
  182. package/dist/toast.d.ts +2 -0
  183. package/dist/toast.js +1 -0
  184. package/dist/unit-grid-DJy8lb5D.d.ts +21 -0
  185. package/dist/virtual-BlX1RuHD.js +306 -0
  186. package/dist/virtual-BlX1RuHD.js.map +1 -0
  187. package/dist/virtual.d.ts +2 -0
  188. package/dist/virtual.js +1 -0
  189. package/dist/watch-swipe-BIucfr9O.js +301 -0
  190. package/dist/watch-swipe-BIucfr9O.js.map +1 -0
  191. package/package.json +234 -3
@@ -0,0 +1,158 @@
1
+ // src/range/range-math.ts
2
+ /** Removes the floating-point noise of `min + n × step` (0.1 + 0.2), from the step's decimals. */
3
+ function roundToStepPrecision(value, step) {
4
+ const decimals = (String(step).split(".")[1] ?? "").length;
5
+ return Number(value.toFixed(decimals));
6
+ }
7
+ /** `value` snapped to `min + n × step` and clamped to `[min, max]`. */
8
+ function snapToStep(value, options) {
9
+ const { min, max, step } = options;
10
+ const snapped = min + Math.round((value - min) / step) * step;
11
+ return roundToStepPrecision(Math.min(Math.max(snapped, min), max), step);
12
+ }
13
+ /** Where `value` sits between `min` and `max`, in percent (0 to 100). */
14
+ function valueToPercent(value, min, max) {
15
+ if (max === min) return 0;
16
+ return (value - min) / (max - min) * 100;
17
+ }
18
+ /** The snapped value at `fraction` (0 to 1) along the range. */
19
+ function valueAtFraction(fraction, options) {
20
+ const clamped = Math.min(Math.max(fraction, 0), 1);
21
+ return snapToStep(options.min + clamped * (options.max - options.min), options);
22
+ }
23
+ /**
24
+ * The fraction (0 to 1) of a point along a control's box: from the inline start (the left, the
25
+ * right in RTL) horizontally, from the bottom vertically (spec/slider.md, "Pointer").
26
+ */
27
+ function fractionAlong(rect, point, orientation, rtl) {
28
+ if (orientation === "vertical") return rect.height === 0 ? 0 : (rect.top + rect.height - point.y) / rect.height;
29
+ if (rect.width === 0) return 0;
30
+ const fromLeft = (point.x - rect.left) / rect.width;
31
+ return rtl ? 1 - fromLeft : fromLeft;
32
+ }
33
+ /**
34
+ * The bounds thumb `index` can reach: its neighbours' values ∓ the minimum distance, else `min`
35
+ * and `max` (spec/slider.md, "State attributes and ARIA").
36
+ */
37
+ function thumbBounds(values, index, options) {
38
+ const gap = options.minStepsBetweenValues * options.step;
39
+ const previous = values[index - 1];
40
+ const next = values[index + 1];
41
+ return {
42
+ min: previous === void 0 ? options.min : roundToStepPrecision(previous + gap, options.step),
43
+ max: next === void 0 ? options.max : roundToStepPrecision(next - gap, options.step)
44
+ };
45
+ }
46
+ /**
47
+ * The thumb a press at `value` moves: the nearest one; among thumbs at the same distance (thumbs
48
+ * on the same value), the last when the press is past them, else the first.
49
+ */
50
+ function nearestThumb(values, value) {
51
+ let best = 0;
52
+ let bestDistance = Number.POSITIVE_INFINITY;
53
+ values.forEach((candidate, index) => {
54
+ const distance = Math.abs(candidate - value);
55
+ if (distance < bestDistance || distance === bestDistance && value > candidate) {
56
+ best = index;
57
+ bestDistance = distance;
58
+ }
59
+ });
60
+ return best;
61
+ }
62
+ /** `values` with thumb `index` moved to `next`, snapped and kept within its reachable bounds. */
63
+ function moveThumb(values, index, next, options) {
64
+ const bounds = thumbBounds(values, index, options);
65
+ const snapped = snapToStep(next, options);
66
+ const value = Math.min(Math.max(snapped, bounds.min), bounds.max);
67
+ return values.map((current, position) => position === index ? value : current);
68
+ }
69
+ // src/range/progress.ts
70
+ /**
71
+ * A Progress's value, percent, status and formatted value (spec/progress.md, "API"): the value is
72
+ * clamped to `[min, max]`, `null` is indeterminate, the clamped `max` is complete.
73
+ */
74
+ function progressValue(value, options = {}) {
75
+ const { min = 0, max = 100, format, locale } = options;
76
+ if (value === null || Number.isNaN(value)) return {
77
+ value: null,
78
+ percent: null,
79
+ status: "indeterminate",
80
+ formattedValue: ""
81
+ };
82
+ const clamped = Math.min(Math.max(value, min), max);
83
+ const percent = valueToPercent(clamped, min, max);
84
+ const formattedValue = format === void 0 ? new Intl.NumberFormat(locale, { style: "percent" }).format(percent / 100) : new Intl.NumberFormat(locale, format).format(clamped);
85
+ return {
86
+ value: clamped,
87
+ percent,
88
+ status: clamped === max ? "complete" : "progressing",
89
+ formattedValue
90
+ };
91
+ }
92
+ // src/range/rating.ts
93
+ /**
94
+ * The value a key moves a rating to (spec/rating.md, "Keyboard"): ArrowRight and ArrowDown one
95
+ * step up, ArrowLeft and ArrowUp one step down (Left and Right swapped in RTL), from `0` to the
96
+ * first step, wrapping between the first step and `count` with `loop`, never to `0`; Home the
97
+ * first step, End `count`. The step is 1, or 0.5 with `allowHalf`. `null` when the key does not
98
+ * change it: another key, an end without `loop`, or the value it already has.
99
+ */
100
+ function ratingKeyTarget(key, value, options) {
101
+ const step = options.allowHalf ? .5 : 1;
102
+ const first = Math.min(step, options.count);
103
+ const up = options.rtl ? key === "ArrowDown" || key === "ArrowLeft" : key === "ArrowDown" || key === "ArrowRight";
104
+ const down = options.rtl ? key === "ArrowUp" || key === "ArrowRight" : key === "ArrowUp" || key === "ArrowLeft";
105
+ let target = null;
106
+ if (key === "Home") target = first;
107
+ else if (key === "End") target = options.count;
108
+ else if (up) {
109
+ const next = (Math.floor(value / step) + 1) * step;
110
+ target = next <= options.count ? next : options.loop ? first : null;
111
+ } else if (down) {
112
+ const previous = (Math.ceil(value / step) - 1) * step;
113
+ target = previous >= first ? previous : options.loop ? options.count : null;
114
+ }
115
+ return target === null || target === value || options.count < 1 ? null : target;
116
+ }
117
+ /**
118
+ * The value a pointer at `fraction` of star `index` chooses (spec/rating.md, "Pointer"): the
119
+ * fraction is along the star from its inline-start edge (the toolkit's `fractionAlong`, so the
120
+ * right edge in RTL). With `allowHalf`, its inline-start half chooses `index - 0.5`.
121
+ */
122
+ function ratingValueAt(index, fraction, allowHalf) {
123
+ return allowHalf && fraction < .5 ? index - .5 : index;
124
+ }
125
+ /**
126
+ * Star `index`'s state (spec/rating.md, "API"): `checked` by the value, `highlighted` and `half` by
127
+ * the displayed one (the pointer's preview while it runs, else the value).
128
+ */
129
+ function ratingItemState(index, value, displayed = value) {
130
+ return {
131
+ checked: value > 0 && Math.ceil(value) === index,
132
+ highlighted: displayed > 0 && index <= Math.ceil(displayed),
133
+ half: displayed > 0 && displayed === index - .5
134
+ };
135
+ }
136
+ // src/range/slider-keys.ts
137
+ /**
138
+ * The value a key moves a slider thumb to (spec/slider.md, "Keyboard"), before snapping and
139
+ * clamping; `null` when the key does not move it. Shift with an arrow moves by `largeStep`.
140
+ */
141
+ function sliderKeyTarget(key, shiftKey, value, options) {
142
+ const amount = shiftKey ? options.largeStep : options.step;
143
+ const right = options.rtl ? -1 : 1;
144
+ switch (key) {
145
+ case "ArrowUp": return value + amount;
146
+ case "ArrowDown": return value - amount;
147
+ case "ArrowRight": return value + right * amount;
148
+ case "ArrowLeft": return value - right * amount;
149
+ case "PageUp": return value + options.largeStep;
150
+ case "PageDown": return value - options.largeStep;
151
+ case "Home": return options.min;
152
+ case "End": return options.max;
153
+ default: return null;
154
+ }
155
+ }
156
+ export { progressValue as a, nearestThumb as c, valueAtFraction as d, valueToPercent as f, ratingValueAt as i, snapToStep as l, ratingItemState as n, fractionAlong as o, ratingKeyTarget as r, moveThumb as s, sliderKeyTarget as t, thumbBounds as u };
157
+
158
+ //# sourceMappingURL=range-o0_GBhyY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range-o0_GBhyY.js","names":[],"sources":["../src/range/range-math.ts","../src/range/progress.ts","../src/range/rating.ts","../src/range/slider-keys.ts"],"sourcesContent":["/** The bounds and step of a range (spec/slider.md, \"API\"). */\nexport interface RangeOptions {\n min: number;\n max: number;\n step: number;\n}\n\nexport interface ThumbOptions extends RangeOptions {\n /** The smallest distance between two thumbs, in steps. */\n minStepsBetweenValues: number;\n}\n\n/** Removes the floating-point noise of `min + n × step` (0.1 + 0.2), from the step's decimals. */\nfunction roundToStepPrecision(value: number, step: number): number {\n const decimals = (String(step).split(\".\")[1] ?? \"\").length;\n return Number(value.toFixed(decimals));\n}\n\n/** `value` snapped to `min + n × step` and clamped to `[min, max]`. */\nexport function snapToStep(value: number, options: RangeOptions): number {\n const { min, max, step } = options;\n const snapped = min + Math.round((value - min) / step) * step;\n const clamped = Math.min(Math.max(snapped, min), max);\n return roundToStepPrecision(clamped, step);\n}\n\n/** Where `value` sits between `min` and `max`, in percent (0 to 100). */\nexport function valueToPercent(\n value: number,\n min: number,\n max: number,\n): number {\n if (max === min) {\n return 0;\n }\n return ((value - min) / (max - min)) * 100;\n}\n\n/** The snapped value at `fraction` (0 to 1) along the range. */\nexport function valueAtFraction(\n fraction: number,\n options: RangeOptions,\n): number {\n const clamped = Math.min(Math.max(fraction, 0), 1);\n return snapToStep(\n options.min + clamped * (options.max - options.min),\n options,\n );\n}\n\n/**\n * The fraction (0 to 1) of a point along a control's box: from the inline start (the left, the\n * right in RTL) horizontally, from the bottom vertically (spec/slider.md, \"Pointer\").\n */\nexport function fractionAlong(\n rect: { left: number; top: number; width: number; height: number },\n point: { x: number; y: number },\n orientation: \"horizontal\" | \"vertical\",\n rtl: boolean,\n): number {\n if (orientation === \"vertical\") {\n return rect.height === 0\n ? 0\n : (rect.top + rect.height - point.y) / rect.height;\n }\n if (rect.width === 0) {\n return 0;\n }\n const fromLeft = (point.x - rect.left) / rect.width;\n return rtl ? 1 - fromLeft : fromLeft;\n}\n\n/**\n * The bounds thumb `index` can reach: its neighbours' values ∓ the minimum distance, else `min`\n * and `max` (spec/slider.md, \"State attributes and ARIA\").\n */\nexport function thumbBounds(\n values: readonly number[],\n index: number,\n options: ThumbOptions,\n): { min: number; max: number } {\n const gap = options.minStepsBetweenValues * options.step;\n const previous = values[index - 1];\n const next = values[index + 1];\n return {\n min:\n previous === undefined\n ? options.min\n : roundToStepPrecision(previous + gap, options.step),\n max:\n next === undefined\n ? options.max\n : roundToStepPrecision(next - gap, options.step),\n };\n}\n\n/**\n * The thumb a press at `value` moves: the nearest one; among thumbs at the same distance (thumbs\n * on the same value), the last when the press is past them, else the first.\n */\nexport function nearestThumb(values: readonly number[], value: number): number {\n let best = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n values.forEach((candidate, index) => {\n const distance = Math.abs(candidate - value);\n if (\n distance < bestDistance ||\n (distance === bestDistance && value > candidate)\n ) {\n best = index;\n bestDistance = distance;\n }\n });\n return best;\n}\n\n/** `values` with thumb `index` moved to `next`, snapped and kept within its reachable bounds. */\nexport function moveThumb(\n values: readonly number[],\n index: number,\n next: number,\n options: ThumbOptions,\n): number[] {\n const bounds = thumbBounds(values, index, options);\n const snapped = snapToStep(next, options);\n const value = Math.min(Math.max(snapped, bounds.min), bounds.max);\n return values.map((current, position) =>\n position === index ? value : current,\n );\n}\n","import { valueToPercent } from \"./range-math.ts\";\n\n/** A Progress's status (spec/progress.md): exactly one of these. */\nexport type ProgressStatus = \"indeterminate\" | \"progressing\" | \"complete\";\n\nexport interface ProgressOptions {\n /** The lowest value (default `0`). */\n min?: number;\n /** The highest value (default `100`). */\n max?: number;\n /**\n * How the value is written. Without it, the value is written as a percentage of the range\n * (`{ style: \"percent\" }` of its fraction).\n */\n format?: Intl.NumberFormatOptions;\n /** The locale of the format (BCP 47; default: the runtime's). */\n locale?: string;\n}\n\nexport interface ProgressValue {\n /** The value clamped to `[min, max]`, or `null` when indeterminate. */\n value: number | null;\n /** Where the value sits in the range, from 0 to 100; `null` when indeterminate. */\n percent: number | null;\n status: ProgressStatus;\n /** The value as `format` writes it (a percentage by default); `\"\"` when indeterminate. */\n formattedValue: string;\n}\n\n/**\n * A Progress's value, percent, status and formatted value (spec/progress.md, \"API\"): the value is\n * clamped to `[min, max]`, `null` is indeterminate, the clamped `max` is complete.\n */\nexport function progressValue(\n value: number | null,\n options: ProgressOptions = {},\n): ProgressValue {\n const { min = 0, max = 100, format, locale } = options;\n if (value === null || Number.isNaN(value)) {\n return {\n value: null,\n percent: null,\n status: \"indeterminate\",\n formattedValue: \"\",\n };\n }\n const clamped = Math.min(Math.max(value, min), max);\n const percent = valueToPercent(clamped, min, max);\n const formattedValue =\n format === undefined\n ? new Intl.NumberFormat(locale, { style: \"percent\" }).format(\n percent / 100,\n )\n : new Intl.NumberFormat(locale, format).format(clamped);\n return {\n value: clamped,\n percent,\n status: clamped === max ? \"complete\" : \"progressing\",\n formattedValue,\n };\n}\n","export interface RatingKeyOptions {\n /** The number of stars: the highest value. */\n count: number;\n /** Half steps (0.5) instead of whole ones. */\n allowHalf: boolean;\n rtl: boolean;\n /** Wrap from `count` to the first step, and back (spec/rating.md, `loopFocus`). */\n loop: boolean;\n}\n\n/**\n * The value a key moves a rating to (spec/rating.md, \"Keyboard\"): ArrowRight and ArrowDown one\n * step up, ArrowLeft and ArrowUp one step down (Left and Right swapped in RTL), from `0` to the\n * first step, wrapping between the first step and `count` with `loop`, never to `0`; Home the\n * first step, End `count`. The step is 1, or 0.5 with `allowHalf`. `null` when the key does not\n * change it: another key, an end without `loop`, or the value it already has.\n */\nexport function ratingKeyTarget(\n key: string,\n value: number,\n options: RatingKeyOptions,\n): number | null {\n const step = options.allowHalf ? 0.5 : 1;\n const first = Math.min(step, options.count);\n const up = options.rtl\n ? key === \"ArrowDown\" || key === \"ArrowLeft\"\n : key === \"ArrowDown\" || key === \"ArrowRight\";\n const down = options.rtl\n ? key === \"ArrowUp\" || key === \"ArrowRight\"\n : key === \"ArrowUp\" || key === \"ArrowLeft\";\n let target: number | null = null;\n if (key === \"Home\") {\n target = first;\n } else if (key === \"End\") {\n target = options.count;\n } else if (up) {\n const next = (Math.floor(value / step) + 1) * step;\n target = next <= options.count ? next : options.loop ? first : null;\n } else if (down) {\n const previous = (Math.ceil(value / step) - 1) * step;\n target =\n previous >= first ? previous : options.loop ? options.count : null;\n }\n return target === null || target === value || options.count < 1\n ? null\n : target;\n}\n\n/**\n * The value a pointer at `fraction` of star `index` chooses (spec/rating.md, \"Pointer\"): the\n * fraction is along the star from its inline-start edge (the toolkit's `fractionAlong`, so the\n * right edge in RTL). With `allowHalf`, its inline-start half chooses `index - 0.5`.\n */\nexport function ratingValueAt(\n index: number,\n fraction: number,\n allowHalf: boolean,\n): number {\n return allowHalf && fraction < 0.5 ? index - 0.5 : index;\n}\n\n/** A star's drawn state (spec/rating.md, \"API\"). */\nexport interface RatingItemState {\n /** The star holds `value`: `index` is `value` rounded up. */\n checked: boolean;\n /** The star is drawn filled, whole or half, for the displayed value. */\n highlighted: boolean;\n /** The star is drawn half filled: the displayed value is `index - 0.5`. */\n half: boolean;\n}\n\n/**\n * Star `index`'s state (spec/rating.md, \"API\"): `checked` by the value, `highlighted` and `half` by\n * the displayed one (the pointer's preview while it runs, else the value).\n */\nexport function ratingItemState(\n index: number,\n value: number,\n displayed: number = value,\n): RatingItemState {\n return {\n checked: value > 0 && Math.ceil(value) === index,\n highlighted: displayed > 0 && index <= Math.ceil(displayed),\n half: displayed > 0 && displayed === index - 0.5,\n };\n}\n","export interface SliderKeyOptions {\n step: number;\n largeStep: number;\n /** The bounds the thumb can reach (`thumbBounds`). */\n min: number;\n max: number;\n orientation: \"horizontal\" | \"vertical\";\n rtl: boolean;\n}\n\n/**\n * The value a key moves a slider thumb to (spec/slider.md, \"Keyboard\"), before snapping and\n * clamping; `null` when the key does not move it. Shift with an arrow moves by `largeStep`.\n */\nexport function sliderKeyTarget(\n key: string,\n shiftKey: boolean,\n value: number,\n options: SliderKeyOptions,\n): number | null {\n const amount = shiftKey ? options.largeStep : options.step;\n // in RTL the horizontal arrows swap, whatever the orientation\n const right = options.rtl ? -1 : 1;\n switch (key) {\n case \"ArrowUp\":\n return value + amount;\n case \"ArrowDown\":\n return value - amount;\n case \"ArrowRight\":\n return value + right * amount;\n case \"ArrowLeft\":\n return value - right * amount;\n case \"PageUp\":\n return value + options.largeStep;\n case \"PageDown\":\n return value - options.largeStep;\n case \"Home\":\n return options.min;\n case \"End\":\n return options.max;\n default:\n return null;\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import { _ as ProgressOptions, a as ratingItemState, b as progressValue, c as RangeOptions, d as moveThumb, f as nearestThumb, g as valueToPercent, h as valueAtFraction, i as RatingKeyOptions, l as ThumbOptions, m as thumbBounds, n as sliderKeyTarget, o as ratingKeyTarget, p as snapToStep, r as RatingItemState, s as ratingValueAt, t as SliderKeyOptions, u as fractionAlong, v as ProgressStatus, y as ProgressValue } from "./index-wBpjRykh.js";
2
+ export { type ProgressOptions, type ProgressStatus, type ProgressValue, type RangeOptions, type RatingItemState, type RatingKeyOptions, type SliderKeyOptions, type ThumbOptions, fractionAlong, moveThumb, nearestThumb, progressValue, ratingItemState, ratingKeyTarget, ratingValueAt, sliderKeyTarget, snapToStep, thumbBounds, valueAtFraction, valueToPercent };
package/dist/range.js ADDED
@@ -0,0 +1 @@
1
+ export { o as fractionAlong, s as moveThumb, c as nearestThumb, a as progressValue, n as ratingItemState, r as ratingKeyTarget, i as ratingValueAt, t as sliderKeyTarget, l as snapToStep, u as thumbBounds, d as valueAtFraction, f as valueToPercent } from "./range-o0_GBhyY.js";
@@ -0,0 +1,447 @@
1
+ // src/scroll-area/scroll-geometry.ts
2
+ /** The smallest thumb, in pixels (spec/scroll-area.md, "Measurement"; Base UI's). */
3
+ const MIN_THUMB_SIZE = 16;
4
+ /** A position within this many pixels of an edge counts as the edge. */
5
+ const EDGE_TOLERANCE = 1;
6
+ /**
7
+ * A scroll position as a distance from the start of its range, clamped to `[0, max]`, and moved
8
+ * onto an edge when it is within 1 px of it (subpixel scrolling ends a pixel short).
9
+ */
10
+ function scrollFromStart(position, max) {
11
+ if (max <= 0) return 0;
12
+ const clamped = Math.min(max, Math.max(0, position));
13
+ const atStart = clamped <= EDGE_TOLERANCE;
14
+ const atEnd = max - clamped <= EDGE_TOLERANCE;
15
+ if (atStart && atEnd) return clamped <= max - clamped ? 0 : max;
16
+ if (atStart) return 0;
17
+ return atEnd ? max : clamped;
18
+ }
19
+ /**
20
+ * A thumb's size (the room times the visible fraction, at least `MIN_THUMB_SIZE`) and offset (the
21
+ * scroll's fraction of its range times the room the thumb leaves).
22
+ */
23
+ function thumbGeometry({ clientSize, scrollSize, fromStart, room }) {
24
+ const visible = scrollSize > 0 ? Math.min(1, clientSize / scrollSize) : 1;
25
+ const size = Math.max(16, Math.max(0, room) * visible);
26
+ const max = Math.max(0, scrollSize - clientSize);
27
+ const free = room - size;
28
+ return {
29
+ size,
30
+ offset: max > 0 && free > 0 ? fromStart / max * free : 0
31
+ };
32
+ }
33
+ /**
34
+ * The scroll distance from the start that a thumb offset stands for (a drag's or a track
35
+ * press's), clamped to the range.
36
+ */
37
+ function scrollForThumbOffset(offset, free, max) {
38
+ if (free <= 0 || max <= 0) return 0;
39
+ return Math.min(max, Math.max(0, offset / free * max));
40
+ }
41
+ // src/scroll-area/create-scroll-area.ts
42
+ /** How long `scrolling` stays after the last user scroll, in milliseconds (Base UI's). */
43
+ const SCROLLING_TIMEOUT = 500;
44
+ /** How long after the last scroll event a scroll ends (and the next one is programmatic). */
45
+ const SCROLL_END_TIMEOUT = 100;
46
+ /** The elements that take the focus: the Viewport needs no tab stop of its own when one is in it. */
47
+ const FOCUSABLE = "a[href], area[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), iframe, summary, audio[controls], video[controls], [contenteditable]:not([contenteditable=\"false\"]), [tabindex]:not([tabindex^=\"-\"])";
48
+ /** The state before any measurement: what a server renders. */
49
+ function initialScrollAreaState() {
50
+ return {
51
+ measured: false,
52
+ hasOverflowX: false,
53
+ hasOverflowY: false,
54
+ overflowXStart: false,
55
+ overflowXEnd: false,
56
+ overflowYStart: false,
57
+ overflowYEnd: false,
58
+ scrollingX: false,
59
+ scrollingY: false,
60
+ hovering: false,
61
+ focusable: false
62
+ };
63
+ }
64
+ /** The threshold of every edge, each at least `0`. */
65
+ function normalizeScrollAreaThreshold(input) {
66
+ const edges = typeof input === "number" ? {
67
+ xStart: input,
68
+ xEnd: input,
69
+ yStart: input,
70
+ yEnd: input
71
+ } : input ?? {};
72
+ const edge = (value) => Math.max(0, Number.isFinite(value) ? value : 0);
73
+ return {
74
+ xStart: edge(edges.xStart),
75
+ xEnd: edge(edges.xEnd),
76
+ yStart: edge(edges.yStart),
77
+ yEnd: edge(edges.yEnd)
78
+ };
79
+ }
80
+ /**
81
+ * A ScrollArea's DOM side (spec/scroll-area.md): it measures the Viewport and its Content (on
82
+ * mount, on scroll, on resize through a `ResizeObserver`), writes the measured CSS variables and
83
+ * each Thumb's transform, and runs the Scrollbars' pointer (thumb drag, track press, wheel) and
84
+ * the Root's hover, all with native listeners. It reports the state the framework renders; it
85
+ * holds no value and renders nothing.
86
+ */
87
+ function createScrollArea(root, options) {
88
+ const view = root.ownerDocument.defaultView;
89
+ const parts = {};
90
+ const partCleanups = {};
91
+ let state = initialScrollAreaState();
92
+ let destroyed = false;
93
+ let touch = false;
94
+ let userScroll = false;
95
+ let lastScroll = {
96
+ x: 0,
97
+ y: 0
98
+ };
99
+ let drag = null;
100
+ let savedSnap = null;
101
+ const timers = {
102
+ x: void 0,
103
+ y: void 0,
104
+ end: void 0
105
+ };
106
+ const observer = view !== null && typeof view.ResizeObserver === "function" ? new view.ResizeObserver(() => measure()) : null;
107
+ const emit = (patch) => {
108
+ if (destroyed) return;
109
+ let changed = false;
110
+ for (const key of Object.keys(patch)) if (state[key] !== patch[key]) changed = true;
111
+ if (changed) {
112
+ state = {
113
+ ...state,
114
+ ...patch
115
+ };
116
+ options.onStateChange(state);
117
+ }
118
+ };
119
+ const clearTimer = (name) => {
120
+ if (timers[name] !== void 0) {
121
+ view?.clearTimeout(timers[name]);
122
+ timers[name] = void 0;
123
+ }
124
+ };
125
+ const startScrolling = (vertical) => {
126
+ const axis = vertical ? "y" : "x";
127
+ emit(vertical ? { scrollingY: true } : { scrollingX: true });
128
+ clearTimer(axis);
129
+ timers[axis] = view?.setTimeout(() => {
130
+ timers[axis] = void 0;
131
+ if (drag?.vertical !== vertical) emit(vertical ? { scrollingY: false } : { scrollingX: false });
132
+ }, SCROLLING_TIMEOUT);
133
+ };
134
+ const isRtl = (element) => {
135
+ const provided = options.direction?.() ?? null;
136
+ if (provided !== null) return provided === "rtl";
137
+ return view?.getComputedStyle(element).direction === "rtl";
138
+ };
139
+ const sizes = (element, vertical) => {
140
+ if (element === void 0 || view === null) return {
141
+ start: 0,
142
+ end: 0
143
+ };
144
+ const style = view.getComputedStyle(element);
145
+ const read = (name) => Number.parseFloat(style.getPropertyValue(name)) || 0;
146
+ return vertical ? {
147
+ start: read("padding-top"),
148
+ end: read("padding-bottom")
149
+ } : {
150
+ start: read("padding-inline-start"),
151
+ end: read("padding-inline-end")
152
+ };
153
+ };
154
+ const margins = (element, vertical) => {
155
+ if (element === void 0 || view === null) return 0;
156
+ const style = view.getComputedStyle(element);
157
+ const read = (name) => Number.parseFloat(style.getPropertyValue(name)) || 0;
158
+ return vertical ? read("margin-top") + read("margin-bottom") : read("margin-inline-start") + read("margin-inline-end");
159
+ };
160
+ /** The track's room and the thumb's size along an axis, for the pointer's math. */
161
+ const trackOf = (vertical) => {
162
+ const scrollbar = parts[vertical ? "scrollbar-y" : "scrollbar-x"];
163
+ const thumb = parts[vertical ? "thumb-y" : "thumb-x"];
164
+ if (scrollbar === void 0) return null;
165
+ const padding = sizes(scrollbar, vertical);
166
+ return {
167
+ scrollbar,
168
+ thumb,
169
+ room: (vertical ? scrollbar.offsetHeight : scrollbar.offsetWidth) - padding.start - padding.end - margins(thumb, vertical),
170
+ size: thumb === void 0 ? 0 : vertical ? thumb.offsetHeight : thumb.offsetWidth,
171
+ paddingStart: padding.start
172
+ };
173
+ };
174
+ function measure() {
175
+ const viewport = parts.viewport;
176
+ if (destroyed || viewport === void 0) return;
177
+ const { scrollHeight, scrollWidth, clientHeight, clientWidth, scrollTop, scrollLeft } = viewport;
178
+ if (scrollHeight === 0 || scrollWidth === 0) {
179
+ emit({ measured: true });
180
+ return;
181
+ }
182
+ const rtl = isRtl(viewport);
183
+ const hasOverflowX = clientWidth < scrollWidth;
184
+ const hasOverflowY = clientHeight < scrollHeight;
185
+ const maxX = Math.max(0, scrollWidth - clientWidth);
186
+ const maxY = Math.max(0, scrollHeight - clientHeight);
187
+ const fromStartX = hasOverflowX ? scrollFromStart(rtl ? -scrollLeft : scrollLeft, maxX) : 0;
188
+ const fromStartY = hasOverflowY ? scrollFromStart(scrollTop, maxY) : 0;
189
+ const edges = [
190
+ fromStartX,
191
+ maxX - fromStartX,
192
+ fromStartY,
193
+ maxY - fromStartY
194
+ ];
195
+ const both = hasOverflowX && hasOverflowY;
196
+ const cornerWidth = both ? parts["scrollbar-y"]?.offsetWidth ?? 0 : 0;
197
+ const cornerHeight = both ? parts["scrollbar-x"]?.offsetHeight ?? 0 : 0;
198
+ root.style.setProperty("--scroll-area-corner-width", `${cornerWidth}px`);
199
+ root.style.setProperty("--scroll-area-corner-height", `${cornerHeight}px`);
200
+ for (const vertical of [true, false]) {
201
+ const track = trackOf(vertical);
202
+ if (track === null) continue;
203
+ const geometry = thumbGeometry({
204
+ clientSize: vertical ? clientHeight : clientWidth,
205
+ scrollSize: vertical ? scrollHeight : scrollWidth,
206
+ fromStart: vertical ? fromStartY : fromStartX,
207
+ room: track.room
208
+ });
209
+ track.scrollbar.style.setProperty(vertical ? "--scroll-area-thumb-height" : "--scroll-area-thumb-width", `${geometry.size}px`);
210
+ if (track.thumb !== void 0) {
211
+ const offset = vertical ? `0px, ${geometry.offset}px, 0px` : `${rtl ? -geometry.offset : geometry.offset}px, 0px, 0px`;
212
+ track.thumb.style.transform = `translate3d(${offset})`;
213
+ }
214
+ }
215
+ [
216
+ "x-start",
217
+ "x-end",
218
+ "y-start",
219
+ "y-end"
220
+ ].forEach((name, index) => {
221
+ viewport.style.setProperty(`--scroll-area-overflow-${name}`, `${edges[index]}px`);
222
+ });
223
+ const threshold = normalizeScrollAreaThreshold(options.threshold?.());
224
+ emit({
225
+ measured: true,
226
+ hasOverflowX,
227
+ hasOverflowY,
228
+ overflowXStart: hasOverflowX && fromStartX > threshold.xStart,
229
+ overflowXEnd: hasOverflowX && maxX - fromStartX > threshold.xEnd,
230
+ overflowYStart: hasOverflowY && fromStartY > threshold.yStart,
231
+ overflowYEnd: hasOverflowY && maxY - fromStartY > threshold.yEnd,
232
+ focusable: (hasOverflowX || hasOverflowY) && viewport.querySelector(FOCUSABLE) === null
233
+ });
234
+ }
235
+ const onRootPointer = (event) => {
236
+ touch = event.pointerType === "touch";
237
+ if (event.type !== "pointerdown" && !touch) emit({ hovering: event.target instanceof Node && root.contains(event.target) });
238
+ };
239
+ const onRootLeave = () => emit({ hovering: false });
240
+ root.addEventListener("pointerenter", onRootPointer);
241
+ root.addEventListener("pointermove", onRootPointer);
242
+ root.addEventListener("pointerdown", onRootPointer);
243
+ root.addEventListener("pointerleave", onRootLeave);
244
+ try {
245
+ if (root.matches(":hover")) emit({ hovering: true });
246
+ } catch {}
247
+ const scrollTo = (vertical, fromStart) => {
248
+ const viewport = parts.viewport;
249
+ if (viewport === void 0) return;
250
+ if (vertical) viewport.scrollTop = fromStart;
251
+ else viewport.scrollLeft = isRtl(viewport) ? -fromStart : fromStart;
252
+ };
253
+ const disableSnap = () => {
254
+ const viewport = parts.viewport;
255
+ if (viewport !== void 0 && savedSnap === null) {
256
+ savedSnap = viewport.style.scrollSnapType;
257
+ viewport.style.scrollSnapType = "none";
258
+ }
259
+ };
260
+ const restoreSnap = () => {
261
+ if (savedSnap !== null && parts.viewport !== void 0) parts.viewport.style.scrollSnapType = savedSnap;
262
+ savedSnap = null;
263
+ };
264
+ const endDrag = () => {
265
+ const current = drag;
266
+ if (current === null) return;
267
+ drag = null;
268
+ current.stop();
269
+ restoreSnap();
270
+ clearTimer(current.vertical ? "y" : "x");
271
+ emit(current.vertical ? { scrollingY: false } : { scrollingX: false });
272
+ };
273
+ /** A drag of the thumb from `event` (a press on the thumb, or a track press after its jump). */
274
+ const startDrag = (vertical, event) => {
275
+ const viewport = parts.viewport;
276
+ const capture = parts[vertical ? "thumb-y" : "thumb-x"] ?? parts[vertical ? "scrollbar-y" : "scrollbar-x"];
277
+ if (viewport === void 0 || capture === void 0 || view === null) return;
278
+ endDrag();
279
+ const rtl = !vertical && isRtl(viewport);
280
+ const point = (pointer) => vertical ? pointer.clientY : rtl ? -pointer.clientX : pointer.clientX;
281
+ const max = vertical ? viewport.scrollHeight - viewport.clientHeight : viewport.scrollWidth - viewport.clientWidth;
282
+ const startScroll = vertical ? viewport.scrollTop : scrollFromStart(rtl ? -viewport.scrollLeft : viewport.scrollLeft, max);
283
+ const pointerId = event.pointerId;
284
+ const onMove = (move) => {
285
+ if (move.pointerId !== pointerId) return;
286
+ if ((move.buttons & 1) === 0) {
287
+ endDrag();
288
+ return;
289
+ }
290
+ const track = trackOf(vertical);
291
+ if (track === null) return;
292
+ const delta = point(move) - (drag?.start ?? 0);
293
+ const offset = (max > 0 ? startScroll / max * (track.room - track.size) : 0) + delta;
294
+ scrollTo(vertical, scrollForThumbOffset(offset, track.room - track.size, max));
295
+ move.preventDefault();
296
+ startScrolling(vertical);
297
+ };
298
+ const onUp = (up) => {
299
+ if (up.pointerId === pointerId) endDrag();
300
+ };
301
+ try {
302
+ capture.setPointerCapture(pointerId);
303
+ } catch {}
304
+ view.addEventListener("pointermove", onMove);
305
+ view.addEventListener("pointerup", onUp);
306
+ view.addEventListener("pointercancel", onUp);
307
+ capture.addEventListener("lostpointercapture", endDrag);
308
+ drag = {
309
+ vertical,
310
+ pointerId,
311
+ start: point(event),
312
+ startScroll,
313
+ capture,
314
+ stop: () => {
315
+ view.removeEventListener("pointermove", onMove);
316
+ view.removeEventListener("pointerup", onUp);
317
+ view.removeEventListener("pointercancel", onUp);
318
+ capture.removeEventListener("lostpointercapture", endDrag);
319
+ try {
320
+ if (capture.hasPointerCapture(pointerId)) capture.releasePointerCapture(pointerId);
321
+ } catch {}
322
+ }
323
+ };
324
+ disableSnap();
325
+ startScrolling(vertical);
326
+ };
327
+ const watchScrollbar = (scrollbar, vertical) => {
328
+ const onPointerDown = (event) => {
329
+ const viewport = parts.viewport;
330
+ if (event.button !== 0 || viewport === void 0) return;
331
+ const thumb = parts[vertical ? "thumb-y" : "thumb-x"];
332
+ if (!(thumb !== void 0 && event.target instanceof Node && thumb.contains(event.target))) {
333
+ const track = trackOf(vertical);
334
+ if (track === null || track.room - track.size <= 0) return;
335
+ const rect = scrollbar.getBoundingClientRect();
336
+ const rtl = !vertical && isRtl(viewport);
337
+ const along = vertical ? event.clientY - rect.top : rtl ? rect.right - event.clientX : event.clientX - rect.left;
338
+ const max = vertical ? viewport.scrollHeight - viewport.clientHeight : viewport.scrollWidth - viewport.clientWidth;
339
+ disableSnap();
340
+ scrollTo(vertical, scrollForThumbOffset(along - track.paddingStart - track.size / 2, track.room - track.size, max));
341
+ measure();
342
+ }
343
+ startDrag(vertical, event);
344
+ };
345
+ const onMouseDown = (event) => event.preventDefault();
346
+ const onWheel = (event) => {
347
+ const viewport = parts.viewport;
348
+ if (viewport === void 0 || event.ctrlKey) return;
349
+ const delta = vertical ? event.deltaY : event.deltaX;
350
+ if (delta === 0) return;
351
+ const max = vertical ? viewport.scrollHeight - viewport.clientHeight : viewport.scrollWidth - viewport.clientWidth;
352
+ const rtl = !vertical && isRtl(viewport);
353
+ const position = vertical ? viewport.scrollTop : rtl ? -viewport.scrollLeft : viewport.scrollLeft;
354
+ const forward = rtl ? -delta : delta;
355
+ if (position <= 0 && forward < 0 || position >= max && forward > 0) return;
356
+ event.preventDefault();
357
+ userScroll = true;
358
+ scrollTo(vertical, Math.min(max, Math.max(0, position + forward)));
359
+ };
360
+ scrollbar.addEventListener("pointerdown", onPointerDown);
361
+ scrollbar.addEventListener("mousedown", onMouseDown);
362
+ scrollbar.addEventListener("wheel", onWheel, { passive: false });
363
+ return () => {
364
+ scrollbar.removeEventListener("pointerdown", onPointerDown);
365
+ scrollbar.removeEventListener("mousedown", onMouseDown);
366
+ scrollbar.removeEventListener("wheel", onWheel);
367
+ };
368
+ };
369
+ const watchViewport = (viewport) => {
370
+ lastScroll = {
371
+ x: viewport.scrollLeft,
372
+ y: viewport.scrollTop
373
+ };
374
+ const onInteraction = () => {
375
+ userScroll = true;
376
+ };
377
+ const onScroll = () => {
378
+ measure();
379
+ const position = {
380
+ x: viewport.scrollLeft,
381
+ y: viewport.scrollTop
382
+ };
383
+ if (touch || userScroll) {
384
+ if (position.y !== lastScroll.y) startScrolling(true);
385
+ if (position.x !== lastScroll.x) startScrolling(false);
386
+ }
387
+ lastScroll = position;
388
+ clearTimer("end");
389
+ timers.end = view?.setTimeout(() => {
390
+ timers.end = void 0;
391
+ if (drag === null) userScroll = false;
392
+ }, SCROLL_END_TIMEOUT);
393
+ };
394
+ const events = [
395
+ "wheel",
396
+ "pointermove",
397
+ "pointerenter",
398
+ "keydown",
399
+ "touchstart"
400
+ ];
401
+ for (const name of events) viewport.addEventListener(name, onInteraction, { passive: true });
402
+ viewport.addEventListener("scroll", onScroll, { passive: true });
403
+ observer?.observe(viewport);
404
+ return () => {
405
+ for (const name of events) viewport.removeEventListener(name, onInteraction);
406
+ viewport.removeEventListener("scroll", onScroll);
407
+ observer?.unobserve(viewport);
408
+ };
409
+ };
410
+ const setPart = (part, element) => {
411
+ if (destroyed || parts[part] === (element ?? void 0)) return;
412
+ if (drag !== null && parts[part] === drag.capture) endDrag();
413
+ partCleanups[part]?.();
414
+ delete partCleanups[part];
415
+ if (element === null) delete parts[part];
416
+ else {
417
+ parts[part] = element;
418
+ if (part === "viewport") partCleanups[part] = watchViewport(element);
419
+ else if (part === "content") {
420
+ observer?.observe(element);
421
+ partCleanups[part] = () => observer?.unobserve(element);
422
+ } else if (part === "scrollbar-x" || part === "scrollbar-y") partCleanups[part] = watchScrollbar(element, part === "scrollbar-y");
423
+ }
424
+ measure();
425
+ };
426
+ return {
427
+ setPart,
428
+ update: measure,
429
+ destroy: () => {
430
+ if (destroyed) return;
431
+ endDrag();
432
+ destroyed = true;
433
+ for (const cleanup of Object.values(partCleanups)) cleanup?.();
434
+ observer?.disconnect();
435
+ clearTimer("x");
436
+ clearTimer("y");
437
+ clearTimer("end");
438
+ root.removeEventListener("pointerenter", onRootPointer);
439
+ root.removeEventListener("pointermove", onRootPointer);
440
+ root.removeEventListener("pointerdown", onRootPointer);
441
+ root.removeEventListener("pointerleave", onRootLeave);
442
+ }
443
+ };
444
+ }
445
+ export { scrollForThumbOffset as a, MIN_THUMB_SIZE as i, initialScrollAreaState as n, scrollFromStart as o, normalizeScrollAreaThreshold as r, thumbGeometry as s, createScrollArea as t };
446
+
447
+ //# sourceMappingURL=scroll-area-BYNhv36t.js.map