cortico-world-memory-core 0.3.2 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/ENV_PROMPT.md +5 -5
- package/README.md +17 -5
- package/describe.json +3 -3
- package/package.json +3 -3
- package/src/config.ts +12 -1
- package/src/recall.ts +10 -1
- package/src/site.ts +54 -5
- package/src/store.ts +165 -14
- package/src/tools.ts +3 -3
- package/src/world.ts +151 -5
- package/webui/app.js +2361 -2045
- package/webui/index.html +2 -0
- package/webui/style.css +721 -665
package/webui/app.js
CHANGED
|
@@ -1,2045 +1,2361 @@
|
|
|
1
|
-
/* 记忆地图前端:无框架、无依赖,数据全部来自本机 /api/*。 */
|
|
2
|
-
|
|
3
|
-
const $ = (sel, root = document) => root.querySelector(sel);
|
|
4
|
-
|
|
5
|
-
const KINDS = [
|
|
6
|
-
{ id: 'fact', label: '事实', css: '--k-fact' },
|
|
7
|
-
{ id: 'self', label: '她自己', css: '--k-self' },
|
|
8
|
-
{ id: 'episode', label: '经历', css: '--k-episode' },
|
|
9
|
-
{ id: 'promise', label: '承诺', css: '--k-promise' },
|
|
10
|
-
{ id: 'note', label: '临时', css: '--k-note' },
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
/** 原文页一次渲染多少条。7 天窗口实测稳定在 1000 条上下,全量拼 DOM 会卡。 */
|
|
14
|
-
const TURNS_PAGE = 200;
|
|
15
|
-
|
|
16
|
-
const S = {
|
|
17
|
-
snap: null,
|
|
18
|
-
view: 'graph',
|
|
19
|
-
query: '',
|
|
20
|
-
kinds: new Set(),
|
|
21
|
-
minWeight: 0,
|
|
22
|
-
range: 'all',
|
|
23
|
-
tag: null,
|
|
24
|
-
selected: null,
|
|
25
|
-
editing: false,
|
|
26
|
-
sort: { key: 'createdAt', dir: -1 },
|
|
27
|
-
docs: null,
|
|
28
|
-
docsLoading: false,
|
|
29
|
-
docSel: null,
|
|
30
|
-
docText: null,
|
|
31
|
-
showLabels: true,
|
|
32
|
-
inspCollapsed: (localStorage.getItem('mcore-insp') ?? 'off') === 'off',
|
|
33
|
-
status: 'active', // active | all | retired
|
|
34
|
-
scope: null,
|
|
35
|
-
maintenance: null,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
toast.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
</section>
|
|
406
|
-
|
|
407
|
-
<section>
|
|
408
|
-
<h3
|
|
409
|
-
<div class="
|
|
410
|
-
${
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
</section>
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
'
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
this.
|
|
584
|
-
|
|
585
|
-
this.
|
|
586
|
-
this.
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
ctx.
|
|
888
|
-
ctx.
|
|
889
|
-
ctx.
|
|
890
|
-
ctx.
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
ctx.
|
|
901
|
-
|
|
902
|
-
ctx.
|
|
903
|
-
ctx.
|
|
904
|
-
ctx.
|
|
905
|
-
|
|
906
|
-
ctx.
|
|
907
|
-
ctx.
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
$('#graph-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
$('#graph-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
];
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
host
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
</div
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
<button class="icon-btn tiny" id="btn-insp-collapse" title="收起右栏 (I)" aria-label="收起右栏">›</button>
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
<
|
|
1404
|
-
<
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
)
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
});
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
);
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
function
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
return
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
$('#edit-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
S.editing =
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
})
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
);
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
if (
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
const
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
);
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
<
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
})
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
if (
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
1
|
+
/* 记忆地图前端:无框架、无依赖,数据全部来自本机 /api/*。 */
|
|
2
|
+
|
|
3
|
+
const $ = (sel, root = document) => root.querySelector(sel);
|
|
4
|
+
|
|
5
|
+
const KINDS = [
|
|
6
|
+
{ id: 'fact', label: '事实', css: '--k-fact' },
|
|
7
|
+
{ id: 'self', label: '她自己', css: '--k-self' },
|
|
8
|
+
{ id: 'episode', label: '经历', css: '--k-episode' },
|
|
9
|
+
{ id: 'promise', label: '承诺', css: '--k-promise' },
|
|
10
|
+
{ id: 'note', label: '临时', css: '--k-note' },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** 原文页一次渲染多少条。7 天窗口实测稳定在 1000 条上下,全量拼 DOM 会卡。 */
|
|
14
|
+
const TURNS_PAGE = 200;
|
|
15
|
+
|
|
16
|
+
const S = {
|
|
17
|
+
snap: null,
|
|
18
|
+
view: 'graph',
|
|
19
|
+
query: '',
|
|
20
|
+
kinds: new Set(),
|
|
21
|
+
minWeight: 0,
|
|
22
|
+
range: 'all',
|
|
23
|
+
tag: null,
|
|
24
|
+
selected: null,
|
|
25
|
+
editing: false,
|
|
26
|
+
sort: { key: 'createdAt', dir: -1 },
|
|
27
|
+
docs: null,
|
|
28
|
+
docsLoading: false,
|
|
29
|
+
docSel: null,
|
|
30
|
+
docText: null,
|
|
31
|
+
showLabels: true,
|
|
32
|
+
inspCollapsed: (localStorage.getItem('mcore-insp') ?? 'off') === 'off',
|
|
33
|
+
status: 'active', // active | all | retired
|
|
34
|
+
scope: null,
|
|
35
|
+
maintenance: null,
|
|
36
|
+
health: null,
|
|
37
|
+
withArchive: localStorage.getItem('mcore-archive') === '1',
|
|
38
|
+
archive: null,
|
|
39
|
+
archiveQ: '',
|
|
40
|
+
turnsLimit: TURNS_PAGE,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const el = {
|
|
44
|
+
search: $('#search'),
|
|
45
|
+
searchClear: $('#search-clear'),
|
|
46
|
+
metrics: $('#metrics'),
|
|
47
|
+
rail: $('#rail'),
|
|
48
|
+
inspector: $('#inspector'),
|
|
49
|
+
inspBody: $('#insp-body'),
|
|
50
|
+
inspStub: $('#insp-stub'),
|
|
51
|
+
statusCount: $('#status-count'),
|
|
52
|
+
statusSite: $('#status-site'),
|
|
53
|
+
brandSub: $('#brand-sub'),
|
|
54
|
+
modal: $('#modal'),
|
|
55
|
+
modalTitle: $('#modal-title'),
|
|
56
|
+
modalBody: $('#modal-body'),
|
|
57
|
+
modalFoot: $('#modal-foot'),
|
|
58
|
+
toast: $('#toast'),
|
|
59
|
+
menu: $('#menu'),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/* ── 小工具 ─────────────────────────────────────────── */
|
|
63
|
+
|
|
64
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
65
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
66
|
+
const clamp = (n, a, b) => Math.min(b, Math.max(a, n));
|
|
67
|
+
|
|
68
|
+
function kindOf(id) {
|
|
69
|
+
return KINDS.find((k) => k.id === id) ?? { id, label: id, css: '--ink-dim' };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function color(name) {
|
|
73
|
+
return getComputedStyle(document.documentElement).getPropertyValue(name).trim() || '#888';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let PALETTE = null;
|
|
77
|
+
function palette() {
|
|
78
|
+
if (PALETTE) return PALETTE;
|
|
79
|
+
PALETTE = {
|
|
80
|
+
ink: color('--ink'),
|
|
81
|
+
line: color('--line-strong'),
|
|
82
|
+
paper: color('--paper-2'),
|
|
83
|
+
kinds: Object.fromEntries(KINDS.map((k) => [k.id, color(k.css)])),
|
|
84
|
+
};
|
|
85
|
+
return PALETTE;
|
|
86
|
+
}
|
|
87
|
+
function invalidatePalette() {
|
|
88
|
+
PALETTE = null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function fmtTime(iso) {
|
|
92
|
+
const d = new Date(iso);
|
|
93
|
+
if (Number.isNaN(d.getTime())) return '—';
|
|
94
|
+
return `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function dayKey(iso) {
|
|
98
|
+
const d = new Date(iso);
|
|
99
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function dayLabel(key) {
|
|
103
|
+
const today = dayKey(new Date().toISOString());
|
|
104
|
+
const yesterday = dayKey(new Date(Date.now() - 86400000).toISOString());
|
|
105
|
+
if (key === today) return '今天';
|
|
106
|
+
if (key === yesterday) return '昨天';
|
|
107
|
+
const [y, m, d] = key.split('-');
|
|
108
|
+
const date = new Date(Number(y), Number(m) - 1, Number(d));
|
|
109
|
+
const week = '日一二三四五六'[date.getDay()];
|
|
110
|
+
return `${m} 月 ${d} 日 · 周${week}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function relative(iso) {
|
|
114
|
+
const at = Date.parse(iso);
|
|
115
|
+
if (!Number.isFinite(at)) return '—';
|
|
116
|
+
const diff = Date.now() - at;
|
|
117
|
+
if (diff < 60_000) return '刚刚';
|
|
118
|
+
if (diff < 3600_000) return `${Math.round(diff / 60_000)} 分钟前`;
|
|
119
|
+
if (diff < 86400_000) return `${Math.round(diff / 3600_000)} 小时前`;
|
|
120
|
+
const days = Math.round(diff / 86400_000);
|
|
121
|
+
return days < 30 ? `${days} 天前` : `${Math.round(days / 30)} 个月前`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function tokens(q) {
|
|
125
|
+
return String(q ?? '')
|
|
126
|
+
.toLowerCase()
|
|
127
|
+
.split(/\s+/)
|
|
128
|
+
.map((t) => t.trim())
|
|
129
|
+
.filter(Boolean);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function matches(text, toks) {
|
|
133
|
+
if (!toks.length) return true;
|
|
134
|
+
const hay = text.toLowerCase();
|
|
135
|
+
return toks.every((t) => hay.includes(t));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function highlight(text, q) {
|
|
139
|
+
const toks = tokens(q).filter((t) => t.length > 0);
|
|
140
|
+
let html = esc(text);
|
|
141
|
+
if (!toks.length) return html;
|
|
142
|
+
const pattern = toks
|
|
143
|
+
.sort((a, b) => b.length - a.length)
|
|
144
|
+
.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
145
|
+
.join('|');
|
|
146
|
+
try {
|
|
147
|
+
html = html.replace(new RegExp(`(${pattern})`, 'gi'), '<mark>$1</mark>');
|
|
148
|
+
} catch {
|
|
149
|
+
/* 正则出错就原样 */
|
|
150
|
+
}
|
|
151
|
+
return html;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function toast(msg, isErr = false) {
|
|
155
|
+
el.toast.textContent = msg;
|
|
156
|
+
el.toast.classList.toggle('err', isErr);
|
|
157
|
+
el.toast.hidden = false;
|
|
158
|
+
clearTimeout(toast._t);
|
|
159
|
+
toast._t = setTimeout(() => {
|
|
160
|
+
el.toast.hidden = true;
|
|
161
|
+
}, isErr ? 4200 : 1900);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 带撤销按钮的提示条:10 秒内点一下,把刚才删的整包灌回来。 */
|
|
165
|
+
function toastUndo(msg, onUndo, ms = 10000) {
|
|
166
|
+
el.toast.innerHTML = `<span>${esc(msg)}</span><button type="button" class="toast-undo">撤销</button>`;
|
|
167
|
+
el.toast.classList.remove('err');
|
|
168
|
+
el.toast.hidden = false;
|
|
169
|
+
clearTimeout(toast._t);
|
|
170
|
+
el.toast.querySelector('.toast-undo')?.addEventListener('click', async () => {
|
|
171
|
+
el.toast.hidden = true;
|
|
172
|
+
clearTimeout(toast._t);
|
|
173
|
+
await onUndo();
|
|
174
|
+
});
|
|
175
|
+
toast._t = setTimeout(() => {
|
|
176
|
+
el.toast.hidden = true;
|
|
177
|
+
}, ms);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 彻底删除:先把要删的摆出来确认,删完 10 秒内可撤销。
|
|
182
|
+
* 撤销走 /api/import(只加不覆盖),所以不会把后来新写的记忆冲掉。
|
|
183
|
+
*/
|
|
184
|
+
async function purgeWithUndo(ids) {
|
|
185
|
+
const victims = ids.map((id) => cards().find((c) => c.id === id)).filter(Boolean);
|
|
186
|
+
if (!victims.length) return 0;
|
|
187
|
+
const preview = victims.slice(0, 5).map((c) => `· ${c.text.slice(0, 40)}`).join('\n');
|
|
188
|
+
const more = victims.length > 5 ? `\n…还有 ${victims.length - 5} 条` : '';
|
|
189
|
+
if (!confirm(`彻底删除这 ${victims.length} 条?\n\n${preview}${more}\n\n删了之后 10 秒内可以撤销。`)) return 0;
|
|
190
|
+
const res = await api('/api/purge', { method: 'POST', body: JSON.stringify({ ids }) });
|
|
191
|
+
const removed = Number(res.removed ?? 0);
|
|
192
|
+
toastUndo(`删了 ${removed} 条`, async () => {
|
|
193
|
+
try {
|
|
194
|
+
await api('/api/import', { method: 'POST', body: JSON.stringify({ cards: victims }) });
|
|
195
|
+
await load();
|
|
196
|
+
toast('已撤销');
|
|
197
|
+
} catch (err) {
|
|
198
|
+
toast(`撤销失败:${err.message}`, true);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
return removed;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function api(path, init = {}) { const res = await fetch(path, {
|
|
205
|
+
...init,
|
|
206
|
+
headers: { 'content-type': 'application/json', ...(init.headers ?? {}) },
|
|
207
|
+
});
|
|
208
|
+
if (!res.ok) {
|
|
209
|
+
let msg = `${res.status}`;
|
|
210
|
+
try {
|
|
211
|
+
const body = await res.json();
|
|
212
|
+
if (body && body.error) msg = body.error;
|
|
213
|
+
} catch {
|
|
214
|
+
/* 非 JSON */
|
|
215
|
+
}
|
|
216
|
+
throw new Error(msg);
|
|
217
|
+
}
|
|
218
|
+
if (res.status === 204) return null;
|
|
219
|
+
const type = res.headers.get('content-type') ?? '';
|
|
220
|
+
return type.includes('application/json') ? res.json() : res.text();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* ── 主题 ───────────────────────────────────────────── */
|
|
224
|
+
|
|
225
|
+
function readThemeHandoff() {
|
|
226
|
+
const hash = location.hash.replace(/^#/, '');
|
|
227
|
+
if (!hash) return null;
|
|
228
|
+
const params = new URLSearchParams(hash);
|
|
229
|
+
const raw = params.get('cortico-theme');
|
|
230
|
+
if (!raw) return null;
|
|
231
|
+
try {
|
|
232
|
+
const b64 = raw.replace(/-/g, '+').replace(/_/g, '/');
|
|
233
|
+
const json = JSON.parse(atob(b64));
|
|
234
|
+
return json && json.palette ? json : null;
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function applyTheme() {
|
|
241
|
+
invalidatePalette();
|
|
242
|
+
const handoff = readThemeHandoff();
|
|
243
|
+
const root = document.documentElement;
|
|
244
|
+
if (handoff) {
|
|
245
|
+
root.dataset.mode = handoff.appearance === 'light' ? 'light' : 'dark';
|
|
246
|
+
for (const [key, value] of Object.entries(handoff.palette)) {
|
|
247
|
+
if (/^#[0-9a-f]{3,8}$/i.test(String(value))) root.style.setProperty(`--${key}`, value);
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const saved = localStorage.getItem('mcore-mode') ?? 'auto';
|
|
252
|
+
root.dataset.mode = saved;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
$('#btn-theme').addEventListener('click', () => {
|
|
256
|
+
const order = ['auto', 'light', 'dark'];
|
|
257
|
+
const current = localStorage.getItem('mcore-mode') ?? 'auto';
|
|
258
|
+
const next = order[(order.indexOf(current) + 1) % order.length];
|
|
259
|
+
if (next === 'auto') localStorage.removeItem('mcore-mode');
|
|
260
|
+
else localStorage.setItem('mcore-mode', next);
|
|
261
|
+
document.documentElement.removeAttribute('style');
|
|
262
|
+
applyTheme();
|
|
263
|
+
render();
|
|
264
|
+
toast(next === 'auto' ? '跟随系统' : next === 'light' ? '浅色' : '深色');
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
/* ── 数据与筛选 ─────────────────────────────────────── */
|
|
268
|
+
|
|
269
|
+
async function load({ quiet = false } = {}) {
|
|
270
|
+
try {
|
|
271
|
+
const snap = await api('/api/snapshot');
|
|
272
|
+
S.snap = snap;
|
|
273
|
+
if (!quiet) render();
|
|
274
|
+
else render();
|
|
275
|
+
} catch (err) {
|
|
276
|
+
toast(`读不到数据:${err.message}`, true);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function cards() {
|
|
281
|
+
return S.snap?.cards ?? [];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function isRetired(c) {
|
|
285
|
+
return c.status === 'retired';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function liveCards() {
|
|
289
|
+
return cards().filter((c) => !isRetired(c));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function filtered() {
|
|
293
|
+
const toks = tokens(S.query);
|
|
294
|
+
const cutoff = S.range === 'all' ? 0 : Date.now() - Number(S.range) * 86400000;
|
|
295
|
+
return cards().filter((c) => {
|
|
296
|
+
if (S.status === 'active' && isRetired(c)) return false;
|
|
297
|
+
if (S.status === 'retired' && !isRetired(c)) return false;
|
|
298
|
+
if (S.scope && (c.scope ?? 'main') !== S.scope) return false;
|
|
299
|
+
if (S.kinds.size && !S.kinds.has(c.kind)) return false;
|
|
300
|
+
if (c.weight < S.minWeight) return false;
|
|
301
|
+
if (cutoff && Date.parse(c.createdAt) < cutoff) return false;
|
|
302
|
+
if (S.tag && !c.tags.includes(S.tag)) return false;
|
|
303
|
+
if (toks.length && !matches(`${c.text} ${c.tags.join(' ')}`, toks)) return false;
|
|
304
|
+
return true;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function selectedCard() {
|
|
309
|
+
if (!S.selected) return null;
|
|
310
|
+
return cards().find((c) => c.id === S.selected) ?? null;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* ── 右栏折叠 ───────────────────────────────────────── */
|
|
314
|
+
|
|
315
|
+
function applyInspState() {
|
|
316
|
+
document.body.dataset.insp = S.inspCollapsed ? 'off' : 'on';
|
|
317
|
+
const badge = $('#stub-count');
|
|
318
|
+
if (badge) badge.textContent = String(filtered().length);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function setInspCollapsed(off) {
|
|
322
|
+
S.inspCollapsed = Boolean(off);
|
|
323
|
+
localStorage.setItem('mcore-insp', S.inspCollapsed ? 'off' : 'on');
|
|
324
|
+
applyInspState();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function selectCard(id, { scroll = false } = {}) {
|
|
328
|
+
S.selected = id ?? null;
|
|
329
|
+
S.editing = false;
|
|
330
|
+
setInspCollapsed(!id); // 选中就展开详情,取消就收回去
|
|
331
|
+
renderStage();
|
|
332
|
+
renderInspector();
|
|
333
|
+
renderStatus();
|
|
334
|
+
if (scroll && id) {
|
|
335
|
+
document.querySelector(`.tl-item[data-id="${id}"], tr[data-id="${id}"]`)?.scrollIntoView({ block: 'nearest' });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function bindInspCollapse() {
|
|
340
|
+
const btn = $('#btn-insp-collapse');
|
|
341
|
+
if (btn) btn.addEventListener('click', () => setInspCollapsed(true));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/* ── 顶栏指标 ───────────────────────────────────────── */
|
|
345
|
+
|
|
346
|
+
function renderMetrics() {
|
|
347
|
+
const st = S.snap?.stats;
|
|
348
|
+
if (!st) {
|
|
349
|
+
el.metrics.innerHTML = '';
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const max = Math.max(1, ...st.byDay.map((d) => d.n));
|
|
353
|
+
const spark = st.byDay
|
|
354
|
+
.map((d, i) => `<i class="${i === st.byDay.length - 1 ? 'today' : ''}" style="height:${Math.max(2, (d.n / max) * 28)}px" title="${d.day} · ${d.n} 条"></i>`)
|
|
355
|
+
.join('');
|
|
356
|
+
const items = [
|
|
357
|
+
{ label: '记忆', value: st.total, unit: '条' },
|
|
358
|
+
{ label: '未完成承诺', value: st.openPromises, unit: st.overdue ? `含逾期 ${st.overdue}` : '条', tone: st.overdue ? 'warn' : '' },
|
|
359
|
+
{ label: '今天新增', value: st.todayNew, unit: '条' },
|
|
360
|
+
{ label: '近 7 天', value: st.weekNew, unit: '条' },
|
|
361
|
+
{ label: '平均权重', value: st.avgWeight.toFixed(2), unit: '' },
|
|
362
|
+
{ label: '对话原文', value: (S.snap.turns ?? []).length, unit: S.snap.archive?.days ? `行 · 归档 ${S.snap.archive.days} 天` : '行' },
|
|
363
|
+
{ label: '工作区文件', value: S.snap.docs?.count ?? 0, unit: '个', tone: S.snap.docs?.enabled ? '' : '' },
|
|
364
|
+
];
|
|
365
|
+
el.metrics.innerHTML =
|
|
366
|
+
items
|
|
367
|
+
.map(
|
|
368
|
+
(m) =>
|
|
369
|
+
`<div class="metric ${m.tone ?? ''}"><span class="label">${m.label}</span><span class="value">${esc(String(m.value))}${
|
|
370
|
+
m.unit ? `<small>${esc(m.unit)}</small>` : ''
|
|
371
|
+
}</span></div>`,
|
|
372
|
+
)
|
|
373
|
+
.join('') + `<div class="spark" title="近 14 天新增">${spark}</div>`;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* ── 左栏筛选 ───────────────────────────────────────── */
|
|
377
|
+
|
|
378
|
+
function renderRail() {
|
|
379
|
+
const st0 = S.snap?.stats;
|
|
380
|
+
// 类型计数跟着「状态」走:看已退休时,数字也是已退休的
|
|
381
|
+
const all = cards().filter((c) =>
|
|
382
|
+
S.status === 'active' ? !isRetired(c) : S.status === 'retired' ? isRetired(c) : true,
|
|
383
|
+
);
|
|
384
|
+
const counts = {};
|
|
385
|
+
for (const c of all) counts[c.kind] = (counts[c.kind] || 0) + 1;
|
|
386
|
+
const tagCount = new Map();
|
|
387
|
+
for (const c of all) for (const t of c.tags) tagCount.set(t, (tagCount.get(t) || 0) + 1);
|
|
388
|
+
const topTags = [...tagCount.entries()].sort((a, b) => b[1] - a[1]).slice(0, 14);
|
|
389
|
+
const st = S.snap?.state;
|
|
390
|
+
const pro = S.snap?.proactive;
|
|
391
|
+
|
|
392
|
+
el.rail.innerHTML = `
|
|
393
|
+
<section>
|
|
394
|
+
<h3>状态</h3>
|
|
395
|
+
<div class="seg" id="status-seg">
|
|
396
|
+
${[
|
|
397
|
+
['active', '在用'],
|
|
398
|
+
['all', '全部'],
|
|
399
|
+
['retired', `已退休${st0?.retired ? `<span class="n">${st0.retired}</span>` : ''}`],
|
|
400
|
+
]
|
|
401
|
+
.map(([v, label]) => `<button data-status="${v}" class="${S.status === v ? 'on' : ''}">${label}</button>`)
|
|
402
|
+
.join('')}
|
|
403
|
+
</div>
|
|
404
|
+
<div class="hint">已退休的不参与检索,可随时恢复</div>
|
|
405
|
+
</section>
|
|
406
|
+
|
|
407
|
+
<section>
|
|
408
|
+
<h3>类型</h3>
|
|
409
|
+
<div class="chip-list">
|
|
410
|
+
${KINDS.map(
|
|
411
|
+
(k) =>
|
|
412
|
+
`<button class="chip ${S.kinds.has(k.id) ? 'on' : ''}" data-kind="${k.id}">
|
|
413
|
+
<span class="dot" style="background:var(${k.css})"></span>${k.label}
|
|
414
|
+
<span class="n">${counts[k.id] ?? 0}</span>
|
|
415
|
+
</button>`,
|
|
416
|
+
).join('')}
|
|
417
|
+
</div>
|
|
418
|
+
<div class="hint">点一下只看这类,再点取消</div>
|
|
419
|
+
</section>
|
|
420
|
+
|
|
421
|
+
${
|
|
422
|
+
(st0?.scopes ?? []).length > 1
|
|
423
|
+
? `<section>
|
|
424
|
+
<h3>记忆域</h3>
|
|
425
|
+
<div class="chip-list">
|
|
426
|
+
${(st0?.scopes ?? [])
|
|
427
|
+
.map(
|
|
428
|
+
(x) =>
|
|
429
|
+
`<button class="chip ${S.scope === x.scope ? 'on' : ''}" data-scope="${esc(x.scope)}">${esc(
|
|
430
|
+
x.scope === 'main' ? '自己写的' : x.scope === 'import' ? '旧插件导入' : x.scope,
|
|
431
|
+
)}<span class="n">${x.n}</span></button>`,
|
|
432
|
+
)
|
|
433
|
+
.join('')}
|
|
434
|
+
</div>
|
|
435
|
+
<div class="hint">${S.scope ? '只看这一域,点一下取消' : '按记忆来源分开看'}</div>
|
|
436
|
+
</section>`
|
|
437
|
+
: ''
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
<section>
|
|
441
|
+
<h3>权重下限</h3>
|
|
442
|
+
<div class="field">
|
|
443
|
+
<input id="w-range" type="range" min="0" max="1" step="0.05" value="${S.minWeight}" />
|
|
444
|
+
<div class="row" style="justify-content:space-between;font-size:11px;color:var(--ink-dim)">
|
|
445
|
+
<span>全部</span><b id="w-value" style="color:var(--ink-soft)">≥ ${S.minWeight.toFixed(2)}</b><span>重要</span>
|
|
446
|
+
</div>
|
|
447
|
+
</div>
|
|
448
|
+
</section>
|
|
449
|
+
|
|
450
|
+
<section>
|
|
451
|
+
<h3>时间</h3>
|
|
452
|
+
<div class="seg" id="range-seg">
|
|
453
|
+
${[
|
|
454
|
+
['all', '全部'],
|
|
455
|
+
['7', '7 天'],
|
|
456
|
+
['30', '30 天'],
|
|
457
|
+
['90', '90 天'],
|
|
458
|
+
]
|
|
459
|
+
.map(([v, label]) => `<button data-range="${v}" class="${S.range === v ? 'on' : ''}">${label}</button>`)
|
|
460
|
+
.join('')}
|
|
461
|
+
</div>
|
|
462
|
+
</section>
|
|
463
|
+
|
|
464
|
+
<section>
|
|
465
|
+
<h3>标签 ${S.tag ? `<button class="chip-btn" id="tag-clear" style="float:right">清除</button>` : ''}</h3>
|
|
466
|
+
<div class="chip-list">
|
|
467
|
+
${topTags.length
|
|
468
|
+
? topTags
|
|
469
|
+
.map(([t, n]) => `<button class="chip ${S.tag === t ? 'on' : ''}" data-tag="${esc(t)}">${esc(t)}<span class="n">${n}</span></button>`)
|
|
470
|
+
.join('')
|
|
471
|
+
: '<span class="hint">还没有标签</span>'}
|
|
472
|
+
</div>
|
|
473
|
+
</section>
|
|
474
|
+
|
|
475
|
+
<section>
|
|
476
|
+
<h3>她此刻</h3>
|
|
477
|
+
<div class="status-card">
|
|
478
|
+
<div class="line"><span>精力</span><b>${Math.round(st?.energy ?? 0)}</b></div>
|
|
479
|
+
<div class="meter"><i style="width:${clamp(st?.energy ?? 0, 0, 100)}%"></i></div>
|
|
480
|
+
<div class="line"><span>心情</span><b>${Math.round(st?.mood ?? 0)}</b></div>
|
|
481
|
+
<div class="meter"><i style="width:${clamp(st?.mood ?? 0, 0, 100)}%;background:var(--warn)"></i></div>
|
|
482
|
+
<div class="line"><span>在做</span><b>${esc(st?.activity ?? '—')}</b></div>
|
|
483
|
+
<div class="line"><span>在哪</span><b>${esc(st?.location || '—')}</b></div>
|
|
484
|
+
<div class="line"><span>主动开口</span><b>${pro?.enabled ? `今天 ${pro.count}/${pro.cap || '∞'}` : '关'}</b></div>
|
|
485
|
+
<div class="line"><span>下次</span><b>${pro?.dueAt ? fmtTime(pro.dueAt) : '未安排'}</b></div>
|
|
486
|
+
</div>
|
|
487
|
+
</section>
|
|
488
|
+
`;
|
|
489
|
+
|
|
490
|
+
const w = $('#w-range', el.rail);
|
|
491
|
+
if (w) {
|
|
492
|
+
w.addEventListener('input', () => {
|
|
493
|
+
S.minWeight = Number(w.value);
|
|
494
|
+
$('#w-value', el.rail).textContent = `≥ ${S.minWeight.toFixed(2)}`;
|
|
495
|
+
renderStage();
|
|
496
|
+
renderStatus();
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
el.rail.addEventListener('click', (event) => {
|
|
502
|
+
const kindBtn = event.target.closest('[data-kind]');
|
|
503
|
+
if (kindBtn) {
|
|
504
|
+
const id = kindBtn.dataset.kind;
|
|
505
|
+
if (S.kinds.has(id)) S.kinds.delete(id);
|
|
506
|
+
else S.kinds.add(id);
|
|
507
|
+
render();
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const tagBtn = event.target.closest('[data-tag]');
|
|
511
|
+
if (tagBtn) {
|
|
512
|
+
const t = tagBtn.dataset.tag;
|
|
513
|
+
S.tag = S.tag === t ? null : t;
|
|
514
|
+
render();
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
if (event.target.id === 'tag-clear') {
|
|
518
|
+
S.tag = null;
|
|
519
|
+
render();
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
const rangeBtn = event.target.closest('[data-range]');
|
|
523
|
+
if (rangeBtn) {
|
|
524
|
+
S.range = rangeBtn.dataset.range;
|
|
525
|
+
render();
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const statusBtn = event.target.closest('[data-status]');
|
|
529
|
+
if (statusBtn) {
|
|
530
|
+
S.status = statusBtn.dataset.status;
|
|
531
|
+
render();
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
const scopeBtn = event.target.closest('[data-scope]');
|
|
535
|
+
if (scopeBtn) {
|
|
536
|
+
S.scope = S.scope === scopeBtn.dataset.scope ? null : scopeBtn.dataset.scope;
|
|
537
|
+
render();
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
/* ── 图谱 ───────────────────────────────────────────── */
|
|
542
|
+
|
|
543
|
+
class Graph {
|
|
544
|
+
constructor(canvas) {
|
|
545
|
+
this.canvas = canvas;
|
|
546
|
+
this.ctx = canvas.getContext('2d');
|
|
547
|
+
this.nodes = [];
|
|
548
|
+
this.links = [];
|
|
549
|
+
this.view = { x: 0, y: 0, k: 1 };
|
|
550
|
+
this.alpha = 1;
|
|
551
|
+
this.hover = null;
|
|
552
|
+
this.dragNode = null;
|
|
553
|
+
this.panning = false;
|
|
554
|
+
this.last = null;
|
|
555
|
+
this.frame = 0;
|
|
556
|
+
this.fitted = false;
|
|
557
|
+
this.onSelect = null;
|
|
558
|
+
this.bind();
|
|
559
|
+
new ResizeObserver(() => this.resize()).observe(canvas.parentElement);
|
|
560
|
+
this.resize();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
bind() {
|
|
564
|
+
const c = this.canvas;
|
|
565
|
+
c.addEventListener('pointerdown', (e) => {
|
|
566
|
+
const p = this.toWorld(e);
|
|
567
|
+
const hit = this.pick(p);
|
|
568
|
+
c.setPointerCapture(e.pointerId);
|
|
569
|
+
if (hit) {
|
|
570
|
+
this.dragNode = hit;
|
|
571
|
+
hit.vx = 0;
|
|
572
|
+
hit.vy = 0;
|
|
573
|
+
hit.dragging = true;
|
|
574
|
+
} else {
|
|
575
|
+
this.panning = true;
|
|
576
|
+
this.last = { x: e.clientX, y: e.clientY };
|
|
577
|
+
}
|
|
578
|
+
c.classList.add('dragging');
|
|
579
|
+
});
|
|
580
|
+
c.addEventListener('pointermove', (e) => {
|
|
581
|
+
const p = this.toWorld(e);
|
|
582
|
+
if (this.dragNode) {
|
|
583
|
+
this.dragNode.x = p.x;
|
|
584
|
+
this.dragNode.y = p.y;
|
|
585
|
+
this.alpha = Math.max(this.alpha, 0.35);
|
|
586
|
+
this.kick();
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
if (this.panning && this.last) {
|
|
590
|
+
this.view.x += e.clientX - this.last.x;
|
|
591
|
+
this.view.y += e.clientY - this.last.y;
|
|
592
|
+
this.last = { x: e.clientX, y: e.clientY };
|
|
593
|
+
this.draw();
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const hit = this.pick(p);
|
|
597
|
+
const id = hit ? hit.id : null;
|
|
598
|
+
if (id !== this.hover) {
|
|
599
|
+
this.hover = id;
|
|
600
|
+
this.draw();
|
|
601
|
+
c.style.cursor = hit ? 'pointer' : 'grab';
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
const end = () => {
|
|
605
|
+
if (this.dragNode) {
|
|
606
|
+
if (this.onSelect && !this.dragMoved) this.onSelect(this.dragNode.id);
|
|
607
|
+
this.dragNode.dragging = false;
|
|
608
|
+
this.dragNode = null;
|
|
609
|
+
}
|
|
610
|
+
this.panning = false;
|
|
611
|
+
this.last = null;
|
|
612
|
+
c.classList.remove('dragging');
|
|
613
|
+
};
|
|
614
|
+
c.addEventListener('pointerup', end);
|
|
615
|
+
c.addEventListener('pointercancel', end);
|
|
616
|
+
c.addEventListener('click', (e) => {
|
|
617
|
+
const hit = this.pick(this.toWorld(e));
|
|
618
|
+
if (!hit && this.onSelect) this.onSelect(null);
|
|
619
|
+
});
|
|
620
|
+
c.addEventListener(
|
|
621
|
+
'wheel',
|
|
622
|
+
(e) => {
|
|
623
|
+
e.preventDefault();
|
|
624
|
+
const before = this.toWorld(e);
|
|
625
|
+
const k = clamp(this.view.k * (e.deltaY < 0 ? 1.12 : 0.89), 0.18, 5);
|
|
626
|
+
this.view.k = k;
|
|
627
|
+
const rect = c.getBoundingClientRect();
|
|
628
|
+
this.view.x = e.clientX - rect.left - before.x * k;
|
|
629
|
+
this.view.y = e.clientY - rect.top - before.y * k;
|
|
630
|
+
this.draw();
|
|
631
|
+
},
|
|
632
|
+
{ passive: false },
|
|
633
|
+
);
|
|
634
|
+
c.addEventListener('dblclick', () => this.fit());
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
resize() {
|
|
638
|
+
const rect = this.canvas.parentElement.getBoundingClientRect();
|
|
639
|
+
const dpr = window.devicePixelRatio || 1;
|
|
640
|
+
const w = Math.max(1, rect.width);
|
|
641
|
+
const h = Math.max(1, rect.height);
|
|
642
|
+
// 右栏收起/展开会改变舞台宽度:把画面中心钉住,别让节点跑到左边去
|
|
643
|
+
if (this.w && this.h) {
|
|
644
|
+
this.view.x += (w - this.w) / 2;
|
|
645
|
+
this.view.y += (h - this.h) / 2;
|
|
646
|
+
}
|
|
647
|
+
this.w = w;
|
|
648
|
+
this.h = h;
|
|
649
|
+
this.canvas.width = Math.round(this.w * dpr);
|
|
650
|
+
this.canvas.height = Math.round(this.h * dpr);
|
|
651
|
+
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
652
|
+
this.draw();
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
toWorld(e) {
|
|
656
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
657
|
+
return { x: (e.clientX - rect.left - this.view.x) / this.view.k, y: (e.clientY - rect.top - this.view.y) / this.view.k };
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
pick(p) {
|
|
661
|
+
let best = null;
|
|
662
|
+
let bestD = Infinity;
|
|
663
|
+
for (const n of this.nodes) {
|
|
664
|
+
const d = Math.hypot(n.x - p.x, n.y - p.y);
|
|
665
|
+
if (d <= n.r + 6 / this.view.k && d < bestD) {
|
|
666
|
+
best = n;
|
|
667
|
+
bestD = d;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return best;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
setData(cards) {
|
|
674
|
+
const wasEmpty = this.nodes.length === 0;
|
|
675
|
+
const prev = new Map(this.nodes.map((n) => [n.id, n]));
|
|
676
|
+
const nodes = cards.map((card, i) => {
|
|
677
|
+
const old = prev.get(card.id);
|
|
678
|
+
const angle = i * 2.399963;
|
|
679
|
+
const radius = 40 + Math.sqrt(i) * 46;
|
|
680
|
+
return {
|
|
681
|
+
id: card.id,
|
|
682
|
+
card,
|
|
683
|
+
r: 5 + card.weight * 9,
|
|
684
|
+
x: old ? old.x : Math.cos(angle) * radius,
|
|
685
|
+
y: old ? old.y : Math.sin(angle) * radius,
|
|
686
|
+
vx: 0,
|
|
687
|
+
vy: 0,
|
|
688
|
+
};
|
|
689
|
+
});
|
|
690
|
+
const index = new Map(nodes.map((n) => [n.id, n]));
|
|
691
|
+
const links = [];
|
|
692
|
+
const byTag = new Map();
|
|
693
|
+
for (const n of nodes) {
|
|
694
|
+
for (const t of n.card.tags) {
|
|
695
|
+
if (!byTag.has(t)) byTag.set(t, []);
|
|
696
|
+
byTag.get(t).push(n);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
for (const [tag, group] of byTag) {
|
|
700
|
+
if (group.length < 2) continue;
|
|
701
|
+
for (let i = 1; i < group.length && i <= 5; i += 1) {
|
|
702
|
+
links.push({ a: group[0], b: group[i], w: 1, tag });
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
// 版本链:新卡 supersedes 旧卡。这条边比标签共现更有信息量,所以优先级更高——
|
|
706
|
+
// 两卡之间如果已经有标签边,就把它升级成版本链,不再画第二条重合的线。
|
|
707
|
+
// 方向按时间流:旧 → 新,箭头指向新卡。
|
|
708
|
+
const pairKey = (x, y) => (x.id < y.id ? `${x.id}|${y.id}` : `${y.id}|${x.id}`);
|
|
709
|
+
const seen = new Map(links.map((l) => [pairKey(l.a, l.b), l]));
|
|
710
|
+
for (const n of nodes) {
|
|
711
|
+
for (const oldId of n.card.supersedes ?? []) {
|
|
712
|
+
const target = index.get(oldId);
|
|
713
|
+
if (!target) continue;
|
|
714
|
+
const key = pairKey(target, n);
|
|
715
|
+
const exist = seen.get(key);
|
|
716
|
+
if (exist) {
|
|
717
|
+
exist.kind = 'supersede';
|
|
718
|
+
exist.w = 1.2;
|
|
719
|
+
exist.a = target;
|
|
720
|
+
exist.b = n;
|
|
721
|
+
} else {
|
|
722
|
+
const l = { a: target, b: n, w: 1.2, tag: null, kind: 'supersede' };
|
|
723
|
+
links.push(l);
|
|
724
|
+
seen.set(key, l);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
// 没有标签连线的节点,按同一天挂到最近的一个节点上,避免孤岛
|
|
729
|
+
const linked = new Set(links.flatMap((l) => [l.a.id, l.b.id]));
|
|
730
|
+
for (const n of nodes) {
|
|
731
|
+
if (linked.has(n.id)) continue;
|
|
732
|
+
const same = nodes
|
|
733
|
+
.filter((m) => m.id !== n.id && dayKey(m.card.createdAt) === dayKey(n.card.createdAt))
|
|
734
|
+
.sort((a, b) => Math.hypot(a.x - n.x, a.y - n.y) - Math.hypot(b.x - n.x, b.y - n.y))[0];
|
|
735
|
+
if (same) links.push({ a: n, b: same, w: 0.25, tag: null });
|
|
736
|
+
}
|
|
737
|
+
this.nodes = nodes;
|
|
738
|
+
this.links = links.map((l) => ({ ...l, a: index.get(l.a.id), b: index.get(l.b.id) })).filter((l) => l.a && l.b);
|
|
739
|
+
this.alpha = 1;
|
|
740
|
+
this.kick();
|
|
741
|
+
if (wasEmpty) {
|
|
742
|
+
this.fit();
|
|
743
|
+
this.fitted = true;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
kick() {
|
|
748
|
+
if (this.frame) return;
|
|
749
|
+
const loop = () => {
|
|
750
|
+
this.frame = 0;
|
|
751
|
+
const active = this.alpha > 0.02 || this.dragNode;
|
|
752
|
+
if (active) {
|
|
753
|
+
this.tick();
|
|
754
|
+
this.draw();
|
|
755
|
+
this.frame = requestAnimationFrame(loop);
|
|
756
|
+
} else {
|
|
757
|
+
this.draw();
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
this.frame = requestAnimationFrame(loop);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
tick() {
|
|
764
|
+
const nodes = this.nodes;
|
|
765
|
+
const links = this.links;
|
|
766
|
+
if (nodes.length > 800) {
|
|
767
|
+
this.alpha *= 0.9;
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const REP = 5200;
|
|
771
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
772
|
+
const a = nodes[i];
|
|
773
|
+
for (let j = i + 1; j < nodes.length; j += 1) {
|
|
774
|
+
const b = nodes[j];
|
|
775
|
+
let dx = b.x - a.x;
|
|
776
|
+
let dy = b.y - a.y;
|
|
777
|
+
let d2 = dx * dx + dy * dy;
|
|
778
|
+
if (d2 < 1) {
|
|
779
|
+
dx = (Math.random() - 0.5) * 2;
|
|
780
|
+
dy = (Math.random() - 0.5) * 2;
|
|
781
|
+
d2 = dx * dx + dy * dy;
|
|
782
|
+
}
|
|
783
|
+
const d = Math.sqrt(d2);
|
|
784
|
+
const f = (REP * (0.6 + a.card.weight * 0.8)) / Math.max(900, d2);
|
|
785
|
+
const fx = (dx / d) * f;
|
|
786
|
+
const fy = (dy / d) * f;
|
|
787
|
+
a.vx -= fx;
|
|
788
|
+
a.vy -= fy;
|
|
789
|
+
b.vx += fx;
|
|
790
|
+
b.vy += fy;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
for (const l of links) {
|
|
794
|
+
const dx = l.b.x - l.a.x;
|
|
795
|
+
const dy = l.b.y - l.a.y;
|
|
796
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
797
|
+
const target = 60 + 40 * (1 - l.w);
|
|
798
|
+
const f = (d - target) * 0.012 * (0.6 + l.w);
|
|
799
|
+
const fx = (dx / d) * f;
|
|
800
|
+
const fy = (dy / d) * f;
|
|
801
|
+
l.a.vx += fx;
|
|
802
|
+
l.a.vy += fy;
|
|
803
|
+
l.b.vx -= fx;
|
|
804
|
+
l.b.vy -= fy;
|
|
805
|
+
}
|
|
806
|
+
const focusId = this.hover ?? null;
|
|
807
|
+
for (const n of nodes) {
|
|
808
|
+
n.vx -= n.x * 0.0016;
|
|
809
|
+
n.vy -= n.y * 0.0016;
|
|
810
|
+
if (n === this.dragNode) {
|
|
811
|
+
n.vx = 0;
|
|
812
|
+
n.vy = 0;
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
n.vx *= 0.86;
|
|
816
|
+
n.vy *= 0.86;
|
|
817
|
+
n.x += n.vx;
|
|
818
|
+
n.y += n.vy;
|
|
819
|
+
}
|
|
820
|
+
if (focusId) {
|
|
821
|
+
const focus = nodes.find((n) => n.id === focusId);
|
|
822
|
+
if (focus) {
|
|
823
|
+
focus.vx *= 0.4;
|
|
824
|
+
focus.vy *= 0.4;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
this.alpha *= 0.972;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
fit() {
|
|
831
|
+
if (!this.nodes.length) {
|
|
832
|
+
this.view = { x: this.w / 2, y: this.h / 2, k: 1 };
|
|
833
|
+
this.draw();
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
let minX = Infinity;
|
|
837
|
+
let minY = Infinity;
|
|
838
|
+
let maxX = -Infinity;
|
|
839
|
+
let maxY = -Infinity;
|
|
840
|
+
for (const n of this.nodes) {
|
|
841
|
+
minX = Math.min(minX, n.x - n.r);
|
|
842
|
+
maxX = Math.max(maxX, n.x + n.r);
|
|
843
|
+
minY = Math.min(minY, n.y - n.r);
|
|
844
|
+
maxY = Math.max(maxY, n.y + n.r);
|
|
845
|
+
}
|
|
846
|
+
const padPx = 70;
|
|
847
|
+
const k = clamp(Math.min((this.w - padPx * 2) / Math.max(1, maxX - minX), (this.h - padPx * 2) / Math.max(1, maxY - minY)), 0.2, 1.8);
|
|
848
|
+
this.view.k = k;
|
|
849
|
+
this.view.x = this.w / 2 - ((minX + maxX) / 2) * k;
|
|
850
|
+
this.view.y = this.h / 2 - ((minY + maxY) / 2) * k;
|
|
851
|
+
this.draw();
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
draw() {
|
|
855
|
+
const ctx = this.ctx;
|
|
856
|
+
if (!ctx) return;
|
|
857
|
+
ctx.clearRect(0, 0, this.w, this.h);
|
|
858
|
+
if (!this.nodes.length) return;
|
|
859
|
+
const { x, y, k } = this.view;
|
|
860
|
+
ctx.save();
|
|
861
|
+
ctx.translate(x, y);
|
|
862
|
+
ctx.scale(k, k);
|
|
863
|
+
|
|
864
|
+
const hoverNeighbors = new Set();
|
|
865
|
+
if (this.hover) {
|
|
866
|
+
for (const l of this.links) {
|
|
867
|
+
if (l.a.id === this.hover) hoverNeighbors.add(l.b.id);
|
|
868
|
+
if (l.b.id === this.hover) hoverNeighbors.add(l.a.id);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
// 版本链两端的节点一定要带标签,否则「被取代的是什么」看不出来
|
|
872
|
+
const chainIds = new Set();
|
|
873
|
+
for (const l of this.links) {
|
|
874
|
+
if (l.kind !== 'supersede') continue;
|
|
875
|
+
chainIds.add(l.a.id);
|
|
876
|
+
chainIds.add(l.b.id);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
const P = palette();
|
|
880
|
+
const ink = P.ink;
|
|
881
|
+
const line = P.line;
|
|
882
|
+
for (const l of this.links) {
|
|
883
|
+
const dim = this.hover && l.a.id !== this.hover && l.b.id !== this.hover;
|
|
884
|
+
const sup = l.kind === 'supersede';
|
|
885
|
+
ctx.strokeStyle = sup ? ink : line;
|
|
886
|
+
ctx.globalAlpha = dim ? 0.07 : sup ? 0.45 : 0.16 + l.w * 0.22;
|
|
887
|
+
ctx.lineWidth = (sup ? 1.5 : 0.8 + l.w * 1.1) / k;
|
|
888
|
+
ctx.setLineDash(sup ? [4 / k, 3 / k] : []);
|
|
889
|
+
ctx.beginPath();
|
|
890
|
+
ctx.moveTo(l.a.x, l.a.y);
|
|
891
|
+
ctx.lineTo(l.b.x, l.b.y);
|
|
892
|
+
ctx.stroke();
|
|
893
|
+
if (sup) {
|
|
894
|
+
// 箭头指向新卡:这条线读作「旧的那条演进成了它」
|
|
895
|
+
const ang = Math.atan2(l.b.y - l.a.y, l.b.x - l.a.x);
|
|
896
|
+
const r = l.b.r + 3 / k;
|
|
897
|
+
const tipX = l.b.x - Math.cos(ang) * r;
|
|
898
|
+
const tipY = l.b.y - Math.sin(ang) * r;
|
|
899
|
+
const size = 5 / k;
|
|
900
|
+
ctx.setLineDash([]);
|
|
901
|
+
ctx.beginPath();
|
|
902
|
+
ctx.moveTo(tipX, tipY);
|
|
903
|
+
ctx.lineTo(tipX - Math.cos(ang - 0.42) * size, tipY - Math.sin(ang - 0.42) * size);
|
|
904
|
+
ctx.lineTo(tipX - Math.cos(ang + 0.42) * size, tipY - Math.sin(ang + 0.42) * size);
|
|
905
|
+
ctx.closePath();
|
|
906
|
+
ctx.fillStyle = ink;
|
|
907
|
+
ctx.fill();
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
ctx.setLineDash([]);
|
|
911
|
+
ctx.globalAlpha = 1;
|
|
912
|
+
|
|
913
|
+
for (const n of this.nodes) {
|
|
914
|
+
const c = P.kinds[n.card.kind] ?? ink;
|
|
915
|
+
const isSel = n.card.id === S.selected;
|
|
916
|
+
const isHover = n.card.id === this.hover;
|
|
917
|
+
const dim = this.hover && !isHover && !hoverNeighbors.has(n.card.id) && !isSel;
|
|
918
|
+
// 被版本链补进来的旧卡已经退休,压暗一档,别让人以为它还在用
|
|
919
|
+
const retired = n.card.status === 'retired';
|
|
920
|
+
const baseAlpha = dim ? 0.28 : retired ? 0.5 : 1;
|
|
921
|
+
ctx.globalAlpha = baseAlpha;
|
|
922
|
+
if (isSel || isHover) {
|
|
923
|
+
ctx.beginPath();
|
|
924
|
+
ctx.arc(n.x, n.y, n.r + 5 / k, 0, Math.PI * 2);
|
|
925
|
+
ctx.fillStyle = c;
|
|
926
|
+
ctx.globalAlpha = 0.16;
|
|
927
|
+
ctx.fill();
|
|
928
|
+
ctx.globalAlpha = baseAlpha;
|
|
929
|
+
}
|
|
930
|
+
ctx.beginPath();
|
|
931
|
+
ctx.arc(n.x, n.y, n.r, 0, Math.PI * 2);
|
|
932
|
+
ctx.fillStyle = c;
|
|
933
|
+
ctx.fill();
|
|
934
|
+
if (isSel) {
|
|
935
|
+
ctx.strokeStyle = ink;
|
|
936
|
+
ctx.lineWidth = 1.6 / k;
|
|
937
|
+
ctx.stroke();
|
|
938
|
+
}
|
|
939
|
+
const showLabel =
|
|
940
|
+
isSel || isHover
|
|
941
|
+
|| (S.showLabels && (chainIds.has(n.card.id) || k > 1.32 || this.nodes.length <= 16));
|
|
942
|
+
if (showLabel) {
|
|
943
|
+
ctx.globalAlpha = dim ? 0.3 : retired ? 0.55 : 0.95;
|
|
944
|
+
const size = Math.max(9.5, 11.5 / k);
|
|
945
|
+
ctx.font = `${size}px -apple-system, "PingFang SC", sans-serif`;
|
|
946
|
+
ctx.textAlign = 'center';
|
|
947
|
+
ctx.textBaseline = 'top';
|
|
948
|
+
const label = n.card.text.slice(0, 14) + (n.card.text.length > 14 ? '…' : '');
|
|
949
|
+
ctx.lineWidth = 3 / k;
|
|
950
|
+
ctx.strokeStyle = P.paper;
|
|
951
|
+
ctx.strokeText(label, n.x, n.y + n.r + 4 / k);
|
|
952
|
+
ctx.fillStyle = ink;
|
|
953
|
+
ctx.fillText(label, n.x, n.y + n.r + 4 / k);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
ctx.globalAlpha = 1;
|
|
957
|
+
ctx.restore();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
let graph = null;
|
|
962
|
+
|
|
963
|
+
function renderGraph() {
|
|
964
|
+
const canvas = $('#graph');
|
|
965
|
+
if (!graph) graph = new Graph(canvas);
|
|
966
|
+
graph.onSelect = (id) => selectCard(id);
|
|
967
|
+
graph.showLabels = S.showLabels;
|
|
968
|
+
const base = filtered();
|
|
969
|
+
// 版本链的另一头通常是已退休的旧卡,默认筛选看不到——补进图里,边才画得出来
|
|
970
|
+
const list = withSuperseded(base);
|
|
971
|
+
$('#graph-empty').hidden = base.length > 0;
|
|
972
|
+
graph.draw();
|
|
973
|
+
// 结构变化才重排;只改选中不重排
|
|
974
|
+
const signature = list.map((c) => c.id).join(',');
|
|
975
|
+
if (signature !== graph.signature) {
|
|
976
|
+
graph.signature = signature;
|
|
977
|
+
graph.setData(list);
|
|
978
|
+
} else {
|
|
979
|
+
graph.nodes = graph.nodes.filter((n) => list.some((c) => c.id === n.id));
|
|
980
|
+
graph.kick();
|
|
981
|
+
}
|
|
982
|
+
renderLegend();
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
function renderLegend() {
|
|
986
|
+
const box = $('#graph-legend');
|
|
987
|
+
const counts = {};
|
|
988
|
+
for (const c of filtered()) counts[c.kind] = (counts[c.kind] || 0) + 1;
|
|
989
|
+
const hasChain = withSuperseded(filtered()).some((c) => (c.supersedes ?? []).length);
|
|
990
|
+
box.innerHTML =
|
|
991
|
+
'<span style="color:var(--ink-dim)">大小=权重</span>' +
|
|
992
|
+
KINDS.filter((k) => counts[k.id]).map((k) => `<span><i style="background:var(${k.css})"></i>${k.label} ${counts[k.id]}</span>`).join('') +
|
|
993
|
+
(hasChain ? '<span style="color:var(--ink-dim)">虚线箭头=被新版本接替</span>' : '');
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/** 把被在用卡 supersedes 掉的旧卡补进图。它们默认已退休、不在筛选结果里,
|
|
997
|
+
* 但版本链恰恰是这个视图最该看得见的关系。 */
|
|
998
|
+
function withSuperseded(list) {
|
|
999
|
+
const ids = new Set(list.map((c) => c.id));
|
|
1000
|
+
const extra = [];
|
|
1001
|
+
for (const c of list) {
|
|
1002
|
+
for (const oldId of c.supersedes ?? []) {
|
|
1003
|
+
if (ids.has(oldId)) continue;
|
|
1004
|
+
const old = cards().find((x) => x.id === oldId);
|
|
1005
|
+
if (!old) continue;
|
|
1006
|
+
ids.add(oldId);
|
|
1007
|
+
extra.push(old);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return extra.length ? [...list, ...extra] : list;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
$('#graph-fit').addEventListener('click', () => graph?.fit());
|
|
1014
|
+
$('#graph-relayout').addEventListener('click', () => {
|
|
1015
|
+
if (!graph) return;
|
|
1016
|
+
graph.fitted = false;
|
|
1017
|
+
graph.nodes.forEach((n, i) => {
|
|
1018
|
+
const angle = i * 2.399963;
|
|
1019
|
+
const radius = 40 + Math.sqrt(i) * 46;
|
|
1020
|
+
n.x = Math.cos(angle) * radius;
|
|
1021
|
+
n.y = Math.sin(angle) * radius;
|
|
1022
|
+
n.vx = 0;
|
|
1023
|
+
n.vy = 0;
|
|
1024
|
+
});
|
|
1025
|
+
graph.alpha = 1;
|
|
1026
|
+
graph.kick();
|
|
1027
|
+
setTimeout(() => graph?.fit(), 700);
|
|
1028
|
+
});
|
|
1029
|
+
$('#graph-labels').addEventListener('change', (e) => {
|
|
1030
|
+
S.showLabels = e.target.checked;
|
|
1031
|
+
if (graph) graph.showLabels = S.showLabels;
|
|
1032
|
+
graph?.draw();
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
/* ── 时间线 ─────────────────────────────────────────── */
|
|
1036
|
+
|
|
1037
|
+
function renderTimeline() {
|
|
1038
|
+
const host = $('#view-timeline');
|
|
1039
|
+
const list = filtered().sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
1040
|
+
if (!list.length) {
|
|
1041
|
+
host.innerHTML = '<div class="empty"><p>这个条件下没有记忆。</p><p class="dim">放宽筛选,或者清空搜索。</p></div>';
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
const groups = new Map();
|
|
1045
|
+
for (const c of list) {
|
|
1046
|
+
const key = dayKey(c.createdAt);
|
|
1047
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
1048
|
+
groups.get(key).push(c);
|
|
1049
|
+
}
|
|
1050
|
+
host.innerHTML = [...groups.entries()]
|
|
1051
|
+
.map(
|
|
1052
|
+
([key, items]) => `
|
|
1053
|
+
<div class="day-group">
|
|
1054
|
+
<div class="day-head"><b>${dayLabel(key)}</b><span>${items.length} 条</span></div>
|
|
1055
|
+
${items
|
|
1056
|
+
.map((c) => {
|
|
1057
|
+
const k = kindOf(c.kind);
|
|
1058
|
+
return `<div class="tl-item ${S.selected === c.id ? 'sel' : ''} ${isRetired(c) ? 'retired' : ''}" data-id="${c.id}">
|
|
1059
|
+
<span class="tl-dot" style="background:var(${k.css})"></span>
|
|
1060
|
+
<div class="tl-body">
|
|
1061
|
+
<div class="tl-text">${highlight(c.text, S.query)}</div>
|
|
1062
|
+
<div class="tl-meta">
|
|
1063
|
+
<span>${k.label}</span>
|
|
1064
|
+
${c.dueAt ? `<span>· ${c.done ? '已完成' : '截止'} ${fmtTime(c.dueAt)}</span>` : ''}
|
|
1065
|
+
${c.tags.map((t) => `<span class="tag">${esc(t)}</span>`).join('')}
|
|
1066
|
+
</div>
|
|
1067
|
+
</div>
|
|
1068
|
+
<div class="tl-right" title="${fmtTime(c.createdAt)}">
|
|
1069
|
+
${fmtTime(c.createdAt).slice(6)}
|
|
1070
|
+
<div class="wbar"><i style="width:${Math.round(c.weight * 100)}%"></i></div>
|
|
1071
|
+
</div>
|
|
1072
|
+
</div>`;
|
|
1073
|
+
})
|
|
1074
|
+
.join('')}
|
|
1075
|
+
</div>`,
|
|
1076
|
+
)
|
|
1077
|
+
.join('');
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/* ── 列表 ───────────────────────────────────────────── */
|
|
1081
|
+
|
|
1082
|
+
const COLS = [
|
|
1083
|
+
{ key: 'kind', label: '类型', width: '76px' },
|
|
1084
|
+
{ key: 'text', label: '内容' },
|
|
1085
|
+
{ key: 'weight', label: '权重', width: '92px' },
|
|
1086
|
+
{ key: 'source', label: '来源', width: '132px' },
|
|
1087
|
+
{ key: 'tags', label: '标签', width: '120px' },
|
|
1088
|
+
{ key: 'createdAt', label: '记于', width: '82px' },
|
|
1089
|
+
{ key: 'uses', label: '用过', width: '48px' },
|
|
1090
|
+
];
|
|
1091
|
+
|
|
1092
|
+
/* 空列不占地方:全库没标签、没人被用过的时候,这两列先不出现 */
|
|
1093
|
+
function activeCols() {
|
|
1094
|
+
const all = liveCards();
|
|
1095
|
+
const hasTags = all.some((c) => c.tags.length > 0);
|
|
1096
|
+
const hasUses = all.some((c) => (c.uses || 0) > 0);
|
|
1097
|
+
return COLS.filter((c) => (c.key === 'tags' ? hasTags : c.key === 'uses' ? hasUses : true));
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
function renderTable() {
|
|
1101
|
+
const host = $('#view-table');
|
|
1102
|
+
const cols = activeCols();
|
|
1103
|
+
const { key, dir } = S.sort;
|
|
1104
|
+
const list = filtered().sort((a, b) => {
|
|
1105
|
+
const va = key === 'tags' ? a.tags.join(',') : a[key] ?? '';
|
|
1106
|
+
const vb = key === 'tags' ? b.tags.join(',') : b[key] ?? '';
|
|
1107
|
+
if (typeof va === 'number' && typeof vb === 'number') return (va - vb) * dir;
|
|
1108
|
+
return String(va).localeCompare(String(vb)) * dir;
|
|
1109
|
+
});
|
|
1110
|
+
host.innerHTML = `
|
|
1111
|
+
<table class="grid" style="min-width:${cols.reduce((n, c) => n + (parseInt(c.width, 10) || 0), 0) + 280}px">
|
|
1112
|
+
<thead><tr>
|
|
1113
|
+
${cols
|
|
1114
|
+
.map(
|
|
1115
|
+
(c) =>
|
|
1116
|
+
`<th style="${c.width ? `width:${c.width}` : ''}" data-sort="${c.key}">${c.label}${
|
|
1117
|
+
key === c.key ? `<span class="arrow">${dir > 0 ? '↑' : '↓'}</span>` : ''
|
|
1118
|
+
}</th>`,
|
|
1119
|
+
)
|
|
1120
|
+
.join('')}
|
|
1121
|
+
</tr></thead>
|
|
1122
|
+
<tbody>
|
|
1123
|
+
${
|
|
1124
|
+
list.length
|
|
1125
|
+
? list
|
|
1126
|
+
.map((c) => {
|
|
1127
|
+
const k = kindOf(c.kind);
|
|
1128
|
+
return `<tr data-id="${c.id}" class="${S.selected === c.id ? 'sel' : ''} ${c.done ? 'done' : ''} ${
|
|
1129
|
+
isRetired(c) ? 'retired' : ''
|
|
1130
|
+
}">
|
|
1131
|
+
<td class="nowrap"><span class="kind-pill"><i style="background:var(${k.css})"></i>${k.label}</span></td>
|
|
1132
|
+
<td class="text">${highlight(c.text, S.query)}</td>
|
|
1133
|
+
<td class="nowrap"><span class="wt" title="权重 ${c.weight.toFixed(2)}"><i class="wt-bar"><b style="width:${Math.round(
|
|
1134
|
+
c.weight * 100,
|
|
1135
|
+
)}%"></b></i><em>${c.weight.toFixed(2)}</em></span></td>
|
|
1136
|
+
<td class="nowrap src" title="${esc(sourceLabel(c.source))}">${esc(sourceShort(c.source))}</td>
|
|
1137
|
+
${
|
|
1138
|
+
cols.some((x) => x.key === 'tags')
|
|
1139
|
+
? `<td><div class="tag-list">${c.tags
|
|
1140
|
+
.slice(0, 4)
|
|
1141
|
+
.map((t) => `<span class="tag">${esc(t)}</span>`)
|
|
1142
|
+
.join('')}</div></td>`
|
|
1143
|
+
: ''
|
|
1144
|
+
}
|
|
1145
|
+
<td class="nowrap time" title="${fmtTime(c.createdAt)}">${relative(c.createdAt)}</td>
|
|
1146
|
+
${cols.some((x) => x.key === 'uses') ? `<td class="nowrap time">${c.uses || 0}</td>` : ''}
|
|
1147
|
+
</tr>`;
|
|
1148
|
+
})
|
|
1149
|
+
.join('')
|
|
1150
|
+
: `<tr><td colspan="${cols.length}" style="padding:28px;text-align:center;color:var(--ink-dim)">没有符合条件的记忆</td></tr>`
|
|
1151
|
+
}
|
|
1152
|
+
</tbody>
|
|
1153
|
+
</table>`;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/* ── 对话原文 ───────────────────────────────────────── */
|
|
1157
|
+
|
|
1158
|
+
function archiveBar() {
|
|
1159
|
+
const retention = S.snap?.archive?.retention ?? 90;
|
|
1160
|
+
const hint = S.withArchive
|
|
1161
|
+
? `连${retention ? ` ${retention} 天内` : '全部'}的归档一起搜`
|
|
1162
|
+
: '只搜最近 7 天;更早的句子在归档里,勾上就能搜到';
|
|
1163
|
+
return `<div class="turns-bar">
|
|
1164
|
+
<label class="switch"><input type="checkbox" id="turns-archive" ${S.withArchive ? 'checked' : ''} /><span>含归档</span></label>
|
|
1165
|
+
<span class="dim">${hint}</span>
|
|
1166
|
+
</div>`;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
function turnRow(t) {
|
|
1170
|
+
return `<div class="turn">
|
|
1171
|
+
<div><time>${fmtTime(t.ts).slice(6)}</time><div class="who">${esc(shortSender(t.sender))}</div></div>
|
|
1172
|
+
<div class="msg">${highlight(t.text.slice(0, 600), S.query)}</div>
|
|
1173
|
+
</div>`;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function bindArchiveToggle() {
|
|
1177
|
+
const box = $('#turns-archive');
|
|
1178
|
+
if (!box) return;
|
|
1179
|
+
box.addEventListener('change', () => {
|
|
1180
|
+
S.withArchive = box.checked;
|
|
1181
|
+
localStorage.setItem('mcore-archive', S.withArchive ? '1' : '0');
|
|
1182
|
+
S.archive = null;
|
|
1183
|
+
S.archiveQ = '';
|
|
1184
|
+
renderTurns();
|
|
1185
|
+
if (S.withArchive && S.query) void ensureArchive(S.query);
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
/** 归档不进快照,勾了「含归档」且有搜索词时才按需拉一次。 */
|
|
1190
|
+
async function ensureArchive(query) {
|
|
1191
|
+
if (!S.withArchive || !query) return;
|
|
1192
|
+
if (S.archiveQ === query && S.archive) return;
|
|
1193
|
+
S.archiveQ = query;
|
|
1194
|
+
S.archive = null;
|
|
1195
|
+
const days = S.snap?.archive?.retention || 3650;
|
|
1196
|
+
try {
|
|
1197
|
+
const rows = await api(`/api/archive?q=${encodeURIComponent(query)}&days=${days}&limit=40`);
|
|
1198
|
+
if (S.query !== query) return;
|
|
1199
|
+
S.archive = Array.isArray(rows) ? rows : [];
|
|
1200
|
+
} catch (err) {
|
|
1201
|
+
if (S.query !== query) return;
|
|
1202
|
+
S.archive = [];
|
|
1203
|
+
toast(`翻归档失败:${err.message}`, true);
|
|
1204
|
+
}
|
|
1205
|
+
if (S.view === 'turns') renderTurns();
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
function renderTurns() {
|
|
1209
|
+
const host = $('#view-turns');
|
|
1210
|
+
const toks = tokens(S.query);
|
|
1211
|
+
const matched = (S.snap?.turns ?? []).filter((t) => matches(t.text, toks)).slice().reverse();
|
|
1212
|
+
const wantArchive = S.withArchive && Boolean(S.query);
|
|
1213
|
+
const archiving = wantArchive && (S.archiveQ !== S.query || S.archive === null);
|
|
1214
|
+
const archived = wantArchive && S.archiveQ === S.query ? (S.archive ?? []) : [];
|
|
1215
|
+
|
|
1216
|
+
if (!matched.length && !archived.length && !archiving) {
|
|
1217
|
+
const dbg = S.snap?.state?.captureDebug;
|
|
1218
|
+
let hint = '在插件设置里确认「存对话原文」是开的,聊几句就会出现在这里。';
|
|
1219
|
+
if (dbg && dbg.scanned && !dbg.kept) {
|
|
1220
|
+
const keys = (dbg.keys ?? []).map((k) => esc(k)).join('、') || '无';
|
|
1221
|
+
hint = `上次扫了 ${dbg.scanned} 条外部事件,一条都没留下——被「算作对话的来源」白名单挡掉了(样例:${keys}),把这几个 key 加进设置里的正则就行。`;
|
|
1222
|
+
}
|
|
1223
|
+
const sub = S.query
|
|
1224
|
+
? S.withArchive
|
|
1225
|
+
? '归档里也没有。'
|
|
1226
|
+
: '最近 7 天里没有。更早的句子在归档里,勾上「含归档」再搜一次。'
|
|
1227
|
+
: hint;
|
|
1228
|
+
host.innerHTML = `<div class="turns-wrap">${archiveBar()}<div class="empty"><p>${
|
|
1229
|
+
S.query ? '没有匹配的对话。' : '还没有存下对话原文。'
|
|
1230
|
+
}</p><p class="dim">${sub}</p></div></div>`;
|
|
1231
|
+
bindArchiveToggle();
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
// 全量拼 DOM 在 1000 条时会明显卡:先渲染最近 200 条,要更多再点。
|
|
1235
|
+
// 分组按匹配总数算,组头显示「已显示/该天总数」,不让人误以为那天只有这么几句。
|
|
1236
|
+
const groups = new Map();
|
|
1237
|
+
for (const t of matched) {
|
|
1238
|
+
const key = dayKey(t.ts);
|
|
1239
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
1240
|
+
groups.get(key).push(t);
|
|
1241
|
+
}
|
|
1242
|
+
const limit = Math.max(TURNS_PAGE, Math.min(S.turnsLimit ?? TURNS_PAGE, matched.length));
|
|
1243
|
+
let remain = limit;
|
|
1244
|
+
const parts = [];
|
|
1245
|
+
for (const [key, items] of groups) {
|
|
1246
|
+
if (remain <= 0) break;
|
|
1247
|
+
const take = items.slice(0, remain);
|
|
1248
|
+
remain -= take.length;
|
|
1249
|
+
parts.push(`
|
|
1250
|
+
<div class="day-group">
|
|
1251
|
+
<div class="day-head"><b>${dayLabel(key)}</b><span>${
|
|
1252
|
+
take.length === items.length ? `${items.length} 条` : `${take.length} / ${items.length} 条`
|
|
1253
|
+
}</span></div>
|
|
1254
|
+
${take.map(turnRow).join('')}
|
|
1255
|
+
</div>`);
|
|
1256
|
+
}
|
|
1257
|
+
// 归档命中按天分组:行里只显示时分,日期靠组头,避免窄列里塞不下「09-28 08:22」
|
|
1258
|
+
const archGroups = new Map();
|
|
1259
|
+
for (const t of archived) {
|
|
1260
|
+
const key = dayKey(t.ts);
|
|
1261
|
+
if (!archGroups.has(key)) archGroups.set(key, []);
|
|
1262
|
+
archGroups.get(key).push(t);
|
|
1263
|
+
}
|
|
1264
|
+
const archiveBlock = archiving
|
|
1265
|
+
? '<div class="day-group archive"><div class="day-head"><b>更早 · 归档</b><span>搜索中…</span></div></div>'
|
|
1266
|
+
: archGroups.size
|
|
1267
|
+
? `<div class="archive-head">更早 · 归档<span>${archived.length} 条</span></div>${[...archGroups.entries()]
|
|
1268
|
+
.map(
|
|
1269
|
+
([key, items]) => `<div class="day-group archive">
|
|
1270
|
+
<div class="day-head"><b>${dayLabel(key)}</b><span>${items.length} 条</span></div>
|
|
1271
|
+
${items.map((t) => turnRow(t)).join('')}
|
|
1272
|
+
</div>`,
|
|
1273
|
+
)
|
|
1274
|
+
.join('')}`
|
|
1275
|
+
: wantArchive
|
|
1276
|
+
? '<p class="turns-none dim">归档里没有匹配的句子。</p>'
|
|
1277
|
+
: '';
|
|
1278
|
+
const more =
|
|
1279
|
+
matched.length > limit
|
|
1280
|
+
? `<button class="btn turns-more" id="turns-more">还有 ${matched.length - limit} 条 · 继续加载</button>`
|
|
1281
|
+
: '';
|
|
1282
|
+
host.innerHTML = `<div class="turns-wrap">${archiveBar()}${parts.join('')}${archiveBlock}${more}</div>`;
|
|
1283
|
+
bindArchiveToggle();
|
|
1284
|
+
$('#turns-more')?.addEventListener('click', () => {
|
|
1285
|
+
S.turnsLimit = limit + TURNS_PAGE;
|
|
1286
|
+
renderTurns();
|
|
1287
|
+
});
|
|
1288
|
+
if (archiving) void ensureArchive(S.query);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function shortSender(key) {
|
|
1292
|
+
const raw = String(key ?? '');
|
|
1293
|
+
const base = raw.split(/[.:]/)[0];
|
|
1294
|
+
const map = { starpost: '星邮', qq: 'QQ', private: 'QQ 私聊', 'desktop-pet': '桌宠' };
|
|
1295
|
+
return map[base] ?? (raw || '—').slice(0, 12);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/* ── 工作区文件 ─────────────────────────────────────── */
|
|
1299
|
+
|
|
1300
|
+
async function ensureDocs() {
|
|
1301
|
+
if (S.docs || S.docsLoading) return;
|
|
1302
|
+
S.docsLoading = true;
|
|
1303
|
+
try {
|
|
1304
|
+
const data = await api('/api/docs');
|
|
1305
|
+
S.docs = data;
|
|
1306
|
+
} catch (err) {
|
|
1307
|
+
S.docs = { roots: [], files: [] };
|
|
1308
|
+
toast(`读不到文件列表:${err.message}`, true);
|
|
1309
|
+
} finally {
|
|
1310
|
+
S.docsLoading = false;
|
|
1311
|
+
if (S.view === 'docs') renderDocs();
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
function renderDocs() {
|
|
1316
|
+
const host = $('#view-docs');
|
|
1317
|
+
if (!S.snap?.docs?.enabled) {
|
|
1318
|
+
host.innerHTML = '<div class="docs-wrap"><div class="empty"><p>没有开启工作区检索。</p><p class="dim">在插件设置里打开「连工作区笔记一起搜」,设好目录。</p></div></div>';
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
if (!S.docs) {
|
|
1322
|
+
host.innerHTML = '<div class="docs-wrap"><div class="empty"><p>正在读目录…</p></div></div>';
|
|
1323
|
+
ensureDocs();
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const toks = tokens(S.query);
|
|
1327
|
+
const files = S.docs.files.filter((f) => matches(f.rel, toks));
|
|
1328
|
+
host.innerHTML = `<div class="docs-wrap">
|
|
1329
|
+
<div class="hint" style="margin-bottom:10px;color:var(--ink-dim);font-size:11px">
|
|
1330
|
+
${S.docs.roots.length} 个目录 · ${S.docs.files.length} 个文件(只读,点开看内容)
|
|
1331
|
+
</div>
|
|
1332
|
+
${
|
|
1333
|
+
files.length
|
|
1334
|
+
? files
|
|
1335
|
+
.map(
|
|
1336
|
+
(f) => `<div class="doc-item ${S.docSel === f.path ? 'sel' : ''}" data-path="${esc(f.path)}">
|
|
1337
|
+
<div><div class="name">${highlight(f.rel, S.query)}</div><div class="path">${fmtTime(new Date(f.mtimeMs).toISOString())} 改过</div></div>
|
|
1338
|
+
<div class="size">${f.chars} 字</div>
|
|
1339
|
+
</div>`,
|
|
1340
|
+
)
|
|
1341
|
+
.join('')
|
|
1342
|
+
: '<div class="empty" style="position:static;padding:30px"><p>没有匹配的文件。</p></div>'
|
|
1343
|
+
}
|
|
1344
|
+
</div>`;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
async function openDoc(path) {
|
|
1348
|
+
S.docSel = path;
|
|
1349
|
+
S.docText = null;
|
|
1350
|
+
setInspCollapsed(false);
|
|
1351
|
+
renderDocs();
|
|
1352
|
+
renderInspector();
|
|
1353
|
+
try {
|
|
1354
|
+
const doc = await api(`/api/doc?path=${encodeURIComponent(path)}`);
|
|
1355
|
+
S.docText = doc;
|
|
1356
|
+
renderInspector();
|
|
1357
|
+
} catch (err) {
|
|
1358
|
+
toast(`打不开:${err.message}`, true);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/* ── 详情栏 ─────────────────────────────────────────── */
|
|
1363
|
+
|
|
1364
|
+
function renderInspector() {
|
|
1365
|
+
if (S.view === 'docs' && S.docSel) return renderDocInspector();
|
|
1366
|
+
const card = selectedCard();
|
|
1367
|
+
if (!card) return renderOverview();
|
|
1368
|
+
const k = kindOf(card.kind);
|
|
1369
|
+
const related = relatedTo(card);
|
|
1370
|
+
el.inspBody.innerHTML = `
|
|
1371
|
+
<div class="insp-head">
|
|
1372
|
+
<span class="card-kind"><i style="background:var(${k.css})"></i>${k.label}</span>
|
|
1373
|
+
${isRetired(card) ? '<span class="card-kind retired">已退休</span>' : ''}
|
|
1374
|
+
<div style="display:flex;gap:4px">
|
|
1375
|
+
${isRetired(card) ? '' : `<button class="btn tiny ghost" id="btn-edit">${S.editing ? '取消' : '编辑'}</button>`}
|
|
1376
|
+
<button class="icon-btn tiny" id="btn-copy" title="复制内容">⧉</button>
|
|
1377
|
+
<button class="icon-btn tiny" id="btn-insp-collapse" title="收起右栏 (I)" aria-label="收起右栏">›</button>
|
|
1378
|
+
</div>
|
|
1379
|
+
</div>
|
|
1380
|
+
${
|
|
1381
|
+
S.editing
|
|
1382
|
+
? `<div class="editor">
|
|
1383
|
+
<textarea id="edit-text"></textarea>
|
|
1384
|
+
<div class="row">
|
|
1385
|
+
<div><div class="label">类型</div>
|
|
1386
|
+
<select id="edit-kind">${KINDS.map((x) => `<option value="${x.id}" ${x.id === card.kind ? 'selected' : ''}>${x.label}</option>`).join('')}</select>
|
|
1387
|
+
</div>
|
|
1388
|
+
<div><div class="label">权重 <b id="edit-weight-val">${card.weight.toFixed(2)}</b></div>
|
|
1389
|
+
<input id="edit-weight" type="range" min="0" max="1" step="0.05" value="${card.weight}" />
|
|
1390
|
+
</div>
|
|
1391
|
+
</div>
|
|
1392
|
+
<div><div class="label">标签(逗号分隔,最多 8 个)</div><input id="edit-tags" type="text" value="${esc(card.tags.join(', '))}" /></div>
|
|
1393
|
+
<div><div class="label">截止(承诺用,可留空)</div><input id="edit-due" type="datetime-local" value="${card.dueAt ? toLocalInput(card.dueAt) : ''}" /></div>
|
|
1394
|
+
<div class="row">
|
|
1395
|
+
<button class="btn primary" id="btn-save">保存</button>
|
|
1396
|
+
${card.kind === 'promise' ? `<button class="btn" id="btn-done">${card.done ? '标为未完成' : '标为完成'}</button>` : ''}
|
|
1397
|
+
</div>
|
|
1398
|
+
</div>`
|
|
1399
|
+
: `<div class="card-text">${highlight(card.text, S.query)}</div>`
|
|
1400
|
+
}
|
|
1401
|
+
<div class="card-meta">
|
|
1402
|
+
<div class="kv"><span>记于</span><b>${fmtTime(card.createdAt)} · ${relative(card.createdAt)}</b></div>
|
|
1403
|
+
<div class="kv"><span>权重</span><b>${card.weight.toFixed(2)}</b></div>
|
|
1404
|
+
<div class="kv"><span>来源</span><b>${esc(sourceLabel(card.source))}</b></div>
|
|
1405
|
+
<div class="kv"><span>被想起</span><b>${card.uses || 0} 次${card.lastUsedAt ? ` · 最近 ${relative(card.lastUsedAt)}` : ''}</b></div>
|
|
1406
|
+
${card.dueAt ? `<div class="kv"><span>${card.done ? '已完成' : '截止'}</span><b>${fmtTime(card.dueAt)}</b></div>` : ''}
|
|
1407
|
+
<div class="kv"><span>编号</span><b style="font-family:var(--mono);font-size:11px">${card.id.slice(0, 8)}</b></div>
|
|
1408
|
+
</div>
|
|
1409
|
+
<div class="card-actions">
|
|
1410
|
+
<button class="btn tiny" id="btn-ask">相关记忆</button>
|
|
1411
|
+
${
|
|
1412
|
+
isRetired(card)
|
|
1413
|
+
? `<button class="btn tiny" id="btn-restore">恢复这条</button>`
|
|
1414
|
+
: `<button class="btn tiny" id="btn-retire">退休</button>`
|
|
1415
|
+
}
|
|
1416
|
+
</div>
|
|
1417
|
+
${lineageHtml(card)}
|
|
1418
|
+
${
|
|
1419
|
+
related.length
|
|
1420
|
+
? `<div class="related"><h3>相关的 ${related.length} 条</h3>${related
|
|
1421
|
+
.map(
|
|
1422
|
+
(r) => `<button class="related-item" data-goto="${r.card.id}">${esc(r.card.text.slice(0, 46))}${
|
|
1423
|
+
r.card.text.length > 46 ? '…' : ''
|
|
1424
|
+
}<span class="why">${esc(r.why)}</span></button>`,
|
|
1425
|
+
)
|
|
1426
|
+
.join('')}</div>`
|
|
1427
|
+
: ''
|
|
1428
|
+
}
|
|
1429
|
+
`;
|
|
1430
|
+
|
|
1431
|
+
if (S.editing) {
|
|
1432
|
+
$('#edit-text').value = card.text;
|
|
1433
|
+
$('#edit-weight').addEventListener('input', (e) => {
|
|
1434
|
+
$('#edit-weight-val').textContent = Number(e.target.value).toFixed(2);
|
|
1435
|
+
});
|
|
1436
|
+
$('#btn-save').addEventListener('click', () => saveCard(card));
|
|
1437
|
+
const doneBtn = $('#btn-done');
|
|
1438
|
+
if (doneBtn) doneBtn.addEventListener('click', () => patchCard(card.id, { done: !card.done }, card.done ? '已标为未完成' : '已标为完成'));
|
|
1439
|
+
}
|
|
1440
|
+
$('#btn-edit')?.addEventListener('click', () => {
|
|
1441
|
+
S.editing = !S.editing;
|
|
1442
|
+
renderInspector();
|
|
1443
|
+
});
|
|
1444
|
+
$('#btn-copy').addEventListener('click', async () => {
|
|
1445
|
+
try {
|
|
1446
|
+
await navigator.clipboard.writeText(card.text);
|
|
1447
|
+
toast('已复制');
|
|
1448
|
+
} catch {
|
|
1449
|
+
toast('复制失败,浏览器不给剪贴板权限', true);
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
// 彻底删除只在维护面板 → 回收站里给:详情栏紧挨「退休」,误触一次就没了
|
|
1453
|
+
const retireBtn = $('#btn-retire');
|
|
1454
|
+
if (retireBtn) {
|
|
1455
|
+
retireBtn.addEventListener('click', async () => {
|
|
1456
|
+
try {
|
|
1457
|
+
await api(`/api/cards/${card.id}/retire`, { method: 'POST', body: '{}' });
|
|
1458
|
+
toast('已退休:不再参与检索,可在「已退休」里恢复');
|
|
1459
|
+
await load();
|
|
1460
|
+
renderInspector();
|
|
1461
|
+
} catch (err) {
|
|
1462
|
+
toast(`操作失败:${err.message}`, true);
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
const restoreBtn = $('#btn-restore');
|
|
1467
|
+
if (restoreBtn) {
|
|
1468
|
+
restoreBtn.addEventListener('click', async () => {
|
|
1469
|
+
try {
|
|
1470
|
+
await api(`/api/cards/${card.id}/restore`, { method: 'POST', body: '{}' });
|
|
1471
|
+
toast('已恢复');
|
|
1472
|
+
await load();
|
|
1473
|
+
renderInspector();
|
|
1474
|
+
} catch (err) {
|
|
1475
|
+
toast(`操作失败:${err.message}`, true);
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
$('#btn-ask').addEventListener('click', () => {
|
|
1480
|
+
S.query = card.tags[0] ?? card.text.slice(0, 4);
|
|
1481
|
+
el.search.value = S.query;
|
|
1482
|
+
render();
|
|
1483
|
+
});
|
|
1484
|
+
el.inspector.querySelectorAll('[data-goto]').forEach((btn) => {
|
|
1485
|
+
btn.addEventListener('click', () => selectCard(btn.dataset.goto));
|
|
1486
|
+
});
|
|
1487
|
+
bindInspCollapse();
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
function renderDocInspector() {
|
|
1491
|
+
const doc = S.docText;
|
|
1492
|
+
el.inspBody.innerHTML = `
|
|
1493
|
+
<div class="insp-head">
|
|
1494
|
+
<span class="card-kind">文件</span>
|
|
1495
|
+
<div style="display:flex;gap:4px">
|
|
1496
|
+
<button class="icon-btn tiny" id="btn-insp-collapse" title="收起右栏 (I)" aria-label="收起右栏">›</button>
|
|
1497
|
+
<button class="icon-btn tiny" id="doc-close" title="关闭">×</button>
|
|
1498
|
+
</div>
|
|
1499
|
+
</div>
|
|
1500
|
+
${doc ? `<div class="card-text" style="max-height:60vh;overflow:auto;font-size:12.5px">${esc(doc.text)}</div>
|
|
1501
|
+
<div class="card-meta"><div class="kv"><span>路径</span><b style="font-size:10.5px;word-break:break-all">${esc(doc.rel)}</b></div></div>`
|
|
1502
|
+
: '<div class="card-text" style="color:var(--ink-dim)">正在读…</div>'}
|
|
1503
|
+
`;
|
|
1504
|
+
bindInspCollapse();
|
|
1505
|
+
$('#doc-close').addEventListener('click', () => {
|
|
1506
|
+
S.docSel = null;
|
|
1507
|
+
S.docText = null;
|
|
1508
|
+
setInspCollapsed(true);
|
|
1509
|
+
render();
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
function renderOverview() {
|
|
1514
|
+
const st = S.snap?.stats;
|
|
1515
|
+
const list = filtered();
|
|
1516
|
+
const kindRows = KINDS.map((k) => ({ ...k, n: st?.byKind?.[k.id] ?? 0 }));
|
|
1517
|
+
const maxKind = Math.max(1, ...kindRows.map((k) => k.n));
|
|
1518
|
+
const recent = [...list].sort((a, b) => b.createdAt.localeCompare(a.createdAt)).slice(0, 7);
|
|
1519
|
+
const plans = S.snap?.plans ?? [];
|
|
1520
|
+
el.inspBody.innerHTML = `
|
|
1521
|
+
<div class="insp-head">
|
|
1522
|
+
<h3 style="margin:0">概览</h3>
|
|
1523
|
+
<button class="icon-btn tiny" id="btn-insp-collapse" title="收起右栏 (I)" aria-label="收起右栏">›</button>
|
|
1524
|
+
</div>
|
|
1525
|
+
<div class="dist">
|
|
1526
|
+
${kindRows
|
|
1527
|
+
.map(
|
|
1528
|
+
(k) => `<div class="row"><span>${k.label}</span>
|
|
1529
|
+
<span class="track"><i style="width:${(k.n / maxKind) * 100}%;background:var(${k.css})"></i></span>
|
|
1530
|
+
<b>${k.n}</b></div>`,
|
|
1531
|
+
)
|
|
1532
|
+
.join('')}
|
|
1533
|
+
</div>
|
|
1534
|
+
<div style="margin-top:16px"><h3>最近记下</h3>
|
|
1535
|
+
<div class="recent-list">
|
|
1536
|
+
${recent.length ? recent.map((c) => `<button data-goto="${c.id}">${esc(c.text.slice(0, 34))}</button>`).join('') : '<span class="hint">还没有</span>'}
|
|
1537
|
+
</div>
|
|
1538
|
+
</div>
|
|
1539
|
+
<div style="margin-top:16px"><h3>今天的安排</h3>
|
|
1540
|
+
<div class="recent-list">
|
|
1541
|
+
${plans.length
|
|
1542
|
+
? plans.map((p) => `<div class="line" style="display:flex;justify-content:space-between;font-size:12px;padding:3px 8px;color:${p.done ? 'var(--ink-dim)' : 'var(--ink-soft)'}"><span>${esc(p.time)} ${esc(p.title)}</span>${p.done ? '<span>✓</span>' : ''}</div>`).join('')
|
|
1543
|
+
: '<span class="hint">空</span>'}
|
|
1544
|
+
</div>
|
|
1545
|
+
</div>
|
|
1546
|
+
<div style="margin-top:16px">
|
|
1547
|
+
<h3>她的状态</h3>
|
|
1548
|
+
<div class="status-card">
|
|
1549
|
+
<div class="line"><span>精力</span><b>${Math.round(S.snap?.state?.energy ?? 0)}</b></div>
|
|
1550
|
+
<input id="ov-energy" type="range" min="0" max="100" value="${Math.round(S.snap?.state?.energy ?? 0)}" />
|
|
1551
|
+
<div class="line"><span>心情</span><b>${Math.round(S.snap?.state?.mood ?? 0)}</b></div>
|
|
1552
|
+
<input id="ov-mood" type="range" min="0" max="100" value="${Math.round(S.snap?.state?.mood ?? 0)}" />
|
|
1553
|
+
<div class="line"><span>在做</span><b>${esc(S.snap?.state?.activity ?? '')}</b></div>
|
|
1554
|
+
<input id="ov-activity" type="text" value="${esc(S.snap?.state?.activity ?? '')}" style="background:var(--sheet-2);border:1px solid var(--line);border-radius:6px;padding:4px 7px" />
|
|
1555
|
+
<button class="btn tiny" id="ov-save" style="margin-top:4px">保存状态</button>
|
|
1556
|
+
</div>
|
|
1557
|
+
</div>
|
|
1558
|
+
<div class="hint" style="margin-top:16px">点节点或列表里的任意一条看详情。选中后用 <kbd>E</kbd> 直接改。</div>
|
|
1559
|
+
`;
|
|
1560
|
+
el.inspector.querySelectorAll('[data-goto]').forEach((btn) => {
|
|
1561
|
+
btn.addEventListener('click', () => selectCard(btn.dataset.goto));
|
|
1562
|
+
});
|
|
1563
|
+
bindInspCollapse();
|
|
1564
|
+
$('#ov-save').addEventListener('click', async () => {
|
|
1565
|
+
try {
|
|
1566
|
+
await api('/api/state', {
|
|
1567
|
+
method: 'POST',
|
|
1568
|
+
body: JSON.stringify({
|
|
1569
|
+
energy: Number($('#ov-energy').value),
|
|
1570
|
+
mood: Number($('#ov-mood').value),
|
|
1571
|
+
activity: $('#ov-activity').value,
|
|
1572
|
+
}),
|
|
1573
|
+
});
|
|
1574
|
+
toast('状态已更新');
|
|
1575
|
+
await load();
|
|
1576
|
+
} catch (err) {
|
|
1577
|
+
toast(`保存失败:${err.message}`, true);
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
function sourceLabel(src) {
|
|
1583
|
+
return { tool: '聊天时写下', map: '记忆地图里手填', import: '旧插件导入', script: '系统' }[src] ?? src ?? '—';
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
/* 表格里只放得下短名,完整语义留给 title */
|
|
1587
|
+
function sourceShort(src) {
|
|
1588
|
+
if (!src) return '—';
|
|
1589
|
+
if (src.startsWith('import:')) return `导入·${src.slice(7).replace(/^(private-|memory-)/, '')}`;
|
|
1590
|
+
return { tool: '聊天', map: '手填', script: '系统' }[src] ?? src;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
function toLocalInput(iso) {
|
|
1594
|
+
const d = new Date(iso);
|
|
1595
|
+
if (Number.isNaN(d.getTime())) return '';
|
|
1596
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
function relatedTo(card) {
|
|
1600
|
+
const toks = new Set(
|
|
1601
|
+
card.text
|
|
1602
|
+
.toLowerCase()
|
|
1603
|
+
.replace(/[^\p{L}\p{N}]+/gu, ' ')
|
|
1604
|
+
.split(/\s+/)
|
|
1605
|
+
.filter((t) => t.length > 1),
|
|
1606
|
+
);
|
|
1607
|
+
const scored = [];
|
|
1608
|
+
for (const other of cards()) {
|
|
1609
|
+
if (other.id === card.id || isRetired(other)) continue;
|
|
1610
|
+
const shared = other.tags.filter((t) => card.tags.includes(t));
|
|
1611
|
+
let score = shared.length * 2;
|
|
1612
|
+
const otherToks = new Set(other.text.toLowerCase().split(''));
|
|
1613
|
+
let overlap = 0;
|
|
1614
|
+
for (const ch of new Set(card.text)) if (otherToks.has(ch)) overlap += 1;
|
|
1615
|
+
score += (overlap / Math.max(1, new Set(card.text).size)) * 1.2;
|
|
1616
|
+
if (score < 1.1) continue;
|
|
1617
|
+
scored.push({
|
|
1618
|
+
card: other,
|
|
1619
|
+
score,
|
|
1620
|
+
why: shared.length ? `同标签 ${shared.join(' ')}` : '内容相近',
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, 4);
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
function lineageHtml(card) {
|
|
1627
|
+
const before = (card.supersedes ?? [])
|
|
1628
|
+
.map((id) => cards().find((c) => c.id === id))
|
|
1629
|
+
.filter(Boolean)
|
|
1630
|
+
.slice(-3);
|
|
1631
|
+
const after = cards().find((c) => (c.supersedes ?? []).includes(card.id));
|
|
1632
|
+
if (!before.length && !after) {
|
|
1633
|
+
if (!isRetired(card)) return '';
|
|
1634
|
+
const why = { merge: '被合并', manual: '手动退休', stale: '标为作废' }[card.retiredBy] ?? '被新版本接替';
|
|
1635
|
+
return `<div class="lineage"><h3>状态</h3><p class="lineage-note">已退休 · ${why}${card.retiredAt ? ` · ${relative(card.retiredAt)}` : ''}</p></div>`;
|
|
1636
|
+
}
|
|
1637
|
+
const item = (c, prefix) =>
|
|
1638
|
+
`<button class="related-item" data-goto="${c.id}">${prefix}${esc(c.text.slice(0, 40))}${c.text.length > 40 ? '…' : ''}<span class="why">${fmtTime(c.createdAt)}</span></button>`;
|
|
1639
|
+
return `<div class="lineage"><h3>版本链</h3>
|
|
1640
|
+
${after ? item(after, '被这条接替:') : ''}
|
|
1641
|
+
${before.map((c) => item(c, '它接替了:')).join('')}
|
|
1642
|
+
</div>`;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
async function saveCard(card) {
|
|
1646
|
+
const text = $('#edit-text').value.trim();
|
|
1647
|
+
if (!text) return toast('内容不能为空', true);
|
|
1648
|
+
const patch = {
|
|
1649
|
+
text,
|
|
1650
|
+
kind: $('#edit-kind').value,
|
|
1651
|
+
weight: Number($('#edit-weight').value),
|
|
1652
|
+
tags: $('#edit-tags')
|
|
1653
|
+
.value.split(/[,,\s]+/)
|
|
1654
|
+
.map((t) => t.trim())
|
|
1655
|
+
.filter(Boolean),
|
|
1656
|
+
dueAt: $('#edit-due').value ? $('#edit-due').value : '',
|
|
1657
|
+
};
|
|
1658
|
+
try {
|
|
1659
|
+
const saved = await api(`/api/cards/${card.id}`, { method: 'PATCH', body: JSON.stringify(patch) });
|
|
1660
|
+
S.editing = false;
|
|
1661
|
+
// 改内容会生成新版本(旧版退休),选中落到新版上
|
|
1662
|
+
if (saved?.id && saved.id !== card.id) S.selected = saved.id;
|
|
1663
|
+
toast(saved?.id && saved.id !== card.id ? '已保存为新版本,旧版进了退休区' : '已保存');
|
|
1664
|
+
await load();
|
|
1665
|
+
} catch (err) {
|
|
1666
|
+
toast(`保存失败:${err.message}`, true);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
async function patchCard(id, patch, msg) {
|
|
1671
|
+
try {
|
|
1672
|
+
await api(`/api/cards/${id}`, { method: 'PATCH', body: JSON.stringify(patch) });
|
|
1673
|
+
toast(msg);
|
|
1674
|
+
await load();
|
|
1675
|
+
} catch (err) {
|
|
1676
|
+
toast(`失败:${err.message}`, true);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
/* ── 体检 ───────────────────────────────────────────── */
|
|
1681
|
+
|
|
1682
|
+
async function ensureHealth() {
|
|
1683
|
+
if (S.health) return;
|
|
1684
|
+
try {
|
|
1685
|
+
S.health = await api('/api/health');
|
|
1686
|
+
if (S.view === 'health') renderHealth();
|
|
1687
|
+
} catch (err) {
|
|
1688
|
+
toast(`体检读不出来:${err.message}`, true);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
function healthCard(label, value, hint, tone = '') {
|
|
1693
|
+
return `<div class="h-card ${tone}">
|
|
1694
|
+
<div class="h-label">${esc(label)}</div>
|
|
1695
|
+
<div class="h-value">${value}</div>
|
|
1696
|
+
<div class="h-hint">${esc(hint)}</div>
|
|
1697
|
+
</div>`;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
function renderHealth() {
|
|
1701
|
+
const host = $('#view-health');
|
|
1702
|
+
const h = S.health;
|
|
1703
|
+
if (!h) {
|
|
1704
|
+
host.innerHTML = '<div class="empty"><p>正在算…</p></div>';
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
const maxN = Math.max(1, ...h.perDay.map((d) => d.n));
|
|
1708
|
+
const bars = h.perDay
|
|
1709
|
+
.map(
|
|
1710
|
+
(d) => `<div class="h-bar" title="${d.day} · ${d.n} 条">
|
|
1711
|
+
<i style="height:${Math.max(2, Math.round((d.n / maxN) * 100))}%"></i>
|
|
1712
|
+
<b>${d.n}</b>
|
|
1713
|
+
<span>${d.day.slice(5).replace('-', '/')}</span>
|
|
1714
|
+
</div>`,
|
|
1715
|
+
)
|
|
1716
|
+
.join('');
|
|
1717
|
+
const dead = h.deadIds.map((id) => cards().find((c) => c.id === id)).filter(Boolean);
|
|
1718
|
+
const deadRows = dead
|
|
1719
|
+
.slice(0, 20)
|
|
1720
|
+
.map(
|
|
1721
|
+
(c) => `<div class="maint-row" data-id="${c.id}">
|
|
1722
|
+
<div class="maint-main">
|
|
1723
|
+
<span class="kind-pill"><i style="background:var(${kindOf(c.kind).css})"></i>${kindOf(c.kind).label}</span>
|
|
1724
|
+
<span class="maint-text" title="${esc(c.text)}">${esc(c.text.slice(0, 80))}${c.text.length > 80 ? '…' : ''}</span>
|
|
1725
|
+
<span class="maint-meta">${relative(c.createdAt)} · ${c.weight.toFixed(2)}</span>
|
|
1726
|
+
</div>
|
|
1727
|
+
</div>`,
|
|
1728
|
+
)
|
|
1729
|
+
.join('');
|
|
1730
|
+
host.innerHTML = `<div class="health-wrap">
|
|
1731
|
+
<div class="h-grid">
|
|
1732
|
+
${healthCard('在用记忆', h.cards.active, `另有 ${h.cards.retired} 条已退休`)}
|
|
1733
|
+
${healthCard('从没被召回', h.cards.dead, '建了 7 天以上、一次都没被搜到', h.cards.dead > h.cards.active * 0.5 ? 'warn' : '')}
|
|
1734
|
+
${healthCard('召回次数', h.recall.calls, `${h.recall.cardsTouched} 张卡被用过`)}
|
|
1735
|
+
${healthCard('对话原文', h.raw.lines, `归档 ${h.raw.archivedLines} 行 · ${h.raw.archivedDays} 天`)}
|
|
1736
|
+
</div>
|
|
1737
|
+
|
|
1738
|
+
<section class="h-block">
|
|
1739
|
+
<h3>近 14 天新增</h3>
|
|
1740
|
+
<div class="h-chart">${bars}</div>
|
|
1741
|
+
</section>
|
|
1742
|
+
|
|
1743
|
+
<section class="h-block">
|
|
1744
|
+
<h3>承诺</h3>
|
|
1745
|
+
<div class="h-line">
|
|
1746
|
+
<span>未完成 <b>${h.promises.open}</b></span>
|
|
1747
|
+
<span class="${h.promises.overdue ? 'warn' : ''}">已过时间 <b>${h.promises.overdue}</b></span>
|
|
1748
|
+
<span class="${h.promises.noDue ? 'warn' : ''}">没有截止时间 <b>${h.promises.noDue}</b></span>
|
|
1749
|
+
<span class="dim">${h.promises.repeating ? `每 ${h.promises.repeating} 天重提一次` : '只提醒一次'}</span>
|
|
1750
|
+
${h.promises.noDue ? '<button class="btn tiny" id="h-fix-promises">去补时间</button>' : ''}
|
|
1751
|
+
</div>
|
|
1752
|
+
</section>
|
|
1753
|
+
|
|
1754
|
+
<section class="h-block">
|
|
1755
|
+
<h3>备份</h3>
|
|
1756
|
+
<div class="h-line">
|
|
1757
|
+
<span>${h.backup.count ? `本地有 <b>${h.backup.count}</b> 份,最新 <b>${esc(h.backup.latest ?? '')}</b>` : '还没有备份,下次写入时会自动生成'}</span>
|
|
1758
|
+
<span class="dim">${esc(h.backup.dir)}</span>
|
|
1759
|
+
</div>
|
|
1760
|
+
</section>
|
|
1761
|
+
|
|
1762
|
+
<section class="h-block">
|
|
1763
|
+
<h3>从没被召回的卡 ${h.cards.dead ? `<button class="btn tiny" id="h-retire-dead">全部退休(${h.cards.dead})</button>` : ''}</h3>
|
|
1764
|
+
${
|
|
1765
|
+
dead.length
|
|
1766
|
+
? `<div class="maint-list">${deadRows}</div>${dead.length > 20 ? `<p class="dim">还有 ${dead.length - 20} 条没列出来。</p>` : ''}`
|
|
1767
|
+
: '<p class="maint-empty">没有。每张卡都被搜到过。</p>'
|
|
1768
|
+
}
|
|
1769
|
+
</section>
|
|
1770
|
+
</div>`;
|
|
1771
|
+
|
|
1772
|
+
const fix = $('#h-fix-promises');
|
|
1773
|
+
if (fix) fix.addEventListener('click', () => void openMaintenance('promises'));
|
|
1774
|
+
const retireDead = $('#h-retire-dead');
|
|
1775
|
+
if (retireDead) {
|
|
1776
|
+
retireDead.addEventListener('click', async () => {
|
|
1777
|
+
const ids = h.deadIds.slice();
|
|
1778
|
+
if (!ids.length) return;
|
|
1779
|
+
if (!confirm(`把 ${ids.length} 张从没被召回的卡标成退休?不删除,随时能在回收站恢复。`)) return;
|
|
1780
|
+
try {
|
|
1781
|
+
for (const id of ids) await api(`/api/cards/${id}/retire`, { method: 'POST', body: '{}' });
|
|
1782
|
+
S.health = null;
|
|
1783
|
+
await load();
|
|
1784
|
+
toast(`${ids.length} 张已退休`);
|
|
1785
|
+
} catch (err) {
|
|
1786
|
+
toast(`失败:${err.message}`, true);
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
/* ── 视图切换与渲染 ─────────────────────────────────── */
|
|
1793
|
+
|
|
1794
|
+
function renderStage() {
|
|
1795
|
+
localStorage.setItem('mcore-view', S.view);
|
|
1796
|
+
$('#view-graph').hidden = S.view !== 'graph';
|
|
1797
|
+
$('#view-timeline').hidden = S.view !== 'timeline';
|
|
1798
|
+
$('#view-table').hidden = S.view !== 'table';
|
|
1799
|
+
$('#view-turns').hidden = S.view !== 'turns';
|
|
1800
|
+
$('#view-docs').hidden = S.view !== 'docs';
|
|
1801
|
+
$('#view-health').hidden = S.view !== 'health';
|
|
1802
|
+
document.querySelectorAll('#tabs .tab').forEach((t) => t.classList.toggle('active', t.dataset.view === S.view));
|
|
1803
|
+
|
|
1804
|
+
if (S.view === 'graph') renderGraph();
|
|
1805
|
+
if (S.view === 'timeline') renderTimeline();
|
|
1806
|
+
if (S.view === 'table') renderTable();
|
|
1807
|
+
if (S.view === 'turns') renderTurns();
|
|
1808
|
+
if (S.view === 'docs') {
|
|
1809
|
+
renderDocs();
|
|
1810
|
+
ensureDocs();
|
|
1811
|
+
}
|
|
1812
|
+
if (S.view === 'health') {
|
|
1813
|
+
renderHealth();
|
|
1814
|
+
void ensureHealth();
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
function renderStatus() {
|
|
1819
|
+
const total = cards().length;
|
|
1820
|
+
const shown = filtered().length;
|
|
1821
|
+
el.statusCount.textContent = `显示 ${shown} / ${total} 条`;
|
|
1822
|
+
const site = S.snap?.site?.origin;
|
|
1823
|
+
el.statusSite.textContent = site ? `服务 ${site}` : '';
|
|
1824
|
+
el.brandSub.textContent = `${total} 条记忆 · ${S.snap?.stats?.openPromises ?? 0} 个承诺在等`;
|
|
1825
|
+
applyInspState();
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
function render() {
|
|
1829
|
+
renderMetrics();
|
|
1830
|
+
renderRail();
|
|
1831
|
+
renderStage();
|
|
1832
|
+
renderInspector();
|
|
1833
|
+
renderStatus();
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
/* ── 选择与键盘 ─────────────────────────────────────── */
|
|
1837
|
+
|
|
1838
|
+
function visibleIds() {
|
|
1839
|
+
const list = filtered();
|
|
1840
|
+
if (S.view === 'timeline') return list.sort((a, b) => b.createdAt.localeCompare(a.createdAt)).map((c) => c.id);
|
|
1841
|
+
if (S.view === 'table') return list.map((c) => c.id);
|
|
1842
|
+
return list.map((c) => c.id);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
function move(delta) {
|
|
1846
|
+
const ids = visibleIds();
|
|
1847
|
+
if (!ids.length) return;
|
|
1848
|
+
const at = ids.indexOf(S.selected);
|
|
1849
|
+
const next = at < 0 ? 0 : clamp(at + delta, 0, ids.length - 1);
|
|
1850
|
+
selectCard(ids[next], { scroll: true });
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
document.addEventListener('keydown', (event) => {
|
|
1854
|
+
const typing = /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName ?? '');
|
|
1855
|
+
if (event.key === 'Escape') {
|
|
1856
|
+
if (!el.modal.hidden) return closeModal();
|
|
1857
|
+
if (typing) {
|
|
1858
|
+
document.activeElement.blur();
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
if (S.query) {
|
|
1862
|
+
S.query = '';
|
|
1863
|
+
el.search.value = '';
|
|
1864
|
+
render();
|
|
1865
|
+
return;
|
|
1866
|
+
}
|
|
1867
|
+
S.selected = null;
|
|
1868
|
+
S.editing = false;
|
|
1869
|
+
setInspCollapsed(true);
|
|
1870
|
+
render();
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
if (typing) return;
|
|
1874
|
+
if (event.key === '/' || (event.key === 'k' && (event.metaKey || event.ctrlKey))) {
|
|
1875
|
+
event.preventDefault();
|
|
1876
|
+
el.search.focus();
|
|
1877
|
+
el.search.select();
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
if (event.key === '?') return showShortcuts();
|
|
1881
|
+
if (event.key === 'j' || event.key === 'ArrowDown') {
|
|
1882
|
+
event.preventDefault();
|
|
1883
|
+
return move(1);
|
|
1884
|
+
}
|
|
1885
|
+
if (event.key === 'k' || event.key === 'ArrowUp') {
|
|
1886
|
+
event.preventDefault();
|
|
1887
|
+
return move(-1);
|
|
1888
|
+
}
|
|
1889
|
+
if (event.key === 'Enter' && S.selected) {
|
|
1890
|
+
S.editing = true;
|
|
1891
|
+
renderInspector();
|
|
1892
|
+
$('#edit-text')?.focus();
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
if (event.key === 'e' && S.selected) {
|
|
1896
|
+
S.editing = true;
|
|
1897
|
+
renderInspector();
|
|
1898
|
+
$('#edit-text')?.focus();
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
if (event.key === 'n') {
|
|
1902
|
+
event.preventDefault();
|
|
1903
|
+
return openCompose();
|
|
1904
|
+
}
|
|
1905
|
+
if (event.key === 'r') return load();
|
|
1906
|
+
if (event.key === 'i') {
|
|
1907
|
+
setInspCollapsed(!S.inspCollapsed);
|
|
1908
|
+
if (!S.inspCollapsed) renderInspector();
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
if (['1', '2', '3', '4', '5', '6'].includes(event.key)) {
|
|
1912
|
+
const views = ['graph', 'timeline', 'table', 'turns', 'docs', 'health'];
|
|
1913
|
+
S.view = views[Number(event.key) - 1];
|
|
1914
|
+
return render();
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
|
|
1918
|
+
// 逐字 render 会把原文 1000+ 条、表格几十行整体重建,打字快了肉眼可见地卡。
|
|
1919
|
+
// 输入框状态立刻更新(清除按钮要跟手),重绘压到 150ms 后。
|
|
1920
|
+
let searchTimer = 0;
|
|
1921
|
+
el.search.addEventListener('input', () => {
|
|
1922
|
+
S.query = el.search.value;
|
|
1923
|
+
el.searchClear.hidden = !S.query;
|
|
1924
|
+
S.turnsLimit = TURNS_PAGE;
|
|
1925
|
+
S.archive = null;
|
|
1926
|
+
S.archiveQ = '';
|
|
1927
|
+
clearTimeout(searchTimer);
|
|
1928
|
+
searchTimer = setTimeout(() => render(), 150);
|
|
1929
|
+
});
|
|
1930
|
+
el.searchClear.addEventListener('click', () => {
|
|
1931
|
+
S.query = '';
|
|
1932
|
+
el.search.value = '';
|
|
1933
|
+
el.searchClear.hidden = true;
|
|
1934
|
+
S.turnsLimit = TURNS_PAGE;
|
|
1935
|
+
S.archive = null;
|
|
1936
|
+
S.archiveQ = '';
|
|
1937
|
+
clearTimeout(searchTimer);
|
|
1938
|
+
render();
|
|
1939
|
+
});
|
|
1940
|
+
|
|
1941
|
+
document.querySelectorAll('#tabs .tab').forEach((tab) => {
|
|
1942
|
+
tab.addEventListener('click', () => {
|
|
1943
|
+
S.view = tab.dataset.view;
|
|
1944
|
+
render();
|
|
1945
|
+
});
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
$('#view-timeline').addEventListener('click', (event) => {
|
|
1949
|
+
const item = event.target.closest('[data-id]');
|
|
1950
|
+
if (!item) return;
|
|
1951
|
+
selectCard(item.dataset.id);
|
|
1952
|
+
});
|
|
1953
|
+
|
|
1954
|
+
$('#view-table').addEventListener('click', (event) => {
|
|
1955
|
+
const th = event.target.closest('th[data-sort]');
|
|
1956
|
+
if (th) {
|
|
1957
|
+
const key = th.dataset.sort;
|
|
1958
|
+
S.sort = { key, dir: S.sort.key === key ? -S.sort.dir : key === 'createdAt' || key === 'weight' || key === 'uses' ? -1 : 1 };
|
|
1959
|
+
return renderStage();
|
|
1960
|
+
}
|
|
1961
|
+
const tr = event.target.closest('tr[data-id]');
|
|
1962
|
+
if (!tr) return;
|
|
1963
|
+
selectCard(tr.dataset.id);
|
|
1964
|
+
});
|
|
1965
|
+
|
|
1966
|
+
$('#view-docs').addEventListener('click', (event) => {
|
|
1967
|
+
const item = event.target.closest('[data-path]');
|
|
1968
|
+
if (item) openDoc(item.dataset.path);
|
|
1969
|
+
});
|
|
1970
|
+
|
|
1971
|
+
/* ── 新建弹层 ───────────────────────────────────────── */
|
|
1972
|
+
|
|
1973
|
+
/* ── 维护与回收站 ───────────────────────────────────── */
|
|
1974
|
+
|
|
1975
|
+
async function openMaintenance(tab = 'dupes') {
|
|
1976
|
+
try {
|
|
1977
|
+
S.maintenance = await api('/api/maintenance');
|
|
1978
|
+
} catch (err) {
|
|
1979
|
+
return toast(`读不出来:${err.message}`, true);
|
|
1980
|
+
}
|
|
1981
|
+
renderMaintenance(tab);
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
function maintRow(card, actions, extraClass = '') {
|
|
1985
|
+
const k = kindOf(card.kind);
|
|
1986
|
+
return `<div class="maint-row ${extraClass}" data-id="${card.id}">
|
|
1987
|
+
<div class="maint-main">
|
|
1988
|
+
<span class="kind-pill"><i style="background:var(${k.css})"></i>${k.label}</span>
|
|
1989
|
+
<span class="maint-text" title="${esc(card.text)}">${esc(card.text.slice(0, 90))}${card.text.length > 90 ? '…' : ''}</span>
|
|
1990
|
+
<span class="maint-meta">${relative(card.createdAt)} · ${card.weight.toFixed(2)}</span>
|
|
1991
|
+
</div>
|
|
1992
|
+
<div class="maint-act">${actions}</div>
|
|
1993
|
+
</div>`;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
function renderMaintenance(tab) {
|
|
1997
|
+
const m = S.maintenance;
|
|
1998
|
+
const byId = (id) => cards().find((c) => c.id === id);
|
|
1999
|
+
const rows = (ids) => ids.map(byId).filter(Boolean);
|
|
2000
|
+
const prom = m.promises ?? { noDue: [], overdue: [] };
|
|
2001
|
+
const tabs = [
|
|
2002
|
+
['dupes', '重复', m.dupes.length],
|
|
2003
|
+
['stale', '疑似作废', m.stale.length],
|
|
2004
|
+
['junk', '垃圾', m.junk.length],
|
|
2005
|
+
['promises', '承诺', prom.noDue.length + prom.overdue.length],
|
|
2006
|
+
['retired', '回收站', m.retired.length],
|
|
2007
|
+
];
|
|
2008
|
+
let content = '';
|
|
2009
|
+
let bulk = '';
|
|
2010
|
+
if (tab === 'dupes') {
|
|
2011
|
+
const groups = m.dupes
|
|
2012
|
+
.map((g) => ({ ...g, cards: rows(g.ids) }))
|
|
2013
|
+
.filter((g) => g.cards.length > 1);
|
|
2014
|
+
content = groups.length
|
|
2015
|
+
? groups
|
|
2016
|
+
.map(
|
|
2017
|
+
(g) => `<div class="maint-group">
|
|
2018
|
+
<div class="maint-group-head">相似度 ${Math.round(g.score * 100)}% · ${g.cards.length} 条</div>
|
|
2019
|
+
${g.cards
|
|
2020
|
+
.map((c) => maintRow(c, `<button class="btn tiny" data-keep="${c.id}" data-drop="${g.cards
|
|
2021
|
+
.filter((x) => x.id !== c.id)
|
|
2022
|
+
.map((x) => x.id)
|
|
2023
|
+
.join(',')}">保留这条</button>`))
|
|
2024
|
+
.join('')}
|
|
2025
|
+
</div>`,
|
|
2026
|
+
)
|
|
2027
|
+
.join('')
|
|
2028
|
+
: '<p class="maint-empty">没有重复。同类型里没有两条内容相近到值得合并的。</p>';
|
|
2029
|
+
} else if (tab === 'stale') {
|
|
2030
|
+
const list = rows(m.stale);
|
|
2031
|
+
content = list.length
|
|
2032
|
+
? list.map((c) => maintRow(c, `<button class="btn tiny" data-retire="${c.id}">退休</button>`)).join('')
|
|
2033
|
+
: '<p class="maint-empty">没有疑似作废的记忆。文案里带「取消了 / 改到 / 作废」,或者 90 天没被召回、权重又低的,会出现在这里。</p>';
|
|
2034
|
+
if (list.length) bulk = `<button class="btn tiny" data-bulk="stale">全部退休(${list.length})</button>`;
|
|
2035
|
+
} else if (tab === 'junk') {
|
|
2036
|
+
const list = rows(m.junk);
|
|
2037
|
+
content = list.length
|
|
2038
|
+
? list.map((c) => maintRow(c, `<button class="btn tiny" data-retire="${c.id}">退休</button><button class="btn tiny danger" data-purge="${c.id}">删除</button>`)).join('')
|
|
2039
|
+
: '<p class="maint-empty">没有垃圾。太短、纯表情、`[取消]` 这类回执会出现在这里。</p>';
|
|
2040
|
+
if (list.length) bulk = `<button class="btn tiny danger" data-bulk="junk">全部删除(${list.length})</button>`;
|
|
2041
|
+
} else if (tab === 'promises') {
|
|
2042
|
+
const noDue = rows(prom.noDue);
|
|
2043
|
+
const overdue = rows(prom.overdue);
|
|
2044
|
+
const blocks = [];
|
|
2045
|
+
if (noDue.length) {
|
|
2046
|
+
blocks.push(`<div class="maint-group">
|
|
2047
|
+
<div class="maint-group-head">没写截止时间 · 提醒管线管不到(${noDue.length})</div>
|
|
2048
|
+
${noDue
|
|
2049
|
+
.map((c) =>
|
|
2050
|
+
maintRow(
|
|
2051
|
+
c,
|
|
2052
|
+
`<input class="due-input" type="datetime-local" data-due="${c.id}" aria-label="截止时间" />
|
|
2053
|
+
<button class="btn tiny" data-save-due="${c.id}">补上</button>`,
|
|
2054
|
+
'wide',
|
|
2055
|
+
),
|
|
2056
|
+
)
|
|
2057
|
+
.join('')}
|
|
2058
|
+
</div>`);
|
|
2059
|
+
}
|
|
2060
|
+
if (overdue.length) {
|
|
2061
|
+
blocks.push(`<div class="maint-group">
|
|
2062
|
+
<div class="maint-group-head">已过时间 · 还没做(${overdue.length})</div>
|
|
2063
|
+
${overdue
|
|
2064
|
+
.map((c) =>
|
|
2065
|
+
maintRow(c, `<button class="btn tiny" data-done="${c.id}">标记做完</button><button class="btn tiny" data-retire="${c.id}">退休</button>`, 'wide'),
|
|
2066
|
+
)
|
|
2067
|
+
.join('')}
|
|
2068
|
+
</div>`);
|
|
2069
|
+
}
|
|
2070
|
+
content = blocks.length
|
|
2071
|
+
? blocks.join('')
|
|
2072
|
+
: '<p class="maint-empty">没有要补的承诺。写承诺时必须带截止时间,到点会提一次。</p>';
|
|
2073
|
+
} else {
|
|
2074
|
+
const list = rows(m.retired);
|
|
2075
|
+
content = list.length
|
|
2076
|
+
? list.map((c) => maintRow(c, `<button class="btn tiny" data-restore="${c.id}">恢复</button><button class="btn tiny danger" data-purge="${c.id}">彻底删除</button>`)).join('')
|
|
2077
|
+
: '<p class="maint-empty">回收站是空的。</p>';
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
openModal(
|
|
2081
|
+
'维护',
|
|
2082
|
+
`<div class="maint-tabs">${tabs
|
|
2083
|
+
.map(([k, label, n]) => `<button data-tab="${k}" class="${tab === k ? 'on' : ''}">${label}${n ? `<span>${n}</span>` : ''}</button>`)
|
|
2084
|
+
.join('')}</div>
|
|
2085
|
+
<p class="maint-note">退休=不参与检索、列表里默认看不到,随时能恢复;彻底删除不可撤销。</p>
|
|
2086
|
+
<div class="maint-body">${content}</div>`,
|
|
2087
|
+
`${bulk}<button class="btn" id="maint-close">关闭</button>`,
|
|
2088
|
+
);
|
|
2089
|
+
|
|
2090
|
+
$('#modal-body')
|
|
2091
|
+
.querySelectorAll('[data-tab]')
|
|
2092
|
+
.forEach((btn) => btn.addEventListener('click', () => renderMaintenance(btn.dataset.tab)));
|
|
2093
|
+
$('#maint-close').addEventListener('click', closeModal);
|
|
2094
|
+
|
|
2095
|
+
const refresh = async (msg) => {
|
|
2096
|
+
toast(msg);
|
|
2097
|
+
await load();
|
|
2098
|
+
S.maintenance = await api('/api/maintenance');
|
|
2099
|
+
renderMaintenance(tab);
|
|
2100
|
+
};
|
|
2101
|
+
$('#modal-body')
|
|
2102
|
+
.querySelectorAll('[data-keep]')
|
|
2103
|
+
.forEach((btn) =>
|
|
2104
|
+
btn.addEventListener('click', async () => {
|
|
2105
|
+
const drop = btn.dataset.drop.split(',').filter(Boolean);
|
|
2106
|
+
try {
|
|
2107
|
+
const res = await api('/api/merge', { method: 'POST', body: JSON.stringify({ keep: btn.dataset.keep, drop }) });
|
|
2108
|
+
await refresh(`合并了 ${res.merged ?? 0} 条`);
|
|
2109
|
+
} catch (err) {
|
|
2110
|
+
toast(`合并失败:${err.message}`, true);
|
|
2111
|
+
}
|
|
2112
|
+
}),
|
|
2113
|
+
);
|
|
2114
|
+
$('#modal-body')
|
|
2115
|
+
.querySelectorAll('[data-retire]')
|
|
2116
|
+
.forEach((btn) =>
|
|
2117
|
+
btn.addEventListener('click', async () => {
|
|
2118
|
+
try {
|
|
2119
|
+
await api(`/api/cards/${btn.dataset.retire}/retire`, { method: 'POST', body: '{}' });
|
|
2120
|
+
await refresh('已退休');
|
|
2121
|
+
} catch (err) {
|
|
2122
|
+
toast(`失败:${err.message}`, true);
|
|
2123
|
+
}
|
|
2124
|
+
}),
|
|
2125
|
+
);
|
|
2126
|
+
$('#modal-body')
|
|
2127
|
+
.querySelectorAll('[data-restore]')
|
|
2128
|
+
.forEach((btn) =>
|
|
2129
|
+
btn.addEventListener('click', async () => {
|
|
2130
|
+
try {
|
|
2131
|
+
await api(`/api/cards/${btn.dataset.restore}/restore`, { method: 'POST', body: '{}' });
|
|
2132
|
+
await refresh('已恢复');
|
|
2133
|
+
} catch (err) {
|
|
2134
|
+
toast(`失败:${err.message}`, true);
|
|
2135
|
+
}
|
|
2136
|
+
}),
|
|
2137
|
+
);
|
|
2138
|
+
$('#modal-body')
|
|
2139
|
+
.querySelectorAll('[data-purge]')
|
|
2140
|
+
.forEach((btn) =>
|
|
2141
|
+
btn.addEventListener('click', async () => {
|
|
2142
|
+
try {
|
|
2143
|
+
const n = await purgeWithUndo([btn.dataset.purge]);
|
|
2144
|
+
if (!n) return;
|
|
2145
|
+
await load();
|
|
2146
|
+
S.maintenance = await api('/api/maintenance');
|
|
2147
|
+
renderMaintenance(tab);
|
|
2148
|
+
} catch (err) {
|
|
2149
|
+
toast(`失败:${err.message}`, true);
|
|
2150
|
+
}
|
|
2151
|
+
}),
|
|
2152
|
+
);
|
|
2153
|
+
$('#modal-body')
|
|
2154
|
+
.querySelectorAll('[data-save-due]')
|
|
2155
|
+
.forEach((btn) =>
|
|
2156
|
+
btn.addEventListener('click', async () => {
|
|
2157
|
+
const input = btn.parentElement?.querySelector('[data-due]');
|
|
2158
|
+
const value = input?.value;
|
|
2159
|
+
if (!value) return toast('先选一个时间', true);
|
|
2160
|
+
try {
|
|
2161
|
+
await api(`/api/cards/${btn.dataset.saveDue}`, { method: 'PATCH', body: JSON.stringify({ dueAt: value }) });
|
|
2162
|
+
await refresh('补上了截止时间');
|
|
2163
|
+
} catch (err) {
|
|
2164
|
+
toast(`失败:${err.message}`, true);
|
|
2165
|
+
}
|
|
2166
|
+
}),
|
|
2167
|
+
);
|
|
2168
|
+
$('#modal-body')
|
|
2169
|
+
.querySelectorAll('[data-done]')
|
|
2170
|
+
.forEach((btn) =>
|
|
2171
|
+
btn.addEventListener('click', async () => {
|
|
2172
|
+
try {
|
|
2173
|
+
await api(`/api/cards/${btn.dataset.done}`, { method: 'PATCH', body: JSON.stringify({ done: true }) });
|
|
2174
|
+
await refresh('标记完成');
|
|
2175
|
+
} catch (err) {
|
|
2176
|
+
toast(`失败:${err.message}`, true);
|
|
2177
|
+
}
|
|
2178
|
+
}),
|
|
2179
|
+
);
|
|
2180
|
+
const bulkBtn = $('#modal-foot [data-bulk]');
|
|
2181
|
+
if (bulkBtn) {
|
|
2182
|
+
bulkBtn.addEventListener('click', async () => {
|
|
2183
|
+
const ids = bulkBtn.dataset.bulk === 'stale' ? S.maintenance.stale : S.maintenance.junk;
|
|
2184
|
+
if (!ids.length) return;
|
|
2185
|
+
if (!confirm(`处理这 ${ids.length} 条?`)) return;
|
|
2186
|
+
try {
|
|
2187
|
+
if (bulkBtn.dataset.bulk === 'stale') {
|
|
2188
|
+
for (const id of ids) await api(`/api/cards/${id}/retire`, { method: 'POST', body: '{}' });
|
|
2189
|
+
await refresh(`${ids.length} 条已退休`);
|
|
2190
|
+
} else {
|
|
2191
|
+
const n = await purgeWithUndo(ids);
|
|
2192
|
+
if (!n) return;
|
|
2193
|
+
await load();
|
|
2194
|
+
S.maintenance = await api('/api/maintenance');
|
|
2195
|
+
renderMaintenance(tab);
|
|
2196
|
+
}
|
|
2197
|
+
} catch (err) {
|
|
2198
|
+
toast(`失败:${err.message}`, true);
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
function openModal(title, bodyHtml, footHtml) {
|
|
2205
|
+
el.modalTitle.textContent = title;
|
|
2206
|
+
el.modalBody.innerHTML = bodyHtml;
|
|
2207
|
+
el.modalFoot.innerHTML = footHtml;
|
|
2208
|
+
el.modal.hidden = false;
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
function closeModal() {
|
|
2212
|
+
el.modal.hidden = true;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
$('#modal-close').addEventListener('click', closeModal);
|
|
2216
|
+
el.modal.addEventListener('click', (e) => {
|
|
2217
|
+
if (e.target === el.modal) closeModal();
|
|
2218
|
+
});
|
|
2219
|
+
|
|
2220
|
+
function openCompose() {
|
|
2221
|
+
openModal(
|
|
2222
|
+
'新建记忆',
|
|
2223
|
+
`<div class="editor">
|
|
2224
|
+
<textarea id="new-text" placeholder="一条只写一件事,40-80 字,写清楚谁、什么时候、怎么了"></textarea>
|
|
2225
|
+
<div class="row">
|
|
2226
|
+
<div><div class="label">类型</div>
|
|
2227
|
+
<select id="new-kind">${KINDS.map((k) => `<option value="${k.id}" ${k.id === 'episode' ? 'selected' : ''}>${k.label}</option>`).join('')}</select>
|
|
2228
|
+
</div>
|
|
2229
|
+
<div><div class="label">权重</div>
|
|
2230
|
+
<input id="new-weight" type="range" min="0" max="1" step="0.05" value="0.5" />
|
|
2231
|
+
</div>
|
|
2232
|
+
</div>
|
|
2233
|
+
<div><div class="label">标签(逗号分隔)</div><input id="new-tags" type="text" placeholder="例如:工作, 生日" /></div>
|
|
2234
|
+
</div>`,
|
|
2235
|
+
`<button class="btn ghost" id="new-cancel">取消</button><button class="btn primary" id="new-save">记下来</button>`,
|
|
2236
|
+
);
|
|
2237
|
+
$('#new-text').focus();
|
|
2238
|
+
const submit = async () => {
|
|
2239
|
+
const text = $('#new-text').value.trim();
|
|
2240
|
+
if (!text) return toast('写点什么', true);
|
|
2241
|
+
try {
|
|
2242
|
+
const card = await api('/api/cards', {
|
|
2243
|
+
method: 'POST',
|
|
2244
|
+
body: JSON.stringify({
|
|
2245
|
+
kind: $('#new-kind').value,
|
|
2246
|
+
text,
|
|
2247
|
+
weight: Number($('#new-weight').value),
|
|
2248
|
+
tags: $('#new-tags')
|
|
2249
|
+
.value.split(/[,,\s]+/)
|
|
2250
|
+
.map((t) => t.trim())
|
|
2251
|
+
.filter(Boolean),
|
|
2252
|
+
}),
|
|
2253
|
+
});
|
|
2254
|
+
closeModal();
|
|
2255
|
+
S.selected = card.id;
|
|
2256
|
+
setInspCollapsed(false);
|
|
2257
|
+
toast('已记下');
|
|
2258
|
+
await load();
|
|
2259
|
+
} catch (err) {
|
|
2260
|
+
toast(`失败:${err.message}`, true);
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
$('#new-save').addEventListener('click', submit);
|
|
2264
|
+
$('#new-cancel').addEventListener('click', closeModal);
|
|
2265
|
+
$('#new-text').addEventListener('keydown', (e) => {
|
|
2266
|
+
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') submit();
|
|
2267
|
+
});
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
$('#btn-new').addEventListener('click', openCompose);
|
|
2271
|
+
|
|
2272
|
+
function showShortcuts() {
|
|
2273
|
+
const rows = [
|
|
2274
|
+
['/ · ⌘K', '聚焦搜索'],
|
|
2275
|
+
['1 – 5', '图谱 / 时间线 / 列表 / 原文 / 文件'],
|
|
2276
|
+
['J · K', '下一条 / 上一条'],
|
|
2277
|
+
['Enter · E', '打开编辑器'],
|
|
2278
|
+
['N', '新建记忆'],
|
|
2279
|
+
['R', '重新读取'],
|
|
2280
|
+
['I', '收起 / 展开右栏'],
|
|
2281
|
+
['Esc', '清空搜索 / 取消选择'],
|
|
2282
|
+
];
|
|
2283
|
+
openModal(
|
|
2284
|
+
'快捷键',
|
|
2285
|
+
`<div class="shortcuts">${rows.map(([k, v]) => `<kbd>${k}</kbd><span>${v}</span>`).join('')}</div>`,
|
|
2286
|
+
`<button class="btn" id="sc-close">知道了</button>`,
|
|
2287
|
+
);
|
|
2288
|
+
$('#sc-close').addEventListener('click', closeModal);
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
/* ── 更多菜单 ───────────────────────────────────────── */
|
|
2292
|
+
|
|
2293
|
+
$('#btn-more').addEventListener('click', (event) => {
|
|
2294
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
2295
|
+
el.menu.innerHTML = `
|
|
2296
|
+
<button id="m-maint">维护与回收站 <span style="color:var(--ink-dim)">⌥</span></button>
|
|
2297
|
+
<hr />
|
|
2298
|
+
<button id="m-md">导出 Markdown</button>
|
|
2299
|
+
<button id="m-json">导出 JSON</button>
|
|
2300
|
+
<hr />
|
|
2301
|
+
<button id="m-keys">快捷键 <span style="color:var(--ink-dim)">?</span></button>
|
|
2302
|
+
<button id="m-refresh">重新读取 <span style="color:var(--ink-dim)">R</span></button>
|
|
2303
|
+
`;
|
|
2304
|
+
el.menu.hidden = false;
|
|
2305
|
+
el.menu.style.left = `${Math.min(rect.left, window.innerWidth - 210)}px`;
|
|
2306
|
+
el.menu.style.top = `${rect.bottom + 6}px`;
|
|
2307
|
+
$('#m-maint').addEventListener('click', () => {
|
|
2308
|
+
el.menu.hidden = true;
|
|
2309
|
+
void openMaintenance();
|
|
2310
|
+
});
|
|
2311
|
+
$('#m-md').addEventListener('click', () => {
|
|
2312
|
+
location.href = '/api/export?fmt=md';
|
|
2313
|
+
el.menu.hidden = true;
|
|
2314
|
+
});
|
|
2315
|
+
$('#m-json').addEventListener('click', () => {
|
|
2316
|
+
location.href = '/api/export?fmt=json';
|
|
2317
|
+
el.menu.hidden = true;
|
|
2318
|
+
});
|
|
2319
|
+
$('#m-keys').addEventListener('click', () => {
|
|
2320
|
+
el.menu.hidden = true;
|
|
2321
|
+
showShortcuts();
|
|
2322
|
+
});
|
|
2323
|
+
$('#m-refresh').addEventListener('click', () => {
|
|
2324
|
+
el.menu.hidden = true;
|
|
2325
|
+
load();
|
|
2326
|
+
});
|
|
2327
|
+
});
|
|
2328
|
+
document.addEventListener('click', (e) => {
|
|
2329
|
+
if (!el.menu.hidden && !el.menu.contains(e.target) && e.target.id !== 'btn-more') el.menu.hidden = true;
|
|
2330
|
+
});
|
|
2331
|
+
|
|
2332
|
+
/* ── 启动 ───────────────────────────────────────────── */
|
|
2333
|
+
|
|
2334
|
+
applyTheme();
|
|
2335
|
+
el.inspStub.addEventListener('click', () => {
|
|
2336
|
+
setInspCollapsed(false);
|
|
2337
|
+
renderInspector();
|
|
2338
|
+
});
|
|
2339
|
+
const bootParams = new URLSearchParams(location.search);
|
|
2340
|
+
const bootView = bootParams.get('view') ?? localStorage.getItem('mcore-view');
|
|
2341
|
+
if (['graph', 'timeline', 'table', 'turns', 'docs', 'health'].includes(bootView)) S.view = bootView;
|
|
2342
|
+
const bootQuery = bootParams.get('q');
|
|
2343
|
+
if (bootQuery) {
|
|
2344
|
+
S.query = bootQuery;
|
|
2345
|
+
el.search.value = bootQuery;
|
|
2346
|
+
el.searchClear.hidden = false;
|
|
2347
|
+
}
|
|
2348
|
+
if (bootParams.get('archive') === '1') {
|
|
2349
|
+
S.withArchive = true;
|
|
2350
|
+
localStorage.setItem('mcore-archive', '1');
|
|
2351
|
+
}
|
|
2352
|
+
await load();
|
|
2353
|
+
const bootCard = bootParams.get('card');
|
|
2354
|
+
if (bootCard && cards().some((c) => c.id === bootCard)) {
|
|
2355
|
+
S.selected = bootCard;
|
|
2356
|
+
setInspCollapsed(false);
|
|
2357
|
+
render();
|
|
2358
|
+
}
|
|
2359
|
+
setInterval(() => {
|
|
2360
|
+
if (!document.hidden) load({ quiet: true });
|
|
2361
|
+
}, 20_000);
|