@brainfish-ai/components 0.20.6 → 0.21.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 (51) hide show
  1. package/dist/badge.d.ts +1 -1
  2. package/dist/chat-search.d.ts +12 -1
  3. package/dist/convos.d.ts +1 -1
  4. package/dist/esm/chunks/{ChatSearch.Bad4C07E.js → ChatSearch.CNS7ZOgA.js} +13 -3
  5. package/dist/esm/chunks/ChatSearch.CNS7ZOgA.js.map +1 -0
  6. package/dist/esm/chunks/FormattedMessage.ieoe4jPf.js.map +1 -1
  7. package/dist/esm/chunks/{chart.DGCX9VIn.js → chart.CTzWtshH.js} +40 -61
  8. package/dist/esm/chunks/chart.CTzWtshH.js.map +1 -0
  9. package/dist/esm/chunks/combobox.DNYCWyub.js.map +1 -1
  10. package/dist/esm/chunks/font-picker.DX1mER3H.js.map +1 -1
  11. package/dist/esm/chunks/hooks.CKojclfe.js.map +1 -1
  12. package/dist/esm/chunks/review-list.jCfkezEr.js +72 -0
  13. package/dist/esm/chunks/review-list.jCfkezEr.js.map +1 -0
  14. package/dist/esm/chunks/status-badge.DkPNh30S.js +952 -0
  15. package/dist/esm/chunks/status-badge.DkPNh30S.js.map +1 -0
  16. package/dist/esm/components/chart-area-linear.js +1 -1
  17. package/dist/esm/components/chart-radial-stacked.js +1 -1
  18. package/dist/esm/components/chat-search.js +1 -1
  19. package/dist/esm/components/convos.js +6 -30
  20. package/dist/esm/components/convos.js.map +1 -1
  21. package/dist/esm/components/ui/alert-dialog.js +22 -54
  22. package/dist/esm/components/ui/alert-dialog.js.map +1 -1
  23. package/dist/esm/components/ui/alert.js +47 -64
  24. package/dist/esm/components/ui/alert.js.map +1 -1
  25. package/dist/esm/components/ui/badge.js +1 -1
  26. package/dist/esm/components/ui/badge.js.map +1 -1
  27. package/dist/esm/components/ui/calendar.js +1 -6
  28. package/dist/esm/components/ui/calendar.js.map +1 -1
  29. package/dist/esm/components/ui/command.js +19 -42
  30. package/dist/esm/components/ui/command.js.map +1 -1
  31. package/dist/esm/components/ui/dialog.js +13 -40
  32. package/dist/esm/components/ui/dialog.js.map +1 -1
  33. package/dist/esm/components/ui/dropdown-menu.js +5 -25
  34. package/dist/esm/components/ui/dropdown-menu.js.map +1 -1
  35. package/dist/esm/components/ui/item.js +8 -46
  36. package/dist/esm/components/ui/item.js.map +1 -1
  37. package/dist/esm/components/ui/sheet.js +17 -53
  38. package/dist/esm/components/ui/sheet.js.map +1 -1
  39. package/dist/esm/global.css +1 -1
  40. package/dist/esm/index.js +2 -1
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/scenes/knowledge-review/review-list.js +2 -0
  43. package/dist/esm/scenes/knowledge-review/review-list.js.map +1 -0
  44. package/dist/index.d.ts +65 -11
  45. package/dist/item.d.ts +9 -9
  46. package/dist/review-list.d.ts +47 -0
  47. package/dist/scenes/knowledge-review/review-list.d.ts +2 -0
  48. package/dist/stats.html +1 -1
  49. package/package.json +9 -5
  50. package/dist/esm/chunks/ChatSearch.Bad4C07E.js.map +0 -1
  51. package/dist/esm/chunks/chart.DGCX9VIn.js.map +0 -1
@@ -0,0 +1,952 @@
1
+ import React__default from 'react';
2
+ import { Circle } from '@phosphor-icons/react';
3
+ import { Badge } from '../components/ui/badge.js';
4
+ import { c as cn } from './utils.Cwtlq8dh.js';
5
+
6
+ /**
7
+ * @module constants
8
+ * @summary Useful constants
9
+ * @description
10
+ * Collection of useful date constants.
11
+ *
12
+ * The constants could be imported from `date-fns/constants`:
13
+ *
14
+ * ```ts
15
+ * import { maxTime, minTime } from "./constants/date-fns/constants";
16
+ *
17
+ * function isAllowedTime(time) {
18
+ * return time <= maxTime && time >= minTime;
19
+ * }
20
+ * ```
21
+ */
22
+
23
+
24
+ /**
25
+ * @constant
26
+ * @name daysInYear
27
+ * @summary Days in 1 year.
28
+ *
29
+ * @description
30
+ * How many days in a year.
31
+ *
32
+ * One years equals 365.2425 days according to the formula:
33
+ *
34
+ * > Leap year occurs every 4 years, except for years that are divisible by 100 and not divisible by 400.
35
+ * > 1 mean year = (365+1/4-1/100+1/400) days = 365.2425 days
36
+ */
37
+ const daysInYear = 365.2425;
38
+
39
+ /**
40
+ * @constant
41
+ * @name millisecondsInWeek
42
+ * @summary Milliseconds in 1 week.
43
+ */
44
+ const millisecondsInWeek = 604800000;
45
+
46
+ /**
47
+ * @constant
48
+ * @name millisecondsInDay
49
+ * @summary Milliseconds in 1 day.
50
+ */
51
+ const millisecondsInDay = 86400000;
52
+
53
+ /**
54
+ * @constant
55
+ * @name millisecondsInMinute
56
+ * @summary Milliseconds in 1 minute
57
+ */
58
+ const millisecondsInMinute = 60000;
59
+
60
+ /**
61
+ * @constant
62
+ * @name millisecondsInHour
63
+ * @summary Milliseconds in 1 hour
64
+ */
65
+ const millisecondsInHour = 3600000;
66
+
67
+ /**
68
+ * @constant
69
+ * @name secondsInHour
70
+ * @summary Seconds in 1 hour.
71
+ */
72
+ const secondsInHour = 3600;
73
+
74
+ /**
75
+ * @constant
76
+ * @name secondsInMinute
77
+ * @summary Seconds in 1 minute.
78
+ */
79
+ const secondsInMinute = 60;
80
+
81
+ /**
82
+ * @constant
83
+ * @name secondsInDay
84
+ * @summary Seconds in 1 day.
85
+ */
86
+ const secondsInDay = secondsInHour * 24;
87
+
88
+ /**
89
+ * @constant
90
+ * @name secondsInWeek
91
+ * @summary Seconds in 1 week.
92
+ */
93
+ const secondsInWeek = secondsInDay * 7;
94
+
95
+ /**
96
+ * @constant
97
+ * @name secondsInYear
98
+ * @summary Seconds in 1 year.
99
+ */
100
+ const secondsInYear = secondsInDay * daysInYear;
101
+
102
+ /**
103
+ * @constant
104
+ * @name secondsInMonth
105
+ * @summary Seconds in 1 month
106
+ */
107
+ const secondsInMonth = secondsInYear / 12;
108
+
109
+ /**
110
+ * @constant
111
+ * @name secondsInQuarter
112
+ * @summary Seconds in 1 quarter.
113
+ */
114
+ const secondsInQuarter = secondsInMonth * 3;
115
+
116
+ /**
117
+ * @constant
118
+ * @name constructFromSymbol
119
+ * @summary Symbol enabling Date extensions to inherit properties from the reference date.
120
+ *
121
+ * The symbol is used to enable the `constructFrom` function to construct a date
122
+ * using a reference date and a value. It allows to transfer extra properties
123
+ * from the reference date to the new date. It's useful for extensions like
124
+ * [`TZDate`](https://github.com/date-fns/tz) that accept a time zone as
125
+ * a constructor argument.
126
+ */
127
+ const constructFromSymbol = Symbol.for("constructDateFrom");
128
+
129
+ /**
130
+ * @name constructFrom
131
+ * @category Generic Helpers
132
+ * @summary Constructs a date using the reference date and the value
133
+ *
134
+ * @description
135
+ * The function constructs a new date using the constructor from the reference
136
+ * date and the given value. It helps to build generic functions that accept
137
+ * date extensions.
138
+ *
139
+ * It defaults to `Date` if the passed reference date is a number or a string.
140
+ *
141
+ * Starting from v3.7.0, it allows to construct a date using `[Symbol.for("constructDateFrom")]`
142
+ * enabling to transfer extra properties from the reference date to the new date.
143
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
144
+ * that accept a time zone as a constructor argument.
145
+ *
146
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
147
+ *
148
+ * @param date - The reference date to take constructor from
149
+ * @param value - The value to create the date
150
+ *
151
+ * @returns Date initialized using the given date and value
152
+ *
153
+ * @example
154
+ * import { constructFrom } from "./constructFrom/date-fns";
155
+ *
156
+ * // A function that clones a date preserving the original type
157
+ * function cloneDate<DateType extends Date>(date: DateType): DateType {
158
+ * return constructFrom(
159
+ * date, // Use constructor from the given date
160
+ * date.getTime() // Use the date value to create a new date
161
+ * );
162
+ * }
163
+ */
164
+ function constructFrom(date, value) {
165
+ if (typeof date === "function") return date(value);
166
+
167
+ if (date && typeof date === "object" && constructFromSymbol in date)
168
+ return date[constructFromSymbol](value);
169
+
170
+ if (date instanceof Date) return new date.constructor(value);
171
+
172
+ return new Date(value);
173
+ }
174
+
175
+ function normalizeDates(context, ...dates) {
176
+ const normalize = constructFrom.bind(
177
+ null,
178
+ context || dates.find((date) => typeof date === "object"),
179
+ );
180
+ return dates.map(normalize);
181
+ }
182
+
183
+ /**
184
+ * @name toDate
185
+ * @category Common Helpers
186
+ * @summary Convert the given argument to an instance of Date.
187
+ *
188
+ * @description
189
+ * Convert the given argument to an instance of Date.
190
+ *
191
+ * If the argument is an instance of Date, the function returns its clone.
192
+ *
193
+ * If the argument is a number, it is treated as a timestamp.
194
+ *
195
+ * If the argument is none of the above, the function returns Invalid Date.
196
+ *
197
+ * Starting from v3.7.0, it clones a date using `[Symbol.for("constructDateFrom")]`
198
+ * enabling to transfer extra properties from the reference date to the new date.
199
+ * It's useful for extensions like [`TZDate`](https://github.com/date-fns/tz)
200
+ * that accept a time zone as a constructor argument.
201
+ *
202
+ * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
203
+ *
204
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
205
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
206
+ *
207
+ * @param argument - The value to convert
208
+ *
209
+ * @returns The parsed date in the local time zone
210
+ *
211
+ * @example
212
+ * // Clone the date:
213
+ * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
214
+ * //=> Tue Feb 11 2014 11:30:30
215
+ *
216
+ * @example
217
+ * // Convert the timestamp to date:
218
+ * const result = toDate(1392098430000)
219
+ * //=> Tue Feb 11 2014 11:30:30
220
+ */
221
+ function toDate(argument, context) {
222
+ // [TODO] Get rid of `toDate` or `constructFrom`?
223
+ return constructFrom(argument, argument);
224
+ }
225
+
226
+ /**
227
+ * Google Chrome as of 67.0.3396.87 introduced timezones with offset that includes seconds.
228
+ * They usually appear for dates that denote time before the timezones were introduced
229
+ * (e.g. for 'Europe/Prague' timezone the offset is GMT+00:57:44 before 1 October 1891
230
+ * and GMT+01:00:00 after that date)
231
+ *
232
+ * Date#getTimezoneOffset returns the offset in minutes and would return 57 for the example above,
233
+ * which would lead to incorrect calculations.
234
+ *
235
+ * This function returns the timezone offset in milliseconds that takes seconds in account.
236
+ */
237
+ function getTimezoneOffsetInMilliseconds(date) {
238
+ const _date = toDate(date);
239
+ const utcDate = new Date(
240
+ Date.UTC(
241
+ _date.getFullYear(),
242
+ _date.getMonth(),
243
+ _date.getDate(),
244
+ _date.getHours(),
245
+ _date.getMinutes(),
246
+ _date.getSeconds(),
247
+ _date.getMilliseconds(),
248
+ ),
249
+ );
250
+ utcDate.setUTCFullYear(_date.getFullYear());
251
+ return +date - +utcDate;
252
+ }
253
+
254
+ /**
255
+ * The {@link startOfDay} function options.
256
+ */
257
+
258
+ /**
259
+ * @name startOfDay
260
+ * @category Day Helpers
261
+ * @summary Return the start of a day for the given date.
262
+ *
263
+ * @description
264
+ * Return the start of a day for the given date.
265
+ * The result will be in the local timezone.
266
+ *
267
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
268
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
269
+ *
270
+ * @param date - The original date
271
+ * @param options - The options
272
+ *
273
+ * @returns The start of a day
274
+ *
275
+ * @example
276
+ * // The start of a day for 2 September 2014 11:55:00:
277
+ * const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
278
+ * //=> Tue Sep 02 2014 00:00:00
279
+ */
280
+ function startOfDay(date, options) {
281
+ const _date = toDate(date);
282
+ _date.setHours(0, 0, 0, 0);
283
+ return _date;
284
+ }
285
+
286
+ /**
287
+ * The {@link differenceInCalendarDays} function options.
288
+ */
289
+
290
+ /**
291
+ * @name differenceInCalendarDays
292
+ * @category Day Helpers
293
+ * @summary Get the number of calendar days between the given dates.
294
+ *
295
+ * @description
296
+ * Get the number of calendar days between the given dates. This means that the times are removed
297
+ * from the dates and then the difference in days is calculated.
298
+ *
299
+ * @param laterDate - The later date
300
+ * @param earlierDate - The earlier date
301
+ * @param options - The options object
302
+ *
303
+ * @returns The number of calendar days
304
+ *
305
+ * @example
306
+ * // How many calendar days are between
307
+ * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
308
+ * const result = differenceInCalendarDays(
309
+ * new Date(2012, 6, 2, 0, 0),
310
+ * new Date(2011, 6, 2, 23, 0)
311
+ * )
312
+ * //=> 366
313
+ * // How many calendar days are between
314
+ * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
315
+ * const result = differenceInCalendarDays(
316
+ * new Date(2011, 6, 3, 0, 1),
317
+ * new Date(2011, 6, 2, 23, 59)
318
+ * )
319
+ * //=> 1
320
+ */
321
+ function differenceInCalendarDays(laterDate, earlierDate, options) {
322
+ const [laterDate_, earlierDate_] = normalizeDates(
323
+ options?.in,
324
+ laterDate,
325
+ earlierDate,
326
+ );
327
+
328
+ const laterStartOfDay = startOfDay(laterDate_);
329
+ const earlierStartOfDay = startOfDay(earlierDate_);
330
+
331
+ const laterTimestamp =
332
+ +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
333
+ const earlierTimestamp =
334
+ +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
335
+
336
+ // Round the number of days to the nearest integer because the number of
337
+ // milliseconds in a day is not constant (e.g. it's different in the week of
338
+ // the daylight saving time clock shift).
339
+ return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
340
+ }
341
+
342
+ /**
343
+ * The {@link differenceInCalendarMonths} function options.
344
+ */
345
+
346
+ /**
347
+ * @name differenceInCalendarMonths
348
+ * @category Month Helpers
349
+ * @summary Get the number of calendar months between the given dates.
350
+ *
351
+ * @description
352
+ * Get the number of calendar months between the given dates.
353
+ *
354
+ * @param laterDate - The later date
355
+ * @param earlierDate - The earlier date
356
+ * @param options - An object with options
357
+ *
358
+ * @returns The number of calendar months
359
+ *
360
+ * @example
361
+ * // How many calendar months are between 31 January 2014 and 1 September 2014?
362
+ * const result = differenceInCalendarMonths(
363
+ * new Date(2014, 8, 1),
364
+ * new Date(2014, 0, 31)
365
+ * )
366
+ * //=> 8
367
+ */
368
+ function differenceInCalendarMonths(laterDate, earlierDate, options) {
369
+ const [laterDate_, earlierDate_] = normalizeDates(
370
+ options?.in,
371
+ laterDate,
372
+ earlierDate,
373
+ );
374
+
375
+ const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
376
+ const monthsDiff = laterDate_.getMonth() - earlierDate_.getMonth();
377
+
378
+ return yearsDiff * 12 + monthsDiff;
379
+ }
380
+
381
+ /**
382
+ * The {@link getQuarter} function options.
383
+ */
384
+
385
+ /**
386
+ * @name getQuarter
387
+ * @category Quarter Helpers
388
+ * @summary Get the year quarter of the given date.
389
+ *
390
+ * @description
391
+ * Get the year quarter of the given date.
392
+ *
393
+ * @param date - The given date
394
+ * @param options - An object with options
395
+ *
396
+ * @returns The quarter
397
+ *
398
+ * @example
399
+ * // Which quarter is 2 July 2014?
400
+ * const result = getQuarter(new Date(2014, 6, 2));
401
+ * //=> 3
402
+ */
403
+ function getQuarter(date, options) {
404
+ const _date = toDate(date);
405
+ const quarter = Math.trunc(_date.getMonth() / 3) + 1;
406
+ return quarter;
407
+ }
408
+
409
+ /**
410
+ * The {@link differenceInCalendarQuarters} function options.
411
+ */
412
+
413
+ /**
414
+ * @name differenceInCalendarQuarters
415
+ * @category Quarter Helpers
416
+ * @summary Get the number of calendar quarters between the given dates.
417
+ *
418
+ * @description
419
+ * Get the number of calendar quarters between the given dates.
420
+ *
421
+ * @param laterDate - The later date
422
+ * @param earlierDate - The earlier date
423
+ * @param options - An object with options
424
+ *
425
+ * @returns The number of calendar quarters
426
+ *
427
+ * @example
428
+ * // How many calendar quarters are between 31 December 2013 and 2 July 2014?
429
+ * const result = differenceInCalendarQuarters(
430
+ * new Date(2014, 6, 2),
431
+ * new Date(2013, 11, 31)
432
+ * )
433
+ * //=> 3
434
+ */
435
+ function differenceInCalendarQuarters(laterDate, earlierDate, options) {
436
+ const [laterDate_, earlierDate_] = normalizeDates(
437
+ options?.in,
438
+ laterDate,
439
+ earlierDate,
440
+ );
441
+
442
+ const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
443
+ const quartersDiff = getQuarter(laterDate_) - getQuarter(earlierDate_);
444
+
445
+ return yearsDiff * 4 + quartersDiff;
446
+ }
447
+
448
+ let defaultOptions = {};
449
+
450
+ function getDefaultOptions() {
451
+ return defaultOptions;
452
+ }
453
+
454
+ /**
455
+ * The {@link startOfWeek} function options.
456
+ */
457
+
458
+ /**
459
+ * @name startOfWeek
460
+ * @category Week Helpers
461
+ * @summary Return the start of a week for the given date.
462
+ *
463
+ * @description
464
+ * Return the start of a week for the given date.
465
+ * The result will be in the local timezone.
466
+ *
467
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
468
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
469
+ *
470
+ * @param date - The original date
471
+ * @param options - An object with options
472
+ *
473
+ * @returns The start of a week
474
+ *
475
+ * @example
476
+ * // The start of a week for 2 September 2014 11:55:00:
477
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
478
+ * //=> Sun Aug 31 2014 00:00:00
479
+ *
480
+ * @example
481
+ * // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
482
+ * const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
483
+ * //=> Mon Sep 01 2014 00:00:00
484
+ */
485
+ function startOfWeek(date, options) {
486
+ const defaultOptions = getDefaultOptions();
487
+ const weekStartsOn =
488
+ defaultOptions.weekStartsOn ??
489
+ defaultOptions.locale?.options?.weekStartsOn ??
490
+ 0;
491
+
492
+ const _date = toDate(date);
493
+ const day = _date.getDay();
494
+ const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
495
+
496
+ _date.setDate(_date.getDate() - diff);
497
+ _date.setHours(0, 0, 0, 0);
498
+ return _date;
499
+ }
500
+
501
+ /**
502
+ * The {@link differenceInCalendarWeeks} function options.
503
+ */
504
+
505
+ /**
506
+ * @name differenceInCalendarWeeks
507
+ * @category Week Helpers
508
+ * @summary Get the number of calendar weeks between the given dates.
509
+ *
510
+ * @description
511
+ * Get the number of calendar weeks between the given dates.
512
+ *
513
+ * @param laterDate - The later date
514
+ * @param earlierDate - The earlier date
515
+ * @param options - An object with options.
516
+ *
517
+ * @returns The number of calendar weeks
518
+ *
519
+ * @example
520
+ * // How many calendar weeks are between 5 July 2014 and 20 July 2014?
521
+ * const result = differenceInCalendarWeeks(
522
+ * new Date(2014, 6, 20),
523
+ * new Date(2014, 6, 5)
524
+ * )
525
+ * //=> 3
526
+ *
527
+ * @example
528
+ * // If the week starts on Monday,
529
+ * // how many calendar weeks are between 5 July 2014 and 20 July 2014?
530
+ * const result = differenceInCalendarWeeks(
531
+ * new Date(2014, 6, 20),
532
+ * new Date(2014, 6, 5),
533
+ * { weekStartsOn: 1 }
534
+ * )
535
+ * //=> 2
536
+ */
537
+ function differenceInCalendarWeeks(laterDate, earlierDate, options) {
538
+ const [laterDate_, earlierDate_] = normalizeDates(
539
+ options?.in,
540
+ laterDate,
541
+ earlierDate,
542
+ );
543
+
544
+ const laterStartOfWeek = startOfWeek(laterDate_);
545
+ const earlierStartOfWeek = startOfWeek(earlierDate_);
546
+
547
+ const laterTimestamp =
548
+ +laterStartOfWeek - getTimezoneOffsetInMilliseconds(laterStartOfWeek);
549
+ const earlierTimestamp =
550
+ +earlierStartOfWeek - getTimezoneOffsetInMilliseconds(earlierStartOfWeek);
551
+
552
+ return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInWeek);
553
+ }
554
+
555
+ /**
556
+ * The {@link differenceInCalendarYears} function options.
557
+ */
558
+
559
+ /**
560
+ * @name differenceInCalendarYears
561
+ * @category Year Helpers
562
+ * @summary Get the number of calendar years between the given dates.
563
+ *
564
+ * @description
565
+ * Get the number of calendar years between the given dates.
566
+ *
567
+ * @param laterDate - The later date
568
+ * @param earlierDate - The earlier date
569
+ * @param options - An object with options
570
+
571
+ * @returns The number of calendar years
572
+ *
573
+ * @example
574
+ * // How many calendar years are between 31 December 2013 and 11 February 2015?
575
+ * const result = differenceInCalendarYears(
576
+ * new Date(2015, 1, 11),
577
+ * new Date(2013, 11, 31)
578
+ * );
579
+ * //=> 2
580
+ */
581
+ function differenceInCalendarYears(laterDate, earlierDate, options) {
582
+ const [laterDate_, earlierDate_] = normalizeDates(
583
+ options?.in,
584
+ laterDate,
585
+ earlierDate,
586
+ );
587
+ return laterDate_.getFullYear() - earlierDate_.getFullYear();
588
+ }
589
+
590
+ function getRoundingMethod(method) {
591
+ return (number) => {
592
+ const round = method ? Math[method] : Math.trunc;
593
+ const result = round(number);
594
+ // Prevent negative zero
595
+ return result === 0 ? 0 : result;
596
+ };
597
+ }
598
+
599
+ /**
600
+ * The {@link differenceInHours} function options.
601
+ */
602
+
603
+ /**
604
+ * @name differenceInHours
605
+ * @category Hour Helpers
606
+ * @summary Get the number of hours between the given dates.
607
+ *
608
+ * @description
609
+ * Get the number of hours between the given dates.
610
+ *
611
+ * @param laterDate - The later date
612
+ * @param earlierDate - The earlier date
613
+ * @param options - An object with options.
614
+ *
615
+ * @returns The number of hours
616
+ *
617
+ * @example
618
+ * // How many hours are between 2 July 2014 06:50:00 and 2 July 2014 19:00:00?
619
+ * const result = differenceInHours(
620
+ * new Date(2014, 6, 2, 19, 0),
621
+ * new Date(2014, 6, 2, 6, 50)
622
+ * )
623
+ * //=> 12
624
+ */
625
+ function differenceInHours(laterDate, earlierDate, options) {
626
+ const [laterDate_, earlierDate_] = normalizeDates(
627
+ options?.in,
628
+ laterDate,
629
+ earlierDate,
630
+ );
631
+ const diff = (+laterDate_ - +earlierDate_) / millisecondsInHour;
632
+ return getRoundingMethod(options?.roundingMethod)(diff);
633
+ }
634
+
635
+ /**
636
+ * @name differenceInMilliseconds
637
+ * @category Millisecond Helpers
638
+ * @summary Get the number of milliseconds between the given dates.
639
+ *
640
+ * @description
641
+ * Get the number of milliseconds between the given dates.
642
+ *
643
+ * @param laterDate - The later date
644
+ * @param earlierDate - The earlier date
645
+ *
646
+ * @returns The number of milliseconds
647
+ *
648
+ * @example
649
+ * // How many milliseconds are between
650
+ * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
651
+ * const result = differenceInMilliseconds(
652
+ * new Date(2014, 6, 2, 12, 30, 21, 700),
653
+ * new Date(2014, 6, 2, 12, 30, 20, 600)
654
+ * )
655
+ * //=> 1100
656
+ */
657
+ function differenceInMilliseconds(laterDate, earlierDate) {
658
+ return +toDate(laterDate) - +toDate(earlierDate);
659
+ }
660
+
661
+ /**
662
+ * The {@link differenceInMinutes} function options.
663
+ */
664
+
665
+ /**
666
+ * @name differenceInMinutes
667
+ * @category Minute Helpers
668
+ * @summary Get the number of minutes between the given dates.
669
+ *
670
+ * @description
671
+ * Get the signed number of full (rounded towards 0) minutes between the given dates.
672
+ *
673
+ * @param dateLeft - The later date
674
+ * @param dateRight - The earlier date
675
+ * @param options - An object with options.
676
+ *
677
+ * @returns The number of minutes
678
+ *
679
+ * @example
680
+ * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
681
+ * const result = differenceInMinutes(
682
+ * new Date(2014, 6, 2, 12, 20, 0),
683
+ * new Date(2014, 6, 2, 12, 7, 59)
684
+ * )
685
+ * //=> 12
686
+ *
687
+ * @example
688
+ * // How many minutes are between 10:01:59 and 10:00:00
689
+ * const result = differenceInMinutes(
690
+ * new Date(2000, 0, 1, 10, 0, 0),
691
+ * new Date(2000, 0, 1, 10, 1, 59)
692
+ * )
693
+ * //=> -1
694
+ */
695
+ function differenceInMinutes(dateLeft, dateRight, options) {
696
+ const diff =
697
+ differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
698
+ return getRoundingMethod(options?.roundingMethod)(diff);
699
+ }
700
+
701
+ /**
702
+ * The {@link differenceInSeconds} function options.
703
+ */
704
+
705
+ /**
706
+ * @name differenceInSeconds
707
+ * @category Second Helpers
708
+ * @summary Get the number of seconds between the given dates.
709
+ *
710
+ * @description
711
+ * Get the number of seconds between the given dates.
712
+ *
713
+ * @param laterDate - The later date
714
+ * @param earlierDate - The earlier date
715
+ * @param options - An object with options.
716
+ *
717
+ * @returns The number of seconds
718
+ *
719
+ * @example
720
+ * // How many seconds are between
721
+ * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
722
+ * const result = differenceInSeconds(
723
+ * new Date(2014, 6, 2, 12, 30, 20, 0),
724
+ * new Date(2014, 6, 2, 12, 30, 7, 999)
725
+ * )
726
+ * //=> 12
727
+ */
728
+ function differenceInSeconds(laterDate, earlierDate, options) {
729
+ const diff = differenceInMilliseconds(laterDate, earlierDate) / 1000;
730
+ return getRoundingMethod(options?.roundingMethod)(diff);
731
+ }
732
+
733
+ /**
734
+ * The {@link intlFormatDistance} function options.
735
+ */
736
+
737
+ /**
738
+ * The unit used to format the distance in {@link intlFormatDistance}.
739
+ */
740
+
741
+ /**
742
+ * @name intlFormatDistance
743
+ * @category Common Helpers
744
+ * @summary Formats distance between two dates in a human-readable format
745
+ * @description
746
+ * The function calculates the difference between two dates and formats it as a human-readable string.
747
+ *
748
+ * The function will pick the most appropriate unit depending on the distance between dates. For example, if the distance is a few hours, it might return `x hours`. If the distance is a few months, it might return `x months`.
749
+ *
750
+ * You can also specify a unit to force using it regardless of the distance to get a result like `123456 hours`.
751
+ *
752
+ * See the table below for the unit picking logic:
753
+ *
754
+ * | Distance between dates | Result (past) | Result (future) |
755
+ * | ---------------------- | -------------- | --------------- |
756
+ * | 0 seconds | now | now |
757
+ * | 1-59 seconds | X seconds ago | in X seconds |
758
+ * | 1-59 minutes | X minutes ago | in X minutes |
759
+ * | 1-23 hours | X hours ago | in X hours |
760
+ * | 1 day | yesterday | tomorrow |
761
+ * | 2-6 days | X days ago | in X days |
762
+ * | 7 days | last week | next week |
763
+ * | 8 days-1 month | X weeks ago | in X weeks |
764
+ * | 1 month | last month | next month |
765
+ * | 2-3 months | X months ago | in X months |
766
+ * | 1 quarter | last quarter | next quarter |
767
+ * | 2-3 quarters | X quarters ago | in X quarters |
768
+ * | 1 year | last year | next year |
769
+ * | 2+ years | X years ago | in X years |
770
+ *
771
+ * @param laterDate - The date
772
+ * @param earlierDate - The date to compare with.
773
+ * @param options - An object with options.
774
+ * See MDN for details [Locale identification and negotiation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation)
775
+ * The narrow one could be similar to the short one for some locales.
776
+ *
777
+ * @returns The distance in words according to language-sensitive relative time formatting.
778
+ *
779
+ * @throws `date` must not be Invalid Date
780
+ * @throws `baseDate` must not be Invalid Date
781
+ * @throws `options.unit` must not be invalid Unit
782
+ * @throws `options.locale` must not be invalid locale
783
+ * @throws `options.localeMatcher` must not be invalid localeMatcher
784
+ * @throws `options.numeric` must not be invalid numeric
785
+ * @throws `options.style` must not be invalid style
786
+ *
787
+ * @example
788
+ * // What is the distance between the dates when the fist date is after the second?
789
+ * intlFormatDistance(
790
+ * new Date(1986, 3, 4, 11, 30, 0),
791
+ * new Date(1986, 3, 4, 10, 30, 0)
792
+ * )
793
+ * //=> 'in 1 hour'
794
+ *
795
+ * // What is the distance between the dates when the fist date is before the second?
796
+ * intlFormatDistance(
797
+ * new Date(1986, 3, 4, 10, 30, 0),
798
+ * new Date(1986, 3, 4, 11, 30, 0)
799
+ * )
800
+ * //=> '1 hour ago'
801
+ *
802
+ * @example
803
+ * // Use the unit option to force the function to output the result in quarters. Without setting it, the example would return "next year"
804
+ * intlFormatDistance(
805
+ * new Date(1987, 6, 4, 10, 30, 0),
806
+ * new Date(1986, 3, 4, 10, 30, 0),
807
+ * { unit: 'quarter' }
808
+ * )
809
+ * //=> 'in 5 quarters'
810
+ *
811
+ * @example
812
+ * // Use the locale option to get the result in Spanish. Without setting it, the example would return "in 1 hour".
813
+ * intlFormatDistance(
814
+ * new Date(1986, 3, 4, 11, 30, 0),
815
+ * new Date(1986, 3, 4, 10, 30, 0),
816
+ * { locale: 'es' }
817
+ * )
818
+ * //=> 'dentro de 1 hora'
819
+ *
820
+ * @example
821
+ * // Use the numeric option to force the function to use numeric values. Without setting it, the example would return "tomorrow".
822
+ * intlFormatDistance(
823
+ * new Date(1986, 3, 5, 11, 30, 0),
824
+ * new Date(1986, 3, 4, 11, 30, 0),
825
+ * { numeric: 'always' }
826
+ * )
827
+ * //=> 'in 1 day'
828
+ *
829
+ * @example
830
+ * // Use the style option to force the function to use short values. Without setting it, the example would return "in 2 years".
831
+ * intlFormatDistance(
832
+ * new Date(1988, 3, 4, 11, 30, 0),
833
+ * new Date(1986, 3, 4, 11, 30, 0),
834
+ * { style: 'short' }
835
+ * )
836
+ * //=> 'in 2 yr'
837
+ */
838
+ function intlFormatDistance(laterDate, earlierDate, options) {
839
+ let value = 0;
840
+ let unit;
841
+
842
+ const [laterDate_, earlierDate_] = normalizeDates(
843
+ options?.in,
844
+ laterDate,
845
+ earlierDate,
846
+ );
847
+
848
+ if (!options?.unit) {
849
+ // Get the unit based on diffInSeconds calculations if no unit is specified
850
+ const diffInSeconds = differenceInSeconds(laterDate_, earlierDate_); // The smallest unit
851
+
852
+ if (Math.abs(diffInSeconds) < secondsInMinute) {
853
+ value = differenceInSeconds(laterDate_, earlierDate_);
854
+ unit = "second";
855
+ } else if (Math.abs(diffInSeconds) < secondsInHour) {
856
+ value = differenceInMinutes(laterDate_, earlierDate_);
857
+ unit = "minute";
858
+ } else if (
859
+ Math.abs(diffInSeconds) < secondsInDay &&
860
+ Math.abs(differenceInCalendarDays(laterDate_, earlierDate_)) < 1
861
+ ) {
862
+ value = differenceInHours(laterDate_, earlierDate_);
863
+ unit = "hour";
864
+ } else if (
865
+ Math.abs(diffInSeconds) < secondsInWeek &&
866
+ (value = differenceInCalendarDays(laterDate_, earlierDate_)) &&
867
+ Math.abs(value) < 7
868
+ ) {
869
+ unit = "day";
870
+ } else if (Math.abs(diffInSeconds) < secondsInMonth) {
871
+ value = differenceInCalendarWeeks(laterDate_, earlierDate_);
872
+ unit = "week";
873
+ } else if (Math.abs(diffInSeconds) < secondsInQuarter) {
874
+ value = differenceInCalendarMonths(laterDate_, earlierDate_);
875
+ unit = "month";
876
+ } else if (Math.abs(diffInSeconds) < secondsInYear) {
877
+ if (differenceInCalendarQuarters(laterDate_, earlierDate_) < 4) {
878
+ // To filter out cases that are less than a year but match 4 quarters
879
+ value = differenceInCalendarQuarters(laterDate_, earlierDate_);
880
+ unit = "quarter";
881
+ } else {
882
+ value = differenceInCalendarYears(laterDate_, earlierDate_);
883
+ unit = "year";
884
+ }
885
+ } else {
886
+ value = differenceInCalendarYears(laterDate_, earlierDate_);
887
+ unit = "year";
888
+ }
889
+ } else {
890
+ // Get the value if unit is specified
891
+ unit = options?.unit;
892
+ if (unit === "second") {
893
+ value = differenceInSeconds(laterDate_, earlierDate_);
894
+ } else if (unit === "minute") {
895
+ value = differenceInMinutes(laterDate_, earlierDate_);
896
+ } else if (unit === "hour") {
897
+ value = differenceInHours(laterDate_, earlierDate_);
898
+ } else if (unit === "day") {
899
+ value = differenceInCalendarDays(laterDate_, earlierDate_);
900
+ } else if (unit === "week") {
901
+ value = differenceInCalendarWeeks(laterDate_, earlierDate_);
902
+ } else if (unit === "month") {
903
+ value = differenceInCalendarMonths(laterDate_, earlierDate_);
904
+ } else if (unit === "quarter") {
905
+ value = differenceInCalendarQuarters(laterDate_, earlierDate_);
906
+ } else if (unit === "year") {
907
+ value = differenceInCalendarYears(laterDate_, earlierDate_);
908
+ }
909
+ }
910
+
911
+ const rtf = new Intl.RelativeTimeFormat(options?.locale, {
912
+ numeric: "auto",
913
+ ...options,
914
+ });
915
+
916
+ return rtf.format(value, unit);
917
+ }
918
+
919
+ function getLocale(locale) {
920
+ const defaultLocale = "en-US";
921
+ if (!locale) {
922
+ if (typeof navigator !== "undefined") {
923
+ locale = navigator.language;
924
+ } else {
925
+ locale = defaultLocale;
926
+ }
927
+ }
928
+ return locale;
929
+ }
930
+ function formatDistance(timestamp, localeParam) {
931
+ const locale = getLocale(localeParam);
932
+ return intlFormatDistance(timestamp, /* @__PURE__ */ new Date(), { locale, style: "short" });
933
+ }
934
+ function formatDate(date, localeParam) {
935
+ const locale = getLocale(localeParam);
936
+ return date.toLocaleDateString(locale, {
937
+ month: "short",
938
+ day: "numeric",
939
+ year: "numeric",
940
+ hour: "numeric",
941
+ minute: "2-digit",
942
+ hour12: true
943
+ });
944
+ }
945
+
946
+ const StatusBadge = React__default.forwardRef(({ className, suffix, children, ...props }, ref) => {
947
+ return /* @__PURE__ */ React__default.createElement("span", { ref, className: cn("flex items-center gap-1 rounded-md p-1", suffix && "bg-dark-300", className) }, /* @__PURE__ */ React__default.createElement(Badge, { ...props }, /* @__PURE__ */ React__default.createElement("span", { className: "flex items-center gap-1" }, /* @__PURE__ */ React__default.createElement(Circle, { weight: "fill", size: 8, className: "!size-2" }), children)), suffix && /* @__PURE__ */ React__default.createElement("span", { className: "text-xs text-default" }, suffix));
948
+ });
949
+ StatusBadge.displayName = "StatusBadge";
950
+
951
+ export { StatusBadge as S, formatDate as a, formatDistance as f };
952
+ //# sourceMappingURL=status-badge.DkPNh30S.js.map