@absoluteui/helpers 0.0.0-stage → 0.13.2

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 (221) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +47 -2
  4. package/SECURITY.md +102 -0
  5. package/dist/array/compare.d.ts +8 -0
  6. package/dist/array/compare.js +2 -0
  7. package/dist/array/index.d.ts +328 -0
  8. package/dist/array/index.js +2 -0
  9. package/dist/array/tree.d.ts +48 -0
  10. package/dist/array/tree.js +2 -0
  11. package/dist/async/batch.d.ts +103 -0
  12. package/dist/async/batch.js +2 -0
  13. package/dist/async/concurrency.d.ts +92 -0
  14. package/dist/async/concurrency.js +2 -0
  15. package/dist/async/control.d.ts +77 -0
  16. package/dist/async/control.js +2 -0
  17. package/dist/async/index.d.ts +8 -0
  18. package/dist/async/index.js +2 -0
  19. package/dist/async/signal.d.ts +95 -0
  20. package/dist/async/signal.js +2 -0
  21. package/dist/boolean/index.d.ts +83 -0
  22. package/dist/boolean/index.js +2 -0
  23. package/dist/business-calendar/days.d.ts +397 -0
  24. package/dist/business-calendar/days.js +2 -0
  25. package/dist/business-calendar/describe.d.ts +45 -0
  26. package/dist/business-calendar/describe.js +2 -0
  27. package/dist/business-calendar/engine.d.ts +305 -0
  28. package/dist/business-calendar/engine.js +2 -0
  29. package/dist/business-calendar/hours.d.ts +96 -0
  30. package/dist/business-calendar/hours.js +2 -0
  31. package/dist/business-calendar/index.d.ts +29 -0
  32. package/dist/business-calendar/index.js +2 -0
  33. package/dist/business-calendar/internal.d.ts +44 -0
  34. package/dist/business-calendar/internal.js +2 -0
  35. package/dist/business-calendar/rules.d.ts +260 -0
  36. package/dist/business-calendar/rules.js +2 -0
  37. package/dist/color/index.d.ts +200 -0
  38. package/dist/color/index.js +2 -0
  39. package/dist/color/named.d.ts +4 -0
  40. package/dist/color/named.js +2 -0
  41. package/dist/compare/index.d.ts +186 -0
  42. package/dist/compare/index.js +2 -0
  43. package/dist/convert/index.d.ts +152 -0
  44. package/dist/convert/index.js +2 -0
  45. package/dist/csv/index.d.ts +6 -0
  46. package/dist/csv/index.js +2 -0
  47. package/dist/csv/parse.d.ts +85 -0
  48. package/dist/csv/parse.js +12 -0
  49. package/dist/csv/stringify.d.ts +48 -0
  50. package/dist/csv/stringify.js +5 -0
  51. package/dist/date/calendar.d.ts +339 -0
  52. package/dist/date/calendar.js +2 -0
  53. package/dist/date/format.d.ts +66 -0
  54. package/dist/date/format.js +2 -0
  55. package/dist/date/index.d.ts +26 -0
  56. package/dist/date/index.js +2 -0
  57. package/dist/date/intervals.d.ts +110 -0
  58. package/dist/date/intervals.js +2 -0
  59. package/dist/date/intl-cache.d.ts +10 -0
  60. package/dist/date/intl-cache.js +2 -0
  61. package/dist/date/locale.d.ts +58 -0
  62. package/dist/date/locale.js +2 -0
  63. package/dist/date/plain-date.d.ts +105 -0
  64. package/dist/date/plain-date.js +2 -0
  65. package/dist/date/plain-time.d.ts +121 -0
  66. package/dist/date/plain-time.js +2 -0
  67. package/dist/date/zone.d.ts +121 -0
  68. package/dist/date/zone.js +2 -0
  69. package/dist/decimal/index.d.ts +149 -0
  70. package/dist/decimal/index.js +2 -0
  71. package/dist/ds/avl.d.ts +50 -0
  72. package/dist/ds/avl.js +2 -0
  73. package/dist/ds/bitset.d.ts +46 -0
  74. package/dist/ds/bitset.js +2 -0
  75. package/dist/ds/bloom.d.ts +41 -0
  76. package/dist/ds/bloom.js +2 -0
  77. package/dist/ds/caches.d.ts +141 -0
  78. package/dist/ds/caches.js +2 -0
  79. package/dist/ds/disjoint-set.d.ts +38 -0
  80. package/dist/ds/disjoint-set.js +2 -0
  81. package/dist/ds/emitter.d.ts +53 -0
  82. package/dist/ds/emitter.js +2 -0
  83. package/dist/ds/graph.d.ts +84 -0
  84. package/dist/ds/graph.js +2 -0
  85. package/dist/ds/heap.d.ts +49 -0
  86. package/dist/ds/heap.js +2 -0
  87. package/dist/ds/index.d.ts +20 -0
  88. package/dist/ds/index.js +2 -0
  89. package/dist/ds/internal.d.ts +19 -0
  90. package/dist/ds/internal.js +2 -0
  91. package/dist/ds/interval-tree.d.ts +49 -0
  92. package/dist/ds/interval-tree.js +2 -0
  93. package/dist/ds/linked-list.d.ts +54 -0
  94. package/dist/ds/linked-list.js +2 -0
  95. package/dist/ds/maps.d.ts +89 -0
  96. package/dist/ds/maps.js +2 -0
  97. package/dist/ds/ring.d.ts +99 -0
  98. package/dist/ds/ring.js +2 -0
  99. package/dist/ds/sorted.d.ts +104 -0
  100. package/dist/ds/sorted.js +2 -0
  101. package/dist/ds/stack.d.ts +28 -0
  102. package/dist/ds/stack.js +2 -0
  103. package/dist/ds/trie.d.ts +84 -0
  104. package/dist/ds/trie.js +2 -0
  105. package/dist/duration/index.d.ts +146 -0
  106. package/dist/duration/index.js +2 -0
  107. package/dist/encoding/index.d.ts +144 -0
  108. package/dist/encoding/index.js +2 -0
  109. package/dist/error/index.d.ts +316 -0
  110. package/dist/error/index.js +2 -0
  111. package/dist/fn/index.d.ts +129 -0
  112. package/dist/fn/index.js +2 -0
  113. package/dist/fn/memo.d.ts +46 -0
  114. package/dist/fn/memo.js +2 -0
  115. package/dist/fn/timing.d.ts +64 -0
  116. package/dist/fn/timing.js +2 -0
  117. package/dist/http/headers.d.ts +160 -0
  118. package/dist/http/headers.js +2 -0
  119. package/dist/http/index.d.ts +10 -0
  120. package/dist/http/index.js +2 -0
  121. package/dist/http/problem.d.ts +37 -0
  122. package/dist/http/problem.js +2 -0
  123. package/dist/http/response.d.ts +43 -0
  124. package/dist/http/response.js +2 -0
  125. package/dist/http/status.d.ts +169 -0
  126. package/dist/http/status.js +2 -0
  127. package/dist/index.d.ts +34 -0
  128. package/dist/index.js +2 -0
  129. package/dist/internal/keys.d.ts +6 -0
  130. package/dist/internal/keys.js +2 -0
  131. package/dist/is/index.d.ts +219 -0
  132. package/dist/is/index.js +2 -0
  133. package/dist/json/index.d.ts +9 -0
  134. package/dist/json/index.js +2 -0
  135. package/dist/json/internal.d.ts +12 -0
  136. package/dist/json/internal.js +2 -0
  137. package/dist/json/ndjson.d.ts +28 -0
  138. package/dist/json/ndjson.js +4 -0
  139. package/dist/json/parse.d.ts +45 -0
  140. package/dist/json/parse.js +2 -0
  141. package/dist/json/patch.d.ts +62 -0
  142. package/dist/json/patch.js +2 -0
  143. package/dist/json/pointer.d.ts +43 -0
  144. package/dist/json/pointer.js +2 -0
  145. package/dist/json/stringify.d.ts +42 -0
  146. package/dist/json/stringify.js +2 -0
  147. package/dist/linq/enumerable.d.ts +208 -0
  148. package/dist/linq/enumerable.js +2 -0
  149. package/dist/linq/index.d.ts +6 -0
  150. package/dist/linq/index.js +2 -0
  151. package/dist/linq/operators.d.ts +503 -0
  152. package/dist/linq/operators.js +2 -0
  153. package/dist/number/core.d.ts +164 -0
  154. package/dist/number/core.js +2 -0
  155. package/dist/number/format.d.ts +80 -0
  156. package/dist/number/format.js +2 -0
  157. package/dist/number/index.d.ts +12 -0
  158. package/dist/number/index.js +2 -0
  159. package/dist/number/internal.d.ts +18 -0
  160. package/dist/number/internal.js +2 -0
  161. package/dist/number/parse.d.ts +45 -0
  162. package/dist/number/parse.js +2 -0
  163. package/dist/number/words.d.ts +19 -0
  164. package/dist/number/words.js +2 -0
  165. package/dist/object/basic.d.ts +130 -0
  166. package/dist/object/basic.js +2 -0
  167. package/dist/object/deep.d.ts +90 -0
  168. package/dist/object/deep.js +2 -0
  169. package/dist/object/diff.d.ts +57 -0
  170. package/dist/object/diff.js +2 -0
  171. package/dist/object/index.d.ts +8 -0
  172. package/dist/object/index.js +2 -0
  173. package/dist/object/internal.d.ts +21 -0
  174. package/dist/object/internal.js +2 -0
  175. package/dist/object/path.d.ts +17 -0
  176. package/dist/object/path.js +2 -0
  177. package/dist/random/core.d.ts +14 -0
  178. package/dist/random/core.js +2 -0
  179. package/dist/random/index.d.ts +167 -0
  180. package/dist/random/index.js +2 -0
  181. package/dist/random/seeded.d.ts +27 -0
  182. package/dist/random/seeded.js +2 -0
  183. package/dist/sanitize/index.d.ts +8 -0
  184. package/dist/sanitize/index.js +2 -0
  185. package/dist/sanitize/pii.d.ts +48 -0
  186. package/dist/sanitize/pii.js +2 -0
  187. package/dist/sanitize/records.d.ts +100 -0
  188. package/dist/sanitize/records.js +2 -0
  189. package/dist/sanitize/text.d.ts +101 -0
  190. package/dist/sanitize/text.js +2 -0
  191. package/dist/set/index.d.ts +162 -0
  192. package/dist/set/index.js +2 -0
  193. package/dist/stats/index.d.ts +190 -0
  194. package/dist/stats/index.js +2 -0
  195. package/dist/string/index.d.ts +494 -0
  196. package/dist/string/index.js +8 -0
  197. package/dist/string/internal.d.ts +33 -0
  198. package/dist/string/internal.js +2 -0
  199. package/dist/string/words.d.ts +14 -0
  200. package/dist/string/words.js +2 -0
  201. package/dist/timezone/index.d.ts +76 -0
  202. package/dist/timezone/index.js +2 -0
  203. package/dist/url/index.d.ts +178 -0
  204. package/dist/url/index.js +2 -0
  205. package/dist/validate/builders.d.ts +6 -0
  206. package/dist/validate/builders.js +2 -0
  207. package/dist/validate/formats.d.ts +237 -0
  208. package/dist/validate/formats.js +2 -0
  209. package/dist/validate/index.d.ts +13 -0
  210. package/dist/validate/index.js +2 -0
  211. package/dist/validate/schema.d.ts +220 -0
  212. package/dist/validate/schema.js +2 -0
  213. package/dist/zip/index.d.ts +8 -0
  214. package/dist/zip/index.js +2 -0
  215. package/dist/zip/internal.d.ts +69 -0
  216. package/dist/zip/internal.js +2 -0
  217. package/dist/zip/reader.d.ts +56 -0
  218. package/dist/zip/reader.js +2 -0
  219. package/dist/zip/writer.d.ts +65 -0
  220. package/dist/zip/writer.js +2 -0
  221. package/package.json +150 -4
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Holiday rule types, builders, validation, Easter computus, and per-year occurrence
3
+ * expansion. Rules are data; the calendar resolves them per year and caches the result.
4
+ */
5
+ import { type DateInput, type IsoWeekday, type PlainDate } from '../date/index.js';
6
+ import { type MinuteRange, type TimeRange } from './internal.js';
7
+ /**
8
+ * Shift of a holiday that falls on a weekend day (per the calendar's weekend):
9
+ * `'nearest-weekday'` (Sat -> Fri, Sun -> Mon for a Sat/Sun weekend; ties go forward),
10
+ * `'next-weekday'`, `'previous-weekday'`, or a map from ISO weekday to a day offset
11
+ * (`{ 7: 1 }`: Sunday -> Monday), which applies on those weekdays whatever the weekend is.
12
+ * When the target already has a holiday (or is a weekend day) the search continues in the
13
+ * same direction, so a substitute day never lands on another holiday.
14
+ * @example
15
+ * const policy: ObservedPolicy = 'nearest-weekday';
16
+ * const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25, { observed: policy })] });
17
+ * isHoliday('2027-12-24', cal)?.name; // => 'Christmas Day' // Saturday 25th is observed on Friday 24th
18
+ * isBusinessDay('2027-12-24', cal); // => false
19
+ * isBusinessDay('2027-12-27', cal); // => true // Monday stays a business day
20
+ */
21
+ export type ObservedPolicy = 'none' | 'nearest-weekday' | 'next-weekday' | 'previous-weekday' | ObservedShiftMap;
22
+ /**
23
+ * Day offsets by ISO weekday for custom observed shifts (-7..7).
24
+ * @example
25
+ * const map: ObservedShiftMap = { 6: -1, 7: 1 }; // Saturday → Friday, Sunday → Monday
26
+ * const cal = createBusinessCalendar({ holidays: [fixedHoliday('Independence Day', 8, 15, { observed: map })] });
27
+ * isHoliday('2027-08-16', cal)?.observed; // => true // Sunday 15th observed on Monday 16th
28
+ */
29
+ export type ObservedShiftMap = Readonly<Partial<Record<IsoWeekday, number>>>;
30
+ /** Fields shared by every holiday rule. */
31
+ export interface HolidayRuleBase {
32
+ /** Plain-text name; also the accessible reason for a non-working day. */
33
+ readonly name: string;
34
+ readonly id?: string;
35
+ /** Scope tags (region, department); see `withTags`. Untagged rules apply everywhere. */
36
+ readonly tags?: readonly string[];
37
+ /** Default `'none'`. */
38
+ readonly observed?: ObservedPolicy;
39
+ /** The day is a working half day instead of a day off. */
40
+ readonly halfDay?: boolean;
41
+ /** Hours of the half day; default the calendar's `halfDayHours`, else the first half of the day. */
42
+ readonly halfDayHours?: readonly TimeRange[];
43
+ }
44
+ /** Year bounds for recurring rules (inclusive). */
45
+ export interface HolidayYearBounds {
46
+ readonly fromYear?: number;
47
+ readonly toYear?: number;
48
+ }
49
+ /** Same month and day every year (Feb 29 only in leap years). */
50
+ export interface FixedHolidayRule extends HolidayRuleBase, HolidayYearBounds {
51
+ readonly kind: 'fixed';
52
+ readonly month: number;
53
+ readonly day: number;
54
+ }
55
+ /** `n`-th weekday of a month: `n` 1..5, or -1..-5 counting from the end (-1 = last). */
56
+ export interface NthWeekdayHolidayRule extends HolidayRuleBase, HolidayYearBounds {
57
+ readonly kind: 'nth-weekday';
58
+ readonly month: number;
59
+ readonly weekday: IsoWeekday;
60
+ readonly n: number;
61
+ }
62
+ /** Days relative to Easter Sunday (Good Friday = -2, Easter Monday = 1). */
63
+ export interface EasterHolidayRule extends HolidayRuleBase, HolidayYearBounds {
64
+ readonly kind: 'easter';
65
+ /** -366..366, default 0. */
66
+ readonly offsetDays?: number;
67
+ /** Default `'western'` (Gregorian computus); `'orthodox'` uses the Julian computus. */
68
+ readonly method?: 'western' | 'orthodox';
69
+ }
70
+ /** A single date. */
71
+ export interface OneOffHolidayRule extends HolidayRuleBase {
72
+ readonly kind: 'date';
73
+ readonly date: DateInput;
74
+ }
75
+ /** Every date from `start` to `end`, inclusive (at most 3660 days). */
76
+ export interface RangeHolidayRule extends HolidayRuleBase {
77
+ readonly kind: 'range';
78
+ readonly start: DateInput;
79
+ readonly end: DateInput;
80
+ }
81
+ /**
82
+ * Dates computed by the application per year (lunar and regional calendars). Must be pure
83
+ * and synchronous; results are cached per year. At most 400 dates per year.
84
+ */
85
+ export interface CustomHolidayRule extends HolidayRuleBase, HolidayYearBounds {
86
+ readonly kind: 'custom';
87
+ readonly dates: (year: number) => readonly DateInput[];
88
+ }
89
+ /**
90
+ * A holiday rule (discriminated by `kind`).
91
+ * @example const rule: HolidayRule = { kind: 'fixed', name: 'New Year', month: 1, day: 1 };
92
+ */
93
+ export type HolidayRule = FixedHolidayRule | NthWeekdayHolidayRule | EasterHolidayRule | OneOffHolidayRule | RangeHolidayRule | CustomHolidayRule;
94
+ /**
95
+ * Rule kinds.
96
+ * @example const k: HolidayKind = 'easter';
97
+ */
98
+ export type HolidayKind = HolidayRule['kind'];
99
+ /**
100
+ * An already-resolved holiday returned by a `HolidayProvider` (no observed shift is applied).
101
+ * A `ResolvedHoliday` is accepted too.
102
+ * @example const h: ProvidedHoliday = { date: '2026-11-08', name: 'Diwali' };
103
+ */
104
+ export interface ProvidedHoliday {
105
+ readonly date: DateInput;
106
+ readonly name: string;
107
+ readonly id?: string;
108
+ readonly tags?: readonly string[];
109
+ readonly halfDay?: boolean;
110
+ readonly halfDayHours?: readonly TimeRange[];
111
+ }
112
+ /**
113
+ * Loads holiday data per year (no country data ships with the package, B4). Must be pure and
114
+ * synchronous; results are cached per calendar and year. Recurring rules returned for a year
115
+ * are expanded for that year only.
116
+ * @example
117
+ * const table: Readonly<Record<number, readonly ProvidedHoliday[]>> = { 2026: [{ date: '2026-11-10', name: 'Foundation Day' }] };
118
+ * const provider: HolidayProvider = { holidaysFor: (year) => table[year] ?? [] };
119
+ * const cal = createBusinessCalendar({ providers: [provider] });
120
+ * isHoliday('2026-11-10', cal)?.name; // => 'Foundation Day'
121
+ * isBusinessDay('2026-11-10', cal); // => false // Tuesday
122
+ */
123
+ export interface HolidayProvider {
124
+ holidaysFor(year: number): readonly (HolidayRule | ProvidedHoliday)[];
125
+ }
126
+ /**
127
+ * A holiday on a specific date. A shifted holiday produces two entries: the original date
128
+ * (`movedTo` set; informational, does not change whether that day is worked) and the observed
129
+ * date (`observed: true`, `originalDate` set).
130
+ * @example
131
+ * const cal = createBusinessCalendar({ holidays: [fixedHoliday('Christmas Day', 12, 25, { observed: 'nearest-weekday' })] });
132
+ * isHoliday('2027-12-24', cal); // => { date: '2027-12-24', name: 'Christmas Day', kind: 'fixed', tags: [], halfDay: false, observed: true, originalDate: '2027-12-25' }
133
+ * holidaysOn('2027-12-25', cal)[0]?.movedTo; // => '2027-12-24' // the Saturday original
134
+ */
135
+ export interface ResolvedHoliday {
136
+ readonly date: PlainDate;
137
+ readonly name: string;
138
+ readonly kind: HolidayKind | 'provided';
139
+ readonly id?: string;
140
+ readonly tags: readonly string[];
141
+ readonly halfDay: boolean;
142
+ readonly observed: boolean;
143
+ readonly originalDate?: PlainDate;
144
+ readonly movedTo?: PlainDate;
145
+ }
146
+ /** Validated rule plus what the engine needs to expand it. Internal. */
147
+ export interface NormalizedRule {
148
+ readonly rule: HolidayRule | ProvidedHoliday;
149
+ readonly kind: HolidayKind | 'provided';
150
+ readonly name: string;
151
+ readonly id: string | undefined;
152
+ readonly tags: readonly string[];
153
+ readonly observed: ObservedPolicy;
154
+ readonly halfDay: boolean;
155
+ readonly halfHours: readonly MinuteRange[] | undefined;
156
+ /** Recurring rules: epoch days for a rule year. */
157
+ readonly occurrences: ((year: number) => readonly number[]) | undefined;
158
+ /** One-off, range, and provided holidays: inclusive epoch-day span. */
159
+ readonly span: readonly [number, number] | undefined;
160
+ readonly fromYear: number;
161
+ readonly toYear: number;
162
+ }
163
+ /** Validates a tag list (1-64 characters each, at most 32). */
164
+ export declare function normalizeTags(value: unknown, property: string): readonly string[];
165
+ /**
166
+ * Easter Sunday for a year (1..275759). `'western'` uses the anonymous Gregorian algorithm
167
+ * (Meeus/Jones/Butcher); `'orthodox'` uses the Julian computus (Meeus) converted to the
168
+ * Gregorian calendar. Both are proleptic before their historical adoption.
169
+ * @example easterSunday(2026) // => '2026-04-05'
170
+ * @example easterSunday(2026, 'orthodox') // => '2026-04-12'
171
+ */
172
+ export declare function easterSunday(year: number, method?: 'western' | 'orthodox'): PlainDate;
173
+ /**
174
+ * Validates a rule (or, with `allowProvided`, a provider's resolved holiday) and returns the
175
+ * engine form. `forceHalf` marks entries of the calendar's `halfDays` list.
176
+ */
177
+ export declare function normalizeRule(value: unknown, property: string, options?: {
178
+ readonly forceHalf?: boolean;
179
+ readonly allowProvided?: boolean;
180
+ }): NormalizedRule;
181
+ /**
182
+ * Options shared by the rule builders.
183
+ * @example
184
+ * const options: HolidayRuleOptions = { observed: 'nearest-weekday', tags: ['US'], fromYear: 2020 };
185
+ * fixedHoliday('Independence Day', 7, 4, options).tags; // => ['US']
186
+ */
187
+ export type HolidayRuleOptions = Omit<HolidayRuleBase, 'name'> & HolidayYearBounds;
188
+ /**
189
+ * Same month and day every year.
190
+ * @example
191
+ * const cal = createBusinessCalendar({ holidays: [fixedHoliday('New Year', 1, 1, { observed: 'nearest-weekday' })] });
192
+ * isBusinessDay('2027-01-01', cal); // => false // Friday
193
+ * isHoliday('2027-12-31', cal)?.name; // => 'New Year' // 1 January 2028 is a Saturday
194
+ */
195
+ export declare function fixedHoliday(name: string, month: number, day: number, options?: HolidayRuleOptions): FixedHolidayRule;
196
+ /**
197
+ * `n`-th weekday of a month (`n` 1..5, or negative from the end).
198
+ * @example
199
+ * const cal = createBusinessCalendar({ holidays: [nthWeekdayHoliday('Thanksgiving', 11, 4, 4)] }); // 4th Thursday of November
200
+ * isHoliday('2026-11-26', cal)?.name; // => 'Thanksgiving'
201
+ * isHoliday('2027-11-25', cal)?.name; // => 'Thanksgiving'
202
+ */
203
+ export declare function nthWeekdayHoliday(name: string, month: number, weekday: IsoWeekday, n: number, options?: HolidayRuleOptions): NthWeekdayHolidayRule;
204
+ /**
205
+ * Last given weekday of a month.
206
+ * @example
207
+ * const cal = createBusinessCalendar({ holidays: [lastWeekdayHoliday('Memorial Day', 5, 1)] }); // last Monday of May
208
+ * isHoliday('2026-05-25', cal)?.name; // => 'Memorial Day'
209
+ * nextBusinessDay('2026-05-22', cal); // => '2026-05-26' // Friday → Tuesday
210
+ */
211
+ export declare function lastWeekdayHoliday(name: string, month: number, weekday: IsoWeekday, options?: HolidayRuleOptions): NthWeekdayHolidayRule;
212
+ /**
213
+ * Days relative to Easter Sunday.
214
+ * @example
215
+ * const cal = createBusinessCalendar({ holidays: [easterHoliday('Good Friday', -2), easterHoliday('Easter Monday', 1)] });
216
+ * listHolidays('2026-04-01', '2026-04-30', cal).map((h) => h.date); // => ['2026-04-03', '2026-04-06'] // Easter Sunday is 5 April
217
+ * @example
218
+ * const cal = createBusinessCalendar({ holidays: [easterHoliday('Orthodox Easter Monday', 1, { method: 'orthodox' })] });
219
+ * isHoliday('2026-04-13', cal)?.name; // => 'Orthodox Easter Monday'
220
+ */
221
+ export declare function easterHoliday(name: string, offsetDays?: number, options?: HolidayRuleOptions & {
222
+ readonly method?: 'western' | 'orthodox';
223
+ }): EasterHolidayRule;
224
+ /**
225
+ * A single date.
226
+ * @example
227
+ * const cal = createBusinessCalendar({ holidays: [oneOffHoliday('Office move', '2026-06-19')] });
228
+ * isBusinessDay('2026-06-19', cal); // => false // Friday
229
+ * isBusinessDay('2027-06-18', cal); // => true // does not recur
230
+ */
231
+ export declare function oneOffHoliday(name: string, date: DateInput, options?: Omit<HolidayRuleOptions, 'fromYear' | 'toYear'>): OneOffHolidayRule;
232
+ /**
233
+ * Every date from `start` to `end`, inclusive.
234
+ * @example
235
+ * const cal = createBusinessCalendar({ holidays: [holidayRange('Winter shutdown', '2026-12-24', '2027-01-01')] });
236
+ * diffDays('2026-12-24', '2027-01-01', { mode: 'calendar', inclusive: 'both', calendar: cal }); // => 9
237
+ * diffDays('2026-12-24', '2027-01-01', { mode: 'weekdays', inclusive: 'both', calendar: cal }); // => 7
238
+ * diffDays('2026-12-24', '2027-01-01', { mode: 'business', inclusive: 'both', calendar: cal }); // => 0
239
+ * nextBusinessDay('2026-12-23', cal); // => '2027-01-04'
240
+ */
241
+ export declare function holidayRange(name: string, start: DateInput, end: DateInput, options?: Omit<HolidayRuleOptions, 'fromYear' | 'toYear'>): RangeHolidayRule;
242
+ /**
243
+ * Dates computed per year by the application (lunar or regional calendars).
244
+ * @example
245
+ * // Dates from the application's own lunar table or server.
246
+ * const festival: Readonly<Record<number, readonly string[]>> = { 2026: ['2026-10-20'], 2027: ['2027-11-09'] };
247
+ * const cal = createBusinessCalendar({ weekend: [7], holidays: [customHoliday('Harvest festival', (year) => festival[year] ?? [])] });
248
+ * isHoliday('2026-10-20', cal)?.name; // => 'Harvest festival'
249
+ * isBusinessDay('2027-11-09', cal); // => false
250
+ */
251
+ export declare function customHoliday(name: string, dates: (year: number) => readonly DateInput[], options?: HolidayRuleOptions): CustomHolidayRule;
252
+ /**
253
+ * Validates a list of rules up front and returns it frozen (errors name the index).
254
+ * @example
255
+ * const US = defineHolidays([fixedHoliday('New Year', 1, 1), nthWeekdayHoliday('Labor Day', 9, 1, 1)]);
256
+ * isHoliday('2026-09-07', createBusinessCalendar({ holidays: US }))?.name; // => 'Labor Day'
257
+ * @example
258
+ * defineHolidays([{ kind: 'fixed', name: 'Typo', month: 13, day: 1 }]); // => throws HLP_BIZCAL_INVALID_RULE
259
+ */
260
+ export declare function defineHolidays(rules: readonly HolidayRule[]): readonly HolidayRule[];
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{MAX_YEAR as I,daysInMonth as P,fromEpochDay as j,isPlainDate as S,plainDate as W,toEpochDay as D,toPlainDate as U}from"../date/index.js";import{hasOwn as G}from"../internal/keys.js";import{epochOf as x,invalid as i,isArray as E,isRecord as Y,limit as B,normalizeRanges as F,optionalText as K,rangesToText as X,requiredName as q,weekdayOfEpoch as N}from"./internal.js";const p=32,C=3660,$=400,J=new Set(["none","nearest-weekday","next-weekday","previous-weekday"]),Q=/^[1-7]$/;function m(e,n,t,o,l="HLP_BIZCAL_INVALID_RULE"){if(typeof e!="number"||!Number.isInteger(e)||e<n||e>t)throw i(l,"Holiday rule field is out of range.",o);return e}function v(e,n){if(e===void 0)return Object.freeze([]);if(!E(e))throw i("HLP_BIZCAL_INVALID_TAGS","Tags must be an array of strings.",n);if(e.length>p)throw B("HLP_BIZCAL_TOO_MANY_TAGS","Too many tags.",p);const t=e.map(o=>{if(typeof o!="string"||o.length===0||o.length>64)throw i("HLP_BIZCAL_INVALID_TAGS","Tags must be strings of 1 to 64 characters.",n);return o});return Object.freeze([...new Set(t)])}function ee(e,n){if(e===void 0)return"none";if(typeof e=="string"){if(!J.has(e))throw i("HLP_BIZCAL_INVALID_OBSERVED","Unknown observed policy.",n);return e}if(!Y(e))throw i("HLP_BIZCAL_INVALID_OBSERVED","Observed policy must be a name or a weekday map.",n);const t={};for(const o of Object.keys(e)){if(!Q.test(o))throw i("HLP_BIZCAL_INVALID_OBSERVED","Observed map keys must be ISO weekdays 1-7.",n);t[Number(o)]=m(e[o],-7,7,n,"HLP_BIZCAL_INVALID_OBSERVED")}return Object.freeze(t)}function w(e,n){if(typeof e!="string"&&!S(e))throw i("HLP_BIZCAL_INVALID_RULE","Expected a PlainDate or YYYY-MM-DD.",n);try{return U(e)}catch{throw i("HLP_BIZCAL_INVALID_RULE","Expected a PlainDate or YYYY-MM-DD.",n)}}const z=(e,n)=>(e%n+n)%n;function ne(e,n="western"){if(m(e,1,I-1,"year","HLP_BIZCAL_INVALID_YEAR"),n==="orthodox"){const s=e%4,f=e%7,b=(19*(e%19)+15)%30,_=z(2*s+4*f-b+34,7),V=Math.floor((b+_+114)/31),T=(b+_+114)%31+1,Z=Math.floor(e/100)-Math.floor(e/400)-2;return j(x(e,V,T)+Z)}if(n!=="western")throw i("HLP_BIZCAL_INVALID_RULE","Easter method must be western or orthodox.","method");const o=e%19,l=Math.floor(e/100),H=e%100,d=Math.floor(l/4),h=l%4,L=Math.floor((l+8)/25),O=Math.floor((l-L+1)/3),R=(19*o+l-d-O+15)%30,A=Math.floor(H/4),k=H%4,y=z(32+2*h+2*A-R-k,7),c=Math.floor((o+11*R+22*y)/451),r=Math.floor((R+y-7*c+114)/31),a=(R+y-7*c+114)%31+1;return W(e,r,a)}function oe(e,n,t,o){const l=P(e,n);if(o>0){const h=x(e,n,1),L=1+(t-N(h)+7)%7+(o-1)*7;return L<=l?h+L-1:void 0}const H=x(e,n,l),d=l-(N(H)-t+7)%7-(-o-1)*7;return d>=1?H-(l-d):void 0}function M(e,n,t={}){if(!Y(e))throw i("HLP_BIZCAL_INVALID_RULE","A holiday rule must be an object.",n);const o=q(e.name,`${n}.name`),l=K(e.id,`${n}.id`),H=v(e.tags,`${n}.tags`),d=e.kind,h=t.allowProvided===!0&&d!=="range"&&d!=="date"&&G(e,"date"),L=h?"none":ee(e.observed,`${n}.observed`);if(e.halfDay!==void 0&&typeof e.halfDay!="boolean")throw i("HLP_BIZCAL_INVALID_RULE","halfDay must be a boolean.",`${n}.halfDay`);const O=t.forceHalf===!0||e.halfDay===!0,R=e.halfDayHours===void 0?void 0:F(e.halfDayHours,`${n}.halfDayHours`),A=e.fromYear===void 0?-I:m(e.fromYear,-I,I,`${n}.fromYear`),k=e.toYear===void 0?I:m(e.toYear,-I,I,`${n}.toYear`);if(A>k)throw i("HLP_BIZCAL_INVALID_RULE","fromYear must not be after toYear.",`${n}.fromYear`);const y={name:o,id:l,tags:H,observed:L,halfDay:O,halfHours:R,fromYear:A,toYear:k},c={...l===void 0?{}:{id:l},...e.tags===void 0?{}:{tags:H},...e.observed===void 0||h?{}:{observed:L},...O?{halfDay:O}:{},...R===void 0?{}:{halfDayHours:X(R)},...e.fromYear===void 0?{}:{fromYear:A},...e.toYear===void 0?{}:{toYear:k}};if(h){const r=w(e.date,`${n}.date`),a=D(r),s=Object.freeze({date:r,name:o,...c});return Object.freeze({...y,rule:s,kind:"provided",observed:"none",occurrences:void 0,span:Object.freeze([a,a])})}switch(d){case"fixed":{const r=m(e.month,1,12,`${n}.month`),a=m(e.day,1,P(2024,r),`${n}.day`),s=Object.freeze({kind:d,name:o,month:r,day:a,...c});return Object.freeze({...y,rule:s,kind:d,occurrences:u=>a<=P(u,r)?[x(u,r,a)]:[],span:void 0})}case"nth-weekday":{const r=m(e.month,1,12,`${n}.month`),a=m(e.weekday,1,7,`${n}.weekday`),s=m(e.n,-5,5,`${n}.n`);if(s===0)throw i("HLP_BIZCAL_INVALID_RULE","n must be 1..5 or -1..-5.",`${n}.n`);const f=Object.freeze({kind:d,name:o,month:r,weekday:a,n:s,...c});return Object.freeze({...y,rule:f,kind:d,occurrences:b=>{const _=oe(b,r,a,s);return _===void 0?[]:[_]},span:void 0})}case"easter":{const r=e.offsetDays===void 0?0:m(e.offsetDays,-366,366,`${n}.offsetDays`),a=e.method??"western";if(a!=="western"&&a!=="orthodox")throw i("HLP_BIZCAL_INVALID_RULE","Easter method must be western or orthodox.",`${n}.method`);const s=Object.freeze({kind:d,name:o,offsetDays:r,method:a,...c});return Object.freeze({...y,rule:s,kind:d,occurrences:u=>u>=1&&u<I?[D(ne(u,a))+r]:[],span:void 0})}case"date":{const r=w(e.date,`${n}.date`),a=D(r),s=Object.freeze({kind:d,name:o,date:r,...c});return Object.freeze({...y,rule:s,kind:d,occurrences:void 0,span:Object.freeze([a,a])})}case"range":{const r=w(e.start,`${n}.start`),a=w(e.end,`${n}.end`),s=D(r),f=D(a);if(f<s)throw i("HLP_BIZCAL_INVALID_RULE","A holiday range must not end before it starts.",`${n}.end`);if(f-s+1>C)throw B("HLP_BIZCAL_RANGE_TOO_LONG","A holiday range may cover at most 3660 days.",C);const u=Object.freeze({kind:d,name:o,start:r,end:a,...c});return Object.freeze({...y,rule:u,kind:d,occurrences:void 0,span:Object.freeze([s,f])})}case"custom":{const r=e.dates;if(typeof r!="function")throw i("HLP_BIZCAL_INVALID_RULE","A custom rule needs a dates(year) function.",`${n}.dates`);const a=r,s=Object.freeze({kind:d,name:o,dates:a,...c});return Object.freeze({...y,rule:s,kind:d,occurrences:u=>{const b=a(u);if(!E(b))throw i("HLP_BIZCAL_INVALID_RULE","A custom rule must return an array of dates.",`${n}.dates`);if(b.length>$)throw B("HLP_BIZCAL_TOO_MANY_DATES","A custom rule returned too many dates for one year.",$);return b.map(_=>D(w(_,`${n}.dates`)))},span:void 0})}default:throw i("HLP_BIZCAL_INVALID_RULE","Unknown holiday rule kind.",`${n}.kind`)}}function g(e){return M(e,"rule").rule}function se(e,n,t,o={}){return g({...o,kind:"fixed",name:e,month:n,day:t})}function te(e,n,t,o,l={}){return g({...l,kind:"nth-weekday",name:e,month:n,weekday:t,n:o})}function ie(e,n,t,o={}){return te(e,n,t,-1,o)}function le(e,n=0,t={}){return g({...t,kind:"easter",name:e,offsetDays:n})}function ue(e,n,t={}){return g({...t,kind:"date",name:e,date:n})}function ye(e,n,t,o={}){return g({...o,kind:"range",name:e,start:n,end:t})}function ce(e,n,t={}){return g({...t,kind:"custom",name:e,dates:n})}function fe(e){if(!E(e))throw i("HLP_BIZCAL_INVALID_RULE","Expected an array of holiday rules.","rules");return Object.freeze(e.map((n,t)=>M(n,`rules[${String(t)}]`).rule))}export{ce as customHoliday,fe as defineHolidays,le as easterHoliday,ne as easterSunday,se as fixedHoliday,ye as holidayRange,ie as lastWeekdayHoliday,M as normalizeRule,v as normalizeTags,te as nthWeekdayHoliday,ue as oneOffHoliday};
@@ -0,0 +1,200 @@
1
+ /** sRGB colour: channels 0-255 (may be fractional), alpha 0-1. */
2
+ export interface Rgb {
3
+ readonly r: number;
4
+ readonly g: number;
5
+ readonly b: number;
6
+ readonly alpha: number;
7
+ }
8
+ /** Hue 0-360 (0 for greys), saturation and lightness 0-100, alpha 0-1. */
9
+ export interface Hsl {
10
+ readonly h: number;
11
+ readonly s: number;
12
+ readonly l: number;
13
+ readonly alpha: number;
14
+ }
15
+ /** OKLCH: lightness 0-1, chroma >= 0 (~0-0.4 for sRGB), hue 0-360, alpha 0-1. */
16
+ export interface Oklch {
17
+ readonly l: number;
18
+ readonly c: number;
19
+ readonly h: number;
20
+ readonly alpha: number;
21
+ }
22
+ /** A CSS colour string or an RGB object (alpha defaults to 1). */
23
+ export type ColorInput = string | {
24
+ readonly r: number;
25
+ readonly g: number;
26
+ readonly b: number;
27
+ readonly alpha?: number;
28
+ };
29
+ /**
30
+ * Parses a CSS colour: hex (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), `rgb()`/`rgba()` (legacy
31
+ * commas and modern space syntax), `hsl()`/`hsla()`, `oklch()`, the 148 named colours, and
32
+ * `transparent`. Returns `undefined` when invalid (including `currentcolor`).
33
+ * @example
34
+ * parseColor('rgb(255 0 0 / 50%)'); // => { r: 255, g: 0, b: 0, alpha: 0.5 }
35
+ * parseColor('rebeccapurple'); // => { r: 102, g: 51, b: 153, alpha: 1 }
36
+ */
37
+ export declare function parseColor(input: string): Rgb | undefined;
38
+ /**
39
+ * Like `parseColor` but throws `HLP_COLOR_INVALID`.
40
+ * @example
41
+ * parseColorOrThrow('#fff'); // => { r: 255, g: 255, b: 255, alpha: 1 }
42
+ */
43
+ export declare function parseColorOrThrow(input: string): Rgb;
44
+ /**
45
+ * The CSS named colour keywords (lowercase).
46
+ * @example
47
+ * cssColorNames().length; // => 148
48
+ */
49
+ export declare function cssColorNames(): string[];
50
+ export interface FormatHexOptions {
51
+ /** `auto` (default) appends alpha only when below 1. */
52
+ readonly alpha?: 'auto' | 'always' | 'never';
53
+ }
54
+ /**
55
+ * Lowercase hex (`#rrggbb` or `#rrggbbaa`).
56
+ * @example
57
+ * formatHex('rgb(255 0 0 / 0.5)'); // => '#ff000080'
58
+ */
59
+ export declare function formatHex(color: ColorInput, options?: FormatHexOptions): string;
60
+ /**
61
+ * CSS `rgb()` in modern space syntax, or legacy `rgb(r, g, b)`/`rgba(...)` with `{ legacy: true }`.
62
+ * @example
63
+ * formatRgb('#ff000080'); // => 'rgb(255 0 0 / 0.502)'
64
+ */
65
+ export declare function formatRgb(color: ColorInput, options?: {
66
+ readonly legacy?: boolean;
67
+ }): string;
68
+ /**
69
+ * CSS `hsl()` in modern syntax.
70
+ * @example
71
+ * formatHsl('#ff0000'); // => 'hsl(0 100% 50%)'
72
+ */
73
+ export declare function formatHsl(color: ColorInput): string;
74
+ /**
75
+ * CSS `oklch()` with lightness as a percentage.
76
+ * @example
77
+ * formatOklch('#ff0000'); // => 'oklch(62.796% 0.25768 29.234)'
78
+ */
79
+ export declare function formatOklch(color: ColorInput): string;
80
+ /**
81
+ * sRGB to HSL.
82
+ * @example
83
+ * rgbToHsl({ r: 255, g: 0, b: 0, alpha: 1 }); // => { h: 0, s: 100, l: 50, alpha: 1 }
84
+ */
85
+ export declare function rgbToHsl(rgb: Rgb): Hsl;
86
+ /**
87
+ * HSL to sRGB.
88
+ * @example
89
+ * hslToRgb({ h: 120, s: 100, l: 25, alpha: 1 }); // => { r: 0, g: 127.5, b: 0, alpha: 1 }
90
+ */
91
+ export declare function hslToRgb(hsl: Hsl): Rgb;
92
+ /**
93
+ * sRGB to OKLCH (hue 0 for greys).
94
+ * @example
95
+ * const white = rgbToOklch({ r: 255, g: 255, b: 255, alpha: 1 });
96
+ * white.l; // => ≈ 1.000
97
+ * white.c; // => ≈ 0.000
98
+ * white.h; // => 0
99
+ */
100
+ export declare function rgbToOklch(rgb: Rgb): Oklch;
101
+ export interface GamutOptions {
102
+ /** `chroma` (default) reduces chroma at constant lightness and hue until in sRGB; `clip` clamps channels. */
103
+ readonly gamut?: 'chroma' | 'clip';
104
+ }
105
+ /**
106
+ * OKLCH to sRGB with gamut mapping.
107
+ * @example
108
+ * const red = oklchToRgb({ l: 0.628, c: 0.2577, h: 29.23, alpha: 1 });
109
+ * red.r; // => ≈ 255
110
+ * red.g; // => ≈ 0
111
+ * red.b; // => ≈ 0
112
+ */
113
+ export declare function oklchToRgb(lch: Oklch, options?: GamutOptions): Rgb;
114
+ /**
115
+ * WCAG 2.x relative luminance (0 black - 1 white). Alpha is ignored: composite first with `compositeOver`.
116
+ * @example
117
+ * relativeLuminance('#ffffff'); // => 1
118
+ */
119
+ export declare function relativeLuminance(color: ColorInput): number;
120
+ /**
121
+ * Alpha-composites `fg` over `bg` (source-over).
122
+ * @example
123
+ * compositeOver('rgb(0 0 0 / 0.5)', '#ffffff'); // => { r: 127.5, g: 127.5, b: 127.5, alpha: 1 }
124
+ */
125
+ export declare function compositeOver(fg: ColorInput, bg: ColorInput): Rgb;
126
+ /**
127
+ * WCAG contrast ratio (1-21), unrounded. A translucent background is composited over white and a
128
+ * translucent foreground over the background.
129
+ * @example
130
+ * contrastRatio('#000', '#fff'); // => 21
131
+ * contrastRatio('#777', '#fff'); // => ≈ 4.48
132
+ */
133
+ export declare function contrastRatio(fg: ColorInput, bg: ColorInput): number;
134
+ export interface MeetsContrastOptions {
135
+ /** Default `AA`. */
136
+ readonly level?: 'AA' | 'AAA';
137
+ /** `normal` text (default), `large` text (>= 24px, or >= 18.66px bold), or `non-text` UI and graphics (1.4.11). */
138
+ readonly size?: 'normal' | 'large' | 'non-text';
139
+ }
140
+ /**
141
+ * WCAG threshold check: AA 4.5 (large 3), AAA 7 (large 4.5), non-text 3. The ratio is not rounded.
142
+ * @example
143
+ * meetsContrast('#777', '#fff'); // => false // 4.48 < 4.5
144
+ * meetsContrast('#777', '#fff', { size: 'large' }); // => true
145
+ */
146
+ export declare function meetsContrast(fg: ColorInput, bg: ColorInput, options?: MeetsContrastOptions): boolean;
147
+ /**
148
+ * The candidate with the highest contrast against `bg` (first wins ties).
149
+ * @example
150
+ * bestTextColor('#1e3a8a'); // => '#ffffff'
151
+ * bestTextColor('#fde68a', ['#1f2937', '#f9fafb']); // => '#1f2937'
152
+ */
153
+ export declare function bestTextColor(bg: ColorInput): '#000000' | '#ffffff';
154
+ export declare function bestTextColor<T extends ColorInput>(bg: ColorInput, candidates: readonly T[]): T;
155
+ /**
156
+ * True when white text contrasts better than black (translucent colours are composited over white).
157
+ * @example
158
+ * isDark('#1e3a8a'); // => true
159
+ */
160
+ export declare function isDark(color: ColorInput): boolean;
161
+ /**
162
+ * Opposite of `isDark`.
163
+ * @example
164
+ * isLight('#fef3c7'); // => true
165
+ */
166
+ export declare function isLight(color: ColorInput): boolean;
167
+ export interface MixOptions extends GamutOptions {
168
+ /** Interpolation space. Default `oklch` (shorter hue arc). `srgb` mixes gamma-encoded channels like CSS `color-mix(in srgb)`. */
169
+ readonly space?: 'oklch' | 'srgb';
170
+ }
171
+ /**
172
+ * Mixes two colours; `weight` is the share of `b` (0 -> `a`, 1 -> `b`). Alpha is interpolated linearly.
173
+ * @example
174
+ * formatHex(mix('#000', '#fff', 0.5, { space: 'srgb' })); // => '#808080'
175
+ */
176
+ export declare function mix(a: ColorInput, b: ColorInput, weight?: number, options?: MixOptions): Rgb;
177
+ /**
178
+ * Raises OKLCH lightness by `amount` (0-1, absolute).
179
+ * @example
180
+ * formatHex(lighten('#1e3a8a', 0.2));
181
+ */
182
+ export declare function lighten(color: ColorInput, amount?: number, options?: GamutOptions): Rgb;
183
+ /**
184
+ * Lowers OKLCH lightness by `amount` (0-1, absolute).
185
+ * @example
186
+ * formatHex(darken('#93c5fd', 0.2));
187
+ */
188
+ export declare function darken(color: ColorInput, amount?: number, options?: GamutOptions): Rgb;
189
+ /**
190
+ * Returns the colour with `alpha` (0-1) replaced.
191
+ * @example
192
+ * formatHex(withAlpha('#ff0000', 0.5)); // => '#ff000080'
193
+ */
194
+ export declare function withAlpha(color: ColorInput, alpha: number): Rgb;
195
+ /**
196
+ * Perceptual distance ΔEOK (Euclidean in Oklab; ~ 0.02 is a just-noticeable difference). Alpha ignored.
197
+ * @example
198
+ * colorDistance('#000', '#fff'); // => ≈ 1.00
199
+ */
200
+ export declare function colorDistance(a: ColorInput, b: ColorInput): number;
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{ValidationError as $}from"../error/index.js";import{namedColor as P,namedColorNames as G}from"./named.js";const s=(n,t,e)=>n<t?t:n>e?e:n,C=n=>(n%360+360)%360,S=/^([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(%|deg|rad|grad|turn)?$/,q=/^([a-z]+)\(([^()]*)\)$/,z=256;function H(n){if(n==="none")return"none";const t=S.exec(n);if(!t)return;const e=Number(t[1]);return Number.isFinite(e)?{v:e,unit:t[2]??""}:void 0}function _(n){if(n==="none")return 0;switch(n.unit){case"":case"deg":return C(n.v);case"rad":return C(n.v*180/Math.PI);case"grad":return C(n.v*.9);case"turn":return C(n.v*360);default:return}}function V(n){return n===void 0?1:n==="none"?0:n.unit==="%"?s(n.v/100,0,1):n.unit===""?s(n.v,0,1):void 0}function K(n){if(!/^[\da-f]+$/.test(n))return;const t=n.length;if(t===3||t===4){const e=r=>Number.parseInt(n.charAt(r)+n.charAt(r),16);return{r:e(0),g:e(1),b:e(2),alpha:t===4?e(3)/255:1}}if(t===6||t===8){const e=r=>Number.parseInt(n.slice(r,r+2),16);return{r:e(0),g:e(2),b:e(4),alpha:t===8?e(6)/255:1}}}function W(n){if(n.includes(",")){const o=n.split(",").map(a=>a.trim());return o.length!==3&&o.length!==4?void 0:[o.slice(0,3),o[3]]}const t=n.split("/");if(t.length>2)return;const e=(t[0]??"").trim().split(/\s+/);if(e.length!==3)return;const r=t[1]?.trim();if(r!=="")return[e,r]}function J(n){if(n.length>z)return;const t=n.trim().toLowerCase();if(t.startsWith("#"))return K(t.slice(1));if(t==="transparent")return{r:0,g:0,b:0,alpha:0};const e=P(t);if(e!==void 0)return{r:e>>>16,g:e>>>8&255,b:e&255,alpha:1};const r=q.exec(t);if(!r)return;const o=r[1]??"",a=W(r[2]??"");if(!a)return;const i=a[0].map(H),[u,l,f]=i;if(u===void 0||l===void 0||f===void 0)return;const p=a[1]===void 0?void 0:H(a[1]);if(a[1]!==void 0&&p===void 0)return;const m=V(p);if(m!==void 0){if(o==="rgb"||o==="rgba"){const c=g=>g==="none"?0:g.unit==="%"?s(g.v*255/100,0,255):g.unit===""?s(g.v,0,255):void 0,b=c(u),h=c(l),y=c(f);return b===void 0||h===void 0||y===void 0?void 0:{r:b,g:h,b:y,alpha:m}}if(o==="hsl"||o==="hsla"){const c=g=>g==="none"?0:g.unit==="%"||g.unit===""?s(g.v,0,100):void 0,b=_(u),h=c(l),y=c(f);return b===void 0||h===void 0||y===void 0?void 0:j({h:b,s:h,l:y,alpha:m})}if(o==="oklch"){const c=u==="none"?0:u.unit==="%"?u.v/100:u.unit===""?u.v:void 0,b=l==="none"?0:l.unit==="%"?l.v/100*.4:l.unit===""?l.v:void 0,h=_(f);return c===void 0||b===void 0||h===void 0?void 0:v({l:s(c,0,1),c:Math.max(0,b),h,alpha:m})}}}function U(n){const t=J(n);if(!t)throw new $("HLP_COLOR_INVALID","The colour is not valid.");return t}function d(n){if(typeof n=="string")return U(n);const{r:t,g:e,b:r}=n,o=n.alpha??1;if(![t,e,r,o].every(Number.isFinite))throw new $("HLP_COLOR_INVALID","The colour is not valid.");return{r:s(t,0,255),g:s(e,0,255),b:s(r,0,255),alpha:s(o,0,1)}}function on(){return G()}const x=(n,t)=>String(Number(n.toFixed(t))),O=n=>Math.round(s(n,0,255)).toString(16).padStart(2,"0");function an(n,t={}){const e=d(n),r=t.alpha??"auto",o=r==="always"||r==="auto"&&e.alpha<1;return`#${O(e.r)}${O(e.g)}${O(e.b)}${o?O(e.alpha*255):""}`}function un(n,t={}){const e=d(n),[r,o,a]=[e.r,e.g,e.b].map(u=>Math.round(u)),i=x(e.alpha,3);return t.legacy===!0?e.alpha<1?`rgba(${r}, ${o}, ${a}, ${i})`:`rgb(${r}, ${o}, ${a})`:e.alpha<1?`rgb(${r} ${o} ${a} / ${i})`:`rgb(${r} ${o} ${a})`}function ln(n){const t=X(d(n)),e=t.alpha<1?` / ${x(t.alpha,3)}`:"";return`hsl(${x(t.h,2)} ${x(t.s,2)}% ${x(t.l,2)}%${e})`}function sn(n){const t=M(d(n)),e=t.alpha<1?` / ${x(t.alpha,3)}`:"";return`oklch(${x(t.l*100,3)}% ${x(t.c,5)} ${x(t.h,3)}${e})`}function X(n){const t=n.r/255,e=n.g/255,r=n.b/255,o=Math.max(t,e,r),a=Math.min(t,e,r),i=(o+a)/2,u=o-a;let l=0,f=0;return u>1e-12&&(f=i===0||i===1?0:u/(1-Math.abs(2*i-1)),o===t?l=(e-r)/u%6:o===e?l=(r-t)/u+2:l=(t-e)/u+4,l=C(l*60)),{h:l,s:f*100,l:i*100,alpha:n.alpha}}function j(n){const t=s(n.s,0,100)/100,e=s(n.l,0,100)/100,r=C(n.h),o=a=>{const i=(a+r/30)%12,u=t*Math.min(e,1-e);return(e-u*Math.max(-1,Math.min(i-3,9-i,1)))*255};return{r:o(0),g:o(8),b:o(4),alpha:s(n.alpha,0,1)}}const I=n=>n<=.04045?n/12.92:((n+.055)/1.055)**2.4,B=n=>n<=.0031308?n*12.92:1.055*n**(1/2.4)-.055;function T(n){return w(I(n.r/255),I(n.g/255),I(n.b/255))}function w(n,t,e){const r=Math.cbrt(.4122214708*n+.5363325363*t+.0514459929*e),o=Math.cbrt(.2119034982*n+.6806995451*t+.1073969566*e),a=Math.cbrt(.0883024619*n+.2817188376*t+.6299787005*e);return{l:.2104542553*r+.793617785*o-.0040720468*a,a:1.9779984951*r-2.428592205*o+.4505937099*a,b:.0259040371*r+.7827717662*o-.808675766*a}}function k(n,t,e){const r=e*Math.PI/180,o=t*Math.cos(r),a=t*Math.sin(r),i=(n+.3963377774*o+.2158037573*a)**3,u=(n-.1055613458*o-.0638541728*a)**3,l=(n-.0894841775*o-1.291485548*a)**3;return[4.0767416621*i-3.3077115913*u+.2309699292*l,-1.2684380046*i+2.6097574011*u-.3413193965*l,-.0041960863*i-.7034186147*u+1.707614701*l]}const A=1e-4;function M(n){const t=T(n),e=Math.hypot(t.a,t.b),r=e<A?0:C(Math.atan2(t.b,t.a)*180/Math.PI);return{l:t.l,c:e,h:r,alpha:n.alpha}}const R=1e-6,Q=.02;function Y(n,t,e,r){const[o=0,a=0,i=0]=n.map(f=>s(f,0,1)),u=w(o,a,i),l=r*Math.PI/180;return Math.hypot(u.l-t,u.a-e*Math.cos(l),u.b-e*Math.sin(l))<Q}const D=n=>n.every(t=>t>=-R&&t<=1+R);function v(n,t={}){const e=s(n.l,0,1),r=s(n.alpha,0,1);let o=Math.max(0,n.c);const a=C(n.h);if(e>=1-R)return{r:255,g:255,b:255,alpha:r};if(e<=R)return{r:0,g:0,b:0,alpha:r};let i=k(e,o,a);if(!D(i)&&t.gamut!=="clip"&&!Y(i,e,o,a)){let p=0,m=o;for(let c=0;c<24;c++){const b=(p+m)/2;D(k(e,b,a))?p=b:m=b}o=p,i=k(e,o,a)}const[u,l,f]=i.map(p=>s(B(s(p,0,1)),0,1)*255);return{r:u,g:l,b:f,alpha:r}}function L(n){const t=d(n);return .2126*I(t.r/255)+.7152*I(t.g/255)+.0722*I(t.b/255)}function N(n,t){const e=d(n),r=d(t),o=e.alpha+r.alpha*(1-e.alpha);if(o<=0)return{r:0,g:0,b:0,alpha:0};const a=(i,u)=>(i*e.alpha+u*r.alpha*(1-e.alpha))/o;return{r:a(e.r,r.r),g:a(e.g,r.g),b:a(e.b,r.b),alpha:o}}const E={r:255,g:255,b:255,alpha:1};function F(n,t){let e=d(t);e.alpha<1&&(e=N(e,E));let r=d(n);r.alpha<1&&(r=N(r,e));const o=L(r),a=L(e);return(Math.max(o,a)+.05)/(Math.min(o,a)+.05)}function cn(n,t,e={}){const{level:r="AA",size:o="normal"}=e,a=o==="non-text"?3:r==="AAA"?o==="large"?4.5:7:o==="large"?3:4.5;return F(n,t)>=a}function fn(n,t=["#000000","#ffffff"]){let e,r=-1;for(const o of t){const a=F(o,n);a>r&&(r=a,e=o)}if(e===void 0)throw new $("HLP_COLOR_NO_CANDIDATES","At least one candidate colour is required.");return e}const Z=Math.sqrt(1.05*.05)-.05;function nn(n){let t=d(n);return t.alpha<1&&(t=N(t,E)),L(t)<Z}function dn(n){return!nn(n)}function bn(n,t,e=.5,r={}){const o=s(Number.isFinite(e)?e:.5,0,1),a=d(n),i=d(t),u=(b,h)=>b+(h-b)*o;if(r.space==="srgb")return{r:u(a.r,i.r),g:u(a.g,i.g),b:u(a.b,i.b),alpha:u(a.alpha,i.alpha)};const l=M(a),f=M(i);let p=l.h,m=f.h;l.c<A&&(p=m),f.c<A&&(m=p);let c=m-p;return c>180?c-=360:c<-180&&(c+=360),v({l:u(l.l,f.l),c:u(l.c,f.c),h:p+c*o,alpha:u(a.alpha,i.alpha)},r)}function en(n,t=.1,e={}){const r=M(d(n));return v({...r,l:s(r.l+t,0,1)},e)}function pn(n,t=.1,e={}){return en(n,-t,e)}function mn(n,t){return{...d(n),alpha:s(Number.isFinite(t)?t:1,0,1)}}function hn(n,t){const e=T(d(n)),r=T(d(t));return Math.hypot(e.l-r.l,e.a-r.a,e.b-r.b)}export{fn as bestTextColor,hn as colorDistance,N as compositeOver,F as contrastRatio,on as cssColorNames,pn as darken,an as formatHex,ln as formatHsl,sn as formatOklch,un as formatRgb,j as hslToRgb,nn as isDark,dn as isLight,en as lighten,cn as meetsContrast,bn as mix,v as oklchToRgb,J as parseColor,U as parseColorOrThrow,L as relativeLuminance,X as rgbToHsl,M as rgbToOklch,mn as withAlpha};
@@ -0,0 +1,4 @@
1
+ /** Named colour to 0xRRGGBB, or `undefined`. `name` must be lowercase. */
2
+ export declare function namedColor(name: string): number | undefined;
3
+ /** All named colour keywords, lowercase. */
4
+ export declare function namedColorNames(): string[];
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ const r="aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkgrey a9a9a9 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkslategrey 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dimgrey 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f grey 808080 honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightgrey d3d3d3 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightslategrey 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370db mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred db7093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 slategrey 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32";let e;function l(d){if(!e){e=new Map;const a=r.split(" ");for(let f=0;f+1<a.length;f+=2)e.set(a[f]??"",Number.parseInt(a[f+1]??"0",16))}return e.get(d)}function i(){return l("black"),[...e?.keys()??[]]}export{l as namedColor,i as namedColorNames};