@hadoku/watchparty-ui 0.0.0-stage → 0.43.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/chunks/AdminPanel-Bvl3P2VE.js +227 -0
- package/dist/chunks/AdminPanel-Bvl3P2VE.js.map +1 -0
- package/dist/chunks/CharacterModal-Dg_XSm4A.js +158 -0
- package/dist/chunks/CharacterModal-Dg_XSm4A.js.map +1 -0
- package/dist/chunks/GameModule-Bx0847wv.js +1515 -0
- package/dist/chunks/GameModule-Bx0847wv.js.map +1 -0
- package/dist/chunks/MapEditor-DxIZeQqi.js +739 -0
- package/dist/chunks/MapEditor-DxIZeQqi.js.map +1 -0
- package/dist/chunks/MediaDrawer-BzR_DusQ.js +715 -0
- package/dist/chunks/MediaDrawer-BzR_DusQ.js.map +1 -0
- package/dist/chunks/PlaylistPanel-C8SqPoEz.js +321 -0
- package/dist/chunks/PlaylistPanel-C8SqPoEz.js.map +1 -0
- package/dist/chunks/Room-CPV26zAk.js +6107 -0
- package/dist/chunks/Room-CPV26zAk.js.map +1 -0
- package/dist/chunks/cover-AUIrlUMF.js +5 -0
- package/dist/chunks/cover-AUIrlUMF.js.map +1 -0
- package/dist/chunks/index-CwuV6ab3.js +10139 -0
- package/dist/chunks/index-CwuV6ab3.js.map +1 -0
- package/dist/chunks/submissionsApi-CqGsgEg5.js +317 -0
- package/dist/chunks/submissionsApi-CqGsgEg5.js.map +1 -0
- package/dist/index.d.ts +1288 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/room-chrome.css +1 -0
- package/dist/room-chrome.d.ts +93 -0
- package/dist/room-chrome.js +3154 -0
- package/dist/room-chrome.js.map +1 -0
- package/dist/watchparty-ui.css +1 -0
- package/package.json +49 -4
|
@@ -0,0 +1,3154 @@
|
|
|
1
|
+
import { jsx as l, jsxs as b, Fragment as Ne } from "react/jsx-runtime";
|
|
2
|
+
import Bt, { useState as P, useRef as J, useMemo as Q, useCallback as N, useEffect as O, createContext as Gt, useContext as Wt, useId as On, useEffectEvent as Kt } from "react";
|
|
3
|
+
import { themePrefs as ce, Icon as Rn, THEMES as Dn, useHadokuThemeOptional as Ln } from "@wolffm/themes";
|
|
4
|
+
import { z as r } from "zod";
|
|
5
|
+
import { createCdnClient as jn, kindOfType as Un, MAX_BYTES as Fn, measureImage as Hn, filesFromClipboard as $n, filesFromDrop as Bn, CdnError as ze } from "@wolffm/cdn-client";
|
|
6
|
+
import { create as Gn } from "zustand";
|
|
7
|
+
import { createPrefsClient as Wn, getDeviceId as Kn, DEVICE_ID_KEY as qn } from "@wolffm/prefs-client";
|
|
8
|
+
import { io as Vn } from "socket.io-client";
|
|
9
|
+
import { resolveIdentityReassert as zn } from "@wolffm/rooms-protocol";
|
|
10
|
+
import { createPortal as Yn } from "react-dom";
|
|
11
|
+
import { useCatalogueSearch as Xn } from "@wolffm/cdn-client/react";
|
|
12
|
+
const qt = "https://cdn.hadoku.me", Vt = /^[0-9a-f]{64}\.(?:png|jpe?g|gif|webp|avif)$/;
|
|
13
|
+
function et(e) {
|
|
14
|
+
return typeof e == "string" && Vt.test(e);
|
|
15
|
+
}
|
|
16
|
+
const tt = 8080, zt = 5173, Jn = "/watchparty/ws", Yt = 500, Zn = 1e3, Y = 4, Xt = typeof process < "u" && process.env ? process.env : {};
|
|
17
|
+
Xt.PRODUCTION_UI_URL;
|
|
18
|
+
Xt.PRODUCTION_SERVER_URL;
|
|
19
|
+
const Ce = r.enum(["S", "A", "B", "C", "D", "F"]), bt = 2e4, Qn = 300;
|
|
20
|
+
r.object({
|
|
21
|
+
name: r.string().min(1).max(32).optional(),
|
|
22
|
+
sprite: r.string().min(1).max(32).optional()
|
|
23
|
+
});
|
|
24
|
+
const I = {
|
|
25
|
+
JOIN: "join",
|
|
26
|
+
SNAPSHOT: "snapshot",
|
|
27
|
+
CONTROL_ACK: "control_ack",
|
|
28
|
+
CONTROL_BROADCAST: "control_broadcast",
|
|
29
|
+
CHAT_SEND: "chat_send",
|
|
30
|
+
CHAT_BROADCAST: "chat_broadcast",
|
|
31
|
+
CHAT_HISTORY: "chat_history",
|
|
32
|
+
PRESENCE: "presence",
|
|
33
|
+
IDENTITY_UPDATE: "identity_update",
|
|
34
|
+
TIME_PING: "time_ping",
|
|
35
|
+
TIME_PONG: "time_pong",
|
|
36
|
+
HEALTH_SNAPSHOT: "health_snapshot",
|
|
37
|
+
BUFFER_STATUS: "buffer_status",
|
|
38
|
+
CLIENT_READY: "client_ready",
|
|
39
|
+
// 'ready_state' here = playback-readiness gate (distinct from READY_EVENTS.STATE = "ready check" UX feature)
|
|
40
|
+
READY_STATE: "ready_state",
|
|
41
|
+
ERROR: "error"
|
|
42
|
+
}, er = r.enum(["play", "pause", "seek", "load", "home"]), tr = r.object({
|
|
43
|
+
framed: r.boolean(),
|
|
44
|
+
depth: r.number().int().nonnegative().max(10)
|
|
45
|
+
});
|
|
46
|
+
r.object({
|
|
47
|
+
room_key: r.string(),
|
|
48
|
+
name: r.string().min(1).max(32).optional(),
|
|
49
|
+
sprite: r.string().min(1).max(32).optional(),
|
|
50
|
+
embed: tr.optional(),
|
|
51
|
+
/** Which media-delivery path this client resolved to ('range' | 'fragment').
|
|
52
|
+
* Optional so older clients still validate. Reported so a party's logs can be split by
|
|
53
|
+
* arm — without it an A/B rollout is unmeasurable, exactly as entry path was before
|
|
54
|
+
* `embed` existed. */
|
|
55
|
+
delivery_arm: r.enum(["range", "fragment"]).optional(),
|
|
56
|
+
/** Browser-persisted device id (`hadoku_device_id`, owned by
|
|
57
|
+
* @wolffm/prefs-client). Lets the server derive a `dev:`-tier
|
|
58
|
+
* ParticipantId for a client with no friend key, so an anonymous viewer
|
|
59
|
+
* keeps their identity across a reload instead of becoming a new person.
|
|
60
|
+
*
|
|
61
|
+
* Optional because it genuinely is: a first-ever visit, or a browser with
|
|
62
|
+
* storage blocked, sends nothing and gets an `eph:` identity. Also keeps
|
|
63
|
+
* older clients validating.
|
|
64
|
+
*
|
|
65
|
+
* CLIENT-ASSERTED — nothing proves it, so it must never gate a capability.
|
|
66
|
+
* See `isAuthenticatedTier` in @wolffm/rooms-protocol. */
|
|
67
|
+
device_id: r.string().min(1).max(128).optional(),
|
|
68
|
+
/** Random per PAGE LOAD, carried on every rejoin from that page. A join whose
|
|
69
|
+
* tab id matches a live connection of the same participant is that tab
|
|
70
|
+
* reconnecting, so the server retires the old connection at once instead of
|
|
71
|
+
* showing it as a second row until the heartbeat reaps it (mistral-bluff
|
|
72
|
+
* 2026-10-20). Never broadcast: it is what lets a rejoin evict a connection.
|
|
73
|
+
* CLIENT-ASSERTED, so it never gates a capability. */
|
|
74
|
+
tab_id: r.string().min(8).max(64).optional(),
|
|
75
|
+
/** Present on a rejoin only: why this page's previous connection ended, as the
|
|
76
|
+
* BROWSER saw it, and for how long it was gone. The server cannot know either
|
|
77
|
+
* — a connection cut upstream never reaches it as a close. */
|
|
78
|
+
reconnect: r.object({
|
|
79
|
+
count: r.number().int().nonnegative(),
|
|
80
|
+
reason: r.string().max(64),
|
|
81
|
+
offline_ms: r.number().int().nonnegative()
|
|
82
|
+
}).optional()
|
|
83
|
+
});
|
|
84
|
+
r.object({
|
|
85
|
+
// The room's id — the same for every participant, unlike the key each one
|
|
86
|
+
// joined with (a leader key is a credential). What a game bundle is told
|
|
87
|
+
// its room is (GameBundleSlot).
|
|
88
|
+
room_id: r.string(),
|
|
89
|
+
play_state: r.enum(["idle", "playing", "paused", "ended"]),
|
|
90
|
+
playhead_ms: r.number().int().nonnegative(),
|
|
91
|
+
leader_id: r.string().nullable(),
|
|
92
|
+
media_id: r.string().nullable(),
|
|
93
|
+
server_seq: r.number().int().nonnegative(),
|
|
94
|
+
server_ts: r.number().int().nonnegative()
|
|
95
|
+
});
|
|
96
|
+
r.object({
|
|
97
|
+
client_seq: r.number().int().positive(),
|
|
98
|
+
kind: er,
|
|
99
|
+
to_ms: r.number().int().nonnegative().optional(),
|
|
100
|
+
media_id: r.string().optional()
|
|
101
|
+
// leader_id removed - not needed since set_leader control was removed
|
|
102
|
+
});
|
|
103
|
+
const Jt = r.object({
|
|
104
|
+
key: r.string().regex(Vt, "not a CDN image key"),
|
|
105
|
+
/**
|
|
106
|
+
* Intrinsic pixels, or **0 meaning "unknown"**.
|
|
107
|
+
*
|
|
108
|
+
* `nonnegative`, not `positive`: `measureImage()` falls back to 0x0 when a
|
|
109
|
+
* file cannot be decoded (a corrupt paste, or a format `createImageBitmap`
|
|
110
|
+
* and the `<img>` fallback both refuse), and the renderer has always handled
|
|
111
|
+
* that — `hasDims = w > 0 && h > 0` drops it to natural flow instead of
|
|
112
|
+
* reserving a box. The schema disagreed, so such a message failed validation
|
|
113
|
+
* and was DROPPED by the server: the paste vanished and the user's typed
|
|
114
|
+
* text went with it, with nothing said. Widening is backward compatible —
|
|
115
|
+
* every message already in history carries positive dimensions.
|
|
116
|
+
*/
|
|
117
|
+
w: r.number().int().nonnegative().max(bt),
|
|
118
|
+
h: r.number().int().nonnegative().max(bt),
|
|
119
|
+
/**
|
|
120
|
+
* Human-readable description, rendered as the `alt` text.
|
|
121
|
+
*
|
|
122
|
+
* Present for a meme picked from the shared library (where it is frequently
|
|
123
|
+
* the ONLY text describing the image, so a meme-heavy log is unusable with a
|
|
124
|
+
* screen reader without it) and absent for a pasted screenshot, which has no
|
|
125
|
+
* title to carry. Optional so that older clients — and every message already
|
|
126
|
+
* in chat history — still validate.
|
|
127
|
+
*
|
|
128
|
+
* It is untrusted text from another client and is rendered as an attribute
|
|
129
|
+
* value only, never as markup. Bounded so one message cannot carry a
|
|
130
|
+
* paragraph; the library's own titles run well under this.
|
|
131
|
+
*/
|
|
132
|
+
title: r.string().max(Qn).optional()
|
|
133
|
+
});
|
|
134
|
+
r.object({
|
|
135
|
+
text: r.string().max(Yt),
|
|
136
|
+
style: r.string().max(64).optional(),
|
|
137
|
+
images: r.array(Jt).max(Y).optional()
|
|
138
|
+
}).refine((e) => e.text.length > 0 || (e.images?.length ?? 0) > 0, { message: "message must carry text or at least one image" });
|
|
139
|
+
const nr = r.enum(["join", "leave", "media_change", "identity_change", "recap"]);
|
|
140
|
+
r.object({
|
|
141
|
+
id: r.string(),
|
|
142
|
+
client_id: r.string(),
|
|
143
|
+
// The sender's participant handle — stable across their reconnects, unlike
|
|
144
|
+
// `client_id`. Optional: system messages and pre-existing history have none.
|
|
145
|
+
author: r.string().optional(),
|
|
146
|
+
name: r.string(),
|
|
147
|
+
sprite: r.string().nullable(),
|
|
148
|
+
text: r.string(),
|
|
149
|
+
ts: r.number(),
|
|
150
|
+
// Optional so a client on an older bundle still validates a message that
|
|
151
|
+
// has none, and so system messages (which never carry images) stay unchanged.
|
|
152
|
+
images: r.array(Jt).max(Y).optional(),
|
|
153
|
+
isSystem: r.boolean().optional(),
|
|
154
|
+
systemType: nr.optional()
|
|
155
|
+
});
|
|
156
|
+
const rr = r.object({
|
|
157
|
+
avg_download_rate_bps: r.number().nonnegative(),
|
|
158
|
+
buffered_ahead_ms: r.number().nonnegative(),
|
|
159
|
+
rtt_ms: r.number().nonnegative(),
|
|
160
|
+
playhead_ms: r.number().nonnegative(),
|
|
161
|
+
is_buffering: r.boolean(),
|
|
162
|
+
fragments_loaded: r.number().int().nonnegative(),
|
|
163
|
+
fragments_pending: r.number().int().nonnegative(),
|
|
164
|
+
fragments_error: r.number().int().nonnegative(),
|
|
165
|
+
video_ready_state: r.number().int().optional(),
|
|
166
|
+
/** Buffered-ahead of the WORST AUDIO track, ms. `buffered_ahead_ms` above is
|
|
167
|
+
* already the min across video and audio; this is reported separately so the
|
|
168
|
+
* health card (and any later analysis) can say WHICH track is starving.
|
|
169
|
+
* -1 means "no audio FragmentManager" (media still loading, or audio not yet
|
|
170
|
+
* attached) and must never be treated as a zero-length buffer. Defaults to
|
|
171
|
+
* -1 so older clients, which never send it, are read as "unknown". */
|
|
172
|
+
audio_buffered_ahead_ms: r.number().default(-1),
|
|
173
|
+
// Nominal media duration (ms) = last fragment's end. Lets the leader's health
|
|
174
|
+
// card distinguish "near end-of-stream, little buffer ahead is expected" from
|
|
175
|
+
// a real low-buffer stall. Defaults to 0 so older clients still validate.
|
|
176
|
+
duration_ms: r.number().nonnegative().default(0),
|
|
177
|
+
/** Media delivery path this client is actually using. Reported HERE and not only at
|
|
178
|
+
* join because the join-time value is provisional — /api/flags lands after the socket
|
|
179
|
+
* connects, so the arm is not final until FragmentManager first reads it. Optional so
|
|
180
|
+
* older clients still validate. */
|
|
181
|
+
delivery_arm: r.enum(["range", "fragment"]).optional(),
|
|
182
|
+
/** Page state, so a stall can be read against what the viewer could see.
|
|
183
|
+
* Without it "he says he saw nothing" and "his player froze for 55s" could
|
|
184
|
+
* not be reconciled (mistral-bluff 2026-10-20). All optional: older
|
|
185
|
+
* clients omit them, and `net_*` exist only where the browser exposes
|
|
186
|
+
* navigator.connection (Chromium). */
|
|
187
|
+
page_visible: r.boolean().optional(),
|
|
188
|
+
page_focused: r.boolean().optional(),
|
|
189
|
+
muted: r.boolean().optional(),
|
|
190
|
+
online: r.boolean().optional(),
|
|
191
|
+
net_type: r.string().max(16).optional(),
|
|
192
|
+
net_rtt_ms: r.number().nonnegative().optional(),
|
|
193
|
+
net_downlink_mbps: r.number().nonnegative().optional(),
|
|
194
|
+
/** ms since this connection last received a time_pong — a half-open
|
|
195
|
+
* socket shows here as a growing number while everything else looks fine. */
|
|
196
|
+
pong_age_ms: r.number().int().nonnegative().optional(),
|
|
197
|
+
reported_at: r.number().int().nonnegative()
|
|
198
|
+
}), or = rr.extend({
|
|
199
|
+
client_id: r.string(),
|
|
200
|
+
name: r.string(),
|
|
201
|
+
sprite_id: r.string().nullable(),
|
|
202
|
+
/** Set when this connected client's last report is older than the freshness
|
|
203
|
+
* window: how old it is, ms. The card then shows the client as silent
|
|
204
|
+
* rather than dropping it — a viewer whose reports cannot get through is the
|
|
205
|
+
* one the leader most needs to see. */
|
|
206
|
+
stale_ms: r.number().int().nonnegative().optional()
|
|
207
|
+
});
|
|
208
|
+
r.object({
|
|
209
|
+
clients: r.array(or),
|
|
210
|
+
server_ts: r.number().int().nonnegative()
|
|
211
|
+
});
|
|
212
|
+
const ir = r.object({
|
|
213
|
+
client_id: r.string(),
|
|
214
|
+
sprite_id: r.string().nullable(),
|
|
215
|
+
name: r.string(),
|
|
216
|
+
buffered_ahead_ms: r.number().nonnegative(),
|
|
217
|
+
// playhead + duration let the viewer buffer ring apply the same near-end
|
|
218
|
+
// exemption the leader's health card uses: near end-of-stream there is
|
|
219
|
+
// legitimately little buffer ahead, so a low buffered_ahead_ms there must NOT
|
|
220
|
+
// render "critical" red. Default 0 so older clients still validate.
|
|
221
|
+
playhead_ms: r.number().nonnegative().default(0),
|
|
222
|
+
duration_ms: r.number().nonnegative().default(0),
|
|
223
|
+
/** The video element's readyState, forwarded so the viewer buffer ring can
|
|
224
|
+
* apply the same "plenty buffered but the element cannot advance" rule the
|
|
225
|
+
* leader's card uses (see components/bufferHealth.ts). -1 = unknown/older
|
|
226
|
+
* client, which must never trip the rule. */
|
|
227
|
+
video_ready_state: r.number().int().default(-1)
|
|
228
|
+
});
|
|
229
|
+
r.object({
|
|
230
|
+
clients: r.array(ir),
|
|
231
|
+
server_ts: r.number().int().nonnegative()
|
|
232
|
+
});
|
|
233
|
+
r.object({
|
|
234
|
+
media_id: r.string()
|
|
235
|
+
});
|
|
236
|
+
const nt = r.enum(["super_upvote", "upvote", "mid", "downvote"]), ar = r.object({
|
|
237
|
+
mediaId: r.string(),
|
|
238
|
+
displayName: r.string(),
|
|
239
|
+
// Enrichment fields — present for flat-playlist ingest output, absent for
|
|
240
|
+
// subfolder-layout playlist clips. All optional so old playlist.json stays valid.
|
|
241
|
+
description: r.string().optional(),
|
|
242
|
+
thumbnail: r.string().optional(),
|
|
243
|
+
// media-relative path, e.g. output/fmp4/.../poster.jpg
|
|
244
|
+
durationMs: r.number().optional(),
|
|
245
|
+
uploadDate: r.string().optional()
|
|
246
|
+
// YouTube upload date 'YYYY-MM-DD'; drives playlist order
|
|
247
|
+
}), sr = r.enum(["basic", "vote"]), Zt = r.object({
|
|
248
|
+
id: r.string(),
|
|
249
|
+
name: r.string(),
|
|
250
|
+
type: sr.default("vote"),
|
|
251
|
+
videos: r.array(ar),
|
|
252
|
+
cover: r.string().optional()
|
|
253
|
+
// media-relative path to the playlist cover image
|
|
254
|
+
});
|
|
255
|
+
r.object({ playlistId: r.string() });
|
|
256
|
+
r.object({ index: r.number().int().min(0) });
|
|
257
|
+
r.object({
|
|
258
|
+
playlistId: r.string(),
|
|
259
|
+
mediaId: r.string(),
|
|
260
|
+
vote: nt
|
|
261
|
+
});
|
|
262
|
+
r.object({ voterKey: r.string().min(1).max(128) });
|
|
263
|
+
r.object({ playlistId: r.string(), mediaIds: r.array(r.string()) });
|
|
264
|
+
r.object({
|
|
265
|
+
playlist: Zt.nullable(),
|
|
266
|
+
activeIndex: r.number().int().nullable(),
|
|
267
|
+
myVotes: r.record(r.string(), nt)
|
|
268
|
+
// mediaId -> VoteValue
|
|
269
|
+
});
|
|
270
|
+
const lr = r.object({
|
|
271
|
+
clientId: r.string(),
|
|
272
|
+
name: r.string(),
|
|
273
|
+
votedCount: r.number().int().nonnegative(),
|
|
274
|
+
totalVideos: r.number().int().nonnegative()
|
|
275
|
+
});
|
|
276
|
+
r.object({
|
|
277
|
+
progress: r.array(lr)
|
|
278
|
+
});
|
|
279
|
+
r.object({
|
|
280
|
+
playlist: Zt,
|
|
281
|
+
votes: r.record(r.string(), r.record(r.string(), nt)),
|
|
282
|
+
// votes[clientId][mediaId]
|
|
283
|
+
names: r.record(r.string(), r.string()),
|
|
284
|
+
// clientId -> display name
|
|
285
|
+
/** clientId -> sprite id, frozen at reveal, so a voter who has since LEFT
|
|
286
|
+
* (and so is gone from the live roster) still renders. Optional: older
|
|
287
|
+
* servers omit it and clients fall back to the roster. */
|
|
288
|
+
sprites: r.record(r.string(), r.string()).optional(),
|
|
289
|
+
/** True when this re-sends results after a voter was removed. A client whose
|
|
290
|
+
* reveal is closed ignores it, rather than having the popup reappear. */
|
|
291
|
+
update: r.boolean().optional()
|
|
292
|
+
});
|
|
293
|
+
const ye = {
|
|
294
|
+
STATE: "playlist_state",
|
|
295
|
+
VOTE_PROGRESS: "playlist_vote_progress",
|
|
296
|
+
RESULTS: "playlist_results",
|
|
297
|
+
/** Server -> the removed voter: forget the ballot you hold in localStorage. */
|
|
298
|
+
VOTES_CLEARED: "playlist_votes_cleared"
|
|
299
|
+
}, Qt = r.object({
|
|
300
|
+
id: r.string(),
|
|
301
|
+
displayName: r.string(),
|
|
302
|
+
thumbnail: r.string().optional()
|
|
303
|
+
});
|
|
304
|
+
r.object({
|
|
305
|
+
items: r.array(Qt)
|
|
306
|
+
});
|
|
307
|
+
const en = r.partialRecord(Ce, r.array(r.string()));
|
|
308
|
+
r.object({ board: en });
|
|
309
|
+
const cr = r.object({
|
|
310
|
+
mediaId: r.string(),
|
|
311
|
+
tier: Ce,
|
|
312
|
+
absoluteTier: Ce,
|
|
313
|
+
/** Tier level + within-row position. Integer part is the tier. */
|
|
314
|
+
score: r.number(),
|
|
315
|
+
/** The consensus mean that decided the tier. Never the displayed number. */
|
|
316
|
+
placementScore: r.number(),
|
|
317
|
+
subRankOffset: r.number(),
|
|
318
|
+
votes: r.record(r.string(), Ce)
|
|
319
|
+
// opaque voterId -> the letter they gave
|
|
320
|
+
});
|
|
321
|
+
r.object({
|
|
322
|
+
items: r.array(Qt),
|
|
323
|
+
placed: r.array(cr),
|
|
324
|
+
unrated: r.array(r.string()),
|
|
325
|
+
spread: r.number(),
|
|
326
|
+
nudged: r.boolean(),
|
|
327
|
+
names: r.record(r.string(), r.string()),
|
|
328
|
+
sprites: r.record(r.string(), r.string()),
|
|
329
|
+
voterCount: r.number().int().nonnegative(),
|
|
330
|
+
myBoard: en
|
|
331
|
+
});
|
|
332
|
+
const dr = {
|
|
333
|
+
/** Broadcast to EVERY connected socket when anyone saves. Carries no board —
|
|
334
|
+
* it is a "re-fetch" ping, because the shared result is identical for all
|
|
335
|
+
* viewers but `myBoard` is not, and one payload cannot serve both. */
|
|
336
|
+
UPDATED: "tierlist_updated"
|
|
337
|
+
};
|
|
338
|
+
r.object({});
|
|
339
|
+
r.object({ ready: r.boolean() });
|
|
340
|
+
r.object({
|
|
341
|
+
active: r.boolean(),
|
|
342
|
+
ready: r.array(r.string())
|
|
343
|
+
// clientIds who have flagged ready
|
|
344
|
+
});
|
|
345
|
+
const ur = {
|
|
346
|
+
STATE: "ready_check_state"
|
|
347
|
+
// distinct from buffer-readiness 'ready_state'
|
|
348
|
+
}, tn = {
|
|
349
|
+
ACTIVE: "game_active",
|
|
350
|
+
// server -> room (room-wide active game id; null = none)
|
|
351
|
+
SYNC: "game_sync"
|
|
352
|
+
};
|
|
353
|
+
r.object({
|
|
354
|
+
gameId: r.string().min(1).max(32).nullable()
|
|
355
|
+
});
|
|
356
|
+
r.object({
|
|
357
|
+
count: r.number().int().min(0).max(9)
|
|
358
|
+
});
|
|
359
|
+
r.object({
|
|
360
|
+
gameId: r.string().nullable(),
|
|
361
|
+
// Present only while a game is active (ws/game.ts builds this from
|
|
362
|
+
// room.gameActivePreview + the live tallies). Optional so the cleared
|
|
363
|
+
// payload — a bare { gameId: null } — still validates.
|
|
364
|
+
hostClientId: r.string().nullable().optional(),
|
|
365
|
+
seed: r.number().optional(),
|
|
366
|
+
players: r.array(r.unknown()).optional(),
|
|
367
|
+
/** clientId -> wins this session. */
|
|
368
|
+
sessionWins: r.record(r.string(), r.number()).optional(),
|
|
369
|
+
botCount: r.number().optional()
|
|
370
|
+
});
|
|
371
|
+
r.object({
|
|
372
|
+
gameId: r.string().min(1).max(32)
|
|
373
|
+
});
|
|
374
|
+
const mr = r.object({
|
|
375
|
+
clientId: r.string(),
|
|
376
|
+
playerId: r.number().int().min(0),
|
|
377
|
+
name: r.string(),
|
|
378
|
+
// Selected character sprite id (sage/herald/cleric/knight/mage/brawler/
|
|
379
|
+
// wanderer/rogue). Optional — clients fall back to a colored square when
|
|
380
|
+
// missing. Drives both avatar rendering AND per-character bomb tinting in
|
|
381
|
+
// the Bevy game.
|
|
382
|
+
sprite: r.string().optional()
|
|
383
|
+
});
|
|
384
|
+
r.object({
|
|
385
|
+
gameId: r.string(),
|
|
386
|
+
hostClientId: r.string().nullable(),
|
|
387
|
+
seed: r.number().int(),
|
|
388
|
+
players: r.array(mr)
|
|
389
|
+
});
|
|
390
|
+
r.object({ d: r.unknown() });
|
|
391
|
+
r.object({ d: r.unknown() });
|
|
392
|
+
r.object({ fromClientId: r.string(), d: r.unknown() });
|
|
393
|
+
const pr = r.object({
|
|
394
|
+
playerId: r.number().int().min(0),
|
|
395
|
+
clientId: r.string().nullable(),
|
|
396
|
+
name: r.string(),
|
|
397
|
+
sprite: r.string().nullable(),
|
|
398
|
+
survived: r.boolean(),
|
|
399
|
+
roundScore: r.number().int().min(0).optional(),
|
|
400
|
+
sessionScore: r.number().int().min(0).optional(),
|
|
401
|
+
/** End-of-round upgrade snapshot — bombMax = max concurrent bombs the
|
|
402
|
+
* player could place; blastLen = blast radius in tiles, one direction.
|
|
403
|
+
* Optional so older client builds keep validating. */
|
|
404
|
+
bombMax: r.number().int().min(0).optional(),
|
|
405
|
+
blastLen: r.number().int().min(0).optional(),
|
|
406
|
+
// Per-pid match counters — all optional so older client builds keep
|
|
407
|
+
// validating against the schema. Server treats missing fields as 0.
|
|
408
|
+
kills: r.number().int().min(0),
|
|
409
|
+
selfKills: r.number().int().min(0).optional(),
|
|
410
|
+
firstBloods: r.number().int().min(0).optional(),
|
|
411
|
+
soulPickups: r.number().int().min(0).optional(),
|
|
412
|
+
powerupsCollected: r.number().int().min(0).optional(),
|
|
413
|
+
bombsPlaced: r.number().int().min(0).optional(),
|
|
414
|
+
blocksDestroyed: r.number().int().min(0).optional(),
|
|
415
|
+
kicks: r.number().int().min(0).optional(),
|
|
416
|
+
killsByKick: r.number().int().min(0).optional(),
|
|
417
|
+
killsByChain: r.number().int().min(0).optional(),
|
|
418
|
+
trapkills: r.number().int().min(0).optional(),
|
|
419
|
+
// Per-cluster multi-kill counters (operator spec: separate columns for
|
|
420
|
+
// double through deca-kill, where deca is the "10+" catch-all).
|
|
421
|
+
doubleKills: r.number().int().min(0).optional(),
|
|
422
|
+
tripleKills: r.number().int().min(0).optional(),
|
|
423
|
+
quadKills: r.number().int().min(0).optional(),
|
|
424
|
+
pentaKills: r.number().int().min(0).optional(),
|
|
425
|
+
hexaKills: r.number().int().min(0).optional(),
|
|
426
|
+
heptaKills: r.number().int().min(0).optional(),
|
|
427
|
+
octaKills: r.number().int().min(0).optional(),
|
|
428
|
+
nonaKills: r.number().int().min(0).optional(),
|
|
429
|
+
decaKills: r.number().int().min(0).optional()
|
|
430
|
+
});
|
|
431
|
+
r.object({
|
|
432
|
+
winnerPlayerId: r.number().int().min(0).nullable(),
|
|
433
|
+
draw: r.boolean(),
|
|
434
|
+
players: r.array(pr),
|
|
435
|
+
// Optional session metadata + round-level extras (Phase C).
|
|
436
|
+
sessionOver: r.boolean().optional(),
|
|
437
|
+
roundNo: r.number().int().min(0).optional(),
|
|
438
|
+
sessionScores: r.record(r.string(), r.number().int().min(0)).optional(),
|
|
439
|
+
maxMultiKill: r.number().int().min(0).optional(),
|
|
440
|
+
maxChainKill: r.number().int().min(0).optional()
|
|
441
|
+
});
|
|
442
|
+
const nn = [
|
|
443
|
+
{
|
|
444
|
+
id: "fantasy",
|
|
445
|
+
characters: [
|
|
446
|
+
{ id: "sage", color: "#7f7c84" },
|
|
447
|
+
{ id: "herald", color: "#bddaf9" },
|
|
448
|
+
{ id: "cleric", color: "#78855e" },
|
|
449
|
+
{ id: "knight", color: "#cfccc0" },
|
|
450
|
+
{ id: "mage", color: "#794983" },
|
|
451
|
+
{ id: "brawler", color: "#af4a33" },
|
|
452
|
+
{ id: "wanderer", color: "#936f42" },
|
|
453
|
+
{ id: "rogue", color: "#667240" }
|
|
454
|
+
]
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
id: "cyber",
|
|
458
|
+
characters: [
|
|
459
|
+
{ id: "gunner", color: "#b6a472" },
|
|
460
|
+
{ id: "chief", color: "#a47e4d" },
|
|
461
|
+
{ id: "walker", color: "#e0443a", rev: 2 },
|
|
462
|
+
{ id: "operative", color: "#347cae" }
|
|
463
|
+
]
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
id: "stream",
|
|
467
|
+
characters: [
|
|
468
|
+
{ id: "idol", color: "#eb82bf" },
|
|
469
|
+
{ id: "recluse", color: "#6d6880" },
|
|
470
|
+
{ id: "phantom", color: "#a4a3ae" },
|
|
471
|
+
{ id: "harlequin", color: "#e5d5c5" },
|
|
472
|
+
{ id: "doll", color: "#a02633", rev: 2 },
|
|
473
|
+
{ id: "imp", color: "#b398cb" }
|
|
474
|
+
]
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
id: "arcane",
|
|
478
|
+
characters: [
|
|
479
|
+
{ id: "apprentice", color: "#c6c15b" },
|
|
480
|
+
{ id: "prodigy", color: "#5b4a6a" },
|
|
481
|
+
{ id: "dreamer", color: "#97d0e4" },
|
|
482
|
+
{ id: "sunny", color: "#ee989b" },
|
|
483
|
+
{ id: "mentor", color: "#e1e0dc" }
|
|
484
|
+
]
|
|
485
|
+
}
|
|
486
|
+
], yt = 8, rt = nn.flatMap((e) => e.characters), Le = rt.map((e) => e.id), fr = Object.fromEntries(rt.map((e) => [e.id, e.color])), hr = Object.fromEntries(rt.map((e) => [e.id, "rev" in e ? e.rev : 1]));
|
|
487
|
+
function fe(e) {
|
|
488
|
+
return !!e && Le.includes(e);
|
|
489
|
+
}
|
|
490
|
+
const gr = 5e3, rn = { mode: "off", percent: 0 }, br = ["off", "on", "ab"];
|
|
491
|
+
function yr(e) {
|
|
492
|
+
return typeof e == "string" && br.includes(e);
|
|
493
|
+
}
|
|
494
|
+
function vr(e) {
|
|
495
|
+
const t = e && typeof e == "object" ? e : {}, n = yr(t.mode) ? t.mode : rn.mode, o = Number(t.percent), i = Number.isFinite(o) ? Math.min(100, Math.max(0, Math.round(o))) : 0;
|
|
496
|
+
return { mode: n, percent: i };
|
|
497
|
+
}
|
|
498
|
+
function wr(e) {
|
|
499
|
+
let t = 2166136261;
|
|
500
|
+
for (let n = 0; n < e.length; n++)
|
|
501
|
+
t ^= e.charCodeAt(n), t = Math.imul(t, 16777619) >>> 0;
|
|
502
|
+
return t >>> 0;
|
|
503
|
+
}
|
|
504
|
+
function Sr(e, t, n) {
|
|
505
|
+
if (n === !0)
|
|
506
|
+
return "fragment";
|
|
507
|
+
if (n === !1)
|
|
508
|
+
return "range";
|
|
509
|
+
const o = vr(e);
|
|
510
|
+
return o.mode === "on" ? "fragment" : o.mode === "off" || o.percent <= 0 ? "range" : o.percent >= 100 || t && wr(t) % 100 < o.percent ? "fragment" : "range";
|
|
511
|
+
}
|
|
512
|
+
const on = r.enum(["url", "magnet", "upload"]), _r = r.enum([
|
|
513
|
+
"pending",
|
|
514
|
+
"approved",
|
|
515
|
+
"fetching",
|
|
516
|
+
"ingesting",
|
|
517
|
+
"ready",
|
|
518
|
+
"rejected",
|
|
519
|
+
"failed"
|
|
520
|
+
]), vt = {
|
|
521
|
+
pending: ["approved", "rejected"],
|
|
522
|
+
approved: ["fetching", "rejected", "failed"],
|
|
523
|
+
fetching: ["ingesting", "failed"],
|
|
524
|
+
ingesting: ["ready", "failed"],
|
|
525
|
+
ready: [],
|
|
526
|
+
rejected: [],
|
|
527
|
+
failed: ["approved"]
|
|
528
|
+
};
|
|
529
|
+
Object.keys(vt).filter((e) => vt[e].length === 0);
|
|
530
|
+
const xr = r.object({
|
|
531
|
+
id: r.string().min(1),
|
|
532
|
+
/** Stable userId from whoami. Never the raw `X-User-Key`. */
|
|
533
|
+
ownerUserId: r.string().min(1),
|
|
534
|
+
kind: on,
|
|
535
|
+
/** The magnet URI, the https URL, or the filetransfer binding id. */
|
|
536
|
+
source: r.string().min(1),
|
|
537
|
+
title: r.string().optional(),
|
|
538
|
+
/**
|
|
539
|
+
* The anime series folder (PascalCase, e.g. `SparksOfTomorrow`) a `magnet`
|
|
540
|
+
* submission belongs to — wave 4 (2026-10-01: "magnets are in scope, and
|
|
541
|
+
* user content is NOT restricted to the playlist tree"). `undefined` for
|
|
542
|
+
* `url`/`upload`, which always land in the playlist tree regardless of
|
|
543
|
+
* title. The scraper derives its own destination from this same string, so
|
|
544
|
+
* it is stored verbatim rather than normalized — a normalization that
|
|
545
|
+
* disagreed with the scraper's own folder-name assumption would silently
|
|
546
|
+
* misroute the copy.
|
|
547
|
+
*/
|
|
548
|
+
series: r.string().optional(),
|
|
549
|
+
state: _r,
|
|
550
|
+
createdAt: r.number().int().nonnegative(),
|
|
551
|
+
updatedAt: r.number().int().nonnegative(),
|
|
552
|
+
/** Why it failed, or why an operator rejected it. */
|
|
553
|
+
error: r.string().optional(),
|
|
554
|
+
/** Size once known. 0 means "known to be empty"; absent means "not yet known" —
|
|
555
|
+
* the same distinction `chatImages` draws for image dimensions. */
|
|
556
|
+
bytes: r.number().int().nonnegative().optional()
|
|
557
|
+
}), Cr = 4096, an = 300, kr = 100;
|
|
558
|
+
r.object({
|
|
559
|
+
kind: on,
|
|
560
|
+
source: r.string().min(1).max(Cr),
|
|
561
|
+
title: r.string().min(1).max(an).optional(),
|
|
562
|
+
/** Required for `kind: 'magnet'` by `checkSource`; ignored for `url`/`upload`. */
|
|
563
|
+
series: r.string().min(1).max(kr).optional()
|
|
564
|
+
});
|
|
565
|
+
r.object({
|
|
566
|
+
reason: r.string().min(1).max(an).optional()
|
|
567
|
+
});
|
|
568
|
+
r.object({
|
|
569
|
+
submissions: r.array(xr)
|
|
570
|
+
});
|
|
571
|
+
r.object({
|
|
572
|
+
error: r.literal("submissions/quota_exceeded"),
|
|
573
|
+
/** The caller's measured bytes in non-terminal submissions, right now. */
|
|
574
|
+
pendingBytes: r.number().int().nonnegative(),
|
|
575
|
+
/** The cap that was applied, from the server's config. */
|
|
576
|
+
capBytes: r.number().int().nonnegative()
|
|
577
|
+
});
|
|
578
|
+
const Ir = /^[a-z0-9][a-z0-9-]{0,31}$/, wt = "https://game-catalog.invalid";
|
|
579
|
+
function Tr(e) {
|
|
580
|
+
if (!e.startsWith("/") || e.startsWith("//") || /[\\\s]/.test(e) || [...e].some((t) => t.charCodeAt(0) < 32 || t.charCodeAt(0) === 127))
|
|
581
|
+
return !1;
|
|
582
|
+
try {
|
|
583
|
+
return new URL(e, wt).origin === wt;
|
|
584
|
+
} catch {
|
|
585
|
+
return !1;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
const sn = r.string().min(2).max(512).refine(Tr, {
|
|
589
|
+
message: "must be a root-relative path on the page origin (e.g. /cardtable/embed/x.js)"
|
|
590
|
+
}), St = {
|
|
591
|
+
id: r.string().regex(Ir),
|
|
592
|
+
name: r.string().min(1).max(64),
|
|
593
|
+
cover: sn.optional()
|
|
594
|
+
}, Er = r.discriminatedUnion("kind", [
|
|
595
|
+
r.object({ ...St, kind: r.literal("iframe") }).strict(),
|
|
596
|
+
r.object({ ...St, kind: r.literal("module"), url: sn }).strict()
|
|
597
|
+
]);
|
|
598
|
+
r.array(Er).max(32).refine((e) => new Set(e.map((t) => t.id)).size === e.length, { message: "game ids must be unique" });
|
|
599
|
+
const ot = r.enum(["anilist", "tmdb"]), Ar = r.object({
|
|
600
|
+
source: ot,
|
|
601
|
+
/** The provider's own id, as a string (AniList and TMDB both use integers). */
|
|
602
|
+
id: r.string(),
|
|
603
|
+
title: r.string(),
|
|
604
|
+
year: r.number().int().nullable(),
|
|
605
|
+
/** AniList `format` (TV, ONA, MOVIE…) or `TV` for TMDB. */
|
|
606
|
+
format: r.string().nullable(),
|
|
607
|
+
episodes: r.number().int().nullable(),
|
|
608
|
+
/** Same-origin proxied poster (`/api/search/thumb?u=…`), or null. */
|
|
609
|
+
poster: r.string().nullable(),
|
|
610
|
+
/** The folder this show would land in — `SousouNoFrieren`. */
|
|
611
|
+
series: r.string(),
|
|
612
|
+
/** On the scraper's watch list already (by series). */
|
|
613
|
+
onWatchlist: r.boolean(),
|
|
614
|
+
/**
|
|
615
|
+
* Not addable: a movie, or a title with no usable Latin-script name. The
|
|
616
|
+
* scraper matches releases by `SxxExx`, so a film can never arrive through it.
|
|
617
|
+
*/
|
|
618
|
+
addable: r.boolean()
|
|
619
|
+
});
|
|
620
|
+
r.object({
|
|
621
|
+
results: r.array(Ar),
|
|
622
|
+
/** Providers that answered. TMDB is absent when no token is configured. */
|
|
623
|
+
sources: r.array(ot)
|
|
624
|
+
});
|
|
625
|
+
const Nr = r.object({
|
|
626
|
+
id: r.string(),
|
|
627
|
+
url: r.string(),
|
|
628
|
+
title: r.string(),
|
|
629
|
+
channel: r.string().nullable(),
|
|
630
|
+
durationS: r.number().nullable(),
|
|
631
|
+
thumb: r.string().nullable()
|
|
632
|
+
});
|
|
633
|
+
r.object({ results: r.array(Nr) });
|
|
634
|
+
r.object({
|
|
635
|
+
source: ot,
|
|
636
|
+
id: r.string().regex(/^\d{1,12}$/)
|
|
637
|
+
});
|
|
638
|
+
r.object({ series: r.string(), title: r.string() });
|
|
639
|
+
let ve = null, ln = qt;
|
|
640
|
+
function Pr(e) {
|
|
641
|
+
e.cdnBase && (ln = e.cdnBase);
|
|
642
|
+
}
|
|
643
|
+
function cn() {
|
|
644
|
+
return ln.replace(/\/+$/, "");
|
|
645
|
+
}
|
|
646
|
+
function je() {
|
|
647
|
+
const e = cn();
|
|
648
|
+
return (!ve || ve.base !== e) && (ve = { base: e, client: jn({ cdnBase: e }) }), ve.client;
|
|
649
|
+
}
|
|
650
|
+
function Pe(e) {
|
|
651
|
+
return !et(e) || !cn() ? null : je().urlFor(e);
|
|
652
|
+
}
|
|
653
|
+
function Mr(e) {
|
|
654
|
+
return e.kind === "file";
|
|
655
|
+
}
|
|
656
|
+
class dn extends Error {
|
|
657
|
+
constructor(t) {
|
|
658
|
+
super(t), this.name = "ChatImageUploadError";
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function ke(e) {
|
|
662
|
+
switch (e) {
|
|
663
|
+
case "unauthenticated":
|
|
664
|
+
return "Sign in to paste images";
|
|
665
|
+
case "forbidden":
|
|
666
|
+
return "Your account can't upload images";
|
|
667
|
+
case "too-large":
|
|
668
|
+
return "Image too large (max 10 MB)";
|
|
669
|
+
case "unsupported-type":
|
|
670
|
+
return "That image type isn't supported";
|
|
671
|
+
case "invalid":
|
|
672
|
+
return "That image couldn't be read";
|
|
673
|
+
case "network":
|
|
674
|
+
return "Check your connection and try again";
|
|
675
|
+
case "unavailable":
|
|
676
|
+
return "Image upload is having trouble — try again";
|
|
677
|
+
default:
|
|
678
|
+
return "Image upload failed";
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function Or(e) {
|
|
682
|
+
return e instanceof ze ? ke(e.reason) : e instanceof dn ? e.message : "Image upload failed";
|
|
683
|
+
}
|
|
684
|
+
function Rr(e) {
|
|
685
|
+
const t = e.type.toLowerCase().split(";")[0].trim();
|
|
686
|
+
return t && Un(t) !== "image" ? ke("unsupported-type") : e.size > Fn.image ? ke("too-large") : e.size === 0 ? ke("invalid") : null;
|
|
687
|
+
}
|
|
688
|
+
function Dr(e) {
|
|
689
|
+
return $n(e);
|
|
690
|
+
}
|
|
691
|
+
function Lr(e) {
|
|
692
|
+
return Bn(e);
|
|
693
|
+
}
|
|
694
|
+
async function jr(e) {
|
|
695
|
+
const t = await Hn(e);
|
|
696
|
+
return { w: t?.width ?? 0, h: t?.height ?? 0 };
|
|
697
|
+
}
|
|
698
|
+
async function Ur(e, t = {}) {
|
|
699
|
+
const n = await je().upload(e, { signal: t.signal });
|
|
700
|
+
if (!et(n.key))
|
|
701
|
+
throw new dn("Image upload returned an unusable key");
|
|
702
|
+
return { key: n.key, deduplicated: n.deduplicated === !0 };
|
|
703
|
+
}
|
|
704
|
+
async function Fr(e, t = {}) {
|
|
705
|
+
const n = [];
|
|
706
|
+
for (const o of e) {
|
|
707
|
+
if (o.kind === "remote") {
|
|
708
|
+
n.push({ key: o.key, w: o.w, h: o.h, ...o.title ? { title: o.title } : {} });
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
const { key: i } = await Ur(o.file, t);
|
|
712
|
+
n.push({ key: i, w: o.w, h: o.h });
|
|
713
|
+
}
|
|
714
|
+
return n;
|
|
715
|
+
}
|
|
716
|
+
function Hr(e) {
|
|
717
|
+
return {
|
|
718
|
+
error: e instanceof Error ? e.message : String(e),
|
|
719
|
+
name: e instanceof Error ? e.name : typeof e,
|
|
720
|
+
reason: e instanceof ze ? e.reason : void 0,
|
|
721
|
+
status: e instanceof ze ? e.status : void 0
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
const Ye = 240, Z = 8, $r = 28, un = 240;
|
|
725
|
+
function Br(e, t, n) {
|
|
726
|
+
let o = t.left - Ye - Z;
|
|
727
|
+
o < Z && (o = t.right + Z), o = Math.min(o, n.width - Ye - Z), o = Math.max(Z, o);
|
|
728
|
+
const i = un + $r;
|
|
729
|
+
let s = e.top + e.height / 2 - i / 2;
|
|
730
|
+
return s = Math.min(s, n.height - i - Z), s = Math.max(Z, s), { left: o, top: s };
|
|
731
|
+
}
|
|
732
|
+
const mn = "/dataplatform/api/memes", Gr = 120;
|
|
733
|
+
function Wr({ onClose: e, onPick: t, onUnavailable: n }) {
|
|
734
|
+
const [o, i] = P(""), s = J(null), a = J(null), c = je(), { items: f, loading: g, error: p, hasMore: D, loadMore: M } = Xn(
|
|
735
|
+
c,
|
|
736
|
+
mn,
|
|
737
|
+
o.trim()
|
|
738
|
+
), T = p?.reason ?? null, C = Q(() => {
|
|
739
|
+
const w = /* @__PURE__ */ new Set();
|
|
740
|
+
return f.filter((R) => w.has(R.key) ? !1 : (w.add(R.key), !0));
|
|
741
|
+
}, [f]), [h, _] = P(null), S = J(null), k = N(() => {
|
|
742
|
+
S.current !== null && (window.clearTimeout(S.current), S.current = null);
|
|
743
|
+
}, []), u = N(() => {
|
|
744
|
+
k(), _(null);
|
|
745
|
+
}, [k]), v = typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(hover: hover)").matches, E = N(
|
|
746
|
+
(w, R, L = !1) => {
|
|
747
|
+
const F = s.current;
|
|
748
|
+
if (!F) return;
|
|
749
|
+
const W = () => _({
|
|
750
|
+
item: w,
|
|
751
|
+
...Br(R.getBoundingClientRect(), F.getBoundingClientRect(), {
|
|
752
|
+
width: window.innerWidth,
|
|
753
|
+
height: window.innerHeight
|
|
754
|
+
})
|
|
755
|
+
});
|
|
756
|
+
k(), L ? W() : S.current = window.setTimeout(W, Gr);
|
|
757
|
+
},
|
|
758
|
+
[k]
|
|
759
|
+
);
|
|
760
|
+
O(() => () => k(), [k]), O(() => {
|
|
761
|
+
T === "unavailable" && n?.();
|
|
762
|
+
}, [T, n]), O(() => {
|
|
763
|
+
a.current?.focus();
|
|
764
|
+
}, []), O(() => {
|
|
765
|
+
const w = (L) => {
|
|
766
|
+
L.key === "Escape" && (L.stopPropagation(), e());
|
|
767
|
+
}, R = (L) => {
|
|
768
|
+
s.current && !s.current.contains(L.target) && e();
|
|
769
|
+
};
|
|
770
|
+
return document.addEventListener("keydown", w), document.addEventListener("mousedown", R), () => {
|
|
771
|
+
document.removeEventListener("keydown", w), document.removeEventListener("mousedown", R);
|
|
772
|
+
};
|
|
773
|
+
}, [e]);
|
|
774
|
+
const U = N((w) => {
|
|
775
|
+
t(w), e();
|
|
776
|
+
}, [t, e]), H = !g && !p && C.length === 0;
|
|
777
|
+
return /* @__PURE__ */ b(
|
|
778
|
+
"div",
|
|
779
|
+
{
|
|
780
|
+
ref: s,
|
|
781
|
+
role: "dialog",
|
|
782
|
+
"aria-label": "Meme library",
|
|
783
|
+
"data-testid": "meme-picker",
|
|
784
|
+
className: "absolute bottom-full left-0 right-0 mb-2 z-30 flex max-h-80 flex-col rounded border border-border bg-bg-card shadow-lg",
|
|
785
|
+
children: [
|
|
786
|
+
/* @__PURE__ */ l("div", { className: "border-b border-border-light p-2", children: /* @__PURE__ */ l(
|
|
787
|
+
"input",
|
|
788
|
+
{
|
|
789
|
+
ref: a,
|
|
790
|
+
type: "text",
|
|
791
|
+
value: o,
|
|
792
|
+
onChange: (w) => i(w.target.value),
|
|
793
|
+
placeholder: "Search memes...",
|
|
794
|
+
"aria-label": "Search memes",
|
|
795
|
+
"data-testid": "meme-search",
|
|
796
|
+
className: "w-full rounded border border-border-light bg-bg-alt px-2 py-1 text-sm text-text placeholder:text-text-secondary focus:outline-none focus:border-primary"
|
|
797
|
+
}
|
|
798
|
+
) }),
|
|
799
|
+
/* @__PURE__ */ b(
|
|
800
|
+
"div",
|
|
801
|
+
{
|
|
802
|
+
className: "flex-1 overflow-y-auto p-2",
|
|
803
|
+
onScroll: u,
|
|
804
|
+
onMouseLeave: u,
|
|
805
|
+
children: [
|
|
806
|
+
p && /* @__PURE__ */ l(
|
|
807
|
+
"p",
|
|
808
|
+
{
|
|
809
|
+
className: "m-2 p-2 text-center text-sm bg-danger-bg text-on-danger-bg rounded",
|
|
810
|
+
role: "alert",
|
|
811
|
+
"data-reason": T,
|
|
812
|
+
children: T === "unauthenticated" ? "Sign in to browse memes" : T === "forbidden" ? "Your account can't browse the meme library" : "Meme library is unavailable"
|
|
813
|
+
}
|
|
814
|
+
),
|
|
815
|
+
H && /* @__PURE__ */ l("p", { className: "p-4 text-center text-sm text-text-secondary", children: o.trim() ? `No memes match "${o.trim()}"` : "The meme library is empty" }),
|
|
816
|
+
C.length > 0 && /* @__PURE__ */ l("div", { className: "grid grid-cols-3 gap-1.5 sm:grid-cols-4", children: C.map((w) => {
|
|
817
|
+
const R = Pe(w.key);
|
|
818
|
+
return R ? /* @__PURE__ */ l(
|
|
819
|
+
"button",
|
|
820
|
+
{
|
|
821
|
+
type: "button",
|
|
822
|
+
onClick: () => U(w),
|
|
823
|
+
title: w.title,
|
|
824
|
+
"data-testid": "meme-result",
|
|
825
|
+
onMouseEnter: (L) => {
|
|
826
|
+
v && E(w, L.currentTarget);
|
|
827
|
+
},
|
|
828
|
+
onMouseLeave: u,
|
|
829
|
+
onFocus: (L) => E(w, L.currentTarget, !0),
|
|
830
|
+
onBlur: u,
|
|
831
|
+
className: "group relative aspect-square overflow-hidden rounded border border-border-light bg-bg-alt focus:outline-none focus:border-primary hover:border-primary",
|
|
832
|
+
children: /* @__PURE__ */ l(
|
|
833
|
+
"img",
|
|
834
|
+
{
|
|
835
|
+
src: R,
|
|
836
|
+
alt: w.title || "Meme",
|
|
837
|
+
loading: "lazy",
|
|
838
|
+
decoding: "async",
|
|
839
|
+
className: "h-full w-full object-cover"
|
|
840
|
+
}
|
|
841
|
+
)
|
|
842
|
+
},
|
|
843
|
+
w.key
|
|
844
|
+
) : null;
|
|
845
|
+
}) }),
|
|
846
|
+
g && /* @__PURE__ */ l("p", { className: "p-2 text-center text-xs text-text-secondary", children: "Loading…" }),
|
|
847
|
+
D && !g && /* @__PURE__ */ l(
|
|
848
|
+
"button",
|
|
849
|
+
{
|
|
850
|
+
type: "button",
|
|
851
|
+
onClick: M,
|
|
852
|
+
"data-testid": "meme-load-more",
|
|
853
|
+
className: "mt-2 w-full rounded border border-border-light py-1 text-xs text-text-secondary hover:text-text hover:border-primary",
|
|
854
|
+
children: "Load more"
|
|
855
|
+
}
|
|
856
|
+
)
|
|
857
|
+
]
|
|
858
|
+
}
|
|
859
|
+
),
|
|
860
|
+
h && /* @__PURE__ */ b(
|
|
861
|
+
"div",
|
|
862
|
+
{
|
|
863
|
+
"data-testid": "meme-preview",
|
|
864
|
+
className: "fixed z-50 flex flex-col gap-1 rounded border border-border-light bg-bg-card p-1.5 shadow-2xl",
|
|
865
|
+
style: {
|
|
866
|
+
left: h.left,
|
|
867
|
+
top: h.top,
|
|
868
|
+
width: Ye,
|
|
869
|
+
/* The placement maths reserves exactly PREVIEW_PX of width.
|
|
870
|
+
Without border-box the padding and border sit OUTSIDE that
|
|
871
|
+
number and the box laps over the panel it is meant to sit
|
|
872
|
+
beside. */
|
|
873
|
+
boxSizing: "border-box",
|
|
874
|
+
/* Never eats the click it is describing. */
|
|
875
|
+
pointerEvents: "none"
|
|
876
|
+
},
|
|
877
|
+
"aria-hidden": "true",
|
|
878
|
+
children: [
|
|
879
|
+
/* @__PURE__ */ l(
|
|
880
|
+
"img",
|
|
881
|
+
{
|
|
882
|
+
src: Pe(h.item.key) ?? void 0,
|
|
883
|
+
alt: "",
|
|
884
|
+
className: "block w-full rounded bg-bg object-contain",
|
|
885
|
+
style: { height: "auto", maxHeight: un }
|
|
886
|
+
}
|
|
887
|
+
),
|
|
888
|
+
h.item.title && /* One line. A long title must not change the box height, because
|
|
889
|
+
the box height is what the placement maths clamped against. */
|
|
890
|
+
/* @__PURE__ */ l("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap text-center text-[10px] text-text-secondary", children: h.item.title })
|
|
891
|
+
]
|
|
892
|
+
}
|
|
893
|
+
)
|
|
894
|
+
]
|
|
895
|
+
}
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
function Kr({ open: e, ...t }) {
|
|
899
|
+
return e ? /* @__PURE__ */ l(Wr, { ...t }) : null;
|
|
900
|
+
}
|
|
901
|
+
const it = {
|
|
902
|
+
serverOrigin: `http://localhost:${tt}`,
|
|
903
|
+
defaultRoomKey: "dev-room",
|
|
904
|
+
cdnBase: qt
|
|
905
|
+
};
|
|
906
|
+
let Ie = { ...it };
|
|
907
|
+
function qr(e) {
|
|
908
|
+
const t = Object.fromEntries(
|
|
909
|
+
Object.entries(e).filter(([n, o]) => o !== void 0)
|
|
910
|
+
);
|
|
911
|
+
Ie = { ...Ie, ...t }, Pr({ cdnBase: Ie.cdnBase });
|
|
912
|
+
}
|
|
913
|
+
function he() {
|
|
914
|
+
return Ie;
|
|
915
|
+
}
|
|
916
|
+
const pn = Gt(it);
|
|
917
|
+
function Vr() {
|
|
918
|
+
return Wt(pn);
|
|
919
|
+
}
|
|
920
|
+
function fn(e) {
|
|
921
|
+
return e.serverOrigin?.replace(/\/$/, "") || "";
|
|
922
|
+
}
|
|
923
|
+
function hn() {
|
|
924
|
+
return fn(he());
|
|
925
|
+
}
|
|
926
|
+
const gn = Gt(null);
|
|
927
|
+
function zr() {
|
|
928
|
+
return Wt(gn);
|
|
929
|
+
}
|
|
930
|
+
const oe = {
|
|
931
|
+
ANON_KEY: "watchparty_preferences",
|
|
932
|
+
DEBUG_FLAG: "wp:debug",
|
|
933
|
+
REPORT_LOGS_FLAG: "wp:reportLogs",
|
|
934
|
+
voteKey: (e, t, n) => `watchparty_vote:${e}:${t}:${n}`
|
|
935
|
+
};
|
|
936
|
+
function Ue() {
|
|
937
|
+
try {
|
|
938
|
+
return globalThis.localStorage ?? null;
|
|
939
|
+
} catch {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function G(e) {
|
|
944
|
+
try {
|
|
945
|
+
return Ue()?.getItem(e) ?? null;
|
|
946
|
+
} catch {
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function at(e, t) {
|
|
951
|
+
try {
|
|
952
|
+
const n = Ue();
|
|
953
|
+
return n ? (n.setItem(e, t), !0) : !1;
|
|
954
|
+
} catch {
|
|
955
|
+
return !1;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function Yr() {
|
|
959
|
+
try {
|
|
960
|
+
const e = Ue();
|
|
961
|
+
if (!e) return [];
|
|
962
|
+
const t = [];
|
|
963
|
+
for (let n = 0; n < e.length; n++) {
|
|
964
|
+
const o = e.key(n);
|
|
965
|
+
o !== null && t.push(o);
|
|
966
|
+
}
|
|
967
|
+
return t;
|
|
968
|
+
} catch {
|
|
969
|
+
return [];
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function Me(e) {
|
|
973
|
+
try {
|
|
974
|
+
Ue()?.removeItem(e);
|
|
975
|
+
} catch {
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
function Xr(e) {
|
|
979
|
+
const t = G(e);
|
|
980
|
+
return t === null ? null : t === "true" ? !0 : t === "false" ? !1 : null;
|
|
981
|
+
}
|
|
982
|
+
const bn = /* @__PURE__ */ new Map();
|
|
983
|
+
let yn = !1;
|
|
984
|
+
function Fe(e, t) {
|
|
985
|
+
bn.set(e, t), yn && vn(e, t);
|
|
986
|
+
}
|
|
987
|
+
function Jr() {
|
|
988
|
+
yn = !0;
|
|
989
|
+
for (const [e, t] of bn) vn(e, t);
|
|
990
|
+
}
|
|
991
|
+
function vn(e, t) {
|
|
992
|
+
typeof window > "u" || (window[e] = t);
|
|
993
|
+
}
|
|
994
|
+
const de = [], Zr = 500;
|
|
995
|
+
let Te = [], Xe = null;
|
|
996
|
+
const Qr = 1e3, eo = 200;
|
|
997
|
+
let Je = null;
|
|
998
|
+
function wn(e) {
|
|
999
|
+
Je = e;
|
|
1000
|
+
}
|
|
1001
|
+
function Sn() {
|
|
1002
|
+
return G(oe.REPORT_LOGS_FLAG) === "true";
|
|
1003
|
+
}
|
|
1004
|
+
function to() {
|
|
1005
|
+
if (typeof window > "u") return !1;
|
|
1006
|
+
if (window.__WP_DEBUG__ || new URLSearchParams(window.location.search).get("debug") === "true") return !0;
|
|
1007
|
+
const t = G(oe.DEBUG_FLAG);
|
|
1008
|
+
return t !== null && t !== "false";
|
|
1009
|
+
}
|
|
1010
|
+
function no() {
|
|
1011
|
+
const e = G(oe.DEBUG_FLAG);
|
|
1012
|
+
if (!e || e === "true") return null;
|
|
1013
|
+
const t = e.split(",").map((n) => n.trim().toLowerCase()).filter(Boolean);
|
|
1014
|
+
return t.length > 0 ? new Set(t) : null;
|
|
1015
|
+
}
|
|
1016
|
+
function ro() {
|
|
1017
|
+
return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
1018
|
+
hour12: !1,
|
|
1019
|
+
hour: "2-digit",
|
|
1020
|
+
minute: "2-digit",
|
|
1021
|
+
second: "2-digit",
|
|
1022
|
+
fractionalSecondDigits: 3
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
function oo(e) {
|
|
1026
|
+
de.push(e), de.length > Zr && de.shift();
|
|
1027
|
+
}
|
|
1028
|
+
const $e = {
|
|
1029
|
+
debug: "color: #64748b; font-weight: normal;",
|
|
1030
|
+
warn: "color: #f59e0b; font-weight: bold;",
|
|
1031
|
+
error: "color: #ef4444; font-weight: bold;",
|
|
1032
|
+
category: "color: #3b82f6; font-weight: bold;",
|
|
1033
|
+
time: "color: #6b7280; font-weight: normal;"
|
|
1034
|
+
};
|
|
1035
|
+
function io(e) {
|
|
1036
|
+
try {
|
|
1037
|
+
return JSON.stringify(e);
|
|
1038
|
+
} catch {
|
|
1039
|
+
return "[unserializable]";
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function st(e, t, n, o, i, s, a) {
|
|
1043
|
+
const c = {
|
|
1044
|
+
level: e,
|
|
1045
|
+
category: i,
|
|
1046
|
+
message: s,
|
|
1047
|
+
data: a,
|
|
1048
|
+
timestamp: Date.now()
|
|
1049
|
+
};
|
|
1050
|
+
if (oo(c), (n || Sn()) && _t(c), !o) {
|
|
1051
|
+
if (!to()) return;
|
|
1052
|
+
const p = no();
|
|
1053
|
+
if (p && !p.has(i.toLowerCase())) return;
|
|
1054
|
+
}
|
|
1055
|
+
const f = ro(), g = a !== void 0 ? " " + io(a) : "";
|
|
1056
|
+
t(
|
|
1057
|
+
`%c[${f}]%c [${i}]%c ${s}${g}`,
|
|
1058
|
+
$e.time,
|
|
1059
|
+
$e.category,
|
|
1060
|
+
$e[e]
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
function d(e, t, n) {
|
|
1064
|
+
st("debug", console.log, !1, !1, e, t, n);
|
|
1065
|
+
}
|
|
1066
|
+
function A(e, t, n) {
|
|
1067
|
+
st("warn", console.warn, !0, !1, e, t, n);
|
|
1068
|
+
}
|
|
1069
|
+
function ue(e, t, n) {
|
|
1070
|
+
st("error", console.error, !0, !0, e, t, n);
|
|
1071
|
+
}
|
|
1072
|
+
function ao() {
|
|
1073
|
+
return [...de];
|
|
1074
|
+
}
|
|
1075
|
+
function so() {
|
|
1076
|
+
de.length = 0;
|
|
1077
|
+
}
|
|
1078
|
+
function lo(e) {
|
|
1079
|
+
const t = e && e.length > 0 ? e.join(",") : "true";
|
|
1080
|
+
at(oe.DEBUG_FLAG, t), console.log("[wp] Debug mode enabled");
|
|
1081
|
+
}
|
|
1082
|
+
function co() {
|
|
1083
|
+
Me(oe.DEBUG_FLAG), console.log("[wp] Debug mode disabled");
|
|
1084
|
+
}
|
|
1085
|
+
const uo = 1024, mo = 5e4;
|
|
1086
|
+
function po(e) {
|
|
1087
|
+
if (e == null) return e;
|
|
1088
|
+
try {
|
|
1089
|
+
const t = JSON.stringify(e);
|
|
1090
|
+
if (t.length <= uo) return e;
|
|
1091
|
+
if (typeof e == "object" && !Array.isArray(e)) {
|
|
1092
|
+
const n = {};
|
|
1093
|
+
for (const [o, i] of Object.entries(e)) {
|
|
1094
|
+
const s = JSON.stringify(i);
|
|
1095
|
+
n[o] = s && s.length > 200 ? `[truncated ${s.length} chars]` : i;
|
|
1096
|
+
}
|
|
1097
|
+
return n;
|
|
1098
|
+
}
|
|
1099
|
+
return `[truncated ${t.length} chars]`;
|
|
1100
|
+
} catch {
|
|
1101
|
+
return "[unserializable]";
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
async function fo() {
|
|
1105
|
+
if (Te.length === 0) return;
|
|
1106
|
+
const e = Te;
|
|
1107
|
+
Te = [], Xe = null;
|
|
1108
|
+
try {
|
|
1109
|
+
let n = he().serverOrigin || "";
|
|
1110
|
+
if ((n === "/" || !n) && typeof window < "u") {
|
|
1111
|
+
const c = window.location;
|
|
1112
|
+
(c.hostname === "localhost" || c.hostname === "127.0.0.1") && c.port === String(zt) ? n = `${c.protocol}//${c.hostname}:${tt}` : n = c.origin;
|
|
1113
|
+
}
|
|
1114
|
+
const o = `${n.replace(/\/$/, "")}/api/client-log`, i = e.map((c) => ({
|
|
1115
|
+
level: c.level,
|
|
1116
|
+
category: c.category,
|
|
1117
|
+
message: c.message,
|
|
1118
|
+
data: po(c.data),
|
|
1119
|
+
timestamp: c.timestamp,
|
|
1120
|
+
url: typeof window < "u" ? window.location.href : void 0,
|
|
1121
|
+
userAgent: typeof navigator < "u" ? navigator.userAgent : void 0,
|
|
1122
|
+
room_key: Je?.room_key,
|
|
1123
|
+
client_id: Je?.client_id
|
|
1124
|
+
}));
|
|
1125
|
+
let s = [], a = 0;
|
|
1126
|
+
for (const c of i) {
|
|
1127
|
+
const f = JSON.stringify(c).length + 1;
|
|
1128
|
+
a + f > mo && s.length > 0 && (await fetch(o, {
|
|
1129
|
+
method: "POST",
|
|
1130
|
+
headers: { "Content-Type": "application/json" },
|
|
1131
|
+
body: JSON.stringify({ logs: s })
|
|
1132
|
+
}), s = [], a = 0), s.push(c), a += f;
|
|
1133
|
+
}
|
|
1134
|
+
s.length > 0 && await fetch(o, {
|
|
1135
|
+
method: "POST",
|
|
1136
|
+
headers: { "Content-Type": "application/json" },
|
|
1137
|
+
body: JSON.stringify({ logs: s })
|
|
1138
|
+
});
|
|
1139
|
+
} catch (t) {
|
|
1140
|
+
console.warn("[wp] log flush failed (client logs may be lost):", ge(t).error);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function _t(e) {
|
|
1144
|
+
if (Te.push(e), !Xe) {
|
|
1145
|
+
const t = Sn() ? eo : Qr;
|
|
1146
|
+
Xe = setTimeout(fo, t);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
function ge(e) {
|
|
1150
|
+
return e instanceof Error ? { error: e.message, name: e.name } : { error: String(e), name: typeof e };
|
|
1151
|
+
}
|
|
1152
|
+
Fe("__wpDebug", {
|
|
1153
|
+
enable: lo,
|
|
1154
|
+
disable: co,
|
|
1155
|
+
history: ao,
|
|
1156
|
+
clear: so
|
|
1157
|
+
});
|
|
1158
|
+
const X = {
|
|
1159
|
+
resolved: !1,
|
|
1160
|
+
userType: "public",
|
|
1161
|
+
accountId: null
|
|
1162
|
+
};
|
|
1163
|
+
function lt() {
|
|
1164
|
+
return X.accountId ? X.accountId : X.resolved && X.userType === "public" ? "anon" : null;
|
|
1165
|
+
}
|
|
1166
|
+
function ho(e) {
|
|
1167
|
+
X.resolved = !0, e.userType && (X.userType = e.userType), e.userId !== void 0 && (X.accountId = e.userId && e.userId !== "public" ? e.userId : null);
|
|
1168
|
+
}
|
|
1169
|
+
function ct() {
|
|
1170
|
+
return X.accountId ?? "public";
|
|
1171
|
+
}
|
|
1172
|
+
function go() {
|
|
1173
|
+
return lt() ?? "unscoped";
|
|
1174
|
+
}
|
|
1175
|
+
function bo() {
|
|
1176
|
+
return nn.flatMap((e) => {
|
|
1177
|
+
const t = e.characters.map((o) => o.id), n = [];
|
|
1178
|
+
for (let o = 0; o < t.length; o += yt)
|
|
1179
|
+
n.push(t.slice(o, o + yt));
|
|
1180
|
+
return n;
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
function xt(e, t) {
|
|
1184
|
+
const n = e.findIndex((o) => o.some((i) => i === t));
|
|
1185
|
+
return n < 0 ? 0 : n;
|
|
1186
|
+
}
|
|
1187
|
+
function _n(e) {
|
|
1188
|
+
return fe(e) ? fr[e] : "var(--color-neutral-bg)";
|
|
1189
|
+
}
|
|
1190
|
+
function He(e) {
|
|
1191
|
+
if (!fe(e)) return;
|
|
1192
|
+
const t = he().serverOrigin.replace(/\/$/, ""), n = hr[e];
|
|
1193
|
+
return `${t}/media/sprites/square_${e}.png${n > 1 ? `?v=${n}` : ""}`;
|
|
1194
|
+
}
|
|
1195
|
+
let pe = null, we = null;
|
|
1196
|
+
function yo() {
|
|
1197
|
+
return pe ? Promise.resolve() : we || (we = (async () => {
|
|
1198
|
+
try {
|
|
1199
|
+
const e = he().serverOrigin.replace(/\/$/, ""), t = await fetch(`${e}/media/sprites/names.json`, { cache: "no-cache" });
|
|
1200
|
+
if (!t.ok) return;
|
|
1201
|
+
const n = await t.json();
|
|
1202
|
+
pe = n, Fe("__DISPLAY_NAMES__", n), d("characters", "Loaded display names", n);
|
|
1203
|
+
} catch (e) {
|
|
1204
|
+
d("characters", "display names fetch failed (degrading to sprite IDs)", ge(e));
|
|
1205
|
+
}
|
|
1206
|
+
})(), we);
|
|
1207
|
+
}
|
|
1208
|
+
function te(e) {
|
|
1209
|
+
return pe?.[e] || e.charAt(0).toUpperCase() + e.slice(1);
|
|
1210
|
+
}
|
|
1211
|
+
function ne(e) {
|
|
1212
|
+
const t = e.toLowerCase();
|
|
1213
|
+
return Le.some((n) => n === t) ? !0 : pe ? Object.values(pe).some((n) => n.toLowerCase() === t) : !1;
|
|
1214
|
+
}
|
|
1215
|
+
const vo = r.object({
|
|
1216
|
+
// Identity. There is deliberately NO `name`: a person's name is their
|
|
1217
|
+
// hadoku key-registry name, resolved by the server from whoami and renamed
|
|
1218
|
+
// through hadoku_site's POST /session/name (operator decision 2026-10-08).
|
|
1219
|
+
// A watchparty-only copy disagreed with cardtable's and is not read.
|
|
1220
|
+
sprite: r.string().optional(),
|
|
1221
|
+
// Chat settings
|
|
1222
|
+
chatCollapsed: r.boolean().optional(),
|
|
1223
|
+
floatingChatEnabled: r.boolean().optional(),
|
|
1224
|
+
// RoomChrome's chat column (roomChrome/chatLayout.ts) — separate from the
|
|
1225
|
+
// app's chatCollapsed on purpose.
|
|
1226
|
+
chromeChatCollapsed: r.boolean().optional(),
|
|
1227
|
+
chromeChatWidth: r.number().optional(),
|
|
1228
|
+
// Media settings
|
|
1229
|
+
volume: r.number().min(0).max(1).optional(),
|
|
1230
|
+
muted: r.boolean().optional(),
|
|
1231
|
+
preferredAudioLang: r.string().optional(),
|
|
1232
|
+
subtitlesEnabled: r.boolean().optional(),
|
|
1233
|
+
subtitleStyle: r.string().optional()
|
|
1234
|
+
}), me = Wn({
|
|
1235
|
+
appId: "watchparty",
|
|
1236
|
+
schema: vo
|
|
1237
|
+
}), wo = /* @__PURE__ */ new Set(["theme", "themeMode"]);
|
|
1238
|
+
function Oe(e) {
|
|
1239
|
+
const t = lt();
|
|
1240
|
+
return t ? `prefs-cache:${t}:${e}` : null;
|
|
1241
|
+
}
|
|
1242
|
+
function So() {
|
|
1243
|
+
return lt() === null;
|
|
1244
|
+
}
|
|
1245
|
+
function Ct(e) {
|
|
1246
|
+
const t = Oe(e);
|
|
1247
|
+
if (!t) return {};
|
|
1248
|
+
const n = G(t);
|
|
1249
|
+
if (!n) return {};
|
|
1250
|
+
try {
|
|
1251
|
+
return JSON.parse(n)?.blob ?? {};
|
|
1252
|
+
} catch {
|
|
1253
|
+
return {};
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
function _o() {
|
|
1257
|
+
let e = 0;
|
|
1258
|
+
for (const t of Yr()) {
|
|
1259
|
+
const n = t.startsWith("prefs-cache:") && t.endsWith(":watchparty"), o = t === Re || t.startsWith(`${Re}:`) && !t.endsWith(":_serverSynced_v1");
|
|
1260
|
+
if (!n && !o) continue;
|
|
1261
|
+
const i = G(t);
|
|
1262
|
+
if (!i) continue;
|
|
1263
|
+
let s;
|
|
1264
|
+
try {
|
|
1265
|
+
s = JSON.parse(i);
|
|
1266
|
+
} catch {
|
|
1267
|
+
continue;
|
|
1268
|
+
}
|
|
1269
|
+
const a = n ? s?.blob : s;
|
|
1270
|
+
if (!a || typeof a != "object" || !("name" in a)) continue;
|
|
1271
|
+
const { name: c, ...f } = a, g = n ? { ...s, blob: f } : f;
|
|
1272
|
+
at(t, JSON.stringify(g)) && e++;
|
|
1273
|
+
}
|
|
1274
|
+
return e > 0 && d("preferences", "Stripped retired name from cached prefs rows", { rewritten: e }), e;
|
|
1275
|
+
}
|
|
1276
|
+
let xn = null, Cn = null;
|
|
1277
|
+
const kt = /* @__PURE__ */ new Set();
|
|
1278
|
+
function dt() {
|
|
1279
|
+
if (So())
|
|
1280
|
+
return d("preferences", "Boot read deferred — session pending, identity unresolved"), {};
|
|
1281
|
+
const e = Ct("portfolio"), t = Ct("watchparty"), n = Object.keys(e).length > 0 ? e : xn ?? {}, o = Object.keys(t).length > 0 ? t : Cn ?? {}, i = ct() || "public";
|
|
1282
|
+
if (kt.has(i))
|
|
1283
|
+
return d("preferences", "Loaded (sync, SDK-only after first read)", {
|
|
1284
|
+
uid: i,
|
|
1285
|
+
sdkThemeKeys: Object.keys(n).length,
|
|
1286
|
+
sdkAppKeys: Object.keys(o).length,
|
|
1287
|
+
// 'mem' indicates in-memory backstop fired (cache was empty,
|
|
1288
|
+
// we used latestBlob instead).
|
|
1289
|
+
themeSource: Object.keys(e).length > 0 ? "cache" : "mem",
|
|
1290
|
+
appSource: Object.keys(t).length > 0 ? "cache" : "mem"
|
|
1291
|
+
}), { ...o, ...n };
|
|
1292
|
+
kt.add(i);
|
|
1293
|
+
const s = In() ?? {}, a = { ...s, ...o, ...n };
|
|
1294
|
+
return d("preferences", "Loaded (sync, first read — legacy + SDK)", {
|
|
1295
|
+
uid: i,
|
|
1296
|
+
sdkThemeKeys: Object.keys(n).length,
|
|
1297
|
+
sdkAppKeys: Object.keys(o).length,
|
|
1298
|
+
legacyKeys: Object.keys(s).length,
|
|
1299
|
+
themeSource: Object.keys(e).length > 0 ? "cache" : "mem",
|
|
1300
|
+
appSource: Object.keys(t).length > 0 ? "cache" : "mem"
|
|
1301
|
+
}), a;
|
|
1302
|
+
}
|
|
1303
|
+
let kn = !1;
|
|
1304
|
+
function xo() {
|
|
1305
|
+
const e = ct();
|
|
1306
|
+
return !e || e === "public";
|
|
1307
|
+
}
|
|
1308
|
+
function K(e, t) {
|
|
1309
|
+
xo() && (kn = !0), wo.has(e) ? ce.save({ [e]: t }, { scope: "device" }).catch((n) => A("preferences", "themePrefs.save failed", { key: e, err: n?.message })) : me.save({ [e]: t }).catch((n) => A("preferences", "watchpartyPrefs.save failed", { key: e, err: n?.message })), d("preferences", "Saved (via SDK)", { key: e, value: t });
|
|
1310
|
+
}
|
|
1311
|
+
let Se = null, It = !1;
|
|
1312
|
+
function Co() {
|
|
1313
|
+
return Se || (Se = (async () => {
|
|
1314
|
+
if (typeof window > "u") return !1;
|
|
1315
|
+
try {
|
|
1316
|
+
It || (It = !0, ce.subscribe((a) => {
|
|
1317
|
+
xn = a, At("portfolio", a), Nt("theme");
|
|
1318
|
+
}), me.subscribe((a) => {
|
|
1319
|
+
Cn = a, At("watchparty", a), Nt("watchparty");
|
|
1320
|
+
}));
|
|
1321
|
+
const [e, t] = await Promise.all([
|
|
1322
|
+
ce.read(),
|
|
1323
|
+
me.read()
|
|
1324
|
+
]);
|
|
1325
|
+
try {
|
|
1326
|
+
const { useAppStore: a } = await Promise.resolve().then(() => En);
|
|
1327
|
+
a.getState().rehydrateFromPrefs();
|
|
1328
|
+
} catch (a) {
|
|
1329
|
+
A("preferences", "inline rehydrate after SDK read failed", { err: a?.message });
|
|
1330
|
+
}
|
|
1331
|
+
const n = Oe("portfolio"), o = Oe("watchparty"), i = n ? G(n) : null, s = o ? G(o) : null;
|
|
1332
|
+
return d("preferences", "sdk.read", {
|
|
1333
|
+
themeKeys: Object.keys(e ?? {}),
|
|
1334
|
+
appKeys: Object.keys(t ?? {}),
|
|
1335
|
+
appName: t?.name,
|
|
1336
|
+
appSprite: t?.sprite,
|
|
1337
|
+
// Post-fetch cache state: should be non-zero if SDK wrote it.
|
|
1338
|
+
sdkThemeBytesPost: i?.length ?? 0,
|
|
1339
|
+
sdkAppBytesPost: s?.length ?? 0
|
|
1340
|
+
}), await ko(e, t), kn ? (d("preferences", "Promoting this load's pre-auth picks to the signed-in user"), await Promise.all([
|
|
1341
|
+
ce.promoteAnonPrefsToUser().catch(() => {
|
|
1342
|
+
}),
|
|
1343
|
+
me.promoteAnonPrefsToUser().catch(() => {
|
|
1344
|
+
})
|
|
1345
|
+
])) : d("preferences", "Skipping anon promotion — no pre-auth writes this load"), d("preferences", "First-load SDK sync complete"), !0;
|
|
1346
|
+
} catch (e) {
|
|
1347
|
+
return A("preferences", "First-load SDK sync failed (non-fatal)", { err: e?.message }), !1;
|
|
1348
|
+
}
|
|
1349
|
+
})(), Se);
|
|
1350
|
+
}
|
|
1351
|
+
const Re = "watchparty_preferences";
|
|
1352
|
+
_o();
|
|
1353
|
+
function Ze() {
|
|
1354
|
+
const e = ct();
|
|
1355
|
+
return !e || e === "public" ? Re : `${Re}:${e}`;
|
|
1356
|
+
}
|
|
1357
|
+
function In() {
|
|
1358
|
+
const e = G(Ze());
|
|
1359
|
+
if (!e) return null;
|
|
1360
|
+
try {
|
|
1361
|
+
const t = JSON.parse(e);
|
|
1362
|
+
return !t || typeof t != "object" || Array.isArray(t) ? null : t;
|
|
1363
|
+
} catch {
|
|
1364
|
+
return null;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
function Tt() {
|
|
1368
|
+
Me(Ze()), Me(`${Ze()}:_serverSynced_v1`);
|
|
1369
|
+
}
|
|
1370
|
+
async function ko(e, t) {
|
|
1371
|
+
const n = In();
|
|
1372
|
+
if (!n || Object.keys(n).length === 0) return;
|
|
1373
|
+
const o = Object.keys(e ?? {}).length > 0, i = Object.keys(t ?? {}).length > 0, s = {}, a = {};
|
|
1374
|
+
for (const [g, p] of Object.entries(n))
|
|
1375
|
+
o || (g === "theme" && typeof p == "string" ? s.theme = p : g === "themeMode" && (p === "simple" || p === "advanced") && (s.themeMode = p)), i || (g === "sprite" && typeof p == "string" ? a.sprite = p : g === "chatCollapsed" && typeof p == "boolean" ? a.chatCollapsed = p : g === "floatingChatEnabled" && typeof p == "boolean" ? a.floatingChatEnabled = p : g === "volume" && typeof p == "number" && p >= 0 && p <= 1 ? a.volume = p : g === "muted" && typeof p == "boolean" ? a.muted = p : g === "preferredAudioLang" && typeof p == "string" ? a.preferredAudioLang = p : g === "subtitlesEnabled" && typeof p == "boolean" ? a.subtitlesEnabled = p : g === "subtitleStyle" && typeof p == "string" && (a.subtitleStyle = p));
|
|
1376
|
+
const c = Object.keys(s), f = Object.keys(a);
|
|
1377
|
+
if (c.length === 0 && f.length === 0) {
|
|
1378
|
+
Tt();
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
d("preferences", "Migrating legacy localStorage prefs to SDK", {
|
|
1382
|
+
themeKeys: c,
|
|
1383
|
+
appKeys: f,
|
|
1384
|
+
sdkHasTheme: o,
|
|
1385
|
+
sdkHasApp: i
|
|
1386
|
+
});
|
|
1387
|
+
try {
|
|
1388
|
+
await Promise.all([
|
|
1389
|
+
c.length > 0 ? ce.save(s, { scope: "device" }) : Promise.resolve(),
|
|
1390
|
+
f.length > 0 ? me.save(a) : Promise.resolve()
|
|
1391
|
+
]), Tt(), d("preferences", "Legacy migration complete");
|
|
1392
|
+
} catch (g) {
|
|
1393
|
+
A("preferences", "Legacy migration save failed — will retry next load", {
|
|
1394
|
+
err: g?.message
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
let Et = !1;
|
|
1399
|
+
function At(e, t) {
|
|
1400
|
+
const n = Oe(e);
|
|
1401
|
+
if (n)
|
|
1402
|
+
try {
|
|
1403
|
+
const o = {
|
|
1404
|
+
blob: t,
|
|
1405
|
+
userVersion: 0,
|
|
1406
|
+
deviceVersion: 0,
|
|
1407
|
+
cachedAt: Date.now()
|
|
1408
|
+
};
|
|
1409
|
+
localStorage.setItem(n, JSON.stringify(o));
|
|
1410
|
+
} catch (o) {
|
|
1411
|
+
Et || (Et = !0, A("preferences", "writeThrough localStorage failed (in-memory backstop only)", {
|
|
1412
|
+
appId: e,
|
|
1413
|
+
err: o?.message,
|
|
1414
|
+
name: o?.name
|
|
1415
|
+
}));
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
function Nt(e) {
|
|
1419
|
+
Promise.resolve().then(() => En).then(({ useAppStore: t }) => {
|
|
1420
|
+
try {
|
|
1421
|
+
t.getState().rehydrateFromPrefs();
|
|
1422
|
+
} catch (n) {
|
|
1423
|
+
A("preferences", "rehydrateFromPrefs threw", { reason: e, err: n?.message });
|
|
1424
|
+
}
|
|
1425
|
+
}).catch((t) => A("preferences", "store import failed", { reason: e, err: t?.message }));
|
|
1426
|
+
}
|
|
1427
|
+
const Tn = 320, De = 240, ut = 640, Io = 320, To = 36, Pt = 16;
|
|
1428
|
+
function V(e, t) {
|
|
1429
|
+
if (!Number.isFinite(e)) return Tn;
|
|
1430
|
+
let n = ut;
|
|
1431
|
+
return t !== void 0 && Number.isFinite(t) && t > 0 && (n = Math.min(n, t - Io)), n = Math.max(n, De), Math.round(Math.min(n, Math.max(De, e)));
|
|
1432
|
+
}
|
|
1433
|
+
function Mt(e, t, n, o) {
|
|
1434
|
+
return V(e + (t - n), o);
|
|
1435
|
+
}
|
|
1436
|
+
function Eo(e, t, n) {
|
|
1437
|
+
switch (t) {
|
|
1438
|
+
case "ArrowLeft":
|
|
1439
|
+
return V(e + Pt, n);
|
|
1440
|
+
case "ArrowRight":
|
|
1441
|
+
return V(e - Pt, n);
|
|
1442
|
+
case "Home":
|
|
1443
|
+
return V(De, n);
|
|
1444
|
+
case "End":
|
|
1445
|
+
return V(ut, n);
|
|
1446
|
+
default:
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
function Ao(e, t) {
|
|
1451
|
+
return { collapsed: e, width: e ? To : t };
|
|
1452
|
+
}
|
|
1453
|
+
const q = dt(), m = Gn((e, t) => ({
|
|
1454
|
+
ready: !1,
|
|
1455
|
+
name: "",
|
|
1456
|
+
sprite: q.sprite || null,
|
|
1457
|
+
me: { clientId: null, nextClientSeq: 1 },
|
|
1458
|
+
snapshot: { roomId: null, mediaId: null, playheadMs: 0, playing: !1, serverSeq: 0, leaderId: null },
|
|
1459
|
+
roster: {},
|
|
1460
|
+
chat: [],
|
|
1461
|
+
chatCollapsed: q.chatCollapsed ?? !1,
|
|
1462
|
+
chromeChatCollapsed: q.chromeChatCollapsed ?? !1,
|
|
1463
|
+
chromeChatWidth: V(q.chromeChatWidth ?? Tn),
|
|
1464
|
+
// Hardcoded on for everyone — the per-user toggle was removed from the
|
|
1465
|
+
// control bar; FloatingChat + toggleFloatingChat code is kept for future
|
|
1466
|
+
// re-enablement but the value is no longer user-controllable.
|
|
1467
|
+
floatingChatEnabled: !0,
|
|
1468
|
+
characterModalOpen: !1,
|
|
1469
|
+
drift: { rtts: [], offsetMs: 0 },
|
|
1470
|
+
snapshotReceivedAt: Date.now(),
|
|
1471
|
+
loadGeneration: 0,
|
|
1472
|
+
readiness: { mediaId: null, ready: !1, readyCount: 0, total: 0 },
|
|
1473
|
+
bufferState: { isBuffering: !1, bufferedEndMs: 0 },
|
|
1474
|
+
toasts: [],
|
|
1475
|
+
mediaPrefs: {
|
|
1476
|
+
volume: q.volume ?? 1,
|
|
1477
|
+
muted: q.muted ?? !1,
|
|
1478
|
+
preferredAudioLang: q.preferredAudioLang || "jpn",
|
|
1479
|
+
subtitlesEnabled: q.subtitlesEnabled ?? !0,
|
|
1480
|
+
subtitleStyle: ["classic", "cinema", "minimal", "contrast"].includes(q.subtitleStyle) ? q.subtitleStyle : "classic"
|
|
1481
|
+
},
|
|
1482
|
+
healthSnapshot: null,
|
|
1483
|
+
sidebarTab: "chat",
|
|
1484
|
+
bufferStatus: null,
|
|
1485
|
+
mutedForAutoplay: !1,
|
|
1486
|
+
playlist: null,
|
|
1487
|
+
activePlaylistIndex: null,
|
|
1488
|
+
myVotes: {},
|
|
1489
|
+
voteProgress: [],
|
|
1490
|
+
playlistResults: null,
|
|
1491
|
+
tierlistOpen: !1,
|
|
1492
|
+
tierlist: null,
|
|
1493
|
+
tierlistDraft: {},
|
|
1494
|
+
tierlistSaving: !1,
|
|
1495
|
+
readyCheck: { active: !1, ready: [] },
|
|
1496
|
+
activeGameId: null,
|
|
1497
|
+
roomKeyType: null,
|
|
1498
|
+
gameSessionWins: {},
|
|
1499
|
+
gameBotCount: 0,
|
|
1500
|
+
setReady: () => {
|
|
1501
|
+
d("store", "App ready"), e({ ready: !0 });
|
|
1502
|
+
},
|
|
1503
|
+
setIdentity: (n, o) => {
|
|
1504
|
+
d("store", "Identity set", { name: n, sprite: o }), e({ name: n, sprite: o }), o && K("sprite", o);
|
|
1505
|
+
},
|
|
1506
|
+
setSessionIdentity: (n, o) => {
|
|
1507
|
+
d("store", "Session identity set (not persisted)", { name: n, sprite: o }), e({ name: n, sprite: o });
|
|
1508
|
+
},
|
|
1509
|
+
ensureAutoIdentity: () => e((n) => {
|
|
1510
|
+
if (n.name) return {};
|
|
1511
|
+
if (n.sprite) {
|
|
1512
|
+
const i = te(n.sprite);
|
|
1513
|
+
return d("store", "Auto-identity: deriving name from saved sprite", { name: i, sprite: n.sprite }), { name: i };
|
|
1514
|
+
}
|
|
1515
|
+
const o = new Set(Object.values(n.roster).map((i) => i.sprite).filter(Boolean));
|
|
1516
|
+
d("store", "ensureAutoIdentity checking", {
|
|
1517
|
+
rosterSize: Object.keys(n.roster).length,
|
|
1518
|
+
usedSprites: Array.from(o)
|
|
1519
|
+
});
|
|
1520
|
+
for (const i of Le)
|
|
1521
|
+
if (!o.has(i)) {
|
|
1522
|
+
const s = te(i);
|
|
1523
|
+
return d("store", "Auto-identity assigned", { name: s, sprite: i }), { name: s, sprite: i };
|
|
1524
|
+
}
|
|
1525
|
+
return A("store", "All characters taken, leaving identity unset"), {};
|
|
1526
|
+
}),
|
|
1527
|
+
ensureMe: (n) => {
|
|
1528
|
+
d("store", "Client ID set", { clientId: n }), e((o) => ({ me: { ...o.me, clientId: n } }));
|
|
1529
|
+
},
|
|
1530
|
+
applySnapshot: (n) => e((o) => {
|
|
1531
|
+
const i = { ...o.roster };
|
|
1532
|
+
if (n.users)
|
|
1533
|
+
for (const f of n.users) i[f.clientId] = f;
|
|
1534
|
+
const s = n.mediaId !== void 0 ? n.mediaId : o.snapshot.mediaId, a = n.leaderId !== void 0 ? n.leaderId : o.snapshot.leaderId;
|
|
1535
|
+
d("store", "Snapshot applied", {
|
|
1536
|
+
mediaId: s,
|
|
1537
|
+
playing: n.playing ?? o.snapshot.playing,
|
|
1538
|
+
serverSeq: n.serverSeq ?? o.snapshot.serverSeq,
|
|
1539
|
+
userCount: n.users?.length ?? 0
|
|
1540
|
+
});
|
|
1541
|
+
const c = n.playheadMs ?? o.snapshot.playheadMs;
|
|
1542
|
+
return {
|
|
1543
|
+
snapshot: {
|
|
1544
|
+
roomId: n.roomId !== void 0 ? n.roomId : o.snapshot.roomId,
|
|
1545
|
+
mediaId: s,
|
|
1546
|
+
playheadMs: c,
|
|
1547
|
+
playing: n.playing ?? o.snapshot.playing,
|
|
1548
|
+
serverSeq: n.serverSeq ?? o.snapshot.serverSeq,
|
|
1549
|
+
leaderId: a
|
|
1550
|
+
},
|
|
1551
|
+
roster: i,
|
|
1552
|
+
// Always update — initial snapshot on join often has playheadMs=0
|
|
1553
|
+
// matching the store default, so the old playheadChanged guard left
|
|
1554
|
+
// snapshotReceivedAt at page-load time. This inflated viewer correction
|
|
1555
|
+
// elapsed by browser launch + buffer gate duration, causing 60-115s drift.
|
|
1556
|
+
snapshotReceivedAt: Date.now()
|
|
1557
|
+
};
|
|
1558
|
+
}),
|
|
1559
|
+
upsertUser: (n) => {
|
|
1560
|
+
d("store", "User upserted", { clientId: n.clientId, name: n.name, isLeader: n.isLeader }), e((o) => ({ roster: { ...o.roster, [n.clientId]: n } }));
|
|
1561
|
+
},
|
|
1562
|
+
removeUser: (n) => {
|
|
1563
|
+
d("store", "User removed", { clientId: n }), e((o) => {
|
|
1564
|
+
const i = { ...o.roster };
|
|
1565
|
+
return delete i[n], { roster: i };
|
|
1566
|
+
});
|
|
1567
|
+
},
|
|
1568
|
+
appendChat: (n) => {
|
|
1569
|
+
d("chat", "Message appended", { id: n.id, from: n.name, isSystem: n.isSystem }), e((o) => ({ chat: [...o.chat, n].slice(-500) }));
|
|
1570
|
+
},
|
|
1571
|
+
setChat: (n) => e({ chat: n.slice(-500) }),
|
|
1572
|
+
toggleChatCollapsed: () => e((n) => {
|
|
1573
|
+
const o = !n.chatCollapsed;
|
|
1574
|
+
return K("chatCollapsed", o), { chatCollapsed: o };
|
|
1575
|
+
}),
|
|
1576
|
+
toggleChromeChatCollapsed: () => e((n) => {
|
|
1577
|
+
const o = !n.chromeChatCollapsed;
|
|
1578
|
+
return K("chromeChatCollapsed", o), { chromeChatCollapsed: o };
|
|
1579
|
+
}),
|
|
1580
|
+
setChromeChatWidth: (n) => e(() => {
|
|
1581
|
+
const o = V(n);
|
|
1582
|
+
return K("chromeChatWidth", o), { chromeChatWidth: o };
|
|
1583
|
+
}),
|
|
1584
|
+
toggleFloatingChat: () => e((n) => {
|
|
1585
|
+
const o = !n.floatingChatEnabled;
|
|
1586
|
+
return K("floatingChatEnabled", o), { floatingChatEnabled: o };
|
|
1587
|
+
}),
|
|
1588
|
+
setCharacterModalOpen: (n) => e({ characterModalOpen: n }),
|
|
1589
|
+
allocateClientSeq: () => {
|
|
1590
|
+
const n = t().me.nextClientSeq;
|
|
1591
|
+
return e((o) => ({ me: { ...o.me, nextClientSeq: n + 1 } })), n;
|
|
1592
|
+
},
|
|
1593
|
+
bumpLoadGeneration: () => e((n) => ({ loadGeneration: n.loadGeneration + 1 })),
|
|
1594
|
+
updateControlState: (n) => {
|
|
1595
|
+
d("store", "updateControlState called", n), e((o) => ({
|
|
1596
|
+
snapshot: { ...o.snapshot, ...n },
|
|
1597
|
+
// Always update snapshotReceivedAt — any control_broadcast from the
|
|
1598
|
+
// server resets the elapsed-time calculation. The old condition
|
|
1599
|
+
// (playheadMs !== s.snapshot.playheadMs) missed media reloads that
|
|
1600
|
+
// set playheadMs=0 when it was already 0, causing prefetch to use
|
|
1601
|
+
// wall-clock-since-page-load as the expected position.
|
|
1602
|
+
snapshotReceivedAt: Date.now()
|
|
1603
|
+
}));
|
|
1604
|
+
},
|
|
1605
|
+
addRttSample: (n, o, i) => e((s) => {
|
|
1606
|
+
const a = [...s.drift.rtts, n].slice(-5);
|
|
1607
|
+
let c = s.drift.offsetMs;
|
|
1608
|
+
if (o && i) {
|
|
1609
|
+
const f = i + n / 2;
|
|
1610
|
+
c = o - f;
|
|
1611
|
+
}
|
|
1612
|
+
return { drift: { rtts: a, offsetMs: c } };
|
|
1613
|
+
}),
|
|
1614
|
+
pushToast: (n, o) => {
|
|
1615
|
+
d("store", "Toast pushed", { kind: n, msg: o }), e((i) => ({ toasts: [...i.toasts, { id: Math.random().toString(36).slice(2), kind: n, msg: o, ts: Date.now() }].slice(-5) }));
|
|
1616
|
+
},
|
|
1617
|
+
popToast: (n) => e((o) => ({ toasts: o.toasts.filter((i) => i.id !== n) })),
|
|
1618
|
+
setReadiness: (n) => e({ readiness: { mediaId: n.mediaId, ready: n.ready, readyCount: n.readyCount, total: n.total } }),
|
|
1619
|
+
setBufferState: (n) => e((o) => ({ bufferState: { ...o.bufferState, ...n } })),
|
|
1620
|
+
setMutedForAutoplay: (n) => e({ mutedForAutoplay: n }),
|
|
1621
|
+
// Media preference actions
|
|
1622
|
+
setVolume: (n) => e((o) => (K("volume", n), { mediaPrefs: { ...o.mediaPrefs, volume: n } })),
|
|
1623
|
+
setMuted: (n) => e((o) => (K("muted", n), { mediaPrefs: { ...o.mediaPrefs, muted: n } })),
|
|
1624
|
+
setPreferredAudioLang: (n) => e((o) => (K("preferredAudioLang", n), { mediaPrefs: { ...o.mediaPrefs, preferredAudioLang: n } })),
|
|
1625
|
+
setSubtitlesEnabled: (n) => e((o) => (K("subtitlesEnabled", n), { mediaPrefs: { ...o.mediaPrefs, subtitlesEnabled: n } })),
|
|
1626
|
+
setSubtitleStyle: (n) => e((o) => (K("subtitleStyle", n), { mediaPrefs: { ...o.mediaPrefs, subtitleStyle: n } })),
|
|
1627
|
+
setHealthSnapshot: (n) => e({ healthSnapshot: n }),
|
|
1628
|
+
setBufferStatus: (n) => e({ bufferStatus: n }),
|
|
1629
|
+
applyPlaylistState: (n) => e({
|
|
1630
|
+
playlist: n.playlist,
|
|
1631
|
+
activePlaylistIndex: n.activeIndex,
|
|
1632
|
+
myVotes: n.myVotes,
|
|
1633
|
+
// Clear stale results when a new playlist state arrives
|
|
1634
|
+
playlistResults: null
|
|
1635
|
+
}),
|
|
1636
|
+
setVoteProgress: (n) => e({ voteProgress: n }),
|
|
1637
|
+
setPlaylistResults: (n) => e({ playlistResults: n }),
|
|
1638
|
+
setTierlistOpen: (n) => e({ tierlistOpen: n }),
|
|
1639
|
+
setTierlistSaving: (n) => e({ tierlistSaving: n }),
|
|
1640
|
+
/**
|
|
1641
|
+
* Apply a server snapshot.
|
|
1642
|
+
*
|
|
1643
|
+
* `adoptDraft` is false for a refresh triggered by SOMEONE ELSE saving: the
|
|
1644
|
+
* shared result must update live, but replacing the draft would yank cards
|
|
1645
|
+
* out from under someone mid-drag. It is true only when this client opens the
|
|
1646
|
+
* board or saves its own, which are the two moments its draft is not ahead of
|
|
1647
|
+
* the server.
|
|
1648
|
+
*/
|
|
1649
|
+
setTierlistSnapshot: (n, o) => e((i) => ({
|
|
1650
|
+
tierlist: n,
|
|
1651
|
+
tierlistDraft: o ? { ...n.myBoard } : i.tierlistDraft
|
|
1652
|
+
})),
|
|
1653
|
+
/**
|
|
1654
|
+
* Move one item on the draft board. Local only — nothing reaches the server
|
|
1655
|
+
* until Save, which is the whole point of the Save button.
|
|
1656
|
+
*
|
|
1657
|
+
* Remove from every row FIRST, so a move within a row reorders rather than
|
|
1658
|
+
* duplicating, then insert at `index`. Absent from every row — not
|
|
1659
|
+
* present-with-a-low-value — is what keeps "not rated" distinguishable from
|
|
1660
|
+
* "rated F" in placeTierlist.
|
|
1661
|
+
*/
|
|
1662
|
+
moveTierlistItem: (n, o, i) => e((s) => {
|
|
1663
|
+
const a = {};
|
|
1664
|
+
for (const [c, f] of Object.entries(s.tierlistDraft)) {
|
|
1665
|
+
const g = (f ?? []).filter((p) => p !== n);
|
|
1666
|
+
g.length > 0 && (a[c] = g);
|
|
1667
|
+
}
|
|
1668
|
+
if (o !== null) {
|
|
1669
|
+
const c = a[o] ?? [], f = Math.max(0, Math.min(i ?? c.length, c.length));
|
|
1670
|
+
c.splice(f, 0, n), a[o] = c;
|
|
1671
|
+
}
|
|
1672
|
+
return { tierlistDraft: a };
|
|
1673
|
+
}),
|
|
1674
|
+
setReadyCheckState: (n) => e({ readyCheck: n }),
|
|
1675
|
+
setActiveGameId: (n) => e({ activeGameId: n }),
|
|
1676
|
+
setRoomKeyType: (n) => e({ roomKeyType: n }),
|
|
1677
|
+
setGameSessionWins: (n) => e({ gameSessionWins: { ...n } }),
|
|
1678
|
+
setGameBotCount: (n) => e({ gameBotCount: Math.max(0, Math.floor(n)) }),
|
|
1679
|
+
rehydrateFromPrefs: () => e((n) => {
|
|
1680
|
+
const o = dt(), i = {};
|
|
1681
|
+
if (o.sprite !== void 0 && (i.sprite = o.sprite || null), o.chatCollapsed !== void 0 && (i.chatCollapsed = o.chatCollapsed), o.chromeChatCollapsed !== void 0 && (i.chromeChatCollapsed = o.chromeChatCollapsed), o.chromeChatWidth !== void 0 && (i.chromeChatWidth = V(o.chromeChatWidth)), ["volume", "muted", "preferredAudioLang", "subtitlesEnabled", "subtitleStyle"].some((c) => o[c] !== void 0)) {
|
|
1682
|
+
const c = { ...n.mediaPrefs };
|
|
1683
|
+
o.volume !== void 0 && (c.volume = o.volume), o.muted !== void 0 && (c.muted = o.muted), o.preferredAudioLang !== void 0 && (c.preferredAudioLang = o.preferredAudioLang), o.subtitlesEnabled !== void 0 && (c.subtitlesEnabled = o.subtitlesEnabled), o.subtitleStyle !== void 0 && ["classic", "cinema", "minimal", "contrast"].includes(o.subtitleStyle) && (c.subtitleStyle = o.subtitleStyle), i.mediaPrefs = c;
|
|
1684
|
+
}
|
|
1685
|
+
return i;
|
|
1686
|
+
}),
|
|
1687
|
+
setSidebarTab: (n) => e((o) => o.sidebarTab === n && n !== "chat" ? { sidebarTab: "chat" } : { sidebarTab: n, chatCollapsed: !1 })
|
|
1688
|
+
}));
|
|
1689
|
+
Fe("__ZUSTAND_STORE__", m);
|
|
1690
|
+
const En = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1691
|
+
__proto__: null,
|
|
1692
|
+
useAppStore: m
|
|
1693
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1694
|
+
function No(e) {
|
|
1695
|
+
return `${hn()}/media/${e}`.replace(/\\/g, "/");
|
|
1696
|
+
}
|
|
1697
|
+
function Po(e, t) {
|
|
1698
|
+
return No(t ?? `${e}/poster.jpg`);
|
|
1699
|
+
}
|
|
1700
|
+
function Mo(e) {
|
|
1701
|
+
return `${hn()}${e}`.replace(/\\/g, "/");
|
|
1702
|
+
}
|
|
1703
|
+
async function Oo(e) {
|
|
1704
|
+
try {
|
|
1705
|
+
const t = await fetch(Mo("/api/tierlist"));
|
|
1706
|
+
if (!t.ok)
|
|
1707
|
+
return A("tierlist", "Board fetch failed", { status: t.status }), null;
|
|
1708
|
+
const n = await t.json();
|
|
1709
|
+
return m.getState().setTierlistSnapshot(n, e), d("tierlist", "Board loaded", {
|
|
1710
|
+
items: n.items.length,
|
|
1711
|
+
voters: n.voterCount,
|
|
1712
|
+
placed: n.placed.length
|
|
1713
|
+
}), n;
|
|
1714
|
+
} catch (t) {
|
|
1715
|
+
return A("tierlist", "Board fetch threw", ge(t)), null;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
let Ot = !1;
|
|
1719
|
+
function Ro() {
|
|
1720
|
+
if (Ot || typeof Image > "u") return;
|
|
1721
|
+
const e = m.getState().tierlist;
|
|
1722
|
+
if (!(!e || e.items.length === 0)) {
|
|
1723
|
+
Ot = !0;
|
|
1724
|
+
for (const t of e.items) {
|
|
1725
|
+
const n = new Image();
|
|
1726
|
+
n.decoding = "async", n.src = Po(t.id, t.thumbnail);
|
|
1727
|
+
}
|
|
1728
|
+
d("tierlist", "Warming posters", { count: e.items.length });
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
function Do() {
|
|
1732
|
+
const e = m.getState(), t = new Set(Object.values(e.roster).map((s) => s.sprite).filter(Boolean)), n = Le.find((s) => !t.has(s));
|
|
1733
|
+
if (!n)
|
|
1734
|
+
return A("socket", "sprite_taken: no available sprites to retry with"), null;
|
|
1735
|
+
const o = !!e.name && !ne(e.name), i = o ? e.name : te(n);
|
|
1736
|
+
return d("socket", "sprite_taken: retrying with next available", { from: e.sprite, to: n, name: i, keptCustomName: o }), e.setSessionIdentity(i, n), { name: i, sprite: n };
|
|
1737
|
+
}
|
|
1738
|
+
function Lo(e) {
|
|
1739
|
+
const t = m.getState(), n = e ? t.roster[e] : void 0;
|
|
1740
|
+
return !n || !!n.sprite && n.sprite === t.sprite;
|
|
1741
|
+
}
|
|
1742
|
+
const jo = 10;
|
|
1743
|
+
function Uo(e = typeof window < "u" ? window : void 0) {
|
|
1744
|
+
if (!e) return { framed: !1, depth: 0 };
|
|
1745
|
+
try {
|
|
1746
|
+
let t = 0, n = e;
|
|
1747
|
+
for (; n !== n.parent && t < jo; )
|
|
1748
|
+
t++, n = n.parent;
|
|
1749
|
+
return { framed: e.top ? e.top !== e.self : t > 0, depth: t };
|
|
1750
|
+
} catch {
|
|
1751
|
+
return { framed: !1, depth: 0 };
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
const Fo = "watchparty_fragment_delivery";
|
|
1755
|
+
function Ho() {
|
|
1756
|
+
if (typeof window > "u") return null;
|
|
1757
|
+
try {
|
|
1758
|
+
const e = new URLSearchParams(window.location.search).get("fragmentDelivery");
|
|
1759
|
+
if (e === "1" || e === "true") return !0;
|
|
1760
|
+
if (e === "0" || e === "false") return !1;
|
|
1761
|
+
} catch {
|
|
1762
|
+
}
|
|
1763
|
+
return Xr(Fo);
|
|
1764
|
+
}
|
|
1765
|
+
let $o = { ...rn }, Be = null;
|
|
1766
|
+
const Rt = "watchparty_delivery_client_id";
|
|
1767
|
+
function Bo() {
|
|
1768
|
+
const e = G(Rt);
|
|
1769
|
+
if (e) return e;
|
|
1770
|
+
const t = globalThis.crypto?.randomUUID?.() ?? `d${Math.random().toString(36).slice(2)}`;
|
|
1771
|
+
return at(Rt, t) ? t : "";
|
|
1772
|
+
}
|
|
1773
|
+
function Go() {
|
|
1774
|
+
return Be === null && (Be = Sr($o, Bo(), Ho())), Be;
|
|
1775
|
+
}
|
|
1776
|
+
function Wo() {
|
|
1777
|
+
return Go();
|
|
1778
|
+
}
|
|
1779
|
+
let Ee;
|
|
1780
|
+
function An() {
|
|
1781
|
+
return G(qn) || void 0;
|
|
1782
|
+
}
|
|
1783
|
+
function Ko() {
|
|
1784
|
+
if (Ee) return;
|
|
1785
|
+
const e = An();
|
|
1786
|
+
if (e) {
|
|
1787
|
+
Ee = e;
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
Kn().then((t) => {
|
|
1791
|
+
t && (Ee = t);
|
|
1792
|
+
}).catch(() => {
|
|
1793
|
+
d("identity", "device id unavailable — joining without one");
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
function qo() {
|
|
1797
|
+
return Ee ??= An();
|
|
1798
|
+
}
|
|
1799
|
+
function Vo(e, t) {
|
|
1800
|
+
let n = 0;
|
|
1801
|
+
for (const o of e.videos) {
|
|
1802
|
+
const i = oe.voteKey(t, e.id, o.mediaId);
|
|
1803
|
+
globalThis.localStorage?.getItem(i) != null && n++, Me(i);
|
|
1804
|
+
}
|
|
1805
|
+
return n;
|
|
1806
|
+
}
|
|
1807
|
+
const zo = 2e4, Yo = 1e4;
|
|
1808
|
+
function Xo() {
|
|
1809
|
+
return { unansweredSince: null, lastPongAt: null, lastTickAt: null };
|
|
1810
|
+
}
|
|
1811
|
+
function Jo(e, t) {
|
|
1812
|
+
e.lastPongAt = t, e.unansweredSince = null;
|
|
1813
|
+
}
|
|
1814
|
+
function Zo(e, t, n) {
|
|
1815
|
+
const o = e.lastTickAt !== null && t - e.lastTickAt > Yo;
|
|
1816
|
+
return e.lastTickAt = t, n ? o || e.unansweredSince === null ? (e.unansweredSince = t, !1) : t - e.unansweredSince > zo : (e.unansweredSince = null, !1);
|
|
1817
|
+
}
|
|
1818
|
+
function Qo(e, t) {
|
|
1819
|
+
return e.lastPongAt === null ? void 0 : Math.max(0, t - e.lastPongAt);
|
|
1820
|
+
}
|
|
1821
|
+
let x = null, $ = null, Ae = null, B = null, z = null;
|
|
1822
|
+
const ei = ri(), ee = Xo();
|
|
1823
|
+
let _e = null, Ge = null, Dt = 0, mt = null, Qe = !1, pt = !1, le = !1, Nn = null;
|
|
1824
|
+
function ti(e) {
|
|
1825
|
+
const t = ie(), n = m.getState();
|
|
1826
|
+
if (n.me.clientId && n.roster[n.me.clientId])
|
|
1827
|
+
return (e.name || e.sprite) && (d("socket", "Identity update (already joined)", { name: e.name, sprite: e.sprite }), t.emit(I.IDENTITY_UPDATE, { name: e.name, sprite: e.sprite })), t;
|
|
1828
|
+
const o = ni(e);
|
|
1829
|
+
return z = o, mt = { name: o.name, sprite: o.sprite }, t.connected ? (d("socket", "Emitting join", o), t.emit(I.JOIN, o)) : t.once("connect", () => {
|
|
1830
|
+
d("socket", "Emitting join", o), t.emit(I.JOIN, o);
|
|
1831
|
+
}), t;
|
|
1832
|
+
}
|
|
1833
|
+
function ni(e) {
|
|
1834
|
+
return {
|
|
1835
|
+
room_key: e.room_key,
|
|
1836
|
+
name: e.name,
|
|
1837
|
+
sprite: e.sprite,
|
|
1838
|
+
// Entry-path telemetry — see lib/embedContext.ts. Sent on every join AND
|
|
1839
|
+
// rejoin (lastJoinPayload carries it), so a reconnect keeps the attribution.
|
|
1840
|
+
embed: Uo(),
|
|
1841
|
+
delivery_arm: Wo(),
|
|
1842
|
+
// Identity tier input — see lib/deviceId.ts. Sent on every join AND rejoin
|
|
1843
|
+
// (lastJoinPayload carries it) so a reconnect lands on the same
|
|
1844
|
+
// ParticipantId rather than minting a new person.
|
|
1845
|
+
device_id: qo(),
|
|
1846
|
+
tab_id: ei
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
function ri() {
|
|
1850
|
+
const e = globalThis.crypto;
|
|
1851
|
+
if (e && typeof e.randomUUID == "function") return e.randomUUID();
|
|
1852
|
+
const t = new Uint8Array(16);
|
|
1853
|
+
if (e && typeof e.getRandomValues == "function") e.getRandomValues(t);
|
|
1854
|
+
else for (let n = 0; n < t.length; n++) t[n] = Math.floor(Math.random() * 256);
|
|
1855
|
+
return Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("");
|
|
1856
|
+
}
|
|
1857
|
+
function ie() {
|
|
1858
|
+
if (!x) {
|
|
1859
|
+
let t = he().serverOrigin || "/";
|
|
1860
|
+
if (t === "/" && typeof window < "u") {
|
|
1861
|
+
const o = window.location;
|
|
1862
|
+
(o.hostname === "localhost" || o.hostname === "127.0.0.1") && o.port === String(zt) && (t = `${o.protocol}//${o.hostname}:${tt}`, d("socket", "Using dev fallback origin", { origin: t }));
|
|
1863
|
+
}
|
|
1864
|
+
const n = new URL(t.startsWith("http") ? t : `${window.location.origin}${t}`).origin;
|
|
1865
|
+
x = Vn(n, { path: Jn, transports: ["websocket", "polling"] }), d("socket", "Socket initialized", { origin: t }), Fe("__SOCKET__", x), B && (clearTimeout(B), B = null), $ = null, Ae = setInterval(() => {
|
|
1866
|
+
if (Zo(ee, Date.now(), !!x?.connected)) {
|
|
1867
|
+
A("socket", "PONG-WATCHDOG no time_pong for 20s — replacing the connection", {
|
|
1868
|
+
sid: x?.id,
|
|
1869
|
+
lastPongAgeMs: Qo(ee, Date.now()) ?? null
|
|
1870
|
+
}), Ge = "pong-watchdog", ee.unansweredSince = null, x?.io.engine?.close();
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
fi();
|
|
1874
|
+
}, gr), x.on("connect", () => {
|
|
1875
|
+
pt = !1;
|
|
1876
|
+
const o = x?.id;
|
|
1877
|
+
if (d("socket", "Connected", { id: o, isReconnect: le }), o)
|
|
1878
|
+
try {
|
|
1879
|
+
m.getState().ensureMe(o), m.setState((i) => ({ me: { ...i.me, nextClientSeq: 1 } })), d("socket", "Reset client sequence for new connection");
|
|
1880
|
+
} catch (i) {
|
|
1881
|
+
ue("socket", "Failed to initialize store on connect", { error: i.message, sid: o });
|
|
1882
|
+
}
|
|
1883
|
+
if (le && z) {
|
|
1884
|
+
const i = m.getState();
|
|
1885
|
+
Dt += 1;
|
|
1886
|
+
const s = {
|
|
1887
|
+
...z,
|
|
1888
|
+
name: i.name,
|
|
1889
|
+
sprite: i.sprite,
|
|
1890
|
+
reconnect: {
|
|
1891
|
+
count: Dt,
|
|
1892
|
+
reason: (_e?.reason ?? "unknown").slice(0, 64),
|
|
1893
|
+
offline_ms: _e ? Math.max(0, Date.now() - _e.at) : 0
|
|
1894
|
+
}
|
|
1895
|
+
}, a = Nn;
|
|
1896
|
+
if (d("socket", "Re-emitting join after reconnect", { room_key: s.room_key, name: s.name, sprite: s.sprite }), a) {
|
|
1897
|
+
let c = !1;
|
|
1898
|
+
const f = () => {
|
|
1899
|
+
c || (c = !0, x.off(I.SNAPSHOT, f), x.emit(I.CLIENT_READY, { media_id: a }), d("socket", "Re-emitted client_ready after reconnect snapshot", { mediaId: a }));
|
|
1900
|
+
};
|
|
1901
|
+
x.on(I.SNAPSHOT, f), setTimeout(() => {
|
|
1902
|
+
c || (c = !0, x.off(I.SNAPSHOT, f), A("socket", "client_ready re-emit timed out waiting for snapshot", { mediaId: a }));
|
|
1903
|
+
}, 1e4);
|
|
1904
|
+
}
|
|
1905
|
+
mt = { name: s.name, sprite: s.sprite }, x.emit(I.JOIN, s), window.dispatchEvent(new CustomEvent("watchparty:socket-reconnect"));
|
|
1906
|
+
} else le && A("socket", "Reconnected — no join payload, not re-joining any room");
|
|
1907
|
+
le = !0;
|
|
1908
|
+
}), x.on("disconnect", (o) => {
|
|
1909
|
+
wn(null), _e = { reason: Ge ?? o, at: Date.now() }, Ge = null, d("socket", "Disconnected", { reason: o });
|
|
1910
|
+
}), x.on("connect_error", (o) => ue("socket", "Connection error", { message: o?.message })), x.on("reconnect_attempt", (o) => A("socket", "Reconnect attempt", { attempt: o })), x.on("reconnect_failed", () => ue("socket", "Reconnect failed")), mi(x);
|
|
1911
|
+
}
|
|
1912
|
+
return x;
|
|
1913
|
+
}
|
|
1914
|
+
function We(e) {
|
|
1915
|
+
return e.play_state === "playing" || e.playing === !0;
|
|
1916
|
+
}
|
|
1917
|
+
function Lt(e, t) {
|
|
1918
|
+
return {
|
|
1919
|
+
id: String(e.id ?? e.server_seq ?? t ?? `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`),
|
|
1920
|
+
clientId: e.client_id,
|
|
1921
|
+
author: typeof e.author == "string" ? e.author : void 0,
|
|
1922
|
+
name: e.name || "Anon",
|
|
1923
|
+
sprite: e.sprite ?? null,
|
|
1924
|
+
text: e.text || "",
|
|
1925
|
+
ts: e.ts || Date.now(),
|
|
1926
|
+
// Attachments arrive from other clients, so the key shape is re-checked
|
|
1927
|
+
// here at the boundary rather than trusted at render time. A malformed
|
|
1928
|
+
// entry is dropped, not rendered and not allowed near an <img src>.
|
|
1929
|
+
images: Array.isArray(e.images) ? e.images.filter((n) => !!n && et(n.key)).slice(0, Y) : void 0,
|
|
1930
|
+
isSystem: e.isSystem || !1,
|
|
1931
|
+
systemType: e.systemType
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
function oi(e) {
|
|
1935
|
+
e.on(I.SNAPSHOT, (t) => {
|
|
1936
|
+
e.emit(tn.SYNC), m.getState().applySnapshot({
|
|
1937
|
+
roomId: t.room_id ?? null,
|
|
1938
|
+
mediaId: t.media_id ?? null,
|
|
1939
|
+
playheadMs: t.playhead_ms || 0,
|
|
1940
|
+
playing: We(t),
|
|
1941
|
+
serverSeq: t.server_seq || 0,
|
|
1942
|
+
leaderId: t.leader_id || null
|
|
1943
|
+
}), m.getState().name || d("socket", "Deferring identity to presence event (snapshot carries no roster)");
|
|
1944
|
+
const n = m.getState(), o = x?.id, s = (o ? n.roster[o] : void 0) ?? mt, a = zn(
|
|
1945
|
+
{ name: n.name, avatarId: n.sprite },
|
|
1946
|
+
s ? { name: s.name, avatarId: s.sprite ?? null } : void 0,
|
|
1947
|
+
// A join that carried no name counts as a default one, so a name that
|
|
1948
|
+
// landed after the join (prefs) is still asserted.
|
|
1949
|
+
(c) => c === "" || ne(c)
|
|
1950
|
+
);
|
|
1951
|
+
if (a) {
|
|
1952
|
+
const c = {
|
|
1953
|
+
...a.name !== void 0 ? { name: a.name } : {},
|
|
1954
|
+
...a.avatarId !== void 0 && !pt ? { sprite: a.avatarId } : {}
|
|
1955
|
+
};
|
|
1956
|
+
Object.keys(c).length > 0 && (d("socket", "Identity update on snapshot", c), e.emit(I.IDENTITY_UPDATE, c));
|
|
1957
|
+
}
|
|
1958
|
+
d("socket", "Received snapshot", {
|
|
1959
|
+
mediaId: t.media_id ?? null,
|
|
1960
|
+
playheadMs: t.playhead_ms || 0,
|
|
1961
|
+
playing: We(t),
|
|
1962
|
+
leaderId: t.leader_id || null,
|
|
1963
|
+
serverSeq: t.server_seq || 0,
|
|
1964
|
+
rosterSize: Object.keys(n.roster).length
|
|
1965
|
+
}), z?.room_key && x?.id && wn({ room_key: z.room_key, client_id: x.id });
|
|
1966
|
+
}), e.on(I.CONTROL_BROADCAST, (t) => {
|
|
1967
|
+
const n = m.getState();
|
|
1968
|
+
if (Object.prototype.hasOwnProperty.call(t, "media_id")) {
|
|
1969
|
+
const o = t.media_id ?? null;
|
|
1970
|
+
n.snapshot.mediaId !== o && (n.applySnapshot({ mediaId: o }), o && n.setReadiness({ mediaId: o, ready: !1, readyCount: 0, total: 0 }), n.bumpLoadGeneration());
|
|
1971
|
+
}
|
|
1972
|
+
n.updateControlState({
|
|
1973
|
+
playheadMs: t.playhead_ms,
|
|
1974
|
+
playing: We(t),
|
|
1975
|
+
serverSeq: t.server_seq,
|
|
1976
|
+
leaderId: t.leader_id ?? n.snapshot.leaderId
|
|
1977
|
+
}), d("socket", "Control broadcast received", {
|
|
1978
|
+
kind: t.kind,
|
|
1979
|
+
serverSeq: t.server_seq,
|
|
1980
|
+
playheadMs: t.playhead_ms,
|
|
1981
|
+
playState: t.play_state,
|
|
1982
|
+
mediaId: t.media_id
|
|
1983
|
+
});
|
|
1984
|
+
}), e.on(I.CONTROL_ACK, (t) => {
|
|
1985
|
+
typeof t?.client_seq == "number" && typeof t?.server_seq == "number" && d("socket", "Control ack received", t);
|
|
1986
|
+
}), e.on(I.TIME_PONG, (t) => {
|
|
1987
|
+
if (Jo(ee, Date.now()), $ && $.ts) {
|
|
1988
|
+
const n = Date.now() - $.ts;
|
|
1989
|
+
m.getState().addRttSample(n, t?.server_ts, $.ts), $ = null, B && (clearTimeout(B), B = null), d("socket", "Time sync RTT", { rtt: n, offset: m.getState().drift.offsetMs });
|
|
1990
|
+
}
|
|
1991
|
+
}), e.on(I.READY_STATE, (t) => {
|
|
1992
|
+
if (!t) return;
|
|
1993
|
+
const n = t.media_id ?? null, o = typeof t.ready_count == "number" ? t.ready_count : 0, i = typeof t.total == "number" ? t.total : 0, s = t.ready === !0;
|
|
1994
|
+
m.getState().setReadiness({ mediaId: n, ready: s, readyCount: o, total: i }), d("socket", "Ready state received", { mediaId: n, readyCount: o, total: i, ready: s });
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
function ii(e) {
|
|
1998
|
+
e.on(I.PRESENCE, (t) => {
|
|
1999
|
+
if (!t) return;
|
|
2000
|
+
if (Array.isArray(t.users)) {
|
|
2001
|
+
const o = {};
|
|
2002
|
+
for (const c of t.users)
|
|
2003
|
+
o[c.client_id] = {
|
|
2004
|
+
clientId: c.client_id,
|
|
2005
|
+
...c.author ? { author: c.author } : {},
|
|
2006
|
+
name: c.name || "Anon",
|
|
2007
|
+
sprite: c.sprite_id ?? c.sprite ?? null,
|
|
2008
|
+
isLeader: c.is_leader,
|
|
2009
|
+
...c.registry_name ? { registryName: !0 } : {}
|
|
2010
|
+
};
|
|
2011
|
+
const i = m.getState(), s = x?.id, a = s ? o[s] : void 0;
|
|
2012
|
+
if (a?.registryName)
|
|
2013
|
+
m.setState({ roster: o }), (a.name !== i.name || a.sprite && a.sprite !== i.sprite) && (d("socket", "Adopting registry name", { from: i.name, to: a.name }), m.getState().setSessionIdentity(a.name, a.sprite ?? i.sprite));
|
|
2014
|
+
else if (s && o[s]) {
|
|
2015
|
+
const c = o[s].name, f = o[s].sprite;
|
|
2016
|
+
if (i.name && !ne(i.name) && (o[s].name = i.name), m.setState({ roster: o }), f && f !== i.sprite) {
|
|
2017
|
+
const g = i.name && !ne(i.name), p = g ? i.name : te(f);
|
|
2018
|
+
d("socket", "Server reassigned sprite", { from: i.sprite, to: f, newName: p, preservingCustomName: g }), m.getState().setSessionIdentity(p, f), p !== c && e.emit(I.IDENTITY_UPDATE, { name: p });
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
d("socket", "Received presence update", t);
|
|
2023
|
+
const n = m.getState();
|
|
2024
|
+
if (!n.name) {
|
|
2025
|
+
n.ensureAutoIdentity?.();
|
|
2026
|
+
const o = m.getState();
|
|
2027
|
+
o.name && (d("socket", "Auto-assigned identity on presence", { name: o.name, sprite: o.sprite }), e.emit(I.IDENTITY_UPDATE, { name: o.name, sprite: o.sprite || void 0 }));
|
|
2028
|
+
}
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
function ai(e) {
|
|
2032
|
+
e.on(I.CHAT_BROADCAST, (t) => {
|
|
2033
|
+
const n = Lt(t, t.server_seq);
|
|
2034
|
+
m.getState().appendChat(n), d("chat", "Message received", n);
|
|
2035
|
+
}), e.on(I.CHAT_HISTORY, (t) => {
|
|
2036
|
+
if (!t?.messages || !Array.isArray(t.messages)) return;
|
|
2037
|
+
const n = t.messages.map((o) => Lt(o));
|
|
2038
|
+
m.getState().setChat(n), d("chat", "History loaded", { count: n.length });
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
function si(e) {
|
|
2042
|
+
e.on(ye.STATE, (t) => {
|
|
2043
|
+
m.getState().applyPlaylistState({
|
|
2044
|
+
playlist: t?.playlist ?? null,
|
|
2045
|
+
activeIndex: t?.activeIndex ?? null,
|
|
2046
|
+
myVotes: t?.myVotes ?? {}
|
|
2047
|
+
}), d("playlist", "Playlist state received", { playlistId: t?.playlist?.id ?? null, activeIndex: t?.activeIndex, myVoteCount: Object.keys(t?.myVotes || {}).length });
|
|
2048
|
+
}), e.on(ye.VOTE_PROGRESS, (t) => {
|
|
2049
|
+
m.getState().setVoteProgress(t?.progress ?? []), d("playlist", "Vote progress", { progressCount: t?.progress?.length });
|
|
2050
|
+
}), e.on(ye.RESULTS, (t) => {
|
|
2051
|
+
m.getState().setPlaylistResults(t ?? null), d("playlist", "Results received", { playlistId: t?.playlist?.id, update: t?.update === !0 });
|
|
2052
|
+
}), e.on(ye.VOTES_CLEARED, (t) => {
|
|
2053
|
+
if (!t?.playlistId || !Array.isArray(t.mediaIds)) return;
|
|
2054
|
+
const n = Vo(
|
|
2055
|
+
{ id: t.playlistId, videos: t.mediaIds.map((i) => ({ mediaId: i })) },
|
|
2056
|
+
go()
|
|
2057
|
+
), o = m.getState();
|
|
2058
|
+
o.playlist?.id === t.playlistId && o.applyPlaylistState({ playlist: o.playlist, activeIndex: o.activePlaylistIndex, myVotes: {} }), d("playlist", "Votes cleared by leader", { playlistId: t.playlistId, removed: n });
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
function li(e) {
|
|
2062
|
+
e.on(dr.UPDATED, () => {
|
|
2063
|
+
d("tierlist", "Someone saved — refreshing the board"), Oo(!1);
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
function ci(e) {
|
|
2067
|
+
e.on(ur.STATE, (t) => {
|
|
2068
|
+
if (!t || typeof t.active != "boolean") return;
|
|
2069
|
+
const n = Array.isArray(t.ready) ? t.ready.filter((o) => typeof o == "string") : [];
|
|
2070
|
+
m.getState().setReadyCheckState({ active: t.active, ready: n }), d("ready-check", "State received", { active: t.active, readyCount: n.length });
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
function di(e) {
|
|
2074
|
+
e.on(tn.ACTIVE, (t) => {
|
|
2075
|
+
const n = typeof t?.gameId == "string" ? t.gameId : null;
|
|
2076
|
+
m.getState().setActiveGameId(n), t?.sessionWins && typeof t.sessionWins == "object" ? m.getState().setGameSessionWins(t.sessionWins) : n === null && m.getState().setGameSessionWins({}), typeof t?.botCount == "number" ? m.getState().setGameBotCount(t.botCount) : n === null && m.getState().setGameBotCount(0), d("game", "game_active", { gameId: n, sessionWins: t?.sessionWins, botCount: t?.botCount });
|
|
2077
|
+
});
|
|
2078
|
+
}
|
|
2079
|
+
function ui(e) {
|
|
2080
|
+
e.on(I.HEALTH_SNAPSHOT, (t) => {
|
|
2081
|
+
m.getState().setHealthSnapshot(t);
|
|
2082
|
+
}), e.on(I.BUFFER_STATUS, (t) => {
|
|
2083
|
+
m.getState().setBufferStatus(t);
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
function mi(e) {
|
|
2087
|
+
oi(e), ii(e), ai(e), ui(e), si(e), li(e), ci(e), di(e), e.on(I.ERROR, (t) => {
|
|
2088
|
+
const n = t?.code || "error/unknown";
|
|
2089
|
+
if (n === "conflict" && t?.message === "sprite_held_by_you") {
|
|
2090
|
+
pt = !0, d("socket", "sprite held by this account's other connection: keeping the server-assigned sprite");
|
|
2091
|
+
return;
|
|
2092
|
+
}
|
|
2093
|
+
if (n === "conflict" && t?.message === "sprite_taken") {
|
|
2094
|
+
if (Lo(x?.id)) {
|
|
2095
|
+
d("socket", "sprite_taken: stale, the server already has our sprite");
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
Qe = !0;
|
|
2099
|
+
let a;
|
|
2100
|
+
try {
|
|
2101
|
+
a = Do();
|
|
2102
|
+
} finally {
|
|
2103
|
+
Qe = !1;
|
|
2104
|
+
}
|
|
2105
|
+
a && e.emit(I.IDENTITY_UPDATE, a);
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
const i = {
|
|
2109
|
+
"control/forbidden": "You are not the leader.",
|
|
2110
|
+
"control/stale_seq": "Stale control sequence.",
|
|
2111
|
+
"control/seq_gap": "Control sequence gap detected.",
|
|
2112
|
+
"rate/limited": "Rate limited. Slow down.",
|
|
2113
|
+
"payload/too_large": "Payload too large.",
|
|
2114
|
+
"room/full": "Room is full.",
|
|
2115
|
+
"auth/invalid_key": "Invalid room key.",
|
|
2116
|
+
"auth/leader_occupied": "A leader is already connected to this room.",
|
|
2117
|
+
"auth/friend_required": "Sign in to join this room.",
|
|
2118
|
+
origin_block: "Origin not allowed.",
|
|
2119
|
+
conflict: "Character is already taken by another user.",
|
|
2120
|
+
"recap/no_media": "Load an episode first.",
|
|
2121
|
+
"recap/no_previous": "This is the first episode of the season — nothing to recap.",
|
|
2122
|
+
"recap/not_episode": "Recaps are only available for episodes.",
|
|
2123
|
+
"recap/not_found": "No recap available for the previous episode."
|
|
2124
|
+
}[n] || n;
|
|
2125
|
+
if (n.startsWith("recap/")) {
|
|
2126
|
+
d("socket", `recap unavailable: ${i}`, { code: n }), m.getState().pushToast("info", i);
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
2129
|
+
(n.startsWith("auth/") ? A : ue)("socket", `Server error: ${i}`, { code: n, raw: t }), m.getState().pushToast("error", i);
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
function pi(e, t) {
|
|
2133
|
+
ie().emit(I.CHAT_SEND, t?.length ? { text: e, images: t } : { text: e });
|
|
2134
|
+
}
|
|
2135
|
+
function fi() {
|
|
2136
|
+
$ || ($ = { ts: Date.now() }, ie().emit(I.TIME_PING, {}), B = setTimeout(() => {
|
|
2137
|
+
$ && (d("socket", "Time ping timed out after 10s, clearing inflight"), $ = null), B = null;
|
|
2138
|
+
}, 1e4));
|
|
2139
|
+
}
|
|
2140
|
+
function hi(e, t) {
|
|
2141
|
+
const n = {};
|
|
2142
|
+
e && (n.name = e), t && (n.sprite = t), !(!n.name && !n.sprite) && (d("socket", "Sending identity update", n), ie().emit(I.IDENTITY_UPDATE, n));
|
|
2143
|
+
}
|
|
2144
|
+
let xe = { name: "", sprite: "" };
|
|
2145
|
+
m.subscribe((e, t) => {
|
|
2146
|
+
if (e.name === t.name && e.sprite === t.sprite || Qe) return;
|
|
2147
|
+
const n = e.me.clientId;
|
|
2148
|
+
if (!n) return;
|
|
2149
|
+
const o = e.roster[n];
|
|
2150
|
+
if (!o) return;
|
|
2151
|
+
const i = !!e.name && !ne(e.name) && e.name !== xe.name && (ne(o.name || "") || o.name !== e.name), s = !!e.sprite && e.sprite !== xe.sprite && o.sprite !== e.sprite;
|
|
2152
|
+
if (!i && !s) return;
|
|
2153
|
+
const a = {};
|
|
2154
|
+
i && (a.name = e.name, xe.name = e.name), s && (a.sprite = e.sprite, xe.sprite = e.sprite), d("socket", "Identity reassert (store change)", a), x?.connected ? x.emit(I.IDENTITY_UPDATE, a) : ie().emit(I.IDENTITY_UPDATE, a);
|
|
2155
|
+
});
|
|
2156
|
+
function gi() {
|
|
2157
|
+
Ae && (clearInterval(Ae), Ae = null), B && (clearTimeout(B), B = null), $ = null, ee.unansweredSince = null, ee.lastTickAt = null;
|
|
2158
|
+
}
|
|
2159
|
+
function bi() {
|
|
2160
|
+
d("socket", "clearJoinState called", { hadPayload: z !== null, room_key: z?.room_key }), z = null, le = !1, Nn = null;
|
|
2161
|
+
}
|
|
2162
|
+
function jt() {
|
|
2163
|
+
d("socket", "leaveRoom called", { room_key: z?.room_key }), bi(), gi(), x && (x.disconnect(), x = null), m.setState({
|
|
2164
|
+
me: { clientId: null, nextClientSeq: 1 },
|
|
2165
|
+
roster: {},
|
|
2166
|
+
snapshot: { roomId: null, mediaId: null, playheadMs: 0, playing: !1, serverSeq: 0, leaderId: null },
|
|
2167
|
+
chat: [],
|
|
2168
|
+
playlist: null,
|
|
2169
|
+
activePlaylistIndex: null,
|
|
2170
|
+
myVotes: {},
|
|
2171
|
+
voteProgress: [],
|
|
2172
|
+
playlistResults: null,
|
|
2173
|
+
readiness: { mediaId: null, ready: !1, readyCount: 0, total: 0 },
|
|
2174
|
+
readyCheck: { active: !1, ready: [] },
|
|
2175
|
+
activeGameId: null,
|
|
2176
|
+
gameSessionWins: {}
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
function yi() {
|
|
2180
|
+
d("chat", "Emitting recap_request"), ie().emit("recap_request");
|
|
2181
|
+
}
|
|
2182
|
+
function vi(e) {
|
|
2183
|
+
return !(e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey);
|
|
2184
|
+
}
|
|
2185
|
+
function wi({ src: e, title: t, onClose: n }) {
|
|
2186
|
+
O(() => {
|
|
2187
|
+
const s = (a) => {
|
|
2188
|
+
a.key === "Escape" && (a.stopPropagation(), n());
|
|
2189
|
+
};
|
|
2190
|
+
return document.addEventListener("keydown", s, !0), () => document.removeEventListener("keydown", s, !0);
|
|
2191
|
+
}, [n]);
|
|
2192
|
+
const o = zr(), i = typeof document > "u" ? null : document.fullscreenElement ?? o ?? document.body;
|
|
2193
|
+
return i ? Yn(
|
|
2194
|
+
/* @__PURE__ */ b(
|
|
2195
|
+
"div",
|
|
2196
|
+
{
|
|
2197
|
+
className: "fixed inset-0 z-[10000] flex flex-col items-center justify-center bg-black/85 p-6",
|
|
2198
|
+
onClick: n,
|
|
2199
|
+
"data-testid": "chat-image-lightbox",
|
|
2200
|
+
role: "dialog",
|
|
2201
|
+
"aria-modal": "true",
|
|
2202
|
+
"aria-label": t || "Image",
|
|
2203
|
+
children: [
|
|
2204
|
+
/* @__PURE__ */ l(
|
|
2205
|
+
"img",
|
|
2206
|
+
{
|
|
2207
|
+
src: e,
|
|
2208
|
+
alt: t ?? "",
|
|
2209
|
+
onClick: (s) => s.stopPropagation(),
|
|
2210
|
+
className: "max-h-full max-w-full rounded object-contain shadow-2xl",
|
|
2211
|
+
"data-testid": "chat-image-lightbox-img"
|
|
2212
|
+
}
|
|
2213
|
+
),
|
|
2214
|
+
t && /* @__PURE__ */ l("p", { className: "mt-3 max-w-full truncate text-center text-sm text-white/80", children: t }),
|
|
2215
|
+
/* @__PURE__ */ l(
|
|
2216
|
+
"button",
|
|
2217
|
+
{
|
|
2218
|
+
type: "button",
|
|
2219
|
+
onClick: n,
|
|
2220
|
+
"aria-label": "Close image",
|
|
2221
|
+
className: "absolute right-4 top-4 rounded px-3 py-1 text-2xl leading-none text-white/70 hover:text-white focus:outline-none focus:ring-1 focus:ring-white/50",
|
|
2222
|
+
children: "×"
|
|
2223
|
+
}
|
|
2224
|
+
)
|
|
2225
|
+
]
|
|
2226
|
+
}
|
|
2227
|
+
),
|
|
2228
|
+
i
|
|
2229
|
+
) : null;
|
|
2230
|
+
}
|
|
2231
|
+
const Ke = 240, Si = 320;
|
|
2232
|
+
function _i({ image: e }) {
|
|
2233
|
+
const [t, n] = P(!1), o = Pe(e.key);
|
|
2234
|
+
if (!o) return null;
|
|
2235
|
+
const i = e.w > 0 && e.h > 0, s = i ? Math.min(1, Si / e.w, Ke / e.h) : 1;
|
|
2236
|
+
return /* @__PURE__ */ b(Ne, { children: [
|
|
2237
|
+
/* @__PURE__ */ l(
|
|
2238
|
+
"a",
|
|
2239
|
+
{
|
|
2240
|
+
href: o,
|
|
2241
|
+
target: "_blank",
|
|
2242
|
+
rel: "noreferrer noopener",
|
|
2243
|
+
className: "block max-w-full cursor-zoom-in",
|
|
2244
|
+
"data-testid": "chat-image",
|
|
2245
|
+
onClick: (a) => {
|
|
2246
|
+
vi(a) && (a.preventDefault(), n(!0));
|
|
2247
|
+
},
|
|
2248
|
+
children: /* @__PURE__ */ l(
|
|
2249
|
+
"img",
|
|
2250
|
+
{
|
|
2251
|
+
src: o,
|
|
2252
|
+
alt: e.title ?? "",
|
|
2253
|
+
loading: "lazy",
|
|
2254
|
+
decoding: "async",
|
|
2255
|
+
width: i ? Math.round(e.w * s) : void 0,
|
|
2256
|
+
height: i ? Math.round(e.h * s) : void 0,
|
|
2257
|
+
className: "rounded border border-border-light object-contain bg-bg-alt/30",
|
|
2258
|
+
style: i ? { aspectRatio: `${e.w} / ${e.h}`, maxWidth: "100%", maxHeight: Ke } : { maxWidth: "100%", maxHeight: Ke }
|
|
2259
|
+
}
|
|
2260
|
+
)
|
|
2261
|
+
}
|
|
2262
|
+
),
|
|
2263
|
+
t && /* @__PURE__ */ l(
|
|
2264
|
+
wi,
|
|
2265
|
+
{
|
|
2266
|
+
src: o,
|
|
2267
|
+
title: e.title,
|
|
2268
|
+
onClose: () => n(!1)
|
|
2269
|
+
}
|
|
2270
|
+
)
|
|
2271
|
+
] });
|
|
2272
|
+
}
|
|
2273
|
+
function xi({ images: e }) {
|
|
2274
|
+
return e?.length ? /* @__PURE__ */ l("div", { className: "flex flex-wrap gap-1 mt-1", "data-testid": "chat-images", children: e.map((t, n) => /* @__PURE__ */ l(_i, { image: t }, `${t.key}-${n}`)) }) : null;
|
|
2275
|
+
}
|
|
2276
|
+
function Ci(e, t) {
|
|
2277
|
+
return e.author && t.author ? e.author === t.author : !!t.clientId && e.clientId === t.clientId;
|
|
2278
|
+
}
|
|
2279
|
+
function qe(e) {
|
|
2280
|
+
return new Date(e).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
2281
|
+
}
|
|
2282
|
+
const ki = Bt.memo(function({ message: t }) {
|
|
2283
|
+
const n = m((a) => a.me.clientId), o = m((a) => a.me.clientId ? a.roster[a.me.clientId]?.author : void 0), i = Ci(t, { clientId: n, author: o });
|
|
2284
|
+
if (t.isSystem && t.systemType === "recap")
|
|
2285
|
+
return /* @__PURE__ */ l("div", { className: "px-2 py-1.5", children: /* @__PURE__ */ b("div", { className: "border-l-2 border-border-light pl-2.5 py-0.5", children: [
|
|
2286
|
+
/* @__PURE__ */ b("div", { className: "text-[10px] uppercase tracking-wide text-text-muted mb-0.5", children: [
|
|
2287
|
+
"Recap",
|
|
2288
|
+
/* @__PURE__ */ l("span", { className: "ml-1.5 normal-case tracking-normal opacity-60", children: qe(t.ts) })
|
|
2289
|
+
] }),
|
|
2290
|
+
/* @__PURE__ */ l("p", { className: "text-[13px] text-text-secondary leading-relaxed whitespace-pre-wrap break-words", children: t.text })
|
|
2291
|
+
] }) });
|
|
2292
|
+
if (t.isSystem)
|
|
2293
|
+
return /* @__PURE__ */ b("div", { className: "px-2 py-0.5 text-[11px] text-text-muted italic text-center leading-tight", children: [
|
|
2294
|
+
t.text,
|
|
2295
|
+
/* @__PURE__ */ l("span", { className: "ml-1 text-[10px] opacity-50", children: qe(t.ts) })
|
|
2296
|
+
] });
|
|
2297
|
+
const s = _n(t.sprite);
|
|
2298
|
+
return /* @__PURE__ */ b("div", { className: `flex items-start gap-2 px-2 py-1 hover:bg-bg-card/20 ${i ? "bg-bg-card/30" : ""}`, children: [
|
|
2299
|
+
fe(t.sprite) ? /* @__PURE__ */ l(
|
|
2300
|
+
"img",
|
|
2301
|
+
{
|
|
2302
|
+
src: He(t.sprite),
|
|
2303
|
+
alt: t.sprite,
|
|
2304
|
+
crossOrigin: "anonymous",
|
|
2305
|
+
className: "w-8 h-8 rounded-full object-cover flex-shrink-0"
|
|
2306
|
+
}
|
|
2307
|
+
) : /* @__PURE__ */ l("span", { className: "w-8 h-8 bg-bg-alt/50 rounded-full flex-shrink-0" }),
|
|
2308
|
+
/* @__PURE__ */ b("div", { className: "flex-1 min-w-0 -mt-0.5", children: [
|
|
2309
|
+
/* @__PURE__ */ l("span", { className: "font-medium text-[13px]", style: { color: s }, children: t.name }),
|
|
2310
|
+
/* @__PURE__ */ l("span", { className: "text-[10px] text-text-muted opacity-60 ml-1.5", children: qe(t.ts) }),
|
|
2311
|
+
t.text && /* @__PURE__ */ l("p", { className: "text-[13px] text-text break-words leading-snug m-0", children: t.text }),
|
|
2312
|
+
/* @__PURE__ */ l(xi, { images: t.images })
|
|
2313
|
+
] })
|
|
2314
|
+
] });
|
|
2315
|
+
});
|
|
2316
|
+
function Ii() {
|
|
2317
|
+
const e = m((i) => i.chat), t = J(null), n = J(!1), o = N(() => {
|
|
2318
|
+
const i = t.current;
|
|
2319
|
+
if (!i) return;
|
|
2320
|
+
const { scrollHeight: s, scrollTop: a, clientHeight: c } = i, f = s - a - c;
|
|
2321
|
+
n.current = f > 40;
|
|
2322
|
+
}, []);
|
|
2323
|
+
return O(() => {
|
|
2324
|
+
const i = t.current;
|
|
2325
|
+
i && !n.current && i.scrollTo({ top: i.scrollHeight, behavior: "smooth" });
|
|
2326
|
+
}, [e.length]), /* @__PURE__ */ l(
|
|
2327
|
+
"div",
|
|
2328
|
+
{
|
|
2329
|
+
ref: t,
|
|
2330
|
+
onScroll: o,
|
|
2331
|
+
className: "flex-1 overflow-y-auto overflow-x-hidden chat-messages",
|
|
2332
|
+
children: e.length === 0 ? /* @__PURE__ */ l("div", { className: "p-4 text-xs text-text-muted text-center", children: "No messages yet. Be the first to say something!" }) : /* @__PURE__ */ l(Ne, { children: e.map((i, s) => {
|
|
2333
|
+
const a = s > 0 ? e[s - 1] : null, c = a && i.ts - a.ts > 1440 * 60 * 1e3;
|
|
2334
|
+
return /* @__PURE__ */ b(Bt.Fragment, { children: [
|
|
2335
|
+
c && /* @__PURE__ */ b("div", { className: "flex items-center gap-2 px-4 py-2 my-1", children: [
|
|
2336
|
+
/* @__PURE__ */ l("div", { className: "flex-1 h-px bg-border" }),
|
|
2337
|
+
/* @__PURE__ */ l("span", { className: "text-[10px] text-text-muted whitespace-nowrap", children: new Date(i.ts).toLocaleDateString([], { weekday: "short", month: "short", day: "numeric" }) }),
|
|
2338
|
+
/* @__PURE__ */ l("div", { className: "flex-1 h-px bg-border" })
|
|
2339
|
+
] }),
|
|
2340
|
+
/* @__PURE__ */ l(ki, { message: i })
|
|
2341
|
+
] }, i.id);
|
|
2342
|
+
}) })
|
|
2343
|
+
}
|
|
2344
|
+
);
|
|
2345
|
+
}
|
|
2346
|
+
const ft = [
|
|
2347
|
+
{
|
|
2348
|
+
name: "recap",
|
|
2349
|
+
description: "Summarise the previous episode of what is loaded",
|
|
2350
|
+
usage: "/recap",
|
|
2351
|
+
scope: "room",
|
|
2352
|
+
requiresMedia: !0
|
|
2353
|
+
},
|
|
2354
|
+
{
|
|
2355
|
+
name: "tierlist",
|
|
2356
|
+
description: "Open the tierlist",
|
|
2357
|
+
usage: "/tierlist",
|
|
2358
|
+
scope: "local"
|
|
2359
|
+
},
|
|
2360
|
+
{
|
|
2361
|
+
name: "character",
|
|
2362
|
+
description: "Change your character",
|
|
2363
|
+
usage: "/character",
|
|
2364
|
+
scope: "local"
|
|
2365
|
+
},
|
|
2366
|
+
{
|
|
2367
|
+
name: "help",
|
|
2368
|
+
description: "List the available commands",
|
|
2369
|
+
usage: "/help",
|
|
2370
|
+
scope: "local"
|
|
2371
|
+
}
|
|
2372
|
+
], re = "/";
|
|
2373
|
+
function Ti(e) {
|
|
2374
|
+
if (!e.startsWith(re)) return null;
|
|
2375
|
+
const t = e.slice(re.length);
|
|
2376
|
+
return /\s/.test(t) ? null : t.toLowerCase();
|
|
2377
|
+
}
|
|
2378
|
+
function Ei(e, t = ft) {
|
|
2379
|
+
const n = e.toLowerCase();
|
|
2380
|
+
if (!n) return [...t].sort((i, s) => i.name.localeCompare(s.name));
|
|
2381
|
+
const o = [];
|
|
2382
|
+
for (const i of t) {
|
|
2383
|
+
const s = i.name.toLowerCase();
|
|
2384
|
+
s.startsWith(n) ? o.push({ cmd: i, rank: 0 }) : s.includes(n) && o.push({ cmd: i, rank: 1 });
|
|
2385
|
+
}
|
|
2386
|
+
return o.sort((i, s) => i.rank - s.rank || i.cmd.name.localeCompare(s.cmd.name)).map((i) => i.cmd);
|
|
2387
|
+
}
|
|
2388
|
+
function Ai(e) {
|
|
2389
|
+
return `${re}${e.name} `;
|
|
2390
|
+
}
|
|
2391
|
+
function Ve(e, t) {
|
|
2392
|
+
return t <= 0 ? 0 : (e % t + t) % t;
|
|
2393
|
+
}
|
|
2394
|
+
function Ni(e, t = ft) {
|
|
2395
|
+
const n = e.trim();
|
|
2396
|
+
if (!n) return null;
|
|
2397
|
+
if (!n.startsWith(re)) return { kind: "chat", text: n };
|
|
2398
|
+
const o = n.slice(re.length), i = o.search(/\s/), s = (i === -1 ? o : o.slice(0, i)).toLowerCase(), a = i === -1 ? "" : o.slice(i).trim(), c = t.find((f) => f.name.toLowerCase() === s);
|
|
2399
|
+
return c ? { kind: "command", command: c, args: a } : { kind: "chat", text: n };
|
|
2400
|
+
}
|
|
2401
|
+
function Pi(e, t) {
|
|
2402
|
+
return e.requiresMedia && !t.hasMedia ? `${re}${e.name} needs an episode loaded.` : null;
|
|
2403
|
+
}
|
|
2404
|
+
function Mi({
|
|
2405
|
+
commands: e,
|
|
2406
|
+
activeIndex: t,
|
|
2407
|
+
hasMedia: n,
|
|
2408
|
+
onPick: o,
|
|
2409
|
+
onHover: i,
|
|
2410
|
+
listboxId: s
|
|
2411
|
+
}) {
|
|
2412
|
+
return e.length === 0 ? null : /* @__PURE__ */ l(
|
|
2413
|
+
"ul",
|
|
2414
|
+
{
|
|
2415
|
+
id: s,
|
|
2416
|
+
role: "listbox",
|
|
2417
|
+
"aria-label": "Slash commands",
|
|
2418
|
+
className: `absolute bottom-full left-0 right-0 z-30 max-h-56 overflow-y-auto
|
|
2419
|
+
bg-bg-card border border-border-light rounded shadow-lg
|
|
2420
|
+
list-none m-0 p-0 py-1 mb-1`,
|
|
2421
|
+
children: e.map((a, c) => {
|
|
2422
|
+
const f = !!a.requiresMedia && !n, g = c === t;
|
|
2423
|
+
return /* @__PURE__ */ b(
|
|
2424
|
+
"li",
|
|
2425
|
+
{
|
|
2426
|
+
id: `${s}-opt-${a.name}`,
|
|
2427
|
+
role: "option",
|
|
2428
|
+
"aria-selected": g,
|
|
2429
|
+
"aria-disabled": f,
|
|
2430
|
+
onMouseDown: (p) => {
|
|
2431
|
+
p.preventDefault(), o(a);
|
|
2432
|
+
},
|
|
2433
|
+
onMouseEnter: () => i(c),
|
|
2434
|
+
className: `px-3 py-1.5 cursor-pointer flex items-baseline gap-2 ${g ? "bg-bg-alt" : ""} ${f ? "opacity-50" : ""}`,
|
|
2435
|
+
children: [
|
|
2436
|
+
/* @__PURE__ */ l("span", { className: "text-sm font-semibold text-text shrink-0", children: a.usage }),
|
|
2437
|
+
/* @__PURE__ */ l("span", { className: "text-xs text-text-secondary truncate", children: f ? "needs an episode loaded" : a.description })
|
|
2438
|
+
]
|
|
2439
|
+
},
|
|
2440
|
+
a.name
|
|
2441
|
+
);
|
|
2442
|
+
})
|
|
2443
|
+
}
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
function Oi({
|
|
2447
|
+
pending: e,
|
|
2448
|
+
uploading: t,
|
|
2449
|
+
onRemove: n
|
|
2450
|
+
}) {
|
|
2451
|
+
return e.length ? /* @__PURE__ */ l("div", { className: "flex flex-wrap gap-1.5 pb-1.5", "data-testid": "chat-attachment-strip", children: e.map((o) => /* @__PURE__ */ b("div", { className: "relative", children: [
|
|
2452
|
+
/* @__PURE__ */ l(
|
|
2453
|
+
"img",
|
|
2454
|
+
{
|
|
2455
|
+
src: o.previewUrl,
|
|
2456
|
+
alt: "",
|
|
2457
|
+
className: `h-14 w-14 rounded border border-border-light object-cover ${t ? "opacity-50" : ""}`
|
|
2458
|
+
}
|
|
2459
|
+
),
|
|
2460
|
+
/* @__PURE__ */ l(
|
|
2461
|
+
"button",
|
|
2462
|
+
{
|
|
2463
|
+
type: "button",
|
|
2464
|
+
onClick: () => n(o.id),
|
|
2465
|
+
disabled: t,
|
|
2466
|
+
"aria-label": "Remove attachment",
|
|
2467
|
+
className: "absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-bg-card border border-border-light text-[10px] text-text-secondary hover:bg-danger-bg hover:text-on-danger-bg disabled:opacity-50",
|
|
2468
|
+
children: "×"
|
|
2469
|
+
}
|
|
2470
|
+
)
|
|
2471
|
+
] }, o.id)) }) : null;
|
|
2472
|
+
}
|
|
2473
|
+
function Ri() {
|
|
2474
|
+
const [e, t] = P([]), [n, o] = P(!1), i = m((h) => h.pushToast), s = J(/* @__PURE__ */ new Set());
|
|
2475
|
+
O(() => () => {
|
|
2476
|
+
for (const h of s.current) URL.revokeObjectURL(h);
|
|
2477
|
+
s.current.clear();
|
|
2478
|
+
}, []);
|
|
2479
|
+
const a = N((h) => {
|
|
2480
|
+
Mr(h) && (URL.revokeObjectURL(h.previewUrl), s.current.delete(h.previewUrl));
|
|
2481
|
+
}, []), c = N(async (h) => {
|
|
2482
|
+
if (!h.length) return;
|
|
2483
|
+
const _ = [];
|
|
2484
|
+
for (const S of h) {
|
|
2485
|
+
const k = Rr(S);
|
|
2486
|
+
if (k) {
|
|
2487
|
+
i("error", k);
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
const { w: u, h: v } = await jr(S), E = URL.createObjectURL(S);
|
|
2491
|
+
s.current.add(E), _.push({
|
|
2492
|
+
kind: "file",
|
|
2493
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
2494
|
+
file: S,
|
|
2495
|
+
previewUrl: E,
|
|
2496
|
+
w: u,
|
|
2497
|
+
h: v
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
_.length && t((S) => {
|
|
2501
|
+
const k = Y - S.length;
|
|
2502
|
+
if (k <= 0) {
|
|
2503
|
+
i("info", `Up to ${Y} images per message`);
|
|
2504
|
+
for (const u of _) a(u);
|
|
2505
|
+
return S;
|
|
2506
|
+
}
|
|
2507
|
+
if (_.length > k) {
|
|
2508
|
+
i("info", `Up to ${Y} images per message`);
|
|
2509
|
+
for (const u of _.slice(k)) a(u);
|
|
2510
|
+
}
|
|
2511
|
+
return [...S, ..._.slice(0, k)];
|
|
2512
|
+
});
|
|
2513
|
+
}, [i, a]), f = N((h) => {
|
|
2514
|
+
const _ = Pe(h.key);
|
|
2515
|
+
_ && (t((S) => S.length >= Y ? (i("info", `Up to ${Y} images per message`), S) : [...S, {
|
|
2516
|
+
kind: "remote",
|
|
2517
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
2518
|
+
key: h.key,
|
|
2519
|
+
previewUrl: _,
|
|
2520
|
+
// The catalogue spells "unknown" as null; the wire schema spells it
|
|
2521
|
+
// as 0, and the renderer falls back to natural flow on that.
|
|
2522
|
+
w: h.width ?? 0,
|
|
2523
|
+
h: h.height ?? 0,
|
|
2524
|
+
title: h.title || void 0
|
|
2525
|
+
}]), je().catalogue(mn).recordUse(h.key));
|
|
2526
|
+
}, [i]), g = N((h) => {
|
|
2527
|
+
t((_) => {
|
|
2528
|
+
const S = _.find((k) => k.id === h);
|
|
2529
|
+
return S && a(S), _.filter((k) => k.id !== h);
|
|
2530
|
+
});
|
|
2531
|
+
}, [a]), p = N(() => {
|
|
2532
|
+
t((h) => {
|
|
2533
|
+
for (const _ of h) a(_);
|
|
2534
|
+
return [];
|
|
2535
|
+
});
|
|
2536
|
+
}, [a]), D = N((h) => {
|
|
2537
|
+
const _ = Dr(h.clipboardData);
|
|
2538
|
+
_.length && (h.preventDefault(), c(_));
|
|
2539
|
+
}, [c]), M = N((h) => {
|
|
2540
|
+
const _ = Lr(h.dataTransfer);
|
|
2541
|
+
_.length && (h.preventDefault(), c(_));
|
|
2542
|
+
}, [c]), T = N((h) => {
|
|
2543
|
+
h.dataTransfer?.types?.includes("Files") && h.preventDefault();
|
|
2544
|
+
}, []), C = N(async () => {
|
|
2545
|
+
if (!e.length) return [];
|
|
2546
|
+
o(!0);
|
|
2547
|
+
try {
|
|
2548
|
+
return await Fr(e);
|
|
2549
|
+
} catch (h) {
|
|
2550
|
+
return A("chat", "Image upload failed", Hr(h)), i("error", Or(h)), null;
|
|
2551
|
+
} finally {
|
|
2552
|
+
o(!1);
|
|
2553
|
+
}
|
|
2554
|
+
}, [e, i]);
|
|
2555
|
+
return {
|
|
2556
|
+
pending: e,
|
|
2557
|
+
uploading: n,
|
|
2558
|
+
addFiles: c,
|
|
2559
|
+
addMeme: f,
|
|
2560
|
+
remove: g,
|
|
2561
|
+
clear: p,
|
|
2562
|
+
uploadPending: C,
|
|
2563
|
+
onPaste: D,
|
|
2564
|
+
onDrop: M,
|
|
2565
|
+
onDragOver: T
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
const Ut = Yt, Di = Zn;
|
|
2569
|
+
function Li({ commands: e = ft }) {
|
|
2570
|
+
const [t, n] = P(""), [o, i] = P(!1), [s, a] = P({ q: null, i: 0 }), [c, f] = P(!1), g = J(null), p = On(), [D, M] = P(!1), [T, C] = P(!1), h = Ri(), _ = m((y) => y.snapshot.mediaId), S = m((y) => y.pushToast), k = m((y) => y.setTierlistOpen), u = m((y) => y.setCharacterModalOpen), v = !!_, E = Ti(t), U = Q(
|
|
2571
|
+
() => E === null ? [] : Ei(E, e),
|
|
2572
|
+
[E, e]
|
|
2573
|
+
), H = E !== null && !c && U.length > 0, w = s.q === E ? Ve(s.i, U.length) : 0, R = N(
|
|
2574
|
+
(y) => a({ q: E, i: y }),
|
|
2575
|
+
[E]
|
|
2576
|
+
), L = N((y, j) => {
|
|
2577
|
+
const ae = Pi(y, { hasMedia: v });
|
|
2578
|
+
if (ae) {
|
|
2579
|
+
S("info", ae);
|
|
2580
|
+
return;
|
|
2581
|
+
}
|
|
2582
|
+
switch (y.name) {
|
|
2583
|
+
case "help":
|
|
2584
|
+
S("info", e.map((Mn) => Mn.usage).join(" "));
|
|
2585
|
+
break;
|
|
2586
|
+
case "recap":
|
|
2587
|
+
yi();
|
|
2588
|
+
break;
|
|
2589
|
+
case "tierlist":
|
|
2590
|
+
Ro(), k(!0);
|
|
2591
|
+
break;
|
|
2592
|
+
case "character":
|
|
2593
|
+
u(!0);
|
|
2594
|
+
break;
|
|
2595
|
+
default:
|
|
2596
|
+
S("info", `${y.usage} is not implemented yet.`);
|
|
2597
|
+
}
|
|
2598
|
+
}, [v, S, e, k, u]), F = N((y) => {
|
|
2599
|
+
n(Ai(y)), f(!1), g.current?.focus();
|
|
2600
|
+
}, []), W = N(async (y) => {
|
|
2601
|
+
if (y.preventDefault(), o || h.uploading) return;
|
|
2602
|
+
const j = Ni(t, e);
|
|
2603
|
+
if (!j && !h.pending.length) return;
|
|
2604
|
+
if (j?.kind === "command" && h.pending.length) {
|
|
2605
|
+
S("info", "Send images on their own, not with a command.");
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
if (j?.kind === "command") {
|
|
2609
|
+
L(j.command, j.args), n(""), !document.hidden && document.hasFocus() && g.current?.focus();
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2612
|
+
const ae = await h.uploadPending();
|
|
2613
|
+
ae !== null && (pi(j?.text ?? "", ae), n(""), h.clear(), i(!0), setTimeout(() => i(!1), Di), !document.hidden && document.hasFocus() && g.current?.focus());
|
|
2614
|
+
}, [t, o, L, h, S, e]), Pn = N((y) => {
|
|
2615
|
+
if (y.key === "Escape" && H) {
|
|
2616
|
+
y.preventDefault(), f(!0);
|
|
2617
|
+
return;
|
|
2618
|
+
}
|
|
2619
|
+
if (H) {
|
|
2620
|
+
if (y.key === "ArrowDown")
|
|
2621
|
+
y.preventDefault(), R(Ve(w + 1, U.length));
|
|
2622
|
+
else if (y.key === "ArrowUp")
|
|
2623
|
+
y.preventDefault(), R(Ve(w - 1, U.length));
|
|
2624
|
+
else if (y.key === "Tab") {
|
|
2625
|
+
y.preventDefault();
|
|
2626
|
+
const j = U[w];
|
|
2627
|
+
j && F(j);
|
|
2628
|
+
} else if (y.key === "Enter") {
|
|
2629
|
+
y.preventDefault();
|
|
2630
|
+
const j = U[w];
|
|
2631
|
+
j && F(j);
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
}, [H, U, w, F, R]);
|
|
2635
|
+
O(() => {
|
|
2636
|
+
const y = () => {
|
|
2637
|
+
document.hidden || !document.hasFocus() || (g.current?.focus(), g.current?.scrollIntoView({ block: "nearest" }));
|
|
2638
|
+
};
|
|
2639
|
+
return window.addEventListener("watchparty:focus-chat-input", y), () => window.removeEventListener("watchparty:focus-chat-input", y);
|
|
2640
|
+
}, []);
|
|
2641
|
+
const be = Ut - t.length, ht = be <= 100, gt = H ? U[w] : void 0;
|
|
2642
|
+
return /* @__PURE__ */ b(
|
|
2643
|
+
"form",
|
|
2644
|
+
{
|
|
2645
|
+
onSubmit: (y) => {
|
|
2646
|
+
W(y);
|
|
2647
|
+
},
|
|
2648
|
+
onPaste: h.onPaste,
|
|
2649
|
+
onDrop: h.onDrop,
|
|
2650
|
+
onDragOver: h.onDragOver,
|
|
2651
|
+
className: "p-2 border-t border-border",
|
|
2652
|
+
children: [
|
|
2653
|
+
/* @__PURE__ */ l(Oi, { pending: h.pending, uploading: h.uploading, onRemove: h.remove }),
|
|
2654
|
+
/* @__PURE__ */ b("div", { className: "relative", children: [
|
|
2655
|
+
H && /* @__PURE__ */ l(
|
|
2656
|
+
Mi,
|
|
2657
|
+
{
|
|
2658
|
+
commands: U,
|
|
2659
|
+
activeIndex: w,
|
|
2660
|
+
hasMedia: v,
|
|
2661
|
+
onPick: F,
|
|
2662
|
+
onHover: R,
|
|
2663
|
+
listboxId: p
|
|
2664
|
+
}
|
|
2665
|
+
),
|
|
2666
|
+
/* @__PURE__ */ l(
|
|
2667
|
+
Kr,
|
|
2668
|
+
{
|
|
2669
|
+
open: D,
|
|
2670
|
+
onClose: () => M(!1),
|
|
2671
|
+
onPick: h.addMeme,
|
|
2672
|
+
onUnavailable: () => {
|
|
2673
|
+
C(!0), M(!1);
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
),
|
|
2677
|
+
/* @__PURE__ */ b("div", { className: "flex items-center gap-1.5", children: [
|
|
2678
|
+
/* @__PURE__ */ b("div", { className: "relative flex-1", children: [
|
|
2679
|
+
/* @__PURE__ */ l(
|
|
2680
|
+
"input",
|
|
2681
|
+
{
|
|
2682
|
+
ref: g,
|
|
2683
|
+
type: "text",
|
|
2684
|
+
value: t,
|
|
2685
|
+
onChange: (y) => {
|
|
2686
|
+
n(y.target.value), f(!1);
|
|
2687
|
+
},
|
|
2688
|
+
onKeyDown: Pn,
|
|
2689
|
+
maxLength: Ut,
|
|
2690
|
+
placeholder: "Send a message",
|
|
2691
|
+
role: "combobox",
|
|
2692
|
+
"aria-expanded": H,
|
|
2693
|
+
"aria-controls": H ? p : void 0,
|
|
2694
|
+
"aria-activedescendant": gt ? `${p}-opt-${gt.name}` : void 0,
|
|
2695
|
+
"aria-autocomplete": "list",
|
|
2696
|
+
className: `w-full bg-bg-card border border-border-light rounded px-3 py-1.5 text-sm focus:outline-none focus:border-text-muted ${ht ? "pr-12" : ""}`
|
|
2697
|
+
}
|
|
2698
|
+
),
|
|
2699
|
+
/* @__PURE__ */ l("span", { className: `absolute right-2 top-1/2 -translate-y-1/2 text-[10px] ${be <= 50 ? be <= 0 ? "bg-danger-bg text-on-danger-bg px-1 rounded" : "bg-primary-bg text-on-primary-bg px-1 rounded" : "text-text-muted"}`, children: ht && be })
|
|
2700
|
+
] }),
|
|
2701
|
+
!T && /* @__PURE__ */ l(
|
|
2702
|
+
"button",
|
|
2703
|
+
{
|
|
2704
|
+
type: "button",
|
|
2705
|
+
onClick: () => M((y) => !y),
|
|
2706
|
+
"aria-label": "Add a meme",
|
|
2707
|
+
"aria-expanded": D,
|
|
2708
|
+
title: "Add a meme",
|
|
2709
|
+
"data-testid": "meme-button",
|
|
2710
|
+
className: `shrink-0 rounded border border-border-light px-2 py-1.5 text-sm hover:border-primary ${D ? "text-text border-primary" : "text-text-secondary"}`,
|
|
2711
|
+
children: /* @__PURE__ */ l(Rn, { name: "image" })
|
|
2712
|
+
}
|
|
2713
|
+
)
|
|
2714
|
+
] })
|
|
2715
|
+
] })
|
|
2716
|
+
]
|
|
2717
|
+
}
|
|
2718
|
+
);
|
|
2719
|
+
}
|
|
2720
|
+
function ji() {
|
|
2721
|
+
const e = m((n) => n.roster), t = Object.values(e);
|
|
2722
|
+
return t.length ? /* @__PURE__ */ l("div", { className: "flex flex-col gap-1", children: t.map((n) => {
|
|
2723
|
+
const o = _n(n.sprite);
|
|
2724
|
+
return /* @__PURE__ */ b("div", { className: "flex items-center gap-2 py-0.5", children: [
|
|
2725
|
+
fe(n.sprite) ? /* @__PURE__ */ l(
|
|
2726
|
+
"img",
|
|
2727
|
+
{
|
|
2728
|
+
src: He(n.sprite),
|
|
2729
|
+
alt: n.sprite,
|
|
2730
|
+
crossOrigin: "anonymous",
|
|
2731
|
+
className: "w-6 h-6 rounded-full object-cover flex-shrink-0"
|
|
2732
|
+
}
|
|
2733
|
+
) : /* @__PURE__ */ l("span", { className: "w-6 h-6 bg-bg-alt rounded-full flex-shrink-0" }),
|
|
2734
|
+
/* @__PURE__ */ l("span", { className: "text-xs font-medium truncate", style: { color: o }, children: n.name || "Anon" }),
|
|
2735
|
+
n.isLeader && /* @__PURE__ */ l("span", { className: "ml-auto px-1.5 py-0.5 rounded text-[9px] font-medium bg-success/20 text-success", children: "Leader" })
|
|
2736
|
+
] }, n.clientId);
|
|
2737
|
+
}) }) : /* @__PURE__ */ l("div", { className: "text-xs text-text-muted", children: "No users online" });
|
|
2738
|
+
}
|
|
2739
|
+
function Ui() {
|
|
2740
|
+
const e = m((i) => Object.keys(i.roster).length), [t, n] = P(!1), o = J(null);
|
|
2741
|
+
return O(() => {
|
|
2742
|
+
if (!t) return;
|
|
2743
|
+
function i(s) {
|
|
2744
|
+
o.current && !o.current.contains(s.target) && n(!1);
|
|
2745
|
+
}
|
|
2746
|
+
return document.addEventListener("mousedown", i), () => document.removeEventListener("mousedown", i);
|
|
2747
|
+
}, [t]), /* @__PURE__ */ b("div", { className: "relative", ref: o, children: [
|
|
2748
|
+
/* @__PURE__ */ b(
|
|
2749
|
+
"button",
|
|
2750
|
+
{
|
|
2751
|
+
onClick: () => {
|
|
2752
|
+
d("chat", "User list toggled", { open: !t, userCount: e }), n(!t);
|
|
2753
|
+
},
|
|
2754
|
+
className: "p-1.5 rounded text-text-secondary hover:text-white hover:bg-bg-alt transition-colors flex items-center gap-1 cursor-pointer",
|
|
2755
|
+
title: "Users",
|
|
2756
|
+
children: [
|
|
2757
|
+
/* @__PURE__ */ l("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" }) }),
|
|
2758
|
+
/* @__PURE__ */ l("span", { className: "text-xs", children: e })
|
|
2759
|
+
]
|
|
2760
|
+
}
|
|
2761
|
+
),
|
|
2762
|
+
t && /* @__PURE__ */ b("div", { className: "absolute top-full right-0 mt-1 bg-bg-card rounded-lg shadow-xl p-3 max-h-64 overflow-y-auto z-50 w-max min-w-[180px] max-w-[220px]", children: [
|
|
2763
|
+
/* @__PURE__ */ b("div", { className: "text-[10px] uppercase tracking-wide text-text-muted mb-2", children: [
|
|
2764
|
+
e,
|
|
2765
|
+
" online"
|
|
2766
|
+
] }),
|
|
2767
|
+
/* @__PURE__ */ l(ji, {})
|
|
2768
|
+
] })
|
|
2769
|
+
] });
|
|
2770
|
+
}
|
|
2771
|
+
function Fi() {
|
|
2772
|
+
const e = m((n) => n.sprite), t = m((n) => n.setCharacterModalOpen);
|
|
2773
|
+
return /* @__PURE__ */ l(
|
|
2774
|
+
"button",
|
|
2775
|
+
{
|
|
2776
|
+
onClick: () => {
|
|
2777
|
+
d("chat", "Opening character modal", { currentSprite: e }), t(!0);
|
|
2778
|
+
},
|
|
2779
|
+
className: "p-1 rounded hover:bg-bg-alt transition-colors cursor-pointer",
|
|
2780
|
+
title: "Change character",
|
|
2781
|
+
children: fe(e) ? /* @__PURE__ */ l(
|
|
2782
|
+
"img",
|
|
2783
|
+
{
|
|
2784
|
+
src: He(e),
|
|
2785
|
+
alt: e,
|
|
2786
|
+
crossOrigin: "anonymous",
|
|
2787
|
+
className: "w-6 h-6 rounded object-cover",
|
|
2788
|
+
fetchPriority: "high"
|
|
2789
|
+
}
|
|
2790
|
+
) : /* @__PURE__ */ l("div", { className: "w-6 h-6 rounded bg-bg-alt flex items-center justify-center", children: /* @__PURE__ */ l("svg", { className: "w-4 h-4 text-text-secondary", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" }) }) })
|
|
2791
|
+
}
|
|
2792
|
+
);
|
|
2793
|
+
}
|
|
2794
|
+
const se = bo();
|
|
2795
|
+
function Hi({ open: e, onClose: t, roomKey: n, tierlist: o }) {
|
|
2796
|
+
const i = Vr(), { name: s, sprite: a, setIdentity: c } = m(), f = m((u) => !!(u.me.clientId && u.roster[u.me.clientId]?.registryName)), [g, p] = P(a), [D, M] = P(/* @__PURE__ */ new Set()), [T, C] = P(() => xt(se, a));
|
|
2797
|
+
O(() => {
|
|
2798
|
+
e && (p(a), C(xt(se, a)));
|
|
2799
|
+
}, [e, a]), O(() => {
|
|
2800
|
+
if (!e || !n) return;
|
|
2801
|
+
const u = `${fn(i)}/api/rooms/${encodeURIComponent(n)}/sprites`;
|
|
2802
|
+
fetch(u).then((v) => v.ok ? v.json() : (A("character", "sprites fetch non-OK", { status: v.status }), Promise.reject(new Error(`status ${v.status}`)))).then((v) => M(new Set(v.used ?? []))).catch((v) => {
|
|
2803
|
+
ue("character", "sprites fetch failed", ge(v)), M(/* @__PURE__ */ new Set());
|
|
2804
|
+
});
|
|
2805
|
+
}, [e, n]);
|
|
2806
|
+
const h = () => {
|
|
2807
|
+
const u = f || !g ? s : te(g);
|
|
2808
|
+
d("character", "Updating identity", { name: u, sprite: g }), c(u, g), hi(u, g || void 0), t();
|
|
2809
|
+
}, _ = (u) => u === a ? !0 : !D.has(u), S = (u) => {
|
|
2810
|
+
u.target === u.currentTarget && t();
|
|
2811
|
+
};
|
|
2812
|
+
O(() => {
|
|
2813
|
+
if (!e) return;
|
|
2814
|
+
const u = (v) => {
|
|
2815
|
+
v.key === "Escape" ? t() : v.key === "ArrowLeft" ? C((E) => Math.max(0, E - 1)) : v.key === "ArrowRight" && C((E) => Math.min(se.length - 1, E + 1));
|
|
2816
|
+
};
|
|
2817
|
+
return window.addEventListener("keydown", u), () => window.removeEventListener("keydown", u);
|
|
2818
|
+
}, [e, t]);
|
|
2819
|
+
const k = g !== a;
|
|
2820
|
+
return e ? /* @__PURE__ */ l(
|
|
2821
|
+
"div",
|
|
2822
|
+
{
|
|
2823
|
+
className: "fixed inset-0 bg-black/70 flex items-center justify-center z-50",
|
|
2824
|
+
onMouseDown: S,
|
|
2825
|
+
role: "dialog",
|
|
2826
|
+
"aria-modal": "true",
|
|
2827
|
+
"aria-label": "Change character",
|
|
2828
|
+
style: { willChange: "opacity" },
|
|
2829
|
+
children: /* @__PURE__ */ b("div", { className: "bg-bg border border-border rounded-lg shadow-xl w-[340px] mx-4 overflow-hidden", children: [
|
|
2830
|
+
/* @__PURE__ */ b("div", { className: "p-4 space-y-4 text-sm", children: [
|
|
2831
|
+
/* @__PURE__ */ b("div", { children: [
|
|
2832
|
+
/* @__PURE__ */ b("div", { className: "flex items-center justify-between mb-1", children: [
|
|
2833
|
+
/* @__PURE__ */ l("label", { className: "text-xs uppercase tracking-wide opacity-70", children: f ? "Display Name" : "Character" }),
|
|
2834
|
+
/* @__PURE__ */ l(
|
|
2835
|
+
"button",
|
|
2836
|
+
{
|
|
2837
|
+
type: "button",
|
|
2838
|
+
onClick: t,
|
|
2839
|
+
className: "text-text-secondary hover:text-white hover:bg-bg-alt rounded p-1 transition-colors cursor-pointer",
|
|
2840
|
+
"aria-label": "Close",
|
|
2841
|
+
children: /* @__PURE__ */ l("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
2842
|
+
}
|
|
2843
|
+
)
|
|
2844
|
+
] }),
|
|
2845
|
+
f && /* @__PURE__ */ l("div", { className: "modal-input", "aria-readonly": "true", children: s })
|
|
2846
|
+
] }),
|
|
2847
|
+
/* @__PURE__ */ b("div", { children: [
|
|
2848
|
+
f && /* @__PURE__ */ l("label", { className: "block text-xs uppercase tracking-wide mb-2 opacity-70", children: "Character" }),
|
|
2849
|
+
/* @__PURE__ */ b("div", { className: "h-[152px] flex items-center gap-1", children: [
|
|
2850
|
+
/* @__PURE__ */ l(Ft, { direction: "prev", hidden: T === 0, onClick: () => C(T - 1) }),
|
|
2851
|
+
/* @__PURE__ */ l("div", { className: "grid grid-cols-4 gap-2 h-full flex-1 content-start", children: (se[T] ?? []).map((u) => {
|
|
2852
|
+
const v = _(u);
|
|
2853
|
+
return /* @__PURE__ */ b(
|
|
2854
|
+
"button",
|
|
2855
|
+
{
|
|
2856
|
+
onClick: () => {
|
|
2857
|
+
if (!v) {
|
|
2858
|
+
d("character", "Sprite unavailable", { sprite: u });
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
d("character", "Sprite selected", { sprite: u }), p(u);
|
|
2862
|
+
},
|
|
2863
|
+
disabled: !v,
|
|
2864
|
+
className: `relative group rounded-lg p-1 flex flex-col items-center gap-1 transition-all ${g === u ? "ring-2 ring-success ring-offset-2 ring-offset-bg bg-bg-card cursor-pointer" : v ? "hover:bg-bg-card border border-transparent hover:border-border-light cursor-pointer" : "opacity-40 cursor-not-allowed"}`,
|
|
2865
|
+
children: [
|
|
2866
|
+
/* @__PURE__ */ l(
|
|
2867
|
+
"img",
|
|
2868
|
+
{
|
|
2869
|
+
src: He(u),
|
|
2870
|
+
alt: u,
|
|
2871
|
+
crossOrigin: "anonymous",
|
|
2872
|
+
className: `w-12 h-12 object-cover rounded ${v ? "" : "grayscale"}`
|
|
2873
|
+
}
|
|
2874
|
+
),
|
|
2875
|
+
/* @__PURE__ */ l("span", { className: "text-[10px] opacity-70 group-hover:opacity-100 whitespace-nowrap", children: te(u) }),
|
|
2876
|
+
!v && /* @__PURE__ */ l("span", { className: "absolute inset-0 flex items-center justify-center bg-bg/60 rounded", children: /* @__PURE__ */ l("span", { className: "text-[8px] font-medium bg-danger-bg text-on-danger-bg px-1 rounded", children: "In Use" }) })
|
|
2877
|
+
]
|
|
2878
|
+
},
|
|
2879
|
+
u
|
|
2880
|
+
);
|
|
2881
|
+
}) }),
|
|
2882
|
+
/* @__PURE__ */ l(Ft, { direction: "next", hidden: T >= se.length - 1, onClick: () => C(T + 1) })
|
|
2883
|
+
] })
|
|
2884
|
+
] })
|
|
2885
|
+
] }),
|
|
2886
|
+
/* @__PURE__ */ b("div", { className: "px-4 pb-4 flex justify-end gap-2", children: [
|
|
2887
|
+
o && /* @__PURE__ */ b(
|
|
2888
|
+
"button",
|
|
2889
|
+
{
|
|
2890
|
+
type: "button",
|
|
2891
|
+
onClick: o.open,
|
|
2892
|
+
onMouseEnter: o.warm,
|
|
2893
|
+
onFocus: o.warm,
|
|
2894
|
+
className: "modal-btn-cancel mr-auto inline-flex items-center gap-1",
|
|
2895
|
+
"aria-label": "Tierlist",
|
|
2896
|
+
children: [
|
|
2897
|
+
/* @__PURE__ */ l("svg", { className: "w-3.5 h-3.5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 6h16M4 12h11M4 18h6" }) }),
|
|
2898
|
+
"Tierlist"
|
|
2899
|
+
]
|
|
2900
|
+
}
|
|
2901
|
+
),
|
|
2902
|
+
/* @__PURE__ */ l(
|
|
2903
|
+
"button",
|
|
2904
|
+
{
|
|
2905
|
+
onClick: t,
|
|
2906
|
+
className: "modal-btn-cancel",
|
|
2907
|
+
children: "Cancel"
|
|
2908
|
+
}
|
|
2909
|
+
),
|
|
2910
|
+
/* @__PURE__ */ l(
|
|
2911
|
+
"button",
|
|
2912
|
+
{
|
|
2913
|
+
onClick: h,
|
|
2914
|
+
disabled: !k,
|
|
2915
|
+
className: "modal-btn-update",
|
|
2916
|
+
style: k ? void 0 : {
|
|
2917
|
+
opacity: 0.4,
|
|
2918
|
+
cursor: "not-allowed",
|
|
2919
|
+
filter: "grayscale(50%)"
|
|
2920
|
+
},
|
|
2921
|
+
children: "Update"
|
|
2922
|
+
}
|
|
2923
|
+
)
|
|
2924
|
+
] })
|
|
2925
|
+
] })
|
|
2926
|
+
}
|
|
2927
|
+
) : null;
|
|
2928
|
+
}
|
|
2929
|
+
function Ft({ direction: e, hidden: t, onClick: n }) {
|
|
2930
|
+
return /* @__PURE__ */ l(
|
|
2931
|
+
"button",
|
|
2932
|
+
{
|
|
2933
|
+
type: "button",
|
|
2934
|
+
onClick: n,
|
|
2935
|
+
className: "char-page-btn",
|
|
2936
|
+
"data-hidden": t ? "1" : void 0,
|
|
2937
|
+
disabled: t,
|
|
2938
|
+
"aria-hidden": t,
|
|
2939
|
+
tabIndex: t ? -1 : void 0,
|
|
2940
|
+
"aria-label": e === "prev" ? "Previous characters" : "Next characters",
|
|
2941
|
+
children: /* @__PURE__ */ l("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: e === "prev" ? "M15 19l-7-7 7-7" : "M9 5l7 7-7 7" }) })
|
|
2942
|
+
}
|
|
2943
|
+
);
|
|
2944
|
+
}
|
|
2945
|
+
function Ht({ className: e = "fixed bottom-4 left-1/2 -translate-x-1/2" }) {
|
|
2946
|
+
const t = m((o) => o.toasts), n = m((o) => o.popToast);
|
|
2947
|
+
return O(() => {
|
|
2948
|
+
const o = t.map((i) => setTimeout(() => n(i.id), 4e3));
|
|
2949
|
+
return () => {
|
|
2950
|
+
o.forEach(clearTimeout);
|
|
2951
|
+
};
|
|
2952
|
+
}, [t, n]), /* @__PURE__ */ l("div", { className: `${e} flex flex-col gap-2 z-50`, children: t.map((o) => /* @__PURE__ */ l("div", { className: `px-3 py-2 rounded text-sm shadow font-medium border ${o.kind === "error" ? "bg-danger-bg text-on-danger-bg border-danger" : "bg-bg-card border-border-light text-text"}`, children: o.msg }, o.id)) });
|
|
2953
|
+
}
|
|
2954
|
+
const $t = (e) => typeof e == "string" && Dn.includes(e);
|
|
2955
|
+
function $i(e, t, n) {
|
|
2956
|
+
return e || ($t(t) ? t : $t(n) ? n : "dark");
|
|
2957
|
+
}
|
|
2958
|
+
function Bi(e, t) {
|
|
2959
|
+
if (t(e.clientWidth), typeof ResizeObserver > "u") return () => {
|
|
2960
|
+
};
|
|
2961
|
+
const n = new ResizeObserver(() => t(e.clientWidth));
|
|
2962
|
+
return n.observe(e), () => n.disconnect();
|
|
2963
|
+
}
|
|
2964
|
+
function Gi(e) {
|
|
2965
|
+
const t = e?.trim() ?? "";
|
|
2966
|
+
return t ? { source: "host", name: t } : { source: "auto" };
|
|
2967
|
+
}
|
|
2968
|
+
function Wi(e) {
|
|
2969
|
+
if (e.source !== "host") return;
|
|
2970
|
+
const { setSessionIdentity: t, sprite: n } = m.getState();
|
|
2971
|
+
t(e.name, n);
|
|
2972
|
+
}
|
|
2973
|
+
function Ki({ className: e = "w-4 h-4" }) {
|
|
2974
|
+
return /* @__PURE__ */ b("svg", { className: e, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, children: [
|
|
2975
|
+
/* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M4 4v16" }),
|
|
2976
|
+
/* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M15 12l-5 4v-8l5 4z" })
|
|
2977
|
+
] });
|
|
2978
|
+
}
|
|
2979
|
+
function qi({ className: e = "w-4 h-4" }) {
|
|
2980
|
+
return /* @__PURE__ */ b("svg", { className: e, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, children: [
|
|
2981
|
+
/* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M20 4v16" }),
|
|
2982
|
+
/* @__PURE__ */ l("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M9 12l5 4v-8l-5 4z" })
|
|
2983
|
+
] });
|
|
2984
|
+
}
|
|
2985
|
+
const Vi = 1500;
|
|
2986
|
+
function aa({
|
|
2987
|
+
roomKey: e,
|
|
2988
|
+
serverOrigin: t,
|
|
2989
|
+
userType: n,
|
|
2990
|
+
userId: o,
|
|
2991
|
+
theme: i,
|
|
2992
|
+
name: s,
|
|
2993
|
+
onLeave: a,
|
|
2994
|
+
onLayoutChange: c,
|
|
2995
|
+
collapsible: f = !0,
|
|
2996
|
+
debug: g,
|
|
2997
|
+
children: p
|
|
2998
|
+
}) {
|
|
2999
|
+
const [D, M] = P(null), { setFrame: T, ...C } = zi(c, f), h = m((w) => w.characterModalOpen), _ = m((w) => w.setCharacterModalOpen), S = Kt(() => s), k = Q(() => (ho({ userType: n, userId: o ?? null }), dt().theme), [n, o]), u = Ln(), v = u?.theme, E = Q(
|
|
3000
|
+
() => $i(i, v, k),
|
|
3001
|
+
[i, v, k]
|
|
3002
|
+
);
|
|
3003
|
+
O(() => {
|
|
3004
|
+
}, [i, u !== null]);
|
|
3005
|
+
const H = Q(
|
|
3006
|
+
() => ({ ...it, serverOrigin: t, defaultRoomKey: e }),
|
|
3007
|
+
[t, e]
|
|
3008
|
+
);
|
|
3009
|
+
return O(() => {
|
|
3010
|
+
g && Jr();
|
|
3011
|
+
}, [g]), O(() => {
|
|
3012
|
+
qr({ serverOrigin: t, defaultRoomKey: e }), m.getState().rehydrateFromPrefs(), Ko();
|
|
3013
|
+
let w = !1;
|
|
3014
|
+
const R = yo();
|
|
3015
|
+
return (async () => {
|
|
3016
|
+
try {
|
|
3017
|
+
await Promise.race([
|
|
3018
|
+
Promise.all([
|
|
3019
|
+
R,
|
|
3020
|
+
Co().then((W) => {
|
|
3021
|
+
W && m.getState().rehydrateFromPrefs();
|
|
3022
|
+
})
|
|
3023
|
+
]),
|
|
3024
|
+
new Promise((W) => setTimeout(W, Vi))
|
|
3025
|
+
]);
|
|
3026
|
+
} catch (W) {
|
|
3027
|
+
A("room-chrome", "pre-join wait threw, proceeding anyway", ge(W));
|
|
3028
|
+
}
|
|
3029
|
+
if (w) return;
|
|
3030
|
+
const L = Gi(S());
|
|
3031
|
+
m.getState().ensureAutoIdentity(), Wi(L);
|
|
3032
|
+
const F = m.getState();
|
|
3033
|
+
d("room-chrome", "Joining room", { roomKey: e, name: F.name, sprite: F.sprite }), ti({ room_key: e, name: F.name || void 0, sprite: F.sprite || void 0 });
|
|
3034
|
+
})(), () => {
|
|
3035
|
+
w = !0, jt();
|
|
3036
|
+
};
|
|
3037
|
+
}, [e, t, n, o]), /* @__PURE__ */ l(pn.Provider, { value: H, children: /* @__PURE__ */ l(gn.Provider, { value: D, children: /* @__PURE__ */ b("div", { ref: T, className: "wp-room-chrome-frame", children: [
|
|
3038
|
+
/* @__PURE__ */ l("div", { className: "wp-room-chrome-frame__content", children: p }),
|
|
3039
|
+
/* @__PURE__ */ b(
|
|
3040
|
+
"aside",
|
|
3041
|
+
{
|
|
3042
|
+
ref: M,
|
|
3043
|
+
className: "wp-room-chrome",
|
|
3044
|
+
"data-theme": E,
|
|
3045
|
+
"data-collapsed": C.collapsed ? "1" : "0",
|
|
3046
|
+
style: { "--wp-room-chrome-width": `${C.state.width}px` },
|
|
3047
|
+
children: [
|
|
3048
|
+
C.collapsed ? /* @__PURE__ */ b(Ne, { children: [
|
|
3049
|
+
/* @__PURE__ */ l(
|
|
3050
|
+
"button",
|
|
3051
|
+
{
|
|
3052
|
+
onClick: C.toggleCollapsed,
|
|
3053
|
+
className: "wp-room-chrome__icon-btn",
|
|
3054
|
+
title: "Show chat",
|
|
3055
|
+
"aria-label": "Show chat",
|
|
3056
|
+
"aria-expanded": !1,
|
|
3057
|
+
children: /* @__PURE__ */ l(qi, {})
|
|
3058
|
+
}
|
|
3059
|
+
),
|
|
3060
|
+
/* @__PURE__ */ l(Ht, { className: "absolute bottom-2 right-full mr-2 w-72" })
|
|
3061
|
+
] }) : /* @__PURE__ */ b(Ne, { children: [
|
|
3062
|
+
/* @__PURE__ */ l(
|
|
3063
|
+
"div",
|
|
3064
|
+
{
|
|
3065
|
+
role: "separator",
|
|
3066
|
+
"aria-orientation": "vertical",
|
|
3067
|
+
"aria-label": "Resize chat",
|
|
3068
|
+
"aria-valuemin": De,
|
|
3069
|
+
"aria-valuemax": ut,
|
|
3070
|
+
"aria-valuenow": C.state.width,
|
|
3071
|
+
tabIndex: 0,
|
|
3072
|
+
className: "wp-room-chrome__resize",
|
|
3073
|
+
"data-dragging": C.dragging ? "1" : "0",
|
|
3074
|
+
onPointerDown: C.onPointerDown,
|
|
3075
|
+
onPointerMove: C.onPointerMove,
|
|
3076
|
+
onPointerUp: C.onPointerEnd,
|
|
3077
|
+
onPointerCancel: C.onPointerEnd,
|
|
3078
|
+
onKeyDown: C.onKeyDown
|
|
3079
|
+
}
|
|
3080
|
+
),
|
|
3081
|
+
/* @__PURE__ */ b("div", { className: "flex items-center gap-1 px-2 py-1.5 border-b border-border", children: [
|
|
3082
|
+
/* @__PURE__ */ l(Ui, {}),
|
|
3083
|
+
/* @__PURE__ */ l(Fi, {}),
|
|
3084
|
+
/* @__PURE__ */ l("div", { className: "flex-1" }),
|
|
3085
|
+
a && /* @__PURE__ */ l(
|
|
3086
|
+
"button",
|
|
3087
|
+
{
|
|
3088
|
+
onClick: () => {
|
|
3089
|
+
jt(), a();
|
|
3090
|
+
},
|
|
3091
|
+
className: "wp-room-chrome__leave",
|
|
3092
|
+
title: "Leave room",
|
|
3093
|
+
"aria-label": "Leave room",
|
|
3094
|
+
children: "Leave"
|
|
3095
|
+
}
|
|
3096
|
+
),
|
|
3097
|
+
f && /* @__PURE__ */ l(
|
|
3098
|
+
"button",
|
|
3099
|
+
{
|
|
3100
|
+
onClick: C.toggleCollapsed,
|
|
3101
|
+
className: "wp-room-chrome__icon-btn",
|
|
3102
|
+
title: "Hide chat",
|
|
3103
|
+
"aria-label": "Hide chat",
|
|
3104
|
+
"aria-expanded": !0,
|
|
3105
|
+
children: /* @__PURE__ */ l(Ki, {})
|
|
3106
|
+
}
|
|
3107
|
+
)
|
|
3108
|
+
] }),
|
|
3109
|
+
/* @__PURE__ */ l(Ii, {}),
|
|
3110
|
+
/* @__PURE__ */ l(Li, { commands: [] }),
|
|
3111
|
+
/* @__PURE__ */ l(Ht, { className: "absolute bottom-14 left-2 right-2" })
|
|
3112
|
+
] }),
|
|
3113
|
+
h && /* @__PURE__ */ l(Hi, { open: !0, onClose: () => _(!1), roomKey: e })
|
|
3114
|
+
]
|
|
3115
|
+
}
|
|
3116
|
+
)
|
|
3117
|
+
] }) }) });
|
|
3118
|
+
}
|
|
3119
|
+
function zi(e, t) {
|
|
3120
|
+
const n = m((u) => u.chromeChatCollapsed) && t, o = m((u) => u.chromeChatWidth), i = m((u) => u.toggleChromeChatCollapsed), s = m((u) => u.setChromeChatWidth), [a, c] = P(null), [f, g] = P(void 0), [p, D] = P(null);
|
|
3121
|
+
O(() => {
|
|
3122
|
+
if (a)
|
|
3123
|
+
return Bi(a, g);
|
|
3124
|
+
}, [a]);
|
|
3125
|
+
const M = V(p?.current ?? o, f), T = Q(() => Ao(n, M), [n, M]), C = Kt((u) => e?.(u));
|
|
3126
|
+
return O(() => {
|
|
3127
|
+
C(T);
|
|
3128
|
+
}, [T]), {
|
|
3129
|
+
setFrame: c,
|
|
3130
|
+
collapsed: n,
|
|
3131
|
+
state: T,
|
|
3132
|
+
dragging: p !== null,
|
|
3133
|
+
toggleCollapsed: i,
|
|
3134
|
+
onPointerDown: (u) => {
|
|
3135
|
+
u.button === 0 && (u.preventDefault(), u.currentTarget.setPointerCapture(u.pointerId), D({ pointerId: u.pointerId, startX: u.clientX, startWidth: M, current: M }));
|
|
3136
|
+
},
|
|
3137
|
+
onPointerMove: (u) => {
|
|
3138
|
+
!p || p.pointerId !== u.pointerId || D({ ...p, current: Mt(p.startWidth, p.startX, u.clientX, f) });
|
|
3139
|
+
},
|
|
3140
|
+
onPointerEnd: (u) => {
|
|
3141
|
+
if (!p || p.pointerId !== u.pointerId) return;
|
|
3142
|
+
const v = Mt(p.startWidth, p.startX, u.clientX, f);
|
|
3143
|
+
D(null), v !== o && s(v);
|
|
3144
|
+
},
|
|
3145
|
+
onKeyDown: (u) => {
|
|
3146
|
+
const v = Eo(M, u.key, f);
|
|
3147
|
+
v !== null && (u.preventDefault(), v !== o && s(v));
|
|
3148
|
+
}
|
|
3149
|
+
};
|
|
3150
|
+
}
|
|
3151
|
+
export {
|
|
3152
|
+
aa as RoomChrome
|
|
3153
|
+
};
|
|
3154
|
+
//# sourceMappingURL=room-chrome.js.map
|