@calchemy/date-react 0.1.0 → 0.1.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.
- package/dist/calendar-scroll.cjs +261 -0
- package/dist/calendar-scroll.cjs.map +1 -0
- package/dist/index.cjs +1719 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +1681 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/calendar-scroll.ts
|
|
21
|
+
var calendar_scroll_exports = {};
|
|
22
|
+
__export(calendar_scroll_exports, {
|
|
23
|
+
CalendarScroll: () => CalendarScroll
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(calendar_scroll_exports);
|
|
26
|
+
|
|
27
|
+
// src/components/calendar/CalendarScroll.tsx
|
|
28
|
+
var import_react2 = require("react");
|
|
29
|
+
var import_react_dom = require("react-dom");
|
|
30
|
+
|
|
31
|
+
// src/components/calendar/context.ts
|
|
32
|
+
var import_react = require("react");
|
|
33
|
+
var CalchemyContext = (0, import_react.createContext)(null);
|
|
34
|
+
var CalendarContext = (0, import_react.createContext)(null);
|
|
35
|
+
var CalendarPeriodContext = (0, import_react.createContext)(null);
|
|
36
|
+
var CalendarScrollContext = (0, import_react.createContext)(null);
|
|
37
|
+
function useCalchemyCalendar() {
|
|
38
|
+
const state = (0, import_react.useContext)(CalendarContext);
|
|
39
|
+
if (!state) {
|
|
40
|
+
throw new Error("Calchemy calendar components must be rendered inside Calchemy.Calendar.");
|
|
41
|
+
}
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/components/calendar/scroll-preload.ts
|
|
46
|
+
function getScrollPosition(element, direction) {
|
|
47
|
+
return direction === "horizontal" ? element.scrollLeft : element.scrollTop;
|
|
48
|
+
}
|
|
49
|
+
function setScrollPosition(element, direction, value) {
|
|
50
|
+
if (direction === "horizontal") {
|
|
51
|
+
element.scrollLeft = value;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
element.scrollTop = value;
|
|
55
|
+
}
|
|
56
|
+
function getScrollSize(element, direction) {
|
|
57
|
+
return direction === "horizontal" ? element.scrollWidth : element.scrollHeight;
|
|
58
|
+
}
|
|
59
|
+
function getClientSize(element, direction) {
|
|
60
|
+
return direction === "horizontal" ? element.clientWidth : element.clientHeight;
|
|
61
|
+
}
|
|
62
|
+
function scrollPeriodIntoView(scrollElement, period, direction) {
|
|
63
|
+
const scrollRect = scrollElement.getBoundingClientRect();
|
|
64
|
+
const periodRect = period.getBoundingClientRect();
|
|
65
|
+
if (direction === "horizontal") {
|
|
66
|
+
scrollElement.scrollLeft += periodRect.left - scrollRect.left;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
scrollElement.scrollTop += periodRect.top - scrollRect.top;
|
|
70
|
+
}
|
|
71
|
+
function getScrollAnchorPeriod(scrollElement, direction) {
|
|
72
|
+
const scrollRect = scrollElement.getBoundingClientRect();
|
|
73
|
+
const periods = Array.from(scrollElement.querySelectorAll("[calchemy-period]"));
|
|
74
|
+
let fallback = null;
|
|
75
|
+
for (const period of periods) {
|
|
76
|
+
const periodRect = period.getBoundingClientRect();
|
|
77
|
+
const periodStart = direction === "horizontal" ? periodRect.left : periodRect.top;
|
|
78
|
+
const periodEnd = direction === "horizontal" ? periodRect.right : periodRect.bottom;
|
|
79
|
+
const scrollStart = direction === "horizontal" ? scrollRect.left : scrollRect.top;
|
|
80
|
+
const scrollEnd = direction === "horizontal" ? scrollRect.right : scrollRect.bottom;
|
|
81
|
+
if (periodEnd <= scrollStart) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (periodStart >= scrollEnd) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
fallback = period;
|
|
88
|
+
if (periodStart >= scrollStart) {
|
|
89
|
+
return period;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return fallback;
|
|
93
|
+
}
|
|
94
|
+
function getCalendarPeriodWindowSize(scrollElement, direction, periodCount) {
|
|
95
|
+
const periods = Array.from(scrollElement.querySelectorAll("[calchemy-period]"));
|
|
96
|
+
const firstPeriod = periods[0];
|
|
97
|
+
const nextPeriod = periods[1];
|
|
98
|
+
const fallback = direction === "horizontal" ? scrollElement.clientWidth : scrollElement.clientHeight;
|
|
99
|
+
if (!firstPeriod) {
|
|
100
|
+
return fallback;
|
|
101
|
+
}
|
|
102
|
+
const firstRect = firstPeriod.getBoundingClientRect();
|
|
103
|
+
const nextRect = nextPeriod?.getBoundingClientRect();
|
|
104
|
+
const singlePeriodSize = nextRect ? direction === "horizontal" ? nextRect.left - firstRect.left : nextRect.top - firstRect.top : direction === "horizontal" ? firstRect.width : firstRect.height;
|
|
105
|
+
const windowSize = Math.abs(singlePeriodSize) * periodCount;
|
|
106
|
+
return windowSize > 0 ? windowSize : fallback;
|
|
107
|
+
}
|
|
108
|
+
function getLoadedPeriodRunway(calendar, anchor, direction) {
|
|
109
|
+
const anchorIndex = anchor?.getAttribute("calchemy-period-index") ? Number(anchor.getAttribute("calchemy-period-index")) : NaN;
|
|
110
|
+
const firstIndex = calendar.periods[0]?.index;
|
|
111
|
+
const lastIndex = calendar.periods.at(-1)?.index;
|
|
112
|
+
if (!Number.isFinite(anchorIndex) || firstIndex === void 0 || lastIndex === void 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return direction === "before" ? anchorIndex - firstIndex : lastIndex - anchorIndex;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/components/calendar/CalendarScroll.tsx
|
|
119
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
120
|
+
var preloadWindowCount = 2;
|
|
121
|
+
function CalendarScroll({
|
|
122
|
+
direction = "vertical",
|
|
123
|
+
onScroll,
|
|
124
|
+
...props
|
|
125
|
+
}) {
|
|
126
|
+
const calendar = useCalchemyCalendar();
|
|
127
|
+
const scrollRef = (0, import_react2.useRef)(null);
|
|
128
|
+
const [leadingSpacer, setLeadingSpacer] = (0, import_react2.useState)({
|
|
129
|
+
periodCount: 0,
|
|
130
|
+
pixelSize: 0
|
|
131
|
+
});
|
|
132
|
+
const positionedPeriodAnchor = (0, import_react2.useRef)(null);
|
|
133
|
+
const suppressPreloadEvaluation = (0, import_react2.useRef)(false);
|
|
134
|
+
const pendingPrependStabilization = (0, import_react2.useRef)(null);
|
|
135
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
136
|
+
const anchorKey = calendar.periodAnchor.toString();
|
|
137
|
+
if (positionedPeriodAnchor.current === anchorKey) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const element = scrollRef.current;
|
|
141
|
+
const currentPeriod = element?.querySelector(
|
|
142
|
+
"[calchemy-period][calchemy-period-index='0']"
|
|
143
|
+
);
|
|
144
|
+
if (!element || !currentPeriod) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
positionedPeriodAnchor.current = anchorKey;
|
|
148
|
+
scrollPeriodIntoView(element, currentPeriod, direction);
|
|
149
|
+
}, [direction, calendar.periodAnchor, calendar.periods]);
|
|
150
|
+
function startBeforePreloadTransaction(element, preloadDirection, periodWindowSize) {
|
|
151
|
+
suppressPreloadEvaluation.current = true;
|
|
152
|
+
const extendPeriodCount = calendar.period.count * preloadWindowCount;
|
|
153
|
+
const previousScrollSize = getScrollSize(element, preloadDirection);
|
|
154
|
+
const previousScrollPosition = getScrollPosition(element, preloadDirection);
|
|
155
|
+
(0, import_react_dom.flushSync)(() => {
|
|
156
|
+
setLeadingSpacer({
|
|
157
|
+
periodCount: extendPeriodCount,
|
|
158
|
+
pixelSize: periodWindowSize * preloadWindowCount
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
setScrollPosition(
|
|
162
|
+
element,
|
|
163
|
+
preloadDirection,
|
|
164
|
+
previousScrollPosition + getScrollSize(element, preloadDirection) - previousScrollSize
|
|
165
|
+
);
|
|
166
|
+
(0, import_react_dom.flushSync)(() => {
|
|
167
|
+
calendar.extendPeriods("before", preloadWindowCount);
|
|
168
|
+
setLeadingSpacer({ periodCount: 0, pixelSize: 0 });
|
|
169
|
+
});
|
|
170
|
+
const insertedDelta = getScrollSize(element, preloadDirection) - previousScrollSize;
|
|
171
|
+
const targetPosition = previousScrollPosition + insertedDelta;
|
|
172
|
+
setScrollPosition(element, preloadDirection, targetPosition);
|
|
173
|
+
pendingPrependStabilization.current = {
|
|
174
|
+
direction: preloadDirection,
|
|
175
|
+
insertedDelta,
|
|
176
|
+
targetPosition
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function stabilizePrependScrollEvent(element) {
|
|
180
|
+
const stabilization = pendingPrependStabilization.current;
|
|
181
|
+
if (!stabilization) {
|
|
182
|
+
suppressPreloadEvaluation.current = false;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const observedPosition = getScrollPosition(
|
|
186
|
+
element,
|
|
187
|
+
stabilization.direction
|
|
188
|
+
);
|
|
189
|
+
const targetDistance = observedPosition - stabilization.targetPosition;
|
|
190
|
+
const staleCoordinate = Math.abs(
|
|
191
|
+
observedPosition + stabilization.insertedDelta - stabilization.targetPosition
|
|
192
|
+
) < Math.abs(targetDistance);
|
|
193
|
+
if (staleCoordinate) {
|
|
194
|
+
setScrollPosition(
|
|
195
|
+
element,
|
|
196
|
+
stabilization.direction,
|
|
197
|
+
observedPosition + stabilization.insertedDelta
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
pendingPrependStabilization.current = null;
|
|
201
|
+
suppressPreloadEvaluation.current = false;
|
|
202
|
+
}
|
|
203
|
+
function handleScroll(event) {
|
|
204
|
+
onScroll?.(event);
|
|
205
|
+
if (event.defaultPrevented) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const element = event.currentTarget;
|
|
209
|
+
if (suppressPreloadEvaluation.current) {
|
|
210
|
+
stabilizePrependScrollEvent(element);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (getScrollSize(element, direction) <= getClientSize(element, direction)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const anchor = getScrollAnchorPeriod(element, direction);
|
|
217
|
+
const anchorIndex = anchor?.getAttribute("calchemy-period-index") ? Number(anchor.getAttribute("calchemy-period-index")) : NaN;
|
|
218
|
+
if (Number.isFinite(anchorIndex)) {
|
|
219
|
+
calendar.setVisiblePeriodIndex(anchorIndex);
|
|
220
|
+
}
|
|
221
|
+
const periodWindowSize = getCalendarPeriodWindowSize(
|
|
222
|
+
element,
|
|
223
|
+
direction,
|
|
224
|
+
calendar.period.count
|
|
225
|
+
);
|
|
226
|
+
const startRunway = getLoadedPeriodRunway(calendar, anchor, "before");
|
|
227
|
+
const runwayThreshold = calendar.period.count * preloadWindowCount;
|
|
228
|
+
const endRunway = getLoadedPeriodRunway(calendar, anchor, "after");
|
|
229
|
+
if (startRunway !== null && startRunway <= runwayThreshold && calendar.canExtendPeriods("before", preloadWindowCount)) {
|
|
230
|
+
startBeforePreloadTransaction(element, direction, periodWindowSize);
|
|
231
|
+
}
|
|
232
|
+
if (endRunway !== null && endRunway <= runwayThreshold && calendar.canExtendPeriods("after", preloadWindowCount)) {
|
|
233
|
+
calendar.extendPeriods("after", preloadWindowCount);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
237
|
+
CalendarScrollContext.Provider,
|
|
238
|
+
{
|
|
239
|
+
value: {
|
|
240
|
+
direction,
|
|
241
|
+
leadingSpacerPeriodCount: leadingSpacer.periodCount,
|
|
242
|
+
leadingSpacerPixelSize: leadingSpacer.pixelSize
|
|
243
|
+
},
|
|
244
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
245
|
+
"div",
|
|
246
|
+
{
|
|
247
|
+
...props,
|
|
248
|
+
ref: scrollRef,
|
|
249
|
+
"calchemy-scroll": "",
|
|
250
|
+
"calchemy-direction": direction,
|
|
251
|
+
onScroll: handleScroll
|
|
252
|
+
}
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
258
|
+
0 && (module.exports = {
|
|
259
|
+
CalendarScroll
|
|
260
|
+
});
|
|
261
|
+
//# sourceMappingURL=calendar-scroll.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/calendar-scroll.ts","../src/components/calendar/CalendarScroll.tsx","../src/components/calendar/context.ts","../src/components/calendar/scroll-preload.ts"],"sourcesContent":["export {\n CalendarScroll,\n type CalchemyCalendarScrollProps,\n} from \"./components/calendar/CalendarScroll\";\n","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 { createContext, useContext } from \"react\";\nimport type { CalchemyState } from \"../../hooks/useCalchemy\";\nimport type { CalendarPeriodModel, CalendarScrollContextValue, CalendarState } from \"./types\";\n\nexport const CalchemyContext = createContext<CalchemyState | null>(null);\nexport const CalendarContext = createContext<CalendarState | null>(null);\nexport const CalendarPeriodContext = createContext<CalendarPeriodModel | null>(null);\nexport const CalendarScrollContext = createContext<CalendarScrollContextValue | null>(null);\n\nexport function useCalchemyContext(): CalchemyState {\n const state = useContext(CalchemyContext);\n\n if (!state) {\n throw new Error(\"Calchemy components must be rendered inside Calchemy.Root.\");\n }\n\n return state;\n}\n\nexport function useCalchemyCalendar(): CalendarState {\n const state = useContext(CalendarContext);\n\n if (!state) {\n throw new Error(\"Calchemy calendar components must be rendered inside Calchemy.Calendar.\");\n }\n\n return state;\n}\n\nexport function useCalendarPeriod(): CalendarPeriodModel | null {\n return useContext(CalendarPeriodContext);\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;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAkD;AAElD,uBAA0B;;;ACF1B,mBAA0C;AAInC,IAAM,sBAAkB,4BAAoC,IAAI;AAChE,IAAM,sBAAkB,4BAAoC,IAAI;AAChE,IAAM,4BAAwB,4BAA0C,IAAI;AAC5E,IAAM,4BAAwB,4BAAiD,IAAI;AAYnF,SAAS,sBAAqC;AACnD,QAAM,YAAQ,yBAAW,eAAe;AAExC,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,yEAAyE;AAAA,EAC3F;AAEA,SAAO;AACT;;;ACzBO,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,E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