cortico-world-fun 0.1.6 → 0.2.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
@@ -12,9 +12,10 @@
12
12
  * 颜色走宿主主题的自定义属性(--surface/--foreground/--border/--accent…),
13
13
  * 自定义属性会继承进 shadow root,所以明暗两套主题都不用自己写。
14
14
  *
15
- * 两个面板:
15
+ * 三个面板:
16
16
  * places —— 二十处地方(以及自己加的、改过的)此刻的状态,以及她正在逛的这一趟
17
- * book —— 纪念册:去过的每一趟
17
+ * book —— 纪念册:去过的每一趟与出游心愿
18
+ * shelf —— 纪念品架:长期收藏与探索进度
18
19
  */
19
20
 
20
21
  const CSS = `
@@ -110,11 +111,54 @@ const CSS = `
110
111
  .fun-trip-when{font-size:11.5px;color:var(--f-dim);white-space:nowrap}
111
112
  .fun-trip-sum{margin-top:3px;font-size:12.5px}
112
113
  .fun-trip-extras{margin-top:5px;font-size:12px;color:var(--f-dim)}
114
+ .fun-trip-actions{display:flex;gap:8px;align-items:center;margin-top:7px}
115
+ .fun-trip-actions{display:flex;gap:6px;align-items:center;margin-top:7px}
116
+ .fun-trip-error{font-size:12px;color:#d9534f}
117
+ .fun-toggle[aria-pressed="true"]{border-color:var(--f-accent);background:color-mix(in srgb,var(--f-accent) 12%,var(--f-card))}
113
118
  .fun-stats{display:flex;gap:16px;flex-wrap:wrap;margin-bottom:12px;padding:9px 12px;border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);background:var(--f-card)}
114
119
  .fun-stat b{display:block;font-size:17px;font-weight:600;line-height:1.25}
115
120
  .fun-stat span{font-size:11.5px;color:var(--f-dim)}
116
121
  .fun-empty{padding:22px 12px;text-align:center;color:var(--f-dim);font-size:12.5px}
117
122
  .fun-err{border:1px solid #d9534f;border-radius:var(--radius-sm,6px);padding:10px 12px;color:#d9534f;background:color-mix(in srgb,#d9534f 10%,transparent);font-size:12.5px}
123
+ /* 轻手账:跟随宿主主题,只用少量色彩区分内容层次。 */
124
+ .fun{font-size:14px;line-height:1.65;padding:8px 4px 24px;--f-round:12px}
125
+ .fun button,.fun input,.fun select{min-height:34px}
126
+ .fun button:focus-visible,.fun input:focus-visible,.fun select:focus-visible,.fun textarea:focus-visible,.fun summary:focus-visible{outline:2px solid var(--f-accent);outline-offset:3px}
127
+ .fun button:disabled{cursor:default;opacity:.6}
128
+ .fun .fun-btn-primary{background:var(--f-accent);border-color:var(--f-accent);color:var(--accent-foreground,#fff)}
129
+ .fun-heading{margin-bottom:16px;padding:4px 0 12px;border-bottom:1px solid var(--f-line)}
130
+ .fun-heading h2{font-size:20px;line-height:1.4;margin:0 0 4px;letter-spacing:.03em}
131
+ .fun-heading p{margin:0;color:var(--f-dim);font-size:12.5px}
132
+ .fun-live,.fun-trip,.fun-stats,.fun-form{border-radius:var(--f-round);padding:14px 16px}
133
+ .fun-live{background:linear-gradient(120deg,color-mix(in srgb,var(--f-accent) 8%,var(--f-card)),var(--f-card));margin-bottom:16px}
134
+ .fun-live h3{font-size:16px}
135
+ .fun-grid{grid-template-columns:repeat(auto-fill,minmax(min(232px,100%),1fr));gap:12px}
136
+ .fun-card{padding:14px;border-radius:var(--f-round);min-height:136px;background:linear-gradient(180deg,color-mix(in srgb,var(--f-accent) 4%,var(--f-card)),var(--f-card) 65%)}
137
+ .fun-card-name{font-size:15px}.fun-card-head{flex-wrap:wrap}.fun-card-desc{line-height:1.7;margin-top:8px}
138
+ .fun-detail{padding:16px;border-radius:0 0 var(--f-round) var(--f-round)}
139
+ .fun-card-active{border-bottom-left-radius:0;border-bottom-right-radius:0;background:color-mix(in srgb,var(--f-accent) 7%,var(--f-card))}
140
+ .fun-tabs,.fun-filters{display:flex;gap:7px;flex-wrap:wrap;margin:12px 0 16px}
141
+ .fun-tabs button,.fun-filters button{border-radius:999px;padding:5px 13px;background:transparent}
142
+ .fun-tabs button[aria-pressed="true"],.fun-filters button[aria-pressed="true"]{border-color:var(--f-accent);color:var(--f-ink);background:color-mix(in srgb,var(--f-accent) 12%,var(--f-card));font-weight:600}
143
+ .fun-stats{gap:18px;background:var(--f-soft);border:none}.fun-stat b{font-size:21px}.fun-stat span{font-size:12px}
144
+ .fun-trip-head{flex-wrap:wrap}.fun-trip-name{font-size:14px}.fun-trip-when{white-space:normal}
145
+ .fun-date{margin:20px 0 10px;font-size:12px;color:var(--f-dim);font-weight:600;display:flex;align-items:center;gap:10px}
146
+ .fun-date:after{content:'';height:1px;background:var(--f-line);flex:1}
147
+ .fun-ticket{position:relative;border-left:3px solid color-mix(in srgb,var(--f-accent) 55%,var(--f-line));margin-bottom:12px}
148
+ .fun-trip-detail{border-top:1px dashed var(--f-line);margin-top:12px;padding-top:4px}
149
+ .fun-trip-detail .fun-sec{margin-top:10px}.fun-trip-detail p{margin:4px 0;font-size:13px;white-space:pre-wrap;overflow-wrap:anywhere}
150
+ .fun-wish-history{margin-top:14px}.fun-wish-history>summary{cursor:pointer;padding:8px 0;color:var(--f-dim)}
151
+ .fun-shelf-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(180px,100%),1fr));gap:10px;margin-top:12px}
152
+ .fun-keepsake{border:1px solid var(--f-line);border-radius:10px;padding:12px;background:var(--f-soft);min-width:0}
153
+ .fun-keepsake>summary{cursor:pointer;line-height:1.7;overflow-wrap:anywhere}.fun-keepsake>summary strong{display:block;color:var(--f-ink);font-weight:600}
154
+ .fun-keepsake .fun-trip-sum{border-top:1px dashed var(--f-line);margin-top:9px;padding-top:9px}
155
+ .fun-progress{display:block;width:100%;height:7px;margin:10px 0;accent-color:var(--f-accent);border:0;border-radius:8px;overflow:hidden;background:var(--f-line)}
156
+ .fun-progress::-webkit-progress-bar{background:var(--f-line);border-radius:8px}.fun-progress::-webkit-progress-value{background:var(--f-accent);border-radius:8px}.fun-progress::-moz-progress-bar{background:var(--f-accent);border-radius:8px}
157
+ .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
+ .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
+ @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}}
161
+
118
162
  `;
119
163
 
120
164
  /** 小工具:建元素 + 设属性,省掉一屏 createElement。 */
@@ -153,8 +197,20 @@ function shell(root) {
153
197
  return box;
154
198
  }
155
199
 
156
- function errorCard(err) {
157
- return el('div', { class: 'fun-err', text: `面板加载失败:${err?.message ?? String(err)}` });
200
+ 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);
204
+ }
205
+
206
+ function heading(title, subtitle) {
207
+ return el('header', { class: 'fun-heading' }, el('h2', { text: title }), el('p', { text: subtitle }));
208
+ }
209
+
210
+ function feedback(box) {
211
+ const node = el('div', { class: 'fun-feedback' });
212
+ box.appendChild(node);
213
+ return node;
158
214
  }
159
215
 
160
216
  // ---------------------------------------------------------------------------
@@ -169,12 +225,15 @@ function mountPlaces(ctx) {
169
225
  box.appendChild(body);
170
226
 
171
227
  let keyword = '';
228
+ let quickFilter = '全部';
172
229
  let expanded = null;
173
230
  /** null = 没在编辑;{ mode: 'new' | 'edit', venue } = 打开表单。 */
174
231
  let editing = null;
175
232
  let formError = '';
176
233
  /** 表单打开期间收到的最新数据,等关掉表单再补画,免得把用户填的内容冲掉。 */
177
234
  let currentData = null;
235
+ const status = feedback(box);
236
+ body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在看看有哪些地方开着…' }));
178
237
 
179
238
  const render = (data) => {
180
239
  // 表单相关声明要放在最前:点「添加地点」时 render 会重跑,
@@ -184,7 +243,8 @@ function mountPlaces(ctx) {
184
243
  const fields = {};
185
244
  const lines = (v) => (Array.isArray(v) ? v.join('\n') : '');
186
245
  const parseLines = (s) => String(s ?? '').split(/[\n,,、]/).map((x) => x.trim()).filter(Boolean);
187
- body.replaceChildren();
246
+ currentData = data;
247
+ body.replaceChildren(heading('去哪儿', '挑一处喜欢的地方,慢慢逛。'));
188
248
 
189
249
  // ---- 正在逛的那一趟 ----
190
250
  if (data.session) {
@@ -230,7 +290,6 @@ function mountPlaces(ctx) {
230
290
  renderList();
231
291
  });
232
292
  const addBtn = el('button', {
233
- class: 'fun-btn-primary',
234
293
  type: 'button',
235
294
  onclick: () => {
236
295
  editing = { mode: 'new', venue: null };
@@ -254,7 +313,6 @@ function mountPlaces(ctx) {
254
313
  // 一键恢复全部预设:只在真有覆盖层时给,免得平时多一个没用的按钮。
255
314
  if (data.overriddenCount) {
256
315
  body.appendChild(el('button', {
257
- class: 'fun-btn-primary',
258
316
  type: 'button',
259
317
  style: { marginBottom: '10px' },
260
318
  onclick: async () => {
@@ -273,6 +331,18 @@ function mountPlaces(ctx) {
273
331
  // ---- 编辑表单(打开时在最上面) ----
274
332
  if (editing) body.appendChild(venueForm());
275
333
 
334
+ const filterBar = el('div', { class: 'fun-filters', role: 'group', 'aria-label': '地点快捷筛选' });
335
+ 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));
340
+ renderList();
341
+ } }, label);
342
+ filterButtons.push({ label, button });
343
+ filterBar.appendChild(button);
344
+ }
345
+ body.appendChild(filterBar);
276
346
  const listBox = el('div');
277
347
  body.appendChild(listBox);
278
348
 
@@ -285,11 +355,20 @@ function mountPlaces(ctx) {
285
355
  function renderList() {
286
356
  listBox.replaceChildren();
287
357
  const kw = keyword.trim().toLowerCase();
358
+ const filtered = data.places.filter((p) => {
359
+ 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));
365
+ return true;
366
+ });
288
367
  const matched = kw
289
- ? data.places.filter((p) => p.name.toLowerCase().includes(kw)
368
+ ? filtered.filter((p) => p.name.toLowerCase().includes(kw)
290
369
  || p.aliases.some((a) => a.toLowerCase().includes(kw))
291
370
  || p.tags.some((t) => t.toLowerCase().includes(kw)))
292
- : data.places;
371
+ : filtered;
293
372
 
294
373
  const open = matched.filter((p) => p.state !== 'closed');
295
374
  const closed = matched.filter((p) => p.state === 'closed');
@@ -308,10 +387,10 @@ function mountPlaces(ctx) {
308
387
  listBox.appendChild(el('div', { class: 'fun-sec', text: title }));
309
388
  listBox.appendChild(el('div', { class: 'fun-grid' }, items.map(cell)));
310
389
  };
311
- section(kw ? `匹配到 ${matched.length} 处` : `开着的(${open.length})`, open);
390
+ section(kw || quickFilter !== '全部' ? `筛选结果 · 开着的(${open.length})` : `开着的(${open.length})`, open);
312
391
  section('已经关了', closed);
313
392
  if (!matched.length) {
314
- listBox.appendChild(el('div', { class: 'fun-empty', text: `没有匹配「${keyword}」的地方。` }));
393
+ listBox.appendChild(el('div', { class: 'fun-empty', text: kw ? `没有匹配「${keyword}」的地方,试试其他筛选。` : '这个筛选下还没有地方,换一项看看。' }));
315
394
  }
316
395
  }
317
396
 
@@ -371,7 +450,7 @@ function mountPlaces(ctx) {
371
450
  const target = active?.parentNode ?? active;
372
451
  // 真 DOM 有 scrollIntoView;测试桩没有,判一下再用。
373
452
  if (target && typeof target.scrollIntoView === 'function') {
374
- target.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
453
+ target.scrollIntoView({ block: 'nearest', behavior: 'auto' });
375
454
  }
376
455
  }
377
456
  }
@@ -447,12 +526,19 @@ function mountPlaces(ctx) {
447
526
  const v = editing.venue ?? {};
448
527
  // 预设编辑:改的是覆盖层,不删场所;没改过的字段仍跟着预设升级走。
449
528
  const isPreset = Boolean(v.id) && !v.userVenue;
529
+ const phases = isPreset && Array.isArray(v.phases) ? v.phases : [];
530
+ const descPhases = phases.filter((ph) => ph.overridesDesc);
531
+ 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
+ : '';
450
536
  const verb = v.food?.verb ?? 'none';
451
537
  const foodItems = v.food?.items ?? [];
452
538
  const errorNode = el('div', { class: 'fun-form-error', text: formError });
453
539
 
454
540
  const field = (label, key, opts = {}) => {
455
- const { type = 'text', value = '', hint = '', multiline = false, options = null, rows = '3' } = opts;
541
+ const { type = 'text', value = '', hint = '', note = '', multiline = false, options = null, rows = '3' } = opts;
456
542
  let input;
457
543
  if (options) {
458
544
  input = el('select', {});
@@ -467,7 +553,8 @@ function mountPlaces(ctx) {
467
553
  }
468
554
  fields[key] = input;
469
555
  return el('label', { class: 'fun-field' },
470
- el('span', { class: 'fun-field-label', text: label }), input);
556
+ el('span', { class: 'fun-field-label', text: label }), input,
557
+ note ? el('span', { class: 'fun-field-scope fun-note', text: note }) : null);
471
558
  };
472
559
 
473
560
  const save = async () => {
@@ -536,6 +623,12 @@ function mountPlaces(ctx) {
536
623
  return el('div', { class: 'fun-form' },
537
624
  el('div', { class: 'fun-form-title', text: title }),
538
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,
539
632
  errorNode,
540
633
  el('div', { class: 'fun-form-grid' },
541
634
  field('名字 *', 'name', { value: v.name ?? '', hint: '例如「巷子里的旧书店」' }),
@@ -554,8 +647,8 @@ function mountPlaces(ctx) {
554
647
  })),
555
648
  // 预设可能带时段:面板的 desc 是「此刻那段」,编辑要用通用那段(descAll),
556
649
  // 否则编辑一次会把某一段的描写写进覆盖层,别的时段全变成那一段。
557
- field('这处是什么样子', 'desc', { value: v.descAll ?? v.desc ?? '', hint: '只写空间与陈设,别写她在干什么', multiline: true, rows: '3' }),
558
- field('能逛的 *', 'areas', { value: lines(v.allAreas ?? v.areas), hint: '一行一处,至少一处', multiline: true, rows: '4' }),
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' }),
559
652
  field('纪念品', 'souvenirs', { value: lines(v.souvenirs), hint: '一行一样', multiline: true, rows: '2' }),
560
653
  field('拍照点', 'photoSpots', { value: lines(v.photoSpots), hint: '一行一处', multiline: true, rows: '2' }),
561
654
  field('能吃能喝的品类', 'foodItems', { value: lines(foodItems), hint: '品类名,一行一样;别写味道', multiline: true, rows: '2' }),
@@ -585,12 +678,11 @@ function mountPlaces(ctx) {
585
678
  if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
586
679
  // 正在填表单时别重画——一分钟的自动刷新会把用户刚填的一整页冲掉。
587
680
  if (editing) { currentData = data; return; }
681
+ status.replaceChildren();
588
682
  render(data);
589
683
  } catch (err) {
590
- root.replaceChildren();
591
- ensureStyle(root);
592
- const box2 = shell(root);
593
- box2.appendChild(errorCard(err));
684
+ if (!currentData) body.replaceChildren();
685
+ status.replaceChildren(errorCard(err, load, Boolean(currentData)));
594
686
  }
595
687
  };
596
688
 
@@ -610,60 +702,225 @@ function mountBook(ctx) {
610
702
  const box = shell(root);
611
703
  const body = el('div');
612
704
  box.appendChild(body);
705
+ let bookTab = 'all';
706
+ 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();
712
+ 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: '带回纪念品' };
613
717
 
614
- const render = (data) => {
615
- body.replaceChildren();
616
- if (!data.total && !data.session) {
617
- body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
618
- return;
718
+ const renderWishes = (data) => {
719
+ const places = data.places ?? [];
720
+ 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);
728
+ 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 })));
732
+ input.value = value;
733
+ return input;
734
+ };
735
+ 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);
744
+ targetInput.disabled = adding || !targets.length;
745
+ const reasonInput = el('input', { class: 'fun-wish-reason', type: 'text', placeholder: '可选,记下为什么想去', disabled: adding ? 'disabled' : null });
746
+ reasonInput.value = wishDraft.reason;
747
+ placeInput.addEventListener('change', () => {
748
+ wishDraft.placeId = placeInput.value;
749
+ wishDraft.target = '';
750
+ wishErrors.delete('add');
751
+ render(currentData);
752
+ });
753
+ typeInput.addEventListener('change', () => {
754
+ wishDraft.type = typeInput.value;
755
+ wishDraft.target = '';
756
+ wishErrors.delete('add');
757
+ render(currentData);
758
+ });
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') ?? '' });
762
+ 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() };
767
+ 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);
774
+ errorNode.textContent = message;
775
+ return;
776
+ }
777
+ wishDraft = { placeId: payload.placeId, type: payload.type, target: payload.target, reason: reasonInput.value };
778
+ await changeWish('add', payload, data);
779
+ };
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})` }));
790
+ for (const wish of wishes) {
791
+ const key = `wish:${wish.id}`;
792
+ const busy = wishPending.has(key);
793
+ 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) }, '取消'));
800
+ }
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));
619
809
  }
810
+ if (wishes.some((w) => w.status !== 'active')) section.appendChild(history);
811
+ body.appendChild(section);
812
+ };
620
813
 
621
- body.appendChild(el('div', { class: 'fun-stats' },
622
- stat(data.total, '趟'),
623
- stat(data.visitedAreaCount, '处逛过'),
624
- stat(data.souvenirCount, '件纪念品'),
625
- stat(data.photoCount, '张照片')));
626
-
627
- if (data.mostVisited.length) {
628
- body.appendChild(el('div', { class: 'fun-sec', text: '常去的' }));
629
- body.appendChild(el('div', { class: 'fun-chips' },
630
- data.mostVisited.slice(0, 8).map((m) => el('span', { class: 'fun-chip', text: `${m.name} ×${m.times}` }))));
814
+ const changeWish = async (key, payload, data) => {
815
+ if (wishPending.has(key)) return;
816
+ wishPending.add(key);
817
+ wishErrors.delete(key);
818
+ render(currentData ?? data);
819
+ let saved = false;
820
+ try {
821
+ const result = await ctx.invoke('wish', [payload]);
822
+ if (!result?.ok) throw new Error(result?.error ?? '心愿保存失败');
823
+ saved = true;
824
+ if (key === 'add') { wishDraft = { placeId: '', type: '', target: '', reason: '' }; wishFormOpen = false; }
825
+ await load(true);
826
+ } catch (error) {
827
+ wishErrors.set(key, `${saved ? '已保存,但列表刷新失败:' : ''}${error?.message ?? String(error)}`);
828
+ if (key === 'add') wishFormOpen = true;
829
+ } finally {
830
+ wishPending.delete(key);
831
+ render(currentData ?? data);
631
832
  }
833
+ };
632
834
 
633
- if (data.session) {
634
- body.appendChild(el('div', { class: 'fun-sec', text: '正在逛' }));
635
- body.appendChild(el('div', { class: 'fun-trip' },
636
- el('div', { class: 'fun-trip-sum', text: data.session.summary })));
637
- }
835
+ const render = (data) => {
836
+ 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 })));
638
843
 
639
- body.appendChild(el('div', { class: 'fun-sec', text: `去过的 ${data.total} 趟` }));
640
- for (const t of data.trips) {
641
- body.appendChild(el('div', { class: 'fun-trip' },
642
- el('div', { class: 'fun-trip-head' },
643
- el('span', { class: 'fun-trip-name', text: t.placeName }),
644
- el('span', { class: 'fun-trip-when', text: `${t.day} ${t.enteredHm}–${t.leftHm}${t.stayedMin ? ` · ${t.stayedMin} 分钟` : ''}` })),
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));
848
+ body.appendChild(tabs);
849
+ if (bookTab === 'wishes') { renderWishes(data); return; }
850
+ if (!data.total && !(data.keepsakeCount > 0)) {
851
+ body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
852
+ return;
853
+ }
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); }
874
+ };
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 + ' 分钟' : '') })),
645
878
  el('div', { class: 'fun-trip-sum', text: t.summary }),
646
- (t.events.length || t.scene)
647
- ? el('div', { class: 'fun-trip-extras' },
648
- t.events.length ? el('div', { text: t.events.slice(0, 2).join(' / ') }) : null,
649
- t.scene ? el('div', { text: `生图 scene:${t.scene}${t.outfit ? ` · outfits:${t.outfit}` : ''}` }) : null)
650
- : null));
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);
882
+ 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);
905
+ }
906
+ body.appendChild(card);
651
907
  }
908
+ if (bookTab === 'kept' && !trips.length) body.appendChild(el('div', { class: 'fun-empty', text: '还没有珍藏的行程。' }));
652
909
  };
653
910
 
654
911
  const stat = (n, label) => el('div', { class: 'fun-stat' },
655
912
  el('b', { text: String(n) }), el('span', { text: label }));
656
913
 
657
- const load = async () => {
914
+ const load = async (propagate = false) => {
658
915
  try {
659
916
  const data = await ctx.invoke('list');
660
917
  if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
918
+ status.replaceChildren();
661
919
  render(data);
662
920
  } catch (err) {
663
- root.replaceChildren();
664
- ensureStyle(root);
665
- const box2 = shell(root);
666
- box2.appendChild(errorCard(err));
921
+ if (propagate) throw err;
922
+ if (!currentData) body.replaceChildren();
923
+ status.replaceChildren(errorCard(err, load, Boolean(currentData)));
667
924
  }
668
925
  };
669
926
 
@@ -683,6 +940,9 @@ function mountShelf(ctx) {
683
940
  const box = shell(root);
684
941
  const body = el('div');
685
942
  box.appendChild(body);
943
+ const status = feedback(box);
944
+ let currentData = null;
945
+ body.appendChild(el('div', { class: 'fun-loading', role: 'status', text: '正在整理纪念品架…' }));
686
946
 
687
947
  const stat = (n, label) => el('div', { class: 'fun-stat' },
688
948
  el('b', { text: String(n) }), el('span', { text: label }));
@@ -690,10 +950,10 @@ function mountShelf(ctx) {
690
950
  const pct = (part) => `${part.done}/${part.total}`;
691
951
 
692
952
  const render = (data) => {
693
- body.replaceChildren();
953
+ currentData = data;
954
+ body.replaceChildren(heading('纪念品架', '每一件小东西,都有带它回来的那一天。'));
694
955
  if (!data.total) {
695
956
  body.appendChild(el('div', { class: 'fun-empty', text: '架子上还什么都没有——她买过纪念品,这里就有了。' }));
696
- return;
697
957
  }
698
958
 
699
959
  body.appendChild(el('div', { class: 'fun-stats' },
@@ -702,20 +962,22 @@ function mountShelf(ctx) {
702
962
  stat(data.places, '处地方'),
703
963
  stat(data.completePlaces, '处逛遍')));
704
964
 
705
- body.appendChild(el('div', { class: 'fun-meta', text: '来自纪念册保留的最近 40 趟;展开物品可看对应行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
965
+ body.appendChild(el('div', { class: 'fun-meta', text: '收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
706
966
 
707
967
  // 每一处的架子:只列真有东西的,空的不用占版面。
708
- body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
968
+ if (data.byPlace.length) body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
709
969
  for (const g of data.byPlace) {
710
970
  body.appendChild(el('div', { class: 'fun-trip' },
711
971
  el('div', { class: 'fun-trip-head' },
712
972
  el('span', { class: 'fun-trip-name', text: g.placeName }),
713
973
  el('span', { class: 'fun-trip-when', text: `${g.items.length} 样 · 最早 ${g.firstDay || '—'}` })),
714
- ...g.items.map((it) => el('details', { class: 'fun-meta' },
715
- el('summary', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''} · 记录中最早 ${it.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,
716
978
  ...(it.memories ?? []).map((m) => el('div', { class: 'fun-trip-sum' },
717
979
  el('div', { text: `${m.day || '日期不详'} · ${m.summary}` }),
718
- m.note ? el('div', { text: `你记的:${m.note}` }) : null))))));
980
+ m.note ? el('div', { text: `你记的:${m.note}` }) : null)))))));
719
981
  }
720
982
 
721
983
  // 进度:只列去过的。服务端已按「快逛遍的」排好,这里照顺序画。
@@ -728,6 +990,7 @@ function mountShelf(ctx) {
728
990
  el('div', { class: 'fun-trip-head' },
729
991
  el('span', { class: 'fun-trip-name', text: p.placeName }),
730
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}%` }),
731
994
  el('div', { class: 'fun-meta', text: `逛过 ${pct(p.areas)}${p.souvenirs.total ? ` · 纪念品 ${pct(p.souvenirs)}` : ''}${p.photos.total ? ` · 拍过 ${pct(p.photos)}` : ''}` }),
732
995
  left
733
996
  ? el('div', { class: 'fun-trip-sum', text: `还差:${p.areas.left.slice(0, 6).join('、')}${left > 6 ? ` 等 ${left} 处` : ''}` })
@@ -740,12 +1003,11 @@ function mountShelf(ctx) {
740
1003
  try {
741
1004
  const data = await ctx.invoke('list');
742
1005
  if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
1006
+ status.replaceChildren();
743
1007
  render(data);
744
1008
  } catch (err) {
745
- root.replaceChildren();
746
- ensureStyle(root);
747
- const box2 = shell(root);
748
- box2.appendChild(errorCard(err));
1009
+ if (!currentData) body.replaceChildren();
1010
+ status.replaceChildren(errorCard(err, load, Boolean(currentData)));
749
1011
  }
750
1012
  };
751
1013
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-fun",
3
- "version": "0.1.6",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "娱乐时间 —— 给 Coopanion 桌宠二十处真能去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山、咖啡店、奶茶店、餐厅、图书馆、夜市、澡堂、旧货市场、江边。进门、逛摊位、买纪念品、拍张照、吃喝点什么,收摊记一笔。能和「鱼的每一天」「生图工作室」联动,但都不依赖。",
6
6
  "license": "MIT",
@@ -39,13 +39,13 @@
39
39
  "PUBLISHING.md"
40
40
  ],
41
41
  "scripts": {
42
- "test": "node test/venues.test.mjs && node test/state.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/keepsakes.test.mjs && node test/user-venues.test.mjs && node test/world.test.mjs && node test/panels.test.mjs",
42
+ "test": "node test/venues.test.mjs && node test/state.test.mjs && node test/events.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/keepsakes.test.mjs && node test/user-venues.test.mjs && node test/aquarium.test.mjs && node test/wishes.test.mjs && node test/choices.test.mjs && node test/world.test.mjs && node test/panels.test.mjs",
43
43
  "verify": "node tools/fix-ps1-bom.mjs install.ps1 && node tools/check-prompt.mjs && node tools/check-isolation.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check",
44
44
  "describe": "node tools/make-describe.mjs",
45
45
  "check:publish": "node tools/publish-check.mjs --online",
46
46
  "check:isolation": "node tools/check-isolation.mjs",
47
47
  "verify:published": "node tools/verify-published.mjs",
48
- "prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/keepsakes.test.mjs && node test/user-venues.test.mjs && node test/world.test.mjs && node test/panels.test.mjs && node tools/check-prompt.mjs && node tools/check-isolation.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
48
+ "prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/events.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/keepsakes.test.mjs && node test/user-venues.test.mjs && node test/aquarium.test.mjs && node test/wishes.test.mjs && node test/choices.test.mjs && node test/world.test.mjs && node test/panels.test.mjs && node tools/check-prompt.mjs && node tools/check-isolation.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
49
49
  },
50
50
  "cortico": {
51
51
  "kind": "world",