@vamdawn/dsh-appearance-plus 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/CHANGELOG.zh-CN.md +28 -0
- package/LICENSE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/cordis.patch.yml +3 -0
- package/dist/client.js +652 -0
- package/dist/index.js +273 -0
- package/package.json +95 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
English | [简体中文](CHANGELOG.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - 2026-11-17
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Publish a Simplified Chinese README (`README.zh-CN.md`) next to the English one, and ship it in the package.
|
|
12
|
+
- Publish a Simplified Chinese changelog (`CHANGELOG.zh-CN.md`) next to the English one, and ship it in the package.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Rename the English settings page to **Appearance Plus**.
|
|
17
|
+
- Rewrite the README around install, usage, configuration, limitations, and development; the dated validation record is no longer part of it.
|
|
18
|
+
|
|
19
|
+
## [0.1.0] - 2026-10-15
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- Add `@vamdawn/dsh-appearance-plus` with an **Appearance+** page in the official Web and Desktop settings panel. Customize the interface font, code font, and window background without editing host stylesheets.
|
|
24
|
+
- Search installed system fonts and one optional extra folder by family name. Extra-folder fonts load from their original files through the host's authenticated file route, and each failed font keeps the last working family.
|
|
25
|
+
- Set a PNG, JPEG, or WebP background image by absolute path, with cover, contain, or tile placement and an adjustable overlay that follows the light or dark palette. Missing, oversized, or unsupported images show a localized error and keep the previous background.
|
|
26
|
+
- Choose the background image or extra font folder through the native macOS dialog, or enter the path manually on any platform.
|
|
27
|
+
- Store settings in the profile's `cordis.patch.yml`, so edits in the settings page and in the file stay in sync. Disabling the plugin removes every token override, style, and font it added.
|
|
28
|
+
- Provide Chinese and English copy, strict Host and Client type checks, automated tests against the built plugin, and the MIT license notice in the distribution.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
[English](CHANGELOG.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - 2026-11-17
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- 在英文版旁发布简体中文 README(`README.zh-CN.md`),并随 npm 包发布。
|
|
12
|
+
- 在英文版旁发布简体中文变更记录(`CHANGELOG.zh-CN.md`),并随 npm 包发布。
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- 将英文设置页的名称改为 **Appearance Plus**。
|
|
17
|
+
- 围绕安装、使用、配置、限制与开发重写 README;带日期的验证记录不再包含在内。
|
|
18
|
+
|
|
19
|
+
## [0.1.0] - 2026-10-15
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- 新增 `@vamdawn/dsh-appearance-plus`,在官方 Web 与 Desktop 设置面板中提供 **Appearance+** 页面。无需修改 Host 样式表即可自定义界面字体、代码字体和窗口背景。
|
|
24
|
+
- 按字体族名称搜索已安装的系统字体以及一个可选的额外目录。额外目录中的字体会通过 Host 的鉴权文件路由从其原始文件加载,字体加载失败时保留上一次可用的字体族。
|
|
25
|
+
- 通过绝对路径设置 PNG、JPEG 或 WebP 背景图片,支持 cover、contain 或平铺方式,并可调整随浅色或深色配色变化的蒙层。图片缺失、过大或格式不受支持时会显示本地化错误,并保留原有背景。
|
|
26
|
+
- 可通过 macOS 原生对话框选择背景图片或额外字体目录,也可在任何平台手动输入路径。
|
|
27
|
+
- 设置保存在 `profile` 的 `cordis.patch.yml` 中,因此设置页面与文件中的修改保持同步。禁用插件会移除它添加的所有 token 覆盖、样式和字体。
|
|
28
|
+
- 提供中英文文案、严格的 Host 与 Client 类型检查、针对构建后插件的自动化测试,以及分发内容中的 MIT 许可证声明。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,102 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vamdawn/dsh-appearance-plus
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@vamdawn/dsh-appearance-plus)
|
|
6
|
+
|
|
7
|
+
Customize the DeepSeek Harness interface font, code font, and window background image. The plugin adds an **Appearance Plus** page to the official settings panel and layers its changes over the active theme, so the built-in Light, Dark, and System palettes keep working.
|
|
8
|
+
|
|
9
|
+
Validated with DSH `0.2.0-rc.2`. It supports the Web UI on loopback pages and the Desktop application that uses it; the TUI has no settings panel. Copy ships in the official Chinese (`zh`) and English (`en`) locales.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
### From npm
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
dsh plugin --profile desktop add @vamdawn/dsh-appearance-plus
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Use `--profile web` for a Web profile. The package contains compiled JavaScript and needs no consumer-side build; it targets Node.js 24 or newer and the DSH versions declared in `peerDependencies`.
|
|
20
|
+
|
|
21
|
+
### From a source checkout
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
cd plugins/dsh-appearance-plus
|
|
25
|
+
npm ci --ignore-scripts
|
|
26
|
+
npm run typecheck
|
|
27
|
+
npm run build
|
|
28
|
+
cd ../..
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then install the directory into your active profile (typically `desktop` or `web`):
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
dsh plugin --profile <profile> add "$PWD/plugins/dsh-appearance-plus"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Installation links the local directory, so keep it and its `dist/` artifacts available and rebuild after changing source files. Refresh the Plugins page and confirm that `@vamdawn/dsh-appearance-plus` is enabled; restart the application if it has not loaded the plugin. If the macOS Desktop CLI is not on PATH, use:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
"/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To uninstall:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
dsh plugin --profile <profile> remove @vamdawn/dsh-appearance-plus
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
Open **Settings** at the bottom of the sidebar, then select **Appearance Plus** in the left navigation. Changes apply immediately without reloading.
|
|
52
|
+
|
|
53
|
+
- **Interface font** and **Code font**: the field shows the selected family. Click it to list every family, type to filter by name, and select with the pointer or with the arrow keys and Enter. **Default** at the top of the list returns to the host default. The chosen family goes first, followed by the host's shipped font stack as fallbacks.
|
|
54
|
+
- **Extra font folder**: one additional folder whose fonts appear in search, marked as *extra folder*. Supported files are `.ttf`, `.otf`, `.ttc`, `.woff`, and `.woff2`, and subfolders are included. **Rescan** picks up newly installed fonts.
|
|
55
|
+
- **Background image**: an absolute path to a PNG, JPEG, or WebP file. **Fit** selects cover, contain, or tile. **Overlay opacity** (0–100, default 60) places a light or dark layer over the image to keep text readable, matching the current palette.
|
|
56
|
+
|
|
57
|
+
**Choose…** opens the native file or folder dialog on macOS; on other platforms, enter the path manually. The plugin references the original files and does not copy them.
|
|
58
|
+
|
|
59
|
+
## Configuration
|
|
60
|
+
|
|
61
|
+
Settings are stored in the profile's `cordis.patch.yml` under the plugin entry. Editing the file updates an open settings page, and changes made on the page are written back:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
- id: dsh-appearance-plus
|
|
65
|
+
name: "@vamdawn/dsh-appearance-plus"
|
|
66
|
+
config:
|
|
67
|
+
uiFont: LXGW WenKai # empty uses the host default
|
|
68
|
+
codeFont: JetBrains Mono
|
|
69
|
+
fontDir: /Users/<user>/Fonts # optional
|
|
70
|
+
backgroundImage: /Users/<user>/Pictures/background.jpg
|
|
71
|
+
backgroundFit: cover # cover | contain | tile
|
|
72
|
+
overlayOpacity: 60 # integer 0-100
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The Host validates every value: an out-of-range opacity or an unknown fit is rejected rather than applied.
|
|
76
|
+
|
|
77
|
+
## Limitations
|
|
78
|
+
|
|
79
|
+
- Extra-folder fonts and background images load through the host's authenticated `GET /api/file` route, which allows 20 MiB per file; larger files fail with a localized error. Installed system fonts load by name and are not affected.
|
|
80
|
+
- The background references the original image. Moving or deleting it shows an error on the settings page while the last working background stays in place until reload.
|
|
81
|
+
- To show the image, the plugin makes the base window surface transparent and the sidebar translucent. Panels that paint their own opaque fill keep it.
|
|
82
|
+
- Paths refer to the machine running the DSH Host. Non-loopback Web pages are not supported and may not persist settings, as with the host's language and theme preferences.
|
|
83
|
+
- The native file and folder dialog is implemented for macOS only.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
cd plugins/dsh-appearance-plus
|
|
89
|
+
npm ci --ignore-scripts
|
|
90
|
+
npm run typecheck
|
|
91
|
+
npm test
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Tests cover family-name selection, font and collection parsing, folder scans, route input validation, schema defaults, applying and reverting fonts and backgrounds, error handling that keeps the last working values, the picker request, and unload cleanup.
|
|
95
|
+
|
|
96
|
+
Sources: `src/index.ts` settings schema and authenticated routes, `src/fonts.ts` folder scans and font metadata, `src/picker.ts` native dialog, `src/client.tsx` settings page and theme overrides, `src/locales.ts` the bilingual dictionaries, `build.mjs` the esbuild bundle.
|
|
97
|
+
|
|
98
|
+
## Links
|
|
99
|
+
|
|
100
|
+
- [CHANGELOG.md](CHANGELOG.md) — release notes.
|
|
101
|
+
- [LICENSE](LICENSE) — MIT.
|
|
102
|
+
- [Repository release rules](https://github.com/Vamdawn/ai-forge/blob/main/docs/versioning-and-release.md) — how versions, tags, and npm publication are handled.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @vamdawn/dsh-appearance-plus
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@vamdawn/dsh-appearance-plus)
|
|
6
|
+
|
|
7
|
+
定制 DeepSeek Harness 的界面字体、代码字体与窗口背景图片。插件在官方设置面板中新增 **外观+** 页面(英文界面显示为 **Appearance Plus**),并把改动叠加在当前主题之上,因此内置的 Light、Dark 和 System 配色仍可正常使用。
|
|
8
|
+
|
|
9
|
+
已在 DSH `0.2.0-rc.2` 上验证。它支持回环地址页面上的 Web UI,以及使用该 Web UI 的 Desktop 应用;TUI 没有设置面板。界面文案以官方中文(`zh`)和英文(`en`)两种语言提供。
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
### 从 npm 安装
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
dsh plugin --profile desktop add @vamdawn/dsh-appearance-plus
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
若使用 Web 的 `profile`,请改用 `--profile web`。包内已包含编译后的 JavaScript,使用方无需构建;它面向 Node.js 24 或更高版本,以及 `peerDependencies` 中声明的 DSH 版本。
|
|
20
|
+
|
|
21
|
+
### 从源码检出安装
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
cd plugins/dsh-appearance-plus
|
|
25
|
+
npm ci --ignore-scripts
|
|
26
|
+
npm run typecheck
|
|
27
|
+
npm run build
|
|
28
|
+
cd ../..
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
然后把该目录安装到当前启用的 `profile` 中(通常是 `desktop` 或 `web`):
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
dsh plugin --profile <profile> add "$PWD/plugins/dsh-appearance-plus"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
安装会链接本地目录,因此请保留该目录及其 `dist/` 产物,并在修改源文件后重新构建。刷新 **Plugins**(插件)页面,确认 `@vamdawn/dsh-appearance-plus` 已启用;如果应用尚未加载该插件,请重启应用。如果 macOS Desktop CLI 不在 PATH 中,请使用:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
"/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
卸载:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
dsh plugin --profile <profile> remove @vamdawn/dsh-appearance-plus
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 用法
|
|
50
|
+
|
|
51
|
+
在侧边栏底部打开 **Settings**(设置),然后在左侧导航中选择 **外观+**。改动立即生效,无需重新加载。
|
|
52
|
+
|
|
53
|
+
- **界面字体**和**代码字体**:字段中显示已选中的字体族。点击可列出全部字体族,输入即可按名称筛选,用鼠标或方向键加回车选择。列表顶部的**默认**可恢复 Host 默认值。所选字体族排在最前,其后是 Host 内置的字体栈作为回退。
|
|
54
|
+
- **额外字体目录**:可再添加一个目录,其中的字体会出现在搜索结果中,并标记为*额外目录*。支持的文件为 `.ttf`、`.otf`、`.ttc`、`.woff` 和 `.woff2`,子目录也会包含在内。**重新扫描**可发现新安装的字体。
|
|
55
|
+
- **背景图片**:PNG、JPEG 或 WebP 文件的绝对路径。**填充方式**可选择铺满、适应或平铺。**遮罩不透明度**(0–100,默认 60)会在图片上叠加浅色或深色遮罩,以保持文字可读,并与当前配色保持一致。
|
|
56
|
+
|
|
57
|
+
**选择…**在 macOS 上会打开系统原生文件或文件夹对话框;在其他平台上请手动输入路径。插件引用原始文件,不会复制它们。
|
|
58
|
+
|
|
59
|
+
## 配置
|
|
60
|
+
|
|
61
|
+
设置保存在 `profile` 的 `cordis.patch.yml` 中对应的插件条目下。编辑该文件会更新已打开的设置页,而设置页上的改动也会写回文件:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
- id: dsh-appearance-plus
|
|
65
|
+
name: "@vamdawn/dsh-appearance-plus"
|
|
66
|
+
config:
|
|
67
|
+
uiFont: LXGW WenKai # 留空则使用 Host 默认值
|
|
68
|
+
codeFont: JetBrains Mono
|
|
69
|
+
fontDir: /Users/<user>/Fonts # 可选
|
|
70
|
+
backgroundImage: /Users/<user>/Pictures/background.jpg
|
|
71
|
+
backgroundFit: cover # 取值:cover | contain | tile
|
|
72
|
+
overlayOpacity: 60 # 整数 0-100
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Host 会校验每个值:超出范围的不透明度或未知的填充方式会被拒绝,而不会生效。
|
|
76
|
+
|
|
77
|
+
## 限制
|
|
78
|
+
|
|
79
|
+
- 额外目录中的字体与背景图片通过 Host 已鉴权的 `GET /api/file` 路由加载,单个文件上限为 20 MiB;更大的文件会失败并显示当前语言的错误提示。已安装的系统字体按名称加载,不受影响。
|
|
80
|
+
- 背景引用的是原始图片。移动或删除该图片会在设置页显示错误,而最近一次可用的背景会保持不变,直到重新加载。
|
|
81
|
+
- 为了显示图片,插件会把基础窗口表面设为透明,并把侧边栏设为半透明。自行绘制不透明填充的面板仍保持原样。
|
|
82
|
+
- 路径指向运行 DSH Host 的机器。非回环地址的 Web 页面不受支持,也可能无法持久化设置,Host 的语言和主题偏好也是如此。
|
|
83
|
+
- 系统原生文件与文件夹对话框仅针对 macOS 实现。
|
|
84
|
+
|
|
85
|
+
## 开发
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
cd plugins/dsh-appearance-plus
|
|
89
|
+
npm ci --ignore-scripts
|
|
90
|
+
npm run typecheck
|
|
91
|
+
npm test
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
测试覆盖字体族名称选择、字体与字体集合解析、目录扫描、路由输入校验、schema 默认值、字体与背景的应用与还原、保留最近一次可用值的错误处理、选择窗口请求,以及卸载清理。
|
|
95
|
+
|
|
96
|
+
源码:`src/index.ts` 设置 schema 与已鉴权路由,`src/fonts.ts` 目录扫描与字体元数据,`src/picker.ts` 系统原生对话框,`src/client.tsx` 设置页与主题覆盖,`src/locales.ts` 双语语言词条,`build.mjs` esbuild 打包。
|
|
97
|
+
|
|
98
|
+
## 链接
|
|
99
|
+
|
|
100
|
+
- [CHANGELOG.zh-CN.md](CHANGELOG.zh-CN.md) — 发布说明。
|
|
101
|
+
- [LICENSE](LICENSE) — MIT。
|
|
102
|
+
- [仓库发布规则](https://github.com/Vamdawn/ai-forge/blob/main/docs/versioning-and-release.md) — 版本、标签与 npm 发布的管理方式。
|
package/cordis.patch.yml
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({ id: "@vamdawn/dsh-appearance-plus", factory: (require) => {
|
|
2
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
3
|
+
"use strict";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/client.tsx
|
|
23
|
+
var client_exports = {};
|
|
24
|
+
__export(client_exports, {
|
|
25
|
+
apply: () => apply,
|
|
26
|
+
inject: () => inject,
|
|
27
|
+
name: () => name
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(client_exports);
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_dsh_client_store = require("@deepseek-ai/dsh-client-store");
|
|
32
|
+
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
33
|
+
|
|
34
|
+
// src/locales.ts
|
|
35
|
+
var DICTIONARIES = {
|
|
36
|
+
zh: {
|
|
37
|
+
nav: "\u5916\u89C2+",
|
|
38
|
+
uiFont: "\u754C\u9762\u5B57\u4F53",
|
|
39
|
+
codeFont: "\u4EE3\u7801\u5B57\u4F53",
|
|
40
|
+
fontDefault: "\u9ED8\u8BA4",
|
|
41
|
+
search: "\u641C\u7D22\u5B57\u4F53",
|
|
42
|
+
fontsLoading: "\u6B63\u5728\u626B\u63CF\u5B57\u4F53\u2026",
|
|
43
|
+
fontsEmpty: "\u6CA1\u6709\u5339\u914D\u7684\u5B57\u4F53\u3002",
|
|
44
|
+
fontsFailed: "\u65E0\u6CD5\u8BFB\u53D6\u5B57\u4F53\u5217\u8868\u3002",
|
|
45
|
+
fontsMore: "\u4EC5\u663E\u793A\u524D 200 \u4E2A\u7ED3\u679C\uFF0C\u8F93\u5165\u66F4\u591A\u5B57\u7B26\u4EE5\u7F29\u5C0F\u8303\u56F4\u3002",
|
|
46
|
+
extraSource: "\u989D\u5916\u76EE\u5F55",
|
|
47
|
+
fontDir: "\u989D\u5916\u5B57\u4F53\u76EE\u5F55",
|
|
48
|
+
fontDirHint: "\u7CFB\u7EDF\u5DF2\u5B89\u88C5\u7684\u5B57\u4F53\u4F1A\u81EA\u52A8\u5217\u51FA\uFF1B\u8FD9\u91CC\u53EF\u4EE5\u518D\u6DFB\u52A0\u4E00\u4E2A\u76EE\u5F55\u3002",
|
|
49
|
+
rescan: "\u91CD\u65B0\u626B\u63CF",
|
|
50
|
+
backgroundImage: "\u80CC\u666F\u56FE\u7247",
|
|
51
|
+
backgroundHint: "\u652F\u6301 PNG\u3001JPEG\u3001WebP\uFF0C\u5355\u4E2A\u6587\u4EF6\u4E0D\u8D85\u8FC7 20 MiB\u3002",
|
|
52
|
+
choose: "\u9009\u62E9\u2026",
|
|
53
|
+
clear: "\u6E05\u9664",
|
|
54
|
+
pathPlaceholder: "\u7EDD\u5BF9\u8DEF\u5F84",
|
|
55
|
+
fit: "\u586B\u5145\u65B9\u5F0F",
|
|
56
|
+
"fit.cover": "\u94FA\u6EE1",
|
|
57
|
+
"fit.contain": "\u9002\u5E94",
|
|
58
|
+
"fit.tile": "\u5E73\u94FA",
|
|
59
|
+
overlay: "\u906E\u7F69\u4E0D\u900F\u660E\u5EA6",
|
|
60
|
+
"error.invalid-request": "\u8BF7\u6C42\u65E0\u6548\u3002",
|
|
61
|
+
"error.busy": "\u5DF2\u6709\u4E00\u4E2A\u9009\u62E9\u7A97\u53E3\u6253\u5F00\u3002",
|
|
62
|
+
"error.unsupported-platform": "\u5F53\u524D\u7CFB\u7EDF\u4E0D\u652F\u6301\u9009\u62E9\u7A97\u53E3\uFF0C\u8BF7\u624B\u52A8\u586B\u5199\u8DEF\u5F84\u3002",
|
|
63
|
+
"error.picker-failed": "\u65E0\u6CD5\u6253\u5F00\u9009\u62E9\u7A97\u53E3\uFF0C\u8BF7\u624B\u52A8\u586B\u5199\u8DEF\u5F84\u3002",
|
|
64
|
+
"error.failed": "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002",
|
|
65
|
+
"error.not-absolute": "\u8BF7\u586B\u5199\u7EDD\u5BF9\u8DEF\u5F84\u3002",
|
|
66
|
+
"error.unsupported-format": "\u4EC5\u652F\u6301 PNG\u3001JPEG\u3001WebP \u56FE\u7247\u3002",
|
|
67
|
+
"error.not-found": "\u6587\u4EF6\u4E0D\u5B58\u5728\u3002",
|
|
68
|
+
"error.too-large": "\u6587\u4EF6\u8D85\u8FC7 20 MiB \u4E0A\u9650\u3002",
|
|
69
|
+
"error.denied": "\u6CA1\u6709\u8BFB\u53D6\u8BE5\u6587\u4EF6\u7684\u6743\u9650\u3002",
|
|
70
|
+
"error.unavailable": "\u65E0\u6CD5\u8BFB\u53D6\u8BE5\u6587\u4EF6\u3002",
|
|
71
|
+
"error.font-load-failed": "\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25\u3002",
|
|
72
|
+
"error.save-failed": "\u8BBE\u7F6E\u672A\u4FDD\u5B58\uFF0C\u8BF7\u91CD\u8BD5\u3002"
|
|
73
|
+
},
|
|
74
|
+
en: {
|
|
75
|
+
nav: "Appearance Plus",
|
|
76
|
+
uiFont: "Interface font",
|
|
77
|
+
codeFont: "Code font",
|
|
78
|
+
fontDefault: "Default",
|
|
79
|
+
search: "Search fonts",
|
|
80
|
+
fontsLoading: "Scanning fonts\u2026",
|
|
81
|
+
fontsEmpty: "No matching fonts.",
|
|
82
|
+
fontsFailed: "Could not load the font list.",
|
|
83
|
+
fontsMore: "Showing the first 200 matches. Type more to narrow the list.",
|
|
84
|
+
extraSource: "extra folder",
|
|
85
|
+
fontDir: "Extra font folder",
|
|
86
|
+
fontDirHint: "Installed system fonts are listed automatically. Add one more folder here.",
|
|
87
|
+
rescan: "Rescan",
|
|
88
|
+
backgroundImage: "Background image",
|
|
89
|
+
backgroundHint: "PNG, JPEG, or WebP, up to 20 MiB.",
|
|
90
|
+
choose: "Choose\u2026",
|
|
91
|
+
clear: "Clear",
|
|
92
|
+
pathPlaceholder: "Absolute path",
|
|
93
|
+
fit: "Fit",
|
|
94
|
+
"fit.cover": "Cover",
|
|
95
|
+
"fit.contain": "Contain",
|
|
96
|
+
"fit.tile": "Tile",
|
|
97
|
+
overlay: "Overlay opacity",
|
|
98
|
+
"error.invalid-request": "Invalid request.",
|
|
99
|
+
"error.busy": "A picker window is already open.",
|
|
100
|
+
"error.unsupported-platform": "This system has no picker window. Enter the path manually.",
|
|
101
|
+
"error.picker-failed": "Could not open the picker window. Enter the path manually.",
|
|
102
|
+
"error.failed": "The operation failed. Please try again.",
|
|
103
|
+
"error.not-absolute": "Enter an absolute path.",
|
|
104
|
+
"error.unsupported-format": "Only PNG, JPEG, and WebP images are supported.",
|
|
105
|
+
"error.not-found": "The file does not exist.",
|
|
106
|
+
"error.too-large": "The file exceeds the 20 MiB limit.",
|
|
107
|
+
"error.denied": "Permission to read the file was denied.",
|
|
108
|
+
"error.unavailable": "The file could not be read.",
|
|
109
|
+
"error.font-load-failed": "The font could not be loaded.",
|
|
110
|
+
"error.save-failed": "The setting was not saved. Please try again."
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/client.tsx
|
|
115
|
+
var NS = "dshAppearancePlus";
|
|
116
|
+
var SOURCE = "dsh-appearance-plus";
|
|
117
|
+
var MAX_MATCHES = 200;
|
|
118
|
+
var COMMIT_DELAY_MS = 300;
|
|
119
|
+
var DEFAULTS = {
|
|
120
|
+
uiFont: "",
|
|
121
|
+
codeFont: "",
|
|
122
|
+
fontDir: "",
|
|
123
|
+
backgroundImage: "",
|
|
124
|
+
backgroundFit: "cover",
|
|
125
|
+
overlayOpacity: 60
|
|
126
|
+
};
|
|
127
|
+
var UI_FALLBACK = '-apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif';
|
|
128
|
+
var CODE_FALLBACK = '"SF Mono", "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", Menlo, Courier, "PingFang SC", "Microsoft YaHei"';
|
|
129
|
+
var FONT_FIELDS = [
|
|
130
|
+
["uiFont", "--dsw-font-family", UI_FALLBACK],
|
|
131
|
+
["codeFont", "--ds-font-family-code", CODE_FALLBACK]
|
|
132
|
+
];
|
|
133
|
+
var BACKGROUND_TOKENS = {
|
|
134
|
+
"--dsw-alias-bg-base": { light: "transparent", dark: "transparent" },
|
|
135
|
+
"--dsw-specific-sidebar-fill": { light: "rgb(249 250 251 / 0.5)", dark: "rgb(27 27 28 / 0.5)" }
|
|
136
|
+
};
|
|
137
|
+
var FIT = {
|
|
138
|
+
cover: "center / cover no-repeat fixed",
|
|
139
|
+
contain: "center / contain no-repeat fixed",
|
|
140
|
+
tile: "left top / auto repeat fixed"
|
|
141
|
+
};
|
|
142
|
+
var IMAGE_EXTENSION = /\.(png|jpe?g|webp)$/i;
|
|
143
|
+
var ABSOLUTE_PATH = /^(\/|[A-Za-z]:[\\/])/;
|
|
144
|
+
var FILE_STATUS = { 403: "denied", 404: "not-found", 413: "too-large" };
|
|
145
|
+
var PAGE_STYLE = { display: "flex", flexDirection: "column", gap: 24 };
|
|
146
|
+
var SECTION_STYLE = { display: "flex", flexDirection: "column", gap: 8 };
|
|
147
|
+
var ROW_STYLE = { display: "flex", alignItems: "center", gap: 8 };
|
|
148
|
+
var HEADING_STYLE = { margin: 0, font: "var(--dsw-font-s-strong-14)", color: "var(--dsw-alias-label-primary)" };
|
|
149
|
+
var HINT_STYLE = { margin: 0, font: "var(--dsw-font-xs-13)", color: "var(--dsw-alias-label-secondary)" };
|
|
150
|
+
var ERROR_STYLE = { ...HINT_STYLE, color: "var(--dsw-alias-state-error-primary)" };
|
|
151
|
+
var FIELD_STYLE = { position: "relative", display: "flex", flexDirection: "column" };
|
|
152
|
+
var POPUP_STYLE = {
|
|
153
|
+
position: "absolute",
|
|
154
|
+
top: "calc(100% + 4px)",
|
|
155
|
+
left: 0,
|
|
156
|
+
right: 0,
|
|
157
|
+
zIndex: 10,
|
|
158
|
+
maxHeight: 280,
|
|
159
|
+
overflowY: "auto",
|
|
160
|
+
padding: 4,
|
|
161
|
+
borderRadius: "var(--dsw-radius-lg)",
|
|
162
|
+
background: "var(--dsw-alias-bg-layer-1)",
|
|
163
|
+
boxShadow: "var(--dsw-elevation-panel)"
|
|
164
|
+
};
|
|
165
|
+
var OPTION_STYLE = {
|
|
166
|
+
display: "flex",
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
gap: 8,
|
|
169
|
+
padding: "6px 8px",
|
|
170
|
+
borderRadius: "var(--dsw-radius-sm)",
|
|
171
|
+
cursor: "pointer",
|
|
172
|
+
font: "var(--dsw-font-s-14)",
|
|
173
|
+
color: "var(--dsw-alias-label-primary)"
|
|
174
|
+
};
|
|
175
|
+
var TAG_STYLE = { marginLeft: "auto", font: "var(--dsw-font-xs-13)", color: "var(--dsw-alias-label-secondary)" };
|
|
176
|
+
var STATUS_STYLE = { ...HINT_STYLE, padding: "6px 8px" };
|
|
177
|
+
function fileUrl(path) {
|
|
178
|
+
return `api/file?path=${encodeURIComponent(path)}`;
|
|
179
|
+
}
|
|
180
|
+
function cssString(value) {
|
|
181
|
+
return `"${value.replace(/\p{Cc}/gu, "").replace(/["\\]/g, "\\$&")}"`;
|
|
182
|
+
}
|
|
183
|
+
function both(value) {
|
|
184
|
+
return { light: value, dark: value };
|
|
185
|
+
}
|
|
186
|
+
function errorKey(code) {
|
|
187
|
+
const key = code.replace(/^dsh-appearance-plus\//, "error.");
|
|
188
|
+
return key.startsWith("error.") && Object.hasOwn(DICTIONARIES.en, key) ? key : "error.failed";
|
|
189
|
+
}
|
|
190
|
+
function backgroundCss(path, fit, opacity) {
|
|
191
|
+
const image = `url("${fileUrl(path)}") ${FIT[fit]}`;
|
|
192
|
+
const layer = (rgb, base) => {
|
|
193
|
+
const overlay = `rgb(${rgb} / ${opacity / 100})`;
|
|
194
|
+
return `background:linear-gradient(${overlay},${overlay}),${image},${base}`;
|
|
195
|
+
};
|
|
196
|
+
return `html:root body{${layer("255 255 255", "#fff")}}html:root body[data-ds-dark-theme]{${layer("21 21 23", "#151517")}}`;
|
|
197
|
+
}
|
|
198
|
+
function FontField({ id, label, value, catalog, onChange, t }) {
|
|
199
|
+
const [query, setQuery] = (0, import_react.useState)(null);
|
|
200
|
+
const [active, setActive] = (0, import_react.useState)(0);
|
|
201
|
+
const open = query !== null;
|
|
202
|
+
const needle = (query ?? "").trim().toLowerCase();
|
|
203
|
+
const matches = (0, import_react.useMemo)(() => catalog.fonts.filter((font) => font.family.toLowerCase().includes(needle)), [catalog.fonts, needle]);
|
|
204
|
+
const options = (0, import_react.useMemo)(() => [...needle ? [] : [null], ...matches.slice(0, MAX_MATCHES)], [needle, matches]);
|
|
205
|
+
const current = Math.min(active, options.length - 1);
|
|
206
|
+
const listId = `${id}-list`;
|
|
207
|
+
const optionId = (index) => `${id}-option-${index}`;
|
|
208
|
+
(0, import_react.useEffect)(() => {
|
|
209
|
+
if (open && current >= 0) {
|
|
210
|
+
document.getElementById(optionId(current))?.scrollIntoView({ block: "nearest" });
|
|
211
|
+
}
|
|
212
|
+
}, [open, current]);
|
|
213
|
+
const show = () => {
|
|
214
|
+
setActive(Math.max(0, options.findIndex((font) => (font?.family ?? "") === value)));
|
|
215
|
+
setQuery("");
|
|
216
|
+
};
|
|
217
|
+
const choose = (font) => {
|
|
218
|
+
setQuery(null);
|
|
219
|
+
if ((font?.family ?? "") !== value) {
|
|
220
|
+
onChange(font?.family ?? "");
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
let status;
|
|
224
|
+
if (catalog.status === "failed") {
|
|
225
|
+
status = "fontsFailed";
|
|
226
|
+
} else if (catalog.status !== "ready") {
|
|
227
|
+
status = "fontsLoading";
|
|
228
|
+
} else if (matches.length === 0) {
|
|
229
|
+
status = "fontsEmpty";
|
|
230
|
+
} else if (matches.length > MAX_MATCHES) {
|
|
231
|
+
status = "fontsMore";
|
|
232
|
+
}
|
|
233
|
+
return /* @__PURE__ */ (0, import_react.createElement)("section", { style: SECTION_STYLE }, /* @__PURE__ */ (0, import_react.createElement)("label", { htmlFor: id, style: HEADING_STYLE }, label), /* @__PURE__ */ (0, import_react.createElement)("div", { style: FIELD_STYLE }, /* @__PURE__ */ (0, import_react.createElement)(
|
|
234
|
+
import_dsh_client_ui_primitives.Input,
|
|
235
|
+
{
|
|
236
|
+
id,
|
|
237
|
+
role: "combobox",
|
|
238
|
+
autoComplete: "off",
|
|
239
|
+
spellCheck: false,
|
|
240
|
+
"aria-expanded": open,
|
|
241
|
+
"aria-controls": listId,
|
|
242
|
+
"aria-autocomplete": "list",
|
|
243
|
+
"aria-activedescendant": open && current >= 0 ? optionId(current) : void 0,
|
|
244
|
+
value: query ?? value,
|
|
245
|
+
placeholder: open ? value || t("search") : t("fontDefault"),
|
|
246
|
+
style: !open && value ? { fontFamily: cssString(value) } : void 0,
|
|
247
|
+
onFocus: show,
|
|
248
|
+
onClick: () => {
|
|
249
|
+
if (!open) {
|
|
250
|
+
show();
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
onBlur: () => setQuery(null),
|
|
254
|
+
onChange: (event) => {
|
|
255
|
+
setQuery(event.target.value);
|
|
256
|
+
setActive(0);
|
|
257
|
+
},
|
|
258
|
+
onKeyDown: (event) => {
|
|
259
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
if (!open) {
|
|
262
|
+
show();
|
|
263
|
+
} else if (options.length > 0) {
|
|
264
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
265
|
+
setActive((current + step + options.length) % options.length);
|
|
266
|
+
}
|
|
267
|
+
} else if (event.key === "Enter" && open && current >= 0) {
|
|
268
|
+
event.preventDefault();
|
|
269
|
+
choose(options[current]);
|
|
270
|
+
} else if (event.key === "Escape" && open) {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
event.stopPropagation();
|
|
273
|
+
setQuery(null);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
), open ? (
|
|
278
|
+
// Keep focus in the input while the pointer selects or scrolls the list.
|
|
279
|
+
/* @__PURE__ */ (0, import_react.createElement)("div", { style: POPUP_STYLE, onMouseDown: (event) => event.preventDefault() }, /* @__PURE__ */ (0, import_react.createElement)("div", { id: listId, role: "listbox", "aria-label": label }, options.map((font, index) => {
|
|
280
|
+
const family = font?.family ?? "";
|
|
281
|
+
const tags = [font?.source === "extra" ? t("extraSource") : "", family === value ? "\u2713" : ""];
|
|
282
|
+
return /* @__PURE__ */ (0, import_react.createElement)(
|
|
283
|
+
"div",
|
|
284
|
+
{
|
|
285
|
+
key: family,
|
|
286
|
+
id: optionId(index),
|
|
287
|
+
role: "option",
|
|
288
|
+
"aria-selected": family === value,
|
|
289
|
+
style: {
|
|
290
|
+
...OPTION_STYLE,
|
|
291
|
+
background: index === current ? "var(--dsw-alias-interactive-bg-hover)" : void 0,
|
|
292
|
+
fontFamily: font ? cssString(family) : void 0
|
|
293
|
+
},
|
|
294
|
+
onMouseEnter: () => setActive(index),
|
|
295
|
+
onClick: () => choose(font)
|
|
296
|
+
},
|
|
297
|
+
font ? family : t("fontDefault"),
|
|
298
|
+
/* @__PURE__ */ (0, import_react.createElement)("span", { style: TAG_STYLE }, tags.filter(Boolean).join(" "))
|
|
299
|
+
);
|
|
300
|
+
})), status ? /* @__PURE__ */ (0, import_react.createElement)("p", { role: "status", style: STATUS_STYLE }, t(status)) : null)
|
|
301
|
+
) : null));
|
|
302
|
+
}
|
|
303
|
+
function PathField({ id, label, hint, value, onCommit, onPick, children, t }) {
|
|
304
|
+
const [draft, setDraft] = (0, import_react.useState)(value);
|
|
305
|
+
const commit = () => {
|
|
306
|
+
if (draft.trim() !== value) {
|
|
307
|
+
onCommit(draft.trim());
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
return /* @__PURE__ */ (0, import_react.createElement)("section", { style: SECTION_STYLE }, /* @__PURE__ */ (0, import_react.createElement)("label", { htmlFor: id, style: HEADING_STYLE }, label), /* @__PURE__ */ (0, import_react.createElement)("p", { style: HINT_STYLE }, hint), /* @__PURE__ */ (0, import_react.createElement)("div", { style: ROW_STYLE }, /* @__PURE__ */ (0, import_react.createElement)(
|
|
311
|
+
import_dsh_client_ui_primitives.Input,
|
|
312
|
+
{
|
|
313
|
+
id,
|
|
314
|
+
value: draft,
|
|
315
|
+
placeholder: t("pathPlaceholder"),
|
|
316
|
+
onBlur: commit,
|
|
317
|
+
onChange: (event) => setDraft(event.target.value),
|
|
318
|
+
onKeyDown: (event) => {
|
|
319
|
+
if (event.key === "Enter") {
|
|
320
|
+
commit();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
), /* @__PURE__ */ (0, import_react.createElement)(import_dsh_client_ui_primitives.Button, { variant: "outline", size: "sm", onClick: onPick }, t("choose")), value ? /* @__PURE__ */ (0, import_react.createElement)(import_dsh_client_ui_primitives.Button, { variant: "ghost", size: "sm", onClick: () => onCommit("") }, t("clear")) : null, children));
|
|
325
|
+
}
|
|
326
|
+
function OverlayField({ value, disabled, onCommit, t }) {
|
|
327
|
+
const [draft, setDraft] = (0, import_react.useState)(value);
|
|
328
|
+
(0, import_react.useEffect)(() => {
|
|
329
|
+
setDraft(value);
|
|
330
|
+
}, [value]);
|
|
331
|
+
(0, import_react.useEffect)(() => {
|
|
332
|
+
if (draft === value) {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
const timer = setTimeout(() => onCommit(draft), COMMIT_DELAY_MS);
|
|
336
|
+
return () => clearTimeout(timer);
|
|
337
|
+
}, [draft]);
|
|
338
|
+
return /* @__PURE__ */ (0, import_react.createElement)("section", { style: SECTION_STYLE }, /* @__PURE__ */ (0, import_react.createElement)("label", { htmlFor: "dsh-appearance-plus-overlay", style: HEADING_STYLE }, t("overlay")), /* @__PURE__ */ (0, import_react.createElement)("div", { style: ROW_STYLE }, /* @__PURE__ */ (0, import_react.createElement)(
|
|
339
|
+
"input",
|
|
340
|
+
{
|
|
341
|
+
id: "dsh-appearance-plus-overlay",
|
|
342
|
+
type: "range",
|
|
343
|
+
min: 0,
|
|
344
|
+
max: 100,
|
|
345
|
+
step: 1,
|
|
346
|
+
value: draft,
|
|
347
|
+
disabled,
|
|
348
|
+
onChange: (event) => setDraft(Number(event.target.value))
|
|
349
|
+
}
|
|
350
|
+
), /* @__PURE__ */ (0, import_react.createElement)("output", { htmlFor: "dsh-appearance-plus-overlay" }, `${draft}%`)));
|
|
351
|
+
}
|
|
352
|
+
function AppearancePage({ useForm, useApplyIssues, useActionIssues, useCatalog, save, pick, loadCatalog, t }) {
|
|
353
|
+
const settings = { ...DEFAULTS, ...useForm((snapshot) => snapshot.value) };
|
|
354
|
+
const applied = useApplyIssues((value) => value);
|
|
355
|
+
const action = useActionIssues((value) => value);
|
|
356
|
+
const catalog = useCatalog((value) => value);
|
|
357
|
+
(0, import_react.useEffect)(() => {
|
|
358
|
+
loadCatalog(false);
|
|
359
|
+
}, [settings.fontDir]);
|
|
360
|
+
const issue = (field) => {
|
|
361
|
+
const key = action[field] ?? applied[field];
|
|
362
|
+
return key ? /* @__PURE__ */ (0, import_react.createElement)("p", { role: "alert", style: ERROR_STYLE }, t(key)) : null;
|
|
363
|
+
};
|
|
364
|
+
const noImage = !settings.backgroundImage;
|
|
365
|
+
return /* @__PURE__ */ (0, import_react.createElement)("div", { style: PAGE_STYLE }, issue("save"), /* @__PURE__ */ (0, import_react.createElement)(
|
|
366
|
+
FontField,
|
|
367
|
+
{
|
|
368
|
+
id: "dsh-appearance-plus-ui-font",
|
|
369
|
+
label: t("uiFont"),
|
|
370
|
+
value: settings.uiFont,
|
|
371
|
+
catalog,
|
|
372
|
+
t,
|
|
373
|
+
onChange: (family) => save("uiFont", family)
|
|
374
|
+
}
|
|
375
|
+
), issue("uiFont"), /* @__PURE__ */ (0, import_react.createElement)(
|
|
376
|
+
FontField,
|
|
377
|
+
{
|
|
378
|
+
id: "dsh-appearance-plus-code-font",
|
|
379
|
+
label: t("codeFont"),
|
|
380
|
+
value: settings.codeFont,
|
|
381
|
+
catalog,
|
|
382
|
+
t,
|
|
383
|
+
onChange: (family) => save("codeFont", family)
|
|
384
|
+
}
|
|
385
|
+
), issue("codeFont"), /* @__PURE__ */ (0, import_react.createElement)(
|
|
386
|
+
PathField,
|
|
387
|
+
{
|
|
388
|
+
key: `dir:${settings.fontDir}`,
|
|
389
|
+
id: "dsh-appearance-plus-font-dir",
|
|
390
|
+
label: t("fontDir"),
|
|
391
|
+
hint: t("fontDirHint"),
|
|
392
|
+
value: settings.fontDir,
|
|
393
|
+
t,
|
|
394
|
+
onCommit: (path) => save("fontDir", path),
|
|
395
|
+
onPick: () => pick("directory", "fontDir")
|
|
396
|
+
},
|
|
397
|
+
/* @__PURE__ */ (0, import_react.createElement)(import_dsh_client_ui_primitives.Button, { variant: "ghost", size: "sm", onClick: () => loadCatalog(true) }, t("rescan"))
|
|
398
|
+
), issue("fontDir"), /* @__PURE__ */ (0, import_react.createElement)(
|
|
399
|
+
PathField,
|
|
400
|
+
{
|
|
401
|
+
key: `image:${settings.backgroundImage}`,
|
|
402
|
+
id: "dsh-appearance-plus-background",
|
|
403
|
+
label: t("backgroundImage"),
|
|
404
|
+
hint: t("backgroundHint"),
|
|
405
|
+
value: settings.backgroundImage,
|
|
406
|
+
t,
|
|
407
|
+
onCommit: (path) => save("backgroundImage", path),
|
|
408
|
+
onPick: () => pick("image", "backgroundImage")
|
|
409
|
+
}
|
|
410
|
+
), issue("backgroundImage"), /* @__PURE__ */ (0, import_react.createElement)(
|
|
411
|
+
import_dsh_client_ui_primitives.SegmentedControl,
|
|
412
|
+
{
|
|
413
|
+
id: "dsh-appearance-plus-fit",
|
|
414
|
+
label: t("fit"),
|
|
415
|
+
value: settings.backgroundFit,
|
|
416
|
+
disabled: noImage,
|
|
417
|
+
options: ["cover", "contain", "tile"].map((fit) => ({ value: fit, label: t(`fit.${fit}`) })),
|
|
418
|
+
onChange: (fit) => save("backgroundFit", fit)
|
|
419
|
+
}
|
|
420
|
+
), /* @__PURE__ */ (0, import_react.createElement)(
|
|
421
|
+
OverlayField,
|
|
422
|
+
{
|
|
423
|
+
value: settings.overlayOpacity,
|
|
424
|
+
disabled: noImage,
|
|
425
|
+
t,
|
|
426
|
+
onCommit: (opacity) => save("overlayOpacity", opacity)
|
|
427
|
+
}
|
|
428
|
+
));
|
|
429
|
+
}
|
|
430
|
+
var name = "dsh-appearance-plus-client";
|
|
431
|
+
var inject = ["slots", "locale", "theme", "configForms"];
|
|
432
|
+
function apply(ctx) {
|
|
433
|
+
const form = ctx.configForms.get("dsh-appearance-plus");
|
|
434
|
+
const applyIssues = (0, import_dsh_client_store.createSnapshotStore)({});
|
|
435
|
+
const actionIssues = (0, import_dsh_client_store.createSnapshotStore)({});
|
|
436
|
+
const catalog = (0, import_dsh_client_store.createSnapshotStore)({ status: "idle", fonts: [] });
|
|
437
|
+
const catalogs = /* @__PURE__ */ new Map();
|
|
438
|
+
const lifetime = new AbortController();
|
|
439
|
+
const style = document.createElement("style");
|
|
440
|
+
let applied = { tokens: {}, css: "", faces: {} };
|
|
441
|
+
let removeLayer = () => {
|
|
442
|
+
};
|
|
443
|
+
let generation = 0;
|
|
444
|
+
let appliedKey;
|
|
445
|
+
let catalogRequest = 0;
|
|
446
|
+
const currentSettings = () => ({ ...DEFAULTS, ...form.getSnapshot().value });
|
|
447
|
+
const fontDir = (settings) => ABSOLUTE_PATH.test(settings.fontDir.trim()) ? settings.fontDir.trim() : "";
|
|
448
|
+
const fetchCatalog = (dir) => {
|
|
449
|
+
let pending = catalogs.get(dir);
|
|
450
|
+
if (!pending) {
|
|
451
|
+
const request = fetch(`api/dsh-appearance-plus/fonts?${new URLSearchParams(dir ? { dir } : {})}`, { signal: lifetime.signal }).then(async (response) => {
|
|
452
|
+
if (!response.ok) {
|
|
453
|
+
throw new Error(`HTTP ${response.status}`);
|
|
454
|
+
}
|
|
455
|
+
const result = await response.json();
|
|
456
|
+
if (!result.ok) {
|
|
457
|
+
throw new Error(result.error.code);
|
|
458
|
+
}
|
|
459
|
+
return result.value;
|
|
460
|
+
});
|
|
461
|
+
pending = request;
|
|
462
|
+
catalogs.set(dir, request);
|
|
463
|
+
request.catch(() => {
|
|
464
|
+
if (catalogs.get(dir) === request) {
|
|
465
|
+
catalogs.delete(dir);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return pending;
|
|
470
|
+
};
|
|
471
|
+
const loadCatalog = async (refresh2) => {
|
|
472
|
+
const request = ++catalogRequest;
|
|
473
|
+
const dir = fontDir(currentSettings());
|
|
474
|
+
if (refresh2) {
|
|
475
|
+
catalogs.clear();
|
|
476
|
+
await fetch("api/dsh-appearance-plus/fonts?refresh=", { signal: lifetime.signal }).catch(() => void 0);
|
|
477
|
+
}
|
|
478
|
+
catalog.set({ status: "loading", fonts: [] });
|
|
479
|
+
try {
|
|
480
|
+
const fonts = await fetchCatalog(dir);
|
|
481
|
+
if (request === catalogRequest) {
|
|
482
|
+
catalog.set({ status: "ready", fonts });
|
|
483
|
+
}
|
|
484
|
+
} catch {
|
|
485
|
+
if (request === catalogRequest && !lifetime.signal.aborted) {
|
|
486
|
+
catalog.set({ status: "failed", fonts: [] });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const loadFamily = async (family, dir) => {
|
|
491
|
+
const entry = dir ? (await fetchCatalog(dir)).find((font) => font.family === family) : void 0;
|
|
492
|
+
if (entry?.source !== "extra") {
|
|
493
|
+
return [];
|
|
494
|
+
}
|
|
495
|
+
return Promise.all(entry.files.map((file) => new FontFace(family, `url("${fileUrl(file.path)}")`, {
|
|
496
|
+
weight: String(file.weight),
|
|
497
|
+
style: file.italic ? "italic" : "normal"
|
|
498
|
+
}).load()));
|
|
499
|
+
};
|
|
500
|
+
const checkImage = async (path) => {
|
|
501
|
+
if (!ABSOLUTE_PATH.test(path)) {
|
|
502
|
+
return "not-absolute";
|
|
503
|
+
}
|
|
504
|
+
if (!IMAGE_EXTENSION.test(path)) {
|
|
505
|
+
return "unsupported-format";
|
|
506
|
+
}
|
|
507
|
+
try {
|
|
508
|
+
const response = await fetch(fileUrl(path), { method: "HEAD", signal: lifetime.signal });
|
|
509
|
+
return response.ok ? void 0 : FILE_STATUS[response.status] ?? "unavailable";
|
|
510
|
+
} catch {
|
|
511
|
+
return "unavailable";
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
const sync = async (settings) => {
|
|
515
|
+
const key = JSON.stringify(settings);
|
|
516
|
+
if (key === appliedKey) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
appliedKey = key;
|
|
520
|
+
const current = ++generation;
|
|
521
|
+
const issues = {};
|
|
522
|
+
const next = { tokens: {}, css: "", faces: {} };
|
|
523
|
+
const keep = (tokens) => {
|
|
524
|
+
for (const token of tokens) {
|
|
525
|
+
if (applied.tokens[token]) {
|
|
526
|
+
next.tokens[token] = applied.tokens[token];
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
const dir = fontDir(settings);
|
|
531
|
+
if (settings.fontDir.trim() && !dir) {
|
|
532
|
+
issues.fontDir = "error.not-absolute";
|
|
533
|
+
}
|
|
534
|
+
for (const [field, token, fallback] of FONT_FIELDS) {
|
|
535
|
+
const family = settings[field].trim();
|
|
536
|
+
if (!family) {
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
next.faces[field] = await loadFamily(family, dir);
|
|
541
|
+
next.tokens[token] = both(`${cssString(family)}, ${fallback}`);
|
|
542
|
+
} catch {
|
|
543
|
+
issues[field] = "error.font-load-failed";
|
|
544
|
+
next.faces[field] = applied.faces[field];
|
|
545
|
+
keep([token]);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const image = settings.backgroundImage.trim();
|
|
549
|
+
if (image) {
|
|
550
|
+
const reason = await checkImage(image);
|
|
551
|
+
if (reason) {
|
|
552
|
+
issues.backgroundImage = `error.${reason}`;
|
|
553
|
+
next.css = applied.css;
|
|
554
|
+
keep(Object.keys(BACKGROUND_TOKENS));
|
|
555
|
+
} else {
|
|
556
|
+
next.css = backgroundCss(image, settings.backgroundFit, settings.overlayOpacity);
|
|
557
|
+
Object.assign(next.tokens, BACKGROUND_TOKENS);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (current !== generation) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const previousFaces = Object.values(applied.faces).flat();
|
|
564
|
+
const nextFaces = Object.values(next.faces).flat();
|
|
565
|
+
for (const face of previousFaces.filter((face2) => !nextFaces.includes(face2))) {
|
|
566
|
+
document.fonts.delete(face);
|
|
567
|
+
}
|
|
568
|
+
for (const face of nextFaces.filter((face2) => !previousFaces.includes(face2))) {
|
|
569
|
+
document.fonts.add(face);
|
|
570
|
+
}
|
|
571
|
+
removeLayer = ctx.theme.overrideTokens(SOURCE, next.tokens);
|
|
572
|
+
style.textContent = next.css;
|
|
573
|
+
applied = next;
|
|
574
|
+
applyIssues.set(issues);
|
|
575
|
+
};
|
|
576
|
+
const refresh = () => {
|
|
577
|
+
if (form.getSnapshot().value !== void 0) {
|
|
578
|
+
void sync(currentSettings());
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
ctx.effect(() => {
|
|
582
|
+
document.head.append(style);
|
|
583
|
+
const unsubscribe = form.subscribe(refresh);
|
|
584
|
+
refresh();
|
|
585
|
+
return () => {
|
|
586
|
+
unsubscribe();
|
|
587
|
+
generation++;
|
|
588
|
+
lifetime.abort();
|
|
589
|
+
removeLayer();
|
|
590
|
+
style.remove();
|
|
591
|
+
for (const face of Object.values(applied.faces).flat()) {
|
|
592
|
+
document.fonts.delete(face);
|
|
593
|
+
}
|
|
594
|
+
applied = { tokens: {}, css: "", faces: {} };
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
ctx.effect(() => ctx.locale.register(NS, DICTIONARIES));
|
|
598
|
+
const save = (field, value) => {
|
|
599
|
+
actionIssues.set({});
|
|
600
|
+
form.set(field, value).then((accepted) => {
|
|
601
|
+
if (!accepted) {
|
|
602
|
+
actionIssues.set({ save: "error.save-failed" });
|
|
603
|
+
}
|
|
604
|
+
}, () => {
|
|
605
|
+
actionIssues.set({ save: "error.save-failed" });
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
const pick = async (kind, field) => {
|
|
609
|
+
actionIssues.set({});
|
|
610
|
+
try {
|
|
611
|
+
const response = await fetch("api/dsh-appearance-plus/pick", {
|
|
612
|
+
method: "POST",
|
|
613
|
+
headers: { "content-type": "application/json" },
|
|
614
|
+
body: JSON.stringify({ kind }),
|
|
615
|
+
signal: lifetime.signal
|
|
616
|
+
});
|
|
617
|
+
if (!response.ok) {
|
|
618
|
+
throw new Error(`HTTP ${response.status}`);
|
|
619
|
+
}
|
|
620
|
+
const result = await response.json();
|
|
621
|
+
if (!result.ok) {
|
|
622
|
+
actionIssues.set({ [field]: errorKey(result.error.code) });
|
|
623
|
+
} else if (result.value !== null) {
|
|
624
|
+
save(field, result.value);
|
|
625
|
+
}
|
|
626
|
+
} catch {
|
|
627
|
+
if (!lifetime.signal.aborted) {
|
|
628
|
+
actionIssues.set({ [field]: "error.failed" });
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
const t = ctx.locale.bind(NS);
|
|
633
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
634
|
+
name: "settings.section",
|
|
635
|
+
id: "dsh-appearance-plus",
|
|
636
|
+
order: 10,
|
|
637
|
+
label: () => t("nav"),
|
|
638
|
+
locale: NS,
|
|
639
|
+
inject: () => ({
|
|
640
|
+
hooks: { form, applyIssues, actionIssues, catalog },
|
|
641
|
+
save,
|
|
642
|
+
pick: (kind, field) => {
|
|
643
|
+
void pick(kind, field);
|
|
644
|
+
},
|
|
645
|
+
loadCatalog: (refreshCatalog) => {
|
|
646
|
+
void loadCatalog(refreshCatalog);
|
|
647
|
+
}
|
|
648
|
+
})
|
|
649
|
+
}, AppearancePage));
|
|
650
|
+
}
|
|
651
|
+
return module.exports;
|
|
652
|
+
} });
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { isAbsolute } from "node:path";
|
|
4
|
+
import z from "@deepseek-ai/schemastery";
|
|
5
|
+
|
|
6
|
+
// src/fonts.ts
|
|
7
|
+
import { open as openFontkit } from "fontkit";
|
|
8
|
+
import { open, readdir } from "node:fs/promises";
|
|
9
|
+
import { extname, join } from "node:path";
|
|
10
|
+
var EXTENSIONS = /* @__PURE__ */ new Set([".ttf", ".otf", ".ttc", ".woff", ".woff2"]);
|
|
11
|
+
var WINDOWS_ENGLISH = 1033;
|
|
12
|
+
function systemFontDirs(platform, home, env) {
|
|
13
|
+
switch (platform) {
|
|
14
|
+
case "darwin":
|
|
15
|
+
return ["/System/Library/Fonts", "/Library/Fonts", join(home, "Library/Fonts")];
|
|
16
|
+
case "win32":
|
|
17
|
+
return [
|
|
18
|
+
join(env.WINDIR ?? "C:\\Windows", "Fonts"),
|
|
19
|
+
...env.LOCALAPPDATA ? [join(env.LOCALAPPDATA, "Microsoft/Windows/Fonts")] : []
|
|
20
|
+
];
|
|
21
|
+
default:
|
|
22
|
+
return ["/usr/share/fonts", "/usr/local/share/fonts", join(home, ".local/share/fonts"), join(home, ".fonts")];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function parseFamily(table) {
|
|
26
|
+
const count = table.readUInt16BE(2);
|
|
27
|
+
const strings = table.readUInt16BE(4);
|
|
28
|
+
let best;
|
|
29
|
+
for (let index = 0; index < count && 6 + index * 12 + 12 <= table.length; index++) {
|
|
30
|
+
const at = 6 + index * 12;
|
|
31
|
+
const platform = table.readUInt16BE(at);
|
|
32
|
+
const language = table.readUInt16BE(at + 4);
|
|
33
|
+
const nameId = table.readUInt16BE(at + 6);
|
|
34
|
+
if (nameId !== 1 && nameId !== 16) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const start = strings + table.readUInt16BE(at + 10);
|
|
38
|
+
const raw = table.subarray(start, start + table.readUInt16BE(at + 8));
|
|
39
|
+
let languageRank;
|
|
40
|
+
let value;
|
|
41
|
+
if (platform === 3 || platform === 0) {
|
|
42
|
+
value = Buffer.from(raw.subarray(0, raw.length & ~1)).swap16().toString("utf16le");
|
|
43
|
+
languageRank = platform === 0 ? 2 : language === WINDOWS_ENGLISH ? 0 : 3;
|
|
44
|
+
} else if (platform === 1) {
|
|
45
|
+
value = raw.toString("latin1");
|
|
46
|
+
languageRank = language === 0 ? 1 : 3;
|
|
47
|
+
} else {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
value = value.trim();
|
|
51
|
+
const rank = languageRank * 2 + (nameId === 16 ? 0 : 1);
|
|
52
|
+
if (value && (!best || rank < best.rank)) {
|
|
53
|
+
best = { rank, value };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return best?.value;
|
|
57
|
+
}
|
|
58
|
+
async function readAt(file, offset, length) {
|
|
59
|
+
const buffer = Buffer.alloc(length);
|
|
60
|
+
const { bytesRead } = await file.read(buffer, 0, length, offset);
|
|
61
|
+
if (bytesRead < length) {
|
|
62
|
+
throw new Error("truncated font file");
|
|
63
|
+
}
|
|
64
|
+
return buffer;
|
|
65
|
+
}
|
|
66
|
+
async function readSfnt(file, offset) {
|
|
67
|
+
const count = (await readAt(file, offset, 12)).readUInt16BE(4);
|
|
68
|
+
const records = await readAt(file, offset + 12, count * 16);
|
|
69
|
+
const tables = /* @__PURE__ */ new Map();
|
|
70
|
+
for (let index = 0; index < count; index++) {
|
|
71
|
+
const at = index * 16;
|
|
72
|
+
tables.set(
|
|
73
|
+
records.toString("latin1", at, at + 4),
|
|
74
|
+
{ offset: records.readUInt32BE(at + 8), length: records.readUInt32BE(at + 12) }
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const name2 = tables.get("name");
|
|
78
|
+
const family = name2 && parseFamily(await readAt(file, name2.offset, name2.length));
|
|
79
|
+
if (!family) {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
const os2 = tables.get("OS/2");
|
|
83
|
+
if (!os2 || os2.length < 64) {
|
|
84
|
+
return { family, weight: 400, italic: false };
|
|
85
|
+
}
|
|
86
|
+
const metrics = await readAt(file, os2.offset, 64);
|
|
87
|
+
return { family, weight: metrics.readUInt16BE(4) || 400, italic: (metrics.readUInt16BE(62) & 1) !== 0 };
|
|
88
|
+
}
|
|
89
|
+
async function readFaces(path) {
|
|
90
|
+
const extension = extname(path).toLowerCase();
|
|
91
|
+
if (extension === ".woff" || extension === ".woff2") {
|
|
92
|
+
const font = await openFontkit(path);
|
|
93
|
+
return ("fonts" in font ? font.fonts : [font]).map((face) => ({
|
|
94
|
+
family: face.getName("preferredFamily", "en") ?? face.familyName,
|
|
95
|
+
weight: face["OS/2"]?.usWeightClass || 400,
|
|
96
|
+
italic: face.italicAngle !== 0
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
const file = await open(path);
|
|
100
|
+
try {
|
|
101
|
+
const header = await readAt(file, 0, 12);
|
|
102
|
+
if (header.toString("latin1", 0, 4) !== "ttcf") {
|
|
103
|
+
const face = await readSfnt(file, 0);
|
|
104
|
+
return face ? [face] : [];
|
|
105
|
+
}
|
|
106
|
+
const count = header.readUInt32BE(8);
|
|
107
|
+
const offsets = await readAt(file, 12, count * 4);
|
|
108
|
+
const faces = [];
|
|
109
|
+
for (let index = 0; index < count; index++) {
|
|
110
|
+
const face = await readSfnt(file, offsets.readUInt32BE(index * 4));
|
|
111
|
+
if (face) {
|
|
112
|
+
faces.push(face);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return faces;
|
|
116
|
+
} finally {
|
|
117
|
+
await file.close();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function scanFonts(dirs, source) {
|
|
121
|
+
const families = /* @__PURE__ */ new Map();
|
|
122
|
+
for (const dir of dirs) {
|
|
123
|
+
let entries;
|
|
124
|
+
try {
|
|
125
|
+
entries = await readdir(dir, { recursive: true, withFileTypes: true });
|
|
126
|
+
} catch {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
for (const entry of entries) {
|
|
130
|
+
if (!entry.isFile() || !EXTENSIONS.has(extname(entry.name).toLowerCase())) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const path = join(entry.parentPath, entry.name);
|
|
134
|
+
let faces;
|
|
135
|
+
try {
|
|
136
|
+
faces = await readFaces(path);
|
|
137
|
+
} catch {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
for (const face of faces) {
|
|
141
|
+
if (face.family.startsWith(".")) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
let family = families.get(face.family);
|
|
145
|
+
if (!family) {
|
|
146
|
+
family = { family: face.family, source, files: [] };
|
|
147
|
+
families.set(face.family, family);
|
|
148
|
+
}
|
|
149
|
+
if (source === "extra") {
|
|
150
|
+
family.files.push({ path, weight: face.weight, italic: face.italic });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return [...families.values()];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/picker.ts
|
|
159
|
+
import { execFile } from "node:child_process";
|
|
160
|
+
import { promisify } from "node:util";
|
|
161
|
+
var run = promisify(execFile);
|
|
162
|
+
var SCRIPTS = {
|
|
163
|
+
image: 'POSIX path of (choose file of type {"public.png", "public.jpeg", "org.webmproject.webp"})',
|
|
164
|
+
directory: "POSIX path of (choose folder)"
|
|
165
|
+
};
|
|
166
|
+
var AppearanceError = class extends Error {
|
|
167
|
+
code;
|
|
168
|
+
constructor(reason) {
|
|
169
|
+
super(reason);
|
|
170
|
+
this.code = `dsh-appearance-plus/${reason}`;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
async function pickPath(kind, signal, platform = process.platform) {
|
|
174
|
+
if (platform !== "darwin") {
|
|
175
|
+
throw new AppearanceError("unsupported-platform");
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const { stdout } = await run("osascript", ["-e", "activate", "-e", SCRIPTS[kind]], { signal });
|
|
179
|
+
return stdout.replace(/\n$/, "").replace(/(.)\/$/, "$1");
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (typeof error === "object" && error !== null && "stderr" in error && String(error.stderr).includes("(-128)")) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
throw new AppearanceError("picker-failed");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/index.ts
|
|
189
|
+
var name = "dsh-appearance-plus";
|
|
190
|
+
var inject = ["connection"];
|
|
191
|
+
var Config = z.object({
|
|
192
|
+
uiFont: z.string().default("").volatile(),
|
|
193
|
+
codeFont: z.string().default("").volatile(),
|
|
194
|
+
fontDir: z.string().default("").volatile(),
|
|
195
|
+
backgroundImage: z.string().default("").volatile(),
|
|
196
|
+
backgroundFit: z.union(["cover", "contain", "tile"]).default("cover").volatile(),
|
|
197
|
+
overlayOpacity: z.number().step(1).min(0).max(100).default(60).volatile()
|
|
198
|
+
});
|
|
199
|
+
async function respond(operation) {
|
|
200
|
+
let result;
|
|
201
|
+
try {
|
|
202
|
+
result = { ok: true, value: await operation() };
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const code = error instanceof AppearanceError ? error.code : "dsh-appearance-plus/failed";
|
|
205
|
+
result = { ok: false, error: { code, message: error instanceof Error ? error.message : code } };
|
|
206
|
+
}
|
|
207
|
+
return Response.json(result);
|
|
208
|
+
}
|
|
209
|
+
function apply(ctx) {
|
|
210
|
+
ctx.inject(["settings"], (child) => {
|
|
211
|
+
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
|
|
212
|
+
});
|
|
213
|
+
const lifetime = new AbortController();
|
|
214
|
+
ctx.effect(() => () => {
|
|
215
|
+
lifetime.abort();
|
|
216
|
+
});
|
|
217
|
+
let systemFonts;
|
|
218
|
+
const extraFonts = /* @__PURE__ */ new Map();
|
|
219
|
+
let picking = false;
|
|
220
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
221
|
+
path: "/api/dsh-appearance-plus/fonts",
|
|
222
|
+
methods: ["GET"],
|
|
223
|
+
requestBody: "buffered",
|
|
224
|
+
fetch: (request) => respond(async () => {
|
|
225
|
+
const params = new URL(request.url).searchParams;
|
|
226
|
+
const dir = params.get("dir") ?? "";
|
|
227
|
+
if (dir && !isAbsolute(dir)) {
|
|
228
|
+
throw new AppearanceError("invalid-request");
|
|
229
|
+
}
|
|
230
|
+
if (params.has("refresh")) {
|
|
231
|
+
systemFonts = void 0;
|
|
232
|
+
extraFonts.clear();
|
|
233
|
+
}
|
|
234
|
+
systemFonts ??= scanFonts(systemFontDirs(process.platform, homedir(), process.env), "system");
|
|
235
|
+
let extra = dir ? extraFonts.get(dir) : void 0;
|
|
236
|
+
if (dir && !extra) {
|
|
237
|
+
extra = scanFonts([dir], "extra");
|
|
238
|
+
extraFonts.set(dir, extra);
|
|
239
|
+
}
|
|
240
|
+
const system = await systemFonts;
|
|
241
|
+
const installed = new Set(system.map((font) => font.family));
|
|
242
|
+
return [...system, ...(await extra ?? []).filter((font) => !installed.has(font.family))].sort((a, b) => a.family.localeCompare(b.family));
|
|
243
|
+
})
|
|
244
|
+
}));
|
|
245
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
246
|
+
path: "/api/dsh-appearance-plus/pick",
|
|
247
|
+
methods: ["POST"],
|
|
248
|
+
requestBody: "buffered",
|
|
249
|
+
fetch: async (request) => {
|
|
250
|
+
const payload = await request.json().catch(() => void 0);
|
|
251
|
+
return respond(async () => {
|
|
252
|
+
if (typeof payload !== "object" || payload === null || !("kind" in payload) || payload.kind !== "image" && payload.kind !== "directory") {
|
|
253
|
+
throw new AppearanceError("invalid-request");
|
|
254
|
+
}
|
|
255
|
+
if (picking) {
|
|
256
|
+
throw new AppearanceError("busy");
|
|
257
|
+
}
|
|
258
|
+
picking = true;
|
|
259
|
+
try {
|
|
260
|
+
return await pickPath(payload.kind, AbortSignal.any([request.signal, lifetime.signal]));
|
|
261
|
+
} finally {
|
|
262
|
+
picking = false;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
export {
|
|
269
|
+
Config,
|
|
270
|
+
apply,
|
|
271
|
+
inject,
|
|
272
|
+
name
|
|
273
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vamdawn/dsh-appearance-plus",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Customize DeepSeek Harness interface fonts, code fonts, and background image",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Vamdawn/ai-forge.git",
|
|
8
|
+
"directory": "plugins/dsh-appearance-plus"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/Vamdawn/ai-forge/tree/main/plugins/dsh-appearance-plus#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Vamdawn/ai-forge/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"deepseek-harness",
|
|
16
|
+
"dsh",
|
|
17
|
+
"plugin",
|
|
18
|
+
"font",
|
|
19
|
+
"background",
|
|
20
|
+
"appearance"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=24"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org/",
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "dist/index.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./dist/index.js",
|
|
33
|
+
"./client": "./dist/client.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"cordis.patch.yml",
|
|
39
|
+
"README.md",
|
|
40
|
+
"README.zh-CN.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"CHANGELOG.zh-CN.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typecheck": "tsc -p tsconfig.host.json && tsc -p tsconfig.client.json && tsc -p tsconfig.tests.json",
|
|
47
|
+
"build": "node build.mjs",
|
|
48
|
+
"pretest": "npm run build",
|
|
49
|
+
"test": "node --test tests/*.test.ts",
|
|
50
|
+
"prepublishOnly": "npm test",
|
|
51
|
+
"prepare": "npm run build",
|
|
52
|
+
"prepack": "npm run typecheck"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@deepseek-ai/schemastery": "3.18.4",
|
|
56
|
+
"fontkit": "2.0.4"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.0-rc.2 <0.3.0",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-theme": ">=0.2.0-rc.2 <0.3.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@deepseek-ai/cordis": "4.0.4",
|
|
64
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.0-rc.2",
|
|
65
|
+
"@deepseek-ai/dsh-client-connection": "0.2.0-rc.2",
|
|
66
|
+
"@deepseek-ai/dsh-client-locale": "0.2.0-rc.2",
|
|
67
|
+
"@deepseek-ai/dsh-client-store": "0.2.0-rc.2",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.0-rc.2",
|
|
69
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.2",
|
|
70
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.2",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.2",
|
|
72
|
+
"@deepseek-ai/dsh-client-ui-theme": "0.2.0-rc.2",
|
|
73
|
+
"@deepseek-ai/dsh-settings": "0.2.0-rc.2",
|
|
74
|
+
"@types/fontkit": "2.0.9",
|
|
75
|
+
"@types/node": "24.19.2",
|
|
76
|
+
"@types/react": "18.3.31",
|
|
77
|
+
"esbuild": "0.28.2",
|
|
78
|
+
"typescript": "7.0.2"
|
|
79
|
+
},
|
|
80
|
+
"dsh": {
|
|
81
|
+
"bundle": {
|
|
82
|
+
"patch": "./cordis.patch.yml"
|
|
83
|
+
},
|
|
84
|
+
"client": {
|
|
85
|
+
"platform": "web",
|
|
86
|
+
"inject": [
|
|
87
|
+
"@deepseek-ai/dsh-client-connection",
|
|
88
|
+
"@deepseek-ai/dsh-client-locale",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-renderer",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-theme",
|
|
92
|
+
"@deepseek-ai/dsh-api-remotes"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"license": "MIT"
|
|
97
|
+
}
|