dsh-think-skin 0.2.0 → 0.3.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 +16 -6
- package/assets/ClaudeCode/verbs.json +139 -135
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274/Raid 1.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274/Raid 2.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//344/270/200/345/210/207/351/203/275/345/245/275 1.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//344/270/273/346/204/217.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/201/234/346/255/242/345/267/245/344/275/234.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/202/254/347/234/240.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/203/217/347/264/240/345/242/250/351/225/234/345/217/215/345/205/211.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/217/271/345/217/267.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/347/210/206/347/261/263/350/212/261).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/347/224/234/347/224/234/345/234/210).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/350/245/277/347/223/234).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/221/206(/350/264/264/347/272/270) 2.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/224/261/346/255/214.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/345/260/217/347/235/241).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/346/231/256/351/200/232).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/347/226/262/345/200/246).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/276/227/345/210/206(10/345/210/206).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/200/235/350/200/203(/350/207/252/344/277/241/345/234/260).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/200/235/350/200/203(/350/256/244/347/234/237/345/234/260).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/346/201/274/346/200/222).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/346/231/256/351/200/232).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/347/224/237/346/260/224).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/346/270/270/346/210/217.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/212/223/346/213/215(/346/211/213/346/234/272).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/212/230/346/211/207.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/214/211/351/222/256.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/255/243/345/234/250/346/200/235/350/200/203.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/210/261/345/277/203 2.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/210/261/345/277/203 3.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/265/351/243/216/346/211/207 1.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/265/351/243/216/346/211/207 2.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/273/346/235/277.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/234/250/347/234/274.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/235/241/350/247/211(/345/207/206/345/244/207/351/230/266/346/256/2651).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/244/274/347/211/251 2.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/242/253/345/207/273/344/270/255(Bits).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/242/253/345/207/273/344/270/255(/347/210/261/345/277/203).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//351/246/213(/345/210/200/345/217/211).gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//351/246/213(/347/255/267/345/255/220).gif +0 -0
- package/assets//351/205/222/347/213/220/PS2.gif +0 -0
- package/client.js +885 -32
- package/index.js +400 -0
- package/package.json +4 -2
- package/tools/compile-pack.py +117 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_Raid 1_2026-08-18-14-25-14.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_Raid 2_2026-08-18-14-25-25.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/344/270/200/345/210/207/351/203/275/345/245/275 1_2026-08-18-14-37-38.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/344/270/273/346/204/217_2026-08-18-14-15-51.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/201/234/346/255/242/345/267/245/344/275/234_2026-08-18-14-34-45.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/202/254/347/234/240_2026-08-18-14-15-43.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/203/217/347/264/240/345/242/250/351/225/234/345/217/215/345/205/211_2026-08-18-14-35-59.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/217/271/345/217/267_2026-08-18-14-12-08.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/347/210/206/347/261/263/350/212/261)_2026-08-18-14-11-25.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/347/224/234/347/224/234/345/234/210)_2026-08-18-14-11-06.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/350/245/277/347/223/234)_2026-08-18-14-11-30.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/221/206(/350/264/264/347/272/270) 2_2026-08-18-14-10-34.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/224/261/346/255/214_2026-08-18-14-28-11.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/345/260/217/347/235/241)_2026-08-18-14-39-08.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/346/231/256/351/200/232)_2026-08-18-14-39-12.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/347/226/262/345/200/246)_2026-08-18-14-39-19.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/276/227/345/210/206(10/345/210/206)_2026-08-18-14-27-16.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/200/235/350/200/203(/350/207/252/344/277/241/345/234/260)_2026-08-18-14-37-20.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/200/235/350/200/203(/350/256/244/347/234/237/345/234/260)_2026-08-18-14-37-25.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/346/201/274/346/200/222)_2026-08-18-14-38-27.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/346/231/256/351/200/232)_2026-08-18-14-38-34.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/347/224/237/346/260/224)_2026-08-18-14-38-24.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/346/270/270/346/210/217_2026-08-18-14-13-01.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/212/223/346/213/215(/346/211/213/346/234/272)_2026-08-18-14-04-40.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/212/230/346/211/207_2026-08-18-14-12-51.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/214/211/351/222/256_2026-08-18-14-03-53.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/255/243/345/234/250/346/200/235/350/200/203_2026-08-18-14-24-28.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/210/261/345/277/203 2_2026-08-18-14-20-22.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/210/261/345/277/203 3_2026-08-18-14-20-29.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/265/351/243/216/346/211/207 1_2026-08-18-14-11-56.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/265/351/243/216/346/211/207 2_2026-08-18-14-12-00.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/273/346/235/277_2026-08-18-14-36-39.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/234/250/347/234/274_2026-08-18-14-38-44.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/235/241/350/247/211(/345/207/206/345/244/207/351/230/266/346/256/2651)_2026-08-18-14-28-50.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/244/274/347/211/251 2_2026-08-18-14-14-21.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/350/242/253/345/207/273/344/270/255(Bits)_2026-08-18-14-13-19.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/350/242/253/345/207/273/344/270/255(/347/210/261/345/277/203)_2026-08-18-14-13-47.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/351/246/213(/345/210/200/345/217/211)_2026-08-18-14-09-51.gif +0 -0
- package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/351/246/213(/347/255/267/345/255/220)_2026-08-18-14-09-43.gif +0 -0
package/client.js
CHANGED
|
@@ -53,12 +53,45 @@ window.__ModuleLoader__.load({
|
|
|
53
53
|
].join(';')
|
|
54
54
|
|
|
55
55
|
const FALLBACK_TEXTS = ['正在思考']
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Claude Code's spinner, taken from its binary: six glyphs that grow one
|
|
59
|
+
* step at a time, played forward then backward, 2 s per step, with the
|
|
60
|
+
* colour sliding toward rgb(171,43,63) as the glyph grows.
|
|
61
|
+
*/
|
|
62
|
+
// Claude Code 的 spinner 定义(二进制里唯一的一处):
|
|
63
|
+
// spinner: { interval: 80, frames: ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'].map(yellow) }
|
|
64
|
+
const SPIN_BRAILLE = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
65
|
+
/**
|
|
66
|
+
* 字符画那组,正走再倒回。
|
|
67
|
+
*
|
|
68
|
+
* 二进制里的默认数组是 ['·','✢','*','✶','✻','✽']。其中 `*`(U+002A) 和
|
|
69
|
+
* `✶`(U+2736 实心六角星) 是锐利字形——终端等宽字体下还能看,浏览器里
|
|
70
|
+
* 就是尖角,和 `✢ ✻ ✽` 这族水滴形完全不搭。所以只留水滴形那一族,
|
|
71
|
+
* 顺序按"从点长成花"排:点 → 四瓣 → 六瓣 → 八瓣。
|
|
72
|
+
*/
|
|
73
|
+
const SPIN_GLYPHS = ['·', '✢', '✻']
|
|
74
|
+
|
|
75
|
+
const SPIN_INTERVAL = 80
|
|
76
|
+
const SPIN_COOL = '#8b8f96'
|
|
77
|
+
const SPIN_HOT = '#ab2b3f'
|
|
78
|
+
const SPIN_ATTR = 'data-ts-spin'
|
|
79
|
+
|
|
56
80
|
const DEFAULT_GRADIENT = ['#a8cdff', '#5b8dff']
|
|
57
81
|
|
|
58
82
|
const React = require('react')
|
|
59
83
|
const h = React.createElement
|
|
60
84
|
|
|
61
85
|
const STYLE_TEXT = [
|
|
86
|
+
// 扫光带:最上层是一条 3 字符宽的白色亮带,位置由 --ts-gl 驱动
|
|
87
|
+
'[', GRAD_ATTR, '][data-ts-glimmer="1"] {',
|
|
88
|
+
'background-image:',
|
|
89
|
+
' linear-gradient(100deg,',
|
|
90
|
+
' transparent calc(var(--ts-gl, 50%) - 7%),',
|
|
91
|
+
' rgba(255,255,255,.85) var(--ts-gl, 50%),',
|
|
92
|
+
' transparent calc(var(--ts-gl, 50%) + 7%)),',
|
|
93
|
+
' var(--ts-gradient);',
|
|
94
|
+
'}',
|
|
62
95
|
'[', GRAD_ATTR, '] {',
|
|
63
96
|
'background-image: var(--ts-gradient);',
|
|
64
97
|
'background-size: 100% 100%;',
|
|
@@ -208,7 +241,9 @@ window.__ModuleLoader__.load({
|
|
|
208
241
|
|
|
209
242
|
/** Read, advance, and store the row's thinking state. */
|
|
210
243
|
function stateOf(row) {
|
|
211
|
-
if (pack === null
|
|
244
|
+
if (pack === null) return null
|
|
245
|
+
const isSpinner = pack.spinner !== undefined && pack.spinner !== null
|
|
246
|
+
if (!isSpinner && (!Array.isArray(pack.images) || pack.images.length === 0)) return null
|
|
212
247
|
const now = Date.now()
|
|
213
248
|
const seconds = secondsOf(row)
|
|
214
249
|
const lastSeconds = row.getAttribute('data-ts-sec')
|
|
@@ -225,7 +260,7 @@ window.__ModuleLoader__.load({
|
|
|
225
260
|
let textIndex = storedText === null ? -1 : Number(storedText)
|
|
226
261
|
|
|
227
262
|
if (isNewRun) {
|
|
228
|
-
imageIndex = pickIndex(pack.images.length, Number(storedImage ?? -1))
|
|
263
|
+
imageIndex = isSpinner ? 0 : pickIndex(pack.images.length, Number(storedImage ?? -1))
|
|
229
264
|
textIndex = pickIndex(textsOf(pack.images[imageIndex]).length, -1)
|
|
230
265
|
row.setAttribute('data-ts-next', nextAt(now))
|
|
231
266
|
} else if (now >= due) {
|
|
@@ -243,6 +278,170 @@ window.__ModuleLoader__.load({
|
|
|
243
278
|
}
|
|
244
279
|
|
|
245
280
|
/** Put our image where the row's own icon box is, swapping it when the pick changes. */
|
|
281
|
+
/** Mix two hex colours; used for the spinner's colour ramp. */
|
|
282
|
+
function lerpHex(a, b, t) {
|
|
283
|
+
const one = parseHex(a)
|
|
284
|
+
const two = parseHex(b)
|
|
285
|
+
if (one === null || two === null) return a
|
|
286
|
+
return '#' + one
|
|
287
|
+
.map((v, i) => Math.round(v + (two[i] - v) * t).toString(16).padStart(2, '0'))
|
|
288
|
+
.join('')
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Draw the breathing glyph instead of an image.
|
|
293
|
+
*
|
|
294
|
+
* The frame comes from a timestamp stamped on the row rather than from a
|
|
295
|
+
* timer: React rewrites the row every second, and a timer would restart.
|
|
296
|
+
*/
|
|
297
|
+
function swapSpinner(row, spinnerConfig) {
|
|
298
|
+
// 模式决定用哪组字符。以前 frames 会盖掉模式,于是"切成字符画还在转盲文"。
|
|
299
|
+
const mode = spinnerConfig.mode === 'glyph' ? 'glyph' : 'braille'
|
|
300
|
+
const glyphs = mode === 'glyph' ? SPIN_GLYPHS : SPIN_BRAILLE
|
|
301
|
+
// 呼吸字形正反来回;盲文是单向转圈
|
|
302
|
+
const frames = mode === 'glyph'
|
|
303
|
+
? glyphs.concat(glyphs.slice(0, -1).reverse())
|
|
304
|
+
: glyphs
|
|
305
|
+
// 两种模式的时长含义不同:盲文是"每帧多久",字符画是"一整趟多久"。
|
|
306
|
+
// 分开存,切换模式才不会把一个模式的数字带到另一个模式里。
|
|
307
|
+
const interval = mode === 'glyph'
|
|
308
|
+
? (Number.isFinite(Number(spinnerConfig.period))
|
|
309
|
+
? Number(spinnerConfig.period)
|
|
310
|
+
: 2000)
|
|
311
|
+
: (Number.isFinite(Number(spinnerConfig.interval))
|
|
312
|
+
? Number(spinnerConfig.interval)
|
|
313
|
+
: 165)
|
|
314
|
+
const cool = typeof spinnerConfig.cool === 'string' ? spinnerConfig.cool : SPIN_COOL
|
|
315
|
+
const hot = typeof spinnerConfig.hot === 'string' ? spinnerConfig.hot : SPIN_HOT
|
|
316
|
+
const fixed = typeof spinnerConfig.color === 'string'
|
|
317
|
+
? spinnerConfig.color
|
|
318
|
+
: (mode === 'glyph' ? '' : '#e5c07b')
|
|
319
|
+
|
|
320
|
+
const existing = row.querySelector('span[' + SPIN_ATTR + ']')
|
|
321
|
+
if (existing !== null) {
|
|
322
|
+
// 配置变了就地更新;已经画出来的标记不会自己重建
|
|
323
|
+
const signature = [frames.join(''), interval, cool, hot, fixed, mode].join('|')
|
|
324
|
+
if (existing.getAttribute('data-ts-sig') !== signature) {
|
|
325
|
+
existing.setAttribute('data-ts-glyphs', frames.join(''))
|
|
326
|
+
existing.setAttribute('data-ts-interval', String(interval))
|
|
327
|
+
existing.setAttribute('data-ts-cool', cool)
|
|
328
|
+
existing.setAttribute('data-ts-hot', hot)
|
|
329
|
+
existing.setAttribute('data-ts-fixed', fixed)
|
|
330
|
+
existing.setAttribute('data-ts-count', String(glyphs.length))
|
|
331
|
+
existing.setAttribute('data-ts-breathe', mode === 'glyph' ? '1' : '0')
|
|
332
|
+
existing.setAttribute('data-ts-sig', signature)
|
|
333
|
+
existing.setAttribute('data-ts-since', String(Date.now()))
|
|
334
|
+
}
|
|
335
|
+
return
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const svg = row.querySelector('svg')
|
|
339
|
+
const box = svg === null ? null : svg.parentElement
|
|
340
|
+
if (box === null) return
|
|
341
|
+
|
|
342
|
+
const mark = document.createElement('span')
|
|
343
|
+
mark.setAttribute(SPIN_ATTR, '')
|
|
344
|
+
mark.setAttribute('aria-hidden', 'true')
|
|
345
|
+
mark.setAttribute('data-ts-glyphs', frames.join(''))
|
|
346
|
+
mark.setAttribute('data-ts-interval', String(interval))
|
|
347
|
+
mark.setAttribute('data-ts-cool', cool)
|
|
348
|
+
mark.setAttribute('data-ts-hot', hot)
|
|
349
|
+
// chalk 的 yellow ≈ #e5c07b,Claude Code 的转圈就是这个颜色
|
|
350
|
+
mark.setAttribute('data-ts-fixed', fixed)
|
|
351
|
+
mark.setAttribute('data-ts-count', String(glyphs.length))
|
|
352
|
+
mark.setAttribute('data-ts-breathe', mode === 'glyph' ? '1' : '0')
|
|
353
|
+
mark.setAttribute('data-ts-sig',
|
|
354
|
+
[frames.join(''), interval, cool, hot, fixed, mode].join('|'))
|
|
355
|
+
mark.setAttribute('data-ts-since', String(Date.now()))
|
|
356
|
+
mark.style.cssText = [
|
|
357
|
+
'width:32px',
|
|
358
|
+
'height:32px',
|
|
359
|
+
'flex:none',
|
|
360
|
+
'display:inline-flex',
|
|
361
|
+
'align-items:center',
|
|
362
|
+
'justify-content:center',
|
|
363
|
+
'font-size:24px',
|
|
364
|
+
'line-height:1',
|
|
365
|
+
'font-family:ui-monospace,SFMono-Regular,Menlo,monospace',
|
|
366
|
+
].join(';')
|
|
367
|
+
box.style.setProperty('display', 'none')
|
|
368
|
+
box.before(mark)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Move the glimmer band across every painted text run.
|
|
373
|
+
*
|
|
374
|
+
* Claude Code walks a highlight three characters wide over the message at
|
|
375
|
+
* 200 ms per step; we reproduce the cadence and let it ride on top of the
|
|
376
|
+
* static gradient.
|
|
377
|
+
*/
|
|
378
|
+
function tickGlimmer(root, now) {
|
|
379
|
+
let nodes
|
|
380
|
+
try {
|
|
381
|
+
nodes = root.querySelectorAll('[data-ts-glimmer="1"]')
|
|
382
|
+
} catch {
|
|
383
|
+
return
|
|
384
|
+
}
|
|
385
|
+
for (const element of nodes) {
|
|
386
|
+
const since = Number(element.getAttribute('data-ts-gl-since')) || now
|
|
387
|
+
const length = (element.textContent || '').length || 12
|
|
388
|
+
const span = length + 6
|
|
389
|
+
// 和打字同速:亮带每步走一个字符,两条动效不会互相打架
|
|
390
|
+
const step = TYPE_MS
|
|
391
|
+
const pos = Math.floor((now - since) / step) % span
|
|
392
|
+
const percent = ((pos / span) * 120 - 10).toFixed(2) + '%'
|
|
393
|
+
if (element.style.getPropertyValue('--ts-gl') !== percent) {
|
|
394
|
+
element.style.setProperty('--ts-gl', percent)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Advance every visible spinner to the frame the clock says it is on. */
|
|
400
|
+
function tickSpinners(root) {
|
|
401
|
+
let marks
|
|
402
|
+
try {
|
|
403
|
+
marks = root.querySelectorAll('span[' + SPIN_ATTR + ']')
|
|
404
|
+
} catch {
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
const now = Date.now()
|
|
408
|
+
for (const mark of marks) {
|
|
409
|
+
const frames = (mark.getAttribute('data-ts-glyphs') || '').split('')
|
|
410
|
+
if (frames.length === 0) continue
|
|
411
|
+
const interval = Number(mark.getAttribute('data-ts-interval')) || SPIN_INTERVAL
|
|
412
|
+
const since = Number(mark.getAttribute('data-ts-since')) || now
|
|
413
|
+
const elapsed = now - since
|
|
414
|
+
const breathe = mark.getAttribute('data-ts-breathe') === '1'
|
|
415
|
+
|
|
416
|
+
// 官方:Oon(t) = (1 - cos(2πt / 2000)) / 2,帧 = round(Oon * (n-1))
|
|
417
|
+
// 也就是说 2000ms 走完「小→大→小」一整趟,不是每帧 2000ms。
|
|
418
|
+
let index
|
|
419
|
+
let phase
|
|
420
|
+
if (breathe) {
|
|
421
|
+
const period = interval > 0 ? interval : 2000
|
|
422
|
+
phase = (1 - Math.cos(2 * Math.PI * elapsed / period)) / 2
|
|
423
|
+
index = Math.round(phase * (frames.length - 1))
|
|
424
|
+
} else {
|
|
425
|
+
index = Math.floor(elapsed / interval) % frames.length
|
|
426
|
+
phase = 0
|
|
427
|
+
}
|
|
428
|
+
const glyph = frames[index]
|
|
429
|
+
if (mark.textContent !== glyph) mark.textContent = glyph
|
|
430
|
+
// 固定色(例如 Claude Code 的黄色)直接套;没配颜色就跟着主题走。
|
|
431
|
+
// 只有 glyph 模式才做"卡住变红"的混色,而且那是独立强度,不跟帧。
|
|
432
|
+
// 字号跟着呼吸走:点最小,花最大。20px 上下浮动看不出形状差别,
|
|
433
|
+
// 加上尺寸变化,"从点长成花"才读得出来。
|
|
434
|
+
const size = Math.round((breathe ? 15 + phase * 11 : 22) * 10) / 10
|
|
435
|
+
const sizeText = size.toFixed(1) + 'px'
|
|
436
|
+
if (mark.style.fontSize !== sizeText) mark.style.fontSize = sizeText
|
|
437
|
+
|
|
438
|
+
const fixed = mark.getAttribute('data-ts-fixed')
|
|
439
|
+
if (fixed !== null && fixed !== '') {
|
|
440
|
+
if (mark.style.color !== fixed) mark.style.color = fixed
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
246
445
|
function swapIcon(row, src) {
|
|
247
446
|
const existing = row.querySelector(`img[${ICON_ATTR}]`)
|
|
248
447
|
if (existing !== null) {
|
|
@@ -272,13 +471,25 @@ window.__ModuleLoader__.load({
|
|
|
272
471
|
* our previous text, so a rotation reaches a string React has not rewritten.
|
|
273
472
|
* @returns the elements that received new visible text, for gradient painting.
|
|
274
473
|
*/
|
|
275
|
-
|
|
276
|
-
|
|
474
|
+
/** 每字符的揭示间隔:12 个字符约 1.1 秒打完。 */
|
|
475
|
+
const TYPE_MS = 90
|
|
476
|
+
|
|
477
|
+
function swapCopy(row, full) {
|
|
478
|
+
// 词条换了就重置打字进度;同一个词一直打,打完就停
|
|
479
|
+
if (row.getAttribute('data-ts-full') !== full) {
|
|
480
|
+
row.setAttribute('data-ts-full', full)
|
|
481
|
+
row.setAttribute('data-ts-typed-at', String(Date.now()))
|
|
482
|
+
row.setAttribute('data-ts-shown', '')
|
|
483
|
+
}
|
|
484
|
+
const startedAt = Number(row.getAttribute('data-ts-typed-at')) || Date.now()
|
|
485
|
+
const typed = Math.min(full.length, Math.max(1, Math.floor((Date.now() - startedAt) / TYPE_MS)))
|
|
486
|
+
const text = full.slice(0, typed)
|
|
487
|
+
const previous = row.getAttribute('data-ts-shown')
|
|
277
488
|
const targets = new Set()
|
|
278
489
|
const replaceIn = (value) => {
|
|
279
490
|
let next = value
|
|
280
491
|
if (next.includes(SOURCE_LABEL)) next = next.split(SOURCE_LABEL).join(text)
|
|
281
|
-
if (previous !== null && previous !== text && next.includes(previous)) {
|
|
492
|
+
if (previous !== null && previous !== '' && previous !== text && next.includes(previous)) {
|
|
282
493
|
next = next.split(previous).join(text)
|
|
283
494
|
}
|
|
284
495
|
return next
|
|
@@ -301,7 +512,7 @@ window.__ModuleLoader__.load({
|
|
|
301
512
|
if (next !== value) element.setAttribute(SHIMMER_ATTR, next)
|
|
302
513
|
}
|
|
303
514
|
|
|
304
|
-
row.setAttribute('data-ts-
|
|
515
|
+
row.setAttribute('data-ts-shown', text)
|
|
305
516
|
return targets
|
|
306
517
|
}
|
|
307
518
|
|
|
@@ -325,6 +536,9 @@ window.__ModuleLoader__.load({
|
|
|
325
536
|
gradient = 'linear-gradient(90deg, ' + colors.join(', ') + ')'
|
|
326
537
|
}
|
|
327
538
|
}
|
|
539
|
+
const glimmer = appearance === undefined || appearance.glimmer !== false
|
|
540
|
+
const glimmerable = glimmer && (mode === 'static' || mode === 'none')
|
|
541
|
+
|
|
328
542
|
for (const element of targets) {
|
|
329
543
|
if (!usable) {
|
|
330
544
|
if (element.hasAttribute(GRAD_ATTR)) {
|
|
@@ -338,6 +552,15 @@ window.__ModuleLoader__.load({
|
|
|
338
552
|
&& element.getAttribute('data-ts-mode') === mode) continue
|
|
339
553
|
element.setAttribute(GRAD_ATTR, '')
|
|
340
554
|
element.setAttribute('data-ts-mode', mode)
|
|
555
|
+
if (glimmerable) {
|
|
556
|
+
if (element.getAttribute('data-ts-glimmer') !== '1') {
|
|
557
|
+
element.setAttribute('data-ts-glimmer', '1')
|
|
558
|
+
element.setAttribute('data-ts-gl-since', String(Date.now()))
|
|
559
|
+
}
|
|
560
|
+
} else if (element.hasAttribute('data-ts-glimmer')) {
|
|
561
|
+
element.removeAttribute('data-ts-glimmer')
|
|
562
|
+
element.style.removeProperty('--ts-gl')
|
|
563
|
+
}
|
|
341
564
|
element.style.setProperty('--ts-gradient', gradient)
|
|
342
565
|
const seconds = appearance !== undefined && Number.isFinite(Number(appearance.speed))
|
|
343
566
|
? Math.max(1, Math.min(60, Number(appearance.speed)))
|
|
@@ -360,13 +583,19 @@ window.__ModuleLoader__.load({
|
|
|
360
583
|
} catch {
|
|
361
584
|
return
|
|
362
585
|
}
|
|
586
|
+
const spinner = pack.spinner !== undefined && pack.spinner !== null
|
|
587
|
+
? pack.spinner
|
|
588
|
+
: null
|
|
589
|
+
|
|
363
590
|
for (const row of rows) {
|
|
364
591
|
const state = stateOf(row)
|
|
365
592
|
if (state === null) continue
|
|
366
|
-
|
|
593
|
+
if (spinner !== null) swapSpinner(row, spinner)
|
|
594
|
+
else swapIcon(row, imageUrl(state.image.file))
|
|
367
595
|
const targets = swapCopy(row, state.text)
|
|
368
596
|
applyGradient(targets, pack.appearance)
|
|
369
597
|
}
|
|
598
|
+
tickSpinners(document)
|
|
370
599
|
}
|
|
371
600
|
|
|
372
601
|
/** Replace the in-memory pack after a save, then repaint. */
|
|
@@ -592,6 +821,113 @@ window.__ModuleLoader__.load({
|
|
|
592
821
|
+ ')'
|
|
593
822
|
}
|
|
594
823
|
|
|
824
|
+
/**
|
|
825
|
+
* A live copy of the spinner mark, driven by the values in the form rather
|
|
826
|
+
* than the saved ones, so switching mode shows the result immediately.
|
|
827
|
+
*/
|
|
828
|
+
function SpinPreview({ mode, interval, color }) {
|
|
829
|
+
const glyphs = mode === 'glyph' ? SPIN_GLYPHS : SPIN_BRAILLE
|
|
830
|
+
const [, setTick] = React.useState(0)
|
|
831
|
+
const startedAt = React.useRef(Date.now())
|
|
832
|
+
React.useEffect(() => {
|
|
833
|
+
startedAt.current = Date.now()
|
|
834
|
+
}, [mode, interval, color])
|
|
835
|
+
React.useEffect(() => {
|
|
836
|
+
const timer = window.setInterval(() => setTick((n) => n + 1), 40)
|
|
837
|
+
return () => window.clearInterval(timer)
|
|
838
|
+
}, [])
|
|
839
|
+
|
|
840
|
+
const elapsed = Date.now() - startedAt.current
|
|
841
|
+
let index
|
|
842
|
+
let phase
|
|
843
|
+
if (mode === 'glyph') {
|
|
844
|
+
const period = interval > 0 ? interval : 2000
|
|
845
|
+
phase = (1 - Math.cos((2 * Math.PI * elapsed) / period)) / 2
|
|
846
|
+
index = Math.round(phase * (glyphs.length - 1))
|
|
847
|
+
} else {
|
|
848
|
+
index = Math.floor(elapsed / Math.max(16, interval)) % glyphs.length
|
|
849
|
+
phase = 0
|
|
850
|
+
}
|
|
851
|
+
const size = mode === 'glyph' ? 15 + phase * 11 : 22
|
|
852
|
+
const shade = typeof color === 'string' && color !== ''
|
|
853
|
+
? color
|
|
854
|
+
: (mode === 'glyph' ? 'currentColor' : '#e5c07b')
|
|
855
|
+
|
|
856
|
+
return h('span', {
|
|
857
|
+
style: {
|
|
858
|
+
width: '30px',
|
|
859
|
+
height: '30px',
|
|
860
|
+
display: 'inline-flex',
|
|
861
|
+
alignItems: 'center',
|
|
862
|
+
justifyContent: 'center',
|
|
863
|
+
fontSize: size.toFixed(1) + 'px',
|
|
864
|
+
lineHeight: 1,
|
|
865
|
+
color: shade,
|
|
866
|
+
fontFamily: 'ui-monospace,SFMono-Regular,Menlo,monospace',
|
|
867
|
+
},
|
|
868
|
+
'aria-hidden': true,
|
|
869
|
+
}, glyphs[index])
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* The little preview line under the gradient controls.
|
|
874
|
+
*
|
|
875
|
+
* It draws from the pack's own pool instead of a hard-coded sentence, so
|
|
876
|
+
* the preview shows what that pack will actually say. Glyph packs also get
|
|
877
|
+
* the typewriter cadence and switch phrase every two seconds.
|
|
878
|
+
*/
|
|
879
|
+
function PreviewLine({ lines, typing, gradient, mode, speed, gradientMode }) {
|
|
880
|
+
const [phrase, setPhrase] = React.useState('正在思考')
|
|
881
|
+
const [shown, setShown] = React.useState('正在思考')
|
|
882
|
+
const key = lines.join('\u0000')
|
|
883
|
+
|
|
884
|
+
React.useEffect(() => {
|
|
885
|
+
const pick = () => (lines.length === 0
|
|
886
|
+
? '正在思考'
|
|
887
|
+
: lines[Math.floor(Math.random() * lines.length)])
|
|
888
|
+
setPhrase(pick())
|
|
889
|
+
if (!typing) return undefined
|
|
890
|
+
// 预览里 5 秒换一次词条,比真实那行慢,看着不吵
|
|
891
|
+
const timer = window.setInterval(() => setPhrase(pick()), 5000)
|
|
892
|
+
return () => window.clearInterval(timer)
|
|
893
|
+
}, [key, typing])
|
|
894
|
+
|
|
895
|
+
React.useEffect(() => {
|
|
896
|
+
if (!typing) {
|
|
897
|
+
setShown(phrase)
|
|
898
|
+
return undefined
|
|
899
|
+
}
|
|
900
|
+
let count = 0
|
|
901
|
+
setShown('')
|
|
902
|
+
const timer = window.setInterval(() => {
|
|
903
|
+
count += 1
|
|
904
|
+
setShown(phrase.slice(0, count))
|
|
905
|
+
if (count >= phrase.length) window.clearInterval(timer)
|
|
906
|
+
}, 90)
|
|
907
|
+
return () => window.clearInterval(timer)
|
|
908
|
+
}, [phrase, typing])
|
|
909
|
+
|
|
910
|
+
if (gradientMode === 'none') {
|
|
911
|
+
return h('span', { style: { fontWeight: 600 } }, shown)
|
|
912
|
+
}
|
|
913
|
+
return h('span', {
|
|
914
|
+
'data-ts-grad': '',
|
|
915
|
+
'data-ts-mode': gradientMode,
|
|
916
|
+
style: {
|
|
917
|
+
'--ts-gradient': mode === 'sweep'
|
|
918
|
+
? sweepGradient(gradient[0], gradient.length > 1 ? gradient[1] : '#ffffff')
|
|
919
|
+
: mode === 'flow'
|
|
920
|
+
? loopGradient(gradient)
|
|
921
|
+
: 'linear-gradient(90deg, ' + gradient.join(', ') + ')',
|
|
922
|
+
'--ts-flow-speed': speed + 's',
|
|
923
|
+
'--ts-base': gradient[0],
|
|
924
|
+
'--ts-shine': gradient.length > 1 ? gradient[1] : '#ffffff',
|
|
925
|
+
'--ts-sweep-speed': speed + 's',
|
|
926
|
+
fontWeight: 600,
|
|
927
|
+
},
|
|
928
|
+
}, shown)
|
|
929
|
+
}
|
|
930
|
+
|
|
595
931
|
const previewOf = (lines) => (lines.length === 0 ? '(空)' : lines.slice(0, 5).join(' · ') + (lines.length > 5 ? ' …' : ''))
|
|
596
932
|
|
|
597
933
|
/**
|
|
@@ -606,6 +942,10 @@ window.__ModuleLoader__.load({
|
|
|
606
942
|
const [gradient, setGradient] = React.useState(DEFAULT_GRADIENT)
|
|
607
943
|
const [gradientMode, setGradientMode] = React.useState('static')
|
|
608
944
|
const [gradientSpeed, setGradientSpeed] = React.useState(3)
|
|
945
|
+
const [spinMode, setSpinMode] = React.useState('braille')
|
|
946
|
+
const [spinInterval, setSpinInterval] = React.useState(165)
|
|
947
|
+
const [spinPeriod, setSpinPeriod] = React.useState(2000)
|
|
948
|
+
const [spinColor, setSpinColor] = React.useState('#e5c07b')
|
|
609
949
|
const [detail, setDetail] = React.useState(null)
|
|
610
950
|
const [draft, setDraft] = React.useState('')
|
|
611
951
|
const [note, setNote] = React.useState('')
|
|
@@ -613,6 +953,11 @@ window.__ModuleLoader__.load({
|
|
|
613
953
|
const [coverFile, setCoverFile] = React.useState(null)
|
|
614
954
|
const [coverPreview, setCoverPreview] = React.useState('')
|
|
615
955
|
const [seedFiles, setSeedFiles] = React.useState([])
|
|
956
|
+
const [importDoc, setImportDoc] = React.useState(null)
|
|
957
|
+
const [importZip, setImportZip] = React.useState(null)
|
|
958
|
+
const [importPreviews, setImportPreviews] = React.useState({})
|
|
959
|
+
const [importCover, setImportCover] = React.useState(null)
|
|
960
|
+
const [importUrl, setImportUrl] = React.useState('')
|
|
616
961
|
const [theme, setTheme] = React.useState(() => {
|
|
617
962
|
try {
|
|
618
963
|
const saved = window.localStorage.getItem('think-skin-theme')
|
|
@@ -633,6 +978,11 @@ window.__ModuleLoader__.load({
|
|
|
633
978
|
setGradientSpeed(
|
|
634
979
|
Number.isFinite(Number(appearance.speed)) ? Number(appearance.speed) : 3,
|
|
635
980
|
)
|
|
981
|
+
const spinner = entry.spinner === undefined || entry.spinner === null ? {} : entry.spinner
|
|
982
|
+
setSpinMode(spinner.mode === 'glyph' ? 'glyph' : 'braille')
|
|
983
|
+
setSpinInterval(Number.isFinite(Number(spinner.interval)) ? Number(spinner.interval) : 165)
|
|
984
|
+
setSpinPeriod(Number.isFinite(Number(spinner.period)) ? Number(spinner.period) : 2000)
|
|
985
|
+
setSpinColor(typeof spinner.color === 'string' ? spinner.color : '')
|
|
636
986
|
setDetail(null)
|
|
637
987
|
}
|
|
638
988
|
|
|
@@ -703,6 +1053,18 @@ window.__ModuleLoader__.load({
|
|
|
703
1053
|
.catch((error) => setNote('保存失败:' + error.message))
|
|
704
1054
|
}
|
|
705
1055
|
|
|
1056
|
+
function saveSpinner() {
|
|
1057
|
+
commit({
|
|
1058
|
+
pack: selected,
|
|
1059
|
+
spinner: {
|
|
1060
|
+
mode: spinMode,
|
|
1061
|
+
interval: spinInterval,
|
|
1062
|
+
period: spinPeriod,
|
|
1063
|
+
color: spinColor,
|
|
1064
|
+
},
|
|
1065
|
+
}, '字形已保存')
|
|
1066
|
+
}
|
|
1067
|
+
|
|
706
1068
|
function saveGradient() {
|
|
707
1069
|
commit({ pack: selected, gradient, mode: gradientMode, speed: gradientSpeed, active: selected }, '已保存')
|
|
708
1070
|
}
|
|
@@ -780,6 +1142,193 @@ window.__ModuleLoader__.load({
|
|
|
780
1142
|
.catch(() => null)
|
|
781
1143
|
}
|
|
782
1144
|
|
|
1145
|
+
/** Minimal zip reader: reads the central directory, stores entries as-is. */
|
|
1146
|
+
function readZipEntries(buffer) {
|
|
1147
|
+
const view = new DataView(buffer)
|
|
1148
|
+
const bytes = new Uint8Array(buffer)
|
|
1149
|
+
let end = -1
|
|
1150
|
+
const floor = Math.max(0, bytes.length - 22 - 0xffff)
|
|
1151
|
+
for (let i = bytes.length - 22; i >= floor; i -= 1) {
|
|
1152
|
+
if (view.getUint32(i, true) === 0x06054b50) {
|
|
1153
|
+
end = i
|
|
1154
|
+
break
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
if (end < 0) throw new Error('不是 zip 文件')
|
|
1158
|
+
const count = view.getUint16(end + 10, true)
|
|
1159
|
+
let cursor = view.getUint32(end + 16, true)
|
|
1160
|
+
const entries = new Map()
|
|
1161
|
+
for (let i = 0; i < count; i += 1) {
|
|
1162
|
+
if (view.getUint32(cursor, true) !== 0x02014b50) break
|
|
1163
|
+
const method = view.getUint16(cursor + 10, true)
|
|
1164
|
+
const compressed = view.getUint32(cursor + 20, true)
|
|
1165
|
+
const nameLength = view.getUint16(cursor + 28, true)
|
|
1166
|
+
const extraLength = view.getUint16(cursor + 30, true)
|
|
1167
|
+
const commentLength = view.getUint16(cursor + 32, true)
|
|
1168
|
+
const localOffset = view.getUint32(cursor + 42, true)
|
|
1169
|
+
const name = new TextDecoder().decode(bytes.subarray(cursor + 46, cursor + 46 + nameLength))
|
|
1170
|
+
const localName = view.getUint16(localOffset + 26, true)
|
|
1171
|
+
const localExtra = view.getUint16(localOffset + 28, true)
|
|
1172
|
+
const start = localOffset + 30 + localName + localExtra
|
|
1173
|
+
entries.set(name, { method, raw: bytes.subarray(start, start + compressed) })
|
|
1174
|
+
cursor += 46 + nameLength + extraLength + commentLength
|
|
1175
|
+
}
|
|
1176
|
+
return entries
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/** Stored entries pass through; deflated ones go through DecompressionStream. */
|
|
1180
|
+
async function entryBytes(entry) {
|
|
1181
|
+
if (entry.method === 0) return entry.raw
|
|
1182
|
+
const stream = new Blob([entry.raw]).stream().pipeThrough(new DecompressionStream('deflate-raw'))
|
|
1183
|
+
return new Uint8Array(await new Response(stream).arrayBuffer())
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/** Save a JSON payload as a download. */
|
|
1187
|
+
function download(name, text) {
|
|
1188
|
+
const blob = new Blob([text], { type: 'application/json' })
|
|
1189
|
+
const href = URL.createObjectURL(blob)
|
|
1190
|
+
const anchor = document.createElement('a')
|
|
1191
|
+
anchor.href = href
|
|
1192
|
+
anchor.download = name
|
|
1193
|
+
anchor.click()
|
|
1194
|
+
window.setTimeout(() => URL.revokeObjectURL(href), 1000)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function exportPack() {
|
|
1198
|
+
if (current === undefined) return
|
|
1199
|
+
setNote('导出中…')
|
|
1200
|
+
fetch(ROUTE + '/export', {
|
|
1201
|
+
method: 'POST',
|
|
1202
|
+
headers: { 'content-type': 'application/json' },
|
|
1203
|
+
body: JSON.stringify({ pack: current.id }),
|
|
1204
|
+
})
|
|
1205
|
+
.then((response) => {
|
|
1206
|
+
if (!response.ok) {
|
|
1207
|
+
return response.text().then((t) => Promise.reject(new Error(t)))
|
|
1208
|
+
}
|
|
1209
|
+
return response.blob()
|
|
1210
|
+
})
|
|
1211
|
+
.then((blob) => {
|
|
1212
|
+
const href = URL.createObjectURL(blob)
|
|
1213
|
+
const anchor = document.createElement('a')
|
|
1214
|
+
anchor.href = href
|
|
1215
|
+
anchor.download = current.id + '.tskin.zip'
|
|
1216
|
+
anchor.click()
|
|
1217
|
+
window.setTimeout(() => URL.revokeObjectURL(href), 1000)
|
|
1218
|
+
setNote('已导出 ' + Math.round(blob.size / 1024) + ' KB')
|
|
1219
|
+
})
|
|
1220
|
+
.catch((error) => setNote('导出失败:' + error.message))
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/** Read a pack file in the browser so the page can preview it first. */
|
|
1224
|
+
function adoptImport(document, zipBytes, previews) {
|
|
1225
|
+
setImportDoc(document)
|
|
1226
|
+
setImportZip(zipBytes)
|
|
1227
|
+
setImportPreviews(previews)
|
|
1228
|
+
const images = Array.isArray(document.pack.images) ? document.pack.images : []
|
|
1229
|
+
setImportCover(document.pack.cover || (images[0] === undefined ? null : images[0].file))
|
|
1230
|
+
setNote('已载入 ' + images.length + ' 张图,可以换封面或直接导入')
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
function loadPackFile(files) {
|
|
1234
|
+
const file = files[0]
|
|
1235
|
+
if (file === undefined) return
|
|
1236
|
+
const isZip = /\.zip$/i.test(file.name)
|
|
1237
|
+
if (!isZip) {
|
|
1238
|
+
file.text()
|
|
1239
|
+
.then((text) => {
|
|
1240
|
+
const document = JSON.parse(text)
|
|
1241
|
+
if (document.format !== 'dsh-think-skin/pack') {
|
|
1242
|
+
setNote('这不是套组文件')
|
|
1243
|
+
return
|
|
1244
|
+
}
|
|
1245
|
+
const previews = {}
|
|
1246
|
+
for (const image of document.pack.images || []) {
|
|
1247
|
+
if (typeof image.data === 'string') {
|
|
1248
|
+
previews[image.file] = 'data:image/gif;base64,' + image.data
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
adoptImport(document, null, previews)
|
|
1252
|
+
})
|
|
1253
|
+
.catch((error) => setNote('文件解析失败:' + error.message))
|
|
1254
|
+
return
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
file.arrayBuffer()
|
|
1258
|
+
.then(async (buffer) => {
|
|
1259
|
+
const entries = readZipEntries(buffer)
|
|
1260
|
+
const manifestEntry = entries.get('pack.json')
|
|
1261
|
+
if (manifestEntry === undefined) {
|
|
1262
|
+
setNote('压缩包里没有 pack.json')
|
|
1263
|
+
return
|
|
1264
|
+
}
|
|
1265
|
+
const document = JSON.parse(new TextDecoder().decode(await entryBytes(manifestEntry)))
|
|
1266
|
+
if (document.format !== 'dsh-think-skin/pack') {
|
|
1267
|
+
setNote('这不是套组文件')
|
|
1268
|
+
return
|
|
1269
|
+
}
|
|
1270
|
+
const previews = {}
|
|
1271
|
+
for (const image of document.pack.images || []) {
|
|
1272
|
+
const entry = entries.get(image.file)
|
|
1273
|
+
if (entry === undefined) continue
|
|
1274
|
+
const bytes = await entryBytes(entry)
|
|
1275
|
+
previews[image.file] = URL.createObjectURL(new Blob([bytes], { type: 'image/gif' }))
|
|
1276
|
+
}
|
|
1277
|
+
adoptImport(document, buffer, previews)
|
|
1278
|
+
})
|
|
1279
|
+
.catch((error) => setNote('解压失败:' + error.message))
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function finishImport(receipt) {
|
|
1283
|
+
setNote('已导入「' + receipt.pack + '」,' + receipt.images + ' 张图')
|
|
1284
|
+
setImportDoc(null)
|
|
1285
|
+
setImportCover(null)
|
|
1286
|
+
setImportUrl('')
|
|
1287
|
+
setDetail(null)
|
|
1288
|
+
load(true)
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function runImport() {
|
|
1292
|
+
if (importDoc === null) {
|
|
1293
|
+
setNote('先选一个套组文件')
|
|
1294
|
+
return
|
|
1295
|
+
}
|
|
1296
|
+
setNote('导入中…')
|
|
1297
|
+
if (importZip !== null) {
|
|
1298
|
+
// zip 直接原样上传,宿主那边解;封面改动通过请求头带过去
|
|
1299
|
+
fetch(ROUTE + '/import', {
|
|
1300
|
+
method: 'POST',
|
|
1301
|
+
headers: {
|
|
1302
|
+
'content-type': 'application/zip',
|
|
1303
|
+
'x-ts-cover': encodeURIComponent(importCover === null ? '' : importCover),
|
|
1304
|
+
},
|
|
1305
|
+
body: importZip,
|
|
1306
|
+
})
|
|
1307
|
+
.then((response) => (response.ok
|
|
1308
|
+
? response.json()
|
|
1309
|
+
: response.text().then((t) => Promise.reject(new Error(t)))))
|
|
1310
|
+
.then(finishImport)
|
|
1311
|
+
.catch((error) => setNote('导入失败:' + error.message))
|
|
1312
|
+
return
|
|
1313
|
+
}
|
|
1314
|
+
const document = { ...importDoc, pack: { ...importDoc.pack, cover: importCover } }
|
|
1315
|
+
post(ROUTE + '/import', { file: document })
|
|
1316
|
+
.then(finishImport)
|
|
1317
|
+
.catch((error) => setNote('导入失败:' + error.message))
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function importFromUrl() {
|
|
1321
|
+
const url = importUrl.trim()
|
|
1322
|
+
if (url === '') {
|
|
1323
|
+
setNote('先填一个 URL')
|
|
1324
|
+
return
|
|
1325
|
+
}
|
|
1326
|
+
setNote('下载中…')
|
|
1327
|
+
post(ROUTE + '/import', { url })
|
|
1328
|
+
.then(finishImport)
|
|
1329
|
+
.catch((error) => setNote('下载导入失败:' + error.message))
|
|
1330
|
+
}
|
|
1331
|
+
|
|
783
1332
|
function upload(files) {
|
|
784
1333
|
const list = Array.from(files || [])
|
|
785
1334
|
if (list.length === 0) return
|
|
@@ -808,11 +1357,13 @@ window.__ModuleLoader__.load({
|
|
|
808
1357
|
}
|
|
809
1358
|
|
|
810
1359
|
function openGeneric() {
|
|
1360
|
+
setNote('')
|
|
811
1361
|
setDetail({ kind: 'generic' })
|
|
812
1362
|
setDraft((current === undefined ? [] : current.fallbackTexts || []).join('\n'))
|
|
813
1363
|
}
|
|
814
1364
|
|
|
815
1365
|
function openImage(image) {
|
|
1366
|
+
setNote('')
|
|
816
1367
|
setDetail({ kind: 'image', id: image.id, name: image.name })
|
|
817
1368
|
setDraft((image.texts || []).join('\n'))
|
|
818
1369
|
}
|
|
@@ -833,6 +1384,136 @@ window.__ModuleLoader__.load({
|
|
|
833
1384
|
|
|
834
1385
|
// ---- detail view -------------------------------------------------------
|
|
835
1386
|
|
|
1387
|
+
if (detail !== null && detail.kind === 'import') {
|
|
1388
|
+
const images = importDoc === null || !Array.isArray(importDoc.pack.images)
|
|
1389
|
+
? []
|
|
1390
|
+
: importDoc.pack.images
|
|
1391
|
+
return h('div', rootProps,
|
|
1392
|
+
h('div', { style: { ...S.row, justifyContent: 'space-between' } },
|
|
1393
|
+
h('strong', { style: { fontSize: '14px' } }, '导入套组'),
|
|
1394
|
+
h('button', {
|
|
1395
|
+
type: 'button',
|
|
1396
|
+
className: 'ts-btn',
|
|
1397
|
+
style: S.btn,
|
|
1398
|
+
onClick: () => {
|
|
1399
|
+
setDetail(null)
|
|
1400
|
+
setImportDoc(null)
|
|
1401
|
+
},
|
|
1402
|
+
}, '返回'),
|
|
1403
|
+
),
|
|
1404
|
+
|
|
1405
|
+
h('div', { style: { ...S.row, alignItems: 'flex-start', gap: '20px' } },
|
|
1406
|
+
h('div', { style: { ...S.card, ...S.cardOn, cursor: 'default', flex: 'none' } },
|
|
1407
|
+
importCover === null
|
|
1408
|
+
? h('div', { style: S.cardArtEmpty }, '空')
|
|
1409
|
+
: h('img', {
|
|
1410
|
+
// 还没导入时它在存储里不存在,用浏览器刚解出来的对象 URL
|
|
1411
|
+
src: importPreviews[importCover] || imageUrl(importCover),
|
|
1412
|
+
style: S.cardArt,
|
|
1413
|
+
alt: '',
|
|
1414
|
+
}),
|
|
1415
|
+
h('div', { style: S.cardName },
|
|
1416
|
+
importDoc === null ? '未载入' : (importDoc.pack.id || '导入的套')),
|
|
1417
|
+
),
|
|
1418
|
+
h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: '12px' } },
|
|
1419
|
+
h('div', null,
|
|
1420
|
+
h('span', { style: S.label }, '本地文件(整份复制进内部存储)'),
|
|
1421
|
+
h('div', { style: S.row },
|
|
1422
|
+
h(FilePick, {
|
|
1423
|
+
label: '选 .zip',
|
|
1424
|
+
accept: '.zip,application/zip',
|
|
1425
|
+
multiple: false,
|
|
1426
|
+
onFiles: loadPackFile,
|
|
1427
|
+
}),
|
|
1428
|
+
h(FilePick, {
|
|
1429
|
+
label: '选旧版 .json',
|
|
1430
|
+
accept: '.json,application/json',
|
|
1431
|
+
multiple: false,
|
|
1432
|
+
onFiles: loadPackFile,
|
|
1433
|
+
}),
|
|
1434
|
+
h('span', { style: S.hint },
|
|
1435
|
+
importDoc === null ? '未选择' : images.length + ' 张图已载入'),
|
|
1436
|
+
),
|
|
1437
|
+
),
|
|
1438
|
+
h('div', null,
|
|
1439
|
+
h('span', { style: S.label }, '或者从 URL 下载(由宿主下载,绕过跨域)'),
|
|
1440
|
+
h('div', { style: S.row },
|
|
1441
|
+
h('input', {
|
|
1442
|
+
value: importUrl,
|
|
1443
|
+
placeholder: 'https://example.com/pack.zip',
|
|
1444
|
+
style: { ...S.field, flex: 1, minWidth: '220px' },
|
|
1445
|
+
onChange: (event) => setImportUrl(event.target.value),
|
|
1446
|
+
onKeyDown: (event) => {
|
|
1447
|
+
if (event.key === 'Enter') importFromUrl()
|
|
1448
|
+
},
|
|
1449
|
+
}),
|
|
1450
|
+
h('button', {
|
|
1451
|
+
type: 'button',
|
|
1452
|
+
className: 'ts-btn',
|
|
1453
|
+
style: S.btn,
|
|
1454
|
+
onClick: importFromUrl,
|
|
1455
|
+
}, '下载并导入'),
|
|
1456
|
+
),
|
|
1457
|
+
),
|
|
1458
|
+
images.length === 0
|
|
1459
|
+
? null
|
|
1460
|
+
: h('div', null,
|
|
1461
|
+
h('span', { style: S.label }, '换封面(点一张,导入后它就是封面)'),
|
|
1462
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '6px' } },
|
|
1463
|
+
images.slice(0, 60).map((image, index) => h('img', {
|
|
1464
|
+
key: 'cover' + index,
|
|
1465
|
+
src: importPreviews[image.file] || '',
|
|
1466
|
+
alt: '',
|
|
1467
|
+
onClick: () => setImportCover(image.file),
|
|
1468
|
+
style: {
|
|
1469
|
+
width: '44px',
|
|
1470
|
+
height: '44px',
|
|
1471
|
+
objectFit: 'contain',
|
|
1472
|
+
borderRadius: '6px',
|
|
1473
|
+
cursor: 'pointer',
|
|
1474
|
+
background: 'rgba(127,127,127,.10)',
|
|
1475
|
+
outline: importCover === image.file ? '2px solid #4c8bf5' : 'none',
|
|
1476
|
+
},
|
|
1477
|
+
})),
|
|
1478
|
+
),
|
|
1479
|
+
),
|
|
1480
|
+
),
|
|
1481
|
+
),
|
|
1482
|
+
|
|
1483
|
+
h('div', { style: S.row },
|
|
1484
|
+
h('button', {
|
|
1485
|
+
type: 'button',
|
|
1486
|
+
className: 'ts-btn',
|
|
1487
|
+
style: S.btn,
|
|
1488
|
+
onClick: runImport,
|
|
1489
|
+
}, '导入'),
|
|
1490
|
+
h('span', { style: S.hint }, note),
|
|
1491
|
+
),
|
|
1492
|
+
|
|
1493
|
+
// 小广告:作者自己的下载器
|
|
1494
|
+
h('div', {
|
|
1495
|
+
style: {
|
|
1496
|
+
marginTop: '6px',
|
|
1497
|
+
padding: '10px 14px',
|
|
1498
|
+
borderRadius: '10px',
|
|
1499
|
+
border: '1px dashed rgba(127,127,127,.35)',
|
|
1500
|
+
background: 'rgba(127,127,127,.05)',
|
|
1501
|
+
fontSize: '12px',
|
|
1502
|
+
lineHeight: 1.7,
|
|
1503
|
+
opacity: 0.75,
|
|
1504
|
+
},
|
|
1505
|
+
},
|
|
1506
|
+
h('strong', { style: { fontWeight: 600 } }, '顺带一提'),
|
|
1507
|
+
h('br'),
|
|
1508
|
+
'URL 只认直链:对象存储、GitHub raw、你自己的静态服务器都行;网盘分享页拿不到直链,用不了。',
|
|
1509
|
+
h('br'),
|
|
1510
|
+
'推荐作者自己的 DLS(下载服务器插件):多线程 + 断点续传,几十 MB 的包下起来稳一些。',
|
|
1511
|
+
h('br'),
|
|
1512
|
+
h('span', { style: { opacity: 0.7 } }, '(只是推荐,这里和 DLS 没有联动。)'),
|
|
1513
|
+
),
|
|
1514
|
+
)
|
|
1515
|
+
}
|
|
1516
|
+
|
|
836
1517
|
if (detail !== null && detail.kind === 'create') {
|
|
837
1518
|
return h('div', rootProps,
|
|
838
1519
|
h('div', { style: { ...S.row, justifyContent: 'space-between' } },
|
|
@@ -969,8 +1650,14 @@ window.__ModuleLoader__.load({
|
|
|
969
1650
|
|
|
970
1651
|
// ---- list view ---------------------------------------------------------
|
|
971
1652
|
|
|
1653
|
+
const isSpinnerPack = current !== undefined
|
|
1654
|
+
&& current.spinner !== undefined
|
|
1655
|
+
&& current.spinner !== null
|
|
972
1656
|
const images = current === undefined || !Array.isArray(current.images) ? [] : current.images
|
|
973
1657
|
const generic = current === undefined ? [] : current.fallbackTexts || []
|
|
1658
|
+
const previewLines = Array.from(new Set(
|
|
1659
|
+
generic.concat(images.flatMap((img) => (Array.isArray(img.texts) ? img.texts : []))),
|
|
1660
|
+
)).filter((line) => typeof line === 'string' && line.length > 0)
|
|
974
1661
|
|
|
975
1662
|
return h('div', rootProps,
|
|
976
1663
|
|
|
@@ -1008,15 +1695,107 @@ window.__ModuleLoader__.load({
|
|
|
1008
1695
|
style: S.card,
|
|
1009
1696
|
onClick: () => {
|
|
1010
1697
|
setNewName('')
|
|
1698
|
+
setNote('')
|
|
1011
1699
|
setDetail({ kind: 'create' })
|
|
1012
1700
|
},
|
|
1013
1701
|
},
|
|
1014
1702
|
h('div', { style: S.cardArtEmpty }, '+'),
|
|
1015
1703
|
h('div', { style: S.cardName }, '新建'),
|
|
1016
1704
|
),
|
|
1705
|
+
h('button', {
|
|
1706
|
+
type: 'button',
|
|
1707
|
+
className: 'ts-card',
|
|
1708
|
+
style: S.card,
|
|
1709
|
+
onClick: () => {
|
|
1710
|
+
setImportDoc(null)
|
|
1711
|
+
setImportCover(null)
|
|
1712
|
+
setImportUrl('')
|
|
1713
|
+
setNote('')
|
|
1714
|
+
setDetail({ kind: 'import' })
|
|
1715
|
+
},
|
|
1716
|
+
},
|
|
1717
|
+
h('div', { style: S.cardArtEmpty }, '↧'),
|
|
1718
|
+
h('div', { style: S.cardName }, '导入套组'),
|
|
1719
|
+
),
|
|
1017
1720
|
),
|
|
1018
1721
|
),
|
|
1019
1722
|
|
|
1723
|
+
// 字形包(没有图片,用字符转圈)
|
|
1724
|
+
current !== undefined && current.spinner !== undefined && current.spinner !== null
|
|
1725
|
+
? h('div', null,
|
|
1726
|
+
h('span', { style: S.label }, '字形(这一套用字符转圈,不用图片)'),
|
|
1727
|
+
h('div', { style: S.row },
|
|
1728
|
+
h('span', { style: S.hint }, '模式'),
|
|
1729
|
+
[['braille', '盲文'], ['glyph', '字符画']].map(([id, text]) => h('button', {
|
|
1730
|
+
key: 'spin-' + id,
|
|
1731
|
+
type: 'button',
|
|
1732
|
+
className: 'ts-btn',
|
|
1733
|
+
style: {
|
|
1734
|
+
...S.btn,
|
|
1735
|
+
padding: '4px 10px',
|
|
1736
|
+
...(spinMode === id ? { borderColor: '#4c8bf5', background: 'rgba(76,139,245,.16)' } : null),
|
|
1737
|
+
},
|
|
1738
|
+
onClick: () => setSpinMode(id),
|
|
1739
|
+
}, text)),
|
|
1740
|
+
h('span', { style: S.hint }, spinMode === 'glyph' ? '整趟时长' : '帧间隔'),
|
|
1741
|
+
h('input', {
|
|
1742
|
+
type: 'number',
|
|
1743
|
+
min: 16,
|
|
1744
|
+
max: 6000,
|
|
1745
|
+
step: 10,
|
|
1746
|
+
value: spinMode === 'glyph' ? spinPeriod : spinInterval,
|
|
1747
|
+
style: { ...S.field, width: '76px', padding: '4px 6px' },
|
|
1748
|
+
onChange: (event) => {
|
|
1749
|
+
const value = Number(event.target.value)
|
|
1750
|
+
if (!Number.isFinite(value)) return
|
|
1751
|
+
const clamped = Math.max(16, Math.min(6000, Math.round(value)))
|
|
1752
|
+
if (spinMode === 'glyph') setSpinPeriod(clamped)
|
|
1753
|
+
else setSpinInterval(clamped)
|
|
1754
|
+
},
|
|
1755
|
+
}),
|
|
1756
|
+
h('span', { style: S.hint }, 'ms'),
|
|
1757
|
+
h('span', { style: S.hint }, '颜色'),
|
|
1758
|
+
h('input', {
|
|
1759
|
+
type: 'color',
|
|
1760
|
+
value: spinColor === '' ? '#e5c07b' : spinColor,
|
|
1761
|
+
onChange: (event) => setSpinColor(event.target.value),
|
|
1762
|
+
}),
|
|
1763
|
+
h('button', {
|
|
1764
|
+
type: 'button',
|
|
1765
|
+
className: 'ts-btn',
|
|
1766
|
+
style: { ...S.btn, fontSize: '12px', padding: '4px 10px' },
|
|
1767
|
+
title: '去掉固定色,让字形跟着主题走',
|
|
1768
|
+
onClick: () => setSpinColor(''),
|
|
1769
|
+
}, '用主题色'),
|
|
1770
|
+
h('button', {
|
|
1771
|
+
type: 'button',
|
|
1772
|
+
className: 'ts-btn',
|
|
1773
|
+
style: S.btn,
|
|
1774
|
+
onClick: saveSpinner,
|
|
1775
|
+
}, '保存'),
|
|
1776
|
+
),
|
|
1777
|
+
h('div', { style: { ...S.row, marginTop: '10px' } },
|
|
1778
|
+
h('span', { style: S.hint }, '预览'),
|
|
1779
|
+
h(SpinPreview, {
|
|
1780
|
+
mode: spinMode,
|
|
1781
|
+
interval: spinMode === 'glyph' ? spinPeriod : spinInterval,
|
|
1782
|
+
color: spinColor,
|
|
1783
|
+
}),
|
|
1784
|
+
h(PreviewLine, {
|
|
1785
|
+
lines: previewLines,
|
|
1786
|
+
typing: true,
|
|
1787
|
+
gradient: gradient,
|
|
1788
|
+
mode: gradientMode,
|
|
1789
|
+
speed: gradientSpeed,
|
|
1790
|
+
gradientMode: gradientMode,
|
|
1791
|
+
}),
|
|
1792
|
+
),
|
|
1793
|
+
h('div', { style: { marginTop: '6px', fontSize: '12px', opacity: 0.55 } },
|
|
1794
|
+
'盲文:⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ 单向转圈,时长=每帧毫秒(官方 80)。'
|
|
1795
|
+
+ '字符画:· ✢ ✻ 余弦呼吸,时长=一整趟毫秒(官方 2000)。两个值各存各的。'),
|
|
1796
|
+
)
|
|
1797
|
+
: null,
|
|
1798
|
+
|
|
1020
1799
|
// gradient
|
|
1021
1800
|
h('div', null,
|
|
1022
1801
|
h('span', { style: S.label }, '文字渐变(2–4 色)'),
|
|
@@ -1086,31 +1865,25 @@ window.__ModuleLoader__.load({
|
|
|
1086
1865
|
+ '切回流动/静态才用得上。'),
|
|
1087
1866
|
h('div', { style: { ...S.row, marginTop: '10px' } },
|
|
1088
1867
|
h('span', { style: S.hint }, '预览'),
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
:
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
: gradientMode === 'flow'
|
|
1098
|
-
? loopGradient(gradient)
|
|
1099
|
-
: 'linear-gradient(90deg, ' + gradient.join(', ') + ')',
|
|
1100
|
-
'--ts-flow-speed': gradientSpeed + 's',
|
|
1101
|
-
'--ts-base': gradient[0],
|
|
1102
|
-
'--ts-shine': gradient.length > 1 ? gradient[1] : '#ffffff',
|
|
1103
|
-
'--ts-sweep-speed': gradientSpeed + 's',
|
|
1104
|
-
fontWeight: 600,
|
|
1105
|
-
},
|
|
1106
|
-
}, '正在思考,用时 3秒'),
|
|
1868
|
+
h(PreviewLine, {
|
|
1869
|
+
lines: previewLines,
|
|
1870
|
+
typing: isSpinnerPack,
|
|
1871
|
+
gradient: gradient,
|
|
1872
|
+
mode: gradientMode,
|
|
1873
|
+
speed: gradientSpeed,
|
|
1874
|
+
gradientMode: gradientMode,
|
|
1875
|
+
}),
|
|
1107
1876
|
),
|
|
1108
1877
|
),
|
|
1109
1878
|
|
|
1110
1879
|
// phrase pools
|
|
1111
1880
|
h('div', null,
|
|
1112
1881
|
h('span', { style: S.label }, '文案池'),
|
|
1113
|
-
h('div', {
|
|
1882
|
+
h('div', {
|
|
1883
|
+
style: isSpinnerPack
|
|
1884
|
+
? { ...S.poolList, aspectRatio: 'auto', overflowY: 'visible' }
|
|
1885
|
+
: S.poolList,
|
|
1886
|
+
},
|
|
1114
1887
|
h('div', {
|
|
1115
1888
|
className: 'ts-row',
|
|
1116
1889
|
style: S.poolRow,
|
|
@@ -1131,7 +1904,9 @@ window.__ModuleLoader__.load({
|
|
|
1131
1904
|
h('div', { style: S.poolPreview }, '通用 · ' + previewOf(generic)),
|
|
1132
1905
|
h('span', { style: S.poolCount }, generic.length + ' 句'),
|
|
1133
1906
|
),
|
|
1134
|
-
|
|
1907
|
+
(current !== undefined && current.spinner !== undefined && current.spinner !== null
|
|
1908
|
+
? []
|
|
1909
|
+
: images).map((image) => h('div', {
|
|
1135
1910
|
key: image.id,
|
|
1136
1911
|
className: 'ts-row',
|
|
1137
1912
|
style: S.poolRow,
|
|
@@ -1147,11 +1922,15 @@ window.__ModuleLoader__.load({
|
|
|
1147
1922
|
)),
|
|
1148
1923
|
),
|
|
1149
1924
|
h('span', { style: { ...S.hint, display: 'block', marginTop: '6px' } },
|
|
1150
|
-
|
|
1925
|
+
current !== undefined && current.spinner !== undefined && current.spinner !== null
|
|
1926
|
+
? '这一套用字符转圈,没有图片池;文案全部来自上面的通用池。'
|
|
1927
|
+
: images.length + ' 张图 · 点任意一行进去改文案'),
|
|
1151
1928
|
),
|
|
1152
1929
|
|
|
1153
|
-
// import
|
|
1154
|
-
|
|
1930
|
+
// import(字形包不需要)
|
|
1931
|
+
current !== undefined && current.spinner !== undefined && current.spinner !== null
|
|
1932
|
+
? null
|
|
1933
|
+
: h('div', null,
|
|
1155
1934
|
h('span', { style: S.label }, '导入图片到「' + (selected === '' ? '未选择' : selected) + '」'),
|
|
1156
1935
|
h('div', { style: S.row },
|
|
1157
1936
|
h(FilePick, {
|
|
@@ -1163,13 +1942,28 @@ window.__ModuleLoader__.load({
|
|
|
1163
1942
|
directory: true,
|
|
1164
1943
|
onFiles: (files) => upload(files.filter((f) => /\.(gif|png|webp|apng|jpe?g)$/i.test(f.name))),
|
|
1165
1944
|
}),
|
|
1945
|
+
),
|
|
1946
|
+
),
|
|
1947
|
+
|
|
1948
|
+
// 套组级操作:和「导入图片」分开,别混在那一行里
|
|
1949
|
+
h('div', null,
|
|
1950
|
+
h('span', { style: S.label }, '套组操作'),
|
|
1951
|
+
h('div', { style: S.row },
|
|
1952
|
+
h('button', {
|
|
1953
|
+
type: 'button',
|
|
1954
|
+
className: 'ts-btn',
|
|
1955
|
+
style: S.btn,
|
|
1956
|
+
onClick: exportPack,
|
|
1957
|
+
title: '导出成 .tskin.json,图片会内嵌在文件里',
|
|
1958
|
+
}, '导出这个套'),
|
|
1166
1959
|
current !== undefined && current.builtin !== true
|
|
1167
1960
|
? h('button', {
|
|
1168
1961
|
type: 'button',
|
|
1169
|
-
|
|
1962
|
+
className: 'ts-btn',
|
|
1963
|
+
style: { ...S.btn, color: '#f2777a' },
|
|
1170
1964
|
onClick: () => deletePack(current.id),
|
|
1171
1965
|
}, '删除这个套')
|
|
1172
|
-
:
|
|
1966
|
+
: h('span', { style: S.hint }, '内置套不能删除'),
|
|
1173
1967
|
),
|
|
1174
1968
|
),
|
|
1175
1969
|
|
|
@@ -1181,6 +1975,40 @@ window.__ModuleLoader__.load({
|
|
|
1181
1975
|
)
|
|
1182
1976
|
}
|
|
1183
1977
|
|
|
1978
|
+
/**
|
|
1979
|
+
* The nav icon for our settings section.
|
|
1980
|
+
*
|
|
1981
|
+
* `settings.section.icon` hands the component `size` (requested square edge)
|
|
1982
|
+
* and `active` (whether the section is selected). We show the active pack's
|
|
1983
|
+
* cover; glyph packs get a star instead, since they have no artwork.
|
|
1984
|
+
*/
|
|
1985
|
+
function SettingsIcon({ size, active }) {
|
|
1986
|
+
const [, bump] = React.useState(0)
|
|
1987
|
+
React.useEffect(() => {
|
|
1988
|
+
if (pack === null) loadPack().then(() => bump((n) => n + 1))
|
|
1989
|
+
}, [])
|
|
1990
|
+
const edge = Number.isFinite(Number(size)) ? Number(size) : 16
|
|
1991
|
+
const box = { width: edge + 'px', height: edge + 'px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }
|
|
1992
|
+
|
|
1993
|
+
if (pack === null) return h('span', { style: { ...box, fontSize: edge * 0.9 } }, '✻')
|
|
1994
|
+
// 字形套也有封面(那个橙色 ✻ 占位图),照样用它,别退化成文字
|
|
1995
|
+
const file = pack.cover || (Array.isArray(pack.images) && pack.images[0] !== undefined
|
|
1996
|
+
? pack.images[0].file
|
|
1997
|
+
: null)
|
|
1998
|
+
if (file === null) return h('span', { style: { ...box, fontSize: edge * 0.9 } }, '✻')
|
|
1999
|
+
return h('img', {
|
|
2000
|
+
src: imageUrl(file),
|
|
2001
|
+
alt: '',
|
|
2002
|
+
style: {
|
|
2003
|
+
width: edge + 'px',
|
|
2004
|
+
height: edge + 'px',
|
|
2005
|
+
objectFit: 'contain',
|
|
2006
|
+
borderRadius: '3px',
|
|
2007
|
+
opacity: active === false ? 0.85 : 1,
|
|
2008
|
+
},
|
|
2009
|
+
})
|
|
2010
|
+
}
|
|
2011
|
+
|
|
1184
2012
|
/** Register the settings page. Failure here must not take the skin down. */
|
|
1185
2013
|
function registerSettings(ctx) {
|
|
1186
2014
|
try {
|
|
@@ -1191,6 +2019,15 @@ window.__ModuleLoader__.load({
|
|
|
1191
2019
|
label: () => '思考状态',
|
|
1192
2020
|
inject: () => ({}),
|
|
1193
2021
|
}, SettingsPanel))
|
|
2022
|
+
|
|
2023
|
+
// 同一个 id 才会被挂到我们那一行的图标位上
|
|
2024
|
+
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
2025
|
+
name: 'settings.section.icon',
|
|
2026
|
+
id: 'think-skin',
|
|
2027
|
+
order: 40,
|
|
2028
|
+
label: () => '思考状态',
|
|
2029
|
+
inject: () => ({}),
|
|
2030
|
+
}, SettingsIcon))
|
|
1194
2031
|
} catch {
|
|
1195
2032
|
/* the panel is optional; the skin keeps working without it */
|
|
1196
2033
|
}
|
|
@@ -1218,9 +2055,25 @@ window.__ModuleLoader__.load({
|
|
|
1218
2055
|
const interval = setInterval(() => {
|
|
1219
2056
|
paint(document)
|
|
1220
2057
|
}, 1000)
|
|
2058
|
+
// 字形每 80ms 一帧,1 秒的节拍会让它一顿一顿地跳,所以单独给一条快节拍。
|
|
2059
|
+
// 只改文字和颜色,不做查询以外的重活。
|
|
2060
|
+
const fast = setInterval(() => {
|
|
2061
|
+
tickSpinners(document)
|
|
2062
|
+
tickGlimmer(document, Date.now())
|
|
2063
|
+
// 有词条还没打完就重画一次(打完就不再触发,避免每秒白跑)
|
|
2064
|
+
for (const row of document.querySelectorAll(ROW)) {
|
|
2065
|
+
const full = row.getAttribute('data-ts-full')
|
|
2066
|
+
const shown = row.getAttribute('data-ts-shown') || ''
|
|
2067
|
+
if (full !== null && shown.length < full.length) {
|
|
2068
|
+
paint(document)
|
|
2069
|
+
break
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
}, 80)
|
|
1221
2073
|
return () => {
|
|
1222
2074
|
observer.disconnect()
|
|
1223
2075
|
clearInterval(interval)
|
|
2076
|
+
clearInterval(fast)
|
|
1224
2077
|
}
|
|
1225
2078
|
})
|
|
1226
2079
|
},
|