@nomideusz/svelte-calendar 1.4.2 → 1.5.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.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Where a time grid opens: the y (grid px, 0 = first visible hour) to put at
3
+ * the top of the scroller so no event is sliced there.
4
+ *
5
+ * Starts at the hour line `line`, moves up an hour at a time while an event
6
+ * crosses it (looking back at most 2 h), then leaves `room` above for the
7
+ * hour label. If an event still crosses the top, the top goes to that event's
8
+ * start while `anchor` (the now line) stays on screen, else to the first hour
9
+ * after it ends, else the room is dropped; only a block too long for all of
10
+ * those is cut.
11
+ */
12
+ export function openingTop(blocks, line, hourH, room, anchor, viewH) {
13
+ const cuts = (y) => blocks.filter((b) => b.top < y && b.top + b.height > y);
14
+ const floor = line - 2 * hourH;
15
+ for (let c = cuts(line).filter((b) => b.top >= floor); c.length; c = cuts(line).filter((b) => b.top >= floor)) {
16
+ line = Math.floor(Math.min(...c.map((b) => b.top)) / hourH) * hourH;
17
+ }
18
+ // The anchor must stay on screen, with half an hour under it.
19
+ const fits = (y) => anchor >= y && anchor <= y + viewH - hourH / 2;
20
+ let y = line;
21
+ for (let guard = 0; guard < 8; guard++) {
22
+ const above = cuts(y - room);
23
+ if (!above.length)
24
+ return Math.max(0, y - room);
25
+ const start = Math.min(...above.map((b) => b.top));
26
+ if (start < y && fits(start)) {
27
+ y = start;
28
+ continue;
29
+ }
30
+ const across = cuts(y);
31
+ if (!across.length)
32
+ return Math.max(0, y);
33
+ const after = Math.ceil(Math.max(...across.map((b) => b.top + b.height)) / hourH) * hourH;
34
+ if (after > y && fits(after)) {
35
+ y = after;
36
+ continue;
37
+ }
38
+ break;
39
+ }
40
+ return Math.max(0, y);
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomideusz/svelte-calendar",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "A themeable Svelte 5 calendar: day, week, scrolling-week and month views, agenda lists, touch-first mobile layouts, drag-and-drop, timezones, a headless API and an embeddable web component.",
5
5
  "type": "module",
6
6
  "sideEffects": [