@celljs/ta-nearby 0.0.0-stage → 4.13.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,1055 @@
1
+ // web-src/i18n.ts
2
+ var EN = {
3
+ title: "Nearby",
4
+ offTitle: "See who is around",
5
+ offHint: "Turned on, the Ta around you on the same network that turned it on too show here, and Ta can make a room of them, hand them work or ask their doubles.",
6
+ hour: "For an hour",
7
+ today: "Today",
8
+ always: "Until I turn it off",
9
+ on: "Nearby is on",
10
+ left: "{time} left",
11
+ leftHours: "{n} h left",
12
+ leftMinutes: "{n} min left",
13
+ untilOff: "until you turn it off",
14
+ turnOff: "Turn off",
15
+ nobody: "No other Ta yet",
16
+ nobodyHint: "Those with you open Discover → Nearby in their Ta and turn it on too.",
17
+ friend: "Friend",
18
+ someone: "A user of Ta",
19
+ makeRoom: "Make a room of {n}",
20
+ makeRoomAll: "Make a room together",
21
+ roomTitle: "Name of the room",
22
+ defaultRoom: "Nearby · {time}",
23
+ made: "Invited {names}: each comes in once they tap Join.",
24
+ missed: "Could not reach {names}.",
25
+ sayIt: "Or tell Ta: “make a room and send today’s notes to those nearby”.",
26
+ youAre: "Others see you as",
27
+ hideName: "Hide my name",
28
+ showName: "Show my name",
29
+ invites: "Invitations",
30
+ invited: "{name} invites you into “{title}”",
31
+ inviteNote: "Nearby, on your network. Once in, you see what is said and shared in the room, and they see what you say there.",
32
+ inviteStranger: "The name is only what they say: join if you know who it is.",
33
+ join: "Join",
34
+ notNow: "Not now",
35
+ error: "Nearby cannot listen here: {error}",
36
+ oldServer: "Update Ta on the computer to use Nearby.",
37
+ settingsName: "Show my name nearby",
38
+ settingsNameHint: "Off: others nearby see “a user of Ta”; your friends still know you.",
39
+ homeDetail: "{n} Ta: {names}",
40
+ homeNobody: "No other Ta yet · {left}",
41
+ spotHint: "Not seeing each other on the same network? Use a code.",
42
+ spotOpen: "Get a code",
43
+ spotJoin: "Enter a code",
44
+ spotJoinTitle: "The code of six digits you were given",
45
+ spotCode: "Code",
46
+ spotShare: "Those with you enter it in Nearby · {n} min left",
47
+ spotClosed: "No one else can come in now; those in stay",
48
+ spotIn: "In by the code",
49
+ spotLeave: "Leave",
50
+ wantsToShow: "{name} wants to show “{title}” on this computer",
51
+ showNote: "Nearby, on your network. It shows here and is not kept once closed.",
52
+ showIt: "Show it",
53
+ from: "From {name}, nearby",
54
+ close: "Close",
55
+ settingsShow: "Those nearby may show things here",
56
+ settingsShowHint: "A screen of a meeting room can show at once; on your own computer, ask first.",
57
+ showOff: "No",
58
+ showAsk: "Ask me",
59
+ showAuto: "At once",
60
+ settingsWork: "Those nearby may ask my Ta to work",
61
+ settingsWorkHint: "They hand it tasks in a room; working in a folder still needs your permission each time.",
62
+ settingsMeet: "Open to meet people nearby",
63
+ settingsMeetHint: "Your Ta and theirs compare cards; Ta proposes to say hello only for a reason, 3 a day at most. Names go only once both say yes.",
64
+ card: "Your card",
65
+ cardNone: "No card yet",
66
+ cardEdit: "Edit",
67
+ cardTitle: "Your card for Nearby",
68
+ cardHint: "Others nearby open to meet see this, never your name until you both say yes. No contacts, companies or paths.",
69
+ cardLine: "What you work on",
70
+ cardTopics: "Topics, by commas",
71
+ cardSeeking: "What you look for, by commas",
72
+ cardOffering: "What you can help with, by commas",
73
+ cardDraft: "Let Ta draft it",
74
+ cardDrafting: "Ta is drafting it in a conversation; it shows here when done.",
75
+ cardDraftReady: "Ta drafted this: look it over",
76
+ cardUse: "Use this card",
77
+ cancel: "Cancel",
78
+ meetOff: "Open to meet people nearby? Ta proposes to say hello only when someone may help you or follows the same things.",
79
+ meetOn: "Open to meet · {line}",
80
+ meetTurnOn: "Turn on",
81
+ greets: "Would like to meet you",
82
+ greetLine: "{name} would like to meet you",
83
+ greetYes: "Say hello",
84
+ greetNo: "Not now"
85
+ };
86
+ var ZH = {
87
+ title: "附近",
88
+ offTitle: "看看身边有谁",
89
+ offHint: "打开后,同一网络里也打开了附近的 Ta 会出现在这里;Ta 能和他们一起建房间、派任务、问他们的分身。",
90
+ hour: "1 小时",
91
+ today: "今天",
92
+ always: "一直,直到我关掉",
93
+ on: "附近已打开",
94
+ left: "还剩 {time}",
95
+ leftHours: "还剩 {n} 小时",
96
+ leftMinutes: "还剩 {n} 分钟",
97
+ untilOff: "直到你关掉",
98
+ turnOff: "关掉",
99
+ nobody: "还没有别的 Ta",
100
+ nobodyHint: "让身边的人在自己的 Ta 里打开 发现 → 附近。",
101
+ friend: "好友",
102
+ someone: "一位 Ta 用户",
103
+ makeRoom: "和这 {n} 位建房间",
104
+ makeRoomAll: "一起建个房间",
105
+ roomTitle: "房间名",
106
+ defaultRoom: "附近 · {time}",
107
+ made: "已邀请 {names},他们点“加入”后就进来。",
108
+ missed: "没联系上 {names}。",
109
+ sayIt: "也可以直接对 Ta 说:“建个房间,把今天的纪要发给附近的人”。",
110
+ youAre: "别人看到的你",
111
+ hideName: "不显示名字",
112
+ showName: "显示名字",
113
+ invites: "邀请",
114
+ invited: "{name} 邀请你进房间「{title}」",
115
+ inviteNote: "在你附近、同一网络里。进去后能看到房间里说的和放的东西,他们也能看到你在那里说的话。",
116
+ inviteStranger: "名字是对方自称的,认识再加入。",
117
+ join: "加入",
118
+ notNow: "不了",
119
+ error: "附近在这台电脑上无法使用:{error}",
120
+ oldServer: "请先更新电脑上的 Ta 再使用附近。",
121
+ settingsName: "在附近显示我的名字",
122
+ settingsNameHint: "关掉后附近的人看到的是“一位 Ta 用户”,你的好友仍认得出你。",
123
+ homeDetail: "{n} 个 Ta:{names}",
124
+ homeNobody: "还没有别的 Ta · {left}",
125
+ spotHint: "同一网络里看不到对方?用在场码。",
126
+ spotOpen: "生成在场码",
127
+ spotJoin: "输入在场码",
128
+ spotJoinTitle: "输入对方给你的 6 位在场码",
129
+ spotCode: "在场码",
130
+ spotShare: "让身边的人在“附近”里输入 · 还剩 {n} 分钟",
131
+ spotClosed: "已过 10 分钟,新的人进不来了,已在的人不受影响",
132
+ spotIn: "已用在场码加入",
133
+ spotLeave: "离开",
134
+ wantsToShow: "{name} 想在这台电脑上展示「{title}」",
135
+ showNote: "在你附近、同一网络里。只在这里显示,关掉就没了,不会保存。",
136
+ showIt: "展示",
137
+ from: "来自 {name}(附近)",
138
+ close: "关闭",
139
+ settingsShow: "附近的人可以在这台电脑上展示",
140
+ settingsShowHint: "会议室大屏可以设成直接展示;自己的电脑建议先问我。",
141
+ showOff: "不可以",
142
+ showAsk: "先问我",
143
+ showAuto: "直接展示",
144
+ settingsWork: "附近的人可以请我的 Ta 做事",
145
+ settingsWorkHint: "对方在房间里把任务交给你的分身;要在目录里做事,每次仍由你授权。",
146
+ settingsMeet: "愿意认识附近的人",
147
+ settingsMeetHint: "你和对方的 Ta 先比对名片,有具体理由才提议你打招呼,每天最多 3 次;双方都同意后才互相知道名字。",
148
+ card: "我的名片",
149
+ cardNone: "还没有名片",
150
+ cardEdit: "编辑",
151
+ cardTitle: "我在附近的名片",
152
+ cardHint: "附近也愿意认识人的 Ta 能看到这张名片;双方都同意前不会看到你的名字。不要写联系方式、公司和路径。",
153
+ cardLine: "一句话说你在做什么",
154
+ cardTopics: "话题,用逗号分开",
155
+ cardSeeking: "在找什么,用逗号分开",
156
+ cardOffering: "能帮别人什么,用逗号分开",
157
+ cardDraft: "让 Ta 起草",
158
+ cardDrafting: "Ta 正在一个对话里起草,好了会出现在这里。",
159
+ cardDraftReady: "Ta 起草好了,看一眼",
160
+ cardUse: "用这张",
161
+ cancel: "取消",
162
+ meetOff: "愿意认识附近的人吗?只有对方可能帮得上你、或你们关注同样的事时,Ta 才会提议你打招呼。",
163
+ meetOn: "愿意认识附近的人 · {line}",
164
+ meetTurnOn: "打开",
165
+ greets: "想认识你",
166
+ greetLine: "{name} 想认识你",
167
+ greetYes: "打个招呼",
168
+ greetNo: "不了"
169
+ };
170
+ var NearbyWords;
171
+ ((NearbyWords) => {
172
+ function of(language) {
173
+ return language === "zh-CN" ? ZH : EN;
174
+ }
175
+ NearbyWords.of = of;
176
+ function format(text, values = {}) {
177
+ return text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
178
+ }
179
+ NearbyWords.format = format;
180
+ })(NearbyWords ||= {});
181
+
182
+ // web-src/nearby-protocol.ts
183
+ var NAME = "@celljs/ta-nearby";
184
+ var NEARBY_VIEW = `${NAME}/nearby`;
185
+ var NearbyKeys;
186
+ ((NearbyKeys) => {
187
+ NearbyKeys.VISIBLE = "visible";
188
+ NearbyKeys.STATUS = "status";
189
+ NearbyKeys.SETTINGS = "settings";
190
+ NearbyKeys.CARDS = "cards";
191
+ NearbyKeys.MET = "met";
192
+ })(NearbyKeys ||= {});
193
+ var SHOW_MAX = 600 * 1024;
194
+
195
+ // web-src/react.ts
196
+ var React;
197
+ function bind(react) {
198
+ React = react;
199
+ }
200
+
201
+ // web-src/page.tsx
202
+ var pi;
203
+ function bindPage(api) {
204
+ pi = api;
205
+ }
206
+ function t(key, values = {}) {
207
+ return NearbyWords.format(NearbyWords.of(pi.ui.language)[key], values);
208
+ }
209
+ function icon(name) {
210
+ return pi.ui.icons[name] ?? pi.ui.icons.LocateFixed ?? pi.ui.icons.Users;
211
+ }
212
+ function message(error) {
213
+ return error instanceof Error ? error.message : String(error);
214
+ }
215
+ async function call(request) {
216
+ try {
217
+ return await pi.callHost("nearby", request);
218
+ } catch (error) {
219
+ const text = message(error);
220
+ throw new Error(/no method|no host/i.test(text) ? t("oldServer") : text);
221
+ }
222
+ }
223
+ var ROOMS_VIEW = "@celljs/ta-rooms/rooms";
224
+ var EMPTY = { visible: false, self: { name: "", face: 0 }, peers: [], invites: [] };
225
+
226
+ class NearbyStore {
227
+ status = EMPTY;
228
+ loaded = false;
229
+ listeners = new Set;
230
+ onInvites;
231
+ onShown;
232
+ get = () => this.status;
233
+ isLoaded = () => this.loaded;
234
+ subscribe = (listener) => {
235
+ this.listeners.add(listener);
236
+ return () => this.listeners.delete(listener);
237
+ };
238
+ start() {
239
+ const stop = pi.storage.onChange((keys) => keys.includes(NearbyKeys.STATUS) && void this.read());
240
+ this.read();
241
+ return stop;
242
+ }
243
+ set(status) {
244
+ const known = new Set(this.status.invites.map((invite) => invite.k));
245
+ const fresh = this.loaded ? status.invites.filter((invite) => !known.has(invite.k)) : status.invites;
246
+ const before = this.status.shown;
247
+ this.status = status;
248
+ this.loaded = true;
249
+ for (const listener of this.listeners) {
250
+ listener();
251
+ }
252
+ if (fresh.length) {
253
+ this.onInvites?.(fresh);
254
+ }
255
+ if (status.shown && (status.shown.k !== before?.k || before.ask && !status.shown.ask)) {
256
+ this.onShown?.(status.shown);
257
+ }
258
+ }
259
+ async read() {
260
+ const value = await pi.storage.get(NearbyKeys.STATUS).catch(() => {
261
+ return;
262
+ });
263
+ this.set(value && typeof value === "object" && Array.isArray(value.peers) ? { ...EMPTY, ...value, invites: value.invites ?? [] } : EMPTY);
264
+ }
265
+ }
266
+ var store = new NearbyStore;
267
+ function useStatus() {
268
+ return React.useSyncExternalStore(store.subscribe, store.get);
269
+ }
270
+ function who(peer) {
271
+ return peer.friend?.name ?? (peer.name || t("someone"));
272
+ }
273
+ function names(list) {
274
+ return list.join(pi.ui.language === "zh-CN" ? "、" : ", ");
275
+ }
276
+ function leftText(until, now = Date.now()) {
277
+ if (until === undefined) {
278
+ return t("untilOff");
279
+ }
280
+ const minutes = Math.max(1, Math.round((until - now) / 60000));
281
+ return minutes < 60 ? t("leftMinutes", { n: minutes }) : t("leftHours", { n: Math.round(minutes / 60) });
282
+ }
283
+ function clock(now = new Date) {
284
+ return `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}`;
285
+ }
286
+ function restOfDay(now = new Date) {
287
+ const end = new Date(now);
288
+ end.setHours(23, 59, 59, 999);
289
+ return Math.max(1, Math.round((end.getTime() - now.getTime()) / 60000));
290
+ }
291
+ function Face({ seed, face, size }) {
292
+ return /* @__PURE__ */ React.createElement(pi.ui.Face, {
293
+ seed,
294
+ face,
295
+ size
296
+ });
297
+ }
298
+ function Looking({ peers }) {
299
+ const shown = peers.slice(0, 5);
300
+ const spots = [
301
+ [0.2, 0.3],
302
+ [0.78, 0.26],
303
+ [0.86, 0.68],
304
+ [0.16, 0.74],
305
+ [0.5, 0.12]
306
+ ];
307
+ return /* @__PURE__ */ React.createElement("div", {
308
+ className: "tnb-looking",
309
+ "aria-hidden": "true"
310
+ }, /* @__PURE__ */ React.createElement("span", {
311
+ className: "tnb-ring"
312
+ }), /* @__PURE__ */ React.createElement("span", {
313
+ className: "tnb-ring tnb-ring-2"
314
+ }), /* @__PURE__ */ React.createElement("span", {
315
+ className: "tnb-ring tnb-ring-3"
316
+ }), /* @__PURE__ */ React.createElement("span", {
317
+ className: "tnb-me"
318
+ }, pi.ui.Avatar ? /* @__PURE__ */ React.createElement(pi.ui.Avatar, {
319
+ size: 44
320
+ }) : null), shown.map((peer, index) => /* @__PURE__ */ React.createElement("span", {
321
+ key: peer.e,
322
+ className: "tnb-spot",
323
+ style: { left: `${spots[index][0] * 100}%`, top: `${spots[index][1] * 100}%` }
324
+ }, /* @__PURE__ */ React.createElement(Face, {
325
+ seed: peer.friend?.id ?? peer.e,
326
+ face: peer.face,
327
+ size: 30
328
+ }))));
329
+ }
330
+ function Busy({ children, onClick, primary }) {
331
+ const [busy, run] = pi.ui.useBusy ? pi.ui.useBusy() : [false, async (action) => action()];
332
+ return /* @__PURE__ */ React.createElement("button", {
333
+ type: "button",
334
+ className: `ta-button${primary ? " ta-primary" : ""}${busy ? " ta-busy" : ""}`,
335
+ disabled: busy,
336
+ onClick: () => void run(async () => {
337
+ try {
338
+ await onClick();
339
+ } catch (error) {
340
+ pi.ui.notify(message(error), "error");
341
+ }
342
+ })
343
+ }, children);
344
+ }
345
+ function visible(minutes) {
346
+ return call({ kind: "visible", on: true, ...minutes ? { minutes } : {} }).then((status) => store.set(status));
347
+ }
348
+ async function makeRoom(people) {
349
+ const title = await pi.ui.input(t("roomTitle"), t("roomTitle"), { value: t("defaultRoom", { time: clock() }) });
350
+ if (title === undefined) {
351
+ return;
352
+ }
353
+ const result = await call({ kind: "room", people: people.map((peer) => peer.e), title: title.trim() || undefined });
354
+ pi.ui.notify([result.invited.length ? t("made", { names: names(result.invited) }) : "", result.missed.length ? t("missed", { names: names(result.missed) }) : ""].filter(Boolean).join(" "));
355
+ pi.ui.showView(ROOMS_VIEW);
356
+ }
357
+ function PeerTile({ peer, chosen, toggle }) {
358
+ return /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("button", {
359
+ type: "button",
360
+ className: `tnb-peer${chosen ? " tnb-chosen" : ""}`,
361
+ "aria-pressed": chosen,
362
+ onClick: toggle
363
+ }, /* @__PURE__ */ React.createElement("span", {
364
+ className: "tnb-peer-face"
365
+ }, /* @__PURE__ */ React.createElement(Face, {
366
+ seed: peer.friend?.id ?? peer.e,
367
+ face: peer.face,
368
+ size: 52
369
+ }), /* @__PURE__ */ React.createElement("span", {
370
+ className: "tnb-check"
371
+ }, pi.ui.SelectCheck ? /* @__PURE__ */ React.createElement(pi.ui.SelectCheck, {
372
+ checked: chosen
373
+ }) : null)), /* @__PURE__ */ React.createElement("span", {
374
+ className: "tnb-peer-name tnb-ellipsis"
375
+ }, who(peer)), peer.friend && /* @__PURE__ */ React.createElement("span", {
376
+ className: "tnb-tag tnb-tag-friend"
377
+ }, t("friend"))));
378
+ }
379
+ function InviteRow({ invite }) {
380
+ return /* @__PURE__ */ React.createElement("li", {
381
+ className: "tnb-invite"
382
+ }, /* @__PURE__ */ React.createElement(Face, {
383
+ seed: invite.friend?.id ?? invite.e,
384
+ face: invite.face,
385
+ size: 40
386
+ }), /* @__PURE__ */ React.createElement("div", {
387
+ className: "tnb-invite-text"
388
+ }, /* @__PURE__ */ React.createElement("span", null, t("invited", { name: who(invite), title: invite.title })), invite.why && /* @__PURE__ */ React.createElement("span", {
389
+ className: "tnb-quiet"
390
+ }, invite.why)), /* @__PURE__ */ React.createElement("div", {
391
+ className: "tnb-actions"
392
+ }, /* @__PURE__ */ React.createElement(Busy, {
393
+ onClick: () => answer(invite.k, false)
394
+ }, t("notNow")), /* @__PURE__ */ React.createElement(Busy, {
395
+ primary: true,
396
+ onClick: () => answer(invite.k, true)
397
+ }, t("join"))));
398
+ }
399
+ async function answer(k, accept) {
400
+ store.set(await call({ kind: "answer", k, accept }));
401
+ if (accept) {
402
+ pi.ui.showView(ROOMS_VIEW);
403
+ }
404
+ }
405
+ function useNow(ms) {
406
+ const [now, setNow] = React.useState(Date.now());
407
+ React.useEffect(() => {
408
+ const timer = setInterval(() => setNow(Date.now()), ms);
409
+ return () => clearInterval(timer);
410
+ }, [ms]);
411
+ return now;
412
+ }
413
+ function NearbyPage() {
414
+ const status = useStatus();
415
+ const now = useNow(30000);
416
+ const [left, setLeft] = React.useState(new Set);
417
+ const chosen = status.peers.filter((peer) => !left.has(peer.e));
418
+ const toggle = (e) => setLeft((before) => {
419
+ const next = new Set(before);
420
+ if (!next.delete(e)) {
421
+ next.add(e);
422
+ }
423
+ return next;
424
+ });
425
+ return /* @__PURE__ */ React.createElement("div", {
426
+ className: "tnb-page"
427
+ }, /* @__PURE__ */ React.createElement("div", {
428
+ className: "tnb-body"
429
+ }, status.invites.length > 0 && /* @__PURE__ */ React.createElement("section", {
430
+ className: "tnb-section"
431
+ }, /* @__PURE__ */ React.createElement("h3", null, t("invites")), /* @__PURE__ */ React.createElement("ul", {
432
+ className: "tnb-card"
433
+ }, status.invites.map((invite) => /* @__PURE__ */ React.createElement(InviteRow, {
434
+ key: invite.k,
435
+ invite
436
+ })))), (status.greets ?? []).length > 0 && /* @__PURE__ */ React.createElement("section", {
437
+ className: "tnb-section"
438
+ }, /* @__PURE__ */ React.createElement("h3", null, t("greets")), /* @__PURE__ */ React.createElement("ul", {
439
+ className: "tnb-card"
440
+ }, (status.greets ?? []).map((greet) => /* @__PURE__ */ React.createElement(GreetRow, {
441
+ key: greet.k,
442
+ greet
443
+ })))), !status.visible ? /* @__PURE__ */ React.createElement("div", {
444
+ className: "tnb-off"
445
+ }, /* @__PURE__ */ React.createElement(Looking, {
446
+ peers: []
447
+ }), /* @__PURE__ */ React.createElement("h2", null, t("offTitle")), /* @__PURE__ */ React.createElement("p", {
448
+ className: "tnb-quiet"
449
+ }, t("offHint")), /* @__PURE__ */ React.createElement("div", {
450
+ className: "tnb-durations"
451
+ }, /* @__PURE__ */ React.createElement(Busy, {
452
+ primary: true,
453
+ onClick: () => visible(60)
454
+ }, t("hour")), /* @__PURE__ */ React.createElement(Busy, {
455
+ onClick: () => visible(restOfDay())
456
+ }, t("today")), /* @__PURE__ */ React.createElement(Busy, {
457
+ onClick: () => visible()
458
+ }, t("always")))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
459
+ className: "tnb-on"
460
+ }, /* @__PURE__ */ React.createElement(Looking, {
461
+ peers: status.peers
462
+ }), /* @__PURE__ */ React.createElement("div", {
463
+ className: "tnb-on-line"
464
+ }, /* @__PURE__ */ React.createElement("span", {
465
+ className: "tnb-dot"
466
+ }), /* @__PURE__ */ React.createElement("span", null, t("on"), " · ", leftText(status.until, now)), /* @__PURE__ */ React.createElement("button", {
467
+ type: "button",
468
+ className: "tnb-link",
469
+ onClick: () => void call({ kind: "visible", on: false }).then((next) => store.set(next), (error) => pi.ui.notify(message(error), "error"))
470
+ }, t("turnOff"))), status.error && /* @__PURE__ */ React.createElement("p", {
471
+ className: "tnb-error"
472
+ }, t("error", { error: status.error }))), status.peers.length === 0 ? /* @__PURE__ */ React.createElement("div", {
473
+ className: "tnb-nobody"
474
+ }, /* @__PURE__ */ React.createElement("strong", null, t("nobody")), /* @__PURE__ */ React.createElement("span", {
475
+ className: "tnb-quiet"
476
+ }, t("nobodyHint"))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("ul", {
477
+ className: "tnb-peers"
478
+ }, status.peers.map((peer) => /* @__PURE__ */ React.createElement(PeerTile, {
479
+ key: peer.e,
480
+ peer,
481
+ chosen: !left.has(peer.e),
482
+ toggle: () => toggle(peer.e)
483
+ }))), /* @__PURE__ */ React.createElement("div", {
484
+ className: "tnb-make"
485
+ }, chosen.length > 0 && /* @__PURE__ */ React.createElement("button", {
486
+ type: "button",
487
+ className: "ta-button ta-primary",
488
+ onClick: () => void makeRoom(chosen).catch((error) => pi.ui.notify(message(error), "error"))
489
+ }, chosen.length === status.peers.length ? t("makeRoomAll") : t("makeRoom", { n: chosen.length })), /* @__PURE__ */ React.createElement("p", {
490
+ className: "tnb-quiet"
491
+ }, t("sayIt")))), /* @__PURE__ */ React.createElement(SpotRow, {
492
+ status,
493
+ now
494
+ }), /* @__PURE__ */ React.createElement(MeetRow, {
495
+ status
496
+ }), /* @__PURE__ */ React.createElement("p", {
497
+ className: "tnb-self"
498
+ }, /* @__PURE__ */ React.createElement("span", {
499
+ className: "tnb-quiet"
500
+ }, t("youAre")), /* @__PURE__ */ React.createElement("span", null, status.self.name || t("someone"))))));
501
+ }
502
+ function spot(action, code) {
503
+ return call({ kind: "spot", action, ...code ? { code } : {} }).then((status) => store.set(status));
504
+ }
505
+ function SpotRow({ status, now }) {
506
+ const current = status.spot;
507
+ if (current) {
508
+ const minutes = Math.min(10, Math.ceil((current.until - Math.max(now, Date.now())) / 60000));
509
+ return /* @__PURE__ */ React.createElement("div", {
510
+ className: "tnb-code-card"
511
+ }, /* @__PURE__ */ React.createElement("span", {
512
+ className: "tnb-quiet"
513
+ }, t("spotCode")), /* @__PURE__ */ React.createElement("strong", {
514
+ className: "tnb-code"
515
+ }, current.code.slice(0, 3), " ", current.code.slice(3)), /* @__PURE__ */ React.createElement("span", {
516
+ className: "tnb-quiet"
517
+ }, minutes > 0 ? current.mine ? t("spotShare", { n: minutes }) : t("spotIn") : t("spotClosed")), /* @__PURE__ */ React.createElement("button", {
518
+ type: "button",
519
+ className: "tnb-link",
520
+ onClick: () => void spot("leave").catch((error) => pi.ui.notify(message(error), "error"))
521
+ }, t("spotLeave")));
522
+ }
523
+ return /* @__PURE__ */ React.createElement("div", {
524
+ className: "tnb-code-row"
525
+ }, /* @__PURE__ */ React.createElement("span", {
526
+ className: "tnb-quiet"
527
+ }, t("spotHint")), /* @__PURE__ */ React.createElement("div", {
528
+ className: "tnb-actions"
529
+ }, /* @__PURE__ */ React.createElement(Busy, {
530
+ onClick: () => spot("open")
531
+ }, t("spotOpen")), /* @__PURE__ */ React.createElement("button", {
532
+ type: "button",
533
+ className: "ta-button",
534
+ onClick: () => void pi.ui.input(t("spotJoinTitle"), "000000").then((code) => code?.trim() ? spot("join", code.replace(/\s/g, "")) : undefined).catch((error) => pi.ui.notify(message(error), "error"))
535
+ }, t("spotJoin"))));
536
+ }
537
+ function ShowContent({ content }) {
538
+ if (content.kind === "html") {
539
+ return /* @__PURE__ */ React.createElement("iframe", {
540
+ className: "tnb-show-frame",
541
+ title: content.title,
542
+ sandbox: "allow-scripts allow-popups",
543
+ referrerPolicy: "no-referrer",
544
+ srcDoc: content.data
545
+ });
546
+ }
547
+ if (content.kind === "image") {
548
+ return /* @__PURE__ */ React.createElement("img", {
549
+ className: "tnb-show-image",
550
+ alt: content.title,
551
+ src: content.data
552
+ });
553
+ }
554
+ if (content.kind === "markdown") {
555
+ return /* @__PURE__ */ React.createElement("div", {
556
+ className: "tnb-show-text"
557
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
558
+ text: content.data
559
+ }));
560
+ }
561
+ return /* @__PURE__ */ React.createElement("pre", {
562
+ className: "tnb-show-text tnb-show-pre"
563
+ }, content.data);
564
+ }
565
+ function ShowOverlay({ shown, close }) {
566
+ const status = useStatus();
567
+ const current = status.shown?.k === shown.k ? status.shown : undefined;
568
+ const [content, setContent] = React.useState();
569
+ React.useEffect(() => {
570
+ if (!current) {
571
+ close();
572
+ } else if (!current.ask && !content) {
573
+ call({ kind: "shown", k: shown.k }).then(setContent, () => close());
574
+ }
575
+ }, [current, content, shown.k, close]);
576
+ const finish = () => void call({ kind: "show", k: shown.k, action: "close" }).then((next) => store.set(next), close);
577
+ if (!current) {
578
+ return null;
579
+ }
580
+ if (current.ask) {
581
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
582
+ title: t("title"),
583
+ onClose: finish
584
+ }, /* @__PURE__ */ React.createElement("div", {
585
+ className: "tnb-dialog"
586
+ }, /* @__PURE__ */ React.createElement("div", {
587
+ className: "tnb-dialog-head"
588
+ }, /* @__PURE__ */ React.createElement(Face, {
589
+ seed: current.friend?.id ?? current.k,
590
+ face: current.face,
591
+ size: 48
592
+ }), /* @__PURE__ */ React.createElement("strong", null, t("wantsToShow", { name: who(current), title: current.title }))), /* @__PURE__ */ React.createElement("p", {
593
+ className: "tnb-quiet"
594
+ }, [t("showNote"), current.friend ? "" : t("inviteStranger")].filter(Boolean).join(pi.ui.language === "zh-CN" ? "" : " ")), /* @__PURE__ */ React.createElement("div", {
595
+ className: "tnb-actions tnb-dialog-actions"
596
+ }, /* @__PURE__ */ React.createElement("button", {
597
+ type: "button",
598
+ className: "ta-button",
599
+ onClick: finish
600
+ }, t("notNow")), /* @__PURE__ */ React.createElement(Busy, {
601
+ primary: true,
602
+ onClick: () => call({ kind: "show", k: shown.k, action: "accept" }).then((next) => store.set(next))
603
+ }, t("showIt")))));
604
+ }
605
+ return /* @__PURE__ */ React.createElement(pi.ui.FullScreen, {
606
+ className: "tnb-show"
607
+ }, /* @__PURE__ */ React.createElement("div", {
608
+ className: "tnb-show-bar"
609
+ }, /* @__PURE__ */ React.createElement(Face, {
610
+ seed: current.friend?.id ?? current.k,
611
+ face: current.face,
612
+ size: 26
613
+ }), /* @__PURE__ */ React.createElement("span", {
614
+ className: "tnb-show-title tnb-ellipsis"
615
+ }, current.title), /* @__PURE__ */ React.createElement("span", {
616
+ className: "tnb-quiet tnb-ellipsis"
617
+ }, t("from", { name: who(current) })), /* @__PURE__ */ React.createElement("button", {
618
+ type: "button",
619
+ className: "ta-button",
620
+ onClick: finish
621
+ }, t("close"))), /* @__PURE__ */ React.createElement("div", {
622
+ className: "tnb-show-body"
623
+ }, content ? /* @__PURE__ */ React.createElement(ShowContent, {
624
+ content
625
+ }) : /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
626
+ rows: 4
627
+ })));
628
+ }
629
+ var showing;
630
+ function openShown(shown) {
631
+ if (showing === shown.k || !pi.ui.custom) {
632
+ return;
633
+ }
634
+ showing = shown.k;
635
+ pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(ShowOverlay, {
636
+ shown,
637
+ close: () => {
638
+ if (showing === shown.k) {
639
+ showing = undefined;
640
+ }
641
+ close();
642
+ }
643
+ }));
644
+ }
645
+ function useSettings() {
646
+ const settings = useStatus().settings ?? {};
647
+ const change = async (next) => {
648
+ try {
649
+ store.set(await call({ kind: "settings", settings: next }));
650
+ } catch (error) {
651
+ pi.ui.notify(message(error), "error");
652
+ }
653
+ };
654
+ return [settings, change];
655
+ }
656
+ function ShowSetting() {
657
+ const [settings, change] = useSettings();
658
+ const modes = [
659
+ ["off", "showOff"],
660
+ ["ask", "showAsk"],
661
+ ["auto", "showAuto"]
662
+ ];
663
+ return /* @__PURE__ */ React.createElement("select", {
664
+ className: "tnb-select",
665
+ "aria-label": t("settingsShow"),
666
+ value: settings.show ?? "ask",
667
+ onChange: (event) => void change({ show: event.target.value })
668
+ }, modes.map(([mode, word]) => /* @__PURE__ */ React.createElement("option", {
669
+ key: mode,
670
+ value: mode
671
+ }, t(word))));
672
+ }
673
+ function WorkSetting() {
674
+ const [settings, change] = useSettings();
675
+ return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
676
+ checked: settings.work === true,
677
+ label: t("settingsWork"),
678
+ onChange: (on) => change({ work: on })
679
+ });
680
+ }
681
+ function GreetRow({ greet }) {
682
+ const answer2 = async (accept) => {
683
+ store.set(await call({ kind: "greet", k: greet.k, accept }));
684
+ if (accept) {
685
+ pi.ui.showView(ROOMS_VIEW);
686
+ }
687
+ };
688
+ return /* @__PURE__ */ React.createElement("li", {
689
+ className: "tnb-invite"
690
+ }, /* @__PURE__ */ React.createElement(Face, {
691
+ seed: greet.friend?.id ?? greet.e,
692
+ face: greet.face,
693
+ size: 40
694
+ }), /* @__PURE__ */ React.createElement("div", {
695
+ className: "tnb-invite-text"
696
+ }, /* @__PURE__ */ React.createElement("span", null, t("greetLine", { name: who(greet) })), greet.line && /* @__PURE__ */ React.createElement("span", null, greet.line), greet.why && /* @__PURE__ */ React.createElement("span", {
697
+ className: "tnb-quiet"
698
+ }, greet.why)), /* @__PURE__ */ React.createElement("div", {
699
+ className: "tnb-actions"
700
+ }, /* @__PURE__ */ React.createElement(Busy, {
701
+ onClick: () => answer2(false)
702
+ }, t("greetNo")), /* @__PURE__ */ React.createElement(Busy, {
703
+ primary: true,
704
+ onClick: () => answer2(true)
705
+ }, t("greetYes"))));
706
+ }
707
+ var join = (items) => items.join(pi.ui.language === "zh-CN" ? "," : ", ");
708
+ var split = (text) => text.split(/[,,、;\n]/).map((item) => item.trim()).filter(Boolean);
709
+ function CardDialog({ close }) {
710
+ const status = useStatus();
711
+ const start = status.cards?.draft ?? status.cards?.card;
712
+ const [line, setLine] = React.useState(start?.line ?? "");
713
+ const [topics, setTopics] = React.useState(join(start?.topics ?? []));
714
+ const [seeking, setSeeking] = React.useState(join(start?.seeking ?? []));
715
+ const [offering, setOffering] = React.useState(join(start?.offering ?? []));
716
+ const [drafting, setDrafting] = React.useState(false);
717
+ const draft = status.cards?.draft;
718
+ const shownDraft = React.useRef(draft);
719
+ React.useEffect(() => {
720
+ if (draft && draft !== shownDraft.current) {
721
+ shownDraft.current = draft;
722
+ setLine(draft.line);
723
+ setTopics(join(draft.topics));
724
+ setSeeking(join(draft.seeking));
725
+ setOffering(join(draft.offering));
726
+ setDrafting(false);
727
+ }
728
+ }, [draft]);
729
+ const card = { line: line.trim(), topics: split(topics), seeking: split(seeking), offering: split(offering) };
730
+ const field = (label, value, set, long) => /* @__PURE__ */ React.createElement("div", {
731
+ className: "tnb-field"
732
+ }, /* @__PURE__ */ React.createElement("span", null, label), long ? /* @__PURE__ */ React.createElement("textarea", {
733
+ className: "tnb-input",
734
+ "aria-label": label,
735
+ rows: 2,
736
+ value,
737
+ onChange: (event) => set(event.target.value)
738
+ }) : /* @__PURE__ */ React.createElement("input", {
739
+ className: "tnb-input",
740
+ "aria-label": label,
741
+ value,
742
+ onChange: (event) => set(event.target.value)
743
+ }));
744
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
745
+ title: t("cardTitle"),
746
+ onClose: close
747
+ }, /* @__PURE__ */ React.createElement("div", {
748
+ className: "tnb-dialog"
749
+ }, /* @__PURE__ */ React.createElement("p", {
750
+ className: "tnb-quiet"
751
+ }, draft ? t("cardDraftReady") : t("cardHint")), field(t("cardLine"), line, setLine, true), field(t("cardTopics"), topics, setTopics), field(t("cardSeeking"), seeking, setSeeking), field(t("cardOffering"), offering, setOffering), drafting && /* @__PURE__ */ React.createElement("p", {
752
+ className: "tnb-quiet"
753
+ }, t("cardDrafting")), /* @__PURE__ */ React.createElement("div", {
754
+ className: "tnb-actions tnb-dialog-actions"
755
+ }, /* @__PURE__ */ React.createElement(Busy, {
756
+ onClick: async () => {
757
+ await call({ kind: "draftCard" });
758
+ setDrafting(true);
759
+ }
760
+ }, t("cardDraft")), /* @__PURE__ */ React.createElement("span", {
761
+ className: "tnb-grow"
762
+ }), /* @__PURE__ */ React.createElement("button", {
763
+ type: "button",
764
+ className: "ta-button",
765
+ onClick: close
766
+ }, t("cancel")), /* @__PURE__ */ React.createElement(Busy, {
767
+ primary: true,
768
+ onClick: async () => {
769
+ store.set(await call({ kind: "cards", card }));
770
+ if (!store.get().settings?.meet) {
771
+ store.set(await call({ kind: "settings", settings: { meet: true } }));
772
+ }
773
+ close();
774
+ }
775
+ }, t("cardUse")))));
776
+ }
777
+ function openCard() {
778
+ pi.ui.custom?.(({ close }) => /* @__PURE__ */ React.createElement(CardDialog, {
779
+ close
780
+ }));
781
+ }
782
+ function MeetRow({ status }) {
783
+ const card = status.cards?.card;
784
+ if (status.settings?.meet && card) {
785
+ return /* @__PURE__ */ React.createElement("p", {
786
+ className: "tnb-meet"
787
+ }, /* @__PURE__ */ React.createElement("span", {
788
+ className: "tnb-quiet tnb-ellipsis"
789
+ }, t("meetOn", { line: card.line || join(card.topics) })), /* @__PURE__ */ React.createElement("button", {
790
+ type: "button",
791
+ className: "tnb-link",
792
+ onClick: openCard
793
+ }, t("cardEdit")));
794
+ }
795
+ return /* @__PURE__ */ React.createElement("div", {
796
+ className: "tnb-code-row"
797
+ }, /* @__PURE__ */ React.createElement("span", {
798
+ className: "tnb-quiet"
799
+ }, status.cards?.draft ? t("cardDraftReady") : t("meetOff")), /* @__PURE__ */ React.createElement("div", {
800
+ className: "tnb-actions"
801
+ }, /* @__PURE__ */ React.createElement("button", {
802
+ type: "button",
803
+ className: "ta-button",
804
+ onClick: () => card ? void call({ kind: "settings", settings: { meet: true } }).then((next) => store.set(next), (error) => pi.ui.notify(message(error), "error")) : openCard()
805
+ }, card ? t("meetTurnOn") : status.cards?.draft ? t("cardEdit") : t("meetTurnOn"))));
806
+ }
807
+ function MeetSetting() {
808
+ const [settings, change] = useSettings();
809
+ const status = useStatus();
810
+ return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
811
+ checked: settings.meet === true,
812
+ label: t("settingsMeet"),
813
+ onChange: (on) => on && !status.cards?.card ? openCard() : change({ meet: on })
814
+ });
815
+ }
816
+ function CardSetting() {
817
+ const status = useStatus();
818
+ const card = status.cards?.card;
819
+ return /* @__PURE__ */ React.createElement("span", {
820
+ className: "tnb-card-setting"
821
+ }, /* @__PURE__ */ React.createElement("span", {
822
+ className: "tnb-quiet tnb-ellipsis"
823
+ }, card ? card.line || join(card.topics) : status.cards?.draft ? t("cardDraftReady") : t("cardNone")), /* @__PURE__ */ React.createElement("button", {
824
+ type: "button",
825
+ className: "ta-button",
826
+ onClick: openCard
827
+ }, t("cardEdit")));
828
+ }
829
+ var inviting;
830
+ function openInvite(invite) {
831
+ if (inviting || !pi.ui.custom) {
832
+ return;
833
+ }
834
+ inviting = invite.k;
835
+ pi.ui.custom(({ close }) => {
836
+ const done = () => {
837
+ inviting = undefined;
838
+ close();
839
+ };
840
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
841
+ title: t("title"),
842
+ onClose: done
843
+ }, /* @__PURE__ */ React.createElement("div", {
844
+ className: "tnb-dialog"
845
+ }, /* @__PURE__ */ React.createElement("div", {
846
+ className: "tnb-dialog-head"
847
+ }, /* @__PURE__ */ React.createElement(Face, {
848
+ seed: invite.friend?.id ?? invite.e,
849
+ face: invite.face,
850
+ size: 48
851
+ }), /* @__PURE__ */ React.createElement("div", {
852
+ className: "tnb-invite-text"
853
+ }, /* @__PURE__ */ React.createElement("strong", null, t("invited", { name: who(invite), title: invite.title })), invite.friend ? /* @__PURE__ */ React.createElement("span", {
854
+ className: "tnb-tag tnb-tag-friend"
855
+ }, t("friend")) : null)), invite.why && /* @__PURE__ */ React.createElement("p", null, invite.why), /* @__PURE__ */ React.createElement("p", {
856
+ className: "tnb-quiet"
857
+ }, [t("inviteNote"), invite.friend ? "" : t("inviteStranger")].filter(Boolean).join(pi.ui.language === "zh-CN" ? "" : " ")), /* @__PURE__ */ React.createElement("div", {
858
+ className: "tnb-actions tnb-dialog-actions"
859
+ }, /* @__PURE__ */ React.createElement(Busy, {
860
+ onClick: () => answer(invite.k, false).finally(done)
861
+ }, t("notNow")), /* @__PURE__ */ React.createElement(Busy, {
862
+ primary: true,
863
+ onClick: () => answer(invite.k, true).finally(done)
864
+ }, t("join")))));
865
+ });
866
+ }
867
+
868
+ class NearbyHome {
869
+ current = [];
870
+ signature = "";
871
+ listeners = new Set;
872
+ items = () => this.current;
873
+ subscribe = (listener) => {
874
+ this.listeners.add(listener);
875
+ return () => this.listeners.delete(listener);
876
+ };
877
+ start() {
878
+ const stop = store.subscribe(() => this.refresh());
879
+ const timer = setInterval(() => this.refresh(), 60000);
880
+ this.refresh();
881
+ return () => {
882
+ stop();
883
+ clearInterval(timer);
884
+ };
885
+ }
886
+ refresh() {
887
+ const status = store.get();
888
+ const greets = status.greets ?? [];
889
+ const shown = status.visible || status.invites.length > 0 || greets.length > 0;
890
+ const detail = status.invites.length ? t("invited", { name: who(status.invites[0]), title: status.invites[0].title }) : greets.length ? t("greetLine", { name: who(greets[0]) }) : status.peers.length ? t("homeDetail", { n: status.peers.length, names: names(status.peers.slice(0, 3).map(who)) }) : t("homeNobody", { left: leftText(status.until) });
891
+ const signature = shown ? [detail, status.invites.length, greets.length, status.peers.map((peer) => peer.e).join(",")].join("|") : "";
892
+ if (signature === this.signature) {
893
+ return;
894
+ }
895
+ this.signature = signature;
896
+ this.current = shown ? [
897
+ {
898
+ id: "nearby",
899
+ title: t("title"),
900
+ detail,
901
+ icon: icon("Radar"),
902
+ unseen: status.invites.length > 0 || greets.length > 0,
903
+ ...status.peers.length && pi.ui.GroupFace ? {
904
+ face: ({ size }) => /* @__PURE__ */ React.createElement(pi.ui.GroupFace, {
905
+ members: store.get().peers.map((peer) => ({ seed: peer.friend?.id ?? peer.e, face: peer.face })),
906
+ size
907
+ })
908
+ } : {},
909
+ open: () => pi.ui.showView(NEARBY_VIEW)
910
+ }
911
+ ] : [];
912
+ for (const listener of this.listeners) {
913
+ listener();
914
+ }
915
+ }
916
+ }
917
+ function NameSwitch() {
918
+ const [settings, change] = useSettings();
919
+ return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
920
+ checked: settings.hideName !== true,
921
+ label: t("settingsName"),
922
+ onChange: (on) => change({ hideName: !on })
923
+ });
924
+ }
925
+ function nearbySettings() {
926
+ return {
927
+ title: () => t("title"),
928
+ icon: icon("Radar"),
929
+ rows: [
930
+ { key: "name", label: () => t("settingsName"), description: () => t("settingsNameHint"), render: NameSwitch },
931
+ { key: "show", label: () => t("settingsShow"), description: () => t("settingsShowHint"), render: ShowSetting },
932
+ { key: "work", label: () => t("settingsWork"), description: () => t("settingsWorkHint"), render: WorkSetting },
933
+ { key: "meet", label: () => t("settingsMeet"), description: () => t("settingsMeetHint"), render: MeetSetting },
934
+ { key: "card", label: () => t("card"), render: CardSetting }
935
+ ]
936
+ };
937
+ }
938
+
939
+ // web-src/style.ts
940
+ var STYLE = `
941
+ .tnb-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
942
+ .tnb-quiet { color: var(--ta-muted); }
943
+ .tnb-page { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overscroll-behavior: none; }
944
+ .tnb-body { display: flex; flex-direction: column; gap: 18px; max-width: 560px; margin: 0 auto; padding: 12px 16px calc(28px + env(safe-area-inset-bottom)); box-sizing: border-box; }
945
+ .tnb-section h3 { margin: 0 0 6px; padding: 0 4px; font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; color: var(--ta-muted); }
946
+ .tnb-card { margin: 0; padding: 2px 10px; list-style: none; border-radius: 14px; background: var(--ta-raised); }
947
+ .tnb-invite { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 10px 0; }
948
+ .tnb-invite > .ta-face, .tnb-invite > .trm-face { align-self: flex-start; }
949
+ .tnb-invite .tnb-actions { margin-left: auto; }
950
+ .tnb-invite + .tnb-invite { border-top: 1px solid var(--ta-border-muted); }
951
+ .tnb-invite-text { display: flex; flex-direction: column; gap: 3px; flex: 1 1 200px; min-width: 0; font-size: calc(13.5px * var(--ta-font-scale)); line-height: 1.45; }
952
+ .tnb-invite-text .tnb-tag { align-self: flex-start; }
953
+ .tnb-actions { display: flex; gap: 8px; flex: none; }
954
+ /* Off: what it does, and for how long */
955
+ .tnb-off, .tnb-on { display: flex; flex-direction: column; align-items: center; text-align: center; }
956
+ .tnb-off h2 { margin: 6px 0 6px; font-size: calc(17px * var(--ta-font-scale)); font-weight: 600; }
957
+ .tnb-off p { max-width: 380px; margin: 0; font-size: calc(13px * var(--ta-font-scale)); line-height: 1.6; }
958
+ .tnb-durations { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 280px; margin-top: 20px; }
959
+ .tnb-durations .ta-button { width: 100%; justify-content: center; min-height: 40px; }
960
+ /* Rings that go out from the user */
961
+ .tnb-looking { position: relative; width: 220px; height: 220px; margin: 8px 0 4px; }
962
+ .tnb-ring { position: absolute; inset: 0; margin: auto; width: 100%; height: 100%; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--ta-accent, var(--ta-link)) 35%, transparent); background: radial-gradient(circle, color-mix(in srgb, var(--ta-accent, var(--ta-link)) 7%, transparent) 0%, transparent 70%); animation: tnb-out 3.6s ease-out infinite; opacity: 0; }
963
+ .tnb-ring-2 { animation-delay: 1.2s; }
964
+ .tnb-ring-3 { animation-delay: 2.4s; }
965
+ @keyframes tnb-out { 0% { transform: scale(0.25); opacity: 0.9; } 100% { transform: scale(1); opacity: 0; } }
966
+ @media (prefers-reduced-motion: reduce) { .tnb-ring { animation: none; opacity: 0.5; } .tnb-ring-2 { transform: scale(0.66); } .tnb-ring-3 { transform: scale(0.33); } }
967
+ .tnb-me { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: grid; place-items: center; }
968
+ .tnb-spot { position: absolute; transform: translate(-50%, -50%); animation: tnb-in 300ms ease-out both; }
969
+ @keyframes tnb-in { from { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } }
970
+ .tnb-on-line { display: flex; align-items: center; gap: 8px; font-size: calc(13px * var(--ta-font-scale)); }
971
+ .tnb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ta-green); }
972
+ .tnb-link { padding: 2px 6px; border: 0; border-radius: 6px; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
973
+ .tnb-link:hover { background: var(--ta-hover); }
974
+ .tnb-error { margin: 8px 0 0; color: var(--ta-red); font-size: calc(12px * var(--ta-font-scale)); }
975
+ .tnb-nobody { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; text-align: center; font-size: calc(13px * var(--ta-font-scale)); }
976
+ /* Those around: tiles to choose */
977
+ .tnb-peers { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0; padding: 0; list-style: none; }
978
+ .tnb-peers > li { width: 96px; }
979
+ .tnb-peer { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 100%; padding: 12px 6px 10px; border: 1px solid transparent; border-radius: 14px; background: var(--ta-raised); color: var(--ta-text); font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: border-color 120ms, opacity 120ms; }
980
+ .tnb-peer:not(.tnb-chosen) { opacity: 0.55; }
981
+ .tnb-peer.tnb-chosen { border-color: color-mix(in srgb, var(--ta-accent, var(--ta-link)) 45%, transparent); }
982
+ .tnb-peer:focus-visible { outline: 1px solid var(--ta-border-focus); }
983
+ .tnb-peer-face { position: relative; display: inline-flex; }
984
+ .tnb-check { position: absolute; right: -4px; bottom: -4px; }
985
+ .tnb-peer-name { max-width: 100%; font-size: calc(13px * var(--ta-font-scale)); font-weight: 500; }
986
+ .tnb-tag { 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)); line-height: calc(17px * var(--ta-font-scale)); }
987
+ .tnb-tag-friend { background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: var(--ta-green); }
988
+ .tnb-make { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
989
+ .tnb-make .ta-button { min-width: 200px; min-height: 40px; justify-content: center; }
990
+ .tnb-make p { margin: 0; font-size: calc(12px * var(--ta-font-scale)); }
991
+ .tnb-code-row { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px; border-radius: 14px; background: var(--ta-raised); font-size: calc(12.5px * var(--ta-font-scale)); text-align: center; }
992
+ .tnb-code-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 12px; border-radius: 14px; background: var(--ta-raised); font-size: calc(12.5px * var(--ta-font-scale)); text-align: center; }
993
+ .tnb-code { font-size: calc(30px * var(--ta-font-scale)); font-weight: 600; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
994
+ .tnb-self { display: flex; justify-content: center; gap: 8px; margin: 0; font-size: calc(12px * var(--ta-font-scale)); }
995
+ .tnb-select { height: 32px; padding: 0 28px 0 10px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: var(--ta-main); color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); }
996
+ .tnb-field { display: flex; flex-direction: column; gap: 4px; font-size: calc(12.5px * var(--ta-font-scale)); color: var(--ta-secondary); }
997
+ .tnb-input { box-sizing: border-box; width: 100%; padding: 7px 10px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: var(--ta-main); color: var(--ta-text); font: inherit; font-size: calc(14px * var(--ta-font-scale)); resize: vertical; }
998
+ .tnb-input:focus { outline: none; border-color: var(--ta-border-focus); }
999
+ .tnb-grow { flex: 1; }
1000
+ .tnb-meet { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0; min-width: 0; font-size: calc(12.5px * var(--ta-font-scale)); }
1001
+ .tnb-card-setting { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 360px; font-size: calc(13px * var(--ta-font-scale)); }
1002
+ .tnb-card-setting .ta-button { flex: none; }
1003
+ /* What one nearby shows, over the page */
1004
+ .tnb-show { background: var(--ta-main); color: var(--ta-text); }
1005
+ .tnb-show-bar { flex: none; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; box-sizing: border-box; border-bottom: 1px solid var(--ta-border-muted); font-size: calc(13px * var(--ta-font-scale)); }
1006
+ .tnb-show-title { font-weight: 600; font-size: calc(14px * var(--ta-font-scale)); }
1007
+ .tnb-show-bar .ta-button { margin-left: auto; flex: none; }
1008
+ .tnb-show-body { flex: 1; min-height: 0; display: flex; overflow: auto; }
1009
+ .tnb-show-frame { flex: 1; width: 100%; border: 0; background: #fff; }
1010
+ .tnb-show-image { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
1011
+ .tnb-show-text { width: 100%; max-width: 860px; margin: 0 auto; padding: 24px; box-sizing: border-box; font-size: calc(16px * var(--ta-font-scale)); line-height: 1.7; }
1012
+ .tnb-show-pre { white-space: pre-wrap; font-family: var(--ta-mono, ui-monospace, monospace); font-size: calc(14px * var(--ta-font-scale)); }
1013
+ /* The invitation over the page */
1014
+ .tnb-dialog { display: flex; flex-direction: column; gap: 10px; min-width: min(360px, 80vw); font-size: calc(13.5px * var(--ta-font-scale)); line-height: 1.5; }
1015
+ .tnb-dialog p { margin: 0; }
1016
+ .tnb-dialog-head { display: flex; align-items: center; gap: 12px; }
1017
+ .tnb-dialog-actions { justify-content: flex-end; margin-top: 4px; }
1018
+ `;
1019
+ function injectStyle() {
1020
+ const style = document.createElement("style");
1021
+ style.dataset.taNearby = "";
1022
+ style.textContent = STYLE;
1023
+ document.head.append(style);
1024
+ return () => style.remove();
1025
+ }
1026
+
1027
+ // web-src/index.tsx
1028
+ function activate(pi2) {
1029
+ bind(pi2.React);
1030
+ bindPage(pi2);
1031
+ const removeStyle = injectStyle();
1032
+ pi2.registerView("nearby", { title: () => t("title"), icon: icon("Radar"), render: NearbyPage, discover: true, order: 82 });
1033
+ pi2.registerSettings(nearbySettings());
1034
+ const home = new NearbyHome;
1035
+ const stopHome = home.start();
1036
+ pi2.registerHomeItems?.(home);
1037
+ store.onInvites = (invites) => {
1038
+ const latest = invites[invites.length - 1];
1039
+ if (latest) {
1040
+ openInvite(latest);
1041
+ }
1042
+ };
1043
+ store.onShown = openShown;
1044
+ const stop = store.start();
1045
+ return () => {
1046
+ stop();
1047
+ stopHome();
1048
+ store.onInvites = undefined;
1049
+ store.onShown = undefined;
1050
+ removeStyle();
1051
+ };
1052
+ }
1053
+ export {
1054
+ activate as default
1055
+ };