Appearance
Plugins API
Signatures for @idlekitjs/plugins. Concepts and usage on each plugin's page.
Autosave
ts
import { autosave, SaveScheduler } from "@idlekitjs/plugins/autosave";
function autosave<T extends object>(options: AutosaveOptions<T>): Extension<T>;
interface AutosaveOptions<T extends object> {
manager: SaveManager<T>; // required — throws at wiring time if missing
getState: () => T; // required — must return the LIVE state
intervalMs?: number; // periodic interval; 0/omitted = lifecycle saves only
}Saves on: the interval (if > 0), visibilitychange → hidden, and pagehide. Listeners are attached in setup and removed in teardown.
SaveScheduler<T>
The scheduling core, public for imperative use ("Save now" buttons):
ts
new SaveScheduler<T>({ manager, getState, intervalMs? });| Method | Behavior |
|---|---|
start() | Attach interval + lifecycle listeners |
save() | Promise<void> — immediate save |
stop() | Detach everything |
Offline progress
ts
import { offlineProgress } from "@idlekitjs/plugins/offline-progress";
function offlineProgress<T extends object>(options?: OfflineProgressOptions): Extension<T>;
interface OfflineProgressOptions {
maxMs?: number; // cap on credited time; default 24 h
}On loaded(savedAt): credits Date.now() - savedAt. On resume(elapsedMs): credits elapsedMs. Both clamped to [0, maxMs], then engine.advance(capped / 1000). Guards: invalid maxMs falls back to the default; negative elapsed times are ignored.
Page lifecycle
Use pageLifecycle from @idlekitjs/browser/page-lifecycle to bridge the Page Visibility API into pause(), resume() and the engine resume event.