@calchemy/date-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/dist/calendar-scroll.d.ts +2 -0
  3. package/dist/calendar-scroll.d.ts.map +1 -0
  4. package/dist/calendar-scroll.js +225 -0
  5. package/dist/calendar-scroll.js.map +1 -0
  6. package/dist/chunk-KI7GMSS3.js +451 -0
  7. package/dist/chunk-KI7GMSS3.js.map +1 -0
  8. package/dist/chunk-NGJGJXY4.js +34 -0
  9. package/dist/chunk-NGJGJXY4.js.map +1 -0
  10. package/dist/components/Calchemy.d.ts +50 -0
  11. package/dist/components/Calchemy.d.ts.map +1 -0
  12. package/dist/components/Calchemy.js +57 -0
  13. package/dist/components/Calchemy.js.map +1 -0
  14. package/dist/components/calendar/Calendar.d.ts +19 -0
  15. package/dist/components/calendar/Calendar.d.ts.map +1 -0
  16. package/dist/components/calendar/Calendar.js +218 -0
  17. package/dist/components/calendar/Calendar.js.map +1 -0
  18. package/dist/components/calendar/CalendarGrid.d.ts +12 -0
  19. package/dist/components/calendar/CalendarGrid.d.ts.map +1 -0
  20. package/dist/components/calendar/CalendarGrid.js +93 -0
  21. package/dist/components/calendar/CalendarGrid.js.map +1 -0
  22. package/dist/components/calendar/CalendarPeriod.d.ts +6 -0
  23. package/dist/components/calendar/CalendarPeriod.d.ts.map +1 -0
  24. package/dist/components/calendar/CalendarPeriod.js +42 -0
  25. package/dist/components/calendar/CalendarPeriod.js.map +1 -0
  26. package/dist/components/calendar/CalendarPeriodHeading.d.ts +4 -0
  27. package/dist/components/calendar/CalendarPeriodHeading.d.ts.map +1 -0
  28. package/dist/components/calendar/CalendarPeriodHeading.js +9 -0
  29. package/dist/components/calendar/CalendarPeriodHeading.js.map +1 -0
  30. package/dist/components/calendar/CalendarPeriodList.d.ts +6 -0
  31. package/dist/components/calendar/CalendarPeriodList.d.ts.map +1 -0
  32. package/dist/components/calendar/CalendarPeriodList.js +93 -0
  33. package/dist/components/calendar/CalendarPeriodList.js.map +1 -0
  34. package/dist/components/calendar/CalendarScroll.d.ts +8 -0
  35. package/dist/components/calendar/CalendarScroll.d.ts.map +1 -0
  36. package/dist/components/calendar/CalendarScroll.js +115 -0
  37. package/dist/components/calendar/CalendarScroll.js.map +1 -0
  38. package/dist/components/calendar/CalendarSelects.d.ts +12 -0
  39. package/dist/components/calendar/CalendarSelects.d.ts.map +1 -0
  40. package/dist/components/calendar/CalendarSelects.js +31 -0
  41. package/dist/components/calendar/CalendarSelects.js.map +1 -0
  42. package/dist/components/calendar/calendar-period-drag.d.ts +74 -0
  43. package/dist/components/calendar/calendar-period-drag.d.ts.map +1 -0
  44. package/dist/components/calendar/calendar-period-drag.js +374 -0
  45. package/dist/components/calendar/calendar-period-drag.js.map +1 -0
  46. package/dist/components/calendar/context.d.ts +10 -0
  47. package/dist/components/calendar/context.d.ts.map +1 -0
  48. package/dist/components/calendar/context.js +23 -0
  49. package/dist/components/calendar/context.js.map +1 -0
  50. package/dist/components/calendar/date-model.d.ts +36 -0
  51. package/dist/components/calendar/date-model.d.ts.map +1 -0
  52. package/dist/components/calendar/date-model.js +257 -0
  53. package/dist/components/calendar/date-model.js.map +1 -0
  54. package/dist/components/calendar/scroll-preload.d.ts +10 -0
  55. package/dist/components/calendar/scroll-preload.d.ts.map +1 -0
  56. package/dist/components/calendar/scroll-preload.js +80 -0
  57. package/dist/components/calendar/scroll-preload.js.map +1 -0
  58. package/dist/components/calendar/types.d.ts +68 -0
  59. package/dist/components/calendar/types.d.ts.map +1 -0
  60. package/dist/components/calendar/types.js +2 -0
  61. package/dist/components/calendar/types.js.map +1 -0
  62. package/dist/hooks/useCalchemy.d.ts +52 -0
  63. package/dist/hooks/useCalchemy.d.ts.map +1 -0
  64. package/dist/hooks/useCalchemy.js +161 -0
  65. package/dist/hooks/useCalchemy.js.map +1 -0
  66. package/dist/hooks/useDebouncedValue.d.ts +3 -0
  67. package/dist/hooks/useDebouncedValue.d.ts.map +1 -0
  68. package/dist/hooks/useDebouncedValue.js +15 -0
  69. package/dist/hooks/useDebouncedValue.js.map +1 -0
  70. package/dist/index.d.ts +6 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +3 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/inline-completion.d.ts +4 -0
  75. package/dist/inline-completion.d.ts.map +1 -0
  76. package/dist/inline-completion.js +7 -0
  77. package/dist/inline-completion.js.map +1 -0
  78. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kartik Iyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export { CalendarScroll, type CalchemyCalendarScrollProps, } from "./components/calendar/CalendarScroll";
2
+ //# sourceMappingURL=calendar-scroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calendar-scroll.d.ts","sourceRoot":"","sources":["../src/calendar-scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,2BAA2B,GACjC,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,225 @@
1
+ import {
2
+ CalendarScrollContext,
3
+ useCalchemyCalendar
4
+ } from "./chunk-NGJGJXY4.js";
5
+
6
+ // src/components/calendar/CalendarScroll.tsx
7
+ import { useLayoutEffect, useRef, useState } from "react";
8
+ import { flushSync } from "react-dom";
9
+
10
+ // src/components/calendar/scroll-preload.ts
11
+ function getScrollPosition(element, direction) {
12
+ return direction === "horizontal" ? element.scrollLeft : element.scrollTop;
13
+ }
14
+ function setScrollPosition(element, direction, value) {
15
+ if (direction === "horizontal") {
16
+ element.scrollLeft = value;
17
+ return;
18
+ }
19
+ element.scrollTop = value;
20
+ }
21
+ function getScrollSize(element, direction) {
22
+ return direction === "horizontal" ? element.scrollWidth : element.scrollHeight;
23
+ }
24
+ function getClientSize(element, direction) {
25
+ return direction === "horizontal" ? element.clientWidth : element.clientHeight;
26
+ }
27
+ function scrollPeriodIntoView(scrollElement, period, direction) {
28
+ const scrollRect = scrollElement.getBoundingClientRect();
29
+ const periodRect = period.getBoundingClientRect();
30
+ if (direction === "horizontal") {
31
+ scrollElement.scrollLeft += periodRect.left - scrollRect.left;
32
+ return;
33
+ }
34
+ scrollElement.scrollTop += periodRect.top - scrollRect.top;
35
+ }
36
+ function getScrollAnchorPeriod(scrollElement, direction) {
37
+ const scrollRect = scrollElement.getBoundingClientRect();
38
+ const periods = Array.from(scrollElement.querySelectorAll("[calchemy-period]"));
39
+ let fallback = null;
40
+ for (const period of periods) {
41
+ const periodRect = period.getBoundingClientRect();
42
+ const periodStart = direction === "horizontal" ? periodRect.left : periodRect.top;
43
+ const periodEnd = direction === "horizontal" ? periodRect.right : periodRect.bottom;
44
+ const scrollStart = direction === "horizontal" ? scrollRect.left : scrollRect.top;
45
+ const scrollEnd = direction === "horizontal" ? scrollRect.right : scrollRect.bottom;
46
+ if (periodEnd <= scrollStart) {
47
+ continue;
48
+ }
49
+ if (periodStart >= scrollEnd) {
50
+ break;
51
+ }
52
+ fallback = period;
53
+ if (periodStart >= scrollStart) {
54
+ return period;
55
+ }
56
+ }
57
+ return fallback;
58
+ }
59
+ function getCalendarPeriodWindowSize(scrollElement, direction, periodCount) {
60
+ const periods = Array.from(scrollElement.querySelectorAll("[calchemy-period]"));
61
+ const firstPeriod = periods[0];
62
+ const nextPeriod = periods[1];
63
+ const fallback = direction === "horizontal" ? scrollElement.clientWidth : scrollElement.clientHeight;
64
+ if (!firstPeriod) {
65
+ return fallback;
66
+ }
67
+ const firstRect = firstPeriod.getBoundingClientRect();
68
+ const nextRect = nextPeriod?.getBoundingClientRect();
69
+ const singlePeriodSize = nextRect ? direction === "horizontal" ? nextRect.left - firstRect.left : nextRect.top - firstRect.top : direction === "horizontal" ? firstRect.width : firstRect.height;
70
+ const windowSize = Math.abs(singlePeriodSize) * periodCount;
71
+ return windowSize > 0 ? windowSize : fallback;
72
+ }
73
+ function getLoadedPeriodRunway(calendar, anchor, direction) {
74
+ const anchorIndex = anchor?.getAttribute("calchemy-period-index") ? Number(anchor.getAttribute("calchemy-period-index")) : NaN;
75
+ const firstIndex = calendar.periods[0]?.index;
76
+ const lastIndex = calendar.periods.at(-1)?.index;
77
+ if (!Number.isFinite(anchorIndex) || firstIndex === void 0 || lastIndex === void 0) {
78
+ return null;
79
+ }
80
+ return direction === "before" ? anchorIndex - firstIndex : lastIndex - anchorIndex;
81
+ }
82
+
83
+ // src/components/calendar/CalendarScroll.tsx
84
+ import { jsx } from "react/jsx-runtime";
85
+ var preloadWindowCount = 2;
86
+ function CalendarScroll({
87
+ direction = "vertical",
88
+ onScroll,
89
+ ...props
90
+ }) {
91
+ const calendar = useCalchemyCalendar();
92
+ const scrollRef = useRef(null);
93
+ const [leadingSpacer, setLeadingSpacer] = useState({
94
+ periodCount: 0,
95
+ pixelSize: 0
96
+ });
97
+ const positionedPeriodAnchor = useRef(null);
98
+ const suppressPreloadEvaluation = useRef(false);
99
+ const pendingPrependStabilization = useRef(null);
100
+ useLayoutEffect(() => {
101
+ const anchorKey = calendar.periodAnchor.toString();
102
+ if (positionedPeriodAnchor.current === anchorKey) {
103
+ return;
104
+ }
105
+ const element = scrollRef.current;
106
+ const currentPeriod = element?.querySelector(
107
+ "[calchemy-period][calchemy-period-index='0']"
108
+ );
109
+ if (!element || !currentPeriod) {
110
+ return;
111
+ }
112
+ positionedPeriodAnchor.current = anchorKey;
113
+ scrollPeriodIntoView(element, currentPeriod, direction);
114
+ }, [direction, calendar.periodAnchor, calendar.periods]);
115
+ function startBeforePreloadTransaction(element, preloadDirection, periodWindowSize) {
116
+ suppressPreloadEvaluation.current = true;
117
+ const extendPeriodCount = calendar.period.count * preloadWindowCount;
118
+ const previousScrollSize = getScrollSize(element, preloadDirection);
119
+ const previousScrollPosition = getScrollPosition(element, preloadDirection);
120
+ flushSync(() => {
121
+ setLeadingSpacer({
122
+ periodCount: extendPeriodCount,
123
+ pixelSize: periodWindowSize * preloadWindowCount
124
+ });
125
+ });
126
+ setScrollPosition(
127
+ element,
128
+ preloadDirection,
129
+ previousScrollPosition + getScrollSize(element, preloadDirection) - previousScrollSize
130
+ );
131
+ flushSync(() => {
132
+ calendar.extendPeriods("before", preloadWindowCount);
133
+ setLeadingSpacer({ periodCount: 0, pixelSize: 0 });
134
+ });
135
+ const insertedDelta = getScrollSize(element, preloadDirection) - previousScrollSize;
136
+ const targetPosition = previousScrollPosition + insertedDelta;
137
+ setScrollPosition(element, preloadDirection, targetPosition);
138
+ pendingPrependStabilization.current = {
139
+ direction: preloadDirection,
140
+ insertedDelta,
141
+ targetPosition
142
+ };
143
+ }
144
+ function stabilizePrependScrollEvent(element) {
145
+ const stabilization = pendingPrependStabilization.current;
146
+ if (!stabilization) {
147
+ suppressPreloadEvaluation.current = false;
148
+ return;
149
+ }
150
+ const observedPosition = getScrollPosition(
151
+ element,
152
+ stabilization.direction
153
+ );
154
+ const targetDistance = observedPosition - stabilization.targetPosition;
155
+ const staleCoordinate = Math.abs(
156
+ observedPosition + stabilization.insertedDelta - stabilization.targetPosition
157
+ ) < Math.abs(targetDistance);
158
+ if (staleCoordinate) {
159
+ setScrollPosition(
160
+ element,
161
+ stabilization.direction,
162
+ observedPosition + stabilization.insertedDelta
163
+ );
164
+ }
165
+ pendingPrependStabilization.current = null;
166
+ suppressPreloadEvaluation.current = false;
167
+ }
168
+ function handleScroll(event) {
169
+ onScroll?.(event);
170
+ if (event.defaultPrevented) {
171
+ return;
172
+ }
173
+ const element = event.currentTarget;
174
+ if (suppressPreloadEvaluation.current) {
175
+ stabilizePrependScrollEvent(element);
176
+ return;
177
+ }
178
+ if (getScrollSize(element, direction) <= getClientSize(element, direction)) {
179
+ return;
180
+ }
181
+ const anchor = getScrollAnchorPeriod(element, direction);
182
+ const anchorIndex = anchor?.getAttribute("calchemy-period-index") ? Number(anchor.getAttribute("calchemy-period-index")) : NaN;
183
+ if (Number.isFinite(anchorIndex)) {
184
+ calendar.setVisiblePeriodIndex(anchorIndex);
185
+ }
186
+ const periodWindowSize = getCalendarPeriodWindowSize(
187
+ element,
188
+ direction,
189
+ calendar.period.count
190
+ );
191
+ const startRunway = getLoadedPeriodRunway(calendar, anchor, "before");
192
+ const runwayThreshold = calendar.period.count * preloadWindowCount;
193
+ const endRunway = getLoadedPeriodRunway(calendar, anchor, "after");
194
+ if (startRunway !== null && startRunway <= runwayThreshold && calendar.canExtendPeriods("before", preloadWindowCount)) {
195
+ startBeforePreloadTransaction(element, direction, periodWindowSize);
196
+ }
197
+ if (endRunway !== null && endRunway <= runwayThreshold && calendar.canExtendPeriods("after", preloadWindowCount)) {
198
+ calendar.extendPeriods("after", preloadWindowCount);
199
+ }
200
+ }
201
+ return /* @__PURE__ */ jsx(
202
+ CalendarScrollContext.Provider,
203
+ {
204
+ value: {
205
+ direction,
206
+ leadingSpacerPeriodCount: leadingSpacer.periodCount,
207
+ leadingSpacerPixelSize: leadingSpacer.pixelSize
208
+ },
209
+ children: /* @__PURE__ */ jsx(
210
+ "div",
211
+ {
212
+ ...props,
213
+ ref: scrollRef,
214
+ "calchemy-scroll": "",
215
+ "calchemy-direction": direction,
216
+ onScroll: handleScroll
217
+ }
218
+ )
219
+ }
220
+ );
221
+ }
222
+ export {
223
+ CalendarScroll
224
+ };
225
+ //# sourceMappingURL=calendar-scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/calendar/CalendarScroll.tsx","../src/components/calendar/scroll-preload.ts"],"sourcesContent":["import { useLayoutEffect, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, UIEvent } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { CalendarScrollContext, useCalchemyCalendar } from \"./context\";\nimport {\n getCalendarPeriodWindowSize,\n getClientSize,\n getLoadedPeriodRunway,\n getScrollAnchorPeriod,\n getScrollPosition,\n getScrollSize,\n scrollPeriodIntoView,\n setScrollPosition,\n} from \"./scroll-preload\";\nimport type { CalendarScrollDirection } from \"./types\";\n\nconst preloadWindowCount = 2;\n\nexport type CalchemyCalendarScrollProps = Omit<\n ComponentPropsWithoutRef<\"div\">,\n \"onScroll\"\n> & {\n direction?: CalendarScrollDirection;\n onScroll?: ComponentPropsWithoutRef<\"div\">[\"onScroll\"];\n};\n\nexport function CalendarScroll({\n direction = \"vertical\",\n onScroll,\n ...props\n}: CalchemyCalendarScrollProps) {\n const calendar = useCalchemyCalendar();\n const scrollRef = useRef<HTMLDivElement | null>(null);\n const [leadingSpacer, setLeadingSpacer] = useState({\n periodCount: 0,\n pixelSize: 0,\n });\n const positionedPeriodAnchor = useRef<string | null>(null);\n const suppressPreloadEvaluation = useRef(false);\n const pendingPrependStabilization = useRef<{\n direction: CalendarScrollDirection;\n insertedDelta: number;\n targetPosition: number;\n } | null>(null);\n\n useLayoutEffect(() => {\n const anchorKey = calendar.periodAnchor.toString();\n if (positionedPeriodAnchor.current === anchorKey) {\n return;\n }\n\n const element = scrollRef.current;\n const currentPeriod = element?.querySelector<HTMLElement>(\n \"[calchemy-period][calchemy-period-index='0']\",\n );\n if (!element || !currentPeriod) {\n return;\n }\n\n positionedPeriodAnchor.current = anchorKey;\n scrollPeriodIntoView(element, currentPeriod, direction);\n }, [direction, calendar.periodAnchor, calendar.periods]);\n\n function startBeforePreloadTransaction(\n element: HTMLDivElement,\n preloadDirection: CalendarScrollDirection,\n periodWindowSize: number,\n ) {\n suppressPreloadEvaluation.current = true;\n const extendPeriodCount = calendar.period.count * preloadWindowCount;\n const previousScrollSize = getScrollSize(element, preloadDirection);\n const previousScrollPosition = getScrollPosition(element, preloadDirection);\n\n flushSync(() => {\n setLeadingSpacer({\n periodCount: extendPeriodCount,\n pixelSize: periodWindowSize * preloadWindowCount,\n });\n });\n\n setScrollPosition(\n element,\n preloadDirection,\n previousScrollPosition +\n getScrollSize(element, preloadDirection) -\n previousScrollSize,\n );\n\n flushSync(() => {\n calendar.extendPeriods(\"before\", preloadWindowCount);\n setLeadingSpacer({ periodCount: 0, pixelSize: 0 });\n });\n\n const insertedDelta =\n getScrollSize(element, preloadDirection) - previousScrollSize;\n const targetPosition = previousScrollPosition + insertedDelta;\n setScrollPosition(element, preloadDirection, targetPosition);\n pendingPrependStabilization.current = {\n direction: preloadDirection,\n insertedDelta,\n targetPosition,\n };\n }\n\n function stabilizePrependScrollEvent(element: HTMLDivElement) {\n const stabilization = pendingPrependStabilization.current;\n if (!stabilization) {\n suppressPreloadEvaluation.current = false;\n return;\n }\n\n const observedPosition = getScrollPosition(\n element,\n stabilization.direction,\n );\n const targetDistance = observedPosition - stabilization.targetPosition;\n const staleCoordinate =\n Math.abs(\n observedPosition +\n stabilization.insertedDelta -\n stabilization.targetPosition,\n ) < Math.abs(targetDistance);\n\n if (staleCoordinate) {\n setScrollPosition(\n element,\n stabilization.direction,\n observedPosition + stabilization.insertedDelta,\n );\n }\n\n pendingPrependStabilization.current = null;\n suppressPreloadEvaluation.current = false;\n }\n\n function handleScroll(event: UIEvent<HTMLDivElement>) {\n onScroll?.(event);\n if (event.defaultPrevented) {\n return;\n }\n\n const element = event.currentTarget;\n if (suppressPreloadEvaluation.current) {\n stabilizePrependScrollEvent(element);\n return;\n }\n\n if (\n getScrollSize(element, direction) <= getClientSize(element, direction)\n ) {\n return;\n }\n\n const anchor = getScrollAnchorPeriod(element, direction);\n const anchorIndex = anchor?.getAttribute(\"calchemy-period-index\")\n ? Number(anchor.getAttribute(\"calchemy-period-index\"))\n : NaN;\n if (Number.isFinite(anchorIndex)) {\n calendar.setVisiblePeriodIndex(anchorIndex);\n }\n\n const periodWindowSize = getCalendarPeriodWindowSize(\n element,\n direction,\n calendar.period.count,\n );\n const startRunway = getLoadedPeriodRunway(calendar, anchor, \"before\");\n const runwayThreshold = calendar.period.count * preloadWindowCount;\n const endRunway = getLoadedPeriodRunway(calendar, anchor, \"after\");\n if (\n startRunway !== null &&\n startRunway <= runwayThreshold &&\n calendar.canExtendPeriods(\"before\", preloadWindowCount)\n ) {\n startBeforePreloadTransaction(element, direction, periodWindowSize);\n }\n if (\n endRunway !== null &&\n endRunway <= runwayThreshold &&\n calendar.canExtendPeriods(\"after\", preloadWindowCount)\n ) {\n calendar.extendPeriods(\"after\", preloadWindowCount);\n }\n }\n\n return (\n <CalendarScrollContext.Provider\n value={{\n direction,\n leadingSpacerPeriodCount: leadingSpacer.periodCount,\n leadingSpacerPixelSize: leadingSpacer.pixelSize,\n }}\n >\n <div\n {...props}\n ref={scrollRef}\n calchemy-scroll=\"\"\n calchemy-direction={direction}\n onScroll={handleScroll}\n />\n </CalendarScrollContext.Provider>\n );\n}\n","import type { CalendarScrollDirection, CalendarState } from \"./types\";\n\nexport function getScrollPosition(element: HTMLElement, direction: CalendarScrollDirection): number {\n return direction === \"horizontal\" ? element.scrollLeft : element.scrollTop;\n}\n\nexport function setScrollPosition(\n element: HTMLElement,\n direction: CalendarScrollDirection,\n value: number,\n): void {\n if (direction === \"horizontal\") {\n element.scrollLeft = value;\n return;\n }\n\n element.scrollTop = value;\n}\n\nexport function getScrollSize(element: HTMLElement, direction: CalendarScrollDirection): number {\n return direction === \"horizontal\" ? element.scrollWidth : element.scrollHeight;\n}\n\nexport function getClientSize(element: HTMLElement, direction: CalendarScrollDirection): number {\n return direction === \"horizontal\" ? element.clientWidth : element.clientHeight;\n}\n\nexport function scrollPeriodIntoView(\n scrollElement: HTMLElement,\n period: HTMLElement,\n direction: CalendarScrollDirection,\n): void {\n const scrollRect = scrollElement.getBoundingClientRect();\n const periodRect = period.getBoundingClientRect();\n\n if (direction === \"horizontal\") {\n scrollElement.scrollLeft += periodRect.left - scrollRect.left;\n return;\n }\n\n scrollElement.scrollTop += periodRect.top - scrollRect.top;\n}\n\nexport function getScrollAnchorPeriod(\n scrollElement: HTMLElement,\n direction: CalendarScrollDirection,\n): HTMLElement | null {\n const scrollRect = scrollElement.getBoundingClientRect();\n const periods = Array.from(scrollElement.querySelectorAll<HTMLElement>(\"[calchemy-period]\"));\n let fallback: HTMLElement | null = null;\n\n for (const period of periods) {\n const periodRect = period.getBoundingClientRect();\n const periodStart = direction === \"horizontal\" ? periodRect.left : periodRect.top;\n const periodEnd = direction === \"horizontal\" ? periodRect.right : periodRect.bottom;\n const scrollStart = direction === \"horizontal\" ? scrollRect.left : scrollRect.top;\n const scrollEnd = direction === \"horizontal\" ? scrollRect.right : scrollRect.bottom;\n\n if (periodEnd <= scrollStart) {\n continue;\n }\n if (periodStart >= scrollEnd) {\n break;\n }\n\n fallback = period;\n if (periodStart >= scrollStart) {\n return period;\n }\n }\n\n return fallback;\n}\n\nexport function getCalendarPeriodWindowSize(\n scrollElement: HTMLElement,\n direction: CalendarScrollDirection,\n periodCount: number,\n): number {\n const periods = Array.from(scrollElement.querySelectorAll<HTMLElement>(\"[calchemy-period]\"));\n const firstPeriod = periods[0];\n const nextPeriod = periods[1];\n const fallback = direction === \"horizontal\" ? scrollElement.clientWidth : scrollElement.clientHeight;\n\n if (!firstPeriod) {\n return fallback;\n }\n\n const firstRect = firstPeriod.getBoundingClientRect();\n const nextRect = nextPeriod?.getBoundingClientRect();\n const singlePeriodSize = nextRect\n ? direction === \"horizontal\"\n ? nextRect.left - firstRect.left\n : nextRect.top - firstRect.top\n : direction === \"horizontal\"\n ? firstRect.width\n : firstRect.height;\n const windowSize = Math.abs(singlePeriodSize) * periodCount;\n\n return windowSize > 0 ? windowSize : fallback;\n}\n\nexport function getLoadedPeriodRunway(\n calendar: CalendarState,\n anchor: HTMLElement | null,\n direction: \"before\" | \"after\",\n): number | null {\n const anchorIndex = anchor?.getAttribute(\"calchemy-period-index\")\n ? Number(anchor.getAttribute(\"calchemy-period-index\"))\n : NaN;\n const firstIndex = calendar.periods[0]?.index;\n const lastIndex = calendar.periods.at(-1)?.index;\n\n if (!Number.isFinite(anchorIndex) || firstIndex === undefined || lastIndex === undefined) {\n return null;\n }\n\n return direction === \"before\" ? anchorIndex - firstIndex : lastIndex - anchorIndex;\n}\n"],"mappings":";;;;;;AAAA,SAAS,iBAAiB,QAAQ,gBAAgB;AAElD,SAAS,iBAAiB;;;ACAnB,SAAS,kBAAkB,SAAsB,WAA4C;AAClG,SAAO,cAAc,eAAe,QAAQ,aAAa,QAAQ;AACnE;AAEO,SAAS,kBACd,SACA,WACA,OACM;AACN,MAAI,cAAc,cAAc;AAC9B,YAAQ,aAAa;AACrB;AAAA,EACF;AAEA,UAAQ,YAAY;AACtB;AAEO,SAAS,cAAc,SAAsB,WAA4C;AAC9F,SAAO,cAAc,eAAe,QAAQ,cAAc,QAAQ;AACpE;AAEO,SAAS,cAAc,SAAsB,WAA4C;AAC9F,SAAO,cAAc,eAAe,QAAQ,cAAc,QAAQ;AACpE;AAEO,SAAS,qBACd,eACA,QACA,WACM;AACN,QAAM,aAAa,cAAc,sBAAsB;AACvD,QAAM,aAAa,OAAO,sBAAsB;AAEhD,MAAI,cAAc,cAAc;AAC9B,kBAAc,cAAc,WAAW,OAAO,WAAW;AACzD;AAAA,EACF;AAEA,gBAAc,aAAa,WAAW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