dsh-live2dwaifu 1.0.3 → 1.0.5
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 +6 -0
- package/lib/client.js +41 -53
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -340,6 +340,12 @@ curl -X POST http://127.0.0.1:<端口>/dsh-live2d/api/push \
|
|
|
340
340
|
|
|
341
341
|
---
|
|
342
342
|
|
|
343
|
+
## 反馈
|
|
344
|
+
|
|
345
|
+
遇到问题、想要新功能、觉得哪句话还是像 AI,都可以写信到 **FujiwaraReisen@outlook.com**。
|
|
346
|
+
|
|
347
|
+
也可以直接去 [GitHub Issues](https://github.com/FujiwaraReisen/dsh-live2dwaifu/issues) 提,附上模型的来源和出问题的样子更容易定位。
|
|
348
|
+
|
|
343
349
|
## 致谢
|
|
344
350
|
|
|
345
351
|
- Live2D Cubism Core © Live2D Inc.
|
package/lib/client.js
CHANGED
|
@@ -151,68 +151,56 @@
|
|
|
151
151
|
.catch(() => setTitle('Live2D'));
|
|
152
152
|
}, [nonce]);
|
|
153
153
|
|
|
154
|
-
//
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
if (f) f.style.pointerEvents = on ? 'none' : '';
|
|
158
|
-
if (cardEl && cardEl.classList) {
|
|
159
|
-
cardEl.classList.toggle('resizing', on && cls === 'resizing');
|
|
160
|
-
cardEl.classList.toggle('moving', on && cls === 'moving');
|
|
161
|
-
}
|
|
162
|
-
document.body.style.userSelect = on ? 'none' : '';
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const bindDrag = (move, cls, cardEl) => {
|
|
166
|
-
const up = () => {
|
|
167
|
-
window.removeEventListener('pointermove', move);
|
|
168
|
-
window.removeEventListener('pointerup', up);
|
|
169
|
-
window.removeEventListener('pointercancel', up);
|
|
170
|
-
lockPointer(false, cls, cardEl);
|
|
171
|
-
};
|
|
172
|
-
window.addEventListener('pointermove', move);
|
|
173
|
-
window.addEventListener('pointerup', up);
|
|
174
|
-
window.addEventListener('pointercancel', up);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// 卡片钉在右下角,所以只有左上角会动:往左上拖变大,往右下拖变小
|
|
178
|
-
const startDrag = (e) => {
|
|
154
|
+
// 拖动时盖一层全屏透明遮罩:既挡住 iframe 吃事件,也保证 pointermove 一定落在父窗口
|
|
155
|
+
const beginDrag = (e, kind) => {
|
|
156
|
+
if (e.button !== undefined && e.button !== 0) return;
|
|
179
157
|
e.preventDefault();
|
|
180
158
|
e.stopPropagation();
|
|
181
|
-
const cardEl = e.currentTarget.closest('.dsh-l2d-card');
|
|
159
|
+
const cardEl = e.currentTarget && e.currentTarget.closest ? e.currentTarget.closest('.dsh-l2d-card') : null;
|
|
182
160
|
const sx = e.clientX;
|
|
183
161
|
const sy = e.clientY;
|
|
184
162
|
const w0 = size.w;
|
|
185
163
|
const h0 = size.h;
|
|
186
|
-
lockPointer(true, 'resizing', cardEl);
|
|
187
|
-
bindDrag((ev) => {
|
|
188
|
-
const maxW = Math.min(720, Math.max(240, window.innerWidth - 60));
|
|
189
|
-
const maxH = Math.max(240, window.innerHeight - 80);
|
|
190
|
-
const w = Math.max(200, Math.min(maxW, w0 + (sx - ev.clientX)));
|
|
191
|
-
const hh = Math.max(220, Math.min(maxH, h0 + (sy - ev.clientY)));
|
|
192
|
-
setSize({ w: Math.round(w), h: Math.round(hh) });
|
|
193
|
-
}, 'resizing', cardEl);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const startMove = (e) => {
|
|
197
|
-
if (e.button !== undefined && e.button !== 0) return;
|
|
198
|
-
const cardEl = e.currentTarget.closest('.dsh-l2d-card');
|
|
199
|
-
const sx = e.clientX;
|
|
200
|
-
const sy = e.clientY;
|
|
201
164
|
const x0 = pos.x;
|
|
202
165
|
const y0 = pos.y;
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
166
|
+
const cls = kind === 'resize' ? 'resizing' : 'moving';
|
|
167
|
+
const shield = document.createElement('div');
|
|
168
|
+
shield.setAttribute('data-dsh-l2d-shield', '1');
|
|
169
|
+
shield.style.cssText =
|
|
170
|
+
'position:fixed;left:0;top:0;right:0;bottom:0;z-index:99999;background:transparent;touch-action:none;cursor:' +
|
|
171
|
+
(kind === 'resize' ? 'nwse-resize' : 'move');
|
|
172
|
+
document.body.appendChild(shield);
|
|
173
|
+
if (cardEl && cardEl.classList) cardEl.classList.add(cls);
|
|
174
|
+
|
|
175
|
+
const move = (ev) => {
|
|
176
|
+
if (kind === 'resize') {
|
|
177
|
+
const maxW = Math.max(240, Math.min(760, window.innerWidth - 40));
|
|
178
|
+
const maxH = Math.max(240, window.innerHeight - 60);
|
|
179
|
+
const w = Math.max(200, Math.min(maxW, w0 + (sx - ev.clientX)));
|
|
180
|
+
const hh = Math.max(200, Math.min(maxH, h0 + (sy - ev.clientY)));
|
|
181
|
+
setSize({ w: Math.round(w), h: Math.round(hh) });
|
|
182
|
+
} else {
|
|
183
|
+
setPos({ x: Math.round(x0 + (ev.clientX - sx)), y: Math.round(y0 + (ev.clientY - sy)) });
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const finish = () => {
|
|
188
|
+
shield.removeEventListener('pointermove', move);
|
|
189
|
+
if (shield.parentNode) shield.parentNode.removeChild(shield);
|
|
190
|
+
if (cardEl && cardEl.classList) cardEl.classList.remove(cls);
|
|
191
|
+
window.removeEventListener('pointermove', move);
|
|
192
|
+
window.removeEventListener('pointerup', finish);
|
|
193
|
+
window.removeEventListener('pointercancel', finish);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
shield.addEventListener('pointermove', move);
|
|
197
|
+
window.addEventListener('pointermove', move);
|
|
198
|
+
window.addEventListener('pointerup', finish);
|
|
199
|
+
window.addEventListener('pointercancel', finish);
|
|
215
200
|
};
|
|
201
|
+
|
|
202
|
+
const startDrag = (e) => beginDrag(e, 'resize');
|
|
203
|
+
const startMove = (e) => beginDrag(e, 'move');
|
|
216
204
|
const noDrag = (e) => e.stopPropagation();
|
|
217
205
|
|
|
218
206
|
const manage = () => ref.current && ref.current.contentWindow.postMessage({ type: 'dsh-live2d/manage' }, '*');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-live2dwaifu",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "给 DSH 网页右下角请一个 Live2D 角色:会眨眼、会呼吸、视线跟着鼠标、点她有反应、说话时嘴动、心情变了眉毛跟着动。模型不用内置——谁装谁放自己的文件夹;支持自定义 .exp3.json 表情和 .motion3.json 动作,卡片能拖能缩,背景可换。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|