cortico-world-fun 0.1.0 → 0.1.4

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 ADDED
@@ -0,0 +1,442 @@
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
+ */
19
+
20
+ const CSS = `
21
+ .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}
22
+ .fun *{box-sizing:border-box}
23
+ .fun-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px}
24
+ .fun input,.fun select,.fun button{font:inherit;color:inherit;background:var(--f-card);border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:5px 9px;outline:none}
25
+ .fun input:focus,.fun select:focus{border-color:var(--f-accent)}
26
+ .fun-search{flex:1;min-width:140px}
27
+ .fun button{cursor:pointer;transition:background .12s,border-color .12s}
28
+ .fun button:hover{border-color:var(--f-accent)}
29
+ .fun-btn-primary{background:var(--f-accent);border-color:var(--f-accent);color:#fff;font-weight:600}
30
+ .fun-btn-primary:hover{filter:brightness(1.06)}
31
+ .fun-btn-primary[disabled]{opacity:.55;cursor:default;filter:none}
32
+ .fun-dim{color:var(--f-dim)}
33
+ .fun-sec{font-weight:600;margin:14px 0 7px;font-size:12px;letter-spacing:.04em;color:var(--f-dim);text-transform:none}
34
+ .fun-sec:first-child{margin-top:2px}
35
+
36
+ /* 正在逛的那一趟 */
37
+ .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)}
38
+ .fun-live-idle{border-left-color:var(--f-line)}
39
+ .fun-live h3{margin:0 0 3px;font-size:14px;font-weight:600}
40
+ .fun-live .fun-meta{font-size:12px;color:var(--f-dim);margin-bottom:6px}
41
+ .fun-chips{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
42
+ .fun-chip{font-size:12px;padding:2px 8px;border-radius:999px;border:1px solid var(--f-line);background:var(--f-soft);color:var(--f-dim)}
43
+ .fun-chip-on{color:var(--f-ink);border-color:var(--f-accent);background:color-mix(in srgb,var(--f-accent) 14%,transparent)}
44
+ .fun-chip-ate{color:var(--f-ink);border-color:var(--f-warm);background:color-mix(in srgb,var(--f-warm) 14%,transparent)}
45
+ .fun-note{font-size:11.5px;color:var(--f-dim);margin-top:5px;line-height:1.5}
46
+ .fun-stale{color:var(--f-warm)}
47
+
48
+ /* 场所卡 */
49
+ .fun-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(232px,1fr));gap:9px;align-items:start}
50
+ .fun-cell{display:flex;flex-direction:column;gap:0;min-width:0}
51
+ /* 展开的那一格跨满整行:详情太窄会被挤成一条,读起来比原来更难受。 */
52
+ .fun-cell-open{grid-column:1/-1}
53
+ .fun-card{border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:9px 11px;background:var(--f-card);cursor:pointer;transition:border-color .12s,background .12s}
54
+ .fun-card:hover{border-color:var(--f-accent)}
55
+ .fun-card:focus-visible{outline:2px solid var(--f-accent);outline-offset:2px}
56
+ .fun-card-closed{opacity:.62}
57
+ .fun-card-open{border-left:3px solid var(--f-mint)}
58
+ .fun-card-soon{border-left:3px solid var(--f-warm)}
59
+ .fun-card-active{border-color:var(--f-accent);border-left-color:var(--f-accent);background:color-mix(in srgb,var(--f-accent) 7%,var(--f-card));border-bottom-left-radius:0;border-bottom-right-radius:0}
60
+ .fun-card-active .fun-card-desc{-webkit-line-clamp:2}
61
+ .fun-card-head{display:flex;justify-content:space-between;gap:8px;align-items:baseline}
62
+ .fun-card-name{font-weight:600;font-size:13.5px}
63
+ .fun-card-state{font-size:11.5px;color:var(--f-dim);white-space:nowrap;margin-left:auto}
64
+ .fun-card-state-open{color:var(--f-mint)}
65
+ .fun-card-state-soon{color:var(--f-warm)}
66
+ .fun-card-arrow{font-size:11px;color:var(--f-dim);width:11px;text-align:center;flex:none}
67
+ .fun-card-active .fun-card-arrow{color:var(--f-accent)}
68
+ .fun-card-desc{font-size:12px;color:var(--f-dim);margin-top:4px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
69
+ .fun-card-foot{display:flex;gap:6px;flex-wrap:wrap;margin-top:7px;font-size:11.5px;color:var(--f-dim)}
70
+
71
+ /* 详情:紧贴它那张卡、占满整行(不再跑到列表末尾) */
72
+ .fun-detail{border:1px solid var(--f-accent);border-top:none;border-radius:0 0 var(--radius-sm,6px) var(--radius-sm,6px);padding:10px 13px 11px;background:var(--f-card)}
73
+ .fun-detail-top{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:5px}
74
+ .fun-detail h4{margin:0;font-size:14px}
75
+ .fun-detail-close{font-size:11.5px;padding:2px 8px;cursor:pointer;background:transparent;border:1px solid var(--f-line);border-radius:999px;color:var(--f-dim)}
76
+ .fun-detail-close:hover{border-color:var(--f-accent);color:var(--f-ink)}
77
+ .fun-detail p{margin:0 0 6px;font-size:12.5px}
78
+ .fun-detail-cols{display:grid;grid-template-columns:minmax(150px,1fr) minmax(150px,1.2fr);gap:14px;align-items:start}
79
+ .fun-detail-col{min-width:0}
80
+ .fun-detail-cols .fun-sec{margin-top:0}
81
+ @media (max-width:560px){.fun-detail-cols{grid-template-columns:1fr;gap:6px}}
82
+ .fun-list{margin:5px 0 0;padding-left:17px;font-size:12.5px}
83
+ .fun-list li{margin:2px 0}
84
+ .fun-scene{font-size:12px;padding:5px 9px;border-radius:var(--radius-sm,6px);background:var(--f-soft);border:1px solid var(--f-line);margin-top:8px}
85
+ .fun-scene b{font-weight:600}
86
+
87
+ /* 纪念册 */
88
+ .fun-trip{border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:9px 12px;margin-bottom:8px;background:var(--f-card)}
89
+ .fun-trip-head{display:flex;justify-content:space-between;gap:10px;align-items:baseline}
90
+ .fun-trip-name{font-weight:600}
91
+ .fun-trip-when{font-size:11.5px;color:var(--f-dim);white-space:nowrap}
92
+ .fun-trip-sum{margin-top:3px;font-size:12.5px}
93
+ .fun-trip-extras{margin-top:5px;font-size:12px;color:var(--f-dim)}
94
+ .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)}
95
+ .fun-stat b{display:block;font-size:17px;font-weight:600;line-height:1.25}
96
+ .fun-stat span{font-size:11.5px;color:var(--f-dim)}
97
+ .fun-empty{padding:22px 12px;text-align:center;color:var(--f-dim);font-size:12.5px}
98
+ .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}
99
+ `;
100
+
101
+ /** 小工具:建元素 + 设属性,省掉一屏 createElement。 */
102
+ function el(tag, props, ...kids) {
103
+ const n = document.createElement(tag);
104
+ if (props) {
105
+ for (const [k, v] of Object.entries(props)) {
106
+ if (v === null || v === undefined || v === false) continue;
107
+ if (k === 'class') n.className = v;
108
+ else if (k === 'text') n.textContent = v;
109
+ else if (k === 'html') n.innerHTML = v;
110
+ else if (k.startsWith('on') && typeof v === 'function') n.addEventListener(k.slice(2), v);
111
+ else if (k === 'style') Object.assign(n.style, v);
112
+ else n.setAttribute(k, v);
113
+ }
114
+ }
115
+ for (const kid of kids.flat()) {
116
+ if (kid === null || kid === undefined || kid === false) continue;
117
+ n.appendChild(typeof kid === 'string' || typeof kid === 'number'
118
+ ? document.createTextNode(String(kid)) : kid);
119
+ }
120
+ return n;
121
+ }
122
+
123
+ /** 只注入一次样式(同一 root 反复 mount 时别叠 <style>)。 */
124
+ function ensureStyle(root) {
125
+ if (root.querySelector('style.fun-style')) return;
126
+ root.appendChild(el('style', { class: 'fun-style', text: CSS }));
127
+ }
128
+
129
+ /** 顶层容器。 */
130
+ function shell(root) {
131
+ ensureStyle(root);
132
+ const box = el('div', { class: 'fun' });
133
+ root.appendChild(box);
134
+ return box;
135
+ }
136
+
137
+ function errorCard(err) {
138
+ return el('div', { class: 'fun-err', text: `面板加载失败:${err?.message ?? String(err)}` });
139
+ }
140
+
141
+ // ---------------------------------------------------------------------------
142
+ // places —— 去哪儿
143
+ // ---------------------------------------------------------------------------
144
+
145
+ function mountPlaces(ctx) {
146
+ const root = ctx.root;
147
+ root.replaceChildren();
148
+ const box = shell(root);
149
+ const body = el('div');
150
+ box.appendChild(body);
151
+
152
+ let keyword = '';
153
+ let expanded = null;
154
+
155
+ const render = (data) => {
156
+ body.replaceChildren();
157
+
158
+ // ---- 正在逛的那一趟 ----
159
+ if (data.session) {
160
+ const s = data.session;
161
+ const venue = data.places.find((p) => p.id === s.placeId);
162
+ const leftAreas = venue
163
+ ? venue.areas.filter((a) => !s.visited.some((v) => v.area === a))
164
+ : [];
165
+ const leftText = leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '都逛过了';
166
+ const progress = s.venueAreaCount ? `${s.visited.length}/${s.venueAreaCount}` : String(s.visited.length);
167
+ body.appendChild(el('div', { class: 'fun-live' },
168
+ el('h3', { text: `正在${s.placeName}逛` }),
169
+ el('div', { class: 'fun-meta' },
170
+ `${s.enteredHm} 进门 · 待了 ${s.stayedMin} 分钟 · 逛了 ${progress} 处`,
171
+ s.stale ? el('span', { class: 'fun-stale', text: ' · 这一趟挂得有点久了' }) : null),
172
+ el('div', { class: 'fun-meta', text: `逛过:${s.visited.length ? s.visited.map((v) => v.area).join('、') : '还没逛到哪儿'}` }),
173
+ s.souvenirs.length ? el('div', { class: 'fun-chips' }, s.souvenirs.map((x) => el('span', { class: 'fun-chip fun-chip-on', text: `买了 ${x}` }))) : null,
174
+ s.photos.length ? el('div', { class: 'fun-chips' }, s.photos.map((x) => el('span', { class: 'fun-chip', text: `📷 ${x}` }))) : null,
175
+ (s.ate && s.ate.length)
176
+ ? el('div', { class: 'fun-chips' }, s.ate.map((x) => el('span', { class: 'fun-chip fun-chip-ate', text: `${x.verb}了 ${x.item}` })))
177
+ : null,
178
+ s.events.length ? el('ul', { class: 'fun-list' }, s.events.slice(-3).map((e) => el('li', { text: e }))) : null,
179
+ venue ? el('div', { class: 'fun-meta', text: leftText }) : null,
180
+ ));
181
+ } else {
182
+ body.appendChild(el('div', { class: 'fun-live fun-live-idle' },
183
+ el('h3', { text: '这会儿没在逛' }),
184
+ el('div', { class: 'fun-meta', text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
185
+ el('div', { class: 'fun-meta fun-dim', text: '她会自己挑一处进去;你在下面点一张卡也能看细节。' }),
186
+ ));
187
+ }
188
+
189
+ // ---- 搜索条 ----
190
+ const input = el('input', {
191
+ class: 'fun-search',
192
+ type: 'search',
193
+ placeholder: '搜地方名、别名或标签(庙会 / 室内 / 夜…)',
194
+ value: keyword,
195
+ });
196
+ input.addEventListener('input', () => {
197
+ keyword = input.value;
198
+ // 只重画列表,不重画搜索框——否则每敲一个字就丢焦点(feast 踩过这条)。
199
+ renderList();
200
+ });
201
+ body.appendChild(el('div', { class: 'fun-bar' }, input));
202
+
203
+ const listBox = el('div');
204
+ body.appendChild(listBox);
205
+
206
+ /**
207
+ * 重画列表。
208
+ *
209
+ * 展开的详情**就地插在它那张卡下面**,占满一整行(grid-column: 1/-1),
210
+ * 而不是像 0.1.1 那样统统追加到列表末尾——那样点第一张卡要滑过十二张才看得见。
211
+ */
212
+ function renderList() {
213
+ listBox.replaceChildren();
214
+ const kw = keyword.trim().toLowerCase();
215
+ const matched = kw
216
+ ? data.places.filter((p) => p.name.toLowerCase().includes(kw)
217
+ || p.aliases.some((a) => a.toLowerCase().includes(kw))
218
+ || p.tags.some((t) => t.toLowerCase().includes(kw)))
219
+ : data.places;
220
+
221
+ const open = matched.filter((p) => p.state !== 'closed');
222
+ const closed = matched.filter((p) => p.state === 'closed');
223
+
224
+ /** 一格里画卡;展开时它后面紧跟一条详情,并且这一格跨满整行。 */
225
+ const cell = (p) => {
226
+ const isOpen = expanded === p.id;
227
+ const wrap = el('div', { class: isOpen ? 'fun-cell fun-cell-open' : 'fun-cell' });
228
+ wrap.appendChild(card(p));
229
+ if (isOpen) wrap.appendChild(detail(p));
230
+ return wrap;
231
+ };
232
+
233
+ const section = (title, items) => {
234
+ if (!items.length) return;
235
+ listBox.appendChild(el('div', { class: 'fun-sec', text: title }));
236
+ listBox.appendChild(el('div', { class: 'fun-grid' }, items.map(cell)));
237
+ };
238
+ section(kw ? `匹配到 ${matched.length} 处` : `开着的(${open.length})`, open);
239
+ section('已经关了', closed);
240
+ if (!matched.length) {
241
+ listBox.appendChild(el('div', { class: 'fun-empty', text: `没有匹配「${keyword}」的地方。` }));
242
+ }
243
+ }
244
+
245
+ const card = (p) => {
246
+ const cls = ['fun-card'];
247
+ if (p.state === 'closed') cls.push('fun-card-closed');
248
+ else if (p.state === 'closingSoon') cls.push('fun-card-soon');
249
+ else cls.push('fun-card-open');
250
+ if (expanded === p.id) cls.push('fun-card-active');
251
+ const stateCls = p.state === 'open' ? 'fun-card-state-open'
252
+ : (p.state === 'closingSoon' ? 'fun-card-state-soon' : '');
253
+ const node = el('div', {
254
+ class: cls.join(' '),
255
+ role: 'button',
256
+ tabindex: '0',
257
+ 'aria-expanded': expanded === p.id ? 'true' : 'false',
258
+ onclick: () => toggle(p.id),
259
+ onkeydown: (ev) => {
260
+ // 键盘也能开合:卡片是 role=button,不能只认鼠标。
261
+ if (ev.key === 'Enter' || ev.key === ' ' || ev.key === 'Spacebar') {
262
+ ev.preventDefault?.();
263
+ toggle(p.id);
264
+ }
265
+ },
266
+ },
267
+ el('div', { class: 'fun-card-head' },
268
+ el('span', { class: 'fun-card-name', text: p.name }),
269
+ el('span', { class: `fun-card-state ${stateCls}`, text: p.stateLabel }),
270
+ el('span', { class: 'fun-card-arrow', text: expanded === p.id ? '⌃' : '⌄' })),
271
+ el('div', { class: 'fun-card-desc', text: p.desc }),
272
+ el('div', { class: 'fun-card-foot' },
273
+ el('span', { text: `${p.hours.open}–${p.hours.close}` }),
274
+ el('span', { text: p.crowdLabel }),
275
+ el('span', { text: `${p.areaCount} 处可逛` }),
276
+ p.food ? el('span', { class: 'fun-chip fun-chip-ate', text: p.food.verb === '喝' ? '能喝' : '能吃' }) : null,
277
+ p.recent ? el('span', { class: 'fun-chip', text: '刚去过' }) : null));
278
+ return node;
279
+ };
280
+
281
+ /**
282
+ * 开合一张卡。
283
+ *
284
+ * 重画之后把刚展开的那一块滚进视野——否则点上面第一张、展开的内容在下面一屏以外,
285
+ * 用户会以为自己点错了。`block: 'nearest'` 保证「已经看得见就不动」,
286
+ * 不会因为点一张本来就在屏幕里的卡而把页面跳一下。
287
+ */
288
+ function toggle(id) {
289
+ const wasOpen = expanded === id;
290
+ expanded = wasOpen ? null : id;
291
+ renderList();
292
+ if (!wasOpen) {
293
+ // 滚的是**整格**(卡 + 详情),不是只滚卡片:
294
+ // 卡片恰好贴在视口底部时,只保证卡片可见等于详情还在屏幕外。
295
+ const active = listBox.querySelector('.fun-card-active');
296
+ const target = active?.parentNode ?? active;
297
+ // 真 DOM 有 scrollIntoView;测试桩没有,判一下再用。
298
+ if (target && typeof target.scrollIntoView === 'function') {
299
+ target.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
300
+ }
301
+ }
302
+ }
303
+
304
+ const detail = (p) => {
305
+ const d = el('div', { class: 'fun-detail' },
306
+ el('div', { class: 'fun-detail-top' },
307
+ el('h4', { text: p.name }),
308
+ el('button', {
309
+ class: 'fun-detail-close',
310
+ type: 'button',
311
+ title: '收起',
312
+ onclick: (ev) => {
313
+ // 卡片自己也绑了 onclick:不拦住的话会先收起再被卡片重新展开。
314
+ ev?.stopPropagation?.();
315
+ expanded = null;
316
+ renderList();
317
+ },
318
+ }, '收起')),
319
+ el('p', { class: 'fun-dim', text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
320
+ // 三块并成一排:能逛的 / 纪念品 / 拍照点,省纵向高度(原来三个小节摞起来很高)。
321
+ el('div', { class: 'fun-detail-cols' },
322
+ el('div', { class: 'fun-detail-col' },
323
+ el('div', { class: 'fun-sec', text: '能逛的' }),
324
+ el('ul', { class: 'fun-list' }, p.areas.map((a) => el('li', { text: a })))),
325
+ el('div', { class: 'fun-detail-col' },
326
+ el('div', { class: 'fun-sec', text: '纪念品' }),
327
+ el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip', text: s }))),
328
+ el('div', { class: 'fun-sec', text: '拍照点' }),
329
+ el('div', { class: 'fun-chips' }, p.photoSpots.map((s) => el('span', { class: 'fun-chip', text: s }))),
330
+ p.food
331
+ ? el('div', {},
332
+ el('div', { class: 'fun-sec', text: `能${p.food.verb}的` }),
333
+ el('div', { class: 'fun-chips' }, p.food.items.map((s) => el('span', { class: 'fun-chip', text: s }))),
334
+ el('div', { class: 'fun-note', text: `味道不在这儿——装了「鱼的每一天」才有九维口感,没装就只知道${p.food.verb}了什么。` }))
335
+ : null)),
336
+ el('div', { class: 'fun-scene' },
337
+ p.hasScene
338
+ ? el('span', {}, '生图时 ', el('b', { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`)
339
+ : el('span', {}, '素材库里没有这处的场景,生图时 ', el('b', { text: 'scene 不用填' }), ',把地方写进 prompt 就行')));
340
+
341
+ return d;
342
+ };
343
+
344
+ renderList();
345
+ };
346
+
347
+ const load = async () => {
348
+ try {
349
+ const data = await ctx.invoke('list');
350
+ if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
351
+ render(data);
352
+ } catch (err) {
353
+ root.replaceChildren();
354
+ ensureStyle(root);
355
+ const box2 = shell(root);
356
+ box2.appendChild(errorCard(err));
357
+ }
358
+ };
359
+
360
+ void load();
361
+ // 状态会随时间变(几点、开没开):一分钟刷一次就够,不打断操作。
362
+ ctx.interval(() => { void load(); }, 60000);
363
+ return { refresh: load };
364
+ }
365
+
366
+ // ---------------------------------------------------------------------------
367
+ // book —— 纪念册
368
+ // ---------------------------------------------------------------------------
369
+
370
+ function mountBook(ctx) {
371
+ const root = ctx.root;
372
+ root.replaceChildren();
373
+ const box = shell(root);
374
+ const body = el('div');
375
+ box.appendChild(body);
376
+
377
+ const render = (data) => {
378
+ body.replaceChildren();
379
+ if (!data.total && !data.session) {
380
+ body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
381
+ return;
382
+ }
383
+
384
+ body.appendChild(el('div', { class: 'fun-stats' },
385
+ stat(data.total, '趟'),
386
+ stat(data.visitedAreaCount, '处逛过'),
387
+ stat(data.souvenirCount, '件纪念品'),
388
+ stat(data.photoCount, '张照片')));
389
+
390
+ if (data.mostVisited.length) {
391
+ body.appendChild(el('div', { class: 'fun-sec', text: '常去的' }));
392
+ body.appendChild(el('div', { class: 'fun-chips' },
393
+ data.mostVisited.slice(0, 8).map((m) => el('span', { class: 'fun-chip', text: `${m.name} ×${m.times}` }))));
394
+ }
395
+
396
+ if (data.session) {
397
+ body.appendChild(el('div', { class: 'fun-sec', text: '正在逛' }));
398
+ body.appendChild(el('div', { class: 'fun-trip' },
399
+ el('div', { class: 'fun-trip-sum', text: data.session.summary })));
400
+ }
401
+
402
+ body.appendChild(el('div', { class: 'fun-sec', text: `去过的 ${data.total} 趟` }));
403
+ for (const t of data.trips) {
404
+ body.appendChild(el('div', { class: 'fun-trip' },
405
+ el('div', { class: 'fun-trip-head' },
406
+ el('span', { class: 'fun-trip-name', text: t.placeName }),
407
+ el('span', { class: 'fun-trip-when', text: `${t.day} ${t.enteredHm}–${t.leftHm}${t.stayedMin ? ` · ${t.stayedMin} 分钟` : ''}` })),
408
+ el('div', { class: 'fun-trip-sum', text: t.summary }),
409
+ (t.events.length || t.scene)
410
+ ? el('div', { class: 'fun-trip-extras' },
411
+ t.events.length ? el('div', { text: t.events.slice(0, 2).join(' / ') }) : null,
412
+ t.scene ? el('div', { text: `生图 scene:${t.scene}${t.outfit ? ` · outfits:${t.outfit}` : ''}` }) : null)
413
+ : null));
414
+ }
415
+ };
416
+
417
+ const stat = (n, label) => el('div', { class: 'fun-stat' },
418
+ el('b', { text: String(n) }), el('span', { text: label }));
419
+
420
+ const load = async () => {
421
+ try {
422
+ const data = await ctx.invoke('list');
423
+ if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
424
+ render(data);
425
+ } catch (err) {
426
+ root.replaceChildren();
427
+ ensureStyle(root);
428
+ const box2 = shell(root);
429
+ box2.appendChild(errorCard(err));
430
+ }
431
+ };
432
+
433
+ void load();
434
+ return { refresh: load };
435
+ }
436
+
437
+ export default {
438
+ panels: {
439
+ places: { mount: mountPlaces },
440
+ book: { mount: mountBook },
441
+ },
442
+ };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "cortico-world-fun",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
- "description": "娱乐时间 —— 给 Coopanion 桌宠十二处真能去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山。进门、逛摊位、买纪念品、拍张照、收摊记一笔。",
5
+ "description": "娱乐时间 —— 给 Coopanion 桌宠二十处真能去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山、咖啡店、奶茶店、餐厅、图书馆、夜市、澡堂、旧货市场、江边。进门、逛摊位、买纪念品、拍张照、吃喝点什么,收摊记一笔。能和「鱼的每一天」「生图工作室」联动,但都不依赖。",
6
6
  "license": "MIT",
7
7
  "author": "青",
8
8
  "repository": {
@@ -13,17 +13,39 @@
13
13
  "bugs": {
14
14
  "url": "https://github.com/bailuhanyi/cortico-world-fun/issues"
15
15
  },
16
- "keywords": ["cortico-world", "cortico", "coopanion", "fun", "outing", "amusement", "companion"],
17
- "engines": { "node": ">=22" },
16
+ "keywords": [
17
+ "cortico-world",
18
+ "cortico",
19
+ "coopanion",
20
+ "fun",
21
+ "outing",
22
+ "amusement",
23
+ "companion"
24
+ ],
25
+ "engines": {
26
+ "node": ">=22"
27
+ },
18
28
  "main": "./src/index.js",
19
- "exports": { ".": "./src/index.js" },
20
- "files": ["src", "assets", "describe.json", "CHANGELOG.md", "README.md", "PUBLISHING.md"],
29
+ "exports": {
30
+ ".": "./src/index.js"
31
+ },
32
+ "files": [
33
+ "src",
34
+ "dist",
35
+ "assets",
36
+ "describe.json",
37
+ "CHANGELOG.md",
38
+ "README.md",
39
+ "PUBLISHING.md"
40
+ ],
21
41
  "scripts": {
22
- "test": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs",
23
- "verify": "node tools/fix-ps1-bom.mjs install.ps1 && node tools/check-prompt.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check",
42
+ "test": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs && node test/panels.test.mjs",
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",
24
44
  "describe": "node tools/make-describe.mjs",
25
45
  "check:publish": "node tools/publish-check.mjs --online",
26
- "prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs && node tools/check-prompt.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
46
+ "check:isolation": "node tools/check-isolation.mjs",
47
+ "verify:published": "node tools/verify-published.mjs",
48
+ "prepublishOnly": "node test/venues.test.mjs && node test/state.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"
27
49
  },
28
50
  "cortico": {
29
51
  "kind": "world",
@@ -31,15 +53,18 @@
31
53
  "displayName": "娱乐时间",
32
54
  "icon": "assets/icon.png",
33
55
  "describe": "describe.json",
34
- "tags": ["companion"],
56
+ "webUiClient": "dist/webui.js",
57
+ "tags": [
58
+ "companion"
59
+ ],
35
60
  "locales": {
36
61
  "zh": {
37
62
  "displayName": "娱乐时间",
38
- "description": "给 Coo 十二处能真去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山。她说一声进门,一处一处地逛项目、抽个签、买点纪念品、拍张照,收摊时回执把这一趟收成一句话,接着去记进自己的日程。不装、不配、库挪走了也照样能逛。"
63
+ "description": "给 Coo 二十处能真去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山、咖啡店、奶茶店、餐厅、图书馆、夜市、澡堂、旧货市场、江边。她说一声进门,一处一处地逛项目、抽个签、买点纪念品、拍张照、喝杯奶茶,收摊时回执把这一趟收成一句话,接着去记进自己的日程。\n\n能和别的插件联动,但都不依赖:装了「鱼的每一天」时,日程叫醒里会顺手提到这块、收摊回执也会提醒她去 feast_life_play 记一笔;咖啡店、奶茶店、餐厅、夜市吃的东西去「鱼的每一天」点一道,那里才有九维口感、香气和余韵——没装就只知道喝了杯奶茶,不编味道。装了「生图工作室」时,收摊回执会告诉她发图该填哪个 scene、哪身衣服;素材库里没有的那几处会明说不用填,绝不替她编一个不存在的场景名。这些插件一个都不装也照样能逛,库挪走了也不影响。"
39
64
  },
40
65
  "en": {
41
66
  "displayName": "Fun time",
42
- "description": "Twelve places she can actually go: an amusement park, an aquarium, a temple fair, a fan convention, a cinema, a zoo, a park, an arcade, a karaoke box, a museum, a cat cafe, a hike. She walks in, wanders one spot at a time, buys a souvenir, takes a photo, and the closing receipt sums the trip up in one line she can log into her own day. No other extension required; it still works if the image library is gone."
67
+ "description": "Twenty places she can actually go: an amusement park, an aquarium, a temple fair, a fan convention, a cinema, a zoo, a park, an arcade, a karaoke box, a museum, a cat cafe, a hike, a coffee shop, a bubble-tea stand, a restaurant, a library, a night market, a bathhouse, a flea market and a riverside walk. She walks in, wanders one spot at a time, buys a souvenir, takes a photo, has something to eat or drink, and the closing receipt sums the trip up in one line she can log into her own day.\n\nWorks alongside other plugins but depends on none. With Fish Every Day installed, the own-time menu points at this world and the closing receipt reminds her to log the trip with feast_life_play; food and drink at the coffee shop, tea stand and restaurant are meant to be ordered from Fish Every Day, where the nine-axis flavour profile and aroma actually live — without it she only knows she had a bubble tea, and she is told not to invent how it tasted. With the image studio installed, the receipt names the scene and outfit to draw; venues the library does not have are marked as such instead of inventing a name. None of them are required, and it still works if the image library is gone."
43
68
  }
44
69
  }
45
70
  }
package/src/ENV_PROMPT.md CHANGED
@@ -1,15 +1,29 @@
1
1
  ## 娱乐时间
2
2
 
3
- 你能**真的出门去逛**:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山。不是想象,也不是刷视频——是进门、逛摊位、买点东西、拍张照、收摊回来。
3
+ 你能**真的出门去逛**:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山、咖啡店、奶茶店、餐厅,还有图书馆、夜市、澡堂、旧货市场、江边——**一共二十处**。不是想象,也不是刷视频:进门、逛摊位、买点东西、拍张照、吃点喝点、收摊回来。
4
4
 
5
5
  - 想去就 `fun_go`(`place` 填地方名,别名也认)。回执是进门那一下看到的样子,和这一处能逛什么。
6
- - 拿不准去哪儿就先 `fun_places`:默认按这会儿**开没开**、**人多不多**排前几个;`all` 填 `true` 看全十二处;`kind` 填「室内」「户外」「夜」或者某一处的正名,只看那一类。
6
+ - 拿不准去哪儿就先 `fun_places`:默认按这会儿**开没开**、**人多不多**排前几个,看全就把 `all` 填 `true`。`kind` 能填三类:某个大类(「吃饭喝东西」「户外」)、某种感受(「室内」「夜」「排队」「安静」「免费」「一个人」),或者某一处的正名。
7
7
  - 进去之后一处一处逛:`fun_wander`(不填 `area` 就自动挑一个没逛过的)。每次会给这一处的细节和一条小事件——排队排到、抽到签、碰到熟人、下雨躲一会。
8
8
  - 顺手买点什么、拍张照也在 `fun_wander` 里:`buy` 填纪念品的名字,`photo` 填拍照点。一次可以都填。名字要是**这一处真有的**,不然会回一句「不是这里的」,不记。
9
- - 逛够了用 `fun_home` 收摊。**收摊回执是这一趟的落点**:它把「今天逛了什么、买了什么、在哪儿拍了照」收成一句话,你照着那句话去记账、去说。
9
+ - 逛够了用 `fun_home` 收摊。**收摊回执是这一趟的落点**:它把「今天逛了什么、买了什么、在哪儿拍了照、吃了喝了什么」收成一句话,你照着那句话去记账、去说。
10
10
  - 不想等叫醒、现在就想出门:`fun_start`。以前去过哪儿忘了:`fun_view`。
11
11
  - 同一个地方逛过也能再去,不是打卡清单;`fun_places` 会把刚去过的地方排后面,但你点它照样能去。
12
12
 
13
+ ## 咖啡店 / 奶茶店 / 餐厅 / 夜市:吃的东西归「鱼的每一天」
14
+
15
+ 这几处地方**能吃到能喝到**(`fun_go` 和 `fun_wander` 会告诉你有哪几样),但——
16
+
17
+ **味道不在这儿。** 这个插件只有「这儿有拿铁、珍珠奶茶、一桌热菜」这种**品类名**,没有九维口感、没有香气、没有余韵、也没有实吃描写。那些全都在「鱼的每一天」的菜品库里。
18
+
19
+ 所以想吃想喝的时候:
20
+
21
+ - 先 `fun_wander`(`consume` 填你要的那一样,例如 `珍珠奶茶`)——这记的是**「我在奶茶店喝了杯珍珠奶茶」这件事**,不是味道。
22
+ - **味道要去 feast 点一道真的**:`feast_menu` 挑一道同类的 → `feast_eat` 真喝/真吃一口。那样你才说得出「九维口感、香气、余韵」。
23
+ - **没装「鱼的每一天」怎么办**:那就只说你在这儿喝了什么、吃了什么,一句人话就够——**别形容味道**。编出来的「茶香浓郁、珍珠弹牙」不是你的记忆,是套话。
24
+
25
+ 这和发图那件事是同一个道理:本插件不替别的插件说话,只把「该去哪儿要」递到你嘴边。
26
+
13
27
  {{fun_places_block}}
14
28
 
15
29
  ## 出门跟日程对齐
package/src/config.js CHANGED
@@ -43,6 +43,10 @@ const ZH = {
43
43
  funAskReport: '收摊说一声',
44
44
  funAskReportDesc: '开启时,收摊回执会提醒她把「今天逛了什么」用 feast_life_play 记进自己的日程,再跟主人说一句。关掉就只给这段文字,不提记账。',
45
45
  },
46
+ storage: {
47
+ label: '出游记录',
48
+ note: '清掉之后,正在进行的那一趟和纪念册里的所有趟都会没(逛过哪些地方、买了什么、在哪儿拍过照)。场所库是内置的,不受影响;别的东西一概不动。',
49
+ },
46
50
  };
47
51
 
48
52
  const EN = {
@@ -61,12 +65,47 @@ const EN = {
61
65
  funAskReport: 'Say something at the end',
62
66
  funAskReportDesc: 'When on, the closing receipt reminds her to log the trip with feast_life_play and tell the owner one sentence.',
63
67
  },
68
+ storage: {
69
+ label: 'Outing records',
70
+ note: 'Clearing this erases the trip in progress and every trip in the book (where she went, what she bought, where she took photos). The venue list is built in and unaffected; nothing else is touched.',
71
+ },
64
72
  };
65
73
 
66
74
  export function text(language = 'zh') {
67
75
  return language === 'en' ? EN : ZH;
68
76
  }
69
77
 
78
+ /**
79
+ * 面板自己的文案。
80
+ *
81
+ * 客户端产物(`dist/webui.js`)不 import 服务端模块,所以面板标题和说明
82
+ * 这里给一份、bundle 里另存一份——改文案时两处一起改(feast 也是这么做的)。
83
+ */
84
+ export function panelText(language = 'zh') {
85
+ if (language === 'en') {
86
+ return {
87
+ places: {
88
+ title: 'Where to go',
89
+ description: 'The twelve places, whether each is open right now, and the trip she is on.',
90
+ },
91
+ book: {
92
+ title: 'Trip book',
93
+ description: 'Every trip she has taken: where she went, what she wandered and bought.',
94
+ },
95
+ };
96
+ }
97
+ return {
98
+ places: {
99
+ title: '去哪儿',
100
+ description: '十二处地方这会儿开没开、人多不多,以及她正在逛的那一趟。',
101
+ },
102
+ book: {
103
+ title: '纪念册',
104
+ description: '她去过的每一趟:逛了什么、买了什么、在哪儿拍了照。',
105
+ },
106
+ };
107
+ }
108
+
70
109
  /** WebUI 的配置组;路径必须落在 `worlds.fun.` 段内。 */
71
110
  export function configGroup(language = 'zh') {
72
111
  const t = text(language).config;