tyrell-components 1.0.0-RC10
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/LICENSE +21 -0
- package/README.md +221 -0
- package/css/tyrell-brand.css +767 -0
- package/css/tyrell.css +1679 -0
- package/dist/tyrell-brand.css +767 -0
- package/dist/tyrell.css +1679 -0
- package/dist/tyrell.js +2 -0
- package/lib/base/ty-component.d.ts +133 -0
- package/lib/base/ty-component.d.ts.map +1 -0
- package/lib/base/ty-component.js +297 -0
- package/lib/base/ty-component.js.map +1 -0
- package/lib/components/button.d.ts +135 -0
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +277 -0
- package/lib/components/button.js.map +1 -0
- package/lib/components/calendar-month.d.ts +132 -0
- package/lib/components/calendar-month.d.ts.map +1 -0
- package/lib/components/calendar-month.js +440 -0
- package/lib/components/calendar-month.js.map +1 -0
- package/lib/components/calendar-navigation.d.ts +137 -0
- package/lib/components/calendar-navigation.d.ts.map +1 -0
- package/lib/components/calendar-navigation.js +366 -0
- package/lib/components/calendar-navigation.js.map +1 -0
- package/lib/components/calendar.d.ts +166 -0
- package/lib/components/calendar.d.ts.map +1 -0
- package/lib/components/calendar.js +774 -0
- package/lib/components/calendar.js.map +1 -0
- package/lib/components/checkbox.d.ts +189 -0
- package/lib/components/checkbox.d.ts.map +1 -0
- package/lib/components/checkbox.js +400 -0
- package/lib/components/checkbox.js.map +1 -0
- package/lib/components/copy.d.ts +180 -0
- package/lib/components/copy.d.ts.map +1 -0
- package/lib/components/copy.js +393 -0
- package/lib/components/copy.js.map +1 -0
- package/lib/components/date-picker.d.ts +379 -0
- package/lib/components/date-picker.d.ts.map +1 -0
- package/lib/components/date-picker.js +1586 -0
- package/lib/components/date-picker.js.map +1 -0
- package/lib/components/dropdown.d.ts +424 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +1640 -0
- package/lib/components/dropdown.js.map +1 -0
- package/lib/components/file-upload.d.ts +121 -0
- package/lib/components/file-upload.d.ts.map +1 -0
- package/lib/components/file-upload.js +441 -0
- package/lib/components/file-upload.js.map +1 -0
- package/lib/components/icon.d.ts +118 -0
- package/lib/components/icon.d.ts.map +1 -0
- package/lib/components/icon.js +245 -0
- package/lib/components/icon.js.map +1 -0
- package/lib/components/input.d.ts +270 -0
- package/lib/components/input.d.ts.map +1 -0
- package/lib/components/input.js +721 -0
- package/lib/components/input.js.map +1 -0
- package/lib/components/modal.d.ts +78 -0
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +497 -0
- package/lib/components/modal.js.map +1 -0
- package/lib/components/multiselect.d.ts +397 -0
- package/lib/components/multiselect.d.ts.map +1 -0
- package/lib/components/multiselect.js +1595 -0
- package/lib/components/multiselect.js.map +1 -0
- package/lib/components/option.d.ts +66 -0
- package/lib/components/option.d.ts.map +1 -0
- package/lib/components/option.js +314 -0
- package/lib/components/option.js.map +1 -0
- package/lib/components/popup.d.ts +43 -0
- package/lib/components/popup.d.ts.map +1 -0
- package/lib/components/popup.js +380 -0
- package/lib/components/popup.js.map +1 -0
- package/lib/components/radio.d.ts +198 -0
- package/lib/components/radio.d.ts.map +1 -0
- package/lib/components/radio.js +437 -0
- package/lib/components/radio.js.map +1 -0
- package/lib/components/resize-observer.d.ts +48 -0
- package/lib/components/resize-observer.d.ts.map +1 -0
- package/lib/components/resize-observer.js +108 -0
- package/lib/components/resize-observer.js.map +1 -0
- package/lib/components/scroll-container.d.ts +51 -0
- package/lib/components/scroll-container.d.ts.map +1 -0
- package/lib/components/scroll-container.js +239 -0
- package/lib/components/scroll-container.js.map +1 -0
- package/lib/components/step.d.ts +26 -0
- package/lib/components/step.d.ts.map +1 -0
- package/lib/components/step.js +75 -0
- package/lib/components/step.js.map +1 -0
- package/lib/components/switch.d.ts +111 -0
- package/lib/components/switch.d.ts.map +1 -0
- package/lib/components/switch.js +240 -0
- package/lib/components/switch.js.map +1 -0
- package/lib/components/tab.d.ts +23 -0
- package/lib/components/tab.d.ts.map +1 -0
- package/lib/components/tab.js +76 -0
- package/lib/components/tab.js.map +1 -0
- package/lib/components/tabs.d.ts +93 -0
- package/lib/components/tabs.d.ts.map +1 -0
- package/lib/components/tabs.js +653 -0
- package/lib/components/tabs.js.map +1 -0
- package/lib/components/tag.d.ts +144 -0
- package/lib/components/tag.d.ts.map +1 -0
- package/lib/components/tag.js +316 -0
- package/lib/components/tag.js.map +1 -0
- package/lib/components/textarea.d.ts +241 -0
- package/lib/components/textarea.d.ts.map +1 -0
- package/lib/components/textarea.js +585 -0
- package/lib/components/textarea.js.map +1 -0
- package/lib/components/tooltip.d.ts +40 -0
- package/lib/components/tooltip.d.ts.map +1 -0
- package/lib/components/tooltip.js +439 -0
- package/lib/components/tooltip.js.map +1 -0
- package/lib/components/wizard.d.ts +86 -0
- package/lib/components/wizard.d.ts.map +1 -0
- package/lib/components/wizard.js +636 -0
- package/lib/components/wizard.js.map +1 -0
- package/lib/icons/fontawesome/brands.d.ts +557 -0
- package/lib/icons/fontawesome/brands.d.ts.map +1 -0
- package/lib/icons/fontawesome/brands.js +557 -0
- package/lib/icons/fontawesome/brands.js.map +1 -0
- package/lib/icons/fontawesome/regular.d.ts +281 -0
- package/lib/icons/fontawesome/regular.d.ts.map +1 -0
- package/lib/icons/fontawesome/regular.js +281 -0
- package/lib/icons/fontawesome/regular.js.map +1 -0
- package/lib/icons/fontawesome/solid.d.ts +1992 -0
- package/lib/icons/fontawesome/solid.d.ts.map +1 -0
- package/lib/icons/fontawesome/solid.js +1992 -0
- package/lib/icons/fontawesome/solid.js.map +1 -0
- package/lib/icons/heroicons/micro.d.ts +324 -0
- package/lib/icons/heroicons/micro.d.ts.map +1 -0
- package/lib/icons/heroicons/micro.js +1032 -0
- package/lib/icons/heroicons/micro.js.map +1 -0
- package/lib/icons/heroicons/mini.d.ts +332 -0
- package/lib/icons/heroicons/mini.d.ts.map +1 -0
- package/lib/icons/heroicons/mini.js +1038 -0
- package/lib/icons/heroicons/mini.js.map +1 -0
- package/lib/icons/heroicons/outline.d.ts +332 -0
- package/lib/icons/heroicons/outline.d.ts.map +1 -0
- package/lib/icons/heroicons/outline.js +993 -0
- package/lib/icons/heroicons/outline.js.map +1 -0
- package/lib/icons/heroicons/solid.d.ts +332 -0
- package/lib/icons/heroicons/solid.d.ts.map +1 -0
- package/lib/icons/heroicons/solid.js +1063 -0
- package/lib/icons/heroicons/solid.js.map +1 -0
- package/lib/icons/lucide.d.ts +1872 -0
- package/lib/icons/lucide.d.ts.map +1 -0
- package/lib/icons/lucide.js +28212 -0
- package/lib/icons/lucide.js.map +1 -0
- package/lib/icons/material/filled.d.ts +2180 -0
- package/lib/icons/material/filled.d.ts.map +1 -0
- package/lib/icons/material/filled.js +14003 -0
- package/lib/icons/material/filled.js.map +1 -0
- package/lib/icons/material/outlined.d.ts +2142 -0
- package/lib/icons/material/outlined.d.ts.map +1 -0
- package/lib/icons/material/outlined.js +14545 -0
- package/lib/icons/material/outlined.js.map +1 -0
- package/lib/icons/material/round.d.ts +2147 -0
- package/lib/icons/material/round.d.ts.map +1 -0
- package/lib/icons/material/round.js +14779 -0
- package/lib/icons/material/round.js.map +1 -0
- package/lib/icons/material/sharp.d.ts +2147 -0
- package/lib/icons/material/sharp.d.ts.map +1 -0
- package/lib/icons/material/sharp.js +14189 -0
- package/lib/icons/material/sharp.js.map +1 -0
- package/lib/icons/material/two-tone.d.ts +2185 -0
- package/lib/icons/material/two-tone.d.ts.map +1 -0
- package/lib/icons/material/two-tone.js +17152 -0
- package/lib/icons/material/two-tone.js.map +1 -0
- package/lib/index.d.ts +86 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +78 -0
- package/lib/index.js.map +1 -0
- package/lib/styles/button.d.ts +14 -0
- package/lib/styles/button.d.ts.map +1 -0
- package/lib/styles/button.js +498 -0
- package/lib/styles/button.js.map +1 -0
- package/lib/styles/calendar-month.d.ts +6 -0
- package/lib/styles/calendar-month.d.ts.map +1 -0
- package/lib/styles/calendar-month.js +275 -0
- package/lib/styles/calendar-month.js.map +1 -0
- package/lib/styles/calendar-navigation.d.ts +6 -0
- package/lib/styles/calendar-navigation.d.ts.map +1 -0
- package/lib/styles/calendar-navigation.js +143 -0
- package/lib/styles/calendar-navigation.js.map +1 -0
- package/lib/styles/calendar.d.ts +6 -0
- package/lib/styles/calendar.d.ts.map +1 -0
- package/lib/styles/calendar.js +28 -0
- package/lib/styles/calendar.js.map +1 -0
- package/lib/styles/checkbox.d.ts +9 -0
- package/lib/styles/checkbox.d.ts.map +1 -0
- package/lib/styles/checkbox.js +19 -0
- package/lib/styles/checkbox.js.map +1 -0
- package/lib/styles/copy.d.ts +7 -0
- package/lib/styles/copy.d.ts.map +1 -0
- package/lib/styles/copy.js +94 -0
- package/lib/styles/copy.js.map +1 -0
- package/lib/styles/custom-scrollbar.d.ts +6 -0
- package/lib/styles/custom-scrollbar.d.ts.map +1 -0
- package/lib/styles/custom-scrollbar.js +157 -0
- package/lib/styles/custom-scrollbar.js.map +1 -0
- package/lib/styles/date-picker.d.ts +6 -0
- package/lib/styles/date-picker.d.ts.map +1 -0
- package/lib/styles/date-picker.js +438 -0
- package/lib/styles/date-picker.js.map +1 -0
- package/lib/styles/dropdown.d.ts +12 -0
- package/lib/styles/dropdown.d.ts.map +1 -0
- package/lib/styles/dropdown.js +1081 -0
- package/lib/styles/dropdown.js.map +1 -0
- package/lib/styles/file-upload.d.ts +2 -0
- package/lib/styles/file-upload.d.ts.map +1 -0
- package/lib/styles/file-upload.js +241 -0
- package/lib/styles/file-upload.js.map +1 -0
- package/lib/styles/icon.d.ts +6 -0
- package/lib/styles/icon.d.ts.map +1 -0
- package/lib/styles/icon.js +241 -0
- package/lib/styles/icon.js.map +1 -0
- package/lib/styles/input.d.ts +7 -0
- package/lib/styles/input.d.ts.map +1 -0
- package/lib/styles/input.js +685 -0
- package/lib/styles/input.js.map +1 -0
- package/lib/styles/modal.d.ts +8 -0
- package/lib/styles/modal.d.ts.map +1 -0
- package/lib/styles/modal.js +134 -0
- package/lib/styles/modal.js.map +1 -0
- package/lib/styles/multiselect.d.ts +6 -0
- package/lib/styles/multiselect.d.ts.map +1 -0
- package/lib/styles/multiselect.js +825 -0
- package/lib/styles/multiselect.js.map +1 -0
- package/lib/styles/option.d.ts +6 -0
- package/lib/styles/option.d.ts.map +1 -0
- package/lib/styles/option.js +116 -0
- package/lib/styles/option.js.map +1 -0
- package/lib/styles/popup.d.ts +8 -0
- package/lib/styles/popup.d.ts.map +1 -0
- package/lib/styles/popup.js +95 -0
- package/lib/styles/popup.js.map +1 -0
- package/lib/styles/radio.d.ts +8 -0
- package/lib/styles/radio.d.ts.map +1 -0
- package/lib/styles/radio.js +160 -0
- package/lib/styles/radio.js.map +1 -0
- package/lib/styles/resize-observer.d.ts +6 -0
- package/lib/styles/resize-observer.d.ts.map +1 -0
- package/lib/styles/resize-observer.js +18 -0
- package/lib/styles/resize-observer.js.map +1 -0
- package/lib/styles/scroll-container.d.ts +6 -0
- package/lib/styles/scroll-container.d.ts.map +1 -0
- package/lib/styles/scroll-container.js +198 -0
- package/lib/styles/scroll-container.js.map +1 -0
- package/lib/styles/step.d.ts +5 -0
- package/lib/styles/step.d.ts.map +1 -0
- package/lib/styles/step.js +50 -0
- package/lib/styles/step.js.map +1 -0
- package/lib/styles/switch.d.ts +9 -0
- package/lib/styles/switch.d.ts.map +1 -0
- package/lib/styles/switch.js +100 -0
- package/lib/styles/switch.js.map +1 -0
- package/lib/styles/tab.d.ts +5 -0
- package/lib/styles/tab.d.ts.map +1 -0
- package/lib/styles/tab.js +51 -0
- package/lib/styles/tab.js.map +1 -0
- package/lib/styles/tabs.d.ts +13 -0
- package/lib/styles/tabs.d.ts.map +1 -0
- package/lib/styles/tabs.js +184 -0
- package/lib/styles/tabs.js.map +1 -0
- package/lib/styles/tag.d.ts +6 -0
- package/lib/styles/tag.d.ts.map +1 -0
- package/lib/styles/tag.js +409 -0
- package/lib/styles/tag.js.map +1 -0
- package/lib/styles/textarea.d.ts +6 -0
- package/lib/styles/textarea.d.ts.map +1 -0
- package/lib/styles/textarea.js +350 -0
- package/lib/styles/textarea.js.map +1 -0
- package/lib/styles/tooltip.d.ts +9 -0
- package/lib/styles/tooltip.d.ts.map +1 -0
- package/lib/styles/tooltip.js +133 -0
- package/lib/styles/tooltip.js.map +1 -0
- package/lib/styles/wizard.d.ts +25 -0
- package/lib/styles/wizard.d.ts.map +1 -0
- package/lib/styles/wizard.js +348 -0
- package/lib/styles/wizard.js.map +1 -0
- package/lib/types/common.d.ts +143 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +5 -0
- package/lib/types/common.js.map +1 -0
- package/lib/utils/calendar-utils.d.ts +176 -0
- package/lib/utils/calendar-utils.d.ts.map +1 -0
- package/lib/utils/calendar-utils.js +370 -0
- package/lib/utils/calendar-utils.js.map +1 -0
- package/lib/utils/custom-scrollbar.d.ts +82 -0
- package/lib/utils/custom-scrollbar.d.ts.map +1 -0
- package/lib/utils/custom-scrollbar.js +320 -0
- package/lib/utils/custom-scrollbar.js.map +1 -0
- package/lib/utils/icon-registry.d.ts +78 -0
- package/lib/utils/icon-registry.d.ts.map +1 -0
- package/lib/utils/icon-registry.js +304 -0
- package/lib/utils/icon-registry.js.map +1 -0
- package/lib/utils/loader-registry.d.ts +35 -0
- package/lib/utils/loader-registry.d.ts.map +1 -0
- package/lib/utils/loader-registry.js +43 -0
- package/lib/utils/loader-registry.js.map +1 -0
- package/lib/utils/locale.d.ts +136 -0
- package/lib/utils/locale.d.ts.map +1 -0
- package/lib/utils/locale.js +213 -0
- package/lib/utils/locale.js.map +1 -0
- package/lib/utils/mobile.d.ts +14 -0
- package/lib/utils/mobile.d.ts.map +1 -0
- package/lib/utils/mobile.js +21 -0
- package/lib/utils/mobile.js.map +1 -0
- package/lib/utils/number-format.d.ts +83 -0
- package/lib/utils/number-format.d.ts.map +1 -0
- package/lib/utils/number-format.js +143 -0
- package/lib/utils/number-format.js.map +1 -0
- package/lib/utils/parse-boolean.d.ts +39 -0
- package/lib/utils/parse-boolean.d.ts.map +1 -0
- package/lib/utils/parse-boolean.js +58 -0
- package/lib/utils/parse-boolean.js.map +1 -0
- package/lib/utils/positioning.d.ts +143 -0
- package/lib/utils/positioning.d.ts.map +1 -0
- package/lib/utils/positioning.js +308 -0
- package/lib/utils/positioning.js.map +1 -0
- package/lib/utils/property-capture.d.ts +132 -0
- package/lib/utils/property-capture.d.ts.map +1 -0
- package/lib/utils/property-capture.js +152 -0
- package/lib/utils/property-capture.js.map +1 -0
- package/lib/utils/property-manager.d.ts +90 -0
- package/lib/utils/property-manager.d.ts.map +1 -0
- package/lib/utils/property-manager.js +197 -0
- package/lib/utils/property-manager.js.map +1 -0
- package/lib/utils/resize-observer.d.ts +42 -0
- package/lib/utils/resize-observer.d.ts.map +1 -0
- package/lib/utils/resize-observer.js +71 -0
- package/lib/utils/resize-observer.js.map +1 -0
- package/lib/utils/scroll-lock.d.ts +79 -0
- package/lib/utils/scroll-lock.d.ts.map +1 -0
- package/lib/utils/scroll-lock.js +197 -0
- package/lib/utils/scroll-lock.js.map +1 -0
- package/lib/utils/styles.d.ts +27 -0
- package/lib/utils/styles.d.ts.map +1 -0
- package/lib/utils/styles.js +53 -0
- package/lib/utils/styles.js.map +1 -0
- package/lib/version.d.ts +8 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +11 -0
- package/lib/version.js.map +1 -0
- package/package.json +163 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calendar Utilities
|
|
3
|
+
*
|
|
4
|
+
* Pure TypeScript utilities for calendar month generation and localization.
|
|
5
|
+
* Ported from ClojureScript ty/date/core.cljs
|
|
6
|
+
*
|
|
7
|
+
* Key Features:
|
|
8
|
+
* - 42-day calendar grid generation (6 weeks × 7 days)
|
|
9
|
+
* - Monday-first week ordering
|
|
10
|
+
* - Rich day context with metadata
|
|
11
|
+
* - Localized weekday names
|
|
12
|
+
* - No external dependencies (native Date API only)
|
|
13
|
+
*
|
|
14
|
+
* Note on Timestamps:
|
|
15
|
+
* - `value`: UTC timestamp at midnight UTC (timezone-independent, use for storage/server)
|
|
16
|
+
* - `localValue`: Local timestamp at midnight local time (use for display/local calculations)
|
|
17
|
+
* - `year/month/dayInMonth`: Calendar date components (user's mental model)
|
|
18
|
+
*
|
|
19
|
+
* Example for October 13, 2025:
|
|
20
|
+
* - value = Date.UTC(2025, 9, 13) = consistent worldwide
|
|
21
|
+
* - localValue = new Date(2025, 9, 13).getTime() = varies by timezone
|
|
22
|
+
* - Both represent the same calendar date, different moments in time
|
|
23
|
+
*/
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Validation Functions
|
|
26
|
+
// ============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* Validate month value (1-12)
|
|
29
|
+
*/
|
|
30
|
+
function validateMonth(month) {
|
|
31
|
+
if (!Number.isInteger(month) || month < 1 || month > 12) {
|
|
32
|
+
throw new RangeError(`Invalid month: ${month}. Must be an integer between 1 and 12.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validate year value (reasonable range)
|
|
37
|
+
*/
|
|
38
|
+
function validateYear(year) {
|
|
39
|
+
if (!Number.isInteger(year) || year < 1 || year > 9999) {
|
|
40
|
+
throw new RangeError(`Invalid year: ${year}. Must be an integer between 1 and 9999.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Helper Functions
|
|
45
|
+
// ============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Check if two dates are on the same day (ignoring time)
|
|
48
|
+
* Works in local timezone
|
|
49
|
+
*/
|
|
50
|
+
function isSameDay(date1, date2) {
|
|
51
|
+
return date1.getFullYear() === date2.getFullYear()
|
|
52
|
+
&& date1.getMonth() === date2.getMonth()
|
|
53
|
+
&& date1.getDate() === date2.getDate();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a date at midnight local time
|
|
57
|
+
* This ensures consistent behavior across the application
|
|
58
|
+
*/
|
|
59
|
+
function createMidnightDate(year, month, day) {
|
|
60
|
+
return new Date(year, month - 1, day, 0, 0, 0, 0);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get today's date at midnight local time
|
|
64
|
+
* Used for consistent "today" detection
|
|
65
|
+
*/
|
|
66
|
+
function getTodayMidnight() {
|
|
67
|
+
const now = new Date();
|
|
68
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a DayContext from a Date object
|
|
72
|
+
*
|
|
73
|
+
* @param date - The date to create context for (should be at midnight)
|
|
74
|
+
* @param targetYear - The year of the calendar month being displayed
|
|
75
|
+
* @param targetMonth - The month (1-12) of the calendar month being displayed
|
|
76
|
+
* @param selection - Optional selection state from calendar
|
|
77
|
+
* @returns Rich day context with metadata
|
|
78
|
+
*/
|
|
79
|
+
function createDayContext(date, targetYear, targetMonth, selection) {
|
|
80
|
+
const year = date.getFullYear();
|
|
81
|
+
const month = date.getMonth() + 1; // Convert to 1-based
|
|
82
|
+
const dayInMonth = date.getDate();
|
|
83
|
+
const dayOfWeek = date.getDay(); // 0 = Sunday, 6 = Saturday
|
|
84
|
+
// Check if this day is from a different month
|
|
85
|
+
const isOtherMonth = year !== targetYear || month !== targetMonth;
|
|
86
|
+
// Determine if previous or next month
|
|
87
|
+
let isPrevMonth = false;
|
|
88
|
+
let isNextMonth = false;
|
|
89
|
+
if (isOtherMonth) {
|
|
90
|
+
if (year < targetYear || (year === targetYear && month < targetMonth)) {
|
|
91
|
+
isPrevMonth = true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
isNextMonth = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Check if today (compare dates at midnight for consistency)
|
|
98
|
+
const todayMidnight = getTodayMidnight();
|
|
99
|
+
const isToday = isSameDay(date, todayMidnight);
|
|
100
|
+
// Check if this day is selected
|
|
101
|
+
const isSelected = selection?.year === year
|
|
102
|
+
&& selection?.month === month
|
|
103
|
+
&& selection?.day === dayInMonth;
|
|
104
|
+
// Calculate both UTC and local timestamps
|
|
105
|
+
// value: UTC midnight (consistent worldwide for the same date)
|
|
106
|
+
// localValue: Local midnight (respects user's timezone)
|
|
107
|
+
const utcValue = Date.UTC(year, month - 1, dayInMonth, 0, 0, 0, 0);
|
|
108
|
+
const localValue = date.getTime();
|
|
109
|
+
return {
|
|
110
|
+
value: utcValue,
|
|
111
|
+
localValue,
|
|
112
|
+
year,
|
|
113
|
+
month,
|
|
114
|
+
dayInMonth,
|
|
115
|
+
weekend: dayOfWeek === 0 || dayOfWeek === 6,
|
|
116
|
+
otherMonth: isOtherMonth,
|
|
117
|
+
prevMonth: isPrevMonth,
|
|
118
|
+
nextMonth: isNextMonth,
|
|
119
|
+
today: isToday,
|
|
120
|
+
isSelected,
|
|
121
|
+
selectedYear: selection?.year,
|
|
122
|
+
selectedMonth: selection?.month,
|
|
123
|
+
selectedDay: selection?.day,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the Monday at or before a given date
|
|
128
|
+
* (Monday = start of week in ISO 8601)
|
|
129
|
+
*
|
|
130
|
+
* @param date - Any date
|
|
131
|
+
* @returns The Monday of that week at midnight
|
|
132
|
+
*/
|
|
133
|
+
function getMondayOfWeek(date) {
|
|
134
|
+
const dayOfWeek = date.getDay(); // 0 = Sunday, 1 = Monday, etc.
|
|
135
|
+
// Calculate days to subtract to get to Monday
|
|
136
|
+
// Sunday (0) → go back 6 days
|
|
137
|
+
// Monday (1) → go back 0 days
|
|
138
|
+
// Tuesday (2) → go back 1 day
|
|
139
|
+
// ...
|
|
140
|
+
const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1;
|
|
141
|
+
// Create new date at Monday midnight
|
|
142
|
+
const monday = new Date(date);
|
|
143
|
+
monday.setDate(date.getDate() - daysToMonday);
|
|
144
|
+
monday.setHours(0, 0, 0, 0); // Ensure midnight
|
|
145
|
+
return monday;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get the start date for the calendar grid
|
|
149
|
+
* (The Monday at or before the first day of the month)
|
|
150
|
+
*
|
|
151
|
+
* @param year - Year
|
|
152
|
+
* @param month - Month (1-12)
|
|
153
|
+
* @returns The Monday that starts the calendar grid
|
|
154
|
+
*/
|
|
155
|
+
function getMonthGridStart(year, month) {
|
|
156
|
+
// Get first day of month at midnight (month is 1-based, Date constructor is 0-based)
|
|
157
|
+
const firstDay = createMidnightDate(year, month, 1);
|
|
158
|
+
// Get the Monday of that week
|
|
159
|
+
return getMondayOfWeek(firstDay);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Add days to a date safely
|
|
163
|
+
* Creates a new date without mutating the original
|
|
164
|
+
*
|
|
165
|
+
* @param date - Starting date
|
|
166
|
+
* @param days - Number of days to add
|
|
167
|
+
* @returns New date with days added
|
|
168
|
+
*/
|
|
169
|
+
function addDays(date, days) {
|
|
170
|
+
const result = new Date(date);
|
|
171
|
+
result.setDate(result.getDate() + days);
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Generate N consecutive days starting from a date
|
|
176
|
+
*
|
|
177
|
+
* @param startDate - Starting date
|
|
178
|
+
* @param count - Number of days to generate
|
|
179
|
+
* @param targetYear - Year of the calendar month
|
|
180
|
+
* @param targetMonth - Month (1-12) of the calendar month
|
|
181
|
+
* @param selection - Optional selection state to include in day contexts
|
|
182
|
+
* @returns Array of day contexts
|
|
183
|
+
*/
|
|
184
|
+
function generateDays(startDate, count, targetYear, targetMonth, selection) {
|
|
185
|
+
const days = [];
|
|
186
|
+
for (let i = 0; i < count; i++) {
|
|
187
|
+
const date = addDays(startDate, i);
|
|
188
|
+
days.push(createDayContext(date, targetYear, targetMonth, selection));
|
|
189
|
+
}
|
|
190
|
+
return days;
|
|
191
|
+
}
|
|
192
|
+
// ============================================================================
|
|
193
|
+
// Main Calendar Functions
|
|
194
|
+
// ============================================================================
|
|
195
|
+
/**
|
|
196
|
+
* Generate a 42-day calendar grid for a given month
|
|
197
|
+
*
|
|
198
|
+
* Returns 6 weeks (42 days) starting from the Monday at or before
|
|
199
|
+
* the first day of the month. This ensures a complete calendar view
|
|
200
|
+
* with days from the previous and next months as needed.
|
|
201
|
+
*
|
|
202
|
+
* @param year - Year (e.g., 2025)
|
|
203
|
+
* @param month - Month (1-12, 1 = January)
|
|
204
|
+
* @param selection - Optional selection state to include in day contexts
|
|
205
|
+
* @returns Array of 42 day contexts with rich metadata
|
|
206
|
+
*
|
|
207
|
+
* @throws {RangeError} If year or month are invalid
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* const days = getCalendarMonthDays(2025, 10); // October 2025
|
|
211
|
+
* console.log(days.length); // 42
|
|
212
|
+
* console.log(days[0].dayInMonth); // First day shown (might be from September)
|
|
213
|
+
*/
|
|
214
|
+
export function getCalendarMonthDays(year, month, selection) {
|
|
215
|
+
// Validate inputs
|
|
216
|
+
validateYear(year);
|
|
217
|
+
validateMonth(month);
|
|
218
|
+
const startDate = getMonthGridStart(year, month);
|
|
219
|
+
return generateDays(startDate, 42, year, month, selection);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get localized weekday names in Monday-first order
|
|
223
|
+
*
|
|
224
|
+
* Note: Intl.DateTimeFormat returns Sunday-first by default,
|
|
225
|
+
* so we reorder to Monday-first: [Mon, Tue, Wed, Thu, Fri, Sat, Sun]
|
|
226
|
+
*
|
|
227
|
+
* @param locale - Locale string (e.g., "en-US", "de-DE", "ja-JP")
|
|
228
|
+
* @param style - Display style: "long" (Monday), "short" (Mon), "narrow" (M)
|
|
229
|
+
* @returns Array of 7 weekday names starting with Monday
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* getLocalizedWeekdays("en-US", "short")
|
|
233
|
+
* // Returns: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
|
|
234
|
+
*
|
|
235
|
+
* getLocalizedWeekdays("de-DE", "long")
|
|
236
|
+
* // Returns: ["Montag", "Dienstag", "Mittwoch", ...]
|
|
237
|
+
*/
|
|
238
|
+
export function getLocalizedWeekdays(locale, style = 'short') {
|
|
239
|
+
const formatter = new Intl.DateTimeFormat(locale, { weekday: style });
|
|
240
|
+
// Create a Sunday (base date) - January 7, 2024 is a Sunday
|
|
241
|
+
const sunday = new Date(2024, 0, 7);
|
|
242
|
+
// Generate Sunday-first array: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
|
243
|
+
const sundayFirst = Array.from({ length: 7 }, (_, i) => {
|
|
244
|
+
const date = addDays(sunday, i);
|
|
245
|
+
return formatter.format(date);
|
|
246
|
+
});
|
|
247
|
+
// Reorder to Monday-first: [Mon, Tue, Wed, Thu, Fri, Sat, Sun]
|
|
248
|
+
const [firstDay, ...rest] = sundayFirst;
|
|
249
|
+
return [...rest, firstDay];
|
|
250
|
+
}
|
|
251
|
+
// ============================================================================
|
|
252
|
+
// Utility Functions (for testing and debugging)
|
|
253
|
+
// ============================================================================
|
|
254
|
+
/**
|
|
255
|
+
* Get month name in specified locale
|
|
256
|
+
*
|
|
257
|
+
* @param month - Month (1-12)
|
|
258
|
+
* @param locale - Locale string
|
|
259
|
+
* @param style - Display style
|
|
260
|
+
* @returns Localized month name
|
|
261
|
+
*
|
|
262
|
+
* @throws {RangeError} If month is invalid
|
|
263
|
+
*/
|
|
264
|
+
export function getMonthName(month, locale = 'en-US', style = 'long') {
|
|
265
|
+
validateMonth(month);
|
|
266
|
+
const date = new Date(2024, month - 1, 1);
|
|
267
|
+
const formatter = new Intl.DateTimeFormat(locale, { month: style });
|
|
268
|
+
return formatter.format(date);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Format a day context as an ISO date string
|
|
272
|
+
*
|
|
273
|
+
* @param dayContext - Day context to format
|
|
274
|
+
* @returns ISO date string (YYYY-MM-DD)
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* formatDayContext({ year: 2025, month: 10, dayInMonth: 13, ... })
|
|
278
|
+
* // Returns: "2025-10-13"
|
|
279
|
+
*/
|
|
280
|
+
export function formatDayContext(dayContext) {
|
|
281
|
+
const { year, month, dayInMonth } = dayContext;
|
|
282
|
+
const monthStr = month.toString().padStart(2, '0');
|
|
283
|
+
const dayStr = dayInMonth.toString().padStart(2, '0');
|
|
284
|
+
return `${year}-${monthStr}-${dayStr}`;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Check if a day context matches a specific date
|
|
288
|
+
*
|
|
289
|
+
* @param dayContext - Day context to check
|
|
290
|
+
* @param year - Target year
|
|
291
|
+
* @param month - Target month (1-12)
|
|
292
|
+
* @param day - Target day
|
|
293
|
+
* @returns True if the day context matches
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* isDayContext(dayCtx, 2025, 10, 13) // true if context is Oct 13, 2025
|
|
297
|
+
*/
|
|
298
|
+
export function isDayContext(dayContext, year, month, day) {
|
|
299
|
+
return dayContext.year === year
|
|
300
|
+
&& dayContext.month === month
|
|
301
|
+
&& dayContext.dayInMonth === day;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Parse an ISO date string (YYYY-MM-DD) into year, month, day components
|
|
305
|
+
*
|
|
306
|
+
* @param isoString - ISO date string (YYYY-MM-DD)
|
|
307
|
+
* @returns Object with year, month (1-12), and day, or null if invalid
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* parseISODate("2025-10-13")
|
|
311
|
+
* // Returns: { year: 2025, month: 10, day: 13 }
|
|
312
|
+
*/
|
|
313
|
+
export function parseISODate(isoString) {
|
|
314
|
+
const match = isoString.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
315
|
+
if (!match)
|
|
316
|
+
return null;
|
|
317
|
+
const year = parseInt(match[1], 10);
|
|
318
|
+
const month = parseInt(match[2], 10);
|
|
319
|
+
const day = parseInt(match[3], 10);
|
|
320
|
+
// Validate ranges
|
|
321
|
+
if (year < 1 || year > 9999)
|
|
322
|
+
return null;
|
|
323
|
+
if (month < 1 || month > 12)
|
|
324
|
+
return null;
|
|
325
|
+
if (day < 1 || day > 31)
|
|
326
|
+
return null;
|
|
327
|
+
// Check if date is valid (handles Feb 30, etc.)
|
|
328
|
+
const date = new Date(year, month - 1, day);
|
|
329
|
+
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
return { year, month, day };
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Convert a UTC timestamp to an ISO date string
|
|
336
|
+
* Interprets the timestamp as UTC midnight and returns the date
|
|
337
|
+
*
|
|
338
|
+
* @param utcTimestamp - UTC timestamp in milliseconds
|
|
339
|
+
* @returns ISO date string (YYYY-MM-DD)
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* const ctx = getCalendarMonthDays(2025, 10)[0];
|
|
343
|
+
* utcTimestampToISO(ctx.value) // "2025-10-13"
|
|
344
|
+
*/
|
|
345
|
+
export function utcTimestampToISO(utcTimestamp) {
|
|
346
|
+
const date = new Date(utcTimestamp);
|
|
347
|
+
const year = date.getUTCFullYear();
|
|
348
|
+
const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
|
|
349
|
+
const day = date.getUTCDate().toString().padStart(2, '0');
|
|
350
|
+
return `${year}-${month}-${day}`;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Convert a local timestamp to an ISO date string
|
|
354
|
+
* Interprets the timestamp in local timezone and returns the date
|
|
355
|
+
*
|
|
356
|
+
* @param localTimestamp - Local timestamp in milliseconds
|
|
357
|
+
* @returns ISO date string (YYYY-MM-DD)
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* const ctx = getCalendarMonthDays(2025, 10)[0];
|
|
361
|
+
* localTimestampToISO(ctx.localValue) // "2025-10-13"
|
|
362
|
+
*/
|
|
363
|
+
export function localTimestampToISO(localTimestamp) {
|
|
364
|
+
const date = new Date(localTimestamp);
|
|
365
|
+
const year = date.getFullYear();
|
|
366
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
367
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
368
|
+
return `${year}-${month}-${day}`;
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=calendar-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-utils.js","sourceRoot":"","sources":["../../src/utils/calendar-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAyDH,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;GAEG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACxD,MAAM,IAAI,UAAU,CAAC,kBAAkB,KAAK,wCAAwC,CAAC,CAAC;IACxF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;QACvD,MAAM,IAAI,UAAU,CAAC,iBAAiB,IAAI,0CAA0C,CAAC,CAAC;IACxF,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;GAGG;AACH,SAAS,SAAS,CAAC,KAAW,EAAE,KAAW;IACzC,OAAO,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE;WAC7C,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,QAAQ,EAAE;WACrC,KAAK,CAAC,OAAO,EAAE,K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AC,CAAC;IAC1D,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,cAAsB;IACxD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACvD,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CustomScrollbar - Reusable scrollbar utility
|
|
3
|
+
*
|
|
4
|
+
* Attaches a custom rendered scrollbar (vertical and/or horizontal) to any
|
|
5
|
+
* scrollable element. Uses the overlay approach: native overflow:auto is
|
|
6
|
+
* preserved for scroll physics, native scrollbar is hidden via CSS,
|
|
7
|
+
* and custom track/thumb elements are synced on top.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* const scrollbar = new CustomScrollbar(scrollEl, { vertical: true })
|
|
11
|
+
* // scrollbar.trackY, scrollbar.thumbY — append these to your DOM
|
|
12
|
+
* // scrollbar.trackX, scrollbar.thumbX — for horizontal
|
|
13
|
+
* scrollbar.destroy() // cleanup
|
|
14
|
+
*
|
|
15
|
+
* CSS classes applied:
|
|
16
|
+
* .ty-scrollbar-track-y / .ty-scrollbar-track-x
|
|
17
|
+
* .ty-scrollbar-thumb-y / .ty-scrollbar-thumb-x
|
|
18
|
+
* .has-overflow — when content overflows
|
|
19
|
+
* .dragging — during thumb drag
|
|
20
|
+
* .scrolling — briefly after scroll (auto-hide)
|
|
21
|
+
*/
|
|
22
|
+
export interface CustomScrollbarOptions {
|
|
23
|
+
vertical?: boolean;
|
|
24
|
+
horizontal?: boolean;
|
|
25
|
+
autoHideDelay?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if custom scrollbar is enabled globally.
|
|
29
|
+
* Default: true (custom scrollbar on).
|
|
30
|
+
* Set data-ty-scrollbar="native" on <html> to opt out.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isCustomScrollbarEnabled(): boolean;
|
|
33
|
+
export declare class CustomScrollbar {
|
|
34
|
+
private _scrollEl;
|
|
35
|
+
private _vertical;
|
|
36
|
+
private _horizontal;
|
|
37
|
+
private _autoHideDelay;
|
|
38
|
+
readonly trackY: HTMLElement | null;
|
|
39
|
+
readonly thumbY: HTMLElement | null;
|
|
40
|
+
readonly trackX: HTMLElement | null;
|
|
41
|
+
readonly thumbX: HTMLElement | null;
|
|
42
|
+
private _isDragging;
|
|
43
|
+
private _dragAxis;
|
|
44
|
+
private _dragStartPos;
|
|
45
|
+
private _dragStartScroll;
|
|
46
|
+
private _rafId;
|
|
47
|
+
private _hideTimeout;
|
|
48
|
+
private _resizeObserver;
|
|
49
|
+
private _onScroll;
|
|
50
|
+
private _onThumbYDown;
|
|
51
|
+
private _onThumbXDown;
|
|
52
|
+
private _onTrackYDown;
|
|
53
|
+
private _onTrackXDown;
|
|
54
|
+
private _onDragMove;
|
|
55
|
+
private _onDragEnd;
|
|
56
|
+
constructor(scrollEl: HTMLElement, options?: CustomScrollbarOptions);
|
|
57
|
+
private _createTrack;
|
|
58
|
+
private _createThumb;
|
|
59
|
+
/** Force update thumb size and position */
|
|
60
|
+
update(): void;
|
|
61
|
+
/** Reset scroll position */
|
|
62
|
+
scrollToTop(smooth?: boolean): void;
|
|
63
|
+
scrollToBottom(smooth?: boolean): void;
|
|
64
|
+
scrollToLeft(smooth?: boolean): void;
|
|
65
|
+
scrollToRight(smooth?: boolean): void;
|
|
66
|
+
/** Cleanup all listeners and observers */
|
|
67
|
+
destroy(): void;
|
|
68
|
+
private _handleScroll;
|
|
69
|
+
private _updateVertical;
|
|
70
|
+
private _updateHorizontal;
|
|
71
|
+
private _updateThumbPositions;
|
|
72
|
+
private _updateThumbY;
|
|
73
|
+
private _updateThumbX;
|
|
74
|
+
private _showScrollbars;
|
|
75
|
+
private _handleThumbYDown;
|
|
76
|
+
private _handleThumbXDown;
|
|
77
|
+
private _handleDragMove;
|
|
78
|
+
private _handleDragEnd;
|
|
79
|
+
private _handleTrackYDown;
|
|
80
|
+
private _handleTrackXDown;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=custom-scrollbar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-scrollbar.d.ts","sourceRoot":"","sources":["../../src/utils/custom-scrollbar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAElD;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAQ;IAG9B,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAO;IAC1C,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAO;IAC1C,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAO;IAC1C,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAO;IAG1C,OAAO,CAAC,WAAW,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