dsh-novel-image 0.0.0 → 0.4.3
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/CHANGELOG.md +116 -0
- package/README.md +137 -6
- package/client.js +1059 -0
- package/docs/DETAIL.md +113 -0
- package/icon.svg +8 -0
- package/index.js +875 -11
- package/lib/assets/store.mjs +173 -0
- package/lib/canon/extract.mjs +333 -0
- package/lib/canon/merge.mjs +44 -0
- package/lib/canon/store.mjs +188 -0
- package/lib/core/errors.mjs +22 -0
- package/lib/core/ids.mjs +9 -0
- package/lib/core/storage.mjs +113 -0
- package/lib/cover/plan.mjs +64 -0
- package/lib/critique/parse.mjs +112 -0
- package/lib/critique/prompt.mjs +78 -0
- package/lib/critique/revision.mjs +96 -0
- package/lib/generate/comfyui.mjs +95 -0
- package/lib/generate/incremental.mjs +36 -0
- package/lib/generate/limits.mjs +43 -0
- package/lib/generate/mock.mjs +29 -0
- package/lib/generate/openai.mjs +138 -0
- package/lib/generate/state.mjs +29 -0
- package/lib/generate/store.mjs +186 -0
- package/lib/generate/workflow.mjs +76 -0
- package/lib/generate/workflows.mjs +59 -0
- package/lib/prompt/compile.mjs +390 -0
- package/lib/prompt/platforms.mjs +102 -0
- package/lib/prompt/profiles.mjs +109 -0
- package/lib/remote-contract.js +81 -0
- package/lib/remote.js +403 -0
- package/lib/schema.mjs +213 -0
- package/lib/service.mjs +1180 -0
- package/lib/source/import.mjs +191 -0
- package/lib/styles/prompt.mjs +54 -0
- package/lib/styles/store.mjs +79 -0
- package/lib/typert-bind.js +28 -0
- package/locale/en.json +1 -0
- package/locale/zh-CN.json +1 -0
- package/package.json +82 -11
package/client.js
ADDED
|
@@ -0,0 +1,1059 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-novel-image",
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
|
|
7
|
+
/* remote contract mirrors lib/remote-contract.js */
|
|
8
|
+
const scalar = (validate) => ({
|
|
9
|
+
parse: (value) => { validate(value); return value; },
|
|
10
|
+
safeParse: (value) => { try { validate(value); return { success: true, data: value }; } catch (error) { return { success: false, error }; } },
|
|
11
|
+
});
|
|
12
|
+
const sid = scalar((value) => { if (typeof value !== "string" || !value) throw new Error("bad sessionId"); });
|
|
13
|
+
const obj = scalar((value) => { if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("bad options"); });
|
|
14
|
+
const res = scalar((value) => { if (!value || typeof value !== "object") throw new Error("bad result"); });
|
|
15
|
+
const codec = (type, schema) => ({ mode: "strict", typeSymbol: type, create: () => schema });
|
|
16
|
+
const param = (name, schema) => ({ name, wire: name, source: "json", codec: codec(name, schema) });
|
|
17
|
+
const invoke = (method, params) => ({
|
|
18
|
+
id: `dsh-novel-image#imagePanel/${method}`,
|
|
19
|
+
namespace: "imagePanel",
|
|
20
|
+
service: "imagePanel",
|
|
21
|
+
method,
|
|
22
|
+
invocation: { kind: "direct" },
|
|
23
|
+
parameters: [param("sessionId", sid), ...params],
|
|
24
|
+
result: codec("ImageResult", res),
|
|
25
|
+
});
|
|
26
|
+
const REMOTE = {
|
|
27
|
+
package: "dsh-novel-image",
|
|
28
|
+
descriptors: [
|
|
29
|
+
invoke("status", []),
|
|
30
|
+
invoke("importText", [param("options", obj)]),
|
|
31
|
+
invoke("getWork", [param("options", obj)]),
|
|
32
|
+
invoke("extractCanon", [param("options", obj)]),
|
|
33
|
+
invoke("getCanon", [param("options", obj)]),
|
|
34
|
+
invoke("updateAnchor", [param("options", obj)]),
|
|
35
|
+
invoke("compile", [param("options", obj)]),
|
|
36
|
+
invoke("exportPack", [param("options", obj)]),
|
|
37
|
+
invoke("importDraft", [param("options", obj)]),
|
|
38
|
+
invoke("critiqueDraft", [param("options", obj)]),
|
|
39
|
+
invoke("reviseDraft", [param("options", obj)]),
|
|
40
|
+
invoke("listAssets", [param("options", obj)]),
|
|
41
|
+
invoke("importAsset", [param("options", obj)]),
|
|
42
|
+
invoke("setAssetReference", [param("options", obj)]),
|
|
43
|
+
invoke("getAssetImage", [param("options", obj)]),
|
|
44
|
+
invoke("listCritiques", [param("options", obj)]),
|
|
45
|
+
invoke("compareCritiques", [param("options", obj)]),
|
|
46
|
+
invoke("analyzeStyle", [param("options", obj)]),
|
|
47
|
+
invoke("listStyles", [param("options", obj)]),
|
|
48
|
+
invoke("searchReferences", [param("options", obj)]),
|
|
49
|
+
invoke("coverPlan", [param("options", obj)]),
|
|
50
|
+
invoke("addVariant", [param("options", obj)]),
|
|
51
|
+
invoke("removeVariant", [param("options", obj)]),
|
|
52
|
+
invoke("listProviders", []),
|
|
53
|
+
invoke("saveProvider", [param("options", obj)]),
|
|
54
|
+
invoke("submitJob", [param("options", obj)]),
|
|
55
|
+
invoke("getJob", [param("options", obj)]),
|
|
56
|
+
invoke("listJobs", [param("options", obj)]),
|
|
57
|
+
invoke("cancelJob", [param("options", obj)]),
|
|
58
|
+
invoke("retryJob", [param("options", obj)]),
|
|
59
|
+
invoke("testProvider", [param("options", obj)]),
|
|
60
|
+
invoke("incrementalPlan", [param("options", obj)]),
|
|
61
|
+
invoke("applyIncremental", [param("options", obj)]),
|
|
62
|
+
invoke("saveWorkflow", [param("options", obj)]),
|
|
63
|
+
invoke("listWorkflows", []),
|
|
64
|
+
invoke("listProfiles", []),
|
|
65
|
+
invoke("platformPresets", []),
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const TAB_ID = "dsh-novel-image";
|
|
70
|
+
const TAB_KIND = "novel-image";
|
|
71
|
+
|
|
72
|
+
const C = {
|
|
73
|
+
bg: "var(--dsw-alias-bg-l0,#f7f6f2)",
|
|
74
|
+
card: "var(--dsw-alias-bg-l1,#ffffff)",
|
|
75
|
+
soft: "var(--dsw-alias-bg-l2,#f1efe9)",
|
|
76
|
+
ink: "var(--dsw-alias-label-primary,#262b27)",
|
|
77
|
+
muted: "var(--dsw-alias-label-secondary,#6b716a)",
|
|
78
|
+
faint: "var(--dsw-alias-label-tertiary,#8d928b)",
|
|
79
|
+
line: "var(--dsw-alias-border-l1,#e5e4de)",
|
|
80
|
+
accent: "var(--dsw-alias-brand-primary,#3f6b55)",
|
|
81
|
+
danger: "var(--dsw-alias-label-danger,#b7655c)",
|
|
82
|
+
ok: "var(--dsw-alias-label-success,#4f8a6d)",
|
|
83
|
+
warn: "var(--dsw-alias-label-warning,#c58a3d)",
|
|
84
|
+
sans: '"Microsoft YaHei","PingFang SC",system-ui,sans-serif',
|
|
85
|
+
};
|
|
86
|
+
const S = {
|
|
87
|
+
root: { padding: 14, background: C.bg, color: C.ink, fontFamily: C.sans, fontSize: 13, height: "100%", overflowY: "auto", boxSizing: "border-box" },
|
|
88
|
+
title: { fontWeight: 700, fontSize: 16, margin: 0 },
|
|
89
|
+
sub: { color: C.muted, fontSize: 11.5, lineHeight: 1.55, margin: "4px 0 10px" },
|
|
90
|
+
card: { background: C.card, border: `1px solid ${C.line}`, borderRadius: 12, padding: 10, marginBottom: 10 },
|
|
91
|
+
label: { color: C.muted, fontSize: 12, margin: "8px 0 4px" },
|
|
92
|
+
input: { width: "100%", boxSizing: "border-box", border: `1px solid ${C.line}`, borderRadius: 8, padding: "6px 8px", fontSize: 12.5, background: C.card, color: C.ink, fontFamily: C.sans },
|
|
93
|
+
area: { width: "100%", boxSizing: "border-box", border: `1px solid ${C.line}`, borderRadius: 8, padding: "6px 8px", fontSize: 12.5, background: C.card, color: C.ink, fontFamily: C.sans, minHeight: 90, resize: "vertical" },
|
|
94
|
+
row: { display: "flex", gap: 6, alignItems: "center", flexWrap: "wrap" },
|
|
95
|
+
primary: { border: 0, background: C.accent, color: "#fff", borderRadius: 8, padding: "6px 10px", fontSize: 12.5, cursor: "pointer", fontFamily: C.sans, minHeight: 30 },
|
|
96
|
+
ghost: { border: `1px solid ${C.line}`, background: C.card, color: C.ink, borderRadius: 8, padding: "5px 9px", fontSize: 12, cursor: "pointer", fontFamily: C.sans, minHeight: 28 },
|
|
97
|
+
tab: (on) => ({ flex: 1, border: `1px solid ${on ? C.accent : C.line}`, background: on ? C.soft : C.card, color: C.ink, borderRadius: 8, padding: "5px 4px", fontSize: 12, cursor: "pointer", fontFamily: C.sans }),
|
|
98
|
+
pre: { whiteSpace: "pre-wrap", wordBreak: "break-word", background: C.soft, border: `1px solid ${C.line}`, borderRadius: 8, padding: 8, fontSize: 12, lineHeight: 1.55, maxHeight: 220, overflow: "auto", margin: "6px 0" },
|
|
99
|
+
chip: (tone) => ({ display: "inline-block", borderRadius: 999, padding: "1px 7px", fontSize: 11, border: `1px solid ${tone}`, color: tone }),
|
|
100
|
+
};
|
|
101
|
+
const KIND = { face: "脸型", hair: "发型", eyes: "眼睛", body: "体型", skin: "肤色", clothing: "服装", prop: "道具", mark: "标志", action: "动作", color: "颜色", other: "其他" };
|
|
102
|
+
const TASK = { cover: "封面", portrait: "立绘", scene: "插图", sheet: "设定图" };
|
|
103
|
+
const TONE = { matched: C.ok, partial: C.warn, missing: C.danger, wrong: C.danger, unclear: C.faint, ok: C.ok, warn: C.warn, bad: C.danger, minor: C.warn, major: C.danger, info: C.faint, pass: C.ok, unusable: C.danger };
|
|
104
|
+
const BG_THEMES = [
|
|
105
|
+
{ id: "paper", name: "素纸", bg: "#f7f6f2" },
|
|
106
|
+
{ id: "mint", name: "薄荷", bg: "#e8f3ec" },
|
|
107
|
+
{ id: "sky", name: "天青", bg: "#e7f1f7" },
|
|
108
|
+
{ id: "lavender", name: "薰衣草", bg: "#eeeaf7" },
|
|
109
|
+
{ id: "peach", name: "蜜桃", bg: "#f9ece4" },
|
|
110
|
+
{ id: "rose", name: "藕粉", bg: "#f8e9ee" },
|
|
111
|
+
{ id: "sand", name: "沙金", bg: "#f6f0df" },
|
|
112
|
+
{ id: "lemon", name: "柠檬", bg: "#f7f5dc" },
|
|
113
|
+
{ id: "sage", name: "鼠尾草", bg: "#edf0e6" },
|
|
114
|
+
{ id: "ice", name: "冰蓝", bg: "#e9f3f4" },
|
|
115
|
+
{ id: "lilac", name: "丁香", bg: "#f1ebf4" },
|
|
116
|
+
{ id: "coral", name: "珊瑚", bg: "#fbeae6" },
|
|
117
|
+
{ id: "seafoam", name: "海沫", bg: "#e6f2ee" },
|
|
118
|
+
{ id: "wheat", name: "麦田", bg: "#f7f1e2" },
|
|
119
|
+
{ id: "cloud", name: "云白", bg: "#f2f3f4" },
|
|
120
|
+
{ id: "blush", name: "胭脂", bg: "#fbe9e9" },
|
|
121
|
+
{ id: "stone", name: "石灰", bg: "#eceeee" },
|
|
122
|
+
{ id: "moss", name: "苔绿", bg: "#ebefe4" },
|
|
123
|
+
{ id: "ocean", name: "海盐", bg: "#e8f0f2" },
|
|
124
|
+
{ id: "plum", name: "梅子", bg: "#f3e9ef" },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
function unwrap(value) {
|
|
128
|
+
if (value && typeof value === "object" && value.error) throw new Error(value.message || value.error);
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function Panel({ sessionId, remote }) {
|
|
133
|
+
const [tab, setTab] = React.useState("canon");
|
|
134
|
+
const [phase, setPhase] = React.useState("loading");
|
|
135
|
+
const [error, setError] = React.useState("");
|
|
136
|
+
const [notice, setNotice] = React.useState("");
|
|
137
|
+
const [busy, setBusy] = React.useState(false);
|
|
138
|
+
const [data, setData] = React.useState(null);
|
|
139
|
+
const [workId, setWorkId] = React.useState("");
|
|
140
|
+
const [canon, setCanon] = React.useState(null);
|
|
141
|
+
const [importTitle, setImportTitle] = React.useState("");
|
|
142
|
+
const [importText, setImportText] = React.useState("");
|
|
143
|
+
const [importMax, setImportMax] = React.useState("");
|
|
144
|
+
const [importNames, setImportNames] = React.useState("");
|
|
145
|
+
const [task, setTask] = React.useState("cover");
|
|
146
|
+
const [profileId, setProfileId] = React.useState("natural-zh");
|
|
147
|
+
const [platformId, setPlatformId] = React.useState("qidian");
|
|
148
|
+
const [pack, setPack] = React.useState(null);
|
|
149
|
+
const [paste, setPaste] = React.useState("");
|
|
150
|
+
const [draft, setDraft] = React.useState(null);
|
|
151
|
+
const [draftPreview, setDraftPreview] = React.useState("");
|
|
152
|
+
const [critique, setCritique] = React.useState(null);
|
|
153
|
+
const [revision, setRevision] = React.useState(null);
|
|
154
|
+
const [assets, setAssets] = React.useState([]);
|
|
155
|
+
const [assetPreview, setAssetPreview] = React.useState("");
|
|
156
|
+
const [assetCharacter, setAssetCharacter] = React.useState("");
|
|
157
|
+
const [assetKind, setAssetKind] = React.useState("face");
|
|
158
|
+
const [assetNote, setAssetNote] = React.useState("");
|
|
159
|
+
const [critiqueHistory, setCritiqueHistory] = React.useState([]);
|
|
160
|
+
const [comparison, setComparison] = React.useState(null);
|
|
161
|
+
const [styles, setStyles] = React.useState([]);
|
|
162
|
+
const [styleId, setStyleId] = React.useState("");
|
|
163
|
+
const [searchQuery, setSearchQuery] = React.useState("");
|
|
164
|
+
const [searchResults, setSearchResults] = React.useState([]);
|
|
165
|
+
const [bgId, setBgId] = React.useState(() => {
|
|
166
|
+
try { return localStorage.getItem("dsh-novel-image-bg") || "paper"; } catch { return "paper"; }
|
|
167
|
+
});
|
|
168
|
+
const [coverPlan, setCoverPlan] = React.useState(null);
|
|
169
|
+
const [coverImage, setCoverImage] = React.useState("");
|
|
170
|
+
const [coverTitle, setCoverTitle] = React.useState("");
|
|
171
|
+
const [coverAuthor, setCoverAuthor] = React.useState("");
|
|
172
|
+
const [coverLayout, setCoverLayout] = React.useState("top");
|
|
173
|
+
const [coverResult, setCoverResult] = React.useState("");
|
|
174
|
+
const [variantLabel, setVariantLabel] = React.useState("");
|
|
175
|
+
const [variantFrom, setVariantFrom] = React.useState("1");
|
|
176
|
+
const [variantTo, setVariantTo] = React.useState("");
|
|
177
|
+
const [variantReason, setVariantReason] = React.useState("");
|
|
178
|
+
const [providers, setProviders] = React.useState([]);
|
|
179
|
+
const [jobs, setJobs] = React.useState([]);
|
|
180
|
+
const [jobProvider, setJobProvider] = React.useState("mock");
|
|
181
|
+
const [providerLabel, setProviderLabel] = React.useState("");
|
|
182
|
+
const [providerKind, setProviderKind] = React.useState("comfyui");
|
|
183
|
+
const [providerEndpoint, setProviderEndpoint] = React.useState("http://127.0.0.1:8188");
|
|
184
|
+
const [providerModel, setProviderModel] = React.useState("");
|
|
185
|
+
const [providerWorkflow, setProviderWorkflow] = React.useState("");
|
|
186
|
+
const [providerCredential, setProviderCredential] = React.useState("");
|
|
187
|
+
const [providerReferenceImages, setProviderReferenceImages] = React.useState("1");
|
|
188
|
+
const [providerEdit, setProviderEdit] = React.useState(false);
|
|
189
|
+
const [providerMaxAttempts, setProviderMaxAttempts] = React.useState("1");
|
|
190
|
+
const [providerRetryDelay, setProviderRetryDelay] = React.useState("800");
|
|
191
|
+
const [providerMinInterval, setProviderMinInterval] = React.useState("0");
|
|
192
|
+
const [providerTestResult, setProviderTestResult] = React.useState(null);
|
|
193
|
+
const coverCanvas = React.useRef(null);
|
|
194
|
+
const theme = BG_THEMES.find((item) => item.id === bgId) ?? BG_THEMES[0];
|
|
195
|
+
React.useEffect(() => {
|
|
196
|
+
try { localStorage.setItem("dsh-novel-image-bg", bgId); } catch { /* ignore */ }
|
|
197
|
+
}, [bgId]);
|
|
198
|
+
|
|
199
|
+
const flash = (message) => { setNotice(message); setTimeout(() => setNotice(""), 2500); };
|
|
200
|
+
|
|
201
|
+
const loadCanon = async (id) => {
|
|
202
|
+
if (!id) return;
|
|
203
|
+
try {
|
|
204
|
+
const value = unwrap(await remote.getCanon(sessionId, { workId: id }));
|
|
205
|
+
setCanon(value);
|
|
206
|
+
} catch (e) {
|
|
207
|
+
setError(String(e?.message ?? e));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const loadAssets = async (id) => {
|
|
212
|
+
if (!id) return;
|
|
213
|
+
try {
|
|
214
|
+
const value = unwrap(await remote.listAssets(sessionId, { workId: id }));
|
|
215
|
+
setAssets(value.assets ?? []);
|
|
216
|
+
} catch (e) {
|
|
217
|
+
setError(String(e?.message ?? e));
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const loadCritiques = async (id) => {
|
|
222
|
+
if (!id) return;
|
|
223
|
+
try {
|
|
224
|
+
const value = unwrap(await remote.listCritiques(sessionId, { workId: id, limit: 12 }));
|
|
225
|
+
setCritiqueHistory(value.critiques ?? []);
|
|
226
|
+
} catch {
|
|
227
|
+
setCritiqueHistory([]);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const loadStyles = async (id) => {
|
|
232
|
+
if (!id) return;
|
|
233
|
+
try {
|
|
234
|
+
const value = unwrap(await remote.listStyles(sessionId, { workId: id }));
|
|
235
|
+
setStyles(value.styles ?? []);
|
|
236
|
+
} catch {
|
|
237
|
+
setStyles([]);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const loadProviders = async () => {
|
|
242
|
+
try {
|
|
243
|
+
const value = unwrap(await remote.listProviders(sessionId));
|
|
244
|
+
setProviders(value.providers ?? []);
|
|
245
|
+
} catch {
|
|
246
|
+
setProviders([]);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const loadJobs = async (id) => {
|
|
251
|
+
if (!id) return;
|
|
252
|
+
try {
|
|
253
|
+
const value = unwrap(await remote.listJobs(sessionId, { workId: id }));
|
|
254
|
+
setJobs(value.jobs ?? []);
|
|
255
|
+
} catch {
|
|
256
|
+
setJobs([]);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const refresh = async (preferred) => {
|
|
261
|
+
setError("");
|
|
262
|
+
if (!remote?.status) {
|
|
263
|
+
setError("右栏连接未就绪:请重新打开「图像」面板,或重装插件后再试。");
|
|
264
|
+
setPhase("error");
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const value = unwrap(await remote.status(sessionId));
|
|
269
|
+
setData(value);
|
|
270
|
+
const next = preferred || workId || value.works?.[0]?.workId || "";
|
|
271
|
+
setWorkId(next);
|
|
272
|
+
if (next) {
|
|
273
|
+
await loadCanon(next);
|
|
274
|
+
await loadAssets(next);
|
|
275
|
+
await loadCritiques(next);
|
|
276
|
+
await loadStyles(next);
|
|
277
|
+
await loadJobs(next);
|
|
278
|
+
}
|
|
279
|
+
await loadProviders();
|
|
280
|
+
setPhase("ready");
|
|
281
|
+
} catch (e) {
|
|
282
|
+
setError(String(e?.message ?? e));
|
|
283
|
+
setPhase("error");
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
React.useEffect(() => { refresh(); }, []);
|
|
288
|
+
|
|
289
|
+
const run = async (fn) => {
|
|
290
|
+
setBusy(true);
|
|
291
|
+
setError("");
|
|
292
|
+
try { return await fn(); }
|
|
293
|
+
catch (e) { setError(String(e?.message ?? e)); return null; }
|
|
294
|
+
finally { setBusy(false); }
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const doImport = () => run(async () => {
|
|
298
|
+
if (!importText.trim()) throw new Error("先粘贴正文。");
|
|
299
|
+
const value = unwrap(await remote.importText(sessionId, {
|
|
300
|
+
title: importTitle.trim() || "未命名作品",
|
|
301
|
+
text: importText,
|
|
302
|
+
maxChapterIndex: importMax ? Number(importMax) : undefined,
|
|
303
|
+
characterNames: importNames.split(/[,,、\s]+/).map((item) => item.trim()).filter(Boolean),
|
|
304
|
+
}));
|
|
305
|
+
setImportText("");
|
|
306
|
+
await refresh(value.workId);
|
|
307
|
+
flash("已导入并生成初版视觉设定");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const doCompile = () => run(async () => {
|
|
311
|
+
if (!workId) throw new Error("先导入作品。");
|
|
312
|
+
const value = unwrap(await remote.compile(sessionId, {
|
|
313
|
+
workId, task, profileId,
|
|
314
|
+
platformId: task === "cover" ? platformId : undefined,
|
|
315
|
+
chapterIndex: canon?.maxChapterIndex,
|
|
316
|
+
characterIds: canon?.characters?.map((character) => character.characterId) ?? [],
|
|
317
|
+
includeDraft: true,
|
|
318
|
+
styleId: styleId || undefined,
|
|
319
|
+
}));
|
|
320
|
+
setPack(value);
|
|
321
|
+
const text = unwrap(await remote.exportPack(sessionId, { workId, packId: value.packId, format: "text" }));
|
|
322
|
+
setPaste(text.content || "");
|
|
323
|
+
flash("提示词包已生成");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
const doAnchor = (anchorId, patch) => run(async () => {
|
|
327
|
+
const value = unwrap(await remote.updateAnchor(sessionId, {
|
|
328
|
+
workId, anchorId, patch, expectedRevision: canon?.revision,
|
|
329
|
+
}));
|
|
330
|
+
setCanon(value.canon);
|
|
331
|
+
flash("已更新;锁定项不会被重抽覆盖");
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const doAddVariant = (character) => run(async () => {
|
|
335
|
+
if (!variantLabel.trim()) throw new Error("先给变体起个名字(如“受伤”“换装”)。");
|
|
336
|
+
const value = unwrap(await remote.addVariant(sessionId, {
|
|
337
|
+
workId,
|
|
338
|
+
characterId: character.characterId,
|
|
339
|
+
label: variantLabel.trim(),
|
|
340
|
+
fromChapter: Number(variantFrom || 1),
|
|
341
|
+
toChapter: variantTo ? Number(variantTo) : undefined,
|
|
342
|
+
reason: variantReason.trim(),
|
|
343
|
+
expectedRevision: canon?.revision,
|
|
344
|
+
}));
|
|
345
|
+
setCanon(value.canon);
|
|
346
|
+
setVariantLabel("");
|
|
347
|
+
setVariantReason("");
|
|
348
|
+
flash("变体已添加;切换章节编译时会自动生效");
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const doRemoveVariant = (character, variant) => run(async () => {
|
|
352
|
+
const value = unwrap(await remote.removeVariant(sessionId, {
|
|
353
|
+
workId,
|
|
354
|
+
characterId: character.characterId,
|
|
355
|
+
variantId: variant.variantId,
|
|
356
|
+
expectedRevision: canon?.revision,
|
|
357
|
+
}));
|
|
358
|
+
setCanon(value);
|
|
359
|
+
flash("变体已删除");
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
const readFile = (file) => new Promise((resolve, reject) => {
|
|
363
|
+
if (!file) return resolve("");
|
|
364
|
+
const reader = new FileReader();
|
|
365
|
+
reader.onload = () => resolve(String(reader.result ?? ""));
|
|
366
|
+
reader.onerror = () => reject(reader.error ?? new Error("读取图片失败"));
|
|
367
|
+
reader.readAsDataURL(file);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const doDraft = (file, dataUrl = draftPreview) => run(async () => {
|
|
371
|
+
if (!file) throw new Error("先选一张首稿图片。");
|
|
372
|
+
if (!pack) throw new Error("先在「提示词」里编译一个包,首稿才有对照目标。");
|
|
373
|
+
const base64 = String(dataUrl).replace(/^data:[^;]+;base64,/, "");
|
|
374
|
+
if (!base64) throw new Error("图片读取失败,请重选。");
|
|
375
|
+
const value = unwrap(await remote.importDraft(sessionId, {
|
|
376
|
+
workId, packId: pack.packId, dataBase64: base64, mime: file.type || "image/png",
|
|
377
|
+
}));
|
|
378
|
+
setDraft(value);
|
|
379
|
+
setCritique(null);
|
|
380
|
+
setRevision(null);
|
|
381
|
+
flash("首稿已导入,可以读图回改");
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const doCritique = () => run(async () => {
|
|
385
|
+
if (!draft) throw new Error("先导入首稿。");
|
|
386
|
+
const value = unwrap(await remote.critiqueDraft(sessionId, { workId, draftId: draft.draftId, packId: pack?.packId }));
|
|
387
|
+
setCritique(value);
|
|
388
|
+
setRevision(null);
|
|
389
|
+
setComparison(null);
|
|
390
|
+
await loadCritiques(workId);
|
|
391
|
+
flash("读图完成;请看 keep/fix");
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
const doCompare = () => run(async () => {
|
|
395
|
+
if (!critique) throw new Error("先读图回改。");
|
|
396
|
+
const previous = critiqueHistory.find((item) => item.critiqueId !== critique.critiqueId && (!pack?.packId || item.packId === pack.packId));
|
|
397
|
+
if (!previous) throw new Error("还没有上一版审稿;先导入二稿再读一次图。");
|
|
398
|
+
const value = unwrap(await remote.compareCritiques(sessionId, {
|
|
399
|
+
workId, baseCritiqueId: previous.critiqueId, nextCritiqueId: critique.critiqueId,
|
|
400
|
+
}));
|
|
401
|
+
setComparison(value);
|
|
402
|
+
flash("已对比上一版");
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
const doImportAsset = (file, dataUrl) => run(async () => {
|
|
406
|
+
if (!file) throw new Error("先选一张图片。");
|
|
407
|
+
const base64 = String(dataUrl).replace(/^data:[^;]+;base64,/, "");
|
|
408
|
+
if (!base64) throw new Error("图片读取失败,请重选。");
|
|
409
|
+
unwrap(await remote.importAsset(sessionId, {
|
|
410
|
+
workId,
|
|
411
|
+
dataBase64: base64,
|
|
412
|
+
mime: file.type || "image/png",
|
|
413
|
+
characterId: assetCharacter || undefined,
|
|
414
|
+
kind: assetKind,
|
|
415
|
+
note: assetNote,
|
|
416
|
+
source: "user",
|
|
417
|
+
}));
|
|
418
|
+
await loadAssets(workId);
|
|
419
|
+
flash("已加入资产库;可设为参考图");
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const doSetReference = (assetId, reference, asset = null) => run(async () => {
|
|
423
|
+
unwrap(await remote.setAssetReference(sessionId, {
|
|
424
|
+
workId, assetId, reference,
|
|
425
|
+
characterId: asset?.characterId || assetCharacter || undefined,
|
|
426
|
+
kind: asset?.kind || assetKind,
|
|
427
|
+
}));
|
|
428
|
+
await loadAssets(workId);
|
|
429
|
+
flash(reference ? "已设为角色参考图;重新编译后进入参考图槽位" : "已取消参考图");
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
const doAnalyzeStyle = (asset) => run(async () => {
|
|
433
|
+
const value = unwrap(await remote.analyzeStyle(sessionId, {
|
|
434
|
+
workId, assetId: asset.assetId, kind: asset.kind === "full-body" || asset.kind === "face" || asset.kind === "outfit" ? "character" : "cover",
|
|
435
|
+
}));
|
|
436
|
+
await loadStyles(workId);
|
|
437
|
+
setStyleId(value.styleId);
|
|
438
|
+
flash("风格档案已生成;编译时可套用");
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
const doSearch = () => run(async () => {
|
|
442
|
+
if (!searchQuery.trim()) throw new Error("先输入搜索词。");
|
|
443
|
+
const value = unwrap(await remote.searchReferences(sessionId, { query: searchQuery.trim(), maxResults: 8 }));
|
|
444
|
+
setSearchResults(value.sources ?? []);
|
|
445
|
+
flash(`找到 ${value.sources?.length ?? 0} 条参考;保存图片后用「选文件」导入`);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const doImportFolder = (files) => run(async () => {
|
|
449
|
+
const list = Array.from(files ?? []).filter((file) => /^image\//.test(file.type)).slice(0, 20);
|
|
450
|
+
if (!list.length) throw new Error("文件夹里没有图片。");
|
|
451
|
+
let ok = 0;
|
|
452
|
+
for (const file of list) {
|
|
453
|
+
try {
|
|
454
|
+
const dataUrl = await readFile(file);
|
|
455
|
+
await remote.importAsset(sessionId, {
|
|
456
|
+
workId,
|
|
457
|
+
dataBase64: String(dataUrl).replace(/^data:[^;]+;base64,/, ""),
|
|
458
|
+
mime: file.type || "image/png",
|
|
459
|
+
kind: assetKind,
|
|
460
|
+
source: "user",
|
|
461
|
+
});
|
|
462
|
+
ok += 1;
|
|
463
|
+
} catch (error) {
|
|
464
|
+
console.error("[novel-image] folder import", file.name, error);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
await loadAssets(workId);
|
|
468
|
+
flash(`文件夹导入 ${ok}/${list.length} 张;可逐张学风格`);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
const doCoverPlan = () => run(async () => {
|
|
472
|
+
const value = unwrap(await remote.coverPlan(sessionId, {
|
|
473
|
+
workId, platformId, layout: coverLayout,
|
|
474
|
+
title: coverTitle || canon?.cover?.title || "",
|
|
475
|
+
author: coverAuthor || canon?.cover?.author || "",
|
|
476
|
+
}));
|
|
477
|
+
setCoverPlan(value);
|
|
478
|
+
flash("封面构图方案已生成");
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const drawCover = () => {
|
|
482
|
+
if (!coverImage) throw new Error("先选一张底图。");
|
|
483
|
+
const canvas = coverCanvas.current;
|
|
484
|
+
if (!canvas) throw new Error("画布未就绪。");
|
|
485
|
+
const plan = coverPlan;
|
|
486
|
+
const width = plan?.platform?.width || 768;
|
|
487
|
+
const height = plan?.platform?.height || 1024;
|
|
488
|
+
canvas.width = width;
|
|
489
|
+
canvas.height = height;
|
|
490
|
+
const ctx = canvas.getContext("2d");
|
|
491
|
+
return new Promise((resolve, reject) => {
|
|
492
|
+
const image = new Image();
|
|
493
|
+
image.onload = () => {
|
|
494
|
+
try {
|
|
495
|
+
ctx.drawImage(image, 0, 0, width, height);
|
|
496
|
+
const title = coverTitle || canon?.cover?.title || "未命名作品";
|
|
497
|
+
const author = coverAuthor || canon?.cover?.author || "";
|
|
498
|
+
const safe = coverPlan?.safeArea;
|
|
499
|
+
const layout = coverLayout;
|
|
500
|
+
const bandX = Math.round(width * ((safe?.leftPct ?? (layout === "split" ? 55 : 0)) / 100));
|
|
501
|
+
const bandY = Math.round(height * ((safe?.topPct ?? (layout === "bottom" ? 72 : layout === "center" ? 36 : 0)) / 100));
|
|
502
|
+
const bandW = Math.round(width * (((safe ? (100 - safe.leftPct - safe.rightPct) : layout === "split" ? 45 : 100)) / 100));
|
|
503
|
+
const bandHeight = Math.round(height * (((safe ? safe.bottomPct - safe.topPct : layout === "bottom" ? 28 : layout === "center" ? 28 : 30)) / 100));
|
|
504
|
+
ctx.fillStyle = "rgba(12,16,18,.58)";
|
|
505
|
+
ctx.fillRect(bandX, bandY, bandW, bandHeight);
|
|
506
|
+
ctx.fillStyle = "#fff";
|
|
507
|
+
ctx.textAlign = "center";
|
|
508
|
+
ctx.textBaseline = "middle";
|
|
509
|
+
const fontSize = Math.max(18, Math.round(bandW * 0.075));
|
|
510
|
+
ctx.font = `700 ${fontSize}px "Microsoft YaHei", "Source Han Serif SC", serif`;
|
|
511
|
+
const maxWidth = bandW * 0.86;
|
|
512
|
+
const chars = [...title];
|
|
513
|
+
const lines = [];
|
|
514
|
+
let line = "";
|
|
515
|
+
for (const char of chars) {
|
|
516
|
+
if (ctx.measureText(line + char).width > maxWidth && line) {
|
|
517
|
+
lines.push(line);
|
|
518
|
+
line = char;
|
|
519
|
+
} else {
|
|
520
|
+
line += char;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (line) lines.push(line);
|
|
524
|
+
const visibleLines = lines.slice(0, 3);
|
|
525
|
+
if (lines.length > 3 && visibleLines[2]) visibleLines[2] = `${visibleLines[2].slice(0, -1)}…`;
|
|
526
|
+
const lineHeight = fontSize * 1.2;
|
|
527
|
+
const startY = bandY + bandHeight / 2 - ((visibleLines.length - 1) * lineHeight) / 2 - (author ? fontSize * 0.35 : 0);
|
|
528
|
+
visibleLines.forEach((text, index) => ctx.fillText(text, bandX + bandW / 2, startY + index * lineHeight));
|
|
529
|
+
if (author) {
|
|
530
|
+
ctx.font = `400 ${Math.max(12, Math.round(fontSize * 0.4))}px "Microsoft YaHei", sans-serif`;
|
|
531
|
+
ctx.fillText(author, bandX + bandW / 2, bandY + bandHeight - fontSize * 0.55);
|
|
532
|
+
}
|
|
533
|
+
resolve(canvas.toDataURL("image/png"));
|
|
534
|
+
} catch (error) {
|
|
535
|
+
reject(error);
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
image.onerror = () => reject(new Error("底图加载失败"));
|
|
539
|
+
image.src = coverImage;
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const doExportCover = () => run(async () => {
|
|
544
|
+
const dataUrl = await drawCover();
|
|
545
|
+
setCoverResult(dataUrl);
|
|
546
|
+
const link = document.createElement("a");
|
|
547
|
+
link.href = dataUrl;
|
|
548
|
+
link.download = `cover-${Date.now()}.png`;
|
|
549
|
+
link.click();
|
|
550
|
+
flash("封面已导出 PNG(叠加标题/作者)");
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const doSaveProvider = () => run(async () => {
|
|
554
|
+
const profileId = providerKind === "mock"
|
|
555
|
+
? "mock"
|
|
556
|
+
: (providerLabel.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || `${providerKind}-local`);
|
|
557
|
+
const saved = unwrap(await remote.saveProvider(sessionId, {
|
|
558
|
+
profileId, label: providerLabel.trim() || profileId, kind: providerKind,
|
|
559
|
+
endpoint: providerEndpoint.trim(), model: providerModel.trim(),
|
|
560
|
+
workflowId: providerWorkflow.trim(), credentialRef: providerCredential.trim(),
|
|
561
|
+
capabilities: { referenceImages: Number(providerReferenceImages || 0), edit: providerEdit },
|
|
562
|
+
maxAttempts: Number(providerMaxAttempts || 1),
|
|
563
|
+
retryDelayMs: Number(providerRetryDelay || 0),
|
|
564
|
+
minIntervalMs: Number(providerMinInterval || 0),
|
|
565
|
+
}));
|
|
566
|
+
await loadProviders();
|
|
567
|
+
setJobProvider(saved.profileId);
|
|
568
|
+
flash(`provider 已保存:${saved.profileId}(未测试连接)`);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
const doSubmitJob = () => run(async () => {
|
|
572
|
+
if (!pack?.packId) throw new Error("先在提示词 Tab 编译一个提示词包。");
|
|
573
|
+
const value = unwrap(await remote.submitJob(sessionId, { workId, packId: pack.packId, providerId: jobProvider }));
|
|
574
|
+
await loadJobs(workId);
|
|
575
|
+
await loadAssets(workId);
|
|
576
|
+
flash(value.job?.status === "succeeded" ? `任务成功:${value.job.result?.assetIds?.length ?? 0} 张结果已入资产库` : `任务状态:${value.job?.status ?? "unknown"}`);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
const doCancelJob = (job) => run(async () => {
|
|
580
|
+
const value = unwrap(await remote.cancelJob(sessionId, { workId, jobId: job.jobId }));
|
|
581
|
+
await loadJobs(workId);
|
|
582
|
+
flash(`任务状态:${value.status}`);
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
const doRetryJob = (job) => run(async () => {
|
|
586
|
+
const value = unwrap(await remote.retryJob(sessionId, { workId, jobId: job.jobId }));
|
|
587
|
+
await loadJobs(workId);
|
|
588
|
+
await loadAssets(workId);
|
|
589
|
+
flash(`重试任务:${value.job?.status ?? "unknown"}`);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
const doTestProvider = (providerId) => run(async () => {
|
|
593
|
+
const value = unwrap(await remote.testProvider(sessionId, { providerId }));
|
|
594
|
+
setProviderTestResult(value);
|
|
595
|
+
flash(`${value.ok ? "连接成功" : "连接失败"}:${value.detail}`);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
const doRevise = (mode) => run(async () => {
|
|
599
|
+
if (!critique) throw new Error("先读图回改。");
|
|
600
|
+
const value = unwrap(await remote.reviseDraft(sessionId, {
|
|
601
|
+
workId, critiqueId: critique.critiqueId, packId: pack?.packId, mode,
|
|
602
|
+
}));
|
|
603
|
+
setRevision(value);
|
|
604
|
+
flash("修改提示词已生成");
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
const copy = async (text) => {
|
|
608
|
+
try { await navigator.clipboard.writeText(text); flash("已复制"); }
|
|
609
|
+
catch { setError("复制失败,请手动选中复制。"); }
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
if (phase === "loading") return h("div", { style: S.root }, "加载中…");
|
|
613
|
+
if (phase === "error") return h("div", { style: S.root }, h("div", { style: S.card }, error || "加载失败"), h("button", { style: S.primary, onClick: () => refresh() }, "重试"));
|
|
614
|
+
|
|
615
|
+
const works = data?.works ?? [];
|
|
616
|
+
const profiles = data?.profiles ?? [];
|
|
617
|
+
const platforms = data?.platforms ?? [];
|
|
618
|
+
|
|
619
|
+
return h("div", { style: { ...S.root, background: theme.bg } },
|
|
620
|
+
h("div", { style: S.row },
|
|
621
|
+
h("h2", { style: S.title }, "视觉设定"),
|
|
622
|
+
h("span", { style: { ...S.chip(C.faint), marginLeft: "auto" } }, "0.4.3"),
|
|
623
|
+
),
|
|
624
|
+
h("div", { style: S.sub }, "从正文长出有原文依据的设定;出图仍用外部工具。"),
|
|
625
|
+
h("div", { style: { ...S.row, gap: 4, marginBottom: 8 } },
|
|
626
|
+
h("span", { style: { color: C.muted, fontSize: 11, marginRight: 4 } }, "底色"),
|
|
627
|
+
BG_THEMES.map((item) => h("button", {
|
|
628
|
+
key: item.id,
|
|
629
|
+
title: item.name,
|
|
630
|
+
"aria-label": `底色:${item.name}`,
|
|
631
|
+
onClick: () => setBgId(item.id),
|
|
632
|
+
style: {
|
|
633
|
+
width: 18, height: 18, borderRadius: 999, cursor: "pointer", padding: 0,
|
|
634
|
+
background: item.bg, border: item.id === bgId ? `2px solid ${C.accent}` : `1px solid ${C.line}`,
|
|
635
|
+
},
|
|
636
|
+
})),
|
|
637
|
+
),
|
|
638
|
+
error ? h("div", { style: { ...S.card, color: C.danger } }, error) : null,
|
|
639
|
+
notice ? h("div", { style: { ...S.card, color: C.ok } }, notice) : null,
|
|
640
|
+
|
|
641
|
+
h("div", { style: S.card },
|
|
642
|
+
h("div", { style: S.row },
|
|
643
|
+
h("select", { style: { ...S.input, flex: 1 }, value: workId, onChange: (event) => { const id = event.target.value; setWorkId(id); loadCanon(id); loadAssets(id); loadCritiques(id); loadStyles(id); loadJobs(id); } },
|
|
644
|
+
works.length ? works.map((work) => h("option", { key: work.workId, value: work.workId }, `${work.title}(${work.chapterCount}章)`)) : h("option", { value: "" }, "还没有作品"),
|
|
645
|
+
),
|
|
646
|
+
h("button", { style: S.ghost, onClick: () => refresh() }, "刷新"),
|
|
647
|
+
),
|
|
648
|
+
h("details", { style: { marginTop: 8 } },
|
|
649
|
+
h("summary", { style: { cursor: "pointer", color: C.muted, fontSize: 12 } }, "导入新作品"),
|
|
650
|
+
h("div", { style: S.label }, "作品名"),
|
|
651
|
+
h("input", { style: S.input, value: importTitle, onChange: (event) => setImportTitle(event.target.value), placeholder: "雨夜" }),
|
|
652
|
+
h("div", { style: S.label }, "正文(TXT/MD 文本)"),
|
|
653
|
+
h("textarea", { style: S.area, value: importText, onChange: (event) => setImportText(event.target.value), placeholder: "粘贴正文…" }),
|
|
654
|
+
h("div", { style: S.row },
|
|
655
|
+
h("input", { style: { ...S.input, flex: 1 }, value: importMax, onChange: (event) => setImportMax(event.target.value), placeholder: "剧透边界:到第 N 章(可空)" }),
|
|
656
|
+
h("input", { style: { ...S.input, flex: 1 }, value: importNames, onChange: (event) => setImportNames(event.target.value), placeholder: "角色名,用逗号分隔" }),
|
|
657
|
+
),
|
|
658
|
+
h("div", { style: { ...S.row, marginTop: 6 } }, h("button", { style: S.primary, disabled: busy, onClick: doImport }, busy ? "处理中…" : "导入并抽取")),
|
|
659
|
+
),
|
|
660
|
+
),
|
|
661
|
+
|
|
662
|
+
h("div", { style: { ...S.row, margin: "6px 0 10px" } },
|
|
663
|
+
h("button", { style: S.tab(tab === "canon"), onClick: () => setTab("canon") }, "设定"),
|
|
664
|
+
h("button", { style: S.tab(tab === "prompt"), onClick: () => setTab("prompt") }, "提示词"),
|
|
665
|
+
h("button", { style: S.tab(tab === "critique"), onClick: () => setTab("critique") }, "回改"),
|
|
666
|
+
h("button", { style: S.tab(tab === "assets"), onClick: () => setTab("assets") }, "资产"),
|
|
667
|
+
h("button", { style: S.tab(tab === "cover"), onClick: () => setTab("cover") }, "封面"),
|
|
668
|
+
h("button", { style: S.tab(tab === "jobs"), onClick: () => setTab("jobs") }, "任务"),
|
|
669
|
+
),
|
|
670
|
+
|
|
671
|
+
tab === "canon" ? renderCanon() : null,
|
|
672
|
+
tab === "prompt" ? renderPrompt() : null,
|
|
673
|
+
tab === "critique" ? renderCritique() : null,
|
|
674
|
+
tab === "assets" ? renderAssets() : null,
|
|
675
|
+
tab === "cover" ? renderCover() : null,
|
|
676
|
+
tab === "jobs" ? renderJobs() : null,
|
|
677
|
+
);
|
|
678
|
+
|
|
679
|
+
function renderCanon() {
|
|
680
|
+
if (!canon) return h("div", { style: S.card }, "先导入作品。");
|
|
681
|
+
return h("div", null,
|
|
682
|
+
h("div", { style: S.sub }, `revision ${canon.revision} · 剧透边界第 ${canon.maxChapterIndex} 章 · ${canon.style?.genre ?? "通用"} / ${canon.style?.medium ?? ""}`),
|
|
683
|
+
(canon.characters ?? []).map((character) =>
|
|
684
|
+
h("div", { key: character.characterId, style: S.card },
|
|
685
|
+
h("div", { style: { fontWeight: 700, marginBottom: 6 } }, character.name),
|
|
686
|
+
character.anchors?.length ? character.anchors.map((anchor) =>
|
|
687
|
+
h("div", { key: anchor.anchorId, style: { borderTop: `1px solid ${C.line}`, paddingTop: 6, marginTop: 6 } },
|
|
688
|
+
h("div", { style: S.row },
|
|
689
|
+
h("span", { style: S.chip(C.muted) }, KIND[anchor.kind] ?? anchor.kind),
|
|
690
|
+
h("span", { style: { flex: 1, fontSize: 12.5 } }, anchor.value),
|
|
691
|
+
h("span", { style: S.chip(anchor.status === "locked" ? C.ok : anchor.status === "rejected" ? C.danger : C.faint) }, anchor.status),
|
|
692
|
+
),
|
|
693
|
+
anchor.evidence?.[0] ? h("div", { style: { color: C.muted, fontSize: 11, marginTop: 4, lineHeight: 1.5 } }, `第${anchor.evidence[0].chapterIndex}章 · ${anchor.evidence[0].quote.slice(0, 110)}`) : null,
|
|
694
|
+
h("div", { style: { ...S.row, marginTop: 5 } },
|
|
695
|
+
h("button", { style: S.ghost, onClick: () => doAnchor(anchor.anchorId, { status: "confirmed" }) }, "确认"),
|
|
696
|
+
h("button", { style: S.ghost, onClick: () => doAnchor(anchor.anchorId, { status: "locked" }) }, "锁定"),
|
|
697
|
+
h("button", { style: S.ghost, onClick: () => doAnchor(anchor.anchorId, { status: "rejected" }) }, "否决"),
|
|
698
|
+
),
|
|
699
|
+
),
|
|
700
|
+
) : h("div", { style: { color: C.muted, fontSize: 12 } }, "没有锚点;可在「抽取」里补,或手动新增。"),
|
|
701
|
+
h("details", { style: { marginTop: 8 } },
|
|
702
|
+
h("summary", { style: { cursor: "pointer", color: C.muted, fontSize: 12 } }, `章节变体(${character.variants?.length ?? 0})`),
|
|
703
|
+
(character.variants ?? []).map((variant) => h("div", { key: variant.variantId, style: { ...S.row, marginTop: 6 } },
|
|
704
|
+
h("span", { style: { flex: 1, fontSize: 12 } }, `${variant.label}(第 ${variant.fromChapter}–${variant.toChapter} 章)`),
|
|
705
|
+
h("button", { style: S.ghost, onClick: () => doRemoveVariant(character, variant) }, "删除"),
|
|
706
|
+
)),
|
|
707
|
+
h("div", { style: { ...S.row, marginTop: 6 } },
|
|
708
|
+
h("input", { style: { ...S.input, flex: 1 }, value: variantLabel, onChange: (event) => setVariantLabel(event.target.value), placeholder: "变体名:受伤/换装" }),
|
|
709
|
+
h("input", { style: { ...S.input, width: 52 }, value: variantFrom, onChange: (event) => setVariantFrom(event.target.value), placeholder: "从" }),
|
|
710
|
+
h("input", { style: { ...S.input, width: 52 }, value: variantTo, onChange: (event) => setVariantTo(event.target.value), placeholder: "到" }),
|
|
711
|
+
),
|
|
712
|
+
h("input", { style: { ...S.input, marginTop: 6 }, value: variantReason, onChange: (event) => setVariantReason(event.target.value), placeholder: "原因(可空)" }),
|
|
713
|
+
h("div", { style: { ...S.row, marginTop: 6 } },
|
|
714
|
+
h("button", { style: S.ghost, disabled: busy, onClick: () => doAddVariant(character) }, "添加变体(复制当前锚点)"),
|
|
715
|
+
),
|
|
716
|
+
),
|
|
717
|
+
),
|
|
718
|
+
),
|
|
719
|
+
(canon.scenes ?? []).length ? h("div", { style: S.card },
|
|
720
|
+
h("div", { style: { fontWeight: 700, marginBottom: 6 } }, "名场面候选"),
|
|
721
|
+
canon.scenes.slice(0, 6).map((scene) => h("div", { key: scene.sceneId, style: { fontSize: 12, color: C.muted, marginBottom: 6, lineHeight: 1.5 } }, `第${scene.chapterIndex}章 · ${scene.summary}`)),
|
|
722
|
+
) : null,
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function renderPrompt() {
|
|
727
|
+
return h("div", null,
|
|
728
|
+
h("div", { style: S.card },
|
|
729
|
+
h("div", { style: S.label }, "任务"),
|
|
730
|
+
h("select", { style: S.input, value: task, onChange: (event) => setTask(event.target.value) },
|
|
731
|
+
Object.entries(TASK).map(([id, label]) => h("option", { key: id, value: id }, label)),
|
|
732
|
+
),
|
|
733
|
+
h("div", { style: S.label }, "目标工具"),
|
|
734
|
+
h("select", { style: S.input, value: profileId, onChange: (event) => setProfileId(event.target.value) },
|
|
735
|
+
profiles.map((profile) => h("option", { key: profile.id, value: profile.id }, profile.label)),
|
|
736
|
+
),
|
|
737
|
+
h("div", { style: S.label }, "套用风格档案"),
|
|
738
|
+
h("select", { style: S.input, value: styleId, onChange: (event) => setStyleId(event.target.value) },
|
|
739
|
+
h("option", { value: "" }, "不套用"),
|
|
740
|
+
styles.map((style) => h("option", { key: style.styleId, value: style.styleId }, style.name)),
|
|
741
|
+
),
|
|
742
|
+
task === "cover" ? h("div", null,
|
|
743
|
+
h("div", { style: S.label }, "平台预设"),
|
|
744
|
+
h("select", { style: S.input, value: platformId, onChange: (event) => setPlatformId(event.target.value) },
|
|
745
|
+
platforms.map((platform) => h("option", { key: platform.id, value: platform.id }, `${platform.label}${platform.status === "unverified" ? "(未核实)" : ""}`)),
|
|
746
|
+
),
|
|
747
|
+
) : null,
|
|
748
|
+
h("div", { style: { ...S.row, marginTop: 8 } }, h("button", { style: S.primary, disabled: busy, onClick: doCompile }, busy ? "编译中…" : "编译提示词包")),
|
|
749
|
+
),
|
|
750
|
+
pack ? h("div", { style: S.card },
|
|
751
|
+
h("div", { style: S.row }, h("strong", null, "提示词"), h("button", { style: { ...S.ghost, marginLeft: "auto" }, onClick: () => copy(pack.output.positive) }, "复制主提示词")),
|
|
752
|
+
h("pre", { style: S.pre }, pack.output.positive),
|
|
753
|
+
pack.output.negative ? h("div", null, h("div", { style: S.label }, "负面/避免"), h("pre", { style: S.pre }, pack.output.negative)) : null,
|
|
754
|
+
pack.warnings?.length ? h("div", { style: { color: C.warn, fontSize: 12, lineHeight: 1.5 } }, pack.warnings.join(";")) : null,
|
|
755
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 6 } }, pack.output.referencePlan?.slots?.length
|
|
756
|
+
? `参考图:${pack.output.referencePlan.slots.length} 张(${pack.output.referencePlan.slots.map((slot) => `${slot.role}·${slot.weight}`).join(";")})`
|
|
757
|
+
: "参考图:无(去「资产」设为参考图后重新编译)"),
|
|
758
|
+
h("div", { style: S.row }, h("button", { style: S.ghost, onClick: () => copy(paste) }, "复制完整带参包")),
|
|
759
|
+
h("details", { style: { marginTop: 8 } }, h("summary", { style: { cursor: "pointer", color: C.muted, fontSize: 12 } }, "完整粘贴块"), h("pre", { style: S.pre }, paste)),
|
|
760
|
+
) : h("div", { style: S.card, color: C.muted }, "还没有提示词包。"),
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function renderCritique() {
|
|
765
|
+
return h("div", null,
|
|
766
|
+
h("div", { style: S.card },
|
|
767
|
+
h("div", { style: S.sub }, "导入外部 AI 的首稿;插件读图对照视觉设定,输出 keep/fix 和下一版提示词。图会发给当前模型。"),
|
|
768
|
+
h("input", { type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", onChange: async (event) => {
|
|
769
|
+
const file = event.target.files?.[0];
|
|
770
|
+
try {
|
|
771
|
+
const dataUrl = await readFile(file);
|
|
772
|
+
setDraftPreview(dataUrl);
|
|
773
|
+
await doDraft(file, dataUrl);
|
|
774
|
+
} catch (error) {
|
|
775
|
+
setError(String(error?.message ?? error));
|
|
776
|
+
}
|
|
777
|
+
} }),
|
|
778
|
+
draftPreview ? h("img", { src: draftPreview, alt: "首稿预览", style: { maxWidth: "100%", borderRadius: 8, marginTop: 8, border: `1px solid ${C.line}` } }) : null,
|
|
779
|
+
h("div", { style: { ...S.row, marginTop: 8 } },
|
|
780
|
+
h("button", { style: S.primary, disabled: busy, onClick: doCritique }, busy ? "读图中…" : "读图回改"),
|
|
781
|
+
h("button", { style: S.ghost, disabled: busy, onClick: () => doRevise("edit") }, "生成 edit 提示词"),
|
|
782
|
+
h("button", { style: S.ghost, disabled: busy, onClick: () => doRevise("regenerate") }, "生成 regenerate 提示词"),
|
|
783
|
+
),
|
|
784
|
+
),
|
|
785
|
+
critique ? h("div", { style: S.card },
|
|
786
|
+
h("div", { style: S.row },
|
|
787
|
+
h("strong", null, "审稿结论"),
|
|
788
|
+
h("span", { style: S.chip(TONE[critique.overall] ?? C.faint) }, critique.overall),
|
|
789
|
+
h("button", { style: { ...S.ghost, marginLeft: "auto" }, disabled: busy, onClick: doCompare }, "对比上一版"),
|
|
790
|
+
),
|
|
791
|
+
h("div", { style: { color: C.muted, fontSize: 12, margin: "4px 0 8px" } }, critique.summary),
|
|
792
|
+
(critique.anchorChecks ?? []).map((check) => h("div", { key: check.anchorId, style: { borderTop: `1px solid ${C.line}`, paddingTop: 5, marginTop: 5 } },
|
|
793
|
+
h("div", { style: S.row },
|
|
794
|
+
h("span", { style: S.chip(TONE[check.status] ?? C.faint) }, check.status),
|
|
795
|
+
h("span", { style: { fontSize: 12.5 } }, `${check.character} · ${KIND[check.kind] ?? check.kind}`),
|
|
796
|
+
),
|
|
797
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 3 } }, `期望:${check.expected}${check.observed ? ` / 看到:${check.observed}` : ""}`),
|
|
798
|
+
)),
|
|
799
|
+
(critique.compositionChecks ?? []).map((check, index) => h("div", { key: `c${index}`, style: { color: C.muted, fontSize: 11.5, marginTop: 5 } }, `构图/${check.kind}:${check.status} ${check.note}`)),
|
|
800
|
+
(critique.styleChecks ?? []).map((check, index) => h("div", { key: `s${index}`, style: { color: C.muted, fontSize: 11.5, marginTop: 4 } }, `风格/${check.kind}:${check.status} ${check.note}`)),
|
|
801
|
+
critique.fix?.length ? h("div", { style: { marginTop: 8, fontSize: 12 } }, `要改:${critique.fix.join(";")}`) : null,
|
|
802
|
+
critique.keep?.length ? h("div", { style: { marginTop: 4, fontSize: 12, color: C.ok } }, `别动:${critique.keep.join(";")}`) : null,
|
|
803
|
+
critique.warnings?.length ? h("div", { style: { marginTop: 6, color: C.warn, fontSize: 11.5 } }, critique.warnings.join(";")) : null,
|
|
804
|
+
) : null,
|
|
805
|
+
revision ? h("div", { style: S.card },
|
|
806
|
+
h("div", { style: S.row }, h("strong", null, "修改提示词"), h("button", { style: { ...S.ghost, marginLeft: "auto" }, onClick: () => copy(revision.editPrompt) }, "复制 edit")),
|
|
807
|
+
h("div", { style: S.label }, "edit(保留构图)"),
|
|
808
|
+
h("pre", { style: S.pre }, revision.editPrompt),
|
|
809
|
+
h("div", { style: S.label }, "regenerate(重抽)"),
|
|
810
|
+
h("pre", { style: S.pre }, revision.regeneratePrompt),
|
|
811
|
+
revision.warnings?.length ? h("div", { style: { color: C.warn, fontSize: 11.5 } }, revision.warnings.join(";")) : null,
|
|
812
|
+
) : null,
|
|
813
|
+
comparison ? h("div", { style: S.card },
|
|
814
|
+
h("div", { style: S.row }, h("strong", null, "v1 → v2 对比"), h("span", { style: S.chip(C.faint), marginLeft: "auto" }, `${comparison.summary.resolved} 已解决 / ${comparison.summary.persisting} 还在 / ${comparison.summary.introduced} 新引入`)),
|
|
815
|
+
h("div", { style: { marginTop: 6, color: C.ok, fontSize: 12 } }, `已解决:${(comparison.resolved ?? []).map((item) => `${item.character}${item.kind}`).join(";") || "无"}`),
|
|
816
|
+
h("div", { style: { marginTop: 4, color: C.warn, fontSize: 12 } }, `还在:${(comparison.persisting ?? []).map((item) => `${item.character}${item.kind}`).join(";") || "无"}`),
|
|
817
|
+
h("div", { style: { marginTop: 4, color: C.danger, fontSize: 12 } }, `新引入:${(comparison.introduced ?? []).map((item) => `${item.character}${item.kind}`).join(";") || "无"}`),
|
|
818
|
+
) : null,
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function renderAssets() {
|
|
823
|
+
return h("div", null,
|
|
824
|
+
h("div", { style: S.card },
|
|
825
|
+
h("div", { style: S.sub }, "导入约稿图/参考图/风格图,绑定角色与用途;设为参考后,重新编译提示词包会自动生成参考图槽位。"),
|
|
826
|
+
h("input", { type: "file", accept: "image/png,image/jpeg,image/webp,image/gif", onChange: async (event) => {
|
|
827
|
+
const file = event.target.files?.[0];
|
|
828
|
+
try {
|
|
829
|
+
const dataUrl = await readFile(file);
|
|
830
|
+
setAssetPreview(dataUrl);
|
|
831
|
+
await doImportAsset(file, dataUrl);
|
|
832
|
+
} catch (error) {
|
|
833
|
+
setError(String(error?.message ?? error));
|
|
834
|
+
}
|
|
835
|
+
} }),
|
|
836
|
+
h("div", { style: { ...S.row, marginTop: 6 } },
|
|
837
|
+
h("label", { style: { ...S.ghost, cursor: "pointer" } },
|
|
838
|
+
"选文件夹",
|
|
839
|
+
h("input", { type: "file", webkitdirectory: "", multiple: true, style: { display: "none" }, onChange: (event) => doImportFolder(event.target.files) }),
|
|
840
|
+
),
|
|
841
|
+
h("span", { style: { color: C.muted, fontSize: 11 } }, "最多 20 张"),
|
|
842
|
+
),
|
|
843
|
+
h("div", { style: S.row },
|
|
844
|
+
h("select", { style: { ...S.input, flex: 1 }, value: assetCharacter, onChange: (event) => setAssetCharacter(event.target.value) },
|
|
845
|
+
h("option", { value: "" }, "不绑定角色"),
|
|
846
|
+
(canon?.characters ?? []).map((character) => h("option", { key: character.characterId, value: character.characterId }, character.name)),
|
|
847
|
+
),
|
|
848
|
+
h("select", { style: { ...S.input, flex: 1 }, value: assetKind, onChange: (event) => setAssetKind(event.target.value) },
|
|
849
|
+
[["face", "正脸"], ["full-body", "全身"], ["outfit", "服装"], ["style", "画风"], ["scene", "场景"], ["other", "其他"]].map(([id, label]) => h("option", { key: id, value: id }, label)),
|
|
850
|
+
),
|
|
851
|
+
),
|
|
852
|
+
h("input", { style: { ...S.input, marginTop: 6 }, value: assetNote, onChange: (event) => setAssetNote(event.target.value), placeholder: "来源/许可备注(可空)" }),
|
|
853
|
+
assetPreview ? h("img", { src: assetPreview, alt: "资产预览", style: { maxWidth: "100%", borderRadius: 8, marginTop: 8, border: `1px solid ${C.line}` } }) : null,
|
|
854
|
+
),
|
|
855
|
+
h("div", { style: S.card },
|
|
856
|
+
h("div", { style: S.label }, "联网找参考"),
|
|
857
|
+
h("div", { style: S.row },
|
|
858
|
+
h("input", { style: { ...S.input, flex: 1 }, value: searchQuery, onChange: (event) => setSearchQuery(event.target.value), placeholder: "如:古风小说封面 设计" }),
|
|
859
|
+
h("button", { style: S.ghost, disabled: busy, onClick: doSearch }, "搜索"),
|
|
860
|
+
),
|
|
861
|
+
(searchResults ?? []).map((item) => h("div", { key: item.url, style: { borderTop: `1px solid ${C.line}`, paddingTop: 5, marginTop: 5 } },
|
|
862
|
+
h("a", { href: item.url, target: "_blank", rel: "noreferrer", style: { color: C.accent, fontSize: 12.5 } }, item.title || item.url),
|
|
863
|
+
item.snippet ? h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 2 } }, item.snippet.slice(0, 120)) : null,
|
|
864
|
+
)),
|
|
865
|
+
h("div", { style: { color: C.muted, fontSize: 11, marginTop: 6 } }, "找到参考后保存到本地,再用上方「选文件/选文件夹」导入;不自动下载版权图。"),
|
|
866
|
+
),
|
|
867
|
+
assets.length ? assets.map((asset) => {
|
|
868
|
+
const character = (canon?.characters ?? []).find((item) => item.characterId === asset.characterId);
|
|
869
|
+
return h("div", { key: asset.assetId, style: S.card },
|
|
870
|
+
h("div", { style: S.row },
|
|
871
|
+
h("span", { style: S.chip(C.muted) }, asset.kind),
|
|
872
|
+
h("span", { style: { flex: 1, fontSize: 12.5 } }, `${character?.name ?? "未绑定"} · ${asset.width}×${asset.height}`),
|
|
873
|
+
h("span", { style: S.chip(asset.reference ? C.ok : C.faint) }, asset.reference ? "参考图" : "未设参考"),
|
|
874
|
+
),
|
|
875
|
+
asset.note ? h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 4 } }, asset.note) : null,
|
|
876
|
+
h("div", { style: { ...S.row, marginTop: 6 } },
|
|
877
|
+
h("button", { style: S.ghost, disabled: busy, onClick: () => doSetReference(asset.assetId, !asset.reference, asset) }, asset.reference ? "取消参考" : "设为参考"),
|
|
878
|
+
h("button", { style: S.ghost, disabled: busy, onClick: () => doAnalyzeStyle(asset) }, "学这张的风格"),
|
|
879
|
+
),
|
|
880
|
+
);
|
|
881
|
+
}) : h("div", { style: { ...S.card, color: C.muted } }, "还没有资产;先导入一张参考图。"),
|
|
882
|
+
styles.length ? h("div", { style: S.card },
|
|
883
|
+
h("div", { style: { fontWeight: 700, marginBottom: 6 } }, "风格档案"),
|
|
884
|
+
styles.map((style) => h("div", { key: style.styleId, style: { borderTop: `1px solid ${C.line}`, paddingTop: 6, marginTop: 6 } },
|
|
885
|
+
h("div", { style: S.row },
|
|
886
|
+
h("span", { style: { flex: 1, fontSize: 12.5 } }, style.name),
|
|
887
|
+
h("span", { style: S.chip(C.muted) }, style.kind),
|
|
888
|
+
h("button", { style: S.ghost, onClick: () => { setStyleId(style.styleId); setTab("prompt"); } }, "套用"),
|
|
889
|
+
),
|
|
890
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 3 } }, [style.medium, style.composition, style.layoutNotes].filter(Boolean).join(" · ").slice(0, 160)),
|
|
891
|
+
)),
|
|
892
|
+
) : null,
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function renderJobs() {
|
|
897
|
+
const current = providers.find((provider) => provider.profileId === jobProvider) ?? providers[0];
|
|
898
|
+
return h("div", null,
|
|
899
|
+
h("div", { style: S.card },
|
|
900
|
+
h("div", { style: S.sub }, "把提示词包提交给你配置的生图后端;结果自动入资产库。真实调用由你显式触发。"),
|
|
901
|
+
h("div", { style: S.label }, "提交到"),
|
|
902
|
+
h("select", { style: S.input, value: jobProvider, onChange: (event) => setJobProvider(event.target.value) },
|
|
903
|
+
providers.map((provider) => h("option", { key: provider.profileId, value: provider.profileId }, `${provider.label}(${provider.kind})`)),
|
|
904
|
+
),
|
|
905
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 4 } }, current ? `端点:${current.endpoint || "—"};状态:${current.status}` : "还没有 provider;在下方登记。"),
|
|
906
|
+
current ? h("div", { style: { ...S.row, marginTop: 4 } }, h("button", { style: S.ghost, disabled: busy, onClick: () => doTestProvider(current.profileId) }, "测试连接"), providerTestResult ? h("span", { style: { color: providerTestResult.ok ? C.ok : C.danger, fontSize: 11.5 } }, providerTestResult.detail) : null) : null,
|
|
907
|
+
h("div", { style: { ...S.row, marginTop: 8 } },
|
|
908
|
+
h("button", { style: S.primary, disabled: busy || !pack, onClick: doSubmitJob }, pack ? "提交当前提示词包" : "先编译提示词包"),
|
|
909
|
+
h("button", { style: S.ghost, disabled: busy, onClick: () => loadJobs(workId) }, "刷新任务"),
|
|
910
|
+
),
|
|
911
|
+
h("details", { style: { marginTop: 8 } },
|
|
912
|
+
h("summary", { style: { cursor: "pointer", color: C.muted, fontSize: 12 } }, "登记 / 修改 provider"),
|
|
913
|
+
h("div", { style: S.label }, "名称"),
|
|
914
|
+
h("input", { style: S.input, value: providerLabel, onChange: (event) => setProviderLabel(event.target.value), placeholder: "本地 ComfyUI" }),
|
|
915
|
+
h("div", { style: S.label }, "类型"),
|
|
916
|
+
h("select", { style: S.input, value: providerKind, onChange: (event) => setProviderKind(event.target.value) },
|
|
917
|
+
[["comfyui", "ComfyUI"], ["openai-compatible", "OpenAI 兼容"], ["mock", "Mock(离线)"]].map(([id, label]) => h("option", { key: id, value: id }, label)),
|
|
918
|
+
),
|
|
919
|
+
h("div", { style: S.label }, "端点"),
|
|
920
|
+
h("input", { style: S.input, value: providerEndpoint, onChange: (event) => setProviderEndpoint(event.target.value), placeholder: "http://127.0.0.1:8188" }),
|
|
921
|
+
h("div", { style: { ...S.row, marginTop: 6 } },
|
|
922
|
+
h("input", { style: { ...S.input, width: 70 }, type: "number", min: 1, max: 5, value: providerMaxAttempts, onChange: (event) => setProviderMaxAttempts(event.target.value), title: "最大尝试次数" }),
|
|
923
|
+
h("input", { style: { ...S.input, width: 90 }, type: "number", min: 0, value: providerRetryDelay, onChange: (event) => setProviderRetryDelay(event.target.value), title: "重试间隔 ms" }),
|
|
924
|
+
h("input", { style: { ...S.input, width: 90 }, type: "number", min: 0, value: providerMinInterval, onChange: (event) => setProviderMinInterval(event.target.value), title: "最小提交间隔 ms" }),
|
|
925
|
+
),
|
|
926
|
+
h("div", { style: { color: C.muted, fontSize: 10.5, marginTop: 2 } }, "最大尝试 / 重试间隔ms / 最小提交间隔ms(仅 429 自动重试)"),
|
|
927
|
+
providerKind === "comfyui" ? h("div", null,
|
|
928
|
+
h("div", { style: S.label }, "Workflow ID"),
|
|
929
|
+
h("input", { style: S.input, value: providerWorkflow, onChange: (event) => setProviderWorkflow(event.target.value), placeholder: "先用 image_save_workflow 存模板" }),
|
|
930
|
+
h("div", { style: S.label }, "参考图上限"),
|
|
931
|
+
h("input", { style: S.input, type: "number", min: 0, max: 4, value: providerReferenceImages, onChange: (event) => setProviderReferenceImages(event.target.value) }),
|
|
932
|
+
) : null,
|
|
933
|
+
providerKind === "openai-compatible" ? h("div", null,
|
|
934
|
+
h("div", { style: S.label }, "模型"),
|
|
935
|
+
h("input", { style: S.input, value: providerModel, onChange: (event) => setProviderModel(event.target.value), placeholder: "图像模型名" }),
|
|
936
|
+
h("div", { style: S.label }, "凭据引用"),
|
|
937
|
+
h("input", { style: S.input, value: providerCredential, onChange: (event) => setProviderCredential(event.target.value), placeholder: "env:OPENAI_API_KEY" }),
|
|
938
|
+
h("label", { style: { ...S.row, marginTop: 6, fontSize: 12 } },
|
|
939
|
+
h("input", { type: "checkbox", checked: providerEdit, onChange: (event) => setProviderEdit(event.target.checked) }),
|
|
940
|
+
"支持参考图/编辑(/v1/images/edits)",
|
|
941
|
+
),
|
|
942
|
+
) : null,
|
|
943
|
+
h("div", { style: { ...S.row, marginTop: 8 } }, h("button", { style: S.ghost, disabled: busy, onClick: doSaveProvider }, "保存 provider")),
|
|
944
|
+
h("div", { style: { color: C.muted, fontSize: 11, marginTop: 4 } }, "不保存明文 Key;OpenAI 兼容只接受 https 或 localhost。"),
|
|
945
|
+
),
|
|
946
|
+
),
|
|
947
|
+
jobs.length ? jobs.map((job) => h("div", { key: job.jobId, style: S.card },
|
|
948
|
+
h("div", { style: S.row },
|
|
949
|
+
h("span", { style: S.chip(TONE[job.status] ?? C.faint) }, job.status),
|
|
950
|
+
h("span", { style: { flex: 1, fontSize: 11.5, color: C.muted } }, `${job.providerProfileId} · ${new Date(job.createdAt).toLocaleString()} · 尝试 ${job.attempts ?? 1}`),
|
|
951
|
+
h("button", { style: S.ghost, onClick: () => loadJobs(workId) }, "刷新"),
|
|
952
|
+
["failed", "cancelled", "stopped-local"].includes(job.status) ? h("button", { style: S.ghost, disabled: busy, onClick: () => doRetryJob(job) }, "重试") : null,
|
|
953
|
+
["succeeded", "failed", "cancelled", "stopped-local"].includes(job.status) ? null : h("button", { style: S.ghost, disabled: busy, onClick: () => doCancelJob(job) }, "取消"),
|
|
954
|
+
),
|
|
955
|
+
job.errorMessage ? h("div", { style: { color: C.danger, fontSize: 11.5, marginTop: 4 } }, `${job.errorCode ?? "error"}:${job.errorMessage}`) : null,
|
|
956
|
+
job.result?.assetIds?.length ? h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 4 } }, `结果资产:${job.result.assetIds.join("、")}(去「资产」查看)`) : null,
|
|
957
|
+
)) : h("div", { style: { ...S.card, color: C.muted } }, "还没有任务。先编译提示词包,再提交到 mock/ComfyUI/API。"),
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function renderCover() {
|
|
962
|
+
const preview = coverResult || coverImage;
|
|
963
|
+
const safe = coverPlan?.safeArea;
|
|
964
|
+
const overlay = safe
|
|
965
|
+
? {
|
|
966
|
+
top: `${safe.topPct}%`,
|
|
967
|
+
height: `${Math.max(1, safe.bottomPct - safe.topPct)}%`,
|
|
968
|
+
left: `${safe.leftPct}%`,
|
|
969
|
+
width: `${Math.max(1, 100 - safe.leftPct - safe.rightPct)}%`,
|
|
970
|
+
}
|
|
971
|
+
: null;
|
|
972
|
+
return h("div", null,
|
|
973
|
+
h("div", { style: S.card },
|
|
974
|
+
h("div", { style: S.sub }, "封面工坊:选平台/版式,导入底图,本地叠标题与作者名,导出 PNG。只做构图与文字,不生成底图。"),
|
|
975
|
+
h("input", { type: "file", accept: "image/png,image/jpeg,image/webp", onChange: async (event) => {
|
|
976
|
+
const file = event.target.files?.[0];
|
|
977
|
+
try {
|
|
978
|
+
const dataUrl = await readFile(file);
|
|
979
|
+
setCoverImage(dataUrl);
|
|
980
|
+
setCoverResult("");
|
|
981
|
+
} catch (error) {
|
|
982
|
+
setError(String(error?.message ?? error));
|
|
983
|
+
}
|
|
984
|
+
} }),
|
|
985
|
+
h("div", { style: S.label }, "平台"),
|
|
986
|
+
h("select", { style: S.input, value: platformId, onChange: (event) => setPlatformId(event.target.value) },
|
|
987
|
+
platforms.map((platform) => h("option", { key: platform.id, value: platform.id }, `${platform.label}${platform.status === "unverified" ? "(未核实)" : ""}`)),
|
|
988
|
+
),
|
|
989
|
+
h("div", { style: S.label }, "版式"),
|
|
990
|
+
h("select", { style: S.input, value: coverLayout, onChange: (event) => setCoverLayout(event.target.value) },
|
|
991
|
+
[["top", "顶部标题带"], ["bottom", "底部标题带"], ["center", "中部标题带"], ["split", "左右分栏"]].map(([id, label]) => h("option", { key: id, value: id }, label)),
|
|
992
|
+
),
|
|
993
|
+
h("div", { style: S.label }, "书名"),
|
|
994
|
+
h("input", { style: S.input, value: coverTitle, onChange: (event) => setCoverTitle(event.target.value), placeholder: canon?.cover?.title || "书名" }),
|
|
995
|
+
h("div", { style: S.label }, "作者名"),
|
|
996
|
+
h("input", { style: S.input, value: coverAuthor, onChange: (event) => setCoverAuthor(event.target.value), placeholder: "作者名(可空)" }),
|
|
997
|
+
h("div", { style: { ...S.row, marginTop: 8 } },
|
|
998
|
+
h("button", { style: S.ghost, disabled: busy, onClick: doCoverPlan }, "生成构图方案"),
|
|
999
|
+
h("button", { style: S.primary, disabled: busy, onClick: doExportCover }, "导出叠字 PNG"),
|
|
1000
|
+
),
|
|
1001
|
+
h("canvas", { ref: coverCanvas, style: { display: "none" } }),
|
|
1002
|
+
),
|
|
1003
|
+
coverPlan ? h("div", { style: S.card },
|
|
1004
|
+
h("div", { style: S.row }, h("strong", null, "构图方案"), h("span", { style: S.chip(C.muted), marginLeft: "auto" }, `${coverPlan.platform?.width ?? "?"}×${coverPlan.platform?.height ?? "?"}`)),
|
|
1005
|
+
h("div", { style: { color: C.muted, fontSize: 12, marginTop: 4 } }, coverPlan.composition),
|
|
1006
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 4 } }, `标题:${coverPlan.titlePlacement};主体:${coverPlan.subjectPlacement}`),
|
|
1007
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 4 } }, coverPlan.thumbnailCheck),
|
|
1008
|
+
coverPlan.risks?.length ? h("div", { style: { color: C.warn, fontSize: 11.5, marginTop: 6 } }, coverPlan.risks.join(";")) : null,
|
|
1009
|
+
h("details", { style: { marginTop: 6 } }, h("summary", { style: { cursor: "pointer", color: C.muted, fontSize: 12 } }, "检查清单"), h("ul", { style: { margin: "4px 0 0 16px", padding: 0, color: C.muted, fontSize: 11.5, lineHeight: 1.6 } }, coverPlan.checklist.map((item, index) => h("li", { key: index }, item)))),
|
|
1010
|
+
) : null,
|
|
1011
|
+
preview ? h("div", { style: S.card },
|
|
1012
|
+
h("div", { style: { position: "relative", maxWidth: 240, border: `1px solid ${C.line}`, borderRadius: 8, overflow: "hidden" } },
|
|
1013
|
+
h("img", { src: preview, alt: "封面预览", style: { display: "block", width: "100%" } }),
|
|
1014
|
+
overlay ? h("div", { style: { position: "absolute", ...overlay, border: `1px dashed ${C.accent}`, background: "rgba(255,255,255,.08)", boxSizing: "border-box" } }) : null,
|
|
1015
|
+
),
|
|
1016
|
+
h("div", { style: { color: C.muted, fontSize: 11.5, marginTop: 6 } }, "虚线为标题安全区;导出后可再缩到 120px 检查缩略图。"),
|
|
1017
|
+
coverResult ? h("img", { src: coverResult, alt: "缩略图", style: { width: 120, marginTop: 8, borderRadius: 6, border: `1px solid ${C.line}` } }) : null,
|
|
1018
|
+
) : null,
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function OpenButton({ open }) {
|
|
1024
|
+
return h("button", { style: { border: 0, background: "transparent", color: "inherit", cursor: "pointer", fontSize: 12 }, title: "打开视觉设定", onClick: open }, "图像");
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
return {
|
|
1028
|
+
inject: ["slots", "remote"],
|
|
1029
|
+
async apply(ctx) {
|
|
1030
|
+
let remote = null;
|
|
1031
|
+
try {
|
|
1032
|
+
const dispose = await ctx.remote.$mount(REMOTE);
|
|
1033
|
+
remote = ctx.get("remote.imagePanel") ?? null;
|
|
1034
|
+
if (typeof dispose === "function") ctx.effect(() => () => { try { dispose(); } catch { /* gone */ } });
|
|
1035
|
+
if (!remote) console.error("[novel-image] remote.imagePanel 未注册");
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
console.error("[novel-image] remote mount 失败", error);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
const seat = ctx.inject(["sidebarRightTabs", "sidebarRight"], (scoped) => {
|
|
1041
|
+
const tabs = scoped.get("sidebarRightTabs");
|
|
1042
|
+
const right = scoped.get("sidebarRight");
|
|
1043
|
+
if (!tabs || !right) return;
|
|
1044
|
+
scoped.effect(() => tabs.register({
|
|
1045
|
+
id: TAB_ID, kind: TAB_KIND, priority: "extension", keepMounted: true, title: () => "图像",
|
|
1046
|
+
guide: [{ id: TAB_ID, order: 22, title: () => "图像", description: () => "从正文抽取视觉设定,编译提示词,读图回改" }],
|
|
1047
|
+
}), "novel-image: tab type");
|
|
1048
|
+
scoped.effect(() => scoped.slots.inject("sidebar.right.pane.tab", () => scoped.slots.register(
|
|
1049
|
+
{ name: "sidebar.right.pane.tab", key: TAB_ID, inject: (sessionId) => ({ sessionId, remote }) }, Panel)), "novel-image: tab body");
|
|
1050
|
+
scoped.effect(() => scoped.slots.inject("conversation.session.header.utilities", () => scoped.slots.register(
|
|
1051
|
+
{ name: "conversation.session.header.utilities", id: "dsh-novel-image-open", order: 38,
|
|
1052
|
+
inject: () => ({ open: () => { try { right.openTab(TAB_KIND); } catch (error) { console.error("[novel-image] openTab", error); } } }) }, OpenButton)), "novel-image: header button");
|
|
1053
|
+
});
|
|
1054
|
+
ctx.effect(() => () => { try { seat?.(); } catch { /* gone */ } });
|
|
1055
|
+
},
|
|
1056
|
+
};
|
|
1057
|
+
},
|
|
1058
|
+
});
|
|
1059
|
+
|