dsh-plugin-zotero 0.6.8 → 0.7.0

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/client/client.js CHANGED
@@ -326,6 +326,19 @@ function deleteAnnotation(input) {
326
326
  function createAnnotations(input) {
327
327
  return post("annotation-create", input);
328
328
  }
329
+ /**
330
+ * 翻译一段选区文本。
331
+ *
332
+ * 引擎与目标语言默认由 Host 读设置决定(含按原文语种自动判向);只有用户在浮层里
333
+ * 临时切换引擎时才传 `provider` 覆盖 —— 长期默认值仍只有设置页一个来源。
334
+ * 请求经 Host 代理:webview 直连微软端点会被 CORS 挡掉。
335
+ */
336
+ function translateSelection(text, options = {}) {
337
+ return post("translate", {
338
+ text,
339
+ provider: options.provider
340
+ }, options.signal);
341
+ }
329
342
  //#endregion
330
343
  //#region src/client/itemTitles.ts
331
344
  /**
@@ -426,6 +439,8 @@ const dicts = {
426
439
  "action.insertCollection": "把整目录加入对话",
427
440
  "action.copy": "复制",
428
441
  "action.retry": "重试",
442
+ "action.close": "关闭",
443
+ "action.translate": "翻译",
429
444
  "status.zoteroOn": "Zotero 已连接",
430
445
  "status.zoteroOff": "Zotero 未连接",
431
446
  "status.mcpOn": "模型工具可用",
@@ -576,6 +591,7 @@ const dicts = {
576
591
  "settings.hint": "这些参数决定面板与模型工具如何连上 Zotero;改完自动保存、即时生效,无需重启。",
577
592
  "group.api": "API 设置",
578
593
  "group.mcp": "MCP 设置",
594
+ "group.translate": "划词翻译",
579
595
  "tools.title": "MCP 工具",
580
596
  "tools.loading": "正在读取工具列表…",
581
597
  "tools.reload": "重新读取",
@@ -637,6 +653,23 @@ const dicts = {
637
653
  "annotation.commentQuickPlaceholder": "评论(回车即标黄写入)",
638
654
  "annotation.created": "已写入 Zotero",
639
655
  "annotation.createdMany": "已写入 Zotero({count} 条)",
656
+ "translate.title": "翻译",
657
+ "translate.dragHint": "拖动标题栏可移动位置",
658
+ "translate.resizeHint": "拖动右下角可调整大小",
659
+ "translate.loading": "正在翻译…",
660
+ "translate.failed": "翻译失败,请检查网络后重试",
661
+ "translate.needRestart": "翻译服务还没启动:请重启一次 DSH(插件宿主半更新后需要重启才生效)",
662
+ "translate.retry": "重试",
663
+ "translate.copy": "复制译文",
664
+ "translate.copied": "译文已复制",
665
+ "translate.engine.bing": "Bing",
666
+ "translate.engine.deepseek": "DeepSeek",
667
+ "translate.engine.default": "默认引擎(跟随设置)",
668
+ "translate.engine.label": "翻译引擎",
669
+ "translate.engine.hint": "换引擎会立刻重新翻译;只影响本次会话,永久默认请在设置页改",
670
+ "translate.engine.actualHint": "本次实际使用的引擎;模型通道不可用时会自动回落",
671
+ "translate.original": "原文",
672
+ "translate.translation": "译文",
640
673
  "group.write": "Zotero 写权限",
641
674
  "write.toggle": "允许写入 Zotero",
642
675
  "write.toggleHint": "打开后可在文献详情里新建、修改、删除高亮与笔记,模型也能改库;写入直接落到 Zotero 本地库,插件不另存副本",
@@ -673,6 +706,21 @@ const dicts = {
673
706
  "field.fulltextMaxBytesHint": "单条附件全文最大返回字节数,超出会被截断,默认 204800",
674
707
  "field.defaultLimit": "默认条目数",
675
708
  "field.defaultLimitHint": "面板条目列表默认拉取条数,默认 50",
709
+ "field.translateProvider": "默认翻译引擎",
710
+ "field.translateProviderHint": "决定划词翻译默认把选区发给谁:Bing 免费、快、不需要密钥;DeepSeek 走当前账号模型,学术长句更顺但会占用额度,不可用时自动回落 Bing。译文浮层里可以临时换引擎",
711
+ "field.translateTarget": "目标语言",
712
+ "field.translateTargetHint": "默认自动判向:中文原文译英文、英文(及其它语种)原文译中文;也可手动锁定一门语言。选区文本会发送到所选翻译服务",
713
+ "translate.provider.bing": "Bing 免费翻译(快)",
714
+ "translate.provider.deepseek": "DeepSeek 模型精翻(占额度)",
715
+ "translate.target.auto": "自动(中→英 / 英→中)",
716
+ "translate.target.zh-CN": "中文(简体)",
717
+ "translate.target.zh-TW": "中文(繁体)",
718
+ "translate.target.en": "英语",
719
+ "translate.target.ja": "日语",
720
+ "translate.target.ko": "韩语",
721
+ "translate.target.fr": "法语",
722
+ "translate.target.de": "德语",
723
+ "translate.target.ru": "俄语",
676
724
  "form.unavailable": "该插件当前未加载,暂时无法配置。",
677
725
  "form.readOnly": "本部署的设置为只读。",
678
726
  "form.autosaving": "正在自动保存…",
@@ -733,6 +781,10 @@ const dicts = {
733
781
  "cmp.excerpt.header": "【Zotero 摘录|{title}|{key}】",
734
782
  "cmp.excerpt.quote": "“{value}”",
735
783
  "cmp.excerpt.chipLabel": "摘录:{value}",
784
+ "cmp.translation.header": "【Zotero 翻译|{title}|{key}】",
785
+ "cmp.translation.quote": "原文:“{value}”",
786
+ "cmp.translation.translated": "译文:{value}",
787
+ "cmp.translation.chipLabel": "翻译:{value}",
736
788
  "cmp.collection.header": "【Zotero 目录|{name}|{key}】共 {n} 条",
737
789
  "cmp.collection.line": "- {title}({meta})",
738
790
  "cmp.collection.more": "……(仅列出前 {n} 条;完整清单可用 mcp__zotero__get_collection_items 获取)",
@@ -766,6 +818,8 @@ const dicts = {
766
818
  "action.insertCollection": "Add the collection to the chat",
767
819
  "action.copy": "Copy",
768
820
  "action.retry": "Retry",
821
+ "action.close": "Close",
822
+ "action.translate": "Translate",
769
823
  "status.zoteroOn": "Zotero connected",
770
824
  "status.zoteroOff": "Zotero not connected",
771
825
  "status.mcpOn": "Model tools available",
@@ -916,6 +970,7 @@ const dicts = {
916
970
  "settings.hint": "These parameters decide how the panel and the model tools reach Zotero; edits save automatically and take effect immediately, no restart needed.",
917
971
  "group.api": "API settings",
918
972
  "group.mcp": "MCP settings",
973
+ "group.translate": "Selection translation",
919
974
  "tools.title": "MCP tools",
920
975
  "tools.loading": "Loading tool list…",
921
976
  "tools.reload": "Reload",
@@ -977,6 +1032,23 @@ const dicts = {
977
1032
  "annotation.commentQuickPlaceholder": "Comment (Enter marks it in yellow)",
978
1033
  "annotation.created": "Saved to Zotero",
979
1034
  "annotation.createdMany": "Saved {count} annotations to Zotero",
1035
+ "translate.title": "Translation",
1036
+ "translate.dragHint": "Drag the title bar to move",
1037
+ "translate.resizeHint": "Drag the bottom-right corner to resize",
1038
+ "translate.loading": "Translating…",
1039
+ "translate.failed": "Translation failed. Check the network and retry.",
1040
+ "translate.needRestart": "Translation service is not up yet: restart DSH once (the plugin host half needs a restart after upgrading)",
1041
+ "translate.retry": "Retry",
1042
+ "translate.copy": "Copy translation",
1043
+ "translate.copied": "Translation copied",
1044
+ "translate.engine.bing": "Bing",
1045
+ "translate.engine.deepseek": "DeepSeek",
1046
+ "translate.engine.default": "Default (from settings)",
1047
+ "translate.engine.label": "Translation engine",
1048
+ "translate.engine.hint": "Switches and re-translates immediately; applies to this session only. Change Settings for a permanent default",
1049
+ "translate.engine.actualHint": "Engine actually used; falls back automatically if the model channel is unavailable",
1050
+ "translate.original": "Source",
1051
+ "translate.translation": "Translation",
980
1052
  "group.write": "Zotero write access",
981
1053
  "write.toggle": "Allow writing to Zotero",
982
1054
  "write.toggleHint": "When on, the item view can create, edit and delete highlights and notes, and the model can change the library too. Writes go straight into your local Zotero library; the plugin keeps no copy of its own",
@@ -1013,6 +1085,21 @@ const dicts = {
1013
1085
  "field.fulltextMaxBytesHint": "Max bytes returned for one attachment full text; longer content is truncated, default 204800",
1014
1086
  "field.defaultLimit": "Default item count",
1015
1087
  "field.defaultLimitHint": "Default number of items a page loads, default 50",
1088
+ "field.translateProvider": "Default translation engine",
1089
+ "field.translateProviderHint": "Where selected text is sent by default: Bing is free, fast and needs no API key; DeepSeek uses your account model for better academic phrasing at the cost of quota, and falls back to Bing when unavailable. The translation popover can override it temporarily",
1090
+ "field.translateTarget": "Target language",
1091
+ "field.translateTargetHint": "Auto by default: Chinese source is translated into English, English (and other languages) into Chinese; you can also pin a language. The selected text is sent to the chosen service",
1092
+ "translate.provider.bing": "Bing (free, fast)",
1093
+ "translate.provider.deepseek": "DeepSeek model (uses quota)",
1094
+ "translate.target.auto": "Auto (CN→EN / EN→CN)",
1095
+ "translate.target.zh-CN": "Chinese (Simplified)",
1096
+ "translate.target.zh-TW": "Chinese (Traditional)",
1097
+ "translate.target.en": "English",
1098
+ "translate.target.ja": "Japanese",
1099
+ "translate.target.ko": "Korean",
1100
+ "translate.target.fr": "French",
1101
+ "translate.target.de": "German",
1102
+ "translate.target.ru": "Russian",
1016
1103
  "form.unavailable": "This plugin is not loaded, so it cannot be configured right now.",
1017
1104
  "form.readOnly": "This deployment stores settings read-only.",
1018
1105
  "form.autosaving": "Saving automatically…",
@@ -1073,6 +1160,10 @@ const dicts = {
1073
1160
  "cmp.excerpt.header": "[Zotero excerpt | {title} | {key}]",
1074
1161
  "cmp.excerpt.quote": "“{value}”",
1075
1162
  "cmp.excerpt.chipLabel": "Excerpt: {value}",
1163
+ "cmp.translation.header": "[Zotero translation | {title} | {key}]",
1164
+ "cmp.translation.quote": "Source: “{value}”",
1165
+ "cmp.translation.translated": "Translation: {value}",
1166
+ "cmp.translation.chipLabel": "Translation: {value}",
1076
1167
  "cmp.collection.header": "[Zotero collection | {name} | {key}] {n} items",
1077
1168
  "cmp.collection.line": "- {title} ({meta})",
1078
1169
  "cmp.collection.more": "… (first {n} only; use mcp__zotero__get_collection_items for the full list)",
@@ -1748,10 +1839,28 @@ function excerptText(t, detail, quote) {
1748
1839
  * PDF 抽取会在汉字之间插空格,标签里顺手清掉(展开给模型的原文不动)。
1749
1840
  */
1750
1841
  function excerptChipLabel(t, quote) {
1751
- const source = tidyAnnotation(quote);
1842
+ return tpl(t("cmp.excerpt.chipLabel"), { value: summarize(quote) });
1843
+ }
1844
+ /**
1845
+ * 一段「原文 + 译文」的引用文本。
1846
+ *
1847
+ * 与纯摘录不同,这里把译文单独成段:模型读到的是对照文本,不需要自己再翻一遍。
1848
+ */
1849
+ function translationText(t, detail, quote, translated) {
1850
+ return `${tpl(t("cmp.translation.header"), {
1851
+ title: detail.title,
1852
+ key: detail.key
1853
+ })}\n${tpl(t("cmp.translation.quote"), { value: quote })}\n${tpl(t("cmp.translation.translated"), { value: translated })}`;
1854
+ }
1855
+ /** 翻译 chip 的标签:用译文开头,比原文更能说明这块内容是什么。 */
1856
+ function translationChipLabel(t, translated) {
1857
+ return tpl(t("cmp.translation.chipLabel"), { value: summarize(translated) });
1858
+ }
1859
+ /** 截到 chip 能显示的长度;胶囊自己还会再省略,这里只是让 ref 前的标签短一点。 */
1860
+ function summarize(text) {
1861
+ const source = tidyAnnotation(text);
1752
1862
  const chars = Array.from(source);
1753
- const summary = chars.length > CHIP_LABEL_LIMIT ? `${chars.slice(0, CHIP_LABEL_LIMIT).join("")}…` : source;
1754
- return tpl(t("cmp.excerpt.chipLabel"), { value: summary });
1863
+ return chars.length > CHIP_LABEL_LIMIT ? `${chars.slice(0, CHIP_LABEL_LIMIT).join("")}…` : source;
1755
1864
  }
1756
1865
  /**
1757
1866
  * PDF 抽取会在汉字之间插空格(`硫 化 氢`),展示与插入时去掉;
@@ -1997,6 +2106,21 @@ async function excerptCitation(t, body) {
1997
2106
  title: decodeRefPart("摘录", rawTitle)
1998
2107
  }, decodeRefPart("摘录", rawQuote));
1999
2108
  }
2109
+ /**
2110
+ * 一段「原文 + 译文」的引用。
2111
+ *
2112
+ * 四段自包含(key / 标题 / 原文 / 译文),不请求 Host:译文是用户当下看到的那一版,
2113
+ * 重新翻译不会改写已插入的 chip。
2114
+ */
2115
+ async function translationCitation(t, body) {
2116
+ const parts = body.split(":");
2117
+ const [rawKey, rawTitle, rawQuote, rawTranslated] = parts;
2118
+ if (parts.length !== 4 || rawKey === void 0 || rawTitle === void 0 || rawQuote === void 0 || rawTranslated === void 0) throw new Error(`无法识别的 Zotero 翻译引用:${body}`);
2119
+ return translationText(t, {
2120
+ key: decodeRefPart("翻译", rawKey),
2121
+ title: decodeRefPart("翻译", rawTitle)
2122
+ }, decodeRefPart("翻译", rawQuote), decodeRefPart("翻译", rawTranslated));
2123
+ }
2000
2124
  /** 解码 ref 里的一段;坏转义会抛 URIError,换成带来源的可辨认错误。 */
2001
2125
  function decodeRefPart(kind, encoded) {
2002
2126
  try {
@@ -2072,6 +2196,12 @@ const ANNOTATION_PREFIX = "ann:";
2072
2196
  * `encodeURIComponent` 把 `:` 与所有空白都编码掉,用 `:` 分段不会歧义。
2073
2197
  */
2074
2198
  const EXCERPT_PREFIX = "exc:";
2199
+ /**
2200
+ * 划词翻译:`tr:<编码后的 itemKey>:<编码后的标题>:<编码后的原文>:<编码后的译文>`。
2201
+ *
2202
+ * 和摘录同理由:译文只存在于插入那一刻,文库里没有对应对象,四段全自包含。
2203
+ */
2204
+ const TRANSLATION_PREFIX = "tr:";
2075
2205
  /** 单个标签:`tag:<编码后的标签名>`。 */
2076
2206
  const TAG_PREFIX = "tag:";
2077
2207
  /** 标签组:`tags:<all|any>:<编码后的标签名>,…`。 */
@@ -2092,6 +2222,7 @@ function citationForRef(t, ref, signal) {
2092
2222
  if (ref.startsWith(NOTE_PREFIX)) return noteCitation(t, ref.slice(5), signal);
2093
2223
  if (ref.startsWith(ANNOTATION_PREFIX)) return annotationCitation(t, ref.slice(4), signal);
2094
2224
  if (ref.startsWith(EXCERPT_PREFIX)) return excerptCitation(t, ref.slice(4));
2225
+ if (ref.startsWith(TRANSLATION_PREFIX)) return translationCitation(t, ref.slice(3));
2095
2226
  if (ref.startsWith(TAG_SET_PREFIX)) return tagSetCitation(t, ref.slice(5), signal);
2096
2227
  if (ref.startsWith(TAG_PREFIX)) return tagCitation(t, ref.slice(4), signal);
2097
2228
  return Promise.reject(/* @__PURE__ */ new Error(`无法识别的 Zotero 引用:${ref}`));
@@ -2164,6 +2295,26 @@ function excerptReference(key, title, quote, label) {
2164
2295
  };
2165
2296
  }
2166
2297
  /**
2298
+ * 一段「原文 + 译文」的 chip。
2299
+ *
2300
+ * 四段全编码,理由同 {@link excerptReference}:译文只存在于插入那一刻。
2301
+ */
2302
+ function translationReference(key, title, quote, translated, label) {
2303
+ const ref = `${TRANSLATION_PREFIX}${[
2304
+ key,
2305
+ title,
2306
+ quote,
2307
+ translated
2308
+ ].map((part) => encodeURIComponent(part)).join(":")}`;
2309
+ return {
2310
+ source: REF_SOURCE,
2311
+ ref,
2312
+ label,
2313
+ appearance: "file",
2314
+ clipboardText: `@${ref}`
2315
+ };
2316
+ }
2317
+ /**
2167
2318
  * 单个标签的 chip。
2168
2319
  *
2169
2320
  * 标签名可能含空格,`clipboardText` 必须无空格,所以先 `encodeURIComponent`。
@@ -2302,6 +2453,27 @@ const TAG_BUTTON_CLASS = "dsh-zp-tag";
2302
2453
  function tagButtonClass(selected = false) {
2303
2454
  return selected ? `${TAG_BUTTON_CLASS} is-selected` : TAG_BUTTON_CLASS;
2304
2455
  }
2456
+ /**
2457
+ * 条目类型图标的 class:配色向 Zotero 7 的 item-type 图标靠拢。
2458
+ *
2459
+ * Zotero 的普通条目是白纸 + 近黑的灰线(#444444),只有书(#4072E5 蓝)、
2460
+ * 笔记(#FAA700 黄)、附件(#DB2C3A 红)带特征色。这里沿用这四支色,
2461
+ * 但仍用自己的单线描边画法:不复制官方 SVG、不铺纸面底色。
2462
+ * 已读态不用粉色,改去饱和 + 淡化,避免整列图标泛彩。
2463
+ */
2464
+ const ITEM_ICON_CLASS = "dsh-zp-item-icon";
2465
+ /** 只有这三个家族带 Zotero 特征色,其余一律墨色。 */
2466
+ const ITEM_ICON_ACCENT_FAMILIES = /* @__PURE__ */ new Set([
2467
+ "book",
2468
+ "note",
2469
+ "attachment"
2470
+ ]);
2471
+ function itemTypeIconClass(family, read = false) {
2472
+ const parts = [ITEM_ICON_CLASS];
2473
+ if (ITEM_ICON_ACCENT_FAMILIES.has(family)) parts.push(`is-${family}`);
2474
+ if (read) parts.push("is-read");
2475
+ return parts.join(" ");
2476
+ }
2305
2477
  /** 全局主题样式:只在入口注入一次,portal / 浮层里的按钮同样生效。 */
2306
2478
  const THEME_CSS = `
2307
2479
  .dsh-zp-soft-btn {
@@ -2338,6 +2510,26 @@ const THEME_CSS = `
2338
2510
  .dsh-zp-tag.is-selected:active {
2339
2511
  background-color: #404040 !important;
2340
2512
  }
2513
+ /* 条目类型图标:近黑墨色为主,只有书 / 笔记 / 附件留 Zotero 特征色。
2514
+ 先给宿主文字色兜底,再用 light-dark() 做深浅两套;老浏览器退成墨色。 */
2515
+ .dsh-zp-item-icon {
2516
+ color: var(--dsw-alias-label-primary, #3b3b3b);
2517
+ color: light-dark(#3b3b3b, #d0d0d0);
2518
+ opacity: 0.95;
2519
+ }
2520
+ .dsh-zp-item-icon.is-book {
2521
+ color: light-dark(#4072e5, #8eaef5);
2522
+ }
2523
+ .dsh-zp-item-icon.is-note {
2524
+ color: light-dark(#b87b06, #eeb23c);
2525
+ }
2526
+ .dsh-zp-item-icon.is-attachment {
2527
+ color: light-dark(#d32f3c, #f0727a);
2528
+ }
2529
+ .dsh-zp-item-icon.is-read {
2530
+ opacity: 0.5;
2531
+ filter: grayscale(1);
2532
+ }
2341
2533
  .dsh-zp-title {
2342
2534
  display: inline-flex;
2343
2535
  align-items: center;
@@ -2451,6 +2643,27 @@ const API_BASE = "/dsh-zotero/api";
2451
2643
  const DISABLED_FIELD = "disabledMcpTools";
2452
2644
  /** 写入总开关的配置字段名。 */
2453
2645
  const WRITE_FIELD = "writeEnabled";
2646
+ /** 划词翻译的引擎字段名。 */
2647
+ const TRANSLATE_PROVIDER_FIELD = "translateProvider";
2648
+ /** 划词翻译的目标语言字段名。 */
2649
+ const TRANSLATE_TARGET_FIELD = "translateTarget";
2650
+ /** 允许的引擎取值;与 Host `TranslateProvider`、译文浮层下拉同步。 */
2651
+ const TRANSLATE_PROVIDERS = ["bing", "deepseek"];
2652
+ /**
2653
+ * 目标语言候选:首项 `auto` = 按原文语种中英互译(与 Zotero 翻译插件一致),
2654
+ * 其余是手动锁定;够覆盖常见文献语言,再多的用「自定义」不划算。
2655
+ */
2656
+ const TRANSLATE_TARGETS = [
2657
+ "auto",
2658
+ "zh-CN",
2659
+ "zh-TW",
2660
+ "en",
2661
+ "ja",
2662
+ "ko",
2663
+ "fr",
2664
+ "de",
2665
+ "ru"
2666
+ ];
2454
2667
  /** 「API 设置」组的字段(本地 API 与面板行为)。 */
2455
2668
  const API_FIELDS = [
2456
2669
  {
@@ -2538,6 +2751,26 @@ function booleanField(field) {
2538
2751
  };
2539
2752
  }
2540
2753
  /**
2754
+ * 枚举字段的规格:值本身就是字符串,但要挡住手改 patch 文件写进来的野值。
2755
+ *
2756
+ * 界面上不出现文本框(引擎与目标语言都是下拉),所以非法值的唯一来源就是
2757
+ * 配置文件;`format` 把野值显示成默认值,用户不动它就不会把野值再存一遍。
2758
+ */
2759
+ function enumField(field, allowed, fallback) {
2760
+ return {
2761
+ field,
2762
+ format: (value) => typeof value === "string" && allowed.includes(value) ? value : fallback,
2763
+ parse: (text) => {
2764
+ const trimmed = text.trim();
2765
+ if (trimmed === "") return { kind: "clear" };
2766
+ return allowed.includes(trimmed) ? {
2767
+ kind: "set",
2768
+ value: trimmed
2769
+ } : void 0;
2770
+ }
2771
+ };
2772
+ }
2773
+ /**
2541
2774
  * 一张卡片的暂存表单模型:改动先进暂存,由组件的防抖自动保存落盘(没有保存按钮)。
2542
2775
  * `scope` 由 `configForms.get(ROW_ID)` 提供(本条的共享配置表单)。
2543
2776
  */
@@ -2548,7 +2781,9 @@ var ZoteroCardController = class {
2548
2781
  this.form = new _deepseek_ai_dsh_client_ui_primitives.SettingsFormModel(scope, [
2549
2782
  ...ALL_FIELDS.map((field) => field.numeric ? (0, _deepseek_ai_dsh_client_ui_primitives.settingsNumberField)(field.name) : (0, _deepseek_ai_dsh_client_ui_primitives.settingsTextField)(field.name)),
2550
2783
  disabledToolsField(DISABLED_FIELD),
2551
- booleanField(WRITE_FIELD)
2784
+ booleanField(WRITE_FIELD),
2785
+ enumField(TRANSLATE_PROVIDER_FIELD, TRANSLATE_PROVIDERS, "bing"),
2786
+ enumField(TRANSLATE_TARGET_FIELD, TRANSLATE_TARGETS, "auto")
2552
2787
  ]);
2553
2788
  this.store = this.form.bind(() => this.projection());
2554
2789
  }
@@ -2562,7 +2797,9 @@ var ZoteroCardController = class {
2562
2797
  fulltextMaxBytes: this.form.field("fulltextMaxBytes"),
2563
2798
  defaultLimit: this.form.field("defaultLimit"),
2564
2799
  disabledMcpTools: this.form.field(DISABLED_FIELD),
2565
- writeEnabled: this.form.field(WRITE_FIELD)
2800
+ writeEnabled: this.form.field(WRITE_FIELD),
2801
+ translateProvider: this.form.field(TRANSLATE_PROVIDER_FIELD),
2802
+ translateTarget: this.form.field(TRANSLATE_TARGET_FIELD)
2566
2803
  };
2567
2804
  }
2568
2805
  /** 席位注册的注入面:hook + 表单动作。 */
@@ -2712,6 +2949,28 @@ const TOOL_DESC_STYLE = {
2712
2949
  display: "block",
2713
2950
  marginTop: 2
2714
2951
  };
2952
+ /** 翻译组里的字段名,与写开关那一行同一视觉层级。 */
2953
+ const TRANSLATE_LABEL_STYLE = {
2954
+ fontSize: 13,
2955
+ fontWeight: 600,
2956
+ display: "block"
2957
+ };
2958
+ /** 目标语言下拉:原生 select,主题色靠 CSS 变量跟随明暗。 */
2959
+ const SELECT_STYLE = {
2960
+ flexShrink: 0,
2961
+ height: 26,
2962
+ padding: "0 4px",
2963
+ fontSize: 12,
2964
+ borderRadius: 6,
2965
+ border: "1px solid rgba(127,127,127,0.35)",
2966
+ background: "Canvas",
2967
+ color: "CanvasText"
2968
+ };
2969
+ /** 引擎选项比语言名长,限宽免得把左侧的说明文字挤没。 */
2970
+ const PROVIDER_SELECT_STYLE = {
2971
+ ...SELECT_STYLE,
2972
+ maxWidth: "52%"
2973
+ };
2715
2974
  /**
2716
2975
  * 写权限操作卡:整块描边 + 浅底,把「必须点按钮」这件事从一片灰字里拎出来。
2717
2976
  * 颜色走主题变量,light/dark 都成立。
@@ -2785,7 +3044,9 @@ function ZoteroSettingsSection(props) {
2785
3044
  state.fulltextMaxBytes.text,
2786
3045
  state.defaultLimit.text,
2787
3046
  state.disabledMcpTools.text,
2788
- state.writeEnabled.text
3047
+ state.writeEnabled.text,
3048
+ state.translateProvider.text,
3049
+ state.translateTarget.text
2789
3050
  ].join("\0");
2790
3051
  /**
2791
3052
  * 自动保存:改完停手 {@link AUTOSAVE_DELAY_MS} 落盘。
@@ -3064,6 +3325,61 @@ function ZoteroSettingsSection(props) {
3064
3325
  })]
3065
3326
  }), renderWriteBody()]
3066
3327
  });
3328
+ /**
3329
+ * 「划词翻译」:引擎与目标语言都用原生下拉。
3330
+ *
3331
+ * 引擎早先是两枚分段按钮,光看「Bing 免费 / DeepSeek 精翻」不知道在选什么,
3332
+ * 改成下拉后选项能带一句人话说明;这里选的是**默认**引擎,译文浮层里还能临时换。
3333
+ * 两项都不走 `SettingsValueField`(那是文本框),但值仍是字符串,因此字段规格用
3334
+ * {@link enumField} —— 表单模型只负责「值合法 + 脏了要存」,控件长什么样由这里定。
3335
+ */
3336
+ const renderTranslate = () => {
3337
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3338
+ style: TOOL_ROW_STYLE,
3339
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3340
+ style: TOOL_INFO_STYLE,
3341
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3342
+ style: TRANSLATE_LABEL_STYLE,
3343
+ children: t("field.translateProvider")
3344
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3345
+ style: TOOL_DESC_STYLE,
3346
+ children: t("field.translateProviderHint")
3347
+ })]
3348
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
3349
+ value: state.translateProvider.text === "deepseek" ? "deepseek" : "bing",
3350
+ disabled: locked,
3351
+ onChange: (event) => props.edit(TRANSLATE_PROVIDER_FIELD, event.target.value),
3352
+ style: PROVIDER_SELECT_STYLE,
3353
+ "aria-label": t("field.translateProvider"),
3354
+ children: TRANSLATE_PROVIDERS.map((value) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
3355
+ value,
3356
+ children: t(`translate.provider.${value}`)
3357
+ }, value))
3358
+ })]
3359
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3360
+ style: TOOL_ROW_STYLE,
3361
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3362
+ style: TOOL_INFO_STYLE,
3363
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3364
+ style: TRANSLATE_LABEL_STYLE,
3365
+ children: t("field.translateTarget")
3366
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3367
+ style: TOOL_DESC_STYLE,
3368
+ children: t("field.translateTargetHint")
3369
+ })]
3370
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
3371
+ value: state.translateTarget.text === "" ? "auto" : state.translateTarget.text,
3372
+ disabled: locked,
3373
+ onChange: (event) => props.edit(TRANSLATE_TARGET_FIELD, event.target.value),
3374
+ style: SELECT_STYLE,
3375
+ "aria-label": t("field.translateTarget"),
3376
+ children: TRANSLATE_TARGETS.map((tag) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
3377
+ value: tag,
3378
+ children: t(`translate.target.${tag}`)
3379
+ }, tag))
3380
+ })]
3381
+ })] });
3382
+ };
3067
3383
  const renderStatus = () => {
3068
3384
  if (state.failed) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
3069
3385
  style: SAVE_FAILED_STYLE,
@@ -3125,6 +3441,13 @@ function ZoteroSettingsSection(props) {
3125
3441
  }), renderTools()]
3126
3442
  })
3127
3443
  ]
3444
+ }),
3445
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
3446
+ style: GROUP_STYLE,
3447
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
3448
+ style: GROUP_HEAD_STYLE,
3449
+ children: t("group.translate")
3450
+ }), renderTranslate()]
3128
3451
  })
3129
3452
  ]
3130
3453
  });
@@ -4181,12 +4504,8 @@ const PATH = {
4181
4504
  note: "M4.5 3h7v10h-7z M4.5 5.6h7 M6.6 7.9h3.3 M6.6 9.9h3.3",
4182
4505
  attachment: "M9.6 3.5 4.9 8.2a1.9 1.9 0 0 0 2.7 2.7l4.7-4.7a3 3 0 0 0-4.2-4.2L3.4 6.7a4.2 4.2 0 0 0 5.9 5.9l1.2-1.2"
4183
4506
  };
4184
- /** 已读图标的粉色:不用主题蓝,蓝色容易被读成「未读消息」徽标。 */
4185
- const READ_ICON_COLOR = "#e8798d";
4186
- /** 未读图标用 Zotero 蓝:列表行里比中性灰更醒目,也与树、按钮同一支蓝。 */
4187
- const ICON_COLOR = "#4a86e8";
4188
4507
  /**
4189
- * 条目类型图标;未知类型显示文档图标,已读条目整体转粉色。
4508
+ * 条目类型图标;未知类型显示文档图标,已读条目去饱和并淡化。
4190
4509
  * 无底衬,默认 22px(比 Zotero 原生 16px 放大,列表里才看得清)。
4191
4510
  */
4192
4511
  function ItemTypeIcon({ itemType, read = false, size = 22 }) {
@@ -4197,13 +4516,10 @@ function ItemTypeIcon({ itemType, read = false, size = 22 }) {
4197
4516
  viewBox: "0 0 16 16",
4198
4517
  fill: "none",
4199
4518
  stroke: "currentColor",
4200
- strokeWidth: 1.35,
4519
+ strokeWidth: 1.2,
4201
4520
  strokeLinejoin: "round",
4202
4521
  strokeLinecap: "round",
4203
- style: {
4204
- opacity: read ? .95 : .9,
4205
- color: read ? READ_ICON_COLOR : ICON_COLOR
4206
- },
4522
+ className: itemTypeIconClass(family, read),
4207
4523
  "aria-hidden": true,
4208
4524
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: PATH[family] })
4209
4525
  });
@@ -28754,7 +29070,7 @@ function AnnotationCard({ t, annotation, style, cardRef, canEdit, onClose, onIns
28754
29070
  role: "dialog",
28755
29071
  "aria-label": typeLabel(t, annotation.type),
28756
29072
  style: {
28757
- ...cardStyle,
29073
+ ...cardStyle$1,
28758
29074
  ...style
28759
29075
  },
28760
29076
  children: [
@@ -28904,7 +29220,7 @@ function AnnotationCard({ t, annotation, style, cardRef, canEdit, onClose, onIns
28904
29220
  ]
28905
29221
  });
28906
29222
  }
28907
- const cardStyle = {
29223
+ const cardStyle$1 = {
28908
29224
  position: "absolute",
28909
29225
  width: 260,
28910
29226
  maxHeight: "55%",
@@ -29712,6 +30028,40 @@ function paceChunk(priority, next) {
29712
30028
  });
29713
30029
  }
29714
30030
  //#endregion
30031
+ //#region src/client/clipboard.ts
30032
+ /**
30033
+ * 剪贴板写入(宿主 webview 专用兜底)。
30034
+ *
30035
+ * `navigator.clipboard` 在 DSH 的 webview 里可能因焦点/权限被拒(实测会 reject),
30036
+ * 所以失败后退回一个临时 textarea + `execCommand('copy')`。
30037
+ */
30038
+ async function writeClipboard(text) {
30039
+ try {
30040
+ await navigator.clipboard.writeText(text);
30041
+ return true;
30042
+ } catch {
30043
+ return legacyCopy(text);
30044
+ }
30045
+ }
30046
+ function legacyCopy(text) {
30047
+ const area = document.createElement("textarea");
30048
+ area.value = text;
30049
+ area.setAttribute("readonly", "");
30050
+ area.style.position = "fixed";
30051
+ area.style.top = "-1000px";
30052
+ area.style.opacity = "0";
30053
+ document.body.appendChild(area);
30054
+ area.select();
30055
+ let ok = false;
30056
+ try {
30057
+ ok = document.execCommand("copy");
30058
+ } catch {
30059
+ ok = false;
30060
+ }
30061
+ area.remove();
30062
+ return ok;
30063
+ }
30064
+ //#endregion
29715
30065
  //#region src/client/viewer/SelectionBar.tsx
29716
30066
  /**
29717
30067
  * 全文选区浮动菜单:标注 / 复制 / 加入对话。
@@ -29723,7 +30073,7 @@ function paceChunk(priority, next) {
29723
30073
  * 就是写入,类型 chip 只决定「点色块建的是高亮还是划线」,评论输入框默认收起 ——
29724
30074
  * 浮条飘在正文上,能少一个常驻控件就少一个。
29725
30075
  */
29726
- function SelectionBar({ t, text, x, y, onInsert, onDismiss, annotate }) {
30076
+ function SelectionBar({ t, text, x, y, onInsert, onDismiss, annotate, translate }) {
29727
30077
  const [type, setType] = (0, react.useState)("highlight");
29728
30078
  const [comment, setComment] = (0, react.useState)("");
29729
30079
  const [commentOpen, setCommentOpen] = (0, react.useState)(false);
@@ -29813,23 +30163,37 @@ function SelectionBar({ t, text, x, y, onInsert, onDismiss, annotate }) {
29813
30163
  }),
29814
30164
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
29815
30165
  style: groupStyle,
29816
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
29817
- type: "button",
29818
- className: SOFT_BUTTON_CLASS,
29819
- onClick: copy,
29820
- style: buttonStyle,
29821
- children: t("action.copy")
29822
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
29823
- type: "button",
29824
- className: SOFT_BUTTON_CLASS,
29825
- onMouseDown: (event) => event.preventDefault(),
29826
- onClick: () => {
29827
- onInsert(text);
29828
- finish();
29829
- },
29830
- style: buttonStyle,
29831
- children: t("action.insertItemShort")
29832
- })]
30166
+ children: [
30167
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30168
+ type: "button",
30169
+ className: SOFT_BUTTON_CLASS,
30170
+ onClick: copy,
30171
+ style: buttonStyle$1,
30172
+ children: t("action.copy")
30173
+ }),
30174
+ translate !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30175
+ type: "button",
30176
+ className: "dsh-zp-soft-btn",
30177
+ onMouseDown: (event) => event.preventDefault(),
30178
+ onClick: () => {
30179
+ translate.onTranslate(text, x, y);
30180
+ finish();
30181
+ },
30182
+ style: buttonStyle$1,
30183
+ children: t("action.translate")
30184
+ }),
30185
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30186
+ type: "button",
30187
+ className: SOFT_BUTTON_CLASS,
30188
+ onMouseDown: (event) => event.preventDefault(),
30189
+ onClick: () => {
30190
+ onInsert(text);
30191
+ finish();
30192
+ },
30193
+ style: buttonStyle$1,
30194
+ children: t("action.insertItemShort")
30195
+ })
30196
+ ]
29833
30197
  })
29834
30198
  ]
29835
30199
  });
@@ -29860,7 +30224,7 @@ const groupStyle = {
29860
30224
  lineHeight: 1.4,
29861
30225
  whiteSpace: "nowrap"
29862
30226
  };
29863
- const buttonStyle = {
30227
+ const buttonStyle$1 = {
29864
30228
  ...SOFT_BUTTON_STYLE,
29865
30229
  padding: "3px 8px",
29866
30230
  borderRadius: 5,
@@ -29900,35 +30264,608 @@ const commentInputStyle = {
29900
30264
  color: "CanvasText",
29901
30265
  boxShadow: "0 4px 14px rgba(0,0,0,0.18)"
29902
30266
  };
30267
+ //#endregion
30268
+ //#region src/client/viewer/TranslationCard.tsx
29903
30269
  /**
29904
- * 宿主 webview 里 navigator.clipboard 可能因焦点/权限被拒(DSH 实测会 reject),
29905
- * 再用一个临时 textarea + execCommand 兜底。
30270
+ * 划词翻译结果浮层。
30271
+ *
30272
+ * 形态上照 `AnnotationCard`(绝对定位、`Canvas` 底色、z-index 9),多出来的只有一条
30273
+ * 可拖动的标题栏:译文往往比选区宽,压住正文时能拖开才谈得上「边看边译」。
30274
+ *
30275
+ * 正文是**左右双栏**:左原文、右译文,各自独立滚动,中间一条明显可见的竖分割线。
30276
+ * 早先的「上摘要 + 下译文」用一条几乎看不见的细线分隔,长段落对照时很难分界。
30277
+ *
30278
+ * 关闭有三个入口:标题栏右侧的 ×、Esc、点击框外 —— 后两个都由 `useDismiss` 统一处理,
30279
+ * 不要另外挂 pointerdown(拖动发生在框内,天然不算「点外」)。
29906
30280
  */
29907
- async function writeClipboard(text) {
29908
- try {
29909
- await navigator.clipboard.writeText(text);
29910
- return true;
29911
- } catch {
29912
- return legacyCopy(text);
30281
+ /** 与边框留的缝隙,贴边时不至于压住滚动条。 */
30282
+ const EDGE = 6;
30283
+ /** 默认尺寸:左右双栏各要放得下几行字,宽度比首版单栏时放宽一截。 */
30284
+ const DEFAULT_WIDTH = 600;
30285
+ const DEFAULT_HEIGHT = 420;
30286
+ /** 拖到多小就不许再小:两栏各留够一行字的宽度,按钮也别换行。 */
30287
+ const MIN_WIDTH = 320;
30288
+ const MIN_HEIGHT = 180;
30289
+ /** 浮层根节点的标记:渲染器判定「这次选区是不是落在浮层里」用。 */
30290
+ const MARK = "data-zp-translate";
30291
+ /**
30292
+ * 选区是否落在译文浮层里。
30293
+ *
30294
+ * 文本渲染器的 `onMouseUp` 挂在整个滚动容器上,浮层也在里面 —— 用户在译文里拖选
30295
+ * 复制时不该被当成本文选区再弹一次工具条。
30296
+ */
30297
+ function isInsideTranslation(node) {
30298
+ if (node === null) return false;
30299
+ const element = node instanceof Element ? node : node.parentElement;
30300
+ if (element === null) return false;
30301
+ return element.closest(`[${MARK}]`) !== null;
30302
+ }
30303
+ function TranslationCard({ t, view, bounds, engine, onEngineChange, onClose, onRetry, onInsert }) {
30304
+ const cardRef = (0, react.useRef)(null);
30305
+ const dragRef = (0, react.useRef)(null);
30306
+ const resizeRef = (0, react.useRef)(null);
30307
+ const [size, setSize] = (0, react.useState)(() => defaultSize(bounds));
30308
+ const [pos, setPos] = (0, react.useState)(() => anchor(view, bounds, size));
30309
+ /** 新选区进来时按当前尺寸重新摆位,但别把用户拖出来的尺寸重置回默认。 */
30310
+ const sizeRef = (0, react.useRef)(size);
30311
+ sizeRef.current = size;
30312
+ (0, react.useEffect)(() => {
30313
+ setPos(anchor(view, bounds, sizeRef.current));
30314
+ }, [
30315
+ view.text,
30316
+ view.x,
30317
+ view.y
30318
+ ]);
30319
+ useDismiss(true, cardRef, onClose);
30320
+ const [active, setActive] = (0, react.useState)(false);
30321
+ function onHandleDown(event) {
30322
+ if (event.button !== 0) return;
30323
+ event.preventDefault();
30324
+ setActive(true);
30325
+ event.currentTarget.setPointerCapture(event.pointerId);
30326
+ dragRef.current = {
30327
+ px: event.clientX,
30328
+ py: event.clientY,
30329
+ left: pos.left,
30330
+ top: pos.top
30331
+ };
30332
+ }
30333
+ function onHandleMove(event) {
30334
+ const drag = dragRef.current;
30335
+ if (drag === null) return;
30336
+ setPos({
30337
+ left: clamp(drag.left + event.clientX - drag.px, EDGE, bounds.width - size.width - EDGE),
30338
+ top: clamp(drag.top + event.clientY - drag.py, EDGE, bounds.height - size.height - EDGE)
30339
+ });
30340
+ }
30341
+ function onHandleUp(event) {
30342
+ if (dragRef.current === null) return;
30343
+ dragRef.current = null;
30344
+ setActive(false);
30345
+ event.currentTarget.releasePointerCapture(event.pointerId);
30346
+ }
30347
+ function onResizeDown(event) {
30348
+ if (event.button !== 0) return;
30349
+ event.preventDefault();
30350
+ event.currentTarget.setPointerCapture(event.pointerId);
30351
+ resizeRef.current = {
30352
+ px: event.clientX,
30353
+ py: event.clientY,
30354
+ width: size.width,
30355
+ height: size.height
30356
+ };
30357
+ }
30358
+ function onResizeMove(event) {
30359
+ const drag = resizeRef.current;
30360
+ if (drag === null) return;
30361
+ setSize(clampSize(drag.width + event.clientX - drag.px, drag.height + event.clientY - drag.py, bounds, pos));
30362
+ }
30363
+ function onResizeUp(event) {
30364
+ if (resizeRef.current === null) return;
30365
+ resizeRef.current = null;
30366
+ event.currentTarget.releasePointerCapture(event.pointerId);
29913
30367
  }
30368
+ function copy() {
30369
+ const text = view.result?.text;
30370
+ if (text === void 0) return;
30371
+ writeClipboard(text).then((ok) => {
30372
+ showToast(t(ok ? "translate.copied" : "toast.copyFailed"));
30373
+ });
30374
+ }
30375
+ function insert() {
30376
+ const text = view.result?.text;
30377
+ if (text === void 0) return;
30378
+ onInsert(view.text, text);
30379
+ onClose();
30380
+ }
30381
+ const engineLabel = view.result === void 0 ? void 0 : t(`translate.engine.${view.result.provider}`);
30382
+ const target = view.result?.target;
30383
+ const targetLabel = target === void 0 ? void 0 : targetName(t, target);
30384
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30385
+ ref: cardRef,
30386
+ [MARK]: "",
30387
+ style: {
30388
+ ...cardStyle,
30389
+ width: size.width,
30390
+ height: size.height,
30391
+ left: pos.left,
30392
+ top: pos.top
30393
+ },
30394
+ role: "dialog",
30395
+ "aria-label": t("translate.title"),
30396
+ children: [
30397
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30398
+ onPointerDown: onHandleDown,
30399
+ onPointerMove: onHandleMove,
30400
+ onPointerUp: onHandleUp,
30401
+ onPointerCancel: onHandleUp,
30402
+ style: {
30403
+ ...handleStyle,
30404
+ cursor: active ? "grabbing" : "move"
30405
+ },
30406
+ title: t("translate.dragHint"),
30407
+ children: [
30408
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
30409
+ style: titleStyle$2,
30410
+ children: [t("translate.title"), engineLabel === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
30411
+ style: engineStyle,
30412
+ title: t("translate.engine.actualHint"),
30413
+ children: engineLabel
30414
+ })]
30415
+ }),
30416
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
30417
+ value: engine,
30418
+ onPointerDown: (event) => event.stopPropagation(),
30419
+ onChange: (event) => {
30420
+ const value = event.target.value;
30421
+ if (value === "default" || value === "bing" || value === "deepseek") onEngineChange(value);
30422
+ },
30423
+ style: engineSelectStyle,
30424
+ "aria-label": t("translate.engine.label"),
30425
+ title: t("translate.engine.hint"),
30426
+ children: [
30427
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
30428
+ value: "default",
30429
+ children: t("translate.engine.default")
30430
+ }),
30431
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
30432
+ value: "bing",
30433
+ children: t("translate.provider.bing")
30434
+ }),
30435
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
30436
+ value: "deepseek",
30437
+ children: t("translate.provider.deepseek")
30438
+ })
30439
+ ]
30440
+ }),
30441
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30442
+ type: "button",
30443
+ onPointerDown: (event) => event.stopPropagation(),
30444
+ onClick: onClose,
30445
+ style: closeStyle,
30446
+ "aria-label": t("action.close"),
30447
+ title: t("action.close"),
30448
+ children: "×"
30449
+ })
30450
+ ]
30451
+ }),
30452
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30453
+ style: columnsStyle,
30454
+ children: [
30455
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30456
+ style: paneStyle,
30457
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30458
+ style: paneHeaderStyle,
30459
+ children: t("translate.original")
30460
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30461
+ style: paneTextStyle,
30462
+ children: view.text
30463
+ })]
30464
+ }),
30465
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30466
+ style: dividerStyle,
30467
+ role: "separator",
30468
+ "aria-orientation": "vertical"
30469
+ }),
30470
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30471
+ style: paneStyle,
30472
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30473
+ style: paneHeaderStyle,
30474
+ children: [t("translate.translation"), targetLabel === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
30475
+ style: paneBadgeStyle,
30476
+ children: targetLabel
30477
+ })]
30478
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30479
+ style: bodyStyle$1,
30480
+ children: [
30481
+ view.status === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30482
+ style: statusStyle,
30483
+ children: t("translate.loading")
30484
+ }),
30485
+ view.status === "error" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30486
+ style: errorStyle,
30487
+ children: view.error ?? t("translate.failed")
30488
+ }),
30489
+ view.status === "done" && view.result !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30490
+ style: paneTextStyle,
30491
+ children: view.result.text
30492
+ })
30493
+ ]
30494
+ })]
30495
+ })
30496
+ ]
30497
+ }),
30498
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
30499
+ style: footerStyle,
30500
+ children: [
30501
+ view.status === "error" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30502
+ type: "button",
30503
+ className: "dsh-zp-soft-btn",
30504
+ onClick: onRetry,
30505
+ style: buttonStyle,
30506
+ children: t("translate.retry")
30507
+ }),
30508
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30509
+ type: "button",
30510
+ className: SOFT_BUTTON_CLASS,
30511
+ onClick: copy,
30512
+ disabled: view.status !== "done",
30513
+ style: buttonStyle,
30514
+ children: t("translate.copy")
30515
+ }),
30516
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30517
+ type: "button",
30518
+ className: SOFT_BUTTON_CLASS,
30519
+ onClick: insert,
30520
+ disabled: view.status !== "done",
30521
+ style: buttonStyle,
30522
+ children: t("action.insertItemShort")
30523
+ })
30524
+ ]
30525
+ }),
30526
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
30527
+ onPointerDown: onResizeDown,
30528
+ onPointerMove: onResizeMove,
30529
+ onPointerUp: onResizeUp,
30530
+ onPointerCancel: onResizeUp,
30531
+ style: resizeHandleStyle,
30532
+ title: t("translate.resizeHint"),
30533
+ "aria-label": t("translate.resizeHint"),
30534
+ role: "separator"
30535
+ })
30536
+ ]
30537
+ });
29914
30538
  }
29915
- function legacyCopy(text) {
29916
- const area = document.createElement("textarea");
29917
- area.value = text;
29918
- area.setAttribute("readonly", "");
29919
- area.style.position = "fixed";
29920
- area.style.top = "-1000px";
29921
- area.style.opacity = "0";
29922
- document.body.appendChild(area);
29923
- area.select();
29924
- let ok = false;
29925
- try {
29926
- ok = document.execCommand("copy");
29927
- } catch {
29928
- ok = false;
30539
+ /**
30540
+ * 初始落点:优先贴在选区下方 14px,其次上方,两边都放不下就贴底(别跑出视口)。
30541
+ *
30542
+ * 高矮用**当前实际尺寸**判断,不再用估值 —— 卡片可能已经被拉大,估值会让它一半
30543
+ * 露在视口外。
30544
+ */
30545
+ function anchor(view, bounds, size) {
30546
+ const below = view.y + 14;
30547
+ const above = view.y - size.height - 14;
30548
+ const maxTop = bounds.height - size.height - EDGE;
30549
+ let top;
30550
+ if (below + size.height <= bounds.height - EDGE) top = below;
30551
+ else if (above >= EDGE) top = above;
30552
+ else top = Math.min(Math.max(below, EDGE), Math.max(EDGE, maxTop));
30553
+ return {
30554
+ left: clamp(view.x - size.width / 2, EDGE, bounds.width - size.width - EDGE),
30555
+ top: clamp(top, EDGE, maxTop)
30556
+ };
30557
+ }
30558
+ /** 默认尺寸:比单栏版更宽,够两栏各铺开一段长摘录 / 整段译文。 */
30559
+ function defaultSize(bounds) {
30560
+ return {
30561
+ width: Math.max(MIN_WIDTH, Math.min(DEFAULT_WIDTH, bounds.width - 12)),
30562
+ height: Math.max(MIN_HEIGHT, Math.min(DEFAULT_HEIGHT, bounds.height - 12))
30563
+ };
30564
+ }
30565
+ /** 缩放时同时受下限与「别越出容器」约束(右下角只往外拉,左上角不动)。 */
30566
+ function clampSize(width, height, bounds, pos) {
30567
+ const maxWidth = Math.max(MIN_WIDTH, bounds.width - pos.left - EDGE);
30568
+ const maxHeight = Math.max(MIN_HEIGHT, bounds.height - pos.top - EDGE);
30569
+ return {
30570
+ width: Math.min(Math.max(width, MIN_WIDTH), maxWidth),
30571
+ height: Math.min(Math.max(height, MIN_HEIGHT), maxHeight)
30572
+ };
30573
+ }
30574
+ function clamp(value, min, max) {
30575
+ if (max < min) return min;
30576
+ return Math.min(Math.max(value, min), max);
30577
+ }
30578
+ /** 设置页下拉里出现过的具体语言;手改配置写进来的野值直接显示原始 tag。 */
30579
+ const KNOWN_TARGETS = /* @__PURE__ */ new Set([
30580
+ "zh-CN",
30581
+ "zh-TW",
30582
+ "en",
30583
+ "ja",
30584
+ "ko",
30585
+ "fr",
30586
+ "de",
30587
+ "ru"
30588
+ ]);
30589
+ function targetName(t, target) {
30590
+ return KNOWN_TARGETS.has(target) ? t(`translate.target.${target}`) : target;
30591
+ }
30592
+ const cardStyle = {
30593
+ position: "absolute",
30594
+ display: "flex",
30595
+ flexDirection: "column",
30596
+ overflow: "hidden",
30597
+ padding: "6px 8px 8px",
30598
+ borderRadius: 8,
30599
+ background: "Canvas",
30600
+ color: "CanvasText",
30601
+ border: "1px solid rgba(127,127,127,0.32)",
30602
+ boxShadow: "0 8px 24px rgba(0,0,0,0.28)",
30603
+ zIndex: 9,
30604
+ fontSize: 12,
30605
+ lineHeight: 1.6,
30606
+ textAlign: "left"
30607
+ };
30608
+ const handleStyle = {
30609
+ display: "flex",
30610
+ alignItems: "center",
30611
+ gap: 6,
30612
+ padding: "1px 2px 5px",
30613
+ marginBottom: 5,
30614
+ borderBottom: "1px solid rgba(127,127,127,0.22)",
30615
+ userSelect: "none",
30616
+ touchAction: "none"
30617
+ };
30618
+ const titleStyle$2 = {
30619
+ display: "flex",
30620
+ alignItems: "center",
30621
+ gap: 6,
30622
+ flex: 1,
30623
+ minWidth: 0,
30624
+ fontWeight: 600,
30625
+ color: "light-dark(#2c3e63, #d5dced)"
30626
+ };
30627
+ const engineStyle = {
30628
+ padding: "0 5px",
30629
+ borderRadius: 4,
30630
+ border: "1px solid rgba(127,127,127,0.35)",
30631
+ fontSize: 11,
30632
+ fontWeight: 400,
30633
+ color: "var(--dsw-alias-label-secondary, GrayText)",
30634
+ whiteSpace: "nowrap"
30635
+ };
30636
+ /** 标题栏里的引擎下拉:原生 select,配色随宿主明暗主题。 */
30637
+ const engineSelectStyle = {
30638
+ flex: "none",
30639
+ height: 20,
30640
+ maxWidth: 170,
30641
+ padding: "0 2px",
30642
+ border: "1px solid rgba(127,127,127,0.35)",
30643
+ borderRadius: 5,
30644
+ fontSize: 11,
30645
+ background: "Canvas",
30646
+ color: "CanvasText",
30647
+ cursor: "pointer"
30648
+ };
30649
+ const closeStyle = {
30650
+ flex: "none",
30651
+ width: 18,
30652
+ height: 18,
30653
+ padding: 0,
30654
+ border: "none",
30655
+ borderRadius: 4,
30656
+ background: "transparent",
30657
+ color: "inherit",
30658
+ fontSize: 14,
30659
+ lineHeight: 1,
30660
+ cursor: "pointer"
30661
+ };
30662
+ /** 双栏容器:吃掉标题栏与底部按钮之外的全部高度。 */
30663
+ const columnsStyle = {
30664
+ display: "flex",
30665
+ flexDirection: "row",
30666
+ alignItems: "stretch",
30667
+ flex: 1,
30668
+ minHeight: 0
30669
+ };
30670
+ /** 单栏:等分宽度,内容超高时只在自己这一栏里滚。 */
30671
+ const paneStyle = {
30672
+ display: "flex",
30673
+ flexDirection: "column",
30674
+ flex: "1 1 0",
30675
+ minWidth: 0,
30676
+ minHeight: 0
30677
+ };
30678
+ const paneHeaderStyle = {
30679
+ display: "flex",
30680
+ alignItems: "center",
30681
+ gap: 6,
30682
+ flex: "none",
30683
+ paddingBottom: 4,
30684
+ fontSize: 11,
30685
+ fontWeight: 600,
30686
+ letterSpacing: "0.04em",
30687
+ color: "var(--dsw-alias-label-secondary, GrayText)",
30688
+ userSelect: "none"
30689
+ };
30690
+ /** 右栏标题后的目标语言徽标:自动判向时显示实际译入的语言。 */
30691
+ const paneBadgeStyle = {
30692
+ padding: "0 4px",
30693
+ borderRadius: 4,
30694
+ border: "1px solid rgba(127,127,127,0.35)",
30695
+ fontSize: 10,
30696
+ fontWeight: 400,
30697
+ letterSpacing: 0,
30698
+ whiteSpace: "nowrap"
30699
+ };
30700
+ /**
30701
+ * 中间竖分割线:2px 实色 + 两侧留白。
30702
+ * 别退回 1px 半透明灰 —— 在浅色底上几乎看不见,这正是要修的问题。
30703
+ */
30704
+ const dividerStyle = {
30705
+ flex: "none",
30706
+ width: 2,
30707
+ alignSelf: "stretch",
30708
+ margin: "0 12px",
30709
+ borderRadius: 1,
30710
+ background: "light-dark(#8593a8, #78859a)"
30711
+ };
30712
+ /** 右栏正文区:吃掉栏目标题之外的全部高度。 */
30713
+ const bodyStyle$1 = {
30714
+ flex: 1,
30715
+ minHeight: 0,
30716
+ display: "flex",
30717
+ flexDirection: "column",
30718
+ overflow: "hidden"
30719
+ };
30720
+ /** 原文 / 译文共用:从栏顶开始铺,长文本在本栏内滚动。 */
30721
+ const paneTextStyle = {
30722
+ flex: 1,
30723
+ minHeight: 0,
30724
+ overflow: "auto",
30725
+ whiteSpace: "pre-wrap",
30726
+ wordBreak: "break-word"
30727
+ };
30728
+ const statusStyle = {
30729
+ margin: "auto 0",
30730
+ padding: "6px 0",
30731
+ color: "var(--dsw-alias-label-secondary, GrayText)"
30732
+ };
30733
+ const errorStyle = {
30734
+ margin: "auto 0",
30735
+ padding: "6px 0",
30736
+ color: "light-dark(#b3261e, #f2b8b5)"
30737
+ };
30738
+ const footerStyle = {
30739
+ display: "flex",
30740
+ justifyContent: "flex-end",
30741
+ gap: 4,
30742
+ marginTop: 6,
30743
+ paddingRight: 10
30744
+ };
30745
+ /** 右下角缩放把手:两条斜线示意「可以拉」,命中区比图形略大。 */
30746
+ const resizeHandleStyle = {
30747
+ position: "absolute",
30748
+ right: 0,
30749
+ bottom: 0,
30750
+ width: 16,
30751
+ height: 16,
30752
+ cursor: "nwse-resize",
30753
+ touchAction: "none",
30754
+ borderBottomRightRadius: 8,
30755
+ backgroundImage: "linear-gradient(135deg, transparent 0 46%, rgba(127,127,127,0.55) 46% 52%, transparent 52% 64%, rgba(127,127,127,0.55) 64% 70%, transparent 70%)"
30756
+ };
30757
+ const buttonStyle = {
30758
+ ...SOFT_BUTTON_STYLE,
30759
+ padding: "2px 8px",
30760
+ borderRadius: 5,
30761
+ font: "inherit",
30762
+ cursor: "pointer",
30763
+ whiteSpace: "nowrap"
30764
+ };
30765
+ //#endregion
30766
+ //#region src/client/viewer/useTranslation.ts
30767
+ /**
30768
+ * 划词翻译的状态机:一次选区 → 一个浮层。
30769
+ *
30770
+ * 发请求、保住「最近一次选区」用于重试、在关闭/换选区时撤掉在途请求;另外管一个
30771
+ * **会话级引擎覆盖**:设置页那份是长期默认值,浮层里换引擎只影响本次会话,
30772
+ * 刷新页面即回到默认值,避免同一个「默认引擎」有两处互相打架的配置源。
30773
+ * 定位与拖动交给 {@link TranslationCard},这里只存初始锚点。
30774
+ */
30775
+ /**
30776
+ * 会话级引擎覆盖(模块级变量,不写盘)。
30777
+ *
30778
+ * 三种文档渲染器各自有一个 `useTranslation` 实例,切换附件时旧实例卸载、新实例挂载;
30779
+ * 放在模块作用域才能让「刚换的引擎」跨渲染器沿用,同时页面一刷新就清空。
30780
+ */
30781
+ let engineOverride;
30782
+ function useTranslation(t) {
30783
+ const [view, setView] = (0, react.useState)(null);
30784
+ const [engine, setEngineState] = (0, react.useState)(() => engineOverride ?? "default");
30785
+ const abortRef = (0, react.useRef)(null);
30786
+ const cancel = (0, react.useCallback)(() => {
30787
+ abortRef.current?.abort();
30788
+ abortRef.current = null;
30789
+ }, []);
30790
+ (0, react.useEffect)(() => () => cancel(), [cancel]);
30791
+ const request = (0, react.useCallback)((text, x, y, choice) => {
30792
+ cancel();
30793
+ const controller = new AbortController();
30794
+ abortRef.current = controller;
30795
+ setView({
30796
+ text,
30797
+ status: "loading",
30798
+ x,
30799
+ y
30800
+ });
30801
+ translateSelection(text, {
30802
+ provider: choice === "default" ? void 0 : choice,
30803
+ signal: controller.signal
30804
+ }).then((result) => {
30805
+ if (controller.signal.aborted) return;
30806
+ setView((current) => current !== null && current.text === text ? {
30807
+ ...current,
30808
+ status: "done",
30809
+ result
30810
+ } : current);
30811
+ }).catch((error) => {
30812
+ if (controller.signal.aborted) return;
30813
+ setView((current) => current !== null && current.text === text ? {
30814
+ ...current,
30815
+ status: "error",
30816
+ error: messageOf(t, error)
30817
+ } : current);
30818
+ }).finally(() => {
30819
+ if (abortRef.current === controller) abortRef.current = null;
30820
+ });
30821
+ }, [cancel, t]);
30822
+ const open = (0, react.useCallback)((text, x, y) => {
30823
+ request(text, x, y, engine);
30824
+ }, [request, engine]);
30825
+ const retry = (0, react.useCallback)(() => {
30826
+ const current = view;
30827
+ if (current === null) return;
30828
+ request(current.text, current.x, current.y, engine);
30829
+ }, [
30830
+ request,
30831
+ view,
30832
+ engine
30833
+ ]);
30834
+ return {
30835
+ view,
30836
+ engine,
30837
+ setEngine: (0, react.useCallback)((next) => {
30838
+ engineOverride = next === "default" ? void 0 : next;
30839
+ setEngineState(next);
30840
+ const current = view;
30841
+ if (current !== null) request(current.text, current.x, current.y, next);
30842
+ }, [request, view]),
30843
+ open,
30844
+ retry,
30845
+ close: (0, react.useCallback)(() => {
30846
+ cancel();
30847
+ setView(null);
30848
+ }, [cancel])
30849
+ };
30850
+ }
30851
+ /**
30852
+ * 错误归一化。
30853
+ *
30854
+ * 参数类错误(选区过长、空文本)Host 给的中文文案最准确,直接用;其余(网络、
30855
+ * 服务端)统一一句「翻译失败」+ 重试按钮,不把 HTTP 细节糊到用户脸上。
30856
+ *
30857
+ * 唯一例外是「未知 action translate」:这是**宿主半还停在旧版本**(插件升级后没重启
30858
+ * DSH)才会出现的 404,原样抛给用户只会得到一句看不懂的路由错误。
30859
+ */
30860
+ function messageOf(t, error) {
30861
+ if (error instanceof ApiFailure) {
30862
+ if (error.code === "bad_request") {
30863
+ if (error.message.includes("未知 action")) return t("translate.needRestart");
30864
+ return error.message;
30865
+ }
30866
+ return t("translate.failed");
29929
30867
  }
29930
- area.remove();
29931
- return ok;
30868
+ return t("translate.failed");
29932
30869
  }
29933
30870
  //#endregion
29934
30871
  //#region src/client/viewer/useReadPosition.ts
@@ -30481,7 +31418,7 @@ function observePages(elements, root, rootMargin, onChange) {
30481
31418
  return observer;
30482
31419
  }
30483
31420
  function PdfViewer(props) {
30484
- const { t, detail, source, annotations, viewerRef, onReady, onZoomChange, onPageChange, onInsertExcerpt, onInsertAnnotation, onOpenInZotero, onChanged, onOutlineChange } = props;
31421
+ const { t, detail, source, annotations, viewerRef, onReady, onZoomChange, onPageChange, onInsertExcerpt, onInsertTranslation, onInsertAnnotation, onOpenInZotero, onChanged, onOutlineChange } = props;
30485
31422
  const rootRef = (0, react.useRef)(null);
30486
31423
  const scrollRef = (0, react.useRef)(null);
30487
31424
  const cardRef = (0, react.useRef)(null);
@@ -30506,6 +31443,8 @@ function PdfViewer(props) {
30506
31443
  */
30507
31444
  const rangeRef = (0, react.useRef)(null);
30508
31445
  const [marking, setMarking] = (0, react.useState)(false);
31446
+ /** 划词翻译浮层:选区变了就重开,正文滚动不影响它(相对 root 定位)。 */
31447
+ const translation = useTranslation(t);
30509
31448
  /**
30510
31449
  * 目录回调走 ref:加载 effect 只该随 url / 重试重跑,不该因为父级重渲染换了
30511
31450
  * 回调身份就重新解析一遍书签(每次解析都要等一个 `getOutline`)。
@@ -31174,7 +32113,21 @@ function PdfViewer(props) {
31174
32113
  annotate: detail.writeEnabled && source !== null && !loading ? {
31175
32114
  busy: marking,
31176
32115
  onCreate: (type, color, comment) => void createMark(type, color, comment)
31177
- } : void 0
32116
+ } : void 0,
32117
+ translate: { onTranslate: translation.open }
32118
+ }),
32119
+ translation.view !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TranslationCard, {
32120
+ t,
32121
+ view: translation.view,
32122
+ bounds: {
32123
+ width: rootWidth,
32124
+ height: rootHeight
32125
+ },
32126
+ engine: translation.engine,
32127
+ onEngineChange: translation.setEngine,
32128
+ onClose: translation.close,
32129
+ onRetry: translation.retry,
32130
+ onInsert: onInsertTranslation
31178
32131
  }),
31179
32132
  card !== null && cardAnnotation !== null && annotationCard(cardAnnotation, card.y)
31180
32133
  ]
@@ -31325,7 +32278,7 @@ function openExternal(href) {
31325
32278
  if (url.protocol !== "http:" && url.protocol !== "https:") return;
31326
32279
  window.open(url.href, "_blank", "noopener,noreferrer");
31327
32280
  }
31328
- function SnapshotViewer({ t, detail, source, annotations, viewerRef, onReady, onInsertExcerpt, onInsertAnnotation, onOpenInZotero, onChanged, onOutlineChange }) {
32281
+ function SnapshotViewer({ t, detail, source, annotations, viewerRef, onReady, onInsertExcerpt, onInsertTranslation, onInsertAnnotation, onOpenInZotero, onChanged, onOutlineChange }) {
31329
32282
  const rootRef = (0, react.useRef)(null);
31330
32283
  const frameRef = (0, react.useRef)(null);
31331
32284
  const cardRef = (0, react.useRef)(null);
@@ -31343,6 +32296,8 @@ function SnapshotViewer({ t, detail, source, annotations, viewerRef, onReady, on
31343
32296
  const [missed, setMissed] = (0, react.useState)(0);
31344
32297
  const [selection, setSelection] = (0, react.useState)(null);
31345
32298
  const [marking, setMarking] = (0, react.useState)(false);
32299
+ /** 划词翻译浮层:在父容器坐标系里,iframe 内滚动不影响它。 */
32300
+ const translation = useTranslation(t);
31346
32301
  /**
31347
32302
  * 打开着的编辑卡片:只记标注 key 与点击位置,内容每次从 `annotations` 里现取。
31348
32303
  *
@@ -31603,7 +32558,21 @@ function SnapshotViewer({ t, detail, source, annotations, viewerRef, onReady, on
31603
32558
  annotate: detail.writeEnabled && source !== null ? {
31604
32559
  busy: marking,
31605
32560
  onCreate: (type, color, comment) => void createMark(type, color, comment)
31606
- } : void 0
32561
+ } : void 0,
32562
+ translate: { onTranslate: translation.open }
32563
+ }),
32564
+ translation.view !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TranslationCard, {
32565
+ t,
32566
+ view: translation.view,
32567
+ bounds: {
32568
+ width: rootWidth,
32569
+ height: rootHeight
32570
+ },
32571
+ engine: translation.engine,
32572
+ onEngineChange: translation.setEngine,
32573
+ onClose: translation.close,
32574
+ onRetry: translation.retry,
32575
+ onInsert: onInsertTranslation
31607
32576
  }),
31608
32577
  card !== null && cardAnnotation !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AnnotationCard, {
31609
32578
  t,
@@ -31755,13 +32724,15 @@ const AnnotatedText = (0, react.memo)(function AnnotatedText({ segments }) {
31755
32724
  }, index);
31756
32725
  }) });
31757
32726
  });
31758
- function TextViewer({ t, detail, annotations, viewerRef, onReady, onInsertExcerpt, onOutlineChange }) {
32727
+ function TextViewer({ t, detail, annotations, viewerRef, onReady, onInsertExcerpt, onInsertTranslation, onOutlineChange }) {
31759
32728
  const boxRef = (0, react.useRef)(null);
31760
32729
  /** 纯文本正文的内层:字符偏移只在这层里数,排除上下两条提示文字。 */
31761
32730
  const contentRef = (0, react.useRef)(null);
31762
32731
  const flashTimer = (0, react.useRef)(null);
31763
32732
  const outlineTimer = (0, react.useRef)(null);
31764
32733
  const [selection, setSelection] = (0, react.useState)(null);
32734
+ /** 划词翻译浮层。这里是滚动容器本身,浮层坐标按内容算,随正文一起滚。 */
32735
+ const translation = useTranslation(t);
31765
32736
  const selfNote = detail.itemType === "note" ? detail.notes.find((note) => note.key === detail.key) ?? null : null;
31766
32737
  const fulltext = detail.fulltext;
31767
32738
  const marked = (0, react.useMemo)(() => selfNote === null ? annotations.filter((annotation) => TEXT_TYPES.has(annotation.type)) : [], [annotations, selfNote]);
@@ -31857,7 +32828,7 @@ function TextViewer({ t, detail, annotations, viewerRef, onReady, onInsertExcerp
31857
32828
  }
31858
32829
  const text = sel.toString().trim();
31859
32830
  const range = sel.getRangeAt(0);
31860
- if (text === "" || !box.contains(range.commonAncestorContainer)) {
32831
+ if (text === "" || !box.contains(range.commonAncestorContainer) || isInsideTranslation(range.commonAncestorContainer)) {
31861
32832
  setSelection(null);
31862
32833
  return;
31863
32834
  }
@@ -31911,7 +32882,21 @@ function TextViewer({ t, detail, annotations, viewerRef, onReady, onInsertExcerp
31911
32882
  x: selection.x,
31912
32883
  y: selection.y,
31913
32884
  onInsert: onInsertExcerpt,
31914
- onDismiss: () => setSelection(null)
32885
+ onDismiss: () => setSelection(null),
32886
+ translate: { onTranslate: translation.open }
32887
+ }),
32888
+ translation.view !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TranslationCard, {
32889
+ t,
32890
+ view: translation.view,
32891
+ bounds: {
32892
+ width: boxRef.current?.clientWidth ?? 320,
32893
+ height: Math.max(boxRef.current?.clientHeight ?? 400, boxRef.current?.scrollHeight ?? 400)
32894
+ },
32895
+ engine: translation.engine,
32896
+ onEngineChange: translation.setEngine,
32897
+ onClose: translation.close,
32898
+ onRetry: translation.retry,
32899
+ onInsert: onInsertTranslation
31915
32900
  })
31916
32901
  ]
31917
32902
  });
@@ -32257,7 +33242,7 @@ function RefreshIcon({ spinning }) {
32257
33242
  })
32258
33243
  });
32259
33244
  }
32260
- function DocumentView({ t, detail, source, annotations, viewerRef, onReady, onInsertExcerpt, onInsertAnnotation, onOpenInZotero, onChanged, refreshing, onRefresh, onOutlineChange }) {
33245
+ function DocumentView({ t, detail, source, annotations, viewerRef, onReady, onInsertExcerpt, onInsertTranslation, onInsertAnnotation, onOpenInZotero, onChanged, refreshing, onRefresh, onOutlineChange }) {
32261
33246
  const renderer = pickRenderer(source, detail);
32262
33247
  const Renderer = renderer.Component;
32263
33248
  const [page, setPage] = (0, react.useState)({
@@ -32360,6 +33345,7 @@ function DocumentView({ t, detail, source, annotations, viewerRef, onReady, onIn
32360
33345
  onZoomChange: handleZoomChange,
32361
33346
  onPageChange: handlePageChange,
32362
33347
  onInsertExcerpt,
33348
+ onInsertTranslation,
32363
33349
  onInsertAnnotation,
32364
33350
  onOpenInZotero,
32365
33351
  onChanged,
@@ -32537,7 +33523,7 @@ function attachmentSource(attachment) {
32537
33523
  source.url = isHtml(source) ? snapshotUrl(attachment.key) : fileUrl(attachment.key);
32538
33524
  return source;
32539
33525
  }
32540
- function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotation, onInsertNote, onChanged, onRefresh }) {
33526
+ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertTranslation, onInsertAnnotation, onInsertNote, onChanged, onRefresh }) {
32541
33527
  const [infoOpen, setInfoOpen] = (0, react.useState)(false);
32542
33528
  const [outlineOpen, setOutlineOpen] = (0, react.useState)(false);
32543
33529
  const [outline, setOutline] = (0, react.useState)({
@@ -32682,6 +33668,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
32682
33668
  viewerRef,
32683
33669
  onReady,
32684
33670
  onInsertExcerpt,
33671
+ onInsertTranslation,
32685
33672
  onInsertAnnotation,
32686
33673
  onOpenInZotero: openInZoteroAt,
32687
33674
  onChanged,
@@ -32832,6 +33819,17 @@ function useInsertion(t, sessions, sessionId, inputActions) {
32832
33819
  }
32833
33820
  insertReference(excerptReference(target.key, target.title, quote, excerptChipLabel(t, quote)));
32834
33821
  }, [insertReference, t]),
33822
+ insertTranslation: (0, react.useCallback)((target, quote, translated) => {
33823
+ if (quote.trim() === "" || translated.trim() === "") {
33824
+ showToast(t("error.empty"));
33825
+ return;
33826
+ }
33827
+ if (Array.from(quote).length + Array.from(translated).length > 4e3) {
33828
+ showToast(tpl(t("error.excerptTooLong"), { n: MAX_EXCERPT_CHARS }));
33829
+ return;
33830
+ }
33831
+ insertReference(translationReference(target.key, target.title, quote, translated, translationChipLabel(t, translated)));
33832
+ }, [insertReference, t]),
32835
33833
  insertAnnotation: (0, react.useCallback)((target, annotation) => {
32836
33834
  insertReference(annotationReference(target.key, annotation.key, annotationChipLabel(t, annotation)));
32837
33835
  }, [insertReference, t]),
@@ -32968,7 +33966,7 @@ function ZoteroItemPane(props) {
32968
33966
  signal,
32969
33967
  t
32970
33968
  ]);
32971
- const { insertItem, insertExcerpt, insertAnnotation, insertNote } = useInsertion(t, sessions, sessionId, inputActions);
33969
+ const { insertItem, insertExcerpt, insertTranslation, insertAnnotation, insertNote } = useInsertion(t, sessions, sessionId, inputActions);
32972
33970
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
32973
33971
  style: {
32974
33972
  position: "relative",
@@ -33006,6 +34004,7 @@ function ZoteroItemPane(props) {
33006
34004
  detail,
33007
34005
  onInsertItem: () => insertItem(detail.key, detail.title),
33008
34006
  onInsertExcerpt: (quote) => insertExcerpt(detail, quote),
34007
+ onInsertTranslation: (quote, translated) => insertTranslation(detail, quote, translated),
33009
34008
  onInsertAnnotation: (annotation) => insertAnnotation(detail, annotation),
33010
34009
  onInsertNote: (note) => insertNote(detail, note),
33011
34010
  onChanged: () => void refresh(),
@@ -33534,15 +34533,29 @@ const titleRowStyle = {
33534
34533
  gap: 8,
33535
34534
  minWidth: 0
33536
34535
  };
33537
- /** 行 hover 只染未选中行:选中态用内联背景,优先级更高,不需要额外规则。 */
33538
- const ITEM_CSS = ".dsh-zotero-item-row:hover{background:rgba(127,127,127,0.08)}";
33539
- /** 行外壳:只负责那条浅色分隔线,通栏铺满。
34536
+ /**
34537
+ * 底色(hover / 选中)统一挂在外壳上,而不是内层行。
34538
+ *
34539
+ * Menu 的 anchor 外面会被包一层按内容收窄的元素,内层行即使 `width:100%` 也只能
34540
+ * 铺到「内容最宽的子元素」(标题)为止,于是就出现「只有标题那一截是蓝的」。
34541
+ * 外壳是普通块级容器,宽度必然是通栏的,把背景放这里最稳。
34542
+ */
34543
+ const ITEM_CSS = [".dsh-zotero-item-shell:hover{background:rgba(127,127,127,0.08)}", ".dsh-zotero-item-shell > *{width:100%;min-width:0}"].join("");
34544
+ /** 选中行底色:整行(外壳)通栏染色,色值与列表 chip 同一支蓝。 */
34545
+ const ITEM_SELECTED_BG = "rgba(80,140,255,0.16)";
34546
+ /**
34547
+ * 行外壳:承载整行底色 + 那条浅色分隔线,通栏铺满。
33540
34548
  *
33541
- * 用 flex 是为了「撑满」:Menu 的 anchor 外面会包一层按内容收窄的元素,
33542
- * 做成 flex 容器后那层被拉伸到整行宽,里面的标题才有确定的宽度可截断。
34549
+ * 单列 grid 给内层一个明确的行宽(配合 `ITEM_CSS` 里对 Menu 包装层的宽度覆盖),
34550
+ * 内层行的 `width:100%` 才有确定宽度可用;`minmax(0,1fr)` 允许轨道缩到比内容更窄,
34551
+ * 长标题才能出省略号而不是溢出被裁。
33543
34552
  */
33544
34553
  const itemShellStyle = {
33545
- display: "flex",
34554
+ display: "grid",
34555
+ gridTemplateColumns: "minmax(0, 1fr)",
34556
+ width: "100%",
34557
+ boxSizing: "border-box",
34558
+ borderRadius: 6,
33546
34559
  borderBottom: "1px solid rgba(127,127,127,0.14)"
33547
34560
  };
33548
34561
  const itemRowStyle = {
@@ -33552,7 +34565,6 @@ const itemRowStyle = {
33552
34565
  width: "100%",
33553
34566
  boxSizing: "border-box",
33554
34567
  padding: "7px 8px",
33555
- borderRadius: 6,
33556
34568
  cursor: "pointer"
33557
34569
  };
33558
34570
  /** 标题独占第一行,可截断。 */
@@ -33682,7 +34694,11 @@ function ItemRow({ t, item, selected, onSelect, onOpen, onInsert }) {
33682
34694
  const read = isRead(item);
33683
34695
  const typeLabel = itemTypeLabel(t, item.itemType);
33684
34696
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
33685
- style: itemShellStyle,
34697
+ className: "dsh-zotero-item-shell",
34698
+ style: selected ? {
34699
+ ...itemShellStyle,
34700
+ background: ITEM_SELECTED_BG
34701
+ } : itemShellStyle,
33686
34702
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
33687
34703
  open: menuOpen,
33688
34704
  onClose: () => setMenuOpen(false),
@@ -33705,10 +34721,7 @@ function ItemRow({ t, item, selected, onSelect, onOpen, onInsert }) {
33705
34721
  event.preventDefault();
33706
34722
  setMenuOpen(true);
33707
34723
  },
33708
- style: selected ? {
33709
- ...itemRowStyle,
33710
- background: "rgba(80,140,255,0.16)"
33711
- } : itemRowStyle,
34724
+ style: itemRowStyle,
33712
34725
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
33713
34726
  style: itemIconStyle,
33714
34727
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemTypeIcon, {