diff --git a/plugins/baidu-translate/.gitignore b/plugins/baidu-translate/.gitignore new file mode 100644 index 000000000..dc88178fc --- /dev/null +++ b/plugins/baidu-translate/.gitignore @@ -0,0 +1,6 @@ +node_modules/ +src-ztools/dist/ +*.log +.env* +.DS_Store +Thumbs.db diff --git a/plugins/baidu-translate/CHANGELOG.md b/plugins/baidu-translate/CHANGELOG.md new file mode 100644 index 000000000..dc1de859d --- /dev/null +++ b/plugins/baidu-translate/CHANGELOG.md @@ -0,0 +1,27 @@ +# 更新日志 + +## 1.1.2 - 2026-11-05 + +- 修复发布包内端点常量引用错误导致的"网络请求失败" +- 网络请求优先走 Electron net 模块(跟随系统代理),node https 兜底 +- 网络错误提示附带真实原因(DNS / 连接 / HTTP 状态),便于排查 + +## 1.1.1 - 2026-11-05 + +- 网络请求增加 User-Agent,避免被目标服务误拦截 + +## 1.1.0 - 2026-11-05 + +- 布局改为上下结构:顶部语言栏,下方左右分栏(左输入 / 右结果) +- 输入自动翻译(600ms 防抖,中文输入法组合期不触发) +- 单词查询词典卡片:多词性含义、音标、词形变化(复数 / 过去式等)、考试标签、英英释义与例句 +- 变形词(claims 等)自动查原形词典择优合并 +- 智能方向:中文 → 英文,英文 / 日语 / 韩语等 → 中文 +- 最近 50 条翻译历史,点击回看重翻 +- 译文逐段 / 整体复制 + +## 1.0.0 - 2026-11-05 + +- 初次发布:基于百度翻译开放平台通用翻译 API 的 ZTools 翻译插件 +- 密钥本地 AES-256-GCM 加密存储,secretKey 不出 preload,不上传任何第三方服务器 +- 源语言自动检测,28 种语言互译,语言方向互换 diff --git a/plugins/baidu-translate/README.md b/plugins/baidu-translate/README.md new file mode 100644 index 000000000..d2fa4902d --- /dev/null +++ b/plugins/baidu-translate/README.md @@ -0,0 +1,59 @@ +# 百度翻译(ZTools 插件) + +基于百度翻译开放平台通用翻译 API 的 ZTools 翻译插件。只接百度翻译,无其他厂商。 + +## 功能 + +- 输入自动翻译(600ms 防抖),Enter 立即翻译,Shift+Enter 换行 +- 智能方向:输入中文 → 译成英文;输入英文/日语/韩语等 → 译成中文(也可手动指定语言) +- 左右分栏:左侧原文,右侧结果 +- 单词查询显示词典卡片:多词性含义、音标、词形变化(复数/过去式等)、考试标签、英英释义与例句;变形词自动查原形补全 +- 译文逐段/整体复制,最近 50 条历史可回看 +- 在 ZTools 主输入框输入文字回车进插件,自动带入并翻译 + +## 密钥配置与安全 + +1. 到[百度翻译开放平台](https://fanyi-api.baidu.com/)注册并开通通用翻译(标准版免费,单次 q ≤ 6000 字节); +2. 在插件「⚙ 设置」中填入 **APPID** 与 **密钥(Secret Key)**,保存。 + +安全设计(密钥不离开本机): + +- 密钥经 **AES-256-GCM** 加密后存入宿主 dbStorage; +- 加密用主密钥是首次保存时随机生成的 32 字节值,落盘在宿主 `userData/baidu-translate.key`,与密文分离存放; +- **secretKey 只进不出**:preload 对渲染层只暴露 `{ appId, hasSecret }`,签名(MD5)与 HTTPS 请求全部在 preload(Node 侧)完成; +- 插件不向百度翻译 API 之外的任何地址发送数据。 + +「清除密钥」会同时删除密文与主密钥文件。 + +词典卡片需在开放平台控制台免费开通「词典资源」后才会返回数据,未开通时仅显示译文。 + +## 开发 + +```bash +npm install +npm run dev # 浏览器调试(无 preload,自动走 mock:假翻译 + localStorage 存密钥) +npm run build # 产物输出到 src-ztools/dist +``` + +目录: + +``` +src/ 渲染层(Vue 3 + TS) + App.vue 翻译主视图 + components/SettingsPanel.vue 密钥设置 + api.ts 宿主/preload 封装 + 浏览器 mock + baidu.ts 语言表、错误码映射 +src-ztools/ + plugin.json 插件清单(feature: baidu-translate,关键词:百度翻译/翻译/fy…) + preload/services.js 密钥加密存取 + 百度 API 请求(Node 侧) + logo.png +scripts/make-logo.cjs logo 生成脚本(零依赖 PNG 绘制) +``` + +## 常见错误码 + +报错卡片会给出中文提示,对应百度 `error_code`:52003 APPID 无效、54001 签名错误(核对密钥)、54003/54005 频率受限、54004 余额不足、58001 语言方向不支持、58003 超过 6000 字节。 + +## 作者 + +yhx diff --git a/plugins/baidu-translate/index.html b/plugins/baidu-translate/index.html new file mode 100644 index 000000000..2eb084498 --- /dev/null +++ b/plugins/baidu-translate/index.html @@ -0,0 +1,12 @@ + + + + + + 百度翻译 + + +
+ + + diff --git a/plugins/baidu-translate/package-lock.json b/plugins/baidu-translate/package-lock.json new file mode 100644 index 000000000..1509fff34 --- /dev/null +++ b/plugins/baidu-translate/package-lock.json @@ -0,0 +1,1521 @@ +{ + "name": "y-translate", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "y-translate", + "version": "1.0.0", + "dependencies": { + "vue": "^3.5.13" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^5.2.1", + "@ztools-center/ztools-api-types": "^1.0.1", + "typescript": "^5.3.0", + "vite": "^6.0.11", + "vue-tsc": "^2.0.0" + } + }, + "node_modules/@babel/helper-string-parser": { + "version": "7.29.13", + "resolved": "https://registry.npmmirror.com/@babel/helper-string-parser/-/helper-string-parser-7.29.13.tgz", + "integrity": "sha512-fWegr+WsEsiMVW4KUNdIIzzMTZSzNiqhy0//6+2MRi2d5NFNsL/AYwBQW8eBnRbTBVRnDVzjaJEUqKaCWjMMdQ==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.29.7", + "resolved": "https://registry.npmmirror.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/parser": { + "version": "7.29.13", + "resolved": "https://registry.npmmirror.com/@babel/parser/-/parser-7.29.13.tgz", + "integrity": "sha512-fJM50YYjlTiBhgdkGmC1tBpv+FMAyo4annf2X6Aks+0yRlaiVkYW/3f07xAfVVkYIoZ9fFZp+mEThUFnuybhkQ==", + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.11" + }, + "bin": { + "parser": "bin/babel-parser.js" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@babel/types": { + "version": "7.29.11", + "resolved": "https://registry.npmmirror.com/@babel/types/-/types-7.29.11.tgz", + "integrity": "sha512-WCsemW40Cpc6gouC1SrY6PBaZ+oLRlEVY9XBvZBI7il/HyUrb2nJ505wE1MHEFyDZNnrWDEuy4jL50WVHfTTSQ==", + "license": "MIT", + "dependencies": { + "@babel/helper-string-parser": "^7.29.11", + "@babel/helper-validator-identifier": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz", + "integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/android-arm/-/android-arm-0.25.12.tgz", + "integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz", + "integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/android-x64/-/android-x64-0.25.12.tgz", + "integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz", + "integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz", + "integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz", + "integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz", + "integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz", + "integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz", + "integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz", + "integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz", + "integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz", + "integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz", + "integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz", + "integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz", + "integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz", + "integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz", + "integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz", + "integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz", + "integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz", + "integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz", + "integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz", + "integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz", + "integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz", + "integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz", + "integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmmirror.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "license": "MIT" + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.67.5.tgz", + "integrity": "sha512-FdWPeulkH+FH+rBzyKBD59tuVN4tRKvmVilSJm0OcnoYsQTpd9UhD78OaPcsYqo2fX6hCwAG0YIjrDLoQ3pR3g==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.67.5.tgz", + "integrity": "sha512-bmkDuBGnF+Ji8atWlXcNjxIC52ShCbdXPbW7Nz0lRoCFi1lrvsO0XobJY36kTj7duc1vOmGJeQ9vtVuGjnzihA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-x64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-android-x64/-/rollup-android-x64-4.67.5.tgz", + "integrity": "sha512-6KvVfnqPTqmbQ5YobMl9HYiSymAsCt8HlNeriDshwJQcveXwT+vIMW6wGL1RcJbXH9+r3BAJvjab5+rIgtSEqA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.67.5.tgz", + "integrity": "sha512-SNamgdrY69oPdBrQV9fKGo6PSmKcVhyn0D0jnDmcqgRJvrxQGGBhtekOHTUJ7TCgkW0nE8XMH9v2CwXmjNIzVA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.67.5.tgz", + "integrity": "sha512-HNdl34thiJtHDSglogjmAlQ296L8cc8zA7ODH65nnmY7E+jPP55WEbh8J5583rWFLMjxyYywxZuwPOwRvEi5tA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.67.5.tgz", + "integrity": "sha512-WvZYtANNswfHzSNHaJAoG6Ipfc4SyZIDYuIjFdHv07xXxhHl+Xx8o+bNDWsxpOADFT2mKXcXVrfOG4OlWTLo8Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.67.5.tgz", + "integrity": "sha512-EUU+Wgf9NyHekceC+DxAdm42f6bq2ezH/7DEb/JnCb8SAUhG2xph5BiVukxplWal2m5pP8CzJZE+FLwRopywjQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.67.5.tgz", + "integrity": "sha512-dgU1CvUuE2IkaJBAeuAbxpDdMHAdZBT5oth5u22DtuoMg4gXXYr2+Sm30RigPJG1F2VEoiGJUziGLuIh9+jPxA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.67.5.tgz", + "integrity": "sha512-rdgJcJig2VngYlcTCRQw2BA8kLWM6QwDFe9uLFo81lya0jPC1r8wZu92sAvTUIv48GWlkRVi6/fpsa5CoFSKoQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.67.5.tgz", + "integrity": "sha512-+jtCiQnrEFHWAUAcUpP7wppb1p6HKOgBP3mXx75cEYpDF2Y5MEqBky2HNz+osFuVx5uX44gnMTmbe5RJauzn6A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.67.5.tgz", + "integrity": "sha512-heflX7ENhL8eHmLcUxDEHCSK8CKLyPprysb2JGoSTh5Ip7nHrzIRc+2USyxul3nxi98H8pGxJIEDEpURlS1X5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.67.5.tgz", + "integrity": "sha512-rRtNU0zBfRHkJ8pscHN9qRtUYLq8Rao4EX7aVWvKcFmJUANkCCXFRU7ovNBEMhpEONyUEB/3DRVDXwDDguSfHA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.67.5.tgz", + "integrity": "sha512-/6auyi9yj8MD/Q+8P+f2ay57jQ7a0j7Yp1JK86pecH6ZnRViQZ5GOjoRSjGArFeTSHFznRbM2QPQcBgDPyNMfQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.67.5.tgz", + "integrity": "sha512-Hsc0vlt+vPvqzUkHKffWKf3YE/yexrY+yeFf7IsUvDC6PV7YGCsA/gJvPa+WJdgxGJnwuoO1HmLkbahaLKabYQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.67.5.tgz", + "integrity": "sha512-Jx5TMMSPJwHY7F/JwPdS6nuBwny2ECRK+EsAJV5HZrfiddeSS6ZrohkLkFZm3rjqBUuQ4FPX5gGMtakUuQO6fQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.67.5.tgz", + "integrity": "sha512-fGWcq2lo/XCqAkBLOokg66D/z+MUouryB8i+QdU9RR6O5knG7rucc0WFPqWYL1Wk/wuiJouDfmyBxmZKRM9bag==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.67.5.tgz", + "integrity": "sha512-JwO/Ys3jybc0UW3V5XO2CMnp0RhvoczDDQTgAEE1IctT+HRY3W5parIIWLUpmAK4gHSeeYJofm2iQPFA62K6ag==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.67.5.tgz", + "integrity": "sha512-vVD4iqel6J6A1xAJlb4mxEO9i1wOJ4/SkcKoDKAuK/wqEBPOA7/P5dDyZvNx46ocHwOUwzo3WjhTdKqET9kEAg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.67.5.tgz", + "integrity": "sha512-HmEfNh5Cdd/NHxgqwMzKnjlvicQQA+D+w+vQXDJSV0x/aHiQSjVwh1Th5RoA7QsMieIaxibt/5iJq68BraTSUg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.67.5.tgz", + "integrity": "sha512-NfmALpbe009nYzZ2QqlSW6nzbGddXpqk3nwualrIr+4QflQCTGMzt3QKK20yARiAnSV9fJdM5WNwIYUf31x3uA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.67.5.tgz", + "integrity": "sha512-ngcE7Udpy/iJ3lexVhYcbpUV2OJIakRGus3snc6K52BnAAJetDBG1Ku5Eh3CECtnW3mpBYWg5VCD4tTaOXKOVQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.67.5.tgz", + "integrity": "sha512-DZ01A2EdTYX8xVeGoGiWkJBRWDh+/BOflwGPVsBay43PDxcq8ez0xuovZnPnk1xjE3CdI0pdZXxsJp/Xjmf7uQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.67.5.tgz", + "integrity": "sha512-nJKiMKDO140DUCEcQZl+f4HiGPMBxrW2webjuWJ2E3qPeoruHf2zByml4TP52lA1zDi6L4I92D/5stxeA/6pig==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.67.5.tgz", + "integrity": "sha512-ykLkBCf+Kls24QmqM3IRf1T4sGMh0rXPyymtj+hXlWKPJnXbXraHqUUsKtOIxqLasjT1i7DhfQGAaZYeiHbSOw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.67.5.tgz", + "integrity": "sha512-NiFPUFw8cHhkmBlL1k1eaz+5AXXm89rztj+DQdDuQ7VGPM0+ADFhezQ2KcBMF50UEFzGUr0+DVjVND743XwKWQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.67.5.tgz", + "integrity": "sha512-Khj/vrKCpdbiAWYbJAeSy4D5iep+qwW/86lNoKvdleJYGxgbRE7h87+5d5T9D7gt8NcqhNFpreRgIg8T4bLzKQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/@vitejs/plugin-vue": { + "version": "5.2.4", + "resolved": "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-5.2.4.tgz", + "integrity": "sha512-7Yx/SXSOcQq5HiiV3orevHUFn+pmMB4cgbEkDYgnkUWb0WfeQ/wa2yFv6D5ICiCQOVpjA7vYDXrC7AGO8yjDHA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "vite": "^5.0.0 || ^6.0.0", + "vue": "^3.2.25" + } + }, + "node_modules/@volar/language-core": { + "version": "2.4.15", + "resolved": "https://registry.npmmirror.com/@volar/language-core/-/language-core-2.4.15.tgz", + "integrity": "sha512-3VHw+QZU0ZG9IuQmzT68IyN4hZNd9GchGPhbD9+pa8CVv7rnoOZwo7T8weIbrRmihqy3ATpdfXFnqRrfPVK6CA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@volar/source-map": "2.4.15" + } + }, + "node_modules/@volar/source-map": { + "version": "2.4.15", + "resolved": "https://registry.npmmirror.com/@volar/source-map/-/source-map-2.4.15.tgz", + "integrity": "sha512-CPbMWlUN6hVZJYGcU/GSoHu4EnCHiLaXI9n8c9la6RaI9W5JHX+NqG+GSQcB0JdC2FIBLdZJwGsfKyBB71VlTg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@volar/typescript": { + "version": "2.4.15", + "resolved": "https://registry.npmmirror.com/@volar/typescript/-/typescript-2.4.15.tgz", + "integrity": "sha512-2aZ8i0cqPGjXb4BhkMsPYDkkuc2ZQ6yOpqwAuNwUoncELqoy5fRgOQtLR9gB0g902iS0NAkvpIzs27geVyVdPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@volar/language-core": "2.4.15", + "path-browserify": "^1.0.1", + "vscode-uri": "^3.0.8" + } + }, + "node_modules/@vue/compiler-core": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/compiler-core/-/compiler-core-3.5.44.tgz", + "integrity": "sha512-k34nCytbK8PQ1gR2mGROYOw6Pnv/mumqIdrZ3x2tbyXZDWm7ViKGLTfdB+DRrWqEQsLgGJvn0WN9jBif5zCTLQ==", + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.9", + "@vue/shared": "3.5.44", + "entities": "^7.0.1", + "estree-walker": "^2.0.2", + "source-map-js": "^1.2.2" + } + }, + "node_modules/@vue/compiler-dom": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/compiler-dom/-/compiler-dom-3.5.44.tgz", + "integrity": "sha512-W5AoBFWdw1lQAKiHowkfgFKFab82oSRT6sGsPfw/q1GRjsy/ZJFLHGhJyBRIFN9APLTUduDH9U2JAiPOIyKuYg==", + "license": "MIT", + "dependencies": { + "@vue/compiler-core": "3.5.44", + "@vue/shared": "3.5.44" + } + }, + "node_modules/@vue/compiler-sfc": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/compiler-sfc/-/compiler-sfc-3.5.44.tgz", + "integrity": "sha512-dzHmQ4jXTpdr5FjIQUeykVakN/uzqFbUo9/C5ikBFg3a3PeM6uRxeczx1ZbXBML0/zJstEh3ygYipzR5Z7b2Pw==", + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.9", + "@vue/compiler-core": "3.5.44", + "@vue/compiler-dom": "3.5.44", + "@vue/compiler-ssr": "3.5.44", + "@vue/shared": "3.5.44", + "estree-walker": "^2.0.2", + "magic-string": "^0.30.21", + "postcss": "^8.5.29", + "source-map-js": "^1.2.2" + } + }, + "node_modules/@vue/compiler-ssr": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/compiler-ssr/-/compiler-ssr-3.5.44.tgz", + "integrity": "sha512-xr5gb1JVHlfXJwSlRz1FeP6uxoazdzHuMTVLE7up+4Vrqxk219CvxLPxD9NXBt47yvZW7+p4DXfyp4O1fkByIA==", + "license": "MIT", + "dependencies": { + "@vue/compiler-dom": "3.5.44", + "@vue/shared": "3.5.44" + } + }, + "node_modules/@vue/compiler-vue2": { + "version": "2.7.16", + "resolved": "https://registry.npmmirror.com/@vue/compiler-vue2/-/compiler-vue2-2.7.16.tgz", + "integrity": "sha512-qYC3Psj9S/mfu9uVi5WvNZIzq+xnXMhOwbTFKKDD7b1lhpnn71jXSFdTQ+WsIEk0ONCd7VV2IMm7ONl6tbQ86A==", + "dev": true, + "license": "MIT", + "dependencies": { + "de-indent": "^1.0.2", + "he": "^1.2.0" + } + }, + "node_modules/@vue/language-core": { + "version": "2.2.12", + "resolved": "https://registry.npmmirror.com/@vue/language-core/-/language-core-2.2.12.tgz", + "integrity": "sha512-IsGljWbKGU1MZpBPN+BvPAdr55YPkj2nB/TBNGNC32Vy2qLG25DYu/NBN2vNtZqdRbTRjaoYrahLrToim2NanA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@volar/language-core": "2.4.15", + "@vue/compiler-dom": "^3.5.0", + "@vue/compiler-vue2": "^2.7.16", + "@vue/shared": "^3.5.0", + "alien-signals": "^1.0.3", + "minimatch": "^9.0.3", + "muggle-string": "^0.4.1", + "path-browserify": "^1.0.1" + }, + "peerDependencies": { + "typescript": "*" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@vue/reactivity": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.5.44.tgz", + "integrity": "sha512-u+QJdKeBBEADkPdevsL+6E12QlYVfBD8Zcw5qjDQKtamI6l14KyqazJMobhCKelhWN5zpyKUiEDoTyHE93cqWw==", + "license": "MIT", + "dependencies": { + "@vue/shared": "3.5.44" + } + }, + "node_modules/@vue/runtime-core": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/runtime-core/-/runtime-core-3.5.44.tgz", + "integrity": "sha512-uEa/ndwjhrrhnOfb2p+sZy6zeoamJOISqaLSJGk/8R6nABT1ZldpzcJoPzKj+zHVomVBPcmQYyC2r4LtvDV6CQ==", + "license": "MIT", + "dependencies": { + "@vue/reactivity": "3.5.44", + "@vue/shared": "3.5.44" + } + }, + "node_modules/@vue/runtime-dom": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/runtime-dom/-/runtime-dom-3.5.44.tgz", + "integrity": "sha512-3fc4ARcXVhVBaJ3ujWiNZJARD6pkyRcwG+ZYhMzjKtKUp7MAY0HLwr7r3Smep3Li6ZaWT6ewdmx8XqdaD5oNZg==", + "license": "MIT", + "dependencies": { + "@vue/reactivity": "3.5.44", + "@vue/runtime-core": "3.5.44", + "@vue/shared": "3.5.44", + "csstype": "^3.2.3" + } + }, + "node_modules/@vue/server-renderer": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/server-renderer/-/server-renderer-3.5.44.tgz", + "integrity": "sha512-R4S1UoH4h5Frrauv8Z5XE5TxV9oBiUSgWIC4TyVK1FK+RocRnOLwFA5Xcmo2011RlgJp+AbZCnw6afrhlgRuUQ==", + "license": "MIT", + "dependencies": { + "@vue/compiler-ssr": "3.5.44", + "@vue/runtime-dom": "3.5.44", + "@vue/shared": "3.5.44" + } + }, + "node_modules/@vue/shared": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/@vue/shared/-/shared-3.5.44.tgz", + "integrity": "sha512-H82XLH0DjmSOdbEwO15x3QTo1f5PWEtv237eLpYKc0mqLu+B8hnq16lFWmuBmNurkeiG3wr+oM1FhOll/YVFRg==", + "license": "MIT" + }, + "node_modules/@ztools-center/ztools-api-types": { + "version": "1.0.3", + "resolved": "https://registry.npmmirror.com/@ztools-center/ztools-api-types/-/ztools-api-types-1.0.3.tgz", + "integrity": "sha512-dv1eOAIasAupqKaQL/gESk1i2+RebdM/1gvZhrvH2D/bo3enCUsAGJ8nrHnlCLBSOGB81eC/SU0IH8BNsUlmvA==", + "dev": true, + "license": "MIT" + }, + "node_modules/alien-signals": { + "version": "1.0.13", + "resolved": "https://registry.npmmirror.com/alien-signals/-/alien-signals-1.0.13.tgz", + "integrity": "sha512-OGj9yyTnJEttvzhTUWuscOvtqxq5vrhF7vL9oS0xJ2mK0ItPYP1/y+vCFebfxoEyAz0++1AIwJ5CMr+Fk3nDmg==", + "dev": true, + "license": "MIT" + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "license": "MIT" + }, + "node_modules/brace-expansion": { + "version": "2.1.7", + "resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-2.1.7.tgz", + "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/csstype": { + "version": "3.2.3", + "resolved": "https://registry.npmmirror.com/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", + "license": "MIT" + }, + "node_modules/de-indent": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/de-indent/-/de-indent-1.0.2.tgz", + "integrity": "sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==", + "dev": true, + "license": "MIT" + }, + "node_modules/entities": { + "version": "7.0.1", + "resolved": "https://registry.npmmirror.com/entities/-/entities-7.0.1.tgz", + "integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/esbuild": { + "version": "0.25.12", + "resolved": "https://registry.npmmirror.com/esbuild/-/esbuild-0.25.12.tgz", + "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.12", + "@esbuild/android-arm": "0.25.12", + "@esbuild/android-arm64": "0.25.12", + "@esbuild/android-x64": "0.25.12", + "@esbuild/darwin-arm64": "0.25.12", + "@esbuild/darwin-x64": "0.25.12", + "@esbuild/freebsd-arm64": "0.25.12", + "@esbuild/freebsd-x64": "0.25.12", + "@esbuild/linux-arm": "0.25.12", + "@esbuild/linux-arm64": "0.25.12", + "@esbuild/linux-ia32": "0.25.12", + "@esbuild/linux-loong64": "0.25.12", + "@esbuild/linux-mips64el": "0.25.12", + "@esbuild/linux-ppc64": "0.25.12", + "@esbuild/linux-riscv64": "0.25.12", + "@esbuild/linux-s390x": "0.25.12", + "@esbuild/linux-x64": "0.25.12", + "@esbuild/netbsd-arm64": "0.25.12", + "@esbuild/netbsd-x64": "0.25.12", + "@esbuild/openbsd-arm64": "0.25.12", + "@esbuild/openbsd-x64": "0.25.12", + "@esbuild/openharmony-arm64": "0.25.12", + "@esbuild/sunos-x64": "0.25.12", + "@esbuild/win32-arm64": "0.25.12", + "@esbuild/win32-ia32": "0.25.12", + "@esbuild/win32-x64": "0.25.12" + } + }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmmirror.com/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "license": "MIT" + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmmirror.com/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmmirror.com/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true, + "license": "MIT", + "bin": { + "he": "bin/he" + } + }, + "node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/minimatch": { + "version": "9.0.9", + "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-9.0.9.tgz", + "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.2" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/muggle-string": { + "version": "0.4.1", + "resolved": "https://registry.npmmirror.com/muggle-string/-/muggle-string-0.4.1.tgz", + "integrity": "sha512-VNTrAak/KhO2i8dqqnqnAHOa3cYBwXEZe9h+D5h/1ZqFSTEFHdM65lR7RoIqq3tBBYavsOXV84NoHXZ0AkPyqQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmmirror.com/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true, + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.32", + "resolved": "https://registry.npmmirror.com/postcss/-/postcss-8.5.32.tgz", + "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/rollup": { + "version": "4.67.5", + "resolved": "https://registry.npmmirror.com/rollup/-/rollup-4.67.5.tgz", + "integrity": "sha512-3Ve5VH1hacCVutdpbmu/htg4kz+JCOIWgy4Q3hjHPYGHeHeIElNHJ0LcJ3rCfIsd5G7qOl5k5mwpzGMj9kdHPA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.10" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.67.5", + "@rollup/rollup-android-arm64": "4.67.5", + "@rollup/rollup-android-x64": "4.67.5", + "@rollup/rollup-darwin-arm64": "4.67.5", + "@rollup/rollup-darwin-x64": "4.67.5", + "@rollup/rollup-freebsd-arm64": "4.67.5", + "@rollup/rollup-freebsd-x64": "4.67.5", + "@rollup/rollup-linux-arm-gnueabihf": "4.67.5", + "@rollup/rollup-linux-arm-musleabihf": "4.67.5", + "@rollup/rollup-linux-arm64-gnu": "4.67.5", + "@rollup/rollup-linux-arm64-musl": "4.67.5", + "@rollup/rollup-linux-loong64-gnu": "4.67.5", + "@rollup/rollup-linux-loong64-musl": "4.67.5", + "@rollup/rollup-linux-ppc64-gnu": "4.67.5", + "@rollup/rollup-linux-ppc64-musl": "4.67.5", + "@rollup/rollup-linux-riscv64-gnu": "4.67.5", + "@rollup/rollup-linux-riscv64-musl": "4.67.5", + "@rollup/rollup-linux-s390x-gnu": "4.67.5", + "@rollup/rollup-linux-x64-gnu": "4.67.5", + "@rollup/rollup-linux-x64-musl": "4.67.5", + "@rollup/rollup-openbsd-x64": "4.67.5", + "@rollup/rollup-openharmony-arm64": "4.67.5", + "@rollup/rollup-win32-arm64-msvc": "4.67.5", + "@rollup/rollup-win32-ia32-msvc": "4.67.5", + "@rollup/rollup-win32-x64-gnu": "4.67.5", + "@rollup/rollup-win32-x64-msvc": "4.67.5", + "fsevents": "~2.3.2" + } + }, + "node_modules/source-map-js": { + "version": "1.2.2", + "resolved": "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.2.2.tgz", + "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmmirror.com/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmmirror.com/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "devOptional": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/vite": { + "version": "6.4.5", + "resolved": "https://registry.npmmirror.com/vite/-/vite-6.4.5.tgz", + "integrity": "sha512-4enwjFfi4IwtEh0w+jPzpLVOFQiPHmmzPxcHXQOyEur47o6u0jE573DmGpjA+7irXoMLYRZD5ZaFUEneS3abPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.25.0", + "fdir": "^6.4.4", + "picomatch": "^4.0.2", + "postcss": "^8.5.3", + "rollup": "^4.34.9", + "tinyglobby": "^0.2.13" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "jiti": ">=1.21.0", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "sass-embedded": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vscode-uri": { + "version": "3.2.0", + "resolved": "https://registry.npmmirror.com/vscode-uri/-/vscode-uri-3.2.0.tgz", + "integrity": "sha512-m2gXo3bn0G1kT9InzMf07fTbqMbGtyckj3bH5ktLO+1Ssv+yiATZ4dhwaQv9UZWxJh6E9IFGnQyjgWVDWVBDrg==", + "dev": true, + "license": "MIT" + }, + "node_modules/vue": { + "version": "3.5.44", + "resolved": "https://registry.npmmirror.com/vue/-/vue-3.5.44.tgz", + "integrity": "sha512-dvvmaOCG7lAMkJTPqPwWeGMsPS6DIsFsfZDUgBp9V6mHf9b3+/wyVwYR4Es+WV6uJC0FKRxp81Obcq0ZwUcGFQ==", + "license": "MIT", + "dependencies": { + "@vue/compiler-dom": "3.5.44", + "@vue/compiler-sfc": "3.5.44", + "@vue/runtime-dom": "3.5.44", + "@vue/server-renderer": "3.5.44", + "@vue/shared": "3.5.44" + }, + "peerDependencies": { + "typescript": "*" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/vue-tsc": { + "version": "2.2.12", + "resolved": "https://registry.npmmirror.com/vue-tsc/-/vue-tsc-2.2.12.tgz", + "integrity": "sha512-P7OP77b2h/Pmk+lZdJ0YWs+5tJ6J2+uOQPo7tlBnY44QqQSPYvS0qVT4wqDJgwrZaLe47etJLLQRFia71GYITw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@volar/typescript": "2.4.15", + "@vue/language-core": "2.2.12" + }, + "bin": { + "vue-tsc": "bin/vue-tsc.js" + }, + "peerDependencies": { + "typescript": ">=5.0.0" + } + } + } +} diff --git a/plugins/baidu-translate/package.json b/plugins/baidu-translate/package.json new file mode 100644 index 000000000..b997cf019 --- /dev/null +++ b/plugins/baidu-translate/package.json @@ -0,0 +1,20 @@ +{ + "name": "y-translate", + "version": "1.1.2", + "description": "A ZTools plugin - 百度翻译", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vue-tsc && vite build" + }, + "dependencies": { + "vue": "^3.5.13" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^5.2.1", + "@ztools-center/ztools-api-types": "^1.0.1", + "typescript": "^5.3.0", + "vite": "^6.0.11", + "vue-tsc": "^2.0.0" + } +} diff --git a/plugins/baidu-translate/scripts/make-logo.cjs b/plugins/baidu-translate/scripts/make-logo.cjs new file mode 100644 index 000000000..f8a5ff003 --- /dev/null +++ b/plugins/baidu-translate/scripts/make-logo.cjs @@ -0,0 +1,225 @@ +/** + * 生成插件 logo(512x512 PNG,零依赖,node 自带 zlib)。 + * + * 设计:蓝色渐变圆角方块 + 两个对话气泡,左泡「文」右泡「A」, + * 纯几何绘制(SDF + 4x 超采样抗锯齿)。 + * + * 用法:node scripts/make-logo.cjs <输出路径> + * + * @author yhx + */ + +const fs = require('node:fs') +const zlib = require('node:zlib') + +const W = 512 +const SS = 4 // 超采样倍数 + +/* ---------------- 颜色 ---------------- */ + +function lerp(a, b, t) { return a + (b - a) * t } +function mixColor(c1, c2, t) { + return [lerp(c1[0], c2[0], t), lerp(c1[1], c2[1], t), lerp(c1[2], c2[2], t)] +} +const BG_TOP = [43, 50, 232] // #2B32E8 +const BG_BOT = [90, 124, 255] // #5A7CFF +const BLUE = [41, 50, 225] // #2932E1 字形色 +const WHITE = [255, 255, 255] + +/* ---------------- SDF 几何 ---------------- */ + +/** 圆角矩形符号距离(<=0 在内部) */ +function sdRoundRect(px, py, cx, cy, hw, hh, r) { + const qx = Math.abs(px - cx) - (hw - r) + const qy = Math.abs(py - cy) - (hh - r) + const ox = Math.max(qx, 0) + const oy = Math.max(qy, 0) + return Math.hypot(ox, oy) + Math.min(Math.max(qx, qy), 0) - r +} + +/** 点到线段距离(圆头描边用) */ +function sdSegment(px, py, ax, ay, bx, by) { + const abx = bx - ax, aby = by - ay + const apx = px - ax, apy = py - ay + const t = Math.max(0, Math.min(1, (apx * abx + apy * aby) / (abx * abx + aby * aby))) + return Math.hypot(apx - abx * t, apy - aby * t) +} + +function sdCircle(px, py, cx, cy, r) { + return Math.hypot(px - cx, py - cy) - r +} + +/** 三角形符号距离(气泡尾巴用) */ +function sdTriangle(px, py, p0, p1, p2) { + const e = [[p0, p1], [p1, p2], [p2, p0]] + let d = Infinity + let s = 1 + for (const [a, b] of e) { + const ex = b[0] - a[0], ey = b[1] - a[1] + const wx = px - a[0], wy = py - a[1] + const t = Math.max(0, Math.min(1, (wx * ex + wy * ey) / (ex * ex + ey * ey))) + d = Math.min(d, Math.hypot(wx - ex * t, wy - ey * t)) + const c = [px < a[0] ? 0 : px > b[0] ? 0 : wx * ex - 0, 0] // 占位,下面用标准法 + void c + const cross = ex * wy - ey * wx + if (cross < 0) s = -s // 只对凸三角形方向有效,这里按顺时针定义 + } + // 用重心/半平面统一判定内外(更稳) + const sign = (() => { + let inside = true + const pts = [p0, p1, p2] + // 保证逆时针:有向面积 + const area = (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0]) + for (let i = 0; i < 3; i++) { + const a = pts[i], b = pts[(i + 1) % 3] + const cross = (b[0] - a[0]) * (py - a[1]) - (b[1] - a[1]) * (px - a[0]) + if (area > 0 ? cross < 0 : cross > 0) inside = false + } + return inside ? -1 : 1 + })() + void s + return sign * d +} + +/* ---------------- 气泡与字形 ---------------- */ + +/** + * 气泡 = 圆角矩形 + 尾巴。 + * dir: 'down'(尾巴在底部左侧,向下指)| 'up'(尾巴在顶部左侧,向上指) + */ +function bubbleD(px, py, cx, cy, hw, hh, r, dir) { + const rect = sdRoundRect(px, py, cx, cy, hw, hh, r) + let tail + if (dir === 'down') { + const x0 = cx - hw + 34, x1 = x0 + 52, y0 = cy + hh - 2 + tail = sdTriangle(px, py, [x0, y0], [x1, y0], [x0, y0 + 46]) + } else { + const x0 = cx - hw + 26, x1 = x0 + 52, y0 = cy - hh + 2 + tail = sdTriangle(px, py, [x0, y0], [x1, y0], [x0, y0 - 46]) + } + return Math.min(rect, tail) +} + +/** 「文」字形(中心 cx,cy,高度约 110) */ +function wenD(px, py, cx, cy) { + const d = [] + d.push(sdCircle(px, py, cx, cy - 52, 6.5)) // 丶 + d.push(sdSegment(px, py, cx - 34, cy - 26, cx + 34, cy - 26) - 5) // 一 + d.push(sdSegment(px, py, cx - 34, cy - 6, cx + 34, cy + 52) - 5) // 乂 撇 + d.push(sdSegment(px, py, cx + 34, cy - 6, cx - 34, cy + 52) - 5) // 乂 捺 + return Math.min(...d) +} + +/** 「A」字形(中心 cx,cy,高度约 90) */ +function aD(px, py, cx, cy) { + const d = [] + d.push(sdSegment(px, py, cx - 30, cy + 40, cx, cy - 44) - 5) + d.push(sdSegment(px, py, cx, cy - 44, cx + 30, cy + 40) - 5) + d.push(sdSegment(px, py, cx - 18, cy + 12, cx + 18, cy + 12) - 5) + return Math.min(...d) +} + +/* ---------------- 组合场景 ---------------- */ + +/** 返回某采样点的颜色 [r,g,b](不透明度由调用方按 alpha 计算) */ +function sceneShape(px, py) { + // 背景圆角方块 + const bgD = sdRoundRect(px, py, W / 2, W / 2, W / 2 - 8, W / 2 - 8, 104) + if (bgD > 0) return null + const t = Math.max(0, Math.min(1, py / W)) + const bg = mixColor(BG_TOP, BG_BOT, t) + + // 气泡:右下白泡(带 A)压在左上文泡下面 + const dA = bubbleD(px, py, 316, 318, 104, 74, 34, 'up') + const dWen = bubbleD(px, py, 196, 190, 104, 74, 34, 'down') + + // 「文」「A」字形只画在各自泡内 + const inWen = dWen <= 0 + const inA = dA <= 0 && dA < dWen + const dGlyphWen = wenD(px, py, 196, 188) + const dGlyphA = aD(px, py, 318, 320) + + if (inWen && dGlyphWen <= 0) return BLUE + if (inA && dGlyphA <= 0) return BLUE + if (dWen <= 0) return WHITE + if (dA <= 0) return WHITE + return bg +} + +/* ---------------- 渲染(4x 超采样) ---------------- */ + +const rgba = Buffer.alloc(W * W * 4) +const step = 1 / SS +for (let y = 0; y < W; y++) { + for (let x = 0; x < W; x++) { + let r = 0, g = 0, b = 0, a = 0 + for (let sy = 0; sy < SS; sy++) { + for (let sx = 0; sx < SS; sx++) { + const px = x + (sx + 0.5) * step + const py = y + (sy + 0.5) * step + const c = sceneShape(px, py) + if (c) { r += c[0]; g += c[1]; b += c[2]; a += 1 } + } + } + const n = SS * SS + const off = (y * W + x) * 4 + if (a > 0) { + const cov = a / n + rgba[off] = Math.round(r / a) + rgba[off + 1] = Math.round(g / a) + rgba[off + 2] = Math.round(b / a) + rgba[off + 3] = Math.round(cov * 255) + } + } +} + +/* ---------------- PNG 编码 ---------------- */ + +const CRC_TABLE = (() => { + const t = new Int32Array(256) + for (let n = 0; n < 256; n++) { + let c = n + for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1 + t[n] = c + } + return t +})() + +function crc32(buf) { + let c = 0xffffffff + for (const byte of buf) c = CRC_TABLE[(c ^ byte) & 0xff] ^ (c >>> 8) + return (c ^ 0xffffffff) >>> 0 +} + +function chunk(type, data) { + const len = Buffer.alloc(4) + len.writeUInt32BE(data.length) + const body = Buffer.concat([Buffer.from(type, 'ascii'), data]) + const crc = Buffer.alloc(4) + crc.writeUInt32BE(crc32(body)) + return Buffer.concat([len, body, crc]) +} + +function encodePng(rgbaBuf, w, h) { + const ihdr = Buffer.alloc(13) + ihdr.writeUInt32BE(w, 0) + ihdr.writeUInt32BE(h, 4) + ihdr[8] = 8 // 位深 + ihdr[9] = 6 // RGBA + // 原始数据:每行前加 filter 0 + const raw = Buffer.alloc((w * 4 + 1) * h) + for (let y = 0; y < h; y++) { + raw[y * (w * 4 + 1)] = 0 + rgbaBuf.copy(raw, y * (w * 4 + 1) + 1, y * w * 4, (y + 1) * w * 4) + } + return Buffer.concat([ + Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), + chunk('IHDR', ihdr), + chunk('IDAT', zlib.deflateSync(raw, { level: 9 })), + chunk('IEND', Buffer.alloc(0)) + ]) +} + +const out = process.argv[2] || 'logo.png' +fs.writeFileSync(out, encodePng(rgba, W, W)) +console.log('written:', out, fs.statSync(out).size, 'bytes') diff --git a/plugins/baidu-translate/src-ztools/logo.png b/plugins/baidu-translate/src-ztools/logo.png new file mode 100644 index 000000000..3b620e997 Binary files /dev/null and b/plugins/baidu-translate/src-ztools/logo.png differ diff --git a/plugins/baidu-translate/src-ztools/plugin.json b/plugins/baidu-translate/src-ztools/plugin.json new file mode 100644 index 000000000..25a2cd6d7 --- /dev/null +++ b/plugins/baidu-translate/src-ztools/plugin.json @@ -0,0 +1,28 @@ +{ + "$schema": "node_modules/@ztools-center/ztools-api-types/resource/ztools.schema.json", + "name": "baidu-translate", + "title": "百度翻译", + "description": "基于百度翻译开放平台的文本翻译,密钥本地加密保存", + "author": "yhx", + "version": "1.1.2", + "main": "dist/index.html", + "preload": "preload/services.js", + "logo": "logo.png", + "development": { + "main": "http://localhost:5173" + }, + "features": [ + { + "code": "baidu-translate", + "explain": "输入文本,用百度翻译", + "icon": "logo.png", + "cmds": [ + "百度翻译", + "翻译", + "translate", + "fanyi", + "fy" + ] + } + ] +} diff --git a/plugins/baidu-translate/src-ztools/preload/package.json b/plugins/baidu-translate/src-ztools/preload/package.json new file mode 100644 index 000000000..5bbefffba --- /dev/null +++ b/plugins/baidu-translate/src-ztools/preload/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/plugins/baidu-translate/src-ztools/preload/services.js b/plugins/baidu-translate/src-ztools/preload/services.js new file mode 100644 index 000000000..b0cf8dee1 --- /dev/null +++ b/plugins/baidu-translate/src-ztools/preload/services.js @@ -0,0 +1,347 @@ +/** + * 百度翻译 preload —— 插件的安全核心。 + * + * 职责(全部在 Node 侧完成,渲染层拿不到密钥明文): + * 1. 密钥的本地加密存储: + * - 随机 AES-256-GCM 主密钥,落盘在宿主 userData 目录(baidu-translate.key); + * - appid + secretKey 序列化后用该主密钥加密,密文存宿主 dbStorage; + * - 密钥(key 文件)与密文(dbStorage)分离存放,泄露一样不等于全泄露。 + * 2. 百度翻译 API 调用:签名(MD5)、表单编码、HTTPS 请求都在这里做, + * 渲染层只发 translate(text, from, to),永远接触不到 secretKey。 + * 3. 读取凭证时只返回 { appId, hasSecret },secretKey 只进不出。 + * + * 浏览器开发模式(无 preload):由渲染层 src/api.ts 提供同接口的 mock。 + * + * @author yhx + */ + +const crypto = require('node:crypto') +const fs = require('node:fs') +const os = require('node:os') +const path = require('node:path') +const https = require('node:https') + +/** dbStorage 里的密文键名(同时是文档 ID) */ +const STORE_KEY = 'baidu-translate:creds' +/** 百度通用文本翻译 API(词典资源也只有这个接口返回) */ +const ENDPOINT = 'https://fanyi-api.baidu.com/api/trans/vip/translate' +/** 免费版单次请求 q 上限 6000 字节(UTF-8),超限返回 58003 */ +const MAX_QUERY_BYTES = 6000 + +/* ------------------------------------------------------------------ */ +/* 主密钥管理 */ +/* ------------------------------------------------------------------ */ + +/** + * 主密钥文件路径。优先放宿主 userData 目录(跟随宿主安装、不在插件目录里, + * 重装/升级插件不丢);拿不到就退回用户主目录下的 .ztools-plugins。 + */ +function keyFilePath() { + let dir = '' + try { + const zt = window.ztools + if (zt && typeof zt.getPath === 'function') dir = zt.getPath('userData') || '' + } catch (e) { /* 老版本宿主没有 getPath:走兜底 */ } + if (!dir || !fs.existsSync(dir)) dir = path.join(os.homedir(), '.ztools-plugins') + try { fs.mkdirSync(dir, { recursive: true }) } catch (e) { /* 建目录失败后面写文件还会再报 */ } + return path.join(dir, 'baidu-translate.key') +} + +/** 读取(或首次生成)32 字节随机主密钥,返回 hex 字符串 */ +function loadOrCreateKey() { + const file = keyFilePath() + try { + const hex = fs.readFileSync(file, 'utf8').trim() + if (/^[0-9a-f]{64}$/i.test(hex)) return hex + } catch (e) { /* 文件不存在:走生成 */ } + const hex = crypto.randomBytes(32).toString('hex') + try { + fs.writeFileSync(file, hex, { encoding: 'utf8', mode: 0o600 }) + } catch (e) { /* 写不了就先返回内存密钥,本次会话内仍可用 */ } + return hex +} + +function aesKey() { + return Buffer.from(loadOrCreateKey(), 'hex') +} + +/* ------------------------------------------------------------------ */ +/* AES-256-GCM 加解密 */ +/* ------------------------------------------------------------------ */ + +/** + * 加密任意 UTF-8 字符串。 + * 输出格式:base64( iv(12B) | authTag(16B) | ciphertext ) + */ +function seal(plain) { + const iv = crypto.randomBytes(12) + const cipher = crypto.createCipheriv('aes-256-gcm', aesKey(), iv) + const data = Buffer.concat([cipher.update(String(plain), 'utf8'), cipher.final()]) + const tag = cipher.getAuthTag() + return Buffer.concat([iv, tag, data]).toString('base64') +} + +/** + * 解密 seal() 的输出。主密钥换过 / 密文损坏 / 被篡改都会抛错,由调用方兜底。 + */ +function open(sealed) { + const buf = Buffer.from(String(sealed), 'base64') + if (buf.length < 12 + 16 + 1) throw new Error('ciphertext too short') + const iv = buf.subarray(0, 12) + const tag = buf.subarray(12, 28) + const data = buf.subarray(28) + const decipher = crypto.createDecipheriv('aes-256-gcm', aesKey(), iv) + decipher.setAuthTag(tag) + return Buffer.concat([decipher.update(data), decipher.final()]).toString('utf8') +} + +/* ------------------------------------------------------------------ */ +/* 凭证存取(密文走宿主 dbStorage,开发兜底走 localStorage) */ +/* ------------------------------------------------------------------ */ + +function storage() { + const zt = window.ztools + if (zt && zt.dbStorage && typeof zt.dbStorage.setItem === 'function') return zt.dbStorage + return window.localStorage // 调试兜底,正常宿主环境走不到 +} + +function readCreds() { + try { + const sealed = storage().getItem(STORE_KEY) + if (!sealed) return null + const json = open(sealed) + const obj = JSON.parse(json) + if (obj && typeof obj.appId === 'string' && typeof obj.secretKey === 'string' && obj.appId && obj.secretKey) { + return { appId: obj.appId, secretKey: obj.secretKey } + } + } catch (e) { /* 解密失败(如主密钥文件被删)当作未配置,让用户重新填写 */ } + return null +} + +function writeCreds(appId, secretKey) { + storage().setItem(STORE_KEY, seal(JSON.stringify({ appId: String(appId), secretKey: String(secretKey) }))) +} + +function clearCreds() { + try { storage().removeItem(STORE_KEY) } catch (e) { /* 忽略 */ } +} + +/* ------------------------------------------------------------------ */ +/* 百度翻译 API */ +/* ------------------------------------------------------------------ */ + +function utf8Bytes(str) { + return Buffer.byteLength(String(str), 'utf8') +} + +/** 通用 POST:优先 Electron net(走 Chromium 网络栈,自动跟随系统代理),兜底 node https */ +function httpsPost(urlStr, body, contentType) { + return new Promise((resolve, reject) => { + const TIMEOUT = 30000 + const parse = (buf) => { + try { + return JSON.parse(buf.toString('utf8')) + } catch (e) { + return null + } + } + + // ---- 首选:Electron net 模块(Chromium 网络栈,跟随系统代理;代理用户必备)---- + try { + const electron = require('electron') + if (electron && electron.net && typeof electron.net.request === 'function') { + const req = electron.net.request({ method: 'POST', url: urlStr }) + req.setHeader('Content-Type', contentType) + req.setHeader('User-Agent', 'y-translate/1.1.0') + let settled = false + const timer = setTimeout(() => { + if (settled) return + settled = true + try { req.abort() } catch (e) { /* 已结束 */ } + reject(new Error('timeout')) + }, TIMEOUT) + req.on('response', (res) => { + const chunks = [] + res.on('data', (c) => chunks.push(c)) + res.on('end', () => { + if (settled) return + settled = true + clearTimeout(timer) + const data = parse(Buffer.concat(chunks)) + if (data) resolve(data) + else reject(new Error('HTTP ' + res.statusCode + ' 非 JSON 响应')) + }) + }) + req.on('error', (e) => { + if (settled) return + settled = true + clearTimeout(timer) + reject(e) + }) + req.write(body) + req.end() + return + } + } catch (e) { /* 无 electron(浏览器调试):走 node https */ } + + // ---- 兜底:node https 直连 ---- + const url = new URL(urlStr) + const req = https.request( + { + hostname: url.hostname, + path: url.pathname, + method: 'POST', + timeout: TIMEOUT, + headers: { + 'Content-Type': contentType, + 'Content-Length': Buffer.byteLength(body), + 'User-Agent': 'y-translate/1.1.0' + } + }, + (res) => { + const chunks = [] + res.on('data', (c) => chunks.push(c)) + res.on('end', () => { + const data = parse(Buffer.concat(chunks)) + if (data) resolve(data) + else reject(new Error('HTTP ' + res.statusCode + ' 非 JSON 响应')) + }) + } + ) + req.on('timeout', () => req.destroy(new Error('timeout'))) + req.on('error', reject) + req.write(body) + req.end() + }) +} + +/** 签名:MD5(appid + q + salt + 密钥),32 位小写 */ +function makeSign(q, salt, creds) { + return crypto + .createHash('md5') + .update(creds.appId + q + salt + creds.secretKey, 'utf8') + .digest('hex') +} + +function makeSalt() { + return String(Date.now()) + String(Math.floor(Math.random() * 10)) +} + +/** + * 通用文本翻译(表单)。词典资源只有这个接口返回。 + */ +function commonTranslate(text, from, to, creds) { + const salt = makeSalt() + return httpsPost( + ENDPOINT, + new URLSearchParams({ + q: text, + from, + to, + appid: creds.appId, + salt, + sign: makeSign(text, salt, creds), + // 词典资源开关:未开通时百度会忽略,开通后单词查询返回 dict 字段 + dict: '1' + }).toString(), + 'application/x-www-form-urlencoded' + ) +} + +/** + * 大模型文本翻译接口相关代码已移除:插件统一走通用文本翻译 API。 + */ + +/* ------------------------------------------------------------------ */ +/* 对渲染层暴露的 services 接口 */ +/* ------------------------------------------------------------------ */ + +window.services = { + ready() { + return typeof window.ztools !== 'undefined' + }, + + /** 单次请求字节上限(给渲染层画字数器用) */ + maxQueryBytes() { + return MAX_QUERY_BYTES + }, + + /** + * 读取已配置凭证。只回 appId 和"是否已填密钥",secretKey 不出 preload。 + * 未配置返回 null。 + */ + loadCreds() { + const creds = readCreds() + if (!creds) return null + return { appId: creds.appId, hasSecret: true } + }, + + /** 保存凭证(覆盖式:secretKey 传空串则保留旧密钥,方便只改 appid) */ + saveCreds(appId, secretKey) { + const id = String(appId || '').trim() + let secret = String(secretKey || '').trim() + if (!id) return { ok: false, reason: 'APPID_REQUIRED' } + if (!secret) { + const old = readCreds() + if (!old || old.appId !== id) return { ok: false, reason: 'SECRET_REQUIRED' } + secret = old.secretKey + } + try { + writeCreds(id, secret) + return { ok: true } + } catch (e) { + return { ok: false, reason: 'ENCRYPT_FAIL' } + } + }, + + /** 清除已保存的凭证(密文与主密钥文件一并删除) */ + clearCreds() { + clearCreds() + try { fs.unlinkSync(keyFilePath()) } catch (e) { /* 文件可能本来就不存在 */ } + return { ok: true } + }, + + /** + * 翻译。渲染层只传文本与语言方向,签名与请求全在这里完成。 + * + * @returns {Promise<{ok:true, from:string, to:string, items:{src?:string,dst:string,dict?:object}[]} + * |{ok:false, code:string, msg?:string}>} + * code 见渲染层 src/baidu.ts 的 ERROR_MSG 映射。 + */ + async translate({ text, from, to } = {}) { + const q = String(text ?? '').trim() + if (!q) return { ok: false, code: 'EMPTY_INPUT' } + + const creds = readCreds() + if (!creds) return { ok: false, code: 'NO_CONFIG' } + + if (utf8Bytes(q) > MAX_QUERY_BYTES) return { ok: false, code: 'BAIDU_58003' } + + try { + const res = await commonTranslate(q, String(from || 'auto'), String(to || 'zh'), creds) + if (res && res.error_code) { + return { ok: false, code: 'BAIDU_' + String(res.error_code), msg: res.error_msg || '' } + } + const items = (Array.isArray(res.trans_result) ? res.trans_result : []) + .map((it) => { + // dict 是 JSON 字符串(音标/词性/释义/词形变化),解析失败不影响译文展示 + let dict + try { + if (typeof it.dict === 'string' && it.dict) dict = JSON.parse(it.dict) + } catch (e) { /* 词典数据损坏就当没有 */ } + return { + src: it && typeof it.src === 'string' ? it.src : '', + dst: it && typeof it.dst === 'string' ? it.dst : '', + dict + } + }) + .filter((it) => it.dst) + return { ok: true, from: String(res.from || from || ''), to: String(res.to || to || ''), items } + } catch (e) { + // 把真实原因(DNS/连接拒绝/证书/HTTP 状态等)带给渲染层,别笼统报"网络失败" + const detail = String((e && (e.message || e.code)) || e || 'unknown').slice(0, 120) + const isTimeout = /timeout|ETIMEDOUT/i.test(detail) || (e && e.code === 'ETIMEDOUT') + return { ok: false, code: isTimeout ? 'TIMEOUT' : 'NETWORK', msg: detail } + } + } +} diff --git a/plugins/baidu-translate/src/App.vue b/plugins/baidu-translate/src/App.vue new file mode 100644 index 000000000..d4088e78d --- /dev/null +++ b/plugins/baidu-translate/src/App.vue @@ -0,0 +1,445 @@ + + + diff --git a/plugins/baidu-translate/src/api.ts b/plugins/baidu-translate/src/api.ts new file mode 100644 index 000000000..0af04ccf5 --- /dev/null +++ b/plugins/baidu-translate/src/api.ts @@ -0,0 +1,297 @@ +/** + * 宿主 API 封装层。 + * + * preload(src-ztools/preload/services.js)暴露 window.services: + * - loadCreds / saveCreds / clearCreds —— 密钥的加密存取(secretKey 不出 preload) + * - translate —— 百度翻译请求(签名与 HTTPS 全在 Node 侧) + * - maxQueryBytes / ready + * + * 浏览器直接访问 localhost:5173 时没有 preload,自动切换到 mock: + * 凭证明文存 localStorage(仅开发)、翻译返回假数据,保证 UI 可独立调试。 + * + * @author yhx + */ + +import type { CredsInfo, HistoryItem, SaveResult, TranslateResult } from './types' + +interface Services { + ready(): boolean + maxQueryBytes(): number + loadCreds(): CredsInfo | null + saveCreds(appId: string, secretKey: string): SaveResult + clearCreds(): SaveResult + translate(text: string, from: string, to: string): Promise +} + +const isHost = () => + typeof window !== 'undefined' && + typeof (window as unknown as { services?: Services }).services !== 'undefined' +export const isDevMock = () => !isHost() + +function realServices(): Services { + return (window as unknown as { services: Services }).services +} + +/* ------------------------------------------------------------------ */ +/* 通用宿主能力 */ +/* ------------------------------------------------------------------ */ + +export const host = { + ready(): boolean { + try { + return realServices().ready() + } catch { + return false + } + }, + + maxQueryBytes(): number { + try { + return realServices().maxQueryBytes() || 6000 + } catch { + return 6000 + } + }, + + loadCreds(): CredsInfo | null { + try { + return realServices().loadCreds() + } catch { + return null + } + }, + + saveCreds(appId: string, secretKey: string): SaveResult { + try { + return realServices().saveCreds(appId, secretKey) + } catch { + return { ok: false, reason: 'ENCRYPT_FAIL' } + } + }, + + clearCreds(): SaveResult { + try { + return realServices().clearCreds() + } catch { + return { ok: false } + } + }, + + async translate(text: string, from: string, to: string): Promise { + // preload 端 window.services.translate 的实参是对象形态,这里做一次适配 + const raw = realServices() as unknown as { + translate(a: { text: string; from: string; to: string }): Promise + } + return raw.translate({ text, from, to }) + }, + /** 翻译结果写回系统剪贴板(优先宿主,浏览器开发环境用 navigator.clipboard 兜底) */ + async copy(text: string): Promise { + try { + const zt = (window as unknown as Record).ztools + if (zt?.clipboard?.writeContent) { + const res = await zt.clipboard.writeContent({ type: 'text', content: text }) + return (res as { success?: boolean } | null)?.success !== false + } + } catch { /* 走浏览器兜底 */ } + try { + await navigator.clipboard.writeText(text) + return true + } catch { + return false + } + }, + + /** 用系统浏览器打开百度翻译开放平台(申请密钥用) */ + openConsole(): void { + const url = 'https://fanyi-api.baidu.com/' + try { + const zt = (window as unknown as Record).ztools + if (typeof zt?.shellOpenExternal === 'function') { + zt.shellOpenExternal(url) + return + } + } catch { /* 走兜底 */ } + window.open(url, '_blank', 'noopener,noreferrer') + }, + + toast(message: string): void { + try { + void (window as unknown as Record).ztools?.showToast?.(message) + } catch { + console.info('[toast]', message) + } + } +} + +/* ------------------------------------------------------------------ */ +/* 浏览器开发 mock */ +/* ------------------------------------------------------------------ */ + +const MOCK_CREDS_KEY = 'y-translate:dev-creds' +const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)) + +/** 假词典:覆盖 mock 调试时常见输入,其他输入返回"伪翻译" */ +const MOCK_DICT: Record = { + 'hello': '你好', + 'hello world': '你好,世界', + 'thank you': '谢谢', + 'good morning': '早上好' +} + +/** 单词查询的 mock 词典数据(模拟百度 dict 字段结构,供浏览器预览词典卡片) */ +function mockDict(word: string): unknown { + const w = word.toLowerCase() + return { + word_result: { + simple_means: { + word_name: w, + word_means: [`${w}:用于问候的感叹词`, '(开发模式示例数据)'], + tags: { core: ['高考', 'CET4', '考研'], other: [''] }, + exchange: { + word_pl: [w + 's'], + word_third: [w + 's'], + word_past: [w + 'ed'], + word_done: [w + 'ed'], + word_ing: [w + 'ing'] + }, + symbols: [ + { + ph_en: 'həˈləʊ', + ph_am: 'həˈloʊ', + ph_other: '', + parts: [ + { part: 'int.', means: ['喂;哈罗(用于问候、接电话或引起注意)'] }, + { part: 'n.', means: ['问候,招呼'] }, + { part: 'vi.', means: ['喊"喂"'] } + ] + } + ] + }, + edict: { + item: [ + { + pos: 'noun', + tr_group: [ + { + tr: ['an expression of greeting'], + example: ['every morning they exchanged polite hellos'], + similar_word: ['hullo', 'hi', 'howdy'] + } + ] + } + ] + } + } + } +} + +const mock: Services = { + ready() { + return false + }, + maxQueryBytes() { + return 6000 + }, + loadCreds() { + try { + const raw = localStorage.getItem(MOCK_CREDS_KEY) + const obj = raw ? JSON.parse(raw) : null + return obj ? { appId: String(obj.appId), hasSecret: true } : null + } catch { + return null + } + }, + saveCreds(appId, secretKey) { + if (!String(appId).trim()) return { ok: false, reason: 'APPID_REQUIRED' } + if (!String(secretKey).trim() && !this.loadCreds()) return { ok: false, reason: 'SECRET_REQUIRED' } + localStorage.setItem(MOCK_CREDS_KEY, JSON.stringify({ appId: String(appId).trim(), hasSecret: true })) + return { ok: true } + }, + clearCreds() { + localStorage.removeItem(MOCK_CREDS_KEY) + return { ok: true } + }, + /** mock 单一假数据源,词典卡片也能在浏览器里演示 */ + async translate(text: string, from: string, to: string): Promise { + await sleep(400) + const q = String(text ?? '').trim() + if (!q) return { ok: false, code: 'EMPTY_INPUT' } + if (!this.loadCreds()) return { ok: false, code: 'NO_CONFIG' } + // 多条(按换行切)时逐条给结果,模拟百度 trans_result 数组形态 + const lines = q.split('\n').filter(Boolean) + return { + ok: true, + from: from === 'auto' ? (/[一-龥]/.test(q) ? 'zh' : 'en') : from, + to, + items: lines.map((line) => { + const w = line.toLowerCase() + const base = { src: line, dst: MOCK_DICT[w] ?? `〔开发模式〕${line}` } + // 单个英文单词时附带词典数据,让词典卡片在浏览器里也能演示 + if (/^[a-z]+$/.test(w)) { + return { ...base, dict: mockDict(w) } + } + return base + }) + } + } +} + +/** 统一出口:宿主走 host 适配层(负责把三参数调用转成 preload 的对象实参), + * 浏览器开发走 mock。**不能直接暴露 realServices()**——它的 translate + * 收对象参数,渲染层按三参数调用会全部解构出 undefined(表现为永远 + * 提示"请输入要翻译的内容")。 + */ +export const api: Services & { + copy(t: string): Promise + openConsole(): void + toast(m: string): void +} = isHost() ? (host as never) : (mock as never) + +/* ------------------------------------------------------------------ */ +/* 历史记录持久化(宿主 dbStorage / 浏览器 localStorage) */ +/* ------------------------------------------------------------------ */ + +const HIST_KEY = 'baidu-translate:history' +const HIST_LIMIT = 50 + +function rawStorage(): Pick { + if (isHost()) return (window as unknown as Record).ztools.dbStorage + return localStorage +} + +export const historyStore = { + load(): HistoryItem[] { + try { + const raw = rawStorage().getItem(HIST_KEY) + const parsed = raw ? JSON.parse(raw) : [] + return Array.isArray(parsed) ? parsed : [] + } catch { + return [] + } + }, + + save(list: HistoryItem[]): void { + try { + rawStorage().setItem(HIST_KEY, JSON.stringify(list.slice(0, HIST_LIMIT))) + } catch { /* 存储失败静默 */ } + }, + + clear(): void { + try { + rawStorage().removeItem(HIST_KEY) + } catch { /* 忽略 */ } + } +} + +// mock 下把宿主能力也补成开发形态,UI 无需分叉 +if (isDevMock()) { + ;(api as unknown as Record).copy = async (t: string) => { + await navigator.clipboard.writeText(t).catch(() => {}) + console.info('[toast] 已复制(开发模式):', t) + return true + } + ;(api as unknown as Record).openConsole = () => { + console.info('[toast] 开发模式:此处会打开 https://fanyi-api.baidu.com/') + } + ;(api as unknown as Record).toast = (m: string) => console.info('[toast]', m) +} diff --git a/plugins/baidu-translate/src/assets/logo.png b/plugins/baidu-translate/src/assets/logo.png new file mode 100644 index 000000000..3b620e997 Binary files /dev/null and b/plugins/baidu-translate/src/assets/logo.png differ diff --git a/plugins/baidu-translate/src/baidu.ts b/plugins/baidu-translate/src/baidu.ts new file mode 100644 index 000000000..a4ce13694 --- /dev/null +++ b/plugins/baidu-translate/src/baidu.ts @@ -0,0 +1,290 @@ +/** + * 百度翻译领域常量:支持语言表、错误码映射、字节计算。 + * 语言与错误码以百度翻译开放平台文档为准(通用翻译 API)。 + * + * @author yhx + */ + +import type { LangOption } from './types' + +/** 百度通用翻译支持的语言(auto 只能作为源语言) */ +export const LANGS: LangOption[] = [ + { code: 'auto', name: '自动检测' }, + { code: 'zh', name: '中文' }, + { code: 'cht', name: '繁体中文' }, + { code: 'en', name: '英语' }, + { code: 'yue', name: '粤语' }, + { code: 'wyw', name: '文言文' }, + { code: 'jp', name: '日语' }, + { code: 'kor', name: '韩语' }, + { code: 'fra', name: '法语' }, + { code: 'spa', name: '西班牙语' }, + { code: 'th', name: '泰语' }, + { code: 'ara', name: '阿拉伯语' }, + { code: 'ru', name: '俄语' }, + { code: 'pt', name: '葡萄牙语' }, + { code: 'de', name: '德语' }, + { code: 'it', name: '意大利语' }, + { code: 'el', name: '希腊语' }, + { code: 'nl', name: '荷兰语' }, + { code: 'pl', name: '波兰语' }, + { code: 'bul', name: '保加利亚语' }, + { code: 'est', name: '爱沙尼亚语' }, + { code: 'dan', name: '丹麦语' }, + { code: 'fin', name: '芬兰语' }, + { code: 'cs', name: '捷克语' }, + { code: 'rom', name: '罗马尼亚语' }, + { code: 'slo', name: '斯洛文尼亚语' }, + { code: 'swe', name: '瑞典语' }, + { code: 'hu', name: '匈牙利语' }, + { code: 'vie', name: '越南语' } +] + +/** 百度 API error_code → 用户能看懂的中文提示 */ +export const ERROR_MSG: Record = { + NO_CONFIG: '尚未配置百度翻译密钥,请先到设置中填写', + EMPTY_INPUT: '请输入要翻译的内容', + NETWORK: '网络请求失败,请检查网络后重试', + TIMEOUT: '请求超时,请重试', + APPID_REQUIRED: '请填写 APPID', + SECRET_REQUIRED: '请填写密钥(Secret Key)', + ENCRYPT_FAIL: '密钥加密保存失败,请重试', + + BAIDU_52001: '请求超时,请重试', + BAIDU_52002: '百度翻译服务临时不可用,请稍后重试', + BAIDU_52003: 'APPID 无效或未被授权,请检查设置', + BAIDU_54000: '请求参数缺失(一般是插件问题,请反馈)', + BAIDU_54001: '签名错误,请核对 APPID 与密钥是否配套', + BAIDU_54003: '请求过于频繁,请稍后再试', + BAIDU_54004: '账户余额不足,请到百度翻译开放平台充值', + BAIDU_54005: '请求过于频繁或文本过长,请稍后再试', + BAIDU_58000: '百度翻译服务失败,请稍后重试', + BAIDU_58001: '不支持的语言方向,请调整目标语言', + BAIDU_58002: '百度翻译服务当前已关闭,请到开放平台检查', + BAIDU_58003: '文本超出单次翻译上限(6000 字节),请分段翻译', + BAIDU_90107: '认证失败或权限不足,请检查账号状态' +} + +export function errMsgOf(code: string | undefined, msg?: string): string { + if (!code) return '未知错误' + const base = ERROR_MSG[code] || `翻译失败(错误码 ${code.replace(/^BAIDU_/, '')})` + // 网络类错误带上真实原因,方便定位(DNS/代理/HTTP 状态等) + if ((code === 'NETWORK' || code === 'TIMEOUT') && msg) return `${base}(${msg})` + return base +} + +/* ------------------------------------------------------------------ */ +/* 词典数据解析(百度 dict 字段,数据源与 fanyi.baidu.com 同源) */ +/* ------------------------------------------------------------------ */ + +/** 词性释义组(简明词典) */ +export interface DictPart { + part: string + means: string[] +} + +/** 词形变化 */ +export interface DictExchange { + name: string + values: string[] +} + +/** 英英释义组 */ +export interface DictEnDef { + pos: string + senses: string[] + examples: string[] + similar: string[] +} + +/** 归一后的词典信息 */ +export interface DictInfo { + word: string + /** 英式/美式/其他(中文词为拼音)音标 */ + phEn: string + phAm: string + phOther: string + parts: DictPart[] + /** 无词性结构的简明含义(中文词常见) */ + means: string[] + /** 考试标签(高考 / CET4 / 考研…) */ + tags: string[] + exchanges: DictExchange[] + enDefs: DictEnDef[] +} + +/** exchange 字段 key → 中文名 */ +const EXCHANGE_LABELS: Record = { + word_pl: '复数', + word_third: '第三人称单数', + word_past: '过去式', + word_done: '过去分词', + word_ing: '现在分词', + word_er: '比较级', + word_est: '最高级' +} + +function strArr(v: unknown): string[] { + return Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string' && !!x) : [] +} + +/** + * 把百度 dict JSON 归一成 DictInfo;结构对不上返回 null。 + * 兼容英文 query(simple_means + edict)与中文 query(simple_means 为主)。 + */ +export function buildDictInfo(raw: unknown): DictInfo | null { + if (!raw || typeof raw !== 'object') return null + const root = raw as Record + const sm = root.word_result?.simple_means + if (!sm || typeof sm !== 'object') return null + + /** + * symbols 是数组:兼类词(如 claims / take)每个词性一段,各带自己的音标与 parts。 + * 必须遍历全部,只取 [0] 会把其他词性的含义全部丢掉(表现为"claims 只显示索赔")。 + * 音标取第一个非空的,正常情况下各段一致。 + */ + const symbols = Array.isArray(sm.symbols) ? sm.symbols : [] + let phEn = '' + let phAm = '' + let phOther = '' + const parts: DictPart[] = [] + const seen = new Set() + for (const sym of symbols) { + if (!sym || typeof sym !== 'object') continue + if (!phEn && typeof sym.ph_en === 'string' && sym.ph_en) phEn = sym.ph_en + if (!phAm && typeof sym.ph_am === 'string' && sym.ph_am) phAm = sym.ph_am + if (!phOther && typeof sym.ph_other === 'string' && sym.ph_other) phOther = sym.ph_other + if (!Array.isArray(sym.parts)) continue + for (const p of sym.parts) { + if (!p || typeof p !== 'object') continue + const means = strArr(p.means) + if (!means.length) continue + const key = String(p.part ?? '') + '\u0000' + means.join('\u0001') + if (seen.has(key)) continue + seen.add(key) + parts.push({ part: String(p.part ?? ''), means }) + } + } + + const exchanges: DictExchange[] = [] + const ex = sm.exchange + if (ex && typeof ex === 'object') { + for (const [key, label] of Object.entries(EXCHANGE_LABELS)) { + const values = strArr((ex as Record)[key]) + if (values.length) exchanges.push({ name: label, values }) + } + } + + const enDefs: DictEnDef[] = [] + const edictItems = root.word_result?.edict?.item + if (Array.isArray(edictItems)) { + for (const entry of edictItems) { + if (!entry || typeof entry !== 'object') continue + const groups = Array.isArray(entry.tr_group) ? entry.tr_group : [] + for (const g of groups) { + const senses = strArr(g?.tr) + if (!senses.length) continue + enDefs.push({ + pos: String(entry.pos ?? ''), + senses, + examples: strArr(g?.example), + similar: strArr(g?.similar_word) + }) + } + } + } + + return { + word: String(sm.word_name ?? ''), + phEn, + phAm, + phOther, + parts, + means: strArr(sm.word_means), + tags: strArr(sm.tags?.core), + exchanges, + enDefs + } +} + +/** 百度返回的源语言代码 → 名称(给结果卡片显示"检测语言"用) */ +export function langName(code: string | undefined): string { + if (!code) return '' + return LANGS.find((l) => l.code === code)?.name || code +} + +/** + * 生成英语变形词的原形候选(按可能性排序,最多 3 个)。 + * claims→claim / boxes→box / claimed→claim / stopped→stop / making→make / studies→study。 + */ +export function lemmaCandidates(word: string): string[] { + const w = word.toLowerCase() + const out: string[] = [] + const push = (s: string) => { + if (s && s !== w && /^[a-z][a-z'-]*$/.test(s) && !out.includes(s)) out.push(s) + } + if (w.endsWith('ies') && w.length > 4) push(w.slice(0, -3) + 'y') + if (w.endsWith('ves') && w.length > 4) { + push(w.slice(0, -3) + 'f') + push(w.slice(0, -3) + 'fe') + } + if (w.endsWith('es') && w.length > 3) { + push(w.slice(0, -1)) + push(w.slice(0, -2)) + } else if (w.endsWith('s') && !w.endsWith('ss') && w.length > 3) { + push(w.slice(0, -1)) + } + if (w.endsWith('ied') && w.length > 4) push(w.slice(0, -3) + 'y') + if (w.endsWith('ed') && w.length > 4) { + push(w.slice(0, -1)) + push(w.slice(0, -2)) + } + if (w.endsWith('ing') && w.length > 5) { + push(w.slice(0, -3) + 'e') + push(w.slice(0, -3)) + } + if (w.endsWith('er') && w.length > 4) { + push(w.slice(0, -2)) + push(w.slice(0, -1)) + } + if (w.endsWith('est') && w.length > 5) { + push(w.slice(0, -3)) + push(w.slice(0, -2)) + } + return out.slice(0, 3) +} + +/** 词典内容丰富度评分(在原词词典与原形词典之间择优) */ +export function dictScore(d: DictInfo | null): number { + if (!d) return 0 + const means = d.parts.reduce((n, p) => n + p.means.length, 0) + d.means.length + const enSenses = d.enDefs.reduce((n, e) => n + e.senses.length, 0) + return means * 2 + enSenses + d.exchanges.length +} + +/** 是否单个英文词(含连字符/撇号,如 well-known、don't) */ +export function isEnglishWord(text: string): boolean { + return /^[a-zA-Z][a-zA-Z'-]*$/.test(text.trim()) +} + +/** UTF-8 字节数(免费版单次 q 上限 6000 字节,字符数会超但字节数不一定) */ +export function utf8Bytes(str: string): number { + return new TextEncoder().encode(str).length +} + +/** + * 智能方向判定(配合 to='smart'): + * - 出现日文假名 / 韩文 → 目标中文; + * - 中文为主(汉字数 ≥ 拉丁字母数)→ 目标英文; + * - 其余(纯英文等外文)→ 目标中文。 + */ +export function pickSmartTarget(text: string): string { + const t = String(text || '') + if (/[\u3040-\u30ff]/.test(t) || /[\uac00-\ud7af]/.test(t)) return 'zh' + const han = (t.match(/[\u4e00-\u9fff]/g) || []).length + if (han > 0) { + const latin = (t.match(/[A-Za-z]/g) || []).length + return han >= latin ? 'en' : 'zh' + } + return 'zh' +} diff --git a/plugins/baidu-translate/src/components/SettingsPanel.vue b/plugins/baidu-translate/src/components/SettingsPanel.vue new file mode 100644 index 000000000..b39e77d6f --- /dev/null +++ b/plugins/baidu-translate/src/components/SettingsPanel.vue @@ -0,0 +1,100 @@ + + + diff --git a/plugins/baidu-translate/src/env.d.ts b/plugins/baidu-translate/src/env.d.ts new file mode 100644 index 000000000..f27cbe7ea --- /dev/null +++ b/plugins/baidu-translate/src/env.d.ts @@ -0,0 +1,21 @@ +/// + +/** + * window.services 由 preload 提供(src-ztools/preload/services.js), + * 类型对齐 src/api.ts 的 Services 接口。 + */ +declare global { + interface Window { + services?: { + ready(): boolean + maxQueryBytes(): number + loadCreds(): import('./types').CredsInfo | null + saveCreds(appId: string, secretKey: string): import('./types').SaveResult + clearCreds(): import('./types').SaveResult + translate(args: { text: string; from: string; to: string }): Promise + } + ztools?: unknown + } +} + +export {} diff --git a/plugins/baidu-translate/src/main.css b/plugins/baidu-translate/src/main.css new file mode 100644 index 000000000..9e0715b20 --- /dev/null +++ b/plugins/baidu-translate/src/main.css @@ -0,0 +1,668 @@ +/** + * 百度翻译插件全局样式。 + * 浅色为主,跟随宿主暗色模式(ztools.isDarkColors)时挂 dark class。 + * + * @author yhx + */ + +:root { + --bg: #f6f7fb; + --panel: #ffffff; + --border: #e3e6ee; + --text: #23262f; + --text-2: #6b7280; + --primary: #2932e1; + --primary-weak: #eef0ff; + --danger: #d5413c; + --ok: #0f8a4d; + --warn: #b26a00; + --radius: 10px; +} + +.dark { + --bg: #1e2028; + --panel: #262933; + --border: #3a3e4c; + --text: #e8eaf0; + --text-2: #9aa1b0; + --primary: #6b74ff; + --primary-weak: #30355a; + --danger: #e2695f; + --ok: #4dbb82; + --warn: #d9a441; +} + +* { + box-sizing: border-box; +} + +html, +body, +#app { + height: 100%; + margin: 0; +} + +body { + font-family: 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif; + font-size: 14px; + color: var(--text); + background: var(--bg); +} + +.app { + display: flex; + flex-direction: column; + height: 100%; + overflow: auto; +} + +/* ---------------- 顶栏 ---------------- */ + +.topbar { + display: flex; + align-items: center; + gap: 8px; + padding: 10px 14px; + border-bottom: 1px solid var(--border); + background: var(--panel); + flex-shrink: 0; +} + +.topbar-logo { + width: 22px; + height: 22px; + border-radius: 6px; +} + +.topbar-title { + font-size: 15px; + font-weight: 600; + margin: 0; +} + +.topbar-spacer { + flex: 1; +} + +.badge { + font-size: 12px; + padding: 2px 8px; + border-radius: 999px; +} + +.badge-ok { + color: var(--ok); + background: color-mix(in srgb, var(--ok) 12%, transparent); +} + +.badge-warn { + color: var(--warn); + background: color-mix(in srgb, var(--warn) 14%, transparent); +} + +.icon-btn { + border: none; + background: transparent; + color: var(--text-2); + font-size: 15px; + line-height: 1; + padding: 6px; + border-radius: 6px; + cursor: pointer; +} + +.icon-btn:hover { + background: var(--primary-weak); + color: var(--primary); +} + +.icon-btn:disabled { + opacity: 0.35; + cursor: default; +} + +.icon-btn:disabled:hover { + background: transparent; + color: var(--text-2); +} + +/* ---------------- 翻译主页(上语言栏,下左右分栏) ---------------- */ + +.main { + display: flex; + flex-direction: column; + gap: 10px; + padding: 12px 14px; + flex: 1; + min-height: 0; +} + +.lang-bar { + display: flex; + align-items: center; + gap: 8px; + flex-shrink: 0; +} + +.panes { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 12px; + flex: 1; + min-height: 0; +} + +.pane { + display: flex; + flex-direction: column; + gap: 10px; + min-height: 0; + min-width: 0; +} + +.lang-select { + flex: 1; + height: 32px; + padding: 0 8px; + border: 1px solid var(--border); + border-radius: var(--radius); + background: var(--panel); + color: var(--text); + font-size: 13px; + outline: none; + min-width: 0; +} + +.lang-select:focus { + border-color: var(--primary); +} + +.swap-btn { + flex-shrink: 0; +} + +.input-box { + background: var(--panel); + border: 1px solid var(--border); + border-radius: var(--radius); + padding: 10px 12px 6px; + flex: 1; + display: flex; + flex-direction: column; + min-height: 0; +} + +.input-area { + width: 100%; + border: none; + outline: none; + resize: none; + background: transparent; + color: var(--text); + font: inherit; + line-height: 1.7; + flex: 1; + min-height: 180px; +} + +.input-foot { + display: flex; + justify-content: space-between; + align-items: center; + gap: 8px; + padding: 4px 0 6px; + border-top: 1px dashed var(--border); + margin-top: 6px; +} + +.hint { + color: var(--text-2); + font-size: 12px; + white-space: nowrap; +} + +.byte-count { + color: var(--text-2); + font-size: 12px; + font-variant-numeric: tabular-nums; + white-space: nowrap; +} + +.byte-count.over { + color: var(--danger); +} + +.input-actions { + display: flex; + gap: 8px; +} + +.primary-btn { + flex: 1; + height: 36px; + border: none; + border-radius: var(--radius); + background: var(--primary); + color: #fff; + font-size: 14px; + font-weight: 600; + letter-spacing: 4px; + cursor: pointer; +} + +.primary-btn:hover { + filter: brightness(1.08); +} + +.primary-btn:disabled { + opacity: 0.45; + cursor: default; + filter: none; +} + +.ghost-btn { + height: 36px; + padding: 0 14px; + border: 1px solid var(--border); + border-radius: var(--radius); + background: var(--panel); + color: var(--text-2); + cursor: pointer; +} + +.ghost-btn:hover:not(:disabled) { + color: var(--danger); + border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); +} + +.ghost-btn:disabled { + opacity: 0.45; + cursor: default; +} + +/* ---------------- 右栏:结果 ---------------- */ + +.pane-result { + overflow: auto; + padding-right: 2px; +} + +.result-card { + background: var(--panel); + border: 1px solid var(--border); + border-radius: var(--radius); + padding: 10px 12px; +} + +.result-head { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 8px; +} + +.detect { + font-size: 12px; + color: var(--text-2); +} + +.mini-btn { + border: none; + background: var(--primary-weak); + color: var(--primary); + font-size: 12px; + padding: 4px 8px; + border-radius: 6px; + cursor: pointer; + white-space: nowrap; +} + +.mini-btn:hover { + filter: brightness(0.96); +} + +.dark .mini-btn:hover { + filter: brightness(1.15); +} + +.segments { + display: flex; + flex-direction: column; + gap: 8px; +} + +.segment { + position: relative; + border: 1px dashed var(--border); + border-radius: 8px; + padding: 8px 10px; +} + +.seg-src { + margin: 0 0 4px; + color: var(--text-2); + font-size: 12px; + line-height: 1.6; + white-space: pre-wrap; + word-break: break-word; +} + +.seg-dst { + margin: 0; + font-size: 14px; + line-height: 1.7; + white-space: pre-wrap; + word-break: break-word; +} + +.seg-copy { + position: absolute; + top: 6px; + right: 6px; + border: none; + background: transparent; + color: var(--text-2); + font-size: 12px; + cursor: pointer; + opacity: 0; + padding: 2px 6px; + border-radius: 6px; +} + +.segment:hover .seg-copy { + opacity: 1; +} + +.seg-copy:hover { + background: var(--primary-weak); + color: var(--primary); +} + +.error-card { + background: color-mix(in srgb, var(--danger) 8%, var(--panel)); + border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border)); + border-radius: var(--radius); + color: var(--danger); + padding: 12px; + line-height: 1.6; +} + +/* ---------------- 词典卡片 ---------------- */ + +.dict { + display: flex; + flex-direction: column; + gap: 10px; +} + +.dict-word-row { + display: flex; + align-items: center; + gap: 8px; + flex-wrap: wrap; +} + +.dict-word { + font-size: 22px; + font-weight: 700; + line-height: 1.2; + word-break: break-all; +} + +.dict-tag { + font-size: 11px; + color: var(--warn); + background: color-mix(in srgb, var(--warn) 12%, transparent); + border-radius: 999px; + padding: 1px 8px; +} + +.dict-phon { + display: flex; + gap: 14px; + color: var(--text-2); + font-size: 13px; +} + +.dict-section { + border-top: 1px dashed var(--border); + padding-top: 8px; + display: flex; + flex-direction: column; + gap: 6px; +} + +.dict-sec-title { + margin: 0; + font-size: 12px; + color: var(--text-2); + font-weight: 600; +} + +.dict-line { + margin: 0; + line-height: 1.7; + font-size: 14px; +} + +.dict-pos { + display: inline-block; + color: var(--primary); + font-weight: 600; + margin-right: 6px; + font-size: 13px; +} + +.dict-exch { + display: flex; + flex-wrap: wrap; + gap: 6px 16px; + font-size: 13px; + line-height: 1.6; +} + +.exch-name { + color: var(--text-2); + margin-right: 4px; +} + +.en-def { + border-left: 2px solid var(--primary-weak); + padding-left: 8px; + display: flex; + flex-direction: column; + gap: 3px; +} + +.en-def-sense { + margin: 0; + font-size: 13px; + line-height: 1.6; +} + +.en-def-example { + margin: 0; + font-size: 12px; + color: var(--text-2); + font-style: italic; +} + +.en-def-similar { + margin: 0; + font-size: 12px; + color: var(--text-2); +} + +.empty-tip { + text-align: center; + color: var(--text-2); + padding: 36px 12px; + border: 1px dashed var(--border); + border-radius: var(--radius); +} + +.empty-main { + margin: 0 0 6px; + font-size: 14px; +} + +.empty-sub { + margin: 0; + font-size: 12px; + opacity: 0.8; +} + +/* ---------------- 历史记录 ---------------- */ + +.history { + margin-top: 2px; +} + +.hist-head { + display: flex; + justify-content: space-between; + align-items: center; + font-size: 12px; + color: var(--text-2); + padding: 0 2px 6px; +} + +.hist-list { + list-style: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + gap: 6px; +} + +.hist-item { + background: var(--panel); + border: 1px solid var(--border); + border-radius: 8px; + padding: 8px 10px; + cursor: pointer; + display: flex; + flex-direction: column; + gap: 3px; +} + +.hist-item:hover { + border-color: var(--primary); +} + +.hist-text { + font-size: 13px; + line-height: 1.5; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.hist-meta { + font-size: 11px; + color: var(--text-2); +} + +/* ---------------- 设置页 ---------------- */ + +.settings { + padding: 18px 16px; + display: flex; + flex-direction: column; + gap: 14px; + max-width: 480px; +} + +.settings-title { + margin: 0; + font-size: 16px; +} + +.settings-desc { + margin: 0; + color: var(--text-2); + font-size: 12px; + line-height: 1.7; +} + +.settings-desc a { + color: var(--primary); + text-decoration: none; +} + +.field { + display: flex; + flex-direction: column; + gap: 6px; +} + +.field-label { + font-size: 13px; + font-weight: 600; +} + +.field-input { + height: 36px; + padding: 0 10px; + border: 1px solid var(--border); + border-radius: var(--radius); + background: var(--panel); + color: var(--text); + font: inherit; + outline: none; + width: 100%; +} + +.field-input:focus { + border-color: var(--primary); +} + +.secret-row { + display: flex; + gap: 4px; + align-items: center; +} + +.field-hint { + font-size: 12px; + color: var(--text-2); +} + +.settings-actions { + display: flex; + gap: 10px; +} + +.settings-actions .primary-btn { + flex: 1; + letter-spacing: 2px; +} + +.danger-btn { + height: 38px; + padding: 0 16px; + border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border)); + border-radius: var(--radius); + background: transparent; + color: var(--danger); + cursor: pointer; +} + +.danger-btn:hover { + background: color-mix(in srgb, var(--danger) 8%, transparent); +} + +.tip { + margin: 0; + font-size: 12px; +} + +.tip-ok { + color: var(--ok); +} + +.tip-err { + color: var(--danger); +} diff --git a/plugins/baidu-translate/src/main.ts b/plugins/baidu-translate/src/main.ts new file mode 100644 index 000000000..2e8fae366 --- /dev/null +++ b/plugins/baidu-translate/src/main.ts @@ -0,0 +1,20 @@ +import { createApp } from 'vue' +import './main.css' +import App from './App.vue' + +createApp(App).mount('#app') + +// 跟随宿主暗色模式:根节点挂 dark class(样式变量在 main.css) +try { + const apply = () => { + const dark = (window as unknown as Record).ztools?.isDarkColors?.() + document.documentElement.classList.toggle('dark', !!dark) + } + apply() + ;(window as unknown as Record).ztools?.onThemeChange?.(apply) +} catch { + /* 无宿主(浏览器开发):跟随系统 */ + if (window.matchMedia?.('(prefers-color-scheme: dark)').matches) { + document.documentElement.classList.add('dark') + } +} diff --git a/plugins/baidu-translate/src/types.ts b/plugins/baidu-translate/src/types.ts new file mode 100644 index 000000000..1281aa5fb --- /dev/null +++ b/plugins/baidu-translate/src/types.ts @@ -0,0 +1,49 @@ +/** + * 全局类型定义。 + * + * @author yhx + */ + +/** 已保存凭证(preload 只回 appId 与"是否已填密钥",secretKey 永不外传) */ +export interface CredsInfo { + appId: string + hasSecret: boolean +} + +/** 保存凭证的返回 */ +export interface SaveResult { + ok: boolean + reason?: 'APPID_REQUIRED' | 'SECRET_REQUIRED' | 'ENCRYPT_FAIL' +} + +/** 翻译结果条目(dict 为百度词典数据,仅单词/词组查询且开通词典资源时返回) */ +export interface TransItem { + src: string + dst: string + dict?: unknown +} + +/** 翻译结果(preload.translate 的返回,统一在这层消费) */ +export interface TranslateResult { + ok: boolean + code?: string + /** 网络类错误的真实原因(DNS/代理/HTTP 状态等),给错误提示拼接用 */ + msg?: string + from?: string + to?: string + items?: TransItem[] +} + +/** 界面上的一条语言选项 */ +export interface LangOption { + code: string + name: string +} + +/** 历史记录条目(存最近翻译,点击可回看重翻) */ +export interface HistoryItem { + id: string + time: number + text: string + result: TranslateResult +} diff --git a/plugins/baidu-translate/tsconfig.json b/plugins/baidu-translate/tsconfig.json new file mode 100644 index 000000000..39b73bc6f --- /dev/null +++ b/plugins/baidu-translate/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "preserve", + "strict": false, + "noImplicitAny": false, + "types": ["@ztools-center/ztools-api-types"] + }, + "include": ["src"] +} diff --git a/plugins/baidu-translate/vite.config.js b/plugins/baidu-translate/vite.config.js new file mode 100644 index 000000000..2eac9cd07 --- /dev/null +++ b/plugins/baidu-translate/vite.config.js @@ -0,0 +1,17 @@ +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' + +/** + * 百度翻译插件构建配置。 + * 产物直接输出到 src-ztools/dist(plugin.json 的 main 指向 dist/index.html), + * base 用相对路径,保证 file:// 协议加载时资源引用不破。 + */ +export default defineConfig({ + plugins: [vue()], + base: './', + build: { + outDir: 'src-ztools/dist', + emptyOutDir: true, + assetsInlineLimit: 0 + } +})