mirror of
https://github.com/hectorqin/reader.git
synced 2026-11-11 13:31:09 +08:00
白纸 / 暖黄 / 浅绿 / 灰调 / 夜间 (prototypes 4 and 23) tint only the reading page — paper, ink, readouts — while the chrome keeps the reading theme. Stored per device in AppSettings (paper, paperFollowsDark), set from the reader's 外观 sheet or 外观与主题. 夜间 makes the reader dark; a light paper gives way to the theme's dark values while the app is dark unless 跟随系统深色模式 is off. Old sepia/green/dark page themes migrate to the matching paper. Tokens are mirrored in TS and CSS and held to contrast by theme-tokens.test.ts.
32 lines
1.6 KiB
TypeScript
32 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { SettingsStore } from '../src/store/settings.ts';
|
|
import type { KeyValueStore } from '../src/core/platform.ts';
|
|
|
|
/** A KeyValueStore over a Map, for SettingsStore.load(). */
|
|
function memory(initial: Record<string, string>): KeyValueStore {
|
|
const values = new Map(Object.entries(initial));
|
|
return { get: async (key: string) => values.get(key) ?? null, set: async (key: string, value: string) => { values.set(key, value); }, remove: async (key: string) => { values.delete(key); } };
|
|
}
|
|
const load = (stored: object) => new SettingsStore(memory({ 'reader.settings.v1': JSON.stringify(stored) })).load();
|
|
|
|
describe('reading paper setting', () => {
|
|
it('defaults to the theme, following the system dark mode', async () => {
|
|
const settings = await new SettingsStore(memory({})).load();
|
|
expect([settings.paper, settings.paperFollowsDark]).toEqual(['theme', true]);
|
|
});
|
|
|
|
it('brings the pre-V3 page theme back as the matching paper, once', async () => {
|
|
expect((await load({ theme: 'sepia' })).paper).toBe('warm');
|
|
expect((await load({ theme: 'green' })).paper).toBe('green');
|
|
expect((await load({ theme: 'dark' })).paper).toBe('night');
|
|
expect((await load({ theme: 'light' })).paper).toBe('theme');
|
|
// A paper chosen since wins over the old value.
|
|
expect((await load({ theme: 'dark', paper: 'white' })).paper).toBe('white');
|
|
});
|
|
|
|
it('ignores an unknown paper or a malformed switch', async () => {
|
|
const settings = await load({ paper: 'sepia', paperFollowsDark: 'yes' });
|
|
expect([settings.paper, settings.paperFollowsDark]).toEqual(['theme', true]);
|
|
});
|
|
});
|