dsh-ccx 0.8.9 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +23 -23
  3. package/README.md +151 -143
  4. package/assets/icon.svg +27 -27
  5. package/cordis.patch.yml +16 -16
  6. package/lib/client.js +1481 -2244
  7. package/lib/index.js +716 -449
  8. package/lib/vendor/code-codex/ascii-tiles.js +145 -0
  9. package/lib/vendor/code-codex/aurora-ionosphere.js +7 -6
  10. package/lib/vendor/code-codex/black-hole.js +10 -7
  11. package/lib/vendor/code-codex/blinking-squares.js +6 -13
  12. package/lib/vendor/code-codex/cloud-train.js +9 -8
  13. package/lib/vendor/code-codex/galleries.json +100 -100
  14. package/lib/vendor/code-codex/glow-horizon.js +1 -1
  15. package/lib/vendor/code-codex/heavenly-cloud.js +5 -4
  16. package/lib/vendor/code-codex/milky-way.js +3 -2
  17. package/lib/vendor/code-codex/mountain.js +5 -4
  18. package/lib/vendor/code-codex/particle-image.js +435 -14
  19. package/lib/vendor/code-codex/pixel-sculpt.js +85 -5
  20. package/lib/vendor/code-codex/scene-defaults.json +94 -1
  21. package/lib/vendor/code-codex/scene-schemas.json +1008 -0
  22. package/lib/vendor/code-codex/shallow-ocean-thumbnails.json +12 -0
  23. package/lib/vendor/code-codex/shallow-ocean.js +5094 -0
  24. package/lib/vendor/code-codex/spectral-drape.js +172 -0
  25. package/package.json +70 -59
  26. package/src/client/api.ts +90 -0
  27. package/src/client/background/layer.ts +187 -0
  28. package/src/client/background/pixel-sculpt.ts +167 -0
  29. package/src/client/background/scene-runner.ts +317 -0
  30. package/src/client/background/shallow-ocean.ts +344 -0
  31. package/src/client/background/vendor-loader.ts +297 -0
  32. package/src/client/background/wallpaper.ts +87 -0
  33. package/src/client/index.ts +247 -0
  34. package/src/client/surfaces/corner-patch.ts +100 -0
  35. package/src/client/surfaces/surface-css.ts +155 -0
  36. package/src/client/ui/draft.ts +105 -0
  37. package/src/client/ui/icons.ts +47 -0
  38. package/src/client/ui/panel.ts +1524 -0
  39. package/src/client/ui/shallow-ocean-panel.ts +376 -0
  40. package/src/client/ui/styles.ts +1471 -0
  41. package/src/host/fence.ts +78 -0
  42. package/src/host/index.ts +26 -0
  43. package/src/host/routes.ts +367 -0
  44. package/src/host/storage.ts +109 -0
  45. package/src/host/window-chrome.ts +53 -0
  46. package/src/shared/constants.ts +239 -0
  47. package/src/shared/sanitize.ts +110 -0
  48. package/src/shared/types.ts +145 -0
  49. package/tsconfig.json +16 -0
@@ -0,0 +1,239 @@
1
+ import type { AppearanceSettings, SceneMeta, SurfaceRegionKey } from './types';
2
+
3
+ export const PLUGIN_ID = 'dsh-ccx';
4
+ export const API_BASE = '/dsh-appearances';
5
+
6
+ export const SCENES: readonly SceneMeta[] = [
7
+ {
8
+ id: 'milky-way',
9
+ label: '银河',
10
+ en: 'Milky Way',
11
+ cardTitle: 'Milky Way Background',
12
+ icon: 'milky-way',
13
+ ext: '',
14
+ layerBg: '#02090d',
15
+ storeKey: 'code-codex:milky-way-background:v1',
16
+ },
17
+ {
18
+ id: 'glow-horizon',
19
+ label: '辉光地平线',
20
+ en: 'Glow Horizon',
21
+ cardTitle: 'Glow Horizon Background',
22
+ icon: 'glow-horizon',
23
+ ext: 'ext-glowhorizon',
24
+ layerBg: '#050507',
25
+ storeKey: 'code-codex:glow-horizon-background:v1',
26
+ },
27
+ {
28
+ id: 'mountain',
29
+ label: '层峦',
30
+ en: 'Layered Mountain',
31
+ cardTitle: 'Layered Mountain Background',
32
+ icon: 'mountain',
33
+ ext: '',
34
+ layerBg: '#02090d',
35
+ storeKey: 'code-codex:mountain-settings:v1',
36
+ },
37
+ {
38
+ id: 'heavenly-cloud',
39
+ label: '云穹',
40
+ en: 'Heavenly Cloud',
41
+ cardTitle: 'Heavenly Cloud Background',
42
+ icon: 'heavenly-cloud',
43
+ ext: 'ext-heavenlycloud',
44
+ layerBg: '#020408',
45
+ storeKey: 'code-codex:heavenly-cloud-background:v1',
46
+ },
47
+ {
48
+ id: 'aurora-ionosphere',
49
+ label: '极光电离层',
50
+ en: 'Aurora Ionosphere',
51
+ cardTitle: 'Aurora Ionosphere Background',
52
+ icon: 'aurora-ionosphere',
53
+ ext: '',
54
+ layerBg: '#02090d',
55
+ storeKey: 'code-codex:aurora-ionosphere-background:v1',
56
+ },
57
+ {
58
+ id: 'black-hole',
59
+ label: '黑洞',
60
+ en: 'Black Hole',
61
+ cardTitle: 'Black Hole Background',
62
+ icon: 'black-hole',
63
+ ext: 'ext-blackhole',
64
+ layerBg: '#000000',
65
+ storeKey: 'code-codex:black-hole-background:v1',
66
+ },
67
+ {
68
+ id: 'cloud-train',
69
+ label: '云列车',
70
+ en: 'Cloud Train',
71
+ cardTitle: 'Cloud Train Background',
72
+ icon: 'cloud-train',
73
+ ext: '',
74
+ layerBg: '#02090d',
75
+ storeKey: 'code-codex:cloud-train-settings:v1',
76
+ },
77
+ {
78
+ id: 'particle-image',
79
+ label: '粒子成像',
80
+ en: 'Particle Image',
81
+ cardTitle: 'Particle Image Background',
82
+ icon: 'particle-image',
83
+ ext: 'ext-particle',
84
+ layerBg: '#000000',
85
+ bgColorKey: 'backgroundColor',
86
+ storeKey: 'code-codex:particle-image-background:v1',
87
+ },
88
+ {
89
+ id: 'pixel-sculpt',
90
+ label: '像素雕塑',
91
+ en: 'Pixel Sculpt',
92
+ cardTitle: 'Pixel Sculpt Background',
93
+ icon: 'pixel-sculpt',
94
+ ext: '',
95
+ layerBg: '#02090d',
96
+ storeKey: 'code-codex:pixel-sculpt-settings:v1',
97
+ },
98
+ {
99
+ id: 'blinking-squares',
100
+ label: '闪烁方块',
101
+ en: 'Blinking Squares',
102
+ cardTitle: 'Blinking Squares Background',
103
+ icon: 'blinking-squares',
104
+ ext: '',
105
+ layerBg: '#000000',
106
+ bgColorKey: 'backgroundColor',
107
+ storeKey: 'code-codex:blinking-squares-background:v1',
108
+ },
109
+ {
110
+ id: 'ascii-tiles',
111
+ label: 'ASCII 字符砖块',
112
+ en: 'ASCII Tiles',
113
+ cardTitle: 'ASCII Tiles Background',
114
+ icon: 'ascii-tiles',
115
+ ext: 'ext-asciitiles',
116
+ layerBg: '#000000',
117
+ bgColorKey: 'backgroundColor',
118
+ storeKey: 'code-codex:ascii-tiles-background:v1',
119
+ },
120
+ {
121
+ id: 'shallow-ocean',
122
+ label: '浅海来信',
123
+ en: 'Shallow Ocean Letters',
124
+ cardTitle: 'Shallow Ocean Letters Background',
125
+ icon: 'shallow-ocean',
126
+ ext: 'ext-shallowocean',
127
+ layerBg: '#181818',
128
+ storeKey: 'code-codex:shallow-ocean-background:v1',
129
+ },
130
+ {
131
+ id: 'spectral-drape',
132
+ label: '光谱点阵帷幕',
133
+ en: 'Spectral Drape',
134
+ cardTitle: 'Spectral Drape Background',
135
+ icon: 'spectral-drape',
136
+ ext: 'ext-spectraldrape',
137
+ layerBg: '#0a0a0a',
138
+ bgColorKey: 'backgroundColor',
139
+ storeKey: 'code-codex:spectral-drape-background:v1',
140
+ },
141
+ ];
142
+
143
+ export const SCENE_IDS: readonly string[] = SCENES.map((s) => s.id);
144
+
145
+ export const SCENE_META_MAP: Readonly<Record<string, SceneMeta>> = Object.fromEntries(
146
+ SCENES.map((s) => [s.id, s]),
147
+ );
148
+
149
+ export const GALLERY_SCENES: Readonly<Record<string, boolean>> = {
150
+ 'particle-image': true,
151
+ 'pixel-sculpt': true,
152
+ };
153
+
154
+ export const STORE_KEYS: Readonly<Record<string, string>> = Object.fromEntries(
155
+ SCENES.map((s) => [s.id, s.storeKey]),
156
+ );
157
+
158
+ export const SCENE_LAYER_BG: Readonly<Record<string, string>> = Object.fromEntries(
159
+ SCENES.map((s) => [s.id, s.layerBg]),
160
+ );
161
+
162
+ export const SURFACE_REGIONS: readonly SurfaceRegionKey[] = [
163
+ 'sidebar',
164
+ 'conversation',
165
+ 'composer',
166
+ 'right',
167
+ ];
168
+
169
+ export const DEFAULT_SETTINGS: AppearanceSettings = Object.freeze({
170
+ version: 6,
171
+ enabled: true,
172
+ mode: 'scene',
173
+ scene: 'milky-way',
174
+ wallpaperId: null,
175
+ wallpaperFit: 'cover',
176
+ wallpaperPosition: 'center',
177
+ surfaces: Object.freeze({
178
+ enabled: true,
179
+ sidebar: 66,
180
+ conversation: 58,
181
+ composer: 86,
182
+ right: 66,
183
+ }),
184
+ sceneParams: {},
185
+ dim: 0,
186
+ blur: 0,
187
+ savedAt: 0,
188
+ });
189
+
190
+ export const CLAMPS = {
191
+ dim: [0, 0.8] as const,
192
+ blur: [0, 20] as const,
193
+ };
194
+
195
+ export const MEDIA_FILE_RE =
196
+ /^CodeCodex-background-(particle-image|pixel-sculpt)-(image|thumbnail)-[0-9a-f]{16}\.png$/;
197
+
198
+ export const WALLPAPER_MIMES: Readonly<Record<string, string>> = {
199
+ '.png': 'image/png',
200
+ '.jpg': 'image/jpeg',
201
+ '.jpeg': 'image/jpeg',
202
+ '.webp': 'image/webp',
203
+ '.gif': 'image/gif',
204
+ '.bmp': 'image/bmp',
205
+ '.avif': 'image/avif',
206
+ '.mp4': 'video/mp4',
207
+ '.webm': 'video/webm',
208
+ '.mov': 'video/quicktime',
209
+ };
210
+
211
+ export const WALLPAPER_MAX_BYTES = 200 * 1024 * 1024;
212
+
213
+ export const SHALLOW_OCEAN_CREATURES = [
214
+ ['manta', 'Manta', '蝠鲼'],
215
+ ['eagle', 'Eagle ray', '斑点鹞鲼'],
216
+ ['stingray', 'Stingray', '蓝斑魟'],
217
+ ['turtle', 'Sea turtle', '海龟'],
218
+ ['moon', 'Moon jelly', '海月水母'],
219
+ ['nettle', 'Sea nettle', '黄金水母'],
220
+ ['silver', 'Silver school', '银色鱼群'],
221
+ ['reef', 'Reef fish', '珊瑚鱼'],
222
+ ['clown', 'Clownfish', '小丑鱼'],
223
+ ['shark', 'Reef shark', '礁鲨'],
224
+ ] as const;
225
+
226
+ export const SHALLOW_OCEAN_EVENTS = [
227
+ ['school', 'Fish migration', '鱼群过境'],
228
+ ['dolphin', 'Dolphin visit', '海豚来访'],
229
+ ['storm', 'Storm', '风暴'],
230
+ ['meteor', 'Meteor fall', '陨石坠落'],
231
+ ['duo', 'Drifting companions', '漂流伙伴'],
232
+ ] as const;
233
+
234
+ export const SHALLOW_OCEAN_PERF_MODES = [
235
+ ['Automatic', '自动'],
236
+ ['Low quality', '低画质'],
237
+ ['Medium quality', '中画质'],
238
+ ['High quality', '高画质'],
239
+ ] as const;
@@ -0,0 +1,110 @@
1
+ import { CLAMPS, DEFAULT_SETTINGS, SCENE_IDS, SURFACE_REGIONS } from './constants';
2
+ import type { AppearanceSettings, SceneParamMap, SurfaceSettings } from './types';
3
+
4
+ export function clamp(value: number, min: number, max: number): number {
5
+ return Math.min(max, Math.max(min, value));
6
+ }
7
+
8
+ export function finiteNum(value: unknown, fallback: number): number {
9
+ const n = Number(value);
10
+ return Number.isFinite(n) ? n : fallback;
11
+ }
12
+
13
+ export function sanitizeSurfaces(input: unknown): SurfaceSettings {
14
+ const src = input && typeof input === 'object' ? (input as Record<string, unknown>) : {};
15
+ const out: SurfaceSettings = { ...DEFAULT_SETTINGS.surfaces };
16
+ out.enabled = src.enabled === true;
17
+ for (const key of SURFACE_REGIONS) {
18
+ const n = Number(src[key]);
19
+ if (Number.isFinite(n)) out[key] = Math.round(clamp(n, 0, 100));
20
+ }
21
+ return out;
22
+ }
23
+
24
+ export function sanitizeSettings(input: unknown): AppearanceSettings {
25
+ const src = input && typeof input === 'object' ? (input as Record<string, unknown>) : {};
26
+ const out: AppearanceSettings = {
27
+ ...DEFAULT_SETTINGS,
28
+ surfaces: { ...DEFAULT_SETTINGS.surfaces },
29
+ sceneParams: {},
30
+ };
31
+
32
+ if (typeof src.enabled === 'boolean') out.enabled = src.enabled;
33
+ if (src.mode === 'scene' || src.mode === 'wallpaper' || src.mode === 'off') out.mode = src.mode;
34
+ if (typeof src.scene === 'string' && SCENE_IDS.includes(src.scene)) out.scene = src.scene;
35
+ if (typeof src.wallpaperId === 'string' && /^[\w-]+$/.test(src.wallpaperId)) {
36
+ out.wallpaperId = src.wallpaperId;
37
+ } else if (src.wallpaperId === null) {
38
+ out.wallpaperId = null;
39
+ }
40
+ if (src.wallpaperFit === 'cover' || src.wallpaperFit === 'contain' || src.wallpaperFit === 'tile') {
41
+ out.wallpaperFit = src.wallpaperFit;
42
+ }
43
+ if (
44
+ src.wallpaperPosition === 'center' ||
45
+ src.wallpaperPosition === 'top' ||
46
+ src.wallpaperPosition === 'bottom' ||
47
+ src.wallpaperPosition === 'left' ||
48
+ src.wallpaperPosition === 'right'
49
+ ) {
50
+ out.wallpaperPosition = src.wallpaperPosition;
51
+ }
52
+
53
+ for (const key of Object.keys(CLAMPS) as (keyof typeof CLAMPS)[]) {
54
+ const n = Number(src[key]);
55
+ if (Number.isFinite(n)) out[key] = clamp(n, CLAMPS[key][0], CLAMPS[key][1]);
56
+ }
57
+
58
+ // v1/v2 legacy surfaceOpacity migration
59
+ let surfacesSrc: unknown = src.surfaces;
60
+ if (!surfacesSrc && Number.isFinite(Number(src.surfaceOpacity))) {
61
+ const legacy = Math.round(clamp(Number(src.surfaceOpacity), 0.05, 1) * 100);
62
+ surfacesSrc = {
63
+ enabled: true,
64
+ sidebar: legacy,
65
+ conversation: legacy,
66
+ composer: Math.min(100, legacy + 20),
67
+ right: legacy,
68
+ };
69
+ }
70
+
71
+ const paramsSrc =
72
+ src.sceneParams && typeof src.sceneParams === 'object'
73
+ ? (src.sceneParams as Record<string, unknown>)
74
+ : {};
75
+ const paramsOut: Record<string, SceneParamMap> = {};
76
+ for (const key of Object.keys(paramsSrc)) {
77
+ if (!/^[a-z-]+$/.test(key)) continue;
78
+ const val = paramsSrc[key];
79
+ if (val && typeof val === 'object' && !Array.isArray(val)) {
80
+ paramsOut[key] = { ...(val as SceneParamMap) };
81
+ }
82
+ }
83
+ out.sceneParams = paramsOut;
84
+ out.surfaces = sanitizeSurfaces(surfacesSrc);
85
+
86
+ // v5 -> v6 composer default bump (only migrate untouched v5 default 58 -> 86)
87
+ if (Number(src.version) < 6 && out.surfaces.composer === 58) {
88
+ out.surfaces.composer = 86;
89
+ }
90
+ if (Number.isFinite(Number(src.savedAt))) {
91
+ out.savedAt = Number(src.savedAt);
92
+ }
93
+ return out;
94
+ }
95
+
96
+ export function pickVisual(s: Partial<AppearanceSettings> | null | undefined) {
97
+ if (!s) return null;
98
+ return {
99
+ enabled: s.enabled,
100
+ mode: s.mode,
101
+ scene: s.scene,
102
+ wallpaperId: s.wallpaperId,
103
+ wallpaperFit: s.wallpaperFit,
104
+ wallpaperPosition: s.wallpaperPosition,
105
+ surfaces: s.surfaces,
106
+ dim: s.dim,
107
+ blur: s.blur,
108
+ sceneParams: s.sceneParams,
109
+ };
110
+ }
@@ -0,0 +1,145 @@
1
+ export type BackgroundMode = 'scene' | 'wallpaper' | 'off';
2
+
3
+ export type WallpaperFit = 'cover' | 'contain' | 'tile';
4
+
5
+ export type WallpaperPosition = 'center' | 'top' | 'bottom' | 'left' | 'right';
6
+
7
+ export type SurfaceRegionKey = 'sidebar' | 'conversation' | 'composer' | 'right';
8
+
9
+ export interface SurfaceSettings {
10
+ enabled: boolean;
11
+ sidebar: number;
12
+ conversation: number;
13
+ composer: number;
14
+ right: number;
15
+ }
16
+
17
+ export type SceneParamValue = number | string | boolean | string[];
18
+ export type SceneParamMap = Record<string, SceneParamValue>;
19
+
20
+ export interface AppearanceSettings {
21
+ version: number;
22
+ enabled: boolean;
23
+ mode: BackgroundMode;
24
+ scene: string;
25
+ wallpaperId: string | null;
26
+ wallpaperFit: WallpaperFit;
27
+ wallpaperPosition: WallpaperPosition;
28
+ surfaces: SurfaceSettings;
29
+ sceneParams: Record<string, SceneParamMap>;
30
+ dim: number;
31
+ blur: number;
32
+ savedAt: number;
33
+ }
34
+
35
+ export interface WallpaperItem {
36
+ id: string;
37
+ name: string;
38
+ mime: string;
39
+ size: number;
40
+ mtimeMs?: number;
41
+ url: string;
42
+ }
43
+
44
+ export interface StateResponse {
45
+ ok: boolean;
46
+ settings: AppearanceSettings;
47
+ defaults: AppearanceSettings;
48
+ scenes: string[];
49
+ wallpapers: WallpaperItem[];
50
+ }
51
+
52
+ export interface SceneField {
53
+ key: string;
54
+ zh: string;
55
+ en: string;
56
+ group?: string;
57
+ hint?: string;
58
+ hintZh?: string;
59
+ min: number;
60
+ max: number;
61
+ step: number;
62
+ unit?: string;
63
+ precision?: number;
64
+ percent?: boolean;
65
+ }
66
+
67
+ export interface SceneColorField {
68
+ key: string;
69
+ zh: string;
70
+ en: string;
71
+ group?: string;
72
+ }
73
+
74
+ export interface SceneToggle {
75
+ key: string;
76
+ zh: string;
77
+ en: string;
78
+ group?: string;
79
+ }
80
+
81
+ export interface SceneGroupDef {
82
+ key: string;
83
+ en: string;
84
+ zh: string;
85
+ keys: string[];
86
+ }
87
+
88
+ export interface SceneSchema {
89
+ storeKey: string;
90
+ panelKind?: 'grouped-reset' | 'shallow-ocean';
91
+ qualityDefault?: string;
92
+ groups?: SceneGroupDef[];
93
+ fields: SceneField[];
94
+ transformFields?: SceneField[];
95
+ colors?: string[];
96
+ colorFields: SceneColorField[];
97
+ toggles: SceneToggle[];
98
+ defaults: Record<string, SceneParamValue>;
99
+ presets?: Record<string, Record<string, SceneParamValue>>;
100
+ }
101
+
102
+ export interface OceanEventJournalState {
103
+ discovered: string[];
104
+ excluded: string[];
105
+ }
106
+
107
+ export interface SceneMeta {
108
+ id: string;
109
+ label: string;
110
+ en: string;
111
+ cardTitle: string;
112
+ icon: string;
113
+ ext: string;
114
+ layerBg: string;
115
+ bgColorKey?: string;
116
+ storeKey: string;
117
+ }
118
+
119
+ export interface VendorRendererInstance {
120
+ ready?: Promise<void>;
121
+ setSettings?: (settings: Record<string, unknown>) => void;
122
+ updateSettings?: (settings: Record<string, unknown>) => void;
123
+ setRenderSettings?: (settings: Record<string, unknown>) => void;
124
+ replay?: () => void;
125
+ replayOpening?: () => void;
126
+ reset?: () => void;
127
+ dispose?: () => void;
128
+ // pixel-sculpt
129
+ setActive?: (active: boolean, opts?: { paused?: boolean }) => void;
130
+ mountControls?: (host: HTMLElement, lang?: string) => void;
131
+ // shallow-ocean
132
+ addCreature?: (kind: string, u?: number, v?: number) => void | Promise<void>;
133
+ previewEvent?: (kind: string) => void;
134
+ action?: (action: string) => void;
135
+ diagnostics?: { parameters?: Record<string, number> } | null;
136
+ }
137
+
138
+ export interface VendorModuleEntry {
139
+ id: string;
140
+ api: number;
141
+ version: string;
142
+ prepareDefaults?: () => Promise<void>;
143
+ exports?: Record<string, unknown>;
144
+ startup: (target: HTMLElement, onError: (msg?: string) => void) => VendorRendererInstance;
145
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "types": ["node"],
8
+ "strict": true,
9
+ "noEmit": true,
10
+ "skipLibCheck": true,
11
+ "resolveJsonModule": true,
12
+ "isolatedModules": true,
13
+ "forceConsistentCasingInFileNames": true
14
+ },
15
+ "include": ["src/**/*.ts", "scripts/**/*.mjs", "test/**/*.mjs"]
16
+ }