@zag-js/date-utils 2.0.0-next.3 → 2.0.0-next.4

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 (65) hide show
  1. package/dist/align.d.mts +4 -8
  2. package/dist/align.d.ts +4 -8
  3. package/dist/align.js +15 -47
  4. package/dist/align.mjs +10 -21
  5. package/dist/assertion.d.mts +6 -10
  6. package/dist/assertion.d.ts +6 -10
  7. package/dist/assertion.js +21 -48
  8. package/dist/assertion.mjs +13 -19
  9. package/dist/constrain.d.mts +7 -10
  10. package/dist/constrain.d.ts +7 -10
  11. package/dist/constrain.js +72 -133
  12. package/dist/constrain.mjs +63 -110
  13. package/dist/date-month.d.mts +17 -21
  14. package/dist/date-month.d.ts +17 -21
  15. package/dist/date-month.js +103 -112
  16. package/dist/date-month.mjs +92 -86
  17. package/dist/date-year.d.mts +8 -11
  18. package/dist/date-year.d.ts +8 -11
  19. package/dist/date-year.js +35 -62
  20. package/dist/date-year.mjs +28 -34
  21. package/dist/duration.d.mts +8 -12
  22. package/dist/duration.d.ts +8 -12
  23. package/dist/duration.js +13 -37
  24. package/dist/duration.mjs +8 -11
  25. package/dist/format.d.mts +5 -8
  26. package/dist/format.d.ts +5 -8
  27. package/dist/format.js +35 -76
  28. package/dist/format.mjs +29 -49
  29. package/dist/formatter.d.mts +3 -6
  30. package/dist/formatter.d.ts +3 -6
  31. package/dist/formatter.js +26 -50
  32. package/dist/formatter.mjs +21 -24
  33. package/dist/get-era-format.d.mts +2 -6
  34. package/dist/get-era-format.d.ts +2 -6
  35. package/dist/get-era-format.js +9 -34
  36. package/dist/get-era-format.mjs +5 -9
  37. package/dist/index.d.mts +15 -15
  38. package/dist/index.d.ts +15 -15
  39. package/dist/index.js +66 -47
  40. package/dist/index.mjs +14 -14
  41. package/dist/locale.d.mts +3 -5
  42. package/dist/locale.d.ts +3 -5
  43. package/dist/locale.js +28 -55
  44. package/dist/locale.mjs +22 -28
  45. package/dist/mutation.d.mts +6 -10
  46. package/dist/mutation.d.ts +6 -10
  47. package/dist/mutation.js +21 -53
  48. package/dist/mutation.mjs +14 -30
  49. package/dist/pagination.d.mts +16 -19
  50. package/dist/pagination.d.ts +16 -19
  51. package/dist/pagination.js +120 -201
  52. package/dist/pagination.mjs +106 -166
  53. package/dist/parse-date.d.mts +2 -6
  54. package/dist/parse-date.d.ts +2 -6
  55. package/dist/parse-date.js +41 -72
  56. package/dist/parse-date.mjs +37 -47
  57. package/dist/preset.d.mts +3 -6
  58. package/dist/preset.d.ts +3 -6
  59. package/dist/preset.js +23 -63
  60. package/dist/preset.mjs +19 -47
  61. package/dist/types.d.mts +17 -20
  62. package/dist/types.d.ts +17 -20
  63. package/dist/types.js +4 -18
  64. package/dist/types.mjs +1 -0
  65. package/package.json +3 -3
package/dist/align.d.mts CHANGED
@@ -1,8 +1,4 @@
1
- import * as _internationalized_date from '@internationalized/date';
2
- import { DateDuration } from '@internationalized/date';
3
- import { DateValue, DateAlignment } from './types.mjs';
4
-
5
- declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
6
- declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
7
-
8
- export { alignDate, alignStartDate };
1
+ import { DateAlignment, DateValue as DateValue$1 } from "./types.mjs";
2
+ import { DateDuration } from "@internationalized/date";
3
+ export declare function alignDate<T extends DateValue$1>(date: T, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): T;
4
+ export declare function alignStartDate<T extends DateValue$1>(date: T, startDate: T, endDate: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): T;
package/dist/align.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- import * as _internationalized_date from '@internationalized/date';
2
- import { DateDuration } from '@internationalized/date';
3
- import { DateValue, DateAlignment } from './types.js';
4
-
5
- declare function alignDate(date: DateValue, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.DateValue;
6
- declare function alignStartDate(date: DateValue, startDate: DateValue, endDate: DateValue, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
7
-
8
- export { alignDate, alignStartDate };
1
+ import { DateAlignment, DateValue as DateValue$1 } from "./types.js";
2
+ import { DateDuration } from "@internationalized/date";
3
+ export declare function alignDate<T extends DateValue$1>(date: T, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): T;
4
+ export declare function alignStartDate<T extends DateValue$1>(date: T, startDate: T, endDate: DateValue$1, duration: DateDuration, locale: string, min?: DateValue$1 | undefined, max?: DateValue$1 | undefined): T;
package/dist/align.js CHANGED
@@ -1,52 +1,20 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/align.ts
21
- var align_exports = {};
22
- __export(align_exports, {
23
- alignDate: () => alignDate,
24
- alignStartDate: () => alignStartDate
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
25
4
  });
26
- module.exports = __toCommonJS(align_exports);
27
- var import_constrain = require("./constrain.js");
5
+ const require_constrain = require("./constrain.js");
6
+ // src/align.ts
28
7
  function alignDate(date, alignment, duration, locale, min, max) {
29
- switch (alignment) {
30
- case "start":
31
- return (0, import_constrain.alignStart)(date, duration, locale, min, max);
32
- case "end":
33
- return (0, import_constrain.alignEnd)(date, duration, locale, min, max);
34
- case "center":
35
- default:
36
- return (0, import_constrain.alignCenter)(date, duration, locale, min, max);
37
- }
8
+ switch (alignment) {
9
+ case "start": return require_constrain.alignStart(date, duration, locale, min, max);
10
+ case "end": return require_constrain.alignEnd(date, duration, locale, min, max);
11
+ default: return require_constrain.alignCenter(date, duration, locale, min, max);
12
+ }
38
13
  }
39
14
  function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
40
- if (date.compare(startDate) < 0) {
41
- return (0, import_constrain.alignEnd)(date, duration, locale, min, max);
42
- }
43
- if (date.compare(endDate) > 0) {
44
- return (0, import_constrain.alignStart)(date, duration, locale, min, max);
45
- }
46
- return startDate;
15
+ if (date.compare(startDate) < 0) return require_constrain.alignEnd(date, duration, locale, min, max);
16
+ if (date.compare(endDate) > 0) return require_constrain.alignStart(date, duration, locale, min, max);
17
+ return startDate;
47
18
  }
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {
50
- alignDate,
51
- alignStartDate
52
- });
19
+ exports.alignDate = alignDate;
20
+ exports.alignStartDate = alignStartDate;
package/dist/align.mjs CHANGED
@@ -1,26 +1,15 @@
1
- // src/align.ts
2
1
  import { alignCenter, alignEnd, alignStart } from "./constrain.mjs";
2
+ // src/align.ts
3
3
  function alignDate(date, alignment, duration, locale, min, max) {
4
- switch (alignment) {
5
- case "start":
6
- return alignStart(date, duration, locale, min, max);
7
- case "end":
8
- return alignEnd(date, duration, locale, min, max);
9
- case "center":
10
- default:
11
- return alignCenter(date, duration, locale, min, max);
12
- }
4
+ switch (alignment) {
5
+ case "start": return alignStart(date, duration, locale, min, max);
6
+ case "end": return alignEnd(date, duration, locale, min, max);
7
+ default: return alignCenter(date, duration, locale, min, max);
8
+ }
13
9
  }
14
10
  function alignStartDate(date, startDate, endDate, duration, locale, min, max) {
15
- if (date.compare(startDate) < 0) {
16
- return alignEnd(date, duration, locale, min, max);
17
- }
18
- if (date.compare(endDate) > 0) {
19
- return alignStart(date, duration, locale, min, max);
20
- }
21
- return startDate;
11
+ if (date.compare(startDate) < 0) return alignEnd(date, duration, locale, min, max);
12
+ if (date.compare(endDate) > 0) return alignStart(date, duration, locale, min, max);
13
+ return startDate;
22
14
  }
23
- export {
24
- alignDate,
25
- alignStartDate
26
- };
15
+ export { alignDate, alignStartDate };
@@ -1,10 +1,6 @@
1
- import { DateValue, DateAvailableFn } from './types.mjs';
2
- import '@internationalized/date';
3
-
4
- declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
5
- declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
- declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
7
- declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
- declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
9
-
10
- export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
1
+ import { DateAvailableFn, DateValue } from "./types.mjs";
2
+ export declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
3
+ export declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
4
+ export declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
5
+ export declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
+ export declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
@@ -1,10 +1,6 @@
1
- import { DateValue, DateAvailableFn } from './types.js';
2
- import '@internationalized/date';
3
-
4
- declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
5
- declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
- declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
7
- declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
- declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
9
-
10
- export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
1
+ import { DateAvailableFn, DateValue } from "./types.js";
2
+ export declare function isDateEqual(dateA: DateValue | null | undefined, dateB?: DateValue | null): boolean;
3
+ export declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, locale: string, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
4
+ export declare function isDateOutsideRange(date: DateValue, startDate?: DateValue | null, endDate?: DateValue | null): boolean;
5
+ export declare function isPreviousRangeInvalid(startDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
6
+ export declare function isNextRangeInvalid(endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
package/dist/assertion.js CHANGED
@@ -1,59 +1,32 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/assertion.ts
21
- var assertion_exports = {};
22
- __export(assertion_exports, {
23
- isDateEqual: () => isDateEqual,
24
- isDateOutsideRange: () => isDateOutsideRange,
25
- isDateUnavailable: () => isDateUnavailable,
26
- isNextRangeInvalid: () => isNextRangeInvalid,
27
- isPreviousRangeInvalid: () => isPreviousRangeInvalid
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
28
4
  });
29
- module.exports = __toCommonJS(assertion_exports);
30
- var import_date = require("@internationalized/date");
5
+ let _internationalized_date = require("@internationalized/date");
6
+ // src/assertion.ts
31
7
  function isDateEqual(dateA, dateB) {
32
- if (dateA == null || dateB == null) return dateA === dateB;
33
- if (!("hour" in dateA) && !("hour" in dateB)) return (0, import_date.isSameDay)(dateA, dateB);
34
- return (0, import_date.toCalendarDateTime)(dateA).compare((0, import_date.toCalendarDateTime)(dateB)) === 0;
8
+ if (dateA == null || dateB == null) return dateA === dateB;
9
+ if (!("hour" in dateA) && !("hour" in dateB)) return (0, _internationalized_date.isSameDay)(dateA, dateB);
10
+ return (0, _internationalized_date.toCalendarDateTime)(dateA).compare((0, _internationalized_date.toCalendarDateTime)(dateB)) === 0;
35
11
  }
36
12
  function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
37
- if (!date) return false;
38
- if (isUnavailable?.(date, locale)) return true;
39
- return isDateOutsideRange(date, minValue, maxValue);
13
+ if (!date) return false;
14
+ if (isUnavailable?.(date, locale)) return true;
15
+ return isDateOutsideRange(date, minValue, maxValue);
40
16
  }
41
17
  function isDateOutsideRange(date, startDate, endDate) {
42
- return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
18
+ return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
43
19
  }
44
20
  function isPreviousRangeInvalid(startDate, minValue, maxValue) {
45
- const prevDate = startDate.subtract({ days: 1 });
46
- return (0, import_date.isSameDay)(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
21
+ const prevDate = startDate.subtract({ days: 1 });
22
+ return (0, _internationalized_date.isSameDay)(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
47
23
  }
48
24
  function isNextRangeInvalid(endDate, minValue, maxValue) {
49
- const nextDate = endDate.add({ days: 1 });
50
- return (0, import_date.isSameDay)(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
25
+ const nextDate = endDate.add({ days: 1 });
26
+ return (0, _internationalized_date.isSameDay)(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
51
27
  }
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- isDateEqual,
55
- isDateOutsideRange,
56
- isDateUnavailable,
57
- isNextRangeInvalid,
58
- isPreviousRangeInvalid
59
- });
28
+ exports.isDateEqual = isDateEqual;
29
+ exports.isDateOutsideRange = isDateOutsideRange;
30
+ exports.isDateUnavailable = isDateUnavailable;
31
+ exports.isNextRangeInvalid = isNextRangeInvalid;
32
+ exports.isPreviousRangeInvalid = isPreviousRangeInvalid;
@@ -1,30 +1,24 @@
1
- // src/assertion.ts
2
1
  import { isSameDay, toCalendarDateTime } from "@internationalized/date";
2
+ // src/assertion.ts
3
3
  function isDateEqual(dateA, dateB) {
4
- if (dateA == null || dateB == null) return dateA === dateB;
5
- if (!("hour" in dateA) && !("hour" in dateB)) return isSameDay(dateA, dateB);
6
- return toCalendarDateTime(dateA).compare(toCalendarDateTime(dateB)) === 0;
4
+ if (dateA == null || dateB == null) return dateA === dateB;
5
+ if (!("hour" in dateA) && !("hour" in dateB)) return isSameDay(dateA, dateB);
6
+ return toCalendarDateTime(dateA).compare(toCalendarDateTime(dateB)) === 0;
7
7
  }
8
8
  function isDateUnavailable(date, isUnavailable, locale, minValue, maxValue) {
9
- if (!date) return false;
10
- if (isUnavailable?.(date, locale)) return true;
11
- return isDateOutsideRange(date, minValue, maxValue);
9
+ if (!date) return false;
10
+ if (isUnavailable?.(date, locale)) return true;
11
+ return isDateOutsideRange(date, minValue, maxValue);
12
12
  }
13
13
  function isDateOutsideRange(date, startDate, endDate) {
14
- return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
14
+ return startDate != null && date.compare(startDate) < 0 || endDate != null && date.compare(endDate) > 0;
15
15
  }
16
16
  function isPreviousRangeInvalid(startDate, minValue, maxValue) {
17
- const prevDate = startDate.subtract({ days: 1 });
18
- return isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
17
+ const prevDate = startDate.subtract({ days: 1 });
18
+ return isSameDay(prevDate, startDate) || isDateOutsideRange(prevDate, minValue, maxValue);
19
19
  }
20
20
  function isNextRangeInvalid(endDate, minValue, maxValue) {
21
- const nextDate = endDate.add({ days: 1 });
22
- return isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
21
+ const nextDate = endDate.add({ days: 1 });
22
+ return isSameDay(nextDate, endDate) || isDateOutsideRange(nextDate, minValue, maxValue);
23
23
  }
24
- export {
25
- isDateEqual,
26
- isDateOutsideRange,
27
- isDateUnavailable,
28
- isNextRangeInvalid,
29
- isPreviousRangeInvalid
30
- };
24
+ export { isDateEqual, isDateOutsideRange, isDateUnavailable, isNextRangeInvalid, isPreviousRangeInvalid };
@@ -1,10 +1,7 @@
1
- import { DateValue, DateDuration } from '@internationalized/date';
2
-
3
- declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
4
- declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
5
- declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
6
- declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
7
- declare function constrainValue<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
8
- declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
9
-
10
- export { alignCenter, alignEnd, alignStart, constrainSegments, constrainStart, constrainValue };
1
+ import { DateDuration, DateValue } from "@internationalized/date";
2
+ export declare function alignCenter<T extends DateValue>(date: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
3
+ export declare function alignStart<T extends DateValue>(date: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
4
+ export declare function alignEnd<T extends DateValue>(date: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
5
+ export declare function constrainStart<T extends DateValue>(date: DateValue, aligned: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
6
+ export declare function constrainValue<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
7
+ export declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
@@ -1,10 +1,7 @@
1
- import { DateValue, DateDuration } from '@internationalized/date';
2
-
3
- declare function alignCenter(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
4
- declare function alignStart(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
5
- declare function alignEnd(date: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
6
- declare function constrainStart(date: DateValue, aligned: DateValue, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): DateValue;
7
- declare function constrainValue<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
8
- declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
9
-
10
- export { alignCenter, alignEnd, alignStart, constrainSegments, constrainStart, constrainValue };
1
+ import { DateDuration, DateValue } from "@internationalized/date";
2
+ export declare function alignCenter<T extends DateValue>(date: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
3
+ export declare function alignStart<T extends DateValue>(date: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
4
+ export declare function alignEnd<T extends DateValue>(date: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
5
+ export declare function constrainStart<T extends DateValue>(date: DateValue, aligned: T, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): T;
6
+ export declare function constrainValue<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
7
+ export declare function constrainSegments<T extends DateValue>(date: T, minValue?: DateValue, maxValue?: DateValue): T;
package/dist/constrain.js CHANGED
@@ -1,146 +1,85 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/constrain.ts
21
- var constrain_exports = {};
22
- __export(constrain_exports, {
23
- alignCenter: () => alignCenter,
24
- alignEnd: () => alignEnd,
25
- alignStart: () => alignStart,
26
- constrainSegments: () => constrainSegments,
27
- constrainStart: () => constrainStart,
28
- constrainValue: () => constrainValue
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
29
4
  });
30
- module.exports = __toCommonJS(constrain_exports);
31
- var import_date = require("@internationalized/date");
5
+ let _internationalized_date = require("@internationalized/date");
6
+ // src/constrain.ts
7
+ function withCalendarDate(date, next) {
8
+ return date.set({
9
+ year: next.year,
10
+ month: next.month,
11
+ day: next.day
12
+ });
13
+ }
32
14
  function alignCenter(date, duration, locale, min, max) {
33
- const halfDuration = {};
34
- for (let prop in duration) {
35
- const key = prop;
36
- const value = duration[key];
37
- if (value == null) continue;
38
- halfDuration[key] = Math.floor(value / 2);
39
- if (halfDuration[key] > 0 && value % 2 === 0) {
40
- halfDuration[key]--;
41
- }
42
- }
43
- const aligned = alignStart(date, duration, locale).subtract(halfDuration);
44
- return constrainStart(date, aligned, duration, locale, min, max);
15
+ const halfDuration = {};
16
+ for (let prop in duration) {
17
+ const key = prop;
18
+ const value = duration[key];
19
+ if (value == null) continue;
20
+ halfDuration[key] = Math.floor(value / 2);
21
+ if (halfDuration[key] > 0 && value % 2 === 0) halfDuration[key]--;
22
+ }
23
+ return constrainStart(date, alignStart(date, duration, locale).subtract(halfDuration), duration, locale, min, max);
45
24
  }
46
25
  function alignStart(date, duration, locale, min, max) {
47
- let aligned = date;
48
- if (duration.years) {
49
- aligned = (0, import_date.startOfYear)(date);
50
- } else if (duration.months) {
51
- aligned = (0, import_date.startOfMonth)(date);
52
- } else if (duration.weeks) {
53
- aligned = (0, import_date.startOfWeek)(date, locale);
54
- }
55
- return constrainStart(date, aligned, duration, locale, min, max);
26
+ let aligned = date;
27
+ if (duration.years) aligned = (0, _internationalized_date.startOfYear)(date);
28
+ else if (duration.months) aligned = (0, _internationalized_date.startOfMonth)(date);
29
+ else if (duration.weeks) aligned = (0, _internationalized_date.startOfWeek)(date, locale);
30
+ return constrainStart(date, aligned, duration, locale, min, max);
56
31
  }
57
32
  function alignEnd(date, duration, locale, min, max) {
58
- let d = { ...duration };
59
- if (d.days) {
60
- d.days--;
61
- } else if (d.weeks) {
62
- d.weeks--;
63
- } else if (d.months) {
64
- d.months--;
65
- } else if (d.years) {
66
- d.years--;
67
- }
68
- let aligned = alignStart(date, duration, locale).subtract(d);
69
- return constrainStart(date, aligned, duration, locale, min, max);
33
+ let d = { ...duration };
34
+ if (d.days) d.days--;
35
+ else if (d.weeks) d.weeks--;
36
+ else if (d.months) d.months--;
37
+ else if (d.years) d.years--;
38
+ return constrainStart(date, alignStart(date, duration, locale).subtract(d), duration, locale, min, max);
70
39
  }
71
40
  function constrainStart(date, aligned, duration, locale, min, max) {
72
- if (min && date.compare(min) >= 0) {
73
- aligned = (0, import_date.maxDate)(aligned, alignStart((0, import_date.toCalendarDate)(min), duration, locale));
74
- }
75
- if (max && date.compare(max) <= 0) {
76
- aligned = (0, import_date.minDate)(aligned, alignEnd((0, import_date.toCalendarDate)(max), duration, locale));
77
- }
78
- return aligned;
41
+ let result = aligned;
42
+ if (min && date.compare(min) >= 0) {
43
+ const lower = alignStart((0, _internationalized_date.toCalendarDate)(min), duration, locale);
44
+ if ((0, _internationalized_date.toCalendarDate)(result).compare(lower) < 0) result = withCalendarDate(result, lower);
45
+ }
46
+ if (max && date.compare(max) <= 0) {
47
+ const upper = alignEnd((0, _internationalized_date.toCalendarDate)(max), duration, locale);
48
+ if ((0, _internationalized_date.toCalendarDate)(result).compare(upper) > 0) result = withCalendarDate(result, upper);
49
+ }
50
+ return result;
79
51
  }
80
52
  function constrainValue(date, minValue, maxValue) {
81
- const dateOnly = (0, import_date.toCalendarDate)(date);
82
- const minOnly = minValue ? (0, import_date.toCalendarDate)(minValue) : void 0;
83
- const maxOnly = maxValue ? (0, import_date.toCalendarDate)(maxValue) : void 0;
84
- let constrainedDateOnly = dateOnly;
85
- if (minOnly) {
86
- constrainedDateOnly = (0, import_date.maxDate)(constrainedDateOnly, minOnly);
87
- }
88
- if (maxOnly) {
89
- constrainedDateOnly = (0, import_date.minDate)(constrainedDateOnly, maxOnly);
90
- }
91
- if (constrainedDateOnly.compare(dateOnly) === 0) {
92
- return date;
93
- }
94
- if ("hour" in date) {
95
- return date.set({
96
- year: constrainedDateOnly.year,
97
- month: constrainedDateOnly.month,
98
- day: constrainedDateOnly.day
99
- });
100
- }
101
- return constrainedDateOnly;
53
+ const dateOnly = (0, _internationalized_date.toCalendarDate)(date);
54
+ const minOnly = minValue ? (0, _internationalized_date.toCalendarDate)(minValue) : void 0;
55
+ const maxOnly = maxValue ? (0, _internationalized_date.toCalendarDate)(maxValue) : void 0;
56
+ let constrainedDateOnly = dateOnly;
57
+ if (minOnly) constrainedDateOnly = (0, _internationalized_date.maxDate)(constrainedDateOnly, minOnly);
58
+ if (maxOnly) constrainedDateOnly = (0, _internationalized_date.minDate)(constrainedDateOnly, maxOnly);
59
+ if (constrainedDateOnly.compare(dateOnly) === 0) return date;
60
+ return withCalendarDate(date, constrainedDateOnly);
102
61
  }
103
62
  function constrainSegments(date, minValue, maxValue) {
104
- const dateOnly = (0, import_date.toCalendarDate)(date);
105
- const minOnly = minValue ? (0, import_date.toCalendarDate)(minValue) : void 0;
106
- const maxOnly = maxValue ? (0, import_date.toCalendarDate)(maxValue) : void 0;
107
- let result = dateOnly;
108
- if (minOnly && result.compare(minOnly) < 0) {
109
- if (result.year < minOnly.year) {
110
- result = result.set({ year: minOnly.year });
111
- }
112
- if (result.compare(minOnly) < 0 && result.month < minOnly.month) {
113
- result = result.set({ month: minOnly.month });
114
- }
115
- if (result.compare(minOnly) < 0 && result.day < minOnly.day) {
116
- result = result.set({ day: minOnly.day });
117
- }
118
- }
119
- if (maxOnly && result.compare(maxOnly) > 0) {
120
- if (result.year > maxOnly.year) {
121
- result = result.set({ year: maxOnly.year });
122
- }
123
- if (result.compare(maxOnly) > 0 && result.month > maxOnly.month) {
124
- result = result.set({ month: maxOnly.month });
125
- }
126
- if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) {
127
- result = result.set({ day: maxOnly.day });
128
- }
129
- }
130
- if (result.compare(dateOnly) === 0) {
131
- return date;
132
- }
133
- if ("hour" in date) {
134
- return date.set({ year: result.year, month: result.month, day: result.day });
135
- }
136
- return result;
63
+ const dateOnly = (0, _internationalized_date.toCalendarDate)(date);
64
+ const minOnly = minValue ? (0, _internationalized_date.toCalendarDate)(minValue) : void 0;
65
+ const maxOnly = maxValue ? (0, _internationalized_date.toCalendarDate)(maxValue) : void 0;
66
+ let result = dateOnly;
67
+ if (minOnly && result.compare(minOnly) < 0) {
68
+ if (result.year < minOnly.year) result = result.set({ year: minOnly.year });
69
+ if (result.compare(minOnly) < 0 && result.month < minOnly.month) result = result.set({ month: minOnly.month });
70
+ if (result.compare(minOnly) < 0 && result.day < minOnly.day) result = result.set({ day: minOnly.day });
71
+ }
72
+ if (maxOnly && result.compare(maxOnly) > 0) {
73
+ if (result.year > maxOnly.year) result = result.set({ year: maxOnly.year });
74
+ if (result.compare(maxOnly) > 0 && result.month > maxOnly.month) result = result.set({ month: maxOnly.month });
75
+ if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) result = result.set({ day: maxOnly.day });
76
+ }
77
+ if (result.compare(dateOnly) === 0) return date;
78
+ return withCalendarDate(date, result);
137
79
  }
138
- // Annotate the CommonJS export names for ESM import in node:
139
- 0 && (module.exports = {
140
- alignCenter,
141
- alignEnd,
142
- alignStart,
143
- constrainSegments,
144
- constrainStart,
145
- constrainValue
146
- });
80
+ exports.alignCenter = alignCenter;
81
+ exports.alignEnd = alignEnd;
82
+ exports.alignStart = alignStart;
83
+ exports.constrainSegments = constrainSegments;
84
+ exports.constrainStart = constrainStart;
85
+ exports.constrainValue = constrainValue;