dsh-ccx 0.0.0-stage → 0.8.9
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/NOTICE +23 -0
- package/README.md +142 -2
- package/assets/icon.svg +27 -0
- package/assets/preview-home.png +0 -0
- package/assets/preview-market.png +0 -0
- package/assets/preview-milkyway.png +0 -0
- package/assets/preview-mountain.png +0 -0
- package/assets/preview-settings.png +0 -0
- package/assets/preview-surface.png +0 -0
- package/assets/scene-aurora-ionosphere.png +0 -0
- package/assets/scene-black-hole.png +0 -0
- package/assets/scene-blinking-squares.png +0 -0
- package/assets/scene-cloud-train.png +0 -0
- package/assets/scene-glow-horizon.png +0 -0
- package/assets/scene-heavenly-cloud.png +0 -0
- package/assets/scene-milky-way.png +0 -0
- package/assets/scene-mountain.png +0 -0
- package/assets/scene-particle-image.png +0 -0
- package/assets/scene-pixel-sculpt.png +0 -0
- package/cordis.patch.yml +16 -0
- package/lib/client.js +2244 -0
- package/lib/index.js +512 -0
- package/lib/vendor/code-codex/aurora-ionosphere.js +441 -0
- package/lib/vendor/code-codex/black-hole.js +640 -0
- package/lib/vendor/code-codex/blinking-squares.js +408 -0
- package/lib/vendor/code-codex/cloud-train.js +626 -0
- package/lib/vendor/code-codex/galleries.json +101 -0
- package/lib/vendor/code-codex/glow-horizon.js +260 -0
- package/lib/vendor/code-codex/heavenly-cloud.js +358 -0
- package/lib/vendor/code-codex/milky-way.js +303 -0
- package/lib/vendor/code-codex/mountain.js +335 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-image-098c5fbaa5c415ec.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-image-39894de0da1fa952.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-image-6447780fc6368ce2.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-image-746ff537a0eca39e.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-image-89d064cef83721eb.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-image-e1c658aa459cfcef.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-thumbnail-098c5fbaa5c415ec.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-thumbnail-39894de0da1fa952.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-thumbnail-6447780fc6368ce2.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-thumbnail-746ff537a0eca39e.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-thumbnail-89d064cef83721eb.png +0 -0
- package/lib/vendor/code-codex/particle-image/media/CodeCodex-background-particle-image-thumbnail-e1c658aa459cfcef.png +0 -0
- package/lib/vendor/code-codex/particle-image.js +678 -0
- package/lib/vendor/code-codex/pixel-sculpt/media/CodeCodex-background-pixel-sculpt-image-079ae375628c240b.png +0 -0
- package/lib/vendor/code-codex/pixel-sculpt/media/CodeCodex-background-pixel-sculpt-image-0e0ec1222ff7a1bc.png +0 -0
- package/lib/vendor/code-codex/pixel-sculpt/media/CodeCodex-background-pixel-sculpt-image-3fde0595509bc4d5.png +0 -0
- package/lib/vendor/code-codex/pixel-sculpt.js +358 -0
- package/lib/vendor/code-codex/scene-defaults.json +215 -0
- package/lib/vendor/code-codex/scene-schemas.json +1957 -0
- package/package.json +57 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,2244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-ccx —— 客户端半边(浏览器 bundle)v0.3。
|
|
3
|
+
*
|
|
4
|
+
* 手写、零打包器、零新增依赖(样板照 @dsh-external/dsh-blender-plugin 的
|
|
5
|
+
* lib/client.js:window.__ModuleLoader__.load({ id, factory }))。
|
|
6
|
+
*
|
|
7
|
+
* v0.3 起效果对齐 code-codex 原仓库(github.com/Rice-dog/code-codex,MIT):
|
|
8
|
+
* ① 背景场景 —— 原仓库首方场景渲染器原样 vendor(lib/vendor/code-codex/,
|
|
9
|
+
* 经宿主 /dsh-appearances/vendor/<id>.js 下发)。渲染器自注册在
|
|
10
|
+
* window[Symbol.for("code-codex:background-modules:v1")],startup(元素, settings)
|
|
11
|
+
* 自包含运行(自带 Resize/可见性/掉上下文/reduced-motion 处理),本文件只管
|
|
12
|
+
* 生命周期:懒加载 → startup → updateSettings → dispose。
|
|
13
|
+
* ② UI 表面 —— 原仓库同一套两层做法:
|
|
14
|
+
* a) transparent-background 式通配透明(body 下全部结构元素背景/背滤清零);
|
|
15
|
+
* b) surface-opacity 式分区蒙版:DSH 的稳定 data-slot 钩子(sidebar / main /
|
|
16
|
+
* rightbar / conversation.header / conversation.input.dock)各自一块
|
|
17
|
+
* rgba(底色, var(--ap-mask-*)) 蒙版,区域不透明度 0–100% 独立可调。
|
|
18
|
+
* 不再使用 overrideTokens(v0.2 方案,效果不对)。
|
|
19
|
+
* ③ 壁纸 —— 本地图片/视频导入(host 路由),画在场景层同位。
|
|
20
|
+
* ④ 设置面板 —— Shadow DOM:实时预览舞台(同渲染器跑在 640×360 小盒里)、
|
|
21
|
+
* 场景卡、素材库分页、双语参数网格、分区蒙版滑杆;Esc/外点关闭。
|
|
22
|
+
*
|
|
23
|
+
* 约束(沿用 whale-widget 的教训):theme 等可选服务绝不进 exports.inject;
|
|
24
|
+
* 不注册消耗型全局监听;卸载全部资源经 ctx.effect 清理。
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
window.__ModuleLoader__.load({
|
|
28
|
+
id: "dsh-ccx",
|
|
29
|
+
factory: function (require) {
|
|
30
|
+
var module = { exports: {} };
|
|
31
|
+
var exports = module.exports;
|
|
32
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
33
|
+
|
|
34
|
+
// ─────────────────────────── 常量 ───────────────────────────
|
|
35
|
+
|
|
36
|
+
var PLUGIN_ID = "dsh-ccx";
|
|
37
|
+
var LAYER_ID = "dsh-ap-layer";
|
|
38
|
+
var DIM_ID = "dsh-ap-dim";
|
|
39
|
+
var TRIGGER_ID = "dsh-ap-trigger";
|
|
40
|
+
var PANEL_ID = "dsh-ap-panel";
|
|
41
|
+
var API_BASE = "/dsh-appearances";
|
|
42
|
+
var BG_STYLE_ID = "dsh-ap-surface-style";
|
|
43
|
+
var REGISTRY_SYM = Symbol.for("code-codex:background-modules:v1");
|
|
44
|
+
|
|
45
|
+
// 原仓库首方场景(lib/vendor/code-codex/,MIT)—— 全部 10 种动态背景
|
|
46
|
+
var SCENES = [
|
|
47
|
+
{ id: "milky-way", label: "银河", en: "Milky Way", swatch: "linear-gradient(135deg,#1b0f2e,#5a2a84 45%,#d81159 75%,#fbb13c)" },
|
|
48
|
+
{ id: "glow-horizon", label: "辉光地平线", en: "Glow Horizon", swatch: "linear-gradient(180deg,#05060a 55%,#3b0d3a 72%,#d81159 88%,#fbb13c 97%)" },
|
|
49
|
+
{ id: "mountain", label: "层峦", en: "Layered Mountain", swatch: "linear-gradient(180deg,#0b1026 40%,#274690 62%,#0c1440 78%,#05070f)" },
|
|
50
|
+
{ id: "heavenly-cloud", label: "云穹", en: "Heavenly Cloud", swatch: "linear-gradient(135deg,#07101f,#123a5c 50%,#7fd4e8 85%,#e8f6ff)" },
|
|
51
|
+
{ id: "aurora-ionosphere", label: "极光电离层", en: "Aurora Ionosphere", swatch: "linear-gradient(180deg,#020610 30%,#062f3a 60%,#2ee6a8 82%,#a4f9e0)" },
|
|
52
|
+
{ id: "black-hole", label: "黑洞", en: "Black Hole", swatch: "radial-gradient(circle at 50% 52%,#000 6%,#ff9a3c 16%,#7a2d0c 30%,#05070f 62%)" },
|
|
53
|
+
{ id: "cloud-train", label: "云列车", en: "Cloud Train", swatch: "linear-gradient(180deg,#05070d 35%,#123049 60%,#3f7fae 82%,#c8e6f5)" },
|
|
54
|
+
{ id: "particle-image", label: "粒子成像", en: "Particle Image", swatch: "conic-gradient(from 210deg at 50% 50%,#0b0e17,#3d5a99 30%,#8fb7ff 55%,#0b0e17 80%)" },
|
|
55
|
+
{ id: "pixel-sculpt", label: "像素雕塑", en: "Pixel Sculpt", swatch: "conic-gradient(from 30deg at 50% 50%,#101423,#274690 35%,#9be1ff 60%,#101423 85%)" },
|
|
56
|
+
{ id: "blinking-squares", label: "闪烁方块", en: "Blinking Squares", swatch: "conic-gradient(from 45deg,#0d1420,#1f3a5c 25%,#4fd1c5 50%,#0d1420 75%)" },
|
|
57
|
+
];
|
|
58
|
+
var SCENE_IDS = SCENES.map(function (s) { return s.id; });
|
|
59
|
+
var GALLERIES_SYM = Symbol.for("code-codex:default-galleries:v1");
|
|
60
|
+
var GALLERY_SCENES = { "particle-image": true, "pixel-sculpt": true };
|
|
61
|
+
|
|
62
|
+
// DSH 真实绘制容器(v0.8.3 实机普查:data-slot 标记全是 0×0 隐形锚点,直接上色无视觉;
|
|
63
|
+
// 槽位的「直接父级」才是带底色的布局列,用 :has(> [data-slot]) 稳定命中,不依赖
|
|
64
|
+
// css-module 哈希类名)。base 对齐原版 inject.ts 两档表面色:
|
|
65
|
+
// 主区/输入区 rgba(11,12,15)、侧栏 rgba(16,17,20)。
|
|
66
|
+
// 无「标题栏」分区:DSH 顶条在中央列内、无独立绘制面(原生 0–40px 是 OS 菜单栏,不可达)。
|
|
67
|
+
var REGION_ROWS = [
|
|
68
|
+
{ key: "sidebar", zh: "会话侧栏", en: "Sidebar", selector: 'div:has(> [data-slot="sidebar"])', base: "16,17,20" },
|
|
69
|
+
{ key: "conversation", zh: "对话区", en: "Conversation", selector: 'div:has(> [data-slot="main"])', base: "11,12,15" },
|
|
70
|
+
// 输入面板本体 = Codinput 的卡片钩子(normal/悬浮/侧栏三形态都跟随卡片)。
|
|
71
|
+
// 不能兜底涂输入槽位的父级容器——那是全宽 stack,蒙版会比可见面板大一圈;
|
|
72
|
+
// 无 Codinput 时该区无独立蒙版,由对话区蒙版兜底
|
|
73
|
+
{ key: "composer", zh: "消息输入区", en: "Composer", selector: '[data-composer-card]', base: "11,12,15" },
|
|
74
|
+
{ key: "right", zh: "右侧栏", en: "Right panel", selector: 'div:has(> [data-slot="rightbar"])', base: "16,17,20" },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
// 与宿主半侧 lib/index.js 的 DEFAULT_SETTINGS 保持一致
|
|
78
|
+
// 蒙版默认:侧栏 .66、对话 .58、输入 .86(原版 surface-opacity 面板 composer 档,
|
|
79
|
+
// 输入面板默认不透);右侧栏收起时 0 宽不可见,展开即生效
|
|
80
|
+
var DEFAULTS = {
|
|
81
|
+
version: 6,
|
|
82
|
+
enabled: true,
|
|
83
|
+
mode: "scene",
|
|
84
|
+
scene: "milky-way",
|
|
85
|
+
wallpaperId: null,
|
|
86
|
+
wallpaperFit: "cover",
|
|
87
|
+
wallpaperPosition: "center",
|
|
88
|
+
surfaces: { enabled: true, sidebar: 66, conversation: 58, composer: 86, right: 66 },
|
|
89
|
+
sceneParams: {},
|
|
90
|
+
dim: 0,
|
|
91
|
+
blur: 0,
|
|
92
|
+
savedAt: 0,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
var SCHEMAS = null; // 每场景设置 schema(宿主 /scene-schemas.json,原版抽屉字段)
|
|
96
|
+
var schemaPromise = null;
|
|
97
|
+
|
|
98
|
+
function ensureSchemas() {
|
|
99
|
+
if (SCHEMAS) return Promise.resolve(SCHEMAS);
|
|
100
|
+
if (!schemaPromise) {
|
|
101
|
+
schemaPromise = apiGet("/scene-schemas.json").then(function (s) {
|
|
102
|
+
SCHEMAS = s && typeof s === "object" ? s : {};
|
|
103
|
+
// schema 就绪后重渲染设置面板(首屏可能在 schema 到达前就打开了面板)
|
|
104
|
+
if (settingsOpen && settingsId && SCENE_IDS.indexOf(settingsId) >= 0) renderSettings(settingsId);
|
|
105
|
+
return SCHEMAS;
|
|
106
|
+
}).catch(function () {
|
|
107
|
+
schemaPromise = null;
|
|
108
|
+
return {};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return schemaPromise;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function schemaOf(sceneId) {
|
|
115
|
+
return SCHEMAS && SCHEMAS[sceneId] ? SCHEMAS[sceneId] : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 场景 store 的完整设置:schema 默认值 + 用户覆盖(state.sceneParams[scene])
|
|
119
|
+
// 画廊选型键(selectedImageIds/activeImageId)归 vendor/图库自有:prepareDefaults
|
|
120
|
+
// 首次导入时写入。非用户显式设置不得进 patch,否则空默认值经合并写会把选型清掉
|
|
121
|
+
// (渲染器启动判定 activeImageId||selectedImageIds 非空,清掉即「启动无源图」)
|
|
122
|
+
var GALLERY_OWNED_KEYS = { selectedImageIds: 1, activeImageId: 1 };
|
|
123
|
+
function buildStoreSettings(sceneId) {
|
|
124
|
+
var sch = schemaOf(sceneId);
|
|
125
|
+
var base = sch && sch.defaults ? Object.assign({}, sch.defaults) : {};
|
|
126
|
+
var overrides = state && state.sceneParams && state.sceneParams[sceneId];
|
|
127
|
+
if (overrides && typeof overrides === "object") {
|
|
128
|
+
for (var k in overrides) {
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(overrides, k)) base[k] = overrides[k];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (GALLERY_SCENES[sceneId]) {
|
|
133
|
+
for (var gk in GALLERY_OWNED_KEYS) {
|
|
134
|
+
if (!(overrides && Object.prototype.hasOwnProperty.call(overrides, gk))) delete base[gk];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return base;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var state = null; // 当前生效设置(宿主持久化副本)
|
|
141
|
+
var savedAtLocal = 0; // 本端已采纳的 savedAt(自己的保存回包也会更新它)
|
|
142
|
+
var saveTimer = null;
|
|
143
|
+
var pollTimer = null;
|
|
144
|
+
|
|
145
|
+
// ─────────────────────── 小工具 ───────────────────────
|
|
146
|
+
|
|
147
|
+
function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)); }
|
|
148
|
+
function num(v, dflt) { var n = Number(v); return Number.isFinite(n) ? n : dflt; }
|
|
149
|
+
|
|
150
|
+
function apiGet(path) {
|
|
151
|
+
return fetch(API_BASE + path, { credentials: "omit" }).then(function (r) {
|
|
152
|
+
if (!r.ok) throw new Error("HTTP " + r.status);
|
|
153
|
+
return r.json();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function apiPostJson(path, payload) {
|
|
157
|
+
return fetch(API_BASE + path, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
credentials: "omit",
|
|
160
|
+
headers: { "Content-Type": "application/json" },
|
|
161
|
+
body: JSON.stringify(payload),
|
|
162
|
+
}).then(function (r) { return r.json(); });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ─────────────────────── 背景层(对齐原仓库 layer 做法) ───────────────────────
|
|
166
|
+
|
|
167
|
+
var layer = null; // fixed 全屏层(body 首子节点,z-index:-1)
|
|
168
|
+
var bgWrap = null; // filter(blur/saturate)作用层
|
|
169
|
+
var bgHost = null; // 场景渲染器/壁纸的父容器
|
|
170
|
+
var dimEl = null; // 压暗层
|
|
171
|
+
var bgInstance = null; // 当前原版渲染器实例
|
|
172
|
+
var bgSceneId = null; // bgInstance 对应的场景 id(防竞态)
|
|
173
|
+
var vendorScripts = {}; // 已注入的 <script>(按场景 id)
|
|
174
|
+
|
|
175
|
+
function ensureLayer() {
|
|
176
|
+
if (layer && document.body && document.body.contains(layer)) return;
|
|
177
|
+
layer = document.createElement("div");
|
|
178
|
+
layer.id = LAYER_ID;
|
|
179
|
+
layer.setAttribute("data-dsh-ccx", "background");
|
|
180
|
+
layer.style.cssText = "position:fixed;inset:0;z-index:-1;pointer-events:none;overflow:hidden;"
|
|
181
|
+
+ "width:100vw;height:100vh;margin:0;padding:0;contain:strict;background:#000;--ap-layer-bg:#000;";
|
|
182
|
+
bgWrap = document.createElement("div");
|
|
183
|
+
bgWrap.style.cssText = "position:absolute;inset:0;overflow:hidden;";
|
|
184
|
+
bgHost = document.createElement("div");
|
|
185
|
+
bgHost.style.cssText = "position:absolute;inset:0;";
|
|
186
|
+
dimEl = document.createElement("div");
|
|
187
|
+
dimEl.id = DIM_ID;
|
|
188
|
+
dimEl.style.cssText = "position:absolute;inset:0;background:transparent;--ap-dim-bg:transparent;";
|
|
189
|
+
bgWrap.appendChild(bgHost);
|
|
190
|
+
layer.appendChild(bgWrap);
|
|
191
|
+
layer.appendChild(dimEl);
|
|
192
|
+
var body = document.body || document.documentElement;
|
|
193
|
+
body.prepend(layer); // 原仓库同款:body 首子节点
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ─────────────────── 原版场景渲染器生命周期 ───────────────────
|
|
197
|
+
|
|
198
|
+
// 各场景设置存储键(渲染器自己从 localStorage 读,合并内置默认值;
|
|
199
|
+
// 宿主契约 startup(target, onError) 不传设置——第二参是错误回调)
|
|
200
|
+
var STORE_KEYS = {
|
|
201
|
+
"milky-way": "code-codex:milky-way-background:v1",
|
|
202
|
+
"glow-horizon": "code-codex:glow-horizon-background:v1",
|
|
203
|
+
"mountain": "code-codex:mountain-settings:v1",
|
|
204
|
+
"heavenly-cloud": "code-codex:heavenly-cloud-background:v1",
|
|
205
|
+
"aurora-ionosphere": "code-codex:aurora-ionosphere-background:v1",
|
|
206
|
+
"black-hole": "code-codex:black-hole-background:v1",
|
|
207
|
+
"cloud-train": "code-codex:cloud-train-settings:v1",
|
|
208
|
+
"blinking-squares": "code-codex:blinking-squares-background:v1",
|
|
209
|
+
"particle-image": "code-codex:particle-image-background:v1",
|
|
210
|
+
"pixel-sculpt": "code-codex:pixel-sculpt-settings:v1",
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
function writeSceneSetting(sceneId, patch) {
|
|
214
|
+
var key = STORE_KEYS[sceneId];
|
|
215
|
+
if (!key) return;
|
|
216
|
+
try {
|
|
217
|
+
var cur = {};
|
|
218
|
+
try { cur = JSON.parse(localStorage.getItem(key) ?? "{}") || {}; } catch (e) {}
|
|
219
|
+
localStorage.setItem(key, JSON.stringify(Object.assign({}, cur, patch)));
|
|
220
|
+
} catch (e) {}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 各场景原版层底色(来自上游 plugin-host/backgrounds/* 控制器逐字照抄;
|
|
224
|
+
// blinking-squares / particle-image 用其设置的 backgroundColor,缺省 #000)
|
|
225
|
+
var SCENE_LAYER_BG = {
|
|
226
|
+
"milky-way": "#02090d",
|
|
227
|
+
"aurora-ionosphere": "#02090d",
|
|
228
|
+
"cloud-train": "#02090d",
|
|
229
|
+
"mountain": "#02090d",
|
|
230
|
+
"pixel-sculpt": "#02090d",
|
|
231
|
+
"heavenly-cloud": "#020408",
|
|
232
|
+
"black-hole": "#000000",
|
|
233
|
+
"glow-horizon": "#050507",
|
|
234
|
+
"blinking-squares": "#000000",
|
|
235
|
+
"particle-image": "#000000",
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// 层底色取值:particle-image 的「背景」颜色控件(settings.backgroundColor)实时覆盖
|
|
239
|
+
function sceneLayerBg(id) {
|
|
240
|
+
if (id === "particle-image") {
|
|
241
|
+
var s = state && state.sceneParams && state.sceneParams["particle-image"];
|
|
242
|
+
var c = s && typeof s.backgroundColor === "string" ? s.backgroundColor : null;
|
|
243
|
+
if (c && /^#[\da-fA-F]{6}$/.test(c)) return c;
|
|
244
|
+
}
|
|
245
|
+
return SCENE_LAYER_BG[id] || "#000";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
// particle-image / pixel-sculpt 需要"默认画廊":宿主在 Codex 里由
|
|
250
|
+
// explorer-ui 塞进 window[default-galleries],这里按索引 JSON 自行播种
|
|
251
|
+
// (entry 形状见原仓库 Pt():{count,version,images:Map<id,{data,thumbnail(base64),size,sha256,...}>})
|
|
252
|
+
var galleryPromises = {};
|
|
253
|
+
function ensureGallery(id) {
|
|
254
|
+
if (galleryPromises[id]) return galleryPromises[id];
|
|
255
|
+
galleryPromises[id] = apiGet("/vendor-galleries.json").then(function (index) {
|
|
256
|
+
var meta = index && index[id];
|
|
257
|
+
if (!meta) throw new Error("gallery index missing: " + id);
|
|
258
|
+
return Promise.all(meta.images.map(function (img) {
|
|
259
|
+
var load = function (file) {
|
|
260
|
+
return fetch(API_BASE + "/vendor-media?file=" + encodeURIComponent(file))
|
|
261
|
+
.then(function (r) {
|
|
262
|
+
if (!r.ok) throw new Error("media HTTP " + r.status);
|
|
263
|
+
return r.arrayBuffer();
|
|
264
|
+
})
|
|
265
|
+
.then(function (buf) {
|
|
266
|
+
var bytes = new Uint8Array(buf);
|
|
267
|
+
var bin = "";
|
|
268
|
+
var chunk = 0x8000;
|
|
269
|
+
for (var i = 0; i < bytes.length; i += chunk) {
|
|
270
|
+
bin += String.fromCharCode.apply(null, bytes.subarray(i, i + chunk));
|
|
271
|
+
}
|
|
272
|
+
return btoa(bin);
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
return load(img.dataFile).then(function (dataB64) {
|
|
276
|
+
var entry = {
|
|
277
|
+
id: img.id, name: img.name, type: img.type, size: img.size,
|
|
278
|
+
sha256: img.sha256, data: dataB64, createdAt: img.createdAt || 0,
|
|
279
|
+
};
|
|
280
|
+
if (img.thumbFile) {
|
|
281
|
+
return load(img.thumbFile).then(function (tB64) {
|
|
282
|
+
entry.thumbnail = tB64;
|
|
283
|
+
return entry;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return entry;
|
|
287
|
+
});
|
|
288
|
+
})).then(function (entries) {
|
|
289
|
+
var images = new Map();
|
|
290
|
+
for (var i = 0; i < entries.length; i++) images.set(entries[i].id, entries[i]);
|
|
291
|
+
var reg = window[GALLERIES_SYM] = window[GALLERIES_SYM] || new Map();
|
|
292
|
+
reg.set(id, { count: meta.count, version: meta.version, images: images });
|
|
293
|
+
return true;
|
|
294
|
+
});
|
|
295
|
+
}).catch(function (err) {
|
|
296
|
+
delete galleryPromises[id]; // 允许重试
|
|
297
|
+
throw err;
|
|
298
|
+
});
|
|
299
|
+
return galleryPromises[id];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function registry() {
|
|
303
|
+
return window[REGISTRY_SYM] || null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 画廊选型补种:上游只在「全新图库导入」那一刻写 selectedImageIds/activeImageId;
|
|
307
|
+
// 历史版本曾用空默认值覆盖过 store,这里对「store 缺选型但 IndexedDB 有图」的场景
|
|
308
|
+
// 按上游 fresh 语义重建默认选型(幂等,仅补空;DB 不存在直接放弃,不建库)
|
|
309
|
+
function ensureGallerySelection(id) {
|
|
310
|
+
if (id !== "particle-image") return Promise.resolve(null);
|
|
311
|
+
return new Promise(function (resolve) {
|
|
312
|
+
var key = STORE_KEYS[id];
|
|
313
|
+
var DB = "code-codex-particle-image-background";
|
|
314
|
+
var done = false;
|
|
315
|
+
function finish() { if (!done) { done = true; resolve(null); } }
|
|
316
|
+
function looksSelected(s) {
|
|
317
|
+
return !!(s && ((s.selectedImageIds && s.selectedImageIds.length) || s.activeImageId));
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
if (looksSelected((function () { try { return JSON.parse(localStorage.getItem(key) || "{}"); } catch (e) { return null; } })())) { finish(); return; }
|
|
321
|
+
var req = indexedDB.open(DB);
|
|
322
|
+
req.onupgradeneeded = function () { // 库不存在:不替 vendor 建库
|
|
323
|
+
try { if (req.transaction) req.transaction.abort(); } catch (e) {}
|
|
324
|
+
finish();
|
|
325
|
+
};
|
|
326
|
+
req.onsuccess = function () {
|
|
327
|
+
var db = req.result;
|
|
328
|
+
var wrapped = false;
|
|
329
|
+
function closeDb() { try { db.close(); } catch (e) {} }
|
|
330
|
+
try {
|
|
331
|
+
var rq = db.transaction("images", "readonly").objectStore("images").getAll();
|
|
332
|
+
rq.onsuccess = function () {
|
|
333
|
+
closeDb();
|
|
334
|
+
if (wrapped) return; wrapped = true;
|
|
335
|
+
var rows = (rq.result || []).filter(function (r) {
|
|
336
|
+
return r && r.id !== "__codeCodex_default_media_v1__" && (r.blob || r.file);
|
|
337
|
+
});
|
|
338
|
+
if (!rows.length) { finish(); return; }
|
|
339
|
+
rows.sort(function (a, b) { return (a.createdAt || 0) - (b.createdAt || 0); });
|
|
340
|
+
var cur = {};
|
|
341
|
+
try { cur = JSON.parse(localStorage.getItem(key) || "{}") || {}; } catch (e) {}
|
|
342
|
+
if (looksSelected(cur)) { finish(); return; }
|
|
343
|
+
cur.selectedImageIds = rows.map(function (r) { return r.id; });
|
|
344
|
+
cur.activeImageId = rows[0].id;
|
|
345
|
+
try { localStorage.setItem(key, JSON.stringify(cur)); } catch (e) {}
|
|
346
|
+
finish();
|
|
347
|
+
};
|
|
348
|
+
rq.onerror = function () { closeDb(); if (!wrapped) { wrapped = true; finish(); } };
|
|
349
|
+
} catch (e) { closeDb(); finish(); }
|
|
350
|
+
};
|
|
351
|
+
req.onerror = function () { finish(); };
|
|
352
|
+
req.onblocked = function () { finish(); };
|
|
353
|
+
setTimeout(finish, 3000); // 兜底:不让选型修复阻塞场景启动
|
|
354
|
+
} catch (e) { finish(); }
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 懒加载 vendor 场景脚本 → 返回注册表条目({startup,...})
|
|
359
|
+
function ensureVendorScene(id) {
|
|
360
|
+
return new Promise(function (resolve, reject) {
|
|
361
|
+
var reg = registry();
|
|
362
|
+
if (reg && reg.get(id)) { resolve(reg.get(id)); return; }
|
|
363
|
+
var tag = vendorScripts[id];
|
|
364
|
+
if (!tag) {
|
|
365
|
+
tag = document.createElement("script");
|
|
366
|
+
tag.src = API_BASE + "/vendor/" + id + ".js";
|
|
367
|
+
tag.onerror = function () { delete vendorScripts[id]; reject(new Error("vendor script load failed: " + id)); };
|
|
368
|
+
(document.head || document.documentElement).appendChild(tag);
|
|
369
|
+
vendorScripts[id] = tag;
|
|
370
|
+
}
|
|
371
|
+
var waits = 0;
|
|
372
|
+
var timer = setInterval(function () {
|
|
373
|
+
var reg2 = registry();
|
|
374
|
+
if (reg2 && reg2.get(id)) {
|
|
375
|
+
clearInterval(timer);
|
|
376
|
+
resolve(reg2.get(id));
|
|
377
|
+
} else if (++waits > 100) {
|
|
378
|
+
clearInterval(timer);
|
|
379
|
+
reject(new Error("registry timeout: " + id));
|
|
380
|
+
}
|
|
381
|
+
}, 60);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// 分代容器:粒子框架场景有跨场景启动协调(startup-hold),
|
|
386
|
+
// dispose 后不能立刻清 DOM——旧容器延迟移除,新场景进新容器
|
|
387
|
+
var currentStage = null;
|
|
388
|
+
|
|
389
|
+
function newStage() {
|
|
390
|
+
currentStage = document.createElement("div");
|
|
391
|
+
currentStage.style.cssText = "position:absolute;inset:0;";
|
|
392
|
+
bgHost.appendChild(currentStage);
|
|
393
|
+
return currentStage;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function retireStage(stage) {
|
|
397
|
+
if (!stage) return;
|
|
398
|
+
// 立即隐藏旧舞台(新旧场景同屏重叠的根因):dispose 后旧画布定格,
|
|
399
|
+
// 但 DOM 要保留 4s——粒子框架的场景切换握手(startup-hold)依赖旧 layer
|
|
400
|
+
// 短暂共存,过早移除会卡死新场景
|
|
401
|
+
try { stage.style.visibility = "hidden"; } catch (e) {}
|
|
402
|
+
setTimeout(function () {
|
|
403
|
+
try { if (stage.parentNode) stage.parentNode.removeChild(stage); } catch (e) {}
|
|
404
|
+
}, 4000);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function activeStage() {
|
|
408
|
+
if (!currentStage || !bgHost.contains(currentStage)) return newStage();
|
|
409
|
+
return currentStage;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function disposeBgInstance() {
|
|
413
|
+
bgSceneId = null;
|
|
414
|
+
if (bgInstance) {
|
|
415
|
+
try { bgInstance.dispose && bgInstance.dispose(); } catch (e) {}
|
|
416
|
+
bgInstance = null;
|
|
417
|
+
}
|
|
418
|
+
retireStage(currentStage);
|
|
419
|
+
currentStage = null;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// ─────────── pixel-sculpt 常驻编辑器(上游 controller:面板与背景共用一个实例) ───────────
|
|
423
|
+
|
|
424
|
+
function psActive() {
|
|
425
|
+
return !!(state && state.enabled && state.mode === "scene" && state.scene === "pixel-sculpt");
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function psPaused() {
|
|
429
|
+
var p = state && state.sceneParams && state.sceneParams["pixel-sculpt"];
|
|
430
|
+
return !!(p && typeof p === "object" && p.paused);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
var psEd = null; // {stage, canvas, inst, ready};未启用时也可存在(编辑器),detach 且 paused
|
|
434
|
+
function ensurePsEditor() {
|
|
435
|
+
if (psEd) return psEd.ready;
|
|
436
|
+
var stage = document.createElement("div");
|
|
437
|
+
stage.style.cssText = "position:absolute;inset:0;";
|
|
438
|
+
var canvas = document.createElement("canvas");
|
|
439
|
+
canvas.style.cssText = "width:100%;height:100%;display:block";
|
|
440
|
+
stage.appendChild(canvas);
|
|
441
|
+
psEd = { stage: stage, canvas: canvas, inst: null, ready: null };
|
|
442
|
+
psEd.ready = ensureGallery("pixel-sculpt").catch(function () { return null; })
|
|
443
|
+
.then(function () { return ensureVendorScene("pixel-sculpt"); })
|
|
444
|
+
.then(function (entry) {
|
|
445
|
+
var seed = entry.prepareDefaults ? entry.prepareDefaults() : null;
|
|
446
|
+
return Promise.resolve(seed).catch(function () { return null; }).then(function () {
|
|
447
|
+
var Ctor = entry.exports && entry.exports.PixelSculptRenderer;
|
|
448
|
+
if (typeof Ctor !== "function") throw new Error("PixelSculptRenderer 不可用");
|
|
449
|
+
// persist=true:控件交互实时写 store(上游控制器路径同款;背景 tn 路径才是 false)
|
|
450
|
+
var inst = new Ctor(stage, canvas, null, function (msg) {
|
|
451
|
+
if (msg && psActive()) setStatus("Pixel Sculpt:" + String(msg).slice(0, 60), true);
|
|
452
|
+
}, true);
|
|
453
|
+
psEd.inst = inst;
|
|
454
|
+
return psEd;
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
psEd.ready.catch(function () { psEd = null; }); // 失败允许重试
|
|
458
|
+
return psEd.ready;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// 启用:编辑器的 layer 挂进当前舞台 + setActive(true);停用:摘除 + setActive(false),实例保留
|
|
462
|
+
function attachPsScene(stage, seq, id) {
|
|
463
|
+
ensurePsEditor().then(function (ed) {
|
|
464
|
+
if (seq !== renderSeq || !psActive()) return;
|
|
465
|
+
stage.appendChild(ed.stage);
|
|
466
|
+
try { ed.inst.setActive(true, { paused: psPaused() }); } catch (e) {}
|
|
467
|
+
bgInstance = {
|
|
468
|
+
setSettings: function (s) { try { ed.inst.setSettings(s || {}); } catch (e) {} },
|
|
469
|
+
reset: function () { try { ed.inst.reset(); } catch (e) {} },
|
|
470
|
+
replay: function () { try { ed.inst.replay(); } catch (e) {} },
|
|
471
|
+
dispose: function () {
|
|
472
|
+
try { if (ed.stage.parentNode) ed.stage.parentNode.removeChild(ed.stage); } catch (e) {}
|
|
473
|
+
try { ed.inst.setActive(false, { paused: psPaused() }); } catch (e) {}
|
|
474
|
+
},
|
|
475
|
+
};
|
|
476
|
+
bgSceneId = id;
|
|
477
|
+
}).catch(function (err) {
|
|
478
|
+
if (seq !== renderSeq) return;
|
|
479
|
+
paintFallback("Pixel Sculpt 启动失败:" + String((err && err.message) || err).slice(0, 50));
|
|
480
|
+
setStatus("Pixel Sculpt 启动失败", true);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// 面板:渲染器自带的整套控件挂进 controls-host(控件 DOM 常驻实例,重复挂载是幂等搬移)
|
|
485
|
+
function mountPsControls() {
|
|
486
|
+
if (!ui || !settingsOpen || settingsId !== "pixel-sculpt") return;
|
|
487
|
+
ensurePsEditor().then(function (ed) {
|
|
488
|
+
if (!ui || !settingsOpen || settingsId !== "pixel-sculpt") return;
|
|
489
|
+
var host = ui.settings.querySelector("[data-pshost]");
|
|
490
|
+
if (host && ed.inst) {
|
|
491
|
+
try { ed.inst.mountControls(host, "zh"); } catch (e) {}
|
|
492
|
+
}
|
|
493
|
+
syncPsPanel();
|
|
494
|
+
}).catch(function (err) {
|
|
495
|
+
setStatus("Pixel Sculpt 设置加载失败:" + String((err && err.message) || err).slice(0, 50), true);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// 面板状态同步:未启用提示、暂停开关可用性、重置按钮可用性(上游 renderPixelSculpt 同构)
|
|
500
|
+
function syncPsPanel() {
|
|
501
|
+
if (!ui || !settingsOpen || settingsId !== "pixel-sculpt") return;
|
|
502
|
+
var note = ui.settings.querySelector("[data-psnote]");
|
|
503
|
+
if (note) note.hidden = psActive();
|
|
504
|
+
var pausedEl = ui.settings.querySelector('[data-toggle="__pspaused"]');
|
|
505
|
+
if (pausedEl) { pausedEl.checked = psPaused(); pausedEl.disabled = !psActive(); }
|
|
506
|
+
var rst = ui.settings.querySelector('[data-act="psreset"]');
|
|
507
|
+
if (rst) rst.disabled = !(psEd && psEd.inst);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function paintFallback(text) {
|
|
511
|
+
var stage = activeStage();
|
|
512
|
+
stage.innerHTML = "";
|
|
513
|
+
var tip = document.createElement("div");
|
|
514
|
+
tip.style.cssText = "position:absolute;inset:0;display:flex;align-items:center;justify-content:center;"
|
|
515
|
+
+ "color:#4d5a78;font-size:13px;font-family:system-ui,sans-serif;background:"
|
|
516
|
+
+ "radial-gradient(120% 90% at 50% 110%,#101a33 0%,#07090f 60%);";
|
|
517
|
+
tip.textContent = text || "";
|
|
518
|
+
stage.appendChild(tip);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
var renderSeq = 0;
|
|
522
|
+
var lastRenderSig = null;
|
|
523
|
+
var lastParamsSig = null;
|
|
524
|
+
|
|
525
|
+
function paramsSig() {
|
|
526
|
+
return JSON.stringify(state && state.sceneParams && state.sceneParams[state.scene] || {});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function renderSig() {
|
|
530
|
+
if (!(state && state.enabled && state.mode === "scene")) return null;
|
|
531
|
+
// 参数变化不再触发重建:实时提交走 renderer.setSettings(上游同款)
|
|
532
|
+
return state.mode + ":" + state.scene;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function renderScene() {
|
|
536
|
+
var seq = ++renderSeq;
|
|
537
|
+
var sig = renderSig();
|
|
538
|
+
lastRenderSig = sig;
|
|
539
|
+
lastParamsSig = paramsSig();
|
|
540
|
+
if (!sig) {
|
|
541
|
+
disposeBgInstance();
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
var id = state.scene && SCENE_IDS.indexOf(state.scene) >= 0 ? state.scene : "milky-way";
|
|
545
|
+
// 层底色 = 原版该场景控制器的指定值(经 CSS 变量下发,通配透明清不掉)
|
|
546
|
+
layer.style.setProperty("--ap-layer-bg", sceneLayerBg(id));
|
|
547
|
+
// 全量设置写入场景 store(渲染器启动真值;上游控制器 updateSettings 同语义)
|
|
548
|
+
writeSceneSetting(id, buildStoreSettings(id));
|
|
549
|
+
// 画廊场景(particle-image / pixel-sculpt)先播种默认图片库
|
|
550
|
+
var prepared = GALLERY_SCENES[id]
|
|
551
|
+
? ensureGallery(id).then(function () {
|
|
552
|
+
var entry0 = registry() && registry().get(id);
|
|
553
|
+
if (entry0 && typeof entry0.prepareDefaults === "function") {
|
|
554
|
+
return entry0.prepareDefaults();
|
|
555
|
+
}
|
|
556
|
+
return null;
|
|
557
|
+
})
|
|
558
|
+
: Promise.resolve(null);
|
|
559
|
+
prepared.then(function () {
|
|
560
|
+
return ensureGallerySelection(id);
|
|
561
|
+
}).then(function () {
|
|
562
|
+
return ensureVendorScene(id);
|
|
563
|
+
}).then(function (entry) {
|
|
564
|
+
// 等脚本/画廊期间设置可能已变
|
|
565
|
+
if (seq !== renderSeq || !(state && state.enabled && state.mode === "scene") || state.scene !== id) return;
|
|
566
|
+
disposeBgInstance();
|
|
567
|
+
if (id === "pixel-sculpt") {
|
|
568
|
+
// 上游控制器路径:常驻编辑器实例挂入舞台 + setActive(true),面板与背景共用
|
|
569
|
+
attachPsScene(newStage(), seq, id);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
var stage = newStage();
|
|
573
|
+
try {
|
|
574
|
+
bgInstance = entry.startup(stage, function (msg) {
|
|
575
|
+
// 渲染器会以无参/空串调用 onError 作为良性通知——
|
|
576
|
+
// 只有带消息时写状态行,绝不清洗舞台(会抹掉已挂载的画面)
|
|
577
|
+
if (seq === renderSeq && msg) setStatus("场景提示:" + String(msg).slice(0, 60));
|
|
578
|
+
});
|
|
579
|
+
bgSceneId = id;
|
|
580
|
+
// particle-image / pixel-sculpt 的 startup 返回 {ready, dispose}
|
|
581
|
+
if (bgInstance && bgInstance.ready && typeof bgInstance.ready.then === "function") {
|
|
582
|
+
bgInstance.ready.catch(function (err) {
|
|
583
|
+
if (seq === renderSeq) setStatus("场景未就绪:" + String((err && err.message) || err).slice(0, 60), true);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
} catch (e) {
|
|
587
|
+
bgInstance = null;
|
|
588
|
+
paintFallback("场景渲染器启动失败:" + id + "(" + String((e && e.message) || e).slice(0, 60) + ")");
|
|
589
|
+
setStatus("场景渲染器启动失败:" + id, true);
|
|
590
|
+
}
|
|
591
|
+
}).catch(function (err) {
|
|
592
|
+
if (seq !== renderSeq) return;
|
|
593
|
+
disposeBgInstance();
|
|
594
|
+
paintFallback("场景加载失败:" + id + "(" + String((err && err.message) || err).slice(0, 50) + ")");
|
|
595
|
+
setStatus("场景加载失败:" + id, true);
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
function isBackgroundActive() {
|
|
601
|
+
return !!(state && state.enabled && state.mode === "scene");
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function renderWallpaper() {
|
|
605
|
+
disposeBgInstance();
|
|
606
|
+
var stage = activeStage();
|
|
607
|
+
stage.innerHTML = "";
|
|
608
|
+
if (!(state && state.enabled && state.mode === "wallpaper")) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (!state.wallpaperId) {
|
|
612
|
+
paintFallback("从设置面板的素材库选择一张壁纸");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
var url = API_BASE + "/wallpaper.png?id=" + encodeURIComponent(state.wallpaperId);
|
|
616
|
+
var fit = state.wallpaperFit === "contain" ? "contain" : state.wallpaperFit === "tile" ? "tile" : "cover";
|
|
617
|
+
var posMap = { center: "center", top: "center top", bottom: "center bottom", left: "left center", right: "right center" };
|
|
618
|
+
var pos = posMap[state.wallpaperPosition] || "center";
|
|
619
|
+
if (fit === "tile") {
|
|
620
|
+
var tile = document.createElement("div");
|
|
621
|
+
tile.style.cssText = "position:absolute;inset:0;background-image:url('" + url + "');"
|
|
622
|
+
+ "background-repeat:repeat;background-size:auto;background-position:" + pos + ";";
|
|
623
|
+
var probe = document.createElement("img");
|
|
624
|
+
probe.style.display = "none";
|
|
625
|
+
probe.onerror = function () {
|
|
626
|
+
var v = document.createElement("video");
|
|
627
|
+
v.src = url; v.loop = true; v.muted = true; v.autoplay = true; v.playsInline = true;
|
|
628
|
+
v.style.cssText = "position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:" + pos + ";";
|
|
629
|
+
stage.innerHTML = "";
|
|
630
|
+
stage.appendChild(v);
|
|
631
|
+
try { v.play(); } catch (e) {}
|
|
632
|
+
};
|
|
633
|
+
stage.appendChild(tile);
|
|
634
|
+
stage.appendChild(probe);
|
|
635
|
+
probe.src = url;
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
var img = document.createElement("img");
|
|
639
|
+
img.decoding = "async";
|
|
640
|
+
img.style.cssText = "position:absolute;inset:0;width:100%;height:100%;object-fit:" + fit + ";object-position:" + pos + ";";
|
|
641
|
+
img.onerror = function () {
|
|
642
|
+
var v = document.createElement("video");
|
|
643
|
+
v.src = url; v.loop = true; v.muted = true; v.autoplay = true; v.playsInline = true;
|
|
644
|
+
v.style.cssText = "position:absolute;inset:0;width:100%;height:100%;object-fit:" + fit + ";object-position:" + pos + ";";
|
|
645
|
+
v.onerror = function () { stage.innerHTML = ""; };
|
|
646
|
+
stage.innerHTML = "";
|
|
647
|
+
stage.appendChild(v);
|
|
648
|
+
try { v.play(); } catch (e) {}
|
|
649
|
+
};
|
|
650
|
+
img.src = url;
|
|
651
|
+
stage.appendChild(img);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// ─────────── ② UI 表面:通配透明 + 分区蒙版(原仓库两层做法) ───────────
|
|
655
|
+
|
|
656
|
+
var surfaceStyleEl = null;
|
|
657
|
+
var surfacesApplied = false;
|
|
658
|
+
|
|
659
|
+
function buildSurfaceCss() {
|
|
660
|
+
// 级联层设计(!important 在层间反转优先级,层内声明顺序即优先级):
|
|
661
|
+
// dsh-ap-assert —— 层底色/dim 重申(最高)
|
|
662
|
+
// dsh-ap-masks —— 分区蒙版
|
|
663
|
+
// dsh-ap-clear —— 通配透明(最低,但压过应用内联样式)
|
|
664
|
+
// 通配透明必须排除背景层子树:场景内部靠 background/mix-blend-mode 画的
|
|
665
|
+
// 结构(如 glow-horizon 的穹顶)被清掉会直接丢色(原版把该规则放在独立的
|
|
666
|
+
// transparent-background 插件里,启用场景时不生效——这里用 :not 排除等价实现)。
|
|
667
|
+
// :not(#id *) 带来的特异性提升被层序抵消,无需再堆 data-ap-masks 次数。
|
|
668
|
+
var NOT_LAYER = ":not(#" + LAYER_ID + "):not(#" + LAYER_ID + " *)";
|
|
669
|
+
// DSH 原生设置页豁免(两种状态都生效):通配清除跳过设置面板子树
|
|
670
|
+
// (body 直系 *_overlay 里的 *_panel),面板保持宿主原生底色与渐变,
|
|
671
|
+
// 主界面与背景照常透明。css-module 语义后缀 _panel 稳定、哈希前缀随版本变;
|
|
672
|
+
// :not() 复杂选择器(Chrome 88+)与 composer 卡片豁免同款机制。
|
|
673
|
+
var CLEAR_TAIL = ":not([role=\"img\"]):not([data-icon]):not([class*=\"icon\" i])"
|
|
674
|
+
+ ":not([class*=\"_panel\"]):not([class*=\"_panel\"] *)";
|
|
675
|
+
// 通配清除的元素选择器(:where 全体表面元素)
|
|
676
|
+
var CLEAR_BASE = " body :where(div,main,aside,section,article,header,"
|
|
677
|
+
+ "footer,nav,form,dialog,ul,ol,li,button,input,textarea,select)"
|
|
678
|
+
+ NOT_LAYER;
|
|
679
|
+
var CLEAR_DECL = "background-color:transparent !important;-webkit-backdrop-filter:none !important;backdrop-filter:none !important";
|
|
680
|
+
// 输入卡片保留原生样式:表面蒙版停用(data-ap-masks 移除)时,通配清除不再命中
|
|
681
|
+
// Codinput 卡片子树——输入框保持原有底色(原生 rgba 卡片面),不全透。
|
|
682
|
+
// 蒙版启用时无此豁免:卡片由「消息输入区」蒙版按滑杆值上色。
|
|
683
|
+
var COMPOSER_KEEP = ":not([data-composer-card]):not([data-composer-card] *)";
|
|
684
|
+
// DSH 原生设置页豁免(两种状态都生效):设置面板(body 直系 *_overlay 里的
|
|
685
|
+
// *_panel)子树不被通配清除——面板保持宿主原生底色,主界面与背景照常透明。
|
|
686
|
+
// css-module 语义后缀 _panel/_overlay 稳定,哈希前缀随版本变;须限定
|
|
687
|
+
// `body > [class*="_overlay"]` 直系,否则会命中主界面常驻的装饰 overlay。
|
|
688
|
+
var SETTINGS_KEEP = ":not([class*=\"_panel\"]):not([class*=\"_panel\"] *)";
|
|
689
|
+
var PANEL_KEEPScope = "body > [class*=\"_overlay\"] > [class*=\"_panel\"]";
|
|
690
|
+
var css = "@layer dsh-ap-assert{\n"
|
|
691
|
+
+ "html[data-ap-bg] body div#" + LAYER_ID + "{background:var(--ap-layer-bg,#000) !important}\n"
|
|
692
|
+
+ "html[data-ap-bg] body div#" + DIM_ID + "{background:var(--ap-dim-bg,transparent) !important}\n"
|
|
693
|
+
+ "}\n";
|
|
694
|
+
css += "@layer dsh-ap-masks{\n";
|
|
695
|
+
for (var i = 0; i < REGION_ROWS.length; i++) {
|
|
696
|
+
var r = REGION_ROWS[i];
|
|
697
|
+
css += "html[data-ap-masks] body " + r.selector + "{"
|
|
698
|
+
+ "background-color:rgba(" + r.base + ",var(--ap-mask-" + r.key + ")) !important}\n";
|
|
699
|
+
}
|
|
700
|
+
// 输入卡片的原生 box-shadow(0.5px 白描边 + 黑晕)在透明背景上会显成一圈「框」;
|
|
701
|
+
// 蒙版启用时清掉,让卡片成为纯蒙版色块。停用态卡片走原生样式,阴影保留。
|
|
702
|
+
css += "html[data-ap-masks] body [data-composer-card]{box-shadow:none !important}\n";
|
|
703
|
+
css += "}\n";
|
|
704
|
+
css += "@layer dsh-ap-clear{\n"
|
|
705
|
+
+ "html[data-ap-bg]{background-color:transparent !important}\n"
|
|
706
|
+
+ "html[data-ap-bg] body{isolation:isolate;background-color:transparent !important}\n" // 原版同款:body 独立层叠上下文
|
|
707
|
+
+ "html[data-ap-bg][data-ap-masks]" + CLEAR_BASE + CLEAR_TAIL + "{" + CLEAR_DECL + "!important}\n"
|
|
708
|
+
+ "html[data-ap-bg]:not([data-ap-masks])" + CLEAR_BASE + CLEAR_TAIL + COMPOSER_KEEP + "{" + CLEAR_DECL + "!important}\n"
|
|
709
|
+
// 输入座位的原生「淡入渐变」(background-image: transparent→rgb(21,21,23)):
|
|
710
|
+
// 卡片左缘的空隙会透出这块渐变,看起来像输入框旁多出一块灰色圆角斑——两态都清
|
|
711
|
+
+ "html[data-ap-bg] body [data-composer-seat],"
|
|
712
|
+
+ "html[data-ap-bg] body div:has(> [data-slot=\"conversation.input.dock\"]){background-image:none !important}\n"
|
|
713
|
+
+ "html[data-ap-bg] body :is([class*=\"bg-gradient\"],[class*=\"TopFade\"],[class*=\"fade\"])"
|
|
714
|
+
+ NOT_LAYER + "{background-image:none !important}\n"
|
|
715
|
+
+ "}\n";
|
|
716
|
+
return css;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function applySurfaceVars() {
|
|
720
|
+
var html = document.documentElement;
|
|
721
|
+
for (var i = 0; i < REGION_ROWS.length; i++) {
|
|
722
|
+
var r = REGION_ROWS[i];
|
|
723
|
+
var v = state && state.surfaces ? clamp(num(state.surfaces[r.key], 66), 0, 100) / 100 : 0;
|
|
724
|
+
html.style.setProperty("--ap-mask-" + r.key, v.toFixed(3));
|
|
725
|
+
}
|
|
726
|
+
syncCornerPatch();
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// 圆角缺口补丁:中央列(对话区容器)左上有 16px 圆角 + overflow:hidden,蒙版背景被
|
|
730
|
+
// 圆角裁掉后,弧外月牙露出原始背景。在背景层放一个月牙形补丁(radial mask 只保留
|
|
731
|
+
// 圆角外区域——圆角内透明,避免与中央列蒙版叠加深色),颜色/不透明度跟随「会话侧栏」
|
|
732
|
+
// 滑杆(用户视角这个角属于左侧栏;侧栏调 0 时角也跟着透)。
|
|
733
|
+
var cornerEl = null;
|
|
734
|
+
var cornerRO = null;
|
|
735
|
+
var cornerROTarget = null;
|
|
736
|
+
var cornerRetries = 0;
|
|
737
|
+
function syncCornerPatch() {
|
|
738
|
+
var masksOn = !!(state && state.enabled && state.mode !== "off" && state.surfaces && state.surfaces.enabled);
|
|
739
|
+
var col = document.querySelector('[data-slot="main"]');
|
|
740
|
+
col = col ? col.parentElement : null;
|
|
741
|
+
var r = 0;
|
|
742
|
+
if (masksOn && col && layer) {
|
|
743
|
+
r = parseFloat(getComputedStyle(col).borderTopLeftRadius);
|
|
744
|
+
if (!Number.isFinite(r) || r <= 0) r = 0;
|
|
745
|
+
}
|
|
746
|
+
if (!r || !layer) {
|
|
747
|
+
if (cornerEl) cornerEl.style.display = "none";
|
|
748
|
+
// boot 首次运行早于宿主布局挂载(col 还不存在)——CSS 蒙版是活的、DOM 补丁
|
|
749
|
+
// 不是,必须定时重试到建成(封顶 30s),否则补丁永不出现
|
|
750
|
+
if (masksOn && layer && cornerRetries < 30) {
|
|
751
|
+
cornerRetries++;
|
|
752
|
+
setTimeout(function () { syncCornerPatch(); }, 1000);
|
|
753
|
+
}
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
cornerRetries = 0;
|
|
757
|
+
if (!cornerEl) {
|
|
758
|
+
cornerEl = document.createElement("div");
|
|
759
|
+
cornerEl.id = "dsh-ap-corner";
|
|
760
|
+
cornerEl.style.cssText = "position:absolute;left:0;top:0;pointer-events:none;";
|
|
761
|
+
layer.appendChild(cornerEl);
|
|
762
|
+
}
|
|
763
|
+
var rect = col.getBoundingClientRect();
|
|
764
|
+
var a = clamp(num(state.surfaces.sidebar, 66), 0, 100) / 100;
|
|
765
|
+
var mask = "radial-gradient(circle " + r + "px at 100% 100%, transparent 0, transparent " + (r - 0.6).toFixed(1) + "px, #000 " + r + "px)";
|
|
766
|
+
cornerEl.style.display = "block";
|
|
767
|
+
cornerEl.style.left = rect.x + "px";
|
|
768
|
+
cornerEl.style.top = rect.y + "px";
|
|
769
|
+
cornerEl.style.width = r + "px";
|
|
770
|
+
cornerEl.style.height = r + "px";
|
|
771
|
+
cornerEl.style.background = "rgba(16,17,20," + a.toFixed(3) + ")";
|
|
772
|
+
cornerEl.style.webkitMaskImage = mask;
|
|
773
|
+
cornerEl.style.maskImage = mask;
|
|
774
|
+
// 侧栏折叠/窗口缩放会移动中央列——尺寸变化时重新对位(布局重建换元素时换观察目标)
|
|
775
|
+
if (cornerRO && cornerROTarget !== col) {
|
|
776
|
+
cornerRO.disconnect();
|
|
777
|
+
cornerRO = null;
|
|
778
|
+
}
|
|
779
|
+
if (!cornerRO) {
|
|
780
|
+
cornerRO = new ResizeObserver(function () { syncCornerPatch(); });
|
|
781
|
+
cornerRO.observe(col);
|
|
782
|
+
cornerROTarget = col;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
function applySurfaceStyles() {
|
|
787
|
+
var on = !!(state && state.enabled && state.mode !== "off");
|
|
788
|
+
var masksOn = on && !!(state && state.surfaces && state.surfaces.enabled);
|
|
789
|
+
var html = document.documentElement;
|
|
790
|
+
if (!on) {
|
|
791
|
+
clearSurfaceStyles();
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
if (!surfaceStyleEl || !document.head.contains(surfaceStyleEl)) {
|
|
795
|
+
surfaceStyleEl = document.createElement("style");
|
|
796
|
+
surfaceStyleEl.id = BG_STYLE_ID;
|
|
797
|
+
surfaceStyleEl.setAttribute("data-dsh-ccx", "surface");
|
|
798
|
+
(document.head || document.documentElement).appendChild(surfaceStyleEl);
|
|
799
|
+
}
|
|
800
|
+
if (surfaceStyleEl.textContent !== buildSurfaceCss()) surfaceStyleEl.textContent = buildSurfaceCss();
|
|
801
|
+
html.setAttribute("data-ap-bg", "true");
|
|
802
|
+
applySurfaceVars();
|
|
803
|
+
if (masksOn) html.setAttribute("data-ap-masks", "true");
|
|
804
|
+
else html.removeAttribute("data-ap-masks");
|
|
805
|
+
surfacesApplied = true;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function clearSurfaceStyles() {
|
|
809
|
+
var html = document.documentElement;
|
|
810
|
+
html.removeAttribute("data-ap-bg");
|
|
811
|
+
html.removeAttribute("data-ap-masks");
|
|
812
|
+
for (var i = 0; i < REGION_ROWS.length; i++) {
|
|
813
|
+
try { html.style.removeProperty("--ap-mask-" + REGION_ROWS[i].key); } catch (e) {}
|
|
814
|
+
}
|
|
815
|
+
surfacesApplied = false;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// ─────────── ③ 设置面板(Shadow DOM · code-codex 插件市场 + 设置面板复刻) ───────────
|
|
819
|
+
//
|
|
820
|
+
// v0.8:按 code-codex 0.5.7 真实 UI 逐像素复刻(docs/codex-ui/ 活体采集 + 上游
|
|
821
|
+
// packages/explorer-ui/src/components/styles/*.ts 源码真值):
|
|
822
|
+
// · 320px 插件市场弹层(齿轮上方弹出、底部箭头)——12 张 Appearance 卡片
|
|
823
|
+
// · 344px 场景设置 popover(卡片 ⚙ 右侧弹出、左箭头锚定)——原版分组/工具栏/行结构
|
|
824
|
+
// · 保留 v0.6 确立的「草稿 + 应用」提交制(vendor 渲染器仅 glow-horizon 支持
|
|
825
|
+
// updateSettings,实时提交会导致活跃场景整体重建、开场动画重播)
|
|
826
|
+
// · 移除 v0.7 双卡面板与实时预览舞台(原版无预览;Demo 已评审通过)
|
|
827
|
+
|
|
828
|
+
var root9 = null;
|
|
829
|
+
var marketOpen = false; // 插件市场弹层可见
|
|
830
|
+
var settingsOpen = false; // 设置面板可见
|
|
831
|
+
var settingsId = null; // 设置面板对应卡片 id(custom / surface / 场景 id)
|
|
832
|
+
var ui = null; // { trigger, market, settings }
|
|
833
|
+
var wallpapersCache = [];
|
|
834
|
+
|
|
835
|
+
// 背景调节(图层级,实时生效)
|
|
836
|
+
var PARAM_ROWS = [
|
|
837
|
+
{ key: "dim", zh: "背景压暗", min: 0, max: 80, step: 1, scale: 100 },
|
|
838
|
+
{ key: "blur", zh: "背景模糊", min: 0, max: 20, step: 0.5, scale: 1 },
|
|
839
|
+
];
|
|
840
|
+
var LIB_PAGE_SIZE = 12;
|
|
841
|
+
var libPage = 0;
|
|
842
|
+
|
|
843
|
+
// 场景参数草稿(应用制提交;draftDeltaObj 口径与宿主增量落盘一致)
|
|
844
|
+
var draft = null;
|
|
845
|
+
var draftScene = null;
|
|
846
|
+
|
|
847
|
+
// ───────────── 原版设计 token(暗色,docs/codex-ui/tokens.json 活体校准) ─────────────
|
|
848
|
+
|
|
849
|
+
var PANEL_CSS = [
|
|
850
|
+
":host{all:initial;color-scheme:dark;" +
|
|
851
|
+
"font-family:'Segoe UI','Microsoft YaHei UI',system-ui,sans-serif;font-weight:430}",
|
|
852
|
+
"*{box-sizing:border-box;font-family:inherit}",
|
|
853
|
+
// 触发齿轮(沿用现役位置:left:12 bottom:76)
|
|
854
|
+
".trigger{position:fixed;left:12px;bottom:76px;z-index:2147482000;width:30px;height:30px;border-radius:50%;"
|
|
855
|
+
+ "border:1px solid rgba(128,140,170,.35);background:rgba(20,24,34,.55);backdrop-filter:blur(8px);"
|
|
856
|
+
+ "cursor:pointer;display:flex;align-items:center;justify-content:center;opacity:.5;transition:opacity .15s ease,transform .15s ease;padding:0}",
|
|
857
|
+
".trigger:hover{opacity:1;transform:scale(1.08)}",
|
|
858
|
+
".trigger svg{width:16px;height:16px;fill:none;stroke:#dfe6f5;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}",
|
|
859
|
+
// token(上游 tokens-and-host.ts 暗色组)
|
|
860
|
+
".preview-market-popover,.particle-settings-panel{" +
|
|
861
|
+
"--cle-paper:#1f1f1f;--cle-paper-raised:#242424;--cle-subtle:#242424;--cle-ink:#f2f2f2;--cle-muted:#a3a3a3;" +
|
|
862
|
+
"--cle-rule:#3a3a3a;--cle-rule-strong:#454545;--cle-scroll-thumb:#666666;--cle-hover:#2b2c2e;--cle-subtle-2:#242424;" +
|
|
863
|
+
"--cle-input:#252628;--cle-signal:#69aaf5;--cle-added:#62c990;--cle-focus:#69aaf5;" +
|
|
864
|
+
"--cle-icon-blue:#79b8e6;--cle-icon-violet:#b9a1e3;--cle-market-enable:#e5f0fe;" +
|
|
865
|
+
"--cle-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;" +
|
|
866
|
+
"color-scheme:dark}",
|
|
867
|
+
// ── 插件市场弹层(status-and-market.ts 逐条)──
|
|
868
|
+
".preview-market-popover{position:fixed;left:12px;bottom:114px;z-index:2147482900;" +
|
|
869
|
+
"width:min(320px,calc(100vw - 24px));max-height:calc(100vh - 130px);overflow:visible;color:var(--cle-ink);" +
|
|
870
|
+
"background:var(--cle-paper-raised);border:1px solid var(--cle-rule-strong);border-radius:10px;" +
|
|
871
|
+
"box-shadow:0 14px 34px rgba(12,18,28,.2),0 3px 10px rgba(12,18,28,.12);" +
|
|
872
|
+
"font-size:12px;line-height:1.45;animation:ccx-market-in 130ms cubic-bezier(.2,.8,.2,1) both}",
|
|
873
|
+
".preview-market-popover[hidden]{display:none}",
|
|
874
|
+
".preview-market-popover::after{content:'';position:absolute;bottom:-6px;left:18px;width:10px;height:10px;" +
|
|
875
|
+
"background:var(--cle-paper-raised);border-right:1px solid var(--cle-rule-strong);border-bottom:1px solid var(--cle-rule-strong);" +
|
|
876
|
+
"transform:rotate(45deg)}",
|
|
877
|
+
".preview-market-header{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 10px 8px 14px;" +
|
|
878
|
+
"border-bottom:1px solid var(--cle-rule)}",
|
|
879
|
+
".preview-market-header h3{flex:1;margin:0;color:var(--cle-ink);font-size:13px;font-weight:650;line-height:18px}",
|
|
880
|
+
".preview-market-close{display:grid;flex:0 0 auto;place-items:center;width:24px;height:24px;padding:0;color:var(--cle-muted);" +
|
|
881
|
+
"background:transparent;border:0;border-radius:5px;cursor:pointer}",
|
|
882
|
+
".preview-market-close:hover{color:var(--cle-ink);background:var(--cle-hover)}",
|
|
883
|
+
".preview-market-close svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:1.3}",
|
|
884
|
+
".preview-market-list{position:relative;display:grid;align-content:start;gap:8px;max-height:min(420px,calc(100vh - 150px));" +
|
|
885
|
+
"padding:8px;overflow:auto;scrollbar-color:var(--cle-scroll-thumb) transparent;scrollbar-width:thin}",
|
|
886
|
+
".preview-market-categories{display:grid;width:fit-content;grid-template-columns:repeat(3,max-content);gap:2px;padding:2px;" +
|
|
887
|
+
"background:var(--cle-subtle);border:1px solid var(--cle-rule);border-radius:7px}",
|
|
888
|
+
".preview-market-category{min-width:0;padding:5px 6px;color:var(--cle-muted);background:transparent;border:0;border-radius:5px;" +
|
|
889
|
+
"cursor:pointer;font-size:10px;font-weight:650;line-height:14px;letter-spacing:.01em;white-space:nowrap}",
|
|
890
|
+
".preview-market-category:hover{color:var(--cle-ink);background:var(--cle-hover)}",
|
|
891
|
+
".preview-market-category[aria-selected='true']{color:var(--cle-ink);background:var(--cle-paper);box-shadow:0 1px 2px rgba(12,18,28,.08)}",
|
|
892
|
+
".preview-market-section{display:grid;gap:6px;min-width:0}",
|
|
893
|
+
".preview-market-section[hidden]{display:none}",
|
|
894
|
+
".preview-market-section-list{display:grid;gap:8px}",
|
|
895
|
+
".cat-empty{margin:4px 2px;color:var(--cle-muted);font-size:10.5px}",
|
|
896
|
+
// ── Appearance 卡片(plugin-cards.ts 逐条)──
|
|
897
|
+
".preview-extension{display:grid;grid-template-columns:38px minmax(0,1fr);column-gap:10px;row-gap:9px;padding:10px;" +
|
|
898
|
+
"background:var(--cle-paper);border:1px solid var(--cle-rule);border-radius:8px}",
|
|
899
|
+
".preview-extension-icon{display:grid;place-items:center;align-self:start;width:38px;height:38px;color:var(--cle-icon-blue);" +
|
|
900
|
+
"background:color-mix(in srgb,var(--cle-icon-blue) 10%,var(--cle-paper));" +
|
|
901
|
+
"border:1px solid color-mix(in srgb,var(--cle-icon-blue) 20%,var(--cle-rule));border-radius:8px}",
|
|
902
|
+
".preview-extension-icon svg{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.1;stroke-linecap:round;stroke-linejoin:round}",
|
|
903
|
+
".preview-extension-copy{min-width:0}",
|
|
904
|
+
".preview-extension-title-row{display:flex;flex-direction:column;align-items:flex-start;gap:3px}",
|
|
905
|
+
".preview-extension h4{min-width:0;margin:0;color:var(--cle-ink);font-size:12px;font-weight:650;line-height:17px;overflow-wrap:anywhere}",
|
|
906
|
+
".preview-extension-status{flex:0 0 auto;padding:1px 5px;color:var(--cle-muted);background:var(--cle-subtle);border-radius:999px;" +
|
|
907
|
+
"font-size:9px;line-height:15px}",
|
|
908
|
+
".preview-extension-status[data-enabled='true']{color:var(--cle-added);background:color-mix(in srgb,var(--cle-added) 11%,var(--cle-paper))}",
|
|
909
|
+
".preview-extension-actions{display:flex;grid-column:2;align-items:center;justify-self:start;gap:5px}",
|
|
910
|
+
".preview-extension-action{grid-column:2;justify-self:start;min-width:58px;min-height:25px;padding:3px 10px;color:#173b66;" +
|
|
911
|
+
"background:var(--cle-market-enable);border:1px solid color-mix(in srgb,var(--cle-market-enable) 80%,#69aaf5);" +
|
|
912
|
+
"border-radius:5px;cursor:pointer;font-size:10.5px;font-weight:600}",
|
|
913
|
+
".preview-extension-action:hover{filter:brightness(1.06)}",
|
|
914
|
+
".preview-extension-action[data-enabled='true']{color:var(--cle-muted);background:transparent;border-color:var(--cle-rule-strong)}",
|
|
915
|
+
".particle-settings-trigger{display:grid;flex:0 0 auto;place-items:center;width:25px;height:25px;padding:0;color:var(--cle-muted);" +
|
|
916
|
+
"background:transparent;border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer}",
|
|
917
|
+
".particle-settings-trigger:hover,.particle-settings-trigger[aria-expanded='true']{color:var(--cle-ink);background:var(--cle-hover)}",
|
|
918
|
+
".particle-settings-trigger svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:1.3;stroke-linecap:round;stroke-linejoin:round}",
|
|
919
|
+
// 逐插件 icon 着色(git-history.ts)
|
|
920
|
+
".ext-particle .preview-extension-icon{color:var(--cle-icon-violet);background:color-mix(in srgb,var(--cle-icon-violet) 10%,var(--cle-paper));" +
|
|
921
|
+
"border-color:color-mix(in srgb,var(--cle-icon-violet) 22%,var(--cle-rule))}",
|
|
922
|
+
".ext-blackhole .preview-extension-icon{color:#f59e0b;background:color-mix(in srgb,#f59e0b 10%,var(--cle-paper));" +
|
|
923
|
+
"border-color:color-mix(in srgb,#f59e0b 24%,var(--cle-rule))}",
|
|
924
|
+
".ext-glowhorizon .preview-extension-icon{color:#a558fb;background:color-mix(in srgb,#a558fb 10%,var(--cle-paper));" +
|
|
925
|
+
"border-color:color-mix(in srgb,#a558fb 24%,var(--cle-rule))}",
|
|
926
|
+
".ext-heavenlycloud .preview-extension-icon{color:#38e8ff;background:color-mix(in srgb,#38e8ff 10%,var(--cle-paper));" +
|
|
927
|
+
"border-color:color-mix(in srgb,#38e8ff 24%,var(--cle-rule))}",
|
|
928
|
+
// ── 设置面板 popover(git-history.ts 逐条)──
|
|
929
|
+
".particle-settings-panel{position:fixed;top:12px;left:340px;z-index:2147483000;display:grid;grid-template-rows:auto minmax(0,1fr);" +
|
|
930
|
+
"width:min(344px,calc(100vw - 24px));max-height:calc(100vh - 24px);color:var(--cle-ink);background:var(--cle-paper-raised);" +
|
|
931
|
+
"border:1px solid var(--cle-rule-strong);border-radius:8px;" +
|
|
932
|
+
"box-shadow:0 20px 52px rgba(0,0,0,.34),0 4px 14px rgba(0,0,0,.2);font-size:12px;line-height:1.45;" +
|
|
933
|
+
"animation:ccx-settings-in 130ms cubic-bezier(.2,.8,.2,1) both}",
|
|
934
|
+
".particle-settings-panel[hidden]{display:none}",
|
|
935
|
+
".particle-settings-panel[data-side='right']{transform-origin:left top}",
|
|
936
|
+
".particle-settings-panel[data-side='right']::before{position:absolute;top:var(--cle-anchor-y,24px);left:-6px;width:10px;height:10px;" +
|
|
937
|
+
"background:var(--cle-paper-raised);border-bottom:1px solid var(--cle-rule-strong);border-left:1px solid var(--cle-rule-strong);" +
|
|
938
|
+
"content:'';transform:translateY(-50%) rotate(45deg)}",
|
|
939
|
+
".particle-settings-header{position:relative;z-index:1;display:flex;align-items:flex-start;justify-content:space-between;gap:12px;" +
|
|
940
|
+
"min-width:0;padding:12px 12px 10px 13px;background:var(--cle-paper-raised);border-bottom:1px solid var(--cle-rule);" +
|
|
941
|
+
"border-radius:8px 8px 0 0}",
|
|
942
|
+
".particle-settings-heading{min-width:0}",
|
|
943
|
+
".particle-settings-header h3{margin:0;overflow:hidden;color:var(--cle-ink);font-size:13px;font-weight:650;line-height:18px;" +
|
|
944
|
+
"text-overflow:ellipsis;white-space:nowrap}",
|
|
945
|
+
".particle-settings-header p{margin:1px 0 0;color:var(--cle-muted);font-size:10px;line-height:15px}",
|
|
946
|
+
".particle-settings-header p .badge{margin-left:4px;color:var(--cle-signal)}",
|
|
947
|
+
".particle-settings-close{display:grid;flex:0 0 auto;place-items:center;width:24px;height:24px;padding:0;color:var(--cle-muted);" +
|
|
948
|
+
"background:transparent;border:0;border-radius:5px;cursor:pointer}",
|
|
949
|
+
".particle-settings-close:hover{color:var(--cle-ink);background:var(--cle-hover)}",
|
|
950
|
+
".particle-settings-close svg{width:13px;height:13px;fill:none;stroke:currentColor;stroke-width:1.3}",
|
|
951
|
+
".particle-settings-scroll{display:grid;gap:10px;align-content:start;min-width:0;min-height:0;max-height:calc(100vh - 90px);" +
|
|
952
|
+
"padding:9px 10px 11px;overflow:auto;overscroll-behavior:contain;scrollbar-color:var(--cle-scroll-thumb) transparent;scrollbar-width:thin}",
|
|
953
|
+
// 分组 fieldset
|
|
954
|
+
".particle-settings-group{display:grid;gap:6px;min-width:0;margin:0;padding:0;border:0}",
|
|
955
|
+
".particle-settings-group + .particle-settings-group{padding-top:9px;border-top:1px solid var(--cle-rule)}",
|
|
956
|
+
".particle-settings-group legend{width:100%;margin:0 0 1px;padding:0;color:var(--cle-muted);font-size:9px;font-weight:700;" +
|
|
957
|
+
"line-height:14px;letter-spacing:.04em}",
|
|
958
|
+
// 控制行
|
|
959
|
+
".particle-control-row{display:grid;grid-template-columns:minmax(92px,.9fr) minmax(72px,1.1fr) minmax(42px,auto);align-items:center;" +
|
|
960
|
+
"gap:6px;min-width:0;min-height:34px;color:var(--cle-muted);font-size:10px}",
|
|
961
|
+
".particle-control-row label{min-width:0;overflow-wrap:anywhere;line-height:14px}",
|
|
962
|
+
".particle-control-row input[type='range']{width:100%;min-width:0;margin:0;accent-color:var(--cle-signal);cursor:pointer}",
|
|
963
|
+
".particle-control-value{display:grid;min-width:42px;justify-items:end}",
|
|
964
|
+
".particle-control-row output{box-sizing:border-box;width:100%;min-width:42px;padding:0 3px;color:var(--cle-ink);" +
|
|
965
|
+
"background:transparent;border:1px solid transparent;border-radius:4px;font:9.5px/18px var(--cle-mono);" +
|
|
966
|
+
"font-variant-numeric:tabular-nums;text-align:right;user-select:none}",
|
|
967
|
+
".particle-control-row output:hover{background:var(--cle-hover);border-color:var(--cle-rule)}",
|
|
968
|
+
// 分区行内 ↺(恢复此项默认值,上游 surface-opacity-row 四列网格:数值右侧)
|
|
969
|
+
".surface-opacity-row{grid-template-columns:minmax(92px,1fr) minmax(60px,1fr) 42px 24px;min-height:30px}",
|
|
970
|
+
".surface-opacity-row button{border:1px solid var(--cle-rule);border-radius:4px;background:var(--cle-paper);color:var(--cle-ink);height:24px;padding:0;cursor:pointer;font:inherit}",
|
|
971
|
+
// 开关行 / 颜色行
|
|
972
|
+
".particle-toggle-row,.particle-color-row{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:8px;" +
|
|
973
|
+
"min-height:27px;margin:0 8px;color:var(--cle-muted);font-size:9.5px}",
|
|
974
|
+
".particle-toggle-row input[type='checkbox']{width:14px;height:14px;margin:0;accent-color:var(--cle-signal);cursor:pointer}",
|
|
975
|
+
".particle-color-row input[type='color']{width:29px;height:21px;padding:2px;overflow:hidden;background:var(--cle-input);" +
|
|
976
|
+
"border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer}",
|
|
977
|
+
// 质量工具栏(heavenly-cloud 系,cyan)
|
|
978
|
+
".heavenly-cloud-quality-toolbar{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px}",
|
|
979
|
+
".heavenly-cloud-quality-toolbar.dir4{grid-template-columns:repeat(4,minmax(0,1fr))}",
|
|
980
|
+
".heavenly-cloud-quality-toolbar button{min-width:0;min-height:40px;padding:4px 6px;color:var(--cle-muted);background:var(--cle-paper-raised);" +
|
|
981
|
+
"border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer;font-size:9.5px;font-weight:600;line-height:12px}",
|
|
982
|
+
".heavenly-cloud-quality-toolbar button strong{display:block;margin-bottom:2px;color:#38e8ff;font-family:var(--cle-mono);font-size:11px}",
|
|
983
|
+
".heavenly-cloud-quality-toolbar button:hover:not(:disabled),.heavenly-cloud-quality-toolbar button[aria-pressed='true']{" +
|
|
984
|
+
"color:var(--cle-ink);background:color-mix(in srgb,#38e8ff 10%,var(--cle-paper-raised));" +
|
|
985
|
+
"border-color:color-mix(in srgb,#38e8ff 42%,var(--cle-rule-strong))}",
|
|
986
|
+
// 方向工具栏(glow-horizon,violet)
|
|
987
|
+
".glow-horizon-direction-toolbar{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px;padding-bottom:9px;" +
|
|
988
|
+
"border-bottom:1px solid var(--cle-rule)}",
|
|
989
|
+
".glow-horizon-direction-toolbar button{min-width:0;min-height:34px;padding:3px 5px;color:var(--cle-muted);background:var(--cle-paper-raised);" +
|
|
990
|
+
"border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer;font-size:9.5px;font-weight:600;line-height:12px}",
|
|
991
|
+
".glow-horizon-direction-toolbar button:hover:not(:disabled),.glow-horizon-direction-toolbar button[aria-pressed='true']{" +
|
|
992
|
+
"color:var(--cle-ink);background:color-mix(in srgb,#a558fb 12%,var(--cle-paper-raised));" +
|
|
993
|
+
"border-color:color-mix(in srgb,#a558fb 45%,var(--cle-rule-strong))}",
|
|
994
|
+
".glow-horizon-direction-toolbar .glow-horizon-direction-symbol{display:block;margin-bottom:1px;font-size:14px;line-height:15px}",
|
|
995
|
+
// 黑洞预设工具栏(amber)
|
|
996
|
+
".black-hole-preset-toolbar{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px;padding-bottom:9px;border-bottom:1px solid var(--cle-rule)}",
|
|
997
|
+
".black-hole-preset-toolbar button{min-width:0;min-height:32px;padding:3px 5px;overflow:visible;color:var(--cle-muted);" +
|
|
998
|
+
"background:var(--cle-paper-raised);border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer;" +
|
|
999
|
+
"font-size:9.5px;font-weight:600;line-height:12px;white-space:normal}",
|
|
1000
|
+
".black-hole-preset-toolbar button:hover:not(:disabled),.black-hole-preset-toolbar button[aria-pressed='true']{" +
|
|
1001
|
+
"color:var(--cle-ink);background:color-mix(in srgb,#f59e0b 10%,var(--cle-paper-raised));" +
|
|
1002
|
+
"border-color:color-mix(in srgb,#f59e0b 45%,var(--cle-rule-strong))}",
|
|
1003
|
+
".black-hole-preset-toolbar .black-hole-reset{color:var(--cle-muted);background:var(--cle-subtle)}",
|
|
1004
|
+
// 底部动作区
|
|
1005
|
+
".glow-horizon-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;padding-top:2px}",
|
|
1006
|
+
".glow-horizon-actions.single{grid-template-columns:minmax(0,1fr)}",
|
|
1007
|
+
".glow-horizon-actions button{min-height:30px;padding:4px 8px;color:var(--cle-muted);background:var(--cle-subtle);" +
|
|
1008
|
+
"border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer;font-size:10px;font-weight:600}",
|
|
1009
|
+
".glow-horizon-actions button:hover{color:var(--cle-ink);background:color-mix(in srgb,var(--cle-signal) 10%,var(--cle-subtle));" +
|
|
1010
|
+
"border-color:color-mix(in srgb,var(--cle-signal) 42%,var(--cle-rule-strong))}",
|
|
1011
|
+
// 图片库(details)
|
|
1012
|
+
".particle-source-details{min-width:0;overflow:hidden;background:var(--cle-subtle);border:1px solid var(--cle-rule);border-radius:7px}",
|
|
1013
|
+
".particle-source-details[open]{padding-bottom:8px}",
|
|
1014
|
+
".particle-source-summary{display:flex;align-items:center;gap:7px;min-height:30px;padding:5px 8px;color:var(--cle-ink);cursor:pointer;" +
|
|
1015
|
+
"font-size:10.5px;font-weight:600;list-style:none;user-select:none}",
|
|
1016
|
+
".particle-source-summary::-webkit-details-marker{display:none}",
|
|
1017
|
+
".particle-source-summary::before{flex:0 0 auto;width:6px;height:6px;border-right:1px solid var(--cle-muted);" +
|
|
1018
|
+
"border-bottom:1px solid var(--cle-muted);content:'';transform:rotate(-45deg)}",
|
|
1019
|
+
".particle-source-details[open] .particle-source-summary::before{transform:rotate(45deg) translate(-1px,-1px)}",
|
|
1020
|
+
".particle-source-summary:hover{background:var(--cle-hover)}",
|
|
1021
|
+
".particle-source-count{min-width:0;margin-left:auto;overflow:hidden;color:var(--cle-muted);font:9px/16px var(--cle-mono);white-space:nowrap}",
|
|
1022
|
+
".particle-library-toolbar{display:flex;align-items:center;gap:6px;min-width:0;margin:0 8px 7px}",
|
|
1023
|
+
".particle-library-add,.particle-library-clear{display:inline-flex;align-items:center;justify-content:center;min-height:24px;padding:3px 7px;" +
|
|
1024
|
+
"color:var(--cle-muted);background:var(--cle-paper-raised);border:1px solid var(--cle-rule-strong);border-radius:5px;cursor:pointer;" +
|
|
1025
|
+
"font-size:9.5px;line-height:15px}",
|
|
1026
|
+
".particle-library-add{position:relative;color:var(--cle-ink);border-color:color-mix(in srgb,var(--cle-signal) 48%,var(--cle-rule))}",
|
|
1027
|
+
".particle-library-clear{margin-left:auto}",
|
|
1028
|
+
".particle-library-clear:disabled{cursor:default;opacity:.5}",
|
|
1029
|
+
".particle-library-add:hover,.particle-library-clear:hover:not(:disabled){background:var(--cle-hover)}",
|
|
1030
|
+
".particle-library-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px;min-width:0;margin:0 8px}",
|
|
1031
|
+
".particle-library-empty{grid-column:1/-1;margin:0;padding:10px 7px;color:var(--cle-muted);background:var(--cle-paper-raised);" +
|
|
1032
|
+
"border:1px dashed var(--cle-rule-strong);border-radius:6px;font-size:9.5px;line-height:1.45;text-align:center}",
|
|
1033
|
+
".wallitem{position:relative;min-width:0}",
|
|
1034
|
+
".wallitem .wpick{display:grid;width:100%;min-width:0;padding:0;overflow:hidden;color:var(--cle-muted);background:var(--cle-paper);" +
|
|
1035
|
+
"border:1px solid var(--cle-rule);border-radius:6px;cursor:pointer;text-align:left}",
|
|
1036
|
+
".wallitem .wpick:hover{border-color:var(--cle-rule-strong)}",
|
|
1037
|
+
".wallitem.on .wpick{border-color:var(--cle-signal);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--cle-signal) 20%,transparent)}",
|
|
1038
|
+
".wallitem img,.wallitem .vthumb{display:block;width:100%;aspect-ratio:4/3;object-fit:cover;background:var(--cle-subtle)}",
|
|
1039
|
+
".wallitem .vthumb{display:grid;place-items:center;color:var(--cle-muted);font-size:14px}",
|
|
1040
|
+
".wallitem .wname{display:block;min-width:0;padding:3px 4px 4px;overflow:hidden;font-size:8.5px;line-height:13px;" +
|
|
1041
|
+
"text-overflow:ellipsis;white-space:nowrap}",
|
|
1042
|
+
".wallitem .wdel{position:absolute;z-index:3;top:3px;right:3px;display:grid;place-items:center;width:19px;height:19px;padding:0;" +
|
|
1043
|
+
"color:var(--cle-ink);background:color-mix(in srgb,var(--cle-paper-raised) 88%,transparent);border:1px solid var(--cle-rule-strong);" +
|
|
1044
|
+
"border-radius:5px;cursor:pointer;font-size:11px;line-height:1;opacity:0}",
|
|
1045
|
+
".wallitem:hover .wdel,.wallitem .wdel:focus-visible{opacity:1}",
|
|
1046
|
+
".wallitem .wdel:hover{color:#fff;background:var(--cle-deleted,#b42318);border-color:var(--cle-deleted,#b42318)}",
|
|
1047
|
+
// select / 错误行 / 备注
|
|
1048
|
+
".particle-settings-scroll select{min-height:24px;padding:2px 6px;color:var(--cle-ink);background:var(--cle-input);" +
|
|
1049
|
+
"border:1px solid var(--cle-rule-strong);border-radius:5px;font-size:10px;cursor:pointer}",
|
|
1050
|
+
".panel-note{margin:0;padding:8px;color:var(--cle-muted);background:var(--cle-subtle);border:1px solid var(--cle-rule);" +
|
|
1051
|
+
"border-radius:6px;font-size:9.5px;line-height:1.45}",
|
|
1052
|
+
".particle-plugin-error{grid-column:1/-1;margin:0;padding:6px 7px;color:var(--cle-deleted,#ff7b72);" +
|
|
1053
|
+
"background:color-mix(in srgb,var(--cle-deleted,#ff7b72) 8%,var(--cle-paper));" +
|
|
1054
|
+
"border:1px solid color-mix(in srgb,var(--cle-deleted,#ff7b72) 30%,var(--cle-rule));border-radius:5px;font-size:9.5px;line-height:1.4}",
|
|
1055
|
+
".particle-plugin-error[hidden]{display:none}",
|
|
1056
|
+
"@keyframes ccx-market-in{from{opacity:0;transform:translateY(5px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}",
|
|
1057
|
+
"@keyframes ccx-settings-in{from{opacity:0;transform:translateY(3px) scale(.99)}to{opacity:1;transform:translateY(0) scale(1)}}",
|
|
1058
|
+
// pixel-sculpt 渲染器自挂载控件:上游 git-history.ts 嵌入式主题逐条(控件 DOM 由 vendor 提供)
|
|
1059
|
+
'.particle-settings-panel .particle-settings-scroll { gap: 10px; } .particle-settings-panel .pixelSculpt-controls-host { min-width: 0; } .particle-settings-panel .pixelSculpt-disabled { margin: 0; padding: 8px; color: var(--cle-muted); background: var(--cle-subtle); border: 1px solid var(--cle-rule); border-radius: 6px; font-size: 9.5px; line-height: 1.45; } .particle-settings-panel .pixelSculpt-disabled[hidden] { display: none; } .particle-settings-panel .pixelSculpt-paused-row { margin: 0; padding-top: 9px; border-top: 1px solid var(--cle-rule); } .particle-settings-panel .pixelSculpt-actions { grid-template-columns: minmax(0, 1fr); margin-top: -2px; } .particle-settings-panel .pixelSculpt-actions button:hover { background: var(--cle-hover); border-color: color-mix(in srgb, var(--cle-signal) 45%, var(--cle-rule-strong)); } .pixel-sculpt-controls { color: var(--cle-ink); font-size: 10px; line-height: 1.45; } .pixel-sculpt-controls .panel { position: static; display: grid; gap: 0; width: 100%; max-height: none; padding: 0; overflow: visible; background: transparent; border: 0; border-radius: 0; box-shadow: none; backdrop-filter: none; } .pixel-sculpt-controls .ph { display: none; } .pixel-sculpt-controls .row:not(.gallery-block) { display: grid; grid-template-columns: minmax(92px, .9fr) minmax(72px, 1.1fr) minmax(42px, auto); align-items: center; gap: 6px; min-width: 0; min-height: 34px; margin: 0; padding: 0; color: var(--cle-muted); font-size: 10px; } .pixel-sculpt-controls .row:not(.gallery-block) > .row-head { display: contents; } .pixel-sculpt-controls .row:not(.gallery-block) > .row-head > span { grid-column: 1; min-width: 0; overflow: visible; color: var(--cle-muted); white-space: normal; } .pixel-sculpt-controls .row:not(.gallery-block) > .row-head > output { grid-column: 3; grid-row: 1; box-sizing: border-box; width: 100%; min-width: 42px; padding: 0 3px; color: var(--cle-ink); background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: text; font: 9.5px/18px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; text-align: right; user-select: none; } .pixel-sculpt-controls .row:not(.gallery-block) > .row-head > output:hover { background: var(--cle-hover); border-color: var(--cle-rule); } .pixel-sculpt-controls .row:not(.gallery-block) > input[type="range"] { grid-column: 2; grid-row: 1; } .pixel-sculpt-controls input[type="range"] { width: 100%; min-width: 0; height: auto; margin: 0; appearance: auto; accent-color: var(--cle-signal); background: transparent; border-radius: 0; cursor: pointer; } .pixel-sculpt-controls input[type="range"]::-webkit-slider-thumb { appearance: auto; width: auto; height: auto; background: initial; border: initial; border-radius: initial; box-shadow: none; } .pixel-sculpt-controls .seg { grid-column: 2 / 4; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 5px; min-width: 0; } .pixel-sculpt-controls .seg button { min-width: 0; min-height: 25px; padding: 3px 5px; overflow: hidden; color: var(--cle-muted); background: var(--cle-paper-raised); border: 1px solid var(--cle-rule-strong); border-radius: 5px; cursor: pointer; font-size: 9.5px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; } .pixel-sculpt-controls .seg button:hover, .pixel-sculpt-controls .seg button.on { color: var(--cle-ink); background: var(--cle-hover); border-color: color-mix(in srgb, var(--cle-signal) 45%, var(--cle-rule-strong)); box-shadow: none; } .pixel-sculpt-controls .toggle-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 27px; margin: 0 8px; padding: 0; color: var(--cle-muted); font-size: 9.5px; } .pixel-sculpt-controls .toggle { position: static; display: block; width: 14px; height: 14px; } .pixel-sculpt-controls .toggle input { position: static; width: 14px; height: 14px; margin: 0; opacity: 1; accent-color: var(--cle-signal); cursor: pointer; } .pixel-sculpt-controls .toggle > span { display: none; } .pixel-sculpt-controls .divider { height: 1px; margin: 9px 0; background: var(--cle-rule); } .pixel-sculpt-controls .gallery-block { display: block; min-width: 0; margin: 0 0 6px; padding: 0 0 8px; overflow: hidden; background: var(--cle-subtle); border: 1px solid var(--cle-rule); border-radius: 7px; } .pixel-sculpt-controls .gallery-block > .row-head { display: flex; align-items: center; gap: 7px; min-height: 30px; margin: 0; padding: 5px 8px; color: var(--cle-ink); font-size: 10.5px; font-weight: 600; } .pixel-sculpt-controls .gallery-block > .row-head output { min-width: 0; margin-left: auto; color: var(--cle-muted); font: 9px/16px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } .pixel-sculpt-controls .file-row { display: flex; align-items: center; gap: 6px; min-width: 0; margin: 0 8px 7px; } .pixel-sculpt-controls .file-row button, .pixel-sculpt-controls .gallery-nav button { min-height: 24px; padding: 3px 7px; color: var(--cle-muted); background: var(--cle-paper-raised); border: 1px solid var(--cle-rule-strong); border-radius: 5px; cursor: pointer; font-size: 9.5px; line-height: 15px; } .pixel-sculpt-controls .file-row button { flex: 0 0 auto; color: var(--cle-ink); border-color: color-mix(in srgb, var(--cle-signal) 48%, var(--cle-rule)); } .pixel-sculpt-controls .file-row button:disabled { cursor: default; opacity: .5; } .pixel-sculpt-controls .file-row button:hover, .pixel-sculpt-controls .gallery-nav button:hover:not(:disabled) { background: var(--cle-hover); } .pixel-sculpt-controls .file-row span { min-width: 0; margin-left: auto; overflow: hidden; color: var(--cle-muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; } .pixel-sculpt-controls .gallery-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; min-width: 0; margin: 0 8px; padding: 0; overflow: visible; } .pixel-sculpt-controls .gallery-empty { grid-column: 1 / -1; display: block; width: auto; min-height: 0; margin: 0; padding: 10px 7px; color: var(--cle-muted); background: var(--cle-paper-raised); border: 1px dashed var(--cle-rule-strong); border-radius: 6px; font-size: 9.5px; line-height: 1.45; text-align: center; } .pixel-sculpt-controls .gallery-item { position: relative; min-width: 0; height: auto; overflow: visible; background: transparent; border: 0; border-radius: 0; box-shadow: none; transition: none; } .pixel-sculpt-controls .gallery-item:hover { transform: none; } .pixel-sculpt-controls .gallery-preview { display: grid; width: 100%; height: auto; min-width: 0; padding: 0; overflow: hidden; color: var(--cle-muted); background: var(--cle-paper-raised); border: 1px solid var(--cle-rule); border-radius: 6px; cursor: pointer; } .pixel-sculpt-controls .gallery-preview:hover { border-color: var(--cle-rule-strong); } .pixel-sculpt-controls .gallery-item.is-selected .gallery-preview { border-color: var(--cle-signal); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--cle-signal) 20%, transparent); } .pixel-sculpt-controls .gallery-item.is-active .gallery-preview { box-shadow: inset 0 0 0 1px var(--cle-ink); } .pixel-sculpt-controls .gallery-preview img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; background: var(--cle-subtle); filter: none; } .pixel-sculpt-controls .gallery-name { display: block; min-width: 0; padding: 3px 4px 4px; overflow: hidden; font-size: 8.5px; line-height: 13px; text-overflow: ellipsis; white-space: nowrap; } .pixel-sculpt-controls .gallery-item .remove { position: absolute; z-index: 3; top: 3px; right: 3px; display: grid; place-items: center; width: 19px; height: 19px; padding: 0 0 1px; color: var(--cle-ink); background: color-mix(in srgb, var(--cle-paper-raised) 88%, transparent); border: 1px solid var(--cle-rule-strong); border-radius: 5px; cursor: pointer; font-size: 13px; line-height: 1; opacity: 0; } .pixel-sculpt-controls .gallery-item:hover .remove, .pixel-sculpt-controls .gallery-item:focus-within .remove { opacity: 1; } .pixel-sculpt-controls .gallery-item .remove:hover { color: #ffffff; background: var(--cle-deleted); border-color: var(--cle-deleted); } .pixel-sculpt-controls .gallery-order { position: absolute; z-index: 2; top: 4px; left: 4px; display: grid; place-items: center; min-width: 16px; height: 16px; padding: 0 4px; color: #ffffff; background: var(--cle-signal); border: 1px solid color-mix(in srgb, #ffffff 48%, transparent); border-radius: 999px; pointer-events: none; font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } .pixel-sculpt-controls .gallery-live { position: absolute; z-index: 2; right: 4px; bottom: 21px; padding: 1px 4px; color: var(--cle-ink); background: color-mix(in srgb, var(--cle-paper-raised) 88%, transparent); border: 1px solid var(--cle-rule-strong); border-radius: 3px; pointer-events: none; font: 700 7px/11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .05em; } .pixel-sculpt-controls .gallery-nav { display: grid; grid-template-columns: 32px minmax(0, 1fr) 32px; align-items: center; gap: 6px; margin: 6px 8px 0; } .pixel-sculpt-controls .gallery-nav button { height: 24px; padding: 0; } .pixel-sculpt-controls .gallery-nav button:disabled { cursor: default; opacity: .5; } .pixel-sculpt-controls .gallery-index { color: var(--cle-muted); font: 9px/16px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: center; } .pixel-sculpt-controls .color-row { grid-template-columns: minmax(0, 1fr) 29px !important; gap: 8px !important; min-height: 34px !important; } .pixel-sculpt-controls .color-row > div { display: grid; grid-template-columns: minmax(92px, .9fr) minmax(72px, 1.1fr); align-items: center; gap: 6px; min-width: 0; } .pixel-sculpt-controls .color-row > div > .row-head { margin: 0; color: var(--cle-muted); font-size: 10px; } .pixel-sculpt-controls .color-row input[type="text"] { box-sizing: border-box; width: 100%; min-width: 0; height: 22px; padding: 2px 6px; color: var(--cle-ink); background: var(--cle-input); border: 1px solid var(--cle-rule-strong); border-radius: 5px; outline: 0; font: 9.5px/16px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } .pixel-sculpt-controls .color-row input[type="color"] { width: 29px; height: 21px; padding: 2px; overflow: hidden; appearance: auto; background: var(--cle-input); border: 1px solid var(--cle-rule-strong); border-radius: 5px; cursor: pointer; } .pixel-sculpt-controls [hidden] { display: none !important; }',
|
|
1060
|
+
].join("\n");
|
|
1061
|
+
|
|
1062
|
+
var GEAR_SVG = '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="3.2"/>'
|
|
1063
|
+
+ '<path d="M19.4 15a1.7 1.7 0 0 0 .34 1.87l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.7 1.7 0 0 0-1.87-.34 1.7 1.7 0 0 0-1 1.55V21a2 2 0 1 1-4 0v-.09a1.7 1.7 0 0 0-1-1.55 1.7 1.7 0 0 0-1.87.34l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.7 1.7 0 0 0 .34-1.87 1.7 1.7 0 0 0-1.55-1H3a2 2 0 1 1 0-4h.09a1.7 1.7 0 0 0 1.55-1 1.7 1.7 0 0 0-.34-1.87l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.7 1.7 0 0 0 1.87.34h.01a1.7 1.7 0 0 0 1-1.55V3a2 2 0 1 1 4 0v.09a1.7 1.7 0 0 0 1 1.55 1.7 1.7 0 0 0 1.87-.34l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.7 1.7 0 0 0-.34 1.87v.01a1.7 1.7 0 0 0 1.55 1H21a2 2 0 1 1 0 4h-.09a1.7 1.7 0 0 0-1.55 1z"/></svg>';
|
|
1064
|
+
var CLOSE_SVG = '<svg viewBox="0 0 16 16"><path d="m3.25 3.25 9.5 9.5M12.75 3.25l-9.5 9.5"/></svg>';
|
|
1065
|
+
var SLIDERS_SVG = '<svg viewBox="0 0 16 16"><path d="M2 4h3M9 4h5M2 8h7M13 8h1M2 12h1M7 12h7"/><circle cx="7" cy="4" r="2"/><circle cx="11" cy="8" r="2"/><circle cx="5" cy="12" r="2"/></svg>';
|
|
1066
|
+
|
|
1067
|
+
// 卡片图标(逐字取自上游 plugin-card.ts / plugin-templates.ts)
|
|
1068
|
+
var CARD_ICONS = {
|
|
1069
|
+
eye: '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M1.5 8s2.35-4 6.5-4 6.5 4 6.5 4-2.35 4-6.5 4-6.5-4-6.5-4z"/><circle cx="8" cy="8" r="1.75"/></svg>',
|
|
1070
|
+
sliders: SLIDERS_SVG,
|
|
1071
|
+
waves: '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M1.8 11.9c1.3-4 2.8-6.1 4.2-6.1 1.5 0 1.6 4.4 3 4.4 1.2 0 2.1-2.7 3.3-5.9"/><path d="M3.1 13.6c1.4-2.5 2.6-3.7 3.7-3.7 1.2 0 1.8 2.1 3 2.1 1 0 1.9-1.2 2.8-3.4"/><path d="M3.4 3.3h.01M10.3 2.3h.01M13.5 7h.01"/></svg>',
|
|
1072
|
+
blackhole: '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><circle cx="8" cy="8" r="2.25" fill="currentColor" stroke="none"/><ellipse cx="8" cy="8" rx="6.1" ry="3.15" transform="rotate(-18 8 8)"/><path d="M2.5 9.7c2.4 1.15 8.2 1.15 11-2.35"/></svg>',
|
|
1073
|
+
glowhorizon: '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><ellipse cx="8" cy="9.5" rx="6.5" ry="3.3"/><path d="M1.8 8.5c1.8-2.4 10.6-2.4 12.4 0"/><path d="M3 6.4c1.9-1.5 8.1-1.5 10 0"/></svg>',
|
|
1074
|
+
heavenlycloud: '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M2.1 10.9c.7-1.1 1.8-1.7 3.1-1.7.5-2 2.1-3.3 4.1-3.3 2.4 0 4.3 1.9 4.3 4.3 0 .2 0 .5-.1.7"/><path d="M1.7 12.2h12.7M3.4 14h9.1"/><path d="M6.1 8.6c.6-1.1 1.7-1.8 3-1.8"/></svg>',
|
|
1075
|
+
mountain: '<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M1 13 6 3l4 7 2-4 3 7ZM4 7l2 2 2-2" fill="none" stroke="currentColor"/></svg>',
|
|
1076
|
+
blinking: '<svg viewBox="0 0 16 16" aria-hidden="true" fill="currentColor"><rect x="1" y="1" width="3" height="3"/><rect x="7" y="2" width="2" height="2"/><rect x="12" y="1" width="3" height="3"/><rect x="2" y="8" width="2" height="2"/><rect x="7" y="7" width="3" height="3"/><rect x="12" y="9" width="2" height="2"/><rect x="1" y="12" width="3" height="3"/><rect x="8" y="13" width="2" height="2"/></svg>',
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
// 市场卡片定义(原版英文插件名 + 中文界面文案;上游卡片标题保持英文)
|
|
1080
|
+
var CARD_TITLES = {
|
|
1081
|
+
"milky-way": "Milky Way Background",
|
|
1082
|
+
"glow-horizon": "Glow Horizon Background",
|
|
1083
|
+
"mountain": "Layered Mountain Background",
|
|
1084
|
+
"heavenly-cloud": "Heavenly Cloud Background",
|
|
1085
|
+
"aurora-ionosphere": "Aurora Ionosphere Background",
|
|
1086
|
+
"black-hole": "Black Hole Background",
|
|
1087
|
+
"cloud-train": "Cloud Train Background",
|
|
1088
|
+
"particle-image": "Particle Image Background",
|
|
1089
|
+
"pixel-sculpt": "Pixel Sculpt Background",
|
|
1090
|
+
"blinking-squares": "Blinking Squares Background",
|
|
1091
|
+
};
|
|
1092
|
+
var SCENE_CARD_META = {
|
|
1093
|
+
"milky-way": { icon: "waves", ext: "" },
|
|
1094
|
+
"glow-horizon": { icon: "glowhorizon", ext: "ext-glowhorizon" },
|
|
1095
|
+
"mountain": { icon: "mountain", ext: "" },
|
|
1096
|
+
"heavenly-cloud": { icon: "heavenlycloud", ext: "ext-heavenlycloud" },
|
|
1097
|
+
"aurora-ionosphere": { icon: "waves", ext: "" },
|
|
1098
|
+
"black-hole": { icon: "blackhole", ext: "ext-blackhole" },
|
|
1099
|
+
"cloud-train": { icon: "mountain", ext: "" },
|
|
1100
|
+
"particle-image": { icon: "eye", ext: "ext-particle" },
|
|
1101
|
+
"pixel-sculpt": { icon: "mountain", ext: "" },
|
|
1102
|
+
"blinking-squares": { icon: "blinking", ext: "" },
|
|
1103
|
+
};
|
|
1104
|
+
var CARDS = [{ id: "custom", kind: "wallpaper", title: "Custom Background", icon: "eye", ext: "" }]
|
|
1105
|
+
.concat([{ id: "surface", kind: "surface", title: "UI Surface Opacity", icon: "sliders", ext: "" }])
|
|
1106
|
+
.concat(SCENES.map(function (s) {
|
|
1107
|
+
var m = SCENE_CARD_META[s.id] || { icon: "eye", ext: "" };
|
|
1108
|
+
return { id: s.id, kind: "scene", title: CARD_TITLES[s.id] || s.en, icon: m.icon, ext: m.ext };
|
|
1109
|
+
}));
|
|
1110
|
+
|
|
1111
|
+
// 分组图例(逐字取自原版 plugin-templates.ts 的 <legend>;zh 面板只渲染中文行)
|
|
1112
|
+
var GROUP_LEGENDS = {
|
|
1113
|
+
particles: "粒子", flow: "流动", source: "来源", pointer: "指针", render: "渲染",
|
|
1114
|
+
camera: "相机", disc: "吸积盘", light: "光线",
|
|
1115
|
+
input: "输入", downward: "下滑动态", upward: "上滑动态", release: "释放回弹",
|
|
1116
|
+
entrance: "开场画面", opening: "开场动画", interaction: "交互",
|
|
1117
|
+
};
|
|
1118
|
+
var FIELD_GROUP_OVERRIDES = {
|
|
1119
|
+
"heavenly-cloud": { field: "云场", opening: "开场画面" },
|
|
1120
|
+
"aurora-ionosphere": { field: "电离层", opening: "开场画面" },
|
|
1121
|
+
"milky-way": { field: "运动与形态", opening: "开场画面" },
|
|
1122
|
+
};
|
|
1123
|
+
var TUPLE_MAIN_LEGENDS = {
|
|
1124
|
+
"mountain": "山峦与氛围", "cloud-train": "列车与云海", "blinking-squares": "参数",
|
|
1125
|
+
};
|
|
1126
|
+
var TINT_LABELS = { skyTint: "天空色", smokeTint: "烟雾色", trainTint: "列车色" };
|
|
1127
|
+
var COLOR_SECTION_LEGENDS = { "milky-way": "五色调色板", "glow-horizon": "光效配色" };
|
|
1128
|
+
var QUALITY_TOOLBARS = {
|
|
1129
|
+
"milky-way": { mode: "quality", items: [["low", "1×", "轻量"], ["medium", "2×", "均衡"], ["high", "3×", "精细"]] },
|
|
1130
|
+
"heavenly-cloud": { mode: "quality", items: [["low", "56", "低"], ["medium", "76", "中"], ["high", "100", "高"]] },
|
|
1131
|
+
"aurora-ionosphere": { mode: "quality", items: [["low", "32", "轻量"], ["medium", "50", "均衡"], ["high", "72", "精细"]] },
|
|
1132
|
+
"mountain": { mode: "steps", items: [["28", "28", "流畅"], ["42", "42", "均衡"], ["57", "57", "完整"]] },
|
|
1133
|
+
};
|
|
1134
|
+
var BH_PRESETS = [["cinema", "电影"], ["lens", "透镜"], ["ember", "余烬"]];
|
|
1135
|
+
var BLINK_DIRECTIONS = [["right", "右"], ["left", "左"], ["top", "上"], ["bottom", "下"]];
|
|
1136
|
+
|
|
1137
|
+
// ───────────── 面板挂载 ─────────────
|
|
1138
|
+
|
|
1139
|
+
function ensurePanel() {
|
|
1140
|
+
if (root9 && document.documentElement.contains(root9)) return;
|
|
1141
|
+
root9 = document.createElement("div");
|
|
1142
|
+
root9.id = PANEL_ID;
|
|
1143
|
+
root9.setAttribute("data-dsh-ccx", "panel");
|
|
1144
|
+
var shadow = root9.attachShadow({ mode: "open" });
|
|
1145
|
+
var style = document.createElement("style");
|
|
1146
|
+
style.textContent = PANEL_CSS;
|
|
1147
|
+
shadow.appendChild(style);
|
|
1148
|
+
|
|
1149
|
+
var trigger = document.createElement("button");
|
|
1150
|
+
trigger.className = "trigger";
|
|
1151
|
+
trigger.id = TRIGGER_ID;
|
|
1152
|
+
trigger.title = "背景外观(dsh-ccx)";
|
|
1153
|
+
trigger.innerHTML = GEAR_SVG;
|
|
1154
|
+
trigger.addEventListener("click", function (e) {
|
|
1155
|
+
e.stopPropagation();
|
|
1156
|
+
if (marketOpen) closeMarket(); else openMarket();
|
|
1157
|
+
});
|
|
1158
|
+
shadow.appendChild(trigger);
|
|
1159
|
+
|
|
1160
|
+
var market = document.createElement("div");
|
|
1161
|
+
market.className = "preview-market-popover";
|
|
1162
|
+
market.setAttribute("role", "dialog");
|
|
1163
|
+
market.setAttribute("aria-modal", "false");
|
|
1164
|
+
market.setAttribute("aria-label", "dsh-ccx");
|
|
1165
|
+
market.hidden = true;
|
|
1166
|
+
market.innerHTML = '<div class="preview-market-header"><h3>dsh-ccx</h3>'
|
|
1167
|
+
+ '<button class="preview-market-close" data-act="marketclose" title="关闭 dsh-ccx" aria-label="关闭 dsh-ccx">' + CLOSE_SVG + '</button></div>'
|
|
1168
|
+
+ '<div class="preview-market-list">'
|
|
1169
|
+
+ '<div class="preview-market-section-list" data-act="cards"></div>'
|
|
1170
|
+
+ '</div>';
|
|
1171
|
+
shadow.appendChild(market);
|
|
1172
|
+
|
|
1173
|
+
var settings = document.createElement("section");
|
|
1174
|
+
settings.className = "particle-settings-panel";
|
|
1175
|
+
settings.setAttribute("data-side", "right");
|
|
1176
|
+
settings.setAttribute("role", "dialog");
|
|
1177
|
+
settings.setAttribute("aria-modal", "false");
|
|
1178
|
+
settings.setAttribute("aria-label", "外观设置");
|
|
1179
|
+
settings.hidden = true;
|
|
1180
|
+
shadow.appendChild(settings);
|
|
1181
|
+
|
|
1182
|
+
(document.documentElement || document.body).appendChild(root9);
|
|
1183
|
+
ui = { trigger: trigger, market: market, settings: settings };
|
|
1184
|
+
bindMarket(market);
|
|
1185
|
+
bindSettings(settings);
|
|
1186
|
+
buildCards();
|
|
1187
|
+
document.addEventListener("click", onDocClick, true);
|
|
1188
|
+
document.addEventListener("keydown", onDocKey, true);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// 外点关闭:必须用 composedPath(shadow DOM 内点击在 document 捕获层
|
|
1192
|
+
// 只能看到宿主元素,按 e.target 判断会把面板内点击当外部点击立即关面板)
|
|
1193
|
+
function onDocClick(e) {
|
|
1194
|
+
if (!root9 || (!marketOpen && !settingsOpen)) return;
|
|
1195
|
+
var path = typeof e.composedPath === "function" ? e.composedPath() : null;
|
|
1196
|
+
if (path && path.indexOf(root9) >= 0) return;
|
|
1197
|
+
if (settingsOpen) closeSettings();
|
|
1198
|
+
else closeMarket();
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function onDocKey(e) {
|
|
1202
|
+
if (e.key !== "Escape") return;
|
|
1203
|
+
if (settingsOpen) { closeSettings(); return; } // Esc 先关设置面板,再关市场
|
|
1204
|
+
if (marketOpen) closeMarket();
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
function openMarket() {
|
|
1208
|
+
ensurePanel();
|
|
1209
|
+
marketOpen = true;
|
|
1210
|
+
ui.market.hidden = false;
|
|
1211
|
+
buildCards();
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
function closeMarket() {
|
|
1215
|
+
marketOpen = false;
|
|
1216
|
+
if (ui) ui.market.hidden = true;
|
|
1217
|
+
closeSettings();
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
function positionSettings() {
|
|
1221
|
+
if (!ui || !settingsOpen) return;
|
|
1222
|
+
var p = ui.settings;
|
|
1223
|
+
var m = 12;
|
|
1224
|
+
p.style.maxHeight = (window.innerHeight - m * 2) + "px";
|
|
1225
|
+
var left = 12 + 320 + 8; // 市场左缘 + 市场宽 + 间距
|
|
1226
|
+
left = clamp(left, m, Math.max(m, window.innerWidth - m - 344));
|
|
1227
|
+
p.style.left = Math.round(left) + "px";
|
|
1228
|
+
p.style.top = m + "px";
|
|
1229
|
+
var trig = ui.market.querySelector('[data-gear="' + settingsId + '"]');
|
|
1230
|
+
if (trig) {
|
|
1231
|
+
var pr = p.getBoundingClientRect();
|
|
1232
|
+
var trr = trig.getBoundingClientRect();
|
|
1233
|
+
var y = trr.top + trr.height / 2 - pr.top;
|
|
1234
|
+
p.style.setProperty("--cle-anchor-y", clamp(y, 14, Math.max(14, pr.height - 14)) + "px");
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// ───────────── 市场卡片 ─────────────
|
|
1239
|
+
|
|
1240
|
+
function bgActive() {
|
|
1241
|
+
return !!(state && state.enabled && state.mode !== "off");
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
function cardOn(c) {
|
|
1245
|
+
if (!state) return false;
|
|
1246
|
+
if (c.kind === "scene") return bgActive() && state.mode === "scene" && state.scene === c.id;
|
|
1247
|
+
if (c.kind === "wallpaper") return bgActive() && state.mode === "wallpaper";
|
|
1248
|
+
return !!(state.surfaces && state.surfaces.enabled);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
function cardStatus(c) {
|
|
1252
|
+
var on = cardOn(c);
|
|
1253
|
+
if (c.kind === "surface" && on) return [bgActive() ? "已启用" : "已暂停 · 无背景", on];
|
|
1254
|
+
return [on ? "已启用" : "已停用", on];
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
function buildCards() {
|
|
1258
|
+
if (!ui) return;
|
|
1259
|
+
var box = ui.market.querySelector('[data-act="cards"]');
|
|
1260
|
+
box.innerHTML = CARDS.map(function (c) {
|
|
1261
|
+
var s = cardStatus(c);
|
|
1262
|
+
return '<article class="preview-extension appearance-extension ' + c.ext + '" data-card="' + c.id + '">'
|
|
1263
|
+
+ '<span class="preview-extension-icon" aria-hidden="true">' + CARD_ICONS[c.icon] + '</span>'
|
|
1264
|
+
+ '<div class="preview-extension-copy"><div class="preview-extension-title-row">'
|
|
1265
|
+
+ '<h4>' + c.title + '</h4>'
|
|
1266
|
+
+ '<span class="preview-extension-status" data-st="' + c.id + '"' + (s[1] ? ' data-enabled="true"' : '') + '>' + s[0] + '</span>'
|
|
1267
|
+
+ '</div></div>'
|
|
1268
|
+
+ '<div class="preview-extension-actions">'
|
|
1269
|
+
+ '<button type="button" class="preview-extension-action" data-enable="' + c.id + '" data-enabled="' + s[1] + '" aria-pressed="' + s[1] + '">'
|
|
1270
|
+
+ (s[1] ? "停用" : "启用") + '</button>'
|
|
1271
|
+
+ '<button type="button" class="particle-settings-trigger" data-gear="' + c.id + '" title="Configure ' + c.title + '"'
|
|
1272
|
+
+ ' aria-haspopup="dialog" aria-expanded="' + (settingsOpen && settingsId === c.id) + '">' + SLIDERS_SVG + '</button>'
|
|
1273
|
+
+ '</div></article>';
|
|
1274
|
+
}).join("");
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
function setCardEnabled(id) {
|
|
1278
|
+
var c = null;
|
|
1279
|
+
for (var i = 0; i < CARDS.length; i++) if (CARDS[i].id === id) c = CARDS[i];
|
|
1280
|
+
if (!c || !state) return;
|
|
1281
|
+
// 上游交互语义:启用其它外观时,当前打开的设置面板自动关闭(closeOtherSettings)
|
|
1282
|
+
if (settingsOpen && settingsId && settingsId !== id) closeSettings();
|
|
1283
|
+
if (c.kind === "scene") {
|
|
1284
|
+
if (cardOn(c)) {
|
|
1285
|
+
state.enabled = false; // 停用当前场景(保留选择,便于再次启用)
|
|
1286
|
+
} else {
|
|
1287
|
+
state.scene = id;
|
|
1288
|
+
state.mode = "scene";
|
|
1289
|
+
state.enabled = true;
|
|
1290
|
+
}
|
|
1291
|
+
} else if (c.kind === "wallpaper") {
|
|
1292
|
+
if (cardOn(c)) {
|
|
1293
|
+
state.enabled = false;
|
|
1294
|
+
} else {
|
|
1295
|
+
state.mode = "wallpaper";
|
|
1296
|
+
state.enabled = true;
|
|
1297
|
+
if (!state.wallpaperId && wallpapersCache.length) state.wallpaperId = wallpapersCache[0].id;
|
|
1298
|
+
}
|
|
1299
|
+
} else {
|
|
1300
|
+
state.surfaces.enabled = !state.surfaces.enabled;
|
|
1301
|
+
}
|
|
1302
|
+
scheduleSave();
|
|
1303
|
+
applyAll();
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
function bindMarket(market) {
|
|
1307
|
+
market.addEventListener("click", function (e) {
|
|
1308
|
+
var t = e.target;
|
|
1309
|
+
if (t.closest('[data-act="marketclose"]')) { closeMarket(); return; }
|
|
1310
|
+
var en = t.closest("[data-enable]");
|
|
1311
|
+
if (en) { setCardEnabled(en.getAttribute("data-enable")); return; }
|
|
1312
|
+
var gear = t.closest("[data-gear]");
|
|
1313
|
+
if (gear) {
|
|
1314
|
+
var gid = gear.getAttribute("data-gear");
|
|
1315
|
+
if (settingsOpen && settingsId === gid) closeSettings();
|
|
1316
|
+
else openSettings(gid);
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// ───────────── 设置面板内容 ─────────────
|
|
1323
|
+
|
|
1324
|
+
function escHtml(s) {
|
|
1325
|
+
return String(s).replace(/[&<>"]/g, function (ch) {
|
|
1326
|
+
return { "&": "&", "<": "<", ">": ">", '"': """ }[ch];
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function rangeRow(f, value) {
|
|
1331
|
+
var title = f.hintZh || f.hint ? ' title="' + escHtml(f.hintZh || f.hint) + '"' : "";
|
|
1332
|
+
return '<div class="particle-control-row"' + title + '>'
|
|
1333
|
+
+ '<label for="ccx-f-' + f.key + '">' + escHtml(f.zh) + '</label>'
|
|
1334
|
+
+ '<input id="ccx-f-' + f.key + '" type="range" min="' + f.min + '" max="' + f.max + '" step="' + f.step + '" value="' + value + '" data-field="' + f.key + '" aria-label="' + escHtml(f.zh) + '">'
|
|
1335
|
+
+ '<span class="particle-control-value"><output data-fieldval="' + f.key + '">' + fmtFieldVal(f, value) + '</output></span>'
|
|
1336
|
+
+ '</div>';
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
function toggleRow(key, zh, checked) {
|
|
1340
|
+
return '<label class="particle-toggle-row">' + escHtml(zh)
|
|
1341
|
+
+ '<input type="checkbox" data-toggle="' + key + '"' + (checked ? " checked" : "") + '></label>';
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
function colorRow(key, zh, value) {
|
|
1345
|
+
return '<label class="particle-color-row">' + escHtml(zh)
|
|
1346
|
+
+ '<input type="color" value="' + escHtml(value) + '" data-colorkey="' + key + '" aria-label="' + escHtml(zh) + '"></label>';
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
function groupStart(legend) {
|
|
1350
|
+
return '<fieldset class="particle-settings-group"><legend>' + escHtml(legend) + '</legend>';
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// 底部动作区(原版:重置 / 重播;black-hole 无动作区、particle 重播开场在开场组内;
|
|
1354
|
+
// pixel-sculpt 的重置在专属分支里,动作对象是渲染器实例而非 draft)
|
|
1355
|
+
function sceneActionsHtml(sceneId) {
|
|
1356
|
+
if (sceneId === "black-hole" || sceneId === "particle-image" || sceneId === "pixel-sculpt") return "";
|
|
1357
|
+
return '<div class="glow-horizon-actions">'
|
|
1358
|
+
+ '<button type="button" data-act="draftreset">重置</button>'
|
|
1359
|
+
+ '<button type="button" data-act="replay">重播</button>'
|
|
1360
|
+
+ '</div>';
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// 分组:grouped schema 走 group 字段(含 overrides),元组 schema 主组 + intro* → 开场画面
|
|
1364
|
+
// cloud-train 例外(活体普查:全部滑杆(含 intro*)同属「列车与云海」单组)
|
|
1365
|
+
function sectionsFor(sceneId) {
|
|
1366
|
+
var sch = schemaOf(sceneId);
|
|
1367
|
+
var fields = sch && sch.fields ? sch.fields : [];
|
|
1368
|
+
var out = [];
|
|
1369
|
+
if (!fields.length) return out;
|
|
1370
|
+
if (fields[0].group) {
|
|
1371
|
+
var byGroup = {}, order = [];
|
|
1372
|
+
for (var i = 0; i < fields.length; i++) {
|
|
1373
|
+
var g = fields[i].group;
|
|
1374
|
+
if (!byGroup[g]) { byGroup[g] = []; order.push(g); }
|
|
1375
|
+
byGroup[g].push(fields[i]);
|
|
1376
|
+
}
|
|
1377
|
+
for (var k = 0; k < order.length; k++) {
|
|
1378
|
+
var leg = (FIELD_GROUP_OVERRIDES[sceneId] && FIELD_GROUP_OVERRIDES[sceneId][order[k]]) || GROUP_LEGENDS[order[k]] || order[k];
|
|
1379
|
+
out.push({ group: order[k], legend: leg, fields: byGroup[order[k]] });
|
|
1380
|
+
}
|
|
1381
|
+
return out;
|
|
1382
|
+
}
|
|
1383
|
+
var main = [], intro = [];
|
|
1384
|
+
for (var n = 0; n < fields.length; n++) {
|
|
1385
|
+
(/^intro/.test(fields[n].key) && sceneId !== "cloud-train" ? intro : main).push(fields[n]);
|
|
1386
|
+
}
|
|
1387
|
+
if (main.length) out.push({ legend: TUPLE_MAIN_LEGENDS[sceneId] || "参数", fields: main });
|
|
1388
|
+
if (intro.length) out.push({ legend: "开场画面", fields: intro });
|
|
1389
|
+
return out;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function galleryHtml(sceneId) {
|
|
1393
|
+
var reg = window[GALLERIES_SYM];
|
|
1394
|
+
var gal = reg && reg.get ? reg.get(sceneId) : null;
|
|
1395
|
+
var count = gal && gal.count ? gal.count : 0;
|
|
1396
|
+
var items = "";
|
|
1397
|
+
if (gal && gal.images) {
|
|
1398
|
+
gal.images.forEach(function (img) {
|
|
1399
|
+
var thumb = img.thumbnail
|
|
1400
|
+
? '<img loading="lazy" src="data:' + (img.type || "image/png") + ';base64,' + img.thumbnail + '" alt="">'
|
|
1401
|
+
: '<span class="vthumb">🖼</span>';
|
|
1402
|
+
items += '<span class="wallitem"><span class="wpick">' + thumb + '<span class="wname">' + escHtml(img.name || img.id) + '</span></span></span>';
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
return '<details class="particle-source-details" open><summary class="particle-source-summary">图片库'
|
|
1406
|
+
+ '<span class="particle-source-count">' + count + ' 个已保存</span></summary>'
|
|
1407
|
+
+ '<div class="particle-library-grid">' + (items || '<p class="particle-library-empty">图库尚未就绪,启用场景后自动载入默认图。</p>') + '</div>'
|
|
1408
|
+
+ '</details>';
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// 场景设置主体(draft 驱动;控件变更实时生效——结构逐项对照活体普查 docs/codex-ui/panel-inventory.json)
|
|
1412
|
+
function sceneSettingsHtml(sceneId) {
|
|
1413
|
+
var sch = schemaOf(sceneId);
|
|
1414
|
+
var d = draft || {};
|
|
1415
|
+
var html = '<div class="particle-settings-scroll">';
|
|
1416
|
+
var inlineToggles = {};
|
|
1417
|
+
if (sceneId === "pixel-sculpt") {
|
|
1418
|
+
// 上游面板结构(plugin-templates #cle-pixelSculpt-settings):未启用提示 +
|
|
1419
|
+
// 渲染器自挂载控件(参数/图库/相机三段)+ 暂停动画 + 重置参数。
|
|
1420
|
+
// schema 全空、不依赖字段清单,放在 schema 检查之前避免误报「尚未加载」
|
|
1421
|
+
html += '<p class="pixelSculpt-disabled" data-psnote' + (psActive() ? " hidden" : "") + '>插件尚未启用;这里的设置会在下次启用时生效。</p>';
|
|
1422
|
+
html += '<div class="pixelSculpt-controls-host" data-pshost></div>';
|
|
1423
|
+
html += '<label class="particle-toggle-row pixelSculpt-paused-row">暂停动画'
|
|
1424
|
+
+ '<input type="checkbox" data-toggle="__pspaused"' + (psPaused() ? " checked" : "") + (psActive() ? "" : " disabled") + '></label>';
|
|
1425
|
+
html += '<div class="glow-horizon-actions single pixelSculpt-actions"><button type="button" data-act="psreset"'
|
|
1426
|
+
+ (psEd && psEd.inst ? "" : " disabled") + '>重置参数</button></div>';
|
|
1427
|
+
html += '<p class="particle-plugin-error" role="status" hidden></p>';
|
|
1428
|
+
return html + '</div>';
|
|
1429
|
+
}
|
|
1430
|
+
if (!sch) return '<div class="particle-settings-scroll"><p class="panel-note">场景 schema 尚未加载…</p></div>';
|
|
1431
|
+
if (sceneId === "blinking-squares") {
|
|
1432
|
+
html += groupStart("渐隐方向");
|
|
1433
|
+
html += '<div class="heavenly-cloud-quality-toolbar dir4" role="group" aria-label="渐隐方向">';
|
|
1434
|
+
for (var li = 0; li < BLINK_DIRECTIONS.length; li++) {
|
|
1435
|
+
var bd = BLINK_DIRECTIONS[li];
|
|
1436
|
+
html += '<button type="button" data-blinkdir="' + bd[0] + '" aria-pressed="' + ((d.direction || "right") === bd[0]) + '">' + bd[1] + '</button>';
|
|
1437
|
+
}
|
|
1438
|
+
html += '</div></fieldset>';
|
|
1439
|
+
// 原版五段结构:方块与闪烁 / 交互与脉冲 / 开场与画质 / 颜色(活体普查 27 行)
|
|
1440
|
+
var bl = sch.fields;
|
|
1441
|
+
html += groupStart("方块与闪烁");
|
|
1442
|
+
for (var b1 = 0; b1 < 10; b1++) html += rangeRow(bl[b1], num(d[bl[b1].key], bl[b1].min));
|
|
1443
|
+
html += '</fieldset>';
|
|
1444
|
+
html += groupStart("交互与脉冲");
|
|
1445
|
+
for (var b2 = 10; b2 < 20; b2++) html += rangeRow(bl[b2], num(d[bl[b2].key], bl[b2].min));
|
|
1446
|
+
html += toggleRow("mouseInteraction", "鼠标交互", !!d.mouseInteraction);
|
|
1447
|
+
html += toggleRow("keyboardInteraction", "键盘随机波纹", !!d.keyboardInteraction);
|
|
1448
|
+
for (var b3 = 20; b3 < 22; b3++) html += rangeRow(bl[b3], num(d[bl[b3].key], bl[b3].min));
|
|
1449
|
+
html += '</fieldset>';
|
|
1450
|
+
html += groupStart("开场与画质");
|
|
1451
|
+
for (var b4 = 22; b4 < bl.length; b4++) html += rangeRow(bl[b4], num(d[bl[b4].key], bl[b4].min));
|
|
1452
|
+
html += toggleRow("introEnabled", "启用开场", !!d.introEnabled);
|
|
1453
|
+
html += toggleRow("paused", "暂停动画", !!d.paused);
|
|
1454
|
+
html += '</fieldset>';
|
|
1455
|
+
html += groupStart("颜色");
|
|
1456
|
+
var blc = sch.colorFields || [];
|
|
1457
|
+
for (var b5 = 0; b5 < blc.length; b5++) html += colorRow(blc[b5].key, blc[b5].zh, d[blc[b5].key] || sch.defaults[blc[b5].key] || "#ffffff");
|
|
1458
|
+
html += '</fieldset>';
|
|
1459
|
+
html += sceneActionsHtml(sceneId);
|
|
1460
|
+
html += '<p class="particle-plugin-error" role="status" hidden></p>';
|
|
1461
|
+
return html + '</div>';
|
|
1462
|
+
}
|
|
1463
|
+
if (sceneId === "black-hole") {
|
|
1464
|
+
html += '<div class="black-hole-preset-toolbar" role="group" aria-label="黑洞场景预设">';
|
|
1465
|
+
for (var bi = 0; bi < BH_PRESETS.length; bi++) {
|
|
1466
|
+
var bp = BH_PRESETS[bi];
|
|
1467
|
+
html += '<button type="button" data-bhpreset="' + bp[0] + '">' + bp[1] + '</button>';
|
|
1468
|
+
}
|
|
1469
|
+
html += '<button type="button" class="black-hole-reset" data-act="draftreset">重置</button></div>';
|
|
1470
|
+
}
|
|
1471
|
+
if (sceneId === "glow-horizon") {
|
|
1472
|
+
html += '<div class="glow-horizon-direction-toolbar" role="group" aria-label="地平线方向">';
|
|
1473
|
+
var dirMeta = [["top", "↑", "上"], ["bottom", "↓", "下"], ["left", "←", "左"], ["right", "→", "右"]];
|
|
1474
|
+
for (var di = 0; di < dirMeta.length; di++) {
|
|
1475
|
+
var dm = dirMeta[di];
|
|
1476
|
+
html += '<button type="button" data-direction="' + dm[0] + '" aria-pressed="' + (d.variant === dm[0]) + '">'
|
|
1477
|
+
+ '<span class="glow-horizon-direction-symbol">' + dm[1] + '</span>' + dm[2] + '</button>';
|
|
1478
|
+
}
|
|
1479
|
+
html += '</div>';
|
|
1480
|
+
}
|
|
1481
|
+
// 渲染质量组:milky-way/heavenly-cloud/aurora 在最前(活体顺序),mountain 在主组之后
|
|
1482
|
+
var qt = QUALITY_TOOLBARS[sceneId];
|
|
1483
|
+
function qualityGroupHtml() {
|
|
1484
|
+
var out = groupStart("渲染质量");
|
|
1485
|
+
out += '<div class="heavenly-cloud-quality-toolbar" role="group" aria-label="渲染质量">';
|
|
1486
|
+
for (var qi = 0; qi < qt.items.length; qi++) {
|
|
1487
|
+
var it = qt.items[qi];
|
|
1488
|
+
var cur = qt.mode === "steps" ? String(num(d.steps, 57)) : (d.quality || sch.qualityDefault || "high");
|
|
1489
|
+
out += '<button type="button" data-' + qt.mode + '="' + it[0] + '" aria-pressed="' + (cur === it[0]) + '">'
|
|
1490
|
+
+ '<strong>' + it[1] + '</strong>' + it[2] + '</button>';
|
|
1491
|
+
}
|
|
1492
|
+
out += '</div>';
|
|
1493
|
+
if (qt.mode === "steps") { // mountain:渲染比例滑杆同属渲染质量组(活体普查)
|
|
1494
|
+
for (var rf = 0; rf < sch.fields.length; rf++) {
|
|
1495
|
+
if (sch.fields[rf].key === "resolution") out += rangeRow(sch.fields[rf], num(d.resolution, sch.fields[rf].min));
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return out + '</fieldset>';
|
|
1499
|
+
}
|
|
1500
|
+
if (qt && sceneId !== "mountain") html += qualityGroupHtml();
|
|
1501
|
+
// 分组滑杆
|
|
1502
|
+
var sections = sectionsFor(sceneId);
|
|
1503
|
+
if (sceneId === "mountain" && sections.length) {
|
|
1504
|
+
sections[0].fields = sections[0].fields.filter(function (f) { return f.key !== "resolution"; });
|
|
1505
|
+
}
|
|
1506
|
+
for (var si = 0; si < sections.length; si++) {
|
|
1507
|
+
var sec = sections[si];
|
|
1508
|
+
html += groupStart(sec.legend);
|
|
1509
|
+
for (var fi = 0; fi < sec.fields.length; fi++) html += rangeRow(sec.fields[fi], num(d[sec.fields[fi].key], sec.fields[fi].min));
|
|
1510
|
+
if (sceneId === "black-hole" && sec.group === "light") {
|
|
1511
|
+
var cfs = sch.colorFields || [];
|
|
1512
|
+
for (var ci = 0; ci < cfs.length; ci++) html += colorRow(cfs[ci].key, cfs[ci].zh, d[cfs[ci].key] || sch.defaults[cfs[ci].key] || "#ffffff");
|
|
1513
|
+
}
|
|
1514
|
+
if (sceneId === "black-hole" && sec.group === "renderer") {
|
|
1515
|
+
html += toggleRow("paused", "暂停动画", !!d.paused);
|
|
1516
|
+
inlineToggles.paused = true;
|
|
1517
|
+
}
|
|
1518
|
+
if (sceneId === "glow-horizon" && sec.group === "input") {
|
|
1519
|
+
html += toggleRow("inertialWheel", "滚轮惯性", !!d.inertialWheel);
|
|
1520
|
+
inlineToggles.inertialWheel = true;
|
|
1521
|
+
}
|
|
1522
|
+
if (sceneId === "particle-image" && sec.group === "source") {
|
|
1523
|
+
html += galleryHtml(sceneId);
|
|
1524
|
+
html += colorRow("backgroundColor", "背景", d.backgroundColor || "#000000");
|
|
1525
|
+
html += toggleRow("autoSwitch", "自动切换", d.autoSwitch !== false);
|
|
1526
|
+
inlineToggles.autoSwitch = true;
|
|
1527
|
+
}
|
|
1528
|
+
if (sceneId === "particle-image" && sec.group === "opening") {
|
|
1529
|
+
html += toggleRow("introEnabled", "粒子汇聚", !!d.introEnabled);
|
|
1530
|
+
inlineToggles.introEnabled = true;
|
|
1531
|
+
html += '<button type="button" class="particle-library-add" data-act="replay" style="margin:2px 8px 0;justify-self:start"'
|
|
1532
|
+
+ (bgInstance && bgSceneId === sceneId ? "" : " disabled") + '>重播开场</button>';
|
|
1533
|
+
}
|
|
1534
|
+
if (sceneId === "particle-image" && sec.group === "pointer") {
|
|
1535
|
+
html += toggleRow("cursorInteraction", "鼠标交互", !!d.cursorInteraction);
|
|
1536
|
+
inlineToggles.cursorInteraction = true;
|
|
1537
|
+
}
|
|
1538
|
+
if (sceneId === "cloud-train") { // 活体普查:三染色行同属列车与云海组
|
|
1539
|
+
var tints = sch.colorFields || [];
|
|
1540
|
+
for (var ki = 0; ki < tints.length; ki++) {
|
|
1541
|
+
html += colorRow(tints[ki].key, TINT_LABELS[tints[ki].key] || tints[ki].zh, d[tints[ki].key] || "#ffffff");
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
html += '</fieldset>';
|
|
1545
|
+
}
|
|
1546
|
+
if (qt && sceneId === "mountain") html += qualityGroupHtml();
|
|
1547
|
+
// 场景级开关(paused 在前;已内联的跳过)
|
|
1548
|
+
var tgs = (sch.toggles || []).slice().sort(function (a, b) { return (a.key === "paused" ? -1 : 0) - (b.key === "paused" ? -1 : 0); });
|
|
1549
|
+
for (var ti = 0; ti < tgs.length; ti++) {
|
|
1550
|
+
if (inlineToggles[tgs[ti].key]) continue;
|
|
1551
|
+
if (sceneId === "particle-image" && tgs[ti].key === "showSourceImage") {
|
|
1552
|
+
html += toggleRow("showSourceImage", "显示源图", d.showSourceImage !== false);
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
html += toggleRow(tgs[ti].key, tgs[ti].zh, !!d[tgs[ti].key]);
|
|
1556
|
+
}
|
|
1557
|
+
// 色板段(milky-way 五色调色板)
|
|
1558
|
+
if (sch.colors) {
|
|
1559
|
+
html += groupStart(COLOR_SECTION_LEGENDS[sceneId] || "颜色");
|
|
1560
|
+
var cols = Array.isArray(d.colors) && d.colors.length === sch.colors.length ? d.colors : sch.colors;
|
|
1561
|
+
for (var pi = 0; pi < sch.colors.length; pi++) html += colorRow("color" + pi, "颜色 " + (pi + 1), cols[pi]);
|
|
1562
|
+
html += '</fieldset>';
|
|
1563
|
+
}
|
|
1564
|
+
html += sceneActionsHtml(sceneId);
|
|
1565
|
+
html += '<p class="particle-plugin-error" role="status" hidden></p>';
|
|
1566
|
+
return html + '</div>';
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
function customSettingsHtml() {
|
|
1570
|
+
var pages = Math.max(1, Math.ceil(wallpapersCache.length / LIB_PAGE_SIZE));
|
|
1571
|
+
if (libPage >= pages) libPage = pages - 1;
|
|
1572
|
+
var slice = wallpapersCache.slice(libPage * LIB_PAGE_SIZE, libPage * LIB_PAGE_SIZE + LIB_PAGE_SIZE);
|
|
1573
|
+
var items = slice.map(function (w) {
|
|
1574
|
+
var isVideo = /^video\//.test(w.mime || "");
|
|
1575
|
+
var thumb = isVideo
|
|
1576
|
+
? '<span class="vthumb">▶</span>'
|
|
1577
|
+
: '<img loading="lazy" src="' + w.url + '" alt="">';
|
|
1578
|
+
return '<span class="wallitem' + (w.id === state.wallpaperId ? " on" : "") + '">'
|
|
1579
|
+
+ '<button type="button" class="wpick" data-wall="' + w.id + '" title="' + escHtml(w.name) + '">' + thumb
|
|
1580
|
+
+ '<span class="wname">' + escHtml(w.name) + '</span></button>'
|
|
1581
|
+
+ '<button type="button" class="wdel" data-wdel="' + w.id + '" title="删除" aria-label="删除 ' + escHtml(w.name) + '">✕</button></span>';
|
|
1582
|
+
}).join("");
|
|
1583
|
+
var html = '<div class="particle-settings-scroll">';
|
|
1584
|
+
html += '<details class="particle-source-details" open><summary class="particle-source-summary">图片库'
|
|
1585
|
+
+ '<span class="particle-source-count">' + wallpapersCache.length + ' 个已保存</span></summary>'
|
|
1586
|
+
+ '<div class="particle-library-toolbar"><span class="particle-library-add" data-act="wallimport">添加图片'
|
|
1587
|
+
+ '<input type="file" data-act="wallfile" accept="image/*,video/mp4,video/webm" hidden></span>'
|
|
1588
|
+
+ '<button type="button" class="particle-library-clear" data-act="wallclear"' + (wallpapersCache.length ? "" : " disabled") + '>清空</button></div>'
|
|
1589
|
+
+ '<div class="particle-library-grid">' + (items || '<p class="particle-library-empty">还没有壁纸,点「添加图片」导入图片或视频。</p>') + '</div>'
|
|
1590
|
+
+ '</details>';
|
|
1591
|
+
html += groupStart("素材属性");
|
|
1592
|
+
html += '<div class="particle-control-row"><label for="ccx-fit">画面适配</label>'
|
|
1593
|
+
+ '<select id="ccx-fit" data-act="fit">'
|
|
1594
|
+
+ '<option value="cover"' + (state.wallpaperFit === "cover" ? " selected" : "") + '>铺满</option>'
|
|
1595
|
+
+ '<option value="contain"' + (state.wallpaperFit === "contain" ? " selected" : "") + '>完整显示</option>'
|
|
1596
|
+
+ '<option value="tile"' + (state.wallpaperFit === "tile" ? " selected" : "") + '>平铺</option></select>'
|
|
1597
|
+
+ '<span class="particle-control-value"></span></div>';
|
|
1598
|
+
html += '<div class="particle-control-row"><label for="ccx-pos">位置</label>'
|
|
1599
|
+
+ '<select id="ccx-pos" data-act="pos">'
|
|
1600
|
+
+ ["center|居中", "top|顶部", "bottom|底部", "left|左侧", "right|右侧"].map(function (o) {
|
|
1601
|
+
var kv = o.split("|");
|
|
1602
|
+
return '<option value="' + kv[0] + '"' + (state.wallpaperPosition === kv[0] ? " selected" : "") + '>' + kv[1] + '</option>';
|
|
1603
|
+
}).join("")
|
|
1604
|
+
+ '</select><span class="particle-control-value"></span></div>';
|
|
1605
|
+
html += '</fieldset>';
|
|
1606
|
+
html += '<div class="glow-horizon-actions single"><button type="button" data-act="customreset">重置参数</button></div>';
|
|
1607
|
+
html += '<p class="particle-plugin-error" role="status" hidden></p>';
|
|
1608
|
+
return html + '</div>';
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
function surfaceSettingsHtml() {
|
|
1612
|
+
var html = '<div class="particle-settings-scroll">';
|
|
1613
|
+
html += '<p class="panel-note">只调节底色,文字和图标保持清晰。0% 完全透明,100% 完全遮挡背景。</p>';
|
|
1614
|
+
html += groupStart("分区不透明度");
|
|
1615
|
+
for (var i = 0; i < REGION_ROWS.length; i++) {
|
|
1616
|
+
var r = REGION_ROWS[i];
|
|
1617
|
+
var v = clamp(num(state.surfaces && state.surfaces[r.key], 66), 0, 100);
|
|
1618
|
+
html += '<div class="particle-control-row surface-opacity-row"><label for="ccx-r-' + r.key + '">' + escHtml(r.zh) + '</label>'
|
|
1619
|
+
+ '<input id="ccx-r-' + r.key + '" type="range" min="0" max="100" step="1" value="' + v + '" data-region="' + r.key + '" aria-label="' + escHtml(r.zh) + '">'
|
|
1620
|
+
+ '<span class="particle-control-value"><output data-regionval="' + r.key + '">' + Math.round(v) + '%</output></span>'
|
|
1621
|
+
+ '<button type="button" data-rowreset="' + r.key + '" title="恢复此项默认值" aria-label="恢复' + escHtml(r.zh) + '默认值">↺</button></div>';
|
|
1622
|
+
}
|
|
1623
|
+
html += '</fieldset>';
|
|
1624
|
+
html += groupStart("背景调节");
|
|
1625
|
+
for (var p = 0; p < PARAM_ROWS.length; p++) {
|
|
1626
|
+
var row = PARAM_ROWS[p];
|
|
1627
|
+
var vv = Number(state[row.key]) * row.scale;
|
|
1628
|
+
html += '<div class="particle-control-row"><label for="ccx-p-' + row.key + '">' + row.zh + '</label>'
|
|
1629
|
+
+ '<input id="ccx-p-' + row.key + '" type="range" min="' + row.min + '" max="' + row.max + '" step="' + row.step + '" value="' + vv + '" data-slider="' + row.key + '" aria-label="' + row.zh + '">'
|
|
1630
|
+
+ '<span class="particle-control-value"><output data-sliderval="' + row.key + '">'
|
|
1631
|
+
+ (row.scale === 100 ? Math.round(vv) + "%" : vv.toFixed(1) + "px") + '</output></span></div>';
|
|
1632
|
+
}
|
|
1633
|
+
html += '</fieldset>';
|
|
1634
|
+
html += '<button type="button" class="particle-library-clear" data-act="surfacereset" style="justify-self:stretch;margin:0">恢复全部默认值</button>';
|
|
1635
|
+
html += '<p class="particle-plugin-error" role="status" hidden></p>';
|
|
1636
|
+
return html + '</div>';
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// ───────────── 草稿工具(应用制提交的真值口径,v0.6 起未变) ─────────────
|
|
1640
|
+
|
|
1641
|
+
function sanitizeDraft(sceneId, d) {
|
|
1642
|
+
var sch = schemaOf(sceneId);
|
|
1643
|
+
var out = d && typeof d === "object" ? Object.assign({}, d) : {};
|
|
1644
|
+
if (!sch) return out;
|
|
1645
|
+
if (["low", "medium", "high"].indexOf(out.quality) < 0) out.quality = sch.qualityDefault || "high";
|
|
1646
|
+
for (var i = 0; i < sch.fields.length; i++) {
|
|
1647
|
+
var f = sch.fields[i];
|
|
1648
|
+
var n = Number(out[f.key]);
|
|
1649
|
+
if (!Number.isFinite(n)) { out[f.key] = num(sch.defaults[f.key], f.min); continue; }
|
|
1650
|
+
out[f.key] = clamp(n, f.min, f.max);
|
|
1651
|
+
}
|
|
1652
|
+
if (sch.colors) {
|
|
1653
|
+
var cols = Array.isArray(out.colors) ? out.colors : sch.colors.slice();
|
|
1654
|
+
out.colors = sch.colors.map(function (c, idx) {
|
|
1655
|
+
return typeof cols[idx] === "string" && /^#[\da-fA-F]{6}$/.test(cols[idx]) ? cols[idx] : c;
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
// 键控颜色行 + 布尔开关(原版面板同构字段)
|
|
1659
|
+
var cfs = sch.colorFields || [];
|
|
1660
|
+
for (var c = 0; c < cfs.length; c++) {
|
|
1661
|
+
var cv = out[cfs[c].key];
|
|
1662
|
+
out[cfs[c].key] = typeof cv === "string" && /^#[\da-fA-F]{6}$/.test(cv) ? cv : sch.defaults[cfs[c].key];
|
|
1663
|
+
}
|
|
1664
|
+
var tgs = sch.toggles || [];
|
|
1665
|
+
for (var t = 0; t < tgs.length; t++) out[tgs[t].key] = !!out[tgs[t].key];
|
|
1666
|
+
return out;
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
function ensureDrawerDraft(sceneId) {
|
|
1670
|
+
var sch = schemaOf(sceneId);
|
|
1671
|
+
var base = sch && sch.defaults ? Object.assign({}, sch.defaults) : {};
|
|
1672
|
+
var saved = state && state.sceneParams && state.sceneParams[sceneId];
|
|
1673
|
+
if (saved && typeof saved === "object") {
|
|
1674
|
+
for (var k in saved) if (Object.prototype.hasOwnProperty.call(saved, k)) base[k] = saved[k];
|
|
1675
|
+
}
|
|
1676
|
+
draft = sanitizeDraft(sceneId, base);
|
|
1677
|
+
draftScene = sceneId;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
function fmtFieldVal(f, value) {
|
|
1681
|
+
if (f.percent) return Math.round(value * 100) + "%";
|
|
1682
|
+
var dec = f.precision != null ? f.precision : (String(f.step).indexOf(".") >= 0 ? (String(f.step).split(".")[1] || "").length : 0);
|
|
1683
|
+
return Number(value).toFixed(dec) + (f.unit || "");
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// 草稿相对 schema 默认值的增量(apply 提交与"待应用"角标共用一个口径)
|
|
1687
|
+
function draftDeltaObj(sceneId) {
|
|
1688
|
+
var sch = schemaOf(sceneId);
|
|
1689
|
+
var base = sch && sch.defaults ? sch.defaults : {};
|
|
1690
|
+
var full = sanitizeDraft(sceneId, draft);
|
|
1691
|
+
var delta = {};
|
|
1692
|
+
for (var k in full) {
|
|
1693
|
+
if (!Object.prototype.hasOwnProperty.call(full, k)) continue;
|
|
1694
|
+
if (k === "quality" && !(k in base)) continue; // 无质量档的场景不落 quality 键
|
|
1695
|
+
if (JSON.stringify(full[k]) !== JSON.stringify(base[k])) delta[k] = full[k];
|
|
1696
|
+
}
|
|
1697
|
+
return { delta: delta, full: full, base: base };
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
function settingsTitle(id) {
|
|
1701
|
+
for (var i = 0; i < CARDS.length; i++) if (CARDS[i].id === id) return CARDS[i].title;
|
|
1702
|
+
return id;
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
function renderSettings(id) {
|
|
1706
|
+
if (!ui) return;
|
|
1707
|
+
var isScene = SCENE_IDS.indexOf(id) >= 0;
|
|
1708
|
+
var body;
|
|
1709
|
+
if (!isScene) body = id === "custom" ? customSettingsHtml() : surfaceSettingsHtml();
|
|
1710
|
+
else {
|
|
1711
|
+
if (!draftScene || draftScene !== id) ensureDrawerDraft(id);
|
|
1712
|
+
draftScene = id;
|
|
1713
|
+
body = sceneSettingsHtml(id);
|
|
1714
|
+
}
|
|
1715
|
+
ui.settings.innerHTML = '<header class="particle-settings-header"><div class="particle-settings-heading">'
|
|
1716
|
+
+ '<p>外观</p>'
|
|
1717
|
+
+ '<h3>' + escHtml(settingsTitle(id)) + '</h3></div>'
|
|
1718
|
+
+ '<div class="particle-settings-header-actions">'
|
|
1719
|
+
+ '<button class="particle-settings-close" type="button" data-act="settingsclose" title="关闭设置 (Esc)" aria-label="关闭设置">' + CLOSE_SVG + '</button>'
|
|
1720
|
+
+ '</div></header>' + body;
|
|
1721
|
+
positionSettings();
|
|
1722
|
+
if (id === "pixel-sculpt") mountPsControls();
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
function openSettings(id) {
|
|
1726
|
+
ensurePanel();
|
|
1727
|
+
settingsId = id;
|
|
1728
|
+
settingsOpen = true;
|
|
1729
|
+
ui.settings.hidden = false;
|
|
1730
|
+
renderSettings(id);
|
|
1731
|
+
buildCards();
|
|
1732
|
+
if (SCENE_IDS.indexOf(id) >= 0) {
|
|
1733
|
+
ensureSchemas().then(function () {
|
|
1734
|
+
if (settingsOpen && settingsId === id) renderSettings(id);
|
|
1735
|
+
});
|
|
1736
|
+
if (GALLERY_SCENES[id]) {
|
|
1737
|
+
ensureGallery(id).then(function () {
|
|
1738
|
+
var e0 = registry() && registry().get(id);
|
|
1739
|
+
return e0 && typeof e0.prepareDefaults === "function" ? e0.prepareDefaults() : null;
|
|
1740
|
+
}).then(function () {
|
|
1741
|
+
return ensureGallerySelection(id);
|
|
1742
|
+
}).then(function () {
|
|
1743
|
+
if (settingsOpen && settingsId === id) renderSettings(id);
|
|
1744
|
+
}).catch(function () {});
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
function closeSettings() {
|
|
1750
|
+
settingsOpen = false;
|
|
1751
|
+
settingsId = null;
|
|
1752
|
+
if (ui) ui.settings.hidden = true;
|
|
1753
|
+
buildCards();
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// ───────────── 设置面板事件(委托;draft 应用制提交) ─────────────
|
|
1757
|
+
|
|
1758
|
+
// ───────────── 实时提交(上游语义:控件变更 → 写 store + renderer.setSettings) ─────────────
|
|
1759
|
+
|
|
1760
|
+
// 各 vendor 渲染器实例的实时设置方法名(startup 返回值即渲染器实例)
|
|
1761
|
+
function pushLiveSettings(inst, full) {
|
|
1762
|
+
if (!inst) return false;
|
|
1763
|
+
var fn = inst.setSettings || inst.updateSettings || inst.setRenderSettings;
|
|
1764
|
+
if (typeof fn !== "function") return false;
|
|
1765
|
+
try { fn.call(inst, full); return true; } catch (e) { return false; }
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
// 控件变更 → 全量设置写入场景 store(渲染器启动真值,与上游控制器同语义)+
|
|
1769
|
+
// 直推运行中的渲染器实例(不重建、不重播开场)+ 稀疏增量落盘宿主
|
|
1770
|
+
function commitLive(sceneId) {
|
|
1771
|
+
if (!draftScene || !draft || draftScene !== sceneId) return;
|
|
1772
|
+
var dd = draftDeltaObj(sceneId);
|
|
1773
|
+
if (Object.keys(dd.delta).length) state.sceneParams[sceneId] = dd.delta;
|
|
1774
|
+
else delete state.sceneParams[sceneId]; // 全默认 = 不留增量键
|
|
1775
|
+
writeSceneSetting(sceneId, dd.full);
|
|
1776
|
+
scheduleSave();
|
|
1777
|
+
// particle「背景」颜色控件:渲染器不消费,直接改层底色(上游控制器同款语义)
|
|
1778
|
+
if (sceneId === "particle-image" && layer) {
|
|
1779
|
+
layer.style.setProperty("--ap-layer-bg", sceneLayerBg(sceneId));
|
|
1780
|
+
}
|
|
1781
|
+
var pushed = false;
|
|
1782
|
+
if (state.enabled && state.mode === "scene" && state.scene === sceneId && bgInstance && bgSceneId === sceneId) {
|
|
1783
|
+
pushed = pushLiveSettings(bgInstance, dd.full);
|
|
1784
|
+
}
|
|
1785
|
+
if (!pushed && state.enabled && state.mode === "scene" && state.scene === sceneId) {
|
|
1786
|
+
renderScene(); // 实例不在(加载失败/竞态)→ 一次性重建兜底
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
function resetDraft() {
|
|
1791
|
+
if (!draftScene) return;
|
|
1792
|
+
var sch = schemaOf(draftScene);
|
|
1793
|
+
draft = sch && sch.defaults ? sanitizeDraft(draftScene, sch.defaults) : {};
|
|
1794
|
+
renderSettings(draftScene);
|
|
1795
|
+
commitLive(draftScene); // 原版 reset = updateSettings(DEFAULTS),即时生效
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
function replayScene(sceneId) {
|
|
1799
|
+
var inst = bgInstance && bgSceneId === sceneId ? bgInstance : null;
|
|
1800
|
+
if (!inst) return;
|
|
1801
|
+
if (typeof inst.replayOpening === "function") { try { inst.replayOpening(); } catch (e) {} return; }
|
|
1802
|
+
if (typeof inst.replay === "function") { try { inst.replay(); } catch (e) {} }
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
function bindSettings(panel) {
|
|
1806
|
+
panel.addEventListener("click", function (e) {
|
|
1807
|
+
var t = e.target;
|
|
1808
|
+
if (t.closest('[data-act="settingsclose"]')) { closeSettings(); return; }
|
|
1809
|
+
if (t.closest('[data-act="psreset"]')) {
|
|
1810
|
+
// pixel-sculpt 重置对象是渲染器实例(runtime 全量默认),宿主侧只清 paused 增量
|
|
1811
|
+
if (psEd && psEd.inst) {
|
|
1812
|
+
try { psEd.inst.reset(); } catch (e2) {}
|
|
1813
|
+
if (state.sceneParams) delete state.sceneParams["pixel-sculpt"];
|
|
1814
|
+
writeSceneSetting("pixel-sculpt", { paused: false });
|
|
1815
|
+
scheduleSave();
|
|
1816
|
+
syncPsPanel();
|
|
1817
|
+
setStatus("Pixel Sculpt 参数已重置");
|
|
1818
|
+
}
|
|
1819
|
+
return;
|
|
1820
|
+
}
|
|
1821
|
+
if (t.closest('[data-act="draftreset"]')) { resetDraft(); return; }
|
|
1822
|
+
if (t.closest('[data-act="replay"]')) { replayScene(draftScene); return; }
|
|
1823
|
+
if (t.closest('[data-act="surfacereset"]')) {
|
|
1824
|
+
state.surfaces = Object.assign({}, DEFAULTS.surfaces);
|
|
1825
|
+
state.dim = DEFAULTS.dim;
|
|
1826
|
+
state.blur = DEFAULTS.blur;
|
|
1827
|
+
scheduleSave();
|
|
1828
|
+
applyAll();
|
|
1829
|
+
renderSettings("surface");
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
if (t.closest('[data-act="customreset"]')) {
|
|
1833
|
+
state.wallpaperFit = DEFAULTS.wallpaperFit;
|
|
1834
|
+
state.wallpaperPosition = DEFAULTS.wallpaperPosition;
|
|
1835
|
+
scheduleSave();
|
|
1836
|
+
applyAll();
|
|
1837
|
+
renderSettings("custom");
|
|
1838
|
+
return;
|
|
1839
|
+
}
|
|
1840
|
+
var rr = t.closest("[data-rowreset]");
|
|
1841
|
+
if (rr) {
|
|
1842
|
+
var rk = rr.getAttribute("data-rowreset");
|
|
1843
|
+
var dflt = clamp(num(DEFAULTS.surfaces && DEFAULTS.surfaces[rk], 66), 0, 100);
|
|
1844
|
+
state.surfaces[rk] = dflt;
|
|
1845
|
+
var rin = panel.querySelector('[data-region="' + rk + '"]');
|
|
1846
|
+
if (rin) rin.value = String(dflt);
|
|
1847
|
+
var rout = panel.querySelector('[data-regionval="' + rk + '"]');
|
|
1848
|
+
if (rout) rout.textContent = Math.round(dflt) + "%";
|
|
1849
|
+
applySurfaceVars();
|
|
1850
|
+
scheduleSave();
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
var qb = t.closest("[data-quality]");
|
|
1854
|
+
if (qb && draft) { draft.quality = qb.getAttribute("data-quality"); renderSettings(draftScene); commitLive(draftScene); return; }
|
|
1855
|
+
var sb = t.closest("[data-steps]");
|
|
1856
|
+
if (sb && draft) { draft.steps = Number(sb.getAttribute("data-steps")); renderSettings(draftScene); commitLive(draftScene); return; }
|
|
1857
|
+
var db = t.closest("[data-direction]");
|
|
1858
|
+
if (db && draft) { draft.variant = db.getAttribute("data-direction"); renderSettings(draftScene); commitLive(draftScene); return; }
|
|
1859
|
+
var bb = t.closest("[data-blinkdir]");
|
|
1860
|
+
if (bb && draft) { draft.direction = bb.getAttribute("data-blinkdir"); renderSettings(draftScene); commitLive(draftScene); return; }
|
|
1861
|
+
var pb = t.closest("[data-bhpreset]");
|
|
1862
|
+
if (pb && draft) {
|
|
1863
|
+
var presets = schemaOf(draftScene) && schemaOf(draftScene).presets || {};
|
|
1864
|
+
var p = presets[pb.getAttribute("data-bhpreset")];
|
|
1865
|
+
if (p) draft = sanitizeDraft(draftScene, Object.assign({}, schemaOf(draftScene).defaults, p));
|
|
1866
|
+
renderSettings(draftScene);
|
|
1867
|
+
commitLive(draftScene);
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
var pick = t.closest("[data-wall]");
|
|
1871
|
+
if (pick) {
|
|
1872
|
+
state.wallpaperId = pick.getAttribute("data-wall");
|
|
1873
|
+
state.mode = "wallpaper";
|
|
1874
|
+
state.enabled = true;
|
|
1875
|
+
scheduleSave();
|
|
1876
|
+
applyAll();
|
|
1877
|
+
renderSettings("custom");
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
var del = t.closest("[data-wdel]");
|
|
1881
|
+
if (del) {
|
|
1882
|
+
var wid = del.getAttribute("data-wdel");
|
|
1883
|
+
apiPostJson("/wallpaper-delete.json", { id: wid }).then(function (r) {
|
|
1884
|
+
if (r && r.wallpapers) wallpapersCache = r.wallpapers;
|
|
1885
|
+
if (state.wallpaperId === wid) {
|
|
1886
|
+
state.wallpaperId = wallpapersCache.length ? wallpapersCache[0].id : null;
|
|
1887
|
+
scheduleSave();
|
|
1888
|
+
}
|
|
1889
|
+
applyAll();
|
|
1890
|
+
renderSettings("custom");
|
|
1891
|
+
}).catch(function () {});
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
if (t.closest('[data-act="wallimport"]')) {
|
|
1895
|
+
var fi = panel.querySelector('[data-act="wallfile"]');
|
|
1896
|
+
if (fi) fi.click();
|
|
1897
|
+
return;
|
|
1898
|
+
}
|
|
1899
|
+
if (t.closest('[data-act="wallclear"]')) {
|
|
1900
|
+
if (!wallpapersCache.length) return;
|
|
1901
|
+
if (!window.confirm("清空素材库中的全部壁纸/视频?")) return;
|
|
1902
|
+
var ids = wallpapersCache.map(function (w) { return w.id; });
|
|
1903
|
+
var next = function (i) {
|
|
1904
|
+
if (i >= ids.length) {
|
|
1905
|
+
wallpapersCache = [];
|
|
1906
|
+
state.wallpaperId = null;
|
|
1907
|
+
libPage = 0;
|
|
1908
|
+
scheduleSave();
|
|
1909
|
+
applyAll();
|
|
1910
|
+
renderSettings("custom");
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
apiPostJson("/wallpaper-delete.json", { id: ids[i] }).then(function () { next(i + 1); }).catch(function () { next(i + 1); });
|
|
1914
|
+
};
|
|
1915
|
+
next(0);
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
});
|
|
1919
|
+
panel.addEventListener("input", function (e) {
|
|
1920
|
+
var t = e.target;
|
|
1921
|
+
if (t.hasAttribute && t.hasAttribute("data-field") && draft) {
|
|
1922
|
+
var key = t.getAttribute("data-field");
|
|
1923
|
+
draft[key] = Number(t.value);
|
|
1924
|
+
var sch = schemaOf(draftScene);
|
|
1925
|
+
var f = null;
|
|
1926
|
+
if (sch) for (var i = 0; i < sch.fields.length; i++) if (sch.fields[i].key === key) f = sch.fields[i];
|
|
1927
|
+
var out = panel.querySelector('[data-fieldval="' + key + '"]');
|
|
1928
|
+
if (out) out.textContent = f ? fmtFieldVal(f, Number(t.value)) : t.value;
|
|
1929
|
+
commitLive(draftScene);
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
if (t.hasAttribute && t.hasAttribute("data-region")) {
|
|
1933
|
+
var rk = t.getAttribute("data-region");
|
|
1934
|
+
state.surfaces[rk] = Number(t.value);
|
|
1935
|
+
var ro = panel.querySelector('[data-regionval="' + rk + '"]');
|
|
1936
|
+
if (ro) ro.textContent = Math.round(t.value) + "%";
|
|
1937
|
+
applySurfaceVars();
|
|
1938
|
+
scheduleSave();
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
if (t.hasAttribute && t.hasAttribute("data-slider")) {
|
|
1942
|
+
var sk = t.getAttribute("data-slider");
|
|
1943
|
+
var row = null;
|
|
1944
|
+
for (var j = 0; j < PARAM_ROWS.length; j++) if (PARAM_ROWS[j].key === sk) row = PARAM_ROWS[j];
|
|
1945
|
+
if (!row) return;
|
|
1946
|
+
state[sk] = Number(t.value) / row.scale;
|
|
1947
|
+
var so = panel.querySelector('[data-sliderval="' + sk + '"]');
|
|
1948
|
+
if (so) so.textContent = row.scale === 100 ? Math.round(t.value) + "%" : Number(t.value).toFixed(1) + "px";
|
|
1949
|
+
scheduleSave();
|
|
1950
|
+
applyAll();
|
|
1951
|
+
return;
|
|
1952
|
+
}
|
|
1953
|
+
if (t.hasAttribute && t.hasAttribute("data-colorkey") && draft) {
|
|
1954
|
+
var ck = t.getAttribute("data-colorkey");
|
|
1955
|
+
if (/^color\d+$/.test(ck)) {
|
|
1956
|
+
if (!Array.isArray(draft.colors)) draft.colors = (schemaOf(draftScene) && schemaOf(draftScene).colors || []).slice();
|
|
1957
|
+
draft.colors[Number(ck.slice(5))] = t.value;
|
|
1958
|
+
} else {
|
|
1959
|
+
draft[ck] = t.value;
|
|
1960
|
+
}
|
|
1961
|
+
commitLive(draftScene);
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
panel.addEventListener("change", function (e) {
|
|
1966
|
+
var t = e.target;
|
|
1967
|
+
if (t.getAttribute && t.getAttribute("data-toggle") === "__pspaused") {
|
|
1968
|
+
// pixel-sculpt 暂停开关:不走 draft(schema 全空),直写增量 + 实例推送
|
|
1969
|
+
var on2 = !!t.checked;
|
|
1970
|
+
if (!state.sceneParams) state.sceneParams = {};
|
|
1971
|
+
if (on2) state.sceneParams["pixel-sculpt"] = { paused: true };
|
|
1972
|
+
else delete state.sceneParams["pixel-sculpt"];
|
|
1973
|
+
writeSceneSetting("pixel-sculpt", { paused: on2 });
|
|
1974
|
+
scheduleSave();
|
|
1975
|
+
if (psEd && psEd.inst) { try { psEd.inst.setSettings({ paused: on2 }); } catch (e2) {} }
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1978
|
+
if (t.hasAttribute && t.hasAttribute("data-toggle") && draft) {
|
|
1979
|
+
draft[t.getAttribute("data-toggle")] = !!t.checked;
|
|
1980
|
+
commitLive(draftScene);
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
if (t.getAttribute && t.getAttribute("data-act") === "fit") {
|
|
1984
|
+
state.wallpaperFit = t.value; scheduleSave(); applyAll(); return;
|
|
1985
|
+
}
|
|
1986
|
+
if (t.getAttribute && t.getAttribute("data-act") === "pos") {
|
|
1987
|
+
state.wallpaperPosition = t.value; scheduleSave(); applyAll(); return;
|
|
1988
|
+
}
|
|
1989
|
+
if (t.getAttribute && t.getAttribute("data-act") === "wallfile" && t.files && t.files[0]) {
|
|
1990
|
+
var f = t.files[0];
|
|
1991
|
+
t.value = "";
|
|
1992
|
+
if (f.size > 200 * 1024 * 1024) { setStatus("文件超过 200MB 上限", true); return; }
|
|
1993
|
+
f.arrayBuffer().then(function (buf) {
|
|
1994
|
+
return fetch(API_BASE + "/wallpaper-upload?name=" + encodeURIComponent(f.name), {
|
|
1995
|
+
method: "POST",
|
|
1996
|
+
credentials: "omit",
|
|
1997
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
1998
|
+
body: buf,
|
|
1999
|
+
}).then(function (r) { return r.json(); });
|
|
2000
|
+
}).then(function (r) {
|
|
2001
|
+
if (r && r.ok) {
|
|
2002
|
+
wallpapersCache = r.wallpapers || [];
|
|
2003
|
+
libPage = 0;
|
|
2004
|
+
state.wallpaperId = r.wallpaper.id;
|
|
2005
|
+
state.mode = "wallpaper";
|
|
2006
|
+
state.enabled = true;
|
|
2007
|
+
scheduleSave();
|
|
2008
|
+
applyAll();
|
|
2009
|
+
renderSettings("custom");
|
|
2010
|
+
} else {
|
|
2011
|
+
setStatus("导入失败:" + ((r && r.error) || "?"), true);
|
|
2012
|
+
}
|
|
2013
|
+
}).catch(function (err) { setStatus("导入失败:" + err, true); });
|
|
2014
|
+
}
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
// ───────────── 面板刷新(外部状态变化 / 保存回包后) ─────────────
|
|
2019
|
+
|
|
2020
|
+
function refreshPanel() {
|
|
2021
|
+
if (!ui || !state) return;
|
|
2022
|
+
buildCards();
|
|
2023
|
+
// 启用/停用翻转时(含跨窗口轮询),pixel-sculpt 面板的提示与开关可用性要跟着变
|
|
2024
|
+
if (settingsOpen && settingsId === "pixel-sculpt") syncPsPanel();
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
function setStatus(text, isError) {
|
|
2028
|
+
if (text) console.info("[dsh-ccx]", text);
|
|
2029
|
+
if (isError && ui && settingsOpen && ui.settings) {
|
|
2030
|
+
var err = ui.settings.querySelector(".particle-plugin-error");
|
|
2031
|
+
if (err) { err.hidden = false; err.textContent = text; }
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
// ─────────────────────── 状态保存 / 轮询 ───────────────────────
|
|
2036
|
+
|
|
2037
|
+
var saveSeq = 0; // 保存代数:连续快速保存时丢弃过期回包(乱序响应会把旧 sceneParams 重新灌回 state)
|
|
2038
|
+
|
|
2039
|
+
function scheduleSave() {
|
|
2040
|
+
setStatus("保存中…");
|
|
2041
|
+
if (saveTimer) clearTimeout(saveTimer);
|
|
2042
|
+
saveTimer = setTimeout(function () {
|
|
2043
|
+
saveTimer = null;
|
|
2044
|
+
var mySeq = ++saveSeq;
|
|
2045
|
+
var payload = Object.assign({}, state);
|
|
2046
|
+
// 保存必须打 /state-save.json:宿主路由表不区分 method,
|
|
2047
|
+
// POST 到 /state.json 会命中 GET 处理器拿旧状态并静默回滚(v0.1.x "设置调不了"的根因)
|
|
2048
|
+
apiPostJson("/state-save.json", { settings: payload }).then(function (r) {
|
|
2049
|
+
if (mySeq !== saveSeq) return; // 已有更新的保存,本回包按过期丢弃
|
|
2050
|
+
if (r && r.ok && r.settings) {
|
|
2051
|
+
var local = state;
|
|
2052
|
+
state = sanitizeState(r.settings);
|
|
2053
|
+
savedAtLocal = state.savedAt || 0;
|
|
2054
|
+
refreshPanel();
|
|
2055
|
+
if (JSON.stringify(pickVisual(local)) !== JSON.stringify(pickVisual(state))) applyAll();
|
|
2056
|
+
}
|
|
2057
|
+
setStatus("已保存");
|
|
2058
|
+
}).catch(function () { if (mySeq === saveSeq) setStatus("保存失败"); });
|
|
2059
|
+
}, 400);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
function pickVisual(s) {
|
|
2063
|
+
return {
|
|
2064
|
+
enabled: s.enabled, mode: s.mode, scene: s.scene, wallpaperId: s.wallpaperId,
|
|
2065
|
+
wallpaperFit: s.wallpaperFit, wallpaperPosition: s.wallpaperPosition,
|
|
2066
|
+
surfaces: s.surfaces, dim: s.dim, blur: s.blur, sceneParams: s.sceneParams,
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
function sanitizeState(src) {
|
|
2071
|
+
var out = Object.assign({}, DEFAULTS, src || {});
|
|
2072
|
+
out.enabled = !!out.enabled;
|
|
2073
|
+
if (["scene", "wallpaper", "off"].indexOf(out.mode) < 0) out.mode = "scene";
|
|
2074
|
+
if (SCENE_IDS.indexOf(out.scene) < 0) out.scene = "milky-way";
|
|
2075
|
+
if (out.wallpaperId != null && !/^[\w-]+$/.test(String(out.wallpaperId))) out.wallpaperId = null;
|
|
2076
|
+
if (["cover", "contain", "tile"].indexOf(out.wallpaperFit) < 0) out.wallpaperFit = "cover";
|
|
2077
|
+
if (["center", "top", "bottom", "left", "right"].indexOf(out.wallpaperPosition) < 0) out.wallpaperPosition = "center";
|
|
2078
|
+
delete out.quality; // v4 遗留死字段,逐场景质量在 sceneParams/store
|
|
2079
|
+
out.dim = clamp(num(out.dim, DEFAULTS.dim), 0, 0.8);
|
|
2080
|
+
out.blur = clamp(num(out.blur, DEFAULTS.blur), 0, 20);
|
|
2081
|
+
var paramsIn = out.sceneParams && typeof out.sceneParams === "object" ? out.sceneParams : {};
|
|
2082
|
+
var paramsOut = {};
|
|
2083
|
+
for (var pk in paramsIn) {
|
|
2084
|
+
if (!Object.prototype.hasOwnProperty.call(paramsIn, pk)) continue;
|
|
2085
|
+
if (!/^[a-z-]+$/.test(pk)) continue;
|
|
2086
|
+
if (paramsIn[pk] && typeof paramsIn[pk] === "object" && !Array.isArray(paramsIn[pk])) paramsOut[pk] = paramsIn[pk];
|
|
2087
|
+
}
|
|
2088
|
+
out.sceneParams = paramsOut;
|
|
2089
|
+
// surfaces:v1/v2 老设置的 surfaceOpacity 折算为各区域统一蒙版
|
|
2090
|
+
var src2 = src || {};
|
|
2091
|
+
var surfacesIn = src2.surfaces && typeof src2.surfaces === "object" ? src2.surfaces : null;
|
|
2092
|
+
if (!surfacesIn && num(src2.surfaceOpacity, -1) >= 0) {
|
|
2093
|
+
var legacy = Math.round(clamp(num(src2.surfaceOpacity, 0.66), 0.05, 1) * 100);
|
|
2094
|
+
surfacesIn = { enabled: true, sidebar: legacy, conversation: legacy, composer: Math.min(100, legacy + 20), header: legacy, right: legacy };
|
|
2095
|
+
}
|
|
2096
|
+
var sOut = Object.assign({}, DEFAULTS.surfaces);
|
|
2097
|
+
if (surfacesIn) {
|
|
2098
|
+
sOut.enabled = surfacesIn.enabled === true;
|
|
2099
|
+
for (var i = 0; i < REGION_ROWS.length; i++) {
|
|
2100
|
+
var key = REGION_ROWS[i].key;
|
|
2101
|
+
var v = Number(surfacesIn[key]);
|
|
2102
|
+
if (Number.isFinite(v)) sOut[key] = clamp(v, 0, 100);
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
// v5→v6:输入区默认 58(v5 默认值)升 86(原版面板 composer 档);与 bundle 侧迁移同口径
|
|
2106
|
+
if (num(out.version, 0) < 6 && sOut.composer === 58) sOut.composer = 86;
|
|
2107
|
+
out.surfaces = sOut;
|
|
2108
|
+
out.version = 6;
|
|
2109
|
+
return out;
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// ─────────────────────── 总装 ───────────────────────
|
|
2113
|
+
|
|
2114
|
+
function applyAll() {
|
|
2115
|
+
if (!state) return;
|
|
2116
|
+
ensurePanel();
|
|
2117
|
+
var bgOn = state.enabled && state.mode !== "off";
|
|
2118
|
+
layer.style.display = bgOn ? "" : "none";
|
|
2119
|
+
if (bgOn && state.mode === "scene") {
|
|
2120
|
+
if (renderSig() !== lastRenderSig) {
|
|
2121
|
+
renderScene();
|
|
2122
|
+
} else if (paramsSig() !== lastParamsSig) {
|
|
2123
|
+
// 跨窗口参数同步:直推运行中的渲染器,推不动再重建
|
|
2124
|
+
lastParamsSig = paramsSig();
|
|
2125
|
+
var fullSettings = buildStoreSettings(state.scene);
|
|
2126
|
+
writeSceneSetting(state.scene, fullSettings);
|
|
2127
|
+
if (!(bgInstance && bgSceneId === state.scene && pushLiveSettings(bgInstance, fullSettings))) renderScene();
|
|
2128
|
+
}
|
|
2129
|
+
} else if (bgOn && state.mode === "wallpaper") {
|
|
2130
|
+
renderWallpaper();
|
|
2131
|
+
} else {
|
|
2132
|
+
disposeBgInstance();
|
|
2133
|
+
lastRenderSig = null;
|
|
2134
|
+
}
|
|
2135
|
+
// 视觉调节
|
|
2136
|
+
bgWrap.style.filter = num(state.blur, 0) > 0 ? "blur(" + num(state.blur, 0) + "px)" : "";
|
|
2137
|
+
var blurPx = num(state.blur, 0);
|
|
2138
|
+
bgWrap.style.transform = blurPx > 0 ? "scale(" + (1 + Math.min(0.08, blurPx * 0.006)).toFixed(3) + ")" : "";
|
|
2139
|
+
dimEl.style.background = bgOn ? "rgba(3,6,14," + clamp(num(state.dim, 0), 0, 0.8).toFixed(3) + ")" : "transparent";
|
|
2140
|
+
dimEl.style.setProperty("--ap-dim-bg", dimEl.style.background); // 同值经变量下发,避开通配透明
|
|
2141
|
+
// UI 表面(通配透明 + 分区蒙版)
|
|
2142
|
+
applySurfaceStyles();
|
|
2143
|
+
refreshPanel();
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
function startPolling() {
|
|
2147
|
+
if (pollTimer) return;
|
|
2148
|
+
pollTimer = setInterval(function () {
|
|
2149
|
+
if (document.hidden) return;
|
|
2150
|
+
apiGet("/state.json").then(function (data) {
|
|
2151
|
+
if (!data || !data.settings) return;
|
|
2152
|
+
var remote = sanitizeState(data.settings);
|
|
2153
|
+
var remoteAt = num(remote.savedAt, 0);
|
|
2154
|
+
if (remoteAt && remoteAt !== savedAtLocal) {
|
|
2155
|
+
var before = JSON.stringify(pickVisual(state || {}));
|
|
2156
|
+
state = remote;
|
|
2157
|
+
savedAtLocal = remoteAt;
|
|
2158
|
+
if (Array.isArray(data.wallpapers)) wallpapersCache = data.wallpapers;
|
|
2159
|
+
if (before !== JSON.stringify(pickVisual(state))) applyAll();
|
|
2160
|
+
}
|
|
2161
|
+
}).catch(function () {});
|
|
2162
|
+
}, 8000);
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
var resizeTimer = null;
|
|
2166
|
+
function onResize() {
|
|
2167
|
+
if (resizeTimer) clearTimeout(resizeTimer);
|
|
2168
|
+
resizeTimer = setTimeout(function () {
|
|
2169
|
+
if (settingsOpen) positionSettings();
|
|
2170
|
+
}, 120);
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
var started = false;
|
|
2174
|
+
|
|
2175
|
+
// 一次性迁移:v0.5 曾把(部分错误的)全量默认值预写进场景 store 并持久化。
|
|
2176
|
+
// 清掉 8 个参数场景的键,渲染器回到内嵌默认;画廊两场景的键(选择集)不动。
|
|
2177
|
+
var STORE_MIGRATION_KEY = "dsh-ap:scene-stores-v2";
|
|
2178
|
+
function migratePoisonedStores() {
|
|
2179
|
+
try {
|
|
2180
|
+
if (localStorage.getItem(STORE_MIGRATION_KEY)) return;
|
|
2181
|
+
for (var id in STORE_KEYS) {
|
|
2182
|
+
if (GALLERY_SCENES[id]) continue;
|
|
2183
|
+
try { localStorage.removeItem(STORE_KEYS[id]); } catch (e) {}
|
|
2184
|
+
}
|
|
2185
|
+
localStorage.setItem(STORE_MIGRATION_KEY, "1");
|
|
2186
|
+
} catch (e) {}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Client plugin body(cordis 浏览器上下文)。
|
|
2191
|
+
* @param ctx - client cordis context。
|
|
2192
|
+
*/
|
|
2193
|
+
function apply(ctx) {
|
|
2194
|
+
if (started) return;
|
|
2195
|
+
started = true;
|
|
2196
|
+
ctx.effect(function () {
|
|
2197
|
+
return function () {
|
|
2198
|
+
started = false;
|
|
2199
|
+
teardown();
|
|
2200
|
+
};
|
|
2201
|
+
}, PLUGIN_ID + ": reset apply guard");
|
|
2202
|
+
|
|
2203
|
+
migratePoisonedStores();
|
|
2204
|
+
ensureLayer();
|
|
2205
|
+
ensureSchemas();
|
|
2206
|
+
apiGet("/state.json").then(function (data) {
|
|
2207
|
+
state = sanitizeState(data && data.settings);
|
|
2208
|
+
if (Array.isArray(data && data.wallpapers)) wallpapersCache = data.wallpapers;
|
|
2209
|
+
savedAtLocal = num(state.savedAt, 0);
|
|
2210
|
+
applyAll();
|
|
2211
|
+
startPolling();
|
|
2212
|
+
}).catch(function () {
|
|
2213
|
+
// 宿主路由不在(老宿主/被停用):保持默认观感,不拖垮页面
|
|
2214
|
+
state = sanitizeState(null);
|
|
2215
|
+
applyAll();
|
|
2216
|
+
});
|
|
2217
|
+
|
|
2218
|
+
window.addEventListener("resize", onResize);
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
function teardown() {
|
|
2222
|
+
if (saveTimer) { clearTimeout(saveTimer); saveTimer = null; }
|
|
2223
|
+
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
|
|
2224
|
+
if (resizeTimer) { clearTimeout(resizeTimer); resizeTimer = null; }
|
|
2225
|
+
window.removeEventListener("resize", onResize);
|
|
2226
|
+
document.removeEventListener("click", onDocClick, true);
|
|
2227
|
+
document.removeEventListener("keydown", onDocKey, true);
|
|
2228
|
+
clearSurfaceStyles();
|
|
2229
|
+
disposeBgInstance();
|
|
2230
|
+
if (layer && layer.parentNode) { try { layer.parentNode.removeChild(layer); } catch (e) {} }
|
|
2231
|
+
layer = null;
|
|
2232
|
+
if (root9 && root9.parentNode) { try { root9.parentNode.removeChild(root9); } catch (e) {} }
|
|
2233
|
+
root9 = null;
|
|
2234
|
+
ui = null;
|
|
2235
|
+
marketOpen = false;
|
|
2236
|
+
settingsOpen = false;
|
|
2237
|
+
settingsId = null;
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
exports.apply = apply;
|
|
2241
|
+
exports.inject = [];
|
|
2242
|
+
return module.exports;
|
|
2243
|
+
},
|
|
2244
|
+
});
|