dsh-xinqi-live2d 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -2
- package/cordis.patch.yml +14 -0
- package/lib/client.js +223 -0
- package/lib/index.js +562 -0
- package/package.json +56 -4
- package/vendor/cubism4.min.js +1 -0
- package/vendor/live2dcubismcore.min.js +9 -0
- package/vendor/pixi.min.js +1108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 panmaci4676
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-live2d-emotion
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DSH 情绪 Live2D 挂件:每轮回复打一个情绪标签,屏幕右上角模型实时换表情。
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
dsh plugin --profile web add dsh-live2d-emotion
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## v2.0.0 重写说明
|
|
10
|
+
|
|
11
|
+
**挂件跑在独立 iframe 里。** 这是与 v1 的根本区别:
|
|
12
|
+
|
|
13
|
+
| | v1 | v2 |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| 渲染位置 | 宿主 `shell.overlay` | **独立 iframe** |
|
|
16
|
+
| WebGL 崩了 | 整个 DSH 白屏 | **只影响那块区域** |
|
|
17
|
+
| CDN 挂了 | 拖垮宿主渲染树 | iframe 显示错误,宿主无感 |
|
|
18
|
+
| 宿主端依赖 | pixi + live2d + WebGL | **只有一个 iframe 标签** |
|
|
19
|
+
|
|
20
|
+
## 装模型
|
|
21
|
+
|
|
22
|
+
把模型放到(插件不带模型,通常几十 MB):
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
~/.dsh/live2d/<模型名>/<模型名>.model3.json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
插件会在该目录及一级子目录里找唯一一个 `*.model3.json`。
|
|
29
|
+
|
|
30
|
+
## 情绪标签
|
|
31
|
+
|
|
32
|
+
`live2d_report_emotion` 工具接受:`happy/开心`、`love/爱`、`shy/害羞`、`sad/难过`、
|
|
33
|
+
`cry/哭`、`angry/生气`、`confused/困惑`、`dizzy`、`nervous/紧张`、`excited/兴奋`、
|
|
34
|
+
`sleepy/困`、`neutral/平静`。
|
|
35
|
+
|
|
36
|
+
表情 8 秒后自动回默认。
|
|
37
|
+
|
|
38
|
+
## 配置
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
- id: live2d-emotion
|
|
42
|
+
config:
|
|
43
|
+
modelDir: /root/.dsh/live2d
|
|
44
|
+
modelFile: 大肥鱼.model3.json
|
|
45
|
+
size: 220
|
|
46
|
+
defaultEmotion: 默认
|
|
47
|
+
enabled: true
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 接口
|
|
51
|
+
|
|
52
|
+
| 方法 | 路径 | 说明 |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| GET | `/-/live2d/frame` | 挂件页面(iframe src) |
|
|
55
|
+
| GET | `/-/live2d/state` | 状态 + 模型信息 |
|
|
56
|
+
| POST | `/-/live2d/emotion` | 上报情绪 |
|
|
57
|
+
| GET | `/-/live2d/events` | SSE |
|
|
58
|
+
| GET | `/-/live2d/model/*` | 模型文件(防穿越) |
|
|
59
|
+
| GET | `/-/live2d/info` | 诊断 |
|
|
60
|
+
|
|
61
|
+
## 依赖
|
|
62
|
+
|
|
63
|
+
需要浏览器能访问 `cdn.jsdelivr.net`(pixi / pixi-live2d-display / cubism core 都在 iframe 内加载)。
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# dsh-xinqi-live2d — bundle patch
|
|
2
|
+
#
|
|
3
|
+
# v2.0.0 重写:挂件渲染在**独立 iframe** 里,与宿主前端渲染树完全隔离。
|
|
4
|
+
# 即便 Live2D/WebGL 在 iframe 里彻底崩掉,也不会影响 DSH 本体。
|
|
5
|
+
#
|
|
6
|
+
# 配置(全部有默认值):
|
|
7
|
+
# modelDir 模型根目录(默认 <DSH_HOME>/live2d)
|
|
8
|
+
# modelFile 指定入口 .model3.json(默认自动找)
|
|
9
|
+
# size 挂件边长 px(默认 220)
|
|
10
|
+
# defaultEmotion 无情绪时的表情名(默认「默认」)
|
|
11
|
+
# enabled 总开关(默认 true)
|
|
12
|
+
- insert:
|
|
13
|
+
- id: live2d-emotion
|
|
14
|
+
name: './lib/index.js'
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-xinqi-live2d v2 — browser half
|
|
3
|
+
*
|
|
4
|
+
* **极简**:只渲染一个 iframe + 拖动条。
|
|
5
|
+
* 所有 Live2D / WebGL / CDN 的活都在 iframe 内部完成,
|
|
6
|
+
* 与宿主前端渲染树完全隔离 —— iframe 里彻底崩掉也不会影响 DSH。
|
|
7
|
+
*
|
|
8
|
+
* v1 的教训:把 pixi 塞进 shell.overlay 会让整个页面 "Failed to load plugins"。
|
|
9
|
+
*/
|
|
10
|
+
window.__ModuleLoader__.load({
|
|
11
|
+
id: 'dsh-xinqi-live2d',
|
|
12
|
+
factory: require => {
|
|
13
|
+
const module = { exports: {} }
|
|
14
|
+
const exports = module.exports
|
|
15
|
+
const React = require('react')
|
|
16
|
+
const { createElement: h, useState, useEffect, useRef, useCallback } = React
|
|
17
|
+
|
|
18
|
+
const NS = 'live2d-emotion'
|
|
19
|
+
const API = '/-/live2d'
|
|
20
|
+
const POS_KEY = 'dsh-xinqi-live2d.pos.v2'
|
|
21
|
+
const HIDE_KEY = 'dsh-xinqi-live2d.hidden.v2'
|
|
22
|
+
|
|
23
|
+
const C = {
|
|
24
|
+
fg: 'var(--dsw-alias-label-primary, #e6edf3)',
|
|
25
|
+
fgDim: 'var(--dsw-alias-label-secondary, #8b949e)',
|
|
26
|
+
border: 'var(--dsw-alias-border-l2, rgba(128,128,128,.32))',
|
|
27
|
+
bg: 'var(--dsw-alias-bg-layer-2, rgba(22,27,34,.94))',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function loadPos() {
|
|
31
|
+
try {
|
|
32
|
+
const raw = window.localStorage.getItem(POS_KEY)
|
|
33
|
+
if (raw) {
|
|
34
|
+
const p = JSON.parse(raw)
|
|
35
|
+
if (typeof p.x === 'number' && typeof p.y === 'number') return p
|
|
36
|
+
}
|
|
37
|
+
} catch {}
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
function savePos(p) { try { window.localStorage.setItem(POS_KEY, JSON.stringify(p)) } catch {} }
|
|
41
|
+
function loadHidden() { try { return window.localStorage.getItem(HIDE_KEY) === '1' } catch { return false } }
|
|
42
|
+
function saveHidden(v) { try { window.localStorage.setItem(HIDE_KEY, v ? '1' : '0') } catch {} }
|
|
43
|
+
|
|
44
|
+
function Widget() {
|
|
45
|
+
const [hidden, setHidden] = useState(loadHidden)
|
|
46
|
+
const [pos, setPos] = useState(() => loadPos() || { x: 16, y: 72 })
|
|
47
|
+
const [collapsed, setCollapsed] = useState(false)
|
|
48
|
+
const [size, setSize] = useState(220)
|
|
49
|
+
const [label, setLabel] = useState('平静')
|
|
50
|
+
const [ready, setReady] = useState(false)
|
|
51
|
+
const dragRef = useRef(null)
|
|
52
|
+
const posRef = useRef(pos)
|
|
53
|
+
posRef.current = pos
|
|
54
|
+
|
|
55
|
+
// 拉一次尺寸 + 情绪标签
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (hidden) return undefined
|
|
58
|
+
let stop = false
|
|
59
|
+
fetch(`${API}/state`, { credentials: 'same-origin', cache: 'no-store' })
|
|
60
|
+
.then((r) => r.json())
|
|
61
|
+
.then((d) => {
|
|
62
|
+
if (stop || !d || d.ok === false) return
|
|
63
|
+
const v = d.value || {}
|
|
64
|
+
if (typeof v.size === 'number') setSize(v.size)
|
|
65
|
+
if (v.label) setLabel(v.label)
|
|
66
|
+
setReady(true)
|
|
67
|
+
})
|
|
68
|
+
.catch(() => setReady(true))
|
|
69
|
+
return () => { stop = true }
|
|
70
|
+
}, [hidden])
|
|
71
|
+
|
|
72
|
+
// 情绪标签(轮询,轻量)
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (hidden) return undefined
|
|
75
|
+
const tick = () => {
|
|
76
|
+
if (document.visibilityState === 'hidden') return
|
|
77
|
+
fetch(`${API}/state`, { credentials: 'same-origin', cache: 'no-store' })
|
|
78
|
+
.then((r) => r.json())
|
|
79
|
+
.then((d) => {
|
|
80
|
+
const v = d && d.value
|
|
81
|
+
if (v && v.label) setLabel(v.label)
|
|
82
|
+
if (v && typeof v.size === 'number') setSize(v.size)
|
|
83
|
+
})
|
|
84
|
+
.catch(() => {})
|
|
85
|
+
}
|
|
86
|
+
const iv = setInterval(tick, 4000)
|
|
87
|
+
return () => clearInterval(iv)
|
|
88
|
+
}, [hidden])
|
|
89
|
+
|
|
90
|
+
const onDown = useCallback((e) => {
|
|
91
|
+
if (e.target.closest('[data-nodrag]')) return
|
|
92
|
+
const r = e.currentTarget.getBoundingClientRect()
|
|
93
|
+
dragRef.current = { dx: e.clientX - r.left, dy: e.clientY - r.top }
|
|
94
|
+
e.currentTarget.setPointerCapture?.(e.pointerId)
|
|
95
|
+
}, [])
|
|
96
|
+
const onMove = useCallback((e) => {
|
|
97
|
+
const d = dragRef.current
|
|
98
|
+
if (!d) return
|
|
99
|
+
setPos({
|
|
100
|
+
x: Math.max(0, Math.min(window.innerWidth - 100, e.clientX - d.dx)),
|
|
101
|
+
y: Math.max(0, Math.min(window.innerHeight - 80, e.clientY - d.dy)),
|
|
102
|
+
})
|
|
103
|
+
}, [])
|
|
104
|
+
const onUp = useCallback(() => {
|
|
105
|
+
if (dragRef.current) savePos(posRef.current)
|
|
106
|
+
dragRef.current = null
|
|
107
|
+
}, [])
|
|
108
|
+
|
|
109
|
+
if (hidden) {
|
|
110
|
+
return h('button', {
|
|
111
|
+
type: 'button',
|
|
112
|
+
title: '显示 Live2D',
|
|
113
|
+
onClick: () => { saveHidden(false); setHidden(false) },
|
|
114
|
+
style: {
|
|
115
|
+
position: 'absolute', right: '12px', top: '12px', zIndex: 30,
|
|
116
|
+
width: '34px', height: '34px', borderRadius: '10px',
|
|
117
|
+
border: `1px solid ${C.border}`, background: C.bg, color: C.fg,
|
|
118
|
+
cursor: 'pointer', fontSize: '15px', lineHeight: 1,
|
|
119
|
+
boxShadow: '0 4px 14px rgba(0,0,0,.24)',
|
|
120
|
+
},
|
|
121
|
+
}, '🐟')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const btn = {
|
|
125
|
+
width: '22px', height: '22px', borderRadius: '6px', border: 'none',
|
|
126
|
+
background: 'transparent', color: C.fgDim, cursor: 'pointer',
|
|
127
|
+
fontSize: '12px', lineHeight: 1, display: 'grid', placeItems: 'center',
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const w = collapsed ? 120 : size
|
|
131
|
+
const hgt = collapsed ? 32 : size + 28
|
|
132
|
+
|
|
133
|
+
return h('div', {
|
|
134
|
+
onPointerDown: onDown,
|
|
135
|
+
onPointerMove: onMove,
|
|
136
|
+
onPointerUp: onUp,
|
|
137
|
+
style: {
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
left: pos.x + 'px',
|
|
140
|
+
top: pos.y + 'px',
|
|
141
|
+
zIndex: 30,
|
|
142
|
+
width: w + 'px',
|
|
143
|
+
height: hgt + 'px',
|
|
144
|
+
borderRadius: '14px',
|
|
145
|
+
background: C.bg,
|
|
146
|
+
border: `1px solid ${C.border}`,
|
|
147
|
+
boxShadow: '0 10px 30px rgba(0,0,0,.30)',
|
|
148
|
+
backdropFilter: 'blur(10px)',
|
|
149
|
+
overflow: 'hidden',
|
|
150
|
+
cursor: 'grab',
|
|
151
|
+
userSelect: 'none',
|
|
152
|
+
touchAction: 'none',
|
|
153
|
+
display: 'flex',
|
|
154
|
+
flexDirection: 'column',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
// 标题栏
|
|
158
|
+
h('div', {
|
|
159
|
+
style: {
|
|
160
|
+
display: 'flex', alignItems: 'center', gap: '4px',
|
|
161
|
+
padding: '5px 7px', flex: 'none',
|
|
162
|
+
borderBottom: collapsed ? 'none' : `1px solid ${C.border}`,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
h('span', {
|
|
166
|
+
style: {
|
|
167
|
+
flex: 1, minWidth: 0, fontSize: '11px', color: C.fgDim,
|
|
168
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
169
|
+
},
|
|
170
|
+
}, (collapsed ? '🐟 ' : '') + label),
|
|
171
|
+
h('button', {
|
|
172
|
+
type: 'button', 'data-nodrag': true, title: collapsed ? '展开' : '收起',
|
|
173
|
+
onClick: () => setCollapsed(!collapsed), style: btn,
|
|
174
|
+
}, collapsed ? '▢' : '—'),
|
|
175
|
+
h('button', {
|
|
176
|
+
type: 'button', 'data-nodrag': true, title: '隐藏',
|
|
177
|
+
onClick: () => { saveHidden(true); setHidden(true) }, style: btn,
|
|
178
|
+
}, '✕'),
|
|
179
|
+
),
|
|
180
|
+
|
|
181
|
+
// iframe 区域:Live2D 全部跑在这里,与宿主隔离
|
|
182
|
+
!collapsed && h('iframe', {
|
|
183
|
+
'data-nodrag': true,
|
|
184
|
+
src: ready ? `${API}/frame2` : 'about:blank',
|
|
185
|
+
title: 'Live2D',
|
|
186
|
+
sandbox: 'allow-scripts allow-same-origin',
|
|
187
|
+
style: {
|
|
188
|
+
flex: 1,
|
|
189
|
+
width: '100%',
|
|
190
|
+
border: 'none',
|
|
191
|
+
background: 'transparent',
|
|
192
|
+
display: 'block',
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const name = 'dsh-xinqi-live2d'
|
|
199
|
+
const inject = ['slots']
|
|
200
|
+
|
|
201
|
+
function apply(ctx) {
|
|
202
|
+
// 照抄 access-gate / console-hm 的写法:inject 的回调直接返回 register 的结果。
|
|
203
|
+
// 不要在中间再包一层 ctx.effect —— 那会让注册时机和声明生命周期错位。
|
|
204
|
+
try {
|
|
205
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
206
|
+
name: 'shell.overlay',
|
|
207
|
+
id: 'live2d-emotion-widget',
|
|
208
|
+
order: 90,
|
|
209
|
+
label: () => 'Live2D',
|
|
210
|
+
locale: NS,
|
|
211
|
+
inject: () => ({}),
|
|
212
|
+
}, Widget))
|
|
213
|
+
} catch (e) {
|
|
214
|
+
try { console.warn('[live2d-emotion] 挂件注册失败(已忽略):', e) } catch {}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
exports.name = name
|
|
219
|
+
exports.inject = inject
|
|
220
|
+
exports.apply = apply
|
|
221
|
+
return module.exports
|
|
222
|
+
},
|
|
223
|
+
})
|