dsh-cyrene-theme-change 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -19,6 +19,13 @@ SPDX-License-Identifier: MIT
19
19
  原项目的版权与功劳归原作者与直接上游;本仓库只对其新增部分负责。
20
20
  上游 MIT,本项目同样以 MIT 发布,并按 MIT 要求保留上述版权声明。
21
21
 
22
+ 参考与致谢
23
+ dsh-liquid-glass(Ultronen,MIT)
24
+ https://github.com/Ultronen/dsh-liquid-glass
25
+ 参考点:用 ctx.theme.overrideTokens 做半透明而不是自写 --dsw-* 变量;
26
+ backdrop-filter 会创建 containing block、破坏弹窗浮层,因此不做全局面模糊。
27
+ 本项目未复制其代码,仅采用其公开的结论与 API 用法。
28
+
22
29
  本项目以 MIT 许可证发布,完整条款见同目录的 LICENSE 文件。
23
30
  使用、修改、再分发与商用均被允许,只需保留本 NOTICE 与 LICENSE 中的版权声明。
24
31
  注意:第三方素材(见三、四节)不因本许可证而改变归属。
package/README.md CHANGED
@@ -26,6 +26,28 @@
26
26
  >
27
27
  > **Unofficial fan project.** Cyrene and all *Honkai: Star Rail* character art, names and assets are © miHoYo / HoYoverse, used here as non-commercial fan work. Not affiliated with or endorsed by miHoYo, HoYoverse or DeepSeek — see 「致谢」 below.
28
28
 
29
+ ## 液态玻璃
30
+
31
+ 三档,从省到贵:
32
+
33
+ | 档 | 做法 | 默认 |
34
+ |---|---|---|
35
+ | 关 | 普通毛玻璃(原有主题) | — |
36
+ | **透明** | `ctx.theme.overrideTokens` 把「面」的 token 换成半透明,背景图透上来 | ✅ 开启 |
37
+ | **折射** | 再叠一层 SVG `feTurbulence` + `feDisplacementMap` 做真实折射 | 关(开销大,在面板里开) |
38
+
39
+ 两条从实测里换来的硬约束:
40
+
41
+ 1. **不用 `backdrop-filter` 做全局面**。它会创建 containing block,把设置弹窗和浮层搞坏
42
+ (`dsh-liquid-glass` 也踩过这个坑并因此放弃;我们之前给 shell.overlay 加模糊,整窗糊掉)。
43
+ 2. **折射层只挂在 `::before` 上,且只作用于本插件自己的 `.cyre-*` 元素**。
44
+ 挂在元素本身会把文字一起扭曲;碰 `[data-slot]` 槽位会连累整个窗口。
45
+
46
+ 折射档的操作开销来自 `feDisplacementMap` 的逐像素采样,手机上明显吃 GPU,所以默认关闭。
47
+
48
+ 感谢 [`dsh-liquid-glass`](https://github.com/Ultronen/dsh-liquid-glass)(MIT)验证了
49
+ 「只做透明度、不做 backdrop-filter」这条路线,以及 `overrideTokens` 的正确用法。
50
+
29
51
  ## 与上游的差异
30
52
 
31
53
  上游 [`dsh-plugin-cyrene`](https://github.com/under-the-ocean/dsh-plugin-cyrene) 提供的是
package/lib/client.js CHANGED
@@ -164,7 +164,7 @@ body[data-dsh-cyrene][data-cyrene-skin="on"]{
164
164
  --dsw-alias-label-primary-inverted:#fff8fc;
165
165
  --dsw-alias-label-secondary:#87627a;
166
166
  --dsw-alias-label-tertiary:#826477;
167
- --dsw-alias-markdown-code-block:rgba(255,255,255,.62);
167
+ --dsw-alias-markdown-code-block:rgba(255,255,255,var(--cyre-glass-a,.62));
168
168
  --dsw-alias-menu-group-header-fill:rgba(255,236,246,.85);
169
169
  --dsw-alias-scrollbar-bg-l2:rgba(239,107,168,.18);
170
170
  --dsw-alias-scrollbar-hover-l2:rgba(239,107,168,.36);
@@ -177,11 +177,11 @@ body[data-dsh-cyrene][data-cyrene-skin="on"]{
177
177
  --dsw-alias-state-warn-label:#9a5f27;
178
178
  --dsw-alias-state-warn-tertiary:#fdeee0;
179
179
  --dsw-alias-tooltip-bg:rgba(74,43,63,.94);
180
- --dsw-specific-bubble:rgba(255,255,255,.55);
181
- --dsw-specific-input-major:rgba(255,255,255,.72);
180
+ --dsw-specific-bubble:rgba(255,255,255,var(--cyre-glass-a,.55));
181
+ --dsw-specific-input-major:rgba(255,255,255,var(--cyre-glass-a,.72));
182
182
  --dsw-specific-menu:rgba(255,250,253,.95);
183
183
  --dsw-specific-selector:rgba(255,255,255,.8);
184
- --dsw-specific-sidebar-fill:rgba(255,241,248,.55);
184
+ --dsw-specific-sidebar-fill:rgba(255,241,248,var(--cyre-glass-a,.55));
185
185
  --dsw-specific-sidebar-nav-item-active-accent:rgba(239,107,168,.16);
186
186
  --dsw-static-neutral-bluish-00:#fdf6fa;
187
187
  --dsw-shadow-lv2:0 18px 48px rgba(214,96,160,.16), 0 2px 8px rgba(214,96,160,.1);
@@ -224,7 +224,7 @@ body[data-dsh-cyrene][data-cyrene-skin="on"][data-ds-dark-theme]{
224
224
  --dsw-alias-label-primary-inverted:#2a1622;
225
225
  --dsw-alias-label-secondary:#cfa8bd;
226
226
  --dsw-alias-label-tertiary:#b08fa2;
227
- --dsw-alias-markdown-code-block:rgba(30,20,28,.6);
227
+ --dsw-alias-markdown-code-block:rgba(30,20,28,var(--cyre-glass-a,.6));
228
228
  --dsw-alias-menu-group-header-fill:rgba(60,36,54,.9);
229
229
  --dsw-alias-scrollbar-bg-l2:rgba(247,166,205,.18);
230
230
  --dsw-alias-scrollbar-hover-l2:rgba(247,166,205,.38);
@@ -241,11 +241,11 @@ body[data-dsh-cyrene][data-cyrene-skin="on"][data-ds-dark-theme]{
241
241
  所以这两种"小浮层"在深色下改成浅底:字仍然是那个深色,对比度约 13:1。 */
242
242
  --dsw-alias-tooltip-bg:rgba(255,246,251,.97);
243
243
  --dsw-alias-toast-bg:rgba(255,246,251,.97);
244
- --dsw-specific-bubble:rgba(58,36,52,.5);
245
- --dsw-specific-input-major:rgba(54,34,50,.75);
244
+ --dsw-specific-bubble:rgba(58,36,52,var(--cyre-glass-a,.5));
245
+ --dsw-specific-input-major:rgba(54,34,50,var(--cyre-glass-a,.75));
246
246
  --dsw-specific-menu:rgba(40,26,38,.96);
247
247
  --dsw-specific-selector:rgba(52,32,48,.85);
248
- --dsw-specific-sidebar-fill:rgba(46,28,44,.58);
248
+ --dsw-specific-sidebar-fill:rgba(46,28,44,var(--cyre-glass-a,.58));
249
249
  --dsw-specific-sidebar-nav-item-active-accent:rgba(247,166,205,.18);
250
250
  --dsw-static-neutral-bluish-00:#2a1a26;
251
251
  --dsw-shadow-lv2:0 20px 52px rgba(0,0,0,.45), 0 2px 10px rgba(0,0,0,.35);
@@ -359,10 +359,10 @@ body[data-dsh-cyrene][data-cyrene-skin="on"][data-ds-dark-theme] .cyre-bg-veil{
359
359
  气泡 position:fixed 的 Tooltip)是这一层的后代,一旦它成为 fixed 后代的
360
360
  包含块,鼠标停在发送键上时界面就会闪。 */
361
361
  body[data-dsh-cyrene][data-cyrene-skin="on"][data-cyre-bg="on"]{
362
- --dsw-specific-bubble:rgba(255,255,255,.78);
362
+ --dsw-specific-bubble:rgba(255,255,255,var(--cyre-glass-a,.78));
363
363
  }
364
364
  body[data-dsh-cyrene][data-cyrene-skin="on"][data-cyre-bg="on"][data-ds-dark-theme]{
365
- --dsw-specific-bubble:rgba(66,44,62,.76);
365
+ --dsw-specific-bubble:rgba(66,44,62,var(--cyre-glass-a,.76));
366
366
  }
367
367
  body[data-dsh-cyrene][data-cyrene-skin="on"][data-cyre-bg="on"] [data-conversation-scroll] :is(p,li,h1,h2,h3,h4,h5,h6,blockquote,td,th){
368
368
  text-shadow:0 1px 2px rgba(255,255,255,.9), 0 0 10px rgba(255,250,253,.72);
@@ -866,12 +866,100 @@ body[data-dsh-cyrene][data-ds-dark-theme]{
866
866
  .cyre-card{background-image:none}
867
867
  }
868
868
  /* 深色皮肤下内高光要收敛,否则整块发白发灰。 */
869
+ /* ── 液态玻璃:只做透明度,不用 backdrop-filter ──────────────────
870
+ 参考 dsh-liquid-glass 的实测结论:backdrop-filter 会创建 containing block,
871
+ 把设置弹窗和浮层搞坏(他们踩过,我们之前给 shell.overlay 加模糊也糊过整窗)。
872
+ 所以这里的"玻璃"靠两件事:
873
+ 1. 把 DSH 的面色 token 换成半透明——本文件里那组 --dsw-* 覆盖,
874
+ 2. 结构层只加内高光和细白边,让边缘有"玻璃厚度",不加任何模糊。 */
875
+ body[data-dsh-cyrene][data-cyrene-skin="on"] [data-chat-flow] [class*="bubble"]{
876
+ box-shadow:
877
+ inset 0 1px 0 rgba(255,255,255,.55),
878
+ 0 4px 16px rgba(176,120,156,.10);
879
+ border:1px solid rgba(255,255,255,.42);
880
+ }
881
+ body[data-dsh-cyrene][data-cyrene-skin="on"] [data-composer-card]{
882
+ box-shadow:
883
+ inset 0 1px 0 rgba(255,255,255,.8),
884
+ inset 0 -1px 0 rgba(255,255,255,.24),
885
+ 0 8px 26px rgba(176,120,156,.13);
886
+ border:1px solid rgba(255,255,255,.55);
887
+ }
888
+ body[data-dsh-cyrene][data-cyrene-skin="on"] [data-code-block-content]{
889
+ box-shadow:
890
+ inset 0 1px 0 rgba(255,255,255,.16),
891
+ 0 6px 20px rgba(20,10,20,.18);
892
+ border:1px solid rgba(255,255,255,.12);
893
+ }
894
+ /* ── 真·液态玻璃(可选,默认关) ──────────────────────────────────
895
+ 做法:给本插件自己的每一块面加一个 ::before,让它只承载
896
+ 的 backdrop-filter,再用 SVG 位移滤镜把「背后的像素」扭出折射起伏。
897
+ 两条硬约束,都是踩出来的:
898
+ 1. 滤镜挂在 ::before 上,不挂在元素本身 —— 否则文字会跟着扭;
899
+ 2. 只作用于 .cyre-* 自己的界面,绝不碰 [data-slot] 槽位 ——
900
+ 那会创建 containing block,把设置弹窗和浮层搞坏。
901
+ 开销:feTurbulence + feDisplacementMap 是逐像素算的,手机上明显吃 GPU,
902
+ 所以做成开关,默认 off。 */
903
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-card,
904
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-editor,
905
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-panel,
906
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-page{
907
+ position:relative;
908
+ isolation:isolate;
909
+ background-color:transparent;
910
+ }
911
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-card::before,
912
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-editor::before,
913
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-panel::before,
914
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-page::before{
915
+ content:"";
916
+ position:absolute;
917
+ inset:0;
918
+ border-radius:inherit;
919
+ z-index:-1;
920
+ background:linear-gradient(135deg,rgba(255,255,255,.34),rgba(255,255,255,.10) 52%,rgba(255,255,255,.28));
921
+ backdrop-filter:blur(10px) saturate(175%);
922
+ -webkit-backdrop-filter:blur(10px) saturate(175%);
923
+ filter:url(#cyrene-theme-change-liquid);
924
+ box-shadow:
925
+ inset 0 1px 0 rgba(255,255,255,.85),
926
+ inset 0 -1px 0 rgba(255,255,255,.30),
927
+ 0 10px 30px rgba(176,120,156,.16);
928
+ }
929
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-card::before,
930
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-editor::before,
931
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-panel::before,
932
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"][data-theme="dark"] .cyre-page::before{
933
+ background:linear-gradient(135deg,rgba(64,46,62,.42),rgba(38,30,42,.20) 52%,rgba(58,42,56,.36));
934
+ box-shadow:
935
+ inset 0 1px 0 rgba(255,255,255,.22),
936
+ inset 0 -1px 0 rgba(255,255,255,.06),
937
+ 0 10px 30px rgba(0,0,0,.34);
938
+ }
939
+ @supports not ((backdrop-filter:blur(1px)) and (filter:url(#x))){
940
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-card::before,
941
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-editor::before,
942
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-panel::before,
943
+ body[data-dsh-cyrene][data-cyrene-glass="heavy"] .cyre-page::before{
944
+ filter:none;
945
+ }
946
+ }
947
+ body[data-dsh-cyrene][data-cyrene-skin="on"] [data-slot="sidebar"]{
948
+ box-shadow:inset -1px 0 0 rgba(255,255,255,.45);
949
+ }
950
+ body[data-dsh-cyrene][data-cyrene-skin="on"][data-theme="dark"] [data-slot="sidebar"]{
951
+ box-shadow:inset -1px 0 0 rgba(255,255,255,.12);
952
+ }
869
953
  body[data-dsh-cyrene][data-cyrene-skin="on"] .cyre-card{
870
954
  box-shadow:
871
955
  inset 0 1px 0 rgba(255,255,255,.14),
872
956
  inset 0 -1px 0 rgba(255,255,255,.05),
873
957
  0 6px 22px rgba(0,0,0,.28);
874
958
  }
959
+ .cyre-ring{display:inline-flex;align-items:center;color:var(--cy-ui-accent,#e8699f);transition:color .2s ease}
960
+ .cyre-ring.warm{color:#e8a33d}
961
+ .cyre-ring.alert{color:#e0575b}
962
+ .cyre-ring-label{font-size:11.5px;color:var(--cy-ui-soft);font-variant-numeric:tabular-nums}
875
963
  .cyre-card-head{
876
964
  display:flex;align-items:center;gap:8px;
877
965
  font-size:12.5px;font-weight:600;color:var(--cy-ui-text);
@@ -1203,6 +1291,10 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
1203
1291
  persona: "", enabled: true, theme: true, stickers: true, rev: 0,
1204
1292
  /** 桌宠(Live2D)开关;默认关,避免和 dsh-cyrene 的桌宠叠在一起。 */
1205
1293
  pet: false,
1294
+ /** 液态玻璃不透明度(0.25–0.95)。 */
1295
+ glassAlpha: 0.55,
1296
+ /** 真·液态玻璃(SVG 位移折射):视觉最像,开销也最大,默认关。 */
1297
+ glassHeavy: false,
1206
1298
  /** 聊天里贴图的最大边长(px):落到 body 上的 --cyre-sticker-size。 */
1207
1299
  stickerSize: 96,
1208
1300
  defaultPersona: "", statePath: "",
@@ -1288,6 +1380,8 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
1288
1380
  if (typeof value.theme === "boolean") state.theme = value.theme;
1289
1381
  if (typeof value.stickers === "boolean") state.stickers = value.stickers;
1290
1382
  if (typeof value.pet === "boolean") state.pet = value.pet;
1383
+ if (Number.isFinite(value.glassAlpha)) state.glassAlpha = value.glassAlpha;
1384
+ if (typeof value.glassHeavy === "boolean") state.glassHeavy = value.glassHeavy;
1291
1385
  if (Number.isFinite(value.stickerSize)) state.stickerSize = value.stickerSize;
1292
1386
  if (value.hero !== null && typeof value.hero === "object") {
1293
1387
  if (typeof value.hero.title === "string") state.heroTitle = value.hero.title;
@@ -1310,11 +1404,20 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
1310
1404
  }
1311
1405
 
1312
1406
  /** 主题开关落到 body 属性上;样式表只认 on。贴图大小与色纱浓度落到 CSS 变量上。 */
1407
+ // ⚠️ 曾经试过用 ctx.theme.overrideTokens 做玻璃(dsh-liquid-glass 的路子),
1408
+ // 但本插件早有一套写死在本文件里的 --dsw-* 覆盖,选择器在 body[...] 上,
1409
+ // 优先级高于主题服务在 :root 写的值——结果服务覆写根本没生效。
1410
+ // 现在统一成本文件里的 CSS 变量 + --cyre-glass-a 滑块,只保留一条路。
1313
1411
  function applySkin() {
1314
1412
  if (!document.body) return;
1315
1413
  document.body.setAttribute(SKIN_ATTR, state.theme ? "on" : "off");
1414
+ document.body.setAttribute("data-cyrene-glass", state.glassHeavy === true ? "heavy" : "off");
1415
+ if (state.theme === true && state.glassHeavy === true) ensureLiquidFilter();
1316
1416
  const size = Number.isFinite(state.stickerSize) ? Math.round(state.stickerSize) : 96;
1317
1417
  document.body.style.setProperty("--cyre-sticker-size", size + "px");
1418
+ // 液态玻璃的不透明度:0.25(很透)→ 0.95(几乎不透明)
1419
+ const alpha = Number.isFinite(state.glassAlpha) ? Math.min(0.95, Math.max(0.25, state.glassAlpha)) : 0.55;
1420
+ document.body.style.setProperty("--cyre-glass-a", String(alpha));
1318
1421
  applyBackground();
1319
1422
  }
1320
1423
 
@@ -2345,6 +2448,8 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2345
2448
  '<label class="cyre-switch"><input type="checkbox" data-role="theme"><span>粉白毛玻璃主题</span></label>',
2346
2449
  '<label class="cyre-switch"><input type="checkbox" data-role="stickers"><span>允许发表情包</span></label>',
2347
2450
  '<label class="cyre-switch"><input type="checkbox" data-role="pet"><span>桌宠</span></label>',
2451
+ '<label class="cyre-switch"><input type="checkbox" data-role="glassHeavy"><span>液态玻璃 · 折射(开销大)</span></label>',
2452
+ '<label class="cyre-switch"><span>玻璃不透明度</span><input type="range" class="cyre-range" min="0.25" max="0.95" step="0.05" data-role="glassAlpha"><span data-role="glassAlphaVal">55%</span></label>',
2348
2453
  '<span class="cyre-status" data-role="status"></span>',
2349
2454
  "</div>",
2350
2455
  '<p class="cyre-hint" data-role="pet-line">当前情绪:<span data-role="pet-emotion">平静</span>(只读,来自关系与情绪)</p>',
@@ -2381,9 +2486,14 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2381
2486
  '<p class="cyre-hint">世界书是翁法罗斯的设定库(从官方 wiki 整理):常驻只占一行索引,模型要用 cyrene_worldbook_search 才会取正文。</p>',
2382
2487
  '<div class="cyre-card" data-role="usage-card">',
2383
2488
  '<div class="cyre-card-head"><span class="cyre-mark">✦</span><span>Token 用量</span></div>',
2489
+ '<div class="cyre-row" data-role="usage-head">',
2490
+ '<span class="cyre-ring" data-role="usage-ring" aria-hidden="true"></span>',
2491
+ '<span class="cyre-ring-label" data-role="usage-hit">—</span>',
2492
+ "</div>",
2384
2493
  '<div class="cyre-kv" data-role="usage-kv">读取中…</div>',
2385
2494
  '<div class="cyre-row">',
2386
2495
  '<button type="button" class="cyre-btn" data-role="usage-refresh">刷新</button>',
2496
+ '<button type="button" class="cyre-btn cyre-primary" data-role="usage-open">打开用量窗口</button>',
2387
2497
  '<span class="cyre-manager-status" data-role="usage-note"></span>',
2388
2498
  "</div>",
2389
2499
  "</div>",
@@ -2413,6 +2523,9 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2413
2523
  const themeBox = pick("theme");
2414
2524
  const stickersBox = pick("stickers");
2415
2525
  const petBox = pick("pet");
2526
+ const glassHeavyBox = pick("glassHeavy");
2527
+ const glassAlphaRange = pick("glassAlpha");
2528
+ const glassAlphaVal = pick("glassAlphaVal");
2416
2529
  const petEmotionLine = pick("pet-emotion");
2417
2530
  // ── Token 用量 ────────────────────────────────────────────────
2418
2531
  // 数据来自宿主自己的 /api/session/list(每个会话的 tokenUsage 投影),
@@ -2421,6 +2534,31 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2421
2534
  const usageKv = pick("usage-kv");
2422
2535
  const usageNote = pick("usage-note");
2423
2536
  const usageRefresh = pick("usage-refresh");
2537
+ const usageRing = pick("usage-ring");
2538
+ const usageHit = pick("usage-hit");
2539
+ /**
2540
+ * 环形指标:和 Cyrene-Agent 的 ContextUsageRing 同一个视觉语言(20px 圆环、
2541
+ * 三档变色),但指标换成**缓存命中率**——DSH 不向插件暴露上下文窗口大小,
2542
+ * 拿不到"占满度";命中率是我们能算准的,而且对成本最直接。
2543
+ * 颜色语义反过来:命中率高是好事(主题色),低才暖/红。
2544
+ */
2545
+ const RING_R = 8.5;
2546
+ const RING_C = 2 * Math.PI * RING_R;
2547
+ function paintRing(hit) {
2548
+ if (usageRing === null) return;
2549
+ const ratio = Math.max(0, Math.min(1, (Number(hit) || 0) / 100));
2550
+ const tier = hit >= 95 ? "" : hit >= 80 ? " warm" : " alert";
2551
+ usageRing.className = "cyre-ring" + tier;
2552
+ usageRing.innerHTML = '<svg viewBox="0 0 20 20" width="20" height="20">'
2553
+ + '<circle cx="10" cy="10" r="' + RING_R + '" fill="none" stroke="currentColor"'
2554
+ + ' stroke-opacity=".18" stroke-width="3"></circle>'
2555
+ + '<circle cx="10" cy="10" r="' + RING_R + '" fill="none" stroke="currentColor"'
2556
+ + ' stroke-width="3" stroke-linecap="round"'
2557
+ + ' stroke-dasharray="' + RING_C.toFixed(2) + '"'
2558
+ + ' stroke-dashoffset="' + (RING_C * (1 - ratio)).toFixed(2) + '"'
2559
+ + ' transform="rotate(-90 10 10)"></circle></svg>';
2560
+ if (usageHit !== null) usageHit.textContent = (Number(hit) || 0).toFixed(1) + "% 命中";
2561
+ }
2424
2562
  const PRICE = { input: 1, cache: 0.02, output: 4, outputPeak: 8 };
2425
2563
  const fmt = (n) => {
2426
2564
  const v = Number(n ?? 0);
@@ -2508,6 +2646,7 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2508
2646
  lines.push("缓存命中 " + all.hit.toFixed(1) + "%");
2509
2647
  lines.push("估算花费 " + money(all.cost) + "(" + rows.filter((r) => r.usage !== null).length + " 个会话)");
2510
2648
  usageKv.textContent = lines.join("\n");
2649
+ paintRing(all.hit);
2511
2650
  if (usageNote !== null) {
2512
2651
  usageNote.textContent = "按 DeepSeek 公开价估算,含缓存折扣";
2513
2652
  }
@@ -2515,6 +2654,19 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2515
2654
  if (usageRefresh !== null) {
2516
2655
  usageRefresh.addEventListener("click", () => { void renderUsage(); });
2517
2656
  }
2657
+ // 独立窗口:和 Cyrene-Agent 的用量查看器一样是单独一扇 GUI。
2658
+ // 液态玻璃也只有在那种自带背景的页面上才看得出来。
2659
+ const usageOpen = pick("usage-open");
2660
+ if (usageOpen !== null) {
2661
+ usageOpen.addEventListener("click", () => {
2662
+ try {
2663
+ window.open(new URL("cyrene/usage", document.baseURI).href, "cyrene-usage",
2664
+ "width=480,height=640,menubar=no,toolbar=no,location=no,status=no");
2665
+ } catch (error) {
2666
+ log("warn", "打开用量窗口失败", error);
2667
+ }
2668
+ });
2669
+ }
2518
2670
  if (typeof fetch === "function") {
2519
2671
  void renderUsage();
2520
2672
  } else if (usageKv !== null) {
@@ -2678,6 +2830,12 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2678
2830
  themeBox.checked = state.theme;
2679
2831
  stickersBox.checked = state.stickers !== false;
2680
2832
  petBox.checked = state.pet === true;
2833
+ if (glassHeavyBox !== null) glassHeavyBox.checked = state.glassHeavy === true;
2834
+ if (glassAlphaRange !== null) {
2835
+ const alpha = Number.isFinite(state.glassAlpha) ? state.glassAlpha : 0.55;
2836
+ glassAlphaRange.value = String(alpha);
2837
+ if (glassAlphaVal !== null) glassAlphaVal.textContent = Math.round(alpha * 100) + "%";
2838
+ }
2681
2839
  // 只读行:显示关系管线算出来的主导情绪;桌宠关着也照样更新(方便先看再开)。
2682
2840
  petEmotionLine.textContent = petEmotion.dimension === null
2683
2841
  ? "平静"
@@ -2735,6 +2893,15 @@ body[data-dsh-cyrene] [data-composer-input][data-placeholder^="Describe what you
2735
2893
  });
2736
2894
  petBox.addEventListener("change", () => {
2737
2895
  void save({ pet: petBox.checked }).then(paint);
2896
+ if (glassHeavyBox !== null) glassHeavyBox.addEventListener("change", () => {
2897
+ void save({ glassHeavy: glassHeavyBox.checked }).then(paint);
2898
+ });
2899
+ if (glassAlphaRange !== null) glassAlphaRange.addEventListener("input", () => {
2900
+ if (glassAlphaVal !== null) glassAlphaVal.textContent = Math.round(Number(glassAlphaRange.value) * 100) + "%";
2901
+ });
2902
+ if (glassAlphaRange !== null) glassAlphaRange.addEventListener("change", () => {
2903
+ void save({ glassAlpha: Number(glassAlphaRange.value) }).then(paint);
2904
+ });
2738
2905
  });
2739
2906
 
2740
2907
  // 状态筛选只重画卡片,不发请求(筛选是纯本地的)。
package/lib/index.js CHANGED
@@ -92,6 +92,193 @@ const PACKAGE_ID = 'dsh-cyrene-theme-change'
92
92
  const SECTION_NAME = 'cyrene:persona'
93
93
  /** fenced 路由前缀;客户端半请求 <base>/cyrene/state。 */
94
94
  const ROUTE_PREFIX = '/cyrene'
95
+
96
+ /**
97
+ * 「用量」独立窗口(GET /cyrene/usage)。
98
+ *
99
+ * 为什么单独一页而不是塞在设置面板里:
100
+ * 1. Cyrene-Agent 的用量查看器本身就是一扇独立 GUI;
101
+ * 2. 液态玻璃需要**背后有内容**才能看出来——设置面板背后是不透明底色,
102
+ * 玻璃只会变成一块磨砂色块。这一页自带渐变背景,玻璃才立得住。
103
+ *
104
+ * 数据:页面自己向宿主 /api/session/list 取(同源,带登录 cookie)。
105
+ * 价格:DeepSeek 公开价,未缓存输入 1 / 缓存命中 0.02 / 输出 4(闲时)8(峰值)元每百万。
106
+ */
107
+ const USAGE_PAGE_HTML = `<!doctype html>
108
+ <html lang="zh-CN"><head><meta charset="utf-8">
109
+ <meta name="viewport" content="width=device-width,initial-scale=1">
110
+ <title>昔涟 · Token 用量</title>
111
+ <style>
112
+ :root{color-scheme:light dark}
113
+ *{box-sizing:border-box}
114
+ body{
115
+ margin:0;min-height:100vh;padding:18px;
116
+ font:13px/1.6 system-ui,-apple-system,"PingFang SC",sans-serif;
117
+ color:#3f2d3a;
118
+ background:
119
+ radial-gradient(1200px 600px at 12% -10%,#ffd9ec 0%,transparent 60%),
120
+ radial-gradient(900px 500px at 100% 0%,#d7e6ff 0%,transparent 55%),
121
+ radial-gradient(800px 700px at 50% 120%,#ffe9f3 0%,transparent 60%),
122
+ linear-gradient(160deg,#fdf7fb 0%,#f4f7ff 48%,#fff5f9 100%);
123
+ background-attachment:fixed;
124
+ }
125
+ .wrap{max-width:560px;margin:0 auto;display:flex;flex-direction:column;gap:14px}
126
+ .card{
127
+ position:relative;border-radius:20px;padding:16px 18px;
128
+ background:linear-gradient(135deg,rgba(255,255,255,.62),rgba(255,255,255,.28) 46%,rgba(255,255,255,.5));
129
+ border:1px solid rgba(255,255,255,.75);
130
+ box-shadow:
131
+ inset 0 1px 0 rgba(255,255,255,.95),
132
+ inset 0 -1px 0 rgba(255,255,255,.35),
133
+ 0 10px 30px rgba(178,120,160,.16);
134
+ backdrop-filter:blur(22px) saturate(180%);
135
+ -webkit-backdrop-filter:blur(22px) saturate(180%);
136
+ }
137
+ .head{display:flex;align-items:center;gap:10px;font-weight:600;font-size:13.5px;letter-spacing:.3px}
138
+ .head .dot{color:#e8699f}
139
+ .hero{display:flex;align-items:center;gap:16px}
140
+ .ring{flex:0 0 auto;color:#e8699f}
141
+ .ring.warm{color:#e8a33d}.ring.alert{color:#e0575b}
142
+ .pct{font-size:30px;font-weight:700;line-height:1;font-variant-numeric:tabular-nums}
143
+ .sub{font-size:11.5px;opacity:.62;margin-top:4px}
144
+ .rows{display:flex;flex-direction:column;gap:6px;margin-top:10px}
145
+ .row{display:flex;justify-content:space-between;gap:12px;font-variant-numeric:tabular-nums}
146
+ .row span:first-child{opacity:.66}
147
+ .bar{height:6px;border-radius:999px;background:rgba(200,150,180,.22);overflow:hidden;display:flex;margin-top:10px}
148
+ .bar i{display:block;height:100%}
149
+ .legend{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:11.5px;opacity:.7}
150
+ .legend b{font-weight:600}
151
+ .hint{font-size:11.5px;opacity:.55;text-align:center}
152
+ @media (prefers-color-scheme:dark){
153
+ body{color:#f4e7ef;background:
154
+ radial-gradient(1200px 600px at 12% -10%,#4a2740 0%,transparent 60%),
155
+ radial-gradient(900px 500px at 100% 0%,#22324f 0%,transparent 55%),
156
+ linear-gradient(160deg,#211723 0%,#1a1f2b 50%,#241a24 100%)}
157
+ .card{background:linear-gradient(135deg,rgba(58,40,54,.66),rgba(40,32,46,.42) 46%,rgba(58,42,56,.58));
158
+ border-color:rgba(255,255,255,.16);
159
+ box-shadow:inset 0 1px 0 rgba(255,255,255,.18),inset 0 -1px 0 rgba(255,255,255,.05),0 10px 30px rgba(0,0,0,.42)}
160
+ .ring{color:#f19fc6}
161
+ }
162
+ </style></head>
163
+ <body><div class="wrap">
164
+
165
+ <div class="card">
166
+ <div class="head"><span class="dot">✦</span><span>缓存命中率</span></div>
167
+ <div class="hero">
168
+ <span class="ring" id="ring"></span>
169
+ <div>
170
+ <div class="pct" id="pct">—</div>
171
+ <div class="sub" id="hitsub">全部会话</div>
172
+ </div>
173
+ </div>
174
+ <div class="bar" id="bar"><i id="barCache"></i><i id="barUnc"></i></div>
175
+ <div class="legend">
176
+ <span><b id="lgCache">0</b> 缓存读取</span>
177
+ <span><b id="lgUnc">0</b> 未缓存</span>
178
+ <span><b id="lgOut">0</b> 输出</span>
179
+ </div>
180
+ </div>
181
+
182
+ <div class="card">
183
+ <div class="head"><span class="dot">✦</span><span>估算花费</span></div>
184
+ <div class="rows">
185
+ <div class="row"><span>本次会话</span><b id="costCur">—</b></div>
186
+ <div class="row"><span>全部会话</span><b id="costAll">—</b></div>
187
+ <div class="row"><span>计价档</span><b id="tier">—</b></div>
188
+ </div>
189
+ <div class="sub" id="note">按 DeepSeek 公开价估算:未缓存 1 / 缓存 0.02 / 输出 4(闲时)8(峰值)元每百万 token</div>
190
+ </div>
191
+
192
+ <div class="hint" id="stamp">读取中…</div>
193
+ </div>
194
+ <script>
195
+ (function () {
196
+ var PRICE = { input: 1, cache: 0.02, out: 4, outPeak: 8 };
197
+ var RING_R = 26, RING_C = 2 * Math.PI * RING_R;
198
+
199
+ function fmt(n) {
200
+ n = Number(n || 0);
201
+ if (n >= 1e6) return (n / 1e6).toFixed(2) + "M";
202
+ if (n >= 1e3) return (n / 1e3).toFixed(1) + "k";
203
+ return String(Math.round(n));
204
+ }
205
+ function money(n) { return "¥" + (n < 0.01 ? n.toFixed(4) : n.toFixed(2)); }
206
+ function peak() {
207
+ var d = new Date(), day = d.getDay(), h = d.getHours();
208
+ if (day === 0 || day === 6) return false;
209
+ return (h >= 9 && h < 12) || (h >= 14 && h < 18);
210
+ }
211
+ function paintRing(hit) {
212
+ var ratio = Math.max(0, Math.min(1, (Number(hit) || 0) / 100));
213
+ var el = document.getElementById("ring");
214
+ el.className = "ring" + (hit >= 95 ? "" : hit >= 80 ? " warm" : " alert");
215
+ el.innerHTML = '<svg width="76" height="76" viewBox="0 0 64 64">'
216
+ + '<circle cx="32" cy="32" r="' + RING_R + '" fill="none" stroke="currentColor" stroke-opacity=".16" stroke-width="6"></circle>'
217
+ + '<circle cx="32" cy="32" r="' + RING_R + '" fill="none" stroke="currentColor" stroke-width="6" stroke-linecap="round"'
218
+ + ' stroke-dasharray="' + RING_C.toFixed(2) + '" stroke-dashoffset="' + (RING_C * (1 - ratio)).toFixed(2) + '"'
219
+ + ' transform="rotate(-90 32 32)"></circle></svg>';
220
+ }
221
+ function rpc() {
222
+ return fetch("/api/session/list", {
223
+ method: "POST",
224
+ headers: { "content-type": "application/json" },
225
+ credentials: "same-origin",
226
+ body: JSON.stringify({
227
+ type: "client-request", rpcId: "usage-" + Date.now(),
228
+ method: "session/list", payload: { args: { _request: {} } }
229
+ })
230
+ }).then(function (r) { return r.json(); });
231
+ }
232
+ function sumOf(items) {
233
+ var s = { unc: 0, cache: 0, out: 0 };
234
+ items.forEach(function (it) {
235
+ var u = it && it.projections && it.projections.values && it.projections.values.tokenUsage;
236
+ if (!u) return;
237
+ s.unc += Number(u.uncachedInputTokens || 0);
238
+ s.cache += Number(u.cacheReadTokens || 0);
239
+ s.out += Number(u.outputTokens || 0);
240
+ });
241
+ return s;
242
+ }
243
+ function costOf(s) {
244
+ var p = peak();
245
+ return (s.unc / 1e6) * PRICE.input + (s.cache / 1e6) * PRICE.cache + (s.out / 1e6) * (p ? PRICE.outPeak : PRICE.out);
246
+ }
247
+ function refresh() {
248
+ rpc().then(function (payload) {
249
+ var items = (payload && payload.result && payload.result.value && payload.result.value.items) || [];
250
+ var all = sumOf(items);
251
+ var total = all.unc + all.cache;
252
+ var hit = total === 0 ? 0 : (all.cache / total) * 100;
253
+ paintRing(hit);
254
+ document.getElementById("pct").textContent = hit.toFixed(1) + "%";
255
+ document.getElementById("hitsub").textContent = items.length + " 个会话 · 未缓存 " + fmt(all.unc);
256
+ document.getElementById("lgCache").textContent = fmt(all.cache);
257
+ document.getElementById("lgUnc").textContent = fmt(all.unc);
258
+ document.getElementById("lgOut").textContent = fmt(all.out);
259
+ var bar = document.getElementById("bar");
260
+ bar.children[0].style.width = (total === 0 ? 0 : (all.cache / total) * 100) + "%";
261
+ bar.children[0].style.background = "linear-gradient(90deg,#f9a8d4,#e8699f)";
262
+ bar.children[1].style.width = (total === 0 ? 0 : (all.unc / total) * 100) + "%";
263
+ bar.children[1].style.background = "rgba(160,120,150,.35)";
264
+ document.getElementById("costAll").textContent = money(costOf(all));
265
+ var cur = document.getElementById("costCur");
266
+ var holder = window.opener && window.opener.document
267
+ ? window.opener.document.querySelector("[data-conversation-session]") : null;
268
+ var sid = holder ? holder.getAttribute("data-conversation-session") : "";
269
+ var mine = items.filter(function (it) { return it.sessionId === sid; });
270
+ if (mine.length > 0) cur.textContent = money(costOf(sumOf(mine)));
271
+ else cur.textContent = "(切换回主窗口刷新)";
272
+ document.getElementById("tier").textContent = peak() ? "峰值(工作日 9-12 / 14-18)" : "闲时";
273
+ document.getElementById("stamp").textContent = "更新于 " + new Date().toLocaleTimeString() + " · 每 5 秒自动刷新";
274
+ }).catch(function (e) {
275
+ document.getElementById("stamp").textContent = "读取失败:" + e.message;
276
+ });
277
+ }
278
+ refresh();
279
+ setInterval(refresh, 5000);
280
+ })();
281
+ </script></body></html>`
95
282
  /** 请求体上限,防止一次误粘贴把提示词写爆。 */
96
283
  const MAX_BODY_BYTES = 256 * 1024
97
284
 
@@ -261,6 +448,14 @@ const state = {
261
448
  * 这是纯前端展示开关,关掉只卸 canvas,不影响记忆与关系。
262
449
  */
263
450
  pet: false,
451
+ /**
452
+ * 液态玻璃的不透明度(0.25–0.95,数字越大越实)。
453
+ * 走宿主 ctx.theme.overrideTokens 把面色 token 换成 rgba,不做模糊——
454
+ * backdrop-filter 会创建 containing block,把设置弹窗和浮层搞坏。
455
+ */
456
+ glassAlpha: 0.55,
457
+ /** 真·液态玻璃(SVG 位移折射)。开销大,默认关。 */
458
+ glassHeavy: false,
264
459
  /** 聊天里贴图的最大边长(px):客户端半把它落到 CSS 变量上。 */
265
460
  stickerSize: 96,
266
461
  /**
@@ -546,6 +741,17 @@ function applyPatch(patch) {
546
741
  state.pet = patch.pet
547
742
  changed = true
548
743
  }
744
+ if (typeof patch.glassHeavy === 'boolean' && patch.glassHeavy !== state.glassHeavy) {
745
+ state.glassHeavy = patch.glassHeavy
746
+ changed = true
747
+ }
748
+ if (Number.isFinite(patch.glassAlpha)) {
749
+ const alpha = Math.min(0.95, Math.max(0.25, Number(patch.glassAlpha)))
750
+ if (alpha !== state.glassAlpha) {
751
+ state.glassAlpha = alpha
752
+ changed = true
753
+ }
754
+ }
549
755
  if (Number.isFinite(patch.stickerSize)) {
550
756
  const size = clampStickerSize(patch.stickerSize)
551
757
  if (size !== state.stickerSize) {
@@ -623,6 +829,8 @@ function persist(ctx) {
623
829
  theme: state.theme,
624
830
  stickers: state.stickers,
625
831
  pet: state.pet,
832
+ glassAlpha: state.glassAlpha,
833
+ glassHeavy: state.glassHeavy,
626
834
  stickerSize: state.stickerSize,
627
835
  customStickers: state.customStickers.map((entry) => ({ ...entry })),
628
836
  customBackgrounds: state.customBackgrounds.map((entry) => ({ ...entry })),
@@ -3043,6 +3251,16 @@ export function apply(ctx, config) {
3043
3251
  const url = new URL(req.url ?? '/', 'http://localhost')
3044
3252
  const route = url.pathname.slice(ROUTE_PREFIX.length) || '/'
3045
3253
  try {
3254
+ if (route === '/usage' && req.method === 'GET') {
3255
+ // 独立的「用量」窗口:Cyrene-Agent 是单独一扇 GUI,这里也做成独立页,
3256
+ // 顺便解决液态玻璃在没有背景的面板里看不出来的问题(这页自带渐变背景)。
3257
+ res.writeHead(200, {
3258
+ 'Content-Type': 'text/html; charset=utf-8',
3259
+ 'Cache-Control': 'no-store',
3260
+ })
3261
+ res.end(USAGE_PAGE_HTML)
3262
+ return
3263
+ }
3046
3264
  if (route === '/state' && req.method === 'GET') {
3047
3265
  await Promise.all([ensureLoaded(ctx), ensureHero(ctx)])
3048
3266
  sendJson(res, 200, { ok: true, value: publicState() })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cyrene-theme-change",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "昔涟(Cyrene)主题:粉白渐变毛玻璃 UI + 侧边栏可编辑的人格设定 + 表情包 / 背景图 / 世界书 + 认知记忆(L0/L1/L2 分层、成色衰减、语义召回、账本与健康行、压缩反思)与关系情绪 | A Cyrene (Honkai: Star Rail) theme for DeepSeek Harness",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",