dsh-think-skin 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/index.js +62 -1
- package/package.json +4 -2
- package/seed.js +126 -0
- package/tools/test-seed.mjs +124 -0
package/README.md
CHANGED
|
@@ -110,7 +110,30 @@ $DSH_HOME/storages/think_skin/
|
|
|
110
110
|
The browser fetches `pack.json` once and each image with `immutable` caching, so the bundle
|
|
111
111
|
stays around 19 KB no matter how many images a pack holds.
|
|
112
112
|
|
|
113
|
+
### 装完就有(1.1.2)
|
|
114
|
+
|
|
115
|
+
三个内置套的图**随包一起发**,第一次启动铺进 `storages`,不需要你导入任何东西:
|
|
116
|
+
|
|
117
|
+
| 套 | 图 | 文案 |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| 蓝色大肥鱼 | 39 张 GIF | 27 条兜底 + 每张自己的 |
|
|
120
|
+
| ClaudeCode | 1 张占位图 | 184 个 -ing 动词 |
|
|
121
|
+
| 酒狐 | 1 张 GIF | 4 条兜底 + 歌词,另带三段《朋友的酒》 |
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
素材 assets/compiled-128/蓝色大肥鱼/ · assets/ClaudeCode/ · assets/酒狐/
|
|
125
|
+
文案 assets/texts/<套名>.json
|
|
126
|
+
拼装 seed.js(纯函数,可单测)→ index.js 里 seedBuiltinPacks()
|
|
127
|
+
规则 只补缺的套;你改过、删过的不覆盖
|
|
128
|
+
体积 首次启动会拷 13.4 MB,之后就只是读
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> **1.1.1 的坑**:那个版本只有音乐会被铺进来,图不会 —— 装完看到的是空列表。
|
|
132
|
+
> 1.1.2 修了。测这个不能靠开发机(开发机上早就导入过),要清空 `storages/think_skin`
|
|
133
|
+
> 再重启:`node tools/test-seed.mjs` 就是干这个的。
|
|
134
|
+
|
|
113
135
|
**导入图片:** 设置 → 思考状态 → 选图片 / 选文件夹。文件会被**复制**进上面的目录,原文件随便处置。
|
|
136
|
+
|
|
114
137
|
**Import from the CLI:**
|
|
115
138
|
|
|
116
139
|
```bash
|
package/index.js
CHANGED
|
@@ -19,6 +19,8 @@ import zlib from 'node:zlib'
|
|
|
19
19
|
import os from 'node:os'
|
|
20
20
|
import path from 'node:path'
|
|
21
21
|
|
|
22
|
+
import { BUILTIN_PACKS, planBuiltinSeeds } from './seed.js'
|
|
23
|
+
|
|
22
24
|
const ROUTE = '/think-skin'
|
|
23
25
|
const STORE = 'think_skin'
|
|
24
26
|
|
|
@@ -871,6 +873,62 @@ export function apply(ctx) {
|
|
|
871
873
|
})
|
|
872
874
|
ctx.effect(() => disposeMusicDel)
|
|
873
875
|
|
|
876
|
+
/**
|
|
877
|
+
* 把内置套组(蓝色大肥鱼 / ClaudeCode / 酒狐)铺进 storages。
|
|
878
|
+
*
|
|
879
|
+
* 之前只有音乐会被铺进来,图没有 —— 所以别人装完看到的是空列表。
|
|
880
|
+
* 素材在 assets/ 下,文案在 assets/texts/<套名>.json,
|
|
881
|
+
* 拼装逻辑在 seed.js(纯函数,能直接用 node 测,不用起 DSH)。
|
|
882
|
+
* 只补缺的套,用户改过的不覆盖。
|
|
883
|
+
*/
|
|
884
|
+
async function seedBuiltinPacks() {
|
|
885
|
+
let touched = false
|
|
886
|
+
try {
|
|
887
|
+
const document = await load()
|
|
888
|
+
const material = {}
|
|
889
|
+
for (const entry of BUILTIN_PACKS) {
|
|
890
|
+
for (const dir of entry.dirs) {
|
|
891
|
+
let fileNames = []
|
|
892
|
+
try {
|
|
893
|
+
const names = await fs.readdir(new URL('./assets/' + dir + '/', import.meta.url))
|
|
894
|
+
fileNames = names.filter((n) => /\.(gif|png|webp|jpe?g|avif)$/i.test(n))
|
|
895
|
+
} catch {
|
|
896
|
+
continue
|
|
897
|
+
}
|
|
898
|
+
if (fileNames.length === 0) continue
|
|
899
|
+
let texts = {}
|
|
900
|
+
try {
|
|
901
|
+
texts = JSON.parse(
|
|
902
|
+
await fs.readFile(
|
|
903
|
+
new URL('./assets/texts/' + entry.id + '.json', import.meta.url),
|
|
904
|
+
'utf8',
|
|
905
|
+
),
|
|
906
|
+
)
|
|
907
|
+
} catch {
|
|
908
|
+
/* 没有文案表就退化成「按文件名当名字」 */
|
|
909
|
+
}
|
|
910
|
+
material[entry.id] = { dir, fileNames, texts }
|
|
911
|
+
break
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
for (const item of planBuiltinSeeds(document.packs.map((p) => p.id), material)) {
|
|
916
|
+
const dir = path.join(root, 'images', item.id)
|
|
917
|
+
await fs.mkdir(dir, { recursive: true })
|
|
918
|
+
for (const copy of item.copies) {
|
|
919
|
+
const bytes = await fs.readFile(new URL('./assets/' + copy.from, import.meta.url))
|
|
920
|
+
await fs.writeFile(path.join(dir, copy.to.slice(item.id.length + 1)), bytes)
|
|
921
|
+
}
|
|
922
|
+
document.packs.push(item.pack)
|
|
923
|
+
if (!document.active) document.active = item.id
|
|
924
|
+
touched = true
|
|
925
|
+
}
|
|
926
|
+
if (touched) await save(document)
|
|
927
|
+
} catch {
|
|
928
|
+
/* 内置套组是送分项,铺不进去也不该挡住插件启动 */
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
874
932
|
/**
|
|
875
933
|
* 把内置套组自带的音乐铺进 storages。
|
|
876
934
|
*
|
|
@@ -914,7 +972,10 @@ export function apply(ctx) {
|
|
|
914
972
|
}
|
|
915
973
|
}
|
|
916
974
|
|
|
917
|
-
|
|
975
|
+
// 先铺套组(音乐只给「已存在的套」铺,所以顺序不能反)
|
|
976
|
+
seedBuiltinPacks()
|
|
977
|
+
.then(seedBuiltinMusic)
|
|
978
|
+
.catch(() => {})
|
|
918
979
|
|
|
919
980
|
/**
|
|
920
981
|
* Export one pack as a self-contained JSON document.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-think-skin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "把 DSH 的思考状态行换成你自己的图、自己的话:每张图带自己的文案池,逐字打出、高光扫过、渐变可调。支持套组导入导出与字符转圈。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,9 @@
|
|
|
45
45
|
"assets/screenshots",
|
|
46
46
|
"screenshots.json",
|
|
47
47
|
"tools/export-texts.py",
|
|
48
|
-
"locale"
|
|
48
|
+
"locale",
|
|
49
|
+
"seed.js",
|
|
50
|
+
"tools/test-seed.mjs"
|
|
49
51
|
],
|
|
50
52
|
"dsh": {
|
|
51
53
|
"bundle": {
|
package/seed.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置套组的「出厂内容」—— 装完就该有的那三个套。
|
|
3
|
+
*
|
|
4
|
+
* 之前只有 seedBuiltinMusic:音乐铺进去了,图没铺,所以别人装完看到的是空列表。
|
|
5
|
+
* 这里把「一个套由什么组成」写成纯数据 + 纯函数,index.js 只负责读盘和拷文件,
|
|
6
|
+
* 逻辑本身能直接用 node 跑测试(不用起 DSH)。
|
|
7
|
+
*
|
|
8
|
+
* 约定:
|
|
9
|
+
* · 图片的 file 字段是「<套名>/fNNN.<ext>」,相对 storages/think_skin/images/
|
|
10
|
+
* · texts 来自 assets/texts/<套名>.json,按图片名(文件名词干)对齐
|
|
11
|
+
* · 只补缺的套,不覆盖用户已经改过的
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** 出厂套组的清单。dirs 是素材可能所在的目录(按顺序找,找到就用)。 */
|
|
15
|
+
export const BUILTIN_PACKS = [
|
|
16
|
+
{ id: '蓝色大肥鱼', dirs: ['compiled-128/蓝色大肥鱼', '蓝色大肥鱼'] },
|
|
17
|
+
{ id: 'ClaudeCode', dirs: ['ClaudeCode'] },
|
|
18
|
+
{ id: '酒狐', dirs: ['酒狐'] },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
/** 每个套的配色/转圈样式。图能扫出来,但这些是设计决定,写死在这里。 */
|
|
22
|
+
const APPEARANCE = {
|
|
23
|
+
蓝色大肥鱼: { gradient: ['#a8cdff', '#5b8dff'], mode: 'sweep', speed: 3 },
|
|
24
|
+
ClaudeCode: {
|
|
25
|
+
gradient: ['#f0a882', '#d97757'],
|
|
26
|
+
mode: 'sweep',
|
|
27
|
+
speed: 3,
|
|
28
|
+
spinner: { mode: 'glyph', interval: 165, color: '#eb720f', period: 2000 },
|
|
29
|
+
},
|
|
30
|
+
酒狐: { gradient: ['#ffd6a5', '#ff9e6d'] },
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const IMAGE_EXT = new Set(['.gif', '.png', '.webp', '.jpg', '.jpeg', '.avif'])
|
|
34
|
+
|
|
35
|
+
/** 文件名去掉扩展名 —— texts 里就是用这个名字当键。 */
|
|
36
|
+
export function stem(fileName) {
|
|
37
|
+
return String(fileName).replace(/\.[^.]+$/, '')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 把「素材目录里有哪些文件」+「texts 里的文案」拼成一个套的完整数据。
|
|
42
|
+
*
|
|
43
|
+
* @param {string} packId 套名,也是目录名
|
|
44
|
+
* @param {{ fallbackTexts?: string[], images?: Record<string, {texts?: string[], useFallback?: boolean}> }} texts
|
|
45
|
+
* @param {string[]} fileNames 素材目录下的文件名列表(只留图片)
|
|
46
|
+
* @param {string} [assetDir] 素材目录(相对 assets/),用于生成拷贝来源
|
|
47
|
+
* @returns {{ pack: object, copies: {from: string, to: string}[] }}
|
|
48
|
+
*/
|
|
49
|
+
export function buildBuiltinPack(packId, texts, fileNames, assetDir = packId) {
|
|
50
|
+
const imagesByName = new Map()
|
|
51
|
+
for (const name of texts?.images && Object.keys(texts.images).length > 0
|
|
52
|
+
? Object.keys(texts.images)
|
|
53
|
+
: []) {
|
|
54
|
+
imagesByName.set(name, texts.images[name] || {})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const usable = (fileNames || [])
|
|
58
|
+
.filter((n) => IMAGE_EXT.has(String(n).slice(String(n).lastIndexOf('.')).toLowerCase()))
|
|
59
|
+
// 文案表里有名字的优先,没名字的按文件名排序跟在后面(别丢图)
|
|
60
|
+
.sort((a, b) => {
|
|
61
|
+
const ia = imagesByName.has(stem(a)) ? 0 : 1
|
|
62
|
+
const ib = imagesByName.has(stem(b)) ? 0 : 1
|
|
63
|
+
return ia - ib || String(a).localeCompare(String(b), 'zh')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const images = []
|
|
67
|
+
const copies = []
|
|
68
|
+
let index = 0
|
|
69
|
+
for (const fileName of usable) {
|
|
70
|
+
const name = stem(fileName)
|
|
71
|
+
const meta = imagesByName.get(name) || {}
|
|
72
|
+
const ext = String(fileName).slice(String(fileName).lastIndexOf('.')).toLowerCase()
|
|
73
|
+
index += 1
|
|
74
|
+
const id = 'f' + String(index).padStart(3, '0')
|
|
75
|
+
const stored = id + ext
|
|
76
|
+
images.push({
|
|
77
|
+
id,
|
|
78
|
+
file: packId + '/' + stored,
|
|
79
|
+
name,
|
|
80
|
+
texts: Array.isArray(meta.texts) ? meta.texts : [],
|
|
81
|
+
useFallback: meta.useFallback !== false,
|
|
82
|
+
music: [],
|
|
83
|
+
useFallbackMusic: true,
|
|
84
|
+
})
|
|
85
|
+
copies.push({ from: assetDir + '/' + fileName, to: packId + '/' + stored })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const appearance = APPEARANCE[packId] || { gradient: ['#a8cdff', '#5b8dff'] }
|
|
89
|
+
const pack = {
|
|
90
|
+
id: packId,
|
|
91
|
+
name: packId,
|
|
92
|
+
cover: images.length > 0 ? images[0].file : null,
|
|
93
|
+
fallbackTexts:
|
|
94
|
+
Array.isArray(texts?.fallbackTexts) && texts.fallbackTexts.length > 0
|
|
95
|
+
? texts.fallbackTexts
|
|
96
|
+
: ['正在思考'],
|
|
97
|
+
appearance: { ...appearance },
|
|
98
|
+
images,
|
|
99
|
+
builtin: true,
|
|
100
|
+
}
|
|
101
|
+
if (appearance.spinner !== undefined) pack.spinner = { ...appearance.spinner }
|
|
102
|
+
|
|
103
|
+
return { pack, copies }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 决定这次要补哪几个套。
|
|
108
|
+
*
|
|
109
|
+
* @param {string[]} existingIds 文档里已有的套名
|
|
110
|
+
* @param {Record<string, {dir?: string, fileNames: string[], texts: object}>} material 每个套能用的素材
|
|
111
|
+
* @returns {{ id: string, pack: object, copies: {from: string, to: string}[] }[]}
|
|
112
|
+
*/
|
|
113
|
+
export function planBuiltinSeeds(existingIds, material) {
|
|
114
|
+
const have = new Set(existingIds || [])
|
|
115
|
+
const out = []
|
|
116
|
+
for (const entry of BUILTIN_PACKS) {
|
|
117
|
+
const id = entry.id
|
|
118
|
+
if (have.has(id)) continue
|
|
119
|
+
const m = material[id]
|
|
120
|
+
if (m === undefined || !Array.isArray(m.fileNames) || m.fileNames.length === 0) continue
|
|
121
|
+
const { pack, copies } = buildBuiltinPack(id, m.texts || {}, m.fileNames, m.dir || id)
|
|
122
|
+
if (pack.images.length === 0) continue
|
|
123
|
+
out.push({ id, pack, copies })
|
|
124
|
+
}
|
|
125
|
+
return out
|
|
126
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跑一遍「从零安装」时内置套组的铺装流程,不依赖 DSH。
|
|
3
|
+
*
|
|
4
|
+
* node tools/test-seed.mjs → 用临时目录做 storage,跑完打印结果
|
|
5
|
+
* node tools/test-seed.mjs --keep → 保留临时目录,方便自己进去看
|
|
6
|
+
*
|
|
7
|
+
* 覆盖的是 index.js 里 seedBuiltinPacks 的同一套逻辑(素材扫描 → planBuiltinSeeds
|
|
8
|
+
* → 拷文件),差别只在 storage 根是临时的。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'node:fs/promises'
|
|
12
|
+
import os from 'node:os'
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
15
|
+
|
|
16
|
+
import { BUILTIN_PACKS, planBuiltinSeeds } from '../seed.js'
|
|
17
|
+
|
|
18
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const assetsRoot = path.join(here, '..', 'assets')
|
|
20
|
+
const keep = process.argv.includes('--keep')
|
|
21
|
+
|
|
22
|
+
const isImage = (n) => /\.(gif|png|webp|jpe?g|avif)$/i.test(n)
|
|
23
|
+
|
|
24
|
+
async function readMaterial() {
|
|
25
|
+
const material = {}
|
|
26
|
+
for (const entry of BUILTIN_PACKS) {
|
|
27
|
+
for (const dir of entry.dirs) {
|
|
28
|
+
let fileNames = []
|
|
29
|
+
try {
|
|
30
|
+
fileNames = (await fs.readdir(path.join(assetsRoot, dir))).filter(isImage)
|
|
31
|
+
} catch {
|
|
32
|
+
continue
|
|
33
|
+
}
|
|
34
|
+
if (fileNames.length === 0) continue
|
|
35
|
+
let texts = {}
|
|
36
|
+
try {
|
|
37
|
+
texts = JSON.parse(await fs.readFile(path.join(assetsRoot, 'texts', entry.id + '.json'), 'utf8'))
|
|
38
|
+
} catch {
|
|
39
|
+
/* 没有文案表也能跑 */
|
|
40
|
+
}
|
|
41
|
+
material[entry.id] = { dir, fileNames, texts }
|
|
42
|
+
break
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return material
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function main() {
|
|
49
|
+
const storage = await fs.mkdtemp(path.join(os.tmpdir(), 'ts-seed-'))
|
|
50
|
+
const material = await readMaterial()
|
|
51
|
+
|
|
52
|
+
console.log('素材扫描:')
|
|
53
|
+
for (const [id, m] of Object.entries(material)) {
|
|
54
|
+
console.log(' %s ← assets/%s (%d 张图, 文案 %d 条)', id, m.dir, m.fileNames.length,
|
|
55
|
+
Array.isArray(m.texts?.fallbackTexts) ? m.texts.fallbackTexts.length : 0)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 空文档 = 全新安装的样子
|
|
59
|
+
const document = { packs: [], active: null, settings: { musicEnabled: true, musicVolume: 42, musicMode: 'random' } }
|
|
60
|
+
const plan = planBuiltinSeeds(document.packs.map((p) => p.id), material)
|
|
61
|
+
|
|
62
|
+
for (const item of plan) {
|
|
63
|
+
const dir = path.join(storage, 'images', item.id)
|
|
64
|
+
await fs.mkdir(dir, { recursive: true })
|
|
65
|
+
for (const copy of item.copies) {
|
|
66
|
+
const bytes = await fs.readFile(path.join(assetsRoot, copy.from))
|
|
67
|
+
await fs.writeFile(path.join(dir, copy.to.slice(item.id.length + 1)), bytes)
|
|
68
|
+
}
|
|
69
|
+
document.packs.push(item.pack)
|
|
70
|
+
if (!document.active) document.active = item.id
|
|
71
|
+
}
|
|
72
|
+
await fs.writeFile(path.join(storage, 'pack.json'), JSON.stringify(document, null, 2), 'utf8')
|
|
73
|
+
|
|
74
|
+
// ── 校验 ────────────────────────────────────────────────────────────
|
|
75
|
+
const problems = []
|
|
76
|
+
const onDisk = JSON.parse(await fs.readFile(path.join(storage, 'pack.json'), 'utf8'))
|
|
77
|
+
for (const pack of onDisk.packs) {
|
|
78
|
+
if (!pack.builtin) problems.push(pack.id + ': 没标 builtin')
|
|
79
|
+
if (!pack.cover) problems.push(pack.id + ': 没有 cover')
|
|
80
|
+
if (pack.images.length === 0) problems.push(pack.id + ': 一张图都没有')
|
|
81
|
+
for (const image of pack.images) {
|
|
82
|
+
const p = path.join(storage, 'images', image.file)
|
|
83
|
+
try {
|
|
84
|
+
const st = await fs.stat(p)
|
|
85
|
+
if (st.size === 0) problems.push(pack.id + '/' + image.id + ': 文件是空的')
|
|
86
|
+
} catch {
|
|
87
|
+
problems.push(pack.id + '/' + image.id + ': 文件不存在 ' + image.file)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log('\n铺装结果:')
|
|
93
|
+
for (const pack of onDisk.packs) {
|
|
94
|
+
const stats = await Promise.all(pack.images.map((i) => fs.stat(path.join(storage, 'images', i.file))))
|
|
95
|
+
const bytes = stats.reduce((sum, s) => sum + s.size, 0)
|
|
96
|
+
const line = ' ' + pack.id.padEnd(10) +
|
|
97
|
+
' images=' + String(pack.images.length).padEnd(4) +
|
|
98
|
+
' cover=' + String(pack.cover).padEnd(26) +
|
|
99
|
+
' fallback=' + String(pack.fallbackTexts.length).padEnd(4) +
|
|
100
|
+
Math.round(bytes / 1024) + ' KB'
|
|
101
|
+
console.log(line)
|
|
102
|
+
}
|
|
103
|
+
console.log(' active =', onDisk.active)
|
|
104
|
+
|
|
105
|
+
const withTexts = onDisk.packs.flatMap((p) => p.images).filter((i) => i.texts.length > 0).length
|
|
106
|
+
const totalImages = onDisk.packs.flatMap((p) => p.images).length
|
|
107
|
+
console.log(' 有独立文案的图: %d / %d(其余走 fallback)', withTexts, totalImages)
|
|
108
|
+
|
|
109
|
+
if (problems.length > 0) {
|
|
110
|
+
console.log('\n❌ 问题:')
|
|
111
|
+
for (const p of problems.slice(0, 12)) console.log(' ' + p)
|
|
112
|
+
process.exitCode = 1
|
|
113
|
+
} else {
|
|
114
|
+
console.log('\n✅ 三个内置套全部铺好,文件都在、非空、cover 有效')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (keep) console.log('\n临时目录: ' + storage)
|
|
118
|
+
else await fs.rm(storage, { recursive: true, force: true })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
main().catch((error) => {
|
|
122
|
+
console.error(error)
|
|
123
|
+
process.exitCode = 1
|
|
124
|
+
})
|