feat(plugin): enhance font management in plugins by introducing host CSS variables for typography; update examples and documentation for consistent font usage across plugin interfaces

This commit is contained in:
Kang committed 2026-10-03 19:24:54 +08:00
1 parent 2b123a67a3
commit ac014d9667
8 files changed
+37 -6

No files matched your search

+12
View File
@@ -25,6 +25,18 @@ Rust 模板还包含编译脚本,编译后自动填入当前平台的可执行
将生成的 `.nyap` 安装到插件面板,检查权限并启用。UI 模板需先选中已连接终端;
Rust 模板可以打开界面点击运行,也可以直接执行插件卡片上的原生命令。
## 页面字体
宿主会将应用的界面字体栈通过 `NyaTerm.context.theme` 中的 `--font-sans`、
`--font-display` 同步到插件页面;修改设置时,已打开的页面也会收到更新,无需重载。
`--font-mono` 提供宿主的默认等宽字体栈。SDK 默认使用界面字体,表单控件继承字体;
插件自定义 CSS 应使用 `font-family: var(--font-sans, system-ui, sans-serif)`,
代码区域可使用 `var(--font-mono, monospace)`,避免写死 `system-ui`。
iframe 可以使用系统安装的字体,但不会继承主界面的 `@font-face`。
若使用未安装到系统的内置字体或其他 Web 字体,需要在插件包内提供字体文件并声明
`@font-face`。已有插件若写死字体,需要修改 CSS 并重新打包安装。
## 编写 Rust 后台
入口实现 `Plugin`,由 `Server::from_env()` 启动服务。SDK 负责握手、传输、
+10 -1
View File
@@ -194,7 +194,16 @@ must match exactly; no wildcards, paths or implicit subdomain grants.
`NyaTerm.context` contains plugin identity/version and CSS theme variables;
`NyaTerm.onContextChange(listener)` returns an unsubscribe function. Theme variables
are applied to the iframe document automatically. This context contains no scope
are applied to the iframe document automatically, including `--font-sans` and
`--font-display` (the configured UI font stack) and `--font-mono`. Font changes
are pushed to open panels without reloading them. The SDK defaults to the UI font
and makes form controls inherit it; plugin styles should use
`font-family: var(--font-sans, system-ui, sans-serif)` instead of a fixed family.
Use `var(--font-mono, monospace)` for code. System-installed fonts are available
inside the iframe, but the host's `@font-face` declarations are not inherited;
package any required web fonts with the plugin and declare them in its CSS.
Existing packages with a fixed font family need to update their CSS and be rebuilt.
This context contains no scope
token. Tokens are managed by the parent bridge. Scopes expire after 30 minutes;
open panels renew at 25 minutes by recreating their document. Preserve needed
nonsecret preferences in plugin storage.