dsh-plugin-ekko-skin-manager 0.0.0-stage → 0.1.3

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 ADDED
@@ -0,0 +1,25 @@
1
+ MIT License — newly authored DSH adaptation code only
2
+
3
+ Copyright (c) 2026 Ekko Miku Theme contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this adaptation's newly authored software and associated documentation files
7
+ (the "Software"), to deal in the Software without restriction, including without
8
+ limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the Software
10
+ is 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.
22
+
23
+ This license does not relicense inherited artwork, photographs, icons, or other
24
+ third-party materials. Their existing rights and licenses remain applicable.
25
+ See NOTICE and THIRD_PARTY_LICENSES.
package/README.md CHANGED
@@ -1,3 +1,84 @@
1
- # Temporary Holding Version
1
+ # Ekko 皮肤管理器 · DeepSeek Harness
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 的 **设置 → Ekko 皮肤** 管理初音未来与有菜玫瑰,支持原生界面、独立装饰偏好和互斥切换。可只安装初音;无需同时安装两款主题。
4
+
5
+ **Compatible with: dsh 0.2.1-rc.5** · Node.js ≥ 22。
6
+
7
+ ## 新用户安装
8
+
9
+ 推荐一次安装管理器与初音主题:
10
+
11
+ ```sh
12
+ dsh plugin --profile web add dsh-plugin-ekko-skin-manager@0.1.3 dsh-plugin-miku-theme@0.2.3
13
+ ```
14
+
15
+ 刷新 DSH 网页后,全新浏览器默认启用可用主题。通过 **账号菜单 → 设置 → Ekko 皮肤** 切换外观、开关人物与照片、调整背景浓度。profile 名称不同,请将 `web` 改为实际名称。
16
+
17
+ 只想先安装管理器:
18
+
19
+ ```sh
20
+ dsh plugin --profile web add dsh-plugin-ekko-skin-manager@0.1.3
21
+ ```
22
+
23
+ 没有主题时保留原生界面,管理页面仍可打开,不会卡在加载状态。玫瑰为可选主题,未安装时不会影响初音。明确选择过“原生界面”时会尊重该选择。
24
+
25
+ 首次启动 DSH 时,先在原生“预览版说明”中点击“继续”。主题不附带模型服务;正常对话仍需按 DSH 的流程配置模型和工作区。
26
+
27
+ ## GitHub 与安装包
28
+
29
+ GitHub 安装:
30
+
31
+ ```sh
32
+ dsh plugin --profile web add github:cjjchina3088191870-sudo/dsh-plugin-ekko-skin-manager#v0.1.3 github:cjjchina3088191870-sudo/dsh-plugin-miku-theme#v0.2.3
33
+ ```
34
+
35
+ 从两个仓库的 GitHub Releases 下载 `.tgz` 后:
36
+
37
+ ```sh
38
+ dsh plugin --profile web add ./dsh-plugin-ekko-skin-manager-0.1.3.tgz ./dsh-plugin-miku-theme-0.2.3.tgz
39
+ ```
40
+
41
+ 包内含完整构建结果;安装与运行无需 Ekko 源码、私有目录、开发依赖或 `prepare` 脚本。
42
+
43
+ ## 使用与更新
44
+
45
+ 每个浏览器保存自己的主题选择,同一浏览器的其他标签页同步。首次加载按实际安装情况选择默认主题;已保存但未安装的主题会回退到可用主题。没有主题时回到原生界面。
46
+
47
+ ```sh
48
+ dsh plugin --profile web update dsh-plugin-ekko-skin-manager dsh-plugin-miku-theme
49
+ ```
50
+
51
+ 临时停用装饰时,在管理页面选择 **原生界面**。主题切换保留会话与草稿;不修改模型、账号、订阅或工作区。
52
+
53
+ ## 从旧“皮肤管理”插件迁移
54
+
55
+ 新用户跳过本节。只有之前安装过旧管理器的用户需要迁移。
56
+
57
+ 迁移工具只调整这两个主题及管理器的配置项,会先备份,并停用旧管理器入口;不修改模型、权限或外部挂件。保留旧管理器包作为禁用的兼容项,无需卸载其他皮肤。
58
+
59
+ 在 DSH profile 目录执行(将示例路径替换为自己的 DSH 主目录):
60
+
61
+ ```sh
62
+ node node_modules/dsh-plugin-ekko-skin-manager/lib/migrate.js /你的/DSH主目录 web
63
+ ```
64
+
65
+ DSH 主目录通常是用户目录下的 `.dsh`;设置了 `DSH_HOME` 时以它为准。备份位于该目录的 `ekko-skins-backups/`。迁移后刷新网页,使用新的 **设置 → Ekko 皮肤**。
66
+
67
+ ## 工作方式
68
+
69
+ - 前端只有一个呈现拥有者。预载新素材后,等待旧主题完整卸载,再挂载新主题。
70
+ - 资源入口持续存在,切换不关闭后台素材提供者,不会因停用外观而出现失效图片。
71
+ - 颜色、CSS、人物、照片、DOM 标记、观察器与草稿桥接随主题释放;原生输入框保留。
72
+ - 选择原生界面会清除主题呈现,保留管理入口。两款主题的装饰偏好分别保存。
73
+ - 素材加载失败时保留当前正常主题,并提供重试入口。
74
+
75
+ ## 开发
76
+
77
+ ```sh
78
+ npm install --ignore-scripts
79
+ npm run build
80
+ npm test
81
+ npm pack
82
+ ```
83
+
84
+ `DSH_SKIN_MANAGER_TOOLCHAIN` 仅用于开发时复用 esbuild 与 YAML 工具。发布包内已构建迁移工具及其 YAML 依赖。新增代码采用 MIT,内置 YAML 库许可证见 `THIRD_PARTY_LICENSES/YAML-LICENSE`。
@@ -0,0 +1,13 @@
1
+ Copyright Eemeli Aro <eemeli@gmail.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
@@ -0,0 +1,6 @@
1
+ - insert:
2
+ - id: ekko-skin-manager
3
+ name: dsh-plugin-ekko-skin-manager
4
+ disabled: false
5
+ config:
6
+ defaultSkin: miku
package/design-qa.md ADDED
@@ -0,0 +1,11 @@
1
+ # 发布验证
2
+
3
+ 运行目标:DSH 0.2.1-rc.5 / Node.js 22 或更新版本。
4
+
5
+ - 初音欢迎页、对话页、浅色及深色、360×639 和 390×844 手机尺寸已在真实 DSH 页面检查。
6
+ - 新会话图标居中、顶部按钮位于边框内、输入框底部间距约 14px。
7
+ - 主题切换清理旧呈现,保留草稿及原生编辑器,装饰层不拦截点击。
8
+ - 发布前新增管理器首次安装检查:只安装初音、只安装管理器、已保存的缺失主题,以及延迟加载的主题提供者。
9
+ - 主题预览见 `preview/`(初音包)。
10
+
11
+ 发布包包含构建结果与资源,不包含本机账号、凭据、会话或开发环境配置。
package/lib/client.js ADDED
@@ -0,0 +1,308 @@
1
+ window.__ModuleLoader__.load({id:"dsh-plugin-ekko-skin-manager",factory:(require)=>{const module={exports:{}};const exports=module.exports;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // work/dsh-plugin-ekko-skin-manager/src/client.jsx
31
+ var client_exports = {};
32
+ __export(client_exports, {
33
+ apply: () => apply,
34
+ inject: () => inject
35
+ });
36
+ module.exports = __toCommonJS(client_exports);
37
+ var import_react = __toESM(require("react"), 1);
38
+
39
+ // work/dsh-plugin-ekko-skin-manager/src/controller.mjs
40
+ var SELECTION_KEY = "dsh:ekko-skins:selection:v1";
41
+ var SKIN_IDS = ["default", "rose", "miku"];
42
+ function readSelection(storage, fallback = "rose") {
43
+ try {
44
+ const value = JSON.parse(storage.getItem(SELECTION_KEY));
45
+ if (value?.version === 1 && SKIN_IDS.includes(value.skin)) return value.skin;
46
+ } catch {
47
+ }
48
+ const old = {};
49
+ for (const id of ["rose", "miku"]) try {
50
+ old[id] = JSON.parse(storage.getItem("dsh:ekko-" + id + ":v1"))?.enabled;
51
+ } catch {
52
+ }
53
+ if (old.rose === false && old.miku === true) return "miku";
54
+ if (old.miku === false && old.rose === true) return "rose";
55
+ if (old.rose === false && old.miku === false) return "default";
56
+ return SKIN_IDS.includes(fallback) ? fallback : "rose";
57
+ }
58
+ function createController({ storage, mount, prepare = async () => {
59
+ }, fallback = "rose" }) {
60
+ const providers = /* @__PURE__ */ new Map(), listeners = /* @__PURE__ */ new Set();
61
+ let wanted = readSelection(storage, fallback), persistWanted = true, runtime = null, epoch = 0, closed = false, initialized = false, tail = Promise.resolve();
62
+ let snapshot = { selected: "default", desired: wanted, busy: false, error: null, available: [] };
63
+ const publish = (value) => {
64
+ snapshot = { ...snapshot, ...value, available: [...providers.keys()] };
65
+ for (const fn of listeners) fn();
66
+ };
67
+ async function release() {
68
+ const previous = runtime;
69
+ runtime = null;
70
+ if (previous) await previous.handle.dispose();
71
+ }
72
+ function reconcile() {
73
+ if (closed) return Promise.resolve();
74
+ const ticket = ++epoch, target = wanted, persist = persistWanted;
75
+ publish({ desired: target, busy: true, error: null });
76
+ tail = tail.catch(() => {
77
+ }).then(async () => {
78
+ if (closed || ticket !== epoch) return;
79
+ const provider = providers.get(target);
80
+ if (target !== "default" && !provider) {
81
+ if (runtime && providers.get(runtime.provider.id) !== runtime.provider) {
82
+ await release();
83
+ publish({ selected: "default" });
84
+ }
85
+ return;
86
+ }
87
+ if (runtime?.provider !== provider || target === "default") {
88
+ if (provider) await prepare(provider);
89
+ if (closed || ticket !== epoch) return;
90
+ await release();
91
+ if (closed || ticket !== epoch) return;
92
+ if (provider) {
93
+ runtime = { provider, handle: mount(provider) };
94
+ try {
95
+ await runtime.handle.ready();
96
+ } catch (error) {
97
+ await release();
98
+ throw error;
99
+ }
100
+ if (closed || ticket !== epoch) {
101
+ await release();
102
+ return;
103
+ }
104
+ }
105
+ }
106
+ if (persist) try {
107
+ storage.setItem(SELECTION_KEY, JSON.stringify({ version: 1, skin: target }));
108
+ } catch {
109
+ }
110
+ publish({ selected: target, busy: false, error: null });
111
+ }).catch((error) => {
112
+ if (!closed && ticket === epoch) publish({ selected: runtime?.provider.id || "default", busy: false, error: String(error?.message || error) });
113
+ });
114
+ return tail;
115
+ }
116
+ return {
117
+ getSnapshot: () => snapshot,
118
+ subscribe(fn) {
119
+ listeners.add(fn);
120
+ return () => listeners.delete(fn);
121
+ },
122
+ register(provider) {
123
+ if (!["rose", "miku"].includes(provider.id) || typeof provider.plugin?.apply !== "function") throw new TypeError("Unknown Ekko skin provider");
124
+ providers.set(provider.id, provider);
125
+ publish({});
126
+ if (initialized && provider.id === wanted) void reconcile();
127
+ return () => {
128
+ if (providers.get(provider.id) !== provider) return;
129
+ providers.delete(provider.id);
130
+ publish({});
131
+ if (provider.id === wanted || runtime?.provider === provider) void reconcile();
132
+ };
133
+ },
134
+ choose(id, { persist = true } = {}) {
135
+ if (!SKIN_IDS.includes(id)) return Promise.reject(new TypeError("Unknown skin"));
136
+ initialized = true;
137
+ wanted = id;
138
+ persistWanted = persist;
139
+ return reconcile();
140
+ },
141
+ initialize(defaultSkin, installedIds) {
142
+ initialized = true;
143
+ wanted = readSelection(storage, defaultSkin);
144
+ if (Array.isArray(installedIds) && wanted !== "default" && !installedIds.includes(wanted)) wanted = defaultSkin === "default" ? "default" : installedIds.includes(defaultSkin) ? defaultSkin : SKIN_IDS.find((id) => id !== "default" && installedIds.includes(id)) || "default";
145
+ persistWanted = true;
146
+ return reconcile();
147
+ },
148
+ provider: (id) => providers.get(id),
149
+ settled: () => tail,
150
+ async dispose() {
151
+ if (closed) return;
152
+ closed = true;
153
+ ++epoch;
154
+ await tail.catch(() => {
155
+ });
156
+ await release();
157
+ listeners.clear();
158
+ providers.clear();
159
+ }
160
+ };
161
+ }
162
+
163
+ // work/dsh-plugin-ekko-skin-manager/src/generated.mjs
164
+ var STYLES = ".ekko-skins{display:grid;gap:18px;color:var(--dsw-alias-label-primary);font:14px/1.6 var(--ds-font-family,system-ui);}\n.ekko-skins h2,.ekko-skins h3,.ekko-skins p{margin:0;}.ekko-skins h2{font-size:20px;line-height:1.5;}.ekko-skins h3{font-size:15px;}\n.ekko-skins-intro{display:grid;gap:5px;}.ekko-skins-intro p,.ekko-skin-version,.ekko-skin-option small{color:var(--dsw-alias-label-secondary);font-size:12px;}\n.ekko-skin-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;}\n.ekko-skin-card{min-width:0;overflow:hidden;border:1px solid var(--dsw-alias-border-l2);border-radius:16px;background:var(--dsw-alias-bg-layer-1);box-shadow:0 4px 12px #234c6510;}\n.ekko-skin-card[data-active='true']{border-color:var(--dsw-alias-brand-primary);box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-brand-primary) 18%,transparent);}\n.ekko-skin-cover{display:block;width:100%;aspect-ratio:1400/787;object-fit:cover;border-bottom:1px solid var(--dsw-alias-border-l3);}\n.ekko-skin-description{display:grid;gap:10px;padding:13px;}.ekko-skin-title{display:flex;align-items:center;justify-content:space-between;gap:8px;}.ekko-skin-state{color:var(--dsw-alias-brand-text);font-size:11px;white-space:nowrap;}\n.ekko-skin-button{border:1px solid var(--dsw-alias-border-l2);border-radius:9px;padding:7px 12px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;cursor:pointer;}\n.ekko-skin-button:disabled{opacity:.65;cursor:default;}.ekko-skin-button:focus-visible,.ekko-skins input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:3px;}\n.ekko-skin-button[data-active='true']{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary-invert);}\n.ekko-skin-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px;}.ekko-skin-options{padding:15px;border:1px solid var(--dsw-alias-border-l2);border-radius:14px;background:var(--dsw-alias-bg-layer-1);}\n.ekko-skin-option{display:flex;align-items:center;justify-content:space-between;gap:18px;min-height:40px;padding:8px 0;border-bottom:1px solid var(--dsw-alias-border-l3);}.ekko-skin-option:last-child{border:0;}.ekko-skin-option span{display:grid;gap:2px;}.ekko-skin-option input{accent-color:var(--dsw-alias-brand-primary);}.ekko-skin-option input[type='range']{width:130px;max-width:40%;}.ekko-skin-error{padding:10px 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;color:var(--dsw-alias-state-danger,#c43d3d);font-size:13px;}\n@media(max-width:640px){.ekko-skin-grid{grid-template-columns:1fr;}.ekko-skins h2{font-size:18px;}.ekko-skin-toolbar{align-items:flex-start;}.ekko-skin-description{padding:12px;}}\n/* Keep the native settings shell usable on phones: tabs above the content. */\n@media(max-width:640px){\n [role='dialog']:has(>[class*='_nav']>[class*='_navList']){flex-direction:column;width:calc(100vw - 24px);max-width:calc(100vw - 24px);height:min(800px,calc(100dvh - 48px));}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList'])>[class*='_nav']{width:100%;padding:15px 12px 0;gap:12px;}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList']) [class*='_navTitle']{padding-inline:5px;}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList']) [class*='_navList']{flex-direction:row;gap:4px;overflow:auto;padding-bottom:5px;}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList']) [class*='_navCell']{flex:none;width:max-content;height:36px;padding:7px 10px;font-size:13px;}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList'])>[class*='_content']{min-height:0;width:100%;}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList']) [class*='_header']{position:absolute;top:10px;right:10px;height:auto;padding:0;}\n [role='dialog']:has(>[class*='_nav']>[class*='_navList']) [class*='_options']{padding:12px 12px 18px;min-width:0;}\n .ekko-skins{gap:13px;width:100%;min-width:0;}\n .ekko-skin-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;}\n .ekko-skin-description{padding:9px;gap:7px;min-width:0;}.ekko-skin-title{gap:4px;flex-wrap:wrap;}.ekko-skin-title h3{font-size:13px;}.ekko-skin-state{font-size:10px;}\n .ekko-skin-button{font-size:12px;padding:6px;min-height:36px;max-width:100%;overflow-wrap:anywhere;}\n .ekko-skin-toolbar{flex-wrap:wrap;min-width:0;}.ekko-skin-options{min-width:0;padding:11px;}.ekko-skin-options .ekko-skin-toolbar h3{font-size:13px;}\n}\n";
165
+
166
+ // work/dsh-plugin-ekko-skin-manager/src/client.jsx
167
+ var inject = ["slots", "theme", "layout"];
168
+ var NAMES = { rose: { zh: "\u6709\u83DC\u73AB\u7470", en: "Arina Rose" }, miku: { zh: "\u521D\u97F3\u672A\u6765", en: "Hatsune Miku" } };
169
+ var COPY = {
170
+ zh: { nav: "Ekko \u76AE\u80A4", title: "\u73AB\u7470\u4E0E\u521D\u97F3", intro: "\u9009\u62E9\u4F60\u7684\u521B\u4F5C\u7A7A\u95F4\uFF1B\u6BCF\u4E2A\u4E3B\u9898\u7684\u88C5\u9970\u504F\u597D\u5206\u522B\u4FDD\u7559\u3002", use: "\u4F7F\u7528", active: "\u5F53\u524D\u4F7F\u7528", switching: "\u6B63\u5728\u5207\u6362\u2026", native: "\u539F\u751F\u754C\u9762", options: "\u4E3B\u9898\u88C5\u9970", artwork: "\u6B22\u8FCE\u9875\u88C5\u9970", companion: "\u5BF9\u8BDD\u4EBA\u7269\u80CC\u666F", polaroid: "\u53F3\u4E0B\u89D2\u7167\u7247", opacity: "\u5BF9\u8BDD\u80CC\u666F\u6D53\u5EA6", reset: "\u6062\u590D\u6B64\u4E3B\u9898\u9ED8\u8BA4", loading: "\u6B63\u5728\u52A0\u8F7D\u4E3B\u9898\u2026", unavailable: "\u53EF\u9009\u4E3B\u9898\uFF0C\u5C1A\u672A\u5B89\u88C5", retry: "\u91CD\u8BD5", loadFailed: "\u76AE\u80A4\u7BA1\u7406\u5668\u6682\u65F6\u65E0\u6CD5\u52A0\u8F7D\uFF0C\u8BF7\u91CD\u8BD5\u3002", materialFailed: "\u4E3B\u9898\u7D20\u6750\u672A\u80FD\u52A0\u8F7D\uFF0C\u8BF7\u91CD\u8BD5\u3002" },
171
+ en: { nav: "Ekko skins", title: "Rose & Miku", intro: "Choose your creative space. Each skin keeps its own appearance preferences.", use: "Use", active: "In use", switching: "Switching\u2026", native: "Native appearance", options: "Artwork preferences", artwork: "Welcome artwork", companion: "Chat character background", polaroid: "Corner photo", opacity: "Chat background opacity", reset: "Reset this skin", loading: "Loading skins\u2026", unavailable: "Optional skin, not installed", retry: "Retry", loadFailed: "Unable to load the skin manager. Please retry.", materialFailed: "Unable to load the skin artwork. Please retry." }
172
+ };
173
+ var language = () => /^zh/i.test(document.documentElement.lang || navigator.language) ? "zh" : "en";
174
+ function apply(ctx) {
175
+ const storage = window.localStorage, imageCache = /* @__PURE__ */ new Map();
176
+ let alive = true, catalog = null, loadError = null, view, preferenceRevision = 0;
177
+ const listeners = /* @__PURE__ */ new Set();
178
+ const prepare = (provider) => Promise.all([...new Set(Object.values(provider.assets))].filter((url) => !url.startsWith("data:")).map((url) => {
179
+ if (!imageCache.has(url)) imageCache.set(url, new Promise((resolve, reject) => {
180
+ const img = new Image(), timer = setTimeout(() => {
181
+ img.onload = img.onerror = null;
182
+ reject(Error(COPY[language()].materialFailed));
183
+ }, 12e3);
184
+ img.onload = () => {
185
+ clearTimeout(timer);
186
+ resolve();
187
+ };
188
+ img.onerror = () => {
189
+ clearTimeout(timer);
190
+ reject(Error(COPY[language()].materialFailed));
191
+ };
192
+ img.src = url;
193
+ }).catch((error) => {
194
+ imageCache.delete(url);
195
+ throw error;
196
+ }));
197
+ return imageCache.get(url);
198
+ }));
199
+ const controller = createController({ storage, prepare, mount(provider) {
200
+ const fiber = ctx.plugin(provider.plugin);
201
+ return { ready: () => fiber.await(), dispose: () => fiber.dispose() };
202
+ } });
203
+ const refresh = () => {
204
+ view = { catalog, error: loadError, presentation: controller.getSnapshot(), preferenceRevision };
205
+ for (const fn of listeners) fn();
206
+ };
207
+ const unsubscribe = controller.subscribe(refresh);
208
+ refresh();
209
+ ctx.provide("ekkoSkins", controller);
210
+ const style = document.createElement("style");
211
+ style.dataset.ekkoSkinManager = "";
212
+ style.textContent = STYLES;
213
+ document.head.append(style);
214
+ async function load() {
215
+ loadError = null;
216
+ refresh();
217
+ try {
218
+ const response = await fetch("./ekko-skins/catalog", { credentials: "same-origin" });
219
+ if (!response.ok) throw Error("catalog");
220
+ const result = await response.json();
221
+ if (!Array.isArray(result.skins)) throw Error("catalog");
222
+ if (!alive) return;
223
+ catalog = result;
224
+ refresh();
225
+ await controller.initialize(result.defaultSkin, result.skins.filter((s) => s.available).map((s) => s.id));
226
+ } catch {
227
+ if (alive) {
228
+ loadError = COPY[language()].loadFailed;
229
+ refresh();
230
+ }
231
+ }
232
+ }
233
+ function setPreference(id, patch) {
234
+ const provider = controller.provider(id);
235
+ if (!provider) return;
236
+ const value = { ...provider.normalizeSettings({ ...provider.readSettings(storage), ...patch }), enabled: true };
237
+ let oldValue;
238
+ try {
239
+ oldValue = storage.getItem(provider.storageKey);
240
+ storage.setItem(provider.storageKey, JSON.stringify(value));
241
+ } catch {
242
+ }
243
+ window.dispatchEvent(new StorageEvent("storage", { key: provider.storageKey, newValue: JSON.stringify(value), oldValue: oldValue || null, storageArea: storage }));
244
+ preferenceRevision++;
245
+ refresh();
246
+ }
247
+ const subscribe = (fn) => {
248
+ listeners.add(fn);
249
+ return () => listeners.delete(fn);
250
+ };
251
+ function Panel() {
252
+ (0, import_react.useEffect)(() => {
253
+ if (innerWidth > 640) return;
254
+ const frame = requestAnimationFrame(() => document.querySelector("[role='dialog'] [class*='_navList'] [class*='_active']")?.scrollIntoView({ block: "nearest", inline: "nearest" }));
255
+ return () => cancelAnimationFrame(frame);
256
+ }, []);
257
+ const state = (0, import_react.useSyncExternalStore)(subscribe, () => view), lang = language(), c = COPY[lang], p = state.presentation;
258
+ const id = p.selected, provider = controller.provider(id), prefs = provider ? provider.readSettings(storage) : null;
259
+ const choose = (target) => {
260
+ void controller.choose(target);
261
+ };
262
+ return /* @__PURE__ */ import_react.default.createElement("section", { className: "ekko-skins", "data-ekko-skin-manager": "", "aria-label": c.nav }, /* @__PURE__ */ import_react.default.createElement("header", { className: "ekko-skins-intro" }, /* @__PURE__ */ import_react.default.createElement("h2", null, c.title), /* @__PURE__ */ import_react.default.createElement("p", null, c.intro)), state.error && /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-error", role: "alert" }, state.error, " ", /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ekko-skin-button", onClick: load }, c.retry)), !state.catalog && !state.error && /* @__PURE__ */ import_react.default.createElement("p", { role: "status" }, c.loading), /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-grid" }, ["rose", "miku"].map((skin) => {
263
+ const entry = state.catalog?.skins.find((s) => s.id === skin), name = NAMES[skin][lang], active = id === skin, available = entry?.available && p.available.includes(skin);
264
+ return /* @__PURE__ */ import_react.default.createElement("article", { key: skin, className: "ekko-skin-card", "data-active": active }, entry?.preview && /* @__PURE__ */ import_react.default.createElement("img", { className: "ekko-skin-cover", src: entry.preview[document.body.hasAttribute("data-ds-dark-theme") ? "dark" : "light"], alt: name, loading: "lazy" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-description" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-title" }, /* @__PURE__ */ import_react.default.createElement("h3", null, name), active && /* @__PURE__ */ import_react.default.createElement("span", { className: "ekko-skin-state" }, c.active)), /* @__PURE__ */ import_react.default.createElement("span", { className: "ekko-skin-version" }, entry?.version ? "v" + entry.version : c.unavailable), /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ekko-skin-button", "data-active": active, disabled: !available || active || p.busy, onClick: () => choose(skin) }, p.busy && p.desired === skin ? c.switching : active ? c.active : c.use + " " + name)));
265
+ })), /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-toolbar" }, /* @__PURE__ */ import_react.default.createElement("span", null, p.busy ? c.switching : id === "default" ? c.native : NAMES[id]?.[lang]), /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ekko-skin-button", disabled: id === "default" || p.busy, onClick: () => choose("default") }, c.native)), p.error && /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-error", role: "alert" }, p.error, /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ekko-skin-button", onClick: () => choose(p.desired) }, c.retry)), prefs && /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-options" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "ekko-skin-toolbar" }, /* @__PURE__ */ import_react.default.createElement("h3", null, NAMES[id][lang], " \xB7 ", c.options), /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "ekko-skin-button", disabled: p.busy, onClick: () => setPreference(id, { artwork: true, companion: true, polaroid: true, opacity: 0.12 }) }, c.reset)), ["artwork", "companion", "polaroid"].map((key) => /* @__PURE__ */ import_react.default.createElement("label", { className: "ekko-skin-option", key }, /* @__PURE__ */ import_react.default.createElement("span", null, c[key]), /* @__PURE__ */ import_react.default.createElement("input", { type: "checkbox", checked: prefs[key], disabled: p.busy, onChange: (e) => setPreference(id, { [key]: e.target.checked }) }))), /* @__PURE__ */ import_react.default.createElement("label", { className: "ekko-skin-option" }, /* @__PURE__ */ import_react.default.createElement("span", null, c.opacity, /* @__PURE__ */ import_react.default.createElement("small", null, Math.round(prefs.opacity * 100), "%")), /* @__PURE__ */ import_react.default.createElement("input", { type: "range", min: ".04", max: ".24", step: ".01", value: prefs.opacity, disabled: p.busy, onChange: (e) => setPreference(id, { opacity: Number(e.target.value) }) }))));
266
+ }
267
+ function registerSection() {
268
+ return ctx.slots.inject("settings.section", () => ctx.slots.register({ name: "settings.section", id: "ekko-skins", order: 115, label: () => COPY[language()].nav }, Panel));
269
+ }
270
+ let section = registerSection();
271
+ const locale = new MutationObserver(() => {
272
+ section?.();
273
+ section = registerSection();
274
+ refresh();
275
+ });
276
+ locale.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
277
+ const appearance = new MutationObserver(refresh);
278
+ appearance.observe(document.body, { attributes: true, attributeFilter: ["data-ds-dark-theme"] });
279
+ const onStorage = (e) => {
280
+ if (e.key === SELECTION_KEY) void controller.choose(readSelection(storage, catalog?.defaultSkin), { persist: false });
281
+ if (e.key?.startsWith("dsh:ekko-")) {
282
+ preferenceRevision++;
283
+ refresh();
284
+ }
285
+ };
286
+ const onPreferences = () => {
287
+ preferenceRevision++;
288
+ refresh();
289
+ };
290
+ window.addEventListener("storage", onStorage);
291
+ window.addEventListener("dsh:ekko-skin-preferences", onPreferences);
292
+ void load();
293
+ ctx.effect(() => async () => {
294
+ alive = false;
295
+ section?.();
296
+ locale.disconnect();
297
+ appearance.disconnect();
298
+ window.removeEventListener("storage", onStorage);
299
+ window.removeEventListener("dsh:ekko-skin-preferences", onPreferences);
300
+ unsubscribe();
301
+ await controller.dispose();
302
+ style.remove();
303
+ listeners.clear();
304
+ imageCache.clear();
305
+ }, "ekko-skins: controller, section and presentation cleanup");
306
+ }
307
+
308
+ return module.exports;}});
package/lib/index.js ADDED
@@ -0,0 +1,90 @@
1
+ // work/dsh-plugin-ekko-skin-manager/src/index.mjs
2
+ import { readFile } from "node:fs/promises";
3
+ import { createRequire } from "node:module";
4
+ import { createHash } from "node:crypto";
5
+ import { dirname, join } from "node:path";
6
+ import { pathToFileURL } from "node:url";
7
+ var require2 = createRequire(import.meta.url);
8
+ var PREFIX = "/ekko-skins";
9
+ var PACKAGES = { rose: "dsh-plugin-rose-theme", miku: "dsh-plugin-miku-theme" };
10
+ function createHandler({ resolvePackage = (name) => dirname(require2.resolve(name + "/package.json")), defaultSkin = "miku" } = {}) {
11
+ async function catalog() {
12
+ const skins = [];
13
+ for (const [id, pkg] of Object.entries(PACKAGES)) {
14
+ try {
15
+ const root = resolvePackage(pkg), meta = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
16
+ skins.push({ id, version: meta.version, available: meta.dsh?.ekkoSkinProvider === 1, preview: { light: "./ekko-skins/preview/" + id + "/light.webp", dark: "./ekko-skins/preview/" + id + "/dark.webp" } });
17
+ } catch {
18
+ skins.push({ id, available: false });
19
+ }
20
+ }
21
+ const installed = skins.filter((s) => s.available).map((s) => s.id);
22
+ const preferred = ["rose", "miku", "default"].includes(defaultSkin) ? defaultSkin : "miku";
23
+ const selected = preferred === "default" || installed.includes(preferred) ? preferred : installed[0] || "default";
24
+ return { version: "0.1.3", defaultSkin: selected, skins };
25
+ }
26
+ return async (req, res) => {
27
+ if (!["GET", "HEAD"].includes(req.method)) {
28
+ res.writeHead(405, { Allow: "GET, HEAD" }).end();
29
+ return;
30
+ }
31
+ const pathname = new URL(req.url || "/", "http://localhost").pathname;
32
+ if (pathname === PREFIX + "/catalog") {
33
+ const bytes2 = Buffer.from(JSON.stringify(await catalog()));
34
+ res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store", "Content-Length": bytes2.length, "X-Content-Type-Options": "nosniff" });
35
+ res.end(req.method === "HEAD" ? void 0 : bytes2);
36
+ return;
37
+ }
38
+ const match = /^\/ekko-skins\/(assets|preview)\/(rose|miku)\/([a-z0-9.-]+)$/.exec(pathname);
39
+ if (!match) {
40
+ res.writeHead(404).end();
41
+ return;
42
+ }
43
+ const [, kind, id, file] = match;
44
+ let bytes;
45
+ try {
46
+ const root = resolvePackage(PACKAGES[id]);
47
+ if (kind === "assets") {
48
+ if (!/^[a-f0-9]{64}\.(webp|png|svg|woff2)$/.test(file)) {
49
+ res.writeHead(404).end();
50
+ return;
51
+ }
52
+ const manifest = JSON.parse(await readFile(join(root, "assets/manifest.json"), "utf8"));
53
+ if (!Object.values(manifest).includes(file)) {
54
+ res.writeHead(404).end();
55
+ return;
56
+ }
57
+ bytes = await readFile(join(root, "assets/runtime", file));
58
+ } else {
59
+ if (!["light.webp", "dark.webp"].includes(file)) {
60
+ res.writeHead(404).end();
61
+ return;
62
+ }
63
+ bytes = await readFile(join(root, "preview", file));
64
+ }
65
+ } catch {
66
+ res.writeHead(404).end();
67
+ return;
68
+ }
69
+ const etag = '"' + createHash("sha256").update(bytes).digest("hex") + '"';
70
+ const type = file.endsWith(".svg") ? "image/svg+xml" : file.endsWith(".png") ? "image/png" : file.endsWith(".woff2") ? "font/woff2" : "image/webp";
71
+ const headers = { "Content-Type": type, "Cache-Control": kind === "assets" ? "public, max-age=31536000, immutable" : "no-cache", ETag: etag, "X-Content-Type-Options": "nosniff", "Cross-Origin-Resource-Policy": "same-origin" };
72
+ if (req.headers["if-none-match"] === etag) {
73
+ res.writeHead(304, headers).end();
74
+ return;
75
+ }
76
+ res.writeHead(200, { ...headers, "Content-Length": bytes.length });
77
+ res.end(req.method === "HEAD" ? void 0 : bytes);
78
+ };
79
+ }
80
+ function apply(ctx, config = {}) {
81
+ ctx.inject(["webServer", "profileContext"], (child) => {
82
+ const resolver = createRequire(pathToFileURL(join(child.get("profileContext").dir, "package.json")));
83
+ child.effect(() => child.get("webServer").register({ kind: "prefix", path: PREFIX, handler: createHandler({ defaultSkin: config.defaultSkin, resolvePackage: (name) => dirname(resolver.resolve(name + "/package.json")) }) }));
84
+ });
85
+ }
86
+ export {
87
+ PREFIX,
88
+ apply,
89
+ createHandler
90
+ };