${e(i.title)}
${row(t.author, i.author)}${row(t.edition, i.edition)}${row(t.language, i.language)}${tags}${secs}${ann}${link}${file}
import { escapeHtml as e } from "../../html.ts"; import { fmt, LANG_NAMES, LANGS, type Dict, type Lang } from "./i18n/index.ts"; import { flatten, label, MAX_DEPTH, type SectionNode } from "./tree.ts"; export const LIBRARY_CSS = `:root{--bg:#f7f6f2;--fg:#1d1d1b;--muted:#5d5d58;--card:#fff;--line:#e2e0d8;--accent:#2f5d50;--warn:#9a3412} @media (prefers-color-scheme:dark){:root{--bg:#141413;--fg:#ecebe6;--muted:#a3a29b;--card:#1e1e1c;--line:#33332f;--accent:#8cc1b0;--warn:#fdba74}} *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif} main{max-width:880px;margin:0 auto;padding:32px 16px}a{color:var(--accent)}h1{margin:8px 0}.lead,.meta,.note{color:var(--muted)} nav.top{display:flex;gap:16px;flex-wrap:wrap;font-size:.875rem;justify-content:space-between}nav.top span a{margin-left:8px} form.search{display:flex;gap:8px;margin:16px 0 24px}form.search input{flex:1} input,select,textarea,button{font:inherit;padding:6px 10px;border:1px solid var(--line);border-radius:6px;background:var(--card);color:var(--fg)} button{cursor:pointer;border-color:var(--accent);color:var(--accent)}textarea{width:100%;min-height:120px} details{margin:4px 0}details>div,ul.toc ul{margin-left:20px}summary{cursor:pointer;font-weight:600} ul{padding-left:20px}ul.toc{list-style:none;padding-left:0}.items{list-style:"📖 ";padding-left:24px} .card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:20px;margin:16px 0} .error{border:1px solid var(--warn);color:var(--warn);border-radius:8px;padding:8px 12px}.ok{color:var(--accent)} .tag{display:inline-block;border:1px solid var(--line);border-radius:999px;padding:0 8px;margin:0 4px 4px 0;font-size:.875rem} .btn{display:inline-block;margin:8px 8px 0 0;padding:8px 16px;border:1px solid var(--accent);border-radius:8px;text-decoration:none} .inline{display:inline-flex;gap:6px;margin:2px 8px 2px 0;align-items:center}.hidden{opacity:.55} label{display:block;margin:10px 0 2px}label.check{display:flex;gap:6px;margin:2px 0;font-weight:normal} .f input[type=text],.f input[type=url]{width:100%}table{border-collapse:collapse;width:100%}td,th{border-bottom:1px solid var(--line);padding:6px;text-align:left} .d1{padding-left:20px}.d2{padding-left:40px}.d3{padding-left:60px}.d4{padding-left:80px}`; export interface ItemView { id: string; title: string; author: string; edition: string; language: string; annotation: string; tags: string[]; linkUrl: string | null; fileName: string | null; fileSize: number | null; fileAccess: "public" | "closed"; rightsBasis: "own" | "licensed" | "public_domain" | null; status: "draft" | "published"; sectionIds: string[]; } interface ShellOpts { lang: Lang; title: string; switchPath?: string } function shell(t: Dict, o: ShellOpts, inner: string): string { const langs = o.switchPath ? `${e(t.languages)}:${(Object.keys(LANGS) as Lang[]) .map((l) => (l === o.lang ? ` ${e(LANG_NAMES[l])}` : ` ${e(LANG_NAMES[l])}`)) .join("")}` : ""; return `
${e(msg)}
` : ""); // ---------- публичная часть ---------- function itemLink(i: ItemView): string { const by = i.author ? ` ` : ""; return `${e(t.nothingFound)}
`}` : `${e(t.lead)}
${form}${body}`); } export function renderItem(t: Dict, lang: Lang, i: ItemView, sections: SectionNode[], opts: { editor: boolean }): string { const row = (k: string, v: string) => (v ? `${e(p.trim())}
`).join("")}` : ""; const link = i.linkUrl ? `${e(t.openLink)}` : ""; const file = i.fileName ? `${e(t.download)}${i.fileAccess === "closed" ? `${e(t.closedFileNote)}
` : ""}` : ""; const draft = i.status === "draft" ? `${e(t.draftNote)}
` : ""; const back = opts.editor ? ` · ${e(t.backToEditor)}` : ""; return shell( t, { lang, title: `${i.title} — ${t.title}`, switchPath: `/library/items/${i.id}` }, `${draft}${link}${file}
${e(t.allLibrary)}${back}
`, ); } export function renderMessage(t: Dict, lang: Lang, title: string, text: string): string { return shell(t, { lang, title }, `${e(text)}
`); } // ---------- редактор ---------- const csrfInput = (csrf: string) => ``; export function renderLogin(t: Dict, lang: Lang, opts: { error?: string; disabled?: boolean }): string { const form = opts.disabled ? "" : ``; return shell(t, { lang, title: t.loginTitle, switchPath: "/library/editor" }, `${e(opts.disabled ? t.editorOff : t.loginLead)}
${err(opts.error)}${form}`); } export function renderEditor(t: Dict, lang: Lang, csrf: string, tree: SectionNode[], items: ItemView[], opts: { error?: string; saved?: boolean }): string { const act = (n: SectionNode, action: string, text: string) => ``; const node = (n: SectionNode): string => { const addChild = n.depth < MAX_DEPTH - 1 ? `` : ""; const rename = ``; const hide = n.selfHidden ? act(n, "restore", t.restore) : act(n, "hide", t.hide); return `| ${e(i.title)} | ${e(i.author)} | ${e(status(i))} |
${e(t.noMaterials)}
`; const top = ``; return shell( t, { lang, title: t.editorTitle, switchPath: "/library/editor" }, `${e(t.editorLead)}
${top}${err(opts.error)}${opts.saved ? `${e(t.saved)}
` : ""}${e(fmt(t.currentFile, { name: item.fileName, size: Math.ceil((item.fileSize ?? 0) / 1024) }))}
` : ""} ` : ""; const links = `${e(t.backToEditor)}${item ? ` · ${e(t.preview)}` : ""}
`; return shell( t, { lang, title: `${item?.title ?? t.newMaterial} — ${t.editorTitle}`, switchPath: item ? `/library/editor/items/${item.id}` : "/library/editor/items/new" }, `${e(t.saved)}
` : ""}${main}${file}`, ); }