dsh-brand-pack-loader 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +22 -2
- package/client.js +101 -0
- package/docs/DETAIL.md +7 -0
- package/icon.svg +1 -0
- package/index.js +32 -0
- package/locale/en.json +1 -0
- package/locale/zh.json +1 -0
- package/package.json +38 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pirate mode contributors
|
|
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,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 品牌包加载器
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
主题通过 `pack.sidebarMark`、`pack.heroMark` 和 `pack.wordmark` 分别配置侧栏标记、对话首页标记和完整字标。加载器只负责读取配置、渲染图片和注册 DSH 品牌槽位,不携带任何主题素材或文字。
|
|
4
|
+
|
|
5
|
+
每项可以为 `false`、base64 图片 data URL,或 `{ src, width, height, tint }` 图片配置。支持 SVG、PNG、JPEG、WebP。字符串图片保留原颜色和纵横比;`tint: true` 将图片的透明轮廓作为遮罩,跟随宿主文字颜色。尺寸由配置提供。SVG 始终作为图片或遮罩使用,不插入为页面标记,支持内嵌位图的合成图片。
|
|
6
|
+
|
|
7
|
+
加载器通过配置行 id `brand-pack-loader` 读取配置表单。未配置的槽位不注册;配置清除或插件停用时释放槽位。主题素材与图片 data URL 由主题包维护。
|
|
8
|
+
|
|
9
|
+
槽位优先级为 `-0.5`,高于官方默认图案的 `0`,低于 `dsh-logo-swap` 个人设置的 `-1`。加载器不读写第三方浏览器存储。
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
- id: brand-pack-loader
|
|
13
|
+
config:
|
|
14
|
+
pack:
|
|
15
|
+
id: example
|
|
16
|
+
sidebarMark: 'data:image/png;base64,...'
|
|
17
|
+
heroMark: 'data:image/png;base64,...'
|
|
18
|
+
wordmark:
|
|
19
|
+
src: 'data:image/svg+xml;base64,...'
|
|
20
|
+
width: 160
|
|
21
|
+
height: 24
|
|
22
|
+
tint: true
|
|
23
|
+
```
|
package/client.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-brand-pack-loader',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const { createElement: h, useSyncExternalStore } = require('react');
|
|
5
|
+
const FIELDS = ['sidebarMark', 'heroMark', 'wordmark'];
|
|
6
|
+
const IMAGE_SOURCE = /^data:image\/(?:svg\+xml|png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/u;
|
|
7
|
+
|
|
8
|
+
function imageOf(value) {
|
|
9
|
+
const image = typeof value === 'string' ? { src: value, tint: false } : value;
|
|
10
|
+
if (!image || typeof image.src !== 'string' || image.src.length > 2 * 1024 * 1024 || !IMAGE_SOURCE.test(image.src)) return null;
|
|
11
|
+
if (image.tint && !(Number.isFinite(image.width) && image.width > 0 && Number.isFinite(image.height) && image.height > 0)) return null;
|
|
12
|
+
return image;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
inject: ['slots', 'configForms'],
|
|
17
|
+
apply(ctx) {
|
|
18
|
+
let current = null;
|
|
19
|
+
const listeners = new Set();
|
|
20
|
+
const snapshot = () => current;
|
|
21
|
+
const subscribe = (listener) => {
|
|
22
|
+
listeners.add(listener);
|
|
23
|
+
return () => listeners.delete(listener);
|
|
24
|
+
};
|
|
25
|
+
const publish = (pack) => {
|
|
26
|
+
current = pack ? Object.fromEntries(FIELDS.map(field => [field, imageOf(pack[field])])) : null;
|
|
27
|
+
for (const listener of [...listeners]) listener();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Images remain in an img or CSS mask context. SVG is never inserted as
|
|
31
|
+
// document markup, so composites can contain embedded raster artwork.
|
|
32
|
+
function BrandImage({ field, size, className, maxWidth }) {
|
|
33
|
+
const pack = useSyncExternalStore(subscribe, snapshot);
|
|
34
|
+
const image = pack?.[field];
|
|
35
|
+
if (!image) return null;
|
|
36
|
+
const height = size ?? image.height ?? 24;
|
|
37
|
+
const common = {
|
|
38
|
+
'aria-hidden': true,
|
|
39
|
+
'data-dsh-brand-pack': field,
|
|
40
|
+
className,
|
|
41
|
+
};
|
|
42
|
+
if (image.tint) {
|
|
43
|
+
const mask = `url("${image.src}") center / contain no-repeat`;
|
|
44
|
+
return h('span', {
|
|
45
|
+
...common,
|
|
46
|
+
style: {
|
|
47
|
+
display: 'block', flex: 'none', height,
|
|
48
|
+
width: height * image.width / image.height, maxWidth,
|
|
49
|
+
backgroundColor: 'currentColor', mask, WebkitMask: mask,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return h('img', {
|
|
54
|
+
...common,
|
|
55
|
+
src: image.src, height, alt: '', draggable: false,
|
|
56
|
+
style: { display: 'block', flex: 'none', height, width: 'auto', maxWidth, objectFit: 'contain' },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const targets = [
|
|
61
|
+
['sidebar.brand.mark', 'sidebarMark', props => h(BrandImage, { field: 'sidebarMark', size: props.size ?? 24, maxWidth: 200 })],
|
|
62
|
+
['conversation.hero.brand.mark', 'heroMark', props => h(BrandImage, { field: 'heroMark', size: props.size ?? 34, className: props.className, maxWidth: 240 })],
|
|
63
|
+
['sidebar.brand.name', 'wordmark', () => h(BrandImage, { field: 'wordmark', maxWidth: 220 })],
|
|
64
|
+
];
|
|
65
|
+
for (const [name, field, component] of targets) {
|
|
66
|
+
ctx.slots.inject(name, () => {
|
|
67
|
+
let dispose = null;
|
|
68
|
+
const sync = () => {
|
|
69
|
+
if (current?.[field] && dispose === null) {
|
|
70
|
+
dispose = ctx.slots.register({ name, priority: -0.5 }, component);
|
|
71
|
+
} else if (!current?.[field] && dispose !== null) {
|
|
72
|
+
dispose();
|
|
73
|
+
dispose = null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const unsubscribe = subscribe(sync);
|
|
77
|
+
try { sync(); } catch (error) { unsubscribe(); throw error; }
|
|
78
|
+
return () => { unsubscribe(); dispose?.(); };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return ctx.effect(() => {
|
|
83
|
+
const form = ctx.configForms.get('brand-pack-loader');
|
|
84
|
+
let revision;
|
|
85
|
+
const sync = () => {
|
|
86
|
+
const { status, value } = form.getSnapshot();
|
|
87
|
+
if (status === 'loading') return;
|
|
88
|
+
const pack = status === 'ready' ? value?.pack : null;
|
|
89
|
+
const next = JSON.stringify(pack ?? false);
|
|
90
|
+
if (revision === next) return;
|
|
91
|
+
publish(pack || null);
|
|
92
|
+
revision = next;
|
|
93
|
+
};
|
|
94
|
+
const unsubscribe = form.subscribe(sync);
|
|
95
|
+
try { sync(); } catch (error) { unsubscribe(); throw error; }
|
|
96
|
+
return () => { unsubscribe(); publish(null); };
|
|
97
|
+
}, 'brand-pack-loader: brand images');
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
});
|
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Brand pack loader
|
|
2
|
+
|
|
3
|
+
The loader consumes theme-owned `sidebarMark`, `heroMark` and `wordmark` image configurations and registers the corresponding official brand slots. It contains no theme artwork, names, badge labels or fixed wordmark dimensions.
|
|
4
|
+
|
|
5
|
+
Each image is false, a base64 SVG/PNG/JPEG/WebP data URL, or `{ src, width, height, tint }`. Ordinary images retain their colours. Tinted images use their alpha as a CSS mask and inherit the host's text colour; dimensions come from configuration. SVG is displayed only in an image or mask context, including composites with embedded raster images.
|
|
6
|
+
|
|
7
|
+
The Client reads the configuration row id `brand-pack-loader`. Its configuration subscription, store and slot registrations belong to the current plugin instance and are released on unload. Slot priority is -0.5, between official artwork at 0 and user overrides from dsh-logo-swap at -1.
|
package/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" fill="none"><rect x="5" y="7" width="26" height="22" rx="3" stroke="#527d98" stroke-width="2"/><circle cx="23" cy="13" r="2.5" fill="#d5a24d"/><path d="m8 25 7-8 5 5 3-3 5 6" stroke="#527d98" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
const localRequire = createRequire(import.meta.url);
|
|
5
|
+
const hostRoot = process.env.DSH_INSTALL_DIR
|
|
6
|
+
?? (process.resourcesPath && join(process.resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', 'dsh'));
|
|
7
|
+
const schemastery = hostRoot
|
|
8
|
+
? createRequire(join(hostRoot, 'package.json'))('@deepseek-ai/schemastery')
|
|
9
|
+
: localRequire('@deepseek-ai/schemastery');
|
|
10
|
+
const z = schemastery.default ?? schemastery;
|
|
11
|
+
const source = () => z.string().pattern(/^data:image\/(?:svg\+xml|png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$/u);
|
|
12
|
+
const image = z.object({
|
|
13
|
+
src: source().required(),
|
|
14
|
+
width: z.natural().min(1).required(),
|
|
15
|
+
height: z.natural().min(1).required(),
|
|
16
|
+
tint: z.boolean().default(false),
|
|
17
|
+
});
|
|
18
|
+
const mark = () => z.union([z.const(false), source(), image]).default(false);
|
|
19
|
+
const pack = z.object({
|
|
20
|
+
id: z.string().pattern(/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u).required(),
|
|
21
|
+
sidebarMark: mark(),
|
|
22
|
+
heroMark: mark(),
|
|
23
|
+
wordmark: mark(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const Config = z.object({ pack: z.union([z.const(false), pack]).default(false).volatile() });
|
|
27
|
+
|
|
28
|
+
export function apply(ctx) {
|
|
29
|
+
ctx.inject(['settings'], scope => scope.effect(
|
|
30
|
+
() => scope.settings.configure({ auto: false }, ctx.fiber),
|
|
31
|
+
));
|
|
32
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"Brand pack loader","description":"Renders theme-provided images, dimensions and optional masks in sidebar, home and wordmark slots. Contains no theme artwork and never rewrites personal logo settings."}}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"meta":{"title":"品牌包加载器","description":"读取主题提供的图片、尺寸与可选遮罩配置,注册侧栏标记、首页标记和可选字标。加载器不含主题素材,不改写个人 Logo 设置。"}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-brand-pack-loader",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Registers validated SVG images in DSH brand slots from bundle row configuration.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/butterfly301/dsh-brand-pack-loader.git"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"dsh": ">=0.2.2-rc.5 <0.3.0"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.js",
|
|
16
|
+
"./client": "./client.js",
|
|
17
|
+
"./locale/*.json": "./locale/*.json",
|
|
18
|
+
"./icon": "./icon.svg",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.js",
|
|
23
|
+
"client.js",
|
|
24
|
+
"locale",
|
|
25
|
+
"docs",
|
|
26
|
+
"icon.svg",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"dsh": {
|
|
31
|
+
"client": {
|
|
32
|
+
"platform": "web",
|
|
33
|
+
"immediately": true,
|
|
34
|
+
"inject": [
|
|
35
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
36
|
+
"@deepseek-ai/dsh-client-ui-brand-official"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|