@kalyx/core 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -8
- package/dist/index.cjs +151 -20
- package/dist/index.d.cts +167 -75
- package/dist/index.d.ts +348 -9
- package/dist/index.js +538 -9
- package/package.json +20 -1
- package/dist/adapters/date-fns.d.ts +0 -16
- package/dist/adapters/date-fns.d.ts.map +0 -1
- package/dist/adapters/date-fns.js +0 -148
- package/dist/adapters/date-fns.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -106
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -8
- package/dist/types.js.map +0 -1
- package/dist/utils/calendar.d.ts +0 -35
- package/dist/utils/calendar.d.ts.map +0 -1
- package/dist/utils/calendar.js +0 -141
- package/dist/utils/calendar.js.map +0 -1
- package/dist/utils/date.d.ts +0 -22
- package/dist/utils/date.d.ts.map +0 -1
- package/dist/utils/date.js +0 -66
- package/dist/utils/date.js.map +0 -1
- package/dist/utils/locale.d.ts +0 -33
- package/dist/utils/locale.d.ts.map +0 -1
- package/dist/utils/locale.js +0 -70
- package/dist/utils/locale.js.map +0 -1
- package/dist/utils/time.d.ts +0 -58
- package/dist/utils/time.d.ts.map +0 -1
- package/dist/utils/time.js +0 -127
- package/dist/utils/time.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,348 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @kalyx/core type definitions.
|
|
3
|
+
*
|
|
4
|
+
* All date values are represented as ISO 8601 UTC strings.
|
|
5
|
+
* Native Date objects are not used.
|
|
6
|
+
*/
|
|
7
|
+
/** ISO 8601 UTC date string. e.g. "2026-01-15T00:00:00.000Z" */
|
|
8
|
+
type ISODateString = string;
|
|
9
|
+
/**
|
|
10
|
+
* Date-disable rules. Multiple rules can be combined in an array.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const rules: DisabledRule[] = [
|
|
15
|
+
* { before: '2026-01-01T00:00:00.000Z' }, // disable before Jan 1
|
|
16
|
+
* { after: '2026-12-31T00:00:00.000Z' }, // disable after Dec 31
|
|
17
|
+
* { date: '2026-06-15T00:00:00.000Z' }, // disable a specific date
|
|
18
|
+
* { dayOfWeek: [0, 6] }, // disable weekends
|
|
19
|
+
* ];
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
type DisabledRule = {
|
|
23
|
+
date: ISODateString;
|
|
24
|
+
} | {
|
|
25
|
+
before: ISODateString;
|
|
26
|
+
} | {
|
|
27
|
+
after: ISODateString;
|
|
28
|
+
} | {
|
|
29
|
+
dayOfWeek: number[];
|
|
30
|
+
};
|
|
31
|
+
/** Date range (RangePicker) */
|
|
32
|
+
interface DateRange {
|
|
33
|
+
start: ISODateString | null;
|
|
34
|
+
end: ISODateString | null;
|
|
35
|
+
}
|
|
36
|
+
/** Represents a single day in the calendar grid */
|
|
37
|
+
interface CalendarDay {
|
|
38
|
+
/** ISO 8601 UTC string */
|
|
39
|
+
isoString: ISODateString;
|
|
40
|
+
/** Day of month (1-31) */
|
|
41
|
+
dayNumber: number;
|
|
42
|
+
/** Whether this day belongs to the currently displayed month */
|
|
43
|
+
isCurrentMonth: boolean;
|
|
44
|
+
/** Whether this day is today */
|
|
45
|
+
isToday: boolean;
|
|
46
|
+
/** Whether this day is the selected date (single selection) */
|
|
47
|
+
isSelected: boolean;
|
|
48
|
+
/** Whether this day is disabled */
|
|
49
|
+
isDisabled: boolean;
|
|
50
|
+
/** Whether this day is focused */
|
|
51
|
+
isFocused: boolean;
|
|
52
|
+
/** Whether this day is the start of a range */
|
|
53
|
+
isRangeStart: boolean;
|
|
54
|
+
/** Whether this day is the end of a range */
|
|
55
|
+
isRangeEnd: boolean;
|
|
56
|
+
/** Whether this day is inside a range (between start and end) */
|
|
57
|
+
isInRange: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** Calendar grid: array of weeks, each week is an array of days */
|
|
60
|
+
type CalendarWeek = CalendarDay[];
|
|
61
|
+
type CalendarGrid = CalendarWeek[];
|
|
62
|
+
/**
|
|
63
|
+
* Date library adapter interface.
|
|
64
|
+
* Abstracts all date operations so the underlying library (e.g. Temporal API) can be swapped.
|
|
65
|
+
* Default implementation: {@link DateFnsAdapter}
|
|
66
|
+
*/
|
|
67
|
+
interface DateAdapter {
|
|
68
|
+
/** Any format → ISO 8601 UTC string */
|
|
69
|
+
parse(value: string, format?: string): string;
|
|
70
|
+
/** ISO string → display string */
|
|
71
|
+
format(iso: string, formatStr: string, timezone?: string): string;
|
|
72
|
+
addDays(iso: string, n: number): string;
|
|
73
|
+
addMonths(iso: string, n: number): string;
|
|
74
|
+
addYears(iso: string, n: number): string;
|
|
75
|
+
isBefore(a: string, b: string): boolean;
|
|
76
|
+
isAfter(a: string, b: string): boolean;
|
|
77
|
+
isSameDay(a: string, b: string, timezone?: string): boolean;
|
|
78
|
+
isSameMonth(a: string, b: string): boolean;
|
|
79
|
+
startOfDay(iso: string, timezone?: string): string;
|
|
80
|
+
startOfMonth(iso: string): string;
|
|
81
|
+
endOfMonth(iso: string): string;
|
|
82
|
+
startOfWeek(iso: string, weekStartsOn?: 0 | 1): string;
|
|
83
|
+
endOfWeek(iso: string, weekStartsOn?: 0 | 1): string;
|
|
84
|
+
now(): string;
|
|
85
|
+
today(timezone?: string): string;
|
|
86
|
+
isValid(value: string): boolean;
|
|
87
|
+
getYear(iso: string): number;
|
|
88
|
+
getMonth(iso: string): number;
|
|
89
|
+
getDate(iso: string): number;
|
|
90
|
+
getDay(iso: string): number;
|
|
91
|
+
}
|
|
92
|
+
/** First day of the week */
|
|
93
|
+
type WeekStartsOn = 0 | 1;
|
|
94
|
+
/** Options for generating a calendar grid */
|
|
95
|
+
interface CalendarOptions {
|
|
96
|
+
weekStartsOn?: WeekStartsOn;
|
|
97
|
+
today?: ISODateString;
|
|
98
|
+
selected?: ISODateString | null;
|
|
99
|
+
focusedDate?: ISODateString;
|
|
100
|
+
disabled?: DisabledRule[];
|
|
101
|
+
/** Selected range (RangePicker) */
|
|
102
|
+
range?: DateRange | null;
|
|
103
|
+
/** Currently hovered date (for RangePicker preview) */
|
|
104
|
+
rangeHover?: ISODateString | null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* DateAdapter implementation backed by date-fns.
|
|
109
|
+
* All operations run in UTC to avoid timezone interference.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { DateFnsAdapter } from '@kalyx/core';
|
|
114
|
+
*
|
|
115
|
+
* DateFnsAdapter.format('2026-01-15T00:00:00.000Z', 'yyyy-MM-dd'); // "2026-01-15"
|
|
116
|
+
* DateFnsAdapter.addDays('2026-01-15T00:00:00.000Z', 7); // "2026-01-22T..."
|
|
117
|
+
* DateFnsAdapter.isSameDay('2026-01-15T00:00:00.000Z', '2026-01-15T23:59:59.000Z'); // true
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare const DateFnsAdapter: DateAdapter;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Builds the calendar grid for the given month.
|
|
124
|
+
* Returns a 2D array (`CalendarGrid`) organized by week.
|
|
125
|
+
*
|
|
126
|
+
* @param monthISO - ISO datetime containing the month to display
|
|
127
|
+
* @param adapter - Date operation adapter ({@link DateFnsAdapter})
|
|
128
|
+
* @param options - Week start day, selected date, disabled rules, range, etc.
|
|
129
|
+
* @returns A calendar grid of 4-6 weeks. Each week is an array of 7 {@link CalendarDay}.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const grid = getCalendarDays('2026-01-01T00:00:00.000Z', DateFnsAdapter, {
|
|
134
|
+
* weekStartsOn: 0,
|
|
135
|
+
* selected: '2026-01-15T00:00:00.000Z',
|
|
136
|
+
* disabled: [{ dayOfWeek: [0, 6] }],
|
|
137
|
+
* });
|
|
138
|
+
* // grid[0] = first week (CalendarDay[7])
|
|
139
|
+
* // grid[0][0].dayNumber = 28 (previous month)
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function getCalendarDays(monthISO: string, adapter: DateAdapter, options?: CalendarOptions): CalendarGrid;
|
|
143
|
+
/**
|
|
144
|
+
* Checks whether the given date matches any disable rule.
|
|
145
|
+
*/
|
|
146
|
+
declare function isDateDisabled(iso: string, rules: DisabledRule[], adapter: DateAdapter): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Returns the earlier of two dates.
|
|
149
|
+
*/
|
|
150
|
+
declare function minDate(a: ISODateString, b: ISODateString, adapter: DateAdapter): ISODateString;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the later of two dates.
|
|
153
|
+
*/
|
|
154
|
+
declare function maxDate(a: ISODateString, b: ISODateString, adapter: DateAdapter): ISODateString;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Normalizes a date string to ISO 8601 UTC form.
|
|
158
|
+
* "2026-01-15" → "2026-01-15T00:00:00.000Z"
|
|
159
|
+
*
|
|
160
|
+
* Full datetime strings must include a timezone suffix (Z or ±HH:MM).
|
|
161
|
+
* Strings without a timezone suffix are treated as-is (not matched as datetime).
|
|
162
|
+
*/
|
|
163
|
+
declare function normalizeISO(value: string): string;
|
|
164
|
+
/**
|
|
165
|
+
* Parses user input text into an ISO string.
|
|
166
|
+
* Returns null on failure.
|
|
167
|
+
*/
|
|
168
|
+
declare function parseInputValue(input: string, adapter: DateAdapter): string | null;
|
|
169
|
+
|
|
170
|
+
/** Time-of-day value (24-hour clock) */
|
|
171
|
+
interface TimeValue {
|
|
172
|
+
hours: number;
|
|
173
|
+
minutes: number;
|
|
174
|
+
seconds: number;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Replaces the time portion of an ISO datetime.
|
|
178
|
+
* Operates in UTC.
|
|
179
|
+
*/
|
|
180
|
+
declare function setTime(iso: ISODateString, time: Partial<TimeValue>): ISODateString;
|
|
181
|
+
/**
|
|
182
|
+
* Extracts the time portion of an ISO datetime.
|
|
183
|
+
*/
|
|
184
|
+
declare function getTime(iso: ISODateString): TimeValue;
|
|
185
|
+
/**
|
|
186
|
+
* Parses an "HH:MM" or "HH:MM:SS" string into a TimeValue.
|
|
187
|
+
* Returns null on invalid input.
|
|
188
|
+
*/
|
|
189
|
+
declare function parseTimeString(input: string): TimeValue | null;
|
|
190
|
+
/**
|
|
191
|
+
* Formats a TimeValue as "HH:MM" or "HH:MM:SS".
|
|
192
|
+
*/
|
|
193
|
+
declare function formatTimeString(time: TimeValue, withSeconds?: boolean): string;
|
|
194
|
+
/**
|
|
195
|
+
* Converts a 24-hour value to 12-hour form.
|
|
196
|
+
* 0 → 12 AM, 12 → 12 PM
|
|
197
|
+
*/
|
|
198
|
+
declare function to12Hour(hours24: number): {
|
|
199
|
+
hours12: number;
|
|
200
|
+
period: 'AM' | 'PM';
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Converts a 12-hour value to 24-hour form.
|
|
204
|
+
*/
|
|
205
|
+
declare function to24Hour(hours12: number, period: 'AM' | 'PM'): number;
|
|
206
|
+
/**
|
|
207
|
+
* Builds an hours list (0-23 or 1-12).
|
|
208
|
+
*/
|
|
209
|
+
declare function generateHours(format?: '12h' | '24h'): number[];
|
|
210
|
+
/**
|
|
211
|
+
* Builds a minutes list at the given step.
|
|
212
|
+
* step=1 → [0, 1, 2, ..., 59]
|
|
213
|
+
* step=15 → [0, 15, 30, 45]
|
|
214
|
+
* step=5 → [0, 5, 10, ..., 55]
|
|
215
|
+
*/
|
|
216
|
+
declare function generateMinutes(step?: number): number[];
|
|
217
|
+
/**
|
|
218
|
+
* Checks whether two TimeValues are identical (hours, minutes, and seconds).
|
|
219
|
+
*/
|
|
220
|
+
declare function isSameTime(a: TimeValue, b: TimeValue): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Formats an ISO datetime as a time string (UTC based).
|
|
223
|
+
* Accepts an adapter for API consistency.
|
|
224
|
+
*/
|
|
225
|
+
declare function formatTimeFromISO(iso: ISODateString, format: 'HH:mm' | 'HH:mm:ss' | 'h:mm a' | 'h:mm:ss a'): string;
|
|
226
|
+
|
|
227
|
+
interface WeekdayInfo {
|
|
228
|
+
/** Short name (e.g. "Su", "일") */
|
|
229
|
+
short: string;
|
|
230
|
+
/** Full name (e.g. "Sunday", "일요일") */
|
|
231
|
+
full: string;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Returns a localized month name via Intl.DateTimeFormat.
|
|
235
|
+
* @param month 0-indexed (0 = January)
|
|
236
|
+
* @param locale BCP 47 locale string (e.g. "en-US", "ko-KR", "ja-JP")
|
|
237
|
+
*/
|
|
238
|
+
declare function getMonthName(month: number, locale?: string): string;
|
|
239
|
+
/**
|
|
240
|
+
* Returns a month+year string like "January 2026" or "2026년 1월".
|
|
241
|
+
*/
|
|
242
|
+
declare function formatMonthYear(year: number, month: number, locale?: string): string;
|
|
243
|
+
/**
|
|
244
|
+
* Returns localized weekday names via Intl.DateTimeFormat.
|
|
245
|
+
* Ordered according to weekStartsOn.
|
|
246
|
+
*
|
|
247
|
+
* @param locale BCP 47 locale string
|
|
248
|
+
* @param weekStartsOn 0 = Sunday, 1 = Monday
|
|
249
|
+
* @returns Array of 7 WeekdayInfo entries
|
|
250
|
+
*/
|
|
251
|
+
declare function getWeekdayNames(locale?: string, weekStartsOn?: WeekStartsOn): WeekdayInfo[];
|
|
252
|
+
/**
|
|
253
|
+
* Returns a fully formatted date string via Intl.DateTimeFormat (for screen readers).
|
|
254
|
+
* e.g. "Thursday, January 15, 2026"
|
|
255
|
+
*/
|
|
256
|
+
declare function formatFullDate(iso: string, locale?: string): string;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Format a UTC ISO string for display in a specific IANA timezone.
|
|
260
|
+
* Handles DST transitions correctly. Supports a small set of tokens: `yyyy MM dd HH mm ss`.
|
|
261
|
+
*
|
|
262
|
+
* @param iso - UTC ISO 8601 string
|
|
263
|
+
* @param formatStr - token string (e.g. `"yyyy-MM-dd HH:mm"`)
|
|
264
|
+
* @param timeZone - IANA zone (e.g. `"America/New_York"`)
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* formatInTimezone('2026-03-08T07:30:00.000Z', 'yyyy-MM-dd HH:mm', 'America/New_York');
|
|
268
|
+
* // → '2026-03-08 03:30' (post spring-forward EDT)
|
|
269
|
+
*/
|
|
270
|
+
declare function formatInTimezone(iso: ISODateString, formatStr: string, timeZone: string): string;
|
|
271
|
+
/**
|
|
272
|
+
* UTC offset (minutes east of UTC) at a given UTC instant, as applied by the given timezone.
|
|
273
|
+
* The offset may differ on either side of a DST transition.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* getTimezoneOffsetMinutes('2026-03-08T06:00:00.000Z', 'America/New_York'); // -300 (EST, UTC-5)
|
|
277
|
+
* getTimezoneOffsetMinutes('2026-03-08T07:00:00.000Z', 'America/New_York'); // -240 (EDT, UTC-4)
|
|
278
|
+
* getTimezoneOffsetMinutes('2026-01-15T12:00:00.000Z', 'Asia/Seoul'); // 540 (UTC+9)
|
|
279
|
+
*/
|
|
280
|
+
declare function getTimezoneOffsetMinutes(iso: ISODateString, timeZone: string): number;
|
|
281
|
+
/**
|
|
282
|
+
* Midnight of the civil date (as observed in `timeZone`) returned as a UTC ISO string.
|
|
283
|
+
*
|
|
284
|
+
* Across DST transitions this is the correct way to compute "start of day" — the offset
|
|
285
|
+
* changes, so the UTC instant of midnight differs before and after the transition.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* startOfDayInTimezone('2026-03-08T12:00:00.000Z', 'America/New_York'); // '2026-03-08T05:00:00.000Z' (EST)
|
|
289
|
+
* startOfDayInTimezone('2026-03-09T12:00:00.000Z', 'America/New_York'); // '2026-03-09T04:00:00.000Z' (EDT)
|
|
290
|
+
*/
|
|
291
|
+
declare function startOfDayInTimezone(iso: ISODateString, timeZone: string): ISODateString;
|
|
292
|
+
/**
|
|
293
|
+
* Whether two UTC instants fall on the same civil day in the given timezone.
|
|
294
|
+
* Timezone-safe alternative to comparing `iso.slice(0, 10)`.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* // Seoul is UTC+9, so 03:00 UTC and 14:00 UTC are both on 2026-01-15 KST
|
|
298
|
+
* isSameDayInTimezone('2026-01-15T03:00:00.000Z', '2026-01-15T14:00:00.000Z', 'Asia/Seoul'); // true
|
|
299
|
+
* // But 17:00 UTC is 02:00 KST on 2026-01-16
|
|
300
|
+
* isSameDayInTimezone('2026-01-15T03:00:00.000Z', '2026-01-15T17:00:00.000Z', 'Asia/Seoul'); // false
|
|
301
|
+
*/
|
|
302
|
+
declare function isSameDayInTimezone(a: ISODateString, b: ISODateString, timeZone: string): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* "Today" in the given timezone, returned as the UTC ISO string representing that day's midnight.
|
|
305
|
+
* Prefer this over `new Date()` when the notion of "today" should follow the user's displayed
|
|
306
|
+
* timezone rather than the server's local clock.
|
|
307
|
+
*/
|
|
308
|
+
declare function todayInTimezone(timeZone: string): ISODateString;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Default English labels for ARIA attributes and accessible text.
|
|
312
|
+
* Override via the `labels` prop on Root components.
|
|
313
|
+
*/
|
|
314
|
+
interface DatePickerLabels {
|
|
315
|
+
triggerOpen: string;
|
|
316
|
+
triggerClose: string;
|
|
317
|
+
popoverLabel: string;
|
|
318
|
+
prevMonth: string;
|
|
319
|
+
nextMonth: string;
|
|
320
|
+
prevYear: string;
|
|
321
|
+
nextYear: string;
|
|
322
|
+
prevDecade: string;
|
|
323
|
+
nextDecade: string;
|
|
324
|
+
/** Used by DateTimePicker.Input (present only when DatePickerContext is provided by DateTimePickerRoot) */
|
|
325
|
+
dateTimeInput?: string;
|
|
326
|
+
}
|
|
327
|
+
interface RangePickerLabels extends DatePickerLabels {
|
|
328
|
+
startInput: string;
|
|
329
|
+
endInput: string;
|
|
330
|
+
presetsGroup: string;
|
|
331
|
+
}
|
|
332
|
+
interface TimePickerLabels {
|
|
333
|
+
timeInput: string;
|
|
334
|
+
hourList: string;
|
|
335
|
+
minuteList: string;
|
|
336
|
+
amPmToggle: string;
|
|
337
|
+
hourOption: (hour: number) => string;
|
|
338
|
+
minuteOption: (minute: number) => string;
|
|
339
|
+
}
|
|
340
|
+
interface DateTimePickerLabels extends DatePickerLabels, TimePickerLabels {
|
|
341
|
+
dateTimeInput: string;
|
|
342
|
+
}
|
|
343
|
+
declare const DEFAULT_DATEPICKER_LABELS: DatePickerLabels;
|
|
344
|
+
declare const DEFAULT_RANGEPICKER_LABELS: RangePickerLabels;
|
|
345
|
+
declare const DEFAULT_TIMEPICKER_LABELS: TimePickerLabels;
|
|
346
|
+
declare const DEFAULT_DATETIMEPICKER_LABELS: DateTimePickerLabels;
|
|
347
|
+
|
|
348
|
+
export { type CalendarDay, type CalendarGrid, type CalendarOptions, type CalendarWeek, DEFAULT_DATEPICKER_LABELS, DEFAULT_DATETIMEPICKER_LABELS, DEFAULT_RANGEPICKER_LABELS, DEFAULT_TIMEPICKER_LABELS, type DateAdapter, DateFnsAdapter, type DatePickerLabels, type DateRange, type DateTimePickerLabels, type DisabledRule, type ISODateString, type RangePickerLabels, type TimePickerLabels, type TimeValue, type WeekStartsOn, type WeekdayInfo, formatFullDate, formatInTimezone, formatMonthYear, formatTimeFromISO, formatTimeString, generateHours, generateMinutes, getCalendarDays, getMonthName, getTime, getTimezoneOffsetMinutes, getWeekdayNames, isDateDisabled, isSameDayInTimezone, isSameTime, maxDate, minDate, normalizeISO, parseInputValue, parseTimeString, setTime, startOfDayInTimezone, to12Hour, to24Hour, todayInTimezone };
|