Skip to content

lightweight, client-only calendar web application. All data persists in the URL hash for instant sharing, No backend required. Optional AES-GCM password protection keeps shared links locked without a server

JavaScript

add time line

Supun Lakmalf8dabb13c393
diff --git a/index.html b/index.html
index f8e892d..43f082b 100644
--- a/index.html
+++ b/index.html
@@ -133,6 +133,8 @@
data-i18n="view.month">Month</button>
<button data-view="year" role="tab" aria-label="Year view" aria-selected="false" tabindex="-1" data-i18n="view.year">Year</button>
<button data-view="agenda" role="tab" aria-label="Agenda view" aria-selected="false" tabindex="-1" data-i18n="view.agenda">Agenda</button>
+ <button data-view="timeline" role="tab" aria-label="Timeline view" aria-selected="false" tabindex="-1"
+ data-i18n="view.timeline">Timeline</button>
</div>
<button id="focus-btn" type="button" data-i18n="btn.focus">Focus</button>
@@ -247,6 +249,30 @@
</div>
<div id="weekday-row" class="weekday-row"></div>
<div id="calendar-grid" class="calendar-grid" role="grid" aria-label="Calendar"></div>
+ <div id="timeline-controls" class="timeline-controls hidden" aria-label="Timeline controls">
+ <div id="timeline-minimap" class="timeline-minimap" role="slider" tabindex="0"
+ aria-label="Timeline navigator">
+ <div id="timeline-minimap-events" class="timeline-minimap-events"></div>
+ <div id="timeline-minimap-today" class="timeline-minimap-today" aria-hidden="true"></div>
+ <div id="timeline-minimap-selected" class="timeline-minimap-selected" aria-hidden="true"></div>
+ <div id="timeline-minimap-viewport" class="timeline-minimap-viewport" aria-hidden="true"></div>
+ </div>
+ <div class="timeline-controls-row">
+ <button id="timeline-zoom-out" type="button" class="timeline-zoom-btn" aria-label="Zoom out timeline">
+ <i class="fa-solid fa-minus" aria-hidden="true"></i>
+ </button>
+ <label class="timeline-zoom-label" for="timeline-zoom-range">
+ <span class="timeline-zoom-label-text">Zoom</span>
+ <input id="timeline-zoom-range" type="range" min="0" max="4" step="1" value="2"
+ aria-label="Timeline zoom level">
+ <span id="timeline-zoom-value" class="timeline-zoom-value">Day</span>
+ </label>
+ <button id="timeline-zoom-in" type="button" class="timeline-zoom-btn" aria-label="Zoom in timeline">
+ <i class="fa-solid fa-plus" aria-hidden="true"></i>
+ </button>
+ <button id="timeline-jump-today" type="button" class="timeline-center-btn">Center Today</button>
+ </div>
+ </div>
<div id="locked-overlay" class="locked-overlay hidden">
<div class="locked-card">
<h3 data-i18n="locked.title">Encrypted calendar</h3>
@@ -609,6 +635,8 @@
<button data-view="month" role="tab" aria-label="Month view" aria-selected="true" tabindex="0" class="active">Month</button>
<button data-view="year" role="tab" aria-label="Year view" aria-selected="false" tabindex="-1">Year</button>
<button data-view="agenda" role="tab" aria-label="Agenda view" aria-selected="false" tabindex="-1">Agenda</button>
+ <button data-view="timeline" role="tab" aria-label="Timeline view" aria-selected="false" tabindex="-1"
+ data-i18n="view.timeline">Timeline</button>
</div>
</div>
diff --git a/locales/en.js b/locales/en.js
index 5275f34..ea7aedf 100644
--- a/locales/en.js
+++ b/locales/en.js
@@ -12,6 +12,7 @@ export default {
"view.month": "Month",
"view.year": "Year",
"view.agenda": "Agenda",
+ "view.timeline": "Timeline",
// Action buttons
"btn.addEvent": "Add event",
diff --git a/locales/it.js b/locales/it.js
index a9988fc..896b075 100644
--- a/locales/it.js
+++ b/locales/it.js
@@ -12,6 +12,7 @@ export default {
'view.month': 'Mese',
'view.year': 'Anno',
'view.agenda': 'Agenda',
+ 'view.timeline': 'Timeline',
// Action buttons
'btn.addEvent': 'Aggiungi evento',
diff --git a/locales/si.js b/locales/si.js
index 2288768..e8cf213 100644
--- a/locales/si.js
+++ b/locales/si.js
@@ -13,6 +13,8 @@ export default {
"view.year": "අවුරුද්ද",
"view.agenda": "න්‍යාය පත්‍රය",
+ "view.timeline": "Timeline",
+
// Action buttons
"btn.addEvent": "සිදුවීම එක් කරන්න",
"btn.copyLink": "සබැඳිය පිටපත් කරන්න",
diff --git a/locales/ta.js b/locales/ta.js
index c24a516..a328c4e 100644
--- a/locales/ta.js
+++ b/locales/ta.js
@@ -13,6 +13,8 @@ export default {
'view.year': 'ஆண்டு',
'view.agenda': 'நிகழ்ச்சி நிரல்',
+ 'view.timeline': 'Timeline',
+
// Action buttons
'btn.addEvent': 'நிகழ்வைச் சேர்',
'btn.copyLink': 'இணைப்பை நகலெடு',
diff --git a/modules/cacheElements.js b/modules/cacheElements.js
index 41e12c1..5917248 100644
--- a/modules/cacheElements.js
+++ b/modules/cacheElements.js
@@ -21,6 +21,17 @@ export function cacheElements(ui) {
ui.monthLabel = document.getElementById("month-label");
ui.weekdayRow = document.getElementById("weekday-row");
ui.calendarGrid = document.getElementById("calendar-grid");
+ ui.timelineControls = document.getElementById("timeline-controls");
+ ui.timelineZoomOut = document.getElementById("timeline-zoom-out");
+ ui.timelineZoomIn = document.getElementById("timeline-zoom-in");
+ ui.timelineZoomRange = document.getElementById("timeline-zoom-range");
+ ui.timelineZoomValue = document.getElementById("timeline-zoom-value");
+ ui.timelineJumpToday = document.getElementById("timeline-jump-today");
+ ui.timelineMinimap = document.getElementById("timeline-minimap");
+ ui.timelineMinimapEvents = document.getElementById("timeline-minimap-events");
+ ui.timelineMinimapToday = document.getElementById("timeline-minimap-today");
+ ui.timelineMinimapSelected = document.getElementById("timeline-minimap-selected");
+ ui.timelineMinimapViewport = document.getElementById("timeline-minimap-viewport");
ui.selectedDateLabel = document.getElementById("selected-date-label");
ui.eventList = document.getElementById("event-list");
ui.addEventInline = document.getElementById("add-event-inline");
diff --git a/modules/constants.js b/modules/constants.js
index 0e3e749..23b8321 100644
--- a/modules/constants.js
+++ b/modules/constants.js
@@ -5,7 +5,7 @@ export const DEFAULT_COLORS = ["#ff6b6b", "#ffd43b", "#4dabf7", "#63e6be", "#977
// View Types
export const DEFAULT_VIEW = "month";
-export const VALID_VIEWS = new Set(["day", "week", "month", "year", "agenda"]);
+export const VALID_VIEWS = new Set(["day", "week", "month", "year", "agenda", "timeline"]);
// Default Application State
export const DEFAULT_STATE = {
diff --git a/modules/timelineRender.js b/modules/timelineRender.js
new file mode 100644
index 0000000..ad6d8d4
--- /dev/null
+++ b/modules/timelineRender.js
@@ -0,0 +1,388 @@
+import { formatDateKey } from "./calendarRender.js";
+
+const DAY_MS = 86400000;
+const MIN_EVENT_MS = 45 * 60000;
+const MIN_EVENT_WIDTH = 28;
+const RULER_HEIGHT = 72;
+const LANE_HEIGHT = 74;
+const CARD_HEIGHT = 56;
+const BOTTOM_PADDING = 48;
+
+function clamp(value, min, max) {
+ return Math.max(min, Math.min(max, value));
+}
+
+function isValidDate(value) {
+ return value instanceof Date && !Number.isNaN(value.getTime());
+}
+
+function startOfDayMs(date) {
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
+}
+
+function endOfDayMs(date) {
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999).getTime();
+}
+
+function toX(dateMs, rangeStartMs, dayWidth) {
+ return ((dateMs - rangeStartMs) / DAY_MS) * dayWidth;
+}
+
+function formatMonthLabel(date, locale) {
+ return date.toLocaleDateString(locale, { month: "short", year: "numeric" });
+}
+
+function formatWeekLabel(date, locale) {
+ return date.toLocaleDateString(locale, { month: "short", day: "numeric" });
+}
+
+function formatDayLabel(date, locale, compact = false) {
+ if (compact) {
+ return date.toLocaleDateString(locale, { day: "numeric", month: "short" });
+ }
+ return date.toLocaleDateString(locale, { weekday: "short", day: "numeric" });
+}
+
+function formatHourMarker(hour) {
+ return `${String(hour).padStart(2, "0")}:00`;
+}
+
+function formatEventTimeRange(event, locale, allDayLabel) {
+ if (event.isAllDay) return allDayLabel;
+ const startDate = new Date(event.start);
+ const endDate = new Date(event.end);
+ const sameDay = formatDateKey(startDate) === formatDateKey(endDate);
+ const timeOptions = { hour: "2-digit", minute: "2-digit" };
+
+ const startTime = startDate.toLocaleTimeString(locale, timeOptions);
+ const endTime = endDate.toLocaleTimeString(locale, timeOptions);
+
+ if (sameDay) {
+ return `${startTime} - ${endTime}`;
+ }
+
+ const dateOptions = { month: "short", day: "numeric" };
+ const startDay = startDate.toLocaleDateString(locale, dateOptions);
+ const endDay = endDate.toLocaleDateString(locale, dateOptions);
+ return `${startDay} ${startTime} -> ${endDay} ${endTime}`;
+}
+
+function getVisualDensity(dayWidth) {
+ if (dayWidth >= 1440) {
+ return { minVisualDurationMs: 1 * 60000, minEventWidth: 1 };
+ }
+ if (dayWidth >= 720) {
+ return { minVisualDurationMs: 2 * 60000, minEventWidth: 2 };
+ }
+ if (dayWidth >= 480) {
+ return { minVisualDurationMs: 5 * 60000, minEventWidth: 3 };
+ }
+ if (dayWidth >= 220) {
+ return { minVisualDurationMs: 12 * 60000, minEventWidth: 8 };
+ }
+ if (dayWidth >= 120) {
+ return { minVisualDurationMs: 25 * 60000, minEventWidth: 14 };
+ }
+ return { minVisualDurationMs: MIN_EVENT_MS, minEventWidth: MIN_EVENT_WIDTH };
+}
+
+function layoutIntoLanes(occurrences, rangeStartMs, rangeEndMs, minVisualDurationMs) {
+ const items = [];
+ const visibleRangeEnd = rangeEndMs + DAY_MS;
+
+ (occurrences || []).forEach((occ) => {
+ const start = Number(occ && occ.start);
+ const rawEnd = Number(occ && occ.end);
+ if (!Number.isFinite(start)) return;
+ const end = Number.isFinite(rawEnd) ? rawEnd : start;
+ const visualEnd = Math.max(end, start + minVisualDurationMs);
+ if (visualEnd < rangeStartMs || start > visibleRangeEnd) return;
+ items.push({
+ ...occ,
+ _layoutStart: start,
+ _layoutEnd: visualEnd,
+ _lane: 0,
+ });
+ });
+
+ items.sort((a, b) => a._layoutStart - b._layoutStart || a._layoutEnd - b._layoutEnd);
+
+ const laneEndTimes = [];
+ items.forEach((item) => {
+ let laneIndex = laneEndTimes.findIndex((laneEnd) => laneEnd <= item._layoutStart);
+ if (laneIndex === -1) laneIndex = laneEndTimes.length;
+ laneEndTimes[laneIndex] = item._layoutEnd;
+ item._lane = laneIndex;
+ });
+
+ return { items, laneCount: Math.max(1, laneEndTimes.length) };
+}
+
+export function renderTimelineView({
+ container,
+ occurrences = [],
+ rangeStart,
+ rangeEnd,
+ selectedDate,
+ dayWidth = 64,
+ locale = "en-US",
+ allDayLabel = "All day",
+ emptyLabel = "No upcoming events",
+ onSelectDay,
+ onEventClick,
+ onZoomRequest,
+} = {}) {
+ if (!container) {
+ return {
+ scrollHost: null,
+ range: null,
+ centerOnDate: () => {},
+ setSelectedDate: () => {},
+ };
+ }
+
+ const safeDayWidth = clamp(Number(dayWidth) || 64, 8, 1600);
+ const density = getVisualDensity(safeDayWidth);
+ const now = new Date();
+ const safeStartDate = isValidDate(rangeStart) ? rangeStart : new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
+ const safeEndDate = isValidDate(rangeEnd) ? rangeEnd : new Date(now.getFullYear(), now.getMonth(), now.getDate() + 30);
+
+ const rangeStartMs = startOfDayMs(safeStartDate);
+ const rangeEndMs = Math.max(endOfDayMs(safeEndDate), rangeStartMs + DAY_MS);
+ const totalDays = Math.max(1, Math.ceil((rangeEndMs - rangeStartMs) / DAY_MS) + 1);
+ const timelineWidth = Math.max(720, totalDays * safeDayWidth);
+
+ container.innerHTML = "";
+
+ const shell = document.createElement("div");
+ shell.className = "timeline-shell";
+
+ const scrollHost = document.createElement("div");
+ scrollHost.className = "timeline-scroll";
+ scrollHost.tabIndex = 0;
+ scrollHost.setAttribute("aria-label", "Timeline");
+
+ const canvas = document.createElement("div");
+ canvas.className = "timeline-canvas";
+ canvas.style.width = `${timelineWidth}px`;
+
+ const gridLayer = document.createElement("div");
+ gridLayer.className = "timeline-grid";
+ gridLayer.style.width = `${timelineWidth}px`;
+ gridLayer.style.setProperty("--timeline-day-width", `${safeDayWidth}px`);
+
+ const ruler = document.createElement("div");
+ ruler.className = "timeline-ruler";
+ ruler.style.width = `${timelineWidth}px`;
+
+ const eventLayer = document.createElement("div");
+ eventLayer.className = "timeline-events";
+ eventLayer.style.width = `${timelineWidth}px`;
+
+ canvas.appendChild(gridLayer);
+ canvas.appendChild(ruler);
+ canvas.appendChild(eventLayer);
+ scrollHost.appendChild(canvas);
+ shell.appendChild(scrollHost);
+ container.appendChild(shell);
+
+ const showHourGrid = safeDayWidth >= 480 && totalDays <= 220;
+ const showMinuteGrid = safeDayWidth >= 1200 && totalDays <= 90;
+ const showDayLabels = safeDayWidth >= 26;
+ const dayLabelStep = safeDayWidth >= 80 ? 1 : safeDayWidth >= 44 ? 2 : 4;
+ let hourLabelStep = safeDayWidth >= 1200 ? 1 : safeDayWidth >= 800 ? 2 : safeDayWidth >= 480 ? 3 : 6;
+ if (totalDays > 30) hourLabelStep = Math.max(hourLabelStep, 6);
+ if (totalDays > 90) hourLabelStep = Math.max(hourLabelStep, 12);
+
+ for (let day = 0; day <= totalDays; day += 1) {
+ const tickDate = new Date(rangeStartMs + day * DAY_MS);
+ const x = day * safeDayWidth;
+ const line = document.createElement("div");
+ line.className = "timeline-day-line";
+ if (tickDate.getDate() === 1 || day === 0) line.classList.add("is-major");
+ line.style.left = `${x}px`;
+ gridLayer.appendChild(line);
+
+ if (tickDate.getDate() === 1 || day === 0) {
+ const monthChip = document.createElement("div");
+ monthChip.className = "timeline-month-chip";
+ monthChip.style.left = `${x + 8}px`;
+ monthChip.textContent = formatMonthLabel(tickDate, locale);
+ ruler.appendChild(monthChip);
+ } else if (safeDayWidth >= 96 && safeDayWidth < 320 && tickDate.getDay() === 1) {
+ const weekChip = document.createElement("div");
+ weekChip.className = "timeline-week-chip";
+ weekChip.style.left = `${x + 6}px`;
+ weekChip.textContent = formatWeekLabel(tickDate, locale);
+ ruler.appendChild(weekChip);
+ }
+
+ if (showDayLabels && (day === 0 || day % dayLabelStep === 0 || tickDate.getDate() === 1)) {
+ const dayChip = document.createElement("div");
+ dayChip.className = "timeline-day-chip";
+ dayChip.style.left = `${x + 4}px`;
+ dayChip.textContent = formatDayLabel(tickDate, locale, safeDayWidth < 64);
+ ruler.appendChild(dayChip);
+ }
+
+ if (showHourGrid || showMinuteGrid) {
+ const hourLineStep = showHourGrid ? 1 : 6;
+ for (let hour = hourLineStep; hour < 24; hour += hourLineStep) {
+ const hourLine = document.createElement("div");
+ hourLine.className = "timeline-hour-line";
+ if (hour % 6 === 0) hourLine.classList.add("is-major");
+ hourLine.style.left = `${x + (hour / 24) * safeDayWidth}px`;
+ gridLayer.appendChild(hourLine);
+ }
+
+ if (safeDayWidth >= 96) {
+ for (let hour = 0; hour < 24; hour += hourLabelStep) {
+ const hourChip = document.createElement("div");
+ hourChip.className = "timeline-hour-chip";
+ hourChip.style.left = `${x + (hour / 24) * safeDayWidth + 2}px`;
+ hourChip.textContent = formatHourMarker(hour);
+ ruler.appendChild(hourChip);
+ }
+ }
+ }
+
+ if (showMinuteGrid) {
+ for (let halfHour = 1; halfHour < 48; halfHour += 1) {
+ if (halfHour % 2 === 0) continue;
+ const minuteLine = document.createElement("div");
+ minuteLine.className = "timeline-minute-line";
+ minuteLine.style.left = `${x + (halfHour / 48) * safeDayWidth}px`;
+ gridLayer.appendChild(minuteLine);
+ }
+
+ for (let halfHour = 1; halfHour < 48; halfHour += 2) {
+ const minuteChip = document.createElement("div");
+ minuteChip.className = "timeline-minute-chip";
+ minuteChip.style.left = `${x + (halfHour / 48) * safeDayWidth + 2}px`;
+ minuteChip.textContent = ":30";
+ ruler.appendChild(minuteChip);
+ }
+ }
+ }
+
+ const todayLine = document.createElement("div");
+ todayLine.className = "timeline-focus-line is-today";
+ const todayX = toX(startOfDayMs(new Date()), rangeStartMs, safeDayWidth);
+ todayLine.style.left = `${todayX}px`;
+ gridLayer.appendChild(todayLine);
+
+ const selectedLine = document.createElement("div");
+ selectedLine.className = "timeline-focus-line is-selected";
+ gridLayer.appendChild(selectedLine);
+
+ const updateSelectedLine = (date) => {
+ if (!isValidDate(date)) return;
+ const x = toX(startOfDayMs(date), rangeStartMs, safeDayWidth);
+ selectedLine.style.left = `${x}px`;
+ };
+ updateSelectedLine(isValidDate(selectedDate) ? selectedDate : new Date());
+
+ const laidOut = layoutIntoLanes(occurrences, rangeStartMs, rangeEndMs, density.minVisualDurationMs);
+ const contentHeight = RULER_HEIGHT + laidOut.laneCount * LANE_HEIGHT + CARD_HEIGHT + BOTTOM_PADDING;
+ canvas.style.height = `${Math.max(320, contentHeight)}px`;
+
+ laidOut.items.forEach((event) => {
+ const clippedStart = Math.max(event._layoutStart, rangeStartMs);
+ const clippedEnd = Math.min(event._layoutEnd, rangeEndMs + DAY_MS);
+ const left = toX(clippedStart, rangeStartMs, safeDayWidth);
+ const width = Math.max(density.minEventWidth, ((clippedEnd - clippedStart) / DAY_MS) * safeDayWidth);
+
+ const card = document.createElement("button");
+ card.type = "button";
+ card.className = "timeline-event";
+ card.style.left = `${left}px`;
+ card.style.top = `${RULER_HEIGHT + event._lane * LANE_HEIGHT}px`;
+ card.style.width = `${width}px`;
+ card.style.setProperty("--bg-color", event.color || "#1a73e8");
+ if (width < 88) card.classList.add("is-compact");
+ if (width < 46) card.classList.add("is-micro");
+
+ const timeLabel = document.createElement("span");
+ timeLabel.className = "timeline-event-time";
+ timeLabel.textContent = formatEventTimeRange(event, locale, allDayLabel);
+
+ const title = document.createElement("span");
+ title.className = "timeline-event-title";
+ title.textContent = event.title || "Untitled";
+
+ card.appendChild(timeLabel);
+ card.appendChild(title);
+ card.title = `${title.textContent} - ${timeLabel.textContent}`;
+ card.setAttribute("aria-label", `${title.textContent}. ${timeLabel.textContent}`);
+
+ card.addEventListener("click", (evt) => {
+ evt.stopPropagation();
+ if (typeof onEventClick === "function") {
+ onEventClick(event);
+ }
+ });
+
+ eventLayer.appendChild(card);
+ });
+
+ if (!laidOut.items.length) {
+ const empty = document.createElement("div");
+ empty.className = "timeline-empty";
+ empty.textContent = emptyLabel;
+ empty.style.top = `${RULER_HEIGHT + 18}px`;
+ eventLayer.appendChild(empty);
+ }
+
+ if (typeof onSelectDay === "function") {
+ canvas.addEventListener("click", (event) => {
+ if (event.target.closest(".timeline-event")) return;
+ const rect = canvas.getBoundingClientRect();
+ const x = clamp(event.clientX - rect.left, 0, timelineWidth - 1);
+ const dayIndex = Math.floor(x / safeDayWidth);
+ const date = new Date(rangeStartMs + dayIndex * DAY_MS);
+ onSelectDay(date);
+ });
+ }
+
+ scrollHost.addEventListener(
+ "wheel",
+ (event) => {
+ const isZoomGesture = event.ctrlKey || event.metaKey;
+ if (isZoomGesture && typeof onZoomRequest === "function") {
+ event.preventDefault();
+ const rect = scrollHost.getBoundingClientRect();
+ const ratio = rect.width > 0 ? clamp((event.clientX - rect.left) / rect.width, 0, 1) : 0.5;
+ onZoomRequest(event.deltaY < 0 ? 1 : -1, ratio);
+ return;
+ }
+
+ const canScrollVertically = scrollHost.scrollHeight > scrollHost.clientHeight + 1;
+ if (!canScrollVertically && Math.abs(event.deltaY) > Math.abs(event.deltaX) && scrollHost.scrollWidth > scrollHost.clientWidth) {
+ event.preventDefault();
+ scrollHost.scrollLeft += event.deltaY;
+ }
+ },
+ { passive: false },
+ );
+
+ const centerOnDate = (date, { behavior = "auto", anchor = 0.5 } = {}) => {
+ if (!isValidDate(date)) return;
+ const dayOffset = (startOfDayMs(date) - rangeStartMs) / DAY_MS;
+ const target = dayOffset * safeDayWidth - scrollHost.clientWidth * anchor;
+ const maxLeft = Math.max(0, scrollHost.scrollWidth - scrollHost.clientWidth);
+ scrollHost.scrollTo({
+ left: clamp(target, 0, maxLeft),
+ behavior,
+ });
+ };
+
+ return {
+ scrollHost,
+ range: {
+ start: new Date(rangeStartMs),
+ end: new Date(rangeEndMs),
+ },
+ centerOnDate,
+ setSelectedDate: updateSelectedLine,
+ };
+}
diff --git a/script.js b/script.js
index 6e06d74..a4451e6 100644
--- a/script.js
+++ b/script.js
@@ -43,6 +43,7 @@ import { expandEvents } from "./modules/recurrenceEngine.js";
import { createResponsiveFeaturesController } from "./modules/responsiveFeatures.js";
import { StateSaveManager } from "./modules/stateSaveManager.js";
import { createTemplateGalleryController } from "./modules/templateGallery.js";
+import { renderTimelineView } from "./modules/timelineRender.js";
import { AVAILABLE_ZONES, getLocalZone, getZoneInfo, isValidZone, parseOffsetSearchTerm } from "./modules/timezoneManager.js";
import { parsePathToEventEntries } from "./modules/urlPathEventParser.js";
import { WorldPlanner } from "./modules/worldPlannerModule.js";
@@ -65,9 +66,25 @@ let jsonModalController = null;
let notificationTimer = null;
let responsiveFeaturesController = null;
let templateGalleryController = null;
+let timelineViewData = null;
+let timelineNeedsCenter = false;
+let timelinePendingAnchorDate = null;
+let timelineMinimapSession = null;
const notifiedOccurrences = new Map();
-
-const ui = {};
+
+const ui = {};
+const MS_PER_DAY = 24 * 60 * MS_PER_MINUTE;
+const TIMELINE_ZOOM_LEVELS = [
+ { key: "month", dayWidth: 10 },
+ { key: "week", dayWidth: 28 },
+ { key: "day", dayWidth: 96 },
+ { key: "hour", dayWidth: 480 },
+ { key: "minute", dayWidth: 1440 },
+];
+const DEFAULT_TIMELINE_ZOOM_LEVEL = 2;
+const TIMELINE_RECURRING_WINDOW_DAYS = 365;
+const TIMELINE_PADDING_DAYS = 14;
+let timelineZoomLevel = DEFAULT_TIMELINE_ZOOM_LEVEL;
function isCalendarLocked() {
return lockState.encrypted && !lockState.unlocked;
@@ -127,15 +144,27 @@ function startOfDay(date) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
}
-function addDays(date, days) {
- const next = new Date(date.getTime());
- next.setDate(next.getDate() + days);
- return next;
-}
-
-function formatMonthLabel(date) {
- return `${getTranslatedMonthName(date)} ${date.getFullYear()}`;
-}
+function addDays(date, days) {
+ const next = new Date(date.getTime());
+ next.setDate(next.getDate() + days);
+ return next;
+}
+
+function endOfDay(date) {
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
+}
+
+function clamp(value, min, max) {
+ return Math.max(min, Math.min(max, value));
+}
+
+function isValidDate(value) {
+ return value instanceof Date && !Number.isNaN(value.getTime());
+}
+
+function formatMonthLabel(date) {
+ return `${getTranslatedMonthName(date)} ${date.getFullYear()}`;
+}
function formatDateLabel(date) {
return `${getTranslatedWeekday(date)}, ${getTranslatedMonthName(date)} ${date.getDate()}`;
@@ -163,12 +192,13 @@ function getStoredView(view) {
return VALID_VIEWS.has(view) ? view : DEFAULT_VIEW;
}
-function applyStoredView() {
- const stored = state && state.s ? state.s.v : null;
- currentView = getStoredView(stored);
- if (state && state.s) state.s.v = currentView;
- updateViewButtons();
-}
+function applyStoredView() {
+ const stored = state && state.s ? state.s.v : null;
+ currentView = getStoredView(stored);
+ if (state && state.s) state.s.v = currentView;
+ timelineNeedsCenter = currentView === "timeline";
+ updateViewButtons();
+}
function normalizeTimezones(rawZones) {
if (!Array.isArray(rawZones)) return [];
@@ -685,9 +715,9 @@ function updateFocusButton(isActive) {
ui.focusBtn.setAttribute("aria-pressed", active ? "true" : "false");
}
-function updateViewButtons() {
- if (!ui.viewButtons || !ui.viewButtons.length) return;
- ui.viewButtons.forEach((button) => {
+function updateViewButtons() {
+ if (!ui.viewButtons || !ui.viewButtons.length) return;
+ ui.viewButtons.forEach((button) => {
const isActive = button.dataset.view === currentView;
button.classList.toggle(CSS_CLASSES.ACTIVE, isActive);
button.setAttribute("aria-selected", isActive ? "true" : "false");
@@ -697,15 +727,416 @@ function updateViewButtons() {
const isActive = button.dataset.view === currentView;
button.classList.toggle(CSS_CLASSES.ACTIVE, isActive);
button.setAttribute("aria-selected", isActive ? "true" : "false");
- });
- }
-}
-
-function setView(view) {
- if (!VALID_VIEWS.has(view)) return;
- if (currentView === view) return;
-
- const grid = ui.calendarGrid;
+ });
+ }
+}
+
+function destroyTimelineMinimapSession() {
+ if (!timelineMinimapSession) return;
+
+ const {
+ frameId,
+ scrollHost,
+ onScroll,
+ onResize,
+ minimapEl,
+ onPointerDown,
+ onPointerMove,
+ onPointerUp,
+ onPointerCancel,
+ onKeyDown,
+ } = timelineMinimapSession;
+
+ if (frameId) window.cancelAnimationFrame(frameId);
+ if (scrollHost && onScroll) scrollHost.removeEventListener("scroll", onScroll);
+ if (onResize) window.removeEventListener("resize", onResize);
+
+ if (minimapEl) {
+ if (onPointerDown) minimapEl.removeEventListener("pointerdown", onPointerDown);
+ if (onPointerMove) minimapEl.removeEventListener("pointermove", onPointerMove);
+ if (onPointerUp) minimapEl.removeEventListener("pointerup", onPointerUp);
+ if (onPointerCancel) minimapEl.removeEventListener("pointercancel", onPointerCancel);
+ if (onKeyDown) minimapEl.removeEventListener("keydown", onKeyDown);
+ }
+
+ timelineMinimapSession = null;
+}
+
+function buildTimelineMinimapIntervals(occurrences, rangeStartMs, rangeEndMs) {
+ const intervals = [];
+ const minDurationMs = 20 * MS_PER_MINUTE;
+
+ (occurrences || []).forEach((occ) => {
+ const rawStart = Number(occ && occ.start);
+ const rawEnd = Number(occ && occ.end);
+ if (!Number.isFinite(rawStart)) return;
+
+ const startMs = rawStart;
+ const endMs = Number.isFinite(rawEnd) && rawEnd > startMs ? rawEnd : startMs + minDurationMs;
+ const clippedStart = Math.max(startMs, rangeStartMs);
+ const clippedEnd = Math.min(endMs, rangeEndMs);
+ if (clippedEnd <= clippedStart) return;
+ intervals.push([clippedStart, clippedEnd]);
+ });
+
+ intervals.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
+
+ const merged = [];
+ const mergeGapMs = 8 * MS_PER_MINUTE;
+
+ intervals.forEach((interval) => {
+ const previous = merged[merged.length - 1];
+ if (!previous || interval[0] > previous[1] + mergeGapMs) {
+ merged.push(interval);
+ return;
+ }
+ previous[1] = Math.max(previous[1], interval[1]);
+ });
+
+ return merged;
+}
+
+function paintTimelineMinimapEvents(occurrences, rangeStartMs, rangeEndMs) {
+ if (!ui.timelineMinimapEvents) return;
+
+ ui.timelineMinimapEvents.innerHTML = "";
+ const spanMs = Math.max(MS_PER_DAY, rangeEndMs - rangeStartMs);
+ const intervals = buildTimelineMinimapIntervals(occurrences, rangeStartMs, rangeEndMs);
+ const maxSegments = 600;
+ const stride = intervals.length > maxSegments ? Math.ceil(intervals.length / maxSegments) : 1;
+
+ for (let i = 0; i < intervals.length; i += stride) {
+ const [startMs, endMs] = intervals[i];
+ const leftPct = ((startMs - rangeStartMs) / spanMs) * 100;
+ const widthPct = Math.max(((endMs - startMs) / spanMs) * 100, 0.1);
+
+ const segment = document.createElement("span");
+ segment.className = "timeline-minimap-segment";
+ segment.style.left = `${leftPct}%`;
+ segment.style.width = `${widthPct}%`;
+ ui.timelineMinimapEvents.appendChild(segment);
+ }
+}
+
+function syncTimelineMinimapUI() {
+ if (!timelineMinimapSession) return;
+ const session = timelineMinimapSession;
+ const { scrollHost, minimapEl, rangeStartMs, rangeEndMs } = session;
+ if (!scrollHost || !minimapEl) return;
+ if (!ui.timelineMinimapViewport || !ui.timelineMinimapToday || !ui.timelineMinimapSelected) return;
+
+ const spanMs = Math.max(MS_PER_DAY, rangeEndMs - rangeStartMs);
+ const todayRatio = clamp((startOfDay(new Date()).getTime() - rangeStartMs) / spanMs, 0, 1);
+ const selectedRatio = clamp((startOfDay(selectedDate).getTime() - rangeStartMs) / spanMs, 0, 1);
+
+ ui.timelineMinimapToday.style.left = `${todayRatio * 100}%`;
+ ui.timelineMinimapSelected.style.left = `${selectedRatio * 100}%`;
+
+ const widthRatio = scrollHost.scrollWidth > 0 ? scrollHost.clientWidth / scrollHost.scrollWidth : 1;
+ const widthPct = clamp(widthRatio * 100, 6, 100);
+ const leftPct = scrollHost.scrollWidth > 0 ? (scrollHost.scrollLeft / scrollHost.scrollWidth) * 100 : 0;
+
+ ui.timelineMinimapViewport.style.width = `${widthPct}%`;
+ ui.timelineMinimapViewport.style.left = `${clamp(leftPct, 0, 100 - widthPct)}%`;
+
+ const centerRatio = clamp((scrollHost.scrollLeft + scrollHost.clientWidth * 0.5) / Math.max(1, scrollHost.scrollWidth), 0, 1);
+ minimapEl.setAttribute("aria-valuemin", "0");
+ minimapEl.setAttribute("aria-valuemax", "100");
+ minimapEl.setAttribute("aria-valuenow", String(Math.round(centerRatio * 100)));
+ minimapEl.setAttribute("aria-valuetext", `${Math.round(centerRatio * 100)}% through timeline`);
+}
+
+function initTimelineMinimap({ occurrences = [], range, scrollHost } = {}) {
+ if (
+ !ui.timelineMinimap ||
+ !ui.timelineMinimapEvents ||
+ !ui.timelineMinimapToday ||
+ !ui.timelineMinimapSelected ||
+ !ui.timelineMinimapViewport ||
+ !scrollHost ||
+ !range ||
+ !isValidDate(range.start) ||
+ !isValidDate(range.end)
+ ) {
+ destroyTimelineMinimapSession();
+ return;
+ }
+
+ destroyTimelineMinimapSession();
+
+ const rangeStartMs = startOfDay(range.start).getTime();
+ const rangeEndMs = endOfDay(range.end).getTime() + MS_PER_DAY;
+ const minimapEl = ui.timelineMinimap;
+
+ paintTimelineMinimapEvents(occurrences, rangeStartMs, rangeEndMs);
+
+ const moveTimelineFromClientX = (clientX, { syncSelected = false } = {}) => {
+ const rect = minimapEl.getBoundingClientRect();
+ if (!rect.width) return;
+
+ const ratio = clamp((clientX - rect.left) / rect.width, 0, 1);
+ const targetLeft = scrollHost.scrollWidth * ratio - scrollHost.clientWidth * 0.5;
+ const maxLeft = Math.max(0, scrollHost.scrollWidth - scrollHost.clientWidth);
+ scrollHost.scrollLeft = clamp(targetLeft, 0, maxLeft);
+
+ if (syncSelected) {
+ const selectedMs = rangeStartMs + ratio * Math.max(MS_PER_DAY, rangeEndMs - rangeStartMs);
+ handleSelectDay(new Date(selectedMs));
+ }
+ };
+
+ const session = {
+ minimapEl,
+ scrollHost,
+ rangeStartMs,
+ rangeEndMs,
+ frameId: 0,
+ pointerId: null,
+ isDragging: false,
+ };
+
+ const scheduleSync = () => {
+ if (!timelineMinimapSession) return;
+ if (timelineMinimapSession.frameId) return;
+
+ timelineMinimapSession.frameId = window.requestAnimationFrame(() => {
+ if (!timelineMinimapSession) return;
+ timelineMinimapSession.frameId = 0;
+ syncTimelineMinimapUI();
+ });
+ };
+
+ session.onScroll = () => scheduleSync();
+ session.onResize = () => scheduleSync();
+
+ session.onPointerDown = (event) => {
+ if (event.button !== 0 && event.pointerType !== "touch" && event.pointerType !== "pen") return;
+ event.preventDefault();
+
+ session.isDragging = true;
+ session.pointerId = event.pointerId;
+ if (typeof minimapEl.setPointerCapture === "function") {
+ minimapEl.setPointerCapture(event.pointerId);
+ }
+
+ moveTimelineFromClientX(event.clientX, { syncSelected: true });
+ scheduleSync();
+ };
+
+ session.onPointerMove = (event) => {
+ if (!session.isDragging || event.pointerId !== session.pointerId) return;
+ moveTimelineFromClientX(event.clientX);
+ scheduleSync();
+ };
+
+ const stopDragging = (event, syncSelected) => {
+ if (!session.isDragging || event.pointerId !== session.pointerId) return;
+ if (syncSelected) moveTimelineFromClientX(event.clientX, { syncSelected: true });
+
+ session.isDragging = false;
+ session.pointerId = null;
+
+ if (typeof minimapEl.releasePointerCapture === "function") {
+ try {
+ minimapEl.releasePointerCapture(event.pointerId);
+ } catch (_error) {
+ // Ignore if pointer was already released.
+ }
+ }
+
+ scheduleSync();
+ };
+
+ session.onPointerUp = (event) => stopDragging(event, true);
+ session.onPointerCancel = (event) => stopDragging(event, false);
+
+ session.onKeyDown = (event) => {
+ const step = Math.max(32, Math.round(scrollHost.clientWidth * 0.24));
+ if (event.key === "ArrowLeft") {
+ event.preventDefault();
+ scrollHost.scrollLeft -= step;
+ scheduleSync();
+ return;
+ }
+ if (event.key === "ArrowRight") {
+ event.preventDefault();
+ scrollHost.scrollLeft += step;
+ scheduleSync();
+ return;
+ }
+ if (event.key === "Home") {
+ event.preventDefault();
+ scrollHost.scrollLeft = 0;
+ scheduleSync();
+ return;
+ }
+ if (event.key === "End") {
+ event.preventDefault();
+ scrollHost.scrollLeft = scrollHost.scrollWidth;
+ scheduleSync();
+ }
+ };
+
+ scrollHost.addEventListener("scroll", session.onScroll, { passive: true });
+ window.addEventListener("resize", session.onResize);
+ minimapEl.addEventListener("pointerdown", session.onPointerDown);
+ minimapEl.addEventListener("pointermove", session.onPointerMove);
+ minimapEl.addEventListener("pointerup", session.onPointerUp);
+ minimapEl.addEventListener("pointercancel", session.onPointerCancel);
+ minimapEl.addEventListener("keydown", session.onKeyDown);
+
+ timelineMinimapSession = session;
+ syncTimelineMinimapUI();
+}
+
+function getTimelineRange() {
+ const zoomKey = (TIMELINE_ZOOM_LEVELS[timelineZoomLevel] || TIMELINE_ZOOM_LEVELS[DEFAULT_TIMELINE_ZOOM_LEVEL]).key;
+ const baseWindowDays = zoomKey === "minute" ? 3 : zoomKey === "hour" ? 14 : zoomKey === "day" ? 45 : zoomKey === "week" ? 90 : 180;
+ const recurringWindowDays = zoomKey === "minute" ? 14 : zoomKey === "hour" ? 45 : zoomKey === "day" ? 120 : zoomKey === "week" ? 240 : TIMELINE_RECURRING_WINDOW_DAYS;
+ const maxSpanDays = zoomKey === "minute" ? 10 : zoomKey === "hour" ? 30 : zoomKey === "day" ? 120 : zoomKey === "week" ? 365 : 900;
+
+ const selectedMs = startOfDay(selectedDate).getTime();
+ let minStart = selectedMs - baseWindowDays * MS_PER_DAY;
+ let maxEnd = selectedMs + baseWindowDays * MS_PER_DAY;
+ let hasRecurring = false;
+
+ (state.e || []).forEach((entry) => {
+ if (!Array.isArray(entry)) return;
+ const startMin = Number(entry[0]);
+ if (!Number.isFinite(startMin)) return;
+ const startMs = startMin * MS_PER_MINUTE;
+ const durationMin = Math.max(0, Number(entry[1]) || 0);
+ const endMs = durationMin > 0 ? startMs + durationMin * MS_PER_MINUTE : startMs + 12 * 60 * MS_PER_MINUTE;
+ minStart = Math.min(minStart, startMs);
+ maxEnd = Math.max(maxEnd, endMs);
+ if (["d", "w", "m", "y"].includes(entry[4])) hasRecurring = true;
+ });
+
+ if (hasRecurring) {
+ minStart = Math.min(minStart, selectedMs - recurringWindowDays * MS_PER_DAY);
+ maxEnd = Math.max(maxEnd, selectedMs + recurringWindowDays * MS_PER_DAY);
+ }
+
+ const spanDays = (maxEnd - minStart) / MS_PER_DAY;
+ if (spanDays > maxSpanDays) {
+ const halfSpan = (maxSpanDays * MS_PER_DAY) / 2;
+ minStart = selectedMs - halfSpan;
+ maxEnd = selectedMs + halfSpan;
+ }
+
+ const start = startOfDay(new Date(minStart - TIMELINE_PADDING_DAYS * MS_PER_DAY));
+ const end = endOfDay(new Date(maxEnd + TIMELINE_PADDING_DAYS * MS_PER_DAY));
+ return { start, end };
+}
+
+function getTimelineDayWidth() {
+ const level = TIMELINE_ZOOM_LEVELS[timelineZoomLevel] || TIMELINE_ZOOM_LEVELS[DEFAULT_TIMELINE_ZOOM_LEVEL];
+ return level.dayWidth;
+}
+
+function getTimelineZoomLabel(levelIndex = timelineZoomLevel) {
+ const level = TIMELINE_ZOOM_LEVELS[levelIndex] || TIMELINE_ZOOM_LEVELS[DEFAULT_TIMELINE_ZOOM_LEVEL];
+ if (level.key === "month") return t("view.month");
+ if (level.key === "week") return t("view.week");
+ if (level.key === "day") return t("view.day");
+ if (level.key === "hour") return "Hour";
+ return "Minute";
+}
+
+function updateTimelineControlsVisibility() {
+ const show = currentView === "timeline";
+ if (ui.timelineControls) {
+ ui.timelineControls.classList.toggle(CSS_CLASSES.HIDDEN, !show);
+ }
+ if (ui.timelineZoomRange) {
+ ui.timelineZoomRange.min = "0";
+ ui.timelineZoomRange.max = String(TIMELINE_ZOOM_LEVELS.length - 1);
+ ui.timelineZoomRange.step = "1";
+ ui.timelineZoomRange.value = String(timelineZoomLevel);
+ }
+ if (ui.timelineZoomValue) {
+ ui.timelineZoomValue.textContent = getTimelineZoomLabel();
+ }
+}
+
+function getTimelineAnchorDate(anchorRatio = 0.5) {
+ if (!timelineViewData || !timelineViewData.scrollHost || !timelineViewData.range) {
+ return startOfDay(selectedDate);
+ }
+
+ const scrollHost = timelineViewData.scrollHost;
+ if (!scrollHost.clientWidth) return startOfDay(selectedDate);
+ const ratio = clamp(anchorRatio, 0, 1);
+ const offsetDays = (scrollHost.scrollLeft + scrollHost.clientWidth * ratio) / getTimelineDayWidth();
+ const anchorMs = timelineViewData.range.start.getTime() + offsetDays * MS_PER_DAY;
+ return new Date(anchorMs);
+}
+
+function applyTimelineZoom(nextLevel, { anchorRatio = 0.5 } = {}) {
+ const rawLevel = Number(nextLevel);
+ if (!Number.isFinite(rawLevel)) return;
+ const clampedLevel = clamp(Math.round(rawLevel), 0, TIMELINE_ZOOM_LEVELS.length - 1);
+ if (clampedLevel === timelineZoomLevel) return;
+
+ if (currentView === "timeline") {
+ timelinePendingAnchorDate = getTimelineAnchorDate(anchorRatio);
+ }
+
+ timelineZoomLevel = clampedLevel;
+ if (ui.timelineZoomRange) ui.timelineZoomRange.value = String(timelineZoomLevel);
+ if (ui.timelineZoomValue) ui.timelineZoomValue.textContent = getTimelineZoomLabel();
+ if (currentView === "timeline") render();
+}
+
+function handleTimelineZoomStep(direction, anchorRatio = 0.5) {
+ const delta = direction > 0 ? 1 : -1;
+ applyTimelineZoom(timelineZoomLevel + delta, { anchorRatio });
+}
+
+function handleTimelineZoomInput(event) {
+ const value = Number(event && event.target ? event.target.value : NaN);
+ if (!Number.isFinite(value)) return;
+ applyTimelineZoom(Math.round(value), { anchorRatio: 0.5 });
+}
+
+function handleTimelineJumpToday() {
+ const today = startOfDay(new Date());
+ selectedDate = today;
+ viewDate = today;
+ renderEventList();
+ if (timelineViewData && timelineViewData.setSelectedDate) {
+ timelineViewData.setSelectedDate(today);
+ }
+ if (timelineViewData && timelineViewData.centerOnDate) {
+ timelineViewData.centerOnDate(today, { behavior: "smooth" });
+ timelineNeedsCenter = false;
+ } else {
+ timelineNeedsCenter = true;
+ }
+ syncTimelineMinimapUI();
+}
+
+function getTimelineShiftDays() {
+ const level = TIMELINE_ZOOM_LEVELS[timelineZoomLevel] || TIMELINE_ZOOM_LEVELS[DEFAULT_TIMELINE_ZOOM_LEVEL];
+ if (level.key === "minute") return 1;
+ if (level.key === "hour") return 7;
+ if (level.key === "day") return 14;
+ if (level.key === "week") return 30;
+ return 60;
+}
+
+function setView(view) {
+ if (!VALID_VIEWS.has(view)) return;
+ if (currentView === view) return;
+ if (view === "timeline") {
+ timelineNeedsCenter = true;
+ } else {
+ timelinePendingAnchorDate = null;
+ timelineViewData = null;
+ destroyTimelineMinimapSession();
+ }
+
+ const grid = ui.calendarGrid;
if (grid) {
grid.classList.add(CSS_CLASSES.VIEW_ANIMATE_OUT);
grid.addEventListener(
@@ -1014,14 +1445,20 @@ function render() {
}
const weekStartsOnMonday = state.s.m === 1;
- if (ui.calendarGrid) {
- ui.calendarGrid.className = `calendar-grid ${currentView}-view`;
- ui.calendarGrid.style.gridTemplateColumns = "";
- ui.calendarGrid.style.gridTemplateRows = "";
- }
- if (ui.weekdayRow) {
- ui.weekdayRow.classList.toggle(CSS_CLASSES.HIDDEN, currentView === "year" || currentView === "agenda");
- }
+ if (ui.calendarGrid) {
+ ui.calendarGrid.className = `calendar-grid ${currentView}-view`;
+ ui.calendarGrid.style.gridTemplateColumns = "";
+ ui.calendarGrid.style.gridTemplateRows = "";
+ }
+ updateTimelineControlsVisibility();
+ if (currentView !== "timeline") {
+ timelineViewData = null;
+ timelinePendingAnchorDate = null;
+ destroyTimelineMinimapSession();
+ }
+ if (ui.weekdayRow) {
+ ui.weekdayRow.classList.toggle(CSS_CLASSES.HIDDEN, currentView === "year" || currentView === "agenda" || currentView === "timeline");
+ }
if (currentView === "month") {
const range = getMonthGridRange(viewDate, weekStartsOnMonday);
@@ -1090,7 +1527,52 @@ function render() {
if (ui.monthLabel && agendaData && agendaData.range) {
ui.monthLabel.textContent = `Agenda · ${formatRangeLabel(agendaData.range.start, agendaData.range.end)}`;
}
- } else if (currentView === "year") {
+ } else if (currentView === "timeline") {
+ const range = getTimelineRange();
+ const expanded = expandEvents(state.e, range.start, range.end);
+ const decorated = decorateOccurrences(expanded);
+ occurrencesByDay = groupOccurrences(decorated);
+
+ if (ui.monthLabel) ui.monthLabel.textContent = `${t("view.timeline")} - ${formatRangeLabel(range.start, range.end)}`;
+ if (ui.calendarGrid) {
+ timelineViewData = renderTimelineView({
+ container: ui.calendarGrid,
+ occurrences: decorated,
+ rangeStart: range.start,
+ rangeEnd: range.end,
+ selectedDate,
+ dayWidth: getTimelineDayWidth(),
+ locale: getCurrentLocale(),
+ allDayLabel: t("calendar.allDay"),
+ emptyLabel: t("calendar.noUpcoming"),
+ onSelectDay: handleSelectDay,
+ onZoomRequest: (direction, anchorRatio) => handleTimelineZoomStep(direction, anchorRatio),
+ onEventClick: (event) => {
+ selectedDate = startOfDay(new Date(event.start));
+ viewDate = selectedDate;
+ renderEventList();
+ openEventModal({ index: event.sourceIndex });
+ },
+ });
+
+ initTimelineMinimap({
+ occurrences: decorated,
+ range: timelineViewData && timelineViewData.range ? timelineViewData.range : range,
+ scrollHost: timelineViewData ? timelineViewData.scrollHost : null,
+ });
+
+ if (timelinePendingAnchorDate && timelineViewData.centerOnDate) {
+ timelineViewData.centerOnDate(timelinePendingAnchorDate, { behavior: "auto" });
+ timelinePendingAnchorDate = null;
+ timelineNeedsCenter = false;
+ } else if (timelineNeedsCenter && timelineViewData.centerOnDate) {
+ timelineViewData.centerOnDate(selectedDate, { behavior: "auto" });
+ timelineNeedsCenter = false;
+ } else if (timelineViewData.setSelectedDate) {
+ timelineViewData.setSelectedDate(selectedDate);
+ }
+ }
+ } else if (currentView === "year") {
const year = viewDate.getFullYear();
const start = new Date(year, 0, 1);
const end = new Date(year, 11, 31, 23, 59, 59);
@@ -1111,13 +1593,13 @@ function render() {
}
}
- // Assign stagger indices to calendar cells
- if (ui.calendarGrid) {
- const cells = ui.calendarGrid.querySelectorAll(".day-cell, .time-cell, .mini-month, .agenda-event-item");
- cells.forEach((cell, index) => {
- cell.style.setProperty("--cell-index", index);
- });
- }
+ // Assign stagger indices to calendar cells
+ if (ui.calendarGrid) {
+ const cells = ui.calendarGrid.querySelectorAll(".day-cell, .time-cell, .mini-month, .agenda-event-item, .timeline-event");
+ cells.forEach((cell, index) => {
+ cell.style.setProperty("--cell-index", index);
+ });
+ }
renderEventList();
renderTimezones();
@@ -1183,9 +1665,9 @@ function renderEventList() {
});
}
-function handleSelectDay(date) {
- selectedDate = startOfDay(date);
- if (currentView === "month") {
+function handleSelectDay(date) {
+ selectedDate = startOfDay(date);
+ if (currentView === "month") {
if (ui.calendarGrid) {
const previous = ui.calendarGrid.querySelector(".day-cell.is-selected");
if (previous) previous.classList.remove(CSS_CLASSES.IS_SELECTED);
@@ -1193,13 +1675,22 @@ function handleSelectDay(date) {
const next = ui.calendarGrid.querySelector(`.day-cell[data-date="${key}"]`);
if (next) next.classList.add(CSS_CLASSES.IS_SELECTED);
}
- renderEventList();
- return;
- }
-
- viewDate = startOfDay(date);
- render();
-}
+ renderEventList();
+ return;
+ }
+ if (currentView === "timeline") {
+ viewDate = startOfDay(date);
+ if (timelineViewData && timelineViewData.setSelectedDate) {
+ timelineViewData.setSelectedDate(selectedDate);
+ }
+ renderEventList();
+ syncTimelineMinimapUI();
+ return;
+ }
+
+ viewDate = startOfDay(date);
+ render();
+}
function openEventModal({ index = null, date = null } = {}) {
if (!ensureEditable()) return;
@@ -1499,20 +1990,24 @@ function handleWeekStartToggle() {
scheduleSave();
}
-function shiftView(direction) {
- if (currentView === "month") {
- viewDate = new Date(viewDate.getFullYear(), viewDate.getMonth() + direction, 1);
- } else if (currentView === "year") {
- viewDate = new Date(viewDate.getFullYear() + direction, 0, 1);
- } else if (currentView === "week") {
- selectedDate = addDays(selectedDate, direction * 7);
- viewDate = startOfDay(selectedDate);
- } else if (currentView === "day") {
- selectedDate = addDays(selectedDate, direction);
- viewDate = startOfDay(selectedDate);
- }
- render();
-}
+function shiftView(direction) {
+ if (currentView === "month") {
+ viewDate = new Date(viewDate.getFullYear(), viewDate.getMonth() + direction, 1);
+ } else if (currentView === "year") {
+ viewDate = new Date(viewDate.getFullYear() + direction, 0, 1);
+ } else if (currentView === "week") {
+ selectedDate = addDays(selectedDate, direction * 7);
+ viewDate = startOfDay(selectedDate);
+ } else if (currentView === "day") {
+ selectedDate = addDays(selectedDate, direction);
+ viewDate = startOfDay(selectedDate);
+ } else if (currentView === "timeline") {
+ selectedDate = addDays(selectedDate, direction * getTimelineShiftDays());
+ viewDate = startOfDay(selectedDate);
+ timelineNeedsCenter = true;
+ }
+ render();
+}
function handlePrevMonth() {
shiftView(-1);
@@ -1522,12 +2017,13 @@ function handleNextMonth() {
shiftView(1);
}
-function handleToday() {
- const today = startOfDay(new Date());
- viewDate = today;
- selectedDate = today;
- render();
-}
+function handleToday() {
+ const today = startOfDay(new Date());
+ viewDate = today;
+ selectedDate = today;
+ if (currentView === "timeline") timelineNeedsCenter = true;
+ render();
+}
function fallbackCopyText(text) {
const textArea = document.createElement("textarea");
@@ -1745,6 +2241,10 @@ function bindEvents() {
if (ui.weekstartToggle) ui.weekstartToggle.addEventListener("click", handleWeekStartToggle);
if (ui.themeToggle) ui.themeToggle.addEventListener("click", handleThemeToggle);
if (ui.notifyToggle) ui.notifyToggle.addEventListener("click", handleNotificationToggle);
+ if (ui.timelineZoomOut) ui.timelineZoomOut.addEventListener("click", () => handleTimelineZoomStep(-1));
+ if (ui.timelineZoomIn) ui.timelineZoomIn.addEventListener("click", () => handleTimelineZoomStep(1));
+ if (ui.timelineZoomRange) ui.timelineZoomRange.addEventListener("input", handleTimelineZoomInput);
+ if (ui.timelineJumpToday) ui.timelineJumpToday.addEventListener("click", handleTimelineJumpToday);
initLanguageDropdown();
if (ui.unlockBtn) ui.unlockBtn.addEventListener("click", attemptUnlock);
if (ui.viewJson) ui.viewJson.addEventListener("click", openJsonModal);
diff --git a/styles.css b/styles.css
index 0b73508..f5264ae 100644
--- a/styles.css
+++ b/styles.css
@@ -471,6 +471,7 @@ button:disabled {
flex-direction: column;
min-width: 0;
min-height: 0;
+ position: relative;
}
.tz-sidebar {
@@ -630,6 +631,159 @@ button:disabled {
flex-wrap: wrap;
}
+.timeline-controls {
+ position: absolute;
+ left: 50%;
+ bottom: 14px;
+ transform: translateX(-50%);
+ display: inline-flex;
+ flex-direction: column;
+ align-items: stretch;
+ gap: 8px;
+ padding: 8px;
+ border-radius: 14px;
+ border: 1px solid var(--border-soft);
+ background: color-mix(in srgb, var(--panel), transparent 8%);
+ box-shadow: var(--shadow-sm);
+ backdrop-filter: blur(8px);
+ -webkit-backdrop-filter: blur(8px);
+ z-index: 4;
+ width: min(760px, calc(100% - 24px));
+ max-width: calc(100% - 24px);
+}
+
+.timeline-controls-row {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ width: 100%;
+ flex-wrap: wrap;
+}
+
+.timeline-minimap {
+ position: relative;
+ height: 34px;
+ width: 100%;
+ border-radius: 10px;
+ border: 1px solid var(--border-soft);
+ background: linear-gradient(
+ 180deg,
+ color-mix(in srgb, var(--panel-2), transparent 6%),
+ color-mix(in srgb, var(--panel), transparent 0%)
+ );
+ overflow: hidden;
+ cursor: pointer;
+ touch-action: none;
+}
+
+.timeline-minimap:focus-visible {
+ outline: 2px solid var(--accent);
+ outline-offset: 2px;
+}
+
+.timeline-minimap-events {
+ position: absolute;
+ inset: 0;
+ z-index: 1;
+}
+
+.timeline-minimap-segment {
+ position: absolute;
+ top: 9px;
+ bottom: 9px;
+ min-width: 2px;
+ border-radius: 999px;
+ background: color-mix(in srgb, var(--accent), transparent 36%);
+ opacity: 0.9;
+}
+
+.timeline-minimap-today,
+.timeline-minimap-selected {
+ position: absolute;
+ top: 3px;
+ bottom: 3px;
+ width: 2px;
+ z-index: 3;
+ pointer-events: none;
+}
+
+.timeline-minimap-today {
+ background: color-mix(in srgb, var(--focus-urgent), transparent 10%);
+}
+
+.timeline-minimap-selected {
+ background: color-mix(in srgb, var(--accent), transparent 0%);
+ box-shadow: 0 0 0 1px color-mix(in srgb, var(--panel), transparent 15%);
+}
+
+.timeline-minimap-viewport {
+ position: absolute;
+ top: 2px;
+ bottom: 2px;
+ left: 0;
+ width: 100%;
+ min-width: 18px;
+ border-radius: 8px;
+ border: 1px solid color-mix(in srgb, var(--accent), transparent 35%);
+ background: color-mix(in srgb, var(--accent-soft), transparent 12%);
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--panel), transparent 40%);
+ z-index: 4;
+ pointer-events: none;
+}
+
+.timeline-zoom-btn {
+ width: 34px;
+ height: 34px;
+ border-radius: 999px;
+ padding: 0;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ border: 1px solid var(--border);
+ background: var(--panel);
+}
+
+.timeline-zoom-label {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 0.74rem;
+ font-weight: 600;
+ color: var(--muted);
+ text-transform: uppercase;
+ letter-spacing: 0.08em;
+}
+
+.timeline-zoom-value {
+ min-width: 56px;
+ display: inline-block;
+ text-align: center;
+ padding: 4px 8px;
+ border-radius: 999px;
+ border: 1px solid var(--border-soft);
+ background: var(--panel);
+ color: var(--text);
+ font-size: 0.7rem;
+ letter-spacing: 0.06em;
+}
+
+#timeline-zoom-range {
+ accent-color: var(--accent);
+ width: clamp(108px, 16vw, 180px);
+ cursor: pointer;
+}
+
+.timeline-center-btn {
+ padding: 7px 12px;
+ border-radius: 999px;
+ font-size: 0.74rem;
+ font-weight: 600;
+ border: 1px solid var(--border);
+ background: var(--panel);
+ color: var(--text);
+}
+
.weekday-row {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
@@ -747,6 +901,246 @@ button:disabled {
max-width: 420px;
}
+.calendar-grid.timeline-view {
+ display: block;
+ overflow: hidden;
+ background:
+ radial-gradient(circle at 8% 4%, color-mix(in srgb, var(--accent-soft), transparent 30%), transparent 38%),
+ linear-gradient(180deg, var(--panel), var(--panel-2));
+}
+
+.calendar-grid.timeline-view .timeline-scroll {
+ padding-bottom: 156px;
+}
+
+.timeline-shell {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+}
+
+.timeline-scroll {
+ position: relative;
+ flex: 1;
+ min-height: 0;
+ overflow: auto;
+ border-top: 1px solid var(--border-soft);
+ scrollbar-gutter: stable both-edges;
+ outline: none;
+}
+
+.timeline-canvas {
+ position: relative;
+ min-height: 100%;
+ isolation: isolate;
+}
+
+.timeline-grid {
+ position: absolute;
+ inset: 0;
+ pointer-events: none;
+ z-index: 1;
+}
+
+.timeline-ruler {
+ position: sticky;
+ top: 0;
+ height: 72px;
+ border-bottom: 1px solid var(--border-soft);
+ background: linear-gradient(180deg, color-mix(in srgb, var(--panel), transparent 6%), color-mix(in srgb, var(--panel-2), transparent 15%));
+ backdrop-filter: blur(6px);
+ -webkit-backdrop-filter: blur(6px);
+ z-index: 6;
+}
+
+.timeline-day-line {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ width: 1px;
+ background: color-mix(in srgb, var(--border-soft), transparent 22%);
+}
+
+.timeline-day-line.is-major {
+ width: 2px;
+ background: color-mix(in srgb, var(--accent), transparent 60%);
+}
+
+.timeline-hour-line,
+.timeline-minute-line {
+ position: absolute;
+ top: 72px;
+ bottom: 0;
+ width: 1px;
+ pointer-events: none;
+}
+
+.timeline-hour-line {
+ background: color-mix(in srgb, var(--border), transparent 55%);
+}
+
+.timeline-hour-line.is-major {
+ background: color-mix(in srgb, var(--accent), transparent 78%);
+}
+
+.timeline-minute-line {
+ background: color-mix(in srgb, var(--border-soft), transparent 72%);
+}
+
+.timeline-month-chip,
+.timeline-week-chip {
+ position: absolute;
+ top: 10px;
+ pointer-events: none;
+ font-weight: 600;
+ font-variant-numeric: tabular-nums;
+ color: var(--text);
+ white-space: nowrap;
+}
+
+.timeline-month-chip {
+ font-size: 0.76rem;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+}
+
+.timeline-week-chip {
+ top: 38px;
+ font-size: 0.72rem;
+ color: var(--muted);
+}
+
+.timeline-day-chip,
+.timeline-hour-chip,
+.timeline-minute-chip {
+ position: absolute;
+ pointer-events: none;
+ white-space: nowrap;
+ font-variant-numeric: tabular-nums;
+ color: var(--muted);
+}
+
+.timeline-day-chip {
+ top: 28px;
+ font-size: 0.66rem;
+ font-weight: 600;
+ color: var(--text);
+}
+
+.timeline-hour-chip {
+ top: 46px;
+ font-size: 0.58rem;
+ letter-spacing: 0.04em;
+}
+
+.timeline-minute-chip {
+ top: 58px;
+ font-size: 0.52rem;
+ letter-spacing: 0.03em;
+ opacity: 0.92;
+}
+
+.timeline-focus-line {
+ position: absolute;
+ top: 72px;
+ bottom: 0;
+ width: 2px;
+ z-index: 2;
+}
+
+.timeline-focus-line.is-selected {
+ background: color-mix(in srgb, var(--accent), transparent 20%);
+ box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent), transparent 70%);
+}
+
+.timeline-focus-line.is-today {
+ background: color-mix(in srgb, var(--focus-urgent), transparent 15%);
+ box-shadow: 0 0 10px color-mix(in srgb, var(--focus-urgent), transparent 45%);
+}
+
+.timeline-events {
+ position: relative;
+ z-index: 4;
+}
+
+.timeline-event {
+ position: absolute;
+ height: 56px;
+ border-radius: 14px;
+ border: 1px solid color-mix(in srgb, var(--bg-color, var(--accent)), #ffffff 70%);
+ border-left-width: 4px;
+ border-left-color: var(--bg-color, var(--accent));
+ background: linear-gradient(
+ 145deg,
+ color-mix(in srgb, var(--bg-color, var(--accent)), transparent 84%),
+ color-mix(in srgb, var(--panel), transparent 5%)
+ );
+ color: var(--text);
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ gap: 3px;
+ padding: 8px 12px;
+ text-align: left;
+ box-shadow: var(--shadow-sm);
+ cursor: pointer;
+ transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
+ animation: cell-fade-in 0.35s ease backwards;
+ animation-delay: calc(var(--cell-index, 0) * 15ms);
+}
+
+.timeline-event:hover {
+ transform: translateY(-2px);
+ box-shadow: var(--shadow-md);
+ border-color: color-mix(in srgb, var(--bg-color, var(--accent)), #ffffff 50%);
+}
+
+.timeline-event.is-compact {
+ padding: 6px 8px;
+ gap: 2px;
+ border-left-width: 3px;
+}
+
+.timeline-event.is-micro {
+ padding: 4px 6px;
+ border-left-width: 2px;
+}
+
+.timeline-event.is-micro .timeline-event-time {
+ display: none;
+}
+
+.timeline-event-time {
+ font-size: 0.65rem;
+ font-weight: 700;
+ letter-spacing: 0.07em;
+ text-transform: uppercase;
+ color: var(--muted);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.timeline-event-title {
+ font-size: 0.83rem;
+ font-weight: 600;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.timeline-empty {
+ position: absolute;
+ left: 18px;
+ padding: 14px 16px;
+ border-radius: 12px;
+ border: 1px dashed var(--border);
+ background: color-mix(in srgb, var(--panel-2), transparent 10%);
+ color: var(--muted);
+ font-size: 0.86rem;
+ max-width: 340px;
+}
+
.calendar-grid.month-view {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
@@ -1957,6 +2351,26 @@ body[data-theme="dark"] .app-launcher-modal-body,
justify-content: space-between;
}
+ .timeline-controls {
+ max-width: calc(100% - 20px);
+ width: calc(100% - 20px);
+ bottom: 10px;
+ padding: 7px;
+ gap: 7px;
+ }
+
+ .timeline-minimap {
+ height: 31px;
+ }
+
+ .timeline-controls-row {
+ justify-content: space-between;
+ }
+
+ #timeline-zoom-range {
+ width: min(220px, 42vw);
+ }
+
.calendar-grid.month-view {
font-size: 0.8rem;
}
@@ -2078,6 +2492,96 @@ body[data-theme="dark"] .app-launcher-modal-body,
font-size: 0.68rem;
}
+ .calendar-grid.timeline-view .timeline-scroll {
+ padding-bottom: 186px;
+ }
+
+ .timeline-controls {
+ left: 8px;
+ right: 8px;
+ transform: none;
+ width: auto;
+ max-width: none;
+ bottom: calc(8px + env(safe-area-inset-bottom, 0px));
+ padding: 6px;
+ gap: 6px;
+ }
+
+ .timeline-minimap {
+ height: 28px;
+ }
+
+ .timeline-controls-row {
+ gap: 6px;
+ justify-content: space-between;
+ }
+
+ .timeline-zoom-label {
+ flex: 1 1 auto;
+ min-width: 0;
+ }
+
+ .timeline-zoom-label-text {
+ display: none;
+ }
+
+ .timeline-zoom-value {
+ min-width: 48px;
+ padding: 4px 6px;
+ font-size: 0.66rem;
+ }
+
+ #timeline-zoom-range {
+ width: clamp(108px, 37vw, 170px);
+ }
+
+ .timeline-center-btn {
+ padding-inline: 10px;
+ font-size: 0.7rem;
+ }
+
+ .timeline-ruler {
+ height: 64px;
+ }
+
+ .timeline-focus-line {
+ top: 64px;
+ }
+
+ .timeline-hour-line,
+ .timeline-minute-line {
+ top: 64px;
+ }
+
+ .timeline-day-chip {
+ top: 22px;
+ font-size: 0.62rem;
+ }
+
+ .timeline-hour-chip {
+ top: 38px;
+ font-size: 0.54rem;
+ }
+
+ .timeline-minute-chip {
+ top: 50px;
+ font-size: 0.48rem;
+ }
+
+ .timeline-event {
+ height: 52px;
+ border-radius: 12px;
+ padding: 7px 10px;
+ }
+
+ .timeline-event-time {
+ font-size: 0.62rem;
+ }
+
+ .timeline-event-title {
+ font-size: 0.8rem;
+ }
+
.mobile-warning-card {
flex-direction: column;
align-items: flex-start;