Phase F of the AFFiNE plan (ADR-16): - Calendars: people subscribe to iCal feeds (webcal, Google's secret address, Outlook) or CalDAV accounts in account settings; their events show at the top of journal pages in the reader's time zone. Repeats, moved and cancelled occurrences, IANA and Windows zones are handled. Events are read on demand and kept in memory for 15 minutes; passwords are sealed with DOCWELL_SECRET_KEY; sources follow the webhook address rules. New calendar_accounts collection. - Importers: zips of Markdown (Obsidian vaults, Bear TextBundles and .bear2bk, Readwise's Markdown, Docwell's own space export) keep folders as pages, resolve [[wikilinks]] and embeds by name, and turn front matter and #tags into properties and tags. OneNote .mht exports, Readwise CSV, and any other CSV as a database page. - Exports: PNG of a page drawn in the browser, print styles that print only the page in the light theme, and workspace snapshots (records, Yjs states, JSON and files in one zip) that restore as a new workspace. Old ids are swapped byte for byte inside the Yjs updates, so links point at the restored pages and comments stay anchored. - Web-Clipper/: a Manifest V3 extension for Chrome, Edge and Firefox that saves the article or the selection as Markdown through the import API with a personal API token. - OpenAPI, generated clients, translations and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import { ref, watchEffect } from "vue";
|
|
|
|
export type ThemeMode = "system" | "light" | "dark";
|
|
|
|
const STORAGE_KEY = "docwell.theme";
|
|
const mode = ref<ThemeMode>(readStoredMode());
|
|
|
|
function readStoredMode(): ThemeMode {
|
|
try {
|
|
const v = localStorage.getItem(STORAGE_KEY);
|
|
if (v === "light" || v === "dark" || v === "system") return v;
|
|
} catch {
|
|
// Storage can be unavailable (private mode, webviews); fall back to system.
|
|
}
|
|
return "system";
|
|
}
|
|
|
|
let started = false;
|
|
|
|
/** Shared light/dark/system theme state; toggles the `dark` class on <html>. */
|
|
export function useTheme() {
|
|
if (!started && typeof window !== "undefined") {
|
|
started = true;
|
|
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
const apply = () => {
|
|
const dark = mode.value === "dark" || (mode.value === "system" && media.matches);
|
|
document.documentElement.classList.toggle("dark", dark);
|
|
};
|
|
media.addEventListener("change", apply);
|
|
// Paper is light: print in the light theme, then put the chosen one back.
|
|
window.addEventListener("beforeprint", () => document.documentElement.classList.remove("dark"));
|
|
window.addEventListener("afterprint", apply);
|
|
watchEffect(() => {
|
|
apply();
|
|
try {
|
|
localStorage.setItem(STORAGE_KEY, mode.value);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
});
|
|
}
|
|
return { mode };
|
|
}
|