@sqjian/dsh-skin 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/README.md CHANGED
@@ -1,3 +1,31 @@
1
- # Temporary Holding Version
1
+ # DSH Skin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 通过 DSH 插件条目的 `config` 配置侧栏、聊天首屏和 favicon。默认预设在侧栏和浏览器标签页使用 Ghostery 彩色图标,在聊天首屏使用黑白图标。自定义图片放在 `$DSH_HOME/storages/skin/`,可只读挂载。替换配置或图片后重启 DSH 并刷新页面即可。
4
+
5
+ 默认图标来自 [TheSVG 的 Ghostery 图标页](https://thesvg.org/icon/ghostery)。
6
+
7
+ ## Configuration
8
+
9
+ 将 `logo.png` 放入上述目录,把插件条目中的整个 `config` 替换为以下内容:
10
+
11
+ ```yaml
12
+ config:
13
+ sidebarName: Acme
14
+ sidebarLogo: logo.png
15
+ ```
16
+
17
+ | 字段 | 用途 | 省略时 |
18
+ |---|---|---|
19
+ | `sidebarName` | 侧栏名称和图标的无障碍描述 | `Ghostery` |
20
+ | `sidebarLogo` | 侧栏 Logo | `builtin:ghostery-color` |
21
+ | `heroTitle` | 聊天首屏标题 | 使用侧栏名称 |
22
+ | `heroLogo` | 聊天首屏 Logo | 使用侧栏 Logo |
23
+ | `favicon` | 浏览器图标 | 使用侧栏 Logo |
24
+
25
+ 图片字段支持相对于品牌目录的文件名或子路径、宿主绝对路径,以及内置图片 `builtin:ghostery-color`、`builtin:ghostery-mono`。支持 SVG 和 PNG。升级时,将 patch 引用的旧配置行 `ui-branding` 改为 `skin`,并将自定义图片从 `storages/ui-branding/` 移至 `storages/skin/`。
26
+
27
+ ## Build And Verify
28
+
29
+ 在插件组合包根目录执行 `mise run install-deps`、`mise run build`、`mise run test`。开发时使用 `dsh dev` 加载 patch。安装 patch 禁用 `ui-brand-official`。恢复官方品牌时同步恢复该配置行。
30
+
31
+ 侧栏展开显示名称和官方 `HARNESS` 徽标,收起显示 Logo。禁用插件后释放首屏样式并恢复原 favicon。升级 DSH 时复核 `BrandWordmark` 徽标裁剪坐标和 `conversation.hero.brand.mark` 相邻的原始标题结构。
@@ -0,0 +1 @@
1
+ <svg fill="#00AEF0" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Ghostery</title><path d="M22.058 19.93c-1.01-2.29-1.185-4.228-1.212-4.99V8.67C20.846 3.882 16.886 0 12 0S3.15 3.882 3.15 8.671v6.36c-.037.82-.236 2.7-1.207 4.899-1.306 2.955-.226 2.603.742 2.36.968-.242 3.13-1.192 3.805-.022.675 1.17 1.238 2.184 2.814 1.523 1.576-.663 2.318-.883 2.543-.883h.306c.225 0 .968.22 2.543.882 1.576.662 2.14-.353 2.814-1.522.676-1.17 2.837-.22 3.805.022.968.243 2.048.595.743-2.36M9.268 4.728c.953 0 1.725 1.198 1.725 2.676 0 1.478-.772 2.677-1.725 2.677-.953 0-1.726-1.198-1.726-2.677 0-1.478.773-2.676 1.726-2.676m2.73 10.697c-2.1 0-3.867-2.025-4.4-4.279 1.029 1.387 2.617 2.277 4.4 2.277 1.784 0 3.372-.89 4.401-2.277-.533 2.254-2.3 4.28-4.4 4.28m2.73-5.345c-.953 0-1.725-1.198-1.725-2.677 0-1.478.772-2.676 1.726-2.676.953 0 1.725 1.198 1.725 2.676 0 1.478-.772 2.677-1.725 2.677Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Ghostery</title><path d="M22.058 19.93c-1.01-2.29-1.185-4.228-1.212-4.99V8.67C20.846 3.882 16.886 0 12 0S3.15 3.882 3.15 8.671v6.36c-.037.82-.236 2.7-1.207 4.899-1.306 2.955-.226 2.603.742 2.36.968-.242 3.13-1.192 3.805-.022.675 1.17 1.238 2.184 2.814 1.523 1.576-.663 2.318-.883 2.543-.883h.306c.225 0 .968.22 2.543.882 1.576.662 2.14-.353 2.814-1.522.676-1.17 2.837-.22 3.805.022.968.243 2.048.595.743-2.36M9.268 4.728c.953 0 1.725 1.198 1.725 2.676 0 1.478-.772 2.677-1.725 2.677-.953 0-1.726-1.198-1.726-2.677 0-1.478.773-2.676 1.726-2.676m2.73 10.697c-2.1 0-3.867-2.025-4.4-4.279 1.029 1.387 2.617 2.277 4.4 2.277 1.784 0 3.372-.89 4.401-2.277-.533 2.254-2.3 4.28-4.4 4.28m2.73-5.345c-.953 0-1.725-1.198-1.725-2.677 0-1.478.772-2.676 1.726-2.676.953 0 1.725 1.198 1.725 2.676 0 1.478-.772 2.677-1.725 2.677Z"/></svg>
@@ -0,0 +1,10 @@
1
+ - id: ui-brand-official
2
+ disabled: true
3
+ - insert:
4
+ - id: skin
5
+ name: "@sqjian/dsh-skin"
6
+ config:
7
+ sidebarName: Ghostery
8
+ sidebarLogo: builtin:ghostery-color
9
+ heroTitle: Ghostery Chat
10
+ heroLogo: builtin:ghostery-mono
package/dist/client.js ADDED
@@ -0,0 +1,126 @@
1
+ // src/client.ts
2
+ window.__ModuleLoader__.load({
3
+ id: "@sqjian/dsh-skin",
4
+ factory(require) {
5
+ const { createElement: h } = require("react");
6
+ const { BrandWordmark } = require("@deepseek-ai/dsh-client-ui-primitives");
7
+ return {
8
+ inject: ["slots"],
9
+ async apply(ctx) {
10
+ const request = new AbortController();
11
+ ctx.effect(() => () => request.abort());
12
+ let brand;
13
+ try {
14
+ const response = await fetch(new URL("api/skin", document.baseURI), {
15
+ signal: request.signal,
16
+ credentials: "same-origin"
17
+ });
18
+ if (!response.ok) throw new Error(`读取品牌配置失败 HTTP ${response.status}`);
19
+ brand = await response.json();
20
+ } catch (error) {
21
+ if (request.signal.aborted) return;
22
+ throw error;
23
+ }
24
+ if (request.signal.aborted) return;
25
+ function BrandMark({ size }) {
26
+ return h("img", {
27
+ src: brand.sidebarLogo,
28
+ alt: brand.sidebarName,
29
+ width: size,
30
+ height: size,
31
+ draggable: false,
32
+ style: {
33
+ display: "block",
34
+ objectFit: "contain"
35
+ }
36
+ });
37
+ }
38
+ function BrandName() {
39
+ return h("span", {
40
+ "aria-label": `${brand.sidebarName} harness`,
41
+ style: {
42
+ display: "inline-flex",
43
+ alignItems: "center",
44
+ gap: 8,
45
+ height: 24
46
+ }
47
+ }, h("span", { style: {
48
+ fontSize: 20,
49
+ fontWeight: 500,
50
+ letterSpacing: "-0.5px",
51
+ lineHeight: "24px"
52
+ } }, brand.sidebarName), h("svg", {
53
+ width: 52,
54
+ height: 24,
55
+ viewBox: "129.348 0 52 24",
56
+ "aria-hidden": true,
57
+ style: {
58
+ overflow: "hidden",
59
+ flexShrink: 0
60
+ }
61
+ }, h(BrandWordmark, { size: 24 })));
62
+ }
63
+ function HeroBrand({ size }) {
64
+ return h("span", {
65
+ "data-skin-hero": "",
66
+ style: {
67
+ display: "inline-flex",
68
+ alignItems: "center",
69
+ gap: 10
70
+ }
71
+ }, h("img", {
72
+ src: brand.heroLogo,
73
+ alt: brand.sidebarName,
74
+ width: size,
75
+ height: size,
76
+ draggable: false,
77
+ style: {
78
+ display: "block",
79
+ objectFit: "contain"
80
+ }
81
+ }), h("span", null, brand.heroTitle));
82
+ }
83
+ ctx.effect(() => {
84
+ const icons = [...document.head.querySelectorAll("link[rel~=\"icon\"]")];
85
+ const originals = icons.map((icon) => ({
86
+ icon,
87
+ attributes: [
88
+ "href",
89
+ "type",
90
+ "sizes"
91
+ ].map((name) => [name, icon.getAttribute(name)])
92
+ }));
93
+ if (!icons.length) {
94
+ const icon = document.createElement("link");
95
+ icon.rel = "icon";
96
+ document.head.append(icon);
97
+ icons.push(icon);
98
+ }
99
+ for (const icon of icons) {
100
+ icon.href = brand.favicon;
101
+ icon.type = brand.favicon.slice(5, brand.favicon.indexOf(";"));
102
+ icon.removeAttribute("sizes");
103
+ }
104
+ return () => {
105
+ if (!originals.length) icons[0].remove();
106
+ for (const { icon, attributes } of originals) for (const [name, value] of attributes) if (value === null) icon.removeAttribute(name);
107
+ else icon.setAttribute(name, value);
108
+ };
109
+ });
110
+ ctx.slots.inject("conversation.hero.brand.mark", () => {
111
+ ctx.effect(() => {
112
+ const style = document.createElement("style");
113
+ style.textContent = "span:has(> [data-slot=\"conversation.hero.brand.mark\"] > [data-skin-hero]) + span { display: none; }";
114
+ document.head.append(style);
115
+ return () => style.remove();
116
+ });
117
+ return ctx.slots.register({ name: "conversation.hero.brand.mark" }, HeroBrand);
118
+ });
119
+ ctx.slots.inject("sidebar.brand.mark", () => ctx.slots.inject("sidebar.brand.name", function* () {
120
+ yield ctx.slots.register({ name: "sidebar.brand.mark" }, BrandMark);
121
+ yield ctx.slots.register({ name: "sidebar.brand.name" }, BrandName);
122
+ }));
123
+ }
124
+ };
125
+ }
126
+ });
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import Schema from "@deepseek-ai/schemastery";
2
+ import { readFileSync } from "node:fs";
3
+ import { extname, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
6
+ // src/skin.ts
7
+ var builtins = /* @__PURE__ */ new Map([["builtin:ghostery-mono", "ghostery-mono.svg"], ["builtin:ghostery-color", "ghostery-color.svg"]]);
8
+ function resolveSkin(config = {}) {
9
+ const assets = dshHomePath("storages", "skin");
10
+ const images = /* @__PURE__ */ new Map();
11
+ function image(field, source) {
12
+ let path = resolve(assets, source);
13
+ if (source.startsWith("builtin:")) {
14
+ const file = builtins.get(source);
15
+ if (!file) throw new Error(`${field} 指定了未知内置图片 ${source}`);
16
+ path = fileURLToPath(new URL(`../assets/${file}`, import.meta.url));
17
+ }
18
+ const cached = images.get(path);
19
+ if (cached) return cached;
20
+ const extension = extname(path).toLowerCase();
21
+ if (extension !== ".svg" && extension !== ".png") throw new Error(`${field} 仅支持 SVG 或 PNG 图片:${path}`);
22
+ const mime = extension === ".svg" ? "image/svg+xml" : "image/png";
23
+ let bytes;
24
+ try {
25
+ bytes = readFileSync(path);
26
+ } catch (cause) {
27
+ throw new Error(`${field} 无法读取图片:${path}`, { cause });
28
+ }
29
+ if (!(extension === ".png" ? bytes.subarray(0, 8).equals(Buffer.from("89504e470d0a1a0a", "hex")) : /<svg[\s/>]/.test(bytes.toString("utf8")))) throw new Error(`${field} 图片内容与扩展名不符:${path}`);
30
+ const url = `data:${mime};base64,${bytes.toString("base64")}`;
31
+ images.set(path, url);
32
+ return url;
33
+ }
34
+ const sidebarName = config.sidebarName ?? "Ghostery";
35
+ const sidebarLogo = image("sidebarLogo", config.sidebarLogo ?? "builtin:ghostery-color");
36
+ return {
37
+ sidebarName,
38
+ sidebarLogo,
39
+ heroTitle: config.heroTitle ?? sidebarName,
40
+ heroLogo: config.heroLogo === void 0 ? sidebarLogo : image("heroLogo", config.heroLogo),
41
+ favicon: config.favicon === void 0 ? sidebarLogo : image("favicon", config.favicon)
42
+ };
43
+ }
44
+ // src/index.ts
45
+ var inject = ["connection"];
46
+ var Config = Schema.object({
47
+ sidebarName: Schema.string().default("Ghostery").description("侧栏品牌名称"),
48
+ sidebarLogo: Schema.string().default("builtin:ghostery-color").description("侧栏 Logo"),
49
+ heroTitle: Schema.string().description("聊天首屏标题,默认使用侧栏名称"),
50
+ heroLogo: Schema.string().description("聊天首屏 Logo,默认使用侧栏 Logo"),
51
+ favicon: Schema.string().description("浏览器图标,默认使用侧栏 Logo")
52
+ });
53
+ function apply(ctx, config) {
54
+ const brand = resolveSkin(config);
55
+ ctx.effect(() => ctx.connection.fetch.register({
56
+ path: "/api/skin",
57
+ methods: ["GET"],
58
+ requestBody: "buffered",
59
+ fetch: () => Response.json(brand, { headers: { "Cache-Control": "no-store" } })
60
+ }));
61
+ }
62
+ export { Config, apply, inject };
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@sqjian/dsh-skin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "可配置侧栏、聊天首屏和浏览器图标",
6
+ "engines": {
7
+ "dsh": ">=0.2.2-0 <=0.2.2 || >=0.2.3-0 <=0.2.3",
8
+ "node": ">=24.9.0"
9
+ },
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./client": "./dist/client.js",
13
+ "./assets/*": "./assets/*"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "assets",
18
+ "cordis.patch.yml"
19
+ ],
20
+ "dsh": {
21
+ "bundle": {
22
+ "patch": "./cordis.patch.yml"
23
+ },
24
+ "client": {
25
+ "platform": "web",
26
+ "immediately": true,
27
+ "inject": [
28
+ "@deepseek-ai/dsh-client-ui-sidebar",
29
+ "@deepseek-ai/dsh-client-ui-conversation"
30
+ ]
31
+ }
32
+ },
33
+ "dependencies": {
34
+ "@deepseek-ai/dsh-home-paths": "0.2.2-rc.3",
35
+ "@deepseek-ai/schemastery": "^3.18.1"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "22.20.4",
39
+ "@types/react": "18.3.31",
40
+ "typescript": "5.9.3",
41
+ "vite": "8.3.8",
42
+ "yaml": "^2.9.1"
43
+ },
44
+ "scripts": {
45
+ "typecheck": "tsc --noEmit",
46
+ "build": "pnpm run typecheck && vite build --mode host && vite build"
47
+ }
6
48
  }