dsh-share-chat 0.3.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -126
- package/client.js +2304 -336
- package/docs/DETAIL.md +8 -20
- package/index.js +186 -0
- package/package.json +9 -11
- package/CHANGELOG.md +0 -65
- package/cli/chat-mcp.mjs +0 -225
- package/cli/chat.cmd +0 -3
- package/cli/chat.mjs +0 -335
- package/docs/GAME.md +0 -69
- package/docs/INSTALL.md +0 -95
- package/docs/MEETING.md +0 -69
package/client.js
CHANGED
|
@@ -158,6 +158,90 @@ window.__ModuleLoader__.load({
|
|
|
158
158
|
return '📄'
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 主题自适应兜底:找自己背后真正有颜色的那一层,判断是亮面还是暗面。
|
|
164
|
+
* 某些槽位(比如 main 面板)不会把 DSH 的暗色背景带下来,此时 token 可能是
|
|
165
|
+
* 「白字」而背景是白的 —— 这里按实际背景强制一套可读的 token。
|
|
166
|
+
*/
|
|
167
|
+
function parseColorToRgb(value) {
|
|
168
|
+
const m = String(value || '').match(/rgba?\(([^)]+)\)/)
|
|
169
|
+
if (!m) return null
|
|
170
|
+
const parts = m[1].split(',').map((x) => parseFloat(x.trim()))
|
|
171
|
+
if (parts.length < 3 || parts.some((n) => Number.isNaN(n))) return null
|
|
172
|
+
return { r: parts[0], g: parts[1], b: parts[2], a: parts.length > 3 ? parts[3] : 1 }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function relativeLuminance(c) {
|
|
176
|
+
const f = (v) => {
|
|
177
|
+
const x = v / 255
|
|
178
|
+
return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4)
|
|
179
|
+
}
|
|
180
|
+
return 0.2126 * f(c.r) + 0.7152 * f(c.g) + 0.0722 * f(c.b)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function effectiveBackground(el) {
|
|
184
|
+
let node = el
|
|
185
|
+
while (node && node.nodeType === 1) {
|
|
186
|
+
const c = parseColorToRgb(getComputedStyle(node).backgroundColor)
|
|
187
|
+
if (c && c.a > 0.5) return c
|
|
188
|
+
node = node.parentElement
|
|
189
|
+
}
|
|
190
|
+
return { r: 255, g: 255, b: 255, a: 1 }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const LIGHT_TOKENS = {
|
|
194
|
+
'--dsw-alias-label-primary': '#1f2328',
|
|
195
|
+
'--dsw-alias-label-secondary': '#5b6570',
|
|
196
|
+
'--dsw-alias-label-tertiary': '#8b949e',
|
|
197
|
+
'--dsw-alias-label-quaternary': '#a0a8b0',
|
|
198
|
+
'--dsw-alias-border-l2': 'rgba(20,20,20,.12)',
|
|
199
|
+
'--dsw-alias-border-l3': 'rgba(20,20,20,.18)',
|
|
200
|
+
'--dsw-alias-fill-l1': 'rgba(0,0,0,.035)',
|
|
201
|
+
'--dsw-alias-fill-l2': 'rgba(0,0,0,.07)',
|
|
202
|
+
'--dsw-alias-card-fill': 'rgba(0,0,0,.04)',
|
|
203
|
+
'--dsw-alias-card-fill-hover': 'rgba(0,0,0,.08)',
|
|
204
|
+
'--dsw-alias-interactive-bg-hover': 'rgba(0,0,0,.06)',
|
|
205
|
+
'--dsw-alias-brand-primary': '#247bbf',
|
|
206
|
+
'--dsw-alias-link': '#247bbf',
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const DARK_TOKENS = {
|
|
210
|
+
'--dsw-alias-label-primary': '#e9f2f6',
|
|
211
|
+
'--dsw-alias-label-secondary': '#9fb3bd',
|
|
212
|
+
'--dsw-alias-label-tertiary': '#7c939d',
|
|
213
|
+
'--dsw-alias-label-quaternary': '#5f757e',
|
|
214
|
+
'--dsw-alias-border-l2': 'rgba(255,255,255,.12)',
|
|
215
|
+
'--dsw-alias-border-l3': 'rgba(255,255,255,.18)',
|
|
216
|
+
'--dsw-alias-fill-l1': 'rgba(255,255,255,.035)',
|
|
217
|
+
'--dsw-alias-fill-l2': 'rgba(255,255,255,.08)',
|
|
218
|
+
'--dsw-alias-card-fill': 'rgba(255,255,255,.05)',
|
|
219
|
+
'--dsw-alias-card-fill-hover': 'rgba(255,255,255,.10)',
|
|
220
|
+
'--dsw-alias-interactive-bg-hover': 'rgba(255,255,255,.07)',
|
|
221
|
+
'--dsw-alias-brand-primary': '#247bbf',
|
|
222
|
+
'--dsw-alias-link': '#67b6ea',
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** 如果文字色和实际背景的对比度太低,就用实际背景对应的那套 token */
|
|
226
|
+
function adaptSurfaceTokens(root) {
|
|
227
|
+
try {
|
|
228
|
+
if (!root || typeof getComputedStyle !== 'function') return
|
|
229
|
+
const bg = effectiveBackground(root)
|
|
230
|
+
const fg = parseColorToRgb(getComputedStyle(root).color) || { r: 0, g: 0, b: 0, a: 1 }
|
|
231
|
+
const l1 = relativeLuminance(bg)
|
|
232
|
+
const l2 = relativeLuminance(fg)
|
|
233
|
+
const ratio = (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05)
|
|
234
|
+
const surfaceIsLight = l1 > 0.5
|
|
235
|
+
root.setAttribute('data-sc-surface', surfaceIsLight ? 'light' : 'dark')
|
|
236
|
+
if (ratio < 3) {
|
|
237
|
+
const tokens = surfaceIsLight ? LIGHT_TOKENS : DARK_TOKENS
|
|
238
|
+
for (const k of Object.keys(tokens)) root.style.setProperty(k, tokens[k])
|
|
239
|
+
}
|
|
240
|
+
} catch (e) {
|
|
241
|
+
/* 取不到样式就算了,保持原样 */
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
161
245
|
// ───────────────────────── 样式 ─────────────────────────
|
|
162
246
|
|
|
163
247
|
const STYLE_ID = 'dsh-share-chat-style'
|
|
@@ -175,8 +259,9 @@ window.__ModuleLoader__.load({
|
|
|
175
259
|
.sc-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.10))}
|
|
176
260
|
.sc-btn:active{transform:scale(.97)}
|
|
177
261
|
.sc-btn:disabled{opacity:.42;cursor:default;transform:none}
|
|
178
|
-
.sc-btn-primary{border-color:transparent;background
|
|
179
|
-
.sc-btn-primary:hover{background
|
|
262
|
+
.sc-btn-primary{border-color:transparent;background:#247bbf;color:#fff}
|
|
263
|
+
.sc-btn-primary:hover{background:#1f6cab}
|
|
264
|
+
.sc-btn-primary:disabled{background:#2f5f86;color:rgba(255,255,255,.72)}
|
|
180
265
|
.sc-btn-ghost{border-color:transparent}
|
|
181
266
|
.sc-btn-ghost:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.10))}
|
|
182
267
|
.sc-icon-btn{width:30px;padding:0;font-size:15px}
|
|
@@ -298,6 +383,65 @@ window.__ModuleLoader__.load({
|
|
|
298
383
|
.sc-ok{font-size:11.5px;color:var(--dsw-alias-state-success-primary,#2f8f65)}
|
|
299
384
|
.sc-hint{font-size:11px;color:var(--dsw-alias-label-tertiary,#8b949e)}
|
|
300
385
|
|
|
386
|
+
.sc-camp{flex:1;min-height:0;overflow:auto;padding:16px 18px}
|
|
387
|
+
.sc-camp-top{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:14px}
|
|
388
|
+
.sc-camp-grid{display:flex;flex-direction:column;gap:10px;max-width:880px;margin:0 auto}
|
|
389
|
+
.sc-camp-card{display:flex;align-items:center;gap:12px;padding:12px 14px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.22));border-radius:14px;background:var(--dsw-alias-card-fill,rgba(128,128,128,.05));cursor:pointer;transition:background .15s,border-color .15s}
|
|
390
|
+
.sc-camp-card:hover{background:var(--dsw-alias-card-fill-hover,rgba(128,128,128,.10));border-color:var(--dsw-alias-border-l3,rgba(128,128,128,.32))}
|
|
391
|
+
.sc-camp-emoji{width:38px;height:38px;border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:19px;background:rgba(36,123,191,.18)}
|
|
392
|
+
.sc-camp-info{flex:1;min-width:0}
|
|
393
|
+
.sc-camp-name{font-size:13.5px;font-weight:600}
|
|
394
|
+
.sc-camp-greet{font-size:12px;color:var(--dsw-alias-label-secondary,#5b6570);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
395
|
+
.sc-camp-meta{font-size:11px;color:var(--dsw-alias-label-tertiary,#8b949e)}
|
|
396
|
+
.sc-camp-badge{display:inline-flex;align-items:center;height:20px;padding:0 8px;border-radius:99px;font-size:10.5px;white-space:nowrap}
|
|
397
|
+
.sc-badge-have{background:rgba(76,195,138,.16);color:#4cc38a}
|
|
398
|
+
.sc-badge-new{background:rgba(36,123,191,.18);color:#67b6ea}
|
|
399
|
+
.sc-badge-diff{background:rgba(240,180,80,.16);color:#e6b35c}
|
|
400
|
+
.sc-badge-builtin{background:rgba(255,255,255,.08);color:var(--dsw-alias-label-tertiary,#8b949e)}
|
|
401
|
+
.sc-camp-form{display:flex;flex-direction:column;gap:10px;max-width:520px;padding:16px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.22));border-radius:14px;background:var(--dsw-alias-card-fill,rgba(128,128,128,.05))}
|
|
402
|
+
.sc-camp-plugins{display:flex;flex-direction:column;gap:6px;margin-top:10px}
|
|
403
|
+
.sc-camp-plug{display:flex;align-items:center;gap:8px;font-size:12px}
|
|
404
|
+
.sc-camp-plug .nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
405
|
+
.sc-char-svg{display:block;overflow:visible}
|
|
406
|
+
.sc-scene{position:relative;height:200px;border-radius:14px;overflow:hidden;margin:0 0 14px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.22));background:linear-gradient(180deg,#0d2a35 0%,#0a1a20 100%)}
|
|
407
|
+
.sc-scene-floor{position:absolute;left:0;right:0;bottom:0;height:52px;background:linear-gradient(180deg,rgba(36,123,191,.20),rgba(36,123,191,.03));border-top:1px solid rgba(86,176,236,.28)}
|
|
408
|
+
.sc-scene-actor{position:absolute;bottom:16px;display:flex;flex-direction:column;align-items:center;gap:2px}
|
|
409
|
+
.sc-scene-bob{animation:sc-bob 2.4s ease-in-out infinite}
|
|
410
|
+
.sc-scene-actor.walk{animation:sc-walk-in .95s ease-out both}
|
|
411
|
+
.sc-scene-name{font-size:10px;line-height:1.6;padding:1px 7px;border-radius:99px;background:rgba(0,0,0,.45);color:#dfeef5;white-space:nowrap}
|
|
412
|
+
.sc-scene-empty{position:absolute;left:50%;top:16px;transform:translateX(-50%);font-size:11.5px;color:rgba(223,238,245,.55)}
|
|
413
|
+
@keyframes sc-bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-3px)}}
|
|
414
|
+
@keyframes sc-walk-in{from{transform:translateX(-140px);opacity:0}to{transform:translateX(0);opacity:1}}
|
|
415
|
+
.sc-char-btn{display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 10px;border-radius:11px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.3));background:transparent;color:inherit;font:inherit;font-size:12px;cursor:pointer}
|
|
416
|
+
.sc-char-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.1))}
|
|
417
|
+
.sc-face-mask{position:fixed;inset:0;z-index:2147483645;display:flex;align-items:center;justify-content:center;background:rgba(4,10,14,.72);backdrop-filter:blur(6px)}
|
|
418
|
+
.sc-face{width:min(1040px,94vw);height:min(720px,92vh);display:flex;flex-direction:column;border-radius:18px;overflow:hidden;
|
|
419
|
+
background:var(--dsw-alias-bg-base,#0e1116);color:var(--dsw-alias-label-primary,#e9f2f6);
|
|
420
|
+
border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.24));box-shadow:0 30px 80px rgba(0,0,0,.55)}
|
|
421
|
+
.sc-face-head{display:flex;align-items:center;gap:8px;padding:12px 16px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.2));flex:0 0 auto;flex-wrap:wrap}
|
|
422
|
+
.sc-face-title{font-size:14px;font-weight:600}
|
|
423
|
+
.sc-face-body{flex:1;min-height:0;display:flex}
|
|
424
|
+
.sc-face-left{width:340px;flex:0 0 auto;padding:16px;border-right:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.2));display:flex;flex-direction:column;align-items:center;gap:10px}
|
|
425
|
+
.sc-face-stage{width:100%;height:330px;border-radius:14px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.2));background:radial-gradient(120% 80% at 50% 0%,rgba(80,150,190,.20),rgba(10,20,26,.5));display:flex;align-items:center;justify-content:center;overflow:hidden}
|
|
426
|
+
.sc-face-right{flex:1;min-width:0;display:flex;flex-direction:column}
|
|
427
|
+
.sc-face-tabs{display:flex;gap:6px;padding:10px 14px;overflow-x:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.2));flex:0 0 auto}
|
|
428
|
+
.sc-face-tab{height:26px;padding:0 10px;border-radius:8px;border:1px solid transparent;background:transparent;color:var(--dsw-alias-label-secondary,#9fb3bd);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}
|
|
429
|
+
.sc-face-tab.on{background:rgba(36,123,191,.18);border-color:rgba(86,176,236,.4);color:var(--dsw-alias-label-primary,#e9f2f6)}
|
|
430
|
+
.sc-face-params{flex:1;min-height:0;overflow:auto;padding:14px 16px}
|
|
431
|
+
.sc-face-row{display:flex;align-items:center;gap:10px;margin-bottom:10px}
|
|
432
|
+
.sc-face-row .lab{width:70px;flex:0 0 auto;font-size:12px;color:var(--dsw-alias-label-secondary,#9fb3bd)}
|
|
433
|
+
.sc-face-row input[type=range]{flex:1;accent-color:#247bbf;height:18px}
|
|
434
|
+
.sc-face-row .num{width:44px;text-align:right;font-size:11.5px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-tertiary,#8b949e)}
|
|
435
|
+
.sc-face-sw{margin-bottom:12px}
|
|
436
|
+
.sc-face-sw .lab{display:block;font-size:12px;color:var(--dsw-alias-label-secondary,#9fb3bd);margin-bottom:6px}
|
|
437
|
+
.sc-swatches{display:flex;gap:7px;flex-wrap:wrap}
|
|
438
|
+
.sc-swatch{width:24px;height:24px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0}
|
|
439
|
+
.sc-swatch.on{border-color:#67b6ea;box-shadow:0 0 0 2px rgba(103,182,234,.25)}
|
|
440
|
+
.sc-seg{display:flex;gap:6px;flex-wrap:wrap}
|
|
441
|
+
.sc-seg button{height:26px;padding:0 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.22));background:transparent;color:inherit;font:inherit;font-size:12px;cursor:pointer}
|
|
442
|
+
.sc-seg button.on{background:rgba(36,123,191,.22);border-color:rgba(86,176,236,.45)}
|
|
443
|
+
.sc-face-foot{display:flex;align-items:center;gap:8px;padding:10px 16px;border-top:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.2));flex:0 0 auto;flex-wrap:wrap}
|
|
444
|
+
.sc-face-code{flex:1;min-width:160px;font-family:ui-monospace,Consolas,monospace;font-size:10.5px}
|
|
301
445
|
@media (max-width: 720px){
|
|
302
446
|
.sc-side{width:152px;flex-basis:152px}
|
|
303
447
|
.sc-side-title{padding:10px 10px 4px}
|
|
@@ -330,24 +474,9 @@ window.__ModuleLoader__.load({
|
|
|
330
474
|
return x
|
|
331
475
|
}
|
|
332
476
|
|
|
333
|
-
|
|
334
|
-
let avatarBase = ''
|
|
335
|
-
|
|
336
|
-
function avatar(name, id, size, avatarId, isGroup) {
|
|
477
|
+
function avatar(name, id, size) {
|
|
337
478
|
const sz = size || 30
|
|
338
|
-
if (avatarId) {
|
|
339
|
-
return h('img', {
|
|
340
|
-
className: 'sc-avatar',
|
|
341
|
-
src: avatarBase + '/f/' + avatarId,
|
|
342
|
-
alt: String(name || id || ''),
|
|
343
|
-
loading: 'lazy',
|
|
344
|
-
style: { width: sz + 'px', height: sz + 'px', objectFit: 'cover', display: 'block' },
|
|
345
|
-
})
|
|
346
|
-
}
|
|
347
479
|
const hue = hueOf(id || name)
|
|
348
|
-
const initial = isGroup
|
|
349
|
-
? '👥'
|
|
350
|
-
: String(name || id || '?').trim().charAt(0).toUpperCase()
|
|
351
480
|
return h(
|
|
352
481
|
'span',
|
|
353
482
|
{
|
|
@@ -364,7 +493,7 @@ window.__ModuleLoader__.load({
|
|
|
364
493
|
' 58% 44%))',
|
|
365
494
|
},
|
|
366
495
|
},
|
|
367
|
-
|
|
496
|
+
String(name || id || '?').trim().charAt(0).toUpperCase(),
|
|
368
497
|
)
|
|
369
498
|
}
|
|
370
499
|
|
|
@@ -627,9 +756,7 @@ window.__ModuleLoader__.load({
|
|
|
627
756
|
|
|
628
757
|
function ChatPanel(props) {
|
|
629
758
|
const auth = props.auth
|
|
630
|
-
avatarBase = auth.server
|
|
631
759
|
const [friends, setFriends] = useState([])
|
|
632
|
-
const [groups, setGroups] = useState([])
|
|
633
760
|
const [active, setActive] = useState(null)
|
|
634
761
|
const [messages, setMessages] = useState([])
|
|
635
762
|
const [draft, setDraft] = useState('')
|
|
@@ -638,7 +765,7 @@ window.__ModuleLoader__.load({
|
|
|
638
765
|
const [sending, setSending] = useState(false)
|
|
639
766
|
const [uploading, setUploading] = useState(false)
|
|
640
767
|
const [emojiOpen, setEmojiOpen] = useState(false)
|
|
641
|
-
const [
|
|
768
|
+
const [campMode, setCampMode] = useState(false)
|
|
642
769
|
|
|
643
770
|
const cursorRef = useRef(0)
|
|
644
771
|
const listRef = useRef(null)
|
|
@@ -654,7 +781,6 @@ window.__ModuleLoader__.load({
|
|
|
654
781
|
try {
|
|
655
782
|
const r = await api(auth.server, '/api/friends', { token: auth.token })
|
|
656
783
|
setFriends(r.friends || [])
|
|
657
|
-
setGroups(r.groups || [])
|
|
658
784
|
return r.friends || []
|
|
659
785
|
} catch (e) {
|
|
660
786
|
setErr(friendly(e))
|
|
@@ -667,11 +793,6 @@ window.__ModuleLoader__.load({
|
|
|
667
793
|
loadFriends().then((list) => {
|
|
668
794
|
if (alive && list.length && !active) setActive(list[0].id)
|
|
669
795
|
})
|
|
670
|
-
api(auth.server, '/api/me', { token: auth.token })
|
|
671
|
-
.then((me) => {
|
|
672
|
-
if (alive && me && me.avatar) setMyAvatar(me.avatar)
|
|
673
|
-
})
|
|
674
|
-
.catch(() => {})
|
|
675
796
|
return () => {
|
|
676
797
|
alive = false
|
|
677
798
|
}
|
|
@@ -709,17 +830,10 @@ window.__ModuleLoader__.load({
|
|
|
709
830
|
const f = await api(auth.server, '/api/friends', { token: auth.token })
|
|
710
831
|
if (!alive) return
|
|
711
832
|
const list = f.friends || []
|
|
712
|
-
const
|
|
713
|
-
const key =
|
|
714
|
-
list.map((x) => x.id + ':' + (x.displayName || '') + ':' + (x.avatar || '')).join('|') +
|
|
715
|
-
'§' +
|
|
716
|
-
glist
|
|
717
|
-
.map((g) => g.id + ':' + g.name + ':' + (g.avatar || '') + ':' + (g.members || []).length)
|
|
718
|
-
.join('|')
|
|
833
|
+
const key = list.map((x) => x.id + ':' + (x.displayName || '')).join('|')
|
|
719
834
|
if (key !== friendsKeyRef.current) {
|
|
720
835
|
friendsKeyRef.current = key
|
|
721
836
|
setFriends(list)
|
|
722
|
-
setGroups(glist)
|
|
723
837
|
if (!activeRef.current && list.length) setActive(list[0].id)
|
|
724
838
|
}
|
|
725
839
|
} catch (e) {
|
|
@@ -826,89 +940,6 @@ window.__ModuleLoader__.load({
|
|
|
826
940
|
}
|
|
827
941
|
|
|
828
942
|
/* 好友列表里的「最后一条」摘要 */
|
|
829
|
-
/** 建群 / 拉人 / 换自己的头像 */
|
|
830
|
-
const createGroup = async () => {
|
|
831
|
-
let name = ''
|
|
832
|
-
try {
|
|
833
|
-
name = (window.prompt('群名?') || '').trim()
|
|
834
|
-
} catch (e) {
|
|
835
|
-
name = ''
|
|
836
|
-
}
|
|
837
|
-
if (!name) return
|
|
838
|
-
setErr('')
|
|
839
|
-
try {
|
|
840
|
-
const r = await api(auth.server, '/api/groups', {
|
|
841
|
-
method: 'POST',
|
|
842
|
-
token: auth.token,
|
|
843
|
-
body: { name },
|
|
844
|
-
})
|
|
845
|
-
await loadFriends()
|
|
846
|
-
setActive('g:' + r.group.id)
|
|
847
|
-
cursorRef.current = 0
|
|
848
|
-
setMessages([])
|
|
849
|
-
} catch (e) {
|
|
850
|
-
setErr(friendly(e))
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
const addMember = async () => {
|
|
855
|
-
if (!active || active.indexOf('g:') !== 0) return
|
|
856
|
-
let id = ''
|
|
857
|
-
try {
|
|
858
|
-
id = (window.prompt('把谁的 ID 拉进群?') || '').trim()
|
|
859
|
-
} catch (e) {
|
|
860
|
-
id = ''
|
|
861
|
-
}
|
|
862
|
-
if (!id) return
|
|
863
|
-
setErr('')
|
|
864
|
-
try {
|
|
865
|
-
await api(auth.server, '/api/groups/' + active.slice(2) + '/members', {
|
|
866
|
-
method: 'POST',
|
|
867
|
-
token: auth.token,
|
|
868
|
-
body: { id },
|
|
869
|
-
})
|
|
870
|
-
await loadFriends()
|
|
871
|
-
} catch (e) {
|
|
872
|
-
setErr(friendly(e))
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
const avatarInputRef = useRef(null)
|
|
877
|
-
const uploadAvatar = async (file) => {
|
|
878
|
-
if (!file) return
|
|
879
|
-
setErr('')
|
|
880
|
-
try {
|
|
881
|
-
const buf = await file.arrayBuffer()
|
|
882
|
-
const res = await fetch(auth.server + '/api/upload', {
|
|
883
|
-
method: 'POST',
|
|
884
|
-
headers: {
|
|
885
|
-
authorization: 'Bearer ' + auth.token,
|
|
886
|
-
'content-type': file.type || 'application/octet-stream',
|
|
887
|
-
'x-filename': encodeURIComponent(file.name || ''),
|
|
888
|
-
},
|
|
889
|
-
body: buf,
|
|
890
|
-
})
|
|
891
|
-
let up = null
|
|
892
|
-
try {
|
|
893
|
-
up = await res.json()
|
|
894
|
-
} catch {
|
|
895
|
-
up = null
|
|
896
|
-
}
|
|
897
|
-
if (!res.ok || !up) {
|
|
898
|
-
setErr('头像上传失败')
|
|
899
|
-
return
|
|
900
|
-
}
|
|
901
|
-
await api(auth.server, '/api/avatar', {
|
|
902
|
-
method: 'POST',
|
|
903
|
-
token: auth.token,
|
|
904
|
-
body: { uploadId: up.id },
|
|
905
|
-
})
|
|
906
|
-
setMyAvatar(up.id)
|
|
907
|
-
} catch (e) {
|
|
908
|
-
setErr(friendly(e))
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
943
|
const lastOf = (fid) => {
|
|
913
944
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
914
945
|
const m = messages[i]
|
|
@@ -925,32 +956,6 @@ window.__ModuleLoader__.load({
|
|
|
925
956
|
return String(b.text || '')
|
|
926
957
|
}
|
|
927
958
|
|
|
928
|
-
/** 会话 = 好友 + 群,统一成一种形状给侧栏和标题用 */
|
|
929
|
-
const convs = [
|
|
930
|
-
...friends.map((f) => ({
|
|
931
|
-
kind: 'dm',
|
|
932
|
-
key: f.id,
|
|
933
|
-
title: f.displayName || f.id,
|
|
934
|
-
avatar: f.avatar || '',
|
|
935
|
-
members: [],
|
|
936
|
-
})),
|
|
937
|
-
...groups.map((g) => ({
|
|
938
|
-
kind: 'group',
|
|
939
|
-
key: 'g:' + g.id,
|
|
940
|
-
title: g.name,
|
|
941
|
-
avatar: g.avatar || '',
|
|
942
|
-
members: g.members || [],
|
|
943
|
-
})),
|
|
944
|
-
]
|
|
945
|
-
const current = convs.find((c) => c.key === active) || null
|
|
946
|
-
const isGroup = !!(current && current.kind === 'group')
|
|
947
|
-
const nameOf = (id) => {
|
|
948
|
-
const mem = current && (current.members || []).find((x) => x.id === id)
|
|
949
|
-
if (mem) return mem.displayName || id
|
|
950
|
-
const dm = convs.find((c) => c.kind === 'dm' && c.key === id)
|
|
951
|
-
return dm ? dm.title : id
|
|
952
|
-
}
|
|
953
|
-
|
|
954
959
|
const thread = messages.filter((m) => m.from === active || m.to === active)
|
|
955
960
|
|
|
956
961
|
const renderMessage = (m) => {
|
|
@@ -961,21 +966,16 @@ window.__ModuleLoader__.load({
|
|
|
961
966
|
if (kind === 'snapshot') {
|
|
962
967
|
content = h(SnapshotCard, { snapshotId: b.snapshotId, auth })
|
|
963
968
|
} else if (kind === 'image') {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
)
|
|
969
|
+
content = h('img', {
|
|
970
|
+
className: 'sc-msg-img',
|
|
971
|
+
src: auth.server + b.url,
|
|
972
|
+
alt: b.caption || '图片',
|
|
973
|
+
})
|
|
970
974
|
} else if (kind === 'file') {
|
|
971
975
|
const t = String(b.type || '')
|
|
972
976
|
const src = auth.server + b.url
|
|
973
977
|
if (t.startsWith('image/')) {
|
|
974
|
-
content = h(
|
|
975
|
-
'a',
|
|
976
|
-
{ href: src + '?download=1', target: '_blank', rel: 'noreferrer', title: '点开保存' },
|
|
977
|
-
h('img', { className: 'sc-msg-img', src, alt: b.name || '图片' }),
|
|
978
|
-
)
|
|
978
|
+
content = h('img', { className: 'sc-msg-img', src, alt: b.name || '图片' })
|
|
979
979
|
} else if (t.startsWith('video/')) {
|
|
980
980
|
content = h('video', { src, controls: true, style: MEDIA_STYLE })
|
|
981
981
|
} else if (t.startsWith('audio/')) {
|
|
@@ -985,7 +985,7 @@ window.__ModuleLoader__.load({
|
|
|
985
985
|
'a',
|
|
986
986
|
{
|
|
987
987
|
className: 'sc-file',
|
|
988
|
-
href: src
|
|
988
|
+
href: src,
|
|
989
989
|
target: '_blank',
|
|
990
990
|
rel: 'noreferrer',
|
|
991
991
|
download: b.name || undefined,
|
|
@@ -995,11 +995,7 @@ window.__ModuleLoader__.load({
|
|
|
995
995
|
'span',
|
|
996
996
|
{ className: 'sc-file-main' },
|
|
997
997
|
h('span', { className: 'sc-file-name' }, b.name || '附件'),
|
|
998
|
-
h(
|
|
999
|
-
'span',
|
|
1000
|
-
{ className: 'sc-file-size' },
|
|
1001
|
-
(b.type || '未知类型') + ' · ' + kbText(b.size) + ' · 点击下载',
|
|
1002
|
-
),
|
|
998
|
+
h('span', { className: 'sc-file-size' }, (b.type || '未知类型') + ' · ' + kbText(b.size)),
|
|
1003
999
|
),
|
|
1004
1000
|
)
|
|
1005
1001
|
}
|
|
@@ -1009,9 +1005,6 @@ window.__ModuleLoader__.load({
|
|
|
1009
1005
|
return h(
|
|
1010
1006
|
'div',
|
|
1011
1007
|
{ key: m.seq, className: 'sc-msg' + (mine ? ' mine' : '') },
|
|
1012
|
-
isGroup && !mine
|
|
1013
|
-
? h('div', { className: 'sc-time', style: { marginBottom: '2px' } }, nameOf(m.from))
|
|
1014
|
-
: null,
|
|
1015
1008
|
content,
|
|
1016
1009
|
h('div', { className: 'sc-time' }, clockText(m.at)),
|
|
1017
1010
|
)
|
|
@@ -1024,31 +1017,11 @@ window.__ModuleLoader__.load({
|
|
|
1024
1017
|
h(
|
|
1025
1018
|
'div',
|
|
1026
1019
|
{ className: 'sc-chat-head' },
|
|
1027
|
-
|
|
1028
|
-
h('input', {
|
|
1029
|
-
ref: avatarInputRef,
|
|
1030
|
-
type: 'file',
|
|
1031
|
-
accept: 'image/*',
|
|
1032
|
-
style: { display: 'none' },
|
|
1033
|
-
onChange: (e) => {
|
|
1034
|
-
const f = e.target.files && e.target.files[0]
|
|
1035
|
-
if (f) uploadAvatar(f)
|
|
1036
|
-
e.target.value = ''
|
|
1037
|
-
},
|
|
1038
|
-
}),
|
|
1020
|
+
h(Character, { id: auth.id, ch: readMyCharacter(), size: 30 }),
|
|
1039
1021
|
h(
|
|
1040
1022
|
'div',
|
|
1041
1023
|
{ style: { minWidth: 0 } },
|
|
1042
|
-
h(
|
|
1043
|
-
'div',
|
|
1044
|
-
{
|
|
1045
|
-
className: 'sc-chat-name',
|
|
1046
|
-
style: { cursor: 'pointer' },
|
|
1047
|
-
title: '点一下换我的头像',
|
|
1048
|
-
onClick: () => avatarInputRef.current && avatarInputRef.current.click(),
|
|
1049
|
-
},
|
|
1050
|
-
'@' + (auth.displayName || auth.id),
|
|
1051
|
-
),
|
|
1024
|
+
h('div', { className: 'sc-chat-name' }, '@' + (auth.displayName || auth.id)),
|
|
1052
1025
|
h('div', { className: 'sc-chat-sub' }, auth.server.replace(/^https?:\/\//, '')),
|
|
1053
1026
|
),
|
|
1054
1027
|
h('span', { className: 'sc-grow' }),
|
|
@@ -1062,6 +1035,15 @@ window.__ModuleLoader__.load({
|
|
|
1062
1035
|
err,
|
|
1063
1036
|
)
|
|
1064
1037
|
: null,
|
|
1038
|
+
h(
|
|
1039
|
+
'button',
|
|
1040
|
+
{
|
|
1041
|
+
className: 'sc-btn' + (campMode ? ' sc-btn-primary' : ''),
|
|
1042
|
+
onClick: () => setCampMode((v) => !v),
|
|
1043
|
+
title: '串门:看看好友的营地',
|
|
1044
|
+
},
|
|
1045
|
+
campMode ? '💬 会话' : '🏕 串门',
|
|
1046
|
+
),
|
|
1065
1047
|
h(
|
|
1066
1048
|
'button',
|
|
1067
1049
|
{
|
|
@@ -1075,13 +1057,15 @@ window.__ModuleLoader__.load({
|
|
|
1075
1057
|
h('button', { className: 'sc-btn sc-btn-ghost', onClick: props.onLogout }, '退出'),
|
|
1076
1058
|
),
|
|
1077
1059
|
/* 主体 */
|
|
1078
|
-
|
|
1060
|
+
campMode
|
|
1061
|
+
? h(CampPanel, { auth })
|
|
1062
|
+
: h(
|
|
1079
1063
|
'div',
|
|
1080
1064
|
{ className: 'sc-chat-body' },
|
|
1081
1065
|
h(
|
|
1082
1066
|
'div',
|
|
1083
1067
|
{ className: 'sc-side' },
|
|
1084
|
-
h('div', { className: 'sc-side-title' }, '
|
|
1068
|
+
h('div', { className: 'sc-side-title' }, '好友'),
|
|
1085
1069
|
h(
|
|
1086
1070
|
'div',
|
|
1087
1071
|
{ className: 'sc-add' },
|
|
@@ -1095,40 +1079,27 @@ window.__ModuleLoader__.load({
|
|
|
1095
1079
|
},
|
|
1096
1080
|
}),
|
|
1097
1081
|
h('button', { className: 'sc-btn sc-btn-sm', onClick: addFriend }, '添加'),
|
|
1098
|
-
h('button', { className: 'sc-btn sc-btn-sm', onClick: createGroup, title: '建一个群' }, '建群'),
|
|
1099
1082
|
),
|
|
1100
1083
|
h(
|
|
1101
1084
|
'div',
|
|
1102
1085
|
{ className: 'sc-friends' },
|
|
1103
|
-
|
|
1104
|
-
? emptyState('👥', '
|
|
1105
|
-
:
|
|
1086
|
+
friends.length === 0
|
|
1087
|
+
? emptyState('👥', '还没有好友', '在上面输入对方 ID 加一个')
|
|
1088
|
+
: friends.map((f) =>
|
|
1106
1089
|
h(
|
|
1107
1090
|
'div',
|
|
1108
1091
|
{
|
|
1109
|
-
key:
|
|
1110
|
-
className: 'sc-friend' + (active ===
|
|
1111
|
-
onClick: () =>
|
|
1112
|
-
|
|
1113
|
-
cursorRef.current = 0
|
|
1114
|
-
setMessages([])
|
|
1115
|
-
},
|
|
1116
|
-
title: c.key,
|
|
1092
|
+
key: f.id,
|
|
1093
|
+
className: 'sc-friend' + (active === f.id ? ' on' : ''),
|
|
1094
|
+
onClick: () => setActive(f.id),
|
|
1095
|
+
title: f.id,
|
|
1117
1096
|
},
|
|
1118
|
-
|
|
1097
|
+
h(Character, { id: f.id, size: 30 }),
|
|
1119
1098
|
h(
|
|
1120
1099
|
'div',
|
|
1121
1100
|
{ className: 'sc-friend-main' },
|
|
1122
|
-
h(
|
|
1123
|
-
|
|
1124
|
-
{ className: 'sc-friend-name' },
|
|
1125
|
-
c.title + (c.kind === 'group' ? ' (' + c.members.length + ')' : ''),
|
|
1126
|
-
),
|
|
1127
|
-
h(
|
|
1128
|
-
'div',
|
|
1129
|
-
{ className: 'sc-friend-last' },
|
|
1130
|
-
previewOf(lastOf(c.key)) || '还没有消息',
|
|
1131
|
-
),
|
|
1101
|
+
h('div', { className: 'sc-friend-name' }, f.displayName || f.id),
|
|
1102
|
+
h('div', { className: 'sc-friend-last' }, previewOf(lastOf(f.id)) || '还没有消息'),
|
|
1132
1103
|
),
|
|
1133
1104
|
),
|
|
1134
1105
|
),
|
|
@@ -1137,33 +1108,6 @@ window.__ModuleLoader__.load({
|
|
|
1137
1108
|
h(
|
|
1138
1109
|
'div',
|
|
1139
1110
|
{ className: 'sc-main' },
|
|
1140
|
-
current
|
|
1141
|
-
? h(
|
|
1142
|
-
'div',
|
|
1143
|
-
{
|
|
1144
|
-
className: 'sc-side-title',
|
|
1145
|
-
style: {
|
|
1146
|
-
padding: '10px 14px 4px',
|
|
1147
|
-
display: 'flex',
|
|
1148
|
-
alignItems: 'center',
|
|
1149
|
-
gap: '8px',
|
|
1150
|
-
},
|
|
1151
|
-
},
|
|
1152
|
-
h(
|
|
1153
|
-
'span',
|
|
1154
|
-
null,
|
|
1155
|
-
current.title + (isGroup ? ' · ' + current.members.length + ' 人' : ''),
|
|
1156
|
-
),
|
|
1157
|
-
h('span', { className: 'sc-grow' }),
|
|
1158
|
-
isGroup
|
|
1159
|
-
? h(
|
|
1160
|
-
'button',
|
|
1161
|
-
{ className: 'sc-btn sc-btn-sm', onClick: addMember, title: '拉人进群' },
|
|
1162
|
-
'+人',
|
|
1163
|
-
)
|
|
1164
|
-
: null,
|
|
1165
|
-
)
|
|
1166
|
-
: null,
|
|
1167
1111
|
h(
|
|
1168
1112
|
'div',
|
|
1169
1113
|
{ className: 'sc-thread', ref: listRef },
|
|
@@ -1572,120 +1516,2134 @@ window.__ModuleLoader__.load({
|
|
|
1572
1516
|
)
|
|
1573
1517
|
}
|
|
1574
1518
|
|
|
1575
|
-
// ─────────────────────────
|
|
1519
|
+
// ───────────────────────── 串门(营地 P1:只读) ─────────────────────────
|
|
1520
|
+
|
|
1521
|
+
// ───────────────────────── 3D 渲染引擎(WebGL,无依赖) ─────────────────────────
|
|
1576
1522
|
|
|
1577
1523
|
/**
|
|
1578
|
-
*
|
|
1579
|
-
*
|
|
1524
|
+
* 迷你 3D:球面头部按参数变形 + 平面投影脸部贴图 + 卡通分层光照 + 反向外扩描边。
|
|
1525
|
+
* 只画到编辑器的大画布里;小头像仍走 SVG,避免几十个 WebGL 上下文。
|
|
1580
1526
|
*/
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1527
|
+
function createFace3D(canvas, getFace, getAngle) {
|
|
1528
|
+
const gl = canvas.getContext('webgl', { antialias: true, alpha: true, premultipliedAlpha: false })
|
|
1529
|
+
if (!gl) return null
|
|
1530
|
+
|
|
1531
|
+
const K = 0.62, Y0 = 0.02, TEX = 1024
|
|
1532
|
+
const px = (x) => (0.5 + x * K) * TEX
|
|
1533
|
+
const py = (y) => (0.5 - (y - Y0) * K) * TEX
|
|
1534
|
+
const ps = (v) => v * K * TEX
|
|
1535
|
+
|
|
1536
|
+
const mat4 = {
|
|
1537
|
+
perspective(fovy, aspect, near, far) {
|
|
1538
|
+
const f = 1 / Math.tan(fovy / 2), nf = 1 / (near - far)
|
|
1539
|
+
return [f / aspect,0,0,0, 0,f,0,0, 0,0,(far + near) * nf,-1, 0,0,2 * far * near * nf,0]
|
|
1540
|
+
},
|
|
1541
|
+
lookAt(eye, target, up) {
|
|
1542
|
+
const sub = (a, b) => [a[0]-b[0], a[1]-b[1], a[2]-b[2]]
|
|
1543
|
+
const dot = (a, b) => a[0]*b[0]+a[1]*b[1]+a[2]*b[2]
|
|
1544
|
+
const cross = (a, b) => [a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0]]
|
|
1545
|
+
const norm = (v) => { const l = Math.hypot(v[0],v[1],v[2]) || 1; return [v[0]/l, v[1]/l, v[2]/l] }
|
|
1546
|
+
const z = norm(sub(eye, target)), x = norm(cross(up, z)), y = cross(z, x)
|
|
1547
|
+
return [x[0],y[0],z[0],0, x[1],y[1],z[1],0, x[2],y[2],z[2],0, -dot(x,eye), -dot(y,eye), -dot(z,eye), 1]
|
|
1548
|
+
},
|
|
1549
|
+
rotY(a) { const c = Math.cos(a), s = Math.sin(a); return [c,0,-s,0, 0,1,0,0, s,0,c,0, 0,0,0,1] },
|
|
1550
|
+
mul(a, b) {
|
|
1551
|
+
const o = new Array(16)
|
|
1552
|
+
for (let i = 0; i < 4; i++) for (let j = 0; j < 4; j++) {
|
|
1553
|
+
let v = 0
|
|
1554
|
+
for (let k = 0; k < 4; k++) v += a[k * 4 + j] * b[i * 4 + k]
|
|
1555
|
+
o[i * 4 + j] = v
|
|
1556
|
+
}
|
|
1557
|
+
return o
|
|
1558
|
+
},
|
|
1559
|
+
}
|
|
1585
1560
|
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1561
|
+
function compile(type, src) {
|
|
1562
|
+
const sh = gl.createShader(type)
|
|
1563
|
+
gl.shaderSource(sh, src); gl.compileShader(sh)
|
|
1564
|
+
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(sh))
|
|
1565
|
+
return sh
|
|
1566
|
+
}
|
|
1567
|
+
function program(vs, fs) {
|
|
1568
|
+
const p = gl.createProgram()
|
|
1569
|
+
gl.attachShader(p, compile(gl.VERTEX_SHADER, vs))
|
|
1570
|
+
gl.attachShader(p, compile(gl.FRAGMENT_SHADER, fs))
|
|
1571
|
+
gl.linkProgram(p)
|
|
1572
|
+
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p))
|
|
1573
|
+
return p
|
|
1574
|
+
}
|
|
1589
1575
|
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1576
|
+
const TOON_VS = [
|
|
1577
|
+
'attribute vec3 aPos; attribute vec3 aNormal; attribute vec2 aUV;',
|
|
1578
|
+
'uniform mat4 uMVP; uniform mat4 uModel;',
|
|
1579
|
+
'varying vec3 vN; varying vec2 vUV;',
|
|
1580
|
+
'void main(){ vN = normalize(mat3(uModel) * aNormal); vUV = aUV; gl_Position = uMVP * vec4(aPos,1.0); }',
|
|
1581
|
+
].join('\n')
|
|
1582
|
+
const TOON_FS = [
|
|
1583
|
+
'precision mediump float;',
|
|
1584
|
+
'varying vec3 vN; varying vec2 vUV;',
|
|
1585
|
+
'uniform vec3 uColor; uniform vec3 uRim; uniform vec3 uLight;',
|
|
1586
|
+
'uniform sampler2D uTex; uniform float uUseTex;',
|
|
1587
|
+
'void main(){',
|
|
1588
|
+
' vec3 n = normalize(vN); vec3 l = normalize(uLight);',
|
|
1589
|
+
' float d = dot(n, l);',
|
|
1590
|
+
' float band = d > 0.55 ? 1.0 : (d > 0.05 ? 0.8 : (d > -0.35 ? 0.62 : 0.48));',
|
|
1591
|
+
' vec3 v = normalize(vec3(0.0,0.15,1.0));',
|
|
1592
|
+
' float rim = pow(1.0 - max(dot(n, v), 0.0), 2.2);',
|
|
1593
|
+
' vec4 tex = texture2D(uTex, vUV);',
|
|
1594
|
+
' vec3 base = mix(uColor, tex.rgb, tex.a * uUseTex);',
|
|
1595
|
+
' gl_FragColor = vec4(base * band + uRim * rim * 0.5, 1.0);',
|
|
1596
|
+
'}',
|
|
1597
|
+
].join('\n')
|
|
1598
|
+
const OUT_VS = [
|
|
1599
|
+
'attribute vec3 aPos; attribute vec3 aNormal;',
|
|
1600
|
+
'uniform mat4 uMVP; uniform float uThick;',
|
|
1601
|
+
'void main(){ gl_Position = uMVP * vec4(aPos + aNormal * uThick, 1.0); }',
|
|
1602
|
+
].join('\n')
|
|
1603
|
+
const OUT_FS = 'precision mediump float; uniform vec3 uColor; void main(){ gl_FragColor = vec4(uColor,1.0); }'
|
|
1604
|
+
|
|
1605
|
+
let progToon, progOut
|
|
1606
|
+
try {
|
|
1607
|
+
progToon = program(TOON_VS, TOON_FS)
|
|
1608
|
+
progOut = program(OUT_VS, OUT_FS)
|
|
1609
|
+
} catch (e) {
|
|
1610
|
+
return null
|
|
1611
|
+
}
|
|
1612
|
+
const lt = (p, n) => gl.getUniformLocation(p, n)
|
|
1613
|
+
const at = (p, n) => gl.getAttribLocation(p, n)
|
|
1614
|
+
|
|
1615
|
+
function sphere(seg, rings) {
|
|
1616
|
+
const pos = [], nrm = [], uv = [], idx = []
|
|
1617
|
+
for (let y = 0; y <= rings; y++) {
|
|
1618
|
+
const v = y / rings, phi = v * Math.PI
|
|
1619
|
+
for (let x = 0; x <= seg; x++) {
|
|
1620
|
+
const u = x / seg, th = u * Math.PI * 2
|
|
1621
|
+
const sx = Math.sin(phi) * Math.sin(th), sy = Math.cos(phi), sz = Math.sin(phi) * Math.cos(th)
|
|
1622
|
+
pos.push(sx, sy, sz); nrm.push(sx, sy, sz); uv.push(0.5 + sx * K, 0.5 - (sy - Y0) * K)
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
for (let yy = 0; yy < rings; yy++) for (let xx = 0; xx < seg; xx++) {
|
|
1626
|
+
const a = yy * (seg + 1) + xx, b = a + 1, c = a + seg + 1, d = c + 1
|
|
1627
|
+
idx.push(a, c, b, b, c, d)
|
|
1628
|
+
}
|
|
1629
|
+
return { pos, nrm, uv, idx }
|
|
1593
1630
|
}
|
|
1594
1631
|
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
const pcs = new Map() // remotePeerId -> { pc, el, name, pending: [] }
|
|
1605
|
-
const peers = new Map() // remotePeerId -> { id, name, muted, cam, sharing }
|
|
1632
|
+
function vbo(mesh) {
|
|
1633
|
+
const o = {}
|
|
1634
|
+
o.pos = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, o.pos); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(mesh.pos), gl.STATIC_DRAW)
|
|
1635
|
+
o.nrm = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, o.nrm); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(mesh.nrm), gl.STATIC_DRAW)
|
|
1636
|
+
o.uvb = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, o.uvb); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(mesh.uv), gl.STATIC_DRAW)
|
|
1637
|
+
o.idx = gl.createBuffer(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, o.idx); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(mesh.idx), gl.STATIC_DRAW)
|
|
1638
|
+
o.count = mesh.idx.length
|
|
1639
|
+
return o
|
|
1640
|
+
}
|
|
1606
1641
|
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1642
|
+
function buildHead(f) {
|
|
1643
|
+
const m = sphere(64, 40)
|
|
1644
|
+
for (let i = 0; i < m.pos.length; i += 3) {
|
|
1645
|
+
let x = m.pos[i], y = m.pos[i + 1], z = m.pos[i + 2]
|
|
1646
|
+
const sx = 1 + f.faceWidth * 0.0016
|
|
1647
|
+
const jaw = 1 - f.jaw * 0.0022 * (y < 0 ? -y : 0)
|
|
1648
|
+
const chin = 1 + f.chin * 0.0012 * (y < -0.3 ? 1 : 0)
|
|
1649
|
+
const fore = 1 + f.forehead * 0.0012 * (y > 0.4 ? 1 : 0)
|
|
1650
|
+
const cheek = 1 + f.cheek * 0.0012 * (Math.abs(y) < 0.35 ? 1 : 0)
|
|
1651
|
+
x *= sx * jaw * cheek
|
|
1652
|
+
z *= sx * jaw * cheek * (1 + f.noseLength * 0.0008 * (z > 0.75 ? 1 : 0))
|
|
1653
|
+
y *= chin * fore
|
|
1654
|
+
if (y > 0.78) y = 0.78 + (y - 0.78) * 0.8
|
|
1655
|
+
m.pos[i] = x; m.pos[i + 1] = y; m.pos[i + 2] = z
|
|
1656
|
+
const l = Math.hypot(x, y, z) || 1
|
|
1657
|
+
m.nrm[i] = x / l; m.nrm[i + 1] = y / l; m.nrm[i + 2] = z / l
|
|
1658
|
+
m.uv[i / 3 * 2] = 0.5 + x * K
|
|
1659
|
+
m.uv[i / 3 * 2 + 1] = 0.5 - (y - Y0) * K
|
|
1660
|
+
}
|
|
1661
|
+
return m
|
|
1662
|
+
}
|
|
1619
1663
|
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1664
|
+
function buildHair() {
|
|
1665
|
+
const m = sphere(56, 36)
|
|
1666
|
+
const keep = new Uint8Array(m.pos.length / 3)
|
|
1667
|
+
for (let i = 0; i < m.pos.length; i += 3) {
|
|
1668
|
+
const x = m.pos[i], y = m.pos[i + 1], z = m.pos[i + 2]
|
|
1669
|
+
const r = 1.09 + Math.max(0, -y) * 0.05
|
|
1670
|
+
m.pos[i] = x * r; m.pos[i + 1] = y * r; m.pos[i + 2] = z * r
|
|
1671
|
+
const l = Math.hypot(m.pos[i], m.pos[i + 1], m.pos[i + 2]) || 1
|
|
1672
|
+
m.nrm[i] = m.pos[i] / l; m.nrm[i + 1] = m.pos[i + 1] / l; m.nrm[i + 2] = m.pos[i + 2] / l
|
|
1673
|
+
const front = z > 0.15
|
|
1674
|
+
const hairline = front ? 0.24 + 0.07 * Math.cos(x * 9) - Math.abs(x) * 0.06 : 0.02
|
|
1675
|
+
keep[i / 3] = y > hairline || z < -0.25 ? 1 : 0
|
|
1676
|
+
}
|
|
1677
|
+
const idx = []
|
|
1678
|
+
for (let k = 0; k < m.idx.length; k += 3) {
|
|
1679
|
+
const a = m.idx[k], b = m.idx[k + 1], c = m.idx[k + 2]
|
|
1680
|
+
if (keep[a] && keep[b] && keep[c]) idx.push(a, b, c)
|
|
1681
|
+
}
|
|
1682
|
+
m.idx = idx
|
|
1683
|
+
return m
|
|
1684
|
+
}
|
|
1635
1685
|
|
|
1636
|
-
|
|
1637
|
-
|
|
1686
|
+
function buildFringe() {
|
|
1687
|
+
const m = sphere(96, 32)
|
|
1688
|
+
const keep = new Uint8Array(m.pos.length / 3)
|
|
1689
|
+
for (let i = 0; i < m.pos.length; i += 3) {
|
|
1690
|
+
const x = m.pos[i], y = m.pos[i + 1], z = m.pos[i + 2]
|
|
1691
|
+
const r = 1.13
|
|
1692
|
+
m.pos[i] = x * r; m.pos[i + 1] = y * r; m.pos[i + 2] = z * r
|
|
1693
|
+
const l = Math.hypot(m.pos[i], m.pos[i + 1], m.pos[i + 2]) || 1
|
|
1694
|
+
m.nrm[i] = m.pos[i] / l; m.nrm[i + 1] = m.pos[i + 1] / l; m.nrm[i + 2] = m.pos[i + 2] / l
|
|
1695
|
+
const ang = Math.atan2(x, z)
|
|
1696
|
+
const strand = Math.sin(ang * 7 + 0.6)
|
|
1697
|
+
keep[i / 3] = z > 0.28 && y < 0.62 && y > 0.16 + Math.abs(x) * 0.04 && strand > -0.2 ? 1 : 0
|
|
1698
|
+
}
|
|
1699
|
+
const idx = []
|
|
1700
|
+
for (let k = 0; k < m.idx.length; k += 3) {
|
|
1701
|
+
const a = m.idx[k], b = m.idx[k + 1], c = m.idx[k + 2]
|
|
1702
|
+
if (keep[a] && keep[b] && keep[c]) idx.push(a, b, c)
|
|
1703
|
+
}
|
|
1704
|
+
m.idx = idx
|
|
1705
|
+
return m
|
|
1706
|
+
}
|
|
1638
1707
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1708
|
+
function buildPart(scaleX, scaleY, scaleZ, dy, sx, sy) {
|
|
1709
|
+
const m = sphere(sx || 24, sy || 18)
|
|
1710
|
+
for (let i = 0; i < m.pos.length; i += 3) {
|
|
1711
|
+
m.pos[i] *= scaleX
|
|
1712
|
+
m.pos[i + 1] = m.pos[i + 1] * scaleY + dy
|
|
1713
|
+
m.pos[i + 2] *= scaleZ
|
|
1714
|
+
const l = Math.hypot(m.pos[i] / scaleX, (m.pos[i + 1] - dy) / scaleY, m.pos[i + 2] / scaleZ) || 1
|
|
1715
|
+
m.nrm[i] = m.pos[i] / scaleX / l
|
|
1716
|
+
m.nrm[i + 1] = (m.pos[i + 1] - dy) / scaleY / l
|
|
1717
|
+
m.nrm[i + 2] = m.pos[i + 2] / scaleZ / l
|
|
1718
|
+
}
|
|
1719
|
+
return m
|
|
1720
|
+
}
|
|
1642
1721
|
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1722
|
+
function sideLock(side) {
|
|
1723
|
+
const m = sphere(16, 20)
|
|
1724
|
+
for (let i = 0; i < m.pos.length; i += 3) {
|
|
1725
|
+
m.pos[i] = m.pos[i] * 0.1 + side * 0.84
|
|
1726
|
+
m.pos[i + 1] = m.pos[i + 1] * 0.62 - 0.1
|
|
1727
|
+
m.pos[i + 2] = m.pos[i + 2] * 0.12 + 0.42
|
|
1728
|
+
const l = Math.hypot((m.pos[i] - side * 0.84) / 0.1, (m.pos[i + 1] + 0.1) / 0.62, (m.pos[i + 2] - 0.42) / 0.12) || 1
|
|
1729
|
+
m.nrm[i] = (m.pos[i] - side * 0.84) / 0.1 / l
|
|
1730
|
+
m.nrm[i + 1] = (m.pos[i + 1] + 0.1) / 0.62 / l
|
|
1731
|
+
m.nrm[i + 2] = (m.pos[i + 2] - 0.42) / 0.12 / l
|
|
1732
|
+
}
|
|
1733
|
+
return m
|
|
1734
|
+
}
|
|
1646
1735
|
|
|
1647
|
-
|
|
1648
|
-
|
|
1736
|
+
function faceTexture(f) {
|
|
1737
|
+
const c = document.createElement('canvas')
|
|
1738
|
+
c.width = TEX; c.height = TEX
|
|
1739
|
+
const g = c.getContext('2d')
|
|
1740
|
+
const hairHex = C_HAIR[f.hairColor % C_HAIR.length]
|
|
1741
|
+
const skinHex = F_SKIN[f.skinTone]
|
|
1742
|
+
const eyeY = 0 + f.eyeHeight * 0.0006
|
|
1743
|
+
const eyeX = 0.24 + f.eyeSpacing * 0.0011
|
|
1744
|
+
const erx = 0.115 * (1 + f.eyeSize * 0.005)
|
|
1745
|
+
const ery = 0.14 * (1 + f.eyeSize * 0.005)
|
|
1746
|
+
const tilt = f.eyeTilt * 0.0018
|
|
1747
|
+
|
|
1748
|
+
const bA = Math.min(1, Math.max(0, f.blush / 100)) * 0.45
|
|
1749
|
+
if (bA > 0.01) {
|
|
1750
|
+
;[-1, 1].forEach((sd) => {
|
|
1751
|
+
const cx = px(sd * (eyeX + erx * 0.35)), cy = py(eyeY - 0.22), rad = ps(erx * 1.5)
|
|
1752
|
+
const grd = g.createRadialGradient(cx, cy, 2, cx, cy, rad)
|
|
1753
|
+
grd.addColorStop(0, 'rgba(255,140,155,' + bA + ')')
|
|
1754
|
+
grd.addColorStop(1, 'rgba(255,140,155,0)')
|
|
1755
|
+
g.fillStyle = grd
|
|
1756
|
+
g.beginPath(); g.arc(cx, cy, rad, 0, 7); g.fill()
|
|
1757
|
+
})
|
|
1758
|
+
}
|
|
1759
|
+
;[-1, 1].forEach((sd) => {
|
|
1760
|
+
g.save()
|
|
1761
|
+
g.translate(px(sd * eyeX), py(eyeY))
|
|
1762
|
+
g.rotate(sd * tilt)
|
|
1763
|
+
const rx = ps(erx), ry = ps(ery)
|
|
1764
|
+
g.beginPath(); g.ellipse(0, 0, rx, ry, 0, 0, 7); g.fillStyle = '#fbfdff'; g.fill()
|
|
1765
|
+
const cg = g.createRadialGradient(-rx * 0.2, -ry * 0.28, rx * 0.1, 0, 0, rx * 1.05)
|
|
1766
|
+
cg.addColorStop(0, '#8fb6ff'); cg.addColorStop(0.55, '#4a63b0'); cg.addColorStop(1, '#2b3a72')
|
|
1767
|
+
g.beginPath(); g.ellipse(0, ry * 0.06, rx * 0.68, ry * 0.72, 0, 0, 7); g.fillStyle = cg; g.fill()
|
|
1768
|
+
g.beginPath(); g.ellipse(0, ry * 0.08, rx * 0.34, ry * 0.4, 0, 0, 7); g.fillStyle = '#151a2c'; g.fill()
|
|
1769
|
+
g.beginPath(); g.ellipse(-rx * 0.3, -ry * 0.34, rx * 0.22, ry * 0.18, 0, 0, 7); g.fillStyle = '#ffffff'; g.fill()
|
|
1770
|
+
g.beginPath(); g.arc(rx * 0.3, ry * 0.36, rx * 0.12, 0, 7); g.fillStyle = 'rgba(255,255,255,.92)'; g.fill()
|
|
1771
|
+
g.beginPath(); g.ellipse(0, 0, rx * 1.02, ry * 1.02, 0, Math.PI * 0.92, Math.PI * 2.08)
|
|
1772
|
+
g.strokeStyle = '#232946'; g.lineWidth = rx * 0.3; g.lineCap = 'round'; g.stroke()
|
|
1773
|
+
g.restore()
|
|
1774
|
+
})
|
|
1775
|
+
g.strokeStyle = hairHex
|
|
1776
|
+
g.lineWidth = ps(0.022); g.lineCap = 'round'
|
|
1777
|
+
;[-1, 1].forEach((sd) => {
|
|
1778
|
+
g.beginPath()
|
|
1779
|
+
g.moveTo(px(sd * (eyeX + erx * 1.15)), py(eyeY + 0.2))
|
|
1780
|
+
g.quadraticCurveTo(px(sd * eyeX), py(eyeY + 0.26 + f.browArch * 0.0008), px(sd * (eyeX - erx * 1.05)), py(eyeY + 0.19))
|
|
1781
|
+
g.stroke()
|
|
1782
|
+
})
|
|
1783
|
+
g.fillStyle = 'rgba(150,95,80,.45)'
|
|
1784
|
+
g.beginPath(); g.ellipse(px(0), py(-0.16), ps(0.012), ps(0.009), 0, 0, 7); g.fill()
|
|
1785
|
+
const smile = f.mouthSmile * 0.0016
|
|
1786
|
+
g.strokeStyle = '#b8564f'; g.lineWidth = ps(0.02); g.lineCap = 'round'
|
|
1787
|
+
g.beginPath()
|
|
1788
|
+
g.moveTo(px(-0.08), py(-0.3))
|
|
1789
|
+
g.quadraticCurveTo(px(0), py(-0.3 - 0.05 - smile), px(0.08), py(-0.3))
|
|
1790
|
+
g.stroke()
|
|
1791
|
+
|
|
1792
|
+
const t = gl.createTexture()
|
|
1793
|
+
gl.bindTexture(gl.TEXTURE_2D, t)
|
|
1794
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false)
|
|
1795
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c)
|
|
1796
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
|
|
1797
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
|
1798
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
|
1799
|
+
return t
|
|
1800
|
+
}
|
|
1649
1801
|
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1802
|
+
let meshes = null
|
|
1803
|
+
let tex = null
|
|
1804
|
+
let sig = ''
|
|
1805
|
+
|
|
1806
|
+
function rebuild(f) {
|
|
1807
|
+
const next = JSON.stringify([f.faceWidth, f.jaw, f.cheek, f.chin, f.forehead, f.noseLength, f.eyeSize, f.eyeSpacing, f.eyeTilt, f.eyeHeight, f.mouthSmile, f.blush, f.hairColor, f.skinTone, f.browArch])
|
|
1808
|
+
if (next === sig && meshes) return
|
|
1809
|
+
sig = next
|
|
1810
|
+
if (meshes) {
|
|
1811
|
+
for (const k of Object.keys(meshes)) {
|
|
1812
|
+
const m = meshes[k]
|
|
1813
|
+
if (m && m.pos) { gl.deleteBuffer(m.pos); gl.deleteBuffer(m.nrm); gl.deleteBuffer(m.uvb); gl.deleteBuffer(m.idx) }
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
meshes = {
|
|
1817
|
+
head: vbo(buildHead(f)),
|
|
1818
|
+
hair: vbo(buildHair(f)),
|
|
1819
|
+
fringe: vbo(buildFringe(f)),
|
|
1820
|
+
body: vbo(buildPart(1.12, 0.58, 0.78, -1.36)),
|
|
1821
|
+
neck: vbo(buildPart(0.26, 0.42, 0.26, -1.06)),
|
|
1822
|
+
lockL: vbo(sideLock(-1)),
|
|
1823
|
+
lockR: vbo(sideLock(1)),
|
|
1824
|
+
}
|
|
1825
|
+
if (tex) gl.deleteTexture(tex)
|
|
1826
|
+
tex = faceTexture(f)
|
|
1655
1827
|
}
|
|
1656
|
-
paint()
|
|
1657
1828
|
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
? 'border:0;background:#247bbf;color:#fff'
|
|
1667
|
-
: 'border:1px solid rgba(255,255,255,.22);background:rgba(255,255,255,.06);color:#eaf3f6')
|
|
1668
|
-
b.addEventListener('click', onClick)
|
|
1669
|
-
return b
|
|
1829
|
+
function drawMesh(m, prog, attrs) {
|
|
1830
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, m.pos); gl.enableVertexAttribArray(attrs.pos); gl.vertexAttribPointer(attrs.pos, 3, gl.FLOAT, false, 0, 0)
|
|
1831
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, m.nrm); gl.enableVertexAttribArray(attrs.nrm); gl.vertexAttribPointer(attrs.nrm, 3, gl.FLOAT, false, 0, 0)
|
|
1832
|
+
if (attrs.uv >= 0) {
|
|
1833
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, m.uvb); gl.enableVertexAttribArray(attrs.uv); gl.vertexAttribPointer(attrs.uv, 2, gl.FLOAT, false, 0, 0)
|
|
1834
|
+
}
|
|
1835
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, m.idx)
|
|
1836
|
+
gl.drawElements(gl.TRIANGLES, m.count, gl.UNSIGNED_SHORT, 0)
|
|
1670
1837
|
}
|
|
1671
1838
|
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1839
|
+
const A = {
|
|
1840
|
+
pos: at(progToon, 'aPos'), nrm: at(progToon, 'aNormal'), uv: at(progToon, 'aUV'),
|
|
1841
|
+
mvp: lt(progToon, 'uMVP'), model: lt(progToon, 'uModel'), color: lt(progToon, 'uColor'),
|
|
1842
|
+
rim: lt(progToon, 'uRim'), light: lt(progToon, 'uLight'), tex: lt(progToon, 'uTex'), useTex: lt(progToon, 'uUseTex'),
|
|
1843
|
+
}
|
|
1844
|
+
const O = {
|
|
1845
|
+
pos: at(progOut, 'aPos'), nrm: at(progOut, 'aNormal'), mvp: lt(progOut, 'uMVP'), thick: lt(progOut, 'uThick'), color: lt(progOut, 'uColor'),
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function render() {
|
|
1849
|
+
const f = getFace()
|
|
1850
|
+
rebuild(f)
|
|
1851
|
+
const w = canvas.width, h = canvas.height
|
|
1852
|
+
gl.viewport(0, 0, w, h)
|
|
1853
|
+
gl.clearColor(0, 0, 0, 0)
|
|
1854
|
+
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
|
|
1855
|
+
gl.enable(gl.DEPTH_TEST)
|
|
1856
|
+
gl.enable(gl.CULL_FACE)
|
|
1857
|
+
|
|
1858
|
+
const proj = mat4.perspective(Math.PI / 5, w / h, 0.1, 100)
|
|
1859
|
+
const view = mat4.lookAt([0, 0.2, 5.2], [0, -0.5, 0], [0, 1, 0])
|
|
1860
|
+
const model = mat4.rotY(((getAngle() || 0) * Math.PI) / 180)
|
|
1861
|
+
const mvp = mat4.mul(proj, mat4.mul(view, model))
|
|
1862
|
+
|
|
1863
|
+
gl.cullFace(gl.FRONT)
|
|
1864
|
+
gl.useProgram(progOut)
|
|
1865
|
+
gl.uniformMatrix4fv(O.mvp, false, new Float32Array(mvp))
|
|
1866
|
+
gl.uniform3fv(O.color, new Float32Array([0.13, 0.16, 0.27]))
|
|
1867
|
+
;[[meshes.hair, 0.032], [meshes.fringe, 0.016], [meshes.lockL, 0.02], [meshes.lockR, 0.02], [meshes.body, 0.024], [meshes.neck, 0.02], [meshes.head, 0.016]].forEach((pair) => {
|
|
1868
|
+
gl.uniformMatrix4fv(O.mvp, false, new Float32Array(mvp))
|
|
1869
|
+
gl.uniform1f(O.thick, pair[1])
|
|
1870
|
+
drawMesh(pair[0], progOut, O)
|
|
1871
|
+
})
|
|
1872
|
+
|
|
1873
|
+
gl.cullFace(gl.BACK)
|
|
1874
|
+
gl.useProgram(progToon)
|
|
1875
|
+
gl.uniformMatrix4fv(A.mvp, false, new Float32Array(mvp))
|
|
1876
|
+
gl.uniformMatrix4fv(A.model, false, new Float32Array(model))
|
|
1877
|
+
gl.uniform3fv(A.light, new Float32Array([-0.35, 0.55, 0.78]))
|
|
1878
|
+
gl.uniform3fv(A.rim, new Float32Array([0.42, 0.62, 0.95]))
|
|
1879
|
+
gl.activeTexture(gl.TEXTURE0)
|
|
1880
|
+
gl.bindTexture(gl.TEXTURE_2D, tex)
|
|
1881
|
+
gl.uniform1i(A.tex, 0)
|
|
1882
|
+
|
|
1883
|
+
const drawPart = (mesh, color, useTex) => {
|
|
1884
|
+
gl.uniform3fv(A.color, new Float32Array(color))
|
|
1885
|
+
gl.uniform1f(A.useTex, useTex ? 1 : 0)
|
|
1886
|
+
drawMesh(mesh, progToon, A)
|
|
1887
|
+
}
|
|
1888
|
+
drawPart(meshes.body, [0.17, 0.22, 0.38], false)
|
|
1889
|
+
drawPart(meshes.neck, [0.99, 0.83, 0.73], false)
|
|
1890
|
+
drawPart(meshes.head, [1.0, 0.86, 0.77], true)
|
|
1891
|
+
drawPart(meshes.hair, [0.26, 0.32, 0.6], false)
|
|
1892
|
+
drawPart(meshes.fringe, [0.23, 0.28, 0.54], false)
|
|
1893
|
+
drawPart(meshes.lockL, [0.23, 0.28, 0.54], false)
|
|
1894
|
+
drawPart(meshes.lockR, [0.23, 0.28, 0.54], false)
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
let raf = 0
|
|
1898
|
+
let disposed = false
|
|
1899
|
+
function loop() {
|
|
1900
|
+
if (disposed) return
|
|
1901
|
+
try { render() } catch (e) { /* 单帧失败不致命 */ }
|
|
1902
|
+
raf = requestAnimationFrame(loop)
|
|
1903
|
+
}
|
|
1904
|
+
loop()
|
|
1905
|
+
|
|
1906
|
+
return {
|
|
1907
|
+
dispose() {
|
|
1908
|
+
disposed = true
|
|
1909
|
+
if (raf) cancelAnimationFrame(raf)
|
|
1910
|
+
},
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
/** 全屏捏脸编辑器 */
|
|
1915
|
+
function FaceEditor(props) {
|
|
1916
|
+
const [draft, setDraft] = useState(() => normalizeFace(props.initial))
|
|
1917
|
+
const [tab, setTab] = useState(0)
|
|
1918
|
+
const [angle, setAngle] = useState(0)
|
|
1919
|
+
const [spin, setSpin] = useState(false)
|
|
1920
|
+
const [history, setHistory] = useState(() => [normalizeFace(props.initial)])
|
|
1921
|
+
const [cursor, setCursor] = useState(0)
|
|
1922
|
+
const [codeOpen, setCodeOpen] = useState(false)
|
|
1923
|
+
const [codeInput, setCodeInput] = useState('')
|
|
1924
|
+
const [toast, setToast] = useState('')
|
|
1925
|
+
const stageRef = useRef(null)
|
|
1926
|
+
const canvasRef = useRef(null)
|
|
1927
|
+
const draftRef = useRef(draft)
|
|
1928
|
+
const angleRef = useRef(angle)
|
|
1929
|
+
draftRef.current = draft
|
|
1930
|
+
angleRef.current = angle
|
|
1931
|
+
const [mode, setMode] = useState('3d')
|
|
1932
|
+
const lastPush = useRef(0)
|
|
1933
|
+
|
|
1934
|
+
useEffect(() => {
|
|
1935
|
+
const onKey = (e) => {
|
|
1936
|
+
if (e.key === 'Escape') props.onClose()
|
|
1937
|
+
}
|
|
1938
|
+
window.addEventListener('keydown', onKey)
|
|
1939
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
1940
|
+
}, [props])
|
|
1941
|
+
|
|
1942
|
+
useEffect(() => {
|
|
1943
|
+
if (mode !== '3d') return
|
|
1944
|
+
const cv = canvasRef.current
|
|
1945
|
+
if (!cv) return
|
|
1946
|
+
const eng = createFace3D(cv, () => draftRef.current, () => angleRef.current)
|
|
1947
|
+
return () => {
|
|
1948
|
+
if (eng) eng.dispose()
|
|
1949
|
+
}
|
|
1950
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1951
|
+
}, [mode])
|
|
1952
|
+
|
|
1953
|
+
useEffect(() => {
|
|
1954
|
+
if (!spin) return
|
|
1955
|
+
const t = window.setInterval(() => setAngle((a) => (a + 2 > 32 ? -32 : a + 2)), 60)
|
|
1956
|
+
return () => window.clearInterval(t)
|
|
1957
|
+
}, [spin])
|
|
1958
|
+
|
|
1959
|
+
const commit = (next, pushHistory) => {
|
|
1960
|
+
const f = normalizeFace(next)
|
|
1961
|
+
setDraft(f)
|
|
1962
|
+
if (pushHistory) {
|
|
1963
|
+
const now = Date.now()
|
|
1964
|
+
if (now - lastPush.current > 350) {
|
|
1965
|
+
lastPush.current = now
|
|
1966
|
+
setHistory((h) => h.slice(0, cursor + 1).concat([f]).slice(-60))
|
|
1967
|
+
setCursor((c) => Math.min(c + 1, 59))
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
const setParam = (key, value) => commit(Object.assign({}, draft, { [key]: value }), true)
|
|
1973
|
+
|
|
1974
|
+
const undo = () => {
|
|
1975
|
+
if (cursor <= 0) return
|
|
1976
|
+
setCursor(cursor - 1)
|
|
1977
|
+
setDraft(history[cursor - 1])
|
|
1978
|
+
}
|
|
1979
|
+
const redo = () => {
|
|
1980
|
+
if (cursor >= history.length - 1) return
|
|
1981
|
+
setCursor(cursor + 1)
|
|
1982
|
+
setDraft(history[cursor + 1])
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
const activeGroup = FACE_GROUPS[tab]
|
|
1986
|
+
const renderControl = (item) => {
|
|
1987
|
+
const [key, label, def, min, max, kind] = item
|
|
1988
|
+
const value = draft[key]
|
|
1989
|
+
if (kind && kind.indexOf('palette:') === 0) {
|
|
1990
|
+
const palette = kind.slice(8) === 'F_SKIN' ? F_SKIN : kind.slice(8) === 'F_HAIR' ? F_HAIR : kind.slice(8) === 'F_EYE' ? F_EYE : F_OUTFIT
|
|
1991
|
+
return h(
|
|
1992
|
+
'div',
|
|
1993
|
+
{ className: 'sc-face-sw', key: key },
|
|
1994
|
+
h('span', { className: 'lab' }, label),
|
|
1995
|
+
h(
|
|
1996
|
+
'div',
|
|
1997
|
+
{ className: 'sc-swatches' },
|
|
1998
|
+
palette.map((color, i) =>
|
|
1999
|
+
h('button', {
|
|
2000
|
+
key: color + i,
|
|
2001
|
+
className: 'sc-swatch' + (value === i ? ' on' : ''),
|
|
2002
|
+
style: { background: color },
|
|
2003
|
+
onClick: () => setParam(key, i),
|
|
2004
|
+
title: color,
|
|
2005
|
+
}),
|
|
2006
|
+
),
|
|
2007
|
+
),
|
|
2008
|
+
)
|
|
2009
|
+
}
|
|
2010
|
+
if (kind && kind.indexOf('names:') === 0) {
|
|
2011
|
+
const names = kind.slice(6).split('|')
|
|
2012
|
+
return h(
|
|
2013
|
+
'div',
|
|
2014
|
+
{ className: 'sc-face-sw', key: key },
|
|
2015
|
+
h('span', { className: 'lab' }, label),
|
|
2016
|
+
h(
|
|
2017
|
+
'div',
|
|
2018
|
+
{ className: 'sc-seg' },
|
|
2019
|
+
names.map((n, i) =>
|
|
2020
|
+
h('button', { key: n, className: value === i ? 'on' : '', onClick: () => setParam(key, i) }, n),
|
|
2021
|
+
),
|
|
2022
|
+
),
|
|
2023
|
+
)
|
|
2024
|
+
}
|
|
2025
|
+
return h(
|
|
2026
|
+
'div',
|
|
2027
|
+
{ className: 'sc-face-row', key: key },
|
|
2028
|
+
h('span', { className: 'lab' }, label),
|
|
2029
|
+
h('input', {
|
|
2030
|
+
type: 'range',
|
|
2031
|
+
min: min,
|
|
2032
|
+
max: max,
|
|
2033
|
+
value: value,
|
|
2034
|
+
onChange: (e) => setParam(key, Number(e.target.value)),
|
|
2035
|
+
onDoubleClick: () => setParam(key, def),
|
|
2036
|
+
}),
|
|
2037
|
+
h('span', { className: 'num' }, value > 0 ? '+' + value : String(value)),
|
|
2038
|
+
)
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
const save = () => {
|
|
2042
|
+
const f = normalizeFace(draft)
|
|
2043
|
+
writeJson(K_CHARACTER, f)
|
|
2044
|
+
props.onSave(f)
|
|
2045
|
+
props.onClose()
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
return h(
|
|
2049
|
+
'div',
|
|
2050
|
+
{ className: 'sc-face-mask', onMouseDown: (e) => e.target === e.currentTarget && props.onClose() },
|
|
2051
|
+
h(
|
|
2052
|
+
'div',
|
|
2053
|
+
{ className: 'sc-face', onMouseDown: (e) => e.stopPropagation() },
|
|
2054
|
+
h(
|
|
2055
|
+
'div',
|
|
2056
|
+
{ className: 'sc-face-head' },
|
|
2057
|
+
h('span', { className: 'sc-face-title' }, '捏脸工作室'),
|
|
2058
|
+
h('span', { className: 'sc-face-meta' }, '拖动滑杆实时预览 · 双击滑杆归零'),
|
|
2059
|
+
h('span', { className: 'sc-grow' }),
|
|
2060
|
+
h(
|
|
2061
|
+
'div',
|
|
2062
|
+
{ className: 'sc-seg' },
|
|
2063
|
+
['3d', '2d'].map((m) =>
|
|
2064
|
+
h(
|
|
2065
|
+
'button',
|
|
2066
|
+
{ key: m, className: mode === m ? 'on' : '', onClick: () => setMode(m) },
|
|
2067
|
+
m === '3d' ? '3D' : '2D',
|
|
2068
|
+
),
|
|
2069
|
+
),
|
|
2070
|
+
),
|
|
2071
|
+
h(
|
|
2072
|
+
'div',
|
|
2073
|
+
{ className: 'sc-seg' },
|
|
2074
|
+
F_STYLE.map((st) =>
|
|
2075
|
+
h(
|
|
2076
|
+
'button',
|
|
2077
|
+
{
|
|
2078
|
+
key: st,
|
|
2079
|
+
className: draft.style === st ? 'on' : '',
|
|
2080
|
+
onClick: () => commit(Object.assign({}, draft, { style: st }), true),
|
|
2081
|
+
},
|
|
2082
|
+
st === 'cartoon' ? 'Q 版' : '半写实',
|
|
2083
|
+
),
|
|
2084
|
+
),
|
|
2085
|
+
),
|
|
2086
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: undo, disabled: cursor <= 0 }, '撤销'),
|
|
2087
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: redo, disabled: cursor >= history.length - 1 }, '重做'),
|
|
2088
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => commit(randomFace(draft.style), true) }, '随机'),
|
|
2089
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => commit(zeroFace(draft.style), true) }, '重置'),
|
|
2090
|
+
h('button', { className: 'sc-btn sc-btn-primary sc-btn-sm', onClick: save }, '保存'),
|
|
2091
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: props.onClose }, '关闭'),
|
|
2092
|
+
),
|
|
2093
|
+
h(
|
|
2094
|
+
'div',
|
|
2095
|
+
{ className: 'sc-face-body' },
|
|
2096
|
+
h(
|
|
2097
|
+
'div',
|
|
2098
|
+
{ className: 'sc-face-left' },
|
|
2099
|
+
h(
|
|
2100
|
+
'div',
|
|
2101
|
+
{ className: 'sc-face-stage', ref: stageRef },
|
|
2102
|
+
mode === '3d'
|
|
2103
|
+
? h('canvas', {
|
|
2104
|
+
ref: canvasRef,
|
|
2105
|
+
width: 620,
|
|
2106
|
+
height: 760,
|
|
2107
|
+
style: { height: '100%', width: 'auto', maxWidth: '100%', display: 'block' },
|
|
2108
|
+
})
|
|
2109
|
+
: h(FaceRender, { face: draft, size: 300, angle, uid: 'editor' }),
|
|
2110
|
+
),
|
|
2111
|
+
h(
|
|
2112
|
+
'div',
|
|
2113
|
+
{ style: { width: '100%', display: 'flex', alignItems: 'center', gap: '8px' } },
|
|
2114
|
+
h('span', { className: 'sc-camp-meta' }, '转台'),
|
|
2115
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => setAngle((a) => Math.max(-32, a - 6)) }, '◀'),
|
|
2116
|
+
h('input', {
|
|
2117
|
+
type: 'range',
|
|
2118
|
+
min: -32,
|
|
2119
|
+
max: 32,
|
|
2120
|
+
value: angle,
|
|
2121
|
+
style: { flex: 1, accentColor: '#247bbf' },
|
|
2122
|
+
onChange: (e) => setAngle(Number(e.target.value)),
|
|
2123
|
+
}),
|
|
2124
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => setAngle((a) => Math.min(32, a + 6)) }, '▶'),
|
|
2125
|
+
),
|
|
2126
|
+
h(
|
|
2127
|
+
'div',
|
|
2128
|
+
{ style: { display: 'flex', gap: '6px', flexWrap: 'wrap', justifyContent: 'center' } },
|
|
2129
|
+
h('button', { className: 'sc-btn sc-btn-sm' + (spin ? ' sc-btn-primary' : ''), onClick: () => setSpin((v) => !v) }, spin ? '停止转台' : '自动转台'),
|
|
2130
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => setAngle(0) }, '正面'),
|
|
2131
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => setCodeOpen((v) => !v) }, '脸码'),
|
|
2132
|
+
),
|
|
2133
|
+
codeOpen
|
|
2134
|
+
? h(
|
|
2135
|
+
'div',
|
|
2136
|
+
{ style: { width: '100%', display: 'flex', flexDirection: 'column', gap: '6px' } },
|
|
2137
|
+
h('input', {
|
|
2138
|
+
className: 'sc-input sc-face-code',
|
|
2139
|
+
style: { width: '100%', fontFamily: 'ui-monospace,Consolas,monospace' },
|
|
2140
|
+
readOnly: true,
|
|
2141
|
+
value: faceCodeOf(draft),
|
|
2142
|
+
onFocus: (e) => e.target.select(),
|
|
2143
|
+
}),
|
|
2144
|
+
h(
|
|
2145
|
+
'div',
|
|
2146
|
+
{ style: { display: 'flex', gap: '6px' } },
|
|
2147
|
+
h(
|
|
2148
|
+
'button',
|
|
2149
|
+
{
|
|
2150
|
+
className: 'sc-btn sc-btn-sm',
|
|
2151
|
+
onClick: () => {
|
|
2152
|
+
try {
|
|
2153
|
+
navigator.clipboard.writeText(faceCodeOf(draft))
|
|
2154
|
+
setToast('已复制')
|
|
2155
|
+
} catch (e) {
|
|
2156
|
+
setToast('复制失败,手动选中')
|
|
2157
|
+
}
|
|
2158
|
+
},
|
|
2159
|
+
},
|
|
2160
|
+
'复制',
|
|
2161
|
+
),
|
|
2162
|
+
h('input', {
|
|
2163
|
+
className: 'sc-input',
|
|
2164
|
+
style: { flex: 1, minWidth: '90px' },
|
|
2165
|
+
placeholder: '粘贴脸码…',
|
|
2166
|
+
value: codeInput,
|
|
2167
|
+
onChange: (e) => setCodeInput(e.target.value),
|
|
2168
|
+
}),
|
|
2169
|
+
h(
|
|
2170
|
+
'button',
|
|
2171
|
+
{
|
|
2172
|
+
className: 'sc-btn sc-btn-sm',
|
|
2173
|
+
onClick: () => {
|
|
2174
|
+
const f = faceFromCode(codeInput)
|
|
2175
|
+
if (!f) {
|
|
2176
|
+
setToast('脸码无效')
|
|
2177
|
+
return
|
|
2178
|
+
}
|
|
2179
|
+
commit(f, true)
|
|
2180
|
+
setToast('已套用')
|
|
2181
|
+
},
|
|
2182
|
+
},
|
|
2183
|
+
'套用',
|
|
2184
|
+
),
|
|
2185
|
+
),
|
|
2186
|
+
)
|
|
2187
|
+
: null,
|
|
2188
|
+
toast ? h('div', { className: 'sc-camp-meta' }, toast) : null,
|
|
2189
|
+
),
|
|
2190
|
+
h(
|
|
2191
|
+
'div',
|
|
2192
|
+
{ className: 'sc-face-right' },
|
|
2193
|
+
h(
|
|
2194
|
+
'div',
|
|
2195
|
+
{ className: 'sc-face-tabs' },
|
|
2196
|
+
FACE_GROUPS.map((g, i) =>
|
|
2197
|
+
h(
|
|
2198
|
+
'button',
|
|
2199
|
+
{ key: g.key, className: 'sc-face-tab' + (i === tab ? ' on' : ''), onClick: () => setTab(i) },
|
|
2200
|
+
g.label,
|
|
2201
|
+
),
|
|
2202
|
+
),
|
|
2203
|
+
),
|
|
2204
|
+
h('div', { className: 'sc-face-params' }, activeGroup.items.map(renderControl)),
|
|
2205
|
+
),
|
|
2206
|
+
),
|
|
2207
|
+
h(
|
|
2208
|
+
'div',
|
|
2209
|
+
{ className: 'sc-face-foot' },
|
|
2210
|
+
h('span', { className: 'sc-camp-meta' }, '预设'),
|
|
2211
|
+
FACE_PRESETS.map((p) =>
|
|
2212
|
+
h(
|
|
2213
|
+
'button',
|
|
2214
|
+
{ key: p.name, className: 'sc-btn sc-btn-sm', onClick: () => commit(applyPreset(draft, p), true) },
|
|
2215
|
+
p.name,
|
|
2216
|
+
),
|
|
2217
|
+
),
|
|
2218
|
+
h('span', { className: 'sc-grow' }),
|
|
2219
|
+
h('span', { className: 'sc-camp-meta' }, '保存后:头像、串门现场、发布营地都会用这张脸'),
|
|
2220
|
+
),
|
|
2221
|
+
),
|
|
2222
|
+
)
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
/**
|
|
2226
|
+
* 营地快照 = 我装了哪些插件 + 营地名/一句话。
|
|
2227
|
+
* P1 只做「发布 / 浏览 / 看清单」:不装任何东西,复刻留到 P2。
|
|
2228
|
+
*/
|
|
2229
|
+
function CampPanel(props) {
|
|
2230
|
+
const auth = props.auth
|
|
2231
|
+
const [scope, setScope] = useState('friends')
|
|
2232
|
+
const [camps, setCamps] = useState([])
|
|
2233
|
+
const [detail, setDetail] = useState(null)
|
|
2234
|
+
const [myPlugins, setMyPlugins] = useState(null)
|
|
2235
|
+
const [mine, setMine] = useState(null)
|
|
2236
|
+
const [showForm, setShowForm] = useState(false)
|
|
2237
|
+
const [form, setForm] = useState({ name: '', greeting: '', visibility: 'friends' })
|
|
2238
|
+
const [busy, setBusy] = useState(false)
|
|
2239
|
+
const [err, setErr] = useState('')
|
|
2240
|
+
const [loading, setLoading] = useState(false)
|
|
2241
|
+
const [shareCode, setShareCode] = useState('')
|
|
2242
|
+
const [picked, setPicked] = useState({})
|
|
2243
|
+
const [applying, setApplying] = useState(false)
|
|
2244
|
+
const [applyResults, setApplyResults] = useState(null)
|
|
2245
|
+
const [myChar, setMyChar] = useState(() => readMyCharacter())
|
|
2246
|
+
const [visitors, setVisitors] = useState([])
|
|
2247
|
+
const [faceOpen, setFaceOpen] = useState(false)
|
|
2248
|
+
|
|
2249
|
+
const collect = async () => {
|
|
2250
|
+
try {
|
|
2251
|
+
const res = await fetch('/api/share-chat/camp/collect', { credentials: 'same-origin' })
|
|
2252
|
+
if (!res.ok) return []
|
|
2253
|
+
const data = await res.json()
|
|
2254
|
+
return Array.isArray(data.plugins) ? data.plugins : []
|
|
2255
|
+
} catch (e) {
|
|
2256
|
+
return []
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
const loadMine = async () => {
|
|
2261
|
+
try {
|
|
2262
|
+
const r = await api(auth.server, '/api/camp/' + encodeURIComponent(auth.id), { token: auth.token })
|
|
2263
|
+
setMine(r)
|
|
2264
|
+
setForm((f) => ({
|
|
2265
|
+
name: f.name || r.camp.name || '',
|
|
2266
|
+
greeting: f.greeting || r.camp.greeting || '',
|
|
2267
|
+
visibility: r.visibility || f.visibility,
|
|
2268
|
+
}))
|
|
2269
|
+
} catch (e) {
|
|
2270
|
+
if (e.code === 'not-found') setMine(null)
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
const loadList = async (sc) => {
|
|
2275
|
+
setLoading(true)
|
|
2276
|
+
setErr('')
|
|
2277
|
+
try {
|
|
2278
|
+
const r = await api(auth.server, '/api/camps?scope=' + sc, { token: auth.token })
|
|
2279
|
+
setCamps(r.camps || [])
|
|
2280
|
+
} catch (e) {
|
|
2281
|
+
setErr(friendly(e))
|
|
2282
|
+
} finally {
|
|
2283
|
+
setLoading(false)
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
useEffect(() => {
|
|
2288
|
+
collect().then(setMyPlugins)
|
|
2289
|
+
loadMine()
|
|
2290
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2291
|
+
}, [])
|
|
2292
|
+
useEffect(() => {
|
|
2293
|
+
loadList(scope)
|
|
2294
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2295
|
+
}, [scope])
|
|
2296
|
+
|
|
2297
|
+
const publish = async () => {
|
|
2298
|
+
setBusy(true)
|
|
2299
|
+
setErr('')
|
|
2300
|
+
try {
|
|
2301
|
+
const all = await collect()
|
|
2302
|
+
const plugins = all.filter((p) => !p.builtin)
|
|
2303
|
+
const camp = {
|
|
2304
|
+
name: form.name || (auth.displayName || auth.id) + ' 的营地',
|
|
2305
|
+
greeting: form.greeting,
|
|
2306
|
+
theme: null,
|
|
2307
|
+
character: myChar,
|
|
2308
|
+
plugins,
|
|
2309
|
+
}
|
|
2310
|
+
const saved = await api(auth.server, '/api/camp', {
|
|
2311
|
+
method: 'POST',
|
|
2312
|
+
token: auth.token,
|
|
2313
|
+
body: { camp, visibility: form.visibility },
|
|
2314
|
+
})
|
|
2315
|
+
if (saved && saved.code) setShareCode(saved.code)
|
|
2316
|
+
setShowForm(false)
|
|
2317
|
+
await loadMine()
|
|
2318
|
+
await loadList(scope)
|
|
2319
|
+
} catch (e) {
|
|
2320
|
+
setErr(friendly(e))
|
|
2321
|
+
} finally {
|
|
2322
|
+
setBusy(false)
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
const unpublish = async () => {
|
|
2327
|
+
setBusy(true)
|
|
2328
|
+
try {
|
|
2329
|
+
await api(auth.server, '/api/camp', { method: 'DELETE', token: auth.token })
|
|
2330
|
+
setMine(null)
|
|
2331
|
+
await loadList(scope)
|
|
2332
|
+
} catch (e) {
|
|
2333
|
+
setErr(friendly(e))
|
|
2334
|
+
} finally {
|
|
2335
|
+
setBusy(false)
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// 串门现场:每 5 秒心跳,每 3 秒拉一次访客
|
|
2340
|
+
useEffect(() => {
|
|
2341
|
+
if (!detail) return
|
|
2342
|
+
const owner = detail.owner
|
|
2343
|
+
const code = detail.visibility === 'unlisted' ? '' : ''
|
|
2344
|
+
let alive = true
|
|
2345
|
+
const beat = async () => {
|
|
2346
|
+
try {
|
|
2347
|
+
const r = await api(auth.server, '/api/camp/' + encodeURIComponent(owner) + '/visit' + (code ? '?code=' + code : ''), {
|
|
2348
|
+
method: 'POST',
|
|
2349
|
+
token: auth.token,
|
|
2350
|
+
body: { character: myChar },
|
|
2351
|
+
})
|
|
2352
|
+
if (alive && r && Array.isArray(r.visitors)) setVisitors(r.visitors)
|
|
2353
|
+
} catch (e) {
|
|
2354
|
+
/* ignore */
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
const poll = async () => {
|
|
2358
|
+
try {
|
|
2359
|
+
const r = await api(auth.server, '/api/camp/' + encodeURIComponent(owner) + '/visitors', { token: auth.token })
|
|
2360
|
+
if (alive && r && Array.isArray(r.visitors)) setVisitors(r.visitors)
|
|
2361
|
+
} catch (e) {
|
|
2362
|
+
/* ignore */
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
beat()
|
|
2366
|
+
const t1 = window.setInterval(beat, 5000)
|
|
2367
|
+
const t2 = window.setInterval(poll, 3000)
|
|
2368
|
+
return () => {
|
|
2369
|
+
alive = false
|
|
2370
|
+
window.clearInterval(t1)
|
|
2371
|
+
window.clearInterval(t2)
|
|
2372
|
+
}
|
|
2373
|
+
}, [detail, myChar, auth.server, auth.token])
|
|
2374
|
+
|
|
2375
|
+
const openDetail = async (owner, rev) => {
|
|
2376
|
+
setErr('')
|
|
2377
|
+
setPicked({})
|
|
2378
|
+
setApplyResults(null)
|
|
2379
|
+
setVisitors([])
|
|
2380
|
+
try {
|
|
2381
|
+
const q = rev ? '?rev=' + rev : ''
|
|
2382
|
+
const r = await api(auth.server, '/api/camp/' + encodeURIComponent(owner) + q, { token: auth.token })
|
|
2383
|
+
setDetail(r)
|
|
2384
|
+
} catch (e) {
|
|
2385
|
+
setErr(friendly(e))
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
const diffOf = (p) => {
|
|
2390
|
+
if (p.builtin) return ['内置', 'sc-badge-builtin']
|
|
2391
|
+
const mineP = (myPlugins || []).find((x) => x.name === p.name)
|
|
2392
|
+
if (!mineP) return ['可安装', 'sc-badge-new']
|
|
2393
|
+
if (mineP.version === p.version) return ['已有', 'sc-badge-have']
|
|
2394
|
+
return ['版本不同', 'sc-badge-diff']
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
const pickable = (p) => {
|
|
2398
|
+
const [tag] = diffOf(p)
|
|
2399
|
+
return tag === '可安装' || tag === '版本不同'
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
const togglePick = (p) => {
|
|
2403
|
+
setPicked((prev) => {
|
|
2404
|
+
const next = { ...prev }
|
|
2405
|
+
if (next[p.name]) delete next[p.name]
|
|
2406
|
+
else next[p.name] = p
|
|
2407
|
+
return next
|
|
2408
|
+
})
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
const replicate = async (camp) => {
|
|
2412
|
+
const chosen = Object.values(picked)
|
|
2413
|
+
if (!chosen.length) return
|
|
2414
|
+
setApplying(true)
|
|
2415
|
+
setApplyResults(null)
|
|
2416
|
+
setErr('')
|
|
2417
|
+
try {
|
|
2418
|
+
const nres = await fetch('/api/share-chat/camp/nonce', { credentials: 'same-origin' })
|
|
2419
|
+
if (!nres.ok) throw new Error('拿不到本机授权(' + nres.status + ')')
|
|
2420
|
+
const { nonce } = await nres.json()
|
|
2421
|
+
const res = await fetch('/api/share-chat/camp/apply', {
|
|
2422
|
+
method: 'POST',
|
|
2423
|
+
credentials: 'same-origin',
|
|
2424
|
+
headers: { 'content-type': 'application/json' },
|
|
2425
|
+
body: JSON.stringify({
|
|
2426
|
+
nonce,
|
|
2427
|
+
specs: chosen.map((p) => ({ spec: p.spec, name: p.name, version: p.version })),
|
|
2428
|
+
}),
|
|
2429
|
+
})
|
|
2430
|
+
const data = await res.json().catch(() => ({}))
|
|
2431
|
+
if (!res.ok) throw new Error(data.error || '安装失败 ' + res.status)
|
|
2432
|
+
setApplyResults(data.results || [])
|
|
2433
|
+
setPicked({})
|
|
2434
|
+
const fresh = await collect()
|
|
2435
|
+
setMyPlugins(fresh)
|
|
2436
|
+
} catch (e) {
|
|
2437
|
+
setErr(String(e.message || e))
|
|
2438
|
+
} finally {
|
|
2439
|
+
setApplying(false)
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
const undoApply = async (targets) => {
|
|
2444
|
+
setApplying(true)
|
|
2445
|
+
try {
|
|
2446
|
+
const res = await fetch('/api/share-chat/camp/remove', {
|
|
2447
|
+
method: 'POST',
|
|
2448
|
+
credentials: 'same-origin',
|
|
2449
|
+
headers: { 'content-type': 'application/json' },
|
|
2450
|
+
body: JSON.stringify({ targets }),
|
|
2451
|
+
})
|
|
2452
|
+
const data = await res.json().catch(() => ({}))
|
|
2453
|
+
setApplyResults(data.results && data.results.length ? null : null)
|
|
2454
|
+
const fresh = await collect()
|
|
2455
|
+
setMyPlugins(fresh)
|
|
2456
|
+
setErr(data.results && data.results.some((r) => !r.ok) ? '部分撤销失败,看控制台' : '')
|
|
2457
|
+
} catch (e) {
|
|
2458
|
+
setErr(String(e.message || e))
|
|
2459
|
+
} finally {
|
|
2460
|
+
setApplying(false)
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
if (faceOpen) {
|
|
2465
|
+
return h(FaceEditor, {
|
|
2466
|
+
initial: myChar,
|
|
2467
|
+
onSave: (f) => setMyChar(f),
|
|
2468
|
+
onClose: () => setFaceOpen(false),
|
|
2469
|
+
})
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
if (detail) {
|
|
2473
|
+
const camp = detail.camp
|
|
2474
|
+
const mineMap = new Map((myPlugins || []).map((p) => [p.name, p]))
|
|
2475
|
+
return h(
|
|
2476
|
+
'div',
|
|
2477
|
+
{ className: 'sc-camp' },
|
|
2478
|
+
h(
|
|
2479
|
+
'div',
|
|
2480
|
+
{ className: 'sc-camp-top' },
|
|
2481
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => setDetail(null) }, '← 返回'),
|
|
2482
|
+
h('strong', { style: { fontSize: '14px' } }, camp.name),
|
|
2483
|
+
h('span', { className: 'sc-camp-meta' }, '@' + detail.owner),
|
|
2484
|
+
h('span', { className: 'sc-grow' }),
|
|
2485
|
+
detail.revisions.length > 1
|
|
2486
|
+
? h(
|
|
2487
|
+
'select',
|
|
2488
|
+
{
|
|
2489
|
+
className: 'sc-input',
|
|
2490
|
+
style: { height: '28px', width: 'auto', padding: '0 8px' },
|
|
2491
|
+
value: String(detail.rev),
|
|
2492
|
+
onChange: (e) => openDetail(detail.owner, Number(e.target.value)),
|
|
2493
|
+
},
|
|
2494
|
+
detail.revisions.map((r) =>
|
|
2495
|
+
h('option', { key: r.rev, value: String(r.rev) }, '第 ' + r.rev + ' 版'),
|
|
2496
|
+
),
|
|
2497
|
+
)
|
|
2498
|
+
: null,
|
|
2499
|
+
h('span', { style: { opacity: 0.5, fontSize: '11px' } }, '复刻功能下一步开放'),
|
|
2500
|
+
),
|
|
2501
|
+
h(CampScene, {
|
|
2502
|
+
owner: detail.owner,
|
|
2503
|
+
ownerName: camp.name,
|
|
2504
|
+
ownerCharacter: camp.character,
|
|
2505
|
+
myCharacter: myChar,
|
|
2506
|
+
me: auth.id,
|
|
2507
|
+
visitors,
|
|
2508
|
+
}),
|
|
2509
|
+
camp.greeting ? h('div', { className: 'sc-camp-greet', style: { marginBottom: '10px' } }, camp.greeting) : null,
|
|
2510
|
+
h('div', { className: 'sc-camp-meta' }, '共 ' + camp.plugins.length + ' 个插件 · 与你有 ' + (myPlugins ? myPlugins.length : 0) + ' 个'),
|
|
2511
|
+
h(
|
|
2512
|
+
'div',
|
|
2513
|
+
{ className: 'sc-camp-plugins' },
|
|
2514
|
+
camp.plugins.map((p, i) => {
|
|
2515
|
+
const [tag, cls] = diffOf(p)
|
|
2516
|
+
const can = pickable(p)
|
|
2517
|
+
return h(
|
|
2518
|
+
'div',
|
|
2519
|
+
{ className: 'sc-camp-plug', key: i },
|
|
2520
|
+
can
|
|
2521
|
+
? h('input', {
|
|
2522
|
+
type: 'checkbox',
|
|
2523
|
+
checked: !!picked[p.name],
|
|
2524
|
+
onChange: () => togglePick(p),
|
|
2525
|
+
})
|
|
2526
|
+
: null,
|
|
2527
|
+
h('span', { className: 'nm' }, p.name + (p.version ? '@' + p.version : '')),
|
|
2528
|
+
h('span', { className: 'sc-camp-meta' }, p.source === 'git' ? 'git' : p.source || ''),
|
|
2529
|
+
h('span', { className: 'sc-camp-badge ' + cls }, tag),
|
|
2530
|
+
)
|
|
2531
|
+
}),
|
|
2532
|
+
),
|
|
2533
|
+
h(
|
|
2534
|
+
'div',
|
|
2535
|
+
{ style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '14px', flexWrap: 'wrap' } },
|
|
2536
|
+
h(
|
|
2537
|
+
'button',
|
|
2538
|
+
{
|
|
2539
|
+
className: 'sc-btn sc-btn-primary',
|
|
2540
|
+
disabled: applying || Object.keys(picked).length === 0,
|
|
2541
|
+
onClick: () => replicate(camp),
|
|
2542
|
+
},
|
|
2543
|
+
applying ? '安装中…' : '复刻选中的 ' + Object.keys(picked).length + ' 个插件',
|
|
2544
|
+
),
|
|
2545
|
+
applyResults
|
|
2546
|
+
? h(
|
|
2547
|
+
'button',
|
|
2548
|
+
{
|
|
2549
|
+
className: 'sc-btn',
|
|
2550
|
+
disabled: applying,
|
|
2551
|
+
onClick: () =>
|
|
2552
|
+
undoApply(applyResults.filter((r) => r.ok && r.bundle).map((r) => r.bundle)),
|
|
2553
|
+
},
|
|
2554
|
+
'撤销这次安装',
|
|
2555
|
+
)
|
|
2556
|
+
: null,
|
|
2557
|
+
h('span', { className: 'sc-camp-meta' }, '只装你勾的;装完可能需要刷新页面'),
|
|
2558
|
+
),
|
|
2559
|
+
applyResults
|
|
2560
|
+
? h(
|
|
2561
|
+
'div',
|
|
2562
|
+
{ className: 'sc-camp-plugins' },
|
|
2563
|
+
applyResults.map((r, i) =>
|
|
2564
|
+
h(
|
|
2565
|
+
'div',
|
|
2566
|
+
{ className: 'sc-camp-plug', key: i },
|
|
2567
|
+
h('span', { className: 'nm' }, r.spec || r.name || ''),
|
|
2568
|
+
h(
|
|
2569
|
+
'span',
|
|
2570
|
+
{ className: 'sc-camp-badge ' + (r.ok ? 'sc-badge-have' : 'sc-badge-diff') },
|
|
2571
|
+
r.ok ? '已安装' + (r.application && r.application !== 'applied' ? '(' + r.application + ')' : '') : '失败',
|
|
2572
|
+
),
|
|
2573
|
+
h('span', { className: 'sc-camp-meta' }, r.ok ? '' : String(r.error || '')),
|
|
2574
|
+
),
|
|
2575
|
+
),
|
|
2576
|
+
)
|
|
2577
|
+
: null,
|
|
2578
|
+
err ? h('div', { className: 'sc-err', style: { marginTop: '10px' } }, err) : null,
|
|
2579
|
+
)
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
return h(
|
|
2583
|
+
'div',
|
|
2584
|
+
{ className: 'sc-camp' },
|
|
2585
|
+
h(
|
|
2586
|
+
'div',
|
|
2587
|
+
{ className: 'sc-camp-top' },
|
|
2588
|
+
h('strong', { style: { fontSize: '14px' } }, '串门'),
|
|
2589
|
+
h('span', { className: 'sc-camp-meta' }, '看看好友的营地,装了哪些插件'),
|
|
2590
|
+
h('span', { className: 'sc-grow' }),
|
|
2591
|
+
h(
|
|
2592
|
+
'button',
|
|
2593
|
+
{
|
|
2594
|
+
className: 'sc-char-btn',
|
|
2595
|
+
title: '打开捏脸工作室',
|
|
2596
|
+
onClick: () => setFaceOpen(true),
|
|
2597
|
+
},
|
|
2598
|
+
h(Character, { ch: myChar, size: 22 }),
|
|
2599
|
+
'捏脸',
|
|
2600
|
+
),
|
|
2601
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => setShowForm((v) => !v) }, mine ? '重新发布' : '发布我的营地'),
|
|
2602
|
+
h('button', { className: 'sc-btn sc-btn-sm', onClick: () => loadList(scope) }, '刷新'),
|
|
2603
|
+
),
|
|
2604
|
+
h(
|
|
2605
|
+
'div',
|
|
2606
|
+
{ className: 'sc-camp-top' },
|
|
2607
|
+
h(
|
|
2608
|
+
'button',
|
|
2609
|
+
{ className: 'sc-btn sc-btn-sm' + (scope === 'friends' ? ' sc-btn-primary' : ''), onClick: () => setScope('friends') },
|
|
2610
|
+
'好友营地',
|
|
2611
|
+
),
|
|
2612
|
+
h(
|
|
2613
|
+
'button',
|
|
2614
|
+
{ className: 'sc-btn sc-btn-sm' + (scope === 'public' ? ' sc-btn-primary' : ''), onClick: () => setScope('public') },
|
|
2615
|
+
'营地广场',
|
|
2616
|
+
),
|
|
2617
|
+
mine
|
|
2618
|
+
? h(
|
|
2619
|
+
'span',
|
|
2620
|
+
{ className: 'sc-camp-meta' },
|
|
2621
|
+
'我的营地已发布 · 第 ' + mine.rev + ' 版 · ' + mine.visibility,
|
|
2622
|
+
)
|
|
2623
|
+
: null,
|
|
2624
|
+
mine && shareCode
|
|
2625
|
+
? h(
|
|
2626
|
+
'button',
|
|
2627
|
+
{
|
|
2628
|
+
className: 'sc-camp-badge sc-badge-new',
|
|
2629
|
+
style: { cursor: 'pointer', border: 0 },
|
|
2630
|
+
onClick: () => navigator.clipboard && navigator.clipboard.writeText(shareCode),
|
|
2631
|
+
title: '复制访问码',
|
|
2632
|
+
},
|
|
2633
|
+
'访问码 ' + shareCode,
|
|
2634
|
+
)
|
|
2635
|
+
: null,
|
|
2636
|
+
),
|
|
2637
|
+
showForm
|
|
2638
|
+
? h(
|
|
2639
|
+
'div',
|
|
2640
|
+
{ className: 'sc-camp-form', style: { margin: '0 auto 14px' } },
|
|
2641
|
+
h('input', {
|
|
2642
|
+
className: 'sc-input',
|
|
2643
|
+
placeholder: '营地名(例如:摸鱼营地)',
|
|
2644
|
+
value: form.name,
|
|
2645
|
+
onChange: (e) => setForm({ ...form, name: e.target.value }),
|
|
2646
|
+
}),
|
|
2647
|
+
h('input', {
|
|
2648
|
+
className: 'sc-input',
|
|
2649
|
+
placeholder: '一句话签名',
|
|
2650
|
+
value: form.greeting,
|
|
2651
|
+
onChange: (e) => setForm({ ...form, greeting: e.target.value }),
|
|
2652
|
+
}),
|
|
2653
|
+
h(
|
|
2654
|
+
'select',
|
|
2655
|
+
{
|
|
2656
|
+
className: 'sc-input',
|
|
2657
|
+
value: form.visibility,
|
|
2658
|
+
onChange: (e) => setForm({ ...form, visibility: e.target.value }),
|
|
2659
|
+
},
|
|
2660
|
+
h('option', { value: 'friends' }, '仅好友可见'),
|
|
2661
|
+
h('option', { value: 'public' }, '公开(进营地广场)'),
|
|
2662
|
+
h('option', { value: 'unlisted' }, '不列出(凭访问码)'),
|
|
2663
|
+
),
|
|
2664
|
+
h(
|
|
2665
|
+
'div',
|
|
2666
|
+
{ style: { display: 'flex', gap: '8px', alignItems: 'center' } },
|
|
2667
|
+
h('button', { className: 'sc-btn sc-btn-primary', onClick: publish, disabled: busy }, busy ? '发布中…' : '发布'),
|
|
2668
|
+
mine ? h('button', { className: 'sc-btn', onClick: unpublish, disabled: busy }, '下线') : null,
|
|
2669
|
+
h('span', { className: 'sc-camp-meta' }, '发布的内容只有营地名、签名和插件清单,不含路径/凭据/会话'),
|
|
2670
|
+
),
|
|
2671
|
+
)
|
|
2672
|
+
: null,
|
|
2673
|
+
err ? h('div', { className: 'sc-err', style: { marginBottom: '8px' } }, err) : null,
|
|
2674
|
+
loading ? h('div', { className: 'sc-camp-meta' }, '加载中…') : null,
|
|
2675
|
+
h(
|
|
2676
|
+
'div',
|
|
2677
|
+
{ className: 'sc-camp-grid' },
|
|
2678
|
+
camps.length === 0 && !loading
|
|
2679
|
+
? emptyState('🏕', scope === 'public' ? '广场上还没有营地' : '好友还没人发布营地', '发布一个自己的,或去广场看看')
|
|
2680
|
+
: camps.map((c) =>
|
|
2681
|
+
h(
|
|
2682
|
+
'div',
|
|
2683
|
+
{ className: 'sc-camp-card', key: c.owner, onClick: () => openDetail(c.owner) },
|
|
2684
|
+
h(Character, { ch: c.character, id: c.owner, size: 34 }),
|
|
2685
|
+
h(
|
|
2686
|
+
'div',
|
|
2687
|
+
{ className: 'sc-camp-info' },
|
|
2688
|
+
h('div', { className: 'sc-camp-name' }, c.name),
|
|
2689
|
+
h('div', { className: 'sc-camp-greet' }, c.greeting || '(没有签名)'),
|
|
2690
|
+
h(
|
|
2691
|
+
'div',
|
|
2692
|
+
{ className: 'sc-camp-meta' },
|
|
2693
|
+
'@' + c.owner + ' · ' + c.pluginCount + ' 个插件 · 第 ' + c.rev + ' 版',
|
|
2694
|
+
),
|
|
2695
|
+
),
|
|
2696
|
+
h('span', { className: 'sc-camp-badge sc-badge-new' }, '进去看看'),
|
|
2697
|
+
),
|
|
2698
|
+
),
|
|
2699
|
+
),
|
|
2700
|
+
)
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
// ───────────────────────── 虚拟形象 ─────────────────────────
|
|
2704
|
+
|
|
2705
|
+
const K_CHARACTER = 'dsh-share-chat.character'
|
|
2706
|
+
const CHAR_SKINS = ['#f3cba6', '#e8b78f', '#c98d64', '#8d5a3b']
|
|
2707
|
+
const CHAR_HAIRS = ['#2b2b2b', '#5a3a26', '#8a5a2b', '#d9b25f', '#3d5a80', '#a33b52']
|
|
2708
|
+
const CHAR_OUTFITS = ['#247bbf', '#2f8f65', '#8a5ec9', '#d0693b', '#3d7a8c', '#b03a5b']
|
|
2709
|
+
|
|
2710
|
+
function charHash(str) {
|
|
2711
|
+
let h = 2166136261
|
|
2712
|
+
const t = String(str || '?')
|
|
2713
|
+
for (let i = 0; i < t.length; i++) {
|
|
2714
|
+
h ^= t.charCodeAt(i)
|
|
2715
|
+
h = Math.imul(h, 16777619)
|
|
2716
|
+
}
|
|
2717
|
+
return Math.abs(h)
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
const CHAR_HATS = ['none', 'none', 'none', 'cap', 'beanie', 'halo']
|
|
2721
|
+
|
|
2722
|
+
function defaultCharacter(id) {
|
|
2723
|
+
const h = charHash(id)
|
|
2724
|
+
return {
|
|
2725
|
+
seed: h % 999999,
|
|
2726
|
+
skin: CHAR_SKINS[h % CHAR_SKINS.length],
|
|
2727
|
+
hair: CHAR_HAIRS[(h >> 3) % CHAR_HAIRS.length],
|
|
2728
|
+
outfit: CHAR_OUTFITS[(h >> 6) % CHAR_OUTFITS.length],
|
|
2729
|
+
hat: CHAR_HATS[(h >> 9) % CHAR_HATS.length],
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
function normalizeCharacter(c, id) {
|
|
2734
|
+
const base = defaultCharacter(id || 'anon')
|
|
2735
|
+
const src = c && typeof c === 'object' ? c : {}
|
|
2736
|
+
const color = (v, fb) => (/^#[0-9a-f]{6}$/i.test(String(v || '')) ? String(v) : fb)
|
|
2737
|
+
return {
|
|
2738
|
+
seed: Number.isFinite(Number(src.seed)) ? Number(src.seed) : base.seed,
|
|
2739
|
+
skin: color(src.skin, base.skin),
|
|
2740
|
+
hair: color(src.hair, base.hair),
|
|
2741
|
+
outfit: color(src.outfit, base.outfit),
|
|
2742
|
+
hat: ['none', 'cap', 'beanie', 'halo'].includes(src.hat) ? src.hat : base.hat,
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
function readMyCharacter() {
|
|
2747
|
+
return normalizeFace(readJson(K_CHARACTER))
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
function randomCharacter(prev) {
|
|
2751
|
+
return randomFace((prev && prev.style) || 'cartoon')
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
/** 小人儿:v2 捏脸参数的渲染入口(兼容 v1 哈希形象) */
|
|
2755
|
+
function Character(props) {
|
|
2756
|
+
const f = props.face ? normalizeFace(props.face, props.id) : normalizeFace(props.ch, props.id)
|
|
2757
|
+
const size = props.size || 56
|
|
2758
|
+
return h(FaceRender, {
|
|
2759
|
+
face: f,
|
|
2760
|
+
size: size,
|
|
2761
|
+
angle: props.angle === undefined ? 0 : props.angle,
|
|
2762
|
+
uid: (props.id || '') + (props.uid || ''),
|
|
2763
|
+
})
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
/** 串门现场:营地主人 + 我 + 其他访客 */
|
|
2767
|
+
function CampScene(props) {
|
|
2768
|
+
const ownerChar = normalizeFace(props.ownerCharacter, props.owner)
|
|
2769
|
+
const myChar = normalizeFace(props.myCharacter, props.me)
|
|
2770
|
+
const visitors = Array.isArray(props.visitors) ? props.visitors.filter((v) => v.id !== props.me && v.id !== props.owner) : []
|
|
2771
|
+
const slots = [
|
|
2772
|
+
{ key: 'me', char: myChar, name: '我', left: '12%', walk: true },
|
|
2773
|
+
{ key: 'owner', char: ownerChar, name: props.ownerName || props.owner, left: '72%' },
|
|
2774
|
+
...visitors.slice(0, 3).map((v, i) => ({
|
|
2775
|
+
key: v.id,
|
|
2776
|
+
char: normalizeFace(v.character, v.id),
|
|
2777
|
+
name: v.name || v.id,
|
|
2778
|
+
left: 34 + i * 14 + '%',
|
|
2779
|
+
})),
|
|
2780
|
+
]
|
|
2781
|
+
return h(
|
|
2782
|
+
'div',
|
|
2783
|
+
{ className: 'sc-scene' },
|
|
2784
|
+
h('div', { className: 'sc-scene-floor' }),
|
|
2785
|
+
visitors.length === 0
|
|
2786
|
+
? h('div', { className: 'sc-scene-empty' }, '现在只有你们俩,等别人推门进来')
|
|
2787
|
+
: null,
|
|
2788
|
+
slots.map((slot) =>
|
|
2789
|
+
h(
|
|
2790
|
+
'div',
|
|
2791
|
+
{
|
|
2792
|
+
key: slot.key,
|
|
2793
|
+
className: 'sc-scene-actor' + (slot.walk ? ' walk' : ''),
|
|
2794
|
+
style: { left: slot.left },
|
|
2795
|
+
},
|
|
2796
|
+
h('div', { className: 'sc-scene-bob' }, h(Character, { ch: slot.char, size: slot.key === 'owner' ? 62 : 50 })),
|
|
2797
|
+
h('div', { className: 'sc-scene-name' }, slot.name),
|
|
2798
|
+
),
|
|
2799
|
+
),
|
|
2800
|
+
)
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
// ───────────────────────── 捏脸引擎 v2 ─────────────────────────
|
|
2804
|
+
|
|
2805
|
+
const FACE_V = 2
|
|
2806
|
+
const F_SKIN = ['#f7dbc4', '#f0c9a8', '#e2b189', '#cb9468', '#a9744c', '#8a5738']
|
|
2807
|
+
const F_HAIR = ['#241f1c', '#43301f', '#65452a', '#95683c', '#d8b05c', '#8b3646', '#3b567c', '#6f4785']
|
|
2808
|
+
const F_EYE = ['#26221f', '#4a3826', '#33513f', '#38557a', '#543544', '#6b5a2f']
|
|
2809
|
+
const F_OUTFIT = ['#247bbf', '#2f8f65', '#8a5ec9', '#d0693b', '#3d7a8c', '#b03a5b', '#5a6570', '#c9a227']
|
|
2810
|
+
const F_HAT = ['none', 'cap', 'beanie', 'halo']
|
|
2811
|
+
const F_GLASSES = ['none', 'round', 'square']
|
|
2812
|
+
const F_EARRING = ['none', 'dot']
|
|
2813
|
+
const F_STYLE = ['cartoon', 'real']
|
|
2814
|
+
|
|
2815
|
+
const FACE_GROUPS = [
|
|
2816
|
+
{
|
|
2817
|
+
key: 'shape',
|
|
2818
|
+
label: '脸型',
|
|
2819
|
+
items: [
|
|
2820
|
+
['faceWidth', '脸宽', 0, -100, 100],
|
|
2821
|
+
['jaw', '下颌', 0, -100, 100],
|
|
2822
|
+
['cheek', '颧骨', 0, -100, 100],
|
|
2823
|
+
['chin', '下巴', 0, -100, 100],
|
|
2824
|
+
['forehead', '额头', 0, -100, 100],
|
|
2825
|
+
],
|
|
2826
|
+
},
|
|
2827
|
+
{
|
|
2828
|
+
key: 'eyes',
|
|
2829
|
+
label: '眼睛',
|
|
2830
|
+
items: [
|
|
2831
|
+
['eyeSize', '大小', 0, -100, 100],
|
|
2832
|
+
['eyeSpacing', '眼距', 0, -100, 100],
|
|
2833
|
+
['eyeTilt', '眼角', 0, -100, 100],
|
|
2834
|
+
['eyeHeight', '位置', 0, -100, 100],
|
|
2835
|
+
['eyeLid', '眼睑', 0, 0, 100],
|
|
2836
|
+
['eyePupil', '瞳孔', 0, -100, 100],
|
|
2837
|
+
],
|
|
2838
|
+
},
|
|
2839
|
+
{
|
|
2840
|
+
key: 'brow',
|
|
2841
|
+
label: '眉毛',
|
|
2842
|
+
items: [
|
|
2843
|
+
['browThick', '粗细', 0, -100, 100],
|
|
2844
|
+
['browArch', '弧度', 0, -100, 100],
|
|
2845
|
+
['browHeight', '高低', 0, -100, 100],
|
|
2846
|
+
['browTilt', '眉头', 0, -100, 100],
|
|
2847
|
+
],
|
|
2848
|
+
},
|
|
2849
|
+
{
|
|
2850
|
+
key: 'nose',
|
|
2851
|
+
label: '鼻子',
|
|
2852
|
+
items: [
|
|
2853
|
+
['noseLength', '长短', 0, -100, 100],
|
|
2854
|
+
['noseWidth', '宽窄', 0, -100, 100],
|
|
2855
|
+
['noseBridge', '鼻梁', 0, 0, 100],
|
|
2856
|
+
['noseTip', '鼻头', 0, -100, 100],
|
|
2857
|
+
],
|
|
2858
|
+
},
|
|
2859
|
+
{
|
|
2860
|
+
key: 'mouth',
|
|
2861
|
+
label: '嘴巴',
|
|
2862
|
+
items: [
|
|
2863
|
+
['mouthWidth', '宽窄', 0, -100, 100],
|
|
2864
|
+
['mouthFull', '厚薄', 0, -100, 100],
|
|
2865
|
+
['mouthSmile', '嘴角', 0, -100, 100],
|
|
2866
|
+
['mouthHeight', '高低', 0, -100, 100],
|
|
2867
|
+
],
|
|
2868
|
+
},
|
|
2869
|
+
{
|
|
2870
|
+
key: 'ears',
|
|
2871
|
+
label: '耳朵',
|
|
2872
|
+
items: [
|
|
2873
|
+
['earSize', '大小', 0, -100, 100],
|
|
2874
|
+
['earAngle', '角度', 0, -100, 100],
|
|
2875
|
+
],
|
|
2876
|
+
},
|
|
2877
|
+
{
|
|
2878
|
+
key: 'look',
|
|
2879
|
+
label: '肤色',
|
|
2880
|
+
items: [
|
|
2881
|
+
['skinTone', '肤色', 1, 0, F_SKIN.length - 1, 'palette:F_SKIN'],
|
|
2882
|
+
['blush', '腮红', 30, 0, 100],
|
|
2883
|
+
['shadow', '面部阴影', 45, 0, 100],
|
|
2884
|
+
['eyeColor', '瞳色', 0, 0, F_EYE.length - 1, 'palette:F_EYE'],
|
|
2885
|
+
['browColor', '眉色', 0, 0, F_HAIR.length - 1, 'palette:F_HAIR'],
|
|
2886
|
+
],
|
|
2887
|
+
},
|
|
2888
|
+
{
|
|
2889
|
+
key: 'hair',
|
|
2890
|
+
label: '头发',
|
|
2891
|
+
items: [
|
|
2892
|
+
['hairStyle', '发型', 0, 0, 7, 'names:' + ['短发', '波波', '长直', '马尾', '卷发', '寸头', '偏分', '双马尾'].join('|')],
|
|
2893
|
+
['hairColor', '发色', 0, 0, F_HAIR.length - 1, 'palette:F_HAIR'],
|
|
2894
|
+
['fringe', '刘海', 45, 0, 100],
|
|
2895
|
+
],
|
|
2896
|
+
},
|
|
2897
|
+
{
|
|
2898
|
+
key: 'makeup',
|
|
2899
|
+
label: '妆容',
|
|
2900
|
+
items: [
|
|
2901
|
+
['eyeliner', '眼线', 0, 0, 100],
|
|
2902
|
+
['lip', '唇色', 35, 0, 100],
|
|
2903
|
+
],
|
|
2904
|
+
},
|
|
2905
|
+
{
|
|
2906
|
+
key: 'acc',
|
|
2907
|
+
label: '配饰',
|
|
2908
|
+
items: [
|
|
2909
|
+
['hat', '帽子', 0, 0, F_HAT.length - 1, 'names:' + F_HAT.join('|')],
|
|
2910
|
+
['glasses', '眼镜', 0, 0, F_GLASSES.length - 1, 'names:' + F_GLASSES.join('|')],
|
|
2911
|
+
['earring', '耳饰', 0, 0, F_EARRING.length - 1, 'names:' + F_EARRING.join('|')],
|
|
2912
|
+
],
|
|
2913
|
+
},
|
|
2914
|
+
{
|
|
2915
|
+
key: 'body',
|
|
2916
|
+
label: '身形',
|
|
2917
|
+
items: [
|
|
2918
|
+
['build', '体宽', 0, -100, 100],
|
|
2919
|
+
['outfit', '衣服', 0, 0, F_OUTFIT.length - 1, 'palette:F_OUTFIT'],
|
|
2920
|
+
],
|
|
2921
|
+
},
|
|
2922
|
+
]
|
|
2923
|
+
|
|
2924
|
+
const FACE_PARAMS = []
|
|
2925
|
+
for (const g of FACE_GROUPS) for (const it of g.items) FACE_PARAMS.push(it)
|
|
2926
|
+
|
|
2927
|
+
const clampNum = (v, min, max, fb) => {
|
|
2928
|
+
const n = Number(v)
|
|
2929
|
+
if (!Number.isFinite(n)) return fb
|
|
2930
|
+
return Math.max(min, Math.min(max, Math.round(n)))
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
function zeroFace(style) {
|
|
2934
|
+
const f = { v: FACE_V, style: style || 'cartoon' }
|
|
2935
|
+
for (const it of FACE_PARAMS) f[it[0]] = it[2]
|
|
2936
|
+
return f
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
/** v1(seed/skin/hair/outfit/hat)→ v2 */
|
|
2940
|
+
function faceFromV1(old, id) {
|
|
2941
|
+
const h = charHash(id || 'anon')
|
|
2942
|
+
const seed = old && Number.isFinite(Number(old.seed)) ? Number(old.seed) : h % 999999
|
|
2943
|
+
const pick = (n) => ((seed >> n) % 61) - 30
|
|
2944
|
+
const f = zeroFace('cartoon')
|
|
2945
|
+
f.faceWidth = pick(0)
|
|
2946
|
+
f.jaw = pick(2)
|
|
2947
|
+
f.cheek = pick(4)
|
|
2948
|
+
f.chin = pick(6)
|
|
2949
|
+
f.forehead = pick(8)
|
|
2950
|
+
f.eyeSize = pick(10)
|
|
2951
|
+
f.eyeSpacing = pick(12)
|
|
2952
|
+
f.eyeTilt = pick(14)
|
|
2953
|
+
f.browThick = pick(16)
|
|
2954
|
+
f.noseLength = pick(18)
|
|
2955
|
+
f.mouthWidth = pick(20)
|
|
2956
|
+
const near = (hex, arr, fb) => {
|
|
2957
|
+
const c = String(hex || '')
|
|
2958
|
+
const i = arr.findIndex((x) => x.toLowerCase() === c.toLowerCase())
|
|
2959
|
+
return i >= 0 ? i : fb
|
|
2960
|
+
}
|
|
2961
|
+
f.skinTone = near(old && old.skin, F_SKIN, 1)
|
|
2962
|
+
f.hairColor = near(old && old.hair, F_HAIR, 0)
|
|
2963
|
+
f.outfit = near(old && old.outfit, F_OUTFIT, 0)
|
|
2964
|
+
f.hat = Math.max(0, F_HAT.indexOf(String((old && old.hat) || 'none')))
|
|
2965
|
+
return f
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function normalizeFace(input, id) {
|
|
2969
|
+
const src = input && typeof input === 'object' ? input : null
|
|
2970
|
+
if (!src) return faceFromV1(null, id)
|
|
2971
|
+
if (src.v !== FACE_V && (src.shape || src.eyes) === undefined && src.faceWidth === undefined) {
|
|
2972
|
+
return faceFromV1(src, id)
|
|
2973
|
+
}
|
|
2974
|
+
const f = zeroFace(F_STYLE.includes(src.style) ? src.style : 'cartoon')
|
|
2975
|
+
for (const it of FACE_PARAMS) {
|
|
2976
|
+
const [key, , def, min, max] = it
|
|
2977
|
+
f[key] = clampNum(src[key], min, max, def)
|
|
2978
|
+
}
|
|
2979
|
+
return f
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
function randomFace(style) {
|
|
2983
|
+
const r = (min, max) => Math.round(min + Math.random() * (max - min))
|
|
2984
|
+
const f = zeroFace(style)
|
|
2985
|
+
for (const it of FACE_PARAMS) {
|
|
2986
|
+
const [key, , , min, max, kind] = it
|
|
2987
|
+
if (kind && kind.startsWith('palette:')) f[key] = r(min, max)
|
|
2988
|
+
else if (kind && kind.startsWith('names:')) f[key] = r(min, max)
|
|
2989
|
+
else if (key === 'eyeLid' || key === 'blush' || key === 'fringe' || key === 'noseBridge') f[key] = r(min, Math.min(max, 80))
|
|
2990
|
+
else f[key] = r(Math.max(min, -60), Math.min(max, 60))
|
|
2991
|
+
}
|
|
2992
|
+
return f
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
function faceCodeOf(face) {
|
|
2996
|
+
const f = normalizeFace(face)
|
|
2997
|
+
const nums = [FACE_V, F_STYLE.indexOf(f.style)].concat(FACE_PARAMS.map((it) => f[it[0]]))
|
|
2998
|
+
const payload = nums.join('.')
|
|
2999
|
+
let b64 = ''
|
|
3000
|
+
try {
|
|
3001
|
+
b64 = btoa(payload).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
3002
|
+
} catch (e) {
|
|
3003
|
+
b64 = ''
|
|
3004
|
+
}
|
|
3005
|
+
return 'FACE2-' + b64
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
function faceFromCode(code) {
|
|
3009
|
+
try {
|
|
3010
|
+
const raw = String(code || '').trim()
|
|
3011
|
+
if (!raw.startsWith('FACE2-')) return null
|
|
3012
|
+
const b64 = raw.slice(6).replace(/-/g, '+').replace(/_/g, '/')
|
|
3013
|
+
const text = atob(b64 + '==='.slice((b64.length + 3) % 4))
|
|
3014
|
+
const nums = text.split('.').map((x) => Number(x))
|
|
3015
|
+
if (nums.length !== FACE_PARAMS.length + 2 || nums[0] !== FACE_V) return null
|
|
3016
|
+
const f = zeroFace(F_STYLE[nums[1]] || 'cartoon')
|
|
3017
|
+
FACE_PARAMS.forEach((it, i) => {
|
|
3018
|
+
f[it[0]] = clampNum(nums[i + 2], it[3], it[4], it[2])
|
|
3019
|
+
})
|
|
3020
|
+
return f
|
|
3021
|
+
} catch (e) {
|
|
3022
|
+
return null
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
const FACE_PRESETS = [
|
|
3027
|
+
{ name: '中性', patch: {} },
|
|
3028
|
+
{ name: '清秀', patch: { faceWidth: -30, jaw: -40, chin: -20, eyeSize: 18, eyeSpacing: 6, browThick: -35, noseWidth: -30, mouthWidth: -18, lip: 60 } },
|
|
3029
|
+
{ name: '硬朗', patch: { faceWidth: 34, jaw: 55, cheek: 40, chin: 35, eyeSize: -18, browThick: 55, browTilt: -30, noseBridge: 65, mouthWidth: 22, lip: 10 } },
|
|
3030
|
+
{ name: '幼态', patch: { faceWidth: 22, jaw: -25, chin: -35, eyeSize: 55, eyeHeight: 20, eyeSpacing: 18, noseLength: -40, noseWidth: -35, mouthWidth: -25, blush: 70 } },
|
|
3031
|
+
{ name: '成熟', patch: { jaw: 22, cheek: 30, chin: 18, eyeSize: -10, eyeTilt: 20, browArch: 40, noseLength: 30, noseBridge: 40, lip: 60, eyeliner: 45 } },
|
|
3032
|
+
{ name: '搞怪', patch: { faceWidth: 55, jaw: -60, eyeSize: 70, eyeSpacing: 60, eyeTilt: -50, browThick: 80, noseTip: 70, mouthWidth: 60, mouthSmile: 80, hat: 2 } },
|
|
3033
|
+
]
|
|
3034
|
+
|
|
3035
|
+
function applyPreset(face, preset) {
|
|
3036
|
+
const f = normalizeFace(face)
|
|
3037
|
+
const next = Object.assign({}, f, preset.patch || {})
|
|
3038
|
+
return normalizeFace(next)
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
/** 把参数算成一条脸型轮廓 */
|
|
3042
|
+
function faceOutline(f) {
|
|
3043
|
+
const cx = 100
|
|
3044
|
+
const rx = 44 + f.faceWidth * 0.11 - f.cheek * 0.02
|
|
3045
|
+
const top = 44 - f.forehead * 0.06
|
|
3046
|
+
const cy = 104
|
|
3047
|
+
const chinY = 166 + f.chin * 0.11
|
|
3048
|
+
const jawW = 30 + f.jaw * 0.11 + f.cheek * 0.03
|
|
3049
|
+
const jawY = 132 + f.jaw * 0.05
|
|
3050
|
+
return {
|
|
3051
|
+
cx, rx, top, cy, chinY, jawW, jawY,
|
|
3052
|
+
d:
|
|
3053
|
+
'M ' + cx + ' ' + top +
|
|
3054
|
+
' C ' + (cx + rx * 0.62) + ' ' + (top - 2) + ',' + (cx + rx) + ' ' + (cy - 32) + ',' + (cx + rx) + ' ' + (cy + 2) +
|
|
3055
|
+
' C ' + (cx + rx) + ' ' + jawY + ',' + (cx + jawW) + ' ' + (chinY - 16) + ',' + cx + ' ' + chinY +
|
|
3056
|
+
' C ' + (cx - jawW) + ' ' + (chinY - 16) + ',' + (cx - rx) + ' ' + jawY + ',' + (cx - rx) + ' ' + (cy + 2) +
|
|
3057
|
+
' C ' + (cx - rx) + ' ' + (cy - 32) + ',' + (cx - rx * 0.62) + ' ' + (top - 2) + ',' + cx + ' ' + top + ' Z',
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
/** 参数化脸部(纯 SVG) */
|
|
3062
|
+
function FaceSVG(props) {
|
|
3063
|
+
const f = normalizeFace(props.face, props.id)
|
|
3064
|
+
const style = f.style
|
|
3065
|
+
const real = style === 'real'
|
|
3066
|
+
const size = props.size || 120
|
|
3067
|
+
const angle = Math.max(-35, Math.min(35, Number(props.angle) || 0))
|
|
3068
|
+
const rad = (angle * Math.PI) / 180
|
|
3069
|
+
const sx = Math.max(0.3, Math.cos(rad))
|
|
3070
|
+
const depth = Math.sin(rad)
|
|
3071
|
+
const uid = 'f' + (props.uid || Math.abs(charHash(JSON.stringify(f))).toString(36))
|
|
3072
|
+
const skin = F_SKIN[f.skinTone]
|
|
3073
|
+
const skinDark = shade(skin, -18)
|
|
3074
|
+
const hair = F_HAIR[f.hairColor]
|
|
3075
|
+
const eyeCol = F_EYE[f.eyeColor]
|
|
3076
|
+
const browCol = F_HAIR[f.browColor]
|
|
3077
|
+
const outfit = F_OUTFIT[f.outfit]
|
|
3078
|
+
const o = faceOutline(f)
|
|
3079
|
+
|
|
3080
|
+
const eyeY = o.cy + 8 + f.eyeHeight * 0.1
|
|
3081
|
+
const eyeX = 21 + f.eyeSpacing * 0.1
|
|
3082
|
+
const eyeRx = (real ? 6.6 : 9.6) + f.eyeSize * 0.042
|
|
3083
|
+
const eyeRy = (real ? 4.6 : 7.0) + f.eyeSize * 0.028
|
|
3084
|
+
const eyeTilt = f.eyeTilt * 0.09
|
|
3085
|
+
const irisR = Math.min(eyeRx * 0.78, (real ? 4.2 : 6.2) + f.eyePupil * 0.008)
|
|
3086
|
+
const browY = eyeY - (real ? 12 : 14) - f.browHeight * 0.08
|
|
3087
|
+
const browThick = (real ? 2.0 : 2.6) + f.browThick * 0.022
|
|
3088
|
+
const browW = eyeRx * 1.55
|
|
3089
|
+
const noseY = eyeY + 20 + f.noseLength * 0.1
|
|
3090
|
+
const noseW = 4 + f.noseWidth * 0.035
|
|
3091
|
+
const mouthY = o.chinY - 20 + f.mouthHeight * 0.06
|
|
3092
|
+
const mouthW = 12 + f.mouthWidth * 0.09
|
|
3093
|
+
const smile = f.mouthSmile * 0.09
|
|
3094
|
+
const lipFull = 2.8 + f.mouthFull * 0.035
|
|
3095
|
+
const earRy = 10 + f.earSize * 0.05
|
|
3096
|
+
const earTilt = f.earAngle * 0.2
|
|
3097
|
+
|
|
3098
|
+
const eye = (side) =>
|
|
3099
|
+
h(
|
|
3100
|
+
'g',
|
|
3101
|
+
{ transform: 'translate(' + (o.cx + side * eyeX) + ',' + eyeY + ') rotate(' + side * eyeTilt + ')' },
|
|
3102
|
+
h('ellipse', { rx: eyeRx, ry: eyeRy, fill: '#fdfdfd' }),
|
|
3103
|
+
h('ellipse', { cx: side * 0.6, cy: 0.4, rx: irisR, ry: irisR, fill: eyeCol }),
|
|
3104
|
+
h('ellipse', { cx: side * 0.6, cy: 0.4, rx: irisR * 0.42, ry: irisR * 0.42, fill: '#16181a' }),
|
|
3105
|
+
h('circle', { cx: side * 0.6 + irisR * 0.32, cy: -irisR * 0.3, r: Math.max(0.7, irisR * 0.18), fill: '#fff' }),
|
|
3106
|
+
f.eyeLid > 8
|
|
3107
|
+
? h('path', {
|
|
3108
|
+
d: 'M ' + -eyeRx + ' 0 Q 0 ' + -eyeRy * (1 + f.eyeLid * 0.004) + ' ' + eyeRx + ' 0',
|
|
3109
|
+
fill: 'none',
|
|
3110
|
+
stroke: skinDark,
|
|
3111
|
+
strokeWidth: 1.4 + f.eyeLid * 0.01,
|
|
3112
|
+
})
|
|
3113
|
+
: null,
|
|
3114
|
+
f.eyeliner > 6
|
|
3115
|
+
? h('path', {
|
|
3116
|
+
d: 'M ' + -eyeRx + ' -1 Q 0 ' + -eyeRy * 1.08 + ' ' + (eyeRx + 1.6) + ' -2.4',
|
|
3117
|
+
fill: 'none',
|
|
3118
|
+
stroke: '#2a2320',
|
|
3119
|
+
strokeWidth: 0.8 + f.eyeliner * 0.02,
|
|
3120
|
+
strokeLinecap: 'round',
|
|
3121
|
+
})
|
|
3122
|
+
: null,
|
|
3123
|
+
)
|
|
3124
|
+
|
|
3125
|
+
const brow = (side) =>
|
|
3126
|
+
h('path', {
|
|
3127
|
+
d:
|
|
3128
|
+
'M ' + (o.cx + side * eyeX - browW) + ' ' + (browY + side * f.browTilt * 0.03) +
|
|
3129
|
+
' Q ' + (o.cx + side * eyeX) + ' ' + (browY - browW * 0.42 - f.browArch * 0.1) + ' ' +
|
|
3130
|
+
(o.cx + side * eyeX + browW) + ' ' + (browY - 1.5),
|
|
3131
|
+
fill: 'none',
|
|
3132
|
+
stroke: browCol,
|
|
3133
|
+
strokeWidth: browThick,
|
|
3134
|
+
strokeLinecap: 'round',
|
|
3135
|
+
opacity: real ? 0.92 : 1,
|
|
3136
|
+
})
|
|
3137
|
+
|
|
3138
|
+
const hatNode =
|
|
3139
|
+
f.hat === 'cap'
|
|
3140
|
+
? h('g', null,
|
|
3141
|
+
h('path', { d: 'M ' + (o.cx - o.rx) + ' ' + (o.top + 8) + ' C ' + (o.cx - o.rx + 4) + ' ' + (o.top - 22) + ',' + (o.cx + o.rx - 4) + ' ' + (o.top - 22) + ',' + (o.cx + o.rx) + ' ' + (o.top + 8) + ' Z', fill: '#247bbf' }),
|
|
3142
|
+
h('rect', { x: o.cx + 6, y: o.top + 4, width: o.rx + 6, height: 4.6, rx: 2.3, fill: '#1f6cab' }))
|
|
3143
|
+
: f.hat === 'beanie'
|
|
3144
|
+
? h('g', null,
|
|
3145
|
+
h('path', { d: 'M ' + (o.cx - o.rx) + ' ' + (o.top + 10) + ' C ' + (o.cx - o.rx + 2) + ' ' + (o.top - 26) + ',' + (o.cx + o.rx - 2) + ' ' + (o.top - 26) + ',' + (o.cx + o.rx) + ' ' + (o.top + 10) + ' Z', fill: '#d0693b' }),
|
|
3146
|
+
h('rect', { x: o.cx - o.rx - 1, y: o.top + 6, width: o.rx * 2 + 2, height: 6, rx: 3, fill: '#b3572f' }),
|
|
3147
|
+
h('circle', { cx: o.cx, cy: o.top - 24, r: 4, fill: '#f3d9a4' }))
|
|
3148
|
+
: f.hat === 'halo'
|
|
3149
|
+
? h('ellipse', { cx: o.cx, cy: o.top - 16, rx: 16, ry: 3.6, fill: 'none', stroke: '#f4d06f', strokeWidth: 3 })
|
|
3150
|
+
: null
|
|
3151
|
+
|
|
3152
|
+
const glassesNode =
|
|
3153
|
+
f.glasses === 'round'
|
|
3154
|
+
? h('g', { fill: 'none', stroke: '#c9d6de', strokeWidth: 2, opacity: 0.9 },
|
|
3155
|
+
h('circle', { cx: o.cx - eyeX, cy: eyeY, r: eyeRx + 3 }),
|
|
3156
|
+
h('circle', { cx: o.cx + eyeX, cy: eyeY, r: eyeRx + 3 }),
|
|
3157
|
+
h('path', { d: 'M ' + (o.cx - eyeX + eyeRx + 3) + ' ' + eyeY + ' L ' + (o.cx + eyeX - eyeRx - 3) + ' ' + eyeY }))
|
|
3158
|
+
: f.glasses === 'square'
|
|
3159
|
+
? h('g', { fill: 'none', stroke: '#2a2f33', strokeWidth: 2, opacity: 0.9 },
|
|
3160
|
+
h('rect', { x: o.cx - eyeX - eyeRx - 3, y: eyeY - eyeRy - 2, width: (eyeRx + 3) * 2, height: (eyeRy + 2) * 2, rx: 3 }),
|
|
3161
|
+
h('rect', { x: o.cx + eyeX - eyeRx - 3, y: eyeY - eyeRy - 2, width: (eyeRx + 3) * 2, height: (eyeRy + 2) * 2, rx: 3 }),
|
|
3162
|
+
h('path', { d: 'M ' + (o.cx - eyeX + eyeRx + 3) + ' ' + eyeY + ' L ' + (o.cx + eyeX - eyeRx - 3) + ' ' + eyeY }))
|
|
3163
|
+
: null
|
|
3164
|
+
|
|
3165
|
+
const hairStyle = Number(f.hairStyle) || 0
|
|
3166
|
+
const fringe = 6 + f.fringe * 0.16
|
|
3167
|
+
const hairlineY = o.cy - 30 + f.fringe * 0.24
|
|
3168
|
+
const backHair =
|
|
3169
|
+
hairStyle === 2 || hairStyle === 7
|
|
3170
|
+
? h('path', {
|
|
3171
|
+
d: 'M ' + (o.cx - o.rx - 6) + ' ' + (o.top + 10) + ' C ' + (o.cx - o.rx - 18) + ' ' + (o.cy + 40) + ',' + (o.cx - o.rx - 12) + ' ' + (o.chinY + 26) + ',' + o.cx + ' ' + (o.chinY + 30) + ' C ' + (o.cx + o.rx + 12) + ' ' + (o.chinY + 26) + ',' + (o.cx + o.rx + 18) + ' ' + (o.cy + 40) + ',' + (o.cx + o.rx + 6) + ' ' + (o.top + 10) + ' Z',
|
|
3172
|
+
fill: 'url(#' + uid + 'hair)',
|
|
3173
|
+
})
|
|
3174
|
+
: hairStyle === 1
|
|
3175
|
+
? h('path', {
|
|
3176
|
+
d: 'M ' + (o.cx - o.rx - 4) + ' ' + (o.top + 12) + ' C ' + (o.cx - o.rx - 10) + ' ' + (o.cy + 26) + ',' + (o.cx - o.rx) + ' ' + (o.chinY - 16) + ',' + o.cx + ' ' + (o.chinY - 14) + ' C ' + (o.cx + o.rx) + ' ' + (o.chinY - 16) + ',' + (o.cx + o.rx + 10) + ' ' + (o.cy + 26) + ',' + (o.cx + o.rx + 4) + ' ' + (o.top + 12) + ' Z',
|
|
3177
|
+
fill: 'url(#' + uid + 'hair)',
|
|
3178
|
+
})
|
|
3179
|
+
: hairStyle === 3
|
|
3180
|
+
? h('path', {
|
|
3181
|
+
d: 'M ' + (o.cx + o.rx - 2) + ' ' + (o.top + 6) + ' C ' + (o.cx + o.rx + 16) + ' ' + (o.cy) + ',' + (o.cx + o.rx + 10) + ' ' + (o.chinY - 10) + ',' + (o.cx + o.rx - 8) + ' ' + (o.chinY - 18) + ' C ' + (o.cx + o.rx) + ' ' + (o.cy + 6) + ',' + (o.cx + o.rx) + ' ' + (o.top + 22) + ',' + (o.cx + o.rx - 2) + ' ' + (o.top + 6) + ' Z',
|
|
3182
|
+
fill: 'url(#' + uid + 'hair)',
|
|
3183
|
+
})
|
|
3184
|
+
: null
|
|
3185
|
+
|
|
3186
|
+
const hairCap = h(
|
|
3187
|
+
'g',
|
|
3188
|
+
{ clipPath: 'url(#' + uid + 'headclip)' },
|
|
3189
|
+
h('rect', { x: o.cx - o.rx - 2, y: o.top - 30, width: o.rx * 2 + 4, height: hairlineY - (o.top - 30), fill: 'url(#' + uid + 'hair)' }),
|
|
3190
|
+
hairStyle === 5
|
|
3191
|
+
? null
|
|
3192
|
+
: h('path', {
|
|
3193
|
+
d: 'M ' + (o.cx - o.rx) + ' ' + (hairlineY - 10) +
|
|
3194
|
+
' C ' + (o.cx - o.rx * 0.55) + ' ' + (hairlineY + 10 + fringe * 0.2) + ',' + (o.cx - o.rx * 0.2) + ' ' + (hairlineY - 6) + ',' + o.cx + ' ' + (hairlineY - 2) +
|
|
3195
|
+
' C ' + (o.cx + o.rx * 0.25) + ' ' + (hairlineY + 8) + ',' + (o.cx + o.rx * 0.6) + ' ' + (hairlineY + 8 + fringe * 0.18) + ',' + (o.cx + o.rx) + ' ' + (hairlineY - 12) +
|
|
3196
|
+
' L ' + (o.cx + o.rx) + ' ' + (o.top - 20) + ' L ' + (o.cx - o.rx) + ' ' + (o.top - 20) + ' Z',
|
|
3197
|
+
fill: 'url(#' + uid + 'hair)',
|
|
3198
|
+
}),
|
|
3199
|
+
)
|
|
3200
|
+
|
|
3201
|
+
const bodyW = 40 + f.build * 0.14
|
|
3202
|
+
const bodyNode = h(
|
|
3203
|
+
'g',
|
|
3204
|
+
null,
|
|
3205
|
+
h('rect', { x: o.cx - 12, y: o.chinY - 10, width: 24, height: 34, rx: 8, fill: skinDark }),
|
|
3206
|
+
h('path', {
|
|
3207
|
+
d: 'M ' + (o.cx - bodyW) + ' 280 C ' + (o.cx - bodyW + 2) + ' ' + (o.chinY + 26) + ',' + (o.cx - 20) + ' ' + (o.chinY + 16) + ',' + o.cx + ' ' + (o.chinY + 16) +
|
|
3208
|
+
' C ' + (o.cx + 20) + ' ' + (o.chinY + 16) + ',' + (o.cx + bodyW - 2) + ' ' + (o.chinY + 26) + ',' + (o.cx + bodyW) + ' 280 Z',
|
|
3209
|
+
fill: outfit,
|
|
3210
|
+
}),
|
|
3211
|
+
h('path', { d: 'M ' + (o.cx - 11) + ' ' + (o.chinY + 15) + ' L ' + o.cx + ' ' + (o.chinY + 30) + ' L ' + (o.cx + 11) + ' ' + (o.chinY + 15) + ' Z', fill: shade(outfit, 22), opacity: 0.85 }),
|
|
3212
|
+
)
|
|
3213
|
+
|
|
3214
|
+
return h(
|
|
3215
|
+
'svg',
|
|
3216
|
+
{ className: 'sc-char-svg', width: size, height: Math.round(size * 1.4), viewBox: '0 0 200 280', role: 'img', 'aria-label': 'character' },
|
|
3217
|
+
h(
|
|
3218
|
+
'defs',
|
|
3219
|
+
null,
|
|
3220
|
+
h('radialGradient', { id: uid + 'sh', cx: '38%', cy: '30%', r: '72%' },
|
|
3221
|
+
h('stop', { offset: '0%', stopColor: '#ffffff', stopOpacity: real ? 0.20 : 0.14 }),
|
|
3222
|
+
h('stop', { offset: '62%', stopColor: '#ffffff', stopOpacity: 0 }),
|
|
3223
|
+
h('stop', { offset: '100%', stopColor: '#000000', stopOpacity: real ? 0.24 : 0.16 })),
|
|
3224
|
+
h('linearGradient', { id: uid + 'hair', x1: '0', y1: '0', x2: '0', y2: '1' },
|
|
3225
|
+
h('stop', { offset: '0%', stopColor: shade(hair, 16) }),
|
|
3226
|
+
h('stop', { offset: '100%', stopColor: shade(hair, -14) })),
|
|
3227
|
+
h('clipPath', { id: uid + 'headclip' }, h('path', { d: o.d })),
|
|
3228
|
+
),
|
|
3229
|
+
h(
|
|
3230
|
+
'g',
|
|
3231
|
+
{ transform: 'translate(100,0) scale(' + sx + ',1) translate(-100,0)' },
|
|
3232
|
+
bodyNode,
|
|
3233
|
+
backHair,
|
|
3234
|
+
h('ellipse', { cx: o.cx, cy: o.chinY + 4, rx: o.jawW * 0.9, ry: 12, fill: '#000', opacity: 0.10 }),
|
|
3235
|
+
h('path', { d: o.d, fill: skin }),
|
|
3236
|
+
h('path', { d: o.d, fill: 'url(#' + uid + 'sh)' }),
|
|
3237
|
+
hairCap,
|
|
3238
|
+
real
|
|
3239
|
+
? h('g', null,
|
|
3240
|
+
h('ellipse', { cx: o.cx - eyeX, cy: eyeY - 2, rx: eyeRx * 1.5, ry: eyeRy * 1.6, fill: '#000', opacity: 0.06 }),
|
|
3241
|
+
h('ellipse', { cx: o.cx + eyeX, cy: eyeY - 2, rx: eyeRx * 1.5, ry: eyeRy * 1.6, fill: '#000', opacity: 0.06 }),
|
|
3242
|
+
h('ellipse', { cx: o.cx - o.rx * 0.55, cy: o.cy + 30, rx: 12, ry: 8, fill: '#000', opacity: 0.05 }),
|
|
3243
|
+
h('ellipse', { cx: o.cx + o.rx * 0.55, cy: o.cy + 30, rx: 12, ry: 8, fill: '#000', opacity: 0.05 }),
|
|
3244
|
+
h('path', { d: 'M ' + (o.cx - noseW - 0.5) + ' ' + (noseY - 12) + ' Q ' + (o.cx - noseW - 3) + ' ' + (noseY + 2) + ' ' + (o.cx - noseW) + ' ' + (noseY + 5), fill: 'none', stroke: '#000', strokeWidth: 1.6, opacity: 0.08 }),
|
|
3245
|
+
h('path', { d: 'M ' + (o.cx + noseW + 0.5) + ' ' + (noseY - 12) + ' Q ' + (o.cx + noseW + 3) + ' ' + (noseY + 2) + ' ' + (o.cx + noseW) + ' ' + (noseY + 5), fill: 'none', stroke: '#000', strokeWidth: 1.6, opacity: 0.08 }))
|
|
3246
|
+
: null,
|
|
3247
|
+
h('ellipse', { cx: o.cx - o.rx * 0.62, cy: o.cy + 18, rx: 10, ry: 6, fill: '#e2735f', opacity: f.blush / 100 * 0.28 }),
|
|
3248
|
+
h('ellipse', { cx: o.cx + o.rx * 0.62, cy: o.cy + 18, rx: 10, ry: 6, fill: '#e2735f', opacity: f.blush / 100 * 0.28 }),
|
|
3249
|
+
h('ellipse', { cx: o.cx - o.rx, cy: o.cy + 12, rx: 6, ry: earRy, fill: skin, transform: 'rotate(' + (-earTilt) + ' ' + (o.cx - o.rx) + ' ' + (o.cy + 12) + ')' }),
|
|
3250
|
+
h('ellipse', { cx: o.cx + o.rx, cy: o.cy + 12, rx: 6, ry: earRy, fill: skin, transform: 'rotate(' + earTilt + ' ' + (o.cx + o.rx) + ' ' + (o.cy + 12) + ')' }),
|
|
3251
|
+
f.earring === 'dot' ? h('circle', { cx: o.cx + o.rx + 1, cy: o.cy + 24, r: 2.6, fill: '#f4d06f' }) : null,
|
|
3252
|
+
h('path', { d: 'M ' + (o.cx - noseW) + ' ' + (noseY + 4) + ' Q ' + o.cx + ' ' + (noseY + 9) + ' ' + (o.cx + noseW) + ' ' + (noseY + 4), fill: 'none', stroke: skinDark, strokeWidth: real ? 1.8 : 1.4, opacity: 0.75, strokeLinecap: 'round' }),
|
|
3253
|
+
f.noseBridge > 10 ? h('rect', { x: o.cx - 1.6, y: noseY - 16, width: 3.2, height: 16, rx: 1.6, fill: '#fff', opacity: f.noseBridge / 100 * 0.22 }) : null,
|
|
3254
|
+
h('path', {
|
|
3255
|
+
d: 'M ' + (o.cx - mouthW) + ' ' + mouthY + ' Q ' + o.cx + ' ' + (mouthY + lipFull + smile) + ' ' + (o.cx + mouthW) + ' ' + mouthY,
|
|
3256
|
+
fill: 'none',
|
|
3257
|
+
stroke: lipColor(f.lip),
|
|
3258
|
+
strokeWidth: lipFull,
|
|
3259
|
+
strokeLinecap: 'round',
|
|
3260
|
+
}),
|
|
3261
|
+
eye(-1),
|
|
3262
|
+
eye(1),
|
|
3263
|
+
brow(-1),
|
|
3264
|
+
brow(1),
|
|
3265
|
+
hatNode,
|
|
3266
|
+
glassesNode,
|
|
3267
|
+
),
|
|
3268
|
+
)
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
const C_HAIR = ['#3d4c8c', '#2b3560', '#5b6bb0', '#8a5a3c', '#d9b25f', '#b04a63', '#7a5aa8', '#4a8b8f']
|
|
3272
|
+
const C_EYE = ['#4a63b0', '#2f7a6a', '#8a4a7a', '#5a4a3a', '#3d5a80', '#7a5a2f']
|
|
3273
|
+
const C_OUTFIT = ['#2f3a63', '#eef2fb', '#7fb3e0', '#63c2b0', '#d98aa0', '#c9a227', '#8a5ec9', '#d0693b']
|
|
3274
|
+
|
|
3275
|
+
/** Q 版鲸鱼娘:厚描边 + 大眼 + 圆润剪影 */
|
|
3276
|
+
function ChibiFace(props) {
|
|
3277
|
+
const f = normalizeFace(props.face, props.id)
|
|
3278
|
+
const size = props.size || 120
|
|
3279
|
+
const angle = Math.max(-28, Math.min(28, Number(props.angle) || 0))
|
|
3280
|
+
const rad = (angle * Math.PI) / 180
|
|
3281
|
+
const sx = Math.max(0.5, Math.cos(rad))
|
|
3282
|
+
const uid = 'c' + (props.uid || Math.abs(charHash(JSON.stringify(f))).toString(36))
|
|
3283
|
+
const ink = '#252b45'
|
|
3284
|
+
const hair = C_HAIR[f.hairColor % C_HAIR.length]
|
|
3285
|
+
const hairLo = shade(hair, -14)
|
|
3286
|
+
const hairHi = shade(hair, 42)
|
|
3287
|
+
const skin = F_SKIN[f.skinTone]
|
|
3288
|
+
const skinLo = shade(skin, -14)
|
|
3289
|
+
const outfit = C_OUTFIT[f.outfit % C_OUTFIT.length]
|
|
3290
|
+
const iris = C_EYE[f.eyeColor % C_EYE.length]
|
|
3291
|
+
|
|
3292
|
+
const cx = 120
|
|
3293
|
+
const cy = 128
|
|
3294
|
+
const rx = 64 + f.faceWidth * 0.07 + f.cheek * 0.02
|
|
3295
|
+
const ry = 66 + f.chin * 0.03
|
|
3296
|
+
const eyeScale = 1 + f.eyeSize * 0.0045
|
|
3297
|
+
const eyeX = 29 + f.eyeSpacing * 0.07
|
|
3298
|
+
const eyeY = cy + 22 + f.eyeHeight * 0.06
|
|
3299
|
+
const eyeRx = 17 * eyeScale
|
|
3300
|
+
const eyeRy = 19.5 * eyeScale
|
|
3301
|
+
const tilt = f.eyeTilt * 0.1
|
|
3302
|
+
const mouthY = cy + 52 + f.mouthHeight * 0.03
|
|
3303
|
+
const smile = f.mouthSmile * 0.05
|
|
3304
|
+
const hairStyle = Number(f.hairStyle) || 0
|
|
3305
|
+
const hat = f.hat
|
|
3306
|
+
|
|
3307
|
+
const eye = (side) =>
|
|
3308
|
+
h(
|
|
3309
|
+
'g',
|
|
3310
|
+
{ transform: 'translate(' + (cx + side * eyeX) + ',' + eyeY + ') rotate(' + side * tilt + ')' },
|
|
3311
|
+
h('ellipse', { rx: eyeRx + 1.2, ry: eyeRy + 1.2, fill: '#fdfeff', stroke: ink, strokeWidth: 1.3 }),
|
|
3312
|
+
h('ellipse', { rx: eyeRx * 0.92, ry: eyeRy * 0.93, fill: 'url(#' + uid + 'iris)' }),
|
|
3313
|
+
h('ellipse', { cx: 0, cy: eyeRy * 0.12, rx: eyeRx * 0.48, ry: eyeRy * 0.5, fill: '#1b2140' }),
|
|
3314
|
+
h('ellipse', { cx: -eyeRx * 0.22, cy: -eyeRy * 0.4, rx: eyeRx * 0.36, ry: eyeRy * 0.24, fill: '#eaf6ff', opacity: 0.95 }),
|
|
3315
|
+
h('circle', { cx: -eyeRx * 0.46, cy: -eyeRy * 0.04, r: eyeRx * 0.19, fill: '#ffffff' }),
|
|
3316
|
+
h('circle', { cx: eyeRx * 0.32, cy: eyeRy * 0.44, r: eyeRx * 0.12, fill: '#ffffff', opacity: 0.9 }),
|
|
3317
|
+
h('circle', { cx: eyeRx * 0.46, cy: -eyeRy * 0.48, r: eyeRx * 0.07, fill: '#ffffff', opacity: 0.7 }),
|
|
3318
|
+
h('path', {
|
|
3319
|
+
d: 'M ' + -eyeRx * 1.14 + ' ' + -eyeRy * 0.3 + ' Q 0 ' + -eyeRy * 1.16 + ' ' + eyeRx * 1.14 + ' ' + -eyeRy * 0.18,
|
|
3320
|
+
fill: 'none',
|
|
3321
|
+
stroke: ink,
|
|
3322
|
+
strokeWidth: 4.2 - f.eyeLid * 0.008,
|
|
3323
|
+
strokeLinecap: 'round',
|
|
3324
|
+
}),
|
|
3325
|
+
h('path', {
|
|
3326
|
+
d: 'M ' + eyeRx * 0.88 + ' ' + -eyeRy * 0.46 + ' q 5 -5 8 -9',
|
|
3327
|
+
fill: 'none',
|
|
3328
|
+
stroke: ink,
|
|
3329
|
+
strokeWidth: 2.6,
|
|
3330
|
+
strokeLinecap: 'round',
|
|
3331
|
+
}),
|
|
3332
|
+
f.eyeliner > 25
|
|
3333
|
+
? h('path', {
|
|
3334
|
+
d: 'M ' + -eyeRx * 1.0 + ' ' + eyeRy * 0.84 + ' Q 0 ' + eyeRy * 1.12 + ' ' + eyeRx * 0.96 + ' ' + eyeRy * 0.68,
|
|
3335
|
+
fill: 'none',
|
|
3336
|
+
stroke: ink,
|
|
3337
|
+
strokeWidth: 1.5,
|
|
3338
|
+
opacity: 0.38,
|
|
3339
|
+
strokeLinecap: 'round',
|
|
3340
|
+
})
|
|
3341
|
+
: null,
|
|
3342
|
+
)
|
|
3343
|
+
|
|
3344
|
+
// 后发:一整块圆润的披发,到肩部收住
|
|
3345
|
+
const backHair = h('path', {
|
|
3346
|
+
d:
|
|
3347
|
+
'M ' + (cx - rx - 4) + ' ' + (cy - 18) +
|
|
3348
|
+
' C ' + (cx - rx - 16) + ' ' + (cy + 50) + ' ' + (cx - rx - 12) + ' ' + (cy + 100) + ' ' + (cx - rx + 6) + ' ' + (cy + (hairStyle === 5 ? 96 : 128)) +
|
|
3349
|
+
' C ' + (cx - 24) + ' ' + (cy + (hairStyle === 5 ? 68 : 102)) + ' ' + (cx + 24) + ' ' + (cy + (hairStyle === 5 ? 68 : 102)) + ' ' + (cx + rx - 8) + ' ' + (cy + (hairStyle === 5 ? 60 : 92)) +
|
|
3350
|
+
' C ' + (cx + rx + 10) + ' ' + (cy + 76) + ' ' + (cx + rx + 16) + ' ' + (cy + 50) + ' ' + (cx + rx + 4) + ' ' + (cy - 18) +
|
|
3351
|
+
' C ' + (cx + 40) + ' ' + (cy - ry - 22) + ' ' + (cx - 40) + ' ' + (cy - ry - 22) + ' ' + (cx - rx - 4) + ' ' + (cy - 18) + ' Z',
|
|
3352
|
+
fill: hairLo,
|
|
3353
|
+
stroke: ink,
|
|
3354
|
+
strokeWidth: 3.4,
|
|
3355
|
+
strokeLinejoin: 'round',
|
|
3356
|
+
})
|
|
3357
|
+
|
|
3358
|
+
const twinTails =
|
|
3359
|
+
hairStyle === 2 || hairStyle === 7
|
|
3360
|
+
? h('g', null,
|
|
3361
|
+
h('path', { d: 'M ' + (cx - rx + 2) + ' ' + (cy + 4) + ' C ' + (cx - rx - 30) + ' ' + (cy + 50) + ' ' + (cx - rx - 24) + ' ' + (cy + 110) + ' ' + (cx - rx + 4) + ' ' + (cy + 136) + ' C ' + (cx - rx + 2) + ' ' + (cy + 90) + ' ' + (cx - rx + 8) + ' ' + (cy + 44) + ' ' + (cx - rx + 22) + ' ' + (cy + 2) + ' Z', fill: hair, stroke: ink, strokeWidth: 3.2, strokeLinejoin: 'round' }),
|
|
3362
|
+
h('path', { d: 'M ' + (cx + rx - 2) + ' ' + (cy + 4) + ' C ' + (cx + rx + 30) + ' ' + (cy + 50) + ' ' + (cx + rx + 24) + ' ' + (cy + 110) + ' ' + (cx + rx - 4) + ' ' + (cy + 136) + ' C ' + (cx + rx - 2) + ' ' + (cy + 90) + ' ' + (cx + rx - 8) + ' ' + (cy + 44) + ' ' + (cx + rx - 22) + ' ' + (cy + 2) + ' Z', fill: hair, stroke: ink, strokeWidth: 3.2, strokeLinejoin: 'round' }))
|
|
3363
|
+
: null
|
|
3364
|
+
|
|
3365
|
+
const fin = (side) =>
|
|
3366
|
+
h(
|
|
3367
|
+
'g',
|
|
3368
|
+
{ transform: 'translate(' + (cx + side * (rx + 2)) + ',' + (cy + 34) + ') scale(' + side + ',1) rotate(10)' },
|
|
3369
|
+
h('path', {
|
|
3370
|
+
d: 'M 0 0 C 12 -9 26 -2 30 12 C 21 16 9 12 0 5 Z',
|
|
3371
|
+
fill: hairHi,
|
|
3372
|
+
stroke: ink,
|
|
3373
|
+
strokeWidth: 2.8,
|
|
3374
|
+
strokeLinejoin: 'round',
|
|
3375
|
+
}),
|
|
3376
|
+
)
|
|
3377
|
+
|
|
3378
|
+
const head = h('ellipse', { cx: cx, cy: cy, rx: rx, ry: ry, fill: skin, stroke: ink, strokeWidth: 3.4 })
|
|
3379
|
+
|
|
3380
|
+
// 刘海:柔和波浪
|
|
3381
|
+
const bangs = h(
|
|
3382
|
+
'g',
|
|
3383
|
+
null,
|
|
3384
|
+
h('path', {
|
|
3385
|
+
d:
|
|
3386
|
+
'M ' + (cx - rx - 2) + ' ' + (cy - 10) +
|
|
3387
|
+
' C ' + (cx - rx - 12) + ' ' + (cy - ry - 16) + ' ' + (cx + rx + 12) + ' ' + (cy - ry - 16) + ' ' + (cx + rx + 2) + ' ' + (cy - 10) +
|
|
3388
|
+
' Q ' + (cx + rx * 0.82) + ' ' + (cy - 4) + ' ' + (cx + rx * 0.66) + ' ' + (cy - 18) +
|
|
3389
|
+
' Q ' + (cx + rx * 0.48) + ' ' + (cy - 30) + ' ' + (cx + rx * 0.3) + ' ' + (cy - 16) +
|
|
3390
|
+
' Q ' + (cx + rx * 0.12) + ' ' + (cy - 4) + ' ' + (cx - rx * 0.06) + ' ' + (cy - 18) +
|
|
3391
|
+
' Q ' + (cx - rx * 0.24) + ' ' + (cy - 30) + ' ' + (cx - rx * 0.42) + ' ' + (cy - 16) +
|
|
3392
|
+
' Q ' + (cx - rx * 0.6) + ' ' + (cy - 4) + ' ' + (cx - rx * 0.76) + ' ' + (cy - 18) +
|
|
3393
|
+
' Q ' + (cx - rx * 0.9) + ' ' + (cy - 26) + ' ' + (cx - rx - 2) + ' ' + (cy - 10) + ' Z',
|
|
3394
|
+
fill: hair,
|
|
3395
|
+
stroke: ink,
|
|
3396
|
+
strokeWidth: 3.2,
|
|
3397
|
+
strokeLinejoin: 'round',
|
|
3398
|
+
}),
|
|
3399
|
+
h('path', { d: 'M ' + (cx - rx * 0.34) + ' ' + (cy - ry + 8) + ' q 18 -8 34 -2 q -16 10 -34 2 Z', fill: hairHi, opacity: 0.9 }),
|
|
3400
|
+
h('path', { d: 'M ' + (cx + 8) + ' ' + (cy - ry + 4) + ' q 22 -5 34 5 q -20 6 -34 -5 Z', fill: hairHi, opacity: 0.75 }),
|
|
3401
|
+
h('path', { d: 'M ' + (cx - rx * 0.8) + ' ' + (cy - ry + 24) + ' q 13 -6 23 0 q -13 8 -23 0 Z', fill: hairHi, opacity: 0.55 }),
|
|
3402
|
+
)
|
|
3403
|
+
|
|
3404
|
+
const sideLock = (side) =>
|
|
3405
|
+
h('path', {
|
|
3406
|
+
d: 'M ' + (cx + side * (rx - 3)) + ' ' + (cy - 16) +
|
|
3407
|
+
' C ' + (cx + side * (rx + 13)) + ' ' + (cy + 34) + ' ' + (cx + side * (rx + 9)) + ' ' + (cy + 74) + ' ' + (cx + side * (rx - 2)) + ' ' + (cy + 96) +
|
|
3408
|
+
' C ' + (cx + side * (rx - 5)) + ' ' + (cy + 58) + ' ' + (cx + side * (rx - 8)) + ' ' + (cy + 18) + ' ' + (cx + side * (rx - 10)) + ' ' + (cy - 16) + ' Z',
|
|
3409
|
+
fill: hair,
|
|
3410
|
+
stroke: ink,
|
|
3411
|
+
strokeWidth: 3.2,
|
|
3412
|
+
strokeLinejoin: 'round',
|
|
3413
|
+
})
|
|
3414
|
+
|
|
3415
|
+
const ahoge = h('path', {
|
|
3416
|
+
d: 'M ' + (cx - 2) + ' ' + (cy - ry - 6) + ' C ' + (cx + 8) + ' ' + (cy - ry - 34) + ' ' + (cx + 38) + ' ' + (cy - ry - 38) + ' ' + (cx + 44) + ' ' + (cy - ry - 18) + ' C ' + (cx + 36) + ' ' + (cy - ry - 28) + ' ' + (cx + 14) + ' ' + (cy - ry - 16) + ' ' + (cx + 8) + ' ' + (cy - ry + 2) + ' Z',
|
|
3417
|
+
fill: hair,
|
|
3418
|
+
stroke: ink,
|
|
3419
|
+
strokeWidth: 2.8,
|
|
3420
|
+
strokeLinejoin: 'round',
|
|
3421
|
+
})
|
|
3422
|
+
|
|
3423
|
+
// 女仆头饰:一排白色小花边
|
|
3424
|
+
const frill =
|
|
3425
|
+
hat === 'cap'
|
|
3426
|
+
? h('g', null,
|
|
3427
|
+
h('path', {
|
|
3428
|
+
d: 'M ' + (cx - 54) + ' ' + (cy - ry + 22) + ' C ' + (cx - 40) + ' ' + (cy - ry - 14) + ' ' + (cx + 40) + ' ' + (cy - ry - 14) + ' ' + (cx + 54) + ' ' + (cy - ry + 22),
|
|
3429
|
+
fill: 'none', stroke: '#ffffff', strokeWidth: 12, strokeLinecap: 'round',
|
|
3430
|
+
}),
|
|
3431
|
+
h('g', { fill: '#ffffff', stroke: '#dbe4f5', strokeWidth: 1.6 },
|
|
3432
|
+
[-46, -30, -14, 2, 18, 34, 46].map((dx, i) =>
|
|
3433
|
+
h('circle', { key: i, cx: cx + dx, cy: cy - ry + 8 + Math.abs(dx) * 0.28, r: 6.4 }))))
|
|
3434
|
+
: hat === 'beanie'
|
|
3435
|
+
? h('path', {
|
|
3436
|
+
d: 'M ' + (cx - 54) + ' ' + (cy - ry + 20) + ' C ' + (cx - 46) + ' ' + (cy - ry - 28) + ' ' + (cx + 46) + ' ' + (cy - ry - 28) + ' ' + (cx + 54) + ' ' + (cy - ry + 20) + ' Z',
|
|
3437
|
+
fill: '#7fb3e0', stroke: ink, strokeWidth: 3.2,
|
|
3438
|
+
})
|
|
3439
|
+
: hat === 'halo'
|
|
3440
|
+
? h('ellipse', { cx: cx, cy: cy - ry - 22, rx: 22, ry: 5, fill: 'none', stroke: '#f4d06f', strokeWidth: 4 })
|
|
3441
|
+
: null
|
|
3442
|
+
|
|
3443
|
+
const bowAtSide = h('g', { transform: 'translate(' + (cx + rx - 10) + ',' + (cy + 2) + ')' },
|
|
3444
|
+
h('path', { d: 'M 0 0 C -11 -9 -20 -6 -20 2 C -20 10 -11 11 0 0 Z', fill: '#8fc0ea', stroke: ink, strokeWidth: 2.4, strokeLinejoin: 'round' }),
|
|
3445
|
+
h('path', { d: 'M 0 0 C 11 -9 20 -6 20 2 C 20 10 11 11 0 0 Z', fill: '#8fc0ea', stroke: ink, strokeWidth: 2.4, strokeLinejoin: 'round' }),
|
|
3446
|
+
h('circle', { cx: 0, cy: 1, r: 4, fill: '#5a86c9', stroke: ink, strokeWidth: 1.8 }))
|
|
3447
|
+
|
|
3448
|
+
const bodyTop = cy + ry + 6
|
|
3449
|
+
const neck = h('rect', { x: cx - 12, y: cy + ry - 12, width: 24, height: 24, rx: 8, fill: skin, stroke: ink, strokeWidth: 2.8 })
|
|
3450
|
+
const body = h('g', null,
|
|
3451
|
+
h('path', {
|
|
3452
|
+
d: 'M ' + (cx - 52 - f.build * 0.1) + ' 300 C ' + (cx - 50) + ' ' + (bodyTop + 16) + ' ' + (cx - 34) + ' ' + (bodyTop - 2) + ' ' + cx + ' ' + (bodyTop - 2) +
|
|
3453
|
+
' C ' + (cx + 34) + ' ' + (bodyTop - 2) + ' ' + (cx + 50) + ' ' + (bodyTop + 16) + ' ' + (cx + 52 + f.build * 0.1) + ' 300 Z',
|
|
3454
|
+
fill: outfit,
|
|
3455
|
+
stroke: ink,
|
|
3456
|
+
strokeWidth: 3.4,
|
|
3457
|
+
}),
|
|
3458
|
+
h('path', {
|
|
3459
|
+
d: 'M ' + (cx - 20) + ' ' + bodyTop + ' L ' + cx + ' ' + (bodyTop + 28) + ' L ' + (cx + 20) + ' ' + bodyTop +
|
|
3460
|
+
' C ' + (cx + 11) + ' ' + (bodyTop - 6) + ' ' + (cx - 11) + ' ' + (bodyTop - 6) + ' ' + (cx - 20) + ' ' + bodyTop + ' Z',
|
|
3461
|
+
fill: '#f7f9ff', stroke: ink, strokeWidth: 2.4, strokeLinejoin: 'round',
|
|
3462
|
+
}),
|
|
3463
|
+
h('path', { d: 'M ' + (cx - 8) + ' ' + (bodyTop + 6) + ' L ' + cx + ' ' + (bodyTop + 20) + ' L ' + (cx + 8) + ' ' + (bodyTop + 6) + ' L ' + cx + ' ' + (bodyTop + 12) + ' Z', fill: '#2b3350' }),
|
|
3464
|
+
h('circle', { cx: cx, cy: bodyTop + 26, r: 3.4, fill: '#9fd0ff', stroke: ink, strokeWidth: 1.6 }),
|
|
3465
|
+
h('rect', { x: cx - 60, y: bodyTop + 22, width: 14, height: 40, rx: 7, fill: outfit, stroke: ink, strokeWidth: 3, transform: 'rotate(8 ' + (cx - 53) + ' ' + (bodyTop + 42) + ')' }),
|
|
3466
|
+
h('rect', { x: cx + 46, y: bodyTop + 22, width: 14, height: 40, rx: 7, fill: outfit, stroke: ink, strokeWidth: 3, transform: 'rotate(-8 ' + (cx + 53) + ' ' + (bodyTop + 42) + ')' }),
|
|
3467
|
+
)
|
|
3468
|
+
|
|
3469
|
+
const browY = eyeY - 28 - f.browHeight * 0.04
|
|
3470
|
+
return h(
|
|
3471
|
+
'svg',
|
|
3472
|
+
{ className: 'sc-char-svg', width: size, height: Math.round(size * 1.25), viewBox: '0 0 240 300', role: 'img', 'aria-label': 'character' },
|
|
3473
|
+
h(
|
|
3474
|
+
'defs',
|
|
3475
|
+
null,
|
|
3476
|
+
h('linearGradient', { id: uid + 'iris', x1: '0', y1: '0', x2: '0', y2: '1' },
|
|
3477
|
+
h('stop', { offset: '0%', stopColor: shade(iris, 46) }),
|
|
3478
|
+
h('stop', { offset: '58%', stopColor: iris }),
|
|
3479
|
+
h('stop', { offset: '100%', stopColor: shade(iris, -26) })),
|
|
3480
|
+
),
|
|
3481
|
+
h(
|
|
3482
|
+
'g',
|
|
3483
|
+
{ transform: 'translate(120,0) scale(' + sx + ',1) translate(-120,0)' },
|
|
3484
|
+
twinTails,
|
|
3485
|
+
backHair,
|
|
3486
|
+
body,
|
|
3487
|
+
neck,
|
|
3488
|
+
head,
|
|
3489
|
+
ahoge,
|
|
3490
|
+
h('ellipse', { cx: cx - eyeX - 8, cy: eyeY + 24, rx: 12, ry: 6.5, fill: '#ff9aa8', opacity: f.blush / 100 * 0.5 }),
|
|
3491
|
+
h('ellipse', { cx: cx + eyeX + 8, cy: eyeY + 24, rx: 12, ry: 6.5, fill: '#ff9aa8', opacity: f.blush / 100 * 0.5 }),
|
|
3492
|
+
eye(-1),
|
|
3493
|
+
eye(1),
|
|
3494
|
+
h('ellipse', { cx: cx, cy: mouthY - 9, rx: 3.6, ry: 2.2, fill: skinLo, opacity: 0.45 }),
|
|
3495
|
+
h('path', {
|
|
3496
|
+
d: 'M ' + (cx - 7) + ' ' + mouthY + ' Q ' + (cx - 3.5) + ' ' + (mouthY + 4 + smile) + ' ' + cx + ' ' + mouthY + ' Q ' + (cx + 3.5) + ' ' + (mouthY + 4 + smile) + ' ' + (cx + 7) + ' ' + mouthY,
|
|
3497
|
+
fill: 'none', stroke: '#b8564f', strokeWidth: 2.4, strokeLinecap: 'round',
|
|
3498
|
+
}),
|
|
3499
|
+
bangs,
|
|
3500
|
+
sideLock(-1),
|
|
3501
|
+
sideLock(1),
|
|
3502
|
+
frill,
|
|
3503
|
+
bowAtSide,
|
|
3504
|
+
fin(-1),
|
|
3505
|
+
fin(1),
|
|
3506
|
+
f.earring === 'dot' ? h('circle', { cx: cx + rx + 6, cy: eyeY + 24, r: 2.6, fill: '#f4d06f', stroke: ink, strokeWidth: 1.3 }) : null,
|
|
3507
|
+
),
|
|
3508
|
+
)
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
/** 按画风选渲染器:cartoon = Q 版鲸鱼娘,real = 半写实 */
|
|
3512
|
+
function FaceRender(props) {
|
|
3513
|
+
const f = normalizeFace(props.face, props.id)
|
|
3514
|
+
return f.style === 'real' ? h(FaceSVG, props) : h(ChibiFace, Object.assign({}, props, { face: f }))
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
function lipColor(v) {
|
|
3518
|
+
const t = Math.max(0, Math.min(100, Number(v) || 0)) / 100
|
|
3519
|
+
const a = [214, 120, 112]
|
|
3520
|
+
const b = [150, 52, 66]
|
|
3521
|
+
const c = a.map((x, i) => Math.round(x + (b[i] - x) * t))
|
|
3522
|
+
return 'rgb(' + c.join(',') + ')'
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
function shade(hex, amount) {
|
|
3526
|
+
const m = /^#([0-9a-f]{6})$/i.exec(String(hex || ''))
|
|
3527
|
+
if (!m) return hex
|
|
3528
|
+
const n = parseInt(m[1], 16)
|
|
3529
|
+
const f = (v) => Math.max(0, Math.min(255, v + amount))
|
|
3530
|
+
return '#' + [f((n >> 16) & 255), f((n >> 8) & 255), f(n & 255)].map((v) => v.toString(16).padStart(2, '0')).join('')
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3533
|
+
// ───────────────────────── 会议 ─────────────────────────
|
|
3534
|
+
|
|
3535
|
+
/**
|
|
3536
|
+
* 会议:纯浏览器 WebRTC 网状直连(≤6 人),relay 只做房间状态和 SDP/ICE 转发。
|
|
3537
|
+
* 没有媒体服务器,所以没有时长限制;代价是走 P2P,NAT 太差时需要 TURN。
|
|
3538
|
+
*/
|
|
3539
|
+
const MEET_ICE = [
|
|
3540
|
+
{ urls: ['stun:stun.cloudflare.com:3478', 'stun:stun.l.google.com:19302'] },
|
|
3541
|
+
// 以后加 TURN:{ urls: 'turn:turn.example.com:3478', username: 'u', credential: 'p' }
|
|
3542
|
+
]
|
|
3543
|
+
|
|
3544
|
+
function openMeeting(opts) {
|
|
3545
|
+
const auth = opts.auth
|
|
3546
|
+
const onToast = opts.onToast || (() => {})
|
|
3547
|
+
|
|
3548
|
+
if (typeof RTCPeerConnection === 'undefined') {
|
|
3549
|
+
onToast('这个浏览器不支持 WebRTC,开不了会')
|
|
3550
|
+
return { close() {} }
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3553
|
+
let roomId = ''
|
|
3554
|
+
let peerId = ''
|
|
3555
|
+
let localStream = null
|
|
3556
|
+
let camTrack = null
|
|
3557
|
+
let sharing = false
|
|
3558
|
+
let muted = false
|
|
3559
|
+
let camOn = true
|
|
3560
|
+
let sse = null
|
|
3561
|
+
let closed = false
|
|
3562
|
+
const pcs = new Map() // remotePeerId -> { pc, el, name, pending: [] }
|
|
3563
|
+
const peers = new Map() // remotePeerId -> { id, name, muted, cam, sharing }
|
|
3564
|
+
|
|
3565
|
+
/* ---------- DOM ---------- */
|
|
3566
|
+
const root = document.createElement('div')
|
|
3567
|
+
root.style.cssText = [
|
|
3568
|
+
'position:fixed', 'display:flex', 'flex-direction:column', 'background:#0e1116',
|
|
3569
|
+
'color:#eaf3f6', 'border:1px solid rgba(128,128,128,.45)', 'border-radius:14px',
|
|
3570
|
+
'overflow:hidden', 'box-shadow:0 24px 64px rgba(0,0,0,.5)', 'z-index:2147483646',
|
|
3571
|
+
'font:13px/1.5 -apple-system,Segoe UI,Microsoft YaHei,sans-serif',
|
|
3572
|
+
].join(';')
|
|
3573
|
+
const W0 = Math.min(760, window.innerWidth - 40)
|
|
3574
|
+
const H0 = Math.min(540, window.innerHeight - 80)
|
|
3575
|
+
let pos = { x: Math.max(16, (window.innerWidth - W0) / 2), y: Math.max(48, (window.innerHeight - H0) / 2) }
|
|
3576
|
+
const size = { w: W0, h: H0 }
|
|
3577
|
+
|
|
3578
|
+
const head = document.createElement('div')
|
|
3579
|
+
head.style.cssText =
|
|
3580
|
+
'display:flex;align-items:center;gap:8px;padding:9px 12px;background:rgba(255,255,255,.05);border-bottom:1px solid rgba(128,128,128,.25);cursor:move;user-select:none'
|
|
3581
|
+
const titleEl = document.createElement('strong')
|
|
3582
|
+
titleEl.textContent = '📹 会议'
|
|
3583
|
+
titleEl.style.cssText = 'font-size:13px'
|
|
3584
|
+
const codeEl = document.createElement('span')
|
|
3585
|
+
codeEl.style.cssText = 'font-size:11px;opacity:.6;font-family:ui-monospace,Consolas,monospace'
|
|
3586
|
+
const spacer = document.createElement('span')
|
|
3587
|
+
spacer.style.cssText = 'flex:1'
|
|
3588
|
+
const closeBtn = document.createElement('button')
|
|
3589
|
+
closeBtn.textContent = '关闭'
|
|
3590
|
+
closeBtn.style.cssText =
|
|
3591
|
+
'padding:3px 10px;font-size:11px;border-radius:8px;border:1px solid rgba(255,255,255,.3);background:transparent;color:#eaf3f6;cursor:pointer'
|
|
3592
|
+
head.append(titleEl, codeEl, spacer, closeBtn)
|
|
3593
|
+
|
|
3594
|
+
const stage = document.createElement('div')
|
|
3595
|
+
stage.style.cssText = 'flex:1;min-height:0;display:grid;gap:8px;padding:10px;overflow:auto;grid-template-columns:1fr'
|
|
3596
|
+
|
|
3597
|
+
const tools = document.createElement('div')
|
|
3598
|
+
tools.style.cssText =
|
|
3599
|
+
'display:flex;align-items:center;justify-content:center;gap:8px;padding:9px 12px;border-top:1px solid rgba(128,128,128,.25);background:rgba(0,0,0,.25)'
|
|
3600
|
+
|
|
3601
|
+
const grip = document.createElement('div')
|
|
3602
|
+
grip.style.cssText =
|
|
3603
|
+
'position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;background:linear-gradient(135deg,transparent 50%,rgba(255,255,255,.3) 50%)'
|
|
3604
|
+
|
|
3605
|
+
root.append(head, stage, tools, grip)
|
|
3606
|
+
document.body.appendChild(root)
|
|
3607
|
+
|
|
3608
|
+
function paint() {
|
|
3609
|
+
root.style.left = pos.x + 'px'
|
|
3610
|
+
root.style.top = pos.y + 'px'
|
|
3611
|
+
root.style.width = size.w + 'px'
|
|
3612
|
+
root.style.height = size.h + 'px'
|
|
3613
|
+
}
|
|
3614
|
+
paint()
|
|
3615
|
+
|
|
3616
|
+
/* ---------- 小工具 ---------- */
|
|
3617
|
+
function btn(text, label, onClick, primary) {
|
|
3618
|
+
const b = document.createElement('button')
|
|
3619
|
+
b.textContent = text
|
|
3620
|
+
if (label) b.title = label
|
|
3621
|
+
b.style.cssText =
|
|
3622
|
+
'height:32px;min-width:36px;padding:0 12px;border-radius:10px;cursor:pointer;font:inherit;font-size:12.5px;' +
|
|
3623
|
+
(primary
|
|
3624
|
+
? 'border:0;background:#247bbf;color:#fff'
|
|
3625
|
+
: 'border:1px solid rgba(255,255,255,.22);background:rgba(255,255,255,.06);color:#eaf3f6')
|
|
3626
|
+
b.addEventListener('click', onClick)
|
|
3627
|
+
return b
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3630
|
+
function tile(id, name, stream, isSelf) {
|
|
3631
|
+
const box = document.createElement('div')
|
|
3632
|
+
box.style.cssText =
|
|
3633
|
+
'position:relative;border-radius:12px;overflow:hidden;background:#000;min-height:120px;display:flex;align-items:center;justify-content:center'
|
|
3634
|
+
const v = document.createElement('video')
|
|
3635
|
+
v.autoplay = true
|
|
3636
|
+
v.playsInline = true
|
|
3637
|
+
v.muted = !!isSelf
|
|
3638
|
+
v.style.cssText = 'width:100%;height:100%;object-fit:cover'
|
|
3639
|
+
if (stream) v.srcObject = stream
|
|
3640
|
+
const tag = document.createElement('div')
|
|
3641
|
+
tag.style.cssText =
|
|
3642
|
+
'position:absolute;left:8px;bottom:8px;padding:2px 8px;border-radius:8px;background:rgba(0,0,0,.55);font-size:11px'
|
|
3643
|
+
tag.textContent = name + (isSelf ? '(我)' : '')
|
|
3644
|
+
box.append(v, tag)
|
|
3645
|
+
stage.appendChild(box)
|
|
3646
|
+
return { box, video: v, tag }
|
|
1689
3647
|
}
|
|
1690
3648
|
|
|
1691
3649
|
function relayout() {
|
|
@@ -2059,6 +4017,16 @@ window.__ModuleLoader__.load({
|
|
|
2059
4017
|
function SocialView(props) {
|
|
2060
4018
|
const [auth, setAuth] = useState(() => readJson(K_AUTH))
|
|
2061
4019
|
const [gameOpen, setGameOpen] = useState(false)
|
|
4020
|
+
const rootRef = useRef(null)
|
|
4021
|
+
|
|
4022
|
+
useEffect(() => {
|
|
4023
|
+
const el = rootRef.current
|
|
4024
|
+
if (!el) return
|
|
4025
|
+
adaptSurfaceTokens(el)
|
|
4026
|
+
// 主题切换/面板尺寸变化后再校一次
|
|
4027
|
+
const timer = window.setTimeout(() => adaptSurfaceTokens(el), 400)
|
|
4028
|
+
return () => window.clearTimeout(timer)
|
|
4029
|
+
}, [])
|
|
2062
4030
|
|
|
2063
4031
|
const body = !auth
|
|
2064
4032
|
? h(LoginPanel, { onDone: (next) => setAuth(next) })
|
|
@@ -2077,7 +4045,7 @@ window.__ModuleLoader__.load({
|
|
|
2077
4045
|
|
|
2078
4046
|
return h(
|
|
2079
4047
|
'div',
|
|
2080
|
-
{ className: 'sc-root' },
|
|
4048
|
+
{ className: 'sc-root', ref: rootRef },
|
|
2081
4049
|
canShare && auth ? h(Boundary, null, h(ShareBar, { chatProps: props, auth })) : null,
|
|
2082
4050
|
h('div', { style: { flex: 1, minHeight: 0, display: 'flex' } }, body),
|
|
2083
4051
|
gameOpen ? h(GameWindow, { onClose: () => setGameOpen(false) }) : null,
|