* build(workspace): vendor the approved concept stylesheet with a drift check * refactor(workspace): adopt the concept stylesheet as the workspace base * feat(workspace): concept sidebar with real navigation counts * feat(workspace): concept topbar with Theme and ComfyUI link * refactor(workspace): one concept heading and footer for every route * fix(workspace): keep the canvas link on the proxy mount A resolver failure no longer stops the shell from mounting: the ComfyUI link falls back to the root read from the page's own mount path (never another origin). Tests cover a non-standard /ComfyBackendDirect mount, including that no request escapes it. * test(workspace): concept fixture and shell comparison * test(workspace): concept fixture carries the concept inspector facts * fix(workspace): match the concept brand name and compare shell hover states * test(workspace): shell comparison mutation check and docs Add mutate() to the shared concept inventory and a shell mutation check: a nav-row min-height rule and a removed .breadcrumbs each make the comparison fail with the changed path. Harden the resolver-failure guard test with an injection count, make the overlay lint fail when workspace.css is missing, mark the library.css .row-actions leftovers for PR E, and document the concept CSS base, the overlay lint, the comparison method and the recorded shell deviations in TESTING.md. * fix(workspace): focus the page title on a route change A sidebar or history navigation now focuses #page-title, as the concept does on every hashchange (app.js 1168), so a screen reader announces the page heading instead of the main region. The first render leaves focus alone and the skip link still focuses main. The heading module's comment now describes what the shell does. * fix(workspace): give the Overview nav entry its own home glyph Overview reused the concept's Activity pulse byte for byte, so once the Activity row lands two entries would share one icon. Overview now has an outline home glyph. The shell comparison takes it from the D28 ruling instead of the concept's activity path, and the icon test checks that every approved glyph is distinct. * test(workspace): accept only #249 decision markers and state the lint scope The overlay lint accepted any D-number, so another issue's ruling such as "D5 (#245)" could mark a concept override. A marker now has to be a D-number with no other issue cited; the vocabulary rule that cited #245 reads "#245 decision 5". TESTING.md now states that the lint covers workspace.css only, lists the unmarked overrides still in images.css, and says PRs C and D run the lint over each page sheet they keep. * perf(workspace): re-read only Library and Tags counts after a Library write A confirmed Library or vocabulary write cannot change the Images count, but it re-read all three, including the Images output listing. It now re-reads only the Library and Tags counts. Each count has its own read, so a write never cancels an Images read that is still in flight.
78 lines
3.4 KiB
JavaScript
78 lines
3.4 KiB
JavaScript
const STORAGE_KEY = 'pm_workspace_theme';
|
|
// D4 (#249): the concept's Theme select. "system" follows the ComfyUI palette, then the OS.
|
|
const PREFERENCES = new Set(['dark', 'light', 'system']);
|
|
// The pre-#249 "Follow ComfyUI" value, read as System so a saved choice survives the rename.
|
|
const LEGACY = new Map([['follow', 'system']]);
|
|
const LIGHT_PALETTES = new Set(['light', 'solarized', 'github', 'arc']);
|
|
const DARK_PALETTES = new Set(['dark', 'obsidian', 'nord', 'dracula', 'gruvbox']);
|
|
|
|
/** Adapt the standalone page to ComfyUI without coupling the shared toolkit to HTTP. */
|
|
export function mountWorkspaceTheme({ root = document.body, scope, fetchImpl = globalThis.fetch, storage, win = window }) {
|
|
const documentElement = root.ownerDocument.documentElement;
|
|
const previousTheme = root.dataset.caTheme;
|
|
const previousScheme = documentElement.style.colorScheme;
|
|
const system = win.matchMedia('(prefers-color-scheme: dark)');
|
|
let preference = 'system';
|
|
let hostTheme = null;
|
|
let request = null;
|
|
let sequence = 0;
|
|
try {
|
|
storage ??= win.localStorage;
|
|
const stored = storage?.getItem(STORAGE_KEY);
|
|
const saved = LEGACY.get(stored) ?? stored;
|
|
if (PREFERENCES.has(saved)) preference = saved;
|
|
} catch { /* Storage can be disabled while theme controls remain usable. */ }
|
|
|
|
function update() {
|
|
if (scope.signal.aborted) return;
|
|
const theme = preference === 'system' ? hostTheme || (system.matches ? 'dark' : 'light') : preference;
|
|
root.dataset.caTheme = theme;
|
|
documentElement.style.colorScheme = theme;
|
|
}
|
|
|
|
async function refreshHost() {
|
|
if (scope.signal.aborted) return;
|
|
request?.abort();
|
|
const controller = new AbortController();
|
|
request = controller;
|
|
const current = ++sequence;
|
|
let next = null;
|
|
try {
|
|
const prefix = win.location.pathname.match(/^(.*)\/prompt_manager(?:\/|$)/)?.[1] || '';
|
|
const response = await fetchImpl(`${prefix}/api/settings/Comfy.ColorPalette`, { signal: controller.signal });
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
const value = typeof data === 'string' ? data : data?.value;
|
|
const name = typeof value === 'string' ? value.toLowerCase().trim() : '';
|
|
next = LIGHT_PALETTES.has(name) ? 'light' : DARK_PALETTES.has(name) ? 'dark' : null;
|
|
}
|
|
} catch { /* A standalone or unavailable host follows the system preference. */ }
|
|
if (scope.signal.aborted || current !== sequence) return;
|
|
hostTheme = next;
|
|
update();
|
|
}
|
|
|
|
scope.listen(system, 'change', update);
|
|
scope.listen(win, 'focus', refreshHost);
|
|
scope.cleanup(() => {
|
|
sequence++;
|
|
request?.abort();
|
|
if (previousTheme === undefined) delete root.dataset.caTheme;
|
|
else root.dataset.caTheme = previousTheme;
|
|
documentElement.style.colorScheme = previousScheme;
|
|
});
|
|
update();
|
|
const ready = refreshHost();
|
|
return {
|
|
ready,
|
|
get preference() { return preference; },
|
|
setPreference(value) {
|
|
if (scope.signal.aborted) return;
|
|
if (!PREFERENCES.has(value)) throw new TypeError('Unknown theme preference');
|
|
preference = value;
|
|
try { storage?.setItem(STORAGE_KEY, value); } catch { /* Keep the in-memory preference. */ }
|
|
update();
|
|
},
|
|
};
|
|
}
|