@creator-notes/cnotes 0.137.0 → 0.138.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/dist/commands/theme.js +61 -7
- package/dist/lib/themes.js +23 -0
- package/package.json +1 -1
package/dist/commands/theme.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ApiClient } from "../lib/api-client.js";
|
|
|
2
2
|
import { resolveBaseConfig } from "../lib/config.js";
|
|
3
3
|
import { AuthError, ValidationError, handleError } from "../lib/errors.js";
|
|
4
4
|
import { outputJson, outputTable } from "../lib/output.js";
|
|
5
|
-
import { PRESETS, PRESET_IDS, EDITABLE_TOKEN_NAMES, EDITABLE_TOKEN_NAME_SET, hslTripleToHex, parseColorInput, } from "../lib/themes.js";
|
|
5
|
+
import { PRESETS, PRESET_IDS, EDITABLE_TOKEN_NAMES, EDITABLE_TOKEN_NAME_SET, hslTripleToHex, parseColorInput, SYSTEM_THEME_ID, describeSystemThemes, systemHalfError, } from "../lib/themes.js";
|
|
6
6
|
function requireAuthedConfig(program) {
|
|
7
7
|
const cfg = resolveBaseConfig(program.opts());
|
|
8
8
|
if (!cfg.token)
|
|
@@ -25,6 +25,7 @@ export function registerThemeCommands(program) {
|
|
|
25
25
|
outputJson({
|
|
26
26
|
current: current.themeId,
|
|
27
27
|
customBaseId: current.customBaseId,
|
|
28
|
+
systemThemes: current.systemThemes,
|
|
28
29
|
presets: PRESETS.map((p) => ({
|
|
29
30
|
id: p.id,
|
|
30
31
|
name: p.name,
|
|
@@ -45,6 +46,10 @@ export function registerThemeCommands(program) {
|
|
|
45
46
|
if (current.themeId === "custom") {
|
|
46
47
|
console.log(`\nActive: custom (based on ${current.customBaseId}, ${Object.keys(current.customColors).length} overrides)`);
|
|
47
48
|
}
|
|
49
|
+
else if (current.themeId === SYSTEM_THEME_ID && current.systemThemes) {
|
|
50
|
+
console.log(`\nActive: ${describeSystemThemes(current.systemThemes)}`);
|
|
51
|
+
}
|
|
52
|
+
console.log("Follow the operating system with `cnotes theme set system --light <id> --dark <id>`.");
|
|
48
53
|
}
|
|
49
54
|
catch (error) {
|
|
50
55
|
handleError(error, cfg.json);
|
|
@@ -63,7 +68,16 @@ export function registerThemeCommands(program) {
|
|
|
63
68
|
return;
|
|
64
69
|
}
|
|
65
70
|
console.log(`themeId: ${data.themeId}`);
|
|
66
|
-
|
|
71
|
+
if (data.themeId === SYSTEM_THEME_ID) {
|
|
72
|
+
console.log("mode: follows the operating system");
|
|
73
|
+
if (data.systemThemes) {
|
|
74
|
+
console.log(`light: ${data.systemThemes.light}`);
|
|
75
|
+
console.log(`dark: ${data.systemThemes.dark}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.log(`mode: ${data.isDark ? "dark" : "light"}`);
|
|
80
|
+
}
|
|
67
81
|
if (data.themeId === "custom") {
|
|
68
82
|
console.log(`customBaseId: ${data.customBaseId}`);
|
|
69
83
|
}
|
|
@@ -89,11 +103,42 @@ export function registerThemeCommands(program) {
|
|
|
89
103
|
});
|
|
90
104
|
theme
|
|
91
105
|
.command("set")
|
|
92
|
-
.description("Switch to a built-in theme preset")
|
|
93
|
-
.argument("<id>", "Preset ID (run `cnotes theme list` to see all)")
|
|
94
|
-
.
|
|
106
|
+
.description("Switch to a built-in theme preset, or to `system` to follow the operating system")
|
|
107
|
+
.argument("<id>", "Preset ID, or `system` (run `cnotes theme list` to see all)")
|
|
108
|
+
.option("--light <id>", "With `system`: the light theme to use while the operating system is light")
|
|
109
|
+
.option("--dark <id>", "With `system`: the dark theme to use while the operating system is dark")
|
|
110
|
+
.action(async (id, opts) => {
|
|
95
111
|
const cfg = requireAuthedConfig(program);
|
|
96
112
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
113
|
+
if (id === SYSTEM_THEME_ID) {
|
|
114
|
+
for (const half of ["light", "dark"]) {
|
|
115
|
+
const chosen = opts[half];
|
|
116
|
+
const problem = chosen === undefined ? null : systemHalfError(half, chosen);
|
|
117
|
+
if (problem)
|
|
118
|
+
throw new ValidationError(problem);
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const data = await api.put("/api/theme", {
|
|
122
|
+
themeId: SYSTEM_THEME_ID,
|
|
123
|
+
...(opts.light ? { systemLightThemeId: opts.light } : {}),
|
|
124
|
+
...(opts.dark ? { systemDarkThemeId: opts.dark } : {}),
|
|
125
|
+
});
|
|
126
|
+
if (cfg.json) {
|
|
127
|
+
outputJson(data);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
console.log(`Theme set to ${data.systemThemes ? describeSystemThemes(data.systemThemes) : "Match system"}.`);
|
|
131
|
+
console.log("Reload an open browser tab to see the change.");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
handleError(error, cfg.json);
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (opts.light !== undefined || opts.dark !== undefined) {
|
|
140
|
+
throw new ValidationError("--light and --dark only go with `cnotes theme set system`.");
|
|
141
|
+
}
|
|
97
142
|
if (id === "custom") {
|
|
98
143
|
throw new ValidationError("`cnotes theme set custom` is not supported. Use `cnotes theme set-color <token> <color>` to enter custom mode (it seeds the base palette atomically).");
|
|
99
144
|
}
|
|
@@ -119,7 +164,8 @@ export function registerThemeCommands(program) {
|
|
|
119
164
|
.description("Override a single token color (switches theme to 'custom')")
|
|
120
165
|
.argument("<token>", "Editable token name (e.g. primary, background)")
|
|
121
166
|
.argument("<color>", 'HSL ("310 85% 67%"), HSL with alpha ("310 85% 67% / 0.5"), hex ("#ff00aa"), or "transparent"')
|
|
122
|
-
.
|
|
167
|
+
.option("--base <id>", "Preset to start the custom theme from (needed under Match system)")
|
|
168
|
+
.action(async (token, color, opts) => {
|
|
123
169
|
const cfg = requireAuthedConfig(program);
|
|
124
170
|
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
125
171
|
if (!EDITABLE_TOKEN_NAME_SET.has(token)) {
|
|
@@ -135,8 +181,16 @@ export function registerThemeCommands(program) {
|
|
|
135
181
|
// We still need the current themeId to seed customBaseId on the
|
|
136
182
|
// first transition into custom — once we're already custom, the
|
|
137
183
|
// server preserves the existing base.
|
|
184
|
+
if (opts.base !== undefined && !PRESET_IDS.has(opts.base)) {
|
|
185
|
+
throw new ValidationError(`Unknown theme id: ${opts.base}. Run \`cnotes theme list\` to see available presets.`);
|
|
186
|
+
}
|
|
138
187
|
const current = await api.get("/api/theme");
|
|
139
|
-
|
|
188
|
+
// Match system paints a different theme on each device, so there is
|
|
189
|
+
// no one theme to fork: the caller names it.
|
|
190
|
+
if (current.themeId === SYSTEM_THEME_ID && opts.base === undefined) {
|
|
191
|
+
throw new ValidationError("Your theme follows the operating system, so there is no single theme to start from. Pass --base <id>, for example --base light.");
|
|
192
|
+
}
|
|
193
|
+
const customBaseId = opts.base ?? (current.themeId === "custom" ? undefined : current.themeId);
|
|
140
194
|
const data = await api.patch("/api/theme/colors", {
|
|
141
195
|
customColors: { [token]: normalized },
|
|
142
196
|
...(customBaseId ? { customBaseId } : {}),
|
package/dist/lib/themes.js
CHANGED
|
@@ -44,6 +44,29 @@ export const EDITABLE_TOKEN_NAMES = [
|
|
|
44
44
|
export const EDITABLE_TOKEN_NAME_SET = new Set(EDITABLE_TOKEN_NAMES);
|
|
45
45
|
/** All known preset ids — kept in sync with lib/themes/presets.ts PRESET_IDS. */
|
|
46
46
|
export const PRESET_IDS = new Set(PRESETS.map((p) => p.id));
|
|
47
|
+
/**
|
|
48
|
+
* Match system: the theme that follows the operating system's light or dark
|
|
49
|
+
* setting, with one light and one dark preset. Mirrors lib/themes/system.ts;
|
|
50
|
+
* the server checks the halves too.
|
|
51
|
+
*/
|
|
52
|
+
export const SYSTEM_THEME_ID = "system";
|
|
53
|
+
/** Why `id` cannot be this half, or null when it can. */
|
|
54
|
+
export function systemHalfError(half, id) {
|
|
55
|
+
const preset = PRESETS.find((p) => p.id === id);
|
|
56
|
+
if (!preset)
|
|
57
|
+
return `Unknown theme id: ${id}. Run \`cnotes theme list\` to see available presets.`;
|
|
58
|
+
const wantDark = half === "dark";
|
|
59
|
+
if (preset.isDark !== wantDark) {
|
|
60
|
+
const allowed = PRESETS.filter((p) => p.isDark === wantDark).map((p) => p.id).join(", ");
|
|
61
|
+
return `${id} is a ${preset.isDark ? "dark" : "light"} theme, so it cannot be the ${half} one. ${half === "light" ? "Light" : "Dark"} themes: ${allowed}`;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/** "Match system (light: Light, dark: Cursor)". */
|
|
66
|
+
export function describeSystemThemes(themes) {
|
|
67
|
+
const name = (id) => PRESETS.find((p) => p.id === id)?.name ?? id;
|
|
68
|
+
return `Match system (light: ${name(themes.light)}, dark: ${name(themes.dark)})`;
|
|
69
|
+
}
|
|
47
70
|
const HEX3 = /^#?([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/;
|
|
48
71
|
const HEX6 = /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
|
|
49
72
|
export function parseHex(hex) {
|