42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
// Built-in theme registry. Starters ship as frozen code, are merged into list()
|
|
// at read time, and are never inserted into the Table. They are not deletable,
|
|
// renamable, or save-able; "loading" a built-in for edit duplicates it to a
|
|
// fresh uuid row (handled in the store/handlers).
|
|
|
|
const themes = [require("./flatly"), require("./darkly"), require("./cosmo")];
|
|
const byId = Object.freeze(Object.fromEntries(themes.map((t) => [t.id, t])));
|
|
|
|
|
|
function listBuiltins() {
|
|
return themes;
|
|
}
|
|
|
|
|
|
function getBuiltin(id) {
|
|
return byId[id] || null;
|
|
}
|
|
|
|
|
|
function isBuiltinId(id) {
|
|
return typeof id === "string" && id.startsWith("builtin:");
|
|
}
|
|
|
|
|
|
// The starter used as a last-resort successor (e.g. when the active theme is
|
|
// deleted and no other stored theme exists).
|
|
function defaultId() {
|
|
return "builtin:flatly";
|
|
}
|
|
|
|
|
|
// Valid, empty CSS served on a transient miss (table not yet created, theme
|
|
// missing mid-activate). Never a white-screen; the active theme renders
|
|
// unchanged. Always sent with Cache-Control: no-store by the route.
|
|
function fallbackCss() {
|
|
return "/* theme-builder: fallback (no compiled theme) */\n";
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
listBuiltins, getBuiltin, get: getBuiltin, isBuiltinId, defaultId, fallbackCss,
|
|
};
|