Translate all UI strings, docs, comments and preview pages to English; single English locale dictionary; theme labels carry one name each. Add scripts/render-previews.mjs (deterministic preview renders via playwright-core) and re-render all 17 preview PNGs at 1440x860. Palettes, token mapping and plugin behavior unchanged from upstream.
303 lines
15 KiB
JavaScript
303 lines
15 KiB
JavaScript
/**
|
||
* Generator: palettes → all artifacts.
|
||
* node scripts/build.mjs
|
||
* Produces:
|
||
* lib/themes.json token override tables for the 16 themes (machine-readable)
|
||
* lib/client.js client plugin bundle (lazy CJS; registers themes + settings picker)
|
||
* preview/<id>.html GUI preview page per theme (for headless screenshots)
|
||
* preview/gallery.html 16-in-1 overview page
|
||
*/
|
||
import { writeFileSync, mkdirSync } from 'node:fs';
|
||
import { dirname, join } from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
import { PALETTES } from '../src/palettes.mjs';
|
||
import { themeDefOf } from '../src/tokens.mjs';
|
||
|
||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||
const out = (rel, content) => {
|
||
const p = join(root, rel);
|
||
mkdirSync(dirname(p), { recursive: true });
|
||
writeFileSync(p, content);
|
||
console.log('wrote', rel);
|
||
};
|
||
|
||
const THEMES = PALETTES.map(themeDefOf);
|
||
|
||
// ── 1) themes.json ──────────────────────────────────────────
|
||
out('lib/themes.json', JSON.stringify(THEMES, null, 2));
|
||
|
||
// ── 2) client.js (lazy CJS bundle) ──────────────────────────
|
||
const dict = { 'themepack.title': 'Theme skins (16)' };
|
||
for (const t of THEMES) dict['themepack.' + t.id] = t.label.en;
|
||
|
||
const pickerCss = [
|
||
'.dtp-group{border-bottom:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:8px;padding:16px 0;display:flex}',
|
||
'.dtp-title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}',
|
||
'.dtp-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(152px,1fr));gap:8px}',
|
||
'.dtp-cube{box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);border-radius:12px;background:0 0;color:var(--dsw-alias-label-primary);cursor:pointer;font:inherit;display:flex;flex-direction:column;align-items:flex-start;gap:8px;padding:12px 14px;font-size:13px;line-height:18px}',
|
||
'.dtp-cube:hover:not(.dtp-selected){background:var(--dsw-alias-interactive-bg-hover)}',
|
||
'.dtp-selected{border-color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-bg-module-platform)}',
|
||
'.dtp-dots{display:flex;gap:5px}',
|
||
'.dtp-dot{width:14px;height:14px;border-radius:50%;border:1px solid var(--dsw-alias-border-l3)}',
|
||
'.dtp-name{color:var(--dsw-alias-label-secondary)}',
|
||
].join('');
|
||
|
||
const clientJs = `/* dsh-theme-pack client bundle — generated by scripts/build.mjs, do not edit by hand. */
|
||
window.__ModuleLoader__.load({
|
||
id: "dsh-theme-pack",
|
||
factory: (require) => {
|
||
var module = { exports: {} };
|
||
var exports = module.exports;
|
||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||
const { jsx, jsxs } = require("react/jsx-runtime");
|
||
const { defineStore } = require("@deepseek-ai/dsh-client-runtime/client");
|
||
const THEMES = ${JSON.stringify(THEMES)};
|
||
const CSS = ${JSON.stringify(pickerCss)};
|
||
const TAG_ID = "dsh-theme-pack/picker.css";
|
||
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(TAG_ID) + "]") === null) {
|
||
const tag = document.createElement("style");
|
||
tag.dataset.plugin = "dsh-theme-pack";
|
||
tag.dataset.pluginCss = TAG_ID;
|
||
tag.textContent = CSS;
|
||
document.head.appendChild(tag);
|
||
}
|
||
const dict = ${JSON.stringify(dict)};
|
||
function createRowStore() {
|
||
return defineStore({
|
||
init: () => ({ preference: "system", revision: -1 }),
|
||
actions: {
|
||
sync: (d, preference, revision) => {
|
||
if (revision <= d.revision) return;
|
||
d.preference = preference;
|
||
d.revision = revision;
|
||
}
|
||
}
|
||
});
|
||
}
|
||
function ThemePackRow({ t, setTheme, useStore }) {
|
||
const preference = useStore((s) => s.preference);
|
||
return jsxs("div", { className: "dtp-group", children: [
|
||
jsx("div", { className: "dtp-title", children: t("themepack.title") }),
|
||
jsx("div", { className: "dtp-grid", children: THEMES.map((th) => jsxs("button", {
|
||
type: "button",
|
||
className: "dtp-cube" + (preference === th.id ? " dtp-selected" : ""),
|
||
"aria-pressed": preference === th.id,
|
||
title: th.label.en,
|
||
onClick: () => { setTheme(th.id); },
|
||
children: [
|
||
jsx("span", { className: "dtp-dots", children: th.swatches.map((c) => jsx("span", { className: "dtp-dot", style: { background: c } }, c)) }),
|
||
jsx("span", { className: "dtp-name", children: t("themepack." + th.id) })
|
||
]
|
||
}, th.id)) })
|
||
] });
|
||
}
|
||
function apply(ctx) {
|
||
for (const th of THEMES) {
|
||
ctx.effect(() => ctx.theme.register({ id: th.id, colorScheme: th.colorScheme, tokens: th.tokens }), "theme-pack: register " + th.id);
|
||
}
|
||
ctx.effect(() => ctx.locale.register("settings.themePack", { zh: dict, en: dict }), "theme-pack: dictionaries");
|
||
const store = createRowStore();
|
||
let bound;
|
||
const sync = (snapshot) => { if (bound) bound.sync(snapshot.preference, snapshot.revision); };
|
||
ctx.effect(() => {
|
||
const off = ctx.on("theme/change", sync);
|
||
return () => { off(); };
|
||
}, "theme-pack: theme/change mirror");
|
||
const injected = (actions) => {
|
||
bound = actions;
|
||
sync(ctx.theme.getTheme());
|
||
return { setTheme: (id) => { ctx.theme.setTheme(id); } };
|
||
};
|
||
ctx.slots.inject("settings.general.item", () => ctx.slots.register({
|
||
name: "settings.general.item",
|
||
id: "theme-pack",
|
||
order: 11,
|
||
store,
|
||
locale: "settings.themePack",
|
||
inject: injected
|
||
}, ThemePackRow));
|
||
}
|
||
const inject = ["slots", "locale", "theme"];
|
||
exports.apply = apply;
|
||
exports.inject = inject;
|
||
return module.exports;
|
||
}
|
||
});
|
||
`;
|
||
out('lib/client.js', clientJs);
|
||
|
||
// ── 3) Preview pages ────────────────────────────────────────
|
||
const bodyStyle = (t) => Object.entries(t.tokens).map(([k, v]) => `${k}: ${v}`).join('; ');
|
||
|
||
const pageCss = `
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
html, body { height: 100%; }
|
||
body {
|
||
font-family: "Segoe UI", system-ui, sans-serif;
|
||
background: var(--dsw-alias-bg-base);
|
||
color: var(--dsw-alias-label-primary);
|
||
font-size: 14px; line-height: 1.7;
|
||
}
|
||
.app { display: flex; height: 100vh; }
|
||
.sidebar {
|
||
width: 264px; flex-shrink: 0; display: flex; flex-direction: column;
|
||
background: var(--dsw-specific-sidebar-fill);
|
||
border-right: 1px solid var(--dsw-alias-border-l1);
|
||
padding: 16px 12px;
|
||
}
|
||
.logo { font-size: 17px; font-weight: 600; color: var(--dsw-alias-brand-text); padding: 4px 10px 16px; }
|
||
.newchat {
|
||
border: 1px solid var(--dsw-alias-border-l2); border-radius: 12px;
|
||
background: var(--dsw-alias-button-elevated-fill); color: var(--dsw-alias-label-primary);
|
||
font: inherit; padding: 9px 12px; text-align: left; cursor: pointer; margin-bottom: 14px;
|
||
}
|
||
.sess { padding: 8px 10px; border-radius: 10px; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.sess:hover { background: var(--dsw-specific-sidebar-nav-item-hover); }
|
||
.sess.active { background: var(--dsw-specific-sidebar-nav-item-active); color: var(--dsw-alias-label-primary); box-shadow: inset 2px 0 0 var(--dsw-alias-state-business-primary); }
|
||
.sidefoot { margin-top: auto; padding: 8px 10px; color: var(--dsw-alias-label-tertiary); border-top: 1px solid var(--dsw-alias-border-l1); }
|
||
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
|
||
.topbar {
|
||
height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 10px;
|
||
padding: 0 24px; border-bottom: 1px solid var(--dsw-alias-border-l1);
|
||
color: var(--dsw-alias-label-primary); font-weight: 500;
|
||
}
|
||
.model { font-size: 12px; font-weight: 400; color: var(--dsw-alias-label-caption); border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px; padding: 1px 8px; }
|
||
.chat { flex: 1; overflow: hidden; padding: 24px 24px 8px; display: flex; flex-direction: column; align-items: center; }
|
||
.col { width: 100%; max-width: 780px; }
|
||
.msg-user { display: flex; justify-content: flex-end; margin-bottom: 18px; }
|
||
.bubble {
|
||
background: var(--dsw-specific-bubble); color: var(--dsw-alias-label-primary);
|
||
border-radius: 16px; padding: 10px 16px; max-width: 70%;
|
||
}
|
||
.msg-ai { color: var(--dsw-alias-label-primary); }
|
||
.msg-ai p { margin-bottom: 10px; }
|
||
.msg-ai ul { margin: 0 0 10px 22px; color: var(--dsw-alias-label-secondary); }
|
||
code.inline {
|
||
background: var(--dsw-alias-markdown-inline-code); border-radius: 6px;
|
||
padding: 1px 6px; font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px;
|
||
color: var(--dsw-alias-label-primary-bluish);
|
||
}
|
||
.ok { color: var(--dsw-alias-state-success-primary); }
|
||
.warn { color: var(--dsw-alias-state-warn-label); }
|
||
.err { color: var(--dsw-alias-state-error-primary); }
|
||
.code { border: 1px solid var(--dsw-alias-border-l1); border-radius: 14px; overflow: hidden; margin: 6px 0 12px; }
|
||
.codebanner {
|
||
display: flex; justify-content: space-between; align-items: center;
|
||
background: var(--dsw-alias-markdown-code-block-banner);
|
||
border-bottom: 1px solid var(--dsw-alias-border-l1);
|
||
padding: 6px 14px; font-size: 12px; color: var(--dsw-alias-label-caption);
|
||
}
|
||
.code pre {
|
||
background: var(--dsw-alias-markdown-code-block); padding: 14px 16px;
|
||
font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; line-height: 1.65;
|
||
color: var(--dsw-alias-label-secondary); overflow: hidden;
|
||
}
|
||
.kw { color: var(--syn-kw); } .str { color: var(--syn-str); } .fn { color: var(--syn-fn); }
|
||
.num { color: var(--syn-num); } .com { color: var(--syn-com); font-style: italic; }
|
||
.cap { font-size: 12px; color: var(--dsw-alias-label-caption); }
|
||
.composer { flex-shrink: 0; padding: 8px 24px 20px; display: flex; justify-content: center; }
|
||
.input {
|
||
width: 100%; max-width: 780px; display: flex; align-items: center; gap: 10px;
|
||
background: var(--dsw-specific-input-major); border: 1px solid var(--dsw-alias-border-l2);
|
||
border-radius: 24px; padding: 12px 12px 12px 20px;
|
||
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
|
||
}
|
||
.ph { flex: 1; color: var(--dsw-alias-label-caption); }
|
||
.send {
|
||
width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
|
||
background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground);
|
||
font-weight: 600;
|
||
}
|
||
.themetag {
|
||
position: fixed; right: 18px; bottom: 18px; z-index: 9;
|
||
background: var(--dsw-alias-tooltip-bg); color: var(--dsw-alias-label-primary);
|
||
border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px;
|
||
padding: 6px 12px; font-size: 12px;
|
||
}
|
||
.themetag b { color: var(--dsw-alias-state-business-primary); font-weight: 600; }
|
||
`;
|
||
|
||
const codeSample = `<span class="com">// palette → DSH semantic token overrides</span>
|
||
<span class="kw">const</span> themes = palettes.<span class="fn">map</span>((p) => ({
|
||
id: p.id, <span class="com">// e.g. 'tokyo-night'</span>
|
||
colorScheme: <span class="str">'dark'</span>,
|
||
tokens: <span class="fn">tokensFor</span>(p), <span class="com">// full --dsw-alias-* set</span>
|
||
swatches: <span class="num">4</span>,
|
||
}));
|
||
<span class="kw">export default</span> themes;`;
|
||
|
||
function pageHtml(t, p) {
|
||
const synVars = `--syn-kw: ${p.syn.kw}; --syn-str: ${p.syn.str}; --syn-fn: ${p.syn.fn}; --syn-num: ${p.syn.num}; --syn-com: ${p.syn.com}`;
|
||
return `<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>${t.label.en} — DSH theme preview</title>
|
||
<style>${pageCss}</style>
|
||
</head>
|
||
<body style="color-scheme: ${t.colorScheme}; ${bodyStyle(t)}; ${synVars}">
|
||
<div class="app">
|
||
<aside class="sidebar">
|
||
<div class="logo">DeepSeek</div>
|
||
<button class="newchat">+ New chat</button>
|
||
<div class="sess">Midterm exam review notes</div>
|
||
<div class="sess active">DSH theme pack design</div>
|
||
<div class="sess">Calculus drill problems</div>
|
||
<div class="sess">Conference talk outline</div>
|
||
<div class="sidefoot">⚙ Settings</div>
|
||
</aside>
|
||
<div class="main">
|
||
<div class="topbar">DSH theme pack design <span class="model">k3-256k</span></div>
|
||
<div class="chat"><div class="col">
|
||
<div class="msg-user"><div class="bubble">Generate one preview image per theme, 16 in total. The dark themes must have good-looking code blocks.</div></div>
|
||
<div class="msg-ai">
|
||
<p>Mapped onto the <code class="inline">--dsw-alias-*</code> semantic layer. Rules:</p>
|
||
<ul>
|
||
<li>The four background layers and the sidebar come straight from the palette primaries, hierarchy intact;</li>
|
||
<li>Status colors <span class="ok">success</span> / <span class="warn">warning</span> / <span class="err">error</span> keep each theme's official colors.</li>
|
||
</ul>
|
||
<div class="code">
|
||
<div class="codebanner"><span>javascript</span><span>Copy</span></div>
|
||
<pre>${codeSample}</pre>
|
||
</div>
|
||
<p class="cap">Palette source: src/palettes.mjs · Mapper: src/tokens.mjs</p>
|
||
</div>
|
||
</div></div>
|
||
<div class="composer"><div class="input"><span class="ph">Message DeepSeek…</span><span class="send">↑</span></div></div>
|
||
</div>
|
||
</div>
|
||
<div class="themetag"><b>${t.label.en}</b> · ${t.colorScheme === 'dark' ? 'dark' : 'light'} scheme</div>
|
||
</body>
|
||
</html>`;
|
||
}
|
||
|
||
for (let i = 0; i < THEMES.length; i++) out(`preview/${THEMES[i].id}.html`, pageHtml(THEMES[i], PALETTES[i]));
|
||
|
||
// ── 4) Gallery page (16 scaled images) ──────────────────────
|
||
// The gallery embeds the rendered PNGs directly (iframes often haven't finished
|
||
// loading during headless screenshots; img tags are reliable).
|
||
const cells = THEMES.map((t) => `
|
||
<figure>
|
||
<img src="../previews/${t.id}.png" alt="${t.id}">
|
||
<figcaption>${t.label.en}<small>${t.id}</small></figcaption>
|
||
</figure>`).join('\n');
|
||
out('preview/gallery.html', `<!DOCTYPE html>
|
||
<html lang="en"><head><meta charset="utf-8"><title>DSH theme pack, 16 themes</title>
|
||
<style>
|
||
body { margin: 0; background: #111; font-family: "Segoe UI", system-ui, sans-serif; }
|
||
h1 { color: #eee; font-size: 20px; font-weight: 600; padding: 20px 28px 4px; }
|
||
.sub { color: #999; font-size: 13px; padding: 0 28px 16px; }
|
||
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 0 28px 28px; }
|
||
figure { margin: 0; }
|
||
img { width: 100%; display: block; border-radius: 10px; border: 1px solid #333; }
|
||
figcaption { color: #ddd; font-size: 13px; padding: 6px 2px 0; display: flex; justify-content: space-between; }
|
||
figcaption small { color: #777; }
|
||
</style></head>
|
||
<body>
|
||
<h1>DSH Theme Pack · 16 Themes</h1>
|
||
<div class="sub">11 families × light/dark variants = 16 themes: Catppuccin / Gruvbox / Everforest / Rosé Pine / Solarized / Kanagawa / Tokyo Night / Night Owl / Nord / Dracula / One Dark</div>
|
||
<div class="grid">${cells}
|
||
</div>
|
||
</body></html>`);
|
||
|
||
console.log(`done: ${THEMES.length} themes`); |