@cerberus-design/react 0.25.0-rc.7 → 0.25.1-rc.1
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.
- package/dist/components/combobox/combobox.cjs +1 -2
- package/dist/components/combobox/combobox.d.cts +1 -3
- package/dist/components/combobox/combobox.d.ts +1 -3
- package/dist/components/combobox/combobox.js +1 -2
- package/dist/components/cta-dialog/provider.cjs +3 -1
- package/dist/components/cta-dialog/provider.d.cts +2 -1
- package/dist/components/cta-dialog/provider.d.ts +2 -1
- package/dist/components/cta-dialog/provider.js +3 -1
- package/dist/components/date-picker/calendar.cjs +3 -1
- package/dist/components/date-picker/calendar.d.cts +4 -8
- package/dist/components/date-picker/calendar.d.ts +4 -8
- package/dist/components/date-picker/calendar.js +3 -1
- package/dist/components/date-picker/content.cjs +1 -3
- package/dist/components/date-picker/content.d.cts +1 -2
- package/dist/components/date-picker/content.d.ts +1 -2
- package/dist/components/date-picker/content.js +1 -3
- package/dist/components/date-picker/date-picker.cjs +47 -2
- package/dist/components/date-picker/date-picker.d.cts +1 -6
- package/dist/components/date-picker/date-picker.d.ts +1 -6
- package/dist/components/date-picker/date-picker.js +47 -2
- package/dist/components/date-picker/index.cjs +3 -3
- package/dist/components/date-picker/index.js +3 -3
- package/dist/components/date-picker/input.cjs +1 -1
- package/dist/components/date-picker/input.js +1 -1
- package/dist/components/date-picker/primitives.cjs +4 -1
- package/dist/components/date-picker/primitives.d.cts +1 -4
- package/dist/components/date-picker/primitives.d.ts +1 -4
- package/dist/components/date-picker/primitives.js +4 -1
- package/dist/components/date-picker/range-input.cjs +2 -2
- package/dist/components/date-picker/range-input.js +2 -2
- package/dist/components/field/status-indicator.cjs +1 -2
- package/dist/components/field/status-indicator.d.cts +1 -1
- package/dist/components/field/status-indicator.d.ts +1 -1
- package/dist/components/field/status-indicator.js +1 -2
- package/dist/components/file-upload/file-status.cjs +26 -43
- package/dist/components/file-upload/file-status.js +27 -44
- package/dist/components/file-upload/file-uploader.cjs +21 -47
- package/dist/components/file-upload/file-uploader.d.cts +7 -10
- package/dist/components/file-upload/file-uploader.d.ts +7 -10
- package/dist/components/file-upload/file-uploader.js +22 -48
- package/dist/components/file-upload/helpers.cjs +17 -0
- package/dist/components/file-upload/helpers.d.cts +16 -0
- package/dist/components/file-upload/helpers.d.ts +16 -0
- package/dist/components/file-upload/helpers.js +13 -0
- package/dist/components/file-upload/img-preview.cjs +30 -0
- package/dist/components/file-upload/img-preview.d.cts +2 -0
- package/dist/components/file-upload/img-preview.d.ts +2 -0
- package/dist/components/file-upload/img-preview.js +26 -0
- package/dist/components/file-upload/index.cjs +24 -0
- package/dist/components/file-upload/index.d.cts +4 -0
- package/dist/components/file-upload/index.d.ts +4 -0
- package/dist/components/file-upload/index.js +4 -0
- package/dist/components/file-upload/parts.cjs +28 -0
- package/dist/components/file-upload/parts.d.cts +86 -0
- package/dist/components/file-upload/parts.d.ts +86 -0
- package/dist/components/file-upload/parts.js +24 -0
- package/dist/components/file-upload/primitives.cjs +81 -0
- package/dist/components/file-upload/primitives.d.cts +45 -0
- package/dist/components/file-upload/primitives.d.ts +45 -0
- package/dist/components/file-upload/primitives.js +61 -0
- package/dist/components/file-upload/utils.cjs +18 -0
- package/dist/components/file-upload/utils.d.cts +7 -0
- package/dist/components/file-upload/utils.d.ts +7 -0
- package/dist/components/file-upload/utils.js +14 -0
- package/dist/components/select/select.cjs +6 -3
- package/dist/components/select/select.d.cts +1 -3
- package/dist/components/select/select.d.ts +1 -3
- package/dist/components/select/select.js +6 -3
- package/dist/context/confirm-modal.cjs +3 -1
- package/dist/context/confirm-modal.d.cts +2 -1
- package/dist/context/confirm-modal.d.ts +2 -1
- package/dist/context/confirm-modal.js +3 -1
- package/dist/context/prompt-modal.cjs +4 -2
- package/dist/context/prompt-modal.d.cts +2 -1
- package/dist/context/prompt-modal.d.ts +2 -1
- package/dist/context/prompt-modal.js +5 -3
- package/dist/index.cjs +163 -131
- package/dist/index.client.d.cts +1 -1
- package/dist/index.client.d.ts +1 -1
- package/dist/index.js +8 -4
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-clear-trigger.cjs +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-clear-trigger.js +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-context.cjs +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-context.js +6 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-dropzone.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-dropzone.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-hidden-input.cjs +21 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-hidden-input.js +17 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-delete-trigger.cjs +23 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-delete-trigger.js +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-group.cjs +23 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-group.js +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-name.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-name.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview-image.cjs +28 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview-image.js +24 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-preview.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-size-text.cjs +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item-size-text.js +18 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item.cjs +26 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-item.js +22 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-label.cjs +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-label.js +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-root.cjs +47 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-root.js +43 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-trigger.cjs +19 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/file-upload-trigger.js +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-context.cjs +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-context.js +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-group-props-context.cjs +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-group-props-context.js +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-props-context.cjs +15 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload-item-props-context.js +10 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload.cjs +36 -0
- package/dist/node_modules/.pnpm/@ark-ui_react@5.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@ark-ui/react/dist/components/file-upload/use-file-upload.js +32 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.0/node_modules/@internationalized/date/src/CalendarDate.js +3 -3
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.0/node_modules/@internationalized/date/src/conversion.js +1 -1
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.0/node_modules/@internationalized/date/src/queries.js +1 -1
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/CalendarDate.cjs +218 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/CalendarDate.js +212 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/DateFormatter.cjs +135 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/DateFormatter.js +131 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/calendars/GregorianCalendar.cjs +101 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/calendars/GregorianCalendar.js +93 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/conversion.cjs +200 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/conversion.js +186 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/manipulation.cjs +352 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/manipulation.js +336 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/queries.cjs +39 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/queries.js +30 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/string.cjs +44 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/string.js +37 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/utils.cjs +10 -0
- package/dist/node_modules/.pnpm/@internationalized_date@3.10.1/node_modules/@internationalized/date/src/utils.js +6 -0
- package/dist/node_modules/.pnpm/@zag-js_file-upload@1.31.1/node_modules/@zag-js/file-upload/dist/index.cjs +649 -0
- package/dist/node_modules/.pnpm/@zag-js_file-upload@1.31.1/node_modules/@zag-js/file-upload/dist/index.js +643 -0
- package/dist/node_modules/.pnpm/@zag-js_file-utils@1.31.1/node_modules/@zag-js/file-utils/dist/index.cjs +147 -0
- package/dist/node_modules/.pnpm/@zag-js_file-utils@1.31.1/node_modules/@zag-js/file-utils/dist/index.js +138 -0
- package/dist/node_modules/.pnpm/@zag-js_i18n-utils@1.31.1/node_modules/@zag-js/i18n-utils/dist/index.cjs +53 -0
- package/dist/node_modules/.pnpm/@zag-js_i18n-utils@1.31.1/node_modules/@zag-js/i18n-utils/dist/index.js +48 -0
- package/dist/node_modules/.pnpm/@zag-js_utils@1.31.1/node_modules/@zag-js/utils/dist/index.cjs +9 -0
- package/dist/node_modules/.pnpm/@zag-js_utils@1.31.1/node_modules/@zag-js/utils/dist/index.js +9 -1
- package/package.json +7 -7
- package/src/components/combobox/combobox.tsx +7 -13
- package/src/components/cta-dialog/provider.tsx +8 -3
- package/src/components/date-picker/calendar.tsx +10 -9
- package/src/components/date-picker/content.tsx +4 -11
- package/src/components/date-picker/date-picker.tsx +55 -18
- package/src/components/date-picker/input.tsx +1 -1
- package/src/components/date-picker/primitives.tsx +4 -1
- package/src/components/date-picker/range-input.tsx +2 -2
- package/src/components/field/status-indicator.tsx +2 -5
- package/src/components/file-upload/file-status.tsx +14 -21
- package/src/components/file-upload/file-uploader.tsx +37 -49
- package/src/components/file-upload/helpers.ts +28 -0
- package/src/components/file-upload/img-preview.tsx +41 -0
- package/src/components/file-upload/index.ts +4 -0
- package/src/components/file-upload/parts.tsx +126 -0
- package/src/components/file-upload/primitives.ts +156 -0
- package/src/components/file-upload/utils.ts +20 -0
- package/src/components/select/select.tsx +11 -12
- package/src/context/confirm-modal.tsx +7 -2
- package/src/context/prompt-modal.tsx +9 -4
- package/src/index.client.ts +2 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { toCalendarDateTime, toAbsolute, epochFromDate, fromAbsolute, toCalendar } from './conversion.js';
|
|
3
|
+
import { GregorianCalendar } from './calendars/GregorianCalendar.js';
|
|
4
|
+
|
|
5
|
+
const ONE_HOUR = 36e5;
|
|
6
|
+
function add(date, duration) {
|
|
7
|
+
let mutableDate = date.copy();
|
|
8
|
+
let days = "hour" in mutableDate ? addTimeFields(mutableDate, duration) : 0;
|
|
9
|
+
addYears(mutableDate, duration.years || 0);
|
|
10
|
+
if (mutableDate.calendar.balanceYearMonth) {
|
|
11
|
+
mutableDate.calendar.balanceYearMonth(mutableDate, date);
|
|
12
|
+
}
|
|
13
|
+
mutableDate.month += duration.months || 0;
|
|
14
|
+
balanceYearMonth(mutableDate);
|
|
15
|
+
constrainMonthDay(mutableDate);
|
|
16
|
+
mutableDate.day += (duration.weeks || 0) * 7;
|
|
17
|
+
mutableDate.day += duration.days || 0;
|
|
18
|
+
mutableDate.day += days;
|
|
19
|
+
balanceDay(mutableDate);
|
|
20
|
+
if (mutableDate.calendar.balanceDate) {
|
|
21
|
+
mutableDate.calendar.balanceDate(mutableDate);
|
|
22
|
+
}
|
|
23
|
+
if (mutableDate.year < 1) {
|
|
24
|
+
mutableDate.year = 1;
|
|
25
|
+
mutableDate.month = 1;
|
|
26
|
+
mutableDate.day = 1;
|
|
27
|
+
}
|
|
28
|
+
let maxYear = mutableDate.calendar.getYearsInEra(mutableDate);
|
|
29
|
+
if (mutableDate.year > maxYear) {
|
|
30
|
+
let isInverseEra = mutableDate.calendar.isInverseEra?.(mutableDate);
|
|
31
|
+
mutableDate.year = maxYear;
|
|
32
|
+
mutableDate.month = isInverseEra ? 1 : mutableDate.calendar.getMonthsInYear(mutableDate);
|
|
33
|
+
mutableDate.day = isInverseEra ? 1 : mutableDate.calendar.getDaysInMonth(mutableDate);
|
|
34
|
+
}
|
|
35
|
+
if (mutableDate.month < 1) {
|
|
36
|
+
mutableDate.month = 1;
|
|
37
|
+
mutableDate.day = 1;
|
|
38
|
+
}
|
|
39
|
+
let maxMonth = mutableDate.calendar.getMonthsInYear(mutableDate);
|
|
40
|
+
if (mutableDate.month > maxMonth) {
|
|
41
|
+
mutableDate.month = maxMonth;
|
|
42
|
+
mutableDate.day = mutableDate.calendar.getDaysInMonth(mutableDate);
|
|
43
|
+
}
|
|
44
|
+
mutableDate.day = Math.max(1, Math.min(mutableDate.calendar.getDaysInMonth(mutableDate), mutableDate.day));
|
|
45
|
+
return mutableDate;
|
|
46
|
+
}
|
|
47
|
+
function addYears(date, years) {
|
|
48
|
+
if (date.calendar.isInverseEra?.(date)) {
|
|
49
|
+
years = -years;
|
|
50
|
+
}
|
|
51
|
+
date.year += years;
|
|
52
|
+
}
|
|
53
|
+
function balanceYearMonth(date) {
|
|
54
|
+
while (date.month < 1) {
|
|
55
|
+
addYears(date, -1);
|
|
56
|
+
date.month += date.calendar.getMonthsInYear(date);
|
|
57
|
+
}
|
|
58
|
+
let monthsInYear = 0;
|
|
59
|
+
while (date.month > (monthsInYear = date.calendar.getMonthsInYear(date))) {
|
|
60
|
+
date.month -= monthsInYear;
|
|
61
|
+
addYears(date, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function balanceDay(date) {
|
|
65
|
+
while (date.day < 1) {
|
|
66
|
+
date.month--;
|
|
67
|
+
balanceYearMonth(date);
|
|
68
|
+
date.day += date.calendar.getDaysInMonth(date);
|
|
69
|
+
}
|
|
70
|
+
while (date.day > date.calendar.getDaysInMonth(date)) {
|
|
71
|
+
date.day -= date.calendar.getDaysInMonth(date);
|
|
72
|
+
date.month++;
|
|
73
|
+
balanceYearMonth(date);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function constrainMonthDay(date) {
|
|
77
|
+
date.month = Math.max(1, Math.min(date.calendar.getMonthsInYear(date), date.month));
|
|
78
|
+
date.day = Math.max(1, Math.min(date.calendar.getDaysInMonth(date), date.day));
|
|
79
|
+
}
|
|
80
|
+
function constrain(date) {
|
|
81
|
+
if (date.calendar.constrainDate) {
|
|
82
|
+
date.calendar.constrainDate(date);
|
|
83
|
+
}
|
|
84
|
+
date.year = Math.max(1, Math.min(date.calendar.getYearsInEra(date), date.year));
|
|
85
|
+
constrainMonthDay(date);
|
|
86
|
+
}
|
|
87
|
+
function invertDuration(duration) {
|
|
88
|
+
let inverseDuration = {};
|
|
89
|
+
for (let key in duration) {
|
|
90
|
+
if (typeof duration[key] === "number") {
|
|
91
|
+
inverseDuration[key] = -duration[key];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return inverseDuration;
|
|
95
|
+
}
|
|
96
|
+
function subtract(date, duration) {
|
|
97
|
+
return add(date, invertDuration(duration));
|
|
98
|
+
}
|
|
99
|
+
function set(date, fields) {
|
|
100
|
+
let mutableDate = date.copy();
|
|
101
|
+
if (fields.era != null) {
|
|
102
|
+
mutableDate.era = fields.era;
|
|
103
|
+
}
|
|
104
|
+
if (fields.year != null) {
|
|
105
|
+
mutableDate.year = fields.year;
|
|
106
|
+
}
|
|
107
|
+
if (fields.month != null) {
|
|
108
|
+
mutableDate.month = fields.month;
|
|
109
|
+
}
|
|
110
|
+
if (fields.day != null) {
|
|
111
|
+
mutableDate.day = fields.day;
|
|
112
|
+
}
|
|
113
|
+
constrain(mutableDate);
|
|
114
|
+
return mutableDate;
|
|
115
|
+
}
|
|
116
|
+
function setTime(value, fields) {
|
|
117
|
+
let mutableValue = value.copy();
|
|
118
|
+
if (fields.hour != null) {
|
|
119
|
+
mutableValue.hour = fields.hour;
|
|
120
|
+
}
|
|
121
|
+
if (fields.minute != null) {
|
|
122
|
+
mutableValue.minute = fields.minute;
|
|
123
|
+
}
|
|
124
|
+
if (fields.second != null) {
|
|
125
|
+
mutableValue.second = fields.second;
|
|
126
|
+
}
|
|
127
|
+
if (fields.millisecond != null) {
|
|
128
|
+
mutableValue.millisecond = fields.millisecond;
|
|
129
|
+
}
|
|
130
|
+
constrainTime(mutableValue);
|
|
131
|
+
return mutableValue;
|
|
132
|
+
}
|
|
133
|
+
function balanceTime(time) {
|
|
134
|
+
time.second += Math.floor(time.millisecond / 1e3);
|
|
135
|
+
time.millisecond = nonNegativeMod(time.millisecond, 1e3);
|
|
136
|
+
time.minute += Math.floor(time.second / 60);
|
|
137
|
+
time.second = nonNegativeMod(time.second, 60);
|
|
138
|
+
time.hour += Math.floor(time.minute / 60);
|
|
139
|
+
time.minute = nonNegativeMod(time.minute, 60);
|
|
140
|
+
let days = Math.floor(time.hour / 24);
|
|
141
|
+
time.hour = nonNegativeMod(time.hour, 24);
|
|
142
|
+
return days;
|
|
143
|
+
}
|
|
144
|
+
function constrainTime(time) {
|
|
145
|
+
time.millisecond = Math.max(0, Math.min(time.millisecond, 1e3));
|
|
146
|
+
time.second = Math.max(0, Math.min(time.second, 59));
|
|
147
|
+
time.minute = Math.max(0, Math.min(time.minute, 59));
|
|
148
|
+
time.hour = Math.max(0, Math.min(time.hour, 23));
|
|
149
|
+
}
|
|
150
|
+
function nonNegativeMod(a, b) {
|
|
151
|
+
let result = a % b;
|
|
152
|
+
if (result < 0) {
|
|
153
|
+
result += b;
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
function addTimeFields(time, duration) {
|
|
158
|
+
time.hour += duration.hours || 0;
|
|
159
|
+
time.minute += duration.minutes || 0;
|
|
160
|
+
time.second += duration.seconds || 0;
|
|
161
|
+
time.millisecond += duration.milliseconds || 0;
|
|
162
|
+
return balanceTime(time);
|
|
163
|
+
}
|
|
164
|
+
function cycleDate(value, field, amount, options) {
|
|
165
|
+
let mutable = value.copy();
|
|
166
|
+
switch (field) {
|
|
167
|
+
case "era": {
|
|
168
|
+
let eras = value.calendar.getEras();
|
|
169
|
+
let eraIndex = eras.indexOf(value.era);
|
|
170
|
+
if (eraIndex < 0) {
|
|
171
|
+
throw new Error("Invalid era: " + value.era);
|
|
172
|
+
}
|
|
173
|
+
eraIndex = cycleValue(eraIndex, amount, 0, eras.length - 1, options?.round);
|
|
174
|
+
mutable.era = eras[eraIndex];
|
|
175
|
+
constrain(mutable);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case "year": {
|
|
179
|
+
if (mutable.calendar.isInverseEra?.(mutable)) {
|
|
180
|
+
amount = -amount;
|
|
181
|
+
}
|
|
182
|
+
mutable.year = cycleValue(value.year, amount, -Infinity, 9999, options?.round);
|
|
183
|
+
if (mutable.year === -Infinity) {
|
|
184
|
+
mutable.year = 1;
|
|
185
|
+
}
|
|
186
|
+
if (mutable.calendar.balanceYearMonth) {
|
|
187
|
+
mutable.calendar.balanceYearMonth(mutable, value);
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case "month":
|
|
192
|
+
mutable.month = cycleValue(value.month, amount, 1, value.calendar.getMonthsInYear(value), options?.round);
|
|
193
|
+
break;
|
|
194
|
+
case "day":
|
|
195
|
+
mutable.day = cycleValue(value.day, amount, 1, value.calendar.getDaysInMonth(value), options?.round);
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
throw new Error("Unsupported field " + field);
|
|
199
|
+
}
|
|
200
|
+
if (value.calendar.balanceDate) {
|
|
201
|
+
value.calendar.balanceDate(mutable);
|
|
202
|
+
}
|
|
203
|
+
constrain(mutable);
|
|
204
|
+
return mutable;
|
|
205
|
+
}
|
|
206
|
+
function cycleTime(value, field, amount, options) {
|
|
207
|
+
let mutable = value.copy();
|
|
208
|
+
switch (field) {
|
|
209
|
+
case "hour": {
|
|
210
|
+
let hours = value.hour;
|
|
211
|
+
let min = 0;
|
|
212
|
+
let max = 23;
|
|
213
|
+
if (options?.hourCycle === 12) {
|
|
214
|
+
let isPM = hours >= 12;
|
|
215
|
+
min = isPM ? 12 : 0;
|
|
216
|
+
max = isPM ? 23 : 11;
|
|
217
|
+
}
|
|
218
|
+
mutable.hour = cycleValue(hours, amount, min, max, options?.round);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case "minute":
|
|
222
|
+
mutable.minute = cycleValue(value.minute, amount, 0, 59, options?.round);
|
|
223
|
+
break;
|
|
224
|
+
case "second":
|
|
225
|
+
mutable.second = cycleValue(value.second, amount, 0, 59, options?.round);
|
|
226
|
+
break;
|
|
227
|
+
case "millisecond":
|
|
228
|
+
mutable.millisecond = cycleValue(value.millisecond, amount, 0, 999, options?.round);
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
throw new Error("Unsupported field " + field);
|
|
232
|
+
}
|
|
233
|
+
return mutable;
|
|
234
|
+
}
|
|
235
|
+
function cycleValue(value, amount, min, max, round = false) {
|
|
236
|
+
if (round) {
|
|
237
|
+
value += Math.sign(amount);
|
|
238
|
+
if (value < min) {
|
|
239
|
+
value = max;
|
|
240
|
+
}
|
|
241
|
+
let div = Math.abs(amount);
|
|
242
|
+
if (amount > 0) {
|
|
243
|
+
value = Math.ceil(value / div) * div;
|
|
244
|
+
} else {
|
|
245
|
+
value = Math.floor(value / div) * div;
|
|
246
|
+
}
|
|
247
|
+
if (value > max) {
|
|
248
|
+
value = min;
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
value += amount;
|
|
252
|
+
if (value < min) {
|
|
253
|
+
value = max - (min - value - 1);
|
|
254
|
+
} else if (value > max) {
|
|
255
|
+
value = min + (value - max - 1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
function addZoned(dateTime, duration) {
|
|
261
|
+
let ms;
|
|
262
|
+
if (duration.years != null && duration.years !== 0 || duration.months != null && duration.months !== 0 || duration.weeks != null && duration.weeks !== 0 || duration.days != null && duration.days !== 0) {
|
|
263
|
+
let res2 = add(toCalendarDateTime(dateTime), {
|
|
264
|
+
years: duration.years,
|
|
265
|
+
months: duration.months,
|
|
266
|
+
weeks: duration.weeks,
|
|
267
|
+
days: duration.days
|
|
268
|
+
});
|
|
269
|
+
ms = toAbsolute(res2, dateTime.timeZone);
|
|
270
|
+
} else {
|
|
271
|
+
ms = epochFromDate(dateTime) - dateTime.offset;
|
|
272
|
+
}
|
|
273
|
+
ms += duration.milliseconds || 0;
|
|
274
|
+
ms += (duration.seconds || 0) * 1e3;
|
|
275
|
+
ms += (duration.minutes || 0) * 60 * 1e3;
|
|
276
|
+
ms += (duration.hours || 0) * 60 * 60 * 1e3;
|
|
277
|
+
let res = fromAbsolute(ms, dateTime.timeZone);
|
|
278
|
+
return toCalendar(res, dateTime.calendar);
|
|
279
|
+
}
|
|
280
|
+
function subtractZoned(dateTime, duration) {
|
|
281
|
+
return addZoned(dateTime, invertDuration(duration));
|
|
282
|
+
}
|
|
283
|
+
function cycleZoned(dateTime, field, amount, options) {
|
|
284
|
+
switch (field) {
|
|
285
|
+
case "hour": {
|
|
286
|
+
let min = 0;
|
|
287
|
+
let max = 23;
|
|
288
|
+
if (options?.hourCycle === 12) {
|
|
289
|
+
let isPM = dateTime.hour >= 12;
|
|
290
|
+
min = isPM ? 12 : 0;
|
|
291
|
+
max = isPM ? 23 : 11;
|
|
292
|
+
}
|
|
293
|
+
let plainDateTime = toCalendarDateTime(dateTime);
|
|
294
|
+
let minDate = toCalendar(setTime(plainDateTime, { hour: min }), new GregorianCalendar());
|
|
295
|
+
let minAbsolute = [toAbsolute(minDate, dateTime.timeZone, "earlier"), toAbsolute(minDate, dateTime.timeZone, "later")].filter((ms2) => fromAbsolute(ms2, dateTime.timeZone).day === minDate.day)[0];
|
|
296
|
+
let maxDate = toCalendar(setTime(plainDateTime, { hour: max }), new GregorianCalendar());
|
|
297
|
+
let maxAbsolute = [toAbsolute(maxDate, dateTime.timeZone, "earlier"), toAbsolute(maxDate, dateTime.timeZone, "later")].filter((ms2) => fromAbsolute(ms2, dateTime.timeZone).day === maxDate.day).pop();
|
|
298
|
+
let ms = epochFromDate(dateTime) - dateTime.offset;
|
|
299
|
+
let hours = Math.floor(ms / ONE_HOUR);
|
|
300
|
+
let remainder = ms % ONE_HOUR;
|
|
301
|
+
ms = cycleValue(
|
|
302
|
+
hours,
|
|
303
|
+
amount,
|
|
304
|
+
Math.floor(minAbsolute / ONE_HOUR),
|
|
305
|
+
Math.floor(maxAbsolute / ONE_HOUR),
|
|
306
|
+
options?.round
|
|
307
|
+
) * ONE_HOUR + remainder;
|
|
308
|
+
return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);
|
|
309
|
+
}
|
|
310
|
+
case "minute":
|
|
311
|
+
case "second":
|
|
312
|
+
case "millisecond":
|
|
313
|
+
return cycleTime(dateTime, field, amount, options);
|
|
314
|
+
case "era":
|
|
315
|
+
case "year":
|
|
316
|
+
case "month":
|
|
317
|
+
case "day": {
|
|
318
|
+
let res = cycleDate(toCalendarDateTime(dateTime), field, amount, options);
|
|
319
|
+
let ms = toAbsolute(res, dateTime.timeZone);
|
|
320
|
+
return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);
|
|
321
|
+
}
|
|
322
|
+
default:
|
|
323
|
+
throw new Error("Unsupported field " + field);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function setZoned(dateTime, fields, disambiguation) {
|
|
327
|
+
let plainDateTime = toCalendarDateTime(dateTime);
|
|
328
|
+
let res = setTime(set(plainDateTime, fields), fields);
|
|
329
|
+
if (res.compare(plainDateTime) === 0) {
|
|
330
|
+
return dateTime;
|
|
331
|
+
}
|
|
332
|
+
let ms = toAbsolute(res, dateTime.timeZone, disambiguation);
|
|
333
|
+
return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export { add, addZoned, constrain, constrainTime, cycleDate, cycleTime, cycleZoned, invertDuration, set, setTime, setZoned, subtract, subtractZoned };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const conversion = require('./conversion.cjs');
|
|
7
|
+
|
|
8
|
+
function isEqualCalendar(a, b) {
|
|
9
|
+
return a.isEqual?.(b) ?? b.isEqual?.(a) ?? a.identifier === b.identifier;
|
|
10
|
+
}
|
|
11
|
+
function now(timeZone) {
|
|
12
|
+
return conversion.fromAbsolute(Date.now(), timeZone);
|
|
13
|
+
}
|
|
14
|
+
function today(timeZone) {
|
|
15
|
+
return conversion.toCalendarDate(now(timeZone));
|
|
16
|
+
}
|
|
17
|
+
function compareDate(a, b) {
|
|
18
|
+
return a.calendar.toJulianDay(a) - b.calendar.toJulianDay(b);
|
|
19
|
+
}
|
|
20
|
+
function compareTime(a, b) {
|
|
21
|
+
return timeToMs(a) - timeToMs(b);
|
|
22
|
+
}
|
|
23
|
+
function timeToMs(a) {
|
|
24
|
+
return a.hour * 60 * 60 * 1e3 + a.minute * 60 * 1e3 + a.second * 1e3 + a.millisecond;
|
|
25
|
+
}
|
|
26
|
+
let localTimeZone = null;
|
|
27
|
+
function getLocalTimeZone() {
|
|
28
|
+
if (localTimeZone == null) {
|
|
29
|
+
localTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
30
|
+
}
|
|
31
|
+
return localTimeZone;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.compareDate = compareDate;
|
|
35
|
+
exports.compareTime = compareTime;
|
|
36
|
+
exports.getLocalTimeZone = getLocalTimeZone;
|
|
37
|
+
exports.isEqualCalendar = isEqualCalendar;
|
|
38
|
+
exports.now = now;
|
|
39
|
+
exports.today = today;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { toCalendarDate, fromAbsolute } from './conversion.js';
|
|
3
|
+
|
|
4
|
+
function isEqualCalendar(a, b) {
|
|
5
|
+
return a.isEqual?.(b) ?? b.isEqual?.(a) ?? a.identifier === b.identifier;
|
|
6
|
+
}
|
|
7
|
+
function now(timeZone) {
|
|
8
|
+
return fromAbsolute(Date.now(), timeZone);
|
|
9
|
+
}
|
|
10
|
+
function today(timeZone) {
|
|
11
|
+
return toCalendarDate(now(timeZone));
|
|
12
|
+
}
|
|
13
|
+
function compareDate(a, b) {
|
|
14
|
+
return a.calendar.toJulianDay(a) - b.calendar.toJulianDay(b);
|
|
15
|
+
}
|
|
16
|
+
function compareTime(a, b) {
|
|
17
|
+
return timeToMs(a) - timeToMs(b);
|
|
18
|
+
}
|
|
19
|
+
function timeToMs(a) {
|
|
20
|
+
return a.hour * 60 * 60 * 1e3 + a.minute * 60 * 1e3 + a.second * 1e3 + a.millisecond;
|
|
21
|
+
}
|
|
22
|
+
let localTimeZone = null;
|
|
23
|
+
function getLocalTimeZone() {
|
|
24
|
+
if (localTimeZone == null) {
|
|
25
|
+
localTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
26
|
+
}
|
|
27
|
+
return localTimeZone;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { compareDate, compareTime, getLocalTimeZone, isEqualCalendar, now, today };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const conversion = require('./conversion.cjs');
|
|
7
|
+
const GregorianCalendar = require('./calendars/GregorianCalendar.cjs');
|
|
8
|
+
|
|
9
|
+
function timeToString(time) {
|
|
10
|
+
return `${String(time.hour).padStart(2, "0")}:${String(time.minute).padStart(2, "0")}:${String(time.second).padStart(2, "0")}${time.millisecond ? String(time.millisecond / 1e3).slice(1) : ""}`;
|
|
11
|
+
}
|
|
12
|
+
function dateToString(date) {
|
|
13
|
+
let gregorianDate = conversion.toCalendar(date, new GregorianCalendar.GregorianCalendar());
|
|
14
|
+
let year;
|
|
15
|
+
if (gregorianDate.era === "BC") {
|
|
16
|
+
year = gregorianDate.year === 1 ? "0000" : "-" + String(Math.abs(1 - gregorianDate.year)).padStart(6, "00");
|
|
17
|
+
} else {
|
|
18
|
+
year = String(gregorianDate.year).padStart(4, "0");
|
|
19
|
+
}
|
|
20
|
+
return `${year}-${String(gregorianDate.month).padStart(2, "0")}-${String(gregorianDate.day).padStart(2, "0")}`;
|
|
21
|
+
}
|
|
22
|
+
function dateTimeToString(date) {
|
|
23
|
+
return `${dateToString(date)}T${timeToString(date)}`;
|
|
24
|
+
}
|
|
25
|
+
function offsetToString(offset) {
|
|
26
|
+
let sign = Math.sign(offset) < 0 ? "-" : "+";
|
|
27
|
+
offset = Math.abs(offset);
|
|
28
|
+
let offsetHours = Math.floor(offset / (60 * 60 * 1e3));
|
|
29
|
+
let offsetMinutes = Math.floor(offset % (60 * 60 * 1e3) / (60 * 1e3));
|
|
30
|
+
let offsetSeconds = Math.floor(offset % (60 * 60 * 1e3) % (60 * 1e3) / 1e3);
|
|
31
|
+
let stringOffset = `${sign}${String(offsetHours).padStart(2, "0")}:${String(offsetMinutes).padStart(2, "0")}`;
|
|
32
|
+
if (offsetSeconds !== 0) {
|
|
33
|
+
stringOffset += `:${String(offsetSeconds).padStart(2, "0")}`;
|
|
34
|
+
}
|
|
35
|
+
return stringOffset;
|
|
36
|
+
}
|
|
37
|
+
function zonedDateTimeToString(date) {
|
|
38
|
+
return `${dateTimeToString(date)}${offsetToString(date.offset)}[${date.timeZone}]`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.dateTimeToString = dateTimeToString;
|
|
42
|
+
exports.dateToString = dateToString;
|
|
43
|
+
exports.timeToString = timeToString;
|
|
44
|
+
exports.zonedDateTimeToString = zonedDateTimeToString;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { toCalendar } from './conversion.js';
|
|
3
|
+
import { GregorianCalendar } from './calendars/GregorianCalendar.js';
|
|
4
|
+
|
|
5
|
+
function timeToString(time) {
|
|
6
|
+
return `${String(time.hour).padStart(2, "0")}:${String(time.minute).padStart(2, "0")}:${String(time.second).padStart(2, "0")}${time.millisecond ? String(time.millisecond / 1e3).slice(1) : ""}`;
|
|
7
|
+
}
|
|
8
|
+
function dateToString(date) {
|
|
9
|
+
let gregorianDate = toCalendar(date, new GregorianCalendar());
|
|
10
|
+
let year;
|
|
11
|
+
if (gregorianDate.era === "BC") {
|
|
12
|
+
year = gregorianDate.year === 1 ? "0000" : "-" + String(Math.abs(1 - gregorianDate.year)).padStart(6, "00");
|
|
13
|
+
} else {
|
|
14
|
+
year = String(gregorianDate.year).padStart(4, "0");
|
|
15
|
+
}
|
|
16
|
+
return `${year}-${String(gregorianDate.month).padStart(2, "0")}-${String(gregorianDate.day).padStart(2, "0")}`;
|
|
17
|
+
}
|
|
18
|
+
function dateTimeToString(date) {
|
|
19
|
+
return `${dateToString(date)}T${timeToString(date)}`;
|
|
20
|
+
}
|
|
21
|
+
function offsetToString(offset) {
|
|
22
|
+
let sign = Math.sign(offset) < 0 ? "-" : "+";
|
|
23
|
+
offset = Math.abs(offset);
|
|
24
|
+
let offsetHours = Math.floor(offset / (60 * 60 * 1e3));
|
|
25
|
+
let offsetMinutes = Math.floor(offset % (60 * 60 * 1e3) / (60 * 1e3));
|
|
26
|
+
let offsetSeconds = Math.floor(offset % (60 * 60 * 1e3) % (60 * 1e3) / 1e3);
|
|
27
|
+
let stringOffset = `${sign}${String(offsetHours).padStart(2, "0")}:${String(offsetMinutes).padStart(2, "0")}`;
|
|
28
|
+
if (offsetSeconds !== 0) {
|
|
29
|
+
stringOffset += `:${String(offsetSeconds).padStart(2, "0")}`;
|
|
30
|
+
}
|
|
31
|
+
return stringOffset;
|
|
32
|
+
}
|
|
33
|
+
function zonedDateTimeToString(date) {
|
|
34
|
+
return `${dateTimeToString(date)}${offsetToString(date.offset)}[${date.timeZone}]`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { dateTimeToString, dateToString, timeToString, zonedDateTimeToString };
|