@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,501 @@
1
+ // src/form/field-validity.ts
2
+ /** The `ValidityState` keys a field reads (spec/field.md, "Validation"), `valid` aside. */
3
+ const VALIDITY_KEYS = [
4
+ "badInput",
5
+ "customError",
6
+ "patternMismatch",
7
+ "rangeOverflow",
8
+ "rangeUnderflow",
9
+ "stepMismatch",
10
+ "tooLong",
11
+ "tooShort",
12
+ "typeMismatch",
13
+ "valueMissing"
14
+ ];
15
+ const NO_FLAGS = /* @__PURE__ */ Object.fromEntries(VALIDITY_KEYS.map((key) => [key, false]));
16
+ /** Before the first validation: neither valid nor invalid. */
17
+ const UNVALIDATED = {
18
+ validity: {
19
+ ...NO_FLAGS,
20
+ valid: null
21
+ },
22
+ errors: []
23
+ };
24
+ /** Valid, with no message: what a change that clears a shown error leaves. */
25
+ const CLEARED = {
26
+ validity: {
27
+ ...NO_FLAGS,
28
+ valid: true
29
+ },
30
+ errors: []
31
+ };
32
+ function isThenable(value) {
33
+ return typeof value === "object" && value !== null && typeof value.then === "function";
34
+ }
35
+ function messagesOf(result) {
36
+ if (result === null || result === void 0) return [];
37
+ return [...new Set(typeof result === "string" ? [result] : result)].filter((message) => message !== "");
38
+ }
39
+ /** The native step: the element's validity, with the required rule applied. */
40
+ function nativeStep(element, valueChanged) {
41
+ element?.setCustomValidity("");
42
+ const native = element?.willValidate ? element.validity : null;
43
+ const flags = { ...NO_FLAGS };
44
+ for (const key of VALIDITY_KEYS) flags[key] = native?.[key] ?? false;
45
+ if (flags.valueMissing && VALIDITY_KEYS.every((key) => key === "valueMissing" || !flags[key]) && !valueChanged) flags.valueMissing = false;
46
+ const invalid = VALIDITY_KEYS.some((key) => flags[key]);
47
+ return {
48
+ flags,
49
+ invalid,
50
+ errors: invalid && element !== null && element.validationMessage !== "" ? [element.validationMessage] : []
51
+ };
52
+ }
53
+ /** The result of the native step and `validate`'s messages, setting them as the custom validity. */
54
+ function combine(element, step, messages) {
55
+ const flags = { ...step.flags };
56
+ let errors = step.errors;
57
+ if (messages.length > 0) {
58
+ flags.customError = true;
59
+ element?.setCustomValidity(messages.join("\n"));
60
+ errors = [...messages];
61
+ }
62
+ const valid = !VALIDITY_KEYS.some((key) => flags[key]);
63
+ return {
64
+ validity: {
65
+ ...flags,
66
+ valid
67
+ },
68
+ errors: valid ? [] : errors
69
+ };
70
+ }
71
+ /**
72
+ * Validates a field (spec/field.md, "Validation"): reads the native validity of the element the
73
+ * form validates, applies the required rule, runs `validate`, and sets its messages as the
74
+ * element's custom validity, so a native submission is blocked by them. `element` is `null` (or
75
+ * barred from validation, as a `type="hidden"` input) for a control the browser cannot validate:
76
+ * `validate` alone decides. Returns what the field would show. A `validate` that returns a promise
77
+ * is not awaited here (its messages count as none): a field with an async `validate` uses
78
+ * {@link createFieldValidator}.
79
+ */
80
+ function validateField(element, options) {
81
+ const step = nativeStep(element, options.valueChanged);
82
+ if (step.invalid && !options.always) return combine(element, step, []);
83
+ const result = options.validate?.(options.value);
84
+ return combine(element, step, isThenable(result) ? [] : messagesOf(result));
85
+ }
86
+ function sameValue(a, b) {
87
+ if (Object.is(a, b)) return true;
88
+ try {
89
+ return JSON.stringify(a) === JSON.stringify(b);
90
+ } catch {
91
+ return false;
92
+ }
93
+ }
94
+ /** A field's validator: one per field, for as long as it lives. */
95
+ function createFieldValidator() {
96
+ let current = 0;
97
+ let resolved = null;
98
+ return {
99
+ run(element, options, settle) {
100
+ current += 1;
101
+ const run = current;
102
+ const step = nativeStep(element, options.valueChanged);
103
+ if (step.invalid && !options.always) return combine(element, step, []);
104
+ if (!step.invalid && resolved !== null && sameValue(resolved.value, options.value)) return combine(element, step, resolved.messages);
105
+ const result = options.validate?.(options.value);
106
+ if (!isThenable(result)) {
107
+ resolved = null;
108
+ return combine(element, step, messagesOf(result));
109
+ }
110
+ if (step.invalid) return combine(element, step, []);
111
+ const finish = (messages) => {
112
+ if (run !== current) return;
113
+ resolved = {
114
+ value: options.value,
115
+ messages
116
+ };
117
+ settle(combine(element, nativeStep(element, options.valueChanged), messages));
118
+ };
119
+ result.then((answer) => finish(messagesOf(answer)), () => finish([]));
120
+ return null;
121
+ },
122
+ cancel() {
123
+ current += 1;
124
+ }
125
+ };
126
+ }
127
+ // src/form/field-change.ts
128
+ /**
129
+ * Whether a field validates and shows the result on every change: in `onChange` mode, and in
130
+ * `onSubmit` mode once a submission was attempted (spec/field.md, "When the result is shown").
131
+ */
132
+ function validatesOnChange(mode, submitted) {
133
+ return mode === "onChange" || mode === "onSubmit" && submitted;
134
+ }
135
+ /**
136
+ * What a field shows after a change, from what it showed and the change's fresh validation (`null`
137
+ * while its async `validate` is pending). A field that validates on change shows the fresh result,
138
+ * or keeps what it showed while the run is pending. Otherwise a shown error is cleared at once,
139
+ * pending run or not (Epic #49), unless the value is now missing (the required error shows at
140
+ * once); anything else stays as it was.
141
+ */
142
+ function shownAfterChange(shown, next, onChange) {
143
+ if (onChange) return next ?? shown;
144
+ if (shown.validity.valid !== false) return shown;
145
+ return next?.validity.valueMissing ? next : CLEARED;
146
+ }
147
+ // src/form/field-described-by.ts
148
+ /**
149
+ * A control's `aria-describedby` from the field's description and shown errors: their ids in
150
+ * document order, or `undefined` when there is none (spec/field.md).
151
+ */
152
+ function fieldDescribedBy(elements) {
153
+ const sorted = [...elements].filter((element) => element.id !== "").sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
154
+ return sorted.length === 0 ? void 0 : sorted.map((element) => element.id).join(" ");
155
+ }
156
+ // src/form/field-error-shown.ts
157
+ /**
158
+ * Whether a `Field.Error` is shown: always with `match={true}`; never in a disabled field;
159
+ * with a key, while that key is set; with a function, while it returns `true`; without, while the
160
+ * field is invalid (its validity is `false`, the app set `invalid`, or its Form has errors for it).
161
+ */
162
+ function fieldErrorShown(match, shown, field) {
163
+ if (match === true) return true;
164
+ if (field.disabled) return false;
165
+ if (typeof match === "function") return match(shown.validity);
166
+ if (match !== void 0) return shown.validity[match];
167
+ return field.invalid || shown.validity.valid === false;
168
+ }
169
+ /**
170
+ * The messages a `Field.Error` with no children shows: the Form's errors for the field when it has
171
+ * some (only for an Error with no key or function `match`), else the field's own messages.
172
+ */
173
+ function fieldErrorMessages(match, shown, formErrors) {
174
+ return (match === void 0 || match === true) && formErrors.length > 0 ? formErrors : shown.errors;
175
+ }
176
+ // src/form/field-state.ts
177
+ /** The field's state attributes, as booleans keyed by their `data-*` name (without `data-`). */
178
+ function fieldStateAttributes(state) {
179
+ return {
180
+ invalid: state.valid === false,
181
+ valid: state.valid === true,
182
+ dirty: state.dirty,
183
+ touched: state.touched,
184
+ filled: state.filled,
185
+ focused: state.focused,
186
+ disabled: state.disabled
187
+ };
188
+ }
189
+ // src/form/form-bridge.ts
190
+ /** The first control of `form`, in its order, that would block a submission. */
191
+ function firstInvalidControl(form) {
192
+ for (const element of form.elements) {
193
+ const control = element;
194
+ if (control.willValidate && !control.validity.valid) return element;
195
+ }
196
+ return null;
197
+ }
198
+ /**
199
+ * Bridges a primitive's hidden input and its form (spec/README.md, "Forms"): a form reset, and a
200
+ * failed validation (the browser would focus the hidden input; focus goes to the primitive, when
201
+ * its input is the form's first invalid control, and the browser's bubble is not shown on an
202
+ * invisible element, nor does the browser then move the focus on to a later invalid control).
203
+ * Returns the cleanup.
204
+ */
205
+ function bridgeForm(input, options) {
206
+ const form = input.form;
207
+ let timer;
208
+ let holding;
209
+ const cancelLater = (event) => {
210
+ const target = event.target;
211
+ if (event.target !== input && target?.form === form) event.preventDefault();
212
+ };
213
+ const release = () => {
214
+ if (holding !== void 0) {
215
+ clearTimeout(holding);
216
+ holding = void 0;
217
+ form?.ownerDocument.removeEventListener("invalid", cancelLater, true);
218
+ }
219
+ };
220
+ const onReset = () => {
221
+ timer = setTimeout(() => {
222
+ timer = void 0;
223
+ options.reset?.();
224
+ });
225
+ };
226
+ const onInvalid = (event) => {
227
+ const target = options.invalid?.();
228
+ if (target) {
229
+ event.preventDefault();
230
+ if (form === null || firstInvalidControl(form) === input) {
231
+ target.focus();
232
+ if (form !== null && holding === void 0) {
233
+ form.ownerDocument.addEventListener("invalid", cancelLater, true);
234
+ holding = setTimeout(release);
235
+ }
236
+ }
237
+ }
238
+ };
239
+ form?.addEventListener("reset", onReset);
240
+ input.addEventListener("invalid", onInvalid);
241
+ return () => {
242
+ if (timer !== void 0) clearTimeout(timer);
243
+ release();
244
+ form?.removeEventListener("reset", onReset);
245
+ input.removeEventListener("invalid", onInvalid);
246
+ };
247
+ }
248
+ // src/form/form-errors.ts
249
+ /** The Form's errors for one field, as a list of messages (empty for none). */
250
+ function formErrorsFor(errors, name) {
251
+ if (errors == null || name === void 0 || !Object.hasOwn(errors, name)) return [];
252
+ const value = errors[name];
253
+ return (typeof value === "string" ? [value] : value ?? []).filter((message) => message !== "");
254
+ }
255
+ /** The errors without one field's key, or the same object when it has none. */
256
+ function withoutFormErrors(errors, name) {
257
+ if (!Object.hasOwn(errors, name)) return errors;
258
+ const next = { ...errors };
259
+ delete next[name];
260
+ return next;
261
+ }
262
+ // src/form/form-submit.ts
263
+ /**
264
+ * Runs a Form's validation on each submission of `form` (spec/form.md, "A submission"): a capture
265
+ * listener on the form, so it runs before any listener of the consumer's on the form or above it.
266
+ * When `attempt` returns `false`, the submission is blocked: `preventDefault`, and
267
+ * `stopImmediatePropagation`, so no other listener sees it. Returns the cleanup.
268
+ */
269
+ function guardFormSubmit(form, attempt) {
270
+ const onSubmit = (event) => {
271
+ if (!attempt(event)) {
272
+ event.preventDefault();
273
+ event.stopImmediatePropagation();
274
+ }
275
+ };
276
+ form.addEventListener("submit", onSubmit, true);
277
+ return () => form.removeEventListener("submit", onSubmit, true);
278
+ }
279
+ /** The first of these elements in document order (`null` for none). */
280
+ function firstInDocumentOrder(elements) {
281
+ let first = null;
282
+ for (const element of elements) if (element != null && (first === null || first.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING)) first = element;
283
+ return first;
284
+ }
285
+ /** Focuses a field's control for the Form: a text input's text is selected, as Base UI does. */
286
+ function focusFieldControl(element) {
287
+ element.focus();
288
+ if (element.tagName === "INPUT") try {
289
+ element.select();
290
+ } catch {}
291
+ }
292
+ // src/form/label-press.ts
293
+ const CONTROLS = "button, input, select, textarea";
294
+ const FOCUSABLE = "a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
295
+ /**
296
+ * A press on a Label (spec/label.md, "Pointer"): a double press selects none of its text (its
297
+ * `mousedown` default is prevented, Radix and Base UI), unless it lands on a control inside the
298
+ * label, whose own text editing stays.
299
+ */
300
+ function preventLabelSelection(event) {
301
+ if (event.target?.closest?.(CONTROLS)) return;
302
+ if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
303
+ }
304
+ /**
305
+ * The element a Label's press focuses when `for` names no labelable element (spec/label.md,
306
+ * "Pointer"): a Slider's thumb, a group. The named element itself when it can take the focus,
307
+ * else its first focusable descendant; `null` when `for` names a labelable element (the browser
308
+ * activates it) or nothing.
309
+ */
310
+ function labelFocusTarget(label) {
311
+ if (label.control !== null || label.htmlFor === "") return null;
312
+ const named = label.ownerDocument.getElementById(label.htmlFor);
313
+ if (named === null) return null;
314
+ if (named.matches(FOCUSABLE)) return named;
315
+ return named.querySelector(FOCUSABLE);
316
+ }
317
+ // src/form/otp-value.ts
318
+ const CLASSES = {
319
+ numeric: "\\d",
320
+ alpha: "[a-zA-Z]",
321
+ alphanumeric: "[a-zA-Z0-9]",
322
+ none: "\\S"
323
+ };
324
+ /** Whether one character is accepted by `type` (a pattern is tested on the character alone). */
325
+ function otpAccepts(character, type) {
326
+ if (/\s/.test(character)) return false;
327
+ if (type instanceof RegExp) return new RegExp(`^(?:${type.source})$`, type.flags.replace(/[gy]/g, "")).test(character);
328
+ return new RegExp(`^${CLASSES[type]}$`).test(character);
329
+ }
330
+ /**
331
+ * `text` as an OTP value (spec/otp-field.md, "Typing"): whitespace dropped, every character
332
+ * `type` refuses dropped, at most `length` characters (by code point). `rejected` says whether a
333
+ * character other than whitespace was dropped (the field's `onValueInvalid`).
334
+ */
335
+ function normalizeOtp(text, length, type) {
336
+ const characters = Array.from(text.replace(/\s/g, ""));
337
+ const accepted = characters.filter((character) => otpAccepts(character, type));
338
+ return {
339
+ value: accepted.slice(0, Math.max(length, 0)).join(""),
340
+ rejected: accepted.length < characters.length || accepted.length > Math.max(length, 0)
341
+ };
342
+ }
343
+ /**
344
+ * The value once `text` was typed or pasted into slot `index`: its characters replace the slot's
345
+ * and the next ones, the value stays contiguous and at most `length` long (Base UI).
346
+ */
347
+ function replaceOtp(value, index, text, length, type) {
348
+ const current = Array.from(value);
349
+ const typed = Array.from(normalizeOtp(text, length, type).value);
350
+ return normalizeOtp([
351
+ ...current.slice(0, index),
352
+ ...typed,
353
+ ...current.slice(index + typed.length)
354
+ ].join(""), length, type).value;
355
+ }
356
+ /** The value without the character of slot `index`; the later ones move back (Base UI). */
357
+ function removeOtpCharacter(value, index) {
358
+ const current = Array.from(value);
359
+ if (index < 0 || index >= current.length) return value;
360
+ current.splice(index, 1);
361
+ return current.join("");
362
+ }
363
+ /** The virtual keyboard a slot asks for: `numeric` for digits, else `text`. */
364
+ function otpInputMode(type) {
365
+ return type === "numeric" ? "numeric" : "text";
366
+ }
367
+ /**
368
+ * The hidden input's `pattern`: a complete value, `length` accepted characters, so a native form
369
+ * refuses an incomplete code (spec/otp-field.md, "Forms"). A `RegExp` type gives `.{length}`:
370
+ * the value is normalized already, and its flags (`i`) or a source the `v` flag a `pattern` is
371
+ * compiled with refuses would make the browser refuse valid codes, or ignore the pattern.
372
+ */
373
+ function otpPattern(type, length) {
374
+ return `${type instanceof RegExp ? "." : CLASSES[type]}{${Math.max(length, 0)}}`;
375
+ }
376
+ // src/form/submit-attempt.ts
377
+ /**
378
+ * Calls `attempt` on each submission attempt of `form` (spec/field.md, "When the result is
379
+ * shown"): the browser's validation found a control invalid (its `invalid` event, which does not
380
+ * bubble, caught in the capture phase), or the form submits. Returns the cleanup.
381
+ */
382
+ function onSubmitAttempt(form, attempt) {
383
+ form.addEventListener("invalid", attempt, true);
384
+ form.addEventListener("submit", attempt, true);
385
+ return () => {
386
+ form.removeEventListener("invalid", attempt, true);
387
+ form.removeEventListener("submit", attempt, true);
388
+ };
389
+ }
390
+ // src/form/tag-values.ts
391
+ /** The parts of `text` between the delimiters (the whole text with none). */
392
+ function split(text, delimiter) {
393
+ return delimiter === null || delimiter === "" ? [text] : text.split(delimiter);
394
+ }
395
+ /** Why `tag` (trimmed, not empty) cannot join `value`, or `null` when it can. */
396
+ function refusal(tag, value, rules) {
397
+ if (!rules.allowDuplicates && value.includes(tag)) return "duplicate";
398
+ if (value.length >= rules.max) return "max";
399
+ if (rules.validate !== void 0 && !rules.validate(tag, value)) return "invalid";
400
+ return null;
401
+ }
402
+ /**
403
+ * Offers `text` as tags (spec/tags-input.md, "Adding tags"): split by the delimiter, each part
404
+ * trimmed (an empty part dropped), each added at the end unless it is a duplicate (unless
405
+ * `allowDuplicates`), past `max`, or refused by `validate`, checked against the tags so far.
406
+ * `whole`: every part is offered (Enter, a paste, a blur); otherwise the part after the last
407
+ * delimiter is still being typed: it is not offered and stays, untrimmed, after the refused texts
408
+ * in the Input's text, which joins them with the delimiter.
409
+ */
410
+ function takeTags(value, text, rules, whole) {
411
+ const parts = split(text, rules.delimiter);
412
+ const typing = whole ? void 0 : parts.pop();
413
+ let next = value;
414
+ const added = [];
415
+ const refused = [];
416
+ for (const part of parts) {
417
+ const tag = part.trim();
418
+ if (tag === "") continue;
419
+ const cause = refusal(tag, next, rules);
420
+ if (cause === null) {
421
+ next = [...next, tag];
422
+ added.push(tag);
423
+ } else refused.push({
424
+ text: tag,
425
+ cause
426
+ });
427
+ }
428
+ const kept = refused.map((entry) => entry.text);
429
+ if (typing !== void 0 && typing !== "") kept.push(typing);
430
+ return {
431
+ value: next,
432
+ added,
433
+ refused,
434
+ text: kept.join(rules.delimiter ?? "")
435
+ };
436
+ }
437
+ /** How many times `delimiter` (not empty) is in `text`. */
438
+ function occurrences(text, delimiter) {
439
+ return text.split(delimiter).length - 1;
440
+ }
441
+ /**
442
+ * Whether an input that changed the Input's text from `previous` to `next` typed the delimiter
443
+ * (spec/tags-input.md, "Adding tags"): `next` holds it and either the inserted text (an
444
+ * `InputEvent`'s `data`) holds it or `next` holds it more times than `previous`. Any other input
445
+ * (a character, a deletion) only changes the text: the refused texts left in the Input are not
446
+ * offered again on every keystroke.
447
+ */
448
+ function typesDelimiter(previous, next, delimiter, inserted) {
449
+ if (delimiter === null || delimiter === "" || !next.includes(delimiter)) return false;
450
+ if (inserted?.includes(delimiter)) return true;
451
+ return occurrences(next, delimiter) > occurrences(previous, delimiter);
452
+ }
453
+ /**
454
+ * Ends the edit of the tag at `index` with `text` (spec/tags-input.md, "Editing a tag"): trimmed,
455
+ * an empty text removes the tag, the same text changes nothing, a duplicate of another tag (unless
456
+ * `allowDuplicates`) or a text `validate` refuses (with the other tags) is refused, any other text
457
+ * replaces it.
458
+ */
459
+ function editTag(value, index, text, rules) {
460
+ const tag = text.trim();
461
+ const others = value.filter((_, position) => position !== index);
462
+ if (tag === "") return {
463
+ type: "removed",
464
+ value: others
465
+ };
466
+ if (tag === value[index]) return { type: "unchanged" };
467
+ if (!rules.allowDuplicates && others.includes(tag)) return {
468
+ type: "refused",
469
+ text: tag,
470
+ cause: "duplicate"
471
+ };
472
+ if (rules.validate !== void 0 && !rules.validate(tag, others)) return {
473
+ type: "refused",
474
+ text: tag,
475
+ cause: "invalid"
476
+ };
477
+ return {
478
+ type: "replaced",
479
+ value: value.map((current, position) => position === index ? tag : current)
480
+ };
481
+ }
482
+ // src/form/visually-hidden.ts
483
+ /**
484
+ * The structural style of a hidden form input (spec/README.md, "Forms"): out of the layout and
485
+ * invisible, but still a form control the browser submits and validates (unlike `display: none`).
486
+ */
487
+ const VISUALLY_HIDDEN_INPUT_STYLE = {
488
+ position: "absolute",
489
+ width: "1px",
490
+ height: "1px",
491
+ margin: "-1px",
492
+ padding: "0",
493
+ border: "0",
494
+ overflow: "hidden",
495
+ clipPath: "inset(50%)",
496
+ whiteSpace: "nowrap",
497
+ pointerEvents: "none"
498
+ };
499
+ export { validateField as A, fieldDescribedBy as C, UNVALIDATED as D, CLEARED as E, VALIDITY_KEYS as O, fieldErrorShown as S, validatesOnChange as T, formErrorsFor as _, onSubmitAttempt as a, fieldStateAttributes as b, otpInputMode as c, replaceOtp as d, labelFocusTarget as f, guardFormSubmit as g, focusFieldControl as h, typesDelimiter as i, createFieldValidator as k, otpPattern as l, firstInDocumentOrder as m, editTag as n, normalizeOtp as o, preventLabelSelection as p, takeTags as r, otpAccepts as s, VISUALLY_HIDDEN_INPUT_STYLE as t, removeOtpCharacter as u, withoutFormErrors as v, shownAfterChange as w, fieldErrorMessages as x, bridgeForm as y };
500
+
501
+ //# sourceMappingURL=form-DovwKtqz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-DovwKtqz.js","names":[],"sources":["../src/form/field-validity.ts","../src/form/field-change.ts","../src/form/field-described-by.ts","../src/form/field-error-shown.ts","../src/form/field-state.ts","../src/form/form-bridge.ts","../src/form/form-errors.ts","../src/form/form-submit.ts","../src/form/label-press.ts","../src/form/otp-value.ts","../src/form/submit-attempt.ts","../src/form/tag-values.ts","../src/form/visually-hidden.ts"],"sourcesContent":["/** The `ValidityState` keys a field reads (spec/field.md, \"Validation\"), `valid` aside. */\nexport const VALIDITY_KEYS = [\n \"badInput\",\n \"customError\",\n \"patternMismatch\",\n \"rangeOverflow\",\n \"rangeUnderflow\",\n \"stepMismatch\",\n \"tooLong\",\n \"tooShort\",\n \"typeMismatch\",\n \"valueMissing\",\n] as const;\n\nexport type ValidityKey = (typeof VALIDITY_KEYS)[number];\n\n/** A field's validity: the native flags, plus `valid` (`null` before the first validation). */\nexport type FieldValidity = Readonly<Record<ValidityKey, boolean>> & {\n readonly valid: boolean | null;\n};\n\n/** What a field shows: its validity and its messages (empty while valid). */\nexport interface FieldValidation {\n readonly validity: FieldValidity;\n readonly errors: readonly string[];\n}\n\n/** What a field's `validate` answers: a message, a list of messages, or none. */\nexport type FieldValidateResult = string | readonly string[] | null | undefined;\n\n/**\n * A field's `validate`: a message, a list of messages, or none; or a promise of one of these\n * (spec/field.md, \"Async validation\").\n */\nexport type FieldValidate = (\n value: unknown,\n) => FieldValidateResult | PromiseLike<FieldValidateResult>;\n\nconst NO_FLAGS = /* @__PURE__ */ Object.fromEntries(\n VALIDITY_KEYS.map((key) => [key, false]),\n) as Record<ValidityKey, boolean>;\n\n/** Before the first validation: neither valid nor invalid. */\nexport const UNVALIDATED: FieldValidation = {\n validity: { ...NO_FLAGS, valid: null },\n errors: [],\n};\n\n/** Valid, with no message: what a change that clears a shown error leaves. */\nexport const CLEARED: FieldValidation = {\n validity: { ...NO_FLAGS, valid: true },\n errors: [],\n};\n\nexport interface ValidateFieldOptions {\n /** The control's value, given to `validate`. */\n value: unknown;\n validate?: FieldValidate | undefined;\n /**\n * Whether the value has changed once or a submission was attempted. Until then, a\n * `valueMissing` alone counts as valid (the required rule).\n */\n valueChanged: boolean;\n /** Runs `validate` even when the native validity has an error (the field validates on change). */\n always: boolean;\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<FieldValidateResult> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\nfunction messagesOf(result: FieldValidateResult): string[] {\n if (result === null || result === undefined) {\n return [];\n }\n // a message appears once, however often `validate` returns it\n return [...new Set(typeof result === \"string\" ? [result] : result)].filter(\n (message) => message !== \"\",\n );\n}\n\ninterface NativeStep {\n flags: Record<ValidityKey, boolean>;\n /** The native validity has an error (after the required rule). */\n invalid: boolean;\n errors: string[];\n}\n\n/** The native step: the element's validity, with the required rule applied. */\nfunction nativeStep(\n element: HTMLInputElement | null,\n valueChanged: boolean,\n): NativeStep {\n element?.setCustomValidity(\"\");\n const native = element?.willValidate ? element.validity : null;\n const flags = { ...NO_FLAGS };\n for (const key of VALIDITY_KEYS) {\n flags[key] = native?.[key] ?? false;\n }\n const onlyMissing =\n flags.valueMissing &&\n VALIDITY_KEYS.every((key) => key === \"valueMissing\" || !flags[key]);\n if (onlyMissing && !valueChanged) {\n flags.valueMissing = false;\n }\n const invalid = VALIDITY_KEYS.some((key) => flags[key]);\n const errors =\n invalid && element !== null && element.validationMessage !== \"\"\n ? [element.validationMessage]\n : [];\n return { flags, invalid, errors };\n}\n\n/** The result of the native step and `validate`'s messages, setting them as the custom validity. */\nfunction combine(\n element: HTMLInputElement | null,\n step: NativeStep,\n messages: readonly string[],\n): FieldValidation {\n const flags = { ...step.flags };\n let errors = step.errors;\n if (messages.length > 0) {\n flags.customError = true;\n element?.setCustomValidity(messages.join(\"\\n\"));\n errors = [...messages];\n }\n const valid = !VALIDITY_KEYS.some((key) => flags[key]);\n return { validity: { ...flags, valid }, errors: valid ? [] : errors };\n}\n\n/**\n * Validates a field (spec/field.md, \"Validation\"): reads the native validity of the element the\n * form validates, applies the required rule, runs `validate`, and sets its messages as the\n * element's custom validity, so a native submission is blocked by them. `element` is `null` (or\n * barred from validation, as a `type=\"hidden\"` input) for a control the browser cannot validate:\n * `validate` alone decides. Returns what the field would show. A `validate` that returns a promise\n * is not awaited here (its messages count as none): a field with an async `validate` uses\n * {@link createFieldValidator}.\n */\nexport function validateField(\n element: HTMLInputElement | null,\n options: ValidateFieldOptions,\n): FieldValidation {\n const step = nativeStep(element, options.valueChanged);\n if (step.invalid && !options.always) {\n return combine(element, step, []);\n }\n const result = options.validate?.(options.value);\n return combine(element, step, isThenable(result) ? [] : messagesOf(result));\n}\n\n/** A field's validation runs, with the async rules (spec/field.md, \"Async validation\"). */\nexport interface FieldValidator {\n /**\n * Validates the field. Returns the result at once, or `null` while an async `validate` is\n * pending: `settle` then receives the result when it resolves, unless a newer run started\n * first (latest wins). A value the last resolved run validated is not validated again: its\n * messages are reused at once.\n */\n run(\n element: HTMLInputElement | null,\n options: ValidateFieldOptions,\n settle: (validation: FieldValidation) => void,\n ): FieldValidation | null;\n /** Drops the pending run, if any (the field unmounted). */\n cancel(): void;\n}\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n try {\n return JSON.stringify(a) === JSON.stringify(b);\n } catch {\n return false;\n }\n}\n\n/** A field's validator: one per field, for as long as it lives. */\nexport function createFieldValidator(): FieldValidator {\n let current = 0;\n let resolved: { value: unknown; messages: string[] } | null = null;\n return {\n run(element, options, settle) {\n current += 1;\n const run = current;\n const step = nativeStep(element, options.valueChanged);\n if (step.invalid && !options.always) {\n return combine(element, step, []);\n }\n if (\n !step.invalid &&\n resolved !== null &&\n sameValue(resolved.value, options.value)\n ) {\n return combine(element, step, resolved.messages);\n }\n const result = options.validate?.(options.value);\n if (!isThenable(result)) {\n resolved = null;\n return combine(element, step, messagesOf(result));\n }\n if (step.invalid) {\n // a native error is the result at once; the promise is not awaited\n return combine(element, step, []);\n }\n const finish = (messages: string[]) => {\n if (run !== current) {\n return;\n }\n resolved = { value: options.value, messages };\n // the native step again: the element may have changed while the promise ran\n settle(\n combine(\n element,\n nativeStep(element, options.valueChanged),\n messages,\n ),\n );\n };\n result.then(\n (answer) => finish(messagesOf(answer)),\n () => finish([]),\n );\n return null;\n },\n cancel() {\n current += 1;\n },\n };\n}\n","import { CLEARED, type FieldValidation } from \"./field-validity.ts\";\n\n/** A field's `validationMode` (spec/field.md). */\nexport type FieldValidationMode = \"onSubmit\" | \"onBlur\" | \"onChange\";\n\n/**\n * Whether a field validates and shows the result on every change: in `onChange` mode, and in\n * `onSubmit` mode once a submission was attempted (spec/field.md, \"When the result is shown\").\n */\nexport function validatesOnChange(\n mode: FieldValidationMode,\n submitted: boolean,\n): boolean {\n return mode === \"onChange\" || (mode === \"onSubmit\" && submitted);\n}\n\n/**\n * What a field shows after a change, from what it showed and the change's fresh validation (`null`\n * while its async `validate` is pending). A field that validates on change shows the fresh result,\n * or keeps what it showed while the run is pending. Otherwise a shown error is cleared at once,\n * pending run or not (Epic #49), unless the value is now missing (the required error shows at\n * once); anything else stays as it was.\n */\nexport function shownAfterChange(\n shown: FieldValidation,\n next: FieldValidation | null,\n onChange: boolean,\n): FieldValidation {\n if (onChange) {\n return next ?? shown;\n }\n if (shown.validity.valid !== false) {\n return shown;\n }\n return next?.validity.valueMissing ? next : CLEARED;\n}\n","/**\n * A control's `aria-describedby` from the field's description and shown errors: their ids in\n * document order, or `undefined` when there is none (spec/field.md).\n */\nexport function fieldDescribedBy(\n elements: Iterable<HTMLElement>,\n): string | undefined {\n const sorted = [...elements]\n .filter((element) => element.id !== \"\")\n .sort((a, b) =>\n a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING\n ? -1\n : 1,\n );\n return sorted.length === 0\n ? undefined\n : sorted.map((element) => element.id).join(\" \");\n}\n","import type {\n FieldValidation,\n FieldValidity,\n ValidityKey,\n} from \"./field-validity.ts\";\n\n/**\n * `Field.Error`'s `match`: a `ValidityState` key, a function of the field's validity, or `true`\n * for always (spec/field.md).\n */\nexport type FieldErrorMatch =\n | ValidityKey\n | ((validity: FieldValidity) => boolean)\n | true;\n\n/**\n * Whether a `Field.Error` is shown: always with `match={true}`; never in a disabled field;\n * with a key, while that key is set; with a function, while it returns `true`; without, while the\n * field is invalid (its validity is `false`, the app set `invalid`, or its Form has errors for it).\n */\nexport function fieldErrorShown(\n match: FieldErrorMatch | undefined,\n shown: FieldValidation,\n field: { invalid: boolean; disabled: boolean },\n): boolean {\n if (match === true) {\n return true;\n }\n if (field.disabled) {\n return false;\n }\n if (typeof match === \"function\") {\n return match(shown.validity);\n }\n if (match !== undefined) {\n return shown.validity[match];\n }\n return field.invalid || shown.validity.valid === false;\n}\n\n/**\n * The messages a `Field.Error` with no children shows: the Form's errors for the field when it has\n * some (only for an Error with no key or function `match`), else the field's own messages.\n */\nexport function fieldErrorMessages(\n match: FieldErrorMatch | undefined,\n shown: FieldValidation,\n formErrors: readonly string[],\n): readonly string[] {\n const general = match === undefined || match === true;\n return general && formErrors.length > 0 ? formErrors : shown.errors;\n}\n","/** A field's state, which every part carries (spec/field.md, \"State attributes and ARIA\"). */\nexport interface FieldState {\n /** `false` while it shows an error, `true` once validated and valid, `null` before or disabled. */\n valid: boolean | null;\n dirty: boolean;\n touched: boolean;\n filled: boolean;\n focused: boolean;\n disabled: boolean;\n}\n\n/** The field's state attributes, as booleans keyed by their `data-*` name (without `data-`). */\nexport function fieldStateAttributes(\n state: FieldState,\n): Record<\n | \"invalid\"\n | \"valid\"\n | \"dirty\"\n | \"touched\"\n | \"filled\"\n | \"focused\"\n | \"disabled\",\n boolean\n> {\n return {\n invalid: state.valid === false,\n valid: state.valid === true,\n dirty: state.dirty,\n touched: state.touched,\n filled: state.filled,\n focused: state.focused,\n disabled: state.disabled,\n };\n}\n","export interface FormBridgeOptions {\n /**\n * The input's form was reset. Called once the browser has reset its controls, so the\n * framework can return the component to its default and write it back onto the input.\n */\n reset?: () => void;\n /** The browser's validation found the input invalid: where focus goes instead (the primitive). */\n invalid?: () => HTMLElement | null;\n}\n\n/** The first control of `form`, in its order, that would block a submission. */\nfunction firstInvalidControl(form: HTMLFormElement): Element | null {\n for (const element of form.elements) {\n const control = element as HTMLInputElement;\n if (control.willValidate && !control.validity.valid) {\n return element;\n }\n }\n return null;\n}\n\n/**\n * Bridges a primitive's hidden input and its form (spec/README.md, \"Forms\"): a form reset, and a\n * failed validation (the browser would focus the hidden input; focus goes to the primitive, when\n * its input is the form's first invalid control, and the browser's bubble is not shown on an\n * invisible element, nor does the browser then move the focus on to a later invalid control).\n * Returns the cleanup.\n */\nexport function bridgeForm(\n input: HTMLInputElement,\n options: FormBridgeOptions,\n): () => void {\n const form = input.form;\n let timer: ReturnType<typeof setTimeout> | undefined;\n // the validation this bridge took the focus in: the later controls' `invalid` events\n let holding: ReturnType<typeof setTimeout> | undefined;\n // a control of the form, wherever it is: inside it, or associated by `form=\"id\"` outside it\n const cancelLater = (event: Event) => {\n const target = event.target as { form?: unknown } | null;\n if (event.target !== input && target?.form === form) {\n event.preventDefault();\n }\n };\n const release = () => {\n if (holding !== undefined) {\n clearTimeout(holding);\n holding = undefined;\n form?.ownerDocument.removeEventListener(\n \"invalid\",\n cancelLater,\n true,\n );\n }\n };\n const onReset = () => {\n // the reset event fires before the browser resets the controls\n timer = setTimeout(() => {\n timer = undefined;\n options.reset?.();\n });\n };\n const onInvalid = (event: Event) => {\n const target = options.invalid?.();\n if (target) {\n event.preventDefault();\n // the browser fires `invalid` on every invalid control, then focuses the first: only\n // the first one's primitive takes focus (Epic #26, several required pickers)\n if (form === null || firstInvalidControl(form) === input) {\n target.focus();\n // then the browser would focus the first control whose `invalid` was not\n // canceled, a later native one, and show its bubble: the rest of this validation's\n // events are canceled (Epic #49). They come in the same task, one per control,\n // with microtasks between them, so the hold ends with the task\n if (form !== null && holding === undefined) {\n // on the document: a control associated by `form` may be outside the form\n form.ownerDocument.addEventListener(\n \"invalid\",\n cancelLater,\n true,\n );\n holding = setTimeout(release);\n }\n }\n }\n };\n form?.addEventListener(\"reset\", onReset);\n input.addEventListener(\"invalid\", onInvalid);\n return () => {\n if (timer !== undefined) {\n clearTimeout(timer);\n }\n release();\n form?.removeEventListener(\"reset\", onReset);\n input.removeEventListener(\"invalid\", onInvalid);\n };\n}\n","/** A Form's server errors, keyed by the fields' `name` (spec/form.md). */\nexport type FormErrors = Readonly<Record<string, string | readonly string[]>>;\n\n/** The Form's errors for one field, as a list of messages (empty for none). */\nexport function formErrorsFor(\n errors: FormErrors | null | undefined,\n name: string | undefined,\n): readonly string[] {\n if (errors == null || name === undefined || !Object.hasOwn(errors, name)) {\n return [];\n }\n const value = errors[name];\n const list = typeof value === \"string\" ? [value] : (value ?? []);\n return list.filter((message) => message !== \"\");\n}\n\n/** The errors without one field's key, or the same object when it has none. */\nexport function withoutFormErrors(\n errors: FormErrors,\n name: string,\n): FormErrors {\n if (!Object.hasOwn(errors, name)) {\n return errors;\n }\n const next: Record<string, string | readonly string[]> = { ...errors };\n delete next[name];\n return next;\n}\n","/**\n * Runs a Form's validation on each submission of `form` (spec/form.md, \"A submission\"): a capture\n * listener on the form, so it runs before any listener of the consumer's on the form or above it.\n * When `attempt` returns `false`, the submission is blocked: `preventDefault`, and\n * `stopImmediatePropagation`, so no other listener sees it. Returns the cleanup.\n */\nexport function guardFormSubmit(\n form: HTMLFormElement,\n attempt: (event: SubmitEvent) => boolean,\n): () => void {\n const onSubmit = (event: Event) => {\n if (!attempt(event as SubmitEvent)) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n };\n form.addEventListener(\"submit\", onSubmit, true);\n return () => form.removeEventListener(\"submit\", onSubmit, true);\n}\n\n/** The first of these elements in document order (`null` for none). */\nexport function firstInDocumentOrder(\n elements: Iterable<HTMLElement | null | undefined>,\n): HTMLElement | null {\n let first: HTMLElement | null = null;\n for (const element of elements) {\n if (\n element != null &&\n (first === null ||\n first.compareDocumentPosition(element) &\n Node.DOCUMENT_POSITION_PRECEDING)\n ) {\n first = element;\n }\n }\n return first;\n}\n\n/** Focuses a field's control for the Form: a text input's text is selected, as Base UI does. */\nexport function focusFieldControl(element: HTMLElement): void {\n element.focus();\n if (element.tagName === \"INPUT\") {\n try {\n (element as HTMLInputElement).select();\n } catch {\n // an input type with no selection (a checkbox, a range)\n }\n }\n}\n","const CONTROLS = \"button, input, select, textarea\";\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * A press on a Label (spec/label.md, \"Pointer\"): a double press selects none of its text (its\n * `mousedown` default is prevented, Radix and Base UI), unless it lands on a control inside the\n * label, whose own text editing stays.\n */\nexport function preventLabelSelection(event: MouseEvent): void {\n const target = event.target as Element | null;\n if (target?.closest?.(CONTROLS)) {\n return;\n }\n if (!event.defaultPrevented && event.detail > 1) {\n event.preventDefault();\n }\n}\n\n/**\n * The element a Label's press focuses when `for` names no labelable element (spec/label.md,\n * \"Pointer\"): a Slider's thumb, a group. The named element itself when it can take the focus,\n * else its first focusable descendant; `null` when `for` names a labelable element (the browser\n * activates it) or nothing.\n */\nexport function labelFocusTarget(label: HTMLLabelElement): HTMLElement | null {\n if (label.control !== null || label.htmlFor === \"\") {\n return null;\n }\n const named = label.ownerDocument.getElementById(label.htmlFor);\n if (named === null) {\n return null;\n }\n if (named.matches(FOCUSABLE)) {\n return named as HTMLElement;\n }\n return named.querySelector<HTMLElement>(FOCUSABLE);\n}\n","/**\n * The characters an OTP field accepts (spec/otp-field.md, \"API\"): digits, letters, both, any\n * character but whitespace, or a pattern each character must match.\n */\nexport type OtpValidationType =\n | \"numeric\"\n | \"alpha\"\n | \"alphanumeric\"\n | \"none\"\n | RegExp;\n\nconst CLASSES = {\n numeric: \"\\\\d\",\n alpha: \"[a-zA-Z]\",\n alphanumeric: \"[a-zA-Z0-9]\",\n none: \"\\\\S\",\n} as const;\n\n/** Whether one character is accepted by `type` (a pattern is tested on the character alone). */\nexport function otpAccepts(\n character: string,\n type: OtpValidationType,\n): boolean {\n if (/\\s/.test(character)) {\n return false;\n }\n if (type instanceof RegExp) {\n // a fresh, anchored copy: a global pattern's `lastIndex` never carries over\n return new RegExp(\n `^(?:${type.source})$`,\n type.flags.replace(/[gy]/g, \"\"),\n ).test(character);\n }\n return new RegExp(`^${CLASSES[type]}$`).test(character);\n}\n\n/**\n * `text` as an OTP value (spec/otp-field.md, \"Typing\"): whitespace dropped, every character\n * `type` refuses dropped, at most `length` characters (by code point). `rejected` says whether a\n * character other than whitespace was dropped (the field's `onValueInvalid`).\n */\nexport function normalizeOtp(\n text: string,\n length: number,\n type: OtpValidationType,\n): { value: string; rejected: boolean } {\n const characters = Array.from(text.replace(/\\s/g, \"\"));\n const accepted = characters.filter((character) =>\n otpAccepts(character, type),\n );\n return {\n value: accepted.slice(0, Math.max(length, 0)).join(\"\"),\n rejected:\n accepted.length < characters.length ||\n accepted.length > Math.max(length, 0),\n };\n}\n\n/**\n * The value once `text` was typed or pasted into slot `index`: its characters replace the slot's\n * and the next ones, the value stays contiguous and at most `length` long (Base UI).\n */\nexport function replaceOtp(\n value: string,\n index: number,\n text: string,\n length: number,\n type: OtpValidationType,\n): string {\n const current = Array.from(value);\n const typed = Array.from(normalizeOtp(text, length, type).value);\n const next = [\n ...current.slice(0, index),\n ...typed,\n ...current.slice(index + typed.length),\n ];\n return normalizeOtp(next.join(\"\"), length, type).value;\n}\n\n/** The value without the character of slot `index`; the later ones move back (Base UI). */\nexport function removeOtpCharacter(value: string, index: number): string {\n const current = Array.from(value);\n if (index < 0 || index >= current.length) {\n return value;\n }\n current.splice(index, 1);\n return current.join(\"\");\n}\n\n/** The virtual keyboard a slot asks for: `numeric` for digits, else `text`. */\nexport function otpInputMode(type: OtpValidationType): \"numeric\" | \"text\" {\n return type === \"numeric\" ? \"numeric\" : \"text\";\n}\n\n/**\n * The hidden input's `pattern`: a complete value, `length` accepted characters, so a native form\n * refuses an incomplete code (spec/otp-field.md, \"Forms\"). A `RegExp` type gives `.{length}`:\n * the value is normalized already, and its flags (`i`) or a source the `v` flag a `pattern` is\n * compiled with refuses would make the browser refuse valid codes, or ignore the pattern.\n */\nexport function otpPattern(type: OtpValidationType, length: number): string {\n const one = type instanceof RegExp ? \".\" : CLASSES[type];\n return `${one}{${Math.max(length, 0)}}`;\n}\n","/**\n * Calls `attempt` on each submission attempt of `form` (spec/field.md, \"When the result is\n * shown\"): the browser's validation found a control invalid (its `invalid` event, which does not\n * bubble, caught in the capture phase), or the form submits. Returns the cleanup.\n */\nexport function onSubmitAttempt(\n form: HTMLFormElement,\n attempt: () => void,\n): () => void {\n form.addEventListener(\"invalid\", attempt, true);\n form.addEventListener(\"submit\", attempt, true);\n return () => {\n form.removeEventListener(\"invalid\", attempt, true);\n form.removeEventListener(\"submit\", attempt, true);\n };\n}\n","/** Why a text was refused as a tag (spec/tags-input.md, \"Adding tags\"). */\nexport type TagRefusal = \"duplicate\" | \"max\" | \"invalid\";\n\n/** The rules a TagsInput's tags follow (spec/tags-input.md, \"API\"). */\nexport interface TagRules {\n /** Ends a tag while typing and splits a paste; `null` for none. */\n delimiter: string | null;\n /** The most tags (`Infinity` for no limit). */\n max: number;\n /** A text equal to a tag is accepted. */\n allowDuplicates: boolean;\n /** `false` refuses a trimmed text; `value` is the tags it would join. */\n validate?: ((tag: string, value: readonly string[]) => boolean) | undefined;\n}\n\n/** A refused text: trimmed, and why. */\nexport interface RefusedTag {\n text: string;\n cause: TagRefusal;\n}\n\n/** What offering a text as tags gives (`takeTags`). */\nexport interface TakenTags {\n /** The tags after it (the same array when nothing was added). */\n value: readonly string[];\n /** The tags it added, in order. */\n added: string[];\n refused: RefusedTag[];\n /** What the Input holds after it: the refused texts and the text still typed. */\n text: string;\n}\n\n/** The parts of `text` between the delimiters (the whole text with none). */\nfunction split(text: string, delimiter: string | null): string[] {\n return delimiter === null || delimiter === \"\"\n ? [text]\n : text.split(delimiter);\n}\n\n/** Why `tag` (trimmed, not empty) cannot join `value`, or `null` when it can. */\nfunction refusal(\n tag: string,\n value: readonly string[],\n rules: TagRules,\n): TagRefusal | null {\n if (!rules.allowDuplicates && value.includes(tag)) {\n return \"duplicate\";\n }\n if (value.length >= rules.max) {\n return \"max\";\n }\n if (rules.validate !== undefined && !rules.validate(tag, value)) {\n return \"invalid\";\n }\n return null;\n}\n\n/**\n * Offers `text` as tags (spec/tags-input.md, \"Adding tags\"): split by the delimiter, each part\n * trimmed (an empty part dropped), each added at the end unless it is a duplicate (unless\n * `allowDuplicates`), past `max`, or refused by `validate`, checked against the tags so far.\n * `whole`: every part is offered (Enter, a paste, a blur); otherwise the part after the last\n * delimiter is still being typed: it is not offered and stays, untrimmed, after the refused texts\n * in the Input's text, which joins them with the delimiter.\n */\nexport function takeTags(\n value: readonly string[],\n text: string,\n rules: TagRules,\n whole: boolean,\n): TakenTags {\n const parts = split(text, rules.delimiter);\n const typing = whole ? undefined : parts.pop();\n let next = value;\n const added: string[] = [];\n const refused: RefusedTag[] = [];\n for (const part of parts) {\n const tag = part.trim();\n if (tag === \"\") {\n continue;\n }\n const cause = refusal(tag, next, rules);\n if (cause === null) {\n next = [...next, tag];\n added.push(tag);\n } else {\n refused.push({ text: tag, cause });\n }\n }\n const kept = refused.map((entry) => entry.text);\n if (typing !== undefined && typing !== \"\") {\n kept.push(typing);\n }\n return {\n value: next,\n added,\n refused,\n text: kept.join(rules.delimiter ?? \"\"),\n };\n}\n\n/** How many times `delimiter` (not empty) is in `text`. */\nfunction occurrences(text: string, delimiter: string): number {\n return text.split(delimiter).length - 1;\n}\n\n/**\n * Whether an input that changed the Input's text from `previous` to `next` typed the delimiter\n * (spec/tags-input.md, \"Adding tags\"): `next` holds it and either the inserted text (an\n * `InputEvent`'s `data`) holds it or `next` holds it more times than `previous`. Any other input\n * (a character, a deletion) only changes the text: the refused texts left in the Input are not\n * offered again on every keystroke.\n */\nexport function typesDelimiter(\n previous: string,\n next: string,\n delimiter: string | null,\n inserted?: string | null,\n): boolean {\n if (delimiter === null || delimiter === \"\" || !next.includes(delimiter)) {\n return false;\n }\n if (inserted?.includes(delimiter)) {\n return true;\n }\n return occurrences(next, delimiter) > occurrences(previous, delimiter);\n}\n\n/** What ending a tag's edit gives (`editTag`). */\nexport type EditedTag =\n | { type: \"unchanged\" }\n | { type: \"replaced\"; value: readonly string[] }\n | { type: \"removed\"; value: readonly string[] }\n | { type: \"refused\"; text: string; cause: Exclude<TagRefusal, \"max\"> };\n\n/**\n * Ends the edit of the tag at `index` with `text` (spec/tags-input.md, \"Editing a tag\"): trimmed,\n * an empty text removes the tag, the same text changes nothing, a duplicate of another tag (unless\n * `allowDuplicates`) or a text `validate` refuses (with the other tags) is refused, any other text\n * replaces it.\n */\nexport function editTag(\n value: readonly string[],\n index: number,\n text: string,\n rules: TagRules,\n): EditedTag {\n const tag = text.trim();\n const others = value.filter((_, position) => position !== index);\n if (tag === \"\") {\n return { type: \"removed\", value: others };\n }\n if (tag === value[index]) {\n return { type: \"unchanged\" };\n }\n if (!rules.allowDuplicates && others.includes(tag)) {\n return { type: \"refused\", text: tag, cause: \"duplicate\" };\n }\n if (rules.validate !== undefined && !rules.validate(tag, others)) {\n return { type: \"refused\", text: tag, cause: \"invalid\" };\n }\n return {\n type: \"replaced\",\n value: value.map((current, position) =>\n position === index ? tag : current,\n ),\n };\n}\n","/**\n * The structural style of a hidden form input (spec/README.md, \"Forms\"): out of the layout and\n * invisible, but still a form control the browser submits and validates (unlike `display: none`).\n */\nexport const VISUALLY_HIDDEN_INPUT_STYLE = {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n margin: \"-1px\",\n padding: \"0\",\n border: \"0\",\n overflow: \"hidden\",\n clipPath: \"inset(50%)\",\n whiteSpace: \"nowrap\",\n pointerEvents: \"none\",\n} as const;\n"],"mappings":";;AACA,MAAa,gBAAgB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AA0BA,MAAM,WAA2B,uBAAO,YACpC,cAAc,KAAK,QAAQ,CAAC,KAAK,KAAK,CAAC,CAC3C;;AAGA,MAAa,cAA+B;CACxC,UAAU;EAAE,GAAG;EAAU,OAAO;CAAK;CACrC,QAAQ,CAAC;AACb;;AAGA,MAAa,UAA2B;CACpC,UAAU;EAAE,GAAG;EAAU,OAAO;CAAK;CACrC,QAAQ,CAAC;AACb;AAeA,SAAS,WAAW,OAA2D;CAC3E,OACI,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAEtD;AAEA,SAAS,WAAW,QAAuC;CACvD,IAAI,WAAW,QAAQ,WAAW,KAAA,GAC9B,OAAO,CAAC;CAGZ,OAAO,CAAC,GAAG,IAAI,IAAI,OAAO,WAAW,WAAW,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,QAC/D,YAAY,YAAY,EAC7B;AACJ;;AAUA,SAAS,WACL,SACA,cACU;CACV,SAAS,kBAAkB,EAAE;CAC7B,MAAM,SAAS,SAAS,eAAe,QAAQ,WAAW;CAC1D,MAAM,QAAQ,EAAE,GAAG,SAAS;CAC5B,KAAK,MAAM,OAAO,eACd,MAAM,OAAO,SAAS,QAAQ;CAKlC,IAFI,MAAM,gBACN,cAAc,OAAO,QAAQ,QAAQ,kBAAkB,CAAC,MAAM,IAAI,KACnD,CAAC,cAChB,MAAM,eAAe;CAEzB,MAAM,UAAU,cAAc,MAAM,QAAQ,MAAM,IAAI;CAKtD,OAAO;EA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,IAAI,QAAQ,MAAM,QACd,OAAO,EAAE,MAAM,YAAY;CAE/B,IAAI,CAAC,MAAM,mBAAmB,OAAO,SAAS,GAAG,GAC7C,OAAO;EAAE,MAAM;EAAW,MAAM;EAAK,OAAO;CAAY;CAE5D,IAAI,MAAM,aAAa,KAAA,KAAa,CAAC,MAAM,SAAS,KAAK,MAAM,GAC3D,OAAO;EAAE,MAAM;EAAW,MAAM;EAAK,OAAO;CAAU;CAE1D,OAAO;EACH,MAAM;EACN,OAAO,MAAM,KAAK,SAAS,aACvB,aAAa,QAAQ,MAAM,OAC/B;CACJ;AACJ;;;;;;ACnKA,MAAa,8BAA8B;CACvC,UAAU;CACV,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,UAAU;CACV,YAAY;CACZ,eAAe;AACnB"}
package/dist/form.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { A as FieldErrorMatch, B as FieldValidation, C as FormErrors, D as bridgeForm, E as FormBridgeOptions, F as shownAfterChange, G as ValidateFieldOptions, H as FieldValidity, I as validatesOnChange, J as validateField, K as ValidityKey, L as CLEARED, M as fieldErrorShown, N as fieldDescribedBy, O as FieldState, P as FieldValidationMode, R as FieldValidate, S as guardFormSubmit, T as withoutFormErrors, U as UNVALIDATED, V as FieldValidator, W as VALIDITY_KEYS, _ as replaceOtp, a as TagRules, b as firstInDocumentOrder, c as takeTags, d as OtpValidationType, f as normalizeOtp, g as removeOtpCharacter, h as otpPattern, i as TagRefusal, j as fieldErrorMessages, k as fieldStateAttributes, l as typesDelimiter, m as otpInputMode, n as EditedTag, o as TakenTags, p as otpAccepts, q as createFieldValidator, r as RefusedTag, s as editTag, t as VISUALLY_HIDDEN_INPUT_STYLE, u as onSubmitAttempt, v as labelFocusTarget, w as formErrorsFor, x as focusFieldControl, y as preventLabelSelection, z as FieldValidateResult } from "./index-twgzPKvZ.js";
2
+ export { CLEARED, type EditedTag, type FieldErrorMatch, type FieldState, type FieldValidate, type FieldValidateResult, type FieldValidation, type FieldValidationMode, type FieldValidator, type FieldValidity, type FormBridgeOptions, type FormErrors, type OtpValidationType, type RefusedTag, type TagRefusal, type TagRules, type TakenTags, UNVALIDATED, VALIDITY_KEYS, VISUALLY_HIDDEN_INPUT_STYLE, type ValidateFieldOptions, type ValidityKey, bridgeForm, createFieldValidator, editTag, fieldDescribedBy, fieldErrorMessages, fieldErrorShown, fieldStateAttributes, firstInDocumentOrder, focusFieldControl, formErrorsFor, guardFormSubmit, labelFocusTarget, normalizeOtp, onSubmitAttempt, otpAccepts, otpInputMode, otpPattern, preventLabelSelection, removeOtpCharacter, replaceOtp, shownAfterChange, takeTags, typesDelimiter, validateField, validatesOnChange, withoutFormErrors };
package/dist/form.js ADDED
@@ -0,0 +1 @@
1
+ export { E as CLEARED, D as UNVALIDATED, O as VALIDITY_KEYS, t as VISUALLY_HIDDEN_INPUT_STYLE, y as bridgeForm, k as createFieldValidator, n as editTag, C as fieldDescribedBy, x as fieldErrorMessages, S as fieldErrorShown, b as fieldStateAttributes, m as firstInDocumentOrder, h as focusFieldControl, _ as formErrorsFor, g as guardFormSubmit, f as labelFocusTarget, o as normalizeOtp, a as onSubmitAttempt, s as otpAccepts, c as otpInputMode, l as otpPattern, p as preventLabelSelection, u as removeOtpCharacter, d as replaceOtp, w as shownAfterChange, r as takeTags, i as typesDelimiter, A as validateField, T as validatesOnChange, v as withoutFormErrors } from "./form-DovwKtqz.js";