@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,316 @@
1
+ // src/number/auto-repeat.ts
2
+ /**
3
+ * Press and hold on `element` (spec/number-field.md, "Pointer": an Increment or Decrement button):
4
+ * a primary pointer's press steps at once, and keeps stepping while it is held, until it is
5
+ * released, canceled or leaves the element, or the window loses focus. A mouse press keeps the
6
+ * focus where it is (its `mousedown` default is prevented), so the field's input stays focused. The `click`
7
+ * that ends a pointer press steps no more; any other click steps once. Returns the cleanup.
8
+ */
9
+ function watchAutoRepeat(element, options) {
10
+ const { delay = 400, interval = 60 } = options;
11
+ const doc = element.ownerDocument;
12
+ const view = doc.defaultView;
13
+ let timer;
14
+ let pressed = false;
15
+ let swallowClick = false;
16
+ const stop = () => {
17
+ if (timer !== void 0) {
18
+ view?.clearTimeout(timer);
19
+ view?.clearInterval(timer);
20
+ timer = void 0;
21
+ }
22
+ if (!pressed) return;
23
+ pressed = false;
24
+ view?.setTimeout(() => {
25
+ swallowClick = false;
26
+ });
27
+ doc.removeEventListener("pointerup", stop, true);
28
+ doc.removeEventListener("pointercancel", stop, true);
29
+ element.removeEventListener("pointerleave", stop);
30
+ view?.removeEventListener("blur", stop);
31
+ };
32
+ const onDown = (event) => {
33
+ if (event.button !== 0 || !event.isPrimary) return;
34
+ stop();
35
+ swallowClick = true;
36
+ if (options.onStep(event) === false) {
37
+ view?.setTimeout(() => {
38
+ swallowClick = false;
39
+ }, 1e3);
40
+ return;
41
+ }
42
+ pressed = true;
43
+ doc.addEventListener("pointerup", stop, true);
44
+ doc.addEventListener("pointercancel", stop, true);
45
+ element.addEventListener("pointerleave", stop);
46
+ view?.addEventListener("blur", stop);
47
+ timer = view?.setTimeout(() => {
48
+ timer = view?.setInterval(() => {
49
+ if (options.onStep(event) === false) stop();
50
+ }, interval);
51
+ }, delay);
52
+ };
53
+ const onClick = (event) => {
54
+ if (swallowClick) {
55
+ swallowClick = false;
56
+ return;
57
+ }
58
+ options.onStep(event);
59
+ };
60
+ const onMouseDown = (event) => {
61
+ if (event.button === 0) event.preventDefault();
62
+ };
63
+ const onContextMenu = (event) => {
64
+ if (pressed) event.preventDefault();
65
+ };
66
+ element.addEventListener("pointerdown", onDown);
67
+ element.addEventListener("mousedown", onMouseDown);
68
+ element.addEventListener("click", onClick);
69
+ element.addEventListener("contextmenu", onContextMenu);
70
+ return () => {
71
+ stop();
72
+ element.removeEventListener("pointerdown", onDown);
73
+ element.removeEventListener("mousedown", onMouseDown);
74
+ element.removeEventListener("click", onClick);
75
+ element.removeEventListener("contextmenu", onContextMenu);
76
+ };
77
+ }
78
+ // src/number/number-format.ts
79
+ /** The `Intl.NumberFormat` options a field formats with: `format`, else every decimal kept. */
80
+ function numberFormatOptions(format) {
81
+ return format ?? { maximumFractionDigits: 20 };
82
+ }
83
+ /**
84
+ * `value` as the field writes it (spec/number-field.md): `Intl.NumberFormat` of the locale and
85
+ * the format; `""` for `null` (an empty field).
86
+ */
87
+ function formatNumber(value, options = {}) {
88
+ if (value === null || Number.isNaN(value)) return "";
89
+ return new Intl.NumberFormat(options.locale, numberFormatOptions(options.format)).format(value);
90
+ }
91
+ // src/number/number-parse.ts
92
+ const MINUS = "-−‐‑‒–﹣-";
93
+ const PLUS = "++";
94
+ const PERCENT = "%٪﹪%";
95
+ const BIDI = /[‎‏؜‪-‮⁦-⁩]/g;
96
+ const ARABIC = "٠١٢٣٤٥٦٧٨٩";
97
+ const PERSIAN = "۰۱۲۳۴۵۶۷۸۹";
98
+ function symbolsOf(options) {
99
+ const format = numberFormatOptions(options.format);
100
+ const formatter = new Intl.NumberFormat(options.locale, {
101
+ ...format,
102
+ useGrouping: true
103
+ });
104
+ const { numberingSystem } = formatter.resolvedOptions();
105
+ const digitFormatter = new Intl.NumberFormat(options.locale, {
106
+ numberingSystem,
107
+ useGrouping: false
108
+ });
109
+ const digits = /* @__PURE__ */ new Map();
110
+ for (let digit = 0; digit <= 9; digit += 1) {
111
+ digits.set(String(digit), String(digit));
112
+ digits.set(digitFormatter.format(digit), String(digit));
113
+ digits.set(ARABIC[digit], String(digit));
114
+ digits.set(PERSIAN[digit], String(digit));
115
+ }
116
+ let group = "";
117
+ let decimal = ".";
118
+ const text = /* @__PURE__ */ new Set();
119
+ for (const part of formatter.formatToParts(-12345.6)) if (part.type === "group") group = part.value;
120
+ else if (part.type === "decimal") decimal = part.value;
121
+ else if (part.type === "currency" || part.type === "unit" || part.type === "percentSign" || part.type === "literal") for (const character of part.value) text.add(character);
122
+ const percent = format.style === "percent";
123
+ if (percent) for (const character of PERCENT) text.add(character);
124
+ return {
125
+ digits,
126
+ group,
127
+ decimal,
128
+ text,
129
+ percent,
130
+ accounting: format.currencySign === "accounting"
131
+ };
132
+ }
133
+ /**
134
+ * The text reduced to ASCII digits, `.` and `-` (and whatever else was typed), or `null` when a
135
+ * character is none a number of this locale and format can hold.
136
+ */
137
+ function normalize(text, symbols) {
138
+ let negative = false;
139
+ let result = "";
140
+ const source = text.replace(BIDI, "").replace(/\s/g, "");
141
+ const groupIsSpace = /^\s*$/.test(symbols.group.replace(BIDI, ""));
142
+ for (const character of source) {
143
+ const digit = symbols.digits.get(character);
144
+ if (digit !== void 0) result += digit;
145
+ else if (character === symbols.decimal) result += ".";
146
+ else if (!groupIsSpace && character === symbols.group) {} else if (character === "." || character === ",") result += ".";
147
+ else if (MINUS.includes(character)) negative = !negative;
148
+ else if (PLUS.includes(character)) {} else if (symbols.accounting && (character === "(" || character === ")")) {
149
+ if (character === "(") negative = !negative;
150
+ } else if (symbols.text.has(character)) {} else return null;
151
+ }
152
+ return `${negative ? "-" : ""}${result}`;
153
+ }
154
+ /**
155
+ * Whether `text` holds only what a number of this locale and format is written with (the
156
+ * localized digits, the group and decimal separators, the signs, the format's own text), so a
157
+ * field accepts it while it is typed (spec/number-field.md, "Typing"): `"1.2"`, `"-"` and `""`
158
+ * pass, `"12a"` does not.
159
+ */
160
+ function isNumberText(text, options = {}) {
161
+ return normalize(text, symbolsOf(options)) !== null;
162
+ }
163
+ /**
164
+ * The number `text` writes in this locale and format (spec/number-field.md, "Typing"): the
165
+ * localized digits (Arabic-Indic, ...), the group and decimal separators, any minus sign, the
166
+ * currency, unit and percent text; a percent format reads `25%` as `0.25`. `null` for a text with
167
+ * no digit (empty, or a sign alone), `NaN` for one that is no number (`1.2.3`, `12a`).
168
+ */
169
+ function parseNumber(text, options = {}) {
170
+ const symbols = symbolsOf(options);
171
+ const normalized = normalize(text, symbols);
172
+ if (normalized === null) return NaN;
173
+ if (!/\d/.test(normalized)) return normalized.replace("-", "") === "" ? null : NaN;
174
+ if (!/^-?(\d+\.?\d*|\.\d+)$/.test(normalized)) return NaN;
175
+ const value = Number(normalized);
176
+ if (!symbols.percent) return value === 0 ? 0 : value;
177
+ const decimals = (normalized.split(".")[1] ?? "").length;
178
+ const fraction = Number((value / 100).toFixed(decimals + 2));
179
+ return fraction === 0 ? 0 : fraction;
180
+ }
181
+ // src/number/number-step.ts
182
+ function decimalsOf(value) {
183
+ if (!Number.isFinite(value)) return 0;
184
+ const text = String(value);
185
+ const exponent = /e-(\d+)$/.exec(text);
186
+ if (exponent !== null) return Number(exponent[1]) + (text.split(".")[1]?.split("e")[0] ?? "").length;
187
+ return (text.split(".")[1] ?? "").length;
188
+ }
189
+ /** `value` rounded to `decimals`, without floating-point noise (0.1 + 0.2). */
190
+ function roundTo(value, decimals) {
191
+ const rounded = Number(value.toFixed(Math.min(decimals, 20)));
192
+ return rounded === 0 ? 0 : rounded;
193
+ }
194
+ /** `value` within `[min, max]` (either bound may be missing). */
195
+ function clampNumber(value, min, max) {
196
+ let result = value;
197
+ if (max !== void 0 && result > max) result = max;
198
+ if (min !== void 0 && result < min) result = min;
199
+ return result;
200
+ }
201
+ /**
202
+ * The value one step of `amount` away (negative: down), clamped to `[min, max]`
203
+ * (spec/number-field.md, "Stepping"). An empty field (`null`) starts at 0, clamped, with no step
204
+ * (Base UI). With `snapOnStep`, a value off the grid of `|amount|` goes to the next grid point in
205
+ * the step's direction (`1.5` up by 1 gives `2`, down gives `1`).
206
+ */
207
+ function stepNumber(value, amount, options = {}) {
208
+ const { min, max, snapOnStep = false } = options;
209
+ if (value === null || Number.isNaN(value)) return clampNumber(0, min, max);
210
+ const decimals = Math.max(decimalsOf(value), decimalsOf(amount), decimalsOf(min ?? 0));
211
+ if (!snapOnStep || amount === 0) return clampNumber(roundTo(value + amount, decimals), min, max);
212
+ const grid = Math.abs(amount);
213
+ const base = min ?? 0;
214
+ const index = roundTo((value - base) / grid, 10);
215
+ const target = amount > 0 ? Math.floor(index) + 1 : Math.ceil(index) - 1;
216
+ const gridDecimals = Math.max(decimalsOf(grid), decimalsOf(base));
217
+ return clampNumber(roundTo(base + target * grid, gridDecimals), min, max);
218
+ }
219
+ // src/number/scrub.ts
220
+ /**
221
+ * Scrubbing on `element` (spec/number-field.md, "Scrub"): a primary pointer's press starts it,
222
+ * and every `pixelSensitivity` pixels of movement along `direction` is a step, until the pointer
223
+ * is released. A mouse asks for the pointer lock (the movement then never meets the screen's
224
+ * edges, and `onCursor` follows a virtual cursor); a denied lock only leaves the real cursor.
225
+ * The press's default is prevented, so no text is selected. Returns the cleanup.
226
+ */
227
+ function watchScrub(element, options) {
228
+ const { direction = "horizontal", pixelSensitivity = 2 } = options;
229
+ const doc = element.ownerDocument;
230
+ const view = doc.defaultView;
231
+ let active = null;
232
+ let last = {
233
+ x: 0,
234
+ y: 0
235
+ };
236
+ let cursor = {
237
+ x: 0,
238
+ y: 0
239
+ };
240
+ let pending = 0;
241
+ const locked = () => doc.pointerLockElement === element;
242
+ const end = (event) => {
243
+ if (active === null || event.pointerId !== active.pointerId) return;
244
+ active = null;
245
+ doc.removeEventListener("pointermove", onMove, true);
246
+ doc.removeEventListener("pointerup", end, true);
247
+ doc.removeEventListener("pointercancel", end, true);
248
+ if (locked()) doc.exitPointerLock();
249
+ options.onCursor?.(null);
250
+ options.onEnd(event);
251
+ };
252
+ const onMove = (event) => {
253
+ if (active === null || event.pointerId !== active.pointerId) return;
254
+ const isLocked = locked();
255
+ const dx = isLocked ? event.movementX : event.clientX - last.x;
256
+ const dy = isLocked ? event.movementY : event.clientY - last.y;
257
+ last = {
258
+ x: event.clientX,
259
+ y: event.clientY
260
+ };
261
+ if (isLocked && view !== null) {
262
+ const width = view.innerWidth;
263
+ const height = view.innerHeight;
264
+ cursor = {
265
+ x: ((cursor.x + dx) % width + width) % width,
266
+ y: ((cursor.y + dy) % height + height) % height
267
+ };
268
+ options.onCursor?.(cursor);
269
+ }
270
+ pending += direction === "vertical" ? -dy : dx;
271
+ const steps = Math.trunc(pending / pixelSensitivity);
272
+ if (steps !== 0) {
273
+ pending -= steps * pixelSensitivity;
274
+ options.onScrub(steps, event);
275
+ }
276
+ };
277
+ const onDown = (event) => {
278
+ if (event.button !== 0 || !event.isPrimary || active !== null) return;
279
+ if (options.onStart(event) === false) return;
280
+ event.preventDefault();
281
+ active = { pointerId: event.pointerId };
282
+ last = {
283
+ x: event.clientX,
284
+ y: event.clientY
285
+ };
286
+ cursor = { ...last };
287
+ pending = 0;
288
+ doc.addEventListener("pointermove", onMove, true);
289
+ doc.addEventListener("pointerup", end, true);
290
+ doc.addEventListener("pointercancel", end, true);
291
+ if (event.pointerType === "mouse") try {
292
+ (element.requestPointerLock?.())?.then(() => {
293
+ if (!locked()) return;
294
+ if (active === null) doc.exitPointerLock();
295
+ else options.onCursor?.(cursor);
296
+ }, () => {});
297
+ } catch {}
298
+ };
299
+ const onLockChange = () => {
300
+ if (active === null && locked()) doc.exitPointerLock();
301
+ };
302
+ element.addEventListener("pointerdown", onDown);
303
+ doc.addEventListener("pointerlockchange", onLockChange);
304
+ return () => {
305
+ element.removeEventListener("pointerdown", onDown);
306
+ doc.removeEventListener("pointerlockchange", onLockChange);
307
+ doc.removeEventListener("pointermove", onMove, true);
308
+ doc.removeEventListener("pointerup", end, true);
309
+ doc.removeEventListener("pointercancel", end, true);
310
+ if (active !== null && locked()) doc.exitPointerLock();
311
+ active = null;
312
+ };
313
+ }
314
+ export { parseNumber as a, watchAutoRepeat as c, isNumberText as i, clampNumber as n, formatNumber as o, stepNumber as r, numberFormatOptions as s, watchScrub as t };
315
+
316
+ //# sourceMappingURL=number-BFUio97d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-BFUio97d.js","names":[],"sources":["../src/number/auto-repeat.ts","../src/number/number-format.ts","../src/number/number-parse.ts","../src/number/number-step.ts","../src/number/scrub.ts"],"sourcesContent":["export interface AutoRepeatOptions {\n /**\n * One step: at the press, then again every `interval` once the press lasted `delay`; a click\n * that no pointer press started (the keyboard, assistive technology) steps once. Return\n * `false` to stop the repeat (a bound reached).\n */\n onStep: (event: Event) => boolean | undefined;\n /** How long a press lasts before the repeat starts, in ms (default 400, Base UI). */\n delay?: number;\n /** The time between two repeated steps, in ms (default 60, Base UI). */\n interval?: number;\n}\n\n/**\n * Press and hold on `element` (spec/number-field.md, \"Pointer\": an Increment or Decrement button):\n * a primary pointer's press steps at once, and keeps stepping while it is held, until it is\n * released, canceled or leaves the element, or the window loses focus. A mouse press keeps the\n * focus where it is (its `mousedown` default is prevented), so the field's input stays focused. The `click`\n * that ends a pointer press steps no more; any other click steps once. Returns the cleanup.\n */\nexport function watchAutoRepeat(\n element: Element,\n options: AutoRepeatOptions,\n): () => void {\n const { delay = 400, interval = 60 } = options;\n const doc = element.ownerDocument;\n const view = doc.defaultView;\n let timer: number | undefined;\n let pressed = false;\n // the click that follows a pointer press, already stepped at its pointerdown\n let swallowClick = false;\n\n const stop = () => {\n if (timer !== undefined) {\n view?.clearTimeout(timer);\n view?.clearInterval(timer);\n timer = undefined;\n }\n if (!pressed) {\n return;\n }\n pressed = false;\n // the click a release sends comes before this task ends; a press that sends none\n // (released outside, a long touch, a button disabled at its bound) swallows no later\n // click\n view?.setTimeout(() => {\n swallowClick = false;\n });\n doc.removeEventListener(\"pointerup\", stop, true);\n doc.removeEventListener(\"pointercancel\", stop, true);\n element.removeEventListener(\"pointerleave\", stop);\n view?.removeEventListener(\"blur\", stop);\n };\n const onDown = (event: PointerEvent) => {\n if (event.button !== 0 || !event.isPrimary) {\n return;\n }\n stop();\n swallowClick = true;\n if (options.onStep(event) === false) {\n view?.setTimeout(() => {\n swallowClick = false;\n }, 1000);\n return;\n }\n pressed = true;\n doc.addEventListener(\"pointerup\", stop, true);\n doc.addEventListener(\"pointercancel\", stop, true);\n element.addEventListener(\"pointerleave\", stop);\n view?.addEventListener(\"blur\", stop);\n timer = view?.setTimeout(() => {\n timer = view?.setInterval(() => {\n if (options.onStep(event) === false) {\n stop();\n }\n }, interval);\n }, delay);\n };\n const onClick = (event: Event) => {\n if (swallowClick) {\n swallowClick = false;\n return;\n }\n options.onStep(event);\n };\n // a mouse press moves no focus: the field's input keeps it (APG: focus stays on the text\n // field)\n const onMouseDown = (event: MouseEvent) => {\n if (event.button === 0) {\n event.preventDefault();\n }\n };\n // a held touch opens no context menu\n const onContextMenu = (event: Event) => {\n if (pressed) {\n event.preventDefault();\n }\n };\n element.addEventListener(\"pointerdown\", onDown as EventListener);\n element.addEventListener(\"mousedown\", onMouseDown as EventListener);\n element.addEventListener(\"click\", onClick);\n element.addEventListener(\"contextmenu\", onContextMenu);\n return () => {\n stop();\n element.removeEventListener(\"pointerdown\", onDown as EventListener);\n element.removeEventListener(\"mousedown\", onMouseDown as EventListener);\n element.removeEventListener(\"click\", onClick);\n element.removeEventListener(\"contextmenu\", onContextMenu);\n };\n}\n","/** How a number field writes and reads its value (spec/number-field.md, \"API\"). */\nexport interface NumberFormatOptions {\n /** The locale (BCP 47; default: the runtime's). */\n locale?: string | undefined;\n /** `Intl.NumberFormat` options; without them, the plain number with every decimal it has. */\n format?: Intl.NumberFormatOptions | undefined;\n}\n\n/** The `Intl.NumberFormat` options a field formats with: `format`, else every decimal kept. */\nexport function numberFormatOptions(\n format: Intl.NumberFormatOptions | undefined,\n): Intl.NumberFormatOptions {\n return format ?? { maximumFractionDigits: 20 };\n}\n\n/**\n * `value` as the field writes it (spec/number-field.md): `Intl.NumberFormat` of the locale and\n * the format; `\"\"` for `null` (an empty field).\n */\nexport function formatNumber(\n value: number | null,\n options: NumberFormatOptions = {},\n): string {\n if (value === null || Number.isNaN(value)) {\n return \"\";\n }\n return new Intl.NumberFormat(\n options.locale,\n numberFormatOptions(options.format),\n ).format(value);\n}\n","import {\n type NumberFormatOptions,\n numberFormatOptions,\n} from \"./number-format.ts\";\n\n/** The text a locale and a format write numbers with (spec/number-field.md, \"Typing\"). */\ninterface NumberSymbols {\n /** Each localized digit, mapped to its ASCII digit. */\n digits: Map<string, string>;\n group: string;\n decimal: string;\n /** The characters of the format's other text: currency, unit, percent sign, literals. */\n text: Set<string>;\n percent: boolean;\n accounting: boolean;\n}\n\n// the minus signs and plus signs a user may type, whatever the locale writes\nconst MINUS = \"-−‐‑‒–﹣-\";\nconst PLUS = \"++\";\n// the percent signs a percent field accepts beside the locale's\nconst PERCENT = \"%٪﹪%\";\n// bidirectional marks, which some locales write around a sign (ar-EG: U+061C)\nconst BIDI = /[‎‏؜‪-‮⁦-⁩]/g;\n// the Arabic-Indic and Extended Arabic-Indic digits, read in every locale (as the ASCII ones)\nconst ARABIC = \"٠١٢٣٤٥٦٧٨٩\";\nconst PERSIAN = \"۰۱۲۳۴۵۶۷۸۹\";\n\nfunction symbolsOf(options: NumberFormatOptions): NumberSymbols {\n const format = numberFormatOptions(options.format);\n const formatter = new Intl.NumberFormat(options.locale, {\n ...format,\n useGrouping: true,\n });\n const { numberingSystem } = formatter.resolvedOptions();\n const digitFormatter = new Intl.NumberFormat(options.locale, {\n numberingSystem,\n useGrouping: false,\n });\n const digits = new Map<string, string>();\n for (let digit = 0; digit <= 9; digit += 1) {\n digits.set(String(digit), String(digit));\n digits.set(digitFormatter.format(digit), String(digit));\n digits.set(ARABIC[digit] as string, String(digit));\n digits.set(PERSIAN[digit] as string, String(digit));\n }\n let group = \"\";\n let decimal = \".\";\n const text = new Set<string>();\n for (const part of formatter.formatToParts(-12345.6)) {\n if (part.type === \"group\") {\n group = part.value;\n } else if (part.type === \"decimal\") {\n decimal = part.value;\n } else if (\n part.type === \"currency\" ||\n part.type === \"unit\" ||\n part.type === \"percentSign\" ||\n part.type === \"literal\"\n ) {\n for (const character of part.value) {\n text.add(character);\n }\n }\n }\n const percent = format.style === \"percent\";\n if (percent) {\n for (const character of PERCENT) {\n text.add(character);\n }\n }\n return {\n digits,\n group,\n decimal,\n text,\n percent,\n accounting: format.currencySign === \"accounting\",\n };\n}\n\n/**\n * The text reduced to ASCII digits, `.` and `-` (and whatever else was typed), or `null` when a\n * character is none a number of this locale and format can hold.\n */\nfunction normalize(text: string, symbols: NumberSymbols): string | null {\n let negative = false;\n let result = \"\";\n const source = text.replace(BIDI, \"\").replace(/\\s/g, \"\");\n const groupIsSpace = /^\\s*$/.test(symbols.group.replace(BIDI, \"\"));\n for (const character of source) {\n const digit = symbols.digits.get(character);\n if (digit !== undefined) {\n result += digit;\n } else if (character === symbols.decimal) {\n result += \".\";\n } else if (!groupIsSpace && character === symbols.group) {\n // a grouping separator carries no value\n } else if (character === \".\" || character === \",\") {\n // the other separator, where the locale's group is not it: a decimal point (`1.5` in\n // ar-EG, whose own is U+066B)\n result += \".\";\n } else if (MINUS.includes(character)) {\n negative = !negative;\n } else if (PLUS.includes(character)) {\n // a plus sign changes nothing\n } else if (\n symbols.accounting &&\n (character === \"(\" || character === \")\")\n ) {\n if (character === \"(\") {\n negative = !negative;\n }\n } else if (symbols.text.has(character)) {\n // the currency, the unit, the percent sign: text of the format, not of the value\n } else {\n return null;\n }\n }\n return `${negative ? \"-\" : \"\"}${result}`;\n}\n\n/**\n * Whether `text` holds only what a number of this locale and format is written with (the\n * localized digits, the group and decimal separators, the signs, the format's own text), so a\n * field accepts it while it is typed (spec/number-field.md, \"Typing\"): `\"1.2\"`, `\"-\"` and `\"\"`\n * pass, `\"12a\"` does not.\n */\nexport function isNumberText(\n text: string,\n options: NumberFormatOptions = {},\n): boolean {\n return normalize(text, symbolsOf(options)) !== null;\n}\n\n/**\n * The number `text` writes in this locale and format (spec/number-field.md, \"Typing\"): the\n * localized digits (Arabic-Indic, ...), the group and decimal separators, any minus sign, the\n * currency, unit and percent text; a percent format reads `25%` as `0.25`. `null` for a text with\n * no digit (empty, or a sign alone), `NaN` for one that is no number (`1.2.3`, `12a`).\n */\nexport function parseNumber(\n text: string,\n options: NumberFormatOptions = {},\n): number | null {\n const symbols = symbolsOf(options);\n const normalized = normalize(text, symbols);\n if (normalized === null) {\n return Number.NaN;\n }\n if (!/\\d/.test(normalized)) {\n return normalized.replace(\"-\", \"\") === \"\" ? null : Number.NaN;\n }\n if (!/^-?(\\d+\\.?\\d*|\\.\\d+)$/.test(normalized)) {\n return Number.NaN;\n }\n const value = Number(normalized);\n if (!symbols.percent) {\n return value === 0 ? 0 : value;\n }\n // 25% is 0.25: divided by 100 with the decimals it had, so no floating-point noise is added\n const decimals = (normalized.split(\".\")[1] ?? \"\").length;\n const fraction = Number((value / 100).toFixed(decimals + 2));\n return fraction === 0 ? 0 : fraction;\n}\n","/** The bounds and grid a number field steps within (spec/number-field.md, \"API\"). */\nexport interface NumberStepOptions {\n /** The lowest value; none when not given. */\n min?: number | undefined;\n /** The highest value; none when not given. */\n max?: number | undefined;\n /** Step to the grid of `|amount|` (counted from `min`, else from 0) instead of by `amount`. */\n snapOnStep?: boolean | undefined;\n}\n\nfunction decimalsOf(value: number): number {\n if (!Number.isFinite(value)) {\n return 0;\n }\n const text = String(value);\n const exponent = /e-(\\d+)$/.exec(text);\n if (exponent !== null) {\n return (\n Number(exponent[1]) +\n (text.split(\".\")[1]?.split(\"e\")[0] ?? \"\").length\n );\n }\n return (text.split(\".\")[1] ?? \"\").length;\n}\n\n/** `value` rounded to `decimals`, without floating-point noise (0.1 + 0.2). */\nfunction roundTo(value: number, decimals: number): number {\n const rounded = Number(value.toFixed(Math.min(decimals, 20)));\n return rounded === 0 ? 0 : rounded;\n}\n\n/** `value` within `[min, max]` (either bound may be missing). */\nexport function clampNumber(\n value: number,\n min: number | undefined,\n max: number | undefined,\n): number {\n let result = value;\n if (max !== undefined && result > max) {\n result = max;\n }\n if (min !== undefined && result < min) {\n result = min;\n }\n return result;\n}\n\n/**\n * The value one step of `amount` away (negative: down), clamped to `[min, max]`\n * (spec/number-field.md, \"Stepping\"). An empty field (`null`) starts at 0, clamped, with no step\n * (Base UI). With `snapOnStep`, a value off the grid of `|amount|` goes to the next grid point in\n * the step's direction (`1.5` up by 1 gives `2`, down gives `1`).\n */\nexport function stepNumber(\n value: number | null,\n amount: number,\n options: NumberStepOptions = {},\n): number {\n const { min, max, snapOnStep = false } = options;\n if (value === null || Number.isNaN(value)) {\n return clampNumber(0, min, max);\n }\n const decimals = Math.max(\n decimalsOf(value),\n decimalsOf(amount),\n decimalsOf(min ?? 0),\n );\n if (!snapOnStep || amount === 0) {\n return clampNumber(roundTo(value + amount, decimals), min, max);\n }\n const grid = Math.abs(amount);\n const base = min ?? 0;\n // the grid index, without the noise of a division (2.9999999 is 3)\n const index = roundTo((value - base) / grid, 10);\n const target = amount > 0 ? Math.floor(index) + 1 : Math.ceil(index) - 1;\n const gridDecimals = Math.max(decimalsOf(grid), decimalsOf(base));\n return clampNumber(roundTo(base + target * grid, gridDecimals), min, max);\n}\n","/** A point in the viewport, in CSS pixels. */\nexport interface ScrubPoint {\n x: number;\n y: number;\n}\n\nexport interface ScrubOptions {\n /** The axis the pointer scrubs along (default `\"horizontal\"`). */\n direction?: \"horizontal\" | \"vertical\";\n /** The distance one step takes, in px (default 2, Base UI). */\n pixelSensitivity?: number;\n /** A press starts a scrub unless this returns `false` (a disabled or read-only field). */\n onStart: (event: PointerEvent) => boolean | undefined;\n /**\n * The pointer moved by `steps` sensitivities along the axis: right or up is positive. Called\n * once per move that crosses at least one.\n */\n onScrub: (steps: number, event: PointerEvent) => void;\n /** The scrub ended: the pointer was released or canceled. */\n onEnd: (event: PointerEvent) => void;\n /**\n * Where the virtual cursor is while the pointer is locked (the real one is hidden), wrapped\n * around the viewport's edges; `null` once it is unlocked or the scrub ended.\n */\n onCursor?: (point: ScrubPoint | null) => void;\n}\n\n/**\n * Scrubbing on `element` (spec/number-field.md, \"Scrub\"): a primary pointer's press starts it,\n * and every `pixelSensitivity` pixels of movement along `direction` is a step, until the pointer\n * is released. A mouse asks for the pointer lock (the movement then never meets the screen's\n * edges, and `onCursor` follows a virtual cursor); a denied lock only leaves the real cursor.\n * The press's default is prevented, so no text is selected. Returns the cleanup.\n */\nexport function watchScrub(\n element: Element,\n options: ScrubOptions,\n): () => void {\n const { direction = \"horizontal\", pixelSensitivity = 2 } = options;\n const doc = element.ownerDocument;\n const view = doc.defaultView;\n let active: { pointerId: number } | null = null;\n let last: ScrubPoint = { x: 0, y: 0 };\n let cursor: ScrubPoint = { x: 0, y: 0 };\n let pending = 0;\n\n const locked = () => doc.pointerLockElement === element;\n const end = (event: PointerEvent) => {\n if (active === null || event.pointerId !== active.pointerId) {\n return;\n }\n active = null;\n doc.removeEventListener(\"pointermove\", onMove, true);\n doc.removeEventListener(\"pointerup\", end, true);\n doc.removeEventListener(\"pointercancel\", end, true);\n if (locked()) {\n doc.exitPointerLock();\n }\n options.onCursor?.(null);\n options.onEnd(event);\n };\n const onMove = (event: PointerEvent) => {\n if (active === null || event.pointerId !== active.pointerId) {\n return;\n }\n // locked, the pointer stays where it was: its movement is the event's own\n const isLocked = locked();\n const dx = isLocked ? event.movementX : event.clientX - last.x;\n const dy = isLocked ? event.movementY : event.clientY - last.y;\n last = { x: event.clientX, y: event.clientY };\n if (isLocked && view !== null) {\n const width = view.innerWidth;\n const height = view.innerHeight;\n cursor = {\n x: (((cursor.x + dx) % width) + width) % width,\n y: (((cursor.y + dy) % height) + height) % height,\n };\n options.onCursor?.(cursor);\n }\n pending += direction === \"vertical\" ? -dy : dx;\n const steps = Math.trunc(pending / pixelSensitivity);\n if (steps !== 0) {\n pending -= steps * pixelSensitivity;\n options.onScrub(steps, event);\n }\n };\n const onDown = (event: PointerEvent) => {\n if (event.button !== 0 || !event.isPrimary || active !== null) {\n return;\n }\n if (options.onStart(event) === false) {\n return;\n }\n event.preventDefault();\n active = { pointerId: event.pointerId };\n last = { x: event.clientX, y: event.clientY };\n cursor = { ...last };\n pending = 0;\n doc.addEventListener(\"pointermove\", onMove, true);\n doc.addEventListener(\"pointerup\", end, true);\n doc.addEventListener(\"pointercancel\", end, true);\n if (event.pointerType === \"mouse\") {\n try {\n const request = (\n element as Element & {\n requestPointerLock?: () => Promise<void> | undefined;\n }\n ).requestPointerLock?.();\n request?.then(\n () => {\n if (!locked()) {\n return;\n }\n if (active === null) {\n // granted after a quick click ended the scrub: never kept\n doc.exitPointerLock();\n } else {\n options.onCursor?.(cursor);\n }\n },\n () => {},\n );\n } catch {\n // a denied lock leaves the real cursor\n }\n }\n };\n // a lock granted with no promise (Firefox) after the scrub ended is released too\n const onLockChange = () => {\n if (active === null && locked()) {\n doc.exitPointerLock();\n }\n };\n element.addEventListener(\"pointerdown\", onDown as EventListener);\n doc.addEventListener(\"pointerlockchange\", onLockChange);\n return () => {\n element.removeEventListener(\"pointerdown\", onDown as EventListener);\n doc.removeEventListener(\"pointerlockchange\", onLockChange);\n doc.removeEventListener(\"pointermove\", onMove, true);\n doc.removeEventListener(\"pointerup\", end, true);\n doc.removeEventListener(\"pointercancel\", end, true);\n if (active !== null && locked()) {\n doc.exitPointerLock();\n }\n active = null;\n };\n}\n"],"mappings":";;;;;;;;AAoBA,SAAgB,gBACZ,SACA,SACU;CACV,MAAM,EAAE,QAAQ,KAAK,WAAW,OAAO;CACvC,MAAM,MAAM,QAAQ;CACpB,MAAM,OAAO,IAAI;CACjB,IAAI;CACJ,IAAI,UAAU;CAEd,IAAI,eAAe;CAEnB,MAAM,aAAa;EACf,IAAI,UAAU,KAAA,GAAW;GACrB,MAAM,aAAa,KAAK;GACxB,MAAM,cAAc,KAAK;GACzB,QAAQ,KAAA;EACZ;EACA,IAAI,CAAC,SACD;EAEJ,UAAU;EAIV,MAAM,iBAAiB;GACnB,eAAe;EACnB,CAAC;EACD,IAAI,oBAAoB,aAAa,MAAM,IAAI;EAC/C,IAAI,oBAAoB,iBAAiB,MAAM,IAAI;EACnD,QAAQ,oBAAoB,gBAAgB,IAAI;EAChD,MAAM,oBAAoB,QAAQ,IAAI;CAC1C;CACA,MAAM,UAAU,UAAwB;EACpC,IAAI,MAAM,WAAW,KAAK,CAAC,MAAM,WAC7B;EAEJ,KAAK;EACL,eAAe;EACf,IAAI,QAAQ,OAAO,KAAK,MAAM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,OAAO,GAC1B,IAAI,gBAAgB;EAExB,SAAS;CACb;AACJ"}
@@ -0,0 +1,2 @@
1
+ import { a as clampNumber, c as parseNumber, d as numberFormatOptions, f as AutoRepeatOptions, i as NumberStepOptions, l as NumberFormatOptions, n as ScrubPoint, o as stepNumber, p as watchAutoRepeat, r as watchScrub, s as isNumberText, t as ScrubOptions, u as formatNumber } from "./index-CGThV_Md.js";
2
+ export { type AutoRepeatOptions, type NumberFormatOptions, type NumberStepOptions, type ScrubOptions, type ScrubPoint, clampNumber, formatNumber, isNumberText, numberFormatOptions, parseNumber, stepNumber, watchAutoRepeat, watchScrub };
package/dist/number.js ADDED
@@ -0,0 +1 @@
1
+ export { n as clampNumber, o as formatNumber, i as isNumberText, s as numberFormatOptions, a as parseNumber, r as stepNumber, c as watchAutoRepeat, t as watchScrub } from "./number-BFUio97d.js";
@@ -0,0 +1,78 @@
1
+ import { n as watchFocusOutside, t as pushLayer } from "./layer-stack-BEtzaFC1.js";
2
+ // src/overlay/overlay-session.ts
3
+ /**
4
+ * The wiring every overlay repeats (docs/reports/checkpoint.md, boundary pressure 2): its layer
5
+ * (Escape, outside presses), the non-modal focus-out watch, and the focus return by close reason.
6
+ * It holds no component state: the framework passes what it knows through the callbacks.
7
+ */
8
+ function openOverlaySession(doc, options) {
9
+ const view = doc.defaultView;
10
+ let pressing = false;
11
+ let afterPress = null;
12
+ const onPressEnd = () => {
13
+ doc.removeEventListener("pointerup", onPressEnd, true);
14
+ doc.removeEventListener("pointercancel", onPressEnd, true);
15
+ pressing = false;
16
+ const pending = afterPress;
17
+ afterPress = null;
18
+ if (pending) view?.setTimeout(pending, 0);
19
+ };
20
+ const layer = pushLayer(doc, {
21
+ elements: options.elements,
22
+ ignore: options.ignore,
23
+ backdrops: options.backdrops,
24
+ modal: options.modal,
25
+ owner: options.owner ?? options.ignore,
26
+ onEscape: (event) => options.dismiss("escape-key", event),
27
+ onOutsidePress: (event) => {
28
+ if (!pressing) {
29
+ pressing = true;
30
+ doc.addEventListener("pointerup", onPressEnd, true);
31
+ doc.addEventListener("pointercancel", onPressEnd, true);
32
+ }
33
+ options.dismiss("outside-press", event);
34
+ },
35
+ onParentClose: () => options.dismiss("none", void 0)
36
+ });
37
+ const focusOut = options.focusOut;
38
+ const stopWatching = focusOut ? watchFocusOutside(doc, () => [
39
+ ...options.elements(),
40
+ ...focusOut(),
41
+ ...layer.elementsAbove()
42
+ ], (event) => {
43
+ if (!pressing) options.dismiss("focus-out", event);
44
+ }) : () => {};
45
+ let ended = false;
46
+ return {
47
+ elementsAbove: () => layer.elementsAbove(),
48
+ end() {
49
+ if (ended) return;
50
+ ended = true;
51
+ layer.remove();
52
+ stopWatching();
53
+ const returnFocus = options.returnFocus;
54
+ if (!returnFocus) return;
55
+ const reason = returnFocus.reason() ?? "";
56
+ if ((typeof returnFocus.whenUnfocused === "function" ? returnFocus.whenUnfocused() : returnFocus.whenUnfocused)?.has(reason)) {
57
+ const focusIfUnfocused = () => {
58
+ const active = doc.activeElement;
59
+ const inside = active !== null && options.elements().some((element) => element?.contains(active));
60
+ if (active === null || active === doc.body || inside) {
61
+ const target = returnFocus.to();
62
+ if (target && target.isConnected === true) target.focus({ preventScroll: true });
63
+ }
64
+ };
65
+ if (pressing) afterPress = focusIfUnfocused;
66
+ else view?.setTimeout(focusIfUnfocused, 0);
67
+ return;
68
+ }
69
+ if (!returnFocus.when || returnFocus.when.has(reason)) {
70
+ const target = returnFocus.to();
71
+ if (target) target.focus({ preventScroll: true });
72
+ }
73
+ }
74
+ };
75
+ }
76
+ export { openOverlaySession as t };
77
+
78
+ //# sourceMappingURL=overlay-BwPyiM3T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlay-BwPyiM3T.js","names":[],"sources":["../src/overlay/overlay-session.ts"],"sourcesContent":["import { watchFocusOutside } from \"../layers/focus-outside.ts\";\nimport { pushLayer } from \"../layers/layer-stack.ts\";\n\n/**\n * How an overlay asks to be dismissed (spec/README.md, \"Change details\"): `none` when the overlay\n * it was opened from closed (spec/README.md, \"The nested overlay tree\").\n */\nexport type DismissReason =\n | \"escape-key\"\n | \"outside-press\"\n | \"focus-out\"\n | \"none\";\n\n/** The DOM event that dismissed it: `undefined` when an ancestor overlay closed. */\nexport type DismissEvent =\n | KeyboardEvent\n | PointerEvent\n | FocusEvent\n | undefined;\n\ntype Elements = () => readonly (Element | null | undefined)[];\n\nexport interface OverlaySessionOptions {\n /** The overlay's own elements (its positioner or popup). */\n elements: Elements;\n /** Elements a press on does not dismiss it (its trigger, which toggles it itself). */\n ignore?: Elements;\n /**\n * The elements it was opened from (its triggers), which make it a child of the overlay that\n * contains them (default: `ignore`).\n */\n owner?: Elements;\n /**\n * Elements that cover the page under it (a dialog's backdrop and viewport): a press on one is\n * outside this overlay but inside its parent.\n */\n backdrops?: Elements;\n /**\n * A modal overlay (a dialog): a press outside it and its descendants is outside it but inside\n * its parent, so the overlays it was opened from stay open (`pushLayer`'s `modal`).\n */\n modal?: boolean;\n /**\n * Called when Escape, an outside press, (with `focusOut`) focus leaving, or the close of the\n * overlay it was opened from (`none`) dismisses it, with the event that did.\n */\n dismiss: (reason: DismissReason, event?: DismissEvent) => void;\n /**\n * Non-modal overlays: dismiss when focus moves outside the overlay, its child layers and these\n * elements (usually the trigger).\n */\n focusOut?: Elements;\n /**\n * Where focus goes when the session ends: `to()` when `reason()` (the reason the overlay closed)\n * is one of `when` (or always, without `when`); nowhere otherwise. `to()` may return `false`\n * for \"do not move focus\".\n */\n returnFocus?: {\n when?: ReadonlySet<string>;\n /**\n * Reasons that return focus only once the press that dismissed the overlay has ended, and\n * only when it left focus nowhere (on the body) or inside the closing overlay (which is\n * leaving, with its exit animation): a press on a focusable element keeps the focus it\n * gave (spec/popover.md, \"Focus\": Base UI's focus after an outside press). A getter is\n * read when the session ends (a menu's `modal` may change while it is open).\n */\n whenUnfocused?:\n | ReadonlySet<string>\n | (() => ReadonlySet<string> | undefined);\n reason: () => string | null;\n to: () => HTMLElement | null | false;\n };\n}\n\nexport interface OverlaySession {\n /** The elements of the overlays opened from this one (its descendant layers). */\n elementsAbove: () => Element[];\n /** Ends the session: removes the layer and the focus watch, then returns focus if due. */\n end: () => void;\n}\n\n/**\n * The wiring every overlay repeats (docs/reports/checkpoint.md, boundary pressure 2): its layer\n * (Escape, outside presses), the non-modal focus-out watch, and the focus return by close reason.\n * It holds no component state: the framework passes what it knows through the callbacks.\n */\nexport function openOverlaySession(\n doc: Document,\n options: OverlaySessionOptions,\n): OverlaySession {\n const view = doc.defaultView;\n // the outside press in progress, if any: its end runs `afterPress` (once focus has settled)\n let pressing = false;\n let afterPress: (() => void) | null = null;\n const onPressEnd = () => {\n doc.removeEventListener(\"pointerup\", onPressEnd, true);\n doc.removeEventListener(\"pointercancel\", onPressEnd, true);\n pressing = false;\n const pending = afterPress;\n afterPress = null;\n if (pending) {\n // a touch press focuses its target on the compatibility mousedown, after pointerup\n view?.setTimeout(pending, 0);\n }\n };\n const layer = pushLayer(doc, {\n elements: options.elements,\n ignore: options.ignore,\n backdrops: options.backdrops,\n modal: options.modal,\n owner: options.owner ?? options.ignore,\n onEscape: (event) => options.dismiss(\"escape-key\", event),\n onOutsidePress: (event) => {\n if (!pressing) {\n pressing = true;\n doc.addEventListener(\"pointerup\", onPressEnd, true);\n doc.addEventListener(\"pointercancel\", onPressEnd, true);\n }\n options.dismiss(\"outside-press\", event);\n },\n // closing an overlay closes the overlays opened from it\n onParentClose: () => options.dismiss(\"none\", undefined),\n });\n const focusOut = options.focusOut;\n const stopWatching = focusOut\n ? watchFocusOutside(\n doc,\n () => [\n ...options.elements(),\n ...focusOut(),\n ...layer.elementsAbove(),\n ],\n (event) => {\n // the outside press that already dismissed the overlay moved the focus\n if (!pressing) {\n options.dismiss(\"focus-out\", event);\n }\n },\n )\n : () => {};\n let ended = false;\n return {\n elementsAbove: () => layer.elementsAbove(),\n end() {\n if (ended) {\n return;\n }\n ended = true;\n layer.remove();\n stopWatching();\n const returnFocus = options.returnFocus;\n if (!returnFocus) {\n return;\n }\n const reason = returnFocus.reason() ?? \"\";\n const unfocused =\n typeof returnFocus.whenUnfocused === \"function\"\n ? returnFocus.whenUnfocused()\n : returnFocus.whenUnfocused;\n if (unfocused?.has(reason)) {\n const focusIfUnfocused = () => {\n const active = doc.activeElement;\n const inside =\n active !== null &&\n options\n .elements()\n .some((element) => element?.contains(active));\n if (active === null || active === doc.body || inside) {\n const target = returnFocus.to();\n if (target && target.isConnected === true) {\n target.focus({ preventScroll: true });\n }\n }\n };\n if (pressing) {\n afterPress = focusIfUnfocused;\n } else {\n view?.setTimeout(focusIfUnfocused, 0);\n }\n return;\n }\n if (!returnFocus.when || returnFocus.when.has(reason)) {\n const target = returnFocus.to();\n if (target) {\n target.focus({ preventScroll: true });\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;;AAsFA,SAAgB,mBACZ,KACA,SACc;CACd,MAAM,OAAO,IAAI;CAEjB,IAAI,WAAW;CACf,IAAI,aAAkC;CACtC,MAAM,mBAAmB;EACrB,IAAI,oBAAoB,aAAa,YAAY,IAAI;EACrD,IAAI,oBAAoB,iBAAiB,YAAY,IAAI;EACzD,WAAW;EACX,MAAM,UAAU;EAChB,aAAa;EACb,IAAI,SAEA,MAAM,WAAW,SAAS,CAAC;CAEnC;CACA,MAAM,QAAQ,UAAU,KAAK;EACzB,UAAU,QAAQ;EAClB,QAAQ,QAAQ;EAChB,WAAW,QAAQ;EACnB,OAAO,QAAQ;EACf,OAAO,QAAQ,SAAS,QAAQ;EAChC,WAAW,UAAU,QAAQ,QAAQ,cAAc,KAAK;EACxD,iBAAiB,UAAU;GACvB,IAAI,CAAC,UAAU;IACX,WAAW;IACX,IAAI,iBAAiB,aAAa,YAAY,IAAI;IAClD,IAAI,iBAAiB,iBAAiB,YAAY,IAAI;GAC1D;GACA,QAAQ,QAAQ,iBAAiB,KAAK;EAC1C;EAEA,qBAAqB,QAAQ,QAAQ,QAAQ,KAAA,CAAS;CAC1D,CAAC;CACD,MAAM,WAAW,QAAQ;CACzB,MAAM,eAAe,WACf,kBACI,WACM;EACF,GAAG,QAAQ,SAAS;EACpB,GAAG,SAAS;EACZ,GAAG,MAAM,cAAc;CAC3B,IACC,UAAU;EAEP,IAAI,CAAC,UACD,QAAQ,QAAQ,aAAa,KAAK;CAE1C,CACJ,UACM,CAAC;CACb,IAAI,QAAQ;CACZ,OAAO;EACH,qBAAqB,MAAM,cAAc;EACzC,MAAM;GACF,IAAI,OACA;GAEJ,QAAQ;GACR,MAAM,OAAO;GACb,aAAa;GACb,MAAM,cAAc,QAAQ;GAC5B,IAAI,CAAC,aACD;GAEJ,MAAM,SAAS,YAAY,OAAO,KAAK;GAKvC,KAHI,OAAO,YAAY,kBAAkB,aAC/B,YAAY,cAAc,IAC1B,YAAY,cAAA,EACP,IAAI,MAAM,GAAG;IACxB,MAAM,yBAAyB;KAC3B,MAAM,SAAS,IAAI;KACnB,MAAM,SACF,WAAW,QACX,QACK,SAAS,CAAC,CACV,MAAM,YAAY,SAAS,SAAS,MAAM,CAAC;KACpD,IAAI,WAAW,QAAQ,WAAW,IAAI,QAAQ,QAAQ;MAClD,MAAM,SAAS,YAAY,GAAG;MAC9B,IAAI,UAAU,OAAO,gBAAgB,MACjC,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;KAE5C;IACJ;IACA,IAAI,UACA,aAAa;SAEb,MAAM,WAAW,kBAAkB,CAAC;IAExC;GACJ;GACA,IAAI,CAAC,YAAY,QAAQ,YAAY,KAAK,IAAI,MAAM,GAAG;IACnD,MAAM,SAAS,YAAY,GAAG;IAC9B,IAAI,QACA,OAAO,MAAM,EAAE,eAAe,KAAK,CAAC;GAE5C;EACJ;CACJ;AACJ"}
@@ -0,0 +1,2 @@
1
+ import { a as openOverlaySession, i as OverlaySessionOptions, n as DismissReason, r as OverlaySession, t as DismissEvent } from "./index-HIksgK0e.js";
2
+ export { type DismissEvent, type DismissReason, type OverlaySession, type OverlaySessionOptions, openOverlaySession };
@@ -0,0 +1 @@
1
+ export { t as openOverlaySession } from "./overlay-BwPyiM3T.js";
@@ -0,0 +1,51 @@
1
+ // src/pagination/pagination-range.ts
2
+ /** A whole number at least `min`, or `fallback` for a value that is no finite number. */
3
+ function whole(value, min, fallback) {
4
+ return value === void 0 || !Number.isFinite(value) ? fallback : Math.max(min, Math.floor(value));
5
+ }
6
+ /** The number of pages: `count`, or `ceil(total / pageSize)`; never less than 1. */
7
+ function pageCount({ count, total, pageSize }) {
8
+ if (count !== void 0) return whole(count, 1, 1);
9
+ const rows = whole(total, 0, 0);
10
+ const size = whole(pageSize, 1, 10);
11
+ return Math.max(1, Math.ceil(rows / size));
12
+ }
13
+ /** A page clamped to `[1, count]` (a value that is no finite number is 1). */
14
+ function clampPage(page, count) {
15
+ return Math.min(Math.max(1, Math.floor(count)), whole(page, 1, 1));
16
+ }
17
+ /**
18
+ * The items of a pagination: every page when they fit in `2 × boundary + 2 × siblings + 3`
19
+ * items, else the boundary pages, a slot, the window around the current page (kept whole near
20
+ * the ends), a slot and the boundary pages; a slot is an ellipsis, or the single page it would
21
+ * hide.
22
+ */
23
+ function paginationRange({ page, count, siblingCount, boundaryCount }) {
24
+ const pages = Math.max(1, Math.floor(count));
25
+ const current = clampPage(page, pages);
26
+ const siblings = whole(siblingCount, 0, 1);
27
+ const boundary = whole(boundaryCount, 0, 1);
28
+ const pageItem = (value) => ({
29
+ type: "page",
30
+ value
31
+ });
32
+ if (pages <= 2 * boundary + 2 * siblings + 3) return Array.from({ length: pages }, (_, index) => pageItem(index + 1));
33
+ const start = Math.min(Math.max(current - siblings, boundary + 2), pages - boundary - 1 - 2 * siblings);
34
+ const end = start + 2 * siblings;
35
+ const items = [];
36
+ for (let value = 1; value <= boundary; value++) items.push(pageItem(value));
37
+ items.push(start === boundary + 2 ? pageItem(boundary + 1) : {
38
+ type: "ellipsis",
39
+ position: "start"
40
+ });
41
+ for (let value = start; value <= end; value++) items.push(pageItem(value));
42
+ items.push(end === pages - boundary - 1 ? pageItem(pages - boundary) : {
43
+ type: "ellipsis",
44
+ position: "end"
45
+ });
46
+ for (let value = pages - boundary + 1; value <= pages; value++) items.push(pageItem(value));
47
+ return items;
48
+ }
49
+ export { pageCount as n, paginationRange as r, clampPage as t };
50
+
51
+ //# sourceMappingURL=pagination-BkVzaIGP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination-BkVzaIGP.js","names":[],"sources":["../src/pagination/pagination-range.ts"],"sourcesContent":["/** One item of a pagination's range (spec/pagination.md, \"The range\"). */\nexport type PaginationItem =\n | { type: \"page\"; value: number }\n | { type: \"ellipsis\"; position: \"start\" | \"end\" };\n\nexport interface PaginationRangeOptions {\n /** The current page, from 1 (clamped to `[1, count]`). */\n page: number;\n /** The number of pages (at least 1). */\n count: number;\n /** The pages shown on each side of the current one (default `1`). */\n siblingCount?: number | undefined;\n /** The pages always shown at each end (default `1`). */\n boundaryCount?: number | undefined;\n}\n\nexport interface PageCountOptions {\n /** The number of pages, when known. */\n count?: number | undefined;\n /** Else the number of rows... */\n total?: number | undefined;\n /** ...and the rows per page (default `10`). */\n pageSize?: number | undefined;\n}\n\n/** A whole number at least `min`, or `fallback` for a value that is no finite number. */\nfunction whole(value: number | undefined, min: number, fallback: number) {\n return value === undefined || !Number.isFinite(value)\n ? fallback\n : Math.max(min, Math.floor(value));\n}\n\n/** The number of pages: `count`, or `ceil(total / pageSize)`; never less than 1. */\nexport function pageCount({\n count,\n total,\n pageSize,\n}: PageCountOptions): number {\n if (count !== undefined) {\n return whole(count, 1, 1);\n }\n const rows = whole(total, 0, 0);\n const size = whole(pageSize, 1, 10);\n return Math.max(1, Math.ceil(rows / size));\n}\n\n/** A page clamped to `[1, count]` (a value that is no finite number is 1). */\nexport function clampPage(page: number, count: number): number {\n return Math.min(Math.max(1, Math.floor(count)), whole(page, 1, 1));\n}\n\n/**\n * The items of a pagination: every page when they fit in `2 × boundary + 2 × siblings + 3`\n * items, else the boundary pages, a slot, the window around the current page (kept whole near\n * the ends), a slot and the boundary pages; a slot is an ellipsis, or the single page it would\n * hide.\n */\nexport function paginationRange({\n page,\n count,\n siblingCount,\n boundaryCount,\n}: PaginationRangeOptions): PaginationItem[] {\n const pages = Math.max(1, Math.floor(count));\n const current = clampPage(page, pages);\n const siblings = whole(siblingCount, 0, 1);\n const boundary = whole(boundaryCount, 0, 1);\n const pageItem = (value: number): PaginationItem => ({\n type: \"page\",\n value,\n });\n if (pages <= 2 * boundary + 2 * siblings + 3) {\n return Array.from({ length: pages }, (_, index) => pageItem(index + 1));\n }\n // the window keeps its 2 × siblings + 1 pages, sliding inward at the ends\n const start = Math.min(\n Math.max(current - siblings, boundary + 2),\n pages - boundary - 1 - 2 * siblings,\n );\n const end = start + 2 * siblings;\n const items: PaginationItem[] = [];\n for (let value = 1; value <= boundary; value++) {\n items.push(pageItem(value));\n }\n items.push(\n start === boundary + 2\n ? pageItem(boundary + 1)\n : { type: \"ellipsis\", position: \"start\" },\n );\n for (let value = start; value <= end; value++) {\n items.push(pageItem(value));\n }\n items.push(\n end === pages - boundary - 1\n ? pageItem(pages - boundary)\n : { type: \"ellipsis\", position: \"end\" },\n );\n for (let value = pages - boundary + 1; value <= pages; value++) {\n items.push(pageItem(value));\n }\n return items;\n}\n"],"mappings":";;AA0BA,SAAS,MAAM,OAA2B,KAAa,UAAkB;CACrE,OAAO,UAAU,KAAA,KAAa,CAAC,OAAO,SAAS,KAAK,IAC9C,WACA,KAAK,IAAI,KAAK,KAAK,MAAM,KAAK,CAAC;AACzC;;AAGA,SAAgB,UAAU,EACtB,OACA,OACA,YACyB;CACzB,IAAI,UAAU,KAAA,GACV,OAAO,MAAM,OAAO,GAAG,CAAC;CAE5B,MAAM,OAAO,MAAM,OAAO,GAAG,CAAC;CAC9B,MAAM,OAAO,MAAM,UAAU,GAAG,EAAE;CAClC,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,OAAO,IAAI,CAAC;AAC7C;;AAGA,SAAgB,UAAU,MAAc,OAAuB;CAC3D,OAAO,KAAK,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,GAAG,MAAM,MAAM,GAAG,CAAC,CAAC;AACrE;;;;;;;AAQA,SAAgB,gBAAgB,EAC5B,MACA,OACA,cACA,iBACyC;CACzC,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC;CAC3C,MAAM,UAAU,UAAU,MAAM,KAAK;CACrC,MAAM,WAAW,MAAM,cAAc,GAAG,CAAC;CACzC,MAAM,WAAW,MAAM,eAAe,GAAG,CAAC;CAC1C,MAAM,YAAY,WAAmC;EACjD,MAAM;EACN;CACJ;CACA,IAAI,SAAS,IAAI,WAAW,IAAI,WAAW,GACvC,OAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,UAAU,SAAS,QAAQ,CAAC,CAAC;CAG1E,MAAM,QAAQ,KAAK,IACf,KAAK,IAAI,UAAU,UAAU,WAAW,CAAC,GACzC,QAAQ,WAAW,IAAI,IAAI,QAC/B;CACA,MAAM,MAAM,QAAQ,IAAI;CACxB,MAAM,QAA0B,CAAC;CACjC,KAAK,IAAI,QAAQ,GAAG,SAAS,UAAU,SACnC,MAAM,KAAK,SAAS,KAAK,CAAC;CAE9B,MAAM,KACF,UAAU,WAAW,IACf,SAAS,WAAW,CAAC,IACrB;EAAE,MAAM;EAAY,UAAU;CAAQ,CAChD;CACA,KAAK,IAAI,QAAQ,OAAO,SAAS,KAAK,SAClC,MAAM,KAAK,SAAS,KAAK,CAAC;CAE9B,MAAM,KACF,QAAQ,QAAQ,WAAW,IACrB,SAAS,QAAQ,QAAQ,IACzB;EAAE,MAAM;EAAY,UAAU;CAAM,CAC9C;CACA,KAAK,IAAI,QAAQ,QAAQ,WAAW,GAAG,SAAS,OAAO,SACnD,MAAM,KAAK,SAAS,KAAK,CAAC;CAE9B,OAAO;AACX"}
@@ -0,0 +1,2 @@
1
+ import { a as pageCount, i as clampPage, n as PaginationItem, o as paginationRange, r as PaginationRangeOptions, t as PageCountOptions } from "./index-raSUg9U7.js";
2
+ export { type PageCountOptions, type PaginationItem, type PaginationRangeOptions, clampPage, pageCount, paginationRange };
@@ -0,0 +1 @@
1
+ export { t as clampPage, n as pageCount, r as paginationRange } from "./pagination-BkVzaIGP.js";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A calendar date with no time and no time zone (spec/calendar.md, "Dates"). `month` is 1–12.
3
+ * Values are plain, immutable objects: every function returns a new one.
4
+ */
5
+ interface PlainDate {
6
+ readonly year: number;
7
+ readonly month: number;
8
+ readonly day: number;
9
+ }
10
+ /** A range of dates, `start <= end`. */
11
+ interface DateRange {
12
+ readonly start: PlainDate;
13
+ readonly end: PlainDate;
14
+ }
15
+ /** Builds a date, normalizing overflow (`{ month: 13 }` is January of the next year). */
16
+ declare function plainDate(year: number, month: number, day: number): PlainDate;
17
+ /** The local date of `now` (the clock the page sees). */
18
+ declare function today(now?: Date): PlainDate;
19
+ /** Negative when `a` is before `b`, positive when after, 0 when the same day. */
20
+ declare function compareDates(a: PlainDate, b: PlainDate): number;
21
+ declare function isSameDate(a: PlainDate | null | undefined, b: PlainDate | null | undefined): boolean;
22
+ declare function isSameMonth(a: PlainDate, b: PlainDate): boolean;
23
+ /** `2026-11-20` */
24
+ declare function toIsoDate(date: PlainDate): string;
25
+ /** Parses `YYYY-MM-DD`; `null` when the text is not a valid date. */
26
+ declare function fromIsoDate(text: string): PlainDate | null;
27
+ /** A `Date` at local midnight of the day, for `Intl` formatting. */
28
+ declare function toLocalDate(date: PlainDate): Date;
29
+ export { isSameDate as a, toIsoDate as c, fromIsoDate as i, toLocalDate as l, PlainDate as n, isSameMonth as o, compareDates as r, plainDate as s, DateRange as t, today as u };