cortico-world-fun 0.2.1 → 0.3.1

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/dist/webui.js CHANGED
@@ -1,24 +1,517 @@
1
- /**
2
- * 娱乐时间面板的浏览器端(Coo WebUI 扩展面板)。
3
- *
4
- * 约定(照 feed-world 的做法,见宿主 client-panel):
5
- * · 默认导出 `{ panels: { <panelId>: { mount(ctx) } } }`
6
- * · 只往 `ctx.root` 里写 DOM,不碰 document.body
7
- * · 数据一律走 `ctx.invoke(method, args)`,**不读私有状态、不算时间**
8
- * · 定时器只用 `ctx.interval` / `ctx.timeout`(宿主会在面板关掉时 dispose)
9
- *
10
- * 样式:注入一个 <style> 到 ctx.root 里。宿主可能是普通 DOM 也可能是 shadow root,
11
- * 光靠外部 css 在 shadow root 里吃不到;注入 <style> 两边都成立。
12
- * 颜色走宿主主题的自定义属性(--surface/--foreground/--border/--accent…),
13
- * 自定义属性会继承进 shadow root,所以明暗两套主题都不用自己写。
14
- *
15
- * 三个面板:
16
- * places —— 二十处地方(以及自己加的、改过的)此刻的状态,以及她正在逛的这一趟
17
- * book —— 纪念册:去过的每一趟与出游心愿
18
- * shelf —— 纪念品架:长期收藏与探索进度
19
- */
1
+ // webui/stories.js
2
+ var CSS = `
3
+ .fun-stories{--fs-line:var(--border,#e3e4e3);--fs-ink:var(--foreground,#1b1a1e);--fs-dim:var(--muted-foreground,#5c5c60);--fs-card:var(--surface,#fbfbfb);--fs-soft:color-mix(in srgb,var(--fs-card) 93%,var(--fs-ink));--fs-accent:var(--accent,#00a870);--fs-error:var(--destructive,#b23b35);font:14px/1.65 var(--sans,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif);color:var(--fs-ink);padding:8px 4px 24px;overflow-wrap:anywhere}
4
+ .fun-stories *{box-sizing:border-box}
5
+ .fun-stories h2,.fun-stories h3,.fun-stories h4,.fun-stories p{margin:0}
6
+ .fun-stories h2{font-size:20px}.fun-stories h3{font-size:15px}.fun-stories h4{font-size:14px}
7
+ .fun-story-heading{margin-bottom:14px;padding:4px 0 12px;border-bottom:1px solid var(--fs-line)}
8
+ .fun-story-note,.fun-story-field,.fun-story-feedback{color:var(--fs-dim);font-size:12px}
9
+ .fun-story-editor,.fun-story-pack{border:1px solid var(--fs-line);border-radius:12px;background:var(--fs-card);padding:12px;margin-bottom:9px}
10
+ .fun-story-editor{background:var(--fs-soft);margin-bottom:16px}
11
+ .fun-story-editor>summary{cursor:pointer;font-weight:600}
12
+ .fun-story-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(160px,100%),1fr));gap:6px 10px;margin:8px 0}
13
+ .fun-story-grid :is(input,select){display:block;width:100%;min-width:0;margin-top:3px}
14
+ .fun-story-branches{grid-template-columns:repeat(auto-fit,minmax(min(235px,100%),1fr))}
15
+ .fun-story-branch{margin:0;padding:6px 9px;min-width:0;border:1px solid var(--fs-line);border-radius:var(--radius-sm,6px)}
16
+ .fun-story-branch>.fun-story-field{margin:5px 0}
17
+ .fun-story-row{display:flex;align-items:center;gap:6px 8px;flex-wrap:wrap;margin:6px 0}
18
+ .fun-story-row>h3,.fun-story-row>h4{margin-right:auto}
19
+ .fun-story-field{display:block;font-weight:600}
20
+ .fun-story-row label{display:inline-flex;align-items:center;gap:5px}
21
+ .fun-stories button,.fun-stories select,.fun-stories textarea,.fun-story-grid input{font:inherit;color:inherit;background:var(--fs-card);border:1px solid var(--fs-line);border-radius:var(--radius-sm,6px);padding:4px 9px}
22
+ .fun-stories button,.fun-stories select{min-height:31px;max-width:100%}
23
+ .fun-stories button{cursor:pointer}
24
+ .fun-stories button:hover{border-color:var(--fs-accent)}
25
+ .fun-stories button[aria-disabled=true]{opacity:.55;cursor:default}
26
+ .fun-stories :is(button,select,textarea,input):focus-visible{outline:2px solid var(--fs-accent);outline-offset:2px}
27
+ .fun-stories .fun-story-primary{border-color:var(--fs-accent);background:var(--fs-accent);color:var(--accent-foreground,#fff);font-weight:600}
28
+ .fun-stories .fun-story-danger,.fun-story-errors{color:var(--fs-error)}
29
+ .fun-stories textarea{display:block;width:100%;margin:4px 0;resize:vertical;font:12px/1.55 ui-monospace,Consolas,monospace}
30
+ .fun-story-badge{font-size:11.5px;color:var(--fs-dim);border:1px solid var(--fs-line);border-radius:999px;padding:0 7px;background:var(--fs-soft)}
31
+ .fun-story-unavailable{border-style:dashed}
32
+ .fun-stories ul,.fun-stories ol{margin:3px 0;padding-inline-start:19px}
33
+ .fun-story-feedback>:empty,.fun-story-result:empty,.fun-story-confirm:empty{display:none}
34
+ .fun-story-confirm,.fun-story-result{margin-top:8px}
35
+ .fun-story-node{padding:5px 0;border-bottom:1px solid var(--fs-line)}
36
+ .fun-story-node:last-child{border-bottom:0}
37
+ .fun-story-node p{white-space:pre-wrap}
38
+ @media(max-width:420px){.fun-stories{padding-inline:0}.fun-story-editor,.fun-story-pack{padding:10px}}
39
+ `;
40
+ function el(tag, attrs = {}, ...children) {
41
+ const node = document.createElement(tag);
42
+ for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, value);
43
+ for (const child of children.flat()) {
44
+ if (child == null) continue;
45
+ node.appendChild(typeof child === "string" ? document.createTextNode(child) : child);
46
+ }
47
+ return node;
48
+ }
49
+ function messageList(messages) {
50
+ return messages?.length ? el("ul", {}, messages.map((message) => el("li", {}, String(message)))) : null;
51
+ }
52
+ function feedback() {
53
+ const status = el("div", { role: "status" });
54
+ const alert = el("div", { class: "fun-story-errors", role: "alert" });
55
+ return {
56
+ node: el("div", { class: "fun-story-feedback" }, status, alert),
57
+ set(text = "", result) {
58
+ const warnings = messageList(result?.warnings);
59
+ status.replaceChildren(...[text ? document.createTextNode(text) : null, warnings].filter(Boolean));
60
+ const errors = [...new Set([result?.error, ...result?.errors ?? []].filter(Boolean))];
61
+ if (result?.ok === false && !errors.length) errors.push("操作失败,请重试。");
62
+ alert.replaceChildren(...errors.length ? [messageList(errors)] : []);
63
+ }
64
+ };
65
+ }
66
+ function previewGraph(result) {
67
+ const nodes = (result.nodes ?? []).map((node) => {
68
+ const when = node.when && Object.keys(node.when).length ? `条件:${typeof node.when === "string" ? node.when : JSON.stringify(node.when)}` : "";
69
+ const choices = (node.choices ?? []).map((choice) => el("li", {}, `${choice.label || choice.id} → ${choice.next || "结束"}`));
70
+ return el(
71
+ "li",
72
+ { class: "fun-story-node" },
73
+ el("strong", {}, `${node.id}${node.area ? ` · ${node.area}` : ""}`),
74
+ node.event ? el("p", {}, node.event) : null,
75
+ when ? el("p", { class: "fun-story-note" }, when) : null,
76
+ node.next ? el("p", { class: "fun-story-note" }, `下一节点 → ${node.next}`) : null,
77
+ choices.length ? el("ul", {}, choices) : null,
78
+ !node.next && !choices.length ? el("p", { class: "fun-story-note" }, "结束") : null
79
+ );
80
+ });
81
+ return el(
82
+ "section",
83
+ { class: "fun-story-graph", "aria-label": "只读节点图" },
84
+ el("h4", {}, result.title || "节点图"),
85
+ el("p", { class: "fun-story-note" }, result.eligible ? "当前预览条件匹配" : "当前预览条件未匹配"),
86
+ el("ol", {}, nodes)
87
+ );
88
+ }
89
+ function label(text, control) {
90
+ return el("label", { class: "fun-story-field" }, text, control);
91
+ }
92
+ function fillSelect(select, items, placeholder) {
93
+ const selected = select.value;
94
+ select.replaceChildren(
95
+ el("option", { value: "" }, placeholder),
96
+ ...items.map(({ value, label: label2 }) => el("option", { value }, label2))
97
+ );
98
+ select.value = items.some((item) => item.value === selected) ? selected : "";
99
+ }
100
+ function simpleEditor(button, save) {
101
+ const select = (key) => el("select", { class: `fun-story-author-${key}`, "data-story-field": key });
102
+ const input = (key, max, type = "text") => el("input", { class: `fun-story-author-${key}`, type, "data-story-field": key, ...max ? { maxlength: String(max) } : {} });
103
+ const place = select("place");
104
+ const area = select("area");
105
+ const id = input("id", 24);
106
+ id.value = `user-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`;
107
+ const title = input("title", 80);
108
+ const event = input("event", 120);
109
+ const prompt = input("prompt", 160);
110
+ const from = input("from", null, "time");
111
+ const to = input("to", null, "time");
112
+ const branches = ["a", "b"].map((key, index) => {
113
+ const choice = input(`${key}-label`, 160);
114
+ const result = input(`${key}-result`, 160);
115
+ const event2 = input(`${key}-event`, 120);
116
+ const area2 = select(`${key}-area`);
117
+ const node2 = el(
118
+ "fieldset",
119
+ { class: "fun-story-branch" },
120
+ el("legend", { class: "fun-story-field" }, `选项 ${index + 1}`),
121
+ label("选项文字", choice),
122
+ label("选择结果", result),
123
+ label("后续事件", event2),
124
+ label("后续区域", area2)
125
+ );
126
+ return { key, choice, result, event: event2, area: area2, node: node2 };
127
+ });
128
+ let places = [];
129
+ const report = feedback();
130
+ const updateAreas = () => {
131
+ const areas = (places.find((item) => item.id === place.value)?.areas ?? []).map((name) => ({ value: name, label: name }));
132
+ fillSelect(area, areas, "选择起始区域");
133
+ for (const branch of branches) fillSelect(branch.area, areas, "同起始区域");
134
+ };
135
+ place.addEventListener("change", () => {
136
+ area.value = "";
137
+ for (const branch of branches) branch.area.value = "";
138
+ updateAreas();
139
+ });
140
+ const saveButton = button("保存新故事包", () => {
141
+ const fields = [place, area, id, title, event, prompt, ...branches.flatMap((branch) => [branch.choice, branch.result, branch.event])];
142
+ const missing = fields.find((field) => !field.value.trim());
143
+ if (missing) {
144
+ report.set("", { ok: false, error: "请填写地点、起始区域和故事内容。" });
145
+ missing.focus();
146
+ return;
147
+ }
148
+ if (!/^user-[a-z0-9_-]{1,19}$/.test(id.value.trim())) {
149
+ report.set("", { ok: false, error: "标识须以 user- 开头,最多 24 字符,只能含小写字母、数字、短横线或下划线。" });
150
+ id.focus();
151
+ return;
152
+ }
153
+ if (Boolean(from.value) !== Boolean(to.value) || from.value && from.value === to.value) {
154
+ report.set("", { ok: false, error: "请填写不同的开始和结束时间,或将两项都留空。" });
155
+ (from.value && !to.value ? to : from).focus();
156
+ return;
157
+ }
158
+ const start = {
159
+ id: "start",
160
+ area: area.value,
161
+ event: event.value.trim(),
162
+ prompt: prompt.value.trim(),
163
+ choices: branches.map((branch) => ({ id: branch.key, label: branch.choice.value.trim(), result: branch.result.value.trim(), next: `end-${branch.key}` }))
164
+ };
165
+ if (from.value) start.when = { from: from.value, to: to.value };
166
+ const nodes = [start, ...branches.map((branch) => ({ id: `end-${branch.key}`, area: branch.area.value || area.value, event: branch.event.value.trim() }))];
167
+ save(report, JSON.stringify({ version: 1, id: id.value.trim(), title: title.value.trim(), placeId: place.value, start: start.id, nodes }));
168
+ }, { class: "fun-story-action fun-story-primary" });
169
+ const node = el(
170
+ "section",
171
+ { class: "fun-story-editor", "aria-label": "编写故事" },
172
+ el("h3", {}, "编写故事"),
173
+ el("div", { class: "fun-story-grid" }, label("地点", place), label("起始区域", area), label("故事标题", title), label("故事标识", id)),
174
+ el("div", { class: "fun-story-grid" }, label("起始事件", event), label("选择提问", prompt)),
175
+ el("div", { class: "fun-story-grid fun-story-branches" }, branches.map((branch) => branch.node)),
176
+ el(
177
+ "details",
178
+ {},
179
+ el("summary", {}, "触发时段(可选)"),
180
+ el("div", { class: "fun-story-grid" }, label("开始时间", from), label("结束时间", to))
181
+ ),
182
+ el("div", { class: "fun-story-row" }, saveButton),
183
+ report.node
184
+ );
185
+ function update(items) {
186
+ places = items;
187
+ fillSelect(place, items.map((item) => ({ value: item.id, label: item.name || item.id })), "选择地点");
188
+ updateAreas();
189
+ }
190
+ update([]);
191
+ return { node, update };
192
+ }
193
+ function mountStories(ctx) {
194
+ const { root } = ctx;
195
+ const box = el("div", { class: "fun-stories" });
196
+ root.replaceChildren(el("style", {}, CSS), box);
197
+ let busy = false;
198
+ let listRequest = 0;
199
+ let lastPacks;
200
+ let draftEdits = 0;
201
+ function button(text, handler, attrs = {}) {
202
+ const node = el("button", { type: "button", ...attrs }, text);
203
+ node.addEventListener("click", () => {
204
+ if (node.getAttribute("aria-disabled") !== "true" && !ctx.signal?.aborted) handler();
205
+ });
206
+ return node;
207
+ }
208
+ const errorResult = (error) => ({ ok: false, error: error?.message ?? String(error) });
209
+ function setBusy(value) {
210
+ busy = value;
211
+ for (const node of box.querySelectorAll(".fun-story-action")) node.setAttribute("aria-disabled", String(value));
212
+ }
213
+ async function run(report, pending, method, args, render) {
214
+ if (busy) return;
215
+ setBusy(true);
216
+ report.set(pending);
217
+ try {
218
+ const result = await ctx.invoke(method, [args]);
219
+ if (!ctx.signal?.aborted) await render(result ?? { ok: false, error: "返回结果为空。" });
220
+ } catch (error) {
221
+ if (!ctx.signal?.aborted) report.set("", errorResult(error));
222
+ } finally {
223
+ if (!ctx.signal?.aborted) setBusy(false);
224
+ }
225
+ }
226
+ const place = el("select", { class: "fun-story-place" });
227
+ const defaultPlace = () => el("option", { value: "" }, "默认地点");
228
+ place.appendChild(defaultPlace());
229
+ const draft = el("textarea", { class: "fun-story-json", rows: "8", spellcheck: "false", placeholder: "粘贴故事包 JSON…" });
230
+ const overwrite = el("input", { type: "checkbox", class: "fun-story-overwrite" });
231
+ const editorReport = feedback();
232
+ const editorResult = el("div", { class: "fun-story-result" });
233
+ draft.addEventListener("input", () => {
234
+ draftEdits += 1;
235
+ if (!busy) editorReport.set();
236
+ editorResult.replaceChildren();
237
+ });
238
+ function editAction(text, method, pending) {
239
+ return button(text, () => {
240
+ const json = draft.value;
241
+ const edits = draftEdits;
242
+ const placeId = place.value;
243
+ const args = method === "template" ? placeId ? { placeId } : {} : { json };
244
+ if (method === "import" && overwrite.checked) args.replace = true;
245
+ editorResult.replaceChildren();
246
+ void run(editorReport, pending, method, args, async (result) => {
247
+ const changed = draftEdits !== edits || draft.value !== json;
248
+ const previous = changed ? "上次提交:" : "";
249
+ if (method === "template") {
250
+ if (result.ok && !changed) {
251
+ if (typeof result.json !== "string") throw new Error("模板没有返回 JSON。");
252
+ draft.value = result.json;
253
+ overwrite.checked = false;
254
+ }
255
+ editorReport.set(result.ok ? changed ? "草稿已修改,保留当前内容。" : "模板已填入。" : "", result);
256
+ } else if (method === "validate") {
257
+ editorReport.set(previous + (result.ok ? "校验通过。" : "校验未通过。"), result);
258
+ } else if (method === "preview") {
259
+ editorReport.set(previous + (result.ok ? "只读预览已生成。" : "预览失败。"), result);
260
+ if (result.ok) editorResult.appendChild(previewGraph(result));
261
+ } else {
262
+ editorReport.set(previous + (result.ok ? `已导入${result.id ? ` · ${result.id}` : ""}。` : "导入失败。"), result);
263
+ if (result.ok) {
264
+ overwrite.checked = false;
265
+ await load();
266
+ }
267
+ }
268
+ });
269
+ }, { class: `fun-story-action${method === "import" ? " fun-story-primary" : ""}` });
270
+ }
271
+ const loadReport = feedback();
272
+ const libraryReport = feedback();
273
+ const packList = el("div", { class: "fun-story-list" });
274
+ const refreshButton = button("刷新列表", () => {
275
+ void load();
276
+ });
277
+ const simple = simpleEditor(button, (report, json) => {
278
+ void run(report, "正在保存新故事包…", "import", { json }, async (result) => {
279
+ report.set(result.ok ? `已保存新故事包${result.id ? ` · ${result.id}` : ""}。` : "保存失败。", result);
280
+ if (result.ok) await load();
281
+ });
282
+ });
283
+ box.replaceChildren(
284
+ el(
285
+ "header",
286
+ { class: "fun-story-heading" },
287
+ el("h2", {}, "故事包"),
288
+ el("p", { class: "fun-story-note" }, "为地点编写事件节点与分支。草稿仅在导入时保存。")
289
+ ),
290
+ simple.node,
291
+ el(
292
+ "details",
293
+ { class: "fun-story-advanced" },
294
+ el("summary", {}, "高级编辑 · 查看或粘贴完整 JSON"),
295
+ el(
296
+ "section",
297
+ { class: "fun-story-editor", "aria-label": "高级 JSON 编辑器" },
298
+ el("h3", {}, "完整 JSON"),
299
+ el(
300
+ "div",
301
+ { class: "fun-story-row" },
302
+ el("label", { class: "fun-story-field" }, "模板地点", place),
303
+ editAction("填入模板", "template", "正在取模板…")
304
+ ),
305
+ el("label", { class: "fun-story-field" }, "故事包 JSON", draft),
306
+ el(
307
+ "div",
308
+ { class: "fun-story-row" },
309
+ editAction("校验 JSON", "validate", "正在校验…"),
310
+ editAction("预览草稿", "preview", "正在预览…"),
311
+ editAction("导入故事包", "import", "正在导入…"),
312
+ el("label", { class: "fun-story-field" }, overwrite, "覆盖同 ID 故事包")
313
+ ),
314
+ editorReport.node,
315
+ editorResult
316
+ )
317
+ ),
318
+ el(
319
+ "section",
320
+ { "aria-label": "故事包列表" },
321
+ el("div", { class: "fun-story-row" }, el("h3", {}, "已收录故事包"), refreshButton),
322
+ loadReport.node,
323
+ libraryReport.node,
324
+ packList
325
+ )
326
+ );
327
+ function packCard(pack) {
328
+ const title = pack.title || pack.id;
329
+ const report = feedback();
330
+ const resultBox = el("div", { class: "fun-story-result" });
331
+ const confirm = el("div", { class: "fun-story-confirm" });
332
+ const packAction = (text, key, handler, css = "") => button(text, handler, {
333
+ class: `fun-story-action ${css}`,
334
+ "aria-disabled": String(busy),
335
+ "aria-label": `${text} ${title}`,
336
+ "data-story-focus": `${pack.id}:${key}`
337
+ });
338
+ const read = (method, label2) => {
339
+ const opener = packAction(label2, method, () => {
340
+ confirm.replaceChildren();
341
+ resultBox.replaceChildren();
342
+ void run(report, method === "preview" ? "正在预览…" : "正在导出…", method, { id: pack.id }, (result) => {
343
+ report.set(result.ok ? method === "preview" ? "只读预览已生成。" : "已导出,可复制 JSON。" : "", result);
344
+ if (!result.ok) return;
345
+ if (method === "preview") {
346
+ resultBox.appendChild(previewGraph(result));
347
+ } else {
348
+ if (typeof result.json !== "string") throw new Error("导出没有返回 JSON。");
349
+ const output = el("textarea", { class: "fun-story-export", rows: "6", readonly: "", spellcheck: "false" });
350
+ output.value = result.json;
351
+ resultBox.appendChild(el("label", { class: "fun-story-field" }, `导出的 JSON · ${title}`, output));
352
+ }
353
+ resultBox.appendChild(button("收起", () => {
354
+ resultBox.replaceChildren();
355
+ report.set();
356
+ opener.focus();
357
+ }));
358
+ });
359
+ });
360
+ return opener;
361
+ };
362
+ const mutate = (method, label2) => {
363
+ void run(report, `正在${label2}…`, method, { id: pack.id }, async (result) => {
364
+ libraryReport.set();
365
+ report.set("", result);
366
+ if (!result.ok) return;
367
+ libraryReport.set(`已${label2}「${title}」。`, result);
368
+ await load();
369
+ confirm.replaceChildren();
370
+ });
371
+ };
372
+ const toggle = pack.enabled ? ["disable", "停用"] : ["enable", "启用"];
373
+ const remove = pack.builtin ? null : packAction("移除", "remove", () => {
374
+ const cancel = button("取消", () => {
375
+ confirm.replaceChildren();
376
+ remove.focus();
377
+ });
378
+ confirm.replaceChildren(
379
+ el("span", {}, `移除「${title}」?`),
380
+ el("div", { class: "fun-story-row" }, cancel, packAction("确认移除", "confirm", () => mutate("remove", "移除"), "fun-story-danger"))
381
+ );
382
+ cancel.focus();
383
+ }, "fun-story-danger");
384
+ const warnings = pack.warnings?.length ? pack.warnings : pack.available === false ? ["绑定地点或区域当前不匹配。"] : [];
385
+ return el(
386
+ "article",
387
+ { class: "fun-story-pack", "data-pack-id": pack.id },
388
+ el(
389
+ "div",
390
+ { class: "fun-story-row" },
391
+ el("h4", {}, title),
392
+ el("span", { class: "fun-story-badge" }, pack.builtin ? "内置" : "自定义"),
393
+ el("span", { class: "fun-story-badge" }, pack.enabled ? "已启用" : "已停用"),
394
+ pack.available === false ? el("span", { class: "fun-story-badge fun-story-unavailable" }, "暂不可用") : null
395
+ ),
396
+ el("p", { class: "fun-story-note" }, `${pack.placeName || pack.placeId || "未绑定地点"} · ${pack.nodeCount} 个节点 · 版本 ${pack.revision}`),
397
+ pack.description ? el("p", {}, pack.description) : null,
398
+ warnings.length ? el("div", { class: "fun-story-note" }, messageList(warnings)) : null,
399
+ el(
400
+ "div",
401
+ { class: "fun-story-row" },
402
+ read("preview", "预览"),
403
+ read("export", "导出 JSON"),
404
+ packAction(toggle[1], "toggle", () => mutate(...toggle)),
405
+ remove
406
+ ),
407
+ confirm,
408
+ report.node,
409
+ resultBox
410
+ );
411
+ }
412
+ function renderList(data) {
413
+ const selected = place.value;
414
+ place.replaceChildren(defaultPlace(), ...data.places.map((item) => el("option", { value: item.id }, item.name || item.id)));
415
+ place.value = data.places.some((item) => item.id === selected) ? selected : "";
416
+ simple.update(data.places);
417
+ const signature = JSON.stringify(data.packs);
418
+ if (signature === lastPacks) return;
419
+ const focused = root.activeElement ?? document.activeElement;
420
+ const buttonWasFocused = [...packList.querySelectorAll("button")].includes(focused);
421
+ const focusKey = focused?.getAttribute?.("data-story-focus");
422
+ const cards = data.packs.map(packCard);
423
+ packList.replaceChildren(...cards.length ? cards : [el("p", { class: "fun-story-note" }, "还没有故事包。")]);
424
+ lastPacks = signature;
425
+ if (buttonWasFocused) {
426
+ const replacement = [...packList.querySelectorAll("button")].find((node) => focusKey && node.getAttribute("data-story-focus") === focusKey);
427
+ (replacement || refreshButton).focus();
428
+ }
429
+ }
430
+ async function load() {
431
+ if (ctx.signal?.aborted) return;
432
+ const sequence = ++listRequest;
433
+ refreshButton.setAttribute("aria-disabled", "true");
434
+ loadReport.set("正在读取故事包…");
435
+ try {
436
+ const data = await ctx.invoke("list", []);
437
+ if (sequence !== listRequest || ctx.signal?.aborted) return;
438
+ if (!data?.ok) {
439
+ loadReport.set("列表加载失败。", data ?? { ok: false });
440
+ return;
441
+ }
442
+ renderList(data);
443
+ loadReport.set("", data);
444
+ } catch (error) {
445
+ if (sequence === listRequest && !ctx.signal?.aborted) loadReport.set("列表加载失败。", errorResult(error));
446
+ } finally {
447
+ if (sequence === listRequest && !ctx.signal?.aborted) {
448
+ refreshButton.setAttribute("aria-disabled", "false");
449
+ refreshButton.textContent = loadReport.node.querySelector(".fun-story-errors").textContent ? "重试" : "刷新列表";
450
+ }
451
+ }
452
+ }
453
+ void load();
454
+ return { refresh: load };
455
+ }
456
+
457
+ // webui/artwork.js
458
+ var line = (d, extra = "") => `<path d="${d}" ${extra}/>`;
459
+ var rect = (x, y, w, h, r = 3, extra = "") => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${r}" ${extra}/>`;
460
+ var circle = (x, y, r, extra = "") => `<circle cx="${x}" cy="${y}" r="${r}" ${extra}/>`;
461
+ var warm = 'fill="var(--f-art-warm,#e9b97e)"';
462
+ var mint = 'fill="var(--f-art-mint,#99c7b9)"';
463
+ var blue = 'fill="var(--f-art-blue,#9abfd0)"';
464
+ var pink = 'fill="var(--f-art-pink,#d9abc1)"';
465
+ var paper = 'fill="var(--f-card,#fbfbfb)"';
466
+ var scenes = {
467
+ amusement: circle(139, 48, 34, blue) + line("M139 14V82M105 48H173M115 24L163 72M115 72L163 24M139 48L113 108H165Z") + [[139, 14], [173, 48], [139, 82], [105, 48]].map(([x, y]) => rect(x - 6, y - 4, 12, 10, 3, warm)).join("") + line("M202 104V64H267V104M196 64L235 38L274 64Z", warm) + rect(220, 77, 25, 27, 5, pink) + line("M39 91V45M39 45L69 53L39 63Z", mint),
468
+ aquarium: line("M68 108V57C68 8 249 8 249 57V108", blue) + line("M88 108V58C88 31 229 31 229 58V108", paper) + line("M132 56C154 39 180 41 192 52L210 45V67L192 60C170 73 144 68 132 56Z", mint) + circle(181, 52, 1.5, 'fill="currentColor"') + line("M105 108L108 87L117 100L121 78L128 108M208 108L215 82L219 99L228 89L231 108") + circle(111, 57, 3) + circle(118, 43, 2),
469
+ templefair: line("M67 108V38M91 108V38M225 108V38M249 108V38M52 31Q157 47 264 31L260 44H56ZM58 56H258", warm) + line("M102 80H215M109 80V107M207 80V107M99 79L158 54L218 79Z", mint) + [111, 157, 203].map((x) => circle(x, 60, 9, pink) + line(`M${x} 47V51M${x} 69V74`)).join(""),
470
+ con: rect(77, 35, 164, 72, 5, paper) + rect(91, 48, 63, 47, 3, pink) + line("M107 83L116 65L124 76L137 57L146 83Z") + rect(169, 49, 56, 13, 2, warm) + line("M169 73H225M169 83H209M91 107V114M227 107V114") + line("M47 57L53 43L59 57L73 63L59 69L53 83L47 69L33 63Z", blue),
471
+ cinema: rect(75, 23, 174, 79, 5, blue) + rect(89, 35, 146, 53, 2, paper) + line("M149 46L149 76L175 61Z", warm) + [98, 131, 164, 197, 230].map((x) => rect(x - 9, 96, 21, 16, 4, pink)).join("") + line("M42 96L38 68H62L58 96Z", warm) + line("M40 68Q39 54 48 59Q58 48 62 62"),
472
+ zoo: rect(73, 36, 177, 71, 10, mint) + line("M82 42L100 22H224L243 42", warm) + line("M117 107V72Q117 46 142 46Q167 46 167 72V107", paper) + circle(137, 62, 3) + circle(153, 62, 3) + line("M140 78Q146 84 152 78M201 107V67M195 67Q177 42 193 43Q200 24 207 43Q226 38 219 57Z", blue) + circle(53, 61, 18, mint) + line("M53 79V107"),
473
+ park: line("M119 114Q125 89 154 78Q176 67 178 49", warm) + circle(76, 54, 27, mint) + circle(236, 49, 33, mint) + line("M76 65V109M236 62V109") + rect(104, 75, 63, 10, 3, paper) + line("M110 86V102M160 86V102M105 67H166M113 67V76M157 67V76") + circle(157, 25, 13, warm),
474
+ arcade: rect(105, 25, 85, 82, 7, pink) + rect(116, 35, 63, 39, 3, blue) + line("M129 58L139 45L150 60L159 49L169 65") + line("M105 81L94 94H199L190 81Z", warm) + circle(126, 88, 3) + circle(168, 88, 3) + line("M122 85V78") + rect(128, 98, 37, 4, 1, paper) + line("M224 45L235 34M233 62H251M215 32V19"),
475
+ ktv: rect(62, 29, 126, 69, 6, blue) + line("M78 47H161M78 62H134M78 77H151") + line("M220 53L190 95Q187 103 195 106Q201 108 205 103L234 64", warm) + circle(231, 48, 17, pink) + line("M220 35L242 60M214 43L235 65M206 106Q236 121 255 99M272 31V61Q258 55 257 65Q260 77 273 69V40L290 35V55"),
476
+ museum: line("M64 47L159 15L253 47Z", warm) + rect(65, 47, 188, 10, 1, paper) + [86, 125, 164, 203].map((x) => rect(x, 57, 16, 43, 2, blue)).join("") + rect(61, 101, 195, 10, 1, paper) + circle(159, 36, 8, mint) + line("M41 110H278"),
477
+ catcafe: rect(66, 30, 123, 71, 5, warm) + line("M76 43H178M128 43V101M76 77H178") + line("M201 97C177 89 185 72 199 73L198 58L211 67L225 59L228 78C242 102 217 110 201 97Z", pink) + circle(207, 81, 1.5, 'fill="currentColor"') + circle(220, 81, 1.5, 'fill="currentColor"') + line("M206 91Q215 96 221 88M237 98Q263 100 253 83") + rect(89, 87, 18, 15, 3, paper) + line("M107 90Q119 90 112 98"),
478
+ hiking: line("M45 108L128 21L197 108Z", mint) + line("M127 21L104 47L128 43L145 47Z", paper) + line("M143 108L219 42L278 108Z", blue) + line("M150 108L145 94L164 79L164 70M219 42L205 56H232", paper) + circle(241, 24, 12, warm) + line("M83 109V85M75 93L83 79L91 93ZM248 109V86M239 96L248 78L257 96Z"),
479
+ cafe: rect(77, 30, 159, 77, 4, warm) + line("M69 48H243L232 25H81Z", pink) + rect(89, 61, 61, 46, 3, blue) + rect(167, 61, 55, 34, 3, paper) + line("M177 73H204V85H177ZM204 75Q216 74 211 82M183 64Q178 59 184 55M195 64Q190 59 196 55M119 62V106M89 82H150"),
480
+ milktea: rect(77, 29, 164, 78, 5, pink) + rect(88, 38, 141, 15, 2, paper) + line("M107 64L113 105H145L151 64Z", warm) + line("M102 64H156M127 64L135 40", paper) + [119, 129, 139].map((x) => circle(x, 94, 2.5, 'fill="currentColor"')).join("") + rect(174, 67, 40, 40, 3, blue) + line("M179 80H209M179 89H201"),
481
+ diner: rect(67, 29, 183, 78, 6, warm) + rect(80, 40, 69, 48, 3, blue) + line("M114 41V87M80 64H149") + line("M171 80H225M177 81V105M220 81V105") + line("M184 69H216Q217 56 201 56Q184 56 184 69ZM201 56V51", paper) + line("M183 36V47M196 32V43M209 36V47") + rect(88, 95, 51, 11, 3, pink),
482
+ library: rect(71, 29, 177, 78, 4, warm) + line("M87 35V99M155 35V99M231 35V99M87 65H231M87 99H231") + [95, 110, 126, 164, 179, 211].map((x, i) => rect(x, i % 2 ? 45 : 41, 10, i % 2 ? 19 : 23, 1, i % 2 ? mint : blue)).join("") + line("M106 83Q133 75 159 85Q183 75 208 83V111Q183 102 159 111Q134 102 106 111ZM159 85V111", paper),
483
+ market: line("M51 31Q156 58 269 30") + [75, 116, 158, 200, 242].map((x) => circle(x, x === 158 ? 52 : 45, 7, warm)).join("") + line("M60 104V77H130V104M49 77L67 59H123L141 77Z", pink) + line("M180 104V77H250V104M169 77L187 59H243L261 77Z", blue) + line("M73 90H118M192 89H237M81 104V92M225 104V90") + rect(142, 93, 22, 14, 2, mint),
484
+ bathhouse: rect(69, 33, 181, 74, 5, warm) + line("M60 34L89 18H229L258 34Z", blue) + rect(89, 53, 142, 54, 2, paper) + line("M89 54H231V76Q211 66 195 76Q177 67 160 77Q141 67 124 76Q105 66 89 76ZM160 54V107", mint) + line("M112 44Q102 34 112 25M156 45Q145 34 156 25M200 44Q189 34 200 25"),
485
+ thrift: rect(67, 29, 179, 78, 4, mint) + line("M60 48H253L241 26H73Z", warm) + rect(84, 64, 56, 43, 3, paper) + circle(112, 81, 12, blue) + line("M112 72V81L119 84") + line("M163 80L180 65L197 80M180 65V59Q180 53 187 55M163 80H197", pink) + rect(205, 86, 26, 21, 2, pink) + line("M210 86V79H226V86M90 103L102 96H129"),
486
+ riverside: line("M36 90Q93 80 151 90T284 90M36 103Q93 93 151 103T284 103M52 115Q99 107 145 115M187 115Q224 107 269 115", blue) + line("M62 82V57M88 82V57M114 82V57M140 82V57M57 63H147M57 75H147") + line("M165 60Q202 8 262 60M173 60V78M253 60V78M170 60H259", warm) + circle(103, 26, 13, pink) + line("M218 105L230 96H253L247 105Z", mint)
487
+ };
488
+ function venueArtwork(id) {
489
+ const drawing = scenes[id] ?? line("M83 107V51L160 20L237 51V107Z", mint) + rect(108, 64, 32, 43, 3, paper) + rect(169, 62, 42, 27, 3, blue);
490
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 128" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M28 112H292" opacity=".2"/><g>${drawing}</g></svg>`;
491
+ }
492
+ var symbols = {
493
+ ticket: line("M4 6H20V10Q16 12 20 14V18H4V14Q8 12 4 10ZM14 7V9M14 11V13M14 15V17"),
494
+ keychain: circle(9, 7, 4) + line("M9 11V15M7 15H15L18 21H5Z"),
495
+ bookmark: line("M7 3H17V21L12 17L7 21ZM10 7H14M10 10H14"),
496
+ postcard: rect(3, 5, 18, 14, 2) + line("M14 8V16M17 9H19M6 14L9 10L12 14ZM6 16H12"),
497
+ sticker: line("M4 4H20V15L15 20H4ZM15 20V15H20") + circle(9, 9, 1) + circle(15, 9, 1) + line("M8 12Q12 16 16 12"),
498
+ coin: circle(12, 12, 9) + circle(12, 12, 6) + line("M12 7L14 10L17 12L14 14L12 17L10 14L7 12L10 10Z"),
499
+ cup: line("M5 8H16V17Q10 22 5 17ZM16 10H20V15H16M8 3V5M12 3V5"),
500
+ light: line("M8 15Q1 7 8 4Q16 0 19 8Q20 12 16 15V19H8ZM9 22H15M9 16H15"),
501
+ plush: circle(6, 6, 3) + circle(18, 6, 3) + circle(12, 10, 7) + line("M7 16Q4 23 12 22Q20 23 17 16") + circle(9, 9, 1) + circle(15, 9, 1) + line("M11 12H13"),
502
+ charm: line("M12 3V6M7 6H17L20 12L17 21H7L4 12ZM9 10H15M9 14H15M10 18H14"),
503
+ generic: rect(4, 8, 16, 13, 2) + rect(3, 5, 18, 4, 1) + line("M12 5V21M12 5Q4 4 7 1Q10 0 12 5Q14 0 17 1Q20 4 12 5")
504
+ };
505
+ function souvenirCategory(name) {
506
+ const value = String(name ?? "");
507
+ return /票|券|入场/.test(value) ? "ticket" : /钥匙|挂件|挂饰|吊坠/.test(value) ? "keychain" : /书签/.test(value) ? "bookmark" : /明信片|卡片|画片|海报/.test(value) ? "postcard" : /贴纸|贴画|徽章/.test(value) ? "sticker" : /币|章/.test(value) ? "coin" : /杯|茶|咖啡/.test(value) ? "cup" : /灯/.test(value) ? "light" : /玩偶|公仔|小熊|毛绒/.test(value) ? "plush" : /御守|护符|签/.test(value) ? "charm" : "generic";
508
+ }
509
+ function souvenirArtwork(name) {
510
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${symbols[souvenirCategory(name)]}</svg>`;
511
+ }
20
512
 
21
- const CSS = `
513
+ // webui/webui.js
514
+ var CSS2 = `
22
515
  .fun{--f-line:var(--border,#e3e4e3);--f-ink:var(--foreground,#1b1a1e);--f-dim:var(--muted-foreground,#5c5c60);--f-card:var(--surface,#fbfbfb);--f-soft:color-mix(in srgb,var(--surface,#fbfbfb) 92%,var(--foreground,#1b1a1e));--f-accent:var(--accent,#00a870);--f-warm:#e0862f;--f-mint:#00a870;font:13px/1.6 var(--sans,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif);color:var(--f-ink);padding:4px 2px 24px}
23
516
  .fun *{box-sizing:border-box}
24
517
  .fun-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px}
@@ -35,6 +528,15 @@ const CSS = `
35
528
  .fun-sec:first-child{margin-top:2px}
36
529
 
37
530
  /* 正在逛的那一趟 */
531
+ .fun-draft{border:1px solid var(--f-line);border-left:3px solid var(--f-warm);border-radius:var(--radius-sm,6px);padding:12px 14px;margin-bottom:12px;background:var(--f-card)}
532
+ .fun-draft h3{margin:0 0 4px;font-size:15px;font-weight:600}
533
+ .fun-draft-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
534
+ .fun-choice{border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:9px 11px;margin-top:9px;background:var(--f-soft)}
535
+ .fun-choice-title{font-size:12px;font-weight:600}
536
+ .fun-choice .fun-list{margin-top:4px}
537
+ .fun-choice-note{font-size:11.5px;color:var(--f-dim);margin:7px 0 0;line-height:1.5}
538
+ .fun-upcoming-wish{margin:-6px 0 12px;padding:8px 11px;border-radius:var(--radius-sm,6px);background:var(--f-soft);color:var(--f-dim);font-size:12px}
539
+
38
540
  .fun-live{border:1px solid var(--f-line);border-left:3px solid var(--f-accent);border-radius:var(--radius-sm,6px);padding:9px 12px;margin-bottom:12px;background:var(--f-card)}
39
541
  .fun-live-idle{border-left-color:var(--f-line)}
40
542
  .fun-live h3{margin:0 0 3px;font-size:14px;font-weight:600}
@@ -157,409 +659,660 @@ const CSS = `
157
659
  .fun-feedback:empty{display:none}.fun-feedback{margin:10px 0}.fun-feedback .fun-err{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
158
660
  .fun-loading{padding:18px;color:var(--f-dim);font-size:13px}.fun-empty{border:1px dashed var(--f-line);border-radius:var(--f-round);margin:10px 0;background:var(--f-soft)}
159
661
  @media(max-width:420px){.fun{padding-inline:0}.fun-live,.fun-trip,.fun-form{padding:12px}.fun-stats{gap:12px}.fun-detail-cols,.fun-form-grid{grid-template-columns:1fr}.fun-detail-top{flex-wrap:wrap}.fun-trip-actions{flex-wrap:wrap}}
160
- @media(prefers-reduced-motion:reduce){.fun *{transition:none!important;scroll-behavior:auto!important}}
662
+ .fun-art{display:block;color:color-mix(in srgb,var(--f-ink) 64%,var(--f-card));background:color-mix(in srgb,var(--f-accent) 5%,var(--f-card));border-radius:8px;margin-bottom:10px;overflow:hidden;pointer-events:none}.fun-art svg{display:block;width:100%;height:116px}.fun-art-detail svg{height:160px}.fun-icon{display:inline-flex;vertical-align:middle;flex:none;width:22px;height:22px;color:var(--f-dim);margin-right:5px}.fun-icon svg{width:100%;height:100%}.fun-keepsake>summary .fun-icon{width:32px;height:32px;margin-bottom:5px}.fun-recommendations{margin:18px 0 20px}.fun-recommendations h3{font-size:16px;margin:0 0 3px}.fun-recommend-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(218px,100%),1fr));gap:12px;margin-top:10px}.fun-recommend-card{padding:13px;border:1px solid var(--f-line);border-radius:var(--f-round);background:var(--f-card);cursor:pointer;transition:border-color .15s,background .15s}.fun-recommend-card:hover{border-color:var(--f-accent)}.fun-recommend-card:focus-visible{outline:2px solid var(--f-accent);outline-offset:3px}.fun-recommend-name{font-weight:650;font-size:15px}.fun-recommend-reason{margin-top:7px;color:var(--f-dim);font-size:12px}.fun-management{margin:16px 0;color:var(--f-dim);font-size:12px}.fun-management>summary{cursor:pointer;padding:6px 0}.fun-management .fun-bar{margin-top:8px}.fun-detail-actions{flex-wrap:wrap}.fun-detail-edit{border-color:var(--f-line);color:var(--f-dim)}.fun-album-filters{display:grid;grid-template-columns:minmax(160px,2fr) minmax(130px,1fr) minmax(130px,1fr);gap:8px;margin:14px 0}.fun-route{padding:10px 13px;border:1px dashed var(--f-line);border-radius:10px;margin:10px 0;font-size:12px}.fun-route-stops{display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin-top:5px}.fun-link{background:transparent!important;color:var(--f-accent)!important;font-size:12px!important;min-height:30px!important}.fun-inspector{margin-top:10px;padding:12px;border:1px solid var(--f-line);border-radius:10px;background:var(--f-soft)}.fun-inspector h4{margin:0 0 4px}.fun-inline-status{font-size:12px;color:var(--f-dim);padding:8px 0}.fun-timeline{list-style:none;padding:0;margin:8px 0}.fun-timeline-block{border-left:2px solid var(--f-line);padding:0 0 12px 13px;margin-left:4px}.fun-timeline-block:last-child{padding-bottom:2px}.fun-timeline-area{font-size:13px;font-weight:600;margin-bottom:5px}.fun-timeline-row{display:grid;grid-template-columns:minmax(78px,auto) 1fr;gap:10px;font-size:12.5px;margin:5px 0;overflow-wrap:anywhere}.fun-timeline-time{color:var(--f-dim);font-size:11px;font-variant-numeric:tabular-nums}.fun-timeline-choice{border-left:2px solid color-mix(in srgb,var(--f-accent) 40%,var(--f-line));margin:5px 0 5px 10px;padding-left:8px}.fun-timeline-event{margin:6px 0}.fun-timeline-source{font-size:11px;color:var(--f-dim)}.fun-recommend-card,.fun-inspector,.fun-feedback,.fun-outing-result{animation:fun-appear .16s ease-out}@keyframes fun-appear{from{opacity:.4;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}.fun-trip-detail,.fun-detail,.fun-inspector{overflow-wrap:anywhere}.fun{--f-art-warm:color-mix(in srgb,#e9b97e 63%,var(--f-card));--f-art-mint:color-mix(in srgb,#79b7a6 62%,var(--f-card));--f-art-blue:color-mix(in srgb,#7cacc2 62%,var(--f-card));--f-art-pink:color-mix(in srgb,#ce91af 56%,var(--f-card))}@media(max-width:560px){.fun-album-filters{grid-template-columns:1fr}.fun-timeline-row{grid-template-columns:78px 1fr}.fun-art-detail svg{height:128px}}@media(prefers-reduced-motion:reduce){.fun *{transition:none!important;animation:none!important;scroll-behavior:auto!important}}
161
663
 
162
664
  `;
163
-
164
- /** 小工具:建元素 + 设属性,省掉一屏 createElement。 */
165
- function el(tag, props, ...kids) {
665
+ function el2(tag, props, ...kids) {
166
666
  const n = document.createElement(tag);
167
667
  if (props) {
168
668
  for (const [k, v] of Object.entries(props)) {
169
- if (v === null || v === undefined || v === false) continue;
170
- if (k === 'class') n.className = v;
171
- else if (k === 'text') n.textContent = v;
172
- else if (k === 'html') n.innerHTML = v;
173
- else if (k.startsWith('on') && typeof v === 'function') n.addEventListener(k.slice(2), v);
174
- else if (k === 'style') Object.assign(n.style, v);
669
+ if (v === null || v === void 0 || v === false) continue;
670
+ if (k === "class") n.className = v;
671
+ else if (k === "text") n.textContent = v;
672
+ else if (k === "html") n.innerHTML = v;
673
+ else if (k.startsWith("on") && typeof v === "function") n.addEventListener(k.slice(2), v);
674
+ else if (k === "style") Object.assign(n.style, v);
175
675
  else n.setAttribute(k, v);
176
676
  }
177
677
  }
178
678
  for (const kid of kids.flat()) {
179
- if (kid === null || kid === undefined || kid === false) continue;
180
- n.appendChild(typeof kid === 'string' || typeof kid === 'number'
181
- ? document.createTextNode(String(kid)) : kid);
679
+ if (kid === null || kid === void 0 || kid === false) continue;
680
+ n.appendChild(typeof kid === "string" || typeof kid === "number" ? document.createTextNode(String(kid)) : kid);
182
681
  }
183
682
  return n;
184
683
  }
185
-
186
- /** 只注入一次样式(同一 root 反复 mount 时别叠 <style>)。 */
187
684
  function ensureStyle(root) {
188
- if (root.querySelector('style.fun-style')) return;
189
- root.appendChild(el('style', { class: 'fun-style', text: CSS }));
685
+ if (root.querySelector("style.fun-style")) return;
686
+ root.appendChild(el2("style", { class: "fun-style", text: CSS2 }));
190
687
  }
191
-
192
- /** 顶层容器。 */
193
688
  function shell(root) {
194
689
  ensureStyle(root);
195
- const box = el('div', { class: 'fun' });
690
+ const box = el2("div", { class: "fun" });
196
691
  root.appendChild(box);
197
692
  return box;
198
693
  }
199
-
200
694
  function errorCard(err, retry, retained = false) {
201
- return el('div', { class: 'fun-err', role: 'alert' },
202
- el('span', { text: retained ? `刷新失败,保留上次内容:${err?.message ?? String(err)}` : `面板加载失败:${err?.message ?? String(err)}` }),
203
- retry ? el('button', { type: 'button', onclick: () => { void retry(); } }, '重试') : null);
695
+ return el2(
696
+ "div",
697
+ { class: "fun-err", role: "alert" },
698
+ el2("span", { text: retained ? `刷新失败,保留上次内容:${err?.message ?? String(err)}` : `面板加载失败:${err?.message ?? String(err)}` }),
699
+ retry ? el2("button", { type: "button", onclick: () => {
700
+ void retry();
701
+ } }, "重试") : null
702
+ );
204
703
  }
205
-
206
704
  function heading(title, subtitle) {
207
- return el('header', { class: 'fun-heading' }, el('h2', { text: title }), el('p', { text: subtitle }));
705
+ return el2("header", { class: "fun-heading" }, el2("h2", { text: title }), el2("p", { text: subtitle }));
208
706
  }
209
-
210
- function feedback(box) {
211
- const node = el('div', { class: 'fun-feedback' });
707
+ function feedback2(box) {
708
+ const node = el2("div", { class: "fun-feedback" });
212
709
  box.appendChild(node);
213
710
  return node;
214
711
  }
215
-
216
- // ---------------------------------------------------------------------------
217
- // places —— 去哪儿
218
- // ---------------------------------------------------------------------------
219
-
712
+ function sceneArt(place, detail = false) {
713
+ return el2("div", {
714
+ class: `fun-art${detail ? " fun-art-detail" : ""}`,
715
+ "aria-hidden": "true",
716
+ "data-artwork": place.userVenue ? "custom" : place.id,
717
+ html: venueArtwork(place.userVenue ? "" : place.id)
718
+ });
719
+ }
720
+ function itemIcon(name) {
721
+ return el2("span", { class: "fun-icon", "aria-hidden": "true", "data-category": souvenirCategory(name), html: souvenirArtwork(name) });
722
+ }
723
+ function rememberFocus(container) {
724
+ const active = document.activeElement;
725
+ let parent = active;
726
+ while (parent && parent !== container) parent = parent.parentNode;
727
+ const key = parent ? active?.getAttribute?.("data-focus-key") : null;
728
+ const start = active?.selectionStart;
729
+ const end = active?.selectionEnd;
730
+ return () => {
731
+ if (!key) return;
732
+ const target = [...container.querySelectorAll("input"), ...container.querySelectorAll("select")].find((node) => node.getAttribute("data-focus-key") === key);
733
+ target?.focus?.();
734
+ if (typeof start === "number" && typeof target?.setSelectionRange === "function" && target.type !== "date") {
735
+ try {
736
+ target.setSelectionRange(start, end);
737
+ } catch {
738
+ }
739
+ }
740
+ };
741
+ }
742
+ var routeStatus = { planned: "待出发", active: "行程中", between: "站间歇脚", completed: "已完成", cancelled: "已取消" };
743
+ function routeSummary(route, trips = [], selectTrip) {
744
+ const node = el2(
745
+ "section",
746
+ { class: "fun-route", "data-route-id": route.id, "aria-label": "联程记录" },
747
+ el2("strong", { text: `联程 · ${routeStatus[route.status] ?? "状态未知"}` }),
748
+ el2("div", { class: "fun-route-stops", text: (route.stops ?? []).map((stop) => stop.placeName || stop.placeId).join(" → ") })
749
+ );
750
+ const retained = (route.tripIds ?? []).map((id) => trips.find((trip) => trip.id === id)).filter(Boolean);
751
+ if (selectTrip && retained.length) node.appendChild(el2("div", { class: "fun-route-stops" }, retained.map((trip) => el2("button", {
752
+ type: "button",
753
+ class: "fun-link",
754
+ "data-trip-id": trip.id,
755
+ onclick: () => selectTrip(trip)
756
+ }, `${trip.routeOrder ? `第 ${trip.routeOrder} 站 · ` : ""}${trip.placeName} · ${trip.day || "日期不详"}`))));
757
+ if (selectTrip && (route.tripIds ?? []).length > retained.length) node.appendChild(el2("div", { class: "fun-note", text: "较早行程仅保留联程归属,详细记录已归档。" }));
758
+ return node;
759
+ }
760
+ function tripDetails(trip) {
761
+ const detail = el2("section", { class: "fun-trip-detail", "aria-label": `${trip.placeName}行程详情` });
762
+ if (trip.company) detail.appendChild(el2("p", { text: `同行 · ${trip.company}` }));
763
+ if (trip.timelineTruncated) detail.appendChild(el2("p", { class: "fun-note", text: "这趟记录较长,时间线保留进门与最近的活动;较早的逐项细节已省略。" }));
764
+ if (trip.routeId) detail.appendChild(el2("p", { class: "fun-note", text: `联程${trip.routeOrder ? ` · 第 ${trip.routeOrder} 站` : ""}`, "data-route-id": trip.routeId }));
765
+ const supplied = Array.isArray(trip.timeline) && trip.timeline.length > 0;
766
+ const timeline = supplied ? trip.timeline : [
767
+ ...(trip.visited ?? []).map((area) => ({ kind: "area", text: typeof area === "string" ? area : area.area, area: typeof area === "string" ? area : area.area, at: null })),
768
+ ...(trip.events ?? []).map((text) => ({ kind: "event", text, event: text, at: null })),
769
+ ...(trip.choices ?? []).map((choice) => ({ kind: "choice", text: choice.result, event: choice.event, at: null })),
770
+ ...(trip.souvenirs ?? []).map((text) => ({ kind: "buy", text, at: null })),
771
+ ...(trip.photos ?? []).map((text) => ({ kind: "photo", text, at: null })),
772
+ ...(trip.ate ?? []).map((item) => ({ kind: "consume", text: `${item.verb}了 ${item.item}`, at: null }))
773
+ ];
774
+ if (timeline.length) {
775
+ detail.appendChild(el2("div", { class: "fun-sec", text: "沿途时间线" }));
776
+ if (!supplied) detail.appendChild(el2("p", { class: "fun-note", text: "这趟旧记录没有保存逐项时间,以下均标为时间不详。" }));
777
+ const list = el2("ol", { class: "fun-timeline" });
778
+ const blocks = [];
779
+ let current = null;
780
+ const block = (area) => {
781
+ const node = el2("li", { class: "fun-timeline-block", "data-area": area || "" }, el2("div", { class: "fun-timeline-area", text: area || "途中记录(区域未记)" }));
782
+ const value = { area, node, events: [] };
783
+ blocks.push(value);
784
+ list.appendChild(node);
785
+ return value;
786
+ };
787
+ const labels = { enter: "进门", area: "逛到", event: "小事", choice: "选择", buy: "带回", photo: "拍照", consume: "吃喝", close: "收摊" };
788
+ for (const entry of timeline) {
789
+ const known = typeof entry.at === "number" && Number.isFinite(entry.at);
790
+ const clock = known ? [entry.day, entry.hm].filter(Boolean).join(" ") || "时间未标注" : "时间不详";
791
+ const row = el2(
792
+ "div",
793
+ { class: "fun-timeline-row", "data-kind": entry.kind, "data-at": known ? String(entry.at) : "unknown" },
794
+ el2("span", { class: "fun-timeline-time", text: clock }),
795
+ el2("span", null, entry.kind === "buy" ? itemIcon(entry.text) : null, `${labels[entry.kind] ?? "记录"} · ${entry.text || (entry.kind === "area" ? entry.area : "") || "未记内容"}`)
796
+ );
797
+ if (entry.kind === "enter" || entry.kind === "close") {
798
+ current = block(entry.kind === "enter" ? "出发与进门" : "收摊");
799
+ current.node.appendChild(row);
800
+ current = null;
801
+ continue;
802
+ }
803
+ const source = entry.kind === "choice" ? [...blocks].reverse().flatMap((group) => [...group.events].reverse()).find((event) => entry.event && event.name === entry.event && (!entry.area || event.area === entry.area)) : null;
804
+ if (source && current === source.group && current.lastNode === source.node) {
805
+ source.node.appendChild(el2("div", { class: "fun-timeline-choice", "data-event": entry.event }, row));
806
+ continue;
807
+ }
808
+ const area = entry.area || "";
809
+ if (!current || area !== current.area) current = block(area);
810
+ if (entry.kind === "event") {
811
+ const event = el2("div", { class: "fun-timeline-event", "data-event": entry.event || entry.text }, row);
812
+ current.events.push({ name: entry.event || entry.text, area: current.area, group: current, node: event });
813
+ current.node.appendChild(event);
814
+ current.lastNode = event;
815
+ } else {
816
+ if (entry.kind === "choice" && entry.event) {
817
+ row.appendChild(el2("span", { class: "fun-timeline-source", text: `对应小事:${entry.event}` }));
818
+ const choice = el2("div", { class: "fun-timeline-choice", "data-event": entry.event }, row);
819
+ current.node.appendChild(choice);
820
+ current.lastNode = choice;
821
+ } else {
822
+ current.node.appendChild(row);
823
+ current.lastNode = row;
824
+ }
825
+ }
826
+ }
827
+ detail.appendChild(list);
828
+ }
829
+ if (trip.note) detail.appendChild(el2("p", { text: `收摊备注 · ${trip.note}` }));
830
+ if (trip.scene) detail.appendChild(el2("p", { class: "fun-dim", text: `生图 scene:${trip.scene}${trip.outfit ? ` · outfits:${trip.outfit}` : ""}` }));
831
+ return detail;
832
+ }
833
+ function tripLookup(ctx, method, parameter, label2) {
834
+ const states = /* @__PURE__ */ new Map();
835
+ const views = /* @__PURE__ */ new Map();
836
+ const redraw = (id) => {
837
+ for (const view of views.get(id) ?? []) {
838
+ if (view.host.isConnected === false) views.get(id).delete(view);
839
+ else view.paint();
840
+ }
841
+ };
842
+ return (id) => {
843
+ const state = states.get(id) ?? { opened: false, pending: false, trips: null, error: "" };
844
+ states.set(id, state);
845
+ const host = el2("section", { class: "fun-history", "data-lookup-id": id });
846
+ const paint = () => {
847
+ let focused = document.activeElement;
848
+ while (focused && focused !== host) focused = focused.parentNode;
849
+ host.replaceChildren(el2(
850
+ "button",
851
+ {
852
+ type: "button",
853
+ class: "fun-link fun-history-toggle",
854
+ "aria-expanded": String(state.opened),
855
+ disabled: state.pending ? "disabled" : null,
856
+ onclick: () => {
857
+ if (state.pending) return;
858
+ state.opened = !state.opened;
859
+ if (state.opened && state.trips === null) void load();
860
+ else redraw(id);
861
+ }
862
+ },
863
+ state.pending ? "读取中…" : state.opened ? "收起回看" : label2
864
+ ));
865
+ const restore = () => {
866
+ if (!focused) return;
867
+ if (state.pending) {
868
+ host.setAttribute("tabindex", "-1");
869
+ host.focus?.();
870
+ } else host.querySelector(".fun-history-toggle")?.focus?.();
871
+ };
872
+ if (!state.opened) {
873
+ restore();
874
+ return;
875
+ }
876
+ const content = el2("div", { class: "fun-history-content", "aria-live": "polite" });
877
+ host.appendChild(content);
878
+ if (state.pending) content.appendChild(el2("div", { class: "fun-inline-status", role: "status", text: "正在找这段回忆…" }));
879
+ if (state.error) content.appendChild(el2("div", { class: "fun-err", role: "alert" }, el2("span", { text: state.error }), el2("button", { type: "button", onclick: () => {
880
+ void load();
881
+ } }, "重试")));
882
+ if (state.trips?.length === 0) content.appendChild(el2("div", { class: "fun-note", text: "没有可回看的详细行程;较早记录可能已经归档。" }));
883
+ for (const trip of state.trips ?? []) content.appendChild(el2(
884
+ "details",
885
+ { class: "fun-inspector", open: state.trips.length === 1 ? "open" : null, "data-trip-id": trip.id },
886
+ el2("summary", { text: `${trip.placeName} · ${trip.day || "日期不详"} · ${trip.summary || "行程记录"}` }),
887
+ tripDetails(trip)
888
+ ));
889
+ restore();
890
+ };
891
+ const load = async () => {
892
+ if (state.pending) return;
893
+ state.pending = true;
894
+ state.error = "";
895
+ redraw(id);
896
+ try {
897
+ const result = await ctx.invoke(method, [{ [parameter]: id }]);
898
+ if (!result?.ok) throw new Error(result?.error ?? "详细行程暂时读不到");
899
+ if (!Array.isArray(result.trips)) throw new Error("详细行程格式不正确");
900
+ state.trips = result.trips;
901
+ } catch (error) {
902
+ state.error = error?.message ?? String(error);
903
+ } finally {
904
+ state.pending = false;
905
+ if (!ctx.signal?.aborted) redraw(id);
906
+ }
907
+ };
908
+ if (!views.has(id)) views.set(id, /* @__PURE__ */ new Set());
909
+ views.get(id).add({ host, paint });
910
+ paint();
911
+ return host;
912
+ };
913
+ }
220
914
  function mountPlaces(ctx) {
221
915
  const root = ctx.root;
222
916
  root.replaceChildren();
223
917
  const box = shell(root);
224
- const body = el('div');
918
+ const body = el2("div");
225
919
  box.appendChild(body);
226
-
227
- let keyword = '';
228
- let quickFilter = '全部';
920
+ let keyword = "";
921
+ let quickFilter = "全部";
229
922
  let expanded = null;
230
- /** null = 没在编辑;{ mode: 'new' | 'edit', venue } = 打开表单。 */
923
+ let expandedOrigin = "list";
924
+ const historyView = tripLookup(ctx, "history", "placeId", "回看这里的行程");
231
925
  let editing = null;
232
- let formError = '';
233
- /** 表单打开期间收到的最新数据,等关掉表单再补画,免得把用户填的内容冲掉。 */
926
+ let formError = "";
927
+ let outingAction = "";
928
+ let notice = null;
929
+ let loadSequence = 0;
234
930
  let currentData = null;
235
- const status = feedback(box);
236
- body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在看看有哪些地方开着…' }));
237
-
931
+ const status = feedback2(box);
932
+ body.appendChild(el2("div", { class: "fun-loading", role: "status", text: "正在看看有哪些地方开着…" }));
238
933
  const render = (data) => {
239
- // 表单相关声明要放在最前:点「添加地点」时 render 会重跑,
240
- // 而那一轮里 `venueForm()` 在 `if (editing)` 处就会用到 `fields`。
241
- // 放在后面会撞上 TDZ(`Cannot access 'fields' before initialization`)。
934
+ const restoreFocus = rememberFocus(body);
242
935
  const renderAll = () => render(data);
243
936
  const fields = {};
244
- const lines = (v) => (Array.isArray(v) ? v.join('\n') : '');
245
- const parseLines = (s) => String(s ?? '').split(/[\n,,、]/).map((x) => x.trim()).filter(Boolean);
937
+ const lines = (v) => Array.isArray(v) ? v.join("\n") : "";
938
+ const parseLines = (s) => String(s ?? "").split(/[\n,,、]/).map((x) => x.trim()).filter(Boolean);
246
939
  currentData = data;
247
- body.replaceChildren(heading('去哪儿', '挑一处喜欢的地方,慢慢逛。'));
248
-
249
- // ---- 正在逛的那一趟 ----
940
+ body.replaceChildren(heading("去哪儿", "挑一处喜欢的地方,慢慢逛。"));
941
+ const pendingChoice = (choice) => choice ? el2(
942
+ "div",
943
+ { class: "fun-choice" },
944
+ el2("div", { class: "fun-choice-title", text: choice.prompt || "待选择事件" }),
945
+ el2("ul", { class: "fun-list" }, choice.options.map((option) => el2("li", { text: option.label }))),
946
+ el2("p", { class: "fun-choice-note", text: "她可以选一项,也可以略过。" })
947
+ ) : null;
948
+ const draft = data.draft;
949
+ if (draft) {
950
+ const draftAction = (method, label2) => el2("button", {
951
+ type: "button",
952
+ disabled: outingAction || method === "resume" && draft.canResume === false ? "disabled" : null,
953
+ onclick: () => resolveDraft(method, draft.id)
954
+ }, outingAction === method ? "处理中…" : label2);
955
+ body.appendChild(el2(
956
+ "section",
957
+ { class: "fun-draft" },
958
+ el2("h3", { text: `未逛完 · ${draft.placeName}` }),
959
+ el2("div", { class: "fun-meta", text: `最后活动 ${draft.lastDay ? `${draft.lastDay} ` : ""}${draft.lastHm} · 逛了 ${draft.visited.length} 处` }),
960
+ el2("div", { class: "fun-meta", text: draft.visited.length ? `逛过:${draft.visited.map((v) => v.area).join("、")}` : "还没逛到哪儿" }),
961
+ pendingChoice(draft.pendingChoice),
962
+ draft.canResume === false ? el2("div", { class: "fun-meta", text: "这处已不在地点清单中,可以按已有记录收摊。" }) : null,
963
+ el2("div", { class: "fun-draft-actions" }, draftAction("resume", "继续逛"), draftAction("closeDraft", "按已有记录收摊"))
964
+ ));
965
+ }
250
966
  if (data.session) {
251
967
  const s = data.session;
252
968
  const venue = data.places.find((p) => p.id === s.placeId);
253
- const leftAreas = venue
254
- ? venue.areas.filter((a) => !s.visited.some((v) => v.area === a))
255
- : [];
256
- const leftText = leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '都逛过了';
969
+ const leftAreas = venue ? venue.areas.filter((a) => !s.visited.some((v) => v.area === a)) : [];
970
+ const leftText = venue?.state === "closed" ? "这处已经打烊" : leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join("、")}` : "这会儿开放的都逛过了";
257
971
  const progress = s.venueAreaCount ? `${s.visited.length}/${s.venueAreaCount}` : String(s.visited.length);
258
- body.appendChild(el('div', { class: 'fun-live' },
259
- el('h3', { text: `正在${s.placeName}逛` }),
260
- el('div', { class: 'fun-meta' },
972
+ body.appendChild(el2(
973
+ "div",
974
+ { class: "fun-live" },
975
+ el2("h3", { text: `正在${s.placeName}逛` }),
976
+ el2(
977
+ "div",
978
+ { class: "fun-meta" },
261
979
  `${s.enteredHm} 进门 · 待了 ${s.stayedMin} 分钟 · 逛了 ${progress} 处`,
262
- s.stale ? el('span', { class: 'fun-stale', text: ' · 这一趟挂得有点久了' }) : null),
263
- el('div', { class: 'fun-meta', text: `逛过:${s.visited.length ? s.visited.map((v) => v.area).join('、') : '还没逛到哪儿'}` }),
264
- s.souvenirs.length ? el('div', { class: 'fun-chips' }, s.souvenirs.map((x) => el('span', { class: 'fun-chip fun-chip-on', text: `买了 ${x}` }))) : null,
265
- s.photos.length ? el('div', { class: 'fun-chips' }, s.photos.map((x) => el('span', { class: 'fun-chip', text: `📷 ${x}` }))) : null,
266
- (s.ate && s.ate.length)
267
- ? el('div', { class: 'fun-chips' }, s.ate.map((x) => el('span', { class: 'fun-chip fun-chip-ate', text: `${x.verb}了 ${x.item}` })))
268
- : null,
269
- s.events.length ? el('ul', { class: 'fun-list' }, s.events.slice(-3).map((e) => el('li', { text: e }))) : null,
270
- venue ? el('div', { class: 'fun-meta', text: leftText }) : null,
980
+ s.stale ? el2("span", { class: "fun-stale", text: " · 这一趟挂得有点久了" }) : null
981
+ ),
982
+ el2("div", { class: "fun-meta", text: `逛过:${s.visited.length ? s.visited.map((v) => v.area).join("、") : "还没逛到哪儿"}` }),
983
+ s.souvenirs.length ? el2("div", { class: "fun-chips" }, s.souvenirs.map((x) => el2("span", { class: "fun-chip fun-chip-on", text: `买了 ${x}` }))) : null,
984
+ s.photos.length ? el2("div", { class: "fun-chips" }, s.photos.map((x) => el2("span", { class: "fun-chip", text: `📷 ${x}` }))) : null,
985
+ s.ate && s.ate.length ? el2("div", { class: "fun-chips" }, s.ate.map((x) => el2("span", { class: "fun-chip fun-chip-ate", text: `${x.verb}了 ${x.item}` }))) : null,
986
+ s.events.length ? el2("ul", { class: "fun-list" }, s.events.slice(-3).map((e) => el2("li", { text: e }))) : null,
987
+ venue ? el2("div", { class: "fun-meta", text: leftText }) : null,
988
+ pendingChoice(s.pendingChoice)
271
989
  ));
272
- } else {
273
- body.appendChild(el('div', { class: 'fun-live fun-live-idle' },
274
- el('h3', { text: '这会儿没在逛' }),
275
- el('div', { class: 'fun-meta', text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
276
- el('div', { class: 'fun-meta fun-dim', text: '她会自己挑一处进去;你在下面点一张卡也能看细节。' }),
990
+ } else if (!draft) {
991
+ body.appendChild(el2(
992
+ "div",
993
+ { class: "fun-live fun-live-idle" },
994
+ el2("h3", { text: "这会儿没在逛" }),
995
+ el2("div", { class: "fun-meta", text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
996
+ el2("div", { class: "fun-meta fun-dim", text: "她会自己挑一处进去;你在下面点一张卡也能看细节。" })
277
997
  ));
278
998
  }
279
-
280
- // ---- 搜索条 + 自填地点 ----
281
- const input = el('input', {
282
- class: 'fun-search',
283
- type: 'search',
284
- placeholder: '搜地方名、别名或标签(庙会 / 室内 / 夜…)',
285
- value: keyword,
999
+ if (notice) body.appendChild(el2("div", {
1000
+ class: "fun-meta fun-outing-result",
1001
+ role: notice.error ? "alert" : "status",
1002
+ tabindex: "-1",
1003
+ text: notice.text
1004
+ }));
1005
+ if (data.upcomingWish) body.appendChild(el2("div", { class: "fun-upcoming-wish", text: data.upcomingWish }));
1006
+ if (data.route) body.appendChild(routeSummary(data.route));
1007
+ const recommendBox = el2("section", { class: "fun-recommendations", "aria-label": "此刻推荐" });
1008
+ body.appendChild(recommendBox);
1009
+ body.appendChild(el2("div", { class: "fun-sec", text: "全部地方 · 找一处看看" }));
1010
+ const management = el2("details", { class: "fun-management", open: editing ? "open" : null }, el2("summary", { text: "地点管理与说明" }));
1011
+ const input = el2("input", {
1012
+ class: "fun-search",
1013
+ type: "search",
1014
+ placeholder: "搜地方名、别名或标签(庙会 / 室内 / 夜…)",
1015
+ "aria-label": "搜索全部地方",
1016
+ "data-focus-key": "places-search",
1017
+ value: keyword
286
1018
  });
287
- input.addEventListener('input', () => {
1019
+ input.addEventListener("input", () => {
288
1020
  keyword = input.value;
289
- // 只重画列表,不重画搜索框——否则每敲一个字就丢焦点(feast 踩过这条)。
290
1021
  renderList();
291
1022
  });
292
- const addBtn = el('button', {
293
- type: 'button',
1023
+ const addBtn = el2("button", {
1024
+ type: "button",
294
1025
  onclick: () => {
295
- editing = { mode: 'new', venue: null };
296
- formError = '';
1026
+ editing = { mode: "new", venue: null };
1027
+ formError = "";
297
1028
  renderAll();
298
- },
299
- }, '+ 添加地点');
300
- body.appendChild(el('div', { class: 'fun-bar' }, input, addBtn));
301
-
302
- // B 阶段:预设也能编辑(改的是覆盖层,预设本身不动);删只对自己的地方。
303
- body.appendChild(el('div', { class: 'fun-hint' },
304
- `预设的 ${data.total - data.userVenueCount} 处插件自带,现在也能改——改过的会标「已改」,`
305
- + `随时能恢复;你自己加了 ${data.userVenueCount} 处,随时能改能删。`
306
- + (data.overriddenCount
307
- ? ` 已改过 ${data.overriddenCount} 处预设。`
308
- : '')
309
- + (data.feast
310
- ? ' 吃喝的味道会去「鱼的每一天」拿(可在配置里关掉)。'
311
- : ' 吃喝只记名字、不描述味道(可在配置里打开「去鱼的每一天拿」)。')));
312
-
313
- // 一键恢复全部预设:只在真有覆盖层时给,免得平时多一个没用的按钮。
1029
+ }
1030
+ }, "+ 添加地点");
1031
+ body.appendChild(el2("div", { class: "fun-bar" }, input));
1032
+ management.appendChild(el2("div", { class: "fun-bar" }, addBtn));
1033
+ management.appendChild(el2(
1034
+ "div",
1035
+ { class: "fun-hint" },
1036
+ `预设的 ${data.total - data.userVenueCount} 处插件自带,现在也能改——改过的会标「已改」,随时能恢复;你自己加了 ${data.userVenueCount} 处,随时能改能删。` + (data.overriddenCount ? ` 已改过 ${data.overriddenCount} 处预设。` : "") + (data.feast ? " 吃喝的味道会去「鱼的每一天」拿(可在配置里关掉)。" : " 吃喝只记名字、不描述味道(可在配置里打开「去鱼的每一天拿」)。")
1037
+ ));
314
1038
  if (data.overriddenCount) {
315
- body.appendChild(el('button', {
316
- type: 'button',
317
- style: { marginBottom: '10px' },
1039
+ const resetError = el2("div", { class: "fun-form-error", role: "alert" });
1040
+ const resetButton = el2("button", {
1041
+ type: "button",
1042
+ style: { marginBottom: "10px" },
318
1043
  onclick: async () => {
1044
+ if (resetButton.disabled) return;
1045
+ resetButton.disabled = true;
1046
+ resetError.textContent = "";
1047
+ resetButton.textContent = "恢复中…";
319
1048
  try {
320
- const r = await ctx.invoke('resetAll', []);
321
- if (!r?.ok) { formError = r?.error ?? '恢复不了'; return; }
322
- formError = '';
1049
+ const r = await ctx.invoke("resetAll", []);
1050
+ if (!r?.ok) throw new Error(r?.error ?? "恢复不了");
1051
+ formError = "";
323
1052
  await load();
324
1053
  } catch (err) {
325
- formError = err?.message ?? String(err);
1054
+ resetError.textContent = err?.message ?? String(err);
1055
+ } finally {
1056
+ resetButton.disabled = false;
1057
+ resetButton.textContent = `恢复全部预设(${data.overriddenCount} 处)`;
326
1058
  }
327
- },
328
- }, `恢复全部预设(${data.overriddenCount} 处)`));
1059
+ }
1060
+ }, `恢复全部预设(${data.overriddenCount} 处)`);
1061
+ management.appendChild(resetButton);
1062
+ management.appendChild(resetError);
329
1063
  }
330
-
331
- // ---- 编辑表单(打开时在最上面) ----
332
1064
  if (editing) body.appendChild(venueForm());
333
-
334
- const filterBar = el('div', { class: 'fun-filters', role: 'group', 'aria-label': '地点快捷筛选' });
1065
+ const filterBar = el2("div", { class: "fun-filters", role: "group", "aria-label": "地点快捷筛选" });
335
1066
  const filterButtons = [];
336
- for (const label of ['全部', '现在开着', '室内', '户外', '夜游', '我的地点']) {
337
- const button = el('button', { type: 'button', 'aria-pressed': String(quickFilter === label), onclick: () => {
338
- quickFilter = label;
339
- for (const item of filterButtons) item.button.setAttribute('aria-pressed', String(item.label === label));
1067
+ for (const label2 of ["全部", "现在开着", "室内", "户外", "夜游", "我的地点"]) {
1068
+ const button = el2("button", { type: "button", "aria-pressed": String(quickFilter === label2), onclick: () => {
1069
+ quickFilter = label2;
1070
+ for (const item of filterButtons) item.button.setAttribute("aria-pressed", String(item.label === label2));
340
1071
  renderList();
341
- } }, label);
342
- filterButtons.push({ label, button });
1072
+ } }, label2);
1073
+ filterButtons.push({ label: label2, button });
343
1074
  filterBar.appendChild(button);
344
1075
  }
345
1076
  body.appendChild(filterBar);
346
- const listBox = el('div');
1077
+ const listBox = el2("div");
347
1078
  body.appendChild(listBox);
348
-
349
- /**
350
- * 重画列表。
351
- *
352
- * 展开的详情**就地插在它那张卡下面**,占满一整行(grid-column: 1/-1),
353
- * 而不是像 0.1.1 那样统统追加到列表末尾——那样点第一张卡要滑过十二张才看得见。
354
- */
1079
+ body.appendChild(management);
355
1080
  function renderList() {
356
1081
  listBox.replaceChildren();
357
1082
  const kw = keyword.trim().toLowerCase();
1083
+ recommendBox.replaceChildren();
1084
+ const recommendations = [...new Set(data.recommendationIds ?? [])].map((id) => data.places.find((p) => p.id === id && p.state !== "closed")).filter(Boolean).slice(0, 3);
1085
+ if (!kw && quickFilter === "全部" && recommendations.length) {
1086
+ recommendBox.appendChild(el2("h3", { text: "此刻可以看看" }));
1087
+ recommendBox.appendChild(el2("p", { class: "fun-note", text: "几处开着的地方,点开只看细节;出发与选择仍由她自己决定。" }));
1088
+ recommendBox.appendChild(el2("div", { class: "fun-recommend-grid" }, recommendations.map((p) => {
1089
+ const selected = expanded === p.id && expandedOrigin === "recommend";
1090
+ const cell2 = el2("div", { class: selected ? "fun-cell fun-cell-open" : "fun-cell" }, card(p, true));
1091
+ if (selected) cell2.appendChild(detail(p));
1092
+ return cell2;
1093
+ })));
1094
+ }
358
1095
  const filtered = data.places.filter((p) => {
359
1096
  const tags = p.tags ?? [];
360
- if (quickFilter === '现在开着') return p.state !== 'closed';
361
- if (quickFilter === '我的地点') return p.userVenue;
362
- if (quickFilter === '室内') return tags.some((tag) => tag.includes('室内'));
363
- if (quickFilter === '户外') return tags.some((tag) => /户外|室外/.test(tag));
364
- if (quickFilter === '夜游') return tags.some((tag) => /夜/.test(tag));
1097
+ if (quickFilter === "现在开着") return p.state !== "closed";
1098
+ if (quickFilter === "我的地点") return p.userVenue;
1099
+ if (quickFilter === "室内") return tags.some((tag) => tag.includes("室内"));
1100
+ if (quickFilter === "户外") return tags.some((tag) => /户外|室外/.test(tag));
1101
+ if (quickFilter === "夜游") return tags.some((tag) => /夜/.test(tag));
365
1102
  return true;
366
1103
  });
367
- const matched = kw
368
- ? filtered.filter((p) => p.name.toLowerCase().includes(kw)
369
- || p.aliases.some((a) => a.toLowerCase().includes(kw))
370
- || p.tags.some((t) => t.toLowerCase().includes(kw)))
371
- : filtered;
372
-
373
- const open = matched.filter((p) => p.state !== 'closed');
374
- const closed = matched.filter((p) => p.state === 'closed');
375
-
376
- /** 一格里画卡;展开时它后面紧跟一条详情,并且这一格跨满整行。 */
1104
+ const matched = kw ? filtered.filter((p) => p.name.toLowerCase().includes(kw) || p.aliases.some((a) => a.toLowerCase().includes(kw)) || p.tags.some((t) => t.toLowerCase().includes(kw))) : filtered;
1105
+ const open = matched.filter((p) => p.state !== "closed");
1106
+ const closed = matched.filter((p) => p.state === "closed");
377
1107
  const cell = (p) => {
378
- const isOpen = expanded === p.id;
379
- const wrap = el('div', { class: isOpen ? 'fun-cell fun-cell-open' : 'fun-cell' });
1108
+ const isOpen = expanded === p.id && expandedOrigin === "list";
1109
+ const wrap = el2("div", { class: isOpen ? "fun-cell fun-cell-open" : "fun-cell" });
380
1110
  wrap.appendChild(card(p));
381
1111
  if (isOpen) wrap.appendChild(detail(p));
382
1112
  return wrap;
383
1113
  };
384
-
385
1114
  const section = (title, items) => {
386
1115
  if (!items.length) return;
387
- listBox.appendChild(el('div', { class: 'fun-sec', text: title }));
388
- listBox.appendChild(el('div', { class: 'fun-grid' }, items.map(cell)));
1116
+ listBox.appendChild(el2("div", { class: "fun-sec", text: title }));
1117
+ listBox.appendChild(el2("div", { class: "fun-grid" }, items.map(cell)));
389
1118
  };
390
- section(kw || quickFilter !== '全部' ? `筛选结果 · 开着的(${open.length})` : `开着的(${open.length})`, open);
391
- section('已经关了', closed);
1119
+ section(kw || quickFilter !== "全部" ? `筛选结果 · 开着的(${open.length})` : `开着的(${open.length})`, open);
1120
+ section("已经关了", closed);
392
1121
  if (!matched.length) {
393
- listBox.appendChild(el('div', { class: 'fun-empty', text: kw ? `没有匹配「${keyword}」的地方,试试其他筛选。` : '这个筛选下还没有地方,换一项看看。' }));
1122
+ listBox.appendChild(el2("div", { class: "fun-empty", text: kw ? `没有匹配「${keyword}」的地方,试试其他筛选。` : "这个筛选下还没有地方,换一项看看。" }));
394
1123
  }
395
1124
  }
396
-
397
- const card = (p) => {
398
- const cls = ['fun-card'];
399
- if (p.state === 'closed') cls.push('fun-card-closed');
400
- else if (p.state === 'closingSoon') cls.push('fun-card-soon');
401
- else cls.push('fun-card-open');
402
- if (expanded === p.id) cls.push('fun-card-active');
403
- const stateCls = p.state === 'open' ? 'fun-card-state-open'
404
- : (p.state === 'closingSoon' ? 'fun-card-state-soon' : '');
405
- const node = el('div', {
406
- class: cls.join(' '),
407
- role: 'button',
408
- tabindex: '0',
409
- 'aria-expanded': expanded === p.id ? 'true' : 'false',
410
- onclick: () => toggle(p.id),
411
- onkeydown: (ev) => {
412
- // 键盘也能开合:卡片是 role=button,不能只认鼠标。
413
- if (ev.key === 'Enter' || ev.key === ' ' || ev.key === 'Spacebar') {
414
- ev.preventDefault?.();
415
- toggle(p.id);
1125
+ const card = (p, recommended = false) => {
1126
+ const selected = expanded === p.id && expandedOrigin === (recommended ? "recommend" : "list");
1127
+ const cls = [recommended ? "fun-recommend-card" : "fun-card"];
1128
+ if (p.state === "closed") cls.push("fun-card-closed");
1129
+ else if (p.state === "closingSoon") cls.push("fun-card-soon");
1130
+ else cls.push("fun-card-open");
1131
+ if (selected) cls.push("fun-card-active");
1132
+ const stateCls = p.state === "open" ? "fun-card-state-open" : p.state === "closingSoon" ? "fun-card-state-soon" : "";
1133
+ const node = el2(
1134
+ "div",
1135
+ {
1136
+ class: cls.join(" "),
1137
+ role: "button",
1138
+ tabindex: "0",
1139
+ "aria-expanded": selected ? "true" : "false",
1140
+ "aria-label": `${p.name},${p.stateLabel},查看详情`,
1141
+ "data-place-id": p.id,
1142
+ onclick: () => toggle(p.id, recommended),
1143
+ onkeydown: (ev) => {
1144
+ if (ev.key === "Enter" || ev.key === " " || ev.key === "Spacebar") {
1145
+ ev.preventDefault?.();
1146
+ toggle(p.id, recommended, true);
1147
+ }
416
1148
  }
417
1149
  },
418
- },
419
- el('div', { class: 'fun-card-head' },
420
- el('span', { class: 'fun-card-name', text: p.name }),
421
- p.phase ? el('span', { class: 'fun-chip fun-chip-phase', text: p.phase }) : null,
422
- el('span', { class: `fun-card-state ${stateCls}`, text: p.stateLabel }),
423
- el('span', { class: 'fun-card-arrow', text: expanded === p.id ? '⌃' : '⌄' })),
424
- el('div', { class: 'fun-card-desc', text: p.desc }),
425
- el('div', { class: 'fun-card-foot' },
426
- el('span', { text: `${p.hours.open}–${p.hours.close}` }),
427
- el('span', { text: p.crowdLabel }),
428
- el('span', { text: `${p.areaCount} 处可逛` }),
429
- p.food ? el('span', { class: 'fun-chip fun-chip-ate', text: p.food.verb === '喝' ? '能喝' : '能吃' }) : null,
430
- p.visitCount > 0 ? el('span', { class: 'fun-chip', text: `去过 ${p.visitCount} 次` }) : null,
431
- p.recent ? el('span', { class: 'fun-chip', text: '刚去过' }) : null));
1150
+ sceneArt(p),
1151
+ el2(
1152
+ "div",
1153
+ { class: "fun-card-head" },
1154
+ el2("span", { class: recommended ? "fun-recommend-name" : "fun-card-name", text: p.name }),
1155
+ p.phase ? el2("span", { class: "fun-chip fun-chip-phase", text: p.phase }) : null,
1156
+ el2("span", { class: `fun-card-state ${stateCls}`, text: p.stateLabel }),
1157
+ el2("span", { class: "fun-card-arrow", text: selected ? "⌃" : "⌄" })
1158
+ ),
1159
+ recommended ? el2("div", { class: "fun-recommend-reason", text: p.wishReason || p.revisitReason || `${p.hours.open}–${p.hours.close} · ${p.crowdLabel} · ${p.phase || p.tags?.slice(0, 2).join(" / ") || "现在开着"}` }) : null,
1160
+ recommended ? null : el2("div", { class: "fun-card-desc", text: p.desc }),
1161
+ !recommended && p.wishReason ? el2("div", { class: "fun-meta", text: p.wishReason }) : null,
1162
+ !recommended && p.revisitReason ? el2("div", { class: "fun-meta", text: p.revisitReason }) : null,
1163
+ el2(
1164
+ "div",
1165
+ { class: "fun-card-foot" },
1166
+ el2("span", { text: `${p.hours.open}–${p.hours.close}` }),
1167
+ el2("span", { text: p.crowdLabel }),
1168
+ el2("span", { text: `${p.areaCount} 处可逛` }),
1169
+ p.food ? el2("span", { class: "fun-chip fun-chip-ate", text: p.food.verb === "喝" ? "能喝" : "能吃" }) : null,
1170
+ p.visitCount > 0 ? el2("span", { class: "fun-chip", text: `去过 ${p.visitCount} 次` }) : null,
1171
+ p.recent ? el2("span", { class: "fun-chip", text: "刚去过" }) : null
1172
+ )
1173
+ );
432
1174
  return node;
433
1175
  };
434
-
435
- /**
436
- * 开合一张卡。
437
- *
438
- * 重画之后把刚展开的那一块滚进视野——否则点上面第一张、展开的内容在下面一屏以外,
439
- * 用户会以为自己点错了。`block: 'nearest'` 保证「已经看得见就不动」,
440
- * 不会因为点一张本来就在屏幕里的卡而把页面跳一下。
441
- */
442
- function toggle(id) {
443
- const wasOpen = expanded === id;
1176
+ function toggle(id, recommended = false, keyboard = false) {
1177
+ const origin = recommended ? "recommend" : "list";
1178
+ const wasOpen = expanded === id && expandedOrigin === origin;
444
1179
  expanded = wasOpen ? null : id;
1180
+ expandedOrigin = origin;
445
1181
  renderList();
1182
+ if (keyboard) [...(recommended ? recommendBox : listBox).querySelectorAll(recommended ? ".fun-recommend-card" : ".fun-card")].find((node) => node.getAttribute("data-place-id") === id)?.focus?.();
446
1183
  if (!wasOpen) {
447
- // 滚的是**整格**(卡 + 详情),不是只滚卡片:
448
- // 卡片恰好贴在视口底部时,只保证卡片可见等于详情还在屏幕外。
449
- const active = listBox.querySelector('.fun-card-active');
1184
+ const active = (recommended ? recommendBox : listBox).querySelector(".fun-card-active");
450
1185
  const target = active?.parentNode ?? active;
451
- // 真 DOM 有 scrollIntoView;测试桩没有,判一下再用。
452
- if (target && typeof target.scrollIntoView === 'function') {
453
- target.scrollIntoView({ block: 'nearest', behavior: 'auto' });
1186
+ if (target && typeof target.scrollIntoView === "function") {
1187
+ target.scrollIntoView({ block: "nearest", behavior: "auto" });
454
1188
  }
455
1189
  }
456
1190
  }
457
-
458
1191
  const detail = (p) => {
459
- const d = el('div', { class: 'fun-detail' },
460
- el('div', { class: 'fun-detail-top' },
461
- el('h4', { text: p.name },
462
- p.overridden ? el('span', { class: 'fun-chip fun-chip-on', text: '已改', style: { marginLeft: '6px' } }) : null),
463
- el('div', { class: 'fun-detail-actions' },
1192
+ const d = el2(
1193
+ "div",
1194
+ { class: "fun-detail" },
1195
+ el2(
1196
+ "div",
1197
+ { class: "fun-detail-top" },
1198
+ el2(
1199
+ "h4",
1200
+ { text: p.name },
1201
+ p.overridden ? el2("span", { class: "fun-chip fun-chip-on", text: "已改", style: { marginLeft: "6px" } }) : null
1202
+ ),
1203
+ el2(
1204
+ "div",
1205
+ { class: "fun-detail-actions" },
464
1206
  // B 阶段起预设也能编辑:改的是覆盖层,预设常量不动。
465
- el('button', {
466
- class: 'fun-detail-edit',
467
- type: 'button',
1207
+ el2("button", {
1208
+ class: "fun-detail-edit",
1209
+ type: "button",
468
1210
  onclick: (ev) => {
469
1211
  ev?.stopPropagation?.();
470
- editing = { mode: 'edit', venue: p };
471
- formError = '';
1212
+ editing = { mode: "edit", venue: p };
1213
+ formError = "";
472
1214
  renderAll();
473
- },
474
- }, '编辑'),
475
- el('button', {
476
- class: 'fun-detail-close',
477
- type: 'button',
478
- title: '收起',
1215
+ }
1216
+ }, "编辑"),
1217
+ el2("button", {
1218
+ class: "fun-detail-close",
1219
+ type: "button",
1220
+ title: "收起",
479
1221
  onclick: (ev) => {
480
- // 卡片自己也绑了 onclick:不拦住的话会先收起再被卡片重新展开。
481
1222
  ev?.stopPropagation?.();
482
1223
  expanded = null;
483
1224
  renderList();
484
- },
485
- }, '收起'))),
486
- el('p', { class: 'fun-dim', text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
1225
+ }
1226
+ }, "收起")
1227
+ )
1228
+ ),
1229
+ sceneArt(p, true),
1230
+ el2("p", { class: "fun-dim", text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
487
1231
  // 此刻的那段描写:有阶段的场所显示的是「这会儿的样子」,不是通用那段。
488
- el('p', { class: 'fun-detail-desc', text: p.desc }),
1232
+ el2("p", { class: "fun-detail-desc", text: p.desc }),
489
1233
  // 时段一览:让她和主人都看得出「换个时间来是另一副样子」。
490
- (p.phases && p.phases.length > 1)
491
- ? el('div', {},
492
- el('div', { class: 'fun-sec', text: '不同时段' }),
493
- el('div', { class: 'fun-phases' }, p.phases.map((ph) => el('span', {
494
- class: ph.label === p.phase ? 'fun-chip fun-chip-phase fun-chip-on' : 'fun-chip',
495
- title: `${ph.from}–${ph.to}`,
496
- text: `${ph.label} ${ph.from}–${ph.to}`,
497
- }))))
498
- : null,
1234
+ p.phases && p.phases.length > 1 ? el2(
1235
+ "div",
1236
+ {},
1237
+ el2("div", { class: "fun-sec", text: "不同时段" }),
1238
+ el2("div", { class: "fun-phases" }, p.phases.map((ph) => el2("span", {
1239
+ class: ph.label === p.phase ? "fun-chip fun-chip-phase fun-chip-on" : "fun-chip",
1240
+ title: `${ph.from}–${ph.to}`,
1241
+ text: `${ph.label} ${ph.from}–${ph.to}`
1242
+ })))
1243
+ ) : null,
499
1244
  // 三块并成一排:能逛的 / 纪念品 / 拍照点,省纵向高度(原来三个小节摞起来很高)。
500
- el('div', { class: 'fun-detail-cols' },
501
- el('div', { class: 'fun-detail-col' },
502
- el('div', { class: 'fun-sec', text: '能逛的' }),
503
- el('ul', { class: 'fun-list' }, p.areas.map((a) => el('li', { text: a })))),
504
- el('div', { class: 'fun-detail-col' },
505
- el('div', { class: 'fun-sec', text: '纪念品' }),
506
- el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip', text: s }))),
507
- el('div', { class: 'fun-sec', text: '拍照点' }),
508
- el('div', { class: 'fun-chips' }, p.photoSpots.map((s) => el('span', { class: 'fun-chip', text: s }))),
509
- p.food
510
- ? el('div', {},
511
- el('div', { class: 'fun-sec', text: `能${p.food.verb}的` }),
512
- el('div', { class: 'fun-chips' }, p.food.items.map((s) => el('span', { class: 'fun-chip', text: s }))),
513
- el('div', { class: 'fun-note', text: `味道不在这儿——装了「鱼的每一天」才有九维口感,没装就只知道${p.food.verb}了什么。` }))
514
- : null)),
515
- el('div', { class: 'fun-scene' },
516
- p.hasScene
517
- ? el('span', {}, '生图时 ', el('b', { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`)
518
- : el('span', {}, '素材库里没有这处的场景,生图时 ', el('b', { text: 'scene 不用填' }), ',把地方写进 prompt 就行')));
519
-
1245
+ el2(
1246
+ "div",
1247
+ { class: "fun-detail-cols" },
1248
+ el2(
1249
+ "div",
1250
+ { class: "fun-detail-col" },
1251
+ el2("div", { class: "fun-sec", text: "能逛的" }),
1252
+ el2("ul", { class: "fun-list" }, p.areas.map((a) => el2("li", { text: a })))
1253
+ ),
1254
+ el2(
1255
+ "div",
1256
+ { class: "fun-detail-col" },
1257
+ el2("div", { class: "fun-sec", text: "纪念品" }),
1258
+ el2("div", { class: "fun-chips" }, p.souvenirs.map((s) => el2("span", { class: "fun-chip" }, itemIcon(s), s))),
1259
+ el2("div", { class: "fun-sec", text: "拍照点" }),
1260
+ el2("div", { class: "fun-chips" }, p.photoSpots.map((s) => el2("span", { class: "fun-chip", text: s }))),
1261
+ p.food ? el2(
1262
+ "div",
1263
+ {},
1264
+ el2("div", { class: "fun-sec", text: `能${p.food.verb}的` }),
1265
+ el2("div", { class: "fun-chips" }, p.food.items.map((s) => el2("span", { class: "fun-chip", text: s }))),
1266
+ el2("div", { class: "fun-note", text: `味道不在这儿——装了「鱼的每一天」才有九维口感,没装就只知道${p.food.verb}了什么。` })
1267
+ ) : null
1268
+ )
1269
+ ),
1270
+ el2(
1271
+ "div",
1272
+ { class: "fun-scene" },
1273
+ p.hasScene ? el2("span", {}, "生图时 ", el2("b", { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`) : el2("span", {}, "素材库里没有这处的场景,生图时 ", el2("b", { text: "scene 不用填" }), ",把地方写进 prompt 就行")
1274
+ )
1275
+ );
1276
+ d.appendChild(historyView(p.id));
520
1277
  return d;
521
1278
  };
522
-
523
- // ---- 地点表单(自填新建 / 自填编辑 / 预设编辑三态)----
524
- // 放在 render 内部:能直接拿到当前 data 与 editing,保存后整体重画一次即可。
525
1279
  function venueForm() {
526
1280
  const v = editing.venue ?? {};
527
- // 预设编辑:改的是覆盖层,不删场所;没改过的字段仍跟着预设升级走。
528
1281
  const isPreset = Boolean(v.id) && !v.userVenue;
529
1282
  const phases = isPreset && Array.isArray(v.phases) ? v.phases : [];
530
1283
  const descPhases = phases.filter((ph) => ph.overridesDesc);
531
1284
  const areaPhases = phases.filter((ph) => ph.overridesAreas);
532
- const phaseNames = (items) => items.map((ph) => `${ph.label} ${ph.from}–${ph.to}`).join('、');
533
- const scopeNote = (items, noun) => items.length
534
- ? `通用${noun}会保存;在${phaseNames(items)}使用预设时段${noun},未命中这些时段时才使用这里的内容。保存不会同步修改时段。`
535
- : '';
536
- const verb = v.food?.verb ?? 'none';
1285
+ const phaseNames = (items) => items.map((ph) => `${ph.label} ${ph.from}–${ph.to}`).join("、");
1286
+ const scopeNote = (items, noun) => items.length ? `通用${noun}会保存;在${phaseNames(items)}使用预设时段${noun},未命中这些时段时才使用这里的内容。保存不会同步修改时段。` : "";
1287
+ const verb = v.food?.verb ?? "none";
537
1288
  const foodItems = v.food?.items ?? [];
538
- const errorNode = el('div', { class: 'fun-form-error', text: formError });
539
-
540
- const field = (label, key, opts = {}) => {
541
- const { type = 'text', value = '', hint = '', note = '', multiline = false, options = null, rows = '3' } = opts;
542
- let input;
1289
+ const errorNode = el2("div", { class: "fun-form-error", text: formError });
1290
+ const field = (label2, key, opts = {}) => {
1291
+ const { type = "text", value = "", hint = "", note: note2 = "", multiline = false, options = null, rows = "3" } = opts;
1292
+ let input2;
543
1293
  if (options) {
544
- input = el('select', {});
545
- for (const [val, lab] of options) input.appendChild(el('option', { value: val, text: lab }));
546
- input.value = value;
1294
+ input2 = el2("select", {});
1295
+ for (const [val, lab] of options) input2.appendChild(el2("option", { value: val, text: lab }));
1296
+ input2.value = value;
547
1297
  } else if (multiline) {
548
- input = el('textarea', { rows, placeholder: hint });
549
- input.value = value;
1298
+ input2 = el2("textarea", { rows, placeholder: hint });
1299
+ input2.value = value;
550
1300
  } else {
551
- input = el('input', { type, placeholder: hint });
552
- input.value = value;
1301
+ input2 = el2("input", { type, placeholder: hint });
1302
+ input2.value = value;
553
1303
  }
554
- fields[key] = input;
555
- return el('label', { class: 'fun-field' },
556
- el('span', { class: 'fun-field-label', text: label }), input,
557
- note ? el('span', { class: 'fun-field-scope fun-note', text: note }) : null);
1304
+ fields[key] = input2;
1305
+ return el2(
1306
+ "label",
1307
+ { class: "fun-field" },
1308
+ el2("span", { class: "fun-field-label", text: label2 }),
1309
+ input2,
1310
+ note2 ? el2("span", { class: "fun-field-scope fun-note", text: note2 }) : null
1311
+ );
558
1312
  };
559
-
560
1313
  const save = async () => {
561
1314
  const payload = {
562
- ...(v.id ? { id: v.id } : {}),
1315
+ ...v.id ? { id: v.id } : {},
563
1316
  name: fields.name.value.trim(),
564
1317
  aliases: parseLines(fields.aliases.value),
565
1318
  tags: parseLines(fields.tags.value),
@@ -570,23 +1323,22 @@ function mountPlaces(ctx) {
570
1323
  areas: parseLines(fields.areas.value),
571
1324
  souvenirs: parseLines(fields.souvenirs.value),
572
1325
  photoSpots: parseLines(fields.photoSpots.value),
573
- randomEvents: parseLines(fields.randomEvents.value),
1326
+ randomEvents: parseLines(fields.randomEvents.value)
574
1327
  };
575
1328
  const foodVerb = fields.foodVerb.value;
576
- if (foodVerb && foodVerb !== 'none') {
577
- payload.food = { verb: foodVerb === 'drink' ? '喝' : '吃', items: parseLines(fields.foodItems.value) };
1329
+ if (foodVerb && foodVerb !== "none") {
1330
+ payload.food = { verb: foodVerb === "drink" ? "喝" : "吃", items: parseLines(fields.foodItems.value) };
578
1331
  }
579
1332
  try {
580
- const r = await ctx.invoke('save', [payload]);
1333
+ const r = await ctx.invoke("save", [payload]);
581
1334
  if (!r?.ok) {
582
- // 只改错误行,不重画表单——重画会把用户刚填的一整页冲掉。
583
- formError = r?.error ?? '存不下来';
1335
+ formError = r?.error ?? "存不下来";
584
1336
  errorNode.textContent = formError;
585
1337
  return;
586
1338
  }
587
1339
  editing = null;
588
- formError = '';
589
- keyword = '';
1340
+ formError = "";
1341
+ keyword = "";
590
1342
  expanded = null;
591
1343
  await load();
592
1344
  } catch (err) {
@@ -594,17 +1346,17 @@ function mountPlaces(ctx) {
594
1346
  errorNode.textContent = formError;
595
1347
  }
596
1348
  };
597
-
598
1349
  const remove = async () => {
599
1350
  if (!v.id) return;
600
1351
  try {
601
- // 预设不能删,只能「恢复预设」(抹掉这一处覆盖层)。
602
- const r = isPreset
603
- ? await ctx.invoke('reset', [{ id: v.id }])
604
- : await ctx.invoke('remove', [{ id: v.id }]);
605
- if (!r?.ok) { formError = r?.error ?? '操作没成'; errorNode.textContent = formError; return; }
1352
+ const r = isPreset ? await ctx.invoke("reset", [{ id: v.id }]) : await ctx.invoke("remove", [{ id: v.id }]);
1353
+ if (!r?.ok) {
1354
+ formError = r?.error ?? "操作没成";
1355
+ errorNode.textContent = formError;
1356
+ return;
1357
+ }
606
1358
  editing = null;
607
- formError = '';
1359
+ formError = "";
608
1360
  expanded = null;
609
1361
  await load();
610
1362
  } catch (err) {
@@ -612,205 +1364,273 @@ function mountPlaces(ctx) {
612
1364
  errorNode.textContent = formError;
613
1365
  }
614
1366
  };
615
-
616
- const title = editing.mode === 'new'
617
- ? '添加一处自己的地方'
618
- : (isPreset ? `编辑预设:${v.name}` : `编辑:${v.name}`);
619
- const note = isPreset
620
- ? '改的是「覆盖层」,预设本身不动:只存你真改过的字段,以后预设升级的新内容照样能拿到。'
621
- + '时段分段(不同时段不一样)不在这里改;想还原就点「恢复预设」。名字别改成另一处预设的正名。'
622
- : '只写名字和「能逛的」就能用;别的留空也行。一行一条。';
623
- return el('div', { class: 'fun-form' },
624
- el('div', { class: 'fun-form-title', text: title }),
625
- el('div', { class: 'fun-form-note', text: note }),
626
- phases.length ? el('div', { class: 'fun-form-phases' },
627
- el('div', { class: 'fun-form-note', text: `现在 ${data.nowHm} · ${v.phase ? `当前阶段:${v.phase}` : '当前未命中预设时段,使用通用内容'}。编辑通用字段不会改变以下预设时段及其内容;修改营业时间也不会移动这些时段。` }),
628
- el('ul', { class: 'fun-list' }, phases.map((ph) => {
629
- const covered = [ph.overridesDesc ? '描写(desc)' : '', ph.overridesAreas ? '能逛的(areas)' : ''].filter(Boolean);
630
- return el('li', { text: `${ph.label} ${ph.from}–${ph.to}${ph.label === v.phase ? '(当前)' : ''}:${covered.length ? `覆盖通用${covered.join('、')}` : '沿用通用描写与可逛清单'}` });
631
- }))) : null,
1367
+ const title = editing.mode === "new" ? "添加一处自己的地方" : isPreset ? `编辑预设:${v.name}` : `编辑:${v.name}`;
1368
+ const note = isPreset ? "改的是「覆盖层」,预设本身不动:只存你真改过的字段,以后预设升级的新内容照样能拿到。时段分段(不同时段不一样)不在这里改;想还原就点「恢复预设」。名字别改成另一处预设的正名。" : "只写名字和「能逛的」就能用;别的留空也行。一行一条。";
1369
+ return el2(
1370
+ "div",
1371
+ { class: "fun-form" },
1372
+ el2("div", { class: "fun-form-title", text: title }),
1373
+ el2("div", { class: "fun-form-note", text: note }),
1374
+ phases.length ? el2(
1375
+ "div",
1376
+ { class: "fun-form-phases" },
1377
+ el2("div", { class: "fun-form-note", text: `现在 ${data.nowHm} · ${v.phase ? `当前阶段:${v.phase}` : "当前未命中预设时段,使用通用内容"}。编辑通用字段不会改变以下预设时段及其内容;修改营业时间也不会移动这些时段。` }),
1378
+ el2("ul", { class: "fun-list" }, phases.map((ph) => {
1379
+ const covered = [ph.overridesDesc ? "描写(desc)" : "", ph.overridesAreas ? "能逛的(areas)" : ""].filter(Boolean);
1380
+ return el2("li", { text: `${ph.label} ${ph.from}–${ph.to}${ph.label === v.phase ? "(当前)" : ""}:${covered.length ? `覆盖通用${covered.join("、")}` : "沿用通用描写与可逛清单"}` });
1381
+ }))
1382
+ ) : null,
632
1383
  errorNode,
633
- el('div', { class: 'fun-form-grid' },
634
- field('名字 *', 'name', { value: v.name ?? '', hint: '例如「巷子里的旧书店」' }),
635
- field('别名', 'aliases', { value: lines(v.aliases), hint: '一行一个,可选' }),
636
- field('标签', 'tags', { value: lines(v.tags), hint: '室内 / 夜 / 免费… 一行一个' }),
637
- field('推荐穿搭', 'outfit', { value: v.recommendedOutfit ?? '', hint: '可选,例如「外出外套」' }),
638
- field('开门时间', 'open', { value: v.hours?.open ?? '09:00', hint: 'HH:MM' }),
639
- field('关门时间', 'close', { value: v.hours?.close ?? '21:00', hint: 'HH:MM' }),
640
- field('人多不多', 'crowd', {
641
- value: v.crowd ?? 'normal',
642
- options: [['quiet', '人不多'], ['normal', '人不算多'], ['packed', '人很多']],
1384
+ el2(
1385
+ "div",
1386
+ { class: "fun-form-grid" },
1387
+ field("名字 *", "name", { value: v.name ?? "", hint: "例如「巷子里的旧书店」" }),
1388
+ field("别名", "aliases", { value: lines(v.aliases), hint: "一行一个,可选" }),
1389
+ field("标签", "tags", { value: lines(v.tags), hint: "室内 / 夜 / 免费… 一行一个" }),
1390
+ field("推荐穿搭", "outfit", { value: v.recommendedOutfit ?? "", hint: "可选,例如「外出外套」" }),
1391
+ field("开门时间", "open", { value: v.hours?.open ?? "09:00", hint: "HH:MM" }),
1392
+ field("关门时间", "close", { value: v.hours?.close ?? "21:00", hint: "HH:MM" }),
1393
+ field("人多不多", "crowd", {
1394
+ value: v.crowd ?? "normal",
1395
+ options: [["quiet", "人不多"], ["normal", "人不算多"], ["packed", "人很多"]]
643
1396
  }),
644
- field('能吃能喝', 'foodVerb', {
645
- value: verb === '喝' ? 'drink' : (verb === '吃' ? 'eat' : 'none'),
646
- options: [['none', '没有'], ['drink', '喝的'], ['eat', '吃的']],
647
- })),
1397
+ field("能吃能喝", "foodVerb", {
1398
+ value: verb === "喝" ? "drink" : verb === "吃" ? "eat" : "none",
1399
+ options: [["none", "没有"], ["drink", "喝的"], ["eat", "吃的"]]
1400
+ })
1401
+ ),
648
1402
  // 预设可能带时段:面板的 desc 是「此刻那段」,编辑要用通用那段(descAll),
649
1403
  // 否则编辑一次会把某一段的描写写进覆盖层,别的时段全变成那一段。
650
- field(phases.length ? '通用描写(desc)' : '这处是什么样子', 'desc', { value: v.descAll ?? v.desc ?? '', hint: '只写空间与陈设,别写她在干什么', note: scopeNote(descPhases, '描写'), multiline: true, rows: '3' }),
651
- field(phases.length ? '通用可逛清单(areas)*' : '能逛的 *', 'areas', { value: lines(v.allAreas ?? v.areas), hint: '一行一处,至少一处', note: scopeNote(areaPhases, '可逛清单'), multiline: true, rows: '4' }),
652
- field('纪念品', 'souvenirs', { value: lines(v.souvenirs), hint: '一行一样', multiline: true, rows: '2' }),
653
- field('拍照点', 'photoSpots', { value: lines(v.photoSpots), hint: '一行一处', multiline: true, rows: '2' }),
654
- field('能吃能喝的品类', 'foodItems', { value: lines(foodItems), hint: '品类名,一行一样;别写味道', multiline: true, rows: '2' }),
655
- field('可能碰上的小事', 'randomEvents', { value: lines(v.randomEvents), hint: '一行一条,可选', multiline: true, rows: '2' }),
656
- el('div', { class: 'fun-form-actions' },
657
- el('button', { class: 'fun-btn-primary', type: 'button', onclick: save }, '保存'),
658
- v.id ? el('button', { class: 'fun-danger', type: 'button', onclick: remove },
659
- isPreset ? '恢复预设' : '删除这处') : null,
660
- el('button', {
661
- type: 'button',
1404
+ field(phases.length ? "通用描写(desc)" : "这处是什么样子", "desc", { value: v.descAll ?? v.desc ?? "", hint: "只写空间与陈设,别写她在干什么", note: scopeNote(descPhases, "描写"), multiline: true, rows: "3" }),
1405
+ field(phases.length ? "通用可逛清单(areas)*" : "能逛的 *", "areas", { value: lines(v.allAreas ?? v.areas), hint: "一行一处,至少一处", note: scopeNote(areaPhases, "可逛清单"), multiline: true, rows: "4" }),
1406
+ field("纪念品", "souvenirs", { value: lines(v.souvenirs), hint: "一行一样", multiline: true, rows: "2" }),
1407
+ field("拍照点", "photoSpots", { value: lines(v.photoSpots), hint: "一行一处", multiline: true, rows: "2" }),
1408
+ field("能吃能喝的品类", "foodItems", { value: lines(foodItems), hint: "品类名,一行一样;别写味道", multiline: true, rows: "2" }),
1409
+ field("可能碰上的小事", "randomEvents", { value: lines(v.randomEvents), hint: "一行一条,可选", multiline: true, rows: "2" }),
1410
+ el2(
1411
+ "div",
1412
+ { class: "fun-form-actions" },
1413
+ el2("button", { class: "fun-btn-primary", type: "button", onclick: save }, "保存"),
1414
+ v.id ? el2(
1415
+ "button",
1416
+ { class: "fun-danger", type: "button", onclick: remove },
1417
+ isPreset ? "恢复预设" : "删除这处"
1418
+ ) : null,
1419
+ el2("button", {
1420
+ type: "button",
662
1421
  onclick: () => {
663
1422
  editing = null;
664
- formError = '';
665
- // 表单开着时自动刷新只存了数据没重画;关掉时用最新那份补画。
666
- if (currentData) { render(currentData); currentData = null; }
667
- else renderAll();
668
- },
669
- }, '取消')));
1423
+ formError = "";
1424
+ if (currentData) {
1425
+ render(currentData);
1426
+ currentData = null;
1427
+ } else renderAll();
1428
+ }
1429
+ }, "取消")
1430
+ )
1431
+ );
670
1432
  }
671
-
672
1433
  renderList();
1434
+ restoreFocus();
673
1435
  };
674
-
675
1436
  const load = async () => {
1437
+ const sequence = ++loadSequence;
676
1438
  try {
677
- const data = await ctx.invoke('list');
678
- if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
679
- // 正在填表单时别重画——一分钟的自动刷新会把用户刚填的一整页冲掉。
680
- if (editing) { currentData = data; return; }
1439
+ const data = await ctx.invoke("list");
1440
+ if (sequence !== loadSequence || ctx.signal?.aborted) return;
1441
+ if (!data?.ok) throw new Error(data?.error ?? "返回不正常");
1442
+ if (editing) {
1443
+ currentData = data;
1444
+ return;
1445
+ }
681
1446
  status.replaceChildren();
682
1447
  render(data);
683
1448
  } catch (err) {
1449
+ if (sequence !== loadSequence || ctx.signal?.aborted) return;
684
1450
  if (!currentData) body.replaceChildren();
685
1451
  status.replaceChildren(errorCard(err, load, Boolean(currentData)));
686
1452
  }
687
1453
  };
688
-
1454
+ async function resolveDraft(method, id) {
1455
+ if (outingAction) return;
1456
+ outingAction = method;
1457
+ notice = null;
1458
+ render(currentData);
1459
+ try {
1460
+ const result = await ctx.invoke(method, [{ id }]);
1461
+ if (!result?.ok) throw new Error(result?.error ?? "行程更新失败");
1462
+ notice = { text: result.text || "行程已更新。" };
1463
+ currentData = { ...currentData, draft: null };
1464
+ } catch (err) {
1465
+ notice = { text: err?.message ?? String(err), error: true };
1466
+ } finally {
1467
+ outingAction = "";
1468
+ if (ctx.signal?.aborted) return;
1469
+ render(currentData);
1470
+ await load();
1471
+ body.querySelector(".fun-outing-result")?.focus?.();
1472
+ }
1473
+ }
689
1474
  void load();
690
- // 状态会随时间变(几点、开没开):一分钟刷一次就够,不打断操作。
691
- ctx.interval(() => { void load(); }, 60000);
1475
+ ctx.interval(() => {
1476
+ void load();
1477
+ }, 6e4);
692
1478
  return { refresh: load };
693
1479
  }
694
-
695
- // ---------------------------------------------------------------------------
696
- // book —— 纪念册
697
- // ---------------------------------------------------------------------------
698
-
699
1480
  function mountBook(ctx) {
700
1481
  const root = ctx.root;
701
1482
  root.replaceChildren();
702
1483
  const box = shell(root);
703
- const body = el('div');
1484
+ const body = el2("div");
704
1485
  box.appendChild(body);
705
- let bookTab = 'all';
1486
+ let bookTab = "all";
1487
+ let bookKeyword = "";
1488
+ let bookPlace = "";
1489
+ let bookDate = "";
706
1490
  let wishFormOpen = false;
707
- const expandedTrips = new Set();
708
- const status = feedback(box);
709
- body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在翻开纪念册…' }));
710
- const pending = new Set();
711
- const errors = new Map();
1491
+ const expandedTrips = /* @__PURE__ */ new Set();
1492
+ const status = feedback2(box);
1493
+ body.appendChild(el2("div", { class: "fun-loading", role: "status", text: "正在翻开纪念册…" }));
1494
+ const pending = /* @__PURE__ */ new Set();
1495
+ const errors = /* @__PURE__ */ new Map();
712
1496
  let currentData = null;
713
- let wishDraft = { placeId: '', type: '', target: '', reason: '' };
714
- const wishPending = new Set();
715
- const wishErrors = new Map();
716
- const wishTypes = { visit: '去看看', area: '逛一处', phase: '在某个时段去', souvenir: '带回纪念品' };
717
-
1497
+ let wishDraft = { placeId: "", type: "", target: "", reason: "" };
1498
+ const wishPending = /* @__PURE__ */ new Set();
1499
+ const wishErrors = /* @__PURE__ */ new Map();
1500
+ const wishTypes = { visit: "去看看", area: "逛一处", phase: "在某个时段去", souvenir: "带回纪念品" };
718
1501
  const renderWishes = (data) => {
719
1502
  const places = data.places ?? [];
720
1503
  const wishes = data.wishes ?? [];
721
- const adding = wishPending.has('add');
722
- const section = el('section', { class: 'fun-wishes', 'aria-label': '出游心愿' });
723
- section.appendChild(el('div', { class: 'fun-bar' },
724
- el('span', { class: 'fun-sec', text: '出游心愿' }),
725
- el('button', { type: 'button', 'aria-expanded': String(wishFormOpen), disabled: adding ? 'disabled' : null, onclick: () => { wishFormOpen = !wishFormOpen; render(currentData); } }, wishFormOpen ? '收起表单' : '记个心愿')));
726
- const field = (label, input) => el('label', { class: 'fun-field' },
727
- el('span', { class: 'fun-field-label', text: label }), input);
1504
+ const adding = wishPending.has("add");
1505
+ const section = el2("section", { class: "fun-wishes", "aria-label": "出游心愿" });
1506
+ section.appendChild(el2(
1507
+ "div",
1508
+ { class: "fun-bar" },
1509
+ el2("span", { class: "fun-sec", text: "出游心愿" }),
1510
+ el2("button", { type: "button", "aria-expanded": String(wishFormOpen), disabled: adding ? "disabled" : null, onclick: () => {
1511
+ wishFormOpen = !wishFormOpen;
1512
+ render(currentData);
1513
+ } }, wishFormOpen ? "收起表单" : "记个心愿")
1514
+ ));
1515
+ const field = (label2, input) => el2(
1516
+ "label",
1517
+ { class: "fun-field" },
1518
+ el2("span", { class: "fun-field-label", text: label2 }),
1519
+ input
1520
+ );
728
1521
  const select = (className, placeholder, options, value) => {
729
- const input = el('select', { class: className, disabled: adding ? 'disabled' : null },
730
- el('option', { value: '', text: placeholder }),
731
- options.map(([id, name]) => el('option', { value: id, text: name })));
1522
+ const input = el2(
1523
+ "select",
1524
+ { class: className, disabled: adding ? "disabled" : null },
1525
+ el2("option", { value: "", text: placeholder }),
1526
+ options.map(([id, name]) => el2("option", { value: id, text: name }))
1527
+ );
732
1528
  input.value = value;
733
1529
  return input;
734
1530
  };
735
1531
  const place = places.find((p) => p.id === wishDraft.placeId);
736
- const targets = place ? (wishDraft.type === 'area' ? place.areas
737
- : wishDraft.type === 'phase' ? place.phaseNames
738
- : wishDraft.type === 'souvenir' ? place.souvenirs : []) ?? [] : [];
739
- const placeInput = select('fun-wish-place', '请选择地点', places.map((p) => [p.id, p.name]), wishDraft.placeId);
740
- const typeInput = select('fun-wish-type', '请选择心愿类型', Object.entries(wishTypes), wishDraft.type);
741
- const targetInput = select('fun-wish-target', wishDraft.type === 'visit' ? '去看看无需目标'
742
- : !place || !wishDraft.type ? '先选择地点和类型' : targets.length ? '请选择目标' : '此地点没有可选目标',
743
- targets.map((target) => [target, target]), wishDraft.target);
1532
+ const targets = place ? (wishDraft.type === "area" ? place.areas : wishDraft.type === "phase" ? place.phaseNames : wishDraft.type === "souvenir" ? place.souvenirs : []) ?? [] : [];
1533
+ const placeInput = select("fun-wish-place", "请选择地点", places.map((p) => [p.id, p.name]), wishDraft.placeId);
1534
+ const typeInput = select("fun-wish-type", "请选择心愿类型", Object.entries(wishTypes), wishDraft.type);
1535
+ const targetInput = select(
1536
+ "fun-wish-target",
1537
+ wishDraft.type === "visit" ? "去看看无需目标" : !place || !wishDraft.type ? "先选择地点和类型" : targets.length ? "请选择目标" : "此地点没有可选目标",
1538
+ targets.map((target) => [target, target]),
1539
+ wishDraft.target
1540
+ );
744
1541
  targetInput.disabled = adding || !targets.length;
745
- const reasonInput = el('input', { class: 'fun-wish-reason', type: 'text', placeholder: '可选,记下为什么想去', disabled: adding ? 'disabled' : null });
1542
+ const reasonInput = el2("input", { class: "fun-wish-reason", type: "text", placeholder: "可选,记下为什么想去", disabled: adding ? "disabled" : null });
746
1543
  reasonInput.value = wishDraft.reason;
747
- placeInput.addEventListener('change', () => {
1544
+ placeInput.addEventListener("change", () => {
748
1545
  wishDraft.placeId = placeInput.value;
749
- wishDraft.target = '';
750
- wishErrors.delete('add');
1546
+ wishDraft.target = "";
1547
+ wishErrors.delete("add");
751
1548
  render(currentData);
752
1549
  });
753
- typeInput.addEventListener('change', () => {
1550
+ typeInput.addEventListener("change", () => {
754
1551
  wishDraft.type = typeInput.value;
755
- wishDraft.target = '';
756
- wishErrors.delete('add');
1552
+ wishDraft.target = "";
1553
+ wishErrors.delete("add");
757
1554
  render(currentData);
758
1555
  });
759
- targetInput.addEventListener('change', () => { wishDraft.target = targetInput.value; });
760
- reasonInput.addEventListener('input', () => { wishDraft.reason = reasonInput.value; });
761
- const errorNode = el('div', { class: 'fun-form-error', role: 'alert', text: wishErrors.get('add') ?? '' });
1556
+ targetInput.addEventListener("change", () => {
1557
+ wishDraft.target = targetInput.value;
1558
+ });
1559
+ reasonInput.addEventListener("input", () => {
1560
+ wishDraft.reason = reasonInput.value;
1561
+ });
1562
+ const errorNode = el2("div", { class: "fun-form-error", role: "alert", text: wishErrors.get("add") ?? "" });
762
1563
  const save = async () => {
763
- if (wishPending.has('add')) return;
764
- // 只接受用户明确选中的地点、类型与目标;从不替用户挑第一项。
765
- const payload = { action: 'add', placeId: placeInput.value, type: typeInput.value,
766
- target: typeInput.value === 'visit' ? '' : targetInput.value, reason: reasonInput.value.trim() };
1564
+ if (wishPending.has("add")) return;
1565
+ const payload = {
1566
+ action: "add",
1567
+ placeId: placeInput.value,
1568
+ type: typeInput.value,
1569
+ target: typeInput.value === "visit" ? "" : targetInput.value,
1570
+ reason: reasonInput.value.trim()
1571
+ };
767
1572
  const chosenPlace = (currentData.places ?? []).find((p) => p.id === payload.placeId);
768
- const validTargets = chosenPlace ? (payload.type === 'area' ? chosenPlace.areas
769
- : payload.type === 'phase' ? chosenPlace.phaseNames : chosenPlace.souvenirs) ?? [] : [];
770
- if (!chosenPlace || !Object.hasOwn(wishTypes, payload.type)
771
- || (payload.type !== 'visit' && !validTargets.includes(payload.target))) {
772
- const message = '请选择地点、心愿类型及对应目标。';
773
- wishErrors.set('add', message);
1573
+ const validTargets = chosenPlace ? (payload.type === "area" ? chosenPlace.areas : payload.type === "phase" ? chosenPlace.phaseNames : chosenPlace.souvenirs) ?? [] : [];
1574
+ if (!chosenPlace || !Object.hasOwn(wishTypes, payload.type) || payload.type !== "visit" && !validTargets.includes(payload.target)) {
1575
+ const message = "请选择地点、心愿类型及对应目标。";
1576
+ wishErrors.set("add", message);
774
1577
  errorNode.textContent = message;
775
1578
  return;
776
1579
  }
777
1580
  wishDraft = { placeId: payload.placeId, type: payload.type, target: payload.target, reason: reasonInput.value };
778
- await changeWish('add', payload, data);
1581
+ await changeWish("add", payload, data);
779
1582
  };
780
- if (wishFormOpen) section.appendChild(el('div', { class: 'fun-form fun-wish-form' },
781
- el('div', { class: 'fun-form-note', text: '由你选择想去的地方,按保存才记下心愿;心愿不保证立即出发。' }),
782
- el('div', { class: 'fun-form-grid' }, field('地点', placeInput), field('心愿类型', typeInput), field('目标', targetInput)),
783
- field('缘由(可选)', reasonInput), errorNode,
784
- el('button', { class: 'fun-btn-primary', type: 'button', disabled: adding ? 'disabled' : null, onclick: save }, adding ? '保存中…' : '保存心愿')));
785
- if (!wishes.length) section.appendChild(el('div', { class: 'fun-note', text: '还没有出游心愿,想好了再记下。' }));
786
- const statusNames = { active: '待实现', paused: '已暂缓', completed: '已实现', cancelled: '已取消' };
787
- const history = el('details', { class: 'fun-wish-history',
788
- open: wishes.some((w) => w.status !== 'active' && (wishErrors.has(`wish:${w.id}`) || wishPending.has(`wish:${w.id}`))) ? 'open' : null,
789
- }, el('summary', { text: `已实现、暂缓与取消(${wishes.filter((w) => w.status !== 'active').length})` }));
1583
+ if (wishFormOpen) section.appendChild(el2(
1584
+ "div",
1585
+ { class: "fun-form fun-wish-form" },
1586
+ el2("div", { class: "fun-form-note", text: "由你选择想去的地方,按保存才记下心愿;心愿不保证立即出发。" }),
1587
+ el2("div", { class: "fun-form-grid" }, field("地点", placeInput), field("心愿类型", typeInput), field("目标", targetInput)),
1588
+ field("缘由(可选)", reasonInput),
1589
+ errorNode,
1590
+ el2("button", { class: "fun-btn-primary", type: "button", disabled: adding ? "disabled" : null, onclick: save }, adding ? "保存中…" : "保存心愿")
1591
+ ));
1592
+ if (!wishes.length) section.appendChild(el2("div", { class: "fun-note", text: "还没有出游心愿,想好了再记下。" }));
1593
+ const statusNames = { active: "待实现", paused: "已暂缓", completed: "已实现", cancelled: "已取消" };
1594
+ const history = el2("details", {
1595
+ class: "fun-wish-history",
1596
+ open: wishes.some((w) => w.status !== "active" && (wishErrors.has(`wish:${w.id}`) || wishPending.has(`wish:${w.id}`))) ? "open" : null
1597
+ }, el2("summary", { text: `已实现、暂缓与取消(${wishes.filter((w) => w.status !== "active").length})` }));
790
1598
  for (const wish of wishes) {
791
1599
  const key = `wish:${wish.id}`;
792
1600
  const busy = wishPending.has(key);
793
1601
  const state = wish.status;
794
- const actions = el('div', { class: 'fun-trip-actions' });
795
- if (state === 'active' || state === 'paused') {
796
- actions.appendChild(el('button', { type: 'button', disabled: busy ? 'disabled' : null,
797
- onclick: () => changeWish(key, { action: state === 'paused' ? 'resume' : 'pause', id: wish.id }, data) }, state === 'paused' ? '恢复' : '暂缓'));
798
- actions.appendChild(el('button', { type: 'button', disabled: busy ? 'disabled' : null,
799
- onclick: () => changeWish(key, { action: 'cancel', id: wish.id }, data) }, '取消'));
1602
+ const actions = el2("div", { class: "fun-trip-actions" });
1603
+ if (state === "active" || state === "paused") {
1604
+ actions.appendChild(el2("button", {
1605
+ type: "button",
1606
+ disabled: busy ? "disabled" : null,
1607
+ onclick: () => changeWish(key, { action: state === "paused" ? "resume" : "pause", id: wish.id }, data)
1608
+ }, state === "paused" ? "恢复" : "暂缓"));
1609
+ actions.appendChild(el2("button", {
1610
+ type: "button",
1611
+ disabled: busy ? "disabled" : null,
1612
+ onclick: () => changeWish(key, { action: "cancel", id: wish.id }, data)
1613
+ }, "取消"));
800
1614
  }
801
- if (busy) actions.appendChild(el('span', { class: 'fun-dim', text: '保存中…' }));
802
- if (wishErrors.has(key)) actions.appendChild(el('span', { class: 'fun-trip-error', role: 'alert', text: wishErrors.get(key) }));
803
- (state === 'active' ? section : history).appendChild(el('div', { class: 'fun-wish fun-trip' },
804
- el('div', { class: 'fun-trip-head' },
805
- el('span', { class: 'fun-trip-name', text: wish.placeName ?? places.find((p) => p.id === wish.placeId)?.name ?? wish.placeId }),
806
- el('span', { class: 'fun-wish-status fun-dim', text: statusNames[state] ?? state ?? '状态未知' })),
807
- el('div', { class: 'fun-trip-sum', text: `${wishTypes[wish.type] ?? wish.type}${wish.target ? ` · ${wish.target}` : ''}` }),
808
- wish.reason ? el('div', { class: 'fun-wish-note fun-note', text: `缘由:${wish.reason}` }) : null, actions));
1615
+ if (busy) actions.appendChild(el2("span", { class: "fun-dim", text: "保存中…" }));
1616
+ if (wishErrors.has(key)) actions.appendChild(el2("span", { class: "fun-trip-error", role: "alert", text: wishErrors.get(key) }));
1617
+ (state === "active" ? section : history).appendChild(el2(
1618
+ "div",
1619
+ { class: "fun-wish fun-trip" },
1620
+ el2(
1621
+ "div",
1622
+ { class: "fun-trip-head" },
1623
+ el2("span", { class: "fun-trip-name", text: wish.placeName ?? places.find((p) => p.id === wish.placeId)?.name ?? wish.placeId }),
1624
+ el2("span", { class: "fun-wish-status fun-dim", text: statusNames[state] ?? state ?? "状态未知" })
1625
+ ),
1626
+ el2("div", { class: "fun-trip-sum", text: `${wishTypes[wish.type] ?? wish.type}${wish.target ? ` · ${wish.target}` : ""}` }),
1627
+ wish.reason ? el2("div", { class: "fun-wish-note fun-note", text: `缘由:${wish.reason}` }) : null,
1628
+ actions
1629
+ ));
809
1630
  }
810
- if (wishes.some((w) => w.status !== 'active')) section.appendChild(history);
1631
+ if (wishes.some((w) => w.status !== "active")) section.appendChild(history);
811
1632
  body.appendChild(section);
812
1633
  };
813
-
814
1634
  const changeWish = async (key, payload, data) => {
815
1635
  if (wishPending.has(key)) return;
816
1636
  wishPending.add(key);
@@ -818,103 +1638,225 @@ function mountBook(ctx) {
818
1638
  render(currentData ?? data);
819
1639
  let saved = false;
820
1640
  try {
821
- const result = await ctx.invoke('wish', [payload]);
822
- if (!result?.ok) throw new Error(result?.error ?? '心愿保存失败');
1641
+ const result = await ctx.invoke("wish", [payload]);
1642
+ if (!result?.ok) throw new Error(result?.error ?? "心愿保存失败");
823
1643
  saved = true;
824
- if (key === 'add') { wishDraft = { placeId: '', type: '', target: '', reason: '' }; wishFormOpen = false; }
1644
+ if (key === "add") {
1645
+ wishDraft = { placeId: "", type: "", target: "", reason: "" };
1646
+ wishFormOpen = false;
1647
+ }
825
1648
  await load(true);
826
1649
  } catch (error) {
827
- wishErrors.set(key, `${saved ? '已保存,但列表刷新失败:' : ''}${error?.message ?? String(error)}`);
828
- if (key === 'add') wishFormOpen = true;
1650
+ wishErrors.set(key, `${saved ? "已保存,但列表刷新失败:" : ""}${error?.message ?? String(error)}`);
1651
+ if (key === "add") wishFormOpen = true;
829
1652
  } finally {
830
1653
  wishPending.delete(key);
831
1654
  render(currentData ?? data);
832
1655
  }
833
1656
  };
834
-
835
1657
  const render = (data) => {
1658
+ const restoreFocus = rememberFocus(body);
836
1659
  currentData = data;
837
- body.replaceChildren(heading('纪念册', '把走过的地方,收成可以回看的小回忆。'));
838
- if (data.session) body.appendChild(el('div', { class: 'fun-live' },
839
- el('h3', { text: '正在逛 · ' + data.session.placeName }), el('div', { class: 'fun-trip-sum', text: data.session.summary })));
840
- else if (data.trips?.length) body.appendChild(el('div', { class: 'fun-live' },
841
- el('div', { class: 'fun-meta', text: '最近一趟 · ' + data.trips[0].day }),
842
- el('h3', { text: data.trips[0].placeName }), el('div', { class: 'fun-trip-sum', text: data.trips[0].summary })));
843
-
844
- const tabs = el('nav', { class: 'fun-tabs', 'aria-label': '纪念册分类' });
845
- for (const [id, label] of [['all', '全部行程'], ['kept', '珍藏'], ['wishes', '心愿']]) tabs.appendChild(el('button', {
846
- type: 'button', 'aria-pressed': String(bookTab === id), onclick: () => { bookTab = id; render(currentData); },
847
- }, label));
1660
+ body.replaceChildren(heading("纪念册", "把走过的地方,收成可以回看的小回忆。"));
1661
+ if (data.session) body.appendChild(el2(
1662
+ "div",
1663
+ { class: "fun-live" },
1664
+ el2("h3", { text: "正在逛 · " + data.session.placeName }),
1665
+ el2("div", { class: "fun-trip-sum", text: data.session.summary })
1666
+ ));
1667
+ else if (data.trips?.length) body.appendChild(el2(
1668
+ "div",
1669
+ { class: "fun-live" },
1670
+ el2("div", { class: "fun-meta", text: "最近一趟 · " + data.trips[0].day }),
1671
+ el2("h3", { text: data.trips[0].placeName }),
1672
+ el2("div", { class: "fun-trip-sum", text: data.trips[0].summary })
1673
+ ));
1674
+ const tabs = el2("nav", { class: "fun-tabs", "aria-label": "纪念册分类" });
1675
+ for (const [id, label2] of [["all", "全部行程"], ["kept", "珍藏"], ["wishes", "心愿"]]) tabs.appendChild(el2("button", {
1676
+ type: "button",
1677
+ "aria-pressed": String(bookTab === id),
1678
+ onclick: () => {
1679
+ bookTab = id;
1680
+ render(currentData);
1681
+ }
1682
+ }, label2));
848
1683
  body.appendChild(tabs);
849
- if (bookTab === 'wishes') { renderWishes(data); return; }
1684
+ if (bookTab === "wishes") {
1685
+ renderWishes(data);
1686
+ restoreFocus();
1687
+ return;
1688
+ }
850
1689
  if (!data.total && !(data.keepsakeCount > 0)) {
851
- body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
1690
+ body.appendChild(el2("div", { class: "fun-empty", text: "纪念册还是空的——她收一次摊,这里就有一趟。" }));
852
1691
  return;
853
1692
  }
854
- body.appendChild(el('div', { class: 'fun-stats' },
855
- stat(data.totalRecent ?? data.total, '近期行程'), stat(data.keepsakeCount ?? 0, '珍藏'),
856
- stat(data.visitedAreaCount, '处逛过'), stat(data.souvenirCount, '件纪念品'), stat(data.photoCount, '张照片')));
857
- if (data.mostVisited?.length) body.appendChild(el('details', { class: 'fun-wish-history' },
858
- el('summary', { text: '常去的' }), el('div', { class: 'fun-chips' }, data.mostVisited.slice(0, 8).map((m) => el('span', { class: 'fun-chip', text: `${m.name} ×${m.times}` })))));
859
- const trips = bookTab === 'kept' ? data.trips.filter((t) => t.kept) : data.trips;
860
- let previousDay = null;
861
- for (const t of trips) {
862
- if (t.day !== previousDay) { body.appendChild(el('div', { class: 'fun-date', text: t.day || '日期不详' })); previousDay = t.day; }
863
- const err = errors.get(t.id);
864
- const open = expandedTrips.has(t.id);
865
- const toggleKeep = async () => {
866
- if (pending.has(t.id)) return;
867
- pending.add(t.id); errors.delete(t.id); render(data);
868
- try {
869
- const result = await ctx.invoke('favorite', [{ id: t.id, keep: !t.kept }]);
870
- if (!result?.ok) throw new Error(result?.error ?? '珍藏状态保存失败');
871
- await load(true);
872
- } catch (error) { errors.set(t.id, error?.message ?? String(error)); }
873
- finally { pending.delete(t.id); render(currentData ?? data); }
1693
+ body.appendChild(el2(
1694
+ "div",
1695
+ { class: "fun-stats" },
1696
+ stat(data.totalRecent ?? data.total, "近期行程"),
1697
+ stat(data.keepsakeCount ?? 0, "珍藏"),
1698
+ stat(data.visitedAreaCount, "处逛过"),
1699
+ stat(data.souvenirCount, "件纪念品"),
1700
+ stat(data.photoCount, "张照片")
1701
+ ));
1702
+ if (data.mostVisited?.length) body.appendChild(el2(
1703
+ "details",
1704
+ { class: "fun-wish-history" },
1705
+ el2("summary", { text: "常去的" }),
1706
+ el2("div", { class: "fun-chips" }, data.mostVisited.slice(0, 8).map((m) => el2("span", { class: "fun-chip", text: `${m.name} ×${m.times}` })))
1707
+ ));
1708
+ const search = el2("input", { class: "fun-book-search", type: "search", placeholder: "搜地点、同行人、日期、备注或沿途回忆", value: bookKeyword, "aria-label": "搜索纪念册", "data-focus-key": "book-search" });
1709
+ const placeOptions = new Map((data.trips ?? []).map((trip) => [trip.placeId, trip.placeName]));
1710
+ const place = el2(
1711
+ "select",
1712
+ { class: "fun-book-place", "aria-label": "按地点筛选行程", "data-focus-key": "book-place" },
1713
+ el2("option", { value: "", text: "所有地点" }),
1714
+ [...placeOptions].map(([id, name]) => el2("option", { value: id, text: name }))
1715
+ );
1716
+ place.value = bookPlace;
1717
+ const days = [...new Set((data.trips ?? []).map((trip) => trip.day || "unknown"))];
1718
+ const date = el2(
1719
+ "select",
1720
+ { class: "fun-book-date", "aria-label": "按日期筛选行程", "data-focus-key": "book-date" },
1721
+ el2("option", { value: "", text: "所有日期" }),
1722
+ days.map((day) => el2("option", { value: day, text: day === "unknown" ? "日期不详" : day }))
1723
+ );
1724
+ date.value = bookDate;
1725
+ body.appendChild(el2("div", { class: "fun-album-filters" }, search, place, date));
1726
+ const results = el2("div", { class: "fun-book-results" });
1727
+ body.appendChild(results);
1728
+ const allTrips = data.trips ?? [];
1729
+ const textFor = (trip) => [
1730
+ trip.placeName,
1731
+ trip.company,
1732
+ trip.day,
1733
+ trip.note,
1734
+ trip.summary,
1735
+ ...(trip.visited ?? []).map((area) => typeof area === "string" ? area : area.area),
1736
+ ...trip.events ?? [],
1737
+ ...trip.souvenirs ?? [],
1738
+ ...trip.photos ?? [],
1739
+ ...(trip.choices ?? []).map((choice) => choice.event + " " + choice.result),
1740
+ ...(trip.timeline ?? []).map((entry) => entry.text)
1741
+ ].filter(Boolean).join(" ").toLowerCase();
1742
+ const renderResults = () => {
1743
+ results.replaceChildren();
1744
+ const keyword = bookKeyword.trim().toLowerCase();
1745
+ const trips = allTrips.filter((trip) => {
1746
+ if (bookTab === "kept" && !trip.kept) return false;
1747
+ if (bookPlace && trip.placeId !== bookPlace) return false;
1748
+ if (bookDate && (trip.day || "unknown") !== bookDate) return false;
1749
+ if (!keyword) return true;
1750
+ const route = (data.routes ?? []).find((group) => group.id === trip.routeId);
1751
+ const linked = route ? allTrips.filter((member) => (route.tripIds ?? []).includes(member.id)) : [];
1752
+ const linkedText = route ? [(route.stops ?? []).map((stop) => stop.placeName).join(" "), ...linked.map(textFor)].join(" ").toLowerCase() : "";
1753
+ return textFor(trip).includes(keyword) || linkedText.includes(keyword);
1754
+ });
1755
+ if (keyword || bookPlace || bookDate) results.appendChild(el2("div", { class: "fun-note", role: "status", text: "找到 " + trips.length + " 趟行程;联程同时检索相连的地点与记录。" }));
1756
+ const appendTrip = (trip, parent) => {
1757
+ const open = expandedTrips.has(trip.id);
1758
+ const toggleKeep = async () => {
1759
+ if (pending.has(trip.id)) return;
1760
+ pending.add(trip.id);
1761
+ errors.delete(trip.id);
1762
+ renderResults();
1763
+ try {
1764
+ const result = await ctx.invoke("favorite", [{ id: trip.id, keep: !trip.kept }]);
1765
+ if (!result?.ok) throw new Error(result?.error ?? "珍藏状态保存失败");
1766
+ await load(true);
1767
+ } catch (error) {
1768
+ errors.set(trip.id, error?.message ?? String(error));
1769
+ } finally {
1770
+ pending.delete(trip.id);
1771
+ render(currentData ?? data);
1772
+ }
1773
+ };
1774
+ const card = el2(
1775
+ "article",
1776
+ { class: "fun-trip fun-ticket", "data-trip-id": trip.id },
1777
+ el2(
1778
+ "div",
1779
+ { class: "fun-trip-head" },
1780
+ el2("span", { class: "fun-trip-name", text: trip.placeName }),
1781
+ el2("span", { class: "fun-trip-when", text: (trip.enteredHm || "时间不详") + "–" + (trip.leftHm || "时间不详") + (trip.stayedMin ? " · " + trip.stayedMin + " 分钟" : "") })
1782
+ ),
1783
+ el2("div", { class: "fun-trip-sum", text: trip.summary }),
1784
+ trip.routeOrder ? el2("div", { class: "fun-note", text: "联程 · 第 " + trip.routeOrder + " 站" }) : null,
1785
+ el2(
1786
+ "div",
1787
+ { class: "fun-trip-actions" },
1788
+ el2("button", { type: "button", class: "fun-detail-toggle", "data-trip-id": trip.id, "aria-expanded": String(open), onclick: () => {
1789
+ if (open) expandedTrips.delete(trip.id);
1790
+ else expandedTrips.add(trip.id);
1791
+ renderResults();
1792
+ [...results.querySelectorAll(".fun-detail-toggle")].find((button) => button.getAttribute("data-trip-id") === trip.id)?.focus?.();
1793
+ } }, open ? "收起详情" : "查看详情"),
1794
+ el2("button", { type: "button", disabled: pending.has(trip.id) ? "disabled" : null, onclick: toggleKeep }, pending.has(trip.id) ? "保存中…" : trip.kept ? "取消珍藏" : "珍藏"),
1795
+ errors.has(trip.id) ? el2("span", { class: "fun-trip-error", role: "alert", text: errors.get(trip.id) }) : null
1796
+ )
1797
+ );
1798
+ if (open) card.appendChild(tripDetails(trip));
1799
+ parent.appendChild(card);
874
1800
  };
875
- const card = el('article', { class: 'fun-trip fun-ticket' },
876
- el('div', { class: 'fun-trip-head' }, el('span', { class: 'fun-trip-name', text: t.placeName }),
877
- el('span', { class: 'fun-trip-when', text: t.enteredHm + '–' + t.leftHm + (t.stayedMin ? ' · ' + t.stayedMin + ' 分钟' : '') })),
878
- el('div', { class: 'fun-trip-sum', text: t.summary }),
879
- el('div', { class: 'fun-trip-actions' },
880
- el('button', { type: 'button', 'aria-expanded': String(open), onclick: () => {
881
- if (open) expandedTrips.delete(t.id); else expandedTrips.add(t.id);
1801
+ const drawnRoutes = /* @__PURE__ */ new Set();
1802
+ let previousDay = null;
1803
+ for (const trip of trips) {
1804
+ const route = trip.routeId && (data.routes ?? []).find((group) => group.id === trip.routeId);
1805
+ if (route) {
1806
+ if (drawnRoutes.has(route.id)) continue;
1807
+ drawnRoutes.add(route.id);
1808
+ const group = el2("section", { class: "fun-route-group", "data-route-id": route.id });
1809
+ group.appendChild(routeSummary(route, allTrips, (selected) => {
1810
+ expandedTrips.add(selected.id);
1811
+ bookKeyword = "";
1812
+ bookPlace = "";
1813
+ bookDate = "";
1814
+ bookTab = "all";
882
1815
  render(currentData);
883
- const focus = body.querySelectorAll('.fun-detail-toggle');
884
- [...focus].find((node) => node.getAttribute('data-trip-id') === t.id)?.focus();
885
- }, class: 'fun-detail-toggle', 'data-trip-id': t.id }, open ? '收起详情' : '查看详情'),
886
- el('button', { type: 'button', disabled: pending.has(t.id) ? 'disabled' : null, onclick: toggleKeep }, pending.has(t.id) ? '保存中…' : (t.kept ? '取消珍藏' : '珍藏')),
887
- err ? el('span', { class: 'fun-trip-error', role: 'alert', text: err }) : null));
888
- if (open) {
889
- const detail = el('section', { class: 'fun-trip-detail', 'aria-label': t.placeName + '行程详情' });
890
- const part = (title, values) => {
891
- if (!values.length) return;
892
- detail.appendChild(el('div', { class: 'fun-sec', text: title }));
893
- detail.appendChild(el('ul', { class: 'fun-list' }, values.map((text) => el('li', { text }))));
894
- };
895
- if (t.company) detail.appendChild(el('p', { text: '同行 · ' + t.company }));
896
- part('沿途逛过', t.visited ?? []);
897
- part('遇见的小事', t.events ?? []);
898
- part('当时的选择', (t.choices ?? []).map((c) => c.event + ' · ' + c.result));
899
- part('带回的纪念品', t.souvenirs ?? []);
900
- part('拍照记录', t.photos ?? []);
901
- part('吃喝记录', (t.ate ?? []).map((x) => x.verb + '了 ' + x.item));
902
- if (t.note) detail.appendChild(el('p', { text: '收摊备注 · ' + t.note }));
903
- if (t.scene) detail.appendChild(el('p', { class: 'fun-dim', text: '生图 scene:' + t.scene + (t.outfit ? ' · outfits:' + t.outfit : '') }));
904
- card.appendChild(detail);
1816
+ [...body.querySelectorAll(".fun-detail-toggle")].find((button) => button.getAttribute("data-trip-id") === selected.id)?.focus?.();
1817
+ }));
1818
+ const members = (route.tripIds ?? []).map((id) => trips.find((member) => member.id === id)).filter(Boolean);
1819
+ for (const member of members) {
1820
+ group.appendChild(el2("div", { class: "fun-date", text: member.day || "日期不详" }));
1821
+ appendTrip(member, group);
1822
+ }
1823
+ results.appendChild(group);
1824
+ previousDay = null;
1825
+ } else {
1826
+ if (trip.day !== previousDay) {
1827
+ results.appendChild(el2("div", { class: "fun-date", text: trip.day || "日期不详" }));
1828
+ previousDay = trip.day;
1829
+ }
1830
+ appendTrip(trip, results);
1831
+ }
905
1832
  }
906
- body.appendChild(card);
907
- }
908
- if (bookTab === 'kept' && !trips.length) body.appendChild(el('div', { class: 'fun-empty', text: '还没有珍藏的行程。' }));
1833
+ if (!trips.length) results.appendChild(el2("div", { class: "fun-empty", text: bookKeyword || bookPlace || bookDate ? "没有匹配的行程,试试其他地点、日期或搜索词。" : bookTab === "kept" ? "还没有珍藏的行程。" : "还没有可回看的行程。" }));
1834
+ };
1835
+ search.addEventListener("input", () => {
1836
+ bookKeyword = search.value;
1837
+ renderResults();
1838
+ });
1839
+ place.addEventListener("change", () => {
1840
+ bookPlace = place.value;
1841
+ renderResults();
1842
+ });
1843
+ date.addEventListener("change", () => {
1844
+ bookDate = date.value;
1845
+ renderResults();
1846
+ });
1847
+ renderResults();
1848
+ restoreFocus();
909
1849
  };
910
-
911
- const stat = (n, label) => el('div', { class: 'fun-stat' },
912
- el('b', { text: String(n) }), el('span', { text: label }));
913
-
1850
+ const stat = (n, label2) => el2(
1851
+ "div",
1852
+ { class: "fun-stat" },
1853
+ el2("b", { text: String(n) }),
1854
+ el2("span", { text: label2 })
1855
+ );
914
1856
  const load = async (propagate = false) => {
915
1857
  try {
916
- const data = await ctx.invoke('list');
917
- if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
1858
+ const data = await ctx.invoke("list");
1859
+ if (!data?.ok) throw new Error(data?.error ?? "返回不正常");
918
1860
  status.replaceChildren();
919
1861
  render(data);
920
1862
  } catch (err) {
@@ -923,86 +1865,99 @@ function mountBook(ctx) {
923
1865
  status.replaceChildren(errorCard(err, load, Boolean(currentData)));
924
1866
  }
925
1867
  };
926
-
927
1868
  void load();
928
1869
  return { refresh: load };
929
1870
  }
930
-
931
- /**
932
- * 纪念品架:跨趟归集的收藏 + 每处的集齐进度。
933
- *
934
- * 数据全部由服务端的 `shelf/list` 算好(`keepsakes.js` 是纯函数),
935
- * 这里只负责画。**不自己聚合、不自己算日期**——两边各算一遍必然会不一致。
936
- */
937
1871
  function mountShelf(ctx) {
938
1872
  const root = ctx.root;
939
1873
  root.replaceChildren();
940
1874
  const box = shell(root);
941
- const body = el('div');
1875
+ const body = el2("div");
942
1876
  box.appendChild(body);
943
- const status = feedback(box);
1877
+ const status = feedback2(box);
944
1878
  let currentData = null;
945
- body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在整理纪念品架…' }));
946
-
947
- const stat = (n, label) => el('div', { class: 'fun-stat' },
948
- el('b', { text: String(n) }), el('span', { text: label }));
949
-
1879
+ body.appendChild(el2("div", { class: "fun-loading", role: "status", text: "正在整理纪念品架…" }));
1880
+ const stat = (n, label2) => el2(
1881
+ "div",
1882
+ { class: "fun-stat" },
1883
+ el2("b", { text: String(n) }),
1884
+ el2("span", { text: label2 })
1885
+ );
950
1886
  const pct = (part) => `${part.done}/${part.total}`;
951
-
1887
+ const memoryTrip = tripLookup(ctx, "trip", "id", "回看这趟行程");
952
1888
  const render = (data) => {
953
1889
  currentData = data;
954
- body.replaceChildren(heading('纪念品架', '每一件小东西,都有带它回来的那一天。'));
1890
+ body.replaceChildren(heading("纪念品架", "每一件小东西,都有带它回来的那一天。"));
955
1891
  if (!data.total) {
956
- body.appendChild(el('div', { class: 'fun-empty', text: '架子上还什么都没有——她买过纪念品,这里就有了。' }));
1892
+ body.appendChild(el2("div", { class: "fun-empty", text: "架子上还什么都没有——她买过纪念品,这里就有了。" }));
957
1893
  }
958
-
959
- body.appendChild(el('div', { class: 'fun-stats' },
960
- stat(data.total, '样东西'),
961
- stat(data.pieces, '件'),
962
- stat(data.places, '处地方'),
963
- stat(data.completePlaces, '处逛遍')));
964
-
965
- body.appendChild(el('div', { class: 'fun-meta', text: '收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
966
-
967
- // 每一处的架子:只列真有东西的,空的不用占版面。
968
- if (data.byPlace.length) body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
1894
+ body.appendChild(el2(
1895
+ "div",
1896
+ { class: "fun-stats" },
1897
+ stat(data.total, "样东西"),
1898
+ stat(data.pieces, "件"),
1899
+ stat(data.places, "处地方"),
1900
+ stat(data.completePlaces, "处逛遍")
1901
+ ));
1902
+ body.appendChild(el2("div", { class: "fun-meta", text: "收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。" }));
1903
+ if (data.byPlace.length) body.appendChild(el2("div", { class: "fun-sec", text: "按地方归着" }));
969
1904
  for (const g of data.byPlace) {
970
- body.appendChild(el('div', { class: 'fun-trip' },
971
- el('div', { class: 'fun-trip-head' },
972
- el('span', { class: 'fun-trip-name', text: g.placeName }),
973
- el('span', { class: 'fun-trip-when', text: `${g.items.length} 样 · 最早 ${g.firstDay || '—'}` })),
974
- el('div', { class: 'fun-shelf-grid' }, g.items.map((it) => el('details', { class: 'fun-keepsake' },
975
- el('summary', null, el('strong', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''}` }),
976
- el('span', { class: 'fun-dim', text: `记录中最早 ${it.firstDay || '日期不详'}` })),
977
- it.archivedCount ? el('div', { class: 'fun-note', text: `${it.archivedCount} 次收藏仅保留账本,详细行程已不在近期记录中。` }) : null,
978
- ...(it.memories ?? []).map((m) => el('div', { class: 'fun-trip-sum' },
979
- el('div', { text: `${m.day || '日期不详'} · ${m.summary}` }),
980
- m.note ? el('div', { text: `你记的:${m.note}` }) : null)))))));
1905
+ body.appendChild(el2(
1906
+ "div",
1907
+ { class: "fun-trip" },
1908
+ el2(
1909
+ "div",
1910
+ { class: "fun-trip-head" },
1911
+ el2("span", { class: "fun-trip-name", text: g.placeName }),
1912
+ el2("span", { class: "fun-trip-when", text: `${g.items.length} 样 · 最早 ${g.firstDay || "—"}` })
1913
+ ),
1914
+ el2("div", { class: "fun-shelf-grid" }, g.items.map((it) => el2(
1915
+ "details",
1916
+ { class: "fun-keepsake" },
1917
+ el2(
1918
+ "summary",
1919
+ null,
1920
+ itemIcon(it.name),
1921
+ el2("strong", { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ""}` }),
1922
+ el2("span", { class: "fun-dim", text: `记录中最早 ${it.firstDay || "日期不详"}` })
1923
+ ),
1924
+ it.archivedCount ? el2("div", { class: "fun-note", text: `${it.archivedCount} 次收藏仅保留账本,详细行程已不在近期记录中。` }) : null,
1925
+ ...(it.memories ?? []).map((m) => el2(
1926
+ "div",
1927
+ { class: "fun-trip-sum" },
1928
+ el2("div", { text: `${m.day || "日期不详"} · ${m.summary}` }),
1929
+ m.note ? el2("div", { text: `你记的:${m.note}` }) : null,
1930
+ m.id ? memoryTrip(m.id) : null
1931
+ ))
1932
+ )))
1933
+ ));
981
1934
  }
982
-
983
- // 进度:只列去过的。服务端已按「快逛遍的」排好,这里照顺序画。
984
1935
  const visited = data.progress.filter((p) => p.visits > 0);
985
1936
  if (visited.length) {
986
- body.appendChild(el('div', { class: 'fun-sec', text: `逛过的 ${visited.length} 处` }));
1937
+ body.appendChild(el2("div", { class: "fun-sec", text: `逛过的 ${visited.length} 处` }));
987
1938
  for (const p of visited) {
988
1939
  const left = p.areas.left.length;
989
- body.appendChild(el('div', { class: 'fun-trip' },
990
- el('div', { class: 'fun-trip-head' },
991
- el('span', { class: 'fun-trip-name', text: p.placeName }),
992
- el('span', { class: 'fun-trip-when', text: `去过 ${p.visits} 次 · ${p.percent}%` })),
993
- el('progress', { class: 'fun-progress', max: '100', value: String(p.percent), 'aria-label': `${p.placeName}探索进度 ${p.percent}%` }),
994
- el('div', { class: 'fun-meta', text: `逛过 ${pct(p.areas)}${p.souvenirs.total ? ` · 纪念品 ${pct(p.souvenirs)}` : ''}${p.photos.total ? ` · 拍过 ${pct(p.photos)}` : ''}` }),
995
- left
996
- ? el('div', { class: 'fun-trip-sum', text: `还差:${p.areas.left.slice(0, 6).join('、')}${left > 6 ? ` 等 ${left} 处` : ''}` })
997
- : el('div', { class: 'fun-trip-sum', text: '这一处已经逛遍了。' })));
1940
+ body.appendChild(el2(
1941
+ "div",
1942
+ { class: "fun-trip" },
1943
+ el2(
1944
+ "div",
1945
+ { class: "fun-trip-head" },
1946
+ el2("span", { class: "fun-trip-name", text: p.placeName }),
1947
+ el2("span", { class: "fun-trip-when", text: `去过 ${p.visits} 次 · ${p.percent}%` })
1948
+ ),
1949
+ el2("progress", { class: "fun-progress", max: "100", value: String(p.percent), "aria-label": `${p.placeName}探索进度 ${p.percent}%` }),
1950
+ el2("div", { class: "fun-meta", text: `逛过 ${pct(p.areas)}${p.souvenirs.total ? ` · 纪念品 ${pct(p.souvenirs)}` : ""}${p.photos.total ? ` · 拍过 ${pct(p.photos)}` : ""}` }),
1951
+ p.phases?.length ? el2("div", { class: "fun-note fun-visited-phases", text: `去过的时段:${p.phases.join("、")}` }) : null,
1952
+ left ? el2("div", { class: "fun-trip-sum", text: `还差:${p.areas.left.slice(0, 6).join("、")}${left > 6 ? ` 等 ${left} 处` : ""}` }) : el2("div", { class: "fun-trip-sum", text: "这一处已经逛遍了。" })
1953
+ ));
998
1954
  }
999
1955
  }
1000
1956
  };
1001
-
1002
1957
  const load = async () => {
1003
1958
  try {
1004
- const data = await ctx.invoke('list');
1005
- if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
1959
+ const data = await ctx.invoke("list");
1960
+ if (!data?.ok) throw new Error(data?.error ?? "返回不正常");
1006
1961
  status.replaceChildren();
1007
1962
  render(data);
1008
1963
  } catch (err) {
@@ -1010,15 +1965,17 @@ function mountShelf(ctx) {
1010
1965
  status.replaceChildren(errorCard(err, load, Boolean(currentData)));
1011
1966
  }
1012
1967
  };
1013
-
1014
1968
  void load();
1015
1969
  return { refresh: load };
1016
1970
  }
1017
-
1018
- export default {
1971
+ var webui_default = {
1019
1972
  panels: {
1020
1973
  places: { mount: mountPlaces },
1021
1974
  book: { mount: mountBook },
1022
1975
  shelf: { mount: mountShelf },
1023
- },
1976
+ stories: { mount: mountStories }
1977
+ }
1978
+ };
1979
+ export {
1980
+ webui_default as default
1024
1981
  };