@celljs/ta-relay 4.9.1 → 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.
Files changed (118) hide show
  1. package/README.en.md +29 -2
  2. package/README.md +29 -2
  3. package/esm/common/index.d.ts +10 -0
  4. package/esm/common/index.js +10 -0
  5. package/esm/common/relay-blobs.d.ts +54 -0
  6. package/esm/common/relay-blobs.js +153 -0
  7. package/esm/common/relay-card.d.ts +23 -0
  8. package/esm/common/relay-card.js +30 -0
  9. package/esm/common/relay-cipher.d.ts +15 -0
  10. package/esm/common/relay-cipher.js +62 -2
  11. package/esm/common/relay-content.d.ts +104 -0
  12. package/esm/common/relay-content.js +316 -0
  13. package/esm/common/relay-conversation.d.ts +59 -0
  14. package/esm/common/relay-conversation.js +9 -0
  15. package/esm/common/relay-files.d.ts +108 -0
  16. package/esm/common/relay-files.js +170 -0
  17. package/esm/common/relay-hub-util.d.ts +91 -0
  18. package/esm/common/relay-hub-util.js +164 -0
  19. package/esm/common/relay-hub.d.ts +125 -0
  20. package/esm/common/relay-hub.js +438 -0
  21. package/esm/common/relay-hubs.d.ts +271 -0
  22. package/esm/common/relay-hubs.js +844 -0
  23. package/esm/common/relay-identity.d.ts +46 -0
  24. package/esm/common/relay-identity.js +126 -0
  25. package/esm/common/relay-protocol.d.ts +217 -2
  26. package/esm/common/relay-protocol.js +53 -0
  27. package/esm/common/relay-room-chat.d.ts +80 -0
  28. package/esm/common/relay-room-chat.js +152 -0
  29. package/esm/common/relay-socket.d.ts +8 -0
  30. package/esm/common/relay-socket.js +33 -4
  31. package/esm/guest/guest-i18n.d.ts +47 -0
  32. package/esm/guest/guest-i18n.js +97 -0
  33. package/esm/guest/guest-style.d.ts +1 -0
  34. package/esm/guest/guest-style.js +78 -0
  35. package/esm/guest/guest.d.ts +1 -0
  36. package/esm/guest/guest.js +371 -0
  37. package/esm/node/index.d.ts +3 -0
  38. package/esm/node/index.js +3 -0
  39. package/esm/node/relay-files-host.d.ts +27 -0
  40. package/esm/node/relay-files-host.js +130 -0
  41. package/esm/node/relay-host.d.ts +35 -2
  42. package/esm/node/relay-host.js +150 -13
  43. package/esm/node/relay-hub-files.d.ts +12 -0
  44. package/esm/node/relay-hub-files.js +39 -0
  45. package/esm/node/relay-server.d.ts +46 -1
  46. package/esm/node/relay-server.js +227 -1
  47. package/esm/node/relay-store.d.ts +72 -0
  48. package/esm/node/relay-store.js +123 -2
  49. package/esm/node/relay-viewer.d.ts +7 -0
  50. package/esm/node/relay-viewer.js +33 -0
  51. package/esm/viewer/viewer-i18n.d.ts +56 -0
  52. package/esm/viewer/viewer-i18n.js +117 -0
  53. package/esm/viewer/viewer-markdown.d.ts +7 -0
  54. package/esm/viewer/viewer-markdown.js +198 -0
  55. package/esm/viewer/viewer-style.d.ts +1 -0
  56. package/esm/viewer/viewer-style.js +72 -0
  57. package/esm/viewer/viewer.d.ts +8 -0
  58. package/esm/viewer/viewer.js +378 -0
  59. package/lib/common/index.d.ts +10 -0
  60. package/lib/common/index.js +10 -0
  61. package/lib/common/relay-blobs.d.ts +55 -0
  62. package/lib/common/relay-blobs.js +157 -0
  63. package/lib/common/relay-card.d.ts +24 -0
  64. package/lib/common/relay-card.js +33 -0
  65. package/lib/common/relay-cipher.d.ts +15 -0
  66. package/lib/common/relay-cipher.js +63 -3
  67. package/lib/common/relay-content.d.ts +105 -0
  68. package/lib/common/relay-content.js +320 -0
  69. package/lib/common/relay-conversation.d.ts +60 -0
  70. package/lib/common/relay-conversation.js +12 -0
  71. package/lib/common/relay-files.d.ts +109 -0
  72. package/lib/common/relay-files.js +174 -0
  73. package/lib/common/relay-hub-util.d.ts +92 -0
  74. package/lib/common/relay-hub-util.js +167 -0
  75. package/lib/common/relay-hub.d.ts +126 -0
  76. package/lib/common/relay-hub.js +442 -0
  77. package/lib/common/relay-hubs.d.ts +272 -0
  78. package/lib/common/relay-hubs.js +848 -0
  79. package/lib/common/relay-identity.d.ts +47 -0
  80. package/lib/common/relay-identity.js +129 -0
  81. package/lib/common/relay-protocol.d.ts +217 -2
  82. package/lib/common/relay-protocol.js +54 -1
  83. package/lib/common/relay-room-chat.d.ts +81 -0
  84. package/lib/common/relay-room-chat.js +156 -0
  85. package/lib/common/relay-socket.d.ts +8 -0
  86. package/lib/common/relay-socket.js +32 -3
  87. package/lib/guest/guest-i18n.d.ts +48 -0
  88. package/lib/guest/guest-i18n.js +100 -0
  89. package/lib/guest/guest-style.d.ts +2 -0
  90. package/lib/guest/guest-style.js +81 -0
  91. package/lib/guest/guest.d.ts +2 -0
  92. package/lib/guest/guest.js +373 -0
  93. package/lib/node/index.d.ts +3 -0
  94. package/lib/node/index.js +3 -0
  95. package/lib/node/relay-files-host.d.ts +28 -0
  96. package/lib/node/relay-files-host.js +134 -0
  97. package/lib/node/relay-host.d.ts +35 -2
  98. package/lib/node/relay-host.js +149 -12
  99. package/lib/node/relay-hub-files.d.ts +13 -0
  100. package/lib/node/relay-hub-files.js +43 -0
  101. package/lib/node/relay-server.d.ts +46 -1
  102. package/lib/node/relay-server.js +226 -0
  103. package/lib/node/relay-store.d.ts +72 -0
  104. package/lib/node/relay-store.js +121 -0
  105. package/lib/node/relay-viewer.d.ts +8 -0
  106. package/lib/node/relay-viewer.js +32 -0
  107. package/lib/viewer/viewer-i18n.d.ts +57 -0
  108. package/lib/viewer/viewer-i18n.js +120 -0
  109. package/lib/viewer/viewer-markdown.d.ts +8 -0
  110. package/lib/viewer/viewer-markdown.js +201 -0
  111. package/lib/viewer/viewer-style.d.ts +2 -0
  112. package/lib/viewer/viewer-style.js +75 -0
  113. package/lib/viewer/viewer.d.ts +9 -0
  114. package/lib/viewer/viewer.js +381 -0
  115. package/package.json +5 -4
  116. package/viewer/frame.html +1 -0
  117. package/viewer/page.html +80 -0
  118. package/viewer/room.html +87 -0
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelayRoomChat = exports.RelayRoomChatUtil = exports.RELAY_CHAT_TEXT_MAX = exports.RELAY_CHAT_PARTS = exports.RELAY_CHAT_PART_BYTES = exports.RELAY_CHAT_KEY = void 0;
4
+ /** The keys of what is said, `chat:<member>:<n>`: each member writes only its own, so none can write as another. */
5
+ exports.RELAY_CHAT_KEY = 'chat:';
6
+ /** The bytes of JSON of one part at most, well under what the relay takes of a value once sealed. */
7
+ exports.RELAY_CHAT_PART_BYTES = 8 * 1024;
8
+ /** The parts of each member kept: the oldest is cleared as a new one starts. */
9
+ exports.RELAY_CHAT_PARTS = 6;
10
+ exports.RELAY_CHAT_TEXT_MAX = 2000;
11
+ const TRIES = 6;
12
+ var RelayRoomChatUtil;
13
+ (function (RelayRoomChatUtil) {
14
+ function key(member, part) {
15
+ return `${exports.RELAY_CHAT_KEY}${member}:${part}`;
16
+ }
17
+ RelayRoomChatUtil.key = key;
18
+ function parse(key) {
19
+ const match = /^chat:([^:]+):(\d+)$/.exec(key);
20
+ return match ? { member: match[1], part: Number(match[2]) } : undefined;
21
+ }
22
+ RelayRoomChatUtil.parse = parse;
23
+ /** The lines of a part, if its value is one and was written by the member of its key. */
24
+ function lines(member, value, by) {
25
+ if (by !== member || !Array.isArray(value)) {
26
+ return undefined;
27
+ }
28
+ const lines = [];
29
+ for (const line of value) {
30
+ if (line && typeof line.id === 'string' && typeof line.text === 'string' && typeof line.at === 'number') {
31
+ lines.push({ id: line.id, from: member, name: typeof line.name === 'string' ? line.name : '', text: line.text, at: line.at });
32
+ }
33
+ }
34
+ return lines;
35
+ }
36
+ RelayRoomChatUtil.lines = lines;
37
+ function stored(lines) {
38
+ return lines.map(({ id, name, text, at }) => ({ id, name, text, at }));
39
+ }
40
+ RelayRoomChatUtil.stored = stored;
41
+ function bytes(lines) {
42
+ return new TextEncoder().encode(JSON.stringify(lines)).length;
43
+ }
44
+ RelayRoomChatUtil.bytes = bytes;
45
+ function id() {
46
+ return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
47
+ }
48
+ RelayRoomChatUtil.id = id;
49
+ })(RelayRoomChatUtil || (exports.RelayRoomChatUtil = RelayRoomChatUtil = {}));
50
+ /**
51
+ * The group chat of a room (docs/design/ta-link.md 3.7; the Rooms page of Ta and the page of guests), in its shared state: what each member said is in parts of its
52
+ * own (`chat:<member>:<n>`), the latest added to on its version, a new one once it is full, the oldest cleared beyond
53
+ * {@link RELAY_CHAT_PARTS}. So it is there for whoever comes later, sealed as all of the state, and nobody writes as another.
54
+ */
55
+ class RelayRoomChat {
56
+ constructor(rooms, room) {
57
+ this.rooms = rooms;
58
+ this.room = room;
59
+ this.parts = new Map();
60
+ this.listeners = new Set();
61
+ this.all = [];
62
+ }
63
+ /** All that is said, the earliest first. */
64
+ get lines() {
65
+ return this.all;
66
+ }
67
+ subscribe(listener) {
68
+ this.listeners.add(listener);
69
+ return () => this.listeners.delete(listener);
70
+ }
71
+ async load() {
72
+ const state = await this.rooms.getState(this.room, exports.RELAY_CHAT_KEY);
73
+ this.parts.clear();
74
+ for (const [key, value] of Object.entries(state)) {
75
+ this.put(key, value);
76
+ }
77
+ this.changed();
78
+ }
79
+ /** A key of the room set, as its event tells: whether it was of the chat. */
80
+ heard(key, value) {
81
+ if (!RelayRoomChatUtil.parse(key)) {
82
+ return false;
83
+ }
84
+ const known = this.parts.get(key);
85
+ if (known && known.version >= value.version) {
86
+ return true;
87
+ }
88
+ this.put(key, value);
89
+ this.changed();
90
+ return true;
91
+ }
92
+ /** Says `text` as `self` (its member id and name); set again on what another client of the same Ta wrote first. */
93
+ async say(text, self) {
94
+ var _a;
95
+ var _b, _c;
96
+ const said = text.trim().slice(0, exports.RELAY_CHAT_TEXT_MAX);
97
+ if (!said) {
98
+ return;
99
+ }
100
+ for (let tries = 0; tries < TRIES; tries++) {
101
+ const latest = this.latest(self.member);
102
+ // After what it said last, even within the same millisecond: the lines of a member keep their order.
103
+ const last = latest === null || latest === void 0 ? void 0 : latest.lines[latest.lines.length - 1];
104
+ const at = Math.max(Date.now(), ((_b = last === null || last === void 0 ? void 0 : last.at) !== null && _b !== void 0 ? _b : 0) + 1);
105
+ const line = { id: RelayRoomChatUtil.id(), from: self.member, name: self.name, text: said, at };
106
+ const fits = latest && RelayRoomChatUtil.bytes(RelayRoomChatUtil.stored([...latest.lines, line])) <= exports.RELAY_CHAT_PART_BYTES;
107
+ const part = !latest ? 0 : fits ? latest.part : latest.part + 1;
108
+ const lines = fits && latest ? [...latest.lines, line] : [line];
109
+ const key = RelayRoomChatUtil.key(self.member, part);
110
+ const value = RelayRoomChatUtil.stored(lines);
111
+ const result = await this.rooms.setState(this.room, key, value, (_c = (_a = this.parts.get(key)) === null || _a === void 0 ? void 0 : _a.version) !== null && _c !== void 0 ? _c : 0);
112
+ if (result.ok) {
113
+ this.put(key, { value, version: result.version, by: self.member });
114
+ this.changed();
115
+ if (part >= exports.RELAY_CHAT_PARTS) {
116
+ void this.clear(RelayRoomChatUtil.key(self.member, part - exports.RELAY_CHAT_PARTS));
117
+ }
118
+ return;
119
+ }
120
+ await this.load();
121
+ }
122
+ throw new Error('The room is busy: say it again.');
123
+ }
124
+ async clear(key) {
125
+ await this.rooms.setState(this.room, key, null).catch(() => undefined);
126
+ if (this.parts.delete(key)) {
127
+ this.changed();
128
+ }
129
+ }
130
+ latest(member) {
131
+ let latest;
132
+ for (const part of this.parts.values()) {
133
+ if (part.member === member && (!latest || part.part > latest.part)) {
134
+ latest = part;
135
+ }
136
+ }
137
+ return latest;
138
+ }
139
+ put(key, value) {
140
+ const parsed = RelayRoomChatUtil.parse(key);
141
+ const lines = parsed && value.value !== null ? RelayRoomChatUtil.lines(parsed.member, value.value, value.by) : undefined;
142
+ if (!parsed || !lines) {
143
+ this.parts.delete(key);
144
+ return;
145
+ }
146
+ this.parts.set(key, { ...parsed, lines, version: value.version });
147
+ }
148
+ changed() {
149
+ 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));
150
+ for (const listener of this.listeners) {
151
+ listener();
152
+ }
153
+ }
154
+ }
155
+ exports.RelayRoomChat = RelayRoomChat;
156
+ //# sourceMappingURL=relay-room-chat.js.map
@@ -5,6 +5,11 @@ export interface RelaySocketOptions {
5
5
  pingMs?: number;
6
6
  /** Default 15 seconds. */
7
7
  helloMs?: number;
8
+ /**
9
+ * For content shared (RelayContentUtil): this side proves first that it has the key, and the host sends
10
+ * nothing sealed before; a host that refuses says why in the clear (RelayRefusal), as the close's reason.
11
+ */
12
+ proveFirst?: boolean;
8
13
  }
9
14
  /**
10
15
  * A WebSocket to ta serve through a relay, for a paired device: it says hello, checks that the host has
@@ -13,6 +18,7 @@ export interface RelaySocketOptions {
13
18
  */
14
19
  export declare class RelaySocket {
15
20
  protected readonly pairing: RelayPairing;
21
+ protected readonly options: RelaySocketOptions;
16
22
  static readonly CONNECTING = 0;
17
23
  static readonly OPEN = 1;
18
24
  static readonly CLOSING = 2;
@@ -47,6 +53,8 @@ export declare class RelaySocket {
47
53
  send(text: string): void;
48
54
  close(code?: number, reason?: string): void;
49
55
  protected receive(text: string): Promise<void>;
56
+ /** The reason of a clear `refused` of the host, as RelayRefusal says it; `gone` when it says none of them. */
57
+ protected static refusal(text: string): string;
50
58
  /** The relay stopped answering: the connection is gone without a word, and closing it would wait for one. */
51
59
  protected ping(): void;
52
60
  /** Closed at once, rather than once the close is answered. */
@@ -20,6 +20,7 @@ class RelaySocket {
20
20
  constructor(pairing, options = {}) {
21
21
  var _a;
22
22
  this.pairing = pairing;
23
+ this.options = options;
23
24
  this.onopen = null;
24
25
  this.onmessage = null;
25
26
  this.onclose = null;
@@ -35,7 +36,13 @@ class RelaySocket {
35
36
  this.helloTimer = setTimeout(() => this.drop(relay_protocol_1.RelayCloseCode.TIMEOUT, 'The host did not answer.'), (_a = options.helloMs) !== null && _a !== void 0 ? _a : HELLO_MS);
36
37
  this.socket.onopen = () => {
37
38
  var _a;
38
- const hello = { t: 'hello', v: 1, device: pairing.device, nonce: relay_bytes_1.RelayBytes.toBase64(this.nonce) };
39
+ const hello = {
40
+ t: 'hello',
41
+ v: 1,
42
+ device: pairing.device,
43
+ nonce: relay_bytes_1.RelayBytes.toBase64(this.nonce),
44
+ ...(relay_cipher_1.RelayDeflate.supported() ? { z: 1 } : {}),
45
+ };
39
46
  this.socket.send(JSON.stringify(hello));
40
47
  this.pingTimer = setInterval(() => this.ping(), (_a = options.pingMs) !== null && _a !== void 0 ? _a : relay_protocol_1.RELAY_PING_MS);
41
48
  };
@@ -74,6 +81,11 @@ class RelaySocket {
74
81
  async receive(text) {
75
82
  var _a, _b;
76
83
  if (this.cipher) {
84
+ if (this.options.proveFirst && text.startsWith('{')) {
85
+ // Sealed frames are base64url: this is the host's refusal, in the clear, after the proof did not open.
86
+ this.drop(RelaySocket.REFUSED, RelaySocket.refusal(text));
87
+ return;
88
+ }
77
89
  try {
78
90
  const data = await this.cipher.open(text);
79
91
  (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, { data });
@@ -86,12 +98,19 @@ class RelaySocket {
86
98
  try {
87
99
  const welcome = JSON.parse(text);
88
100
  if (welcome.t !== 'ready') {
89
- throw new Error(welcome.reason);
101
+ this.drop(RelaySocket.REFUSED, this.options.proveFirst ? RelaySocket.refusal(text) : 'The host refused this device.');
102
+ return;
90
103
  }
91
104
  const cipher = await relay_cipher_1.RelayCipher.derive(relay_bytes_1.RelayBytes.fromBase64(this.pairing.key), this.nonce, relay_bytes_1.RelayBytes.fromBase64(welcome.nonce), 'client');
92
- if ((await cipher.open(welcome.proof)) !== relay_protocol_1.RELAY_PROOF) {
105
+ if (welcome.proof === undefined && this.options.proveFirst) {
106
+ // What the host sends next opens only if it has the key too.
107
+ this.socket.send(await cipher.seal(relay_protocol_1.RELAY_PROOF));
108
+ }
109
+ else if (welcome.proof === undefined || (await cipher.open(welcome.proof)) !== relay_protocol_1.RELAY_PROOF) {
93
110
  throw new Error('The host did not show the key.');
94
111
  }
112
+ // The messages after the proof, both ways.
113
+ cipher.compress = welcome.z === 1 && relay_cipher_1.RelayDeflate.supported();
95
114
  this.cipher = cipher;
96
115
  clearTimeout(this.helloTimer);
97
116
  this.state = OPEN;
@@ -102,6 +121,16 @@ class RelaySocket {
102
121
  this.drop(RelaySocket.REFUSED, 'The host refused this device.');
103
122
  }
104
123
  }
124
+ /** The reason of a clear `refused` of the host, as RelayRefusal says it; `gone` when it says none of them. */
125
+ static refusal(text) {
126
+ try {
127
+ const reason = JSON.parse(text).reason;
128
+ return reason === 'key' || reason === 'busy' ? reason : 'gone';
129
+ }
130
+ catch (_a) {
131
+ return 'gone';
132
+ }
133
+ }
105
134
  /** The relay stopped answering: the connection is gone without a word, and closing it would wait for one. */
106
135
  ping() {
107
136
  if (this.awaitingPong && this.ponged) {
@@ -0,0 +1,48 @@
1
+ declare const zh: {
2
+ title: string;
3
+ invalid: string;
4
+ invited: string;
5
+ joinHint: string;
6
+ name: string;
7
+ namePlaceholder: string;
8
+ join: string;
9
+ joining: string;
10
+ keep: string;
11
+ haveTa: string;
12
+ waiting: string;
13
+ waitingHint: string;
14
+ cancel: string;
15
+ refused: string;
16
+ again: string;
17
+ removed: string;
18
+ closed: string;
19
+ inviteGone: string;
20
+ own: string;
21
+ connecting: string;
22
+ online: string;
23
+ nobody: string;
24
+ onlineNow: string;
25
+ members: string;
26
+ owner: string;
27
+ you: string;
28
+ guest: string;
29
+ rename: string;
30
+ leave: string;
31
+ leaveAsk: string;
32
+ game: string;
33
+ empty: string;
34
+ placeholder: string;
35
+ send: string;
36
+ failed: string;
37
+ secure: string;
38
+ close: string;
39
+ };
40
+ export type GuestText = keyof typeof zh;
41
+ export declare namespace GuestI18n {
42
+ const chinese: boolean;
43
+ function t(id: GuestText, values?: Record<string, string | number>): string;
44
+ /** The time of a line: when today, else the day too. */
45
+ function time(at: number): string;
46
+ }
47
+ export {};
48
+ //# sourceMappingURL=guest-i18n.d.ts.map
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuestI18n = void 0;
4
+ const zh = {
5
+ title: 'Ta 房间',
6
+ invalid: '这不是一个完整的 Ta 房间邀请链接,请检查是否复制完整。',
7
+ invited: '{by}邀请你加入',
8
+ joinHint: '房主同意后,就能在这里和大家聊天。',
9
+ name: '你的名字',
10
+ namePlaceholder: '大家看到的名字',
11
+ join: '申请加入',
12
+ joining: '正在申请…',
13
+ keep: '你的名字和一把只属于这个浏览器的钥匙保存在本机;清除浏览器数据后要重新申请。',
14
+ haveTa: '装了 Ta?在 Ta 应用里扫码或粘贴这个链接,还能一起玩小镇等游戏。',
15
+ waiting: '已向{by}申请',
16
+ waitingHint: '等对方同意。可以先关掉页面,之后再打开这个链接。',
17
+ cancel: '取消申请',
18
+ refused: '{by}没有同意你加入',
19
+ again: '再申请一次',
20
+ removed: '你已被移出这个房间',
21
+ closed: '这个房间已被房主解散',
22
+ inviteGone: '邀请已失效,请向房主要一个新链接',
23
+ own: '这是你自己的房间,请在 Ta 里打开。',
24
+ connecting: '连接中…',
25
+ online: '另有 {n} 人在线',
26
+ nobody: '其他人都不在线',
27
+ onlineNow: '在线',
28
+ members: '成员',
29
+ owner: '房主',
30
+ you: '我',
31
+ guest: '网页访客',
32
+ rename: '修改我的名字',
33
+ leave: '退出房间',
34
+ leaveAsk: '退出「{title}」?退出后要有新的邀请才能再进来。',
35
+ game: '这个房间里有 Ta 的游戏,装了 Ta 才能一起玩;在这里可以聊天。',
36
+ empty: '还没有人说话。只有房间里的人能看到,中继保存的是密文。',
37
+ placeholder: '发消息',
38
+ send: '发送',
39
+ failed: '没发出去:{reason}',
40
+ secure: '端到端加密,中继看不到内容',
41
+ close: '关闭',
42
+ };
43
+ const en = {
44
+ title: 'A room of Ta',
45
+ invalid: 'This is not a whole link that invites into a room of Ta: check it was copied in full.',
46
+ invited: '{by} invites you to join',
47
+ joinHint: 'Once the owner lets you in, you chat with everyone here.',
48
+ name: 'Your name',
49
+ namePlaceholder: 'What everyone sees',
50
+ join: 'Ask to join',
51
+ joining: 'Asking…',
52
+ keep: 'Your name and a key of this browser alone are kept on this device; clear its data and you ask again.',
53
+ haveTa: 'Have Ta? Scan this link in the Ta app or paste it there, to play the Town and other games together too.',
54
+ waiting: 'Asked {by}',
55
+ waitingHint: 'They let you in. You may close the page and open this link again later.',
56
+ cancel: 'Cancel',
57
+ refused: '{by} did not let you in',
58
+ again: 'Ask again',
59
+ removed: 'You were taken out of this room',
60
+ closed: 'This room was closed by its owner',
61
+ inviteGone: 'The invitation no longer works: ask the owner for a new link',
62
+ own: 'This is a room of your own: open it in Ta.',
63
+ connecting: 'Connecting…',
64
+ online: '{n} more online',
65
+ nobody: 'Nobody else online',
66
+ onlineNow: 'Online',
67
+ members: 'Members',
68
+ owner: 'Owner',
69
+ you: 'You',
70
+ guest: 'Web guest',
71
+ rename: 'Change my name',
72
+ leave: 'Leave the room',
73
+ leaveAsk: 'Leave “{title}”? You come back only by a new invitation.',
74
+ game: 'This room plays a game of Ta, which takes Ta to play; here you chat.',
75
+ empty: 'Nothing said yet. Only those in the room read it: the relay keeps it sealed.',
76
+ placeholder: 'Message',
77
+ send: 'Send',
78
+ failed: 'Not sent: {reason}',
79
+ secure: 'End to end: the relay reads none of it',
80
+ close: 'Close',
81
+ };
82
+ var GuestI18n;
83
+ (function (GuestI18n) {
84
+ GuestI18n.chinese = typeof navigator !== 'undefined' && /^zh\b/i.test(navigator.language);
85
+ function t(id, values = {}) {
86
+ return (GuestI18n.chinese ? zh : en)[id].replace(/\{(\w+)\}/g, (_, name) => { var _a; return String((_a = values[name]) !== null && _a !== void 0 ? _a : ''); });
87
+ }
88
+ GuestI18n.t = t;
89
+ /** The time of a line: when today, else the day too. */
90
+ function time(at) {
91
+ const date = new Date(at);
92
+ const language = GuestI18n.chinese ? 'zh-CN' : undefined;
93
+ const clock = date.toLocaleTimeString(language, { hour: '2-digit', minute: '2-digit' });
94
+ return date.toDateString() === new Date().toDateString()
95
+ ? clock
96
+ : `${date.toLocaleDateString(language, { month: 'numeric', day: 'numeric' })} ${clock}`;
97
+ }
98
+ GuestI18n.time = time;
99
+ })(GuestI18n || (exports.GuestI18n = GuestI18n = {}));
100
+ //# sourceMappingURL=guest-i18n.js.map
@@ -0,0 +1,2 @@
1
+ export declare const GUEST_STYLE = "\n:root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--mine:#e7f6ec;--mine-fg:#14532d;--code:#f6f6f6;--accent:#16a34a;--red:#dc2626;--radius:16px}\n@media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#262626;--mine:#1f3a2a;--mine-fg:#d1fae5;--code:#232323;--accent:#4ade80;--red:#f87171}}\n*{box-sizing:border-box}\nhtml,body{margin:0;height:100%;background:var(--bg);color:var(--fg);font:15px/1.6 -apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;-webkit-font-smoothing:antialiased;overscroll-behavior:none}\nbutton{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}\n.app{display:flex;flex-direction:column;height:100dvh;max-width:760px;margin:0 auto}\n.top{flex:none;display:flex;align-items:center;gap:10px;min-height:54px;padding:8px 10px 8px 16px;padding-top:max(8px,env(safe-area-inset-top));border-bottom:1px solid var(--line);background:var(--bg)}\n.logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}\n.heading{flex:1;min-width:0;display:flex;flex-direction:column}\n.heading b{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.heading b span{color:var(--muted);font-weight:500;margin-left:4px}\n.heading small{font-size:11.5px;line-height:15px;color:var(--accent)}\n.heading small.quiet{color:var(--muted)}\n.icon{flex:none;width:36px;height:36px;display:grid;place-items:center;border:0;border-radius:10px;background:none;font-size:20px;line-height:1;color:var(--muted)}\n.icon:hover{background:var(--soft);color:var(--fg)}\n.center{flex:1;display:flex;flex-direction:column;justify-content:center;padding:24px 22px calc(32px + env(safe-area-inset-bottom));max-width:440px;width:100%;margin:0 auto;gap:14px}\n.card-face{align-self:center}\n.lead{margin:0;text-align:center;color:var(--muted);font-size:14px}\n.room-name{margin:0;text-align:center;font-size:21px;font-weight:600;line-height:1.35;word-break:break-word}\n.hint{margin:0;text-align:center;color:var(--muted);font-size:13px}\n.small{margin:0;color:var(--faint);font-size:12px;line-height:1.55;text-align:center}\nlabel.field{display:flex;flex-direction:column;gap:6px;font-size:13px;color:var(--muted);margin-top:6px}\ninput.text{font:inherit;font-size:16px;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:11px 13px;outline:none}\ninput.text:focus{border-color:var(--accent)}\n.primary{border:0;border-radius:12px;padding:12px 16px;background:#16a34a;color:#fff;font-weight:600;font-size:15px}\n.primary:disabled{opacity:.55;cursor:default}\n.plain{border:0;background:none;color:var(--muted);font-size:13.5px;padding:8px}\n.plain:hover{color:var(--fg)}\n.danger{color:var(--red)}\n.error{margin:0;text-align:center;color:var(--red);font-size:13px}\n.spin{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);animation:spin .9s linear infinite;align-self:center}\n@keyframes spin{to{transform:rotate(360deg)}}\n.face{flex:none;display:inline-grid;place-items:center;border-radius:50%;font-weight:600;line-height:1;user-select:none;position:relative}\n.t0{background:#e6f4ea;color:#166534}.t1{background:#e8f0fe;color:#1d4ed8}.t2{background:#fdf0e6;color:#b45309}.t3{background:#f3e8fd;color:#7e22ce}.t4{background:#fde8ef;color:#be185d}.t5{background:#e6f6f8;color:#0e7490}\n@media (prefers-color-scheme:dark){.t0{background:#1d3326;color:#86efac}.t1{background:#1e2a44;color:#93c5fd}.t2{background:#3a2a1a;color:#fdba74}.t3{background:#2e2140;color:#d8b4fe}.t4{background:#3a1f2a;color:#f9a8d4}.t5{background:#173238;color:#67e8f9}}\n.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(--bg);background:var(--faint)}\n.face i.on{background:var(--accent)}\n.banner{flex:none;margin:10px 14px 0;padding:8px 12px;border-radius:12px;background:var(--soft);color:var(--muted);font-size:12.5px;line-height:1.5}\n.list{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;overscroll-behavior:none;padding:10px 14px 12px;display:flex;flex-direction:column;gap:4px}\n.empty{margin:14vh auto 0;max-width:300px;text-align:center;color:var(--muted);font-size:13px}\n.when{align-self:center;margin:14px 0 6px;color:var(--faint);font-size:11.5px;font-variant-numeric:tabular-nums}\n.msg{display:flex;align-items:flex-start;gap:10px}\n.msg.first{margin-top:10px}\n.msg .slot{width:32px;flex:none;display:flex;justify-content:center}\n.msg .col{display:flex;flex-direction:column;align-items:flex-start;min-width:0;max-width:calc(100% - 84px)}\n.msg .who{margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}\n.bubble{min-width:0;max-width:100%;padding:8px 13px;border-radius:5px var(--radius) var(--radius) var(--radius);background:var(--bubble);word-break:break-word}\n.mine{display:flex;justify-content:flex-end;margin:6px 0 2px}\n.mine .bubble{max-width:78%;border-radius:var(--radius) 5px var(--radius) var(--radius);background:var(--mine);color:var(--mine-fg)}\n.bubble>:first-child{margin-top:0}.bubble>:last-child{margin-bottom:0}\n.bubble p{margin:0 0 .6em}\n.bubble ul,.bubble ol{margin:0 0 .6em;padding-left:1.3em}\n.bubble a{color:inherit;text-decoration:underline;text-underline-offset:2px}\n.bubble code{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--code);padding:1px 4px;border-radius:5px}\n.bubble pre{margin:0 0 .6em;padding:8px 10px;background:var(--code);border-radius:10px;overflow-x:auto}\n.bubble pre code{background:none;padding:0}\n.bubble blockquote{margin:0 0 .6em;padding-left:10px;border-left:3px solid var(--line);color:var(--muted)}\n.failed{align-self:flex-end;color:var(--red);font-size:12px;margin:2px 4px 0}\n.box{flex:none;display:flex;align-items:flex-end;gap:8px;padding:8px 12px calc(10px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--bg)}\n.box textarea{flex:1;min-width:0;resize:none;max-height:160px;font:inherit;font-size:16px;line-height:1.45;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:18px;padding:8px 14px;outline:none}\n.box textarea:focus{border-color:var(--accent)}\n.box .primary{flex:none;border-radius:18px;padding:8px 16px;min-height:40px}\n.foot{flex:none;text-align:center;color:var(--faint);font-size:11px;padding:0 0 6px}\n.sheet{position:fixed;inset:0;z-index:5;display:flex;align-items:flex-end;justify-content:center;background:rgba(0,0,0,.32)}\n.sheet .panel{width:100%;max-width:520px;max-height:80dvh;overflow-y:auto;background:var(--bg);border-radius:18px 18px 0 0;padding:14px 8px calc(14px + env(safe-area-inset-bottom))}\n@media (min-width:700px){.sheet{align-items:center}.sheet .panel{border-radius:18px}}\n.panel h3{margin:4px 14px 8px;font-size:13px;font-weight:500;color:var(--muted)}\n.member{display:flex;align-items:center;gap:10px;padding:8px 12px}\n.member .nm{flex:1;min-width:0;display:flex;align-items:center;gap:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.tag{flex:none;padding:0 6px;border-radius:6px;background:var(--soft);color:var(--muted);font-size:11px;line-height:18px}\n.member .st{font-size:12px;color:var(--muted)}\n.member .st.on{color:var(--accent)}\n.row{display:block;width:100%;text-align:left;border:0;background:none;padding:12px 14px;border-radius:12px;font-size:14.5px}\n.row:hover{background:var(--soft)}\n.sep{height:1px;margin:6px 12px;background:var(--line)}\n";
2
+ //# sourceMappingURL=guest-style.d.ts.map
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GUEST_STYLE = void 0;
4
+ exports.GUEST_STYLE = `
5
+ :root{color-scheme:light dark;--bg:#fff;--fg:#1f1f1f;--muted:#737373;--faint:#a3a3a3;--line:#ececec;--soft:#f5f5f5;--bubble:#f2f2f2;--mine:#e7f6ec;--mine-fg:#14532d;--code:#f6f6f6;--accent:#16a34a;--red:#dc2626;--radius:16px}
6
+ @media (prefers-color-scheme:dark){:root{--bg:#191919;--fg:#ececec;--muted:#a3a3a3;--faint:#6b6b6b;--line:#2c2c2c;--soft:#222;--bubble:#262626;--mine:#1f3a2a;--mine-fg:#d1fae5;--code:#232323;--accent:#4ade80;--red:#f87171}}
7
+ *{box-sizing:border-box}
8
+ html,body{margin:0;height:100%;background:var(--bg);color:var(--fg);font:15px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased;overscroll-behavior:none}
9
+ button{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}
10
+ .app{display:flex;flex-direction:column;height:100dvh;max-width:760px;margin:0 auto}
11
+ .top{flex:none;display:flex;align-items:center;gap:10px;min-height:54px;padding:8px 10px 8px 16px;padding-top:max(8px,env(safe-area-inset-top));border-bottom:1px solid var(--line);background:var(--bg)}
12
+ .logo{width:26px;height:26px;border-radius:8px;background:var(--fg);color:var(--bg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:none}
13
+ .heading{flex:1;min-width:0;display:flex;flex-direction:column}
14
+ .heading b{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
15
+ .heading b span{color:var(--muted);font-weight:500;margin-left:4px}
16
+ .heading small{font-size:11.5px;line-height:15px;color:var(--accent)}
17
+ .heading small.quiet{color:var(--muted)}
18
+ .icon{flex:none;width:36px;height:36px;display:grid;place-items:center;border:0;border-radius:10px;background:none;font-size:20px;line-height:1;color:var(--muted)}
19
+ .icon:hover{background:var(--soft);color:var(--fg)}
20
+ .center{flex:1;display:flex;flex-direction:column;justify-content:center;padding:24px 22px calc(32px + env(safe-area-inset-bottom));max-width:440px;width:100%;margin:0 auto;gap:14px}
21
+ .card-face{align-self:center}
22
+ .lead{margin:0;text-align:center;color:var(--muted);font-size:14px}
23
+ .room-name{margin:0;text-align:center;font-size:21px;font-weight:600;line-height:1.35;word-break:break-word}
24
+ .hint{margin:0;text-align:center;color:var(--muted);font-size:13px}
25
+ .small{margin:0;color:var(--faint);font-size:12px;line-height:1.55;text-align:center}
26
+ label.field{display:flex;flex-direction:column;gap:6px;font-size:13px;color:var(--muted);margin-top:6px}
27
+ input.text{font:inherit;font-size:16px;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:11px 13px;outline:none}
28
+ input.text:focus{border-color:var(--accent)}
29
+ .primary{border:0;border-radius:12px;padding:12px 16px;background:#16a34a;color:#fff;font-weight:600;font-size:15px}
30
+ .primary:disabled{opacity:.55;cursor:default}
31
+ .plain{border:0;background:none;color:var(--muted);font-size:13.5px;padding:8px}
32
+ .plain:hover{color:var(--fg)}
33
+ .danger{color:var(--red)}
34
+ .error{margin:0;text-align:center;color:var(--red);font-size:13px}
35
+ .spin{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);animation:spin .9s linear infinite;align-self:center}
36
+ @keyframes spin{to{transform:rotate(360deg)}}
37
+ .face{flex:none;display:inline-grid;place-items:center;border-radius:50%;font-weight:600;line-height:1;user-select:none;position:relative}
38
+ .t0{background:#e6f4ea;color:#166534}.t1{background:#e8f0fe;color:#1d4ed8}.t2{background:#fdf0e6;color:#b45309}.t3{background:#f3e8fd;color:#7e22ce}.t4{background:#fde8ef;color:#be185d}.t5{background:#e6f6f8;color:#0e7490}
39
+ @media (prefers-color-scheme:dark){.t0{background:#1d3326;color:#86efac}.t1{background:#1e2a44;color:#93c5fd}.t2{background:#3a2a1a;color:#fdba74}.t3{background:#2e2140;color:#d8b4fe}.t4{background:#3a1f2a;color:#f9a8d4}.t5{background:#173238;color:#67e8f9}}
40
+ .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(--bg);background:var(--faint)}
41
+ .face i.on{background:var(--accent)}
42
+ .banner{flex:none;margin:10px 14px 0;padding:8px 12px;border-radius:12px;background:var(--soft);color:var(--muted);font-size:12.5px;line-height:1.5}
43
+ .list{flex:1;min-height:0;overflow-y:auto;overflow-x:hidden;overscroll-behavior:none;padding:10px 14px 12px;display:flex;flex-direction:column;gap:4px}
44
+ .empty{margin:14vh auto 0;max-width:300px;text-align:center;color:var(--muted);font-size:13px}
45
+ .when{align-self:center;margin:14px 0 6px;color:var(--faint);font-size:11.5px;font-variant-numeric:tabular-nums}
46
+ .msg{display:flex;align-items:flex-start;gap:10px}
47
+ .msg.first{margin-top:10px}
48
+ .msg .slot{width:32px;flex:none;display:flex;justify-content:center}
49
+ .msg .col{display:flex;flex-direction:column;align-items:flex-start;min-width:0;max-width:calc(100% - 84px)}
50
+ .msg .who{margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}
51
+ .bubble{min-width:0;max-width:100%;padding:8px 13px;border-radius:5px var(--radius) var(--radius) var(--radius);background:var(--bubble);word-break:break-word}
52
+ .mine{display:flex;justify-content:flex-end;margin:6px 0 2px}
53
+ .mine .bubble{max-width:78%;border-radius:var(--radius) 5px var(--radius) var(--radius);background:var(--mine);color:var(--mine-fg)}
54
+ .bubble>:first-child{margin-top:0}.bubble>:last-child{margin-bottom:0}
55
+ .bubble p{margin:0 0 .6em}
56
+ .bubble ul,.bubble ol{margin:0 0 .6em;padding-left:1.3em}
57
+ .bubble a{color:inherit;text-decoration:underline;text-underline-offset:2px}
58
+ .bubble code{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--code);padding:1px 4px;border-radius:5px}
59
+ .bubble pre{margin:0 0 .6em;padding:8px 10px;background:var(--code);border-radius:10px;overflow-x:auto}
60
+ .bubble pre code{background:none;padding:0}
61
+ .bubble blockquote{margin:0 0 .6em;padding-left:10px;border-left:3px solid var(--line);color:var(--muted)}
62
+ .failed{align-self:flex-end;color:var(--red);font-size:12px;margin:2px 4px 0}
63
+ .box{flex:none;display:flex;align-items:flex-end;gap:8px;padding:8px 12px calc(10px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--bg)}
64
+ .box textarea{flex:1;min-width:0;resize:none;max-height:160px;font:inherit;font-size:16px;line-height:1.45;color:var(--fg);background:var(--soft);border:1px solid var(--line);border-radius:18px;padding:8px 14px;outline:none}
65
+ .box textarea:focus{border-color:var(--accent)}
66
+ .box .primary{flex:none;border-radius:18px;padding:8px 16px;min-height:40px}
67
+ .foot{flex:none;text-align:center;color:var(--faint);font-size:11px;padding:0 0 6px}
68
+ .sheet{position:fixed;inset:0;z-index:5;display:flex;align-items:flex-end;justify-content:center;background:rgba(0,0,0,.32)}
69
+ .sheet .panel{width:100%;max-width:520px;max-height:80dvh;overflow-y:auto;background:var(--bg);border-radius:18px 18px 0 0;padding:14px 8px calc(14px + env(safe-area-inset-bottom))}
70
+ @media (min-width:700px){.sheet{align-items:center}.sheet .panel{border-radius:18px}}
71
+ .panel h3{margin:4px 14px 8px;font-size:13px;font-weight:500;color:var(--muted)}
72
+ .member{display:flex;align-items:center;gap:10px;padding:8px 12px}
73
+ .member .nm{flex:1;min-width:0;display:flex;align-items:center;gap:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
74
+ .tag{flex:none;padding:0 6px;border-radius:6px;background:var(--soft);color:var(--muted);font-size:11px;line-height:18px}
75
+ .member .st{font-size:12px;color:var(--muted)}
76
+ .member .st.on{color:var(--accent)}
77
+ .row{display:block;width:100%;text-align:left;border:0;background:none;padding:12px 14px;border-radius:12px;font-size:14.5px}
78
+ .row:hover{background:var(--soft)}
79
+ .sep{height:1px;margin:6px 12px;background:var(--line)}
80
+ `;
81
+ //# sourceMappingURL=guest-style.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=guest.d.ts.map