/** * The one owner of the {@link SettingsOverride}: what it is, how it changes, * who hears about it, and how it reverts to the resolved config. * * Both the panel bundle and the page runtime import this file, so it is * plain TypeScript: no Vite, no DOM, no panel UI. Everything environmental * comes in through ports ({@link OverrideStorage}, {@link LivePort}, * {@link DurablePort}); the module owns the rest: the `localStorage` keys and * their JSON, baseline capture, the config -> override key map, the * hydrate/adopt loop guard and reset-to-env. * * Adding an overridable setting or a pure preference means adding its entry * to `SETTINGS` in `setting-definitions.ts`; the key map and the defaults * here are derived from it. * * The panel's color scheme rides along: it is not part of the override (the * page never sees it), but it is stored, persisted and adopted the same way, * so it goes through the same loop guard. */ import { type FeatureSettings, type SettingsOverride } from '../types/timeline.js'; import { type OverridableKey, type PreferenceKey, type SettingValue } from './setting-definitions.js'; /** * Overridable settings that have a config baseline: each reads the resolved * value out of the plugin's {@link FeatureSettings}. The config -> override * key map, derived from the Setting definitions. */ export declare const CONFIG_KEYS: { [K in OverridableKey]: (s: FeatureSettings) => SettingValue; }; export type { OverridableKey }; /** * Pure preferences: no config-time baseline, so they revert to these when * the overrides are reset. */ export declare const PREFERENCE_DEFAULTS: { [K in PreferenceKey]: SettingValue; }; /** * The resolved config value each overridden key was set against, recorded so * the Settings tab can notice when `.env` or plugin options moved on. Kept * beside the {@link SettingsOverride}, never inside it: the runtime applies * and receives the override as-is and has no use for these. */ export type OverrideBaselines = Partial>; /** The resolved config value of every overridable setting. */ export declare const configValues: (config: FeatureSettings) => Required>; /** The pure preferences of an override, each its default when unset. */ export declare const preferences: (o: SettingsOverride) => Record; /** The panel's color scheme; `auto` follows the host. */ export type ColorSchemePreference = 'auto' | 'dark' | 'light'; /** localStorage key for the {@link ColorSchemePreference}. */ export declare const COLOR_SCHEME_LS_KEY = "lit-devtools-color-scheme"; /** A stored color scheme, or `auto` for anything unrecognised. */ export declare const parseColorScheme: (raw: unknown) => ColorSchemePreference; /** The slice of `Storage` the module needs; `localStorage` satisfies it. */ export type OverrideStorage = Pick; /** * The live channel to the running page. `push` sends an override out (the * panel's RPC); `listen` receives one (the page runtime's channel). Either may * be absent: the panel never listens, the runtime never pushes. Best-effort. */ export interface LivePort { push?(override: SettingsOverride): void; listen?(cb: (override: SettingsOverride) => void): void; } /** The durable per-user store (devframe's settings). Best-effort. */ export interface DurablePort { set(key: 'override', value: SettingsOverride): void; set(key: 'overrideBaselines', value: OverrideBaselines): void; set(key: 'appearance', value: ColorSchemePreference): void; delete(key: 'override' | 'overrideBaselines'): void; } export interface OverridePorts { storage: OverrideStorage; live?: LivePort; durable?: DurablePort; /** Applies a color scheme to the panel; the page has none to apply. */ readonly applyAppearance?: (scheme: ColorSchemePreference) => void; } /** A snapshot from the durable store, as `adopt` receives it. */ export interface DurableSnapshot { override?: SettingsOverride; overrideBaselines?: OverrideBaselines; appearance?: ColorSchemePreference; } export interface SettingsOverrides { /** The current override; `{}` when unset or unparsable. */ get(): SettingsOverride; /** The config values the current overrides were made against; `{}` if none. */ baselines(): OverrideBaselines; /** * Change one setting: local, durable and live copies, then subscribers. For * a key with a config baseline and a `config`, the baseline is recorded too * (local and durable; never sent live). */ set(key: K, value: SettingsOverride[K], config?: FeatureSettings): void; /** * Drop every override. With `config`, the resolved values (and preference * defaults) are pushed live so the page reverts now. */ reset(config?: FeatureSettings): void; /** Drop one key, reverting it live to its config value. */ resetKey(key: OverridableKey, config: FeatureSettings): void; /** Re-stamp one key's baseline to the config value it has now ("Keep"). */ keep(key: OverridableKey, config: FeatureSettings): void; /** The panel's color scheme; `auto` when unset. */ appearance(): ColorSchemePreference; /** Change the color scheme: local and durable copies, then apply it. */ setAppearance(scheme: ColorSchemePreference): void; /** * A snapshot that arrived from the durable store: mirror it locally (and the * override live) without writing it back. A no-op (returns `false`) when it * already matches, which is what stops adopt -> store write -> onChange -> * adopt looping. */ adopt(snapshot: DurableSnapshot): boolean; /** * Fires with the override after every change made through this module, and * with whatever the live port delivers. Not for external storage writes. * Returns the unsubscribe function. */ subscribe(cb: (override: SettingsOverride) => void): () => void; } export declare const createSettingsOverrides: (ports: OverridePorts) => SettingsOverrides; //# sourceMappingURL=settings-override.d.ts.map