dsh-pet 0.1.4 → 0.1.6
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.en.md +10 -10
- package/README.md +11 -11
- package/assets/config.jsonc +88 -0
- package/assets/thumb//344/270/211/347/220/203/346/212/233/346/216/245.webm +0 -0
- package/assets/thumb//344/270/213/344/272/224/345/255/220/346/243/213.webm +0 -0
- package/assets/thumb//344/270/234/345/274/240/350/245/277/346/234/233.webm +0 -0
- package/assets/thumb//344/270/255/347/247/213/350/265/217/346/234/210/345/220/203/346/234/210/351/245/274.webm +0 -0
- package/assets/thumb//344/274/230/351/233/205/345/245/263/344/273/206/350/210/236.webm +0 -0
- package/assets/thumb//345/201/267/345/220/203/351/233/266/351/243/237/350/242/253/346/212/223/344/275/217.webm +0 -0
- package/assets/thumb//345/206/231/344/273/243/347/240/201.webm +0 -0
- package/assets/thumb//345/206/231/347/246/217/345/255/227.webm +0 -0
- package/assets/thumb//345/207/255/347/251/272/347/224/237/350/212/261.webm +0 -0
- package/assets/thumb//345/212/250/347/211/251/347/216/257/347/273/225.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/344/270/223/345/277/203/347/216/251/351/255/224/346/226/271.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/345/260/217/346/206/251/346/262/211/347/234/240.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/345/267/246/350/275/254/345/245/224/350/267/221.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/346/225/262/345/207/273/346/241/214/351/235/242/344/272/222/345/212/250.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/346/274/202/346/265/256/350/270/217/346/255/245.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/350/267/263/350/267/203/346/212/223/347/242/216/345/244/264/351/241/266/347/211/251/345/223/201.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/350/271/262/344/270/213/347/216/251/347/216/251/345/205/267/346/261/275/350/275/246.webm +0 -0
- package/assets/thumb//345/216/237/345/234/260/351/207/215/345/212/233/344/270/213/350/271/262/345/216/213/347/274/251.webm +0 -0
- package/assets/thumb//345/217/230/351/270/275/345/255/220.webm +0 -0
- package/assets/thumb//345/217/257/347/210/261/345/256/205/350/210/236.webm +0 -0
- package/assets/thumb//345/220/203Token.webm +0 -0
- package/assets/thumb//345/220/203/345/206/260/346/267/207/346/267/213/350/236/215/345/214/226.webm +0 -0
- package/assets/thumb//345/220/203/345/215/210/351/244/220.webm +0 -0
- package/assets/thumb//345/220/203/345/244/247/351/227/270/350/237/271.webm +0 -0
- package/assets/thumb//345/220/203/345/271/264/347/263/225.webm +0 -0
- package/assets/thumb//345/220/203/346/227/251/351/244/220.webm +0 -0
- package/assets/thumb//345/220/203/346/231/232/351/244/220.webm +0 -0
- package/assets/thumb//345/220/203/346/261/244/345/234/206.webm +0 -0
- package/assets/thumb//345/220/203/347/231/275/351/245/255.webm +0 -0
- package/assets/thumb//345/220/203/347/262/275/345/255/220.webm +0 -0
- package/assets/thumb//345/220/203/347/263/226/350/221/253/350/212/246.webm +0 -0
- package/assets/thumb//345/220/203/350/205/212/345/205/253/347/262/245.webm +0 -0
- package/assets/thumb//345/220/203/350/245/277/347/223/234.webm +0 -0
- package/assets/thumb//345/220/203/351/207/215/351/230/263/347/263/225.webm +0 -0
- package/assets/thumb//345/220/203/351/225/277/345/257/277/351/235/242.webm +0 -0
- package/assets/thumb//345/220/203/351/235/222/345/233/242.webm +0 -0
- package/assets/thumb//345/220/203/351/245/272/345/255/220.webm +0 -0
- package/assets/thumb//345/220/271/346/260/224/347/220/203.webm +0 -0
- package/assets/thumb//345/220/271/347/254/233/345/255/220.webm +0 -0
- package/assets/thumb//345/223/210/346/254/240/350/277/236/345/244/251.webm +0 -0
- package/assets/thumb//345/240/206/351/233/252/344/272/272.webm +0 -0
- package/assets/thumb//345/244/247/345/217/243/345/220/203/351/233/266/351/243/237.webm +0 -0
- package/assets/thumb//345/245/263/344/273/206/345/261/210/350/206/235/347/244/274/344/273/252.webm +0 -0
- package/assets/thumb//345/260/217/345/271/205/345/272/246/345/216/237/345/234/260360/345/272/246/346/227/213/350/275/254/345/261/225/347/244/272.webm +0 -0
- package/assets/thumb//345/260/217/346/217/220/347/220/264/346/274/224/345/245/217.webm +0 -0
- package/assets/thumb//345/276/205/346/234/272/345/221/274/345/220/270/344/274/221/351/227/262.webm +0 -0
- package/assets/thumb//346/202/240/351/227/262/345/223/274/346/255/214.webm +0 -0
- package/assets/thumb//346/211/221/345/205/213/351/255/224/346/234/257.webm +0 -0
- package/assets/thumb//346/211/223/347/236/214/347/235/241/350/242/253/346/203/212/351/206/222.webm +0 -0
- package/assets/thumb//346/212/275/351/231/200/350/236/272.webm +0 -0
- package/assets/thumb//346/213/206/347/244/274/347/211/251.webm +0 -0
- package/assets/thumb//346/217/222/350/214/261/350/220/270/350/265/217/350/217/212.webm +0 -0
- package/assets/thumb//346/221/207/346/211/207/347/272/263/345/207/211.webm +0 -0
- package/assets/thumb//346/222/270/347/214/253.webm +0 -0
- package/assets/thumb//346/224/266/347/272/242/345/214/205.webm +0 -0
- package/assets/thumb//346/224/276/345/255/224/346/230/216/347/201/257.webm +0 -0
- package/assets/thumb//346/224/276/346/262/263/347/201/257.webm +0 -0
- package/assets/thumb//346/224/276/347/203/237/350/212/261.webm +0 -0
- package/assets/thumb//346/224/276/351/243/216/347/255/235.webm +0 -0
- package/assets/thumb//346/225/264/344/275/223/346/215/242/350/243/205/350/257/225/350/211/262.webm +0 -0
- package/assets/thumb//346/230/257/345/225/212/357/274/214/345/220/203/344/273/200/344/271/210.webm +0 -0
- package/assets/thumb//346/231/250/351/227/264/345/210/267/347/211/231.webm +0 -0
- package/assets/thumb//346/266/256/347/201/253/351/224/205.webm +0 -0
- package/assets/thumb//346/267/261/345/272/246/346/200/235/350/200/203/347/242/216/347/242/216/345/277/265.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224-/345/202/262/345/250/207/347/224/237/346/260/224.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224-/345/205/203/346/260/224/346/214/245/346/211/213.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224-/345/256/263/347/276/236/346/203/212/350/256/266.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224-/345/274/200/345/277/203/350/267/203/345/212/250.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224-/346/214/240/347/227/222/345/222/257/345/222/257/347/254/221.webm +0 -0
- package/assets/thumb//347/205/247/351/225/234/345/255/220.webm +0 -0
- package/assets/thumb//347/216/251/346/260/264/346/236/252.webm +0 -0
- package/assets/thumb//347/216/251/346/270/270/346/210/217/346/260/224/346/200/245/350/264/245/345/235/217.webm +0 -0
- package/assets/thumb//347/224/250/351/262/270/351/261/274/345/260/276/345/267/264/346/213/215/346/211/223/345/234/260/351/235/242.webm +0 -0
- package/assets/thumb//347/251/277/351/222/210/344/271/236/345/267/247.webm +0 -0
- package/assets/thumb//350/210/236/347/213/256/345/244/264.webm +0 -0
- package/assets/thumb//350/215/241/347/247/213/345/215/203.webm +0 -0
- package/assets/thumb//350/220/214/345/214/226/345/260/217/345/271/275/347/201/265.webm +0 -0
- package/assets/thumb//350/223/235/351/262/270/347/216/260/344/270/226.webm +0 -0
- package/assets/thumb//350/235/264/350/235/266/350/234/234/350/234/202/347/216/257/347/273/225/345/244/264/351/241/266/345/274/200/350/212/261.webm +0 -0
- package/assets/thumb//350/236/203/350/237/271/350/265/260/350/267/257.webm +0 -0
- package/assets/thumb//350/242/253/345/220/223/344/270/200/350/267/263.webm +0 -0
- package/assets/thumb//350/242/253/350/220/275/345/217/266/346/267/271/346/262/241.webm +0 -0
- package/assets/thumb//350/242/253/351/274/240/346/240/207/346/213/226/346/213/275/346/202/254/347/251/272/345/217/215/351/246/210.webm +0 -0
- package/assets/thumb//350/243/205/347/202/271/345/234/243/350/257/236/346/240/221.webm +0 -0
- package/assets/thumb//350/256/250/347/263/226/345/215/227/347/223/234/347/201/257.webm +0 -0
- package/assets/thumb//350/266/205/345/244/247/344/274/270/346/207/222/350/205/260.webm +0 -0
- package/assets/thumb//350/270/242/346/257/275/345/255/220.webm +0 -0
- package/assets/thumb//350/275/273/345/277/253/346/221/207/346/221/206/350/210/236.webm +0 -0
- package/assets/thumb//350/275/273/345/277/253/350/256/260/345/275/225.webm +0 -0
- package/assets/thumb//351/252/221/346/234/250/351/251/254.webm +0 -0
- package/assets/thumb//351/262/270/351/261/274/345/220/220/346/263/241/346/263/241/347/211/271/346/225/210.webm +0 -0
- package/lib/client.js +1105 -693
- package/lib/index.js +172 -125
- package/package.json +20 -6
- package/src/client/app.ts +488 -0
- package/src/client/config.ts +122 -0
- package/src/client/constants.ts +9 -0
- package/src/client/index.ts +15 -0
- package/src/client/pickers.ts +32 -0
- package/src/client/settings.ts +325 -0
- package/src/client/types.ts +37 -0
- package/src/env.d.ts +6 -0
- package/src/host/index.ts +204 -0
- package/assets/thumb//345/260/217/345/271/205/345/272/246/345/216/237/345/234/260 360 /345/272/246/346/227/213/350/275/254/345/261/225/347/244/272.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224 - /345/202/262/345/250/207/347/224/237/346/260/224/357/274/210/344/276/247/350/272/253/345/261/225/347/244/272/357/274/211.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224 - /345/256/263/347/276/236/346/203/212/350/256/266.webm +0 -0
- package/assets/thumb//347/202/271/345/207/273/345/233/236/345/272/224 - /345/274/200/345/277/203/350/267/203/345/212/250.webm +0 -0
- package/assets/thumb//350/242/253/345/220/223/344/270/200/350/267/263/357/274/210/347/202/270/346/257/233/357/274/211.webm +0 -0
package/lib/client.js
CHANGED
|
@@ -1,693 +1,1105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/client/pickers.ts
|
|
3
|
+
const pick = (pool, exclude) => {
|
|
4
|
+
const entries = exclude ? pool.filter((n) => n !== exclude) : pool;
|
|
5
|
+
const src = entries.length ? entries : pool;
|
|
6
|
+
return src[Math.floor(Math.random() * src.length)];
|
|
7
|
+
};
|
|
8
|
+
const randomBetween = (min, max) => Math.floor(min + Math.random() * (max - min));
|
|
9
|
+
const pickWeightedCategory = (categories, facing) => {
|
|
10
|
+
const cats = categories.filter((c) => c.actions.length > 0);
|
|
11
|
+
if (!cats.length) return null;
|
|
12
|
+
const filtered = cats.filter((c) => !(c.noMirror && facing === "right"));
|
|
13
|
+
const eligible = filtered.length ? filtered : cats;
|
|
14
|
+
const totalW = eligible.reduce((s, c) => s + c.weight, 0) || 1;
|
|
15
|
+
let t = Math.random() * totalW;
|
|
16
|
+
for (const c of eligible) {
|
|
17
|
+
t -= c.weight;
|
|
18
|
+
if (t <= 0) return c;
|
|
19
|
+
}
|
|
20
|
+
return eligible[eligible.length - 1];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/client/settings.ts
|
|
25
|
+
const DEFAULT_PETS = [{
|
|
26
|
+
id: "main",
|
|
27
|
+
size: 462,
|
|
28
|
+
corner: "top-right",
|
|
29
|
+
marginX: 24,
|
|
30
|
+
marginY: 100
|
|
31
|
+
}];
|
|
32
|
+
const petBridge = {
|
|
33
|
+
current: null,
|
|
34
|
+
sync: null,
|
|
35
|
+
template: null
|
|
36
|
+
};
|
|
37
|
+
const NS = "pet.config";
|
|
38
|
+
const zh = {
|
|
39
|
+
nav: "桌宠配置",
|
|
40
|
+
intro: "管理多个桌宠:每个宠物可独立设置大小与位置(保存后即时生效)。",
|
|
41
|
+
petsLabel: "宠物列表",
|
|
42
|
+
add: "添加宠物",
|
|
43
|
+
remove: "删除",
|
|
44
|
+
atLeastOne: "至少保留一个宠物。",
|
|
45
|
+
emptyPets: "暂无宠物,点击「添加宠物」创建。",
|
|
46
|
+
sizeLabel: "大小(宽度 px)",
|
|
47
|
+
sizeHint: "高度自动 = 宽度 × 9/16。",
|
|
48
|
+
cornerLabel: "位置",
|
|
49
|
+
"corner.top-left": "左上角",
|
|
50
|
+
"corner.top-right": "右上角",
|
|
51
|
+
"corner.bottom-left": "左下角",
|
|
52
|
+
"corner.bottom-right": "右下角",
|
|
53
|
+
marginX: "水平偏移",
|
|
54
|
+
marginY: "垂直偏移",
|
|
55
|
+
save: "保存",
|
|
56
|
+
reset: "恢复默认",
|
|
57
|
+
saved: "已保存,桌宠即时生效。",
|
|
58
|
+
loadError: "加载配置失败",
|
|
59
|
+
invalid: "请检查输入:大小需为正数,边距可为任意数字。",
|
|
60
|
+
busy: "保存中…"
|
|
61
|
+
};
|
|
62
|
+
const en = {
|
|
63
|
+
nav: "Pet Config",
|
|
64
|
+
intro: "Manage multiple pets: each pet has its own size and position (applies instantly after saving).",
|
|
65
|
+
petsLabel: "Pets",
|
|
66
|
+
add: "Add pet",
|
|
67
|
+
remove: "Remove",
|
|
68
|
+
atLeastOne: "Keep at least one pet.",
|
|
69
|
+
emptyPets: "No pets yet — click \"Add pet\" to create one.",
|
|
70
|
+
sizeLabel: "Size (width px)",
|
|
71
|
+
sizeHint: "Height is automatic = width × 9/16.",
|
|
72
|
+
cornerLabel: "Position",
|
|
73
|
+
"corner.top-left": "Top-left",
|
|
74
|
+
"corner.top-right": "Top-right",
|
|
75
|
+
"corner.bottom-left": "Bottom-left",
|
|
76
|
+
"corner.bottom-right": "Bottom-right",
|
|
77
|
+
marginX: "Horizontal offset",
|
|
78
|
+
marginY: "Vertical offset",
|
|
79
|
+
save: "Save",
|
|
80
|
+
reset: "Reset to default",
|
|
81
|
+
saved: "Saved — the pets updated instantly.",
|
|
82
|
+
loadError: "Failed to load config",
|
|
83
|
+
invalid: "Check your input: size must be positive; margins can be any number.",
|
|
84
|
+
busy: "Saving…"
|
|
85
|
+
};
|
|
86
|
+
function makePetConfigSection(rt) {
|
|
87
|
+
const { h, useState, t } = rt;
|
|
88
|
+
const CORNERS$1 = [
|
|
89
|
+
"top-left",
|
|
90
|
+
"top-right",
|
|
91
|
+
"bottom-left",
|
|
92
|
+
"bottom-right"
|
|
93
|
+
];
|
|
94
|
+
const cornerLabel = (c) => t("corner." + c);
|
|
95
|
+
const inputStyle = {
|
|
96
|
+
boxSizing: "border-box",
|
|
97
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
98
|
+
borderRadius: "8px",
|
|
99
|
+
background: "var(--dsw-alias-bg-layer-1)",
|
|
100
|
+
color: "var(--dsw-alias-label-primary)",
|
|
101
|
+
padding: "5px 10px",
|
|
102
|
+
fontSize: "13px",
|
|
103
|
+
minHeight: "28px",
|
|
104
|
+
outline: "none"
|
|
105
|
+
};
|
|
106
|
+
const stripJsonc$1 = (src) => src.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^\\:])\/\/.*$/gm, "$1").trim();
|
|
107
|
+
/** 生成一个未占用的宠物 id(pet-2、pet-3…) */
|
|
108
|
+
const nextId = (list) => {
|
|
109
|
+
let n = 2;
|
|
110
|
+
for (;; n++) {
|
|
111
|
+
const id = "pet-" + n;
|
|
112
|
+
if (!list.some((p) => p.id === id)) return id;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const normalizePet$1 = (p) => {
|
|
116
|
+
const pos = p && p.position && typeof p.position === "object" ? p.position : {};
|
|
117
|
+
return {
|
|
118
|
+
id: String(p && p.id ? p.id : "main"),
|
|
119
|
+
size: Number(p && p.size) > 0 ? Number(p.size) : DEFAULT_PETS[0].size,
|
|
120
|
+
corner: CORNERS$1.includes(pos.corner) ? pos.corner : DEFAULT_PETS[0].corner,
|
|
121
|
+
marginX: Number.isFinite(Number(pos.marginX)) ? Number(pos.marginX) : DEFAULT_PETS[0].marginX,
|
|
122
|
+
marginY: Number.isFinite(Number(pos.marginY)) ? Number(pos.marginY) : DEFAULT_PETS[0].marginY
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/** 从 config.jsonc 对象提取默认宠物列表:必须为 pets 数组;缺失/为空回落代码兜底 DEFAULT_PETS */
|
|
126
|
+
const defaultsFrom = (obj) => {
|
|
127
|
+
const arr = obj && Array.isArray(obj.pets) ? obj.pets.filter((p) => p && p.id).map(normalizePet$1) : [];
|
|
128
|
+
return arr.length ? arr : DEFAULT_PETS.map((p) => ({ ...p }));
|
|
129
|
+
};
|
|
130
|
+
return function PetConfigSection() {
|
|
131
|
+
const initPets = petBridge.current ?? DEFAULT_PETS;
|
|
132
|
+
const [pets, setPets] = useState(initPets.map((p) => ({ ...p })));
|
|
133
|
+
const [selId, setSelId] = useState(initPets[0]?.id ?? "");
|
|
134
|
+
const [busy, setBusy] = useState(false);
|
|
135
|
+
const [msg, setMsg] = useState({
|
|
136
|
+
kind: "",
|
|
137
|
+
text: ""
|
|
138
|
+
});
|
|
139
|
+
const sel = pets.find((p) => p.id === selId) ?? pets[0] ?? null;
|
|
140
|
+
const updateSel = (patch) => setPets((list) => list.map((p) => p.id === (sel?.id ?? "") ? {
|
|
141
|
+
...p,
|
|
142
|
+
...patch
|
|
143
|
+
} : p));
|
|
144
|
+
const validated = () => {
|
|
145
|
+
for (const p of pets) if (!Number.isFinite(p.size) || p.size <= 0 || !Number.isFinite(p.marginX) || !Number.isFinite(p.marginY)) {
|
|
146
|
+
setMsg({
|
|
147
|
+
kind: "err",
|
|
148
|
+
text: t("invalid")
|
|
149
|
+
});
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return pets;
|
|
153
|
+
};
|
|
154
|
+
const save = async () => {
|
|
155
|
+
const list = validated();
|
|
156
|
+
if (!list) return;
|
|
157
|
+
setBusy(true);
|
|
158
|
+
setMsg({
|
|
159
|
+
kind: "",
|
|
160
|
+
text: ""
|
|
161
|
+
});
|
|
162
|
+
try {
|
|
163
|
+
const res = await fetch("/pet/config", {
|
|
164
|
+
method: "PUT",
|
|
165
|
+
headers: { "content-type": "application/json" },
|
|
166
|
+
body: JSON.stringify({ pets: list.map((p) => ({
|
|
167
|
+
id: p.id,
|
|
168
|
+
size: p.size,
|
|
169
|
+
position: {
|
|
170
|
+
corner: p.corner,
|
|
171
|
+
marginX: p.marginX,
|
|
172
|
+
marginY: p.marginY
|
|
173
|
+
}
|
|
174
|
+
})) })
|
|
175
|
+
});
|
|
176
|
+
if (!res.ok) throw new Error("HTTP " + res.status);
|
|
177
|
+
petBridge.current = list;
|
|
178
|
+
petBridge.sync?.(list);
|
|
179
|
+
setMsg({
|
|
180
|
+
kind: "ok",
|
|
181
|
+
text: t("saved")
|
|
182
|
+
});
|
|
183
|
+
} catch {
|
|
184
|
+
setMsg({
|
|
185
|
+
kind: "err",
|
|
186
|
+
text: t("loadError")
|
|
187
|
+
});
|
|
188
|
+
} finally {
|
|
189
|
+
setBusy(false);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const reset = async () => {
|
|
193
|
+
setBusy(true);
|
|
194
|
+
setMsg({
|
|
195
|
+
kind: "",
|
|
196
|
+
text: ""
|
|
197
|
+
});
|
|
198
|
+
try {
|
|
199
|
+
await fetch("/pet/config", { method: "DELETE" });
|
|
200
|
+
const defRes = await fetch("/pet/config.jsonc");
|
|
201
|
+
const obj = JSON.parse(stripJsonc$1(await defRes.text()));
|
|
202
|
+
const defs = defaultsFrom(obj);
|
|
203
|
+
setPets(defs.map((p) => ({ ...p })));
|
|
204
|
+
setSelId(defs[0]?.id ?? "");
|
|
205
|
+
petBridge.current = defs;
|
|
206
|
+
petBridge.sync?.(defs);
|
|
207
|
+
setMsg({
|
|
208
|
+
kind: "ok",
|
|
209
|
+
text: t("saved")
|
|
210
|
+
});
|
|
211
|
+
} catch {
|
|
212
|
+
setMsg({
|
|
213
|
+
kind: "err",
|
|
214
|
+
text: t("loadError")
|
|
215
|
+
});
|
|
216
|
+
} finally {
|
|
217
|
+
setBusy(false);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const addPet = () => {
|
|
221
|
+
const id = nextId(pets);
|
|
222
|
+
const tpl = petBridge.template ?? DEFAULT_PETS[0];
|
|
223
|
+
const np = {
|
|
224
|
+
id,
|
|
225
|
+
size: tpl.size,
|
|
226
|
+
corner: tpl.corner,
|
|
227
|
+
marginX: tpl.marginX,
|
|
228
|
+
marginY: tpl.marginY
|
|
229
|
+
};
|
|
230
|
+
setPets((list) => [...list, np]);
|
|
231
|
+
setSelId(id);
|
|
232
|
+
};
|
|
233
|
+
const removeSel = () => {
|
|
234
|
+
if (pets.length <= 1) {
|
|
235
|
+
setMsg({
|
|
236
|
+
kind: "err",
|
|
237
|
+
text: t("atLeastOne")
|
|
238
|
+
});
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const list = pets.filter((p) => p.id !== (sel?.id ?? ""));
|
|
242
|
+
setPets(list);
|
|
243
|
+
setSelId(list[0].id);
|
|
244
|
+
};
|
|
245
|
+
const field = (key, value, setter, width) => h("input", {
|
|
246
|
+
type: "number",
|
|
247
|
+
step: key === "size" ? "10" : "1",
|
|
248
|
+
min: key === "size" ? "120" : "",
|
|
249
|
+
value: String(value),
|
|
250
|
+
disabled: busy || !sel,
|
|
251
|
+
onChange: (e) => setter(Number(e.target.value)),
|
|
252
|
+
style: {
|
|
253
|
+
width,
|
|
254
|
+
...inputStyle
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return h("section", {
|
|
258
|
+
style: {
|
|
259
|
+
maxWidth: "720px",
|
|
260
|
+
color: "var(--dsw-alias-label-primary)",
|
|
261
|
+
display: "flex",
|
|
262
|
+
flexDirection: "column",
|
|
263
|
+
gap: "6px"
|
|
264
|
+
},
|
|
265
|
+
children: [
|
|
266
|
+
h("h2", {
|
|
267
|
+
style: {
|
|
268
|
+
margin: 0,
|
|
269
|
+
fontSize: "16px",
|
|
270
|
+
fontWeight: 500,
|
|
271
|
+
lineHeight: "24px"
|
|
272
|
+
},
|
|
273
|
+
children: t("nav")
|
|
274
|
+
}),
|
|
275
|
+
h("p", {
|
|
276
|
+
style: {
|
|
277
|
+
margin: 0,
|
|
278
|
+
fontSize: "14px",
|
|
279
|
+
color: "var(--dsw-alias-label-tertiary)",
|
|
280
|
+
lineHeight: "22px"
|
|
281
|
+
},
|
|
282
|
+
children: t("intro")
|
|
283
|
+
}),
|
|
284
|
+
h("div", {
|
|
285
|
+
style: {
|
|
286
|
+
display: "flex",
|
|
287
|
+
gap: "8px",
|
|
288
|
+
flexWrap: "wrap",
|
|
289
|
+
alignItems: "center",
|
|
290
|
+
marginTop: "4px"
|
|
291
|
+
},
|
|
292
|
+
children: [
|
|
293
|
+
h("span", {
|
|
294
|
+
style: {
|
|
295
|
+
fontSize: "12px",
|
|
296
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
297
|
+
},
|
|
298
|
+
children: t("petsLabel")
|
|
299
|
+
}),
|
|
300
|
+
...pets.map((p) => h("button", {
|
|
301
|
+
key: p.id,
|
|
302
|
+
type: "button",
|
|
303
|
+
onClick: () => setSelId(p.id),
|
|
304
|
+
style: {
|
|
305
|
+
border: "1px solid " + (p.id === (sel?.id ?? "") ? "var(--dsw-alias-state-business-primary)" : "var(--dsw-alias-border-l2)"),
|
|
306
|
+
background: p.id === (sel?.id ?? "") ? "var(--dsw-alias-interactive-bg-active)" : "transparent",
|
|
307
|
+
color: "var(--dsw-alias-label-primary)",
|
|
308
|
+
borderRadius: "8px",
|
|
309
|
+
padding: "4px 12px",
|
|
310
|
+
fontSize: "13px",
|
|
311
|
+
cursor: "pointer"
|
|
312
|
+
},
|
|
313
|
+
children: p.id + " (" + p.size + "px)"
|
|
314
|
+
})),
|
|
315
|
+
h("button", {
|
|
316
|
+
type: "button",
|
|
317
|
+
onClick: addPet,
|
|
318
|
+
disabled: busy,
|
|
319
|
+
style: {
|
|
320
|
+
border: "1px dashed var(--dsw-alias-border-l2)",
|
|
321
|
+
background: "transparent",
|
|
322
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
323
|
+
borderRadius: "8px",
|
|
324
|
+
padding: "4px 12px",
|
|
325
|
+
fontSize: "13px",
|
|
326
|
+
cursor: "pointer"
|
|
327
|
+
},
|
|
328
|
+
children: "+ " + t("add")
|
|
329
|
+
})
|
|
330
|
+
]
|
|
331
|
+
}),
|
|
332
|
+
sel ? h("div", {
|
|
333
|
+
style: {
|
|
334
|
+
display: "flex",
|
|
335
|
+
gap: "16px",
|
|
336
|
+
flexWrap: "wrap",
|
|
337
|
+
marginTop: "8px",
|
|
338
|
+
padding: "12px 14px",
|
|
339
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
340
|
+
borderRadius: "12px"
|
|
341
|
+
},
|
|
342
|
+
children: [
|
|
343
|
+
h("label", {
|
|
344
|
+
style: {
|
|
345
|
+
display: "flex",
|
|
346
|
+
flexDirection: "column",
|
|
347
|
+
gap: "4px",
|
|
348
|
+
fontSize: "12px",
|
|
349
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
350
|
+
},
|
|
351
|
+
children: [
|
|
352
|
+
t("sizeLabel"),
|
|
353
|
+
field("size", sel.size, (v) => updateSel({ size: v }), "150px"),
|
|
354
|
+
h("span", {
|
|
355
|
+
style: {
|
|
356
|
+
fontSize: "11px",
|
|
357
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
358
|
+
},
|
|
359
|
+
children: t("sizeHint")
|
|
360
|
+
})
|
|
361
|
+
]
|
|
362
|
+
}),
|
|
363
|
+
h("label", {
|
|
364
|
+
style: {
|
|
365
|
+
display: "flex",
|
|
366
|
+
flexDirection: "column",
|
|
367
|
+
gap: "4px",
|
|
368
|
+
fontSize: "12px",
|
|
369
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
370
|
+
},
|
|
371
|
+
children: [t("cornerLabel"), h("select", {
|
|
372
|
+
value: sel.corner,
|
|
373
|
+
disabled: busy,
|
|
374
|
+
onChange: (e) => updateSel({ corner: e.target.value }),
|
|
375
|
+
style: {
|
|
376
|
+
width: "160px",
|
|
377
|
+
...inputStyle
|
|
378
|
+
},
|
|
379
|
+
children: CORNERS$1.map((c) => h("option", {
|
|
380
|
+
key: c,
|
|
381
|
+
value: c,
|
|
382
|
+
children: cornerLabel(c)
|
|
383
|
+
}))
|
|
384
|
+
})]
|
|
385
|
+
}),
|
|
386
|
+
h("label", {
|
|
387
|
+
style: {
|
|
388
|
+
display: "flex",
|
|
389
|
+
flexDirection: "column",
|
|
390
|
+
gap: "4px",
|
|
391
|
+
fontSize: "12px",
|
|
392
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
393
|
+
},
|
|
394
|
+
children: [t("marginX"), field("marginX", sel.marginX, (v) => updateSel({ marginX: v }), "120px")]
|
|
395
|
+
}),
|
|
396
|
+
h("label", {
|
|
397
|
+
style: {
|
|
398
|
+
display: "flex",
|
|
399
|
+
flexDirection: "column",
|
|
400
|
+
gap: "4px",
|
|
401
|
+
fontSize: "12px",
|
|
402
|
+
color: "var(--dsw-alias-label-secondary)"
|
|
403
|
+
},
|
|
404
|
+
children: [t("marginY"), field("marginY", sel.marginY, (v) => updateSel({ marginY: v }), "120px")]
|
|
405
|
+
}),
|
|
406
|
+
h("button", {
|
|
407
|
+
type: "button",
|
|
408
|
+
onClick: removeSel,
|
|
409
|
+
disabled: busy,
|
|
410
|
+
title: t("remove"),
|
|
411
|
+
style: {
|
|
412
|
+
alignSelf: "flex-end",
|
|
413
|
+
border: "1px solid var(--dsw-alias-state-error-secondary)",
|
|
414
|
+
background: "transparent",
|
|
415
|
+
color: "var(--dsw-alias-state-error-primary)",
|
|
416
|
+
borderRadius: "8px",
|
|
417
|
+
padding: "4px 12px",
|
|
418
|
+
fontSize: "12px",
|
|
419
|
+
cursor: "pointer"
|
|
420
|
+
},
|
|
421
|
+
children: t("remove")
|
|
422
|
+
})
|
|
423
|
+
]
|
|
424
|
+
}) : h("p", {
|
|
425
|
+
style: {
|
|
426
|
+
margin: 0,
|
|
427
|
+
fontSize: "13px",
|
|
428
|
+
color: "var(--dsw-alias-label-tertiary)"
|
|
429
|
+
},
|
|
430
|
+
children: t("emptyPets")
|
|
431
|
+
}),
|
|
432
|
+
h("div", {
|
|
433
|
+
style: {
|
|
434
|
+
display: "flex",
|
|
435
|
+
gap: "8px",
|
|
436
|
+
alignItems: "center",
|
|
437
|
+
marginTop: "4px"
|
|
438
|
+
},
|
|
439
|
+
children: [
|
|
440
|
+
h("button", {
|
|
441
|
+
type: "button",
|
|
442
|
+
disabled: busy,
|
|
443
|
+
onClick: save,
|
|
444
|
+
style: {
|
|
445
|
+
border: "1px solid var(--dsw-alias-button-info-fill)",
|
|
446
|
+
background: "var(--dsw-alias-button-info-fill)",
|
|
447
|
+
color: "#fff",
|
|
448
|
+
borderRadius: "8px",
|
|
449
|
+
padding: "4px 14px",
|
|
450
|
+
fontSize: "12px",
|
|
451
|
+
cursor: "pointer",
|
|
452
|
+
opacity: busy ? .5 : 1
|
|
453
|
+
},
|
|
454
|
+
children: t("save")
|
|
455
|
+
}),
|
|
456
|
+
h("button", {
|
|
457
|
+
type: "button",
|
|
458
|
+
disabled: busy,
|
|
459
|
+
onClick: reset,
|
|
460
|
+
style: {
|
|
461
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
462
|
+
background: "transparent",
|
|
463
|
+
color: "var(--dsw-alias-label-primary)",
|
|
464
|
+
borderRadius: "8px",
|
|
465
|
+
padding: "4px 14px",
|
|
466
|
+
fontSize: "12px",
|
|
467
|
+
cursor: "pointer",
|
|
468
|
+
opacity: busy ? .5 : 1
|
|
469
|
+
},
|
|
470
|
+
children: t("reset")
|
|
471
|
+
}),
|
|
472
|
+
msg.text ? h("span", {
|
|
473
|
+
style: {
|
|
474
|
+
fontSize: "12px",
|
|
475
|
+
color: msg.kind === "err" ? "var(--dsw-alias-state-error-primary)" : "var(--dsw-alias-state-ok-primary)",
|
|
476
|
+
marginLeft: "4px"
|
|
477
|
+
},
|
|
478
|
+
children: msg.text
|
|
479
|
+
}) : null
|
|
480
|
+
]
|
|
481
|
+
})
|
|
482
|
+
]
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/client/config.ts
|
|
489
|
+
const FALLBACK_IDLE = "待机呼吸休闲";
|
|
490
|
+
const DEFAULT_MOVE_PARAMS = {
|
|
491
|
+
minDist: 60,
|
|
492
|
+
maxDist: 240,
|
|
493
|
+
margin: 20,
|
|
494
|
+
leadSec: 2,
|
|
495
|
+
tailSec: 2
|
|
496
|
+
};
|
|
497
|
+
const stripJsonc = (src) => src.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^\\:])\/\/.*$/gm, "$1").trim();
|
|
498
|
+
const buildMinimalAnim = () => ({
|
|
499
|
+
idle: [FALLBACK_IDLE],
|
|
500
|
+
turn: [],
|
|
501
|
+
drag: [],
|
|
502
|
+
clicks: [],
|
|
503
|
+
moves: {
|
|
504
|
+
default: { ...DEFAULT_MOVE_PARAMS },
|
|
505
|
+
actions: []
|
|
506
|
+
},
|
|
507
|
+
categories: [],
|
|
508
|
+
weights: {
|
|
509
|
+
idle: 100,
|
|
510
|
+
turn: 0,
|
|
511
|
+
move: 0
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
const buildAnim = (obj) => {
|
|
515
|
+
const a = obj?.animations;
|
|
516
|
+
const w = obj?.animationWeights ?? {};
|
|
517
|
+
const strArr = (x) => Array.isArray(x) ? x.map(String).filter(Boolean) : [];
|
|
518
|
+
const idle = strArr(a?.idle);
|
|
519
|
+
if (!idle.length) idle.push(FALLBACK_IDLE);
|
|
520
|
+
const turn = strArr(a?.turn);
|
|
521
|
+
const drag = strArr(a?.drag);
|
|
522
|
+
const clicks = strArr(a?.clicks);
|
|
523
|
+
let mdef = { ...DEFAULT_MOVE_PARAMS };
|
|
524
|
+
let mActs = [];
|
|
525
|
+
if (a?.moves && typeof a.moves === "object") {
|
|
526
|
+
if (a.moves.default && typeof a.moves.default === "object") mdef = {
|
|
527
|
+
...mdef,
|
|
528
|
+
...a.moves.default
|
|
529
|
+
};
|
|
530
|
+
if (Array.isArray(a.moves.actions)) {
|
|
531
|
+
const list = a.moves.actions.filter((x) => x && x.name).map((x) => ({
|
|
532
|
+
name: String(x.name),
|
|
533
|
+
params: x.params && typeof x.params === "object" ? { ...x.params } : void 0
|
|
534
|
+
}));
|
|
535
|
+
if (list.length) mActs = list;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
let cats = [];
|
|
539
|
+
if (Array.isArray(a?.categories)) {
|
|
540
|
+
const list = a.categories.filter((c) => c && c.id && Array.isArray(c.actions) && c.actions.length).map((c) => ({
|
|
541
|
+
id: String(c.id),
|
|
542
|
+
weight: Number(c.weight),
|
|
543
|
+
noMirror: !!c.noMirror,
|
|
544
|
+
actions: c.actions.map(String)
|
|
545
|
+
}));
|
|
546
|
+
if (list.length) cats = list;
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
idle,
|
|
550
|
+
turn,
|
|
551
|
+
drag,
|
|
552
|
+
clicks,
|
|
553
|
+
moves: {
|
|
554
|
+
default: mdef,
|
|
555
|
+
actions: mActs
|
|
556
|
+
},
|
|
557
|
+
categories: cats,
|
|
558
|
+
weights: {
|
|
559
|
+
idle: Number(w.idle) >= 0 ? Number(w.idle) : 10,
|
|
560
|
+
turn: Number(w.turn) >= 0 ? Number(w.turn) : 5,
|
|
561
|
+
move: Number(w.move) >= 0 ? Number(w.move) : 5
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
const CORNERS = [
|
|
566
|
+
"top-left",
|
|
567
|
+
"top-right",
|
|
568
|
+
"bottom-left",
|
|
569
|
+
"bottom-right"
|
|
570
|
+
];
|
|
571
|
+
function normalizePet(p) {
|
|
572
|
+
const pos = p && p.position && typeof p.position === "object" ? p.position : {};
|
|
573
|
+
return {
|
|
574
|
+
id: String(p && p.id ? p.id : "main"),
|
|
575
|
+
size: Number(p && p.size) > 0 ? Number(p.size) : DEFAULT_PETS[0].size,
|
|
576
|
+
corner: CORNERS.indexOf(pos.corner) !== -1 ? pos.corner : DEFAULT_PETS[0].corner,
|
|
577
|
+
marginX: Number.isFinite(Number(pos.marginX)) ? Number(pos.marginX) : DEFAULT_PETS[0].marginX,
|
|
578
|
+
marginY: Number.isFinite(Number(pos.marginY)) ? Number(pos.marginY) : DEFAULT_PETS[0].marginY
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function extractDefaultPets(obj) {
|
|
582
|
+
const arr = obj && Array.isArray(obj.pets) ? obj.pets.filter((p) => p && p.id) : [];
|
|
583
|
+
if (!arr.length) return DEFAULT_PETS.map((p) => ({ ...p }));
|
|
584
|
+
const seen = new Set();
|
|
585
|
+
const out = [];
|
|
586
|
+
for (const p of arr) {
|
|
587
|
+
const id = String(p.id);
|
|
588
|
+
if (!seen.has(id)) {
|
|
589
|
+
seen.add(id);
|
|
590
|
+
out.push(normalizePet(p));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return out.length ? out : DEFAULT_PETS.map((p) => ({ ...p }));
|
|
594
|
+
}
|
|
595
|
+
function resolvePets(defaults, user) {
|
|
596
|
+
if (user && Array.isArray(user.pets)) {
|
|
597
|
+
const list = user.pets.filter((p) => p && p.id).map(normalizePet);
|
|
598
|
+
return list.length ? list : defaults;
|
|
599
|
+
}
|
|
600
|
+
return defaults;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/client/constants.ts
|
|
605
|
+
const CANVAS_H = 360;
|
|
606
|
+
const FEET_Y = 330;
|
|
607
|
+
const HIT_BOX = {
|
|
608
|
+
x0: 200,
|
|
609
|
+
y0: 50,
|
|
610
|
+
x1: 440,
|
|
611
|
+
y1: 335
|
|
612
|
+
};
|
|
613
|
+
const DRAG_THRESHOLD = 5;
|
|
614
|
+
|
|
615
|
+
//#endregion
|
|
616
|
+
//#region src/client/app.ts
|
|
617
|
+
function makeFactory() {
|
|
618
|
+
return (require) => {
|
|
619
|
+
var module = { exports: {} };
|
|
620
|
+
const react = require("react");
|
|
621
|
+
const { useEffect, useRef, useState } = react;
|
|
622
|
+
const { jsx: h } = require("react/jsx-runtime");
|
|
623
|
+
const css = [
|
|
624
|
+
".dsh-pet-root{position:fixed;z-index:40;pointer-events:none;user-select:none}",
|
|
625
|
+
".dsh-pet-root[data-corner=\"bottom-right\"]{right:var(--dsh-pet-mx,24px);bottom:var(--dsh-pet-my,0)}",
|
|
626
|
+
".dsh-pet-root[data-corner=\"bottom-left\"]{left:var(--dsh-pet-mx,24px);bottom:var(--dsh-pet-my,0)}",
|
|
627
|
+
".dsh-pet-root[data-corner=\"top-right\"]{right:var(--dsh-pet-mx,24px);top:var(--dsh-pet-my,0)}",
|
|
628
|
+
".dsh-pet-root[data-corner=\"top-left\"]{left:var(--dsh-pet-mx,24px);top:var(--dsh-pet-my,0)}",
|
|
629
|
+
".dsh-pet-stage{position:relative;width:var(--dsh-pet-size,462px);height:calc(var(--dsh-pet-size,462px)*9/16);pointer-events:none}",
|
|
630
|
+
".dsh-pet-video{position:absolute;inset:0;width:100%;height:100%;object-fit:contain;pointer-events:none;opacity:0;transition:opacity .18s ease;transform-origin:center}",
|
|
631
|
+
".dsh-pet-video.is-front{opacity:1}",
|
|
632
|
+
".dsh-pet-hit{position:absolute;pointer-events:auto;cursor:default;z-index:1}",
|
|
633
|
+
".dsh-pet-hit.dragging{cursor:grabbing}",
|
|
634
|
+
"@media (prefers-reduced-motion: reduce){.dsh-pet-video{transition:none}}"
|
|
635
|
+
].join("\n");
|
|
636
|
+
const cssTag = "dsh-pet/style.css";
|
|
637
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + cssTag + "\"]") === null) {
|
|
638
|
+
const tag = document.createElement("style");
|
|
639
|
+
tag.dataset.plugin = "dsh-pet";
|
|
640
|
+
tag.dataset.pluginCss = cssTag;
|
|
641
|
+
tag.textContent = css;
|
|
642
|
+
document.head.appendChild(tag);
|
|
643
|
+
}
|
|
644
|
+
let ANIM = buildMinimalAnim();
|
|
645
|
+
function PetCard({ cfg }) {
|
|
646
|
+
const [size, setSize] = useState(cfg.size);
|
|
647
|
+
const halfW = size / 2;
|
|
648
|
+
const halfH = size * 9 / 16 / 2;
|
|
649
|
+
const [anim, setAnim] = useState(ANIM.idle[0] ?? "");
|
|
650
|
+
const [once, setOnce] = useState(true);
|
|
651
|
+
const [facing, setFacing] = useState("left");
|
|
652
|
+
const [dragging, setDragging] = useState(false);
|
|
653
|
+
const [customPos, setCustomPos] = useState(null);
|
|
654
|
+
const [corner, setCorner] = useState(cfg.corner);
|
|
655
|
+
const [margin, setMargin] = useState({
|
|
656
|
+
x: cfg.marginX,
|
|
657
|
+
y: cfg.marginY
|
|
658
|
+
});
|
|
659
|
+
useEffect(() => {
|
|
660
|
+
setSize(cfg.size);
|
|
661
|
+
setCorner(cfg.corner);
|
|
662
|
+
setMargin({
|
|
663
|
+
x: cfg.marginX,
|
|
664
|
+
y: cfg.marginY
|
|
665
|
+
});
|
|
666
|
+
}, [
|
|
667
|
+
cfg.size,
|
|
668
|
+
cfg.corner,
|
|
669
|
+
cfg.marginX,
|
|
670
|
+
cfg.marginY
|
|
671
|
+
]);
|
|
672
|
+
const [seq, setSeq] = useState(0);
|
|
673
|
+
const rootRef = useRef(null);
|
|
674
|
+
const stageRef = useRef(null);
|
|
675
|
+
const videoARef = useRef(null);
|
|
676
|
+
const videoBRef = useRef(null);
|
|
677
|
+
const frontRef = useRef(0);
|
|
678
|
+
const pendingRef = useRef(null);
|
|
679
|
+
const genRef = useRef(0);
|
|
680
|
+
const dragRef = useRef({
|
|
681
|
+
active: false,
|
|
682
|
+
dragging: false,
|
|
683
|
+
sx: 0,
|
|
684
|
+
sy: 0,
|
|
685
|
+
offX: 0,
|
|
686
|
+
offY: 0
|
|
687
|
+
});
|
|
688
|
+
const justDraggedRef = useRef(false);
|
|
689
|
+
const animRef = useRef(anim);
|
|
690
|
+
animRef.current = anim;
|
|
691
|
+
const switchTo = (next, nextOnce) => {
|
|
692
|
+
if (!next) return;
|
|
693
|
+
const pending = pendingRef.current;
|
|
694
|
+
if (pending && pending.anim === next && pending.once === nextOnce) return;
|
|
695
|
+
const gen = ++genRef.current;
|
|
696
|
+
pendingRef.current = {
|
|
697
|
+
anim: next,
|
|
698
|
+
once: nextOnce,
|
|
699
|
+
gen
|
|
700
|
+
};
|
|
701
|
+
const target = frontRef.current === 0 ? videoBRef : videoARef;
|
|
702
|
+
const el = target.current;
|
|
703
|
+
if (!el) return;
|
|
704
|
+
el.src = "/pet/thumb/" + encodeURIComponent(next) + ".webm";
|
|
705
|
+
el.loop = !nextOnce;
|
|
706
|
+
el.muted = true;
|
|
707
|
+
el.autoplay = true;
|
|
708
|
+
el.playsInline = true;
|
|
709
|
+
el.onended = nextOnce ? handleEnded : null;
|
|
710
|
+
el.load();
|
|
711
|
+
const onReady = () => {
|
|
712
|
+
el.removeEventListener("loadeddata", onReady);
|
|
713
|
+
if (pendingRef.current?.gen !== gen) return;
|
|
714
|
+
const old = frontRef.current === 0 ? videoARef : videoBRef;
|
|
715
|
+
el.classList.add("is-front");
|
|
716
|
+
if (old.current && old.current !== el) old.current.classList.remove("is-front");
|
|
717
|
+
frontRef.current = frontRef.current === 0 ? 1 : 0;
|
|
718
|
+
pendingRef.current = null;
|
|
719
|
+
el.style.transform = facingRef.current === "right" ? "scaleX(-1)" : "";
|
|
720
|
+
el.play().catch(() => {});
|
|
721
|
+
if (pendingMoveRef.current) startMoveDrive(el);
|
|
722
|
+
};
|
|
723
|
+
el.addEventListener("loadeddata", onReady);
|
|
724
|
+
if (el.readyState >= 2) onReady();
|
|
725
|
+
};
|
|
726
|
+
useEffect(() => {
|
|
727
|
+
switchTo(anim, once);
|
|
728
|
+
}, [
|
|
729
|
+
anim,
|
|
730
|
+
once,
|
|
731
|
+
seq
|
|
732
|
+
]);
|
|
733
|
+
useEffect(() => () => stopMove(), []);
|
|
734
|
+
useEffect(() => {
|
|
735
|
+
const onResize = () => setCustomPos((prev) => prev ? { ...prev } : prev);
|
|
736
|
+
window.addEventListener("resize", onResize);
|
|
737
|
+
return () => window.removeEventListener("resize", onResize);
|
|
738
|
+
}, []);
|
|
739
|
+
const pickNext = () => {
|
|
740
|
+
const roll = Math.random();
|
|
741
|
+
const wI = ANIM.weights.idle;
|
|
742
|
+
const wT = ANIM.weights.turn;
|
|
743
|
+
const wM = ANIM.weights.move;
|
|
744
|
+
const topEnd = (wI + wT + wM) / 100;
|
|
745
|
+
let kind = "";
|
|
746
|
+
let next = "";
|
|
747
|
+
if (roll < wI / 100) {
|
|
748
|
+
kind = "IDLE";
|
|
749
|
+
next = pick(ANIM.idle, animRef.current);
|
|
750
|
+
setAnim(next);
|
|
751
|
+
} else if (roll < (wI + wT) / 100) {
|
|
752
|
+
kind = "TURN";
|
|
753
|
+
next = pick(ANIM.turn, animRef.current);
|
|
754
|
+
setAnim(next);
|
|
755
|
+
} else if (roll < topEnd) if (!tryMove()) {
|
|
756
|
+
const cat = pickWeightedCategory(ANIM.categories, facingRef.current);
|
|
757
|
+
kind = cat ? cat.id : "FALLBACK";
|
|
758
|
+
next = cat ? pick(cat.actions, animRef.current) : pick(ANIM.idle, animRef.current);
|
|
759
|
+
setAnim(next);
|
|
760
|
+
} else {
|
|
761
|
+
kind = "MOVES";
|
|
762
|
+
next = "移动(池内随机)";
|
|
763
|
+
}
|
|
764
|
+
else {
|
|
765
|
+
const cat = pickWeightedCategory(ANIM.categories, facingRef.current);
|
|
766
|
+
kind = cat ? cat.id : "FALLBACK";
|
|
767
|
+
next = cat ? pick(cat.actions, animRef.current) : pick(ANIM.idle, animRef.current);
|
|
768
|
+
setAnim(next);
|
|
769
|
+
}
|
|
770
|
+
console.log("[dsh-pet] roll=" + roll.toFixed(4) + " -> [" + kind + "] " + next);
|
|
771
|
+
setOnce(true);
|
|
772
|
+
setSeq((s) => s + 1);
|
|
773
|
+
};
|
|
774
|
+
const handleEnded = () => {
|
|
775
|
+
if (dragRef.current.active) return;
|
|
776
|
+
if (ANIM.turn.includes(animRef.current)) setFacing((f) => f === "left" ? "right" : "left");
|
|
777
|
+
if (ANIM.drag.includes(animRef.current) || ANIM.clicks.includes(animRef.current)) {
|
|
778
|
+
if (ANIM.idle.length) setAnim(pick(ANIM.idle, animRef.current));
|
|
779
|
+
setOnce(true);
|
|
780
|
+
setSeq((s) => s + 1);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
pickNext();
|
|
784
|
+
};
|
|
785
|
+
const moveRef = useRef(null);
|
|
786
|
+
const moveTokenRef = useRef(0);
|
|
787
|
+
const pendingMoveRef = useRef(null);
|
|
788
|
+
const customPosRef = useRef(customPos);
|
|
789
|
+
customPosRef.current = customPos;
|
|
790
|
+
const currentCenterX = () => {
|
|
791
|
+
const cp = customPosRef.current;
|
|
792
|
+
if (cp) return cp.rx * window.innerWidth;
|
|
793
|
+
const rootEl = rootRef.current;
|
|
794
|
+
if (rootEl) return rootEl.getBoundingClientRect().left + halfW;
|
|
795
|
+
return window.innerWidth - 24 - halfW;
|
|
796
|
+
};
|
|
797
|
+
const currentCenterY = () => {
|
|
798
|
+
const cp = customPosRef.current;
|
|
799
|
+
if (cp) return cp.ry * window.innerHeight;
|
|
800
|
+
const rootEl = rootRef.current;
|
|
801
|
+
if (rootEl) return rootEl.getBoundingClientRect().top + halfH;
|
|
802
|
+
return window.innerHeight - 20 - halfH;
|
|
803
|
+
};
|
|
804
|
+
const startMoveDrive = (el) => {
|
|
805
|
+
const pm = pendingMoveRef.current;
|
|
806
|
+
if (!pm || moveRef.current !== null) return;
|
|
807
|
+
pendingMoveRef.current = null;
|
|
808
|
+
const { startRatio, startYRatio, targetRatio, dir, totalRatio, leadSec, tailSec } = pm;
|
|
809
|
+
const duration = Number.isFinite(el.duration) && el.duration > 0 ? el.duration : 10.09;
|
|
810
|
+
const travelWindow = Math.max(.1, duration - leadSec - tailSec);
|
|
811
|
+
const token = ++moveTokenRef.current;
|
|
812
|
+
const step = () => {
|
|
813
|
+
if (moveTokenRef.current !== token) return;
|
|
814
|
+
const t = el.currentTime || 0;
|
|
815
|
+
const rootEl = rootRef.current;
|
|
816
|
+
if (rootEl) {
|
|
817
|
+
const W = window.innerWidth;
|
|
818
|
+
const H = window.innerHeight;
|
|
819
|
+
let ratioX;
|
|
820
|
+
if (t <= leadSec) ratioX = startRatio;
|
|
821
|
+
else if (t >= duration - tailSec) ratioX = targetRatio;
|
|
822
|
+
else ratioX = startRatio + dir * totalRatio * ((t - leadSec) / travelWindow);
|
|
823
|
+
const px = ratioX * W;
|
|
824
|
+
const py = startYRatio * H;
|
|
825
|
+
rootEl.style.left = px - halfW + "px";
|
|
826
|
+
rootEl.style.top = py - halfH + "px";
|
|
827
|
+
rootEl.style.right = "auto";
|
|
828
|
+
rootEl.style.bottom = "auto";
|
|
829
|
+
}
|
|
830
|
+
if (t < duration - tailSec) moveRef.current = requestAnimationFrame(step);
|
|
831
|
+
else {
|
|
832
|
+
moveRef.current = null;
|
|
833
|
+
setCustomPos({
|
|
834
|
+
rx: targetRatio,
|
|
835
|
+
ry: startYRatio
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
moveRef.current = requestAnimationFrame(step);
|
|
840
|
+
};
|
|
841
|
+
const tryMove = () => {
|
|
842
|
+
if (moveRef.current !== null || pendingMoveRef.current) return true;
|
|
843
|
+
const actions = ANIM.moves.actions;
|
|
844
|
+
if (!actions.length) return false;
|
|
845
|
+
const chosen = actions[Math.floor(Math.random() * actions.length)];
|
|
846
|
+
const mp = Object.assign({}, ANIM.moves.default, chosen.params || {});
|
|
847
|
+
const dir = facingRef.current === "right" !== ANIM.turn.includes(animRef.current) ? 1 : -1;
|
|
848
|
+
const W = window.innerWidth;
|
|
849
|
+
const cx = currentCenterX();
|
|
850
|
+
const distance = randomBetween(mp.minDist, mp.maxDist);
|
|
851
|
+
const target = cx + dir * distance;
|
|
852
|
+
const leftBound = mp.margin + halfW;
|
|
853
|
+
const rightBound = W - mp.margin - halfW;
|
|
854
|
+
if (target < leftBound || target > rightBound) return false;
|
|
855
|
+
pendingMoveRef.current = {
|
|
856
|
+
startRatio: cx / W,
|
|
857
|
+
startYRatio: currentCenterY() / window.innerHeight,
|
|
858
|
+
targetRatio: target / W,
|
|
859
|
+
dir,
|
|
860
|
+
totalRatio: Math.abs(target - cx) / W,
|
|
861
|
+
leadSec: mp.leadSec,
|
|
862
|
+
tailSec: mp.tailSec
|
|
863
|
+
};
|
|
864
|
+
setOnce(true);
|
|
865
|
+
setAnim(chosen.name);
|
|
866
|
+
return true;
|
|
867
|
+
};
|
|
868
|
+
const stopMove = () => {
|
|
869
|
+
pendingMoveRef.current = null;
|
|
870
|
+
moveTokenRef.current++;
|
|
871
|
+
if (moveRef.current !== null) {
|
|
872
|
+
cancelAnimationFrame(moveRef.current);
|
|
873
|
+
moveRef.current = null;
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
const facingRef = useRef(facing);
|
|
877
|
+
facingRef.current = facing;
|
|
878
|
+
const handlePointerDown = (e) => {
|
|
879
|
+
e.currentTarget.classList.add("dragging");
|
|
880
|
+
stopMove();
|
|
881
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
882
|
+
const rootEl = rootRef.current;
|
|
883
|
+
let offX = 0;
|
|
884
|
+
let offY = 0;
|
|
885
|
+
if (rootEl) {
|
|
886
|
+
const rr = rootEl.getBoundingClientRect();
|
|
887
|
+
offX = e.clientX - (rr.left + rr.width / 2);
|
|
888
|
+
offY = e.clientY - (rr.top + rr.height / 2);
|
|
889
|
+
}
|
|
890
|
+
dragRef.current = {
|
|
891
|
+
active: true,
|
|
892
|
+
dragging: false,
|
|
893
|
+
sx: e.clientX,
|
|
894
|
+
sy: e.clientY,
|
|
895
|
+
offX,
|
|
896
|
+
offY
|
|
897
|
+
};
|
|
898
|
+
};
|
|
899
|
+
const handlePointerMove = (e) => {
|
|
900
|
+
const d = dragRef.current;
|
|
901
|
+
if (!d.active) return;
|
|
902
|
+
const dx = e.clientX - d.sx;
|
|
903
|
+
const dy = e.clientY - d.sy;
|
|
904
|
+
if (!d.dragging) {
|
|
905
|
+
if (Math.hypot(dx, dy) < DRAG_THRESHOLD) return;
|
|
906
|
+
d.dragging = true;
|
|
907
|
+
setDragging(true);
|
|
908
|
+
setOnce(true);
|
|
909
|
+
if (ANIM.drag.length) setAnim(pick(ANIM.drag));
|
|
910
|
+
}
|
|
911
|
+
const rootEl = rootRef.current;
|
|
912
|
+
if (rootEl) {
|
|
913
|
+
rootEl.style.left = e.clientX - d.offX - halfW + "px";
|
|
914
|
+
rootEl.style.top = e.clientY - d.offY - halfH + "px";
|
|
915
|
+
rootEl.style.right = "auto";
|
|
916
|
+
rootEl.style.bottom = "auto";
|
|
917
|
+
}
|
|
918
|
+
const stageEl = stageRef.current;
|
|
919
|
+
if (stageEl) stageEl.style.transform = "none";
|
|
920
|
+
};
|
|
921
|
+
const handlePointerUp = (e) => {
|
|
922
|
+
const d = dragRef.current;
|
|
923
|
+
const wasDragging = d.dragging;
|
|
924
|
+
d.active = false;
|
|
925
|
+
d.dragging = false;
|
|
926
|
+
e.currentTarget.classList.remove("dragging");
|
|
927
|
+
if (wasDragging) {
|
|
928
|
+
justDraggedRef.current = true;
|
|
929
|
+
setTimeout(() => {
|
|
930
|
+
justDraggedRef.current = false;
|
|
931
|
+
}, 100);
|
|
932
|
+
setDragging(false);
|
|
933
|
+
setCustomPos({
|
|
934
|
+
rx: (e.clientX - d.offX) / window.innerWidth,
|
|
935
|
+
ry: (e.clientY - d.offY) / window.innerHeight
|
|
936
|
+
});
|
|
937
|
+
const stageEl = stageRef.current;
|
|
938
|
+
if (stageEl) stageEl.style.transform = "translateY(" + bottomPad + "px)";
|
|
939
|
+
if (ANIM.idle.length) setAnim(pick(ANIM.idle, animRef.current));
|
|
940
|
+
setOnce(false);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
const handleClick = (_e) => {
|
|
944
|
+
const d = dragRef.current;
|
|
945
|
+
if (d.active || d.dragging || justDraggedRef.current) return;
|
|
946
|
+
if (once && !ANIM.idle.includes(animRef.current)) return;
|
|
947
|
+
stopMove();
|
|
948
|
+
setOnce(true);
|
|
949
|
+
if (ANIM.clicks.length) setAnim(pick(ANIM.clicks));
|
|
950
|
+
};
|
|
951
|
+
const bottomPad = size * (9 / 16) * (CANVAS_H - FEET_Y) / CANVAS_H;
|
|
952
|
+
const stageStyle = dragging ? { transform: "none" } : { transform: "translateY(" + bottomPad + "px)" };
|
|
953
|
+
const rootStyle = customPos ? (() => {
|
|
954
|
+
const rx = customPos.rx;
|
|
955
|
+
const ry = customPos.ry;
|
|
956
|
+
const left = Math.min(Math.max(rx * window.innerWidth - halfW, 0), window.innerWidth - size);
|
|
957
|
+
const top = Math.min(Math.max(ry * window.innerHeight - halfH, 0), window.innerHeight - size * 9 / 16);
|
|
958
|
+
return {
|
|
959
|
+
left: left + "px",
|
|
960
|
+
top: top + "px",
|
|
961
|
+
right: "auto",
|
|
962
|
+
bottom: "auto"
|
|
963
|
+
};
|
|
964
|
+
})() : {};
|
|
965
|
+
const commonVideoProps = {
|
|
966
|
+
muted: true,
|
|
967
|
+
playsInline: true,
|
|
968
|
+
autoPlay: true,
|
|
969
|
+
title: "dsh-pet"
|
|
970
|
+
};
|
|
971
|
+
const hitProps = {
|
|
972
|
+
className: "dsh-pet-hit",
|
|
973
|
+
style: {
|
|
974
|
+
left: HIT_BOX.x0 / 640 * 100 + "%",
|
|
975
|
+
top: HIT_BOX.y0 / 360 * 100 + "%",
|
|
976
|
+
width: (HIT_BOX.x1 - HIT_BOX.x0) / 640 * 100 + "%",
|
|
977
|
+
height: (HIT_BOX.y1 - HIT_BOX.y0) / 360 * 100 + "%"
|
|
978
|
+
},
|
|
979
|
+
onMouseEnter: (e) => {
|
|
980
|
+
if (!dragRef.current.active) e.currentTarget.style.cursor = "grab";
|
|
981
|
+
},
|
|
982
|
+
onMouseLeave: (e) => {
|
|
983
|
+
if (!dragRef.current.active) e.currentTarget.style.cursor = "default";
|
|
984
|
+
},
|
|
985
|
+
onClick: handleClick,
|
|
986
|
+
onPointerDown: handlePointerDown,
|
|
987
|
+
onPointerMove: handlePointerMove,
|
|
988
|
+
onPointerUp: handlePointerUp,
|
|
989
|
+
onPointerCancel: handlePointerUp,
|
|
990
|
+
title: "dsh-pet"
|
|
991
|
+
};
|
|
992
|
+
return h("div", {
|
|
993
|
+
ref: rootRef,
|
|
994
|
+
className: "dsh-pet-root",
|
|
995
|
+
"data-corner": corner,
|
|
996
|
+
"data-facing": facing,
|
|
997
|
+
style: Object.assign({
|
|
998
|
+
"--dsh-pet-size": size + "px",
|
|
999
|
+
"--dsh-pet-mx": margin.x + "px",
|
|
1000
|
+
"--dsh-pet-my": margin.y + "px"
|
|
1001
|
+
}, rootStyle),
|
|
1002
|
+
children: h("div", {
|
|
1003
|
+
ref: stageRef,
|
|
1004
|
+
className: "dsh-pet-stage",
|
|
1005
|
+
style: stageStyle,
|
|
1006
|
+
children: [
|
|
1007
|
+
h("video", Object.assign({}, commonVideoProps, {
|
|
1008
|
+
ref: videoARef,
|
|
1009
|
+
className: "dsh-pet-video is-front"
|
|
1010
|
+
})),
|
|
1011
|
+
h("video", Object.assign({}, commonVideoProps, {
|
|
1012
|
+
ref: videoBRef,
|
|
1013
|
+
className: "dsh-pet-video"
|
|
1014
|
+
})),
|
|
1015
|
+
h("div", hitProps)
|
|
1016
|
+
]
|
|
1017
|
+
})
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
function PetMulti() {
|
|
1021
|
+
const [pets, setPets] = useState([]);
|
|
1022
|
+
const [ready, setReady] = useState(false);
|
|
1023
|
+
useEffect(() => {
|
|
1024
|
+
let alive = true;
|
|
1025
|
+
(async () => {
|
|
1026
|
+
try {
|
|
1027
|
+
const r1 = await fetch("/pet/config.jsonc");
|
|
1028
|
+
if (!r1.ok) return;
|
|
1029
|
+
const obj = JSON.parse(stripJsonc(await r1.text()));
|
|
1030
|
+
ANIM = buildAnim(obj);
|
|
1031
|
+
const defaults = extractDefaultPets(obj);
|
|
1032
|
+
let user = {};
|
|
1033
|
+
try {
|
|
1034
|
+
const r2 = await fetch("/pet/config");
|
|
1035
|
+
if (r2.ok && r2.status !== 204) user = await r2.json().catch(() => ({}));
|
|
1036
|
+
} catch {}
|
|
1037
|
+
const merged = resolvePets(defaults, user);
|
|
1038
|
+
if (!alive) return;
|
|
1039
|
+
petBridge.current = merged;
|
|
1040
|
+
petBridge.template = defaults.length ? defaults[0] : null;
|
|
1041
|
+
petBridge.sync = (list) => {
|
|
1042
|
+
setPets(list);
|
|
1043
|
+
petBridge.current = list;
|
|
1044
|
+
};
|
|
1045
|
+
setPets(merged);
|
|
1046
|
+
setReady(true);
|
|
1047
|
+
} catch {}
|
|
1048
|
+
})();
|
|
1049
|
+
return () => {
|
|
1050
|
+
alive = false;
|
|
1051
|
+
petBridge.sync = null;
|
|
1052
|
+
};
|
|
1053
|
+
}, []);
|
|
1054
|
+
return ready ? pets.map((p) => h(PetCard, {
|
|
1055
|
+
key: p.id,
|
|
1056
|
+
cfg: p
|
|
1057
|
+
})) : null;
|
|
1058
|
+
}
|
|
1059
|
+
const name = "pet";
|
|
1060
|
+
const inject = ["slots", "locale"];
|
|
1061
|
+
function apply(ctx, _config) {
|
|
1062
|
+
ctx.effect(() => ctx.locale.register(NS, {
|
|
1063
|
+
zh,
|
|
1064
|
+
en
|
|
1065
|
+
}), "dsh-pet: dictionaries");
|
|
1066
|
+
const t = ctx.locale.bind(NS);
|
|
1067
|
+
ctx.slots.inject("shell.overlay", function* () {
|
|
1068
|
+
yield ctx.slots.register({
|
|
1069
|
+
name: "shell.overlay",
|
|
1070
|
+
id: "pet",
|
|
1071
|
+
order: 1e3
|
|
1072
|
+
}, () => h(PetMulti, {}));
|
|
1073
|
+
});
|
|
1074
|
+
const PetConfigSection = makePetConfigSection({
|
|
1075
|
+
h,
|
|
1076
|
+
useState,
|
|
1077
|
+
t
|
|
1078
|
+
});
|
|
1079
|
+
ctx.slots.inject("settings.section", function* () {
|
|
1080
|
+
yield ctx.slots.register({
|
|
1081
|
+
name: "settings.section",
|
|
1082
|
+
id: "pet-config",
|
|
1083
|
+
order: 30,
|
|
1084
|
+
label: () => t("nav"),
|
|
1085
|
+
inject: () => ({ t })
|
|
1086
|
+
}, PetConfigSection);
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
module.exports = {
|
|
1090
|
+
apply,
|
|
1091
|
+
inject,
|
|
1092
|
+
name
|
|
1093
|
+
};
|
|
1094
|
+
return module.exports;
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region src/client/index.ts
|
|
1100
|
+
window.__ModuleLoader__.load({
|
|
1101
|
+
id: "dsh-pet",
|
|
1102
|
+
factory: makeFactory()
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
//#endregion
|