@celljs/ta-relay 4.10.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +13 -1
- package/README.md +13 -1
- package/esm/common/index.d.ts +11 -0
- package/esm/common/index.js +11 -0
- package/esm/common/relay-blobs.d.ts +54 -0
- package/esm/common/relay-blobs.js +153 -0
- package/esm/common/relay-card.d.ts +23 -0
- package/esm/common/relay-card.js +30 -0
- package/esm/common/relay-content.d.ts +104 -0
- package/esm/common/relay-content.js +316 -0
- package/esm/common/relay-conversation.d.ts +59 -0
- package/esm/common/relay-conversation.js +9 -0
- package/esm/common/relay-faces.d.ts +32 -0
- package/esm/common/relay-faces.js +208 -0
- package/esm/common/relay-hub-util.d.ts +91 -0
- package/esm/common/relay-hub-util.js +164 -0
- package/esm/common/relay-hub.d.ts +125 -0
- package/esm/common/relay-hub.js +438 -0
- package/esm/common/relay-hubs-connection.d.ts +98 -0
- package/esm/common/relay-hubs-connection.js +505 -0
- package/esm/common/relay-hubs-protocol.d.ts +130 -0
- package/esm/common/relay-hubs-protocol.js +2 -0
- package/esm/common/relay-hubs.d.ts +61 -0
- package/esm/common/relay-hubs.js +351 -0
- package/esm/common/relay-identity.d.ts +46 -0
- package/esm/common/relay-identity.js +126 -0
- package/esm/common/relay-protocol.d.ts +211 -2
- package/esm/common/relay-protocol.js +53 -0
- package/esm/common/relay-room-chat.d.ts +109 -0
- package/esm/common/relay-room-chat.js +176 -0
- package/esm/common/relay-socket.d.ts +8 -0
- package/esm/common/relay-socket.js +23 -2
- package/esm/guest/guest-i18n.d.ts +50 -0
- package/esm/guest/guest-i18n.js +103 -0
- package/esm/guest/guest-style.d.ts +1 -0
- package/esm/guest/guest-style.js +85 -0
- package/esm/guest/guest.d.ts +1 -0
- package/esm/guest/guest.js +384 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/node/relay-host.d.ts +25 -3
- package/esm/node/relay-host.js +115 -4
- package/esm/node/relay-hub-files.d.ts +12 -0
- package/esm/node/relay-hub-files.js +39 -0
- package/esm/node/relay-server.d.ts +46 -1
- package/esm/node/relay-server.js +227 -1
- package/esm/node/relay-store.d.ts +72 -0
- package/esm/node/relay-store.js +123 -2
- package/esm/node/relay-viewer.d.ts +7 -0
- package/esm/node/relay-viewer.js +33 -0
- package/esm/viewer/viewer-i18n.d.ts +56 -0
- package/esm/viewer/viewer-i18n.js +117 -0
- package/esm/viewer/viewer-markdown.d.ts +7 -0
- package/esm/viewer/viewer-markdown.js +198 -0
- package/esm/viewer/viewer-style.d.ts +1 -0
- package/esm/viewer/viewer-style.js +72 -0
- package/esm/viewer/viewer.d.ts +8 -0
- package/esm/viewer/viewer.js +378 -0
- package/lib/common/index.d.ts +11 -0
- package/lib/common/index.js +11 -0
- package/lib/common/relay-blobs.d.ts +55 -0
- package/lib/common/relay-blobs.js +157 -0
- package/lib/common/relay-card.d.ts +24 -0
- package/lib/common/relay-card.js +33 -0
- package/lib/common/relay-content.d.ts +105 -0
- package/lib/common/relay-content.js +320 -0
- package/lib/common/relay-conversation.d.ts +60 -0
- package/lib/common/relay-conversation.js +12 -0
- package/lib/common/relay-faces.d.ts +33 -0
- package/lib/common/relay-faces.js +211 -0
- package/lib/common/relay-hub-util.d.ts +92 -0
- package/lib/common/relay-hub-util.js +167 -0
- package/lib/common/relay-hub.d.ts +126 -0
- package/lib/common/relay-hub.js +442 -0
- package/lib/common/relay-hubs-connection.d.ts +99 -0
- package/lib/common/relay-hubs-connection.js +510 -0
- package/lib/common/relay-hubs-protocol.d.ts +131 -0
- package/lib/common/relay-hubs-protocol.js +3 -0
- package/lib/common/relay-hubs.d.ts +62 -0
- package/lib/common/relay-hubs.js +355 -0
- package/lib/common/relay-identity.d.ts +47 -0
- package/lib/common/relay-identity.js +129 -0
- package/lib/common/relay-protocol.d.ts +211 -2
- package/lib/common/relay-protocol.js +54 -1
- package/lib/common/relay-room-chat.d.ts +110 -0
- package/lib/common/relay-room-chat.js +180 -0
- package/lib/common/relay-socket.d.ts +8 -0
- package/lib/common/relay-socket.js +23 -2
- package/lib/guest/guest-i18n.d.ts +51 -0
- package/lib/guest/guest-i18n.js +106 -0
- package/lib/guest/guest-style.d.ts +2 -0
- package/lib/guest/guest-style.js +88 -0
- package/lib/guest/guest.d.ts +2 -0
- package/lib/guest/guest.js +386 -0
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.js +2 -0
- package/lib/node/relay-host.d.ts +25 -3
- package/lib/node/relay-host.js +115 -4
- package/lib/node/relay-hub-files.d.ts +13 -0
- package/lib/node/relay-hub-files.js +43 -0
- package/lib/node/relay-server.d.ts +46 -1
- package/lib/node/relay-server.js +226 -0
- package/lib/node/relay-store.d.ts +72 -0
- package/lib/node/relay-store.js +121 -0
- package/lib/node/relay-viewer.d.ts +8 -0
- package/lib/node/relay-viewer.js +32 -0
- package/lib/viewer/viewer-i18n.d.ts +57 -0
- package/lib/viewer/viewer-i18n.js +120 -0
- package/lib/viewer/viewer-markdown.d.ts +8 -0
- package/lib/viewer/viewer-markdown.js +201 -0
- package/lib/viewer/viewer-style.d.ts +2 -0
- package/lib/viewer/viewer-style.js +75 -0
- package/lib/viewer/viewer.d.ts +9 -0
- package/lib/viewer/viewer.js +381 -0
- package/package.json +5 -4
- package/viewer/frame.html +1 -0
- package/viewer/page.html +80 -0
- package/viewer/room.html +94 -0
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
doubleOf: string;
|
|
30
|
+
double: string;
|
|
31
|
+
agentOf: string;
|
|
32
|
+
rename: string;
|
|
33
|
+
leave: string;
|
|
34
|
+
leaveAsk: string;
|
|
35
|
+
game: string;
|
|
36
|
+
empty: string;
|
|
37
|
+
placeholder: string;
|
|
38
|
+
send: string;
|
|
39
|
+
failed: string;
|
|
40
|
+
secure: string;
|
|
41
|
+
close: string;
|
|
42
|
+
};
|
|
43
|
+
export type GuestText = keyof typeof zh;
|
|
44
|
+
export declare namespace GuestI18n {
|
|
45
|
+
const chinese: boolean;
|
|
46
|
+
function t(id: GuestText, values?: Record<string, string | number>): string;
|
|
47
|
+
/** The time of a line: when today, else the day too. */
|
|
48
|
+
function time(at: number): string;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const zh = {
|
|
2
|
+
title: 'Ta 房间',
|
|
3
|
+
invalid: '这不是一个完整的 Ta 房间邀请链接,请检查是否复制完整。',
|
|
4
|
+
invited: '{by}邀请你加入',
|
|
5
|
+
joinHint: '房主同意后,就能在这里和大家聊天。',
|
|
6
|
+
name: '你的名字',
|
|
7
|
+
namePlaceholder: '大家看到的名字',
|
|
8
|
+
join: '申请加入',
|
|
9
|
+
joining: '正在申请…',
|
|
10
|
+
keep: '你的名字和一把只属于这个浏览器的钥匙保存在本机;清除浏览器数据后要重新申请。',
|
|
11
|
+
haveTa: '装了 Ta?在 Ta 应用里扫码或粘贴这个链接,还能一起玩小镇等游戏。',
|
|
12
|
+
waiting: '已向{by}申请',
|
|
13
|
+
waitingHint: '等对方同意。可以先关掉页面,之后再打开这个链接。',
|
|
14
|
+
cancel: '取消申请',
|
|
15
|
+
refused: '{by}没有同意你加入',
|
|
16
|
+
again: '再申请一次',
|
|
17
|
+
removed: '你已被移出这个房间',
|
|
18
|
+
closed: '这个房间已被房主解散',
|
|
19
|
+
inviteGone: '邀请已失效,请向房主要一个新链接',
|
|
20
|
+
own: '这是你自己的房间,请在 Ta 里打开。',
|
|
21
|
+
connecting: '连接中…',
|
|
22
|
+
online: '另有 {n} 人在线',
|
|
23
|
+
nobody: '其他人都不在线',
|
|
24
|
+
onlineNow: '在线',
|
|
25
|
+
members: '成员',
|
|
26
|
+
owner: '房主',
|
|
27
|
+
you: '我',
|
|
28
|
+
guest: '网页访客',
|
|
29
|
+
doubleOf: '{name}的分身',
|
|
30
|
+
double: '分身',
|
|
31
|
+
agentOf: '{name}的智能体',
|
|
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
|
+
doubleOf: "{name}'s double",
|
|
72
|
+
double: 'Double',
|
|
73
|
+
agentOf: "{name}'s agent",
|
|
74
|
+
rename: 'Change my name',
|
|
75
|
+
leave: 'Leave the room',
|
|
76
|
+
leaveAsk: 'Leave “{title}”? You come back only by a new invitation.',
|
|
77
|
+
game: 'This room plays a game of Ta, which takes Ta to play; here you chat.',
|
|
78
|
+
empty: 'Nothing said yet. Only those in the room read it: the relay keeps it sealed.',
|
|
79
|
+
placeholder: 'Message',
|
|
80
|
+
send: 'Send',
|
|
81
|
+
failed: 'Not sent: {reason}',
|
|
82
|
+
secure: 'End to end: the relay reads none of it',
|
|
83
|
+
close: 'Close',
|
|
84
|
+
};
|
|
85
|
+
export var GuestI18n;
|
|
86
|
+
(function (GuestI18n) {
|
|
87
|
+
GuestI18n.chinese = typeof navigator !== 'undefined' && /^zh\b/i.test(navigator.language);
|
|
88
|
+
function t(id, values = {}) {
|
|
89
|
+
return (GuestI18n.chinese ? zh : en)[id].replace(/\{(\w+)\}/g, (_, name) => { var _a; return String((_a = values[name]) !== null && _a !== void 0 ? _a : ''); });
|
|
90
|
+
}
|
|
91
|
+
GuestI18n.t = t;
|
|
92
|
+
/** The time of a line: when today, else the day too. */
|
|
93
|
+
function time(at) {
|
|
94
|
+
const date = new Date(at);
|
|
95
|
+
const language = GuestI18n.chinese ? 'zh-CN' : undefined;
|
|
96
|
+
const clock = date.toLocaleTimeString(language, { hour: '2-digit', minute: '2-digit' });
|
|
97
|
+
return date.toDateString() === new Date().toDateString()
|
|
98
|
+
? clock
|
|
99
|
+
: `${date.toLocaleDateString(language, { month: 'numeric', day: 'numeric' })} ${clock}`;
|
|
100
|
+
}
|
|
101
|
+
GuestI18n.time = time;
|
|
102
|
+
})(GuestI18n || (GuestI18n = {}));
|
|
103
|
+
//# sourceMappingURL=guest-i18n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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-flex;position:relative;user-select:none}\n.face svg{display:block;overflow:visible}\n.ta-face-eyes{transform-box:fill-box;transform-origin:center;animation:blink 5.2s infinite}\n.face[data-face=\"1\"] .ta-face-eyes,.face[data-face=\"5\"] .ta-face-eyes,.face[data-face=\"9\"] .ta-face-eyes,.face[data-face=\"13\"] .ta-face-eyes{animation-delay:-1.7s}\n.face[data-face=\"2\"] .ta-face-eyes,.face[data-face=\"6\"] .ta-face-eyes,.face[data-face=\"10\"] .ta-face-eyes,.face[data-face=\"14\"] .ta-face-eyes{animation-delay:-3.1s}\n.face[data-face=\"3\"] .ta-face-eyes,.face[data-face=\"7\"] .ta-face-eyes,.face[data-face=\"11\"] .ta-face-eyes,.face[data-face=\"15\"] .ta-face-eyes{animation-delay:-4.4s}\n@keyframes blink{0%,94%,100%{transform:scaleY(1)}97%{transform:scaleY(.1)}}\n@media (prefers-reduced-motion:reduce){.face *{animation:none!important}}\n@media (prefers-color-scheme:dark){.face[data-face=\"11\"] .ta-face-body>g>circle{fill:#4a4a52}}\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{display:flex;align-items:center;gap:6px;margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}\n.msg.double .bubble{border:1px dashed var(--soft);background:none}\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";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export const GUEST_STYLE = `
|
|
2
|
+
: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}
|
|
3
|
+
@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}}
|
|
4
|
+
*{box-sizing:border-box}
|
|
5
|
+
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}
|
|
6
|
+
button{font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}
|
|
7
|
+
.app{display:flex;flex-direction:column;height:100dvh;max-width:760px;margin:0 auto}
|
|
8
|
+
.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)}
|
|
9
|
+
.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}
|
|
10
|
+
.heading{flex:1;min-width:0;display:flex;flex-direction:column}
|
|
11
|
+
.heading b{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
12
|
+
.heading b span{color:var(--muted);font-weight:500;margin-left:4px}
|
|
13
|
+
.heading small{font-size:11.5px;line-height:15px;color:var(--accent)}
|
|
14
|
+
.heading small.quiet{color:var(--muted)}
|
|
15
|
+
.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)}
|
|
16
|
+
.icon:hover{background:var(--soft);color:var(--fg)}
|
|
17
|
+
.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}
|
|
18
|
+
.card-face{align-self:center}
|
|
19
|
+
.lead{margin:0;text-align:center;color:var(--muted);font-size:14px}
|
|
20
|
+
.room-name{margin:0;text-align:center;font-size:21px;font-weight:600;line-height:1.35;word-break:break-word}
|
|
21
|
+
.hint{margin:0;text-align:center;color:var(--muted);font-size:13px}
|
|
22
|
+
.small{margin:0;color:var(--faint);font-size:12px;line-height:1.55;text-align:center}
|
|
23
|
+
label.field{display:flex;flex-direction:column;gap:6px;font-size:13px;color:var(--muted);margin-top:6px}
|
|
24
|
+
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}
|
|
25
|
+
input.text:focus{border-color:var(--accent)}
|
|
26
|
+
.primary{border:0;border-radius:12px;padding:12px 16px;background:#16a34a;color:#fff;font-weight:600;font-size:15px}
|
|
27
|
+
.primary:disabled{opacity:.55;cursor:default}
|
|
28
|
+
.plain{border:0;background:none;color:var(--muted);font-size:13.5px;padding:8px}
|
|
29
|
+
.plain:hover{color:var(--fg)}
|
|
30
|
+
.danger{color:var(--red)}
|
|
31
|
+
.error{margin:0;text-align:center;color:var(--red);font-size:13px}
|
|
32
|
+
.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}
|
|
33
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
34
|
+
.face{flex:none;display:inline-flex;position:relative;user-select:none}
|
|
35
|
+
.face svg{display:block;overflow:visible}
|
|
36
|
+
.ta-face-eyes{transform-box:fill-box;transform-origin:center;animation:blink 5.2s infinite}
|
|
37
|
+
.face[data-face="1"] .ta-face-eyes,.face[data-face="5"] .ta-face-eyes,.face[data-face="9"] .ta-face-eyes,.face[data-face="13"] .ta-face-eyes{animation-delay:-1.7s}
|
|
38
|
+
.face[data-face="2"] .ta-face-eyes,.face[data-face="6"] .ta-face-eyes,.face[data-face="10"] .ta-face-eyes,.face[data-face="14"] .ta-face-eyes{animation-delay:-3.1s}
|
|
39
|
+
.face[data-face="3"] .ta-face-eyes,.face[data-face="7"] .ta-face-eyes,.face[data-face="11"] .ta-face-eyes,.face[data-face="15"] .ta-face-eyes{animation-delay:-4.4s}
|
|
40
|
+
@keyframes blink{0%,94%,100%{transform:scaleY(1)}97%{transform:scaleY(.1)}}
|
|
41
|
+
@media (prefers-reduced-motion:reduce){.face *{animation:none!important}}
|
|
42
|
+
@media (prefers-color-scheme:dark){.face[data-face="11"] .ta-face-body>g>circle{fill:#4a4a52}}
|
|
43
|
+
.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)}
|
|
44
|
+
.face i.on{background:var(--accent)}
|
|
45
|
+
.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}
|
|
46
|
+
.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}
|
|
47
|
+
.empty{margin:14vh auto 0;max-width:300px;text-align:center;color:var(--muted);font-size:13px}
|
|
48
|
+
.when{align-self:center;margin:14px 0 6px;color:var(--faint);font-size:11.5px;font-variant-numeric:tabular-nums}
|
|
49
|
+
.msg{display:flex;align-items:flex-start;gap:10px}
|
|
50
|
+
.msg.first{margin-top:10px}
|
|
51
|
+
.msg .slot{width:32px;flex:none;display:flex;justify-content:center}
|
|
52
|
+
.msg .col{display:flex;flex-direction:column;align-items:flex-start;min-width:0;max-width:calc(100% - 84px)}
|
|
53
|
+
.msg .who{display:flex;align-items:center;gap:6px;margin:0 2px 4px;color:var(--muted);font-size:12px;line-height:16px}
|
|
54
|
+
.msg.double .bubble{border:1px dashed var(--soft);background:none}
|
|
55
|
+
.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}
|
|
56
|
+
.mine{display:flex;justify-content:flex-end;margin:6px 0 2px}
|
|
57
|
+
.mine .bubble{max-width:78%;border-radius:var(--radius) 5px var(--radius) var(--radius);background:var(--mine);color:var(--mine-fg)}
|
|
58
|
+
.bubble>:first-child{margin-top:0}.bubble>:last-child{margin-bottom:0}
|
|
59
|
+
.bubble p{margin:0 0 .6em}
|
|
60
|
+
.bubble ul,.bubble ol{margin:0 0 .6em;padding-left:1.3em}
|
|
61
|
+
.bubble a{color:inherit;text-decoration:underline;text-underline-offset:2px}
|
|
62
|
+
.bubble code{font:13px ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--code);padding:1px 4px;border-radius:5px}
|
|
63
|
+
.bubble pre{margin:0 0 .6em;padding:8px 10px;background:var(--code);border-radius:10px;overflow-x:auto}
|
|
64
|
+
.bubble pre code{background:none;padding:0}
|
|
65
|
+
.bubble blockquote{margin:0 0 .6em;padding-left:10px;border-left:3px solid var(--line);color:var(--muted)}
|
|
66
|
+
.failed{align-self:flex-end;color:var(--red);font-size:12px;margin:2px 4px 0}
|
|
67
|
+
.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)}
|
|
68
|
+
.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}
|
|
69
|
+
.box textarea:focus{border-color:var(--accent)}
|
|
70
|
+
.box .primary{flex:none;border-radius:18px;padding:8px 16px;min-height:40px}
|
|
71
|
+
.foot{flex:none;text-align:center;color:var(--faint);font-size:11px;padding:0 0 6px}
|
|
72
|
+
.sheet{position:fixed;inset:0;z-index:5;display:flex;align-items:flex-end;justify-content:center;background:rgba(0,0,0,.32)}
|
|
73
|
+
.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))}
|
|
74
|
+
@media (min-width:700px){.sheet{align-items:center}.sheet .panel{border-radius:18px}}
|
|
75
|
+
.panel h3{margin:4px 14px 8px;font-size:13px;font-weight:500;color:var(--muted)}
|
|
76
|
+
.member{display:flex;align-items:center;gap:10px;padding:8px 12px}
|
|
77
|
+
.member .nm{flex:1;min-width:0;display:flex;align-items:center;gap:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
78
|
+
.tag{flex:none;padding:0 6px;border-radius:6px;background:var(--soft);color:var(--muted);font-size:11px;line-height:18px}
|
|
79
|
+
.member .st{font-size:12px;color:var(--muted)}
|
|
80
|
+
.member .st.on{color:var(--accent)}
|
|
81
|
+
.row{display:block;width:100%;text-align:left;border:0;background:none;padding:12px 14px;border-radius:12px;font-size:14.5px}
|
|
82
|
+
.row:hover{background:var(--soft)}
|
|
83
|
+
.sep{height:1px;margin:6px 12px;background:var(--line)}
|
|
84
|
+
`;
|
|
85
|
+
//# sourceMappingURL=guest-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { FaceUtil } from '../common/relay-faces.js';
|
|
2
|
+
import { RelayHubUtil } from '../common/relay-hub-util.js';
|
|
3
|
+
import { RelayHubs } from '../common/relay-hubs.js';
|
|
4
|
+
import { RelayRoomChat } from '../common/relay-room-chat.js';
|
|
5
|
+
import { ViewerMarkdown } from '../viewer/viewer-markdown.js';
|
|
6
|
+
import { GuestI18n } from './guest-i18n.js';
|
|
7
|
+
import { GUEST_STYLE } from './guest-style.js';
|
|
8
|
+
/*
|
|
9
|
+
* The page a link inviting into a room opens in a browser (docs/design/ta-link.md 3.8): one without Ta asks to join
|
|
10
|
+
* as a guest, and once its owner lets it in, chats there. The keys are this browser's, kept for the relay's origin
|
|
11
|
+
* alone; the relay serves this page and never sees what is said.
|
|
12
|
+
*/
|
|
13
|
+
const { t } = GuestI18n;
|
|
14
|
+
const el = ViewerMarkdown.el;
|
|
15
|
+
const NAMED = 'ta-guest:named';
|
|
16
|
+
/** A new run after this long without a word of the same member; a line with the time after a longer pause. */
|
|
17
|
+
const RUN_MS = 5 * 60 * 1000;
|
|
18
|
+
const PAUSE_MS = 15 * 60 * 1000;
|
|
19
|
+
/** What a guest keeps: the storage of this browser, for the origin of the relay alone. */
|
|
20
|
+
class BrowserStore {
|
|
21
|
+
read(name) {
|
|
22
|
+
try {
|
|
23
|
+
const text = localStorage.getItem(`ta-guest:${name}`);
|
|
24
|
+
return text ? JSON.parse(text) : undefined;
|
|
25
|
+
}
|
|
26
|
+
catch (_a) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
write(name, value) {
|
|
31
|
+
try {
|
|
32
|
+
localStorage.setItem(`ta-guest:${name}`, JSON.stringify(value));
|
|
33
|
+
}
|
|
34
|
+
catch (_a) {
|
|
35
|
+
// A browser that keeps nothing (a private window that is full): this visit alone.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function div(className, ...children) {
|
|
40
|
+
const node = el('div');
|
|
41
|
+
node.className = className;
|
|
42
|
+
node.append(...children);
|
|
43
|
+
return node;
|
|
44
|
+
}
|
|
45
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
46
|
+
function svg(node) {
|
|
47
|
+
var _a;
|
|
48
|
+
const element = document.createElementNS(SVG, node.tag);
|
|
49
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
50
|
+
element.setAttribute(name, String(value));
|
|
51
|
+
}
|
|
52
|
+
element.append(...((_a = node.children) !== null && _a !== void 0 ? _a : []).map(svg));
|
|
53
|
+
return element;
|
|
54
|
+
}
|
|
55
|
+
/** The face of one in the room, as Ta draws it (FaceUtil.art); a dot at its corner when told whether online. */
|
|
56
|
+
function face(id, size, online) {
|
|
57
|
+
const shown = FaceUtil.of(id);
|
|
58
|
+
const node = el('span');
|
|
59
|
+
node.className = 'face';
|
|
60
|
+
node.dataset.face = String(shown);
|
|
61
|
+
node.style.cssText = `width:${size}px;height:${size}px`;
|
|
62
|
+
const picture = svg({ tag: 'svg', attrs: { viewBox: '0 0 40 40', width: size, height: size, 'aria-hidden': 'true' }, children: [FaceUtil.art(shown)] });
|
|
63
|
+
node.append(picture);
|
|
64
|
+
if (online !== undefined) {
|
|
65
|
+
const dot = el('i');
|
|
66
|
+
dot.className = online ? 'on' : '';
|
|
67
|
+
node.append(dot);
|
|
68
|
+
}
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
function button(className, text, onClick) {
|
|
72
|
+
const node = el('button', text);
|
|
73
|
+
node.type = 'button';
|
|
74
|
+
node.className = className;
|
|
75
|
+
node.addEventListener('click', onClick);
|
|
76
|
+
return node;
|
|
77
|
+
}
|
|
78
|
+
/** The page: who asks, waits, and chats, as the room the link names is for this browser. */
|
|
79
|
+
class GuestPage {
|
|
80
|
+
constructor(link) {
|
|
81
|
+
this.link = link;
|
|
82
|
+
this.hubs = new RelayHubs({
|
|
83
|
+
store: new BrowserStore(),
|
|
84
|
+
relay: () => location.origin,
|
|
85
|
+
guest: true,
|
|
86
|
+
name: () => (GuestI18n.chinese ? '访客' : 'Guest'),
|
|
87
|
+
});
|
|
88
|
+
this.screen = '';
|
|
89
|
+
this.stuck = true;
|
|
90
|
+
this.connected = false;
|
|
91
|
+
}
|
|
92
|
+
start() {
|
|
93
|
+
this.hubs.onEvent(event => {
|
|
94
|
+
var _a;
|
|
95
|
+
if (event.type === 'state' && event.room === this.link.room) {
|
|
96
|
+
(_a = this.chat) === null || _a === void 0 ? void 0 : _a.heard(event.key, event);
|
|
97
|
+
}
|
|
98
|
+
else if (event.type === 'rooms') {
|
|
99
|
+
this.update();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
this.hubs.start();
|
|
103
|
+
this.update();
|
|
104
|
+
}
|
|
105
|
+
room() {
|
|
106
|
+
return this.hubs.room(this.link.room);
|
|
107
|
+
}
|
|
108
|
+
/** Shows what holds now: a screen of its own for each status, the chat kept as the room changes. */
|
|
109
|
+
update() {
|
|
110
|
+
var _a;
|
|
111
|
+
var _b;
|
|
112
|
+
const room = this.room();
|
|
113
|
+
const screen = !room ? 'join' : room.status === 'gone' ? `gone:${(_b = room.reason) !== null && _b !== void 0 ? _b : 'closed'}` : room.status;
|
|
114
|
+
if (screen === this.screen && room) {
|
|
115
|
+
if (room.status === 'member') {
|
|
116
|
+
this.refresh(room);
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.screen = screen;
|
|
121
|
+
(_a = this.sheet) === null || _a === void 0 ? void 0 : _a.remove();
|
|
122
|
+
this.sheet = undefined;
|
|
123
|
+
if (!room) {
|
|
124
|
+
this.join();
|
|
125
|
+
}
|
|
126
|
+
else if (room.status === 'waiting') {
|
|
127
|
+
this.waiting();
|
|
128
|
+
}
|
|
129
|
+
else if (room.status === 'member') {
|
|
130
|
+
this.chatScreen(room);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.out(room);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
frame(...children) {
|
|
137
|
+
const app = div('app', ...children);
|
|
138
|
+
document.body.replaceChildren(app);
|
|
139
|
+
return app;
|
|
140
|
+
}
|
|
141
|
+
top() {
|
|
142
|
+
const logo = el('span', 'Ta');
|
|
143
|
+
logo.className = 'logo';
|
|
144
|
+
const heading = div('heading', Object.assign(el('b'), { textContent: t('title') }));
|
|
145
|
+
return div('top', logo, heading);
|
|
146
|
+
}
|
|
147
|
+
join(error) {
|
|
148
|
+
document.title = t('title');
|
|
149
|
+
const field = el('input');
|
|
150
|
+
field.className = 'text';
|
|
151
|
+
field.placeholder = t('namePlaceholder');
|
|
152
|
+
field.maxLength = 40;
|
|
153
|
+
field.enterKeyHint = 'go';
|
|
154
|
+
if (localStorage.getItem(NAMED)) {
|
|
155
|
+
void this.hubs.identity().then(identity => {
|
|
156
|
+
field.value || (field.value = identity.name);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const label = el('label');
|
|
160
|
+
label.className = 'field';
|
|
161
|
+
label.append(t('name'), field);
|
|
162
|
+
const ask = button('primary', t('join'), () => void submit());
|
|
163
|
+
const shown = error ? [Object.assign(el('p', error), { className: 'error' })] : [];
|
|
164
|
+
const submit = async () => {
|
|
165
|
+
const name = field.value.trim();
|
|
166
|
+
if (!name) {
|
|
167
|
+
field.focus();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
ask.disabled = true;
|
|
171
|
+
ask.textContent = t('joining');
|
|
172
|
+
try {
|
|
173
|
+
await this.hubs.setName(name);
|
|
174
|
+
localStorage.setItem(NAMED, '1');
|
|
175
|
+
await this.hubs.join(location.href);
|
|
176
|
+
this.update();
|
|
177
|
+
}
|
|
178
|
+
catch (failure) {
|
|
179
|
+
this.screen = '';
|
|
180
|
+
this.join(failure instanceof Error && /own/.test(failure.message) ? t('own') : String(failure instanceof Error ? failure.message : failure));
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
field.addEventListener('keydown', event => {
|
|
184
|
+
if (event.key === 'Enter' && !event.isComposing) {
|
|
185
|
+
void submit();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
this.frame(this.top(), div('center', Object.assign(face(this.link.owner, 64), { className: 'face card-face' }), Object.assign(el('p', t('invited', { by: this.link.by || '…' })), { className: 'lead' }), Object.assign(el('h1', this.link.title || t('title')), { className: 'room-name' }), Object.assign(el('p', t('joinHint')), { className: 'hint' }), label, ...shown, ask, Object.assign(el('p', t('keep')), { className: 'small' }), Object.assign(el('p', t('haveTa')), { className: 'small' })));
|
|
189
|
+
}
|
|
190
|
+
waiting() {
|
|
191
|
+
this.frame(this.top(), div('center', Object.assign(el('div'), { className: 'spin' }), Object.assign(el('h1', t('waiting', { by: this.link.by || '…' })), { className: 'room-name' }), Object.assign(el('p', t('waitingHint')), { className: 'hint' }), button('plain', t('cancel'), () => void this.hubs.leave(this.link.room).then(() => this.update()))));
|
|
192
|
+
}
|
|
193
|
+
out(room) {
|
|
194
|
+
const text = room.status === 'refused'
|
|
195
|
+
? t('refused', { by: room.ownerName || this.link.by })
|
|
196
|
+
: room.reason === 'removed'
|
|
197
|
+
? t('removed')
|
|
198
|
+
: room.reason === 'invite'
|
|
199
|
+
? t('inviteGone')
|
|
200
|
+
: t('closed');
|
|
201
|
+
this.frame(this.top(), div('center', Object.assign(el('h1', text), { className: 'room-name' }), button('plain', t('again'), () => void this.hubs.leave(this.link.room).then(() => this.update()))));
|
|
202
|
+
}
|
|
203
|
+
chatScreen(room) {
|
|
204
|
+
document.title = room.title;
|
|
205
|
+
this.chat = new RelayRoomChat(this.hubs, room.id);
|
|
206
|
+
this.chat.subscribe(() => this.draw());
|
|
207
|
+
this.connected = room.connected;
|
|
208
|
+
void this.chat.load().catch(() => undefined);
|
|
209
|
+
const heading = div('heading');
|
|
210
|
+
this.heading = heading;
|
|
211
|
+
const more = button('icon', '⋯', () => this.members());
|
|
212
|
+
more.setAttribute('aria-label', t('members'));
|
|
213
|
+
const top = div('top', heading, more);
|
|
214
|
+
const list = div('list');
|
|
215
|
+
list.addEventListener('scroll', () => {
|
|
216
|
+
this.stuck = list.scrollHeight - list.scrollTop - list.clientHeight < 48;
|
|
217
|
+
});
|
|
218
|
+
this.list = list;
|
|
219
|
+
const field = el('textarea');
|
|
220
|
+
field.rows = 1;
|
|
221
|
+
field.placeholder = t('placeholder');
|
|
222
|
+
field.enterKeyHint = 'send';
|
|
223
|
+
const send = button('primary', t('send'), () => void say());
|
|
224
|
+
const fit = () => {
|
|
225
|
+
field.style.height = 'auto';
|
|
226
|
+
field.style.height = `${Math.min(field.scrollHeight + 2, 160)}px`;
|
|
227
|
+
};
|
|
228
|
+
const say = async () => {
|
|
229
|
+
var _a;
|
|
230
|
+
const text = field.value.trim();
|
|
231
|
+
const self = (_a = this.room()) === null || _a === void 0 ? void 0 : _a.members.find(member => member.self);
|
|
232
|
+
if (!text || !self || !this.chat) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
field.value = '';
|
|
236
|
+
fit();
|
|
237
|
+
this.stuck = true;
|
|
238
|
+
try {
|
|
239
|
+
await this.chat.say(text, self);
|
|
240
|
+
}
|
|
241
|
+
catch (failure) {
|
|
242
|
+
field.value || (field.value = text);
|
|
243
|
+
fit();
|
|
244
|
+
const note = Object.assign(el('p', t('failed', { reason: failure instanceof Error ? failure.message : String(failure) })), {
|
|
245
|
+
className: 'failed',
|
|
246
|
+
});
|
|
247
|
+
list.append(note);
|
|
248
|
+
setTimeout(() => note.remove(), 4000);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
field.addEventListener('input', fit);
|
|
252
|
+
field.addEventListener('keydown', event => {
|
|
253
|
+
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
void say();
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
const banner = room.view ? [div('banner', t('game'))] : [];
|
|
259
|
+
this.frame(top, ...banner, list, div('box', field, send), div('foot', t('secure')));
|
|
260
|
+
this.refresh(room);
|
|
261
|
+
this.draw();
|
|
262
|
+
}
|
|
263
|
+
/** The head of the chat, and the members if shown, as the room changed (who is online, the roster). */
|
|
264
|
+
refresh(room) {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
if (room.connected && !this.connected) {
|
|
267
|
+
// Connected again: what was said meanwhile.
|
|
268
|
+
void ((_a = this.chat) === null || _a === void 0 ? void 0 : _a.load().catch(() => undefined));
|
|
269
|
+
}
|
|
270
|
+
this.connected = room.connected;
|
|
271
|
+
const title = el('b', room.title);
|
|
272
|
+
title.append(Object.assign(el('span', `(${room.members.length})`)));
|
|
273
|
+
const online = room.members.filter(member => member.online && !member.self).length;
|
|
274
|
+
const sub = el('small', !room.connected ? t('connecting') : online ? t('online', { n: online }) : t('nobody'));
|
|
275
|
+
sub.className = room.connected && online ? '' : 'quiet';
|
|
276
|
+
(_b = this.heading) === null || _b === void 0 ? void 0 : _b.replaceChildren(title, sub);
|
|
277
|
+
if (this.sheet) {
|
|
278
|
+
this.members();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
draw() {
|
|
282
|
+
var _a;
|
|
283
|
+
const list = this.list;
|
|
284
|
+
const room = this.room();
|
|
285
|
+
if (!list || !room || !this.chat) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const lines = this.chat.lines;
|
|
289
|
+
const self = (_a = room.members.find(member => member.self)) === null || _a === void 0 ? void 0 : _a.member;
|
|
290
|
+
const personOf = (line) => { var _a; var _b; return (_b = (_a = room.members.find(member => member.member === line.from)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : line.name; };
|
|
291
|
+
// What a double says (docs/design/ta-link.md 4) is its own: `X's double`, a guest having none; an agent's, its name.
|
|
292
|
+
const nameOf = (line) => (line.agent ? line.agent.name : line.double ? t('doubleOf').replace('{name}', personOf(line)) : personOf(line));
|
|
293
|
+
const tagOf = (line) => (line.agent ? t('agentOf').replace('{name}', personOf(line)) : line.double ? t('double') : '');
|
|
294
|
+
const speaker = (line) => { var _a; var _b; return `${line.from}:${line.double ? 'd' : ''}:${(_b = (_a = line.agent) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : ''}`; };
|
|
295
|
+
const nodes = [];
|
|
296
|
+
if (!lines.length) {
|
|
297
|
+
nodes.push(div('empty', t('empty')));
|
|
298
|
+
}
|
|
299
|
+
lines.forEach((line, index) => {
|
|
300
|
+
var _a;
|
|
301
|
+
var _b, _c;
|
|
302
|
+
const before = lines[index - 1];
|
|
303
|
+
const separator = !before || line.at - before.at > PAUSE_MS;
|
|
304
|
+
const first = separator || speaker(before) !== speaker(line) || line.at - before.at > RUN_MS;
|
|
305
|
+
if (separator) {
|
|
306
|
+
nodes.push(div('when', GuestI18n.time(line.at)));
|
|
307
|
+
}
|
|
308
|
+
const bubble = div('bubble', ViewerMarkdown.render(line.text));
|
|
309
|
+
bubble.title = GuestI18n.time(line.at);
|
|
310
|
+
if (line.from === self && !line.agent) {
|
|
311
|
+
nodes.push(div('mine', bubble));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const other = room.members.find(member => member.member === line.from);
|
|
315
|
+
const tag = tagOf(line);
|
|
316
|
+
const col = div('col', ...(first ? [div('who', nameOf(line), ...(tag ? [div('tag', tag)] : []))] : []), bubble);
|
|
317
|
+
nodes.push(div(`msg${first ? ' first' : ''}${line.double || line.agent ? ' double' : ''}`, div('slot', ...(first ? [face((_c = (_b = (_a = line.agent) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : other === null || other === void 0 ? void 0 : other.id) !== null && _c !== void 0 ? _c : line.from, 32)] : [])), col));
|
|
318
|
+
});
|
|
319
|
+
list.replaceChildren(...nodes);
|
|
320
|
+
if (this.stuck) {
|
|
321
|
+
list.scrollTop = list.scrollHeight;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/** The members, over the chat: who is online, and the user's name and way out. */
|
|
325
|
+
members() {
|
|
326
|
+
var _a;
|
|
327
|
+
const room = this.room();
|
|
328
|
+
if (!room) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const panel = div('panel', Object.assign(el('h3', `${t('members')} (${room.members.length})`)));
|
|
332
|
+
for (const member of room.members) {
|
|
333
|
+
const tags = [member.self ? t('you') : '', member.owner ? t('owner') : '', member.guest ? t('guest') : ''].filter(Boolean);
|
|
334
|
+
const name = div('nm', member.name, ...tags.map(tag => Object.assign(el('span', tag), { className: 'tag' })));
|
|
335
|
+
const status = Object.assign(el('span', member.online ? t('onlineNow') : ''), { className: 'st on' });
|
|
336
|
+
panel.append(div('member', face(member.id, 34, member.online), name, status));
|
|
337
|
+
}
|
|
338
|
+
panel.append(div('sep'), button('row', t('rename'), () => {
|
|
339
|
+
var _a, _b;
|
|
340
|
+
var _c;
|
|
341
|
+
const name = (_b = prompt(t('name'), (_c = (_a = room.members.find(member => member.self)) === null || _a === void 0 ? void 0 : _a.name) !== null && _c !== void 0 ? _c : '')) === null || _b === void 0 ? void 0 : _b.trim();
|
|
342
|
+
if (name) {
|
|
343
|
+
void this.hubs.setName(name).then(() => this.update());
|
|
344
|
+
}
|
|
345
|
+
}), button('row danger', t('leave'), () => {
|
|
346
|
+
if (confirm(t('leaveAsk', { title: room.title }))) {
|
|
347
|
+
void this.hubs.leave(room.id).then(() => this.update());
|
|
348
|
+
}
|
|
349
|
+
}), button('row', t('close'), () => this.closeSheet()));
|
|
350
|
+
const sheet = div('sheet', panel);
|
|
351
|
+
sheet.addEventListener('click', event => {
|
|
352
|
+
if (event.target === sheet) {
|
|
353
|
+
this.closeSheet();
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
(_a = this.sheet) === null || _a === void 0 ? void 0 : _a.replaceWith(sheet);
|
|
357
|
+
if (!this.sheet) {
|
|
358
|
+
document.body.append(sheet);
|
|
359
|
+
}
|
|
360
|
+
this.sheet = sheet;
|
|
361
|
+
}
|
|
362
|
+
closeSheet() {
|
|
363
|
+
var _a;
|
|
364
|
+
(_a = this.sheet) === null || _a === void 0 ? void 0 : _a.remove();
|
|
365
|
+
this.sheet = undefined;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function main() {
|
|
369
|
+
const style = el('style', GUEST_STYLE);
|
|
370
|
+
document.head.append(style);
|
|
371
|
+
let link;
|
|
372
|
+
try {
|
|
373
|
+
link = RelayHubUtil.parse(location.href);
|
|
374
|
+
}
|
|
375
|
+
catch (_a) {
|
|
376
|
+
const logo = Object.assign(el('span', 'Ta'), { className: 'logo' });
|
|
377
|
+
document.body.replaceChildren(div('app', div('top', logo), div('center', Object.assign(el('p', t('invalid')), { className: 'hint' }))));
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
new GuestPage(link).start();
|
|
381
|
+
}
|
|
382
|
+
addEventListener('hashchange', () => location.reload());
|
|
383
|
+
main();
|
|
384
|
+
//# sourceMappingURL=guest.js.map
|
package/esm/node/index.d.ts
CHANGED
package/esm/node/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from '../common/index.js';
|
|
2
2
|
export * from './relay-files-host.js';
|
|
3
3
|
export * from './relay-host.js';
|
|
4
|
+
export * from './relay-hub-files.js';
|
|
4
5
|
export * from './relay-server.js';
|
|
5
6
|
export * from './relay-store.js';
|
|
7
|
+
export * from './relay-viewer.js';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|