@tempots/beatui 0.80.0 → 0.82.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 (112) hide show
  1. package/dist/{ar-DwHLVgKj.cjs → ar-D7CXDmVZ.cjs} +1 -1
  2. package/dist/{ar-Bo_FZZi7.js → ar-nOSKXpIW.js} +1 -1
  3. package/dist/auth/index.cjs.js +1 -1
  4. package/dist/auth/index.es.js +101 -99
  5. package/dist/beatui.css +393 -0
  6. package/dist/beatui.tailwind.css +393 -0
  7. package/dist/{de-zI5mdV4M.cjs → de-WzsOu9Gn.cjs} +1 -1
  8. package/dist/{de-CCqwOkqN.js → de-f2xcEb34.js} +1 -1
  9. package/dist/{deep-merge-1uN6CG6K.js → deep-merge-CiOwVWn8.js} +269 -284
  10. package/dist/deep-merge-DxZqCkE5.cjs +1 -0
  11. package/dist/{duration-input-C9kpsw-t.js → duration-input-B3vnnwBZ.js} +30 -29
  12. package/dist/duration-input-Dg5SX3lM.cjs +1 -0
  13. package/dist/{es-BF02UrPL.js → es-CDqqzpCw.js} +1 -1
  14. package/dist/{es-Cw90CAbu.cjs → es-Ds2Xf3wV.cjs} +1 -1
  15. package/dist/{fa-DPQV4YB8.js → fa-C7tE_hR3.js} +1 -1
  16. package/dist/{fa-B4lssnzR.cjs → fa-Ct1UtDB7.cjs} +1 -1
  17. package/dist/{fr-1Kd6z1F-.cjs → fr-CzAkRFed.cjs} +1 -1
  18. package/dist/{fr-dmxPhwkD.js → fr-yOW_68YY.js} +1 -1
  19. package/dist/{he-BtQbrVt3.js → he-D2oUloCJ.js} +1 -1
  20. package/dist/{he-CJ3XnuPm.cjs → he-DlXALrK7.cjs} +1 -1
  21. package/dist/{hi-BpfnFKHp.cjs → hi-3dBhLwDs.cjs} +1 -1
  22. package/dist/{hi-D_Le4Yka.js → hi-D5ZlZoQq.js} +1 -1
  23. package/dist/{index-CfaWytS2.cjs → index-C5YCCgnn.cjs} +1 -1
  24. package/dist/{index-K6u33-GC.cjs → index-ChsRjiIp.cjs} +17 -17
  25. package/dist/{index-CGEzILlC.js → index-CiAVfKIZ.js} +1 -1
  26. package/dist/{index-YtW7SCWB.js → index-DT6-HMMz.js} +8 -7
  27. package/dist/index.cjs.js +4 -4
  28. package/dist/index.es.js +296 -291
  29. package/dist/{it-DyHjSuHN.js → it-6e6X-4BB.js} +1 -1
  30. package/dist/{it-COCZ9NyB.cjs → it-DohtcWi9.cjs} +1 -1
  31. package/dist/{ja-X43lABza.js → ja-BxNuNo2H.js} +1 -1
  32. package/dist/{ja--NdggLU9.cjs → ja-eyTArrgS.cjs} +1 -1
  33. package/dist/json-schema/index.cjs.js +1 -8
  34. package/dist/json-schema/index.es.js +1391 -7471
  35. package/dist/json-schema-display/index.cjs.js +1 -0
  36. package/dist/json-schema-display/index.es.js +846 -0
  37. package/dist/json-structure/index.cjs.js +1 -1
  38. package/dist/json-structure/index.es.js +89 -87
  39. package/dist/{ko-BUvb0ggK.cjs → ko-BFLCDMMs.cjs} +1 -1
  40. package/dist/{ko-B9g9iw99.js → ko-Ch0jFsBV.js} +1 -1
  41. package/dist/modal-D2xE47kr.cjs +1 -0
  42. package/dist/{modal-CSHIhHvI.js → modal-hkQD1bqZ.js} +22 -21
  43. package/dist/{nl-0S25Gsld.cjs → nl-Bx2ACvr4.cjs} +1 -1
  44. package/dist/{nl-Ew5jnSsT.js → nl-NuTdZO1s.js} +1 -1
  45. package/dist/notice-C0SmlheE.cjs +1 -0
  46. package/dist/{notice-C-964yaY.js → notice-CZHWWwOQ.js} +52 -51
  47. package/dist/oneof-branch-detection-BVNoKU9d.js +6281 -0
  48. package/dist/oneof-branch-detection-C8g3eWnx.cjs +8 -0
  49. package/dist/{pl-C9f6UBSe.js → pl-Bs4nLJ__.js} +1 -1
  50. package/dist/{pl-B3k-K3S4.cjs → pl-QHl6sl8f.cjs} +1 -1
  51. package/dist/prosemirror/index.cjs.js +1 -1
  52. package/dist/prosemirror/index.es.js +1 -1
  53. package/dist/{pt-DYtAvbrw.js → pt-BETjHZrL.js} +1 -1
  54. package/dist/{pt-CKoikRO5.cjs → pt-DZGw2Z-1.cjs} +1 -1
  55. package/dist/{ru-ZexN-b8V.js → ru-Bi1_DEKM.js} +1 -1
  56. package/dist/{ru-COb7RSDt.cjs → ru-D03IuLqh.cjs} +1 -1
  57. package/dist/stack-BJgsPJ9A.js +873 -0
  58. package/dist/stack-DcZ_u50f.cjs +1 -0
  59. package/dist/string-B9vVyfq3.cjs +1 -0
  60. package/dist/string-DYyMxBl-.js +19 -0
  61. package/dist/text-input-CByq5OIo.cjs +1 -0
  62. package/dist/text-input-CFJntP7G.js +287 -0
  63. package/dist/{toolbar-DNpBIoJo.js → toolbar-DR2Zd4Oo.js} +1 -1
  64. package/dist/toolbar-TPWYzoiF.cjs +1 -0
  65. package/dist/{tr-tO_EH-Y2.cjs → tr-B_-_1wua.cjs} +1 -1
  66. package/dist/{tr-BDvn05-H.js → tr-DiYB-FwX.js} +1 -1
  67. package/dist/translations-B4-Zd2LM.cjs +1 -0
  68. package/dist/translations-Cq8bUKJP.js +584 -0
  69. package/dist/{translations-DwGC_94w.cjs → translations-D62qqNV9.cjs} +1 -1
  70. package/dist/{translations-CfWR4loD.js → translations-DPr6c05Z.js} +1 -1
  71. package/dist/types/components/json-schema/schema-conditionals.d.ts +11 -0
  72. package/dist/types/components/json-schema/schema-context.d.ts +1 -1
  73. package/dist/types/components/json-schema-display/display-widget-customization.d.ts +61 -0
  74. package/dist/types/components/json-schema-display/display-wrapper.d.ts +14 -0
  75. package/dist/types/components/json-schema-display/displays/any-display.d.ts +14 -0
  76. package/dist/types/components/json-schema-display/displays/array-display.d.ts +13 -0
  77. package/dist/types/components/json-schema-display/displays/boolean-display.d.ts +13 -0
  78. package/dist/types/components/json-schema-display/displays/composition-display.d.ts +14 -0
  79. package/dist/types/components/json-schema-display/displays/enum-const-display.d.ts +13 -0
  80. package/dist/types/components/json-schema-display/displays/generic-display.d.ts +18 -0
  81. package/dist/types/components/json-schema-display/displays/null-display.d.ts +13 -0
  82. package/dist/types/components/json-schema-display/displays/number-display.d.ts +13 -0
  83. package/dist/types/components/json-schema-display/displays/object-display.d.ts +13 -0
  84. package/dist/types/components/json-schema-display/displays/string-display.d.ts +14 -0
  85. package/dist/types/components/json-schema-display/index.d.ts +14 -0
  86. package/dist/types/components/json-schema-display/json-schema-display.d.ts +25 -0
  87. package/dist/types/components/json-schema-display/mismatch.d.ts +14 -0
  88. package/dist/types/json-schema-display/index.d.ts +1 -0
  89. package/dist/{ur-DbEqQgS6.js → ur-B69X-xNs.js} +1 -1
  90. package/dist/{ur-BbnYJ3HS.cjs → ur-DyUSmIbo.cjs} +1 -1
  91. package/dist/use-form-CgZyrACX.js +864 -0
  92. package/dist/use-form-JjeKCINk.cjs +2 -0
  93. package/dist/utils-DEbsp9Q9.js +129 -0
  94. package/dist/utils-DIUEhA-Z.cjs +1 -0
  95. package/dist/{vi-CpZUeuSj.js → vi-BdzxA60L.js} +1 -1
  96. package/dist/{vi-ByBwvGQY.cjs → vi-CBmPaHxg.cjs} +1 -1
  97. package/dist/widget-customization-DRA7E9Zf.js +1072 -0
  98. package/dist/widget-customization-G-QLB1rw.cjs +1 -0
  99. package/dist/{zh-DnxK0ieB.cjs → zh-Cb1b8uik.cjs} +1 -1
  100. package/dist/{zh-DJyhKO0I.js → zh-Dn1UJiZa.js} +1 -1
  101. package/package.json +13 -7
  102. package/dist/deep-merge-CBIkQM4E.cjs +0 -1
  103. package/dist/duration-input-DHWhQJnn.cjs +0 -1
  104. package/dist/modal-cc8Ehngz.cjs +0 -1
  105. package/dist/notice-C_BWqu2K.cjs +0 -1
  106. package/dist/toolbar-D5FcnRju.cjs +0 -1
  107. package/dist/translations-0tLX4x7M.js +0 -866
  108. package/dist/translations-WPN3ibDg.cjs +0 -1
  109. package/dist/use-form-D4JFOcjo.cjs +0 -2
  110. package/dist/use-form-D4rqJkvG.js +0 -1731
  111. package/dist/widget-customization-BSjJz3_Y.js +0 -1195
  112. package/dist/widget-customization-CrFVrt4V.cjs +0 -1
@@ -0,0 +1,873 @@
1
+ import { html as n, attr as o } from "@tempots/dom";
2
+ const r = {
3
+ /**
4
+ * Creates a loading state.
5
+ * @param previousValue - The previous value.
6
+ * @returns A loading state.
7
+ * @public
8
+ */
9
+ notAsked: { type: "NotAsked" },
10
+ /**
11
+ * Creates a loading state.
12
+ * @param previousValue - The previous value.
13
+ * @returns A loading state.
14
+ * @public
15
+ */
16
+ loading(s = void 0) {
17
+ return { type: "Loading", previousValue: s };
18
+ },
19
+ /**
20
+ * Creates a successful state.
21
+ * @param value - The value.
22
+ * @returns A successful state.
23
+ * @public
24
+ */
25
+ success(s) {
26
+ return { type: "AsyncSuccess", value: s };
27
+ },
28
+ /**
29
+ * Creates a failure state.
30
+ * @param error - The error.
31
+ * @returns A failure state.
32
+ * @public
33
+ */
34
+ failure(s) {
35
+ return { type: "AsyncFailure", error: s };
36
+ },
37
+ /**
38
+ * Checks if the result is a success.
39
+ * @param r - The result.
40
+ * @returns `true` if the result is a success; otherwise, `false`.
41
+ * @public
42
+ */
43
+ isSuccess(s) {
44
+ return s.type === "AsyncSuccess";
45
+ },
46
+ /**
47
+ * Checks if the result is a failure.
48
+ * @param r - The result.
49
+ * @returns `true` if the result is a failure; otherwise, `false`.
50
+ * @public
51
+ */
52
+ isFailure(s) {
53
+ return s.type === "AsyncFailure";
54
+ },
55
+ /**
56
+ * Checks if the result is a not-asked.
57
+ * @param r - The result.
58
+ * @returns `true` if the result is not-asked; otherwise, `false`.
59
+ * @public
60
+ */
61
+ isNotAsked(s) {
62
+ return s.type === "NotAsked";
63
+ },
64
+ /**
65
+ * Checks if the result is a loading.
66
+ * @param r - The result.
67
+ * @returns `true` if the result is loading; otherwise, `false`.
68
+ * @public
69
+ */
70
+ isLoading(s) {
71
+ return s.type === "Loading";
72
+ },
73
+ /**
74
+ * Gets the value if the result is a success; otherwise, returns the alternative value.
75
+ * @param r - The result.
76
+ * @param alt - The alternative value.
77
+ * @returns The value if the result is a success; otherwise, the alternative value.
78
+ * @public
79
+ */
80
+ getOrElse(s, e) {
81
+ return r.isSuccess(s) ? s.value : e;
82
+ },
83
+ /**
84
+ * Gets the value if the result is a success; otherwise, returns the value from the alternative function.
85
+ * @param r - The result.
86
+ * @param altf - The alternative function.
87
+ * @returns The value if the result is a success; otherwise, the value from the alternative
88
+ * @public
89
+ * function.
90
+ */
91
+ getOrElseLazy(s, e) {
92
+ return r.isSuccess(s) ? s.value : e();
93
+ },
94
+ /**
95
+ * Gets the value if the result is a success; otherwise, returns `null`.
96
+ * @param r - The result.
97
+ * @returns The value if the result is a success; otherwise, `null`.
98
+ * @public
99
+ */
100
+ getOrNull(s) {
101
+ return r.isSuccess(s) ? s.value : null;
102
+ },
103
+ /**
104
+ * Gets the value if the result is a success; otherwise, returns `undefined`.
105
+ * @param r - The result.
106
+ * @returns The value if the result is a success; otherwise, `undefined`.
107
+ * @public
108
+ */
109
+ getOrUndefined(s) {
110
+ return r.isSuccess(s) ? s.value : void 0;
111
+ },
112
+ /**
113
+ * Gets the value of a `AsyncResult` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
114
+ * @param r - The `AsyncResult` to get the value from.
115
+ * @returns The value of the `AsyncResult` if it is a `Success`.
116
+ */
117
+ getUnsafe: (s) => {
118
+ if (r.isSuccess(s))
119
+ return s.value;
120
+ throw r.isFailure(s) ? s.error : new Error("Cannot get value from a not-asked or loading result");
121
+ },
122
+ /**
123
+ * Based on the state of the result, it picks the appropriate function to call and returns the result.
124
+ * @param success - The function to call if the result is a success.
125
+ * @param failure - The function to call if the result is a failure.
126
+ * @param loading - The function to call if the result is loading.
127
+ * @param notAsked - The function to call if the result is not-asked.
128
+ * @returns The result of calling the appropriate function based on the state of the result.
129
+ * @public
130
+ */
131
+ match: (s, {
132
+ success: e,
133
+ failure: u,
134
+ loading: i,
135
+ notAsked: l = i
136
+ }) => r.isSuccess(s) ? e(s.value) : r.isFailure(s) ? u(s.error) : r.isNotAsked(s) ? l() : i(s.previousValue),
137
+ /**
138
+ * Executes side effects based on the state of the result.
139
+ * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
140
+ * The `else` handler is called when no specific handler is provided for the current state.
141
+ * @param r - The result.
142
+ * @param handlers - An object with optional handlers for each state and an optional `else` fallback.
143
+ * @returns The result that was passed in, allowing for chaining.
144
+ * @public
145
+ */
146
+ effect: (s, e) => {
147
+ switch (s.type) {
148
+ case "AsyncSuccess":
149
+ e.success ? e.success(s.value) : e.else?.();
150
+ break;
151
+ case "AsyncFailure":
152
+ e.failure ? e.failure(s.error) : e.else?.();
153
+ break;
154
+ case "Loading":
155
+ e.loading ? e.loading(s.previousValue) : e.else?.();
156
+ break;
157
+ case "NotAsked":
158
+ e.notAsked ? e.notAsked() : e.else?.();
159
+ break;
160
+ }
161
+ return s;
162
+ },
163
+ /**
164
+ * When the result is a success, it applies the function to the value.
165
+ *
166
+ * @param r - The result.
167
+ * @param apply - The function to apply.
168
+ * @returns The result that was passed in.
169
+ * @public
170
+ */
171
+ whenSuccess: (s, e) => (r.isSuccess(s) && e(s.value), s),
172
+ /**
173
+ * When the result is a failure, it applies the function to the error.
174
+ *
175
+ * @param r - The result.
176
+ * @param apply - The function to apply.
177
+ * @returns The result that was passed in.
178
+ * @public
179
+ */
180
+ whenFailure: (s, e) => (r.isFailure(s) && e(s.error), s),
181
+ /**
182
+ * Compares two results for equality.
183
+ * @param r1 - The first result.
184
+ * @param r2 - The second result.
185
+ * @param options - The options to use for comparison. By default, uses strict equality.
186
+ * @returns `true` if the results are equal, `false` otherwise.
187
+ */
188
+ equals: (s, e, u = {
189
+ valueEquals: (i, l) => i === l,
190
+ errorEquals: (i, l) => i === l
191
+ }) => s.type === "AsyncSuccess" && e.type === "AsyncSuccess" ? u.valueEquals(s.value, e.value) : s.type === "AsyncFailure" && e.type === "AsyncFailure" ? u.errorEquals(s.error, e.error) : s.type === "Loading" && e.type === "Loading" ? u.valueEquals(s.previousValue, e.previousValue) : s.type === "NotAsked" && e.type === "NotAsked",
192
+ /**
193
+ * Combines multiple results into a single result.
194
+ * @param results - The results to combine.
195
+ * @returns A single result that is a success if all the input results are successes, otherwise a failure.
196
+ */
197
+ all: (s) => {
198
+ const e = [];
199
+ for (const u of s)
200
+ if (r.isSuccess(u))
201
+ e.push(u.value);
202
+ else
203
+ return u;
204
+ return r.success(e);
205
+ },
206
+ /**
207
+ * Converts a Promise to an AsyncResult.
208
+ * @param p - The Promise to convert.
209
+ * @returns A Promise that resolves to an AsyncResult.
210
+ */
211
+ ofPromise: async (s) => {
212
+ try {
213
+ const e = await s;
214
+ return r.success(e);
215
+ } catch (e) {
216
+ return r.failure(e instanceof Error ? e : new Error(String(e)));
217
+ }
218
+ },
219
+ /**
220
+ * Maps the value of a successful `AsyncResult` to a new value using the provided function.
221
+ * For other states (NotAsked, Loading, Failure), the state is preserved.
222
+ * When mapping a Loading state with a previous value, the previous value is also mapped.
223
+ * @param result - The `AsyncResult` to map.
224
+ * @param fn - The mapping function to apply to the success value.
225
+ * @returns A new `AsyncResult` with the mapped value if successful, otherwise the original state.
226
+ * @public
227
+ */
228
+ map: (s, e) => {
229
+ switch (s.type) {
230
+ case "AsyncSuccess":
231
+ return r.success(e(s.value));
232
+ case "NotAsked":
233
+ return r.notAsked;
234
+ case "AsyncFailure":
235
+ return r.failure(s.error);
236
+ case "Loading":
237
+ return r.loading(
238
+ s.previousValue != null ? e(s.previousValue) : void 0
239
+ );
240
+ }
241
+ },
242
+ /**
243
+ * Maps the value of a successful `AsyncResult` to a new `AsyncResult` using the provided function.
244
+ * This is useful for chaining operations that may also fail.
245
+ * @param result - The `AsyncResult` to flat map.
246
+ * @param fn - The mapping function that returns a new `AsyncResult`.
247
+ * @returns The result of the mapping function if successful, otherwise the original state.
248
+ * @public
249
+ */
250
+ flatMap: (s, e) => {
251
+ switch (s.type) {
252
+ case "AsyncSuccess":
253
+ return e(s.value);
254
+ case "NotAsked":
255
+ return r.notAsked;
256
+ case "AsyncFailure":
257
+ return r.failure(s.error);
258
+ case "Loading":
259
+ return r.loading();
260
+ }
261
+ },
262
+ /**
263
+ * Maps the error of a failed `AsyncResult` to a new error using the provided function.
264
+ * For other states, the state is preserved.
265
+ * @param result - The `AsyncResult` to map the error of.
266
+ * @param fn - The mapping function to apply to the error.
267
+ * @returns A new `AsyncResult` with the mapped error if failed, otherwise the original state.
268
+ * @public
269
+ */
270
+ mapError: (s, e) => {
271
+ switch (s.type) {
272
+ case "AsyncSuccess":
273
+ return r.success(s.value);
274
+ case "NotAsked":
275
+ return r.notAsked;
276
+ case "AsyncFailure":
277
+ return r.failure(e(s.error));
278
+ case "Loading":
279
+ return r.loading(s.previousValue);
280
+ }
281
+ },
282
+ /**
283
+ * Maps the error of a failed `AsyncResult` to a new `AsyncResult` using the provided function.
284
+ * This allows recovery from errors by returning a new successful result.
285
+ * @param result - The `AsyncResult` to recover from.
286
+ * @param fn - The recovery function that returns a new `AsyncResult`.
287
+ * @returns The result of the recovery function if failed, otherwise the original state.
288
+ * @public
289
+ */
290
+ flatMapError: (s, e) => {
291
+ switch (s.type) {
292
+ case "AsyncSuccess":
293
+ return r.success(s.value);
294
+ case "NotAsked":
295
+ return r.notAsked;
296
+ case "AsyncFailure":
297
+ return e(s.error);
298
+ case "Loading":
299
+ return r.loading(s.previousValue);
300
+ }
301
+ },
302
+ /**
303
+ * Converts an `AsyncResult` to a `Result`, discarding the loading and not-asked states.
304
+ * Returns `undefined` if the result is not settled (i.e., NotAsked or Loading).
305
+ * @param result - The `AsyncResult` to convert.
306
+ * @returns A `Result` if the `AsyncResult` is settled, otherwise `undefined`.
307
+ * @public
308
+ */
309
+ toResult: (s) => {
310
+ switch (s.type) {
311
+ case "AsyncSuccess":
312
+ return { type: "Success", value: s.value };
313
+ case "AsyncFailure":
314
+ return { type: "Failure", error: s.error };
315
+ case "NotAsked":
316
+ case "Loading":
317
+ return;
318
+ }
319
+ },
320
+ /**
321
+ * Checks if the result is settled (either success or failure).
322
+ * @param r - The result.
323
+ * @returns `true` if the result is settled; otherwise, `false`.
324
+ * @public
325
+ */
326
+ isSettled(s) {
327
+ return s.type === "AsyncSuccess" || s.type === "AsyncFailure";
328
+ },
329
+ /**
330
+ * Recovers from a failure by providing an alternative value.
331
+ * @param result - The `AsyncResult` to recover from.
332
+ * @param fn - The function that provides an alternative value given the error.
333
+ * @returns A successful `AsyncResult` with the alternative value if failed, otherwise the original state.
334
+ * @public
335
+ */
336
+ recover: (s, e) => {
337
+ switch (s.type) {
338
+ case "AsyncSuccess":
339
+ return r.success(s.value);
340
+ case "NotAsked":
341
+ return r.notAsked;
342
+ case "AsyncFailure":
343
+ return r.success(e(s.error));
344
+ case "Loading":
345
+ return r.loading(s.previousValue);
346
+ }
347
+ },
348
+ /**
349
+ * Applies a function wrapped in an `AsyncResult` to a value wrapped in an `AsyncResult`.
350
+ * Useful for applying multiple arguments to a function in a safe way.
351
+ * @param resultFn - The `AsyncResult` containing the function.
352
+ * @param resultVal - The `AsyncResult` containing the value.
353
+ * @returns A new `AsyncResult` with the result of applying the function to the value.
354
+ * @public
355
+ */
356
+ ap: (s, e) => r.isSuccess(s) && r.isSuccess(e) ? r.success(s.value(e.value)) : r.isFailure(s) ? r.failure(s.error) : r.isFailure(e) ? r.failure(e.error) : r.isLoading(s) || r.isLoading(e) ? r.loading() : r.notAsked,
357
+ /**
358
+ * Maps two `AsyncResult` values using a function.
359
+ * @param r1 - The first `AsyncResult`.
360
+ * @param r2 - The second `AsyncResult`.
361
+ * @param fn - The function to apply to both values.
362
+ * @returns A new `AsyncResult` with the result of applying the function to both values.
363
+ * @public
364
+ */
365
+ map2: (s, e, u) => r.isSuccess(s) && r.isSuccess(e) ? r.success(u(s.value, e.value)) : r.isFailure(s) ? r.failure(s.error) : r.isFailure(e) ? r.failure(e.error) : r.isLoading(s) || r.isLoading(e) ? r.loading() : r.notAsked,
366
+ /**
367
+ * Maps three `AsyncResult` values using a function.
368
+ * @param r1 - The first `AsyncResult`.
369
+ * @param r2 - The second `AsyncResult`.
370
+ * @param r3 - The third `AsyncResult`.
371
+ * @param fn - The function to apply to all three values.
372
+ * @returns A new `AsyncResult` with the result of applying the function to all three values.
373
+ * @public
374
+ */
375
+ map3: (s, e, u, i) => r.isSuccess(s) && r.isSuccess(e) && r.isSuccess(u) ? r.success(i(s.value, e.value, u.value)) : r.isFailure(s) ? r.failure(s.error) : r.isFailure(e) ? r.failure(e.error) : r.isFailure(u) ? r.failure(u.error) : r.isLoading(s) || r.isLoading(e) || r.isLoading(u) ? r.loading() : r.notAsked
376
+ }, c = {
377
+ /**
378
+ * Creates a valid `Validation`.
379
+ * @returns A `Validation` that is `Valid`.
380
+ */
381
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
382
+ valid: { type: "valid" },
383
+ /**
384
+ * Creates an invalid `Validation`.
385
+ * @param error - The error associated with the invalid value.
386
+ * @returns A `Validation` that is `Invalid`.
387
+ */
388
+ invalid(s) {
389
+ return { type: "invalid", error: s };
390
+ },
391
+ /**
392
+ * Checks if a `Validation` is `Valid`.
393
+ * @param r - The `Validation` to check.
394
+ * @returns `true` if the `Validation` is `Valid`, otherwise `false`.
395
+ */
396
+ isValid(s) {
397
+ return s.type === "valid";
398
+ },
399
+ /**
400
+ * Checks if a `Validation` is `Invalid`.
401
+ * @param r - The `Validation` to check.
402
+ * @returns `true` if the `Validation` is `Invalid`, otherwise `false`.
403
+ */
404
+ isInvalid(s) {
405
+ return s.type === "invalid";
406
+ },
407
+ /**
408
+ * Maps the value of a `Validation` to a new value.
409
+ * @param r - The `Validation` to map.
410
+ * @param valid - The mapping function for a valid value.
411
+ * @param invalid - The mapping function for an invalid value.
412
+ * @returns The mapped value.
413
+ */
414
+ match: (s, e, u) => c.isValid(s) ? e() : u(s.error),
415
+ /**
416
+ * Maps the value of a `Validation` to a new `Validation`.
417
+ * @param validation - The `Validation` to map.
418
+ * @param value - The value to map.
419
+ * @returns A new `Validation` with the mapped value.
420
+ */
421
+ toResult: (s, e) => c.match(
422
+ s,
423
+ () => a.success(e),
424
+ (u) => a.failure(u)
425
+ ),
426
+ /**
427
+ * Executes side effects based on the state of the validation.
428
+ * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
429
+ * The `else` handler is called when no specific handler is provided for the current state.
430
+ * @param v - The validation.
431
+ * @param handlers - An object with optional handlers for each state and an optional `else` fallback.
432
+ * @returns The validation that was passed in, allowing for chaining.
433
+ * @public
434
+ */
435
+ effect: (s, e) => (s.type === "valid" ? e.valid ? e.valid() : e.else?.() : e.invalid ? e.invalid(s.error) : e.else?.(), s),
436
+ /**
437
+ * Execute a function when the `Validation` is valid.
438
+ *
439
+ * @param r - The `Validation` to check.
440
+ * @param apply - The function to execute when the `Validation` is valid.
441
+ * @returns The `Validation` object.
442
+ */
443
+ whenValid: (s, e) => (c.isValid(s) && e(), s),
444
+ /**
445
+ * Execute a function when the `Validation` is invalid.
446
+ *
447
+ * @param r - The `Validation` to check.
448
+ * @param apply - The function to execute when the `Validation` is invalid.
449
+ * @returns The `Validation` object.
450
+ */
451
+ whenInvalid: (s, e) => (c.isInvalid(s) && e(s.error), s),
452
+ /**
453
+ * Maps the error of an invalid `Validation` to a new error using the provided function.
454
+ * For valid validations, the validation is preserved unchanged.
455
+ * @param v - The `Validation` to map the error of.
456
+ * @param f - The mapping function to apply to the error.
457
+ * @returns A new `Validation` with the mapped error if invalid, otherwise the original valid.
458
+ * @public
459
+ */
460
+ mapError: (s, e) => s.type === "invalid" ? c.invalid(e(s.error)) : s,
461
+ /**
462
+ * Maps the error of an invalid `Validation` to a new `Validation` using the provided function.
463
+ * This allows recovery from errors by returning a valid validation.
464
+ * @param v - The `Validation` to recover from.
465
+ * @param f - The recovery function that returns a new `Validation`.
466
+ * @returns The result of the recovery function if invalid, otherwise the original valid.
467
+ * @public
468
+ */
469
+ flatMapError: (s, e) => s.type === "invalid" ? e(s.error) : s,
470
+ /**
471
+ * Combines two validations. Both must be valid for the result to be valid.
472
+ * If both are invalid, errors are combined using the provided function.
473
+ * @param v1 - The first validation.
474
+ * @param v2 - The second validation.
475
+ * @param combineErrors - The function to combine two errors.
476
+ * @returns A combined validation.
477
+ * @public
478
+ */
479
+ combine: (s, e, u) => c.isValid(s) && c.isValid(e) ? c.valid : c.isInvalid(s) && c.isInvalid(e) ? c.invalid(u(s.error, e.error)) : c.isInvalid(s) ? s : e,
480
+ /**
481
+ * Combines multiple validations into a single validation.
482
+ * All must be valid for the result to be valid.
483
+ * Returns the first invalid validation if any.
484
+ * @param validations - The validations to combine.
485
+ * @returns A single validation that is valid only if all inputs are valid.
486
+ * @public
487
+ */
488
+ all: (s) => {
489
+ for (const e of s)
490
+ if (c.isInvalid(e))
491
+ return e;
492
+ return c.valid;
493
+ },
494
+ /**
495
+ * Combines multiple validations, accumulating all errors.
496
+ * All must be valid for the result to be valid.
497
+ * If any are invalid, all errors are collected into an array.
498
+ * @param validations - The validations to combine.
499
+ * @returns A validation that is valid only if all inputs are valid, otherwise contains all errors.
500
+ * @public
501
+ */
502
+ allErrors: (s) => {
503
+ const e = [];
504
+ for (const u of s)
505
+ c.isInvalid(u) && e.push(u.error);
506
+ return e.length > 0 ? c.invalid(e) : c.valid;
507
+ },
508
+ /**
509
+ * Compares two validations for equality.
510
+ * @param v1 - The first validation.
511
+ * @param v2 - The second validation.
512
+ * @param errorEquals - Optional custom equality function for errors. Defaults to strict equality.
513
+ * @returns `true` if the validations are equal, `false` otherwise.
514
+ * @public
515
+ */
516
+ equals: (s, e, u = (i, l) => i === l) => s.type === "valid" && e.type === "valid" ? !0 : s.type === "invalid" && e.type === "invalid" ? u(s.error, e.error) : !1,
517
+ /**
518
+ * Recovers from an invalid validation by returning a valid validation.
519
+ * @param v - The `Validation` to recover from.
520
+ * @returns A valid validation regardless of the input.
521
+ * @public
522
+ */
523
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
524
+ recover: (s) => c.valid,
525
+ /**
526
+ * Gets the error if the validation is invalid, otherwise returns undefined.
527
+ * @param v - The validation to get the error from.
528
+ * @returns The error if invalid, otherwise undefined.
529
+ * @public
530
+ */
531
+ getError: (s) => {
532
+ if (c.isInvalid(s))
533
+ return s.error;
534
+ },
535
+ /**
536
+ * Gets the error if the validation is invalid, otherwise returns the default value.
537
+ * @param v - The validation to get the error from.
538
+ * @param defaultError - The default error to return if valid.
539
+ * @returns The error if invalid, otherwise the default error.
540
+ * @public
541
+ */
542
+ getErrorOrElse: (s, e) => c.isInvalid(s) ? s.error : e
543
+ }, a = {
544
+ /**
545
+ * Creates a successful `Result`.
546
+ * @param value - The value to wrap in a `Success` type.
547
+ * @returns A `Result` that is a `Success`.
548
+ * @public
549
+ */
550
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
551
+ success(s) {
552
+ return { type: "Success", value: s };
553
+ },
554
+ /**
555
+ * Creates a failure `Result`.
556
+ * @param error - The error to wrap in a `Failure` type.
557
+ * @returns A `Result` that is a `Failure`.
558
+ * @public
559
+ */
560
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
561
+ failure(s) {
562
+ return { type: "Failure", error: s };
563
+ },
564
+ /**
565
+ * Maps the value of a `Result` to a new value.
566
+ * @param r - The `Result` to map.
567
+ * @param f - The mapping function.
568
+ * @returns A new `Result` with the mapped value.
569
+ * @public
570
+ */
571
+ map: (s, e) => s.type === "Success" ? a.success(e(s.value)) : s,
572
+ /**
573
+ * Maps the value of a `Result` to a new `Result`.
574
+ * @param r - The `Result` to map.
575
+ * @param f - The mapping function.
576
+ * @returns A new `Result` with the mapped value.
577
+ * @public
578
+ */
579
+ flatMap: (s, e) => s.type === "Success" ? e(s.value) : s,
580
+ /**
581
+ * Converts a `Result` to an `AsyncResult`.
582
+ * @param r - The `Result` to convert.
583
+ * @returns An `AsyncResult` that is equivalent to the input `Result`.
584
+ * @public
585
+ */
586
+ toAsync(s) {
587
+ return a.match(
588
+ s,
589
+ (e) => r.success(e),
590
+ (e) => r.failure(e)
591
+ );
592
+ },
593
+ /**
594
+ * Converts a `Result` to a `Validation`.
595
+ * @param r - The `Result` to convert.
596
+ * @returns A `Validation` that is equivalent to the input `Result`.
597
+ * @public
598
+ */
599
+ toValidation(s) {
600
+ return a.match(
601
+ s,
602
+ () => c.valid,
603
+ (e) => c.invalid(e)
604
+ );
605
+ },
606
+ /**
607
+ * Checks if a `Result` is a success.
608
+ * @param r - The `Result` to check.
609
+ * @returns `true` if the `Result` is a `Success`, `false` otherwise.
610
+ * @public
611
+ */
612
+ isSuccess(s) {
613
+ return s.type === "Success";
614
+ },
615
+ /**
616
+ * Checks if a `Result` is a failure.
617
+ * @param r - The `Result` to check.
618
+ * @returns `true` if the `Result` is a `Failure`, `false` otherwise.
619
+ * @public
620
+ */
621
+ isFailure(s) {
622
+ return s.type === "Failure";
623
+ },
624
+ /**
625
+ * Gets the value of a `Result` if it is a `Success`, otherwise returns the provided default value.
626
+ * @param r - The `Result` to get the value from.
627
+ * @param alt - The default value to return if the `Result` is a `Failure`.
628
+ * @returns The value of the `Result` if it is a `Success`, otherwise the default value.
629
+ * @public
630
+ */
631
+ getOrElse(s, e) {
632
+ return a.isSuccess(s) ? s.value : e;
633
+ },
634
+ /**
635
+ * Gets the value of a `Result` if it is a `Success`, otherwise returns the result of the provided function.
636
+ * @param r - The `Result` to get the value from.
637
+ * @param altf - The function to call if the `Result` is a `Failure`.
638
+ * @returns The value of the `Result` if it is a `Success`, otherwise the result of the function.
639
+ * @public
640
+ */
641
+ getOrElseLazy(s, e) {
642
+ return a.isSuccess(s) ? s.value : e();
643
+ },
644
+ /**
645
+ * Gets the value of a `Result` if it is a `Success`, otherwise returns `null`.
646
+ * @param r - The `Result` to get the value from.
647
+ * @returns The value of the `Result` if it is a `Success`, otherwise `null`.
648
+ * @public
649
+ */
650
+ getOrNull(s) {
651
+ return a.isSuccess(s) ? s.value : null;
652
+ },
653
+ /**
654
+ * Gets the value of a `Result` if it is a `Success`, otherwise returns `undefined`.
655
+ * @param r - The `Result` to get the value from.
656
+ * @returns The value of the `Result` if it is a `Success`, otherwise `undefined`.
657
+ * @public
658
+ */
659
+ getOrUndefined(s) {
660
+ return a.isSuccess(s) ? s.value : void 0;
661
+ },
662
+ /**
663
+ * Gets the value of a `Result` if it is a `Success`, otherwise it throws the error contained in the `Failure`.
664
+ * @param r - The `Result` to get the value from.
665
+ * @returns The value of the `Result` if it is a `Success`.
666
+ */
667
+ getUnsafe: (s) => {
668
+ if (a.isSuccess(s))
669
+ return s.value;
670
+ throw s.error;
671
+ },
672
+ /**
673
+ * Based on the state of the result, it picks the appropriate function to call and returns the result.
674
+ * @param success - The function to call if the result is a success.
675
+ * @param failure - The function to call if the result is a failure.
676
+ * @returns The result of calling the appropriate function based on the state of the result.
677
+ * @public
678
+ */
679
+ match: (s, e, u) => a.isSuccess(s) ? e(s.value) : u(s.error),
680
+ /**
681
+ * Executes side effects based on the state of the result.
682
+ * Unlike `match`, all handlers are optional, allowing you to react only to specific states.
683
+ * The `else` handler is called when no specific handler is provided for the current state.
684
+ * @param r - The result.
685
+ * @param handlers - An object with optional handlers for each state and an optional `else` fallback.
686
+ * @returns The result that was passed in, allowing for chaining.
687
+ * @public
688
+ */
689
+ effect: (s, e) => (s.type === "Success" ? e.success ? e.success(s.value) : e.else?.() : e.failure ? e.failure(s.error) : e.else?.(), s),
690
+ /**
691
+ * Calls the provided function if the result is a success.
692
+ * @param apply - The function to call if the result is a success.
693
+ * @returns A function that takes a `Result` and calls the provided function if the result is a success.
694
+ * @public
695
+ */
696
+ whenSuccess: (s, e) => (a.isSuccess(s) && e(s.value), s),
697
+ /**
698
+ * Calls the provided function if the result is a failure.
699
+ * @param apply - The function to call if the result is a failure.
700
+ * @returns The result that was passed in.
701
+ * @public
702
+ */
703
+ whenFailure: (s, e) => (a.isFailure(s) && e(s.error), s),
704
+ /**
705
+ * Combines two results into a single result.
706
+ * @param r1 - The first result.
707
+ * @param r2 - The second result.
708
+ * @param combineV - The function to combine two values.
709
+ * @param combineE - The function to combine two errors.
710
+ * @returns The combined result.
711
+ * @public
712
+ */
713
+ combine: (s, e, u, i) => a.match(
714
+ s,
715
+ (l) => a.match(
716
+ e,
717
+ (t) => a.success(u(l, t)),
718
+ (t) => a.failure(t)
719
+ ),
720
+ (l) => a.match(
721
+ e,
722
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
723
+ (t) => a.failure(l),
724
+ (t) => a.failure(i(l, t))
725
+ )
726
+ ),
727
+ /**
728
+ * Compares two results for equality.
729
+ * @param r1 - The first result.
730
+ * @param r2 - The second result.
731
+ * @param options - The options to use for comparison. By default, uses strict equality.
732
+ * @returns `true` if the results are equal, `false` otherwise.
733
+ */
734
+ equals: (s, e, u = {
735
+ valueEquals: (i, l) => i === l,
736
+ errorEquals: (i, l) => i === l
737
+ }) => s.type === "Success" && e.type === "Success" ? u.valueEquals(s.value, e.value) : s.type === "Failure" && e.type === "Failure" ? u.errorEquals(s.error, e.error) : !1,
738
+ /**
739
+ * Combines multiple results into a single result.
740
+ * @param results - The results to combine.
741
+ * @returns A single result that is a success if all the input results are successes, otherwise a failure.
742
+ */
743
+ all: (s) => {
744
+ const e = [];
745
+ for (const u of s)
746
+ if (a.isSuccess(u))
747
+ e.push(u.value);
748
+ else
749
+ return u;
750
+ return a.success(e);
751
+ },
752
+ /**
753
+ * Maps the error of a failed `Result` to a new error using the provided function.
754
+ * For success results, the result is preserved unchanged.
755
+ * @param r - The `Result` to map the error of.
756
+ * @param f - The mapping function to apply to the error.
757
+ * @returns A new `Result` with the mapped error if failed, otherwise the original success.
758
+ * @public
759
+ */
760
+ mapError: (s, e) => s.type === "Failure" ? a.failure(e(s.error)) : s,
761
+ /**
762
+ * Maps the error of a failed `Result` to a new `Result` using the provided function.
763
+ * This allows recovery from errors by returning a new successful result.
764
+ * @param r - The `Result` to recover from.
765
+ * @param f - The recovery function that returns a new `Result`.
766
+ * @returns The result of the recovery function if failed, otherwise the original success.
767
+ * @public
768
+ */
769
+ flatMapError: (s, e) => s.type === "Failure" ? e(s.error) : s,
770
+ /**
771
+ * Recovers from a failure by providing an alternative value.
772
+ * @param r - The `Result` to recover from.
773
+ * @param f - The function that provides an alternative value given the error.
774
+ * @returns A successful `Result` with the alternative value if failed, otherwise the original success.
775
+ * @public
776
+ */
777
+ recover: (s, e) => s.type === "Failure" ? { type: "Success", value: e(s.error) } : s,
778
+ /**
779
+ * Applies a function wrapped in a `Result` to a value wrapped in a `Result`.
780
+ * Useful for applying multiple arguments to a function in a safe way.
781
+ * @param resultFn - The `Result` containing the function.
782
+ * @param resultVal - The `Result` containing the value.
783
+ * @returns A new `Result` with the result of applying the function to the value.
784
+ * @public
785
+ */
786
+ ap: (s, e) => a.isSuccess(s) && a.isSuccess(e) ? a.success(s.value(e.value)) : a.isFailure(s) ? a.failure(s.error) : a.failure(e.error),
787
+ /**
788
+ * Maps two `Result` values using a function.
789
+ * @param r1 - The first `Result`.
790
+ * @param r2 - The second `Result`.
791
+ * @param f - The function to apply to both values.
792
+ * @returns A new `Result` with the result of applying the function to both values.
793
+ * @public
794
+ */
795
+ map2: (s, e, u) => a.isSuccess(s) && a.isSuccess(e) ? a.success(u(s.value, e.value)) : a.isFailure(s) ? a.failure(s.error) : a.failure(e.error),
796
+ /**
797
+ * Maps three `Result` values using a function.
798
+ * @param r1 - The first `Result`.
799
+ * @param r2 - The second `Result`.
800
+ * @param r3 - The third `Result`.
801
+ * @param f - The function to apply to all three values.
802
+ * @returns A new `Result` with the result of applying the function to all three values.
803
+ * @public
804
+ */
805
+ map3: (s, e, u, i) => a.isSuccess(s) && a.isSuccess(e) && a.isSuccess(u) ? a.success(i(s.value, e.value, u.value)) : a.isFailure(s) ? a.failure(s.error) : a.isFailure(e) ? a.failure(e.error) : a.failure(u.error),
806
+ /**
807
+ * Converts a Promise to a Result.
808
+ * @param p - The Promise to convert.
809
+ * @returns A Promise that resolves to a Result.
810
+ * @public
811
+ */
812
+ ofPromise: async (s) => {
813
+ try {
814
+ const e = await s;
815
+ return a.success(e);
816
+ } catch (e) {
817
+ return a.failure(e instanceof Error ? e : new Error(String(e)));
818
+ }
819
+ },
820
+ /**
821
+ * Swaps the success and failure values of a Result.
822
+ * A success becomes a failure with the value as the error,
823
+ * and a failure becomes a success with the error as the value.
824
+ * @param r - The Result to swap.
825
+ * @returns A new Result with swapped success and failure.
826
+ * @public
827
+ */
828
+ swap: (s) => a.isSuccess(s) ? a.failure(s.value) : a.success(s.error),
829
+ /**
830
+ * Converts a nullable value to a Result.
831
+ * @param value - The nullable value.
832
+ * @param error - The error to use if the value is null or undefined.
833
+ * @returns A Result containing the value if not null/undefined, otherwise a failure.
834
+ * @public
835
+ */
836
+ fromNullable: (s, e) => s == null ? a.failure(e) : a.success(s),
837
+ /**
838
+ * Converts a nullable value to a Result using a lazy error function.
839
+ * @param value - The nullable value.
840
+ * @param errorFn - The function to call to get the error if the value is null or undefined.
841
+ * @returns A Result containing the value if not null/undefined, otherwise a failure.
842
+ * @public
843
+ */
844
+ fromNullableLazy: (s, e) => s == null ? a.failure(e()) : a.success(s),
845
+ /**
846
+ * Wraps a function that may throw into a function that returns a Result.
847
+ * @param f - The function that may throw.
848
+ * @returns A function that returns a Result instead of throwing.
849
+ * @public
850
+ */
851
+ tryCatch: (s) => {
852
+ try {
853
+ return a.success(s());
854
+ } catch (e) {
855
+ return a.failure(e instanceof Error ? e : new Error(String(e)));
856
+ }
857
+ }
858
+ };
859
+ function d(s) {
860
+ return `bc-label bc-label--${s}`;
861
+ }
862
+ const p = (...s) => n.span(o.class(d("emphasis")), ...s), y = (...s) => n.span(o.class(d("default")), ...s), f = (...s) => n.span(o.class(d("muted")), ...s), S = (...s) => n.span(o.class(d("danger")), ...s);
863
+ function g(...s) {
864
+ return n.div(o.class("bc-stack"), ...s);
865
+ }
866
+ export {
867
+ S as D,
868
+ p as E,
869
+ y as L,
870
+ f as M,
871
+ g as S,
872
+ c as i
873
+ };