@trismegisto/primitives 3.4.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/MIGRATION.md +831 -0
  2. package/README.md +8 -0
  3. package/dist/assignee.js +1 -1
  4. package/dist/assignee.js.map +1 -1
  5. package/dist/attachment.js +31 -2
  6. package/dist/attachment.js.map +1 -1
  7. package/dist/back-stack.d.ts +32 -0
  8. package/dist/back-stack.js +166 -0
  9. package/dist/back-stack.js.map +1 -0
  10. package/dist/bottom-sheet-gesture.d.ts +22 -0
  11. package/dist/bottom-sheet-gesture.js +58 -0
  12. package/dist/bottom-sheet-gesture.js.map +1 -0
  13. package/dist/calendar-display.d.ts +60 -0
  14. package/dist/calendar-display.js +132 -0
  15. package/dist/calendar-display.js.map +1 -0
  16. package/dist/calendar-external.d.ts +30 -0
  17. package/dist/calendar-external.js +129 -0
  18. package/dist/calendar-external.js.map +1 -0
  19. package/dist/calendar-grid-nav.d.ts +52 -0
  20. package/dist/calendar-grid-nav.js +91 -0
  21. package/dist/calendar-grid-nav.js.map +1 -0
  22. package/dist/calendar-hit.d.ts +33 -0
  23. package/dist/calendar-hit.js +57 -0
  24. package/dist/calendar-hit.js.map +1 -0
  25. package/dist/calendar-index.d.ts +20 -0
  26. package/dist/calendar-index.js +98 -0
  27. package/dist/calendar-index.js.map +1 -0
  28. package/dist/calendar-interaction.d.ts +83 -0
  29. package/dist/calendar-interaction.js +136 -0
  30. package/dist/calendar-interaction.js.map +1 -0
  31. package/dist/calendar-layout.d.ts +275 -0
  32. package/dist/calendar-layout.js +546 -0
  33. package/dist/calendar-layout.js.map +1 -0
  34. package/dist/calendar-now.d.ts +64 -0
  35. package/dist/calendar-now.js +122 -0
  36. package/dist/calendar-now.js.map +1 -0
  37. package/dist/calendar-pointer.d.ts +90 -0
  38. package/dist/calendar-pointer.js +357 -0
  39. package/dist/calendar-pointer.js.map +1 -0
  40. package/dist/calendar-rules.d.ts +139 -0
  41. package/dist/calendar-rules.js +265 -0
  42. package/dist/calendar-rules.js.map +1 -0
  43. package/dist/calendar-series.d.ts +27 -0
  44. package/dist/calendar-series.js +150 -0
  45. package/dist/calendar-series.js.map +1 -0
  46. package/dist/calendar-timeline.d.ts +75 -0
  47. package/dist/calendar-timeline.js +141 -0
  48. package/dist/calendar-timeline.js.map +1 -0
  49. package/dist/calendar-zone.d.ts +101 -0
  50. package/dist/calendar-zone.js +319 -0
  51. package/dist/calendar-zone.js.map +1 -0
  52. package/dist/camera-capture.d.ts +101 -0
  53. package/dist/camera-capture.js +206 -0
  54. package/dist/camera-capture.js.map +1 -0
  55. package/dist/data-grid-clipboard.d.ts +85 -0
  56. package/dist/data-grid-clipboard.js +223 -0
  57. package/dist/data-grid-clipboard.js.map +1 -0
  58. package/dist/data-grid-cursor.d.ts +165 -0
  59. package/dist/data-grid-cursor.js +219 -0
  60. package/dist/data-grid-cursor.js.map +1 -0
  61. package/dist/data-grid-export.d.ts +6 -1
  62. package/dist/data-grid-export.js +10 -18
  63. package/dist/data-grid-export.js.map +1 -1
  64. package/dist/data-grid-measure.d.ts +1 -1
  65. package/dist/data-grid-measure.js +2 -1
  66. package/dist/data-grid-measure.js.map +1 -1
  67. package/dist/data-grid.d.ts +7 -0
  68. package/dist/data-grid.js.map +1 -1
  69. package/dist/download.d.ts +15 -0
  70. package/dist/download.js +39 -0
  71. package/dist/download.js.map +1 -0
  72. package/dist/drag-drop.d.ts +1 -1
  73. package/dist/drag-drop.js +91 -24
  74. package/dist/drag-drop.js.map +1 -1
  75. package/dist/event-calendar-edit.d.ts +37 -5
  76. package/dist/event-calendar-edit.js +144 -13
  77. package/dist/event-calendar-edit.js.map +1 -1
  78. package/dist/event-calendar.d.ts +130 -11
  79. package/dist/event-calendar.js +195 -29
  80. package/dist/event-calendar.js.map +1 -1
  81. package/dist/file-upload-edit.d.ts +43 -0
  82. package/dist/file-upload-edit.js +64 -0
  83. package/dist/file-upload-edit.js.map +1 -0
  84. package/dist/file-upload-entries.d.ts +84 -0
  85. package/dist/file-upload-entries.js +214 -0
  86. package/dist/file-upload-entries.js.map +1 -0
  87. package/dist/file-upload.d.ts +74 -5
  88. package/dist/file-upload.js +165 -41
  89. package/dist/file-upload.js.map +1 -1
  90. package/dist/focus.d.ts +11 -0
  91. package/dist/focus.js +80 -4
  92. package/dist/focus.js.map +1 -1
  93. package/dist/gallery.d.ts +15 -4
  94. package/dist/gallery.js +28 -7
  95. package/dist/gallery.js.map +1 -1
  96. package/dist/gesture.d.ts +90 -0
  97. package/dist/gesture.js +165 -0
  98. package/dist/gesture.js.map +1 -0
  99. package/dist/graph-centrality.d.ts +36 -0
  100. package/dist/graph-centrality.js +160 -0
  101. package/dist/graph-centrality.js.map +1 -0
  102. package/dist/graph-components.d.ts +49 -0
  103. package/dist/graph-components.js +344 -0
  104. package/dist/graph-components.js.map +1 -0
  105. package/dist/graph-core.d.ts +124 -0
  106. package/dist/graph-core.js +275 -0
  107. package/dist/graph-core.js.map +1 -0
  108. package/dist/graph-order.d.ts +27 -0
  109. package/dist/graph-order.js +105 -0
  110. package/dist/graph-order.js.map +1 -0
  111. package/dist/graph-paths.d.ts +39 -0
  112. package/dist/graph-paths.js +105 -0
  113. package/dist/graph-paths.js.map +1 -0
  114. package/dist/graph-traverse.d.ts +89 -0
  115. package/dist/graph-traverse.js +164 -0
  116. package/dist/graph-traverse.js.map +1 -0
  117. package/dist/graph.d.ts +30 -0
  118. package/dist/graph.js +31 -0
  119. package/dist/graph.js.map +1 -0
  120. package/dist/icalendar.d.ts +33 -5
  121. package/dist/icalendar.js +269 -9
  122. package/dist/icalendar.js.map +1 -1
  123. package/dist/image-crop-io.d.ts +5 -1
  124. package/dist/image-crop-io.js +18 -5
  125. package/dist/image-crop-io.js.map +1 -1
  126. package/dist/image-crop.d.ts +84 -0
  127. package/dist/image-crop.js +131 -0
  128. package/dist/image-crop.js.map +1 -1
  129. package/dist/incident.js +2 -2
  130. package/dist/index.d.ts +32 -0
  131. package/dist/index.js +32 -0
  132. package/dist/index.js.map +1 -1
  133. package/dist/messages-data-grid.d.ts +42 -7
  134. package/dist/messages-data-grid.js +51 -0
  135. package/dist/messages-data-grid.js.map +1 -1
  136. package/dist/messages-en.js +11 -0
  137. package/dist/messages-en.js.map +1 -1
  138. package/dist/messages-es.js +11 -0
  139. package/dist/messages-es.js.map +1 -1
  140. package/dist/messages-event-calendar-pro.d.ts +105 -0
  141. package/dist/messages-event-calendar-pro.js +273 -0
  142. package/dist/messages-event-calendar-pro.js.map +1 -0
  143. package/dist/messages-resumable-upload.d.ts +106 -0
  144. package/dist/messages-resumable-upload.js +256 -0
  145. package/dist/messages-resumable-upload.js.map +1 -0
  146. package/dist/messages-rich-text.d.ts +120 -0
  147. package/dist/messages-rich-text.js +235 -0
  148. package/dist/messages-rich-text.js.map +1 -0
  149. package/dist/messages-secret.d.ts +32 -0
  150. package/dist/messages-secret.js +62 -0
  151. package/dist/messages-secret.js.map +1 -0
  152. package/dist/messages.d.ts +14 -0
  153. package/dist/messages.js +11 -0
  154. package/dist/messages.js.map +1 -1
  155. package/dist/mobile.d.ts +25 -0
  156. package/dist/mobile.js +45 -0
  157. package/dist/mobile.js.map +1 -0
  158. package/dist/native.d.ts +71 -0
  159. package/dist/native.js +147 -0
  160. package/dist/native.js.map +1 -0
  161. package/dist/payments.js +1 -1
  162. package/dist/payments.js.map +1 -1
  163. package/dist/popover-overlay.d.ts +4 -1
  164. package/dist/popover-overlay.js +10 -3
  165. package/dist/popover-overlay.js.map +1 -1
  166. package/dist/recurrence-editor.d.ts +3 -1
  167. package/dist/recurrence-editor.js +6 -0
  168. package/dist/recurrence-editor.js.map +1 -1
  169. package/dist/recurrence.d.ts +70 -10
  170. package/dist/recurrence.js +363 -24
  171. package/dist/recurrence.js.map +1 -1
  172. package/dist/resource-usage.js +1 -1
  173. package/dist/resource-usage.js.map +1 -1
  174. package/dist/resumable-upload-field.d.ts +57 -0
  175. package/dist/resumable-upload-field.js +196 -0
  176. package/dist/resumable-upload-field.js.map +1 -0
  177. package/dist/resumable-upload-store.d.ts +40 -0
  178. package/dist/resumable-upload-store.js +209 -0
  179. package/dist/resumable-upload-store.js.map +1 -0
  180. package/dist/resumable-upload-xhr.d.ts +37 -0
  181. package/dist/resumable-upload-xhr.js +180 -0
  182. package/dist/resumable-upload-xhr.js.map +1 -0
  183. package/dist/resumable-upload.d.ts +268 -0
  184. package/dist/resumable-upload.js +1221 -0
  185. package/dist/resumable-upload.js.map +1 -0
  186. package/dist/rich-text-atoms.d.ts +114 -0
  187. package/dist/rich-text-atoms.js +328 -0
  188. package/dist/rich-text-atoms.js.map +1 -0
  189. package/dist/rich-text-commands.d.ts +2 -2
  190. package/dist/rich-text-commands.js +1 -1
  191. package/dist/rich-text-commands.js.map +1 -1
  192. package/dist/rich-text-dom.d.ts +48 -4
  193. package/dist/rich-text-dom.js +337 -15
  194. package/dist/rich-text-dom.js.map +1 -1
  195. package/dist/rich-text-editor.d.ts +238 -3
  196. package/dist/rich-text-editor.js +1670 -26
  197. package/dist/rich-text-editor.js.map +1 -1
  198. package/dist/rich-text-image.d.ts +62 -0
  199. package/dist/rich-text-image.js +152 -0
  200. package/dist/rich-text-image.js.map +1 -0
  201. package/dist/rich-text-markdown-shortcuts.d.ts +21 -0
  202. package/dist/rich-text-markdown-shortcuts.js +89 -0
  203. package/dist/rich-text-markdown-shortcuts.js.map +1 -0
  204. package/dist/rich-text-markdown.d.ts +57 -0
  205. package/dist/rich-text-markdown.js +1245 -0
  206. package/dist/rich-text-markdown.js.map +1 -0
  207. package/dist/rich-text-model.d.ts +129 -4
  208. package/dist/rich-text-model.js +554 -33
  209. package/dist/rich-text-model.js.map +1 -1
  210. package/dist/rich-text-paste.d.ts +35 -0
  211. package/dist/rich-text-paste.js +254 -0
  212. package/dist/rich-text-paste.js.map +1 -0
  213. package/dist/rich-text-sanitize.d.ts +18 -16
  214. package/dist/rich-text-sanitize.js +203 -10
  215. package/dist/rich-text-sanitize.js.map +1 -1
  216. package/dist/rich-text-schema.d.ts +51 -2
  217. package/dist/rich-text-schema.js +52 -10
  218. package/dist/rich-text-schema.js.map +1 -1
  219. package/dist/rich-text-suggest.d.ts +109 -0
  220. package/dist/rich-text-suggest.js +181 -0
  221. package/dist/rich-text-suggest.js.map +1 -0
  222. package/dist/rich-text-table.d.ts +125 -0
  223. package/dist/rich-text-table.js +478 -0
  224. package/dist/rich-text-table.js.map +1 -0
  225. package/dist/rich-text-validation.d.ts +29 -0
  226. package/dist/rich-text-validation.js +46 -0
  227. package/dist/rich-text-validation.js.map +1 -0
  228. package/dist/rich-text.d.ts +8 -0
  229. package/dist/rich-text.js +8 -0
  230. package/dist/rich-text.js.map +1 -1
  231. package/dist/scheduling.d.ts +6 -0
  232. package/dist/scheduling.js.map +1 -1
  233. package/dist/secret.d.ts +120 -0
  234. package/dist/secret.js +310 -0
  235. package/dist/secret.js.map +1 -0
  236. package/dist/service-graph.js +62 -42
  237. package/dist/service-graph.js.map +1 -1
  238. package/dist/tabs-overflow.d.ts +27 -0
  239. package/dist/tabs-overflow.js +36 -0
  240. package/dist/tabs-overflow.js.map +1 -1
  241. package/dist/viewport-gestures.d.ts +144 -0
  242. package/dist/viewport-gestures.js +352 -0
  243. package/dist/viewport-gestures.js.map +1 -0
  244. package/dist/viewport.d.ts +98 -0
  245. package/dist/viewport.js +241 -0
  246. package/dist/viewport.js.map +1 -0
  247. package/dist/workflow.d.ts +0 -7
  248. package/dist/workflow.js +22 -30
  249. package/dist/workflow.js.map +1 -1
  250. package/dist/workspace.d.ts +3 -4
  251. package/dist/workspace.js +2 -2
  252. package/dist/workspace.js.map +1 -1
  253. package/package.json +5 -4
@@ -1,16 +1,20 @@
1
1
  /**
2
- * Recorrência de eventos, sem framework: um subconjunto simplificado do RRULE (RFC 5545) que cobre o que as
3
- * agendas corporativas pedem — diária, semanal (dias da semana), mensal (dia do mês ou "n-ésima segunda"),
4
- * anual, intervalo, fim por contagem ou por data e exceções. Tudo em **datas de calendário** (`IsoDate`), sem
5
- * fuso: a hora do evento é a mesma em cada ocorrência (hora de parede, como no `event-calendar.ts`).
2
+ * Recorrência de eventos, sem framework, pelo tipo RECUR do RFC 5545: o subconjunto de sempre (diária, semanal,
3
+ * mensal por dia ou "n-ésima segunda", anual, intervalo, contagem, data final, exceções), em **datas de calendário**,
4
+ * e a regra completa (`expandRecurrenceTimes`): frequência por hora, BYMONTH, BYMONTHDAY, BYDAY com posição (5ª,
5
+ * penúltima), BYHOUR, BYSETPOS ("último dia útil do mês"), WKST e UNTIL em instante. A hora do evento é hora de parede
6
+ * do fuso da série.
6
7
  *
7
- * Fica de fora, de propósito: `BYHOUR`/`BYMINUTE`/`BYSETPOS` genérico, `FREQ` abaixo de diária e vários
8
- * `BYMONTH`. Um RRULE com essas partes é lido só no que entende (o resto é ignorado), nunca quebra.
8
+ * Fica de fora, de propósito: frequência abaixo de hora (`MINUTELY`/`SECONDLY`), `BYMINUTE`/`BYSECOND`, `BYWEEKNO` e
9
+ * `BYYEARDAY`. Um RRULE com essas partes é lido só no que entende (o resto é ignorado), nunca quebra.
9
10
  */
10
11
  import { type IsoDate, type Weekday } from './date';
11
12
  import type { PluralMessage } from './i18n';
12
13
  export type RecurrenceFrequency = 'daily' | 'weekly' | 'monthly' | 'yearly';
13
14
  export declare const RECURRENCE_FREQUENCIES: readonly RecurrenceFrequency[];
15
+ /** Frequências da regra completa: as de sempre e a por hora (plantões, verificações periódicas). */
16
+ export type RecurrenceRuleFrequency = RecurrenceFrequency | 'hourly';
17
+ export declare const RECURRENCE_RULE_FREQUENCIES: readonly RecurrenceRuleFrequency[];
14
18
  /** Posição da semana no mês: 1ª a 4ª, ou `-1` (a última). */
15
19
  export type RecurrenceWeekPosition = 1 | 2 | 3 | 4 | -1;
16
20
  /**
@@ -23,7 +27,7 @@ export type RecurrenceWeekPosition = 1 | 2 | 3 | 4 | -1;
23
27
  * - `yearly`: no mesmo dia e mês da primeira data (29/2 só nos anos bissextos).
24
28
  */
25
29
  export interface RecurrenceRule {
26
- readonly frequency: RecurrenceFrequency;
30
+ readonly frequency: RecurrenceRuleFrequency;
27
31
  readonly interval?: number;
28
32
  readonly weekdays?: readonly Weekday[];
29
33
  readonly monthDay?: number;
@@ -32,9 +36,30 @@ export interface RecurrenceRule {
32
36
  readonly position: RecurrenceWeekPosition;
33
37
  };
34
38
  readonly count?: number | null;
39
+ /** Fim inclusivo (data). */
35
40
  readonly until?: IsoDate | null;
36
- /** Datas que a série pula (EXDATE). Contam para `count` como no RFC: a ocorrência existe, só não aparece. */
41
+ /**
42
+ * Fim em instante ISO (UNTIL com hora, em UTC, como manda a norma quando a série tem fuso): a última ocorrência é a
43
+ * que começa até esse instante. Com ele, vale no lugar de `until`.
44
+ */
45
+ readonly untilInstant?: string | null;
46
+ /**
47
+ * Datas que a série pula (EXDATE). Contam para `count` como no RFC: a ocorrência existe, só não aparece. Em série com
48
+ * hora, aceita também a hora de parede (`'2026-10-12T09:00'`) ou o instante (`'2026-10-12T12:00:00Z'`) da ocorrência.
49
+ */
37
50
  readonly exceptions?: readonly IsoDate[];
51
+ /** Vários meses (BYMONTH, 1–12). */
52
+ readonly months?: readonly number[];
53
+ /** Vários dias do mês (BYMONTHDAY; negativo conta do fim: -1 = último, -3 = antepenúltimo). */
54
+ readonly monthDays?: readonly number[];
55
+ /** BYDAY completo: dias da semana com a posição opcional no período (`{ weekday: 5, position: 5 }` = 5ª sexta). */
56
+ readonly byDay?: readonly RecurrenceByDay[];
57
+ /** Posição no conjunto do período (BYSETPOS): "último dia útil do mês" = dias seg–sex + `[-1]`. */
58
+ readonly setPositions?: readonly number[];
59
+ /** Horas do dia (BYHOUR, 0–23). */
60
+ readonly hours?: readonly number[];
61
+ /** Primeiro dia da semana da regra (WKST), que muda o resultado de semanal com intervalo > 1. */
62
+ readonly weekStart?: Weekday;
38
63
  }
39
64
  /** Teto de segurança da expansão (ocorrências por chamada). */
40
65
  export declare const RECURRENCE_MAX_OCCURRENCES = 1000;
@@ -60,12 +85,19 @@ export declare function nextOccurrences(start: IsoDate, rule: RecurrenceRule, fr
60
85
  }): IsoDate[];
61
86
  /** Regra → texto RRULE (`FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE;COUNT=10`). Exceções não entram (são EXDATE). */
62
87
  export declare function formatRRule(rule: RecurrenceRule): string;
63
- /** Texto RRULE (com ou sem o prefixo `RRULE:`) → regra. Sem `FREQ` reconhecida → `null`. */
88
+ /**
89
+ * Texto RRULE (com ou sem o prefixo `RRULE:`) → regra. Sem `FREQ` reconhecida → `null`. Lê as partes novas (BYMONTH,
90
+ * BYSETPOS, WKST...), mas não a frequência por hora: para ela (e o UNTIL em instante), `parseRecurrenceRule`.
91
+ */
64
92
  export declare function parseRRule(text: string | null | undefined): RecurrenceRule | null;
65
- /** Aceita a regra pronta ou o texto RRULE (o que vier do servidor). */
93
+ /** Leitura completa do texto RRULE: tudo do `parseRRule` mais `FREQ=HOURLY` e o UNTIL com hora em `untilInstant`. */
94
+ export declare function parseRecurrenceRule(text: string | null | undefined): RecurrenceRule | null;
95
+ /** Aceita a regra pronta ou o texto RRULE (o que vier do servidor), com a leitura completa. */
66
96
  export declare function toRecurrenceRule(value: RecurrenceRule | string | null | undefined): RecurrenceRule | null;
67
97
  /** Textos da descrição (seção `recurrence` do catálogo). */
68
98
  export interface RecurrenceDescriptionMessages {
99
+ /** Por hora (opcional; sem ele, a descrição usa o texto da diária). */
100
+ readonly hourly?: PluralMessage;
69
101
  readonly daily: PluralMessage;
70
102
  readonly weekly: PluralMessage;
71
103
  readonly monthly: PluralMessage;
@@ -96,4 +128,32 @@ export declare function recurrenceWeekdays(locale: string, firstDay?: Weekday):
96
128
  short: string;
97
129
  long: string;
98
130
  }[];
131
+ /** Um dia da semana do BYDAY, com a posição opcional no período (`2` = 2ª, `-1` = última, `5` = 5ª, `-2` = penúltima). */
132
+ export interface RecurrenceByDay {
133
+ readonly weekday: Weekday;
134
+ readonly position?: number;
135
+ }
136
+ /** Hora de parede de uma ocorrência (data + minutos desde a meia-noite). */
137
+ export interface RecurrenceWallTime {
138
+ readonly date: IsoDate;
139
+ readonly minutes: number;
140
+ }
141
+ /** A regra usa alguma parte além do subconjunto de sempre (vai pelo expansor completo)? */
142
+ export declare function isExtendedRecurrenceRule(rule: RecurrenceRule): boolean;
143
+ /**
144
+ * Ocorrências da série (hora de parede no fuso da série) que caem em `[range.start, range.end)`, pela regra completa
145
+ * do RFC 5545 para o tipo RECUR: frequência por hora, dia, semana, mês e ano; BYMONTH, BYMONTHDAY, BYDAY com posição,
146
+ * BYHOUR, BYSETPOS, WKST, INTERVAL, COUNT e UNTIL (data inclusiva ou instante, comparado pelo instante da ocorrência
147
+ * no fuso `timeZone`). `start` é sempre a 1ª ocorrência possível (o DTSTART); `count` conta desde ele e as exceções
148
+ * contam (a ocorrência existe, só não aparece). Teto de `max` ocorrências por chamada.
149
+ */
150
+ export declare function expandRecurrenceTimes(start: RecurrenceWallTime, rule: RecurrenceRule, range: {
151
+ readonly start: IsoDate;
152
+ readonly end: IsoDate;
153
+ }, options?: {
154
+ readonly weekStartsOn?: Weekday;
155
+ readonly max?: number;
156
+ /** Fuso da série, para o UNTIL em instante e as exceções em instante. */
157
+ readonly toInstant?: (wall: RecurrenceWallTime) => number;
158
+ }): RecurrenceWallTime[];
99
159
  export { weekdayOf as recurrenceWeekdayOf };
@@ -1,19 +1,21 @@
1
1
  /**
2
- * Recorrência de eventos, sem framework: um subconjunto simplificado do RRULE (RFC 5545) que cobre o que as
3
- * agendas corporativas pedem — diária, semanal (dias da semana), mensal (dia do mês ou "n-ésima segunda"),
4
- * anual, intervalo, fim por contagem ou por data e exceções. Tudo em **datas de calendário** (`IsoDate`), sem
5
- * fuso: a hora do evento é a mesma em cada ocorrência (hora de parede, como no `event-calendar.ts`).
2
+ * Recorrência de eventos, sem framework, pelo tipo RECUR do RFC 5545: o subconjunto de sempre (diária, semanal,
3
+ * mensal por dia ou "n-ésima segunda", anual, intervalo, contagem, data final, exceções), em **datas de calendário**,
4
+ * e a regra completa (`expandRecurrenceTimes`): frequência por hora, BYMONTH, BYMONTHDAY, BYDAY com posição (5ª,
5
+ * penúltima), BYHOUR, BYSETPOS ("último dia útil do mês"), WKST e UNTIL em instante. A hora do evento é hora de parede
6
+ * do fuso da série.
6
7
  *
7
- * Fica de fora, de propósito: `BYHOUR`/`BYMINUTE`/`BYSETPOS` genérico, `FREQ` abaixo de diária e vários
8
- * `BYMONTH`. Um RRULE com essas partes é lido só no que entende (o resto é ignorado), nunca quebra.
8
+ * Fica de fora, de propósito: frequência abaixo de hora (`MINUTELY`/`SECONDLY`), `BYMINUTE`/`BYSECOND`, `BYWEEKNO` e
9
+ * `BYYEARDAY`. Um RRULE com essas partes é lido só no que entende (o resto é ignorado), nunca quebra.
9
10
  */
10
11
  import { addDays, addMonths, daysInMonth, parseIso, toIso } from './date';
11
12
  import { formatMessage, pluralMessage } from './i18n';
12
13
  export const RECURRENCE_FREQUENCIES = ['daily', 'weekly', 'monthly', 'yearly'];
14
+ export const RECURRENCE_RULE_FREQUENCIES = ['hourly', ...RECURRENCE_FREQUENCIES];
13
15
  /** Teto de segurança da expansão (ocorrências por chamada). */
14
16
  export const RECURRENCE_MAX_OCCURRENCES = 1000;
15
17
  const RRULE_DAYS = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
16
- const FREQ_TO_RRULE = { daily: 'DAILY', weekly: 'WEEKLY', monthly: 'MONTHLY', yearly: 'YEARLY' };
18
+ const FREQ_TO_RRULE = { hourly: 'HOURLY', daily: 'DAILY', weekly: 'WEEKLY', monthly: 'MONTHLY', yearly: 'YEARLY' };
17
19
  function weekdayOf(iso) {
18
20
  const p = parseIso(iso);
19
21
  return (p ? new Date(Date.UTC(p.year, p.month, p.day)).getUTCDay() : 0);
@@ -38,6 +40,12 @@ export function weekPositionOf(iso) {
38
40
  return -1;
39
41
  return Math.min(4, Math.ceil(p.day / 7));
40
42
  }
43
+ /** Dias entre duas datas (`b - a`), pelas datas UTC (sem horário de verão). */
44
+ function dayGap(a, b) {
45
+ const pa = parseIso(a);
46
+ const pb = parseIso(b);
47
+ return pa && pb ? Math.round((Date.UTC(pb.year, pb.month, pb.day) - Date.UTC(pa.year, pa.month, pa.day)) / 86_400_000) : 0;
48
+ }
41
49
  const clampInterval = (value) => (Number.isFinite(value) && value >= 1 ? Math.floor(value) : 1);
42
50
  /**
43
51
  * Datas da série que caem em `[range.start, range.end)` (fim exclusivo), a partir da primeira data `start`
@@ -47,6 +55,10 @@ export function expandRecurrence(start, rule, range, options = {}) {
47
55
  const first = parseIso(start);
48
56
  if (!first)
49
57
  return [];
58
+ if (isExtendedRecurrenceRule(rule)) {
59
+ // Regra completa: as datas das ocorrências (sem repetir a data das várias horas do mesmo dia).
60
+ return [...new Set(expandRecurrenceTimes({ date: start, minutes: 0 }, rule, range, options).map((w) => w.date))];
61
+ }
50
62
  const interval = clampInterval(rule.interval);
51
63
  const count = rule.count && rule.count > 0 ? Math.floor(rule.count) : Infinity;
52
64
  const until = rule.until && parseIso(rule.until) ? rule.until : null;
@@ -70,7 +82,9 @@ export function expandRecurrence(start, rule, range, options = {}) {
70
82
  const periodCap = 20000;
71
83
  switch (rule.frequency) {
72
84
  case 'daily': {
73
- for (let k = 0, iso = start; k < periodCap; k++, iso = addDays(iso, interval))
85
+ // Sem contagem, a série pode começar direto perto do intervalo pedido (a contagem é a única que olha o começo).
86
+ const skip = count === Infinity && range.start > start ? Math.max(0, Math.floor(dayGap(start, range.start) / interval) - 1) : 0;
87
+ for (let k = skip, iso = addDays(start, skip * interval); k < periodCap; k++, iso = addDays(iso, interval))
74
88
  if (!take(iso))
75
89
  break;
76
90
  break;
@@ -80,7 +94,8 @@ export function expandRecurrence(start, rule, range, options = {}) {
80
94
  const days = (rule.weekdays?.length ? [...new Set(rule.weekdays)] : [weekdayOf(start)]).map((d) => ((d - weekStart + 7) % 7));
81
95
  days.sort((a, b) => a - b);
82
96
  const firstWeek = addDays(start, -((weekdayOf(start) - weekStart + 7) % 7));
83
- outer: for (let k = 0; k < periodCap; k++) {
97
+ const skipWeeks = count === Infinity && range.start > firstWeek ? Math.max(0, Math.floor(dayGap(firstWeek, range.start) / (7 * interval)) - 1) : 0;
98
+ outer: for (let k = skipWeeks; k < periodCap; k++) {
84
99
  const week = addDays(firstWeek, k * 7 * interval);
85
100
  if (week >= stop)
86
101
  break;
@@ -122,6 +137,9 @@ export function expandRecurrence(start, rule, range, options = {}) {
122
137
  }
123
138
  break;
124
139
  }
140
+ case 'hourly':
141
+ // Por hora é sempre regra completa (tratada acima).
142
+ break;
125
143
  }
126
144
  return out;
127
145
  }
@@ -146,22 +164,50 @@ export function formatRRule(rule) {
146
164
  const interval = clampInterval(rule.interval);
147
165
  if (interval > 1)
148
166
  parts.push(`INTERVAL=${interval}`);
149
- if (rule.frequency === 'weekly' && rule.weekdays?.length)
167
+ if (rule.months?.length)
168
+ parts.push(`BYMONTH=${rule.months.join(',')}`);
169
+ if (rule.byDay?.length)
170
+ parts.push(`BYDAY=${rule.byDay.map((b) => `${b.position ?? ''}${RRULE_DAYS[b.weekday]}`).join(',')}`);
171
+ else if (rule.weekdays?.length && (rule.frequency !== 'monthly' || rule.months?.length || rule.setPositions?.length || rule.monthDays?.length))
150
172
  parts.push(`BYDAY=${[...rule.weekdays].sort().map((d) => RRULE_DAYS[d]).join(',')}`);
151
- if (rule.frequency === 'monthly') {
173
+ if (rule.frequency === 'monthly' && !rule.byDay?.length) {
152
174
  if (rule.weekdayPosition)
153
175
  parts.push(`BYDAY=${rule.weekdayPosition.position}${RRULE_DAYS[rule.weekdayPosition.weekday]}`);
154
- else if (rule.monthDay)
176
+ else if (rule.monthDay && !rule.monthDays?.length)
155
177
  parts.push(`BYMONTHDAY=${rule.monthDay}`);
156
178
  }
179
+ if (rule.monthDays?.length)
180
+ parts.push(`BYMONTHDAY=${rule.monthDays.join(',')}`);
181
+ if (rule.hours?.length)
182
+ parts.push(`BYHOUR=${rule.hours.join(',')}`);
183
+ if (rule.setPositions?.length)
184
+ parts.push(`BYSETPOS=${rule.setPositions.join(',')}`);
185
+ if (rule.weekStart !== undefined)
186
+ parts.push(`WKST=${RRULE_DAYS[rule.weekStart]}`);
157
187
  if (rule.count && rule.count > 0)
158
188
  parts.push(`COUNT=${Math.floor(rule.count)}`);
189
+ else if ((rule.untilInstant || rule.until) && /T/.test(rule.untilInstant || rule.until || '')) {
190
+ const text = (rule.untilInstant || rule.until);
191
+ const ms = Date.parse(/[zZ]|[+-]\d{2}:?\d{2}$/.test(text) ? text : `${text}Z`);
192
+ if (!Number.isNaN(ms))
193
+ parts.push(`UNTIL=${new Date(ms).toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '')}`);
194
+ }
159
195
  else if (rule.until && parseIso(rule.until))
160
196
  parts.push(`UNTIL=${compactDate(rule.until)}`);
161
197
  return parts.join(';');
162
198
  }
163
- /** Texto RRULE (com ou sem o prefixo `RRULE:`) → regra. Sem `FREQ` reconhecida → `null`. */
199
+ /**
200
+ * Texto RRULE (com ou sem o prefixo `RRULE:`) → regra. Sem `FREQ` reconhecida → `null`. Lê as partes novas (BYMONTH,
201
+ * BYSETPOS, WKST...), mas não a frequência por hora: para ela (e o UNTIL em instante), `parseRecurrenceRule`.
202
+ */
164
203
  export function parseRRule(text) {
204
+ return readRRule(text, false);
205
+ }
206
+ /** Leitura completa do texto RRULE: tudo do `parseRRule` mais `FREQ=HOURLY` e o UNTIL com hora em `untilInstant`. */
207
+ export function parseRecurrenceRule(text) {
208
+ return readRRule(text, true);
209
+ }
210
+ function readRRule(text, full) {
165
211
  if (!text)
166
212
  return null;
167
213
  const body = text.trim().replace(/^RRULE:/i, '');
@@ -172,7 +218,7 @@ export function parseRRule(text) {
172
218
  map.set(key.trim().toUpperCase(), value.trim().toUpperCase());
173
219
  }
174
220
  const freq = Object.keys(FREQ_TO_RRULE).find((f) => FREQ_TO_RRULE[f] === map.get('FREQ'));
175
- if (!freq)
221
+ if (!freq || (freq === 'hourly' && !full))
176
222
  return null;
177
223
  const rule = { frequency: freq };
178
224
  const interval = Number(map.get('INTERVAL'));
@@ -181,33 +227,61 @@ export function parseRRule(text) {
181
227
  const count = Number(map.get('COUNT'));
182
228
  if (count > 0)
183
229
  rule.count = Math.floor(count);
184
- const until = /^(\d{4})(\d{2})(\d{2})/.exec(map.get('UNTIL') ?? '');
185
- if (until && !rule.count)
230
+ const until = /^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})(Z?))?/.exec(map.get('UNTIL') ?? '');
231
+ if (until && !rule.count) {
186
232
  rule.until = `${until[1]}-${until[2]}-${until[3]}`;
233
+ // Com hora: o instante exato vale para a regra completa (o `until` em data continua o de sempre).
234
+ if (until[4] && full)
235
+ rule.untilInstant = `${until[1]}-${until[2]}-${until[3]}T${until[4]}:${until[5]}:${until[6]}${until[7] ? 'Z' : ''}`;
236
+ }
187
237
  const byDay = (map.get('BYDAY') ?? '').split(',').filter(Boolean);
188
238
  if (byDay.length) {
189
239
  const parsed = byDay
190
240
  .map((token) => /^([+-]?\d)?(SU|MO|TU|WE|TH|FR|SA)$/.exec(token))
191
241
  .filter((m) => !!m)
192
242
  .map((m) => ({ position: m[1] ? Number(m[1]) : 0, weekday: RRULE_DAYS.indexOf(m[2]) }));
193
- if (freq === 'monthly' && parsed[0]?.position) {
243
+ const legacyPosition = parsed.length === 1 && [1, 2, 3, 4, -1].includes(parsed[0].position);
244
+ const extended = map.has('BYSETPOS') || map.has('BYMONTH') || map.has('BYMONTHDAY') || (freq !== 'weekly' && freq !== 'monthly');
245
+ if (freq === 'monthly' && parsed[0]?.position && legacyPosition && !extended) {
194
246
  const pos = parsed[0].position;
195
247
  rule.weekdayPosition = { weekday: parsed[0].weekday, position: (pos < 0 ? -1 : Math.min(pos, 4)) };
196
248
  }
197
- else if (freq === 'weekly') {
249
+ else if (freq === 'weekly' && parsed.every((p) => !p.position)) {
198
250
  rule.weekdays = parsed.map((p) => p.weekday);
199
251
  }
252
+ else {
253
+ rule.byDay = parsed.map((p) => (p.position ? { weekday: p.weekday, position: p.position } : { weekday: p.weekday }));
254
+ }
200
255
  }
201
- const monthDay = Number(map.get('BYMONTHDAY'));
202
- if (freq === 'monthly' && !rule.weekdayPosition && (monthDay === -1 || (monthDay >= 1 && monthDay <= 31)))
203
- rule.monthDay = monthDay;
256
+ const numbers = (key, min, max) => (map.get(key) ?? '')
257
+ .split(',')
258
+ .filter(Boolean)
259
+ .map(Number)
260
+ .filter((n) => Number.isInteger(n) && n !== 0 && Math.abs(n) >= min && Math.abs(n) <= max);
261
+ const monthDays = numbers('BYMONTHDAY', 1, 31);
262
+ if (freq === 'monthly' && !rule.weekdayPosition && !rule.byDay && monthDays.length === 1 && (monthDays[0] === -1 || monthDays[0] > 0))
263
+ rule.monthDay = monthDays[0];
264
+ else if (monthDays.length)
265
+ rule.monthDays = monthDays;
266
+ const months = numbers('BYMONTH', 1, 12).filter((n) => n > 0);
267
+ if (months.length)
268
+ rule.months = months;
269
+ const setPositions = numbers('BYSETPOS', 1, 366);
270
+ if (setPositions.length)
271
+ rule.setPositions = setPositions;
272
+ const hours = (map.get('BYHOUR') ?? '').split(',').filter(Boolean).map(Number).filter((n) => Number.isInteger(n) && n >= 0 && n <= 23);
273
+ if (hours.length)
274
+ rule.hours = hours;
275
+ const wkst = RRULE_DAYS.indexOf((map.get('WKST') ?? ''));
276
+ if (wkst >= 0)
277
+ rule.weekStart = wkst;
204
278
  return rule;
205
279
  }
206
- /** Aceita a regra pronta ou o texto RRULE (o que vier do servidor). */
280
+ /** Aceita a regra pronta ou o texto RRULE (o que vier do servidor), com a leitura completa. */
207
281
  export function toRecurrenceRule(value) {
208
282
  if (!value)
209
283
  return null;
210
- return typeof value === 'string' ? parseRRule(value) : value;
284
+ return typeof value === 'string' ? parseRecurrenceRule(value) : value;
211
285
  }
212
286
  const POSITION_KEYS = { 1: 'first', 2: 'second', 3: 'third', 4: 'fourth', [-1]: 'last' };
213
287
  function weekdayName(weekday, locale, style = 'long') {
@@ -228,7 +302,7 @@ function listOf(items, locale) {
228
302
  */
229
303
  export function describeRecurrence(rule, start, locale, text) {
230
304
  const interval = clampInterval(rule.interval);
231
- const parts = [pluralMessage(text[rule.frequency], interval, locale)];
305
+ const parts = [pluralMessage((rule.frequency === 'hourly' ? text.hourly : text[rule.frequency]) ?? text.daily, interval, locale)];
232
306
  const first = parseIso(start);
233
307
  if (rule.frequency === 'weekly') {
234
308
  const days = (rule.weekdays?.length ? [...new Set(rule.weekdays)] : [weekdayOf(start)]).sort((a, b) => a - b);
@@ -266,5 +340,270 @@ export function recurrenceWeekdays(locale, firstDay = 0) {
266
340
  return { weekday, short: weekdayName(weekday, locale, 'short').replace('.', ''), long: weekdayName(weekday, locale) };
267
341
  });
268
342
  }
343
+ const WEEKDAY_SET = new Set([0, 1, 2, 3, 4, 5, 6]);
344
+ /** A regra usa alguma parte além do subconjunto de sempre (vai pelo expansor completo)? */
345
+ export function isExtendedRecurrenceRule(rule) {
346
+ return (rule.frequency === 'hourly' ||
347
+ !!rule.months?.length ||
348
+ !!rule.monthDays?.length ||
349
+ !!rule.byDay?.length ||
350
+ !!rule.setPositions?.length ||
351
+ !!rule.hours?.length ||
352
+ rule.weekStart !== undefined ||
353
+ !!rule.untilInstant ||
354
+ (!!rule.until && /T/.test(rule.until)));
355
+ }
356
+ const pad2 = (n) => String(n).padStart(2, '0');
357
+ const wallKey = (w) => `${w.date}T${pad2(Math.floor(w.minutes / 60))}:${pad2(w.minutes % 60)}`;
358
+ const compareWall = (a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : a.minutes - b.minutes);
359
+ /** Datas do mês que casam com o BYDAY (posição relativa ao mês). */
360
+ function byDayInMonth(year, month, list) {
361
+ const total = daysInMonth(year, month);
362
+ const out = new Set();
363
+ for (const entry of list) {
364
+ const days = [];
365
+ for (let d = 1; d <= total; d++)
366
+ if (new Date(Date.UTC(year, month, d)).getUTCDay() === entry.weekday)
367
+ days.push(d);
368
+ if (!entry.position)
369
+ days.forEach((d) => out.add(d));
370
+ else {
371
+ const pick = entry.position > 0 ? days[entry.position - 1] : days[days.length + entry.position];
372
+ if (pick)
373
+ out.add(pick);
374
+ }
375
+ }
376
+ return [...out].sort((a, b) => a - b);
377
+ }
378
+ /** Datas do ano que casam com o BYDAY (posição relativa ao ano: `20MO` = 20ª segunda do ano). */
379
+ function byDayInYear(year, list) {
380
+ const out = new Set();
381
+ for (const entry of list) {
382
+ const days = [];
383
+ for (let m = 0; m < 12; m++) {
384
+ const total = daysInMonth(year, m);
385
+ for (let d = 1; d <= total; d++)
386
+ if (new Date(Date.UTC(year, m, d)).getUTCDay() === entry.weekday)
387
+ days.push(toIso(year, m, d));
388
+ }
389
+ if (!entry.position)
390
+ days.forEach((d) => out.add(d));
391
+ else {
392
+ const pick = entry.position > 0 ? days[entry.position - 1] : days[days.length + entry.position];
393
+ if (pick)
394
+ out.add(pick);
395
+ }
396
+ }
397
+ return [...out].sort();
398
+ }
399
+ /** BYMONTHDAY resolvido no mês (negativo conta do fim; dia que o mês não tem é descartado). */
400
+ function monthDaysIn(year, month, list) {
401
+ const total = daysInMonth(year, month);
402
+ const out = new Set();
403
+ for (const d of list) {
404
+ const day = d < 0 ? total + d + 1 : d;
405
+ if (day >= 1 && day <= total)
406
+ out.add(day);
407
+ }
408
+ return [...out].sort((a, b) => a - b);
409
+ }
410
+ /** Aplica BYSETPOS ao conjunto ordenado de um período. */
411
+ function applySetPositions(items, positions) {
412
+ if (!positions?.length)
413
+ return [...items];
414
+ const out = [];
415
+ for (const p of positions) {
416
+ const item = p > 0 ? items[p - 1] : items[items.length + p];
417
+ if (item !== undefined && !out.includes(item))
418
+ out.push(item);
419
+ }
420
+ return out;
421
+ }
422
+ /** Regra do subconjunto de sempre traduzida para as partes completas (para o expansor completo). */
423
+ function normalizedParts(rule) {
424
+ const byDay = [...(rule.byDay ?? [])];
425
+ if (!byDay.length && rule.weekdayPosition)
426
+ byDay.push({ weekday: rule.weekdayPosition.weekday, position: rule.weekdayPosition.position });
427
+ if (!byDay.length && rule.weekdays?.length && rule.frequency !== 'monthly' && rule.frequency !== 'yearly')
428
+ byDay.push(...rule.weekdays.map((weekday) => ({ weekday })));
429
+ if (!byDay.length && rule.weekdays?.length && (rule.frequency === 'monthly' || rule.frequency === 'yearly') && (rule.months?.length || rule.setPositions?.length || rule.monthDays?.length))
430
+ byDay.push(...rule.weekdays.map((weekday) => ({ weekday })));
431
+ const monthDays = rule.monthDays?.length ? [...rule.monthDays] : rule.monthDay !== undefined && !rule.weekdayPosition ? [rule.monthDay] : [];
432
+ return { byDay: byDay.filter((b) => WEEKDAY_SET.has(b.weekday)), monthDays, months: (rule.months ?? []).filter((m) => m >= 1 && m <= 12) };
433
+ }
434
+ /**
435
+ * Ocorrências da série (hora de parede no fuso da série) que caem em `[range.start, range.end)`, pela regra completa
436
+ * do RFC 5545 para o tipo RECUR: frequência por hora, dia, semana, mês e ano; BYMONTH, BYMONTHDAY, BYDAY com posição,
437
+ * BYHOUR, BYSETPOS, WKST, INTERVAL, COUNT e UNTIL (data inclusiva ou instante, comparado pelo instante da ocorrência
438
+ * no fuso `timeZone`). `start` é sempre a 1ª ocorrência possível (o DTSTART); `count` conta desde ele e as exceções
439
+ * contam (a ocorrência existe, só não aparece). Teto de `max` ocorrências por chamada.
440
+ */
441
+ export function expandRecurrenceTimes(start, rule, range, options = {}) {
442
+ const first = parseIso(start.date);
443
+ if (!first)
444
+ return [];
445
+ if (!isExtendedRecurrenceRule(rule)) {
446
+ return expandRecurrence(start.date, rule, range, options).map((date) => ({ date, minutes: start.minutes }));
447
+ }
448
+ const interval = clampInterval(rule.interval);
449
+ const count = rule.count && rule.count > 0 ? Math.floor(rule.count) : Infinity;
450
+ const max = options.max ?? RECURRENCE_MAX_OCCURRENCES;
451
+ const toInstant = options.toInstant ?? ((w) => Date.UTC(...isoParts(w.date)) + w.minutes * 60_000);
452
+ const untilText = rule.untilInstant || rule.until || null;
453
+ const untilInstant = untilText && /T/.test(untilText) ? Date.parse(/[zZ]|[+-]\d{2}:?\d{2}$/.test(untilText) ? untilText : `${untilText}Z`) : null;
454
+ const untilDate = untilText && !/T/.test(untilText) && parseIso(untilText) ? untilText : null;
455
+ const exceptions = (rule.exceptions ?? []).map((e) => String(e));
456
+ const excDates = new Set(exceptions.filter((e) => !/T/.test(e)));
457
+ const excWalls = new Set(exceptions.filter((e) => /T/.test(e) && !/[zZ]|[+-]\d{2}:?\d{2}$/.test(e)).map((e) => e.slice(0, 16)));
458
+ const excInstants = new Set(exceptions.filter((e) => /[zZ]|[+-]\d{2}:?\d{2}$/.test(e) && /T/.test(e)).map((e) => Date.parse(e)));
459
+ const { byDay, monthDays, months } = normalizedParts(rule);
460
+ const monthSet = new Set(months);
461
+ const weekdaysOnly = byDay.filter((b) => !b.position).map((b) => b.weekday);
462
+ const hours = (rule.hours ?? []).filter((h) => h >= 0 && h <= 23);
463
+ const timesOf = (minutes) => (hours.length ? [...new Set(hours)].sort((a, b) => a - b).map((h) => h * 60 + (minutes % 60)) : [minutes]);
464
+ const out = [];
465
+ let seen = 0;
466
+ let done = false;
467
+ /** Registra a candidata (em ordem); devolve `false` quando a série acabou. */
468
+ const take = (w) => {
469
+ if (compareWall(w, start) < 0)
470
+ return true;
471
+ if (seen >= count || out.length >= max)
472
+ return false;
473
+ if (untilDate && w.date > untilDate)
474
+ return false;
475
+ if (untilInstant !== null && toInstant(w) > untilInstant)
476
+ return false;
477
+ if (w.date >= range.end)
478
+ return false;
479
+ seen++;
480
+ const excluded = excDates.has(w.date) || excWalls.has(wallKey(w)) || (excInstants.size > 0 && excInstants.has(toInstant(w)));
481
+ if (w.date >= range.start && !excluded)
482
+ out.push(w);
483
+ return true;
484
+ };
485
+ const takeAll = (list) => {
486
+ for (const w of list.sort(compareWall)) {
487
+ if (!take(w)) {
488
+ done = true;
489
+ return;
490
+ }
491
+ }
492
+ };
493
+ const dayMatches = (iso) => {
494
+ const p = parseIso(iso);
495
+ if (monthSet.size && !monthSet.has(p.month + 1))
496
+ return false;
497
+ if (monthDays.length && !monthDaysIn(p.year, p.month, monthDays).includes(p.day))
498
+ return false;
499
+ if (weekdaysOnly.length && !weekdaysOnly.includes(new Date(Date.UTC(p.year, p.month, p.day)).getUTCDay()))
500
+ return false;
501
+ return true;
502
+ };
503
+ const periodCap = 200_000;
504
+ const pastEnd = (iso) => iso >= range.end || (untilDate !== null && iso > untilDate);
505
+ switch (rule.frequency) {
506
+ case 'hourly': {
507
+ const step = interval * 60;
508
+ for (let k = 0; k < periodCap && !done; k++) {
509
+ const total = start.minutes + k * step;
510
+ const days = Math.floor(total / 1440);
511
+ const w = { date: addDays(start.date, days), minutes: total - days * 1440 };
512
+ if (pastEnd(w.date))
513
+ break;
514
+ if (!dayMatches(w.date) || (hours.length && !hours.includes(Math.floor(w.minutes / 60))))
515
+ continue;
516
+ takeAll([w]);
517
+ }
518
+ break;
519
+ }
520
+ case 'daily': {
521
+ for (let k = 0; k < periodCap && !done; k++) {
522
+ const iso = addDays(start.date, k * interval);
523
+ if (pastEnd(iso))
524
+ break;
525
+ if (!dayMatches(iso))
526
+ continue;
527
+ takeAll(applySetPositions(timesOf(start.minutes).map((m) => ({ date: iso, minutes: m })), rule.setPositions));
528
+ }
529
+ break;
530
+ }
531
+ case 'weekly': {
532
+ const weekStart = rule.weekStart ?? options.weekStartsOn ?? 1;
533
+ const days = (weekdaysOnly.length ? [...new Set(weekdaysOnly)] : [weekdayOf(start.date)]).map((d) => (d - weekStart + 7) % 7).sort((a, b) => a - b);
534
+ const firstWeek = addDays(start.date, -((weekdayOf(start.date) - weekStart + 7) % 7));
535
+ for (let k = 0; k < periodCap && !done; k++) {
536
+ const week = addDays(firstWeek, k * 7 * interval);
537
+ if (pastEnd(week))
538
+ break;
539
+ const set = [];
540
+ for (const offset of days) {
541
+ const iso = addDays(week, offset);
542
+ const p = parseIso(iso);
543
+ if (monthSet.size && !monthSet.has(p.month + 1))
544
+ continue;
545
+ for (const m of timesOf(start.minutes))
546
+ set.push({ date: iso, minutes: m });
547
+ }
548
+ takeAll(applySetPositions(set.sort(compareWall), rule.setPositions));
549
+ }
550
+ break;
551
+ }
552
+ case 'monthly': {
553
+ for (let k = 0; k < periodCap && !done; k++) {
554
+ const month = addMonths(toIso(first.year, first.month, 1), k * interval);
555
+ if (pastEnd(month))
556
+ break;
557
+ const p = parseIso(month);
558
+ if (monthSet.size && !monthSet.has(p.month + 1))
559
+ continue;
560
+ takeAll(applySetPositions(monthCandidates(p.year, p.month, first.day, byDay, monthDays).flatMap((d) => timesOf(start.minutes).map((m) => ({ date: toIso(p.year, p.month, d), minutes: m }))), rule.setPositions));
561
+ }
562
+ break;
563
+ }
564
+ case 'yearly': {
565
+ for (let k = 0; k < periodCap && !done; k++) {
566
+ const year = first.year + k * interval;
567
+ if (pastEnd(toIso(year, 0, 1)))
568
+ break;
569
+ let dates;
570
+ if (months.length) {
571
+ dates = months
572
+ .slice()
573
+ .sort((a, b) => a - b)
574
+ .flatMap((m) => monthCandidates(year, m - 1, first.day, byDay, monthDays).map((d) => toIso(year, m - 1, d)));
575
+ }
576
+ else if (byDay.length && !monthDays.length) {
577
+ dates = byDayInYear(year, byDay);
578
+ }
579
+ else if (monthDays.length) {
580
+ dates = Array.from({ length: 12 }, (_, m) => monthCandidates(year, m, first.day, byDay, monthDays).map((d) => toIso(year, m, d))).flat();
581
+ }
582
+ else {
583
+ dates = first.day <= daysInMonth(year, first.month) ? [toIso(year, first.month, first.day)] : [];
584
+ }
585
+ takeAll(applySetPositions(dates.flatMap((iso) => timesOf(start.minutes).map((m) => ({ date: iso, minutes: m }))), rule.setPositions));
586
+ }
587
+ break;
588
+ }
589
+ }
590
+ return out;
591
+ }
592
+ /** Dias candidatos de um mês: BYMONTHDAY e/ou BYDAY (interseção quando os dois existem) ou o dia do DTSTART. */
593
+ function monthCandidates(year, month, defaultDay, byDay, monthDays, useDefault = true) {
594
+ const fromDays = monthDays.length ? monthDaysIn(year, month, monthDays) : null;
595
+ const fromWeek = byDay.length ? byDayInMonth(year, month, byDay) : null;
596
+ if (fromDays && fromWeek)
597
+ return fromDays.filter((d) => fromWeek.includes(d));
598
+ if (fromDays)
599
+ return fromDays;
600
+ if (fromWeek)
601
+ return fromWeek;
602
+ return useDefault && defaultDay <= daysInMonth(year, month) ? [defaultDay] : [];
603
+ }
604
+ function isoParts(iso) {
605
+ const p = parseIso(iso) ?? { year: 1970, month: 0, day: 1 };
606
+ return [p.year, p.month, p.day];
607
+ }
269
608
  export { weekdayOf as recurrenceWeekdayOf };
270
609
  //# sourceMappingURL=recurrence.js.map