@primeui/scheduler-core 0.0.1-alpha.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.
Files changed (63) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +1 -0
  3. package/dist/calendar/index.d.mts +57 -0
  4. package/dist/calendar/index.mjs +1 -0
  5. package/dist/chunk-2B3YLWHA.mjs +196 -0
  6. package/dist/chunk-2THQAZ26.mjs +1669 -0
  7. package/dist/chunk-5KORIWDT.mjs +41 -0
  8. package/dist/chunk-5N4ZOBJV.mjs +866 -0
  9. package/dist/chunk-6OZAPQZ5.mjs +229 -0
  10. package/dist/chunk-6PK5WSKT.mjs +369 -0
  11. package/dist/chunk-6VYWVIGM.mjs +1170 -0
  12. package/dist/chunk-AAVM7UCG.mjs +100 -0
  13. package/dist/chunk-C7ADJGNV.mjs +157 -0
  14. package/dist/chunk-DYW6WUHE.mjs +277 -0
  15. package/dist/chunk-F5W5HD7S.mjs +285 -0
  16. package/dist/chunk-FIBAZFC4.mjs +871 -0
  17. package/dist/chunk-HPC5B3AR.mjs +558 -0
  18. package/dist/chunk-KQGRXTP5.mjs +650 -0
  19. package/dist/chunk-NMX4BW42.mjs +672 -0
  20. package/dist/chunk-NX46LPLF.mjs +440 -0
  21. package/dist/chunk-NZGJN7HG.mjs +314 -0
  22. package/dist/chunk-QDMZBJDV.mjs +251 -0
  23. package/dist/chunk-QR2SVYAD.mjs +1144 -0
  24. package/dist/chunk-SYJ5O4KH.mjs +136 -0
  25. package/dist/chunk-TNKJPFGI.mjs +569 -0
  26. package/dist/chunk-UMAMDBU4.mjs +1 -0
  27. package/dist/chunk-W2SJW3QQ.mjs +3925 -0
  28. package/dist/chunk-WFUJWDST.mjs +352 -0
  29. package/dist/chunk-XUBQ2IQS.mjs +1 -0
  30. package/dist/chunk-ZUKUKGNK.mjs +613 -0
  31. package/dist/controllers/index.d.mts +384 -0
  32. package/dist/controllers/index.mjs +13 -0
  33. package/dist/date-D_CjQPmM.d.mts +74 -0
  34. package/dist/display-format-CLVvRt4I.d.mts +57 -0
  35. package/dist/event/index.d.mts +267 -0
  36. package/dist/event/index.mjs +8 -0
  37. package/dist/event-surface-_R_LHD95.d.mts +21 -0
  38. package/dist/event.positioning-BdzAVPk7.d.mts +51 -0
  39. package/dist/event.utils-QSNdd-3W.d.mts +35 -0
  40. package/dist/index.d.mts +1128 -0
  41. package/dist/index.mjs +1022 -0
  42. package/dist/interaction/index.d.mts +442 -0
  43. package/dist/interaction/index.mjs +9 -0
  44. package/dist/month/index.d.mts +104 -0
  45. package/dist/month/index.mjs +6 -0
  46. package/dist/overlay-BYM9B6nC.d.mts +64 -0
  47. package/dist/resource/index.d.mts +172 -0
  48. package/dist/resource/index.mjs +1 -0
  49. package/dist/selection-CO_98HdS.d.mts +56 -0
  50. package/dist/time-grid/index.d.mts +92 -0
  51. package/dist/time-grid/index.mjs +13 -0
  52. package/dist/timeline/index.d.mts +165 -0
  53. package/dist/timeline/index.mjs +6 -0
  54. package/dist/touch-BhsMWsjf.d.mts +69 -0
  55. package/dist/utils/index.d.mts +494 -0
  56. package/dist/utils/index.mjs +17 -0
  57. package/dist/views/index.d.mts +51 -0
  58. package/dist/views/index.mjs +8 -0
  59. package/dist/views/timeline/index.d.mts +37 -0
  60. package/dist/views/timeline/index.mjs +4 -0
  61. package/dist/year/index.d.mts +70 -0
  62. package/dist/year/index.mjs +6 -0
  63. package/package.json +58 -0
@@ -0,0 +1,100 @@
1
+ import { normalizeBusinessHours, getBlockedIntervalsForDay } from './chunk-HPC5B3AR.mjs';
2
+ import { timeStringToMinutes, minutesToPixels } from './chunk-WFUJWDST.mjs';
3
+
4
+ // src/utils/overlay.ts
5
+ function getTimedBusinessHoursOverlays(date, businessHours, slotMinTime, slotMaxTime, slotDuration, slotHeight) {
6
+ const configs = normalizeBusinessHours(businessHours);
7
+ if (configs.length === 0) return [];
8
+ const dayOfWeek = date.getDay();
9
+ const config = configs.find((c) => c.daysOfWeek.includes(dayOfWeek));
10
+ const overlays = [];
11
+ const slotMinMinutes = timeStringToMinutes(slotMinTime);
12
+ const slotMaxMinutes = timeStringToMinutes(slotMaxTime);
13
+ const pushOverlay = (startMinutes, endMinutes) => {
14
+ const clampedStart = Math.max(startMinutes, slotMinMinutes);
15
+ const clampedEnd = Math.min(endMinutes, slotMaxMinutes);
16
+ if (clampedStart >= clampedEnd) return;
17
+ const top = minutesToPixels(clampedStart - slotMinMinutes, slotDuration, slotHeight);
18
+ const height = minutesToPixels(clampedEnd - clampedStart, slotDuration, slotHeight);
19
+ overlays.push({
20
+ position: "absolute",
21
+ top: top === 0 ? "0" : `${top}px`,
22
+ left: "0",
23
+ right: "0",
24
+ height: `${height}px`,
25
+ pointerEvents: "none",
26
+ zIndex: "0"
27
+ });
28
+ };
29
+ if (!config) {
30
+ pushOverlay(slotMinMinutes, slotMaxMinutes);
31
+ return overlays;
32
+ }
33
+ const businessStartMinutes = timeStringToMinutes(config.startTime);
34
+ const businessEndMinutes = timeStringToMinutes(config.endTime);
35
+ pushOverlay(slotMinMinutes, businessStartMinutes);
36
+ pushOverlay(businessEndMinutes, slotMaxMinutes);
37
+ return overlays;
38
+ }
39
+ function getTimedBlockedIntervalsOverlays(date, blockedIntervals, slotMinTime, slotMaxTime, slotDuration, slotHeight, resourceId) {
40
+ if (!blockedIntervals) return [];
41
+ const intervals = getBlockedIntervalsForDay(blockedIntervals, date, resourceId);
42
+ if (intervals.length === 0) return [];
43
+ const overlays = [];
44
+ const slotMinMinutes = timeStringToMinutes(slotMinTime);
45
+ const slotMaxMinutes = timeStringToMinutes(slotMaxTime);
46
+ for (const interval of intervals) {
47
+ const intervalStartMinutes = interval.start.getHours() * 60 + interval.start.getMinutes();
48
+ const intervalEndMinutes = interval.end.getHours() * 60 + interval.end.getMinutes();
49
+ const clampedStart = Math.max(intervalStartMinutes, slotMinMinutes);
50
+ const clampedEnd = Math.min(intervalEndMinutes, slotMaxMinutes);
51
+ if (clampedStart >= clampedEnd) continue;
52
+ const top = minutesToPixels(clampedStart - slotMinMinutes, slotDuration, slotHeight);
53
+ const height = minutesToPixels(clampedEnd - clampedStart, slotDuration, slotHeight);
54
+ const style = {
55
+ position: "absolute",
56
+ top: `${top}px`,
57
+ left: "0",
58
+ right: "0",
59
+ height: `${height}px`,
60
+ pointerEvents: "none",
61
+ zIndex: "2"
62
+ };
63
+ if (interval.background) {
64
+ style.background = interval.background;
65
+ }
66
+ overlays.push({
67
+ style,
68
+ title: interval.title,
69
+ className: interval.className,
70
+ interval
71
+ });
72
+ }
73
+ return overlays;
74
+ }
75
+ function isSlotInBusinessHours(slotTime, date, businessHours) {
76
+ if (!businessHours) return false;
77
+ const configs = normalizeBusinessHours(businessHours);
78
+ if (configs.length === 0) return false;
79
+ const dayOfWeek = date.getDay();
80
+ const config = configs.find((c) => c.daysOfWeek.includes(dayOfWeek));
81
+ if (!config) return false;
82
+ const slotMinutes = slotTime.getHours() * 60 + slotTime.getMinutes();
83
+ const bhStart = timeStringToMinutes(config.startTime);
84
+ const bhEnd = timeStringToMinutes(config.endTime);
85
+ return slotMinutes >= bhStart && slotMinutes < bhEnd;
86
+ }
87
+ function isSlotInBlockedInterval(slotTime, date, slotDuration, blockedIntervals, resourceId) {
88
+ if (!blockedIntervals) return false;
89
+ const intervals = getBlockedIntervalsForDay(blockedIntervals, date, resourceId);
90
+ if (intervals.length === 0) return false;
91
+ const slotMinutes = slotTime.getHours() * 60 + slotTime.getMinutes();
92
+ const slotEndMinutes = slotMinutes + slotDuration;
93
+ return intervals.some((interval) => {
94
+ const intStart = interval.start.getHours() * 60 + interval.start.getMinutes();
95
+ const intEnd = interval.end.getHours() * 60 + interval.end.getMinutes();
96
+ return slotMinutes < intEnd && slotEndMinutes > intStart;
97
+ });
98
+ }
99
+
100
+ export { getTimedBlockedIntervalsOverlays, getTimedBusinessHoursOverlays, isSlotInBlockedInterval, isSlotInBusinessHours };
@@ -0,0 +1,157 @@
1
+ // src/utils/event-categories.ts
2
+ var SCHEDULER_AUTO_TEXT_COLOR_KEY = "__primeuiSchedulerAutoTextColor";
3
+ var DEFAULT_CATEGORY_OPTIONS = {
4
+ categories: [],
5
+ categoryField: "categoryId",
6
+ allowMultiple: false,
7
+ showLegend: true,
8
+ legendPosition: "top",
9
+ filterByCategory: false
10
+ };
11
+ function normalizeCategoryOptions(options) {
12
+ if (!options) {
13
+ return { ...DEFAULT_CATEGORY_OPTIONS };
14
+ }
15
+ return { ...DEFAULT_CATEGORY_OPTIONS, ...options };
16
+ }
17
+ function getCategoryById(categories, id) {
18
+ if (id === void 0) return void 0;
19
+ return categories.find((cat) => cat.id === id);
20
+ }
21
+ function getCategoriesByIds(categories, ids) {
22
+ if (!ids || ids.length === 0) return [];
23
+ return categories.filter((cat) => ids.includes(cat.id));
24
+ }
25
+ function getEventCategory(event, categories, categoryField = "categoryId") {
26
+ const categoryId = event[categoryField];
27
+ return getCategoryById(categories, categoryId);
28
+ }
29
+ function getEventCategories(event, categories, categoryField = "categoryId", allowMultiple = false) {
30
+ if (allowMultiple) {
31
+ const categoryIds = event[`${categoryField}s`];
32
+ if (categoryIds && categoryIds.length > 0) {
33
+ return getCategoriesByIds(categories, categoryIds);
34
+ }
35
+ }
36
+ const category = getEventCategory(event, categories, categoryField);
37
+ return category ? [category] : [];
38
+ }
39
+ function getEventCategoryColor(event, categories, categoryField = "categoryId") {
40
+ if (event.color) return event.color;
41
+ const category = getEventCategory(event, categories, categoryField);
42
+ return category?.color;
43
+ }
44
+ function getEventCategoryTextColor(event, categories, categoryField = "categoryId") {
45
+ if (event.textColor) return event.textColor;
46
+ const category = getEventCategory(event, categories, categoryField);
47
+ return category?.textColor;
48
+ }
49
+ function getEventCategoryBorderColor(event, categories, categoryField = "categoryId") {
50
+ if (event.borderColor) return event.borderColor;
51
+ const category = getEventCategory(event, categories, categoryField);
52
+ return category?.borderColor || category?.color;
53
+ }
54
+ function getEventCategoryIcon(event, categories, categoryField = "categoryId") {
55
+ const category = getEventCategory(event, categories, categoryField);
56
+ return category?.icon;
57
+ }
58
+ function getEventCategoryStyle(event, categories, categoryField = "categoryId") {
59
+ const style = {};
60
+ const category = getEventCategory(event, categories, categoryField);
61
+ const bgColor = event.color || category?.color;
62
+ const textColor = event.textColor || category?.textColor;
63
+ const borderColor = event.borderColor || category?.borderColor || bgColor;
64
+ if (bgColor) {
65
+ style.background = bgColor;
66
+ style.borderLeftColor = borderColor;
67
+ }
68
+ if (textColor) {
69
+ style.color = textColor;
70
+ }
71
+ if (borderColor) {
72
+ style.borderColor = borderColor;
73
+ }
74
+ return style;
75
+ }
76
+ function filterEventsByCategory(events, categoryIds, categories, categoryField = "categoryId", allowMultiple = false) {
77
+ if (categoryIds.length === 0) return events;
78
+ return events.filter((event) => {
79
+ const eventCategories = getEventCategories(event, categories, categoryField, allowMultiple);
80
+ return eventCategories.some((cat) => categoryIds.includes(cat.id));
81
+ });
82
+ }
83
+ function filterEventsByCategoryExclude(events, excludeCategoryIds, categories, categoryField = "categoryId", allowMultiple = false) {
84
+ if (excludeCategoryIds.length === 0) return events;
85
+ return events.filter((event) => {
86
+ const eventCategories = getEventCategories(event, categories, categoryField, allowMultiple);
87
+ return !eventCategories.some((cat) => excludeCategoryIds.includes(cat.id));
88
+ });
89
+ }
90
+ function groupEventsByCategory(events, categories, categoryField = "categoryId") {
91
+ const grouped = /* @__PURE__ */ new Map();
92
+ for (const category of categories) {
93
+ grouped.set(category.id, []);
94
+ }
95
+ grouped.set("uncategorized", []);
96
+ for (const event of events) {
97
+ const categoryId = event[categoryField];
98
+ if (categoryId !== void 0 && grouped.has(categoryId)) {
99
+ grouped.get(categoryId).push(event);
100
+ } else {
101
+ grouped.get("uncategorized").push(event);
102
+ }
103
+ }
104
+ return grouped;
105
+ }
106
+ function getCategoryCounts(events, categories, categoryField = "categoryId") {
107
+ const counts = /* @__PURE__ */ new Map();
108
+ for (const category of categories) {
109
+ counts.set(category.id, 0);
110
+ }
111
+ for (const event of events) {
112
+ const categoryId = event[categoryField];
113
+ if (categoryId !== void 0 && counts.has(categoryId)) {
114
+ counts.set(categoryId, counts.get(categoryId) + 1);
115
+ }
116
+ }
117
+ return counts;
118
+ }
119
+ function getSortedCategories(categories) {
120
+ return [...categories].sort((a, b) => {
121
+ const orderA = a.sortOrder ?? Number.MAX_SAFE_INTEGER;
122
+ const orderB = b.sortOrder ?? Number.MAX_SAFE_INTEGER;
123
+ if (orderA !== orderB) return orderA - orderB;
124
+ return a.name.localeCompare(b.name);
125
+ });
126
+ }
127
+ function calculateContrastTextColor(backgroundColor) {
128
+ const hex = backgroundColor.replace("#", "");
129
+ const r = parseInt(hex.substring(0, 2), 16);
130
+ const g = parseInt(hex.substring(2, 4), 16);
131
+ const b = parseInt(hex.substring(4, 6), 16);
132
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
133
+ return luminance > 0.5 ? "#000000" : "#ffffff";
134
+ }
135
+ function getCategoryWithAutoTextColor(category) {
136
+ if (category.textColor) return category;
137
+ return {
138
+ ...category,
139
+ textColor: calculateContrastTextColor(category.color)
140
+ };
141
+ }
142
+ function getCategoriesWithAutoTextColor(categories) {
143
+ return categories.map(getCategoryWithAutoTextColor);
144
+ }
145
+ function markSchedulerAutoTextColor(event) {
146
+ Object.defineProperty(event, SCHEDULER_AUTO_TEXT_COLOR_KEY, {
147
+ value: true,
148
+ enumerable: true,
149
+ configurable: true
150
+ });
151
+ return event;
152
+ }
153
+ function isSchedulerAutoTextColor(event) {
154
+ return Boolean(event && event[SCHEDULER_AUTO_TEXT_COLOR_KEY] === true);
155
+ }
156
+
157
+ export { DEFAULT_CATEGORY_OPTIONS, calculateContrastTextColor, filterEventsByCategory, filterEventsByCategoryExclude, getCategoriesByIds, getCategoriesWithAutoTextColor, getCategoryById, getCategoryCounts, getCategoryWithAutoTextColor, getEventCategories, getEventCategory, getEventCategoryBorderColor, getEventCategoryColor, getEventCategoryIcon, getEventCategoryStyle, getEventCategoryTextColor, getSortedCategories, groupEventsByCategory, isSchedulerAutoTextColor, markSchedulerAutoTextColor, normalizeCategoryOptions };
@@ -0,0 +1,277 @@
1
+ import { GregorianCalendar, toCalendar, CalendarDate, TaiwanCalendar, PersianCalendar, JapaneseCalendar, IslamicUmalquraCalendar, IslamicTabularCalendar, IslamicCivilCalendar, IndianCalendar, HebrewCalendar, CopticCalendar, EthiopicAmeteAlemCalendar, EthiopicCalendar, BuddhistCalendar } from '@internationalized/date';
2
+
3
+ // src/calendar/index.ts
4
+ var schedulerInternationalCalendarIds = ["gregory", "buddhist", "ethiopic", "ethioaa", "coptic", "hebrew", "indian", "islamic-civil", "islamic-tbla", "islamic-umalqura", "japanese", "persian", "roc"];
5
+ var supportedCalendarIds = new Set(schedulerInternationalCalendarIds);
6
+ var calendarAdaptedViews = /* @__PURE__ */ new Set([
7
+ "month",
8
+ "year",
9
+ "dateDay",
10
+ "dateWeek",
11
+ "dateMonth",
12
+ "resourceMonth",
13
+ "day",
14
+ "week",
15
+ "resourceDay",
16
+ "resourceWeek",
17
+ "agenda",
18
+ "timelineDay",
19
+ "timelineWeek",
20
+ "timelineMonth",
21
+ "timelineYear",
22
+ "resourceTimelineDay",
23
+ "resourceTimelineWeek",
24
+ "resourceTimelineMonth"
25
+ ]);
26
+ var gregorianInternationalCalendar = new GregorianCalendar();
27
+ function toGregorianDate(date) {
28
+ return new Date(date.year, date.month - 1, date.day);
29
+ }
30
+ function fromGregorianDate(date) {
31
+ return {
32
+ year: date.getFullYear(),
33
+ month: date.getMonth() + 1,
34
+ day: date.getDate()
35
+ };
36
+ }
37
+ function addMonths(date, amount) {
38
+ const next = new Date(date);
39
+ const day = next.getDate();
40
+ next.setMonth(next.getMonth() + amount);
41
+ if (next.getDate() !== day) {
42
+ next.setDate(0);
43
+ }
44
+ return next;
45
+ }
46
+ var gregorianCalendarAdapter = {
47
+ id: "gregory",
48
+ fromDate: fromGregorianDate,
49
+ toDate: toGregorianDate,
50
+ add(date, duration) {
51
+ let next = toGregorianDate(date);
52
+ if (duration.years) {
53
+ next.setFullYear(next.getFullYear() + duration.years);
54
+ }
55
+ if (duration.months) {
56
+ next = addMonths(next, duration.months);
57
+ }
58
+ if (duration.days) {
59
+ next.setDate(next.getDate() + duration.days);
60
+ }
61
+ return fromGregorianDate(next);
62
+ },
63
+ startOfMonth(date) {
64
+ return { year: date.year, month: date.month, day: 1 };
65
+ },
66
+ endOfMonth(date) {
67
+ return { year: date.year, month: date.month, day: this.getDaysInMonth(date) };
68
+ },
69
+ startOfWeek(date, firstDayOfWeek) {
70
+ const dayOfWeek = this.getDayOfWeek(date);
71
+ const diff = (dayOfWeek - firstDayOfWeek + 7) % 7;
72
+ return this.add(date, { days: -diff });
73
+ },
74
+ getDayOfWeek(date) {
75
+ return toGregorianDate(date).getDay();
76
+ },
77
+ getDaysInMonth(date) {
78
+ return new Date(date.year, date.month, 0).getDate();
79
+ },
80
+ getMonthsInYear() {
81
+ return 12;
82
+ },
83
+ compare(a, b) {
84
+ return toGregorianDate(a).getTime() - toGregorianDate(b).getTime();
85
+ },
86
+ isSameDay(a, b) {
87
+ return a.year === b.year && a.month === b.month && a.day === b.day;
88
+ }
89
+ };
90
+ function isSupportedInternationalCalendarId(calendarId) {
91
+ return supportedCalendarIds.has(calendarId);
92
+ }
93
+ function resolveLocaleCalendarId(locale) {
94
+ try {
95
+ return new Intl.DateTimeFormat(locale).resolvedOptions().calendar || "gregory";
96
+ } catch {
97
+ return "gregory";
98
+ }
99
+ }
100
+ function resolveSchedulerCalendarId(calendar = "gregory", options = {}) {
101
+ const locale = options.locale || "en";
102
+ const calendarId = calendar === "locale" ? resolveLocaleCalendarId(locale) : calendar;
103
+ const isSupported = Boolean(options.createCalendar) || isSupportedInternationalCalendarId(calendarId);
104
+ return {
105
+ requestedCalendar: calendar,
106
+ locale,
107
+ calendarId: isSupported ? calendarId : "gregory",
108
+ isSupported,
109
+ fallbackCalendarId: isSupported ? null : "gregory"
110
+ };
111
+ }
112
+ function isCalendarAdapterCorrectView(view) {
113
+ return Boolean(view && calendarAdaptedViews.has(view));
114
+ }
115
+ function resolveSchedulerCalendarModeForView(calendar, view) {
116
+ if (!calendar || calendar === "gregory") {
117
+ return "gregory";
118
+ }
119
+ if (!view) {
120
+ return calendar;
121
+ }
122
+ return isCalendarAdapterCorrectView(view) ? calendar : "gregory";
123
+ }
124
+ function getCalendarInteractionAdapter(options = {}) {
125
+ const mode = resolveSchedulerCalendarModeForView(options.calendar ?? "gregory", options.view);
126
+ return getSchedulerCalendarAdapter(mode, { locale: options.locale });
127
+ }
128
+ function copyTime(source, target) {
129
+ const result = new Date(target);
130
+ result.setHours(source.getHours(), source.getMinutes(), source.getSeconds(), source.getMilliseconds());
131
+ return result;
132
+ }
133
+ function localDayStart(date) {
134
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
135
+ }
136
+ function moveDateToCalendarDay(sourceDate, targetDay, options = {}) {
137
+ const source = new Date(sourceDate);
138
+ const adapter = getCalendarInteractionAdapter(options);
139
+ const targetCalendarDate = adapter.fromDate(targetDay);
140
+ return copyTime(source, adapter.toDate(targetCalendarDate));
141
+ }
142
+ function addCalendarDaysToDate(sourceDate, days, options = {}) {
143
+ const source = new Date(sourceDate);
144
+ if (days === 0) {
145
+ return new Date(source);
146
+ }
147
+ const adapter = getCalendarInteractionAdapter(options);
148
+ const sourceCalendarDate = adapter.fromDate(source);
149
+ const targetCalendarDate = adapter.add(sourceCalendarDate, { days });
150
+ return copyTime(source, adapter.toDate(targetCalendarDate));
151
+ }
152
+ function differenceInCalendarDays(startDate, endDate, options = {}) {
153
+ const adapter = getCalendarInteractionAdapter(options);
154
+ const startCalendarDate = adapter.fromDate(startDate);
155
+ const endCalendarDate = adapter.fromDate(endDate);
156
+ if (adapter.isSameDay(startCalendarDate, endCalendarDate)) {
157
+ return 0;
158
+ }
159
+ let days = Math.round((localDayStart(endDate).getTime() - localDayStart(startDate).getTime()) / (24 * 60 * 60 * 1e3));
160
+ let candidate = adapter.add(startCalendarDate, { days });
161
+ while (adapter.compare(candidate, endCalendarDate) < 0) {
162
+ days += 1;
163
+ candidate = adapter.add(startCalendarDate, { days });
164
+ }
165
+ while (adapter.compare(candidate, endCalendarDate) > 0) {
166
+ days -= 1;
167
+ candidate = adapter.add(startCalendarDate, { days });
168
+ }
169
+ return days;
170
+ }
171
+ function createBuiltInInternationalCalendar(calendarId) {
172
+ switch (calendarId) {
173
+ case "buddhist":
174
+ return new BuddhistCalendar();
175
+ case "ethiopic":
176
+ return new EthiopicCalendar();
177
+ case "ethioaa":
178
+ return new EthiopicAmeteAlemCalendar();
179
+ case "coptic":
180
+ return new CopticCalendar();
181
+ case "hebrew":
182
+ return new HebrewCalendar();
183
+ case "indian":
184
+ return new IndianCalendar();
185
+ case "islamic-civil":
186
+ return new IslamicCivilCalendar();
187
+ case "islamic-tbla":
188
+ return new IslamicTabularCalendar();
189
+ case "islamic-umalqura":
190
+ return new IslamicUmalquraCalendar();
191
+ case "japanese":
192
+ return new JapaneseCalendar();
193
+ case "persian":
194
+ return new PersianCalendar();
195
+ case "roc":
196
+ return new TaiwanCalendar();
197
+ case "gregory":
198
+ default:
199
+ return new GregorianCalendar();
200
+ }
201
+ }
202
+ function toSchedulerCalendarDate(date) {
203
+ return {
204
+ era: date.era,
205
+ year: date.year,
206
+ month: date.month,
207
+ day: date.day
208
+ };
209
+ }
210
+ function toInternationalizedCalendarDate(date, calendar) {
211
+ return date.era ? new CalendarDate(calendar, date.era, date.year, date.month, date.day) : new CalendarDate(calendar, date.year, date.month, date.day);
212
+ }
213
+ function toLocalDateFromGregorianCalendarDate(date) {
214
+ return new Date(date.year, date.month - 1, date.day);
215
+ }
216
+ function createInternationalizedSchedulerCalendarAdapter(id, calendar) {
217
+ return {
218
+ id,
219
+ fromDate(date) {
220
+ const gregorianDate = new CalendarDate(gregorianInternationalCalendar, date.getFullYear(), date.getMonth() + 1, date.getDate());
221
+ return toSchedulerCalendarDate(toCalendar(gregorianDate, calendar));
222
+ },
223
+ toDate(date) {
224
+ const calendarDate = toInternationalizedCalendarDate(date, calendar);
225
+ const gregorianDate = toCalendar(calendarDate, gregorianInternationalCalendar);
226
+ return toLocalDateFromGregorianCalendarDate(gregorianDate);
227
+ },
228
+ add(date, duration) {
229
+ return toSchedulerCalendarDate(toInternationalizedCalendarDate(date, calendar).add(duration));
230
+ },
231
+ startOfMonth(date) {
232
+ const calendarDate = toInternationalizedCalendarDate(date, calendar);
233
+ return toSchedulerCalendarDate(calendarDate.set({ day: calendar.getMinimumDayInMonth?.(calendarDate) ?? 1 }));
234
+ },
235
+ endOfMonth(date) {
236
+ const calendarDate = toInternationalizedCalendarDate(date, calendar);
237
+ return toSchedulerCalendarDate(calendarDate.set({ day: calendar.getDaysInMonth(calendarDate) }));
238
+ },
239
+ startOfWeek(date, firstDayOfWeek) {
240
+ const dayOfWeek = this.getDayOfWeek(date);
241
+ const diff = (dayOfWeek - firstDayOfWeek + 7) % 7;
242
+ return this.add(date, { days: -diff });
243
+ },
244
+ getDayOfWeek(date) {
245
+ return this.toDate(date).getDay();
246
+ },
247
+ getDaysInMonth(date) {
248
+ return calendar.getDaysInMonth(toInternationalizedCalendarDate(date, calendar));
249
+ },
250
+ getMonthsInYear(date) {
251
+ return calendar.getMonthsInYear(toInternationalizedCalendarDate(date, calendar));
252
+ },
253
+ compare(a, b) {
254
+ return toInternationalizedCalendarDate(a, calendar).compare(toInternationalizedCalendarDate(b, calendar));
255
+ },
256
+ isSameDay(a, b) {
257
+ return this.compare(a, b) === 0;
258
+ }
259
+ };
260
+ }
261
+ function getSchedulerCalendarAdapter(calendar, options = {}) {
262
+ const requestedCalendar = calendar ?? "gregory";
263
+ const resolution = resolveSchedulerCalendarId(requestedCalendar, options);
264
+ const customCalendar = options.createCalendar?.(requestedCalendar === "locale" ? resolution.calendarId : requestedCalendar);
265
+ if (customCalendar) {
266
+ return createInternationalizedSchedulerCalendarAdapter(requestedCalendar === "locale" ? resolution.calendarId : requestedCalendar, customCalendar);
267
+ }
268
+ if (resolution.calendarId === "gregory") {
269
+ return gregorianCalendarAdapter;
270
+ }
271
+ if (!isSupportedInternationalCalendarId(resolution.calendarId)) {
272
+ return gregorianCalendarAdapter;
273
+ }
274
+ return createInternationalizedSchedulerCalendarAdapter(resolution.calendarId, createBuiltInInternationalCalendar(resolution.calendarId));
275
+ }
276
+
277
+ export { addCalendarDaysToDate, differenceInCalendarDays, getSchedulerCalendarAdapter, gregorianCalendarAdapter, isCalendarAdapterCorrectView, moveDateToCalendarDay, resolveSchedulerCalendarId, resolveSchedulerCalendarModeForView, schedulerInternationalCalendarIds };