Official
themes
The stock themes: presets of every colour, type size, corner, density token and background, chosen per light and dark mode and edited in Settings, beside the themes other plugins ship.
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/themes@0.3.4
Permissions in 0.3.4
Files
presets.test.ts7.6 KB
// The presets, the settings that pick them, and the editor's typed fields.
import assert from "node:assert/strict";
import test from "node:test";
import type { Api, ViewContext } from "divergence";
import { allPresets, chosen, duplicate, readSettings, STOCK } from "./settings-model.ts";
test("every stock preset is unique and names its mode", () => {
const ids = STOCK.map((preset) => preset.id);
assert.equal(new Set(ids).size, ids.length);
for (const preset of STOCK) assert.equal(preset.tokens.mode, preset.mode);
for (const family of ["divergence", "vscode", "high-contrast", "compact"])
for (const mode of ["light", "dark"]) assert.ok(ids.includes(`${family}-${mode}`), `${family}-${mode}`);
assert.equal(STOCK.find((preset) => preset.id === "divergence-dark")!.name, "Divergence Dark");
assert.equal(STOCK.find((preset) => preset.id === "divergence-light")!.name, "Divergence Light");
});
test("a mode without a choice, or with a gone one, draws the Divergence preset", () => {
assert.equal(chosen({ presets: {}, active: {} }, "dark").id, "divergence-dark");
assert.equal(chosen({ presets: {}, active: { light: "deleted" } }, "light").id, "divergence-light");
assert.equal(chosen({ presets: {}, active: { dark: "vscode-dark" } }, "dark").id, "vscode-dark");
// A preset of the other mode is not drawn for this one.
assert.equal(chosen({ presets: {}, active: { dark: "vscode-light" } }, "dark").id, "divergence-dark");
});
test("a duplicate is a user preset with an id and a name of its own", () => {
const source = STOCK.find((preset) => preset.id === "vscode-dark")!;
const copy = duplicate(source, STOCK);
assert.equal(copy.name, "VS Code Dark Modern copy");
assert.equal(copy.mode, "dark");
assert.equal(copy.stock, undefined);
assert.equal(copy.tokens.name, "VS Code Dark Modern copy");
assert.notEqual(copy.tokens.colors, source.tokens.colors, "the copy's tokens are its own");
// Duplicating the same preset again names the second copy apart from the first.
const again = duplicate(source, [...STOCK, copy]);
assert.equal(again.name, "VS Code Dark Modern copy 2");
assert.notEqual(again.id, copy.id);
});
test("a malformed settings file keeps what is well formed", () => {
const settings = readSettings({
presets: { good: { name: "Mine", mode: "dark", tokens: {} }, bad: { name: 3 } },
active: "nonsense",
});
assert.deepEqual(Object.keys(settings.presets), ["good"]);
assert.deepEqual(settings.active, {});
assert.equal(allPresets(settings).at(-1)?.id, "good");
});
test("a typed size waits for Enter, so typing 14 never applies 1 on the way", async () => {
const { render } = await import("./settings.tsx");
const { nodes } = await import("../sdk/ui-testing.ts");
const values: Record<string, unknown> = { presets: { mine: { name: "Mine", mode: "dark", tokens: {} } }, active: {} };
const saved: { mine?: { tokens: { type?: { textSize?: number } } } }[] = [];
const api = {
settings: {
get: () => values,
set: async (key: string, value: (typeof saved)[number]) => {
saved.push(value);
values[key] = value;
},
},
} as unknown as Api;
const ctx = { update() {} } as unknown as ViewContext<object>;
const find = (id: string) => nodes(render(ctx, api)).find((node) => node.id === id) as Record<string, (event?: unknown) => void>;
find("preset-mine").onClick!();
find("preset-type-textSize").onChange!({ value: "1" });
find("preset-type-textSize").onChange!({ value: "14" });
assert.equal(saved.length, 0, "nothing applies while typing");
find("preset-type-textSize").onSubmit!();
assert.equal(saved.at(-1)?.mine?.tokens.type?.textSize, 14);
assert.equal(saved.length, 1);
});
test("a plugin's theme is a read-only preset that can be chosen, and a gone one falls back", () => {
const harbour = { id: "harbour/dark", plugin: "harbour", name: "Harbour", mode: "dark" as const, tokens: { name: "Harbour", mode: "dark" as const } };
const presets = allPresets({ presets: {}, active: {} }, [harbour]);
assert.equal(presets.find((preset) => preset.id === "harbour/dark")?.from, "harbour");
assert.equal(chosen({ presets: {}, active: { dark: "harbour/dark" } }, "dark", [harbour]).name, "Harbour");
assert.equal(chosen({ presets: {}, active: { dark: "harbour/dark" } }, "dark").id, "divergence-dark", "the plugin is gone");
const copy = duplicate(presets.find((preset) => preset.id === "harbour/dark")!, presets);
assert.equal(copy.from, undefined, "a copy is the user's own");
});
test("a place's backdrop is set, changed in kind and veil, and removed", async () => {
const { kindOf, startOf, withBackdrop, withGlass } = await import("./backdrops.ts");
let tokens = withBackdrop({ name: "Mine" }, "chat", { image: "/data/backdrops/a.jpg", glass: { opacity: 0.5 } });
assert.equal(kindOf(tokens.backdrop?.["chat"]), "image");
assert.equal(kindOf(tokens.backdrop?.["newChat"]), "none");
const fog = startOf("fog", tokens.backdrop?.["chat"], "#101010");
assert.deepEqual(fog, { scene: "fog", glass: { opacity: 0.5 } }, "the veil stays across kinds");
const faster = startOf("caustics", { ...fog, speed: 2, color: "#7c3aed" }, "#101010");
assert.deepEqual(faster, { scene: "caustics", speed: 2, color: "#7c3aed", glass: { opacity: 0.5 } }, "a scene keeps its hue and speed");
assert.equal(kindOf(startOf("gradient", undefined, "#101010")), "gradient");
assert.equal(kindOf(startOf("color", undefined, "#101010")), "color");
assert.equal(withGlass(fog, { opacity: 0 }).glass, undefined, "no veil and no blur is no glass");
assert.deepEqual(withGlass(fog, { opacity: 0, blur: 8 }).glass, { opacity: 0, blur: 8 });
tokens = withBackdrop(tokens, "chat", undefined);
assert.equal(tokens.backdrop, undefined, "a preset with no backdrop left names none");
assert.equal(tokens.name, "Mine");
});
test("choosing a place's background writes it to the open preset at once", async () => {
const { render } = await import("./settings.tsx");
const { nodes } = await import("../sdk/ui-testing.ts");
const values: Record<string, unknown> = { presets: { mine: { name: "Mine", mode: "dark", tokens: { colors: { background: "#181818" } } } }, active: {} };
type Saved = { mine: { tokens: { backdrop?: Record<string, unknown> } } };
const saved: Saved[] = [];
const api = {
settings: {
get: () => values,
set: async (key: string, value: Saved) => {
saved.push(value);
values[key] = value;
},
},
} as unknown as Api;
const ctx = { update() {} } as unknown as ViewContext<object>;
const find = (id: string) => nodes(render(ctx, api)).find((node) => node.id === id) as Record<string, (event?: unknown) => void>;
find("preset-mine").onClick!();
find("backdrop-newChat").onChange!({ value: "contours" });
await new Promise((resolve) => setTimeout(resolve));
assert.deepEqual(saved.at(-1)?.mine.tokens.backdrop, { newChat: { scene: "contours" } });
find("backdrop-newChat-speed").onChange!({ value: "0.5" });
find("backdrop-newChat-speed").onSubmit!();
find("backdrop-newChat-veil").onChange!({ value: "0.3" });
find("backdrop-newChat-veil").onSubmit!();
await new Promise((resolve) => setTimeout(resolve));
assert.deepEqual(saved.at(-1)?.mine.tokens.backdrop, { newChat: { scene: "contours", speed: 0.5, glass: { opacity: 0.3 } } });
find("backdrop-chat").onChange!({ value: "color" });
await new Promise((resolve) => setTimeout(resolve));
assert.deepEqual(saved.at(-1)?.mine.tokens.backdrop?.["chat"], { fill: "#181818" }, "a colour starts at the preset's background");
find("backdrop-newChat").onChange!({ value: "none" });
await new Promise((resolve) => setTimeout(resolve));
assert.deepEqual(Object.keys(saved.at(-1)?.mine.tokens.backdrop ?? {}), ["chat"]);
});
No comments yet.