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
focusMode
Supun Lakmal145fd036b5a1
diff --git a/index.html b/index.htmlindex 206aefe..a8fdfc5 100644--- a/index.html+++ b/index.html@@ -57,12 +57,13 @@<button id="today-btn" type="button">Today</button><button id="next-month" type="button" aria-label="Next month">Next</button></div>- <div class="view-toggle" role="tablist" aria-label="Calendar view">- <button type="button" data-view="day" role="tab" aria-selected="false">Day</button>- <button type="button" data-view="week" role="tab" aria-selected="false">Week</button>- <button type="button" data-view="month" role="tab" aria-selected="true">Month</button>- <button type="button" data-view="year" role="tab" aria-selected="false">Year</button>- </div>+ <div class="view-toggle" role="tablist" aria-label="Calendar view">+ <button type="button" data-view="day" role="tab" aria-selected="false">Day</button>+ <button type="button" data-view="week" role="tab" aria-selected="false">Week</button>+ <button type="button" data-view="month" role="tab" aria-selected="true">Month</button>+ <button type="button" data-view="year" role="tab" aria-selected="false">Year</button>+ </div>+ <button id="focus-btn" type="button" class="ghost">Focus</button><button id="add-event" type="button" class="primary">Add event</button><button id="copy-link" type="button">Copy link</button><button id="lock-btn" type="button">Lock</button>@@ -121,13 +122,34 @@<h4 class="side-title">Danger zone</h4><button id="clear-all" type="button" class="danger-btn">Clear calendar</button></div>- </aside>- </main>- </div>-- <div id="event-modal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="event-modal-title">- <div class="modal-backdrop"></div>- <div class="modal-card">+ </aside>+ </main>+ </div>++ <div id="focus-overlay" class="focus-overlay" aria-hidden="true">+ <div class="focus-shell">+ <div class="focus-header">+ <button id="focus-exit" type="button" class="icon-btn focus-exit" aria-label="Exit focus mode">x</button>+ <div id="focus-clock" class="focus-clock">00:00</div>+ </div>+ <div class="focus-main">+ <div id="focus-status" class="focus-status">NEXT UP IN</div>+ <div id="focus-timer" class="focus-timer">00:00:00</div>+ <div class="focus-event">+ <div id="focus-title" class="focus-title">No upcoming events</div>+ <div id="focus-time" class="focus-time"></div>+ </div>+ </div>+ <div id="focus-upnext" class="focus-upnext hidden">+ <div class="focus-upnext-label">Up later</div>+ <ul id="focus-upnext-list" class="focus-upnext-list"></ul>+ </div>+ </div>+ </div>++ <div id="event-modal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="event-modal-title">+ <div class="modal-backdrop"></div>+ <div class="modal-card"><header class="modal-header"><h3 id="event-modal-title">Add event</h3><button id="event-close" type="button" class="icon-btn" aria-label="Close">x</button>diff --git a/modules/focusMode.js b/modules/focusMode.jsnew file mode 100644index 0000000..5415b41--- /dev/null+++ b/modules/focusMode.js@@ -0,0 +1,265 @@+import { expandEvents } from "./recurrenceEngine.js";++const MAX_UP_NEXT = 2;++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 endOfDay(date) {+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);+}++function isSameDay(a, b) {+ return (+ a.getFullYear() === b.getFullYear() &&+ a.getMonth() === b.getMonth() &&+ a.getDate() === b.getDate()+ );+}++function formatTime(date) {+ return date.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" });+}++function formatDateLabel(date) {+ return date.toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" });+}++function formatCountdown(ms) {+ const totalSeconds = Math.max(0, Math.floor(ms / 1000));+ const hours = Math.floor(totalSeconds / 3600);+ const minutes = Math.floor((totalSeconds % 3600) / 60);+ const seconds = totalSeconds % 60;+ const hoursLabel = String(hours).padStart(2, "0");+ const minutesLabel = String(minutes).padStart(2, "0");+ const secondsLabel = String(seconds).padStart(2, "0");+ return `${hoursLabel}:${minutesLabel}:${secondsLabel}`;+}++function formatEventTime(event, now) {+ if (!event) return "";+ const dateLabel = isSameDay(event.startDate, now) ? "" : `${formatDateLabel(event.startDate)} | `;+ if (event.isAllDay) {+ return `${dateLabel}All day`.trim();+ }+ return `${dateLabel}${formatTime(event.startDate)} - ${formatTime(event.endDate)}`.trim();+}++function formatUpNextLabel(event, now) {+ const dateLabel = isSameDay(event.startDate, now) ? "" : `${formatDateLabel(event.startDate)} `;+ const timeLabel = event.isAllDay ? "All day" : formatTime(event.startDate);+ return `${dateLabel}${timeLabel}`.trim();+}++function getToneForDiff(diffMs) {+ const minutes = diffMs / 60000;+ if (minutes < 2) return "urgent";+ if (minutes < 10) return "warn";+ if (minutes > 30) return "good";+ return "neutral";+}++export class FocusMode {+ constructor({ getState, fallbackColors = [], onToggle = null } = {}) {+ this.getState = getState;+ this.fallbackColors = fallbackColors;+ this.onToggle = onToggle;+ this.active = false;+ this.intervalId = null;++ this.container = document.getElementById("focus-overlay");+ this.exitButton = document.getElementById("focus-exit");+ this.clockEl = document.getElementById("focus-clock");+ this.statusEl = document.getElementById("focus-status");+ this.timerEl = document.getElementById("focus-timer");+ this.titleEl = document.getElementById("focus-title");+ this.timeEl = document.getElementById("focus-time");+ this.upNextSection = document.getElementById("focus-upnext");+ this.upNextList = document.getElementById("focus-upnext-list");++ this.handleKeydown = this.handleKeydown.bind(this);++ if (this.exitButton) {+ this.exitButton.addEventListener("click", () => this.stop());+ }+ }++ isActive() {+ return this.active;+ }++ start() {+ if (this.active || !this.container) return;+ this.active = true;+ this.container.classList.add("is-active");+ this.container.setAttribute("aria-hidden", "false");+ this.tick();+ this.intervalId = window.setInterval(() => this.tick(), 1000);+ document.addEventListener("keydown", this.handleKeydown);+ if (typeof this.onToggle === "function") this.onToggle(true);+ }++ stop() {+ if (!this.active) return;+ this.active = false;+ if (this.intervalId) {+ window.clearInterval(this.intervalId);+ this.intervalId = null;+ }+ if (this.container) {+ this.container.classList.remove("is-active");+ this.container.setAttribute("aria-hidden", "true");+ this.container.dataset.tone = "neutral";+ }+ document.removeEventListener("keydown", this.handleKeydown);+ if (typeof this.onToggle === "function") this.onToggle(false);+ }++ handleKeydown(event) {+ if (event.key !== "Escape") return;+ event.preventDefault();+ this.stop();+ }++ tick() {+ if (!this.container) return;+ const now = new Date();+ if (this.clockEl) this.clockEl.textContent = formatTime(now);++ const { mode, primary, upcoming } = this.getDisplayState(now);+ if (mode === "empty" || !primary) {+ this.setTone("neutral");+ if (this.statusEl) this.statusEl.textContent = "ALL CLEAR";+ if (this.timerEl) this.timerEl.textContent = "--:--:--";+ if (this.titleEl) this.titleEl.textContent = "No upcoming events";+ if (this.timeEl) {+ this.timeEl.textContent = "";+ this.timeEl.classList.add("hidden");+ }+ this.renderUpNext([], now);+ return;+ }++ if (this.timeEl) {+ this.timeEl.textContent = formatEventTime(primary, now);+ this.timeEl.classList.toggle("hidden", !this.timeEl.textContent);+ }+ if (this.titleEl) this.titleEl.textContent = primary.title;++ if (mode === "active") {+ const diff = Math.max(primary.endDate - now, 0);+ if (this.statusEl) {+ this.statusEl.textContent = primary.isAllDay ? "ALL DAY" : "IN PROGRESS";+ }+ if (this.timerEl) this.timerEl.textContent = formatCountdown(diff);+ this.setTone("urgent");+ } else {+ const diff = Math.max(primary.startDate - now, 0);+ if (this.statusEl) this.statusEl.textContent = "NEXT UP IN";+ if (this.timerEl) this.timerEl.textContent = formatCountdown(diff);+ this.setTone(getToneForDiff(diff));+ }++ this.renderUpNext(upcoming, now);+ }++ setTone(tone) {+ if (!this.container) return;+ this.container.dataset.tone = tone;+ }++ getDisplayState(now) {+ const state = typeof this.getState === "function" ? this.getState() : null;+ const events = state && Array.isArray(state.e) ? state.e : [];+ const colors = state && Array.isArray(state.c) && state.c.length ? state.c : this.fallbackColors;++ const rangeStart = startOfDay(now);+ const rangeEnd = endOfDay(addDays(rangeStart, 1));+ const expanded = expandEvents(events, rangeStart, rangeEnd);+ const decorated = expanded+ .map((occ) => {+ const startDate = new Date(occ.start);+ const endDate = occ.isAllDay ? endOfDay(startDate) : new Date(occ.end);+ return {+ ...occ,+ startDate,+ endDate,+ color: colors[occ.colorIndex] || colors[0] || "#1a73e8",+ };+ })+ .sort((a, b) => a.startDate - b.startDate);++ if (!decorated.length) {+ return { mode: "empty", primary: null, upcoming: [] };+ }++ const timed = decorated.filter((event) => !event.isAllDay);+ const allDay = decorated.filter((event) => event.isAllDay);+ const activeTimed = timed+ .filter((event) => event.startDate <= now && event.endDate > now)+ .sort((a, b) => a.startDate - b.startDate)[0];++ const futureTimed = timed+ .filter((event) => event.startDate > now)+ .sort((a, b) => a.startDate - b.startDate);++ const shouldUseAllDay = !activeTimed && futureTimed.length === 0;+ const activeAllDay = shouldUseAllDay+ ? allDay.find((event) => event.startDate <= now && event.endDate >= now)+ : null;+ const futureAllDay = shouldUseAllDay+ ? allDay+ .filter((event) => event.startDate > now)+ .sort((a, b) => a.startDate - b.startDate)+ : [];++ const active = activeTimed || activeAllDay || null;+ const next = futureTimed[0] || futureAllDay[0] || null;++ if (active) {+ const upcoming = (futureTimed.length ? futureTimed : futureAllDay).slice(0, MAX_UP_NEXT);+ return { mode: "active", primary: active, upcoming };+ }++ if (next) {+ const source = futureTimed.length ? futureTimed : futureAllDay;+ const upcoming = source.filter((event) => event !== next).slice(0, MAX_UP_NEXT);+ return { mode: "upcoming", primary: next, upcoming };+ }++ return { mode: "empty", primary: null, upcoming: [] };+ }++ renderUpNext(list, now) {+ if (!this.upNextList || !this.upNextSection) return;+ this.upNextList.innerHTML = "";+ if (!list || !list.length) {+ this.upNextSection.classList.add("hidden");+ return;+ }+ this.upNextSection.classList.remove("hidden");+ list.forEach((event) => {+ const item = document.createElement("li");+ item.className = "focus-upnext-item";++ const time = document.createElement("span");+ time.className = "focus-upnext-time";+ time.textContent = formatUpNextLabel(event, now);++ const title = document.createElement("span");+ title.className = "focus-upnext-title";+ title.textContent = event.title;++ item.appendChild(time);+ item.appendChild(title);+ this.upNextList.appendChild(item);+ });+ }+}diff --git a/script.js b/script.jsindex e20edd2..afe53b0 100644--- a/script.js+++ b/script.js@@ -1,5 +1,6 @@-import { readStateFromHash, writeStateToHash, isEncryptedHash, clearHash } from "./modules/hashcalUrlManager.js";-import { expandEvents } from "./modules/recurrenceEngine.js";+import { readStateFromHash, writeStateToHash, isEncryptedHash, clearHash } from "./modules/hashcalUrlManager.js";+import { expandEvents } from "./modules/recurrenceEngine.js";+import { FocusMode } from "./modules/focusMode.js";import {formatDateKey,getMonthGridRange,@@ -32,10 +33,11 @@ let currentView = "month";let password = null;let lockState = { encrypted: false, unlocked: true };let saveTimer = null;-let occurrencesByDay = new Map();-let editingIndex = null;-let passwordResolver = null;-let passwordMode = "unlock";+let occurrencesByDay = new Map();+let editingIndex = null;+let passwordResolver = null;+let passwordMode = "unlock";+let focusMode = null;const ui = {};@@ -145,10 +147,11 @@ function cacheElements() {ui.prevMonth = document.getElementById("prev-month");ui.nextMonth = document.getElementById("next-month");ui.todayBtn = document.getElementById("today-btn");- ui.addEventBtn = document.getElementById("add-event");- ui.copyLinkBtn = document.getElementById("copy-link");- ui.lockBtn = document.getElementById("lock-btn");- ui.viewButtons = Array.from(document.querySelectorAll(".view-toggle button"));+ ui.addEventBtn = document.getElementById("add-event");+ ui.copyLinkBtn = document.getElementById("copy-link");+ ui.lockBtn = document.getElementById("lock-btn");+ ui.focusBtn = document.getElementById("focus-btn");+ ui.viewButtons = Array.from(document.querySelectorAll(".view-toggle button"));ui.weekstartToggle = document.getElementById("weekstart-toggle");ui.themeToggle = document.getElementById("theme-toggle");ui.monthLabel = document.getElementById("month-label");@@ -250,12 +253,19 @@ function updateTheme() {}}-function updateWeekStartLabel() {- if (!ui.weekstartToggle) return;- ui.weekstartToggle.textContent = state.s.m ? "Week starts Monday" : "Week starts Sunday";-}--function updateViewButtons() {+function updateWeekStartLabel() {+ if (!ui.weekstartToggle) return;+ ui.weekstartToggle.textContent = state.s.m ? "Week starts Monday" : "Week starts Sunday";+}++function updateFocusButton(isActive) {+ if (!ui.focusBtn) return;+ const active = typeof isActive === "boolean" ? isActive : focusMode && focusMode.isActive();+ ui.focusBtn.textContent = active ? "Exit focus" : "Focus";+ ui.focusBtn.setAttribute("aria-pressed", active ? "true" : "false");+}++function updateViewButtons() {if (!ui.viewButtons || !ui.viewButtons.length) return;ui.viewButtons.forEach((button) => {const isActive = button.dataset.view === currentView;@@ -775,16 +785,25 @@ function handleToday() {render();}-async function handleCopyLink() {- try {- await navigator.clipboard.writeText(window.location.href);- showToast("Link copied", "success");- } catch (error) {- showToast("Unable to copy link", "error");- }-}--function updateJsonModal() {+async function handleCopyLink() {+ try {+ await navigator.clipboard.writeText(window.location.href);+ showToast("Link copied", "success");+ } catch (error) {+ showToast("Unable to copy link", "error");+ }+}++function handleFocusToggle() {+ if (!focusMode) return;+ if (focusMode.isActive()) {+ focusMode.stop();+ } else {+ focusMode.start();+ }+}++function updateJsonModal() {if (ui.jsonOutput) {ui.jsonOutput.value = JSON.stringify(state, null, 2);}@@ -890,11 +909,12 @@ function bindEvents() {button.addEventListener("click", () => setView(button.dataset.view));});}- if (ui.addEventBtn) ui.addEventBtn.addEventListener("click", () => openEventModal({ date: selectedDate }));- if (ui.addEventInline) ui.addEventInline.addEventListener("click", () => openEventModal({ date: selectedDate }));- if (ui.copyLinkBtn) ui.copyLinkBtn.addEventListener("click", handleCopyLink);- if (ui.lockBtn) ui.lockBtn.addEventListener("click", handleLockAction);- if (ui.weekstartToggle) ui.weekstartToggle.addEventListener("click", handleWeekStartToggle);+ if (ui.addEventBtn) ui.addEventBtn.addEventListener("click", () => openEventModal({ date: selectedDate }));+ if (ui.addEventInline) ui.addEventInline.addEventListener("click", () => openEventModal({ date: selectedDate }));+ if (ui.copyLinkBtn) ui.copyLinkBtn.addEventListener("click", handleCopyLink);+ if (ui.lockBtn) ui.lockBtn.addEventListener("click", handleLockAction);+ if (ui.focusBtn) ui.focusBtn.addEventListener("click", handleFocusToggle);+ if (ui.weekstartToggle) ui.weekstartToggle.addEventListener("click", handleWeekStartToggle);if (ui.themeToggle) ui.themeToggle.addEventListener("click", handleThemeToggle);if (ui.unlockBtn) ui.unlockBtn.addEventListener("click", attemptUnlock);if (ui.viewJson) ui.viewJson.addEventListener("click", openJsonModal);@@ -920,16 +940,22 @@ function bindEvents() {window.addEventListener("hashchange", handleHashChange);}-async function init() {- cacheElements();- bindEvents();- await loadStateFromHash();- if (!isEncryptedHash() && !state.e.length && window.location.hash) {- clearHash();- }-- updateViewButtons();- render();+async function init() {+ cacheElements();+ focusMode = new FocusMode({+ getState: () => state,+ fallbackColors: DEFAULT_COLORS,+ onToggle: updateFocusButton,+ });+ bindEvents();+ await loadStateFromHash();+ if (!isEncryptedHash() && !state.e.length && window.location.hash) {+ clearHash();+ }++ updateViewButtons();+ updateFocusButton(false);+ render();if (isEncryptedHash() && !lockState.unlocked) {attemptUnlock();diff --git a/styles.css b/styles.cssindex ce71f37..3a0d50b 100644--- a/styles.css+++ b/styles.css@@ -9,16 +9,20 @@--border-soft: #e6e6e6;--text: #3c4043;--muted: #5f6368;- --accent: #1a73e8;- --accent-soft: rgba(26, 115, 232, 0.12);- --accent-strong: #0b57d0;- --danger: #d93025;- --danger-ink: #ffffff;- --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.12);- --shadow-md: 0 2px 8px rgba(60, 64, 67, 0.16);-}--body[data-theme="dark"] {+ --accent: #1a73e8;+ --accent-soft: rgba(26, 115, 232, 0.12);+ --accent-strong: #0b57d0;+ --danger: #d93025;+ --danger-ink: #ffffff;+ --focus-good: #34a853;+ --focus-warn: #f9ab00;+ --focus-urgent: #ea4335;+ --focus-neutral: var(--text);+ --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.12);+ --shadow-md: 0 2px 8px rgba(60, 64, 67, 0.16);+}++body[data-theme="dark"] {color-scheme: dark;--bg: #202124;--panel: #2b2c2f;@@ -27,14 +31,18 @@ body[data-theme="dark"] {--border-soft: #33363a;--text: #e8eaed;--muted: #9aa0a6;- --accent: #8ab4f8;- --accent-soft: rgba(138, 180, 248, 0.2);- --accent-strong: #a8c7fa;- --danger: #f28b82;- --danger-ink: #1f1f1f;- --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);- --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);-}+ --accent: #8ab4f8;+ --accent-soft: rgba(138, 180, 248, 0.2);+ --accent-strong: #a8c7fa;+ --danger: #f28b82;+ --danger-ink: #1f1f1f;+ --focus-good: #6dd58c;+ --focus-warn: #f5c45d;+ --focus-urgent: #ff8a80;+ --focus-neutral: var(--text);+ --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);+ --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);+}* {box-sizing: border-box;@@ -575,17 +583,184 @@ button:disabled {color: var(--danger);}-.stacked-actions {- display: flex;- flex-direction: column;- gap: 8px;-}--.modal {- position: fixed;- inset: 0;- display: flex;- align-items: center;+.stacked-actions {+ display: flex;+ flex-direction: column;+ gap: 8px;+}++.focus-overlay {+ position: fixed;+ inset: 0;+ z-index: 35;+ display: flex;+ align-items: stretch;+ justify-content: stretch;+ padding: clamp(20px, 4vw, 48px);+ background:+ radial-gradient(circle at top left, var(--accent-soft), transparent 45%),+ radial-gradient(circle at bottom right, rgba(0, 0, 0, 0.08), transparent 40%),+ var(--bg);+ opacity: 0;+ visibility: hidden;+ pointer-events: none;+ transition: opacity 0.25s ease, visibility 0.25s ease;+}++.focus-overlay.is-active {+ opacity: 1;+ visibility: visible;+ pointer-events: auto;+}++.focus-overlay[data-tone="good"] .focus-timer,+.focus-overlay[data-tone="good"] .focus-status {+ color: var(--focus-good);+}++.focus-overlay[data-tone="warn"] .focus-timer,+.focus-overlay[data-tone="warn"] .focus-status {+ color: var(--focus-warn);+}++.focus-overlay[data-tone="urgent"] .focus-timer,+.focus-overlay[data-tone="urgent"] .focus-status {+ color: var(--focus-urgent);+}++.focus-overlay[data-tone="neutral"] .focus-timer {+ color: var(--focus-neutral);+}++.focus-shell {+ flex: 1;+ display: flex;+ flex-direction: column;+ gap: 24px;+ padding: clamp(24px, 5vw, 56px);+ border-radius: 28px;+ background: var(--panel);+ border: 1px solid var(--border);+ box-shadow: var(--shadow-md);+}++.focus-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ font-size: 0.9rem;+ color: var(--muted);+ letter-spacing: 0.08em;+ text-transform: uppercase;+}++.focus-exit {+ border-color: var(--border-soft);+ background: var(--panel-2);+}++.focus-clock {+ font-weight: 600;+ font-size: 0.95rem;+ letter-spacing: 0.12em;+}++.focus-main {+ flex: 1;+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ text-align: center;+ gap: 18px;+}++.focus-status {+ font-size: 0.72rem;+ text-transform: uppercase;+ letter-spacing: 0.35em;+ color: var(--muted);+}++.focus-timer {+ font-family: "SFMono-Regular", "Menlo", "Consolas", "Liberation Mono", monospace;+ font-size: clamp(3rem, 8vw, 6rem);+ font-weight: 700;+ color: var(--focus-neutral);+ letter-spacing: 0.08em;+}++.focus-title {+ font-size: clamp(1.6rem, 3vw, 2.4rem);+ font-weight: 600;+}++.focus-event {+ display: flex;+ flex-direction: column;+ gap: 6px;+ align-items: center;+}++.focus-time {+ font-size: 1rem;+ color: var(--muted);+}++.focus-upnext {+ align-self: flex-start;+ display: flex;+ flex-direction: column;+ gap: 10px;+ max-width: 520px;+}++.focus-upnext-label {+ font-size: 0.7rem;+ text-transform: uppercase;+ letter-spacing: 0.25em;+ color: var(--muted);+}++.focus-upnext-list {+ list-style: none;+ margin: 0;+ padding: 0;+ display: flex;+ flex-direction: column;+ gap: 8px;+}++.focus-upnext-item {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+ padding: 8px 12px;+ border-radius: 10px;+ background: var(--panel-2);+ border: 1px solid var(--border-soft);+ font-size: 0.9rem;+}++.focus-upnext-time {+ font-size: 0.78rem;+ color: var(--muted);+ letter-spacing: 0.04em;+ text-transform: uppercase;+ flex-shrink: 0;+}++.focus-upnext-title {+ font-weight: 600;+ text-align: right;+}++.modal {+ position: fixed;+ inset: 0;+ display: flex;+ align-items: center;justify-content: center;z-index: 20;}@@ -797,11 +972,11 @@ button:disabled {}}-@media (max-width: 720px) {- .topbar {- height: auto;- padding: 12px 16px;- flex-direction: column;+@media (max-width: 720px) {+ .topbar {+ height: auto;+ padding: 12px 16px;+ flex-direction: column;align-items: flex-start;gap: 12px;}@@ -810,12 +985,36 @@ button:disabled {grid-template-columns: 1fr;}- .panel-header {- flex-direction: column;- align-items: flex-start;- }-- .field-row {- grid-template-columns: 1fr;- }-}+ .panel-header {+ flex-direction: column;+ align-items: flex-start;+ }++ .field-row {+ grid-template-columns: 1fr;+ }++ .focus-shell {+ padding: 24px;+ border-radius: 20px;+ }++ .focus-header {+ flex-direction: column;+ align-items: flex-start;+ gap: 10px;+ }++ .focus-upnext {+ align-self: stretch;+ }++ .focus-upnext-item {+ flex-direction: column;+ align-items: flex-start;+ }++ .focus-upnext-title {+ text-align: left;+ }+}diff --git a/task.md b/task.mdnew file mode 100644index 0000000..9b77161--- /dev/null+++ b/task.md@@ -0,0 +1,198 @@+This proposal outlines the implementation plan for the **Countdown/Focus Mode** feature for the `supunlakmal/hash-calendar` project. This document is designed to guide a developer through the integration process while strictly adhering to the project's architectural constraints (Vanilla JS, modularity) and design philosophy.++---++# Feature Project Proposal: Focus Mode (Productivity Dashboard)++## 1. Executive Summary++The **Focus Mode** module transforms the `hash-calendar` from a passive planning tool into an active, "second-screen" productivity monitor. By toggling a specialized UI layer, the complex grid is hidden, and the user is presented with a minimalist interface displaying only the most critical information: the **Current Active Event** or the **Countdown to the Next Event**.++## 2. Motivation (The "Why")++- **User Pain Point:** The traditional calendar grid (Month/Week view) is excellent for planning but cluttered for moment-to-moment tracking. Users constantly switch tabs to check "How much time until my next meeting?"+- **Value Proposition:** Provides a zero-distraction view perfect for leaving on a side monitor. It keeps the user in "flow state" by removing visual noise.++## 3. UI/UX Design & Aesthetics++### Visual Style++- **Philosophy:** Extreme Minimalism. Large typography, high contrast, ample whitespace.+- **Color Logic:**+ - **Neutral/Green:** > 30 minutes until next event.+ - **Orange:** < 10 minutes until next event.+ - **Red:** < 2 minutes (Urgent) or Event in progress.+- **Transition:** A smooth fade-in/out transition when toggling between Grid View and Focus View to maintain the "App-like" feel.++### Mockup Structure++The view will act as an overlay covering the `#calendar-container`.++```text++-------------------------------------------------------++| [Exit Focus Mode (x)] 10:42 AM |+| |+| NEXT UP IN: |+| |+| 00 : 14 : 35 |+| (Hr) (Min) (Sec) |+| |+| 🚀 Daily Standup Meeting |+| 11:00 AM - 11:30 AM |+| |+| |+| Up Later: |+| • 2:00 PM: Design Review |++-------------------------------------------------------++```++## 4. Technical Architecture++### Core Constraints++- **No Library Dependencies:** Must use native `Date` objects and `requestAnimationFrame` or `setInterval`.+- **Zero URL Impact:** This is a _view state_, not data state. Toggling this mode **does not** need to update the hash string, keeping the URL short.+- **Modules:** Logic must be encapsulated in a new module.++### File Structure Changes++1. **New File:** `/modules/focusMode.js` (Handles logic, rendering, and timers).+2. **Modify:** `style.css` (New styling for the dashboard).+3. **Modify:** `index.html` (Add a container div for the Focus View, hidden by default).+4. **Modify:** `script.js` (Initialize the module and attach event listener to the toolbar).++## 5. Implementation Details++### A. The Data Logic (`focusMode.js`)++We need a function `getNextEvent(eventsArray)` that:++1. Takes the global `state.events`.+2. Parses recurrences (using existing `recurrenceEngine.js`) to expand recurring events for "Today."+3. Filters out events that have `endTime < now`.+4. Sorts by `startTime`.+5. Returns the object representing the immediate next event.++### B. The Render Loop++Instead of a static render, this view is live.++- Use a `setInterval` running every 1000ms.+- Calculate `delta = event.startTime - Date.now()`.+- Update the DOM element containing the timer string.+- If `delta` reaches 0, switch UI to "Event In Progress" mode.++### C. CSS & Aesthetics++Classes should reuse the project's existing variables (e.g., `--main-color`) to support Dark/Light mode automatically.++```css+/* style.css draft */+#focus-mode-overlay {+ position: fixed;+ top: 0;+ left: 0;+ width: 100vw;+ height: 100vh;+ background: var(--bg-color);+ z-index: 999;+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+}+.timer-big {+ font-size: 5rem;+ font-weight: 700;+ font-family: monospace; /* Monospaced prevents jittering numbers */+}+```++## 6. Implementation Steps++### Phase 1: Setup++1. Add a generic `<button id="btn-focus">Focus</button>` to the top navigation bar.+2. Create `<div id="focus-overlay" class="hidden">...</div>` in `index.html`.++### Phase 2: Logic Development (The Filter)++1. Create `modules/focusMode.js`.+2. Import `recurrenceEngine` to ensure we catch recurring daily meetings.+3. Write the algorithm to find the nearest future event.++### Phase 3: The Countdown Engine++1. Write the timer logic.+2. Format milliseconds into `HH:MM:SS`.+3. Handle the edge case where no events exist for the rest of the day ("All Clear!").++### Phase 4: UI Integration++1. Hook up the "Focus" button to unhide the overlay and start the timer interval.+2. Hook up the "Exit" button to clear the interval (to save resources) and hide the overlay.++## 7. Code Spec (Draft for `focusMode.js`)++```javascript+export class FocusMode {+ constructor(eventData, recurrenceEngine) {+ this.events = eventData;+ this.recurrence = recurrenceEngine;+ this.timerInterval = null;+ this.container = document.getElementById("focus-overlay");+ }++ findNextEvent() {+ const now = new Date();+ // 1. Expand recurring events for today+ // 2. Filter events where event.end > now+ // 3. Sort by start date+ // 4. Return list[0]+ }++ start() {+ this.container.classList.remove("hidden");+ this.render(); // Initial render+ this.timerInterval = setInterval(() => this.tick(), 1000);+ }++ tick() {+ const next = this.findNextEvent();+ if (!next) {+ this.renderEmptyState();+ return;+ }++ const now = new Date();+ const diff = next.startTime - now;++ // Check if event is currently happening+ if (diff <= 0 && next.endTime > now) {+ this.renderActiveState(next);+ } else {+ this.renderCountdown(next, diff);+ }+ }++ stop() {+ clearInterval(this.timerInterval);+ this.container.classList.add("hidden");+ }+}+```++## 8. Expected Challenges & Solutions++- **Challenge:** Recurrence Logic complexity.+ - **Solution:** Do not reinvent the wheel. Utilize the existing `recurrenceEngine.js` `getEventsForDate` function. Generate events for _Today_ and _Tomorrow_ only, merge them, then filter. This keeps performance high.+- **Challenge:** Time Zones.+ - **Solution:** All math uses `Date.now()` (UTC timestamp comparisons) to remain agnostic, rendering formatted time strings only at the last step.++## 9. Definition of Done++1. [ ] Clicking "Focus" replaces the grid with the overlay.+2. [ ] The countdown decrements accurately every second.+3. [ ] Dark mode toggle works inside Focus Mode.+4. [ ] Pressing "Esc" exits Focus Mode.+5. [ ] No extra data is added to the URL hash.