@celljs/ta-rooms 0.0.0-stage → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web/index.js ADDED
@@ -0,0 +1,1932 @@
1
+ // ../ta-relay/esm/common/relay-bytes.js
2
+ var RelayBytes;
3
+ (function(RelayBytes2) {
4
+ function random(length) {
5
+ return globalThis.crypto.getRandomValues(new Uint8Array(length));
6
+ }
7
+ RelayBytes2.random = random;
8
+ function toBase64(bytes) {
9
+ let binary = "";
10
+ for (const byte of bytes) {
11
+ binary += String.fromCharCode(byte);
12
+ }
13
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
14
+ }
15
+ RelayBytes2.toBase64 = toBase64;
16
+ function fromBase64(text) {
17
+ if (!/^[A-Za-z0-9_-]*$/.test(text)) {
18
+ throw new Error("Not base64url.");
19
+ }
20
+ const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
21
+ const bytes = new Uint8Array(binary.length);
22
+ for (let i = 0;i < binary.length; i++) {
23
+ bytes[i] = binary.charCodeAt(i);
24
+ }
25
+ return bytes;
26
+ }
27
+ RelayBytes2.fromBase64 = fromBase64;
28
+ function concat(...parts) {
29
+ const bytes = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
30
+ let offset = 0;
31
+ for (const part of parts) {
32
+ bytes.set(part, offset);
33
+ offset += part.length;
34
+ }
35
+ return bytes;
36
+ }
37
+ RelayBytes2.concat = concat;
38
+ })(RelayBytes || (RelayBytes = {}));
39
+
40
+ // ../ta-relay/esm/common/relay-identity.js
41
+ var encoder = new TextEncoder;
42
+ var decoder = new TextDecoder;
43
+ var subtle = () => globalThis.crypto.subtle;
44
+ var SIGN = { name: "ECDSA", namedCurve: "P-256" };
45
+ var BOX = { name: "ECDH", namedCurve: "P-256" };
46
+ var SIGNATURE = { name: "ECDSA", hash: "SHA-256" };
47
+ var RelayKeys;
48
+ (function(RelayKeys2) {
49
+ async function hkdf(key, salt, info) {
50
+ const secret = await subtle().importKey("raw", key, "HKDF", false, ["deriveBits"]);
51
+ const bits = await subtle().deriveBits({ name: "HKDF", hash: "SHA-256", salt, info: encoder.encode(info) }, secret, 256);
52
+ return new Uint8Array(bits);
53
+ }
54
+ RelayKeys2.hkdf = hkdf;
55
+ async function sha256(bytes) {
56
+ const data = typeof bytes === "string" ? encoder.encode(bytes) : bytes;
57
+ return new Uint8Array(await subtle().digest("SHA-256", data));
58
+ }
59
+ RelayKeys2.sha256 = sha256;
60
+ async function hash(text) {
61
+ return RelayBytes.toBase64(await sha256(text));
62
+ }
63
+ RelayKeys2.hash = hash;
64
+ async function hmac(key, text) {
65
+ const imported = await subtle().importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
66
+ return RelayBytes.toBase64(new Uint8Array(await subtle().sign("HMAC", imported, encoder.encode(text))));
67
+ }
68
+ RelayKeys2.hmac = hmac;
69
+ function aesKey(key) {
70
+ return subtle().importKey("raw", key, "AES-GCM", false, ["encrypt", "decrypt"]);
71
+ }
72
+ RelayKeys2.aesKey = aesKey;
73
+ async function seal(key, text) {
74
+ const iv = RelayBytes.random(12);
75
+ const sealed = await subtle().encrypt({ name: "AES-GCM", iv }, key, encoder.encode(text));
76
+ return RelayBytes.toBase64(RelayBytes.concat(iv, new Uint8Array(sealed)));
77
+ }
78
+ RelayKeys2.seal = seal;
79
+ async function open(key, sealed) {
80
+ const bytes = RelayBytes.fromBase64(sealed);
81
+ const opened = await subtle().decrypt({ name: "AES-GCM", iv: bytes.subarray(0, 12) }, key, bytes.subarray(12));
82
+ return decoder.decode(opened);
83
+ }
84
+ RelayKeys2.open = open;
85
+ })(RelayKeys || (RelayKeys = {}));
86
+ var RelayIdentityUtil;
87
+ (function(RelayIdentityUtil2) {
88
+ async function create(name, now = Date.now()) {
89
+ const sign2 = await subtle().generateKey(SIGN, true, ["sign", "verify"]);
90
+ const box = await subtle().generateKey(BOX, true, ["deriveBits"]);
91
+ const raw = async (key) => RelayBytes.toBase64(new Uint8Array(await subtle().exportKey("raw", key)));
92
+ const [signPublic, boxPublic] = await Promise.all([raw(sign2.publicKey), raw(box.publicKey)]);
93
+ return {
94
+ id: await id(signPublic, boxPublic),
95
+ name,
96
+ sign: signPublic,
97
+ box: boxPublic,
98
+ signKey: await subtle().exportKey("jwk", sign2.privateKey),
99
+ boxKey: await subtle().exportKey("jwk", box.privateKey),
100
+ createdAt: now
101
+ };
102
+ }
103
+ RelayIdentityUtil2.create = create;
104
+ async function id(sign2, box) {
105
+ const digest = await RelayKeys.sha256(RelayBytes.concat(RelayBytes.fromBase64(sign2), RelayBytes.fromBase64(box)));
106
+ return RelayBytes.toBase64(digest.subarray(0, 16));
107
+ }
108
+ RelayIdentityUtil2.id = id;
109
+ async function check(identity) {
110
+ try {
111
+ if (identity.id !== await id(identity.sign, identity.box)) {
112
+ return false;
113
+ }
114
+ await Promise.all([importSign(identity.sign), importBox(identity.box)]);
115
+ return true;
116
+ } catch (_a) {
117
+ return false;
118
+ }
119
+ }
120
+ RelayIdentityUtil2.check = check;
121
+ function publicOf(identity) {
122
+ return { id: identity.id, name: identity.name, sign: identity.sign, box: identity.box };
123
+ }
124
+ RelayIdentityUtil2.publicOf = publicOf;
125
+ async function sign(identity, text) {
126
+ const key = await subtle().importKey("jwk", identity.signKey, SIGN, false, ["sign"]);
127
+ return RelayBytes.toBase64(new Uint8Array(await subtle().sign(SIGNATURE, key, encoder.encode(text))));
128
+ }
129
+ RelayIdentityUtil2.sign = sign;
130
+ async function verify(signPublic, text, signature) {
131
+ try {
132
+ return await subtle().verify(SIGNATURE, await importSign(signPublic), RelayBytes.fromBase64(signature), encoder.encode(text));
133
+ } catch (_a) {
134
+ return false;
135
+ }
136
+ }
137
+ RelayIdentityUtil2.verify = verify;
138
+ async function agree(identity, otherBox, salt, info) {
139
+ const own = await subtle().importKey("jwk", identity.boxKey, BOX, false, ["deriveBits"]);
140
+ const shared = await subtle().deriveBits({ name: "ECDH", public: await importBox(otherBox) }, own, 256);
141
+ return RelayKeys.hkdf(new Uint8Array(shared), encoder.encode(salt), info);
142
+ }
143
+ RelayIdentityUtil2.agree = agree;
144
+ function importSign(raw) {
145
+ return subtle().importKey("raw", RelayBytes.fromBase64(raw), SIGN, false, ["verify"]);
146
+ }
147
+ function importBox(raw) {
148
+ return subtle().importKey("raw", RelayBytes.fromBase64(raw), BOX, false, []);
149
+ }
150
+ })(RelayIdentityUtil || (RelayIdentityUtil = {}));
151
+
152
+ // ../ta-relay/esm/common/relay-protocol.js
153
+ var RELAY_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' https: data: blob:; style-src 'unsafe-inline' https: data:; img-src https: data: blob:; font-src https: data:; media-src https: data: blob:; connect-src 'none'; form-action 'none'";
154
+ var RELAY_FRAME_HEADER_CSP = `${RELAY_FRAME_CSP}; frame-ancestors 'self'; sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox`;
155
+ var RELAY_SHARE_MAX_BYTES = 8 * 1024 * 1024;
156
+ var RELAY_SHARE_CHUNK_BYTES = 192 * 1024;
157
+ var RELAY_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
158
+ var RELAY_ID = /^[A-Za-z0-9_-]{16,64}$/;
159
+ var RelayCloseCode;
160
+ (function(RelayCloseCode2) {
161
+ RelayCloseCode2[RelayCloseCode2["HOST_OFFLINE"] = 4404] = "HOST_OFFLINE";
162
+ RelayCloseCode2[RelayCloseCode2["REFUSED"] = 4401] = "REFUSED";
163
+ RelayCloseCode2[RelayCloseCode2["REPLACED"] = 4409] = "REPLACED";
164
+ RelayCloseCode2[RelayCloseCode2["CLOSED_BY_HOST"] = 4410] = "CLOSED_BY_HOST";
165
+ RelayCloseCode2[RelayCloseCode2["FULL"] = 4429] = "FULL";
166
+ RelayCloseCode2[RelayCloseCode2["TIMEOUT"] = 4408] = "TIMEOUT";
167
+ })(RelayCloseCode || (RelayCloseCode = {}));
168
+ var RELAY_ROOM_PATH = "/r";
169
+ var RELAY_HUB_MAX_VALUE = 96 * 1024;
170
+ var RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
171
+
172
+ // ../ta-relay/esm/common/relay-hub-util.js
173
+ var RelayHubUtil;
174
+ (function(RelayHubUtil2) {
175
+ function link(link2) {
176
+ const fragment = new URLSearchParams({ v: "1", r: link2.room, i: link2.invite, o: link2.owner, n: link2.title, by: link2.by });
177
+ return `${link2.relay}${RELAY_ROOM_PATH}#${fragment}`;
178
+ }
179
+ RelayHubUtil2.link = link;
180
+ function is(text) {
181
+ try {
182
+ parse(text);
183
+ return true;
184
+ } catch (_a) {
185
+ return false;
186
+ }
187
+ }
188
+ RelayHubUtil2.is = is;
189
+ function parse(text) {
190
+ var _a, _b;
191
+ const url = new URL(text.trim());
192
+ const fragment = new URLSearchParams(url.hash.slice(1));
193
+ const [room, invite, owner] = ["r", "i", "o"].map((name) => {
194
+ var _a2;
195
+ return (_a2 = fragment.get(name)) !== null && _a2 !== undefined ? _a2 : "";
196
+ });
197
+ if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_ROOM_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(room) || !/^[A-Za-z0-9_-]{43}$/.test(invite) || !/^[A-Za-z0-9_-]{22}$/.test(owner)) {
198
+ throw new Error("Not a link inviting into a room of Ta.");
199
+ }
200
+ return { relay: url.origin, room, invite, owner, title: ((_a = fragment.get("n")) !== null && _a !== undefined ? _a : "").slice(0, 200), by: ((_b = fragment.get("by")) !== null && _b !== undefined ? _b : "").slice(0, 100) };
201
+ }
202
+ RelayHubUtil2.parse = parse;
203
+ function randomId() {
204
+ return RelayBytes.toBase64(RelayBytes.random(16));
205
+ }
206
+ RelayHubUtil2.randomId = randomId;
207
+ function randomKey() {
208
+ return RelayBytes.toBase64(RelayBytes.random(32));
209
+ }
210
+ RelayHubUtil2.randomKey = randomKey;
211
+ async function keys(roomKey) {
212
+ const key = RelayBytes.fromBase64(roomKey);
213
+ const none = new Uint8Array(0);
214
+ return {
215
+ seal: await RelayKeys.aesKey(await RelayKeys.hkdf(key, none, "ta-room/1 seal")),
216
+ names: await RelayKeys.hkdf(key, none, "ta-room/1 key")
217
+ };
218
+ }
219
+ RelayHubUtil2.keys = keys;
220
+ async function keyId(keys2, name) {
221
+ return (await RelayKeys.hmac(keys2.names, name)).slice(0, 22);
222
+ }
223
+ RelayHubUtil2.keyId = keyId;
224
+ async function inviteProof(invite) {
225
+ return RelayBytes.toBase64(await RelayKeys.hkdf(RelayBytes.fromBase64(invite), new Uint8Array(0), "ta-room/1 ask auth"));
226
+ }
227
+ RelayHubUtil2.inviteProof = inviteProof;
228
+ async function inviteKey(invite) {
229
+ return RelayKeys.aesKey(await RelayKeys.hkdf(RelayBytes.fromBase64(invite), new Uint8Array(0), "ta-room/1 ask seal"));
230
+ }
231
+ RelayHubUtil2.inviteKey = inviteKey;
232
+ async function seal(key, identity, member, body, at = Date.now()) {
233
+ const p = JSON.stringify({ m: member, at, b: body });
234
+ return RelayKeys.seal(key, JSON.stringify({ p, s: await RelayIdentityUtil.sign(identity, p) }));
235
+ }
236
+ RelayHubUtil2.seal = seal;
237
+ async function open(key, sealed, signOf, options = {}) {
238
+ var _a;
239
+ try {
240
+ const envelope = JSON.parse(await RelayKeys.open(key, sealed));
241
+ const signed = JSON.parse(envelope.p);
242
+ const sign = typeof signed.m === "string" ? signOf(signed.m) : undefined;
243
+ if (!sign || !await RelayIdentityUtil.verify(sign, envelope.p, envelope.s)) {
244
+ return;
245
+ }
246
+ if (options.skewMs !== undefined && Math.abs(((_a = options.now) !== null && _a !== undefined ? _a : Date.now()) - Number(signed.at)) > options.skewMs) {
247
+ return;
248
+ }
249
+ return signed;
250
+ } catch (_b) {
251
+ return;
252
+ }
253
+ }
254
+ RelayHubUtil2.open = open;
255
+ async function sealAsk(invite, identity, member, at = Date.now(), guest = false) {
256
+ const body = { ...RelayIdentityUtil.publicOf(identity), member, at, ...guest ? { guest: true } : {} };
257
+ return seal(await inviteKey(invite), identity, member, body, at);
258
+ }
259
+ RelayHubUtil2.sealAsk = sealAsk;
260
+ async function openAsk(invite, sealed) {
261
+ try {
262
+ const envelope = JSON.parse(await RelayKeys.open(await inviteKey(invite), sealed));
263
+ const signed = JSON.parse(envelope.p);
264
+ const body = signed.b;
265
+ if (!body || signed.m !== body.member || !RELAY_ID.test(String(body.member)) || !await RelayIdentityUtil.check(body) || !await RelayIdentityUtil.verify(body.sign, envelope.p, envelope.s)) {
266
+ return;
267
+ }
268
+ return {
269
+ ...RelayIdentityUtil.publicOf(body),
270
+ name: String(body.name).slice(0, 100),
271
+ member: body.member,
272
+ at: Number(body.at),
273
+ ...body.guest === true ? { guest: true } : {}
274
+ };
275
+ } catch (_a) {
276
+ return;
277
+ }
278
+ }
279
+ RelayHubUtil2.openAsk = openAsk;
280
+ async function sealAnswer(owner, room, ask, body, invite) {
281
+ const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(owner, ask.box, room, "ta-room/1 answer"));
282
+ const d = await RelayKeys.seal(key, JSON.stringify(body));
283
+ const signed = `${room}
284
+ ${ask.member}
285
+ ${d}`;
286
+ const answer = JSON.stringify({ owner: RelayIdentityUtil.publicOf(owner), d, s: await RelayIdentityUtil.sign(owner, signed) });
287
+ return RelayKeys.seal(await inviteKey(invite), answer);
288
+ }
289
+ RelayHubUtil2.sealAnswer = sealAnswer;
290
+ async function openAnswer(identity, room, member, ownerId, answer, invite) {
291
+ try {
292
+ const { owner, d, s } = JSON.parse(await RelayKeys.open(await inviteKey(invite), answer));
293
+ if (owner.id !== ownerId || !await RelayIdentityUtil.check(owner) || !await RelayIdentityUtil.verify(owner.sign, `${room}
294
+ ${member}
295
+ ${d}`, s)) {
296
+ return;
297
+ }
298
+ const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(identity, owner.box, room, "ta-room/1 answer"));
299
+ const body = JSON.parse(await RelayKeys.open(key, d));
300
+ RelayBytes.fromBase64(body.key);
301
+ return { owner: { ...RelayIdentityUtil.publicOf(owner), name: String(owner.name).slice(0, 100) }, body };
302
+ } catch (_a) {
303
+ return;
304
+ }
305
+ }
306
+ RelayHubUtil2.openAnswer = openAnswer;
307
+ })(RelayHubUtil || (RelayHubUtil = {}));
308
+
309
+ // ../ta-relay/esm/common/relay-room-chat.js
310
+ var RELAY_CHAT_KEY = "chat:";
311
+ var RELAY_CHAT_PART_BYTES = 8 * 1024;
312
+ var RELAY_CHAT_PARTS = 6;
313
+ var RELAY_CHAT_TEXT_MAX = 2000;
314
+ var TRIES = 6;
315
+ var RelayRoomChatUtil;
316
+ (function(RelayRoomChatUtil2) {
317
+ function key(member, part) {
318
+ return `${RELAY_CHAT_KEY}${member}:${part}`;
319
+ }
320
+ RelayRoomChatUtil2.key = key;
321
+ function parse(key2) {
322
+ const match = /^chat:([^:]+):(\d+)$/.exec(key2);
323
+ return match ? { member: match[1], part: Number(match[2]) } : undefined;
324
+ }
325
+ RelayRoomChatUtil2.parse = parse;
326
+ function lines(member, value, by) {
327
+ if (by !== member || !Array.isArray(value)) {
328
+ return;
329
+ }
330
+ const lines2 = [];
331
+ for (const line of value) {
332
+ if (line && typeof line.id === "string" && typeof line.text === "string" && typeof line.at === "number") {
333
+ lines2.push({ id: line.id, from: member, name: typeof line.name === "string" ? line.name : "", text: line.text, at: line.at });
334
+ }
335
+ }
336
+ return lines2;
337
+ }
338
+ RelayRoomChatUtil2.lines = lines;
339
+ function stored(lines2) {
340
+ return lines2.map(({ id: id2, name, text, at }) => ({ id: id2, name, text, at }));
341
+ }
342
+ RelayRoomChatUtil2.stored = stored;
343
+ function bytes(lines2) {
344
+ return new TextEncoder().encode(JSON.stringify(lines2)).length;
345
+ }
346
+ RelayRoomChatUtil2.bytes = bytes;
347
+ function id() {
348
+ return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
349
+ }
350
+ RelayRoomChatUtil2.id = id;
351
+ })(RelayRoomChatUtil || (RelayRoomChatUtil = {}));
352
+
353
+ class RelayRoomChat {
354
+ constructor(rooms, room) {
355
+ this.rooms = rooms;
356
+ this.room = room;
357
+ this.parts = new Map;
358
+ this.listeners = new Set;
359
+ this.all = [];
360
+ }
361
+ get lines() {
362
+ return this.all;
363
+ }
364
+ subscribe(listener) {
365
+ this.listeners.add(listener);
366
+ return () => this.listeners.delete(listener);
367
+ }
368
+ async load() {
369
+ const state = await this.rooms.getState(this.room, RELAY_CHAT_KEY);
370
+ this.parts.clear();
371
+ for (const [key, value] of Object.entries(state)) {
372
+ this.put(key, value);
373
+ }
374
+ this.changed();
375
+ }
376
+ heard(key, value) {
377
+ if (!RelayRoomChatUtil.parse(key)) {
378
+ return false;
379
+ }
380
+ const known = this.parts.get(key);
381
+ if (known && known.version >= value.version) {
382
+ return true;
383
+ }
384
+ this.put(key, value);
385
+ this.changed();
386
+ return true;
387
+ }
388
+ async say(text, self) {
389
+ var _a;
390
+ var _b, _c;
391
+ const said = text.trim().slice(0, RELAY_CHAT_TEXT_MAX);
392
+ if (!said) {
393
+ return;
394
+ }
395
+ for (let tries = 0;tries < TRIES; tries++) {
396
+ const latest = this.latest(self.member);
397
+ const last = latest === null || latest === undefined ? undefined : latest.lines[latest.lines.length - 1];
398
+ const at = Math.max(Date.now(), ((_b = last === null || last === undefined ? undefined : last.at) !== null && _b !== undefined ? _b : 0) + 1);
399
+ const line = { id: RelayRoomChatUtil.id(), from: self.member, name: self.name, text: said, at };
400
+ const fits = latest && RelayRoomChatUtil.bytes(RelayRoomChatUtil.stored([...latest.lines, line])) <= RELAY_CHAT_PART_BYTES;
401
+ const part = !latest ? 0 : fits ? latest.part : latest.part + 1;
402
+ const lines = fits && latest ? [...latest.lines, line] : [line];
403
+ const key = RelayRoomChatUtil.key(self.member, part);
404
+ const value = RelayRoomChatUtil.stored(lines);
405
+ const result = await this.rooms.setState(this.room, key, value, (_c = (_a = this.parts.get(key)) === null || _a === undefined ? undefined : _a.version) !== null && _c !== undefined ? _c : 0);
406
+ if (result.ok) {
407
+ this.put(key, { value, version: result.version, by: self.member });
408
+ this.changed();
409
+ if (part >= RELAY_CHAT_PARTS) {
410
+ this.clear(RelayRoomChatUtil.key(self.member, part - RELAY_CHAT_PARTS));
411
+ }
412
+ return;
413
+ }
414
+ await this.load();
415
+ }
416
+ throw new Error("The room is busy: say it again.");
417
+ }
418
+ async clear(key) {
419
+ await this.rooms.setState(this.room, key, null).catch(() => {
420
+ return;
421
+ });
422
+ if (this.parts.delete(key)) {
423
+ this.changed();
424
+ }
425
+ }
426
+ latest(member) {
427
+ let latest;
428
+ for (const part of this.parts.values()) {
429
+ if (part.member === member && (!latest || part.part > latest.part)) {
430
+ latest = part;
431
+ }
432
+ }
433
+ return latest;
434
+ }
435
+ put(key, value) {
436
+ const parsed = RelayRoomChatUtil.parse(key);
437
+ const lines = parsed && value.value !== null ? RelayRoomChatUtil.lines(parsed.member, value.value, value.by) : undefined;
438
+ if (!parsed || !lines) {
439
+ this.parts.delete(key);
440
+ return;
441
+ }
442
+ this.parts.set(key, { ...parsed, lines, version: value.version });
443
+ }
444
+ changed() {
445
+ this.all = [...this.parts.values()].flatMap((part) => part.lines).sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
446
+ for (const listener of this.listeners) {
447
+ listener();
448
+ }
449
+ }
450
+ }
451
+
452
+ // web-src/i18n.ts
453
+ var EN = {
454
+ roomsTitle: "Rooms",
455
+ add: "New",
456
+ me: "Your name in rooms",
457
+ meLine: "In rooms you are “{name}”",
458
+ rename: "Change",
459
+ renamePlaceholder: "What others see",
460
+ requests: "Asking to join",
461
+ requestLine: "wants to join “{title}”",
462
+ friendTag: "Ta friend",
463
+ newTag: "New",
464
+ guestTag: "Web guest",
465
+ requestGuest: "They ask from a browser, without Ta: let in, they only chat, and are not a Ta friend.",
466
+ accept: "Let in",
467
+ refuse: "Refuse",
468
+ requestBody: "{name} wants to join your room “{title}”.",
469
+ requestsBody: "{n} people ask to join your rooms.",
470
+ requestFriend: "You were in a room together before.",
471
+ requestNew: "You have not met in a room before: let in only someone you know.",
472
+ requestWhat: "Once in, they see the messages and the shared state of the room: in a game, where everyone is and what is built.",
473
+ later: "Later",
474
+ ownRoom: "Your room",
475
+ roomOf: "A room of {name}",
476
+ people: "{n} people · {online} online",
477
+ othersOnline: "{n} more online",
478
+ nobodyOnline: "Nobody else online",
479
+ said: "{name}: {text}",
480
+ yesterday: "Yesterday",
481
+ waiting: "Waiting for {name} to let you in",
482
+ refused: "{name} did not let you in",
483
+ closed: "Closed by its owner",
484
+ removed: "You were taken out",
485
+ inviteGone: "The invitation no longer works",
486
+ connecting: "Connecting…",
487
+ invite: "Invite",
488
+ inviteLine: "A link or a QR code; you let them in",
489
+ inviteTitle: "Invite into “{title}”",
490
+ inviteHint: "Send the link: opened in a browser, it asks to chat as a web guest; in the Ta app (scan or paste), to join with Ta. You let in who asks; the link works for 7 days, and a new one stops it.",
491
+ newLink: "New link",
492
+ making: "Making the link…",
493
+ copy: "Copy link",
494
+ copied: "Copied",
495
+ send: "Send…",
496
+ qr: "QR code of the invitation",
497
+ members: "Members",
498
+ membersTitle: "Members of the room",
499
+ membersCount: "{n} members · {online} online",
500
+ noRoomOpen: "Open a room to see who is in it",
501
+ you: "You",
502
+ owner: "Owner",
503
+ online: "Online",
504
+ offline: "Offline",
505
+ remove: "Take out",
506
+ removeTitle: "Take {name} out of “{title}”?",
507
+ removeHint: "They are disconnected at once, and come back only by a new invitation.",
508
+ leave: "Leave the room",
509
+ leaveTitle: "Leave “{title}”?",
510
+ leaveHint: "You come back only by a new invitation.",
511
+ close: "Close the room",
512
+ closeTitle: "Close “{title}” for everyone?",
513
+ closeHint: "Everyone is taken out, and the relay deletes all the room kept.",
514
+ forget: "Remove",
515
+ friends: "Ta friends",
516
+ friendLine: "In {rooms}",
517
+ removeFriend: "Remove",
518
+ removeFriendTitle: "Remove {name} from your Ta friends?",
519
+ removeFriendHint: "The rooms you share stay as they are.",
520
+ emptyTitle: "No rooms yet",
521
+ emptyHint: "No rooms yet. Make one with + and invite friends to chat, or open a link someone sent you to ask to join theirs.",
522
+ pickRoom: "Pick a room to chat in",
523
+ joinTitle: "Join “{title}”?",
524
+ joinBody: "A room of {by}. They let you in first, and your name “{name}” goes to them.",
525
+ joinAction: "Ask to join",
526
+ joinByLink: "Join by a link",
527
+ joinByLinkPlaceholder: "Paste the link of the invitation",
528
+ scan: "Scan a code",
529
+ scanHint: "Scan the QR code of an invitation",
530
+ notInvite: "That is not a link that invites into a room.",
531
+ asked: "Asked {by}: you are in once they let you in.",
532
+ admitted: "You are in “{title}”.",
533
+ refusedNotice: "{by} did not let you into “{title}”.",
534
+ removedNotice: "You were taken out of “{title}”.",
535
+ closedNotice: "“{title}” was closed by its owner.",
536
+ oldApp: "Update the Ta app to use rooms.",
537
+ room: "Room",
538
+ newRoom: "New room",
539
+ newRoomPlaceholder: "Its name, which those you invite see",
540
+ roomOfName: "{name}’s room",
541
+ back: "Back",
542
+ openPage: "Open {name}",
543
+ pageLine: "A room of {name}: play in it together",
544
+ chatEmpty: "Nothing said yet. Only those in the room read it: the relay keeps it sealed.",
545
+ chatPlaceholder: "Message"
546
+ };
547
+ var ZH = {
548
+ roomsTitle: "房间",
549
+ add: "新建",
550
+ me: "我在房间里的名字",
551
+ meLine: "你在房间里叫「{name}」",
552
+ rename: "修改",
553
+ renamePlaceholder: "别人看到的名字",
554
+ requests: "加入申请",
555
+ requestLine: "想加入「{title}」",
556
+ friendTag: "Ta 好友",
557
+ newTag: "新朋友",
558
+ guestTag: "网页访客",
559
+ requestGuest: "对方是用浏览器申请的,没有装 Ta:进来后只能聊天,也不会成为 Ta 好友。",
560
+ accept: "同意",
561
+ refuse: "拒绝",
562
+ requestBody: "「{name}」想加入你的房间「{title}」。",
563
+ requestsBody: "有 {n} 人申请加入你的房间。",
564
+ requestFriend: "你们之前在同一个房间待过。",
565
+ requestNew: "你们还没在房间里见过:只让认识的人进来。",
566
+ requestWhat: "进来后,对方能看到房间里的消息和共享的内容;在游戏里就是大家的位置和搭的东西。",
567
+ later: "稍后",
568
+ ownRoom: "我建的房间",
569
+ roomOf: "{name}的房间",
570
+ people: "{n} 人 · {online} 人在线",
571
+ othersOnline: "另有 {n} 人在线",
572
+ nobodyOnline: "其他人都不在线",
573
+ said: "{name}:{text}",
574
+ yesterday: "昨天",
575
+ waiting: "等{name}同意",
576
+ refused: "{name}没有同意",
577
+ closed: "房主已解散",
578
+ removed: "你已被移出",
579
+ inviteGone: "邀请已失效",
580
+ connecting: "连接中…",
581
+ invite: "邀请",
582
+ inviteLine: "发链接或二维码,由你同意进入",
583
+ inviteTitle: "邀请加入「{title}」",
584
+ inviteHint: "把链接发给对方:在浏览器里打开,可以作为网页访客申请聊天;在 Ta 应用里扫码或粘贴,就用 Ta 加入。都要你同意;链接 7 天内有效,换新链接后旧的作废。",
585
+ newLink: "换一个链接",
586
+ making: "正在生成链接…",
587
+ copy: "复制链接",
588
+ copied: "已复制",
589
+ send: "发送…",
590
+ qr: "邀请二维码",
591
+ members: "成员",
592
+ membersTitle: "房间成员",
593
+ membersCount: "{n} 位成员 · {online} 人在线",
594
+ noRoomOpen: "打开一个房间,这里显示它的成员",
595
+ you: "我",
596
+ owner: "房主",
597
+ online: "在线",
598
+ offline: "离线",
599
+ remove: "移出",
600
+ removeTitle: "把「{name}」移出「{title}」?",
601
+ removeHint: "对方会立刻断开,只有新的邀请才能再进来。",
602
+ leave: "退出房间",
603
+ leaveTitle: "退出「{title}」?",
604
+ leaveHint: "退出后要有新的邀请才能再进来。",
605
+ close: "解散房间",
606
+ closeTitle: "解散「{title}」?",
607
+ closeHint: "所有人都会被移出,中继会删除房间保存的全部内容。",
608
+ forget: "删除",
609
+ friends: "Ta 好友",
610
+ friendLine: "一起在:{rooms}",
611
+ removeFriend: "删除",
612
+ removeFriendTitle: "把「{name}」从 Ta 好友里删除?",
613
+ removeFriendHint: "一起所在的房间不受影响。",
614
+ emptyTitle: "还没有房间",
615
+ emptyHint: "还没有房间。点右上角 + 新建一个,邀请朋友来聊天;别人发来的邀请链接,点开就能申请加入。",
616
+ pickRoom: "选一个房间开始聊天",
617
+ joinTitle: "加入「{title}」?",
618
+ joinBody: "这是{by}的房间。房主同意后你才能进去,你的名字「{name}」会发给对方。",
619
+ joinAction: "申请加入",
620
+ joinByLink: "用邀请链接加入",
621
+ joinByLinkPlaceholder: "粘贴别人发来的邀请链接",
622
+ scan: "扫一扫",
623
+ scanHint: "扫描房间的邀请二维码",
624
+ notInvite: "这不是房间的邀请链接。",
625
+ asked: "已向{by}发出申请,对方同意后就能进入。",
626
+ admitted: "已加入「{title}」。",
627
+ refusedNotice: "{by}没有同意你加入「{title}」。",
628
+ removedNotice: "你已被移出「{title}」。",
629
+ closedNotice: "「{title}」已被房主解散。",
630
+ oldApp: "请更新 Ta 应用后再使用房间。",
631
+ room: "房间",
632
+ newRoom: "新建房间",
633
+ newRoomPlaceholder: "房间名,受邀的人能看到",
634
+ roomOfName: "{name}的房间",
635
+ back: "返回",
636
+ openPage: "打开{name}",
637
+ pageLine: "{name}的房间,大家可以一起玩",
638
+ chatEmpty: "还没有人说话。只有房间里的人能看到,中继保存的是密文。",
639
+ chatPlaceholder: "发消息"
640
+ };
641
+ var RoomWords;
642
+ ((RoomWords) => {
643
+ function of(language) {
644
+ return language === "zh-CN" ? ZH : EN;
645
+ }
646
+ RoomWords.of = of;
647
+ function format(text, values) {
648
+ return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
649
+ }
650
+ RoomWords.format = format;
651
+ })(RoomWords ||= {});
652
+
653
+ // web-src/react.ts
654
+ var React;
655
+ function bind(react) {
656
+ React = react;
657
+ }
658
+
659
+ // web-src/page.tsx
660
+ var ROOMS_KIND = "ta-rooms";
661
+ var ROOMS_VIEW = "@celljs/ta-rooms/rooms";
662
+ var MEMBERS_VIEW = "@celljs/ta-rooms/members";
663
+ var CHAT_STATE = ["chat:"];
664
+ var SEEN_KEY = "seen";
665
+ var pi;
666
+ function bindPage(api) {
667
+ pi = api;
668
+ }
669
+ function t(key, values = {}) {
670
+ return RoomWords.format(RoomWords.of(pi.ui.language)[key], values);
671
+ }
672
+ function icon(name) {
673
+ return pi.ui.icons[name] ?? pi.ui.icons.Users ?? pi.ui.icons.Circle;
674
+ }
675
+ function message(error) {
676
+ return error instanceof Error ? error.message : String(error);
677
+ }
678
+ function rooms() {
679
+ return pi.rooms;
680
+ }
681
+
682
+ class RoomBook {
683
+ state = { requests: [], seen: {} };
684
+ listeners = new Set;
685
+ chats = new Map;
686
+ timer;
687
+ loading;
688
+ again = false;
689
+ seenRead = false;
690
+ onChange;
691
+ get() {
692
+ return this.state;
693
+ }
694
+ subscribe(listener) {
695
+ this.listeners.add(listener);
696
+ return () => this.listeners.delete(listener);
697
+ }
698
+ load() {
699
+ if (this.loading) {
700
+ this.again = true;
701
+ return this.loading;
702
+ }
703
+ const server = rooms();
704
+ if (!server) {
705
+ this.set({ rooms: [], friends: [] });
706
+ return Promise.resolve();
707
+ }
708
+ this.readSeen();
709
+ this.loading = Promise.all([
710
+ server.getIdentity().catch(() => this.state.identity),
711
+ server.listRooms().catch(() => this.state.rooms ?? []),
712
+ server.listRequests().catch(() => this.state.requests),
713
+ server.listFriends().catch(() => this.state.friends ?? [])
714
+ ]).then(([identity, list, requests, friends]) => this.read({ ...this.state, identity, rooms: list, requests, friends })).finally(() => {
715
+ this.loading = undefined;
716
+ if (this.again) {
717
+ this.again = false;
718
+ this.load();
719
+ }
720
+ });
721
+ return this.loading;
722
+ }
723
+ reload() {
724
+ clearTimeout(this.timer);
725
+ this.timer = setTimeout(() => {
726
+ this.load();
727
+ for (const chat of this.chats.values()) {
728
+ chat.load().catch(() => {
729
+ return;
730
+ });
731
+ }
732
+ }, 300);
733
+ }
734
+ set(partial) {
735
+ this.state = { ...this.state, ...partial };
736
+ for (const listener of this.listeners) {
737
+ listener();
738
+ }
739
+ }
740
+ chat(room) {
741
+ const server = rooms();
742
+ if (!server) {
743
+ return;
744
+ }
745
+ let chat = this.chats.get(room);
746
+ if (!chat) {
747
+ chat = new RelayRoomChat(server, room);
748
+ this.chats.set(room, chat);
749
+ chat.load().catch(() => {
750
+ return;
751
+ });
752
+ }
753
+ return chat;
754
+ }
755
+ heard(event) {
756
+ if (event.type === "state") {
757
+ this.chats.get(event.room)?.heard(event.key, event);
758
+ }
759
+ }
760
+ see(room, at) {
761
+ if ((this.state.seen[room] ?? 0) >= at) {
762
+ return;
763
+ }
764
+ const seen = { ...this.state.seen, [room]: at };
765
+ this.set({ seen });
766
+ pi.storage?.set(SEEN_KEY, seen).catch(() => {
767
+ return;
768
+ });
769
+ }
770
+ readSeen() {
771
+ if (this.seenRead || !pi.storage) {
772
+ return;
773
+ }
774
+ this.seenRead = true;
775
+ pi.storage.get(SEEN_KEY).then((seen) => {
776
+ if (seen && typeof seen === "object") {
777
+ this.set({ seen: { ...seen, ...this.state.seen } });
778
+ }
779
+ }).catch(() => {
780
+ return;
781
+ });
782
+ }
783
+ read(next) {
784
+ const before = new Map((this.state.rooms ?? []).map((room) => [room.id, room]));
785
+ const known = this.state.rooms !== undefined;
786
+ this.set(next);
787
+ const changes = (next.rooms ?? []).filter((room) => !known || before.get(room.id)?.status !== room.status).map((room) => ({ before: before.get(room.id), room }));
788
+ if (known && changes.length) {
789
+ this.onChange?.(changes);
790
+ }
791
+ }
792
+ }
793
+ var book = new RoomBook;
794
+ function useBook() {
795
+ const state = React.useSyncExternalStore((listener) => book.subscribe(listener), () => book.get());
796
+ React.useEffect(() => {
797
+ book.load();
798
+ }, []);
799
+ return state;
800
+ }
801
+ var NO_LINES = [];
802
+ var NO_STOP = () => {
803
+ return;
804
+ };
805
+ function useLines(room) {
806
+ const chat = room.status === "member" ? book.chat(room.id) : undefined;
807
+ return React.useSyncExternalStore((listener) => chat?.subscribe(listener) ?? NO_STOP, () => chat?.lines ?? NO_LINES);
808
+ }
809
+ function unseen(room, lines, seen) {
810
+ const self = room.members.find((member) => member.self)?.member;
811
+ const since = seen[room.id] ?? room.joinedAt ?? room.createdAt;
812
+ const last = lines[lines.length - 1];
813
+ return !!last && last.at > since && last.from !== self;
814
+ }
815
+ function openRoom(id) {
816
+ book.set({ opened: id });
817
+ pi.ui.showView(ROOMS_VIEW);
818
+ }
819
+ function useOpened() {
820
+ const { rooms: list, opened } = useBook();
821
+ return opened ? list?.find((room) => room.id === opened && room.status === "member") : undefined;
822
+ }
823
+ function useCompact() {
824
+ return (pi.ui.useDevice?.().layout ?? "expanded") === "compact";
825
+ }
826
+ function usePageOf(room) {
827
+ const pages = pi.ui.usePages?.() ?? [];
828
+ const view = room.view;
829
+ if (!view || view === ROOMS_VIEW) {
830
+ return;
831
+ }
832
+ return pages.find((page) => page.id === view) ?? pages.find((page) => page.onOpen && view.startsWith(`${page.id}/`));
833
+ }
834
+ function statusLine(room) {
835
+ switch (room.status) {
836
+ case "waiting":
837
+ return t("waiting", { name: room.ownerName });
838
+ case "refused":
839
+ return t("refused", { name: room.ownerName });
840
+ case "gone":
841
+ return room.reason === "removed" ? t("removed") : room.reason === "invite" ? t("inviteGone") : t("closed");
842
+ }
843
+ if (!room.connected) {
844
+ return t("connecting");
845
+ }
846
+ const online = room.members.filter((member) => member.online).length;
847
+ return t("people", { n: room.members.length, online });
848
+ }
849
+ function when(at, now = Date.now()) {
850
+ const date = new Date(at);
851
+ const today = new Date(now);
852
+ today.setHours(0, 0, 0, 0);
853
+ const day = 24 * 60 * 60 * 1000;
854
+ const language = pi.ui.language;
855
+ if (at >= today.getTime()) {
856
+ return date.toLocaleTimeString(language, { hour: "2-digit", minute: "2-digit" });
857
+ }
858
+ if (at >= today.getTime() - day) {
859
+ return t("yesterday");
860
+ }
861
+ if (at >= today.getTime() - 6 * day) {
862
+ return date.toLocaleDateString(language, { weekday: "short" });
863
+ }
864
+ return date.toLocaleDateString(language, { month: "numeric", day: "numeric", ...date.getFullYear() !== today.getFullYear() ? { year: "2-digit" } : {} });
865
+ }
866
+ function tint(id) {
867
+ let hash = 0;
868
+ for (const char of id) {
869
+ hash = hash * 31 + char.charCodeAt(0) | 0;
870
+ }
871
+ return Math.abs(hash) % 9;
872
+ }
873
+ function initial(name) {
874
+ return Array.from(name.trim())[0]?.toUpperCase() ?? "?";
875
+ }
876
+ function Face({ id, name, size = 34, online }) {
877
+ const n = tint(id);
878
+ return /* @__PURE__ */ React.createElement("span", {
879
+ className: "trm-face",
880
+ "aria-hidden": "true",
881
+ style: { width: size, height: size, fontSize: Math.round(size * 0.42), background: `var(--ta-tint-${n})`, color: `var(--ta-tint-ink-${n})` }
882
+ }, initial(name), online !== undefined && /* @__PURE__ */ React.createElement("i", {
883
+ className: online ? "trm-on" : "trm-off"
884
+ }));
885
+ }
886
+ function RoomFace({ room, size = 44, unread }) {
887
+ const page = usePageOf(room);
888
+ const members = room.members.length ? room.members.slice(0, 4) : [{ member: room.id, id: room.id, name: room.title }];
889
+ const Mark = page?.icon;
890
+ const cell = members.length === 1 ? size : Math.floor((size - 6) / 2);
891
+ return /* @__PURE__ */ React.createElement("span", {
892
+ className: "trm-room-face",
893
+ "aria-hidden": "true",
894
+ style: { width: size, height: size },
895
+ "data-count": members.length
896
+ }, members.map((member) => {
897
+ const n = tint(member.id);
898
+ return /* @__PURE__ */ React.createElement("span", {
899
+ key: member.member,
900
+ className: "trm-room-face-cell",
901
+ style: {
902
+ width: cell,
903
+ height: cell,
904
+ fontSize: Math.round(cell * 0.5),
905
+ background: `var(--ta-tint-${n})`,
906
+ color: `var(--ta-tint-ink-${n})`
907
+ }
908
+ }, initial(member.name));
909
+ }), Mark && /* @__PURE__ */ React.createElement("span", {
910
+ className: "trm-room-face-mark"
911
+ }, /* @__PURE__ */ React.createElement(Mark, {
912
+ size: 11,
913
+ strokeWidth: 2.4
914
+ })), unread && /* @__PURE__ */ React.createElement("i", {
915
+ className: "trm-unread"
916
+ }));
917
+ }
918
+
919
+ // web-src/dialogs.tsx
920
+ function show(component) {
921
+ if (!pi.ui.custom) {
922
+ pi.ui.notify(t("oldApp"), "warning");
923
+ return;
924
+ }
925
+ return pi.ui.custom(component);
926
+ }
927
+ function RequestRow({ request }) {
928
+ const [busy, run] = (pi.ui.useBusy ?? (() => [false, async (action) => action()]))();
929
+ const answer = (accept) => void run(async () => {
930
+ try {
931
+ await rooms()?.answer(request.room, request.ask, accept);
932
+ } catch (error) {
933
+ pi.ui.notify(message(error), "error");
934
+ }
935
+ await book.load();
936
+ });
937
+ return /* @__PURE__ */ React.createElement("li", {
938
+ className: `trm-row${busy ? " ta-pending" : ""}`
939
+ }, /* @__PURE__ */ React.createElement(Face, {
940
+ id: request.id,
941
+ name: request.name
942
+ }), /* @__PURE__ */ React.createElement("div", {
943
+ className: "trm-row-text"
944
+ }, /* @__PURE__ */ React.createElement("span", {
945
+ className: "trm-row-title"
946
+ }, request.name, /* @__PURE__ */ React.createElement("span", {
947
+ className: `trm-tag${request.friend ? " trm-tag-friend" : ""}`
948
+ }, request.guest ? t("guestTag") : request.friend ? t("friendTag") : t("newTag"))), /* @__PURE__ */ React.createElement("span", {
949
+ className: "trm-row-line"
950
+ }, t("requestLine", { title: request.title }))), /* @__PURE__ */ React.createElement("div", {
951
+ className: "trm-answers"
952
+ }, /* @__PURE__ */ React.createElement("button", {
953
+ type: "button",
954
+ className: "ta-button",
955
+ disabled: busy,
956
+ onClick: () => answer(false)
957
+ }, t("refuse")), /* @__PURE__ */ React.createElement("button", {
958
+ type: "button",
959
+ className: "ta-button ta-primary",
960
+ disabled: busy,
961
+ onClick: () => answer(true)
962
+ }, t("accept"))));
963
+ }
964
+ function RequestsDialog({ close }) {
965
+ const { requests } = useBook();
966
+ const seen = React.useRef(false);
967
+ React.useEffect(() => {
968
+ if (requests.length) {
969
+ seen.current = true;
970
+ } else if (seen.current) {
971
+ close();
972
+ }
973
+ }, [requests.length, close]);
974
+ const first = requests[0];
975
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
976
+ title: t("requests"),
977
+ onClose: close
978
+ }, /* @__PURE__ */ React.createElement("div", {
979
+ className: "trm-dialog"
980
+ }, first && /* @__PURE__ */ React.createElement("p", {
981
+ className: "trm-lead"
982
+ }, requests.length === 1 ? t("requestBody", { name: first.name, title: first.title }) : t("requestsBody", { n: requests.length })), /* @__PURE__ */ React.createElement("ul", {
983
+ className: "trm-rows"
984
+ }, requests.map((request) => /* @__PURE__ */ React.createElement(RequestRow, {
985
+ key: `${request.room}:${request.ask}`,
986
+ request
987
+ }))), /* @__PURE__ */ React.createElement("p", {
988
+ className: "trm-note"
989
+ }, [
990
+ requests.some((request) => !request.friend) ? t("requestNew") : requests.length ? t("requestFriend") : "",
991
+ requests.some((request) => request.guest) ? t("requestGuest") : "",
992
+ t("requestWhat")
993
+ ].filter(Boolean).join(pi.ui.language === "zh-CN" ? "" : " ")), /* @__PURE__ */ React.createElement("div", {
994
+ className: "trm-actions"
995
+ }, /* @__PURE__ */ React.createElement("button", {
996
+ type: "button",
997
+ className: "ta-button",
998
+ onClick: close
999
+ }, t("later")))));
1000
+ }
1001
+ var requestsOpen;
1002
+ function openRequests() {
1003
+ if (requestsOpen) {
1004
+ return;
1005
+ }
1006
+ const close = show(({ close: close2 }) => /* @__PURE__ */ React.createElement(RequestsDialog, {
1007
+ close: () => {
1008
+ requestsOpen = undefined;
1009
+ close2();
1010
+ }
1011
+ }));
1012
+ requestsOpen = close;
1013
+ }
1014
+ function JoinDialog({ link, text, close }) {
1015
+ const { identity } = useBook();
1016
+ const [busy, setBusy] = React.useState(false);
1017
+ const [error, setError] = React.useState();
1018
+ const join = async () => {
1019
+ setBusy(true);
1020
+ setError(undefined);
1021
+ try {
1022
+ const room = await rooms()?.join(text);
1023
+ await book.load();
1024
+ close();
1025
+ if (room?.status === "member") {
1026
+ if (room.view) {
1027
+ pi.ui.showView(room.view);
1028
+ } else {
1029
+ openRoom(room.id);
1030
+ }
1031
+ } else {
1032
+ pi.ui.notify(t("asked", { by: link.by || "…" }));
1033
+ }
1034
+ } catch (failure) {
1035
+ setError(message(failure));
1036
+ setBusy(false);
1037
+ }
1038
+ };
1039
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
1040
+ title: t("joinTitle", { title: link.title || t("room") }),
1041
+ onClose: close
1042
+ }, /* @__PURE__ */ React.createElement("div", {
1043
+ className: "trm-dialog"
1044
+ }, /* @__PURE__ */ React.createElement("div", {
1045
+ className: "trm-join"
1046
+ }, /* @__PURE__ */ React.createElement(Face, {
1047
+ id: link.owner,
1048
+ name: link.by || "?",
1049
+ size: 44
1050
+ }), /* @__PURE__ */ React.createElement("p", {
1051
+ className: "trm-lead"
1052
+ }, t("joinBody", { by: link.by || "…", name: identity?.name ?? "…" }))), error && /* @__PURE__ */ React.createElement("p", {
1053
+ className: "trm-error"
1054
+ }, error), /* @__PURE__ */ React.createElement("div", {
1055
+ className: "trm-actions"
1056
+ }, /* @__PURE__ */ React.createElement("button", {
1057
+ type: "button",
1058
+ className: "ta-button",
1059
+ onClick: close
1060
+ }, t("later")), /* @__PURE__ */ React.createElement("button", {
1061
+ type: "button",
1062
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
1063
+ disabled: busy,
1064
+ onClick: () => void join()
1065
+ }, t("joinAction")))));
1066
+ }
1067
+ function InviteDialog({ room, close }) {
1068
+ const [link, setLink] = React.useState();
1069
+ const [error, setError] = React.useState();
1070
+ const [copied, setCopied] = React.useState(false);
1071
+ const make = React.useCallback((renew) => {
1072
+ setError(undefined);
1073
+ setCopied(false);
1074
+ rooms()?.invite(room.id, renew ? { renew } : undefined).then((made) => setLink(made.link)).catch((failure) => setError(message(failure)));
1075
+ }, [room.id]);
1076
+ React.useEffect(() => make(false), [make]);
1077
+ const canSend = typeof navigator !== "undefined" && typeof navigator.share === "function";
1078
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
1079
+ title: t("inviteTitle", { title: room.title }),
1080
+ onClose: close
1081
+ }, /* @__PURE__ */ React.createElement("div", {
1082
+ className: "trm-dialog trm-invite"
1083
+ }, link ? /* @__PURE__ */ React.createElement(React.Fragment, null, pi.ui.QrCode && /* @__PURE__ */ React.createElement("div", {
1084
+ className: "trm-qr"
1085
+ }, /* @__PURE__ */ React.createElement(pi.ui.QrCode, {
1086
+ text: link,
1087
+ label: t("qr")
1088
+ })), /* @__PURE__ */ React.createElement("p", {
1089
+ className: "trm-hint"
1090
+ }, t("inviteHint")), /* @__PURE__ */ React.createElement("div", {
1091
+ className: "trm-link-box"
1092
+ }, link), /* @__PURE__ */ React.createElement("div", {
1093
+ className: "trm-actions trm-center"
1094
+ }, /* @__PURE__ */ React.createElement("button", {
1095
+ type: "button",
1096
+ className: "ta-button ta-primary",
1097
+ onClick: () => void navigator.clipboard?.writeText(link).then(() => setCopied(true))
1098
+ }, copied ? t("copied") : t("copy")), canSend && /* @__PURE__ */ React.createElement("button", {
1099
+ type: "button",
1100
+ className: "ta-button",
1101
+ onClick: () => void navigator.share({ title: room.title, url: link }).catch(() => {
1102
+ return;
1103
+ })
1104
+ }, t("send")), /* @__PURE__ */ React.createElement("button", {
1105
+ type: "button",
1106
+ className: "ta-button",
1107
+ onClick: () => make(true)
1108
+ }, t("newLink")))) : error ? /* @__PURE__ */ React.createElement("p", {
1109
+ className: "trm-error"
1110
+ }, error) : /* @__PURE__ */ React.createElement("p", {
1111
+ className: "trm-hint"
1112
+ }, t("making"))));
1113
+ }
1114
+ function openInvite(room) {
1115
+ show(({ close }) => /* @__PURE__ */ React.createElement(InviteDialog, {
1116
+ room,
1117
+ close
1118
+ }));
1119
+ }
1120
+ function openJoin(text) {
1121
+ const link = RelayHubUtil.parse(text);
1122
+ const known = book.get().rooms?.find((room) => room.id === link.room && room.status === "member");
1123
+ if (known) {
1124
+ if (known.view) {
1125
+ pi.ui.showView(known.view);
1126
+ } else {
1127
+ openRoom(known.id);
1128
+ }
1129
+ return;
1130
+ }
1131
+ show(({ close }) => /* @__PURE__ */ React.createElement(JoinDialog, {
1132
+ link,
1133
+ text,
1134
+ close
1135
+ }));
1136
+ }
1137
+ async function createRoom() {
1138
+ const name = book.get().identity?.name;
1139
+ const title = await pi.ui.input(t("newRoom"), t("newRoomPlaceholder"), { value: name ? t("roomOfName", { name }) : "" });
1140
+ if (!title?.trim()) {
1141
+ return;
1142
+ }
1143
+ try {
1144
+ const room = await rooms()?.createRoom({ kind: ROOMS_KIND, title: title.trim() });
1145
+ if (room) {
1146
+ await book.load();
1147
+ openRoom(room.id);
1148
+ openInvite(room);
1149
+ }
1150
+ } catch (error) {
1151
+ pi.ui.notify(message(error), "error");
1152
+ }
1153
+ }
1154
+ async function pasteLink() {
1155
+ const text = (await pi.ui.input(t("joinByLink"), t("joinByLinkPlaceholder")))?.trim();
1156
+ if (!text) {
1157
+ return;
1158
+ }
1159
+ if (!RelayHubUtil.is(text)) {
1160
+ pi.ui.notify(t("notInvite"), "warning");
1161
+ return;
1162
+ }
1163
+ openJoin(text);
1164
+ }
1165
+ async function scanLink() {
1166
+ const text = (await pi.ui.scanCode?.(t("scanHint")))?.trim();
1167
+ if (!text) {
1168
+ return;
1169
+ }
1170
+ if (!RelayHubUtil.is(text)) {
1171
+ pi.ui.notify(t("notInvite"), "warning");
1172
+ return;
1173
+ }
1174
+ openJoin(text);
1175
+ }
1176
+ async function rename() {
1177
+ const identity = book.get().identity;
1178
+ const name = await pi.ui.input(t("me"), t("renamePlaceholder"), { value: identity?.name ?? "" });
1179
+ if (name?.trim() && name.trim() !== identity?.name) {
1180
+ try {
1181
+ book.set({ identity: await rooms()?.setName(name.trim()) });
1182
+ } catch (error) {
1183
+ pi.ui.notify(message(error), "error");
1184
+ }
1185
+ }
1186
+ }
1187
+
1188
+ // web-src/room-view.tsx
1189
+ var RUN_MS = 5 * 60 * 1000;
1190
+ var PAUSE_MS = 15 * 60 * 1000;
1191
+ async function confirmThen(title, hint, label, action) {
1192
+ if (!await pi.ui.confirm(title, hint, { confirmLabel: label, danger: true })) {
1193
+ return false;
1194
+ }
1195
+ try {
1196
+ await action();
1197
+ } catch (error) {
1198
+ pi.ui.notify(message(error), "error");
1199
+ }
1200
+ await book.load();
1201
+ return true;
1202
+ }
1203
+ function leaveRoom(room) {
1204
+ if (room.status !== "member") {
1205
+ return (rooms()?.leave(room.id) ?? Promise.resolve()).then(() => book.load()).then(() => true);
1206
+ }
1207
+ return confirmThen(room.owner ? t("closeTitle", { title: room.title }) : t("leaveTitle", { title: room.title }), room.owner ? t("closeHint") : t("leaveHint"), room.owner ? t("close") : t("leave"), async () => rooms()?.leave(room.id));
1208
+ }
1209
+ function time(at) {
1210
+ const date = new Date(at);
1211
+ const clock = date.toLocaleTimeString(pi.ui.language, { hour: "2-digit", minute: "2-digit" });
1212
+ return date.toDateString() === new Date().toDateString() ? clock : `${date.toLocaleDateString(pi.ui.language, { month: "numeric", day: "numeric" })} ${clock}`;
1213
+ }
1214
+ function MembersButton() {
1215
+ const shown = !!pi.ui.useView?.(MEMBERS_VIEW)?.shown;
1216
+ const More = icon("Ellipsis");
1217
+ return /* @__PURE__ */ React.createElement("button", {
1218
+ type: "button",
1219
+ className: `trm-icon trm-members-button${shown ? " trm-on-icon" : ""}`,
1220
+ title: t("members"),
1221
+ "aria-label": t("members"),
1222
+ "aria-pressed": shown,
1223
+ onClick: () => void pi.ui.showView(MEMBERS_VIEW)
1224
+ }, /* @__PURE__ */ React.createElement(More, {
1225
+ size: 18
1226
+ }));
1227
+ }
1228
+ function RoomTitle({ room }) {
1229
+ const online = room.members.filter((member) => member.online && !member.self).length;
1230
+ return /* @__PURE__ */ React.createElement("span", {
1231
+ className: "trm-room-title"
1232
+ }, /* @__PURE__ */ React.createElement("span", {
1233
+ className: "trm-room-title-text"
1234
+ }, /* @__PURE__ */ React.createElement("span", {
1235
+ className: "trm-ellipsis"
1236
+ }, room.title), /* @__PURE__ */ React.createElement("span", {
1237
+ className: "trm-room-count"
1238
+ }, "(", room.members.length, ")")), /* @__PURE__ */ React.createElement("span", {
1239
+ className: `trm-room-sub${room.connected ? "" : " trm-quiet"}`
1240
+ }, !room.connected ? t("connecting") : online ? t("othersOnline", { n: online }) : t("nobodyOnline")));
1241
+ }
1242
+ function PageLine({ room }) {
1243
+ const page = usePageOf(room);
1244
+ if (!page || !room.view) {
1245
+ return null;
1246
+ }
1247
+ const Icon = page.icon ?? icon("ExternalLink");
1248
+ const Chevron = icon("ChevronRight");
1249
+ const view = room.view;
1250
+ return /* @__PURE__ */ React.createElement("button", {
1251
+ type: "button",
1252
+ className: "trm-page-line",
1253
+ onClick: () => void pi.ui.showView(view)
1254
+ }, /* @__PURE__ */ React.createElement("span", {
1255
+ className: "trm-page-line-icon"
1256
+ }, /* @__PURE__ */ React.createElement(Icon, {
1257
+ size: 15
1258
+ })), /* @__PURE__ */ React.createElement("span", {
1259
+ className: "trm-page-line-text"
1260
+ }, t("pageLine", { name: page.title })), /* @__PURE__ */ React.createElement("span", {
1261
+ className: "trm-page-line-open"
1262
+ }, t("openPage", { name: page.title }), /* @__PURE__ */ React.createElement(Chevron, {
1263
+ size: 14
1264
+ })));
1265
+ }
1266
+ function RoomView({ room, head, onBack }) {
1267
+ const Back = icon("ArrowLeft");
1268
+ const chat = book.chat(room.id);
1269
+ const lines = useLines(room);
1270
+ const list = React.useRef(null);
1271
+ const stuck = React.useRef(true);
1272
+ const self = room.members.find((member) => member.self);
1273
+ const nameOf = (line) => room.members.find((member) => member.member === line.from)?.name ?? line.name;
1274
+ React.useLayoutEffect(() => {
1275
+ const element = list.current;
1276
+ if (element && stuck.current) {
1277
+ element.scrollTop = element.scrollHeight;
1278
+ }
1279
+ }, [lines]);
1280
+ React.useEffect(() => {
1281
+ if (pi.ui.Stack) {
1282
+ return;
1283
+ }
1284
+ return pi.onRoomEvent?.((event) => book.heard(event), { messages: true });
1285
+ }, []);
1286
+ React.useEffect(() => {
1287
+ const last = lines[lines.length - 1];
1288
+ if (last) {
1289
+ book.see(room.id, last.at);
1290
+ }
1291
+ }, [lines, room.id]);
1292
+ const say = async (text) => {
1293
+ if (!self || !chat) {
1294
+ throw new Error(t("connecting"));
1295
+ }
1296
+ stuck.current = true;
1297
+ await chat.say(text, self);
1298
+ };
1299
+ return /* @__PURE__ */ React.createElement("div", {
1300
+ className: "trm-room-page"
1301
+ }, head && /* @__PURE__ */ React.createElement("div", {
1302
+ className: "trm-room-head"
1303
+ }, onBack && /* @__PURE__ */ React.createElement("button", {
1304
+ type: "button",
1305
+ className: "trm-icon",
1306
+ title: t("back"),
1307
+ "aria-label": t("back"),
1308
+ onClick: onBack
1309
+ }, /* @__PURE__ */ React.createElement(Back, {
1310
+ size: 18
1311
+ })), /* @__PURE__ */ React.createElement(RoomTitle, {
1312
+ room
1313
+ }), /* @__PURE__ */ React.createElement(MembersButton, null)), /* @__PURE__ */ React.createElement(PageLine, {
1314
+ room
1315
+ }), /* @__PURE__ */ React.createElement("div", {
1316
+ className: "trm-chat ta-conversation",
1317
+ ref: list,
1318
+ onScroll: (event) => {
1319
+ const element = event.currentTarget;
1320
+ stuck.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48;
1321
+ }
1322
+ }, /* @__PURE__ */ React.createElement("div", {
1323
+ className: "trm-chat-col"
1324
+ }, lines.length === 0 && /* @__PURE__ */ React.createElement("div", {
1325
+ className: "trm-chat-empty"
1326
+ }, t("chatEmpty")), lines.map((line, index) => {
1327
+ const before = lines[index - 1];
1328
+ const separator = !before || line.at - before.at > PAUSE_MS;
1329
+ const first = separator || before.from !== line.from || line.at - before.at > RUN_MS;
1330
+ const other = room.members.find((member) => member.member === line.from);
1331
+ return /* @__PURE__ */ React.createElement(React.Fragment, {
1332
+ key: line.id
1333
+ }, separator && /* @__PURE__ */ React.createElement("div", {
1334
+ className: "trm-chat-time"
1335
+ }, time(line.at)), line.from === self?.member ? /* @__PURE__ */ React.createElement("div", {
1336
+ className: "ta-message ta-user trm-mine",
1337
+ title: time(line.at)
1338
+ }, /* @__PURE__ */ React.createElement("div", {
1339
+ className: "ta-bubble"
1340
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
1341
+ text: line.text
1342
+ }))) : /* @__PURE__ */ React.createElement("div", {
1343
+ className: `trm-msg${first ? " trm-first" : ""}`
1344
+ }, /* @__PURE__ */ React.createElement("div", {
1345
+ className: "trm-msg-face"
1346
+ }, first && /* @__PURE__ */ React.createElement(Face, {
1347
+ id: other?.id ?? line.from,
1348
+ name: nameOf(line),
1349
+ size: 30
1350
+ })), /* @__PURE__ */ React.createElement("div", {
1351
+ className: "trm-msg-col"
1352
+ }, first && /* @__PURE__ */ React.createElement("div", {
1353
+ className: "trm-msg-name"
1354
+ }, nameOf(line)), /* @__PURE__ */ React.createElement("div", {
1355
+ className: "trm-msg-bubble",
1356
+ title: time(line.at)
1357
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
1358
+ text: line.text
1359
+ })))));
1360
+ }))), /* @__PURE__ */ React.createElement("div", {
1361
+ className: "trm-chat-bottom"
1362
+ }, /* @__PURE__ */ React.createElement(pi.ui.Composer, {
1363
+ placeholder: t("chatPlaceholder"),
1364
+ onSend: say
1365
+ })));
1366
+ }
1367
+
1368
+ // web-src/members-view.tsx
1369
+ function MemberRow({ room, member }) {
1370
+ const Remove = icon("X");
1371
+ const tags = [member.self ? t("you") : "", member.owner ? t("owner") : "", member.guest ? t("guestTag") : ""].filter(Boolean);
1372
+ return /* @__PURE__ */ React.createElement("li", {
1373
+ className: "trm-member"
1374
+ }, /* @__PURE__ */ React.createElement(Face, {
1375
+ id: member.id,
1376
+ name: member.name,
1377
+ size: 32,
1378
+ online: member.online
1379
+ }), /* @__PURE__ */ React.createElement("span", {
1380
+ className: "trm-member-text"
1381
+ }, /* @__PURE__ */ React.createElement("span", {
1382
+ className: "trm-member-name"
1383
+ }, /* @__PURE__ */ React.createElement("span", {
1384
+ className: "trm-ellipsis"
1385
+ }, member.name), tags.map((tag) => /* @__PURE__ */ React.createElement("span", {
1386
+ key: tag,
1387
+ className: "trm-tag"
1388
+ }, tag))), /* @__PURE__ */ React.createElement("span", {
1389
+ className: `trm-member-detail${member.online ? " trm-live" : ""}`
1390
+ }, member.online ? t("online") : t("offline"))), room.owner && !member.self && /* @__PURE__ */ React.createElement("button", {
1391
+ type: "button",
1392
+ className: "trm-icon trm-danger trm-member-action",
1393
+ title: t("remove"),
1394
+ "aria-label": t("remove"),
1395
+ onClick: () => void confirmThen(t("removeTitle", { name: member.name, title: room.title }), t("removeHint"), t("remove"), async () => rooms()?.removeMember(room.id, member.member))
1396
+ }, /* @__PURE__ */ React.createElement(Remove, {
1397
+ size: 15
1398
+ })));
1399
+ }
1400
+ function SettingRow({ label, value, onClick }) {
1401
+ const Chevron = icon("ChevronRight");
1402
+ return /* @__PURE__ */ React.createElement("button", {
1403
+ type: "button",
1404
+ className: "trm-setting",
1405
+ onClick
1406
+ }, /* @__PURE__ */ React.createElement("span", {
1407
+ className: "trm-setting-label"
1408
+ }, label), value && /* @__PURE__ */ React.createElement("span", {
1409
+ className: "trm-setting-value trm-ellipsis"
1410
+ }, value), /* @__PURE__ */ React.createElement(Chevron, {
1411
+ size: 15
1412
+ }));
1413
+ }
1414
+ function MembersView() {
1415
+ const { identity } = useBook();
1416
+ const room = useOpened();
1417
+ const page = usePageOf(room ?? { view: undefined });
1418
+ if (!room) {
1419
+ return /* @__PURE__ */ React.createElement("div", {
1420
+ className: "trm-panel"
1421
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1422
+ title: t("noRoomOpen")
1423
+ }));
1424
+ }
1425
+ const Plus = icon("Plus");
1426
+ const online = room.members.filter((member) => member.online).length;
1427
+ return /* @__PURE__ */ React.createElement("div", {
1428
+ className: "trm-panel"
1429
+ }, /* @__PURE__ */ React.createElement("div", {
1430
+ className: "trm-panel-scroll"
1431
+ }, /* @__PURE__ */ React.createElement("div", {
1432
+ className: "trm-panel-top"
1433
+ }, /* @__PURE__ */ React.createElement(RoomFace, {
1434
+ room,
1435
+ size: 44
1436
+ }), /* @__PURE__ */ React.createElement("span", {
1437
+ className: "trm-panel-title"
1438
+ }, /* @__PURE__ */ React.createElement("strong", {
1439
+ className: "trm-ellipsis"
1440
+ }, room.title), /* @__PURE__ */ React.createElement("span", {
1441
+ className: "trm-ellipsis"
1442
+ }, room.owner ? t("ownRoom") : t("roomOf", { name: room.ownerName })))), /* @__PURE__ */ React.createElement("div", {
1443
+ className: "trm-panel-label"
1444
+ }, t("membersCount", { n: room.members.length, online })), /* @__PURE__ */ React.createElement("ul", {
1445
+ className: "trm-panel-members"
1446
+ }, room.owner && /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
1447
+ type: "button",
1448
+ className: "trm-member trm-member-add",
1449
+ onClick: () => openInvite(room)
1450
+ }, /* @__PURE__ */ React.createElement("span", {
1451
+ className: "trm-member-plus"
1452
+ }, /* @__PURE__ */ React.createElement(Plus, {
1453
+ size: 16
1454
+ })), /* @__PURE__ */ React.createElement("span", {
1455
+ className: "trm-member-text"
1456
+ }, /* @__PURE__ */ React.createElement("span", {
1457
+ className: "trm-member-name"
1458
+ }, t("invite")), /* @__PURE__ */ React.createElement("span", {
1459
+ className: "trm-member-detail"
1460
+ }, t("inviteLine"))))), room.members.map((member) => /* @__PURE__ */ React.createElement(MemberRow, {
1461
+ key: member.member,
1462
+ room,
1463
+ member
1464
+ }))), /* @__PURE__ */ React.createElement("div", {
1465
+ className: "trm-panel-sep"
1466
+ }), page && room.view && /* @__PURE__ */ React.createElement(SettingRow, {
1467
+ label: t("openPage", { name: page.title }),
1468
+ onClick: () => void pi.ui.showView(room.view)
1469
+ }), /* @__PURE__ */ React.createElement(SettingRow, {
1470
+ label: t("me"),
1471
+ value: identity?.name,
1472
+ onClick: () => void rename()
1473
+ })), /* @__PURE__ */ React.createElement("div", {
1474
+ className: "trm-panel-foot"
1475
+ }, /* @__PURE__ */ React.createElement("button", {
1476
+ type: "button",
1477
+ className: "trm-link trm-danger",
1478
+ onClick: () => void leaveRoom(room).then((left) => left && book.set({ opened: undefined }))
1479
+ }, room.owner ? t("close") : t("leave"))));
1480
+ }
1481
+
1482
+ // web-src/rooms-page.tsx
1483
+ function plain(text) {
1484
+ return text.replace(/```[\s\S]*?(```|$)/g, " ").replace(/[*_~`>#]+/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\s+/g, " ").trim();
1485
+ }
1486
+ function lastAt(room) {
1487
+ const lines = room.status === "member" ? book.chat(room.id)?.lines : undefined;
1488
+ return lines?.[lines.length - 1]?.at ?? room.joinedAt ?? room.createdAt;
1489
+ }
1490
+ function useSorted(list) {
1491
+ const ids = list.map((room) => room.id).join(",");
1492
+ const subscribe = React.useCallback((listener) => {
1493
+ const stops = list.filter((room) => room.status === "member").map((room) => book.chat(room.id)?.subscribe(listener));
1494
+ return () => {
1495
+ for (const stop of stops) {
1496
+ stop?.();
1497
+ }
1498
+ };
1499
+ }, [ids]);
1500
+ const order = React.useSyncExternalStore(subscribe, () => list.map((room) => `${room.id}:${lastAt(room)}`).join(","));
1501
+ return React.useMemo(() => [...list].sort((a, b) => Number(b.status === "member") - Number(a.status === "member") || lastAt(b) - lastAt(a)), [order, list]);
1502
+ }
1503
+ function RoomRow({ room, active, seen, openMenu }) {
1504
+ const lines = useLines(room);
1505
+ const page = usePageOf(room);
1506
+ const member = room.status === "member";
1507
+ const last = lines[lines.length - 1];
1508
+ const self = room.members.find((each) => each.self)?.member;
1509
+ const unread = member && unseen(room, lines, seen);
1510
+ const name = last && (room.members.find((each) => each.member === last.from)?.name ?? last.name);
1511
+ const preview = last ? last.from === self ? plain(last.text) : t("said", { name: name ?? "", text: plain(last.text) }) : statusLine(room);
1512
+ const menu = [
1513
+ member ? [
1514
+ ...room.owner ? [{ key: "invite", label: t("invite"), icon: icon("UserPlus"), run: () => openInvite(room) }] : [],
1515
+ ...page && room.view ? [{ key: "page", label: t("openPage", { name: page.title }), icon: page.icon, run: () => void pi.ui.showView(room.view) }] : []
1516
+ ] : [],
1517
+ [
1518
+ {
1519
+ key: "leave",
1520
+ label: !member ? t("forget") : room.owner ? t("close") : t("leave"),
1521
+ icon: icon("Trash2"),
1522
+ danger: true,
1523
+ run: () => void leaveRoom(room)
1524
+ }
1525
+ ]
1526
+ ];
1527
+ return /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
1528
+ type: "button",
1529
+ className: `trm-room${active ? " trm-active" : ""}${member ? "" : " trm-room-out"}`,
1530
+ "aria-current": active || undefined,
1531
+ onClick: (event) => member ? openRoom(room.id) : openMenu(event, menu),
1532
+ onContextMenu: (event) => openMenu(event, menu)
1533
+ }, /* @__PURE__ */ React.createElement(RoomFace, {
1534
+ room,
1535
+ unread
1536
+ }), /* @__PURE__ */ React.createElement("span", {
1537
+ className: "trm-room-text"
1538
+ }, /* @__PURE__ */ React.createElement("span", {
1539
+ className: "trm-room-line"
1540
+ }, /* @__PURE__ */ React.createElement("span", {
1541
+ className: "trm-room-name trm-ellipsis"
1542
+ }, room.title), page && /* @__PURE__ */ React.createElement("span", {
1543
+ className: "trm-kind"
1544
+ }, page.title), /* @__PURE__ */ React.createElement("span", {
1545
+ className: "trm-room-time"
1546
+ }, when(lastAt(room)))), /* @__PURE__ */ React.createElement("span", {
1547
+ className: `trm-room-preview trm-ellipsis${member ? "" : " trm-quiet"}`
1548
+ }, preview))));
1549
+ }
1550
+ function FriendRow({ friend, openMenu }) {
1551
+ const Remove = icon("Trash2");
1552
+ const remove = () => void confirmThen(t("removeFriendTitle", { name: friend.name }), t("removeFriendHint"), t("removeFriend"), async () => rooms()?.removeFriend(friend.id));
1553
+ return /* @__PURE__ */ React.createElement("li", {
1554
+ className: "trm-friend",
1555
+ onContextMenu: (event) => openMenu(event, [[{ key: "remove", label: t("removeFriend"), icon: Remove, danger: true, run: remove }]])
1556
+ }, /* @__PURE__ */ React.createElement(Face, {
1557
+ id: friend.id,
1558
+ name: friend.name,
1559
+ size: 36
1560
+ }), /* @__PURE__ */ React.createElement("span", {
1561
+ className: "trm-room-text"
1562
+ }, /* @__PURE__ */ React.createElement("span", {
1563
+ className: "trm-room-name trm-ellipsis"
1564
+ }, friend.name), /* @__PURE__ */ React.createElement("span", {
1565
+ className: "trm-room-preview trm-ellipsis"
1566
+ }, t("friendLine", { rooms: friend.rooms.slice(-3).reverse().join("、") }))), /* @__PURE__ */ React.createElement("button", {
1567
+ type: "button",
1568
+ className: "trm-icon trm-danger trm-hover-only",
1569
+ title: t("removeFriend"),
1570
+ "aria-label": t("removeFriend"),
1571
+ onClick: remove
1572
+ }, /* @__PURE__ */ React.createElement(Remove, {
1573
+ size: 15
1574
+ })));
1575
+ }
1576
+ function RoomList({ openMenu }) {
1577
+ const { identity, rooms: list, requests, friends, opened, seen } = useBook();
1578
+ const sorted = useSorted(list ?? []);
1579
+ return /* @__PURE__ */ React.createElement("div", {
1580
+ className: "trm-list"
1581
+ }, requests.length > 0 && /* @__PURE__ */ React.createElement("section", {
1582
+ className: "trm-section"
1583
+ }, /* @__PURE__ */ React.createElement("h3", null, t("requests")), /* @__PURE__ */ React.createElement("ul", {
1584
+ className: "trm-card"
1585
+ }, requests.map((request) => /* @__PURE__ */ React.createElement(RequestRow, {
1586
+ key: `${request.room}:${request.ask}`,
1587
+ request
1588
+ })))), /* @__PURE__ */ React.createElement("section", {
1589
+ className: "trm-section"
1590
+ }, list === undefined ? pi.ui.Skeleton ? /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
1591
+ rows: 3
1592
+ }) : null : sorted.length === 0 ? /* @__PURE__ */ React.createElement("p", {
1593
+ className: "trm-empty"
1594
+ }, t("emptyHint")) : /* @__PURE__ */ React.createElement("ul", {
1595
+ className: "trm-rooms"
1596
+ }, sorted.map((room) => /* @__PURE__ */ React.createElement(RoomRow, {
1597
+ key: room.id,
1598
+ room,
1599
+ active: room.id === opened,
1600
+ seen,
1601
+ openMenu
1602
+ })))), friends && friends.length > 0 && /* @__PURE__ */ React.createElement("section", {
1603
+ className: "trm-section"
1604
+ }, /* @__PURE__ */ React.createElement("h3", null, t("friends")), /* @__PURE__ */ React.createElement("ul", {
1605
+ className: "trm-rooms"
1606
+ }, friends.map((friend) => /* @__PURE__ */ React.createElement(FriendRow, {
1607
+ key: friend.id,
1608
+ friend,
1609
+ openMenu
1610
+ })))), identity && /* @__PURE__ */ React.createElement("p", {
1611
+ className: "trm-me"
1612
+ }, t("meLine", { name: identity.name }), /* @__PURE__ */ React.createElement("button", {
1613
+ type: "button",
1614
+ className: "trm-link",
1615
+ onClick: () => void rename()
1616
+ }, t("rename"))));
1617
+ }
1618
+ function addMenu() {
1619
+ return [
1620
+ [
1621
+ { key: "new", label: t("newRoom"), icon: icon("MessagesSquare"), run: () => void createRoom() },
1622
+ { key: "link", label: t("joinByLink"), icon: icon("Link"), run: () => void pasteLink() },
1623
+ ...pi.ui.scanCode ? [{ key: "scan", label: t("scan"), icon: icon("ScanLine"), run: () => void scanLink() }] : []
1624
+ ],
1625
+ [{ key: "name", label: t("me"), icon: icon("Pencil"), run: () => void rename() }]
1626
+ ];
1627
+ }
1628
+ function RoomsHead() {
1629
+ const compact = useCompact();
1630
+ const opened = useOpened();
1631
+ const [menu, openMenu] = pi.ui.useContextMenu();
1632
+ const Plus = icon("Plus");
1633
+ if (compact && opened && pi.ui.Stack) {
1634
+ return /* @__PURE__ */ React.createElement("div", {
1635
+ className: "trm-head"
1636
+ }, /* @__PURE__ */ React.createElement(RoomTitle, {
1637
+ room: opened
1638
+ }), /* @__PURE__ */ React.createElement("span", {
1639
+ className: "trm-head-end"
1640
+ }, /* @__PURE__ */ React.createElement(MembersButton, null)));
1641
+ }
1642
+ return /* @__PURE__ */ React.createElement("div", {
1643
+ className: "trm-head"
1644
+ }, /* @__PURE__ */ React.createElement("span", {
1645
+ className: "trm-head-title"
1646
+ }, t("roomsTitle")), rooms() && /* @__PURE__ */ React.createElement("span", {
1647
+ className: "trm-head-end"
1648
+ }, /* @__PURE__ */ React.createElement("button", {
1649
+ type: "button",
1650
+ className: "trm-icon",
1651
+ title: t("add"),
1652
+ "aria-label": t("add"),
1653
+ onClick: (event) => openMenu(event, addMenu())
1654
+ }, /* @__PURE__ */ React.createElement(Plus, {
1655
+ size: 18
1656
+ }))), menu);
1657
+ }
1658
+ function RoomsPage() {
1659
+ const compact = useCompact();
1660
+ const opened = useOpened();
1661
+ const [menu, openMenu] = pi.ui.useContextMenu();
1662
+ const [kept, setKept] = React.useState();
1663
+ React.useEffect(() => {
1664
+ if (opened) {
1665
+ setKept(opened);
1666
+ }
1667
+ }, [opened]);
1668
+ if (!rooms()) {
1669
+ return /* @__PURE__ */ React.createElement("div", {
1670
+ className: "trm-page"
1671
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1672
+ title: t("emptyTitle"),
1673
+ hint: t("oldApp")
1674
+ }));
1675
+ }
1676
+ const list = /* @__PURE__ */ React.createElement(RoomList, {
1677
+ openMenu
1678
+ });
1679
+ const close = () => book.set({ opened: undefined });
1680
+ if (!compact) {
1681
+ return /* @__PURE__ */ React.createElement("div", {
1682
+ className: "trm-split"
1683
+ }, /* @__PURE__ */ React.createElement("div", {
1684
+ className: "trm-split-list"
1685
+ }, list), /* @__PURE__ */ React.createElement("div", {
1686
+ className: "trm-split-room"
1687
+ }, opened ? /* @__PURE__ */ React.createElement(RoomView, {
1688
+ key: opened.id,
1689
+ room: opened,
1690
+ head: true
1691
+ }) : /* @__PURE__ */ React.createElement("p", {
1692
+ className: "trm-split-empty"
1693
+ }, t("pickRoom"))), menu);
1694
+ }
1695
+ const Stack = pi.ui.Stack;
1696
+ const shown = opened ?? kept;
1697
+ if (!Stack) {
1698
+ return opened ? /* @__PURE__ */ React.createElement(RoomView, {
1699
+ key: opened.id,
1700
+ room: opened,
1701
+ head: true,
1702
+ onBack: close
1703
+ }) : /* @__PURE__ */ React.createElement("div", {
1704
+ className: "trm-page"
1705
+ }, list, menu);
1706
+ }
1707
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Stack, {
1708
+ base: /* @__PURE__ */ React.createElement("div", {
1709
+ className: "trm-page"
1710
+ }, list),
1711
+ top: shown ? /* @__PURE__ */ React.createElement(RoomView, {
1712
+ key: shown.id,
1713
+ room: shown,
1714
+ head: false
1715
+ }) : null,
1716
+ open: !!opened,
1717
+ onClose: close
1718
+ }), menu);
1719
+ }
1720
+
1721
+ // web-src/style.ts
1722
+ var STYLE = `
1723
+ .trm-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1724
+ .trm-quiet { color: var(--ta-muted); }
1725
+ /* The head of the page (RoomsHead): the title in the middle, its buttons at the end */
1726
+ .trm-head { position: relative; display: flex; align-items: center; justify-content: center; flex: 1; min-width: 0; height: 100%; padding: 0 44px; }
1727
+ .trm-head-title { font-weight: 600; font-size: calc(14.5px * var(--ta-font-scale)); }
1728
+ .trm-head-end { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: flex; }
1729
+ .trm-head .trm-room-title { align-items: center; text-align: center; }
1730
+ /* The list, on a phone and beside a room */
1731
+ .trm-page { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overscroll-behavior: none; }
1732
+ .trm-page > .trm-list { max-width: 720px; margin: 0 auto; }
1733
+ .trm-list { display: flex; flex-direction: column; gap: 14px; padding: 8px 8px calc(24px + env(safe-area-inset-bottom)); box-sizing: border-box; }
1734
+ .trm-section h3 { margin: 6px 12px 6px; font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; color: var(--ta-muted); }
1735
+ .trm-empty { margin: 28px 20px; color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); line-height: 1.6; text-align: center; }
1736
+ .trm-card { margin: 0; padding: 2px 4px; list-style: none; border-radius: 14px; background: var(--ta-raised); }
1737
+ .trm-card .trm-row { padding: 10px 8px; }
1738
+ .trm-rooms { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 1px; }
1739
+ .trm-room { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; border-radius: 12px; background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 120ms; }
1740
+ @media (hover: hover) { .trm-room:hover, .trm-friend:hover, li.trm-member:hover, button.trm-member:hover { background: var(--ta-hover); } }
1741
+ .trm-room:active { background: var(--ta-hover); }
1742
+ .trm-room.trm-active { background: var(--ta-selected, var(--ta-hover-strong)); }
1743
+ .trm-room:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: -1px; }
1744
+ .trm-room-out { opacity: .62; }
1745
+ .trm-room-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
1746
+ .trm-room-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
1747
+ .trm-room-name { flex: 0 1 auto; font-size: calc(14.5px * var(--ta-font-scale)); font-weight: 500; line-height: calc(20px * var(--ta-font-scale)); }
1748
+ .trm-room-time { flex: none; margin-left: auto; padding-left: 8px; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
1749
+ .trm-room-preview { color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); }
1750
+ .trm-kind, .trm-tag { flex: none; align-self: center; padding: 0 6px; border-radius: 6px; background: var(--ta-chip, var(--ta-hover)); color: var(--ta-secondary); font-size: calc(10.5px * var(--ta-font-scale)); font-weight: 400; line-height: calc(17px * var(--ta-font-scale)); }
1751
+ .trm-tag-friend { background: var(--ta-tint-3); color: var(--ta-tint-ink-3); }
1752
+ .trm-friend { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px; }
1753
+ .trm-hover-only { opacity: 0; transition: opacity 120ms; }
1754
+ .trm-friend:hover .trm-hover-only, .trm-hover-only:focus-visible { opacity: 1; }
1755
+ @media (hover: none) { .trm-hover-only { display: none; } }
1756
+ .trm-me { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 0; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1757
+ .trm-link { padding: 2px 4px; border: 0; border-radius: 6px; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
1758
+ .trm-link:hover { background: var(--ta-hover); }
1759
+ .trm-link.trm-danger { color: var(--ta-red); }
1760
+ /* The faces: of one, a letter in a circle; of a room, those of up to four in a rounded square */
1761
+ .trm-face { position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 600; line-height: 1; user-select: none; }
1762
+ .trm-face i { position: absolute; right: -1px; bottom: -1px; width: 28%; height: 28%; min-width: 7px; min-height: 7px; border-radius: 50%; border: 2px solid var(--ta-main); }
1763
+ .trm-on { background: var(--ta-green); }
1764
+ .trm-off { background: var(--ta-border-field); }
1765
+ .trm-room-face { position: relative; flex: none; display: grid; grid-template-columns: repeat(2, auto); align-content: center; justify-content: center; gap: 2px; box-sizing: border-box; border-radius: 12px; background: var(--ta-hover-strong); user-select: none; }
1766
+ .trm-room-face[data-count="1"] { display: flex; background: none; }
1767
+ .trm-room-face[data-count="1"] .trm-room-face-cell { border-radius: 12px; }
1768
+ .trm-room-face[data-count="3"] .trm-room-face-cell:first-child { grid-column: span 2; justify-self: center; }
1769
+ .trm-room-face-cell { display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; font-weight: 600; line-height: 1; }
1770
+ .trm-room-face-mark { position: absolute; right: -4px; bottom: -4px; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--ta-raised); color: var(--ta-text); box-shadow: 0 0 0 2px var(--ta-main); }
1771
+ .trm-unread { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--ta-yellow); box-shadow: 0 0 0 2px var(--ta-main); }
1772
+ /* Beside each other, on a computer or a tablet */
1773
+ .trm-split { display: grid; grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); flex: 1; min-height: 0; height: 100%; }
1774
+ .trm-split-list { min-height: 0; overflow-y: auto; overscroll-behavior: none; border-right: 1px solid var(--ta-border-muted); }
1775
+ .trm-split-room { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
1776
+ .trm-split-empty { margin: auto; color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); }
1777
+ /* A room (room-view.tsx): a group chat, its head and its box */
1778
+ .trm-room-page { display: flex; flex-direction: column; flex: 1; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); }
1779
+ .trm-room-head { flex: none; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 6px 12px 6px 20px; box-sizing: border-box; border-bottom: 1px solid var(--ta-border-muted); }
1780
+ .trm-room-head .trm-room-title { flex: 1; }
1781
+ .trm-room-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
1782
+ .trm-room-title-text { display: flex; align-items: baseline; justify-content: inherit; gap: 4px; min-width: 0; max-width: 100%; font-weight: 600; font-size: calc(14.5px * var(--ta-font-scale)); }
1783
+ .trm-head .trm-room-title-text { justify-content: center; }
1784
+ .trm-room-count { flex: none; color: var(--ta-secondary); font-weight: 500; }
1785
+ .trm-room-sub { color: var(--ta-green); font-size: calc(11px * var(--ta-font-scale)); line-height: calc(15px * var(--ta-font-scale)); }
1786
+ .trm-room-sub.trm-quiet { color: var(--ta-muted); }
1787
+ .trm-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ta-secondary); cursor: pointer; -webkit-tap-highlight-color: transparent; }
1788
+ .trm-icon:hover:not(:disabled), .trm-on-icon { background: var(--ta-hover-strong); color: var(--ta-text); }
1789
+ .trm-icon.trm-danger:hover:not(:disabled) { color: var(--ta-red); }
1790
+ .trm-page-line { flex: none; display: flex; align-items: center; gap: 10px; width: calc(100% - 32px); max-width: calc(var(--ta-col) + 16px); margin: 10px auto 0; padding: 8px 10px 8px 8px; box-sizing: border-box; border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-side); color: var(--ta-text); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); text-align: left; cursor: pointer; transition: background 120ms; }
1791
+ .trm-page-line:hover { background: var(--ta-hover); }
1792
+ .trm-page-line-icon { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--ta-tint-3); color: var(--ta-tint-ink-3); }
1793
+ .trm-page-line-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-secondary); }
1794
+ .trm-page-line-open { display: inline-flex; align-items: center; gap: 2px; flex: none; color: var(--ta-link); font-weight: 500; }
1795
+ .trm-chat { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overflow-anchor: none; overscroll-behavior: none; }
1796
+ .trm-chat-col { display: flex; flex-direction: column; gap: 4px; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding: 12px 24px 12px; box-sizing: border-box; }
1797
+ .trm-chat-time { align-self: center; margin: 14px 0 6px; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
1798
+ .trm-chat-empty { margin: 14vh auto 0; max-width: 300px; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.6; text-align: center; }
1799
+ .trm-mine { margin: 6px 0 2px; }
1800
+ .trm-msg { display: flex; align-items: flex-start; gap: 10px; }
1801
+ .trm-msg.trm-first { margin-top: 10px; }
1802
+ .trm-msg-face { display: flex; justify-content: center; width: 30px; flex: none; }
1803
+ .trm-msg-col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(84%, var(--ta-col)); }
1804
+ .trm-msg-name { margin: 0 2px 4px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(16px * var(--ta-font-scale)); }
1805
+ .trm-msg-bubble { min-width: 0; max-width: 100%; padding: 9px 14px; border: 1px solid var(--ta-border-muted); border-radius: 5px 16px 16px 16px; background: var(--ta-side); color: var(--ta-body); line-height: 1.6; overflow-wrap: anywhere; }
1806
+ .trm-msg-bubble pre { max-width: 100%; overflow-x: auto; }
1807
+ .trm-chat-bottom { flex: none; width: 100%; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding: 8px 24px calc(16px + env(safe-area-inset-bottom)); box-sizing: border-box; }
1808
+ /* The members of the room shown (members-view.tsx), in the workbench */
1809
+ .trm-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); font-size: calc(13px * var(--ta-font-scale)); }
1810
+ .trm-panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; }
1811
+ .trm-panel-top { display: flex; align-items: center; gap: 12px; padding: 14px 10px 10px; }
1812
+ .trm-panel-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
1813
+ .trm-panel-title strong { font-size: calc(15px * var(--ta-font-scale)); font-weight: 600; }
1814
+ .trm-panel-title span { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1815
+ .trm-panel-label { padding: 10px 10px 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1816
+ .trm-panel-members { margin: 0; padding: 0; list-style: none; }
1817
+ .trm-member { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; box-sizing: border-box; border: 0; border-radius: 12px; background: none; color: var(--ta-text); font: inherit; text-align: left; }
1818
+ button.trm-member { cursor: pointer; }
1819
+ .trm-member-plus { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--ta-hover); color: var(--ta-secondary); }
1820
+ .trm-member-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
1821
+ .trm-member-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: calc(13.5px * var(--ta-font-scale)); font-weight: 500; }
1822
+ .trm-member-detail { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1823
+ .trm-member-detail.trm-live { color: var(--ta-green); }
1824
+ .trm-member-action { opacity: 0; transition: opacity 120ms; }
1825
+ .trm-member:hover .trm-member-action, .trm-member-action:focus-visible { opacity: 1; }
1826
+ @media (hover: none) { .trm-member-action { opacity: 1; } }
1827
+ .trm-panel-sep { height: 1px; margin: 8px 10px; background: var(--ta-border-muted); }
1828
+ .trm-setting { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: none; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; }
1829
+ .trm-setting:hover { background: var(--ta-hover); }
1830
+ .trm-setting > svg { flex: none; color: var(--ta-muted); }
1831
+ .trm-setting-label { flex: none; }
1832
+ .trm-setting-value { flex: 1; text-align: right; color: var(--ta-muted); }
1833
+ .trm-panel-foot { display: flex; justify-content: center; flex: none; padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--ta-border-muted); }
1834
+ .trm-panel-foot .trm-link { width: 100%; min-height: 36px; border-radius: 10px; font-weight: 500; }
1835
+ /* Dialogs */
1836
+ .trm-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; }
1837
+ .trm-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
1838
+ .trm-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1839
+ .trm-row-line { display: flex; align-items: center; gap: 4px; min-width: 0; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1840
+ .trm-rows { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
1841
+ .trm-answers { flex: none; display: flex; gap: 6px; }
1842
+ .trm-dialog { display: flex; flex-direction: column; gap: 12px; width: min(420px, calc(100vw - 48px)); }
1843
+ .trm-lead { margin: 0; line-height: 1.5; }
1844
+ .trm-note, .trm-hint { margin: 0; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.5; }
1845
+ .trm-hint { text-align: center; color: var(--ta-secondary); }
1846
+ .trm-error { margin: 0; color: var(--ta-red); font-size: calc(12.5px * var(--ta-font-scale)); }
1847
+ .trm-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
1848
+ .trm-center { justify-content: center; }
1849
+ .trm-join { display: flex; align-items: center; gap: 12px; }
1850
+ .trm-invite { align-items: stretch; }
1851
+ .trm-qr { align-self: center; width: 188px; padding: 10px; border-radius: 14px; background: #fff; border: 1px solid var(--ta-border-muted); }
1852
+ .trm-qr svg { display: block; width: 100%; height: auto; }
1853
+ .trm-link-box { padding: 8px 10px; border-radius: 8px; background: var(--ta-code); font-family: var(--ta-mono); font-size: calc(11.5px * var(--ta-font-scale)); color: var(--ta-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1854
+ .trm-dialog .trm-row { padding: 8px 0; }
1855
+ @media (max-width: 720px) {
1856
+ .trm-chat-col, .trm-chat-bottom { padding-left: 12px; padding-right: 12px; }
1857
+ .trm-msg-col { max-width: calc(100% - 40px); }
1858
+ .trm-page-line { width: calc(100% - 24px); }
1859
+ }
1860
+ @media (max-width: 480px) { .trm-answers .ta-button { padding-left: 10px; padding-right: 10px; } }
1861
+ @media (prefers-reduced-motion: reduce) { .trm-room, .trm-page-line { transition: none; } }
1862
+ `;
1863
+ function injectStyle() {
1864
+ const element = document.createElement("style");
1865
+ element.dataset.taPackage = "ta-rooms";
1866
+ element.textContent = STYLE;
1867
+ document.head.appendChild(element);
1868
+ return () => element.remove();
1869
+ }
1870
+
1871
+ // web-src/index.tsx
1872
+ var OPEN_WITHIN_MS = 15 * 60 * 1000;
1873
+ function tell(pi2, changes) {
1874
+ for (const { before, room } of changes) {
1875
+ if (before?.status === "waiting" && room.status === "member") {
1876
+ pi2.ui.notify(t("admitted", { title: room.title }));
1877
+ if (Date.now() - room.createdAt < OPEN_WITHIN_MS) {
1878
+ if (room.view) {
1879
+ pi2.ui.showView(room.view);
1880
+ } else {
1881
+ openRoom(room.id);
1882
+ }
1883
+ }
1884
+ } else if (before?.status === "waiting" && room.status === "refused") {
1885
+ pi2.ui.notify(t("refusedNotice", { by: room.ownerName, title: room.title }), "warning");
1886
+ } else if (before?.status === "member" && room.status === "gone") {
1887
+ pi2.ui.notify(room.reason === "removed" ? t("removedNotice", { title: room.title }) : t("closedNotice", { title: room.title }), "warning");
1888
+ if (book.get().opened === room.id) {
1889
+ book.set({ opened: undefined });
1890
+ }
1891
+ }
1892
+ }
1893
+ }
1894
+ function activate(pi2) {
1895
+ bind(pi2.React);
1896
+ bindPage(pi2);
1897
+ const removeStyle = injectStyle();
1898
+ pi2.registerView("rooms", { title: () => t("roomsTitle"), icon: icon("Users"), render: RoomsPage, head: RoomsHead, discover: true, order: 81 });
1899
+ pi2.registerView("members", { title: () => t("membersTitle"), icon: icon("Users"), render: MembersView, location: "panel", order: 90 });
1900
+ pi2.registerOpener((link) => {
1901
+ if (link.type !== "url" || !RelayHubUtil.is(link.url)) {
1902
+ return false;
1903
+ }
1904
+ openJoin(link.url);
1905
+ return true;
1906
+ }, { specific: true });
1907
+ const stop = pi2.onRoomEvent?.((event) => {
1908
+ if (event.type === "request") {
1909
+ book.load().then(() => openRequests());
1910
+ } else if (event.type === "rooms") {
1911
+ book.reload();
1912
+ } else {
1913
+ book.heard(event);
1914
+ }
1915
+ }, { messages: false, state: CHAT_STATE });
1916
+ book.onChange = (changes) => tell(pi2, changes);
1917
+ if (pi2.rooms) {
1918
+ book.load().then(() => {
1919
+ if (book.get().requests.length) {
1920
+ openRequests();
1921
+ }
1922
+ });
1923
+ }
1924
+ return () => {
1925
+ stop?.();
1926
+ book.onChange = undefined;
1927
+ removeStyle();
1928
+ };
1929
+ }
1930
+ export {
1931
+ activate as default
1932
+ };