@celljs/ta-moments 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,1987 @@
1
+ // web-src/brief-util.ts
2
+ var BRIEF_MARK = "[ta-moments:brief]";
3
+ var ITEMS = 20;
4
+ var TEXT_CHARS = 240;
5
+ var WHY_CHARS = 120;
6
+ var MomentsBrief;
7
+ ((MomentsBrief) => {
8
+ function link(relay, room, post) {
9
+ return `${relay.replace(/\/+$/, "")}/m#${new URLSearchParams({ r: room, p: post })}`;
10
+ }
11
+ MomentsBrief.link = link;
12
+ function parse(url) {
13
+ try {
14
+ const parsed = new URL(url);
15
+ const fragment = new URLSearchParams(parsed.hash.slice(1));
16
+ const room = fragment.get("r") ?? "";
17
+ const post = fragment.get("p") ?? "";
18
+ return /^https?:$/.test(parsed.protocol) && parsed.pathname === "/m" && /^[A-Za-z0-9_-]{1,64}$/.test(room) && /^[0-9a-f]{8}$/.test(post) ? { room, post } : undefined;
19
+ } catch {
20
+ return;
21
+ }
22
+ }
23
+ MomentsBrief.parse = parse;
24
+ function source(posts, relayOf) {
25
+ const items = posts.filter((post) => !post.mine).sort((a, b) => a.at - b.at).slice(-ITEMS).map((post) => {
26
+ const holds = post.attach?.kind === "package" ? ` [an extension to take: ${post.attach.title}${post.attach.summary ? ` — ${post.attach.summary}` : ""}]` : post.attach ? ` [a link: ${post.attach.title}]` : "";
27
+ const pictures = post.images.length ? ` [${post.images.length} picture${post.images.length > 1 ? "s" : ""}]` : "";
28
+ return {
29
+ at: post.at,
30
+ text: `${post.author.name}: ${flat(post.text, TEXT_CHARS)}${holds}${pictures} — link: ${link(relayOf(post.room), post.room, post.id)}`
31
+ };
32
+ });
33
+ return {
34
+ section: "Posts of the user's Ta friends in Moments, what they made with Ta",
35
+ instruction: [
36
+ "pick at most 3 that matter to this user, by what you know of them (what Ta learned of them, their conversations above):",
37
+ "something they work on or asked for, or could use. Write them as a part of its own after the others, headed",
38
+ '"### 好友在做" in Chinese or "### Friends made" in English, one line each:',
39
+ "[name: a few words of the post](its link) — why it matters to them, in a few words.",
40
+ `Leave the part out when none does: never pick to fill it. ${BRIEF_MARK}`
41
+ ].join(" "),
42
+ items
43
+ };
44
+ }
45
+ MomentsBrief.source = source;
46
+ function picks(answer) {
47
+ const picked = [];
48
+ for (const line of answer.split(/\r?\n/)) {
49
+ const found = /\[[^\]]*\]\(<?(https?:\/\/[^)\s>]+)>?\)(.*)$/.exec(line);
50
+ const target = found && parse(found[1]);
51
+ if (!found || !target || picked.some((pick) => pick.room === target.room && pick.post === target.post)) {
52
+ continue;
53
+ }
54
+ const why = flat(found[2].replace(/^\s*[—–::-]+\s*/, "").replace(/[*_`]+/g, ""), WHY_CHARS);
55
+ picked.push({ ...target, why });
56
+ }
57
+ return picked.slice(0, 3);
58
+ }
59
+ MomentsBrief.picks = picks;
60
+ function flat(text, chars) {
61
+ const line = text.replace(/\s+/g, " ").trim();
62
+ return line.length > chars ? `${line.slice(0, chars)}…` : line;
63
+ }
64
+ })(MomentsBrief ||= {});
65
+
66
+ // web-src/i18n.ts
67
+ var zh = {
68
+ title: "动态",
69
+ post: "发动态",
70
+ addFriend: "加好友",
71
+ friends: "好友",
72
+ friendsCount: "{n} 位",
73
+ friendsNone: "还没有",
74
+ emptyTitle: "还没有好友",
75
+ emptyHint: "加好友后,你们互相看到对方用 Ta 做出来的东西,也能拿去用。",
76
+ noPosts: "还没有动态",
77
+ noPostsHint: "做出满意的东西时,Ta 会问要不要发;也可以点右上角自己发。",
78
+ send: "发送",
79
+ waiting: "等对方同意",
80
+ remove: "删除好友",
81
+ like: "赞",
82
+ unlike: "取消赞",
83
+ take: "拿去用",
84
+ open: "打开",
85
+ takeAgain: "再拿一次",
86
+ tookBy: "{names} 拿去用了",
87
+ deletePost: "删除",
88
+ deleteTitle: "删除这条动态?",
89
+ deleteBody: "好友那里也会一起消失。",
90
+ expires: "{days} 天后消失",
91
+ expiresSoon: "今天消失",
92
+ justNow: "刚刚",
93
+ minutes: "{n} 分钟前",
94
+ hours: "{n} 小时前",
95
+ yesterday: "昨天",
96
+ days: "{n} 天前",
97
+ packageKind: "扩展",
98
+ linkKind: "链接",
99
+ packageHint: "拿去用时,Ta 先读一遍代码、说清它会做什么,你同意了才装",
100
+ expired: "已过期",
101
+ whyHint: "每日简报为你挑的",
102
+ postGone: "这条动态已经不在了",
103
+ waitPictures: "原图在{name}的电脑上,等它上线后显示",
104
+ takeOffline: "在{name}的电脑上,等它上线后才能拿",
105
+ placeholder: "说说你用 Ta 做了什么…",
106
+ addImage: "添加图片",
107
+ removeImage: "移除图片",
108
+ attach: "附带",
109
+ attachNone: "不附带",
110
+ keep: "保留",
111
+ keep3: "3 天",
112
+ keep30: "1 个月",
113
+ keep180: "半年",
114
+ keep0: "长期",
115
+ publish: "发表",
116
+ publishing: "正在发表…",
117
+ cancel: "取消",
118
+ notNow: "不发了",
119
+ draftHead: "发到动态?",
120
+ draftHint: "只有你的好友看得到。",
121
+ draftPosted: "已发到动态",
122
+ draftDeclined: "没有发。",
123
+ viewPost: "去看看",
124
+ failed: "没成功:{message}",
125
+ toolDraft: "起草动态",
126
+ oldApp: "这个功能需要更新的 Ta",
127
+ noFriendsPage: "好友在「房间」里管理,请先在扩展里打开「房间」",
128
+ me: "我",
129
+ imageAlt: "{name} 的图片",
130
+ allowAsk: "好友可以问 Ta",
131
+ allowAskHint: "Ta 只凭这条动态回答,你都看得到",
132
+ comment: "评论",
133
+ askTa: "问 Ta",
134
+ askTaHint: "{name}的 Ta 会按这条动态回答你",
135
+ commentPlaceholder: "评论",
136
+ replyPlaceholder: "回复{name}",
137
+ askPlaceholder: "问{name}的 Ta,比如怎么做的",
138
+ theirTa: "{name}的 Ta",
139
+ replyWord: "回复",
140
+ answerWord: "回答",
141
+ askWord: "问",
142
+ pending: "等{name}上线后送到",
143
+ sending: "送出中",
144
+ deleteTalkTitle: "删除这条评论?",
145
+ deleteAnswerTitle: "删除 Ta 的这条回答?",
146
+ deleteAnswerBody: "也可以点它回复,补充或纠正。",
147
+ deleteTalk: "删除"
148
+ };
149
+ var en = {
150
+ title: "Moments",
151
+ post: "Post",
152
+ addFriend: "Add friend",
153
+ friends: "Friends",
154
+ friendsCount: "{n}",
155
+ friendsNone: "None yet",
156
+ emptyTitle: "No friends yet",
157
+ emptyHint: "Once you add friends, you see what each other makes with Ta, and can take it.",
158
+ noPosts: "No posts yet",
159
+ noPostsHint: "When you make something you like, Ta offers to post it; or post yourself from the top.",
160
+ send: "Send",
161
+ waiting: "Waiting for them",
162
+ remove: "Remove",
163
+ like: "Like",
164
+ unlike: "Unlike",
165
+ take: "Take it",
166
+ open: "Open",
167
+ takeAgain: "Take again",
168
+ tookBy: "{names} took it",
169
+ deletePost: "Delete",
170
+ deleteTitle: "Delete this post?",
171
+ deleteBody: "It goes for your friends too.",
172
+ expires: "Goes in {days} days",
173
+ expiresSoon: "Goes today",
174
+ justNow: "Just now",
175
+ minutes: "{n} min ago",
176
+ hours: "{n} h ago",
177
+ yesterday: "Yesterday",
178
+ days: "{n} days ago",
179
+ packageKind: "Extension",
180
+ linkKind: "Link",
181
+ packageHint: "Taking it, Ta reads its code first and installs it once you agree",
182
+ expired: "Expired",
183
+ whyHint: "Picked for you by the daily brief",
184
+ postGone: "This post is gone",
185
+ waitPictures: "The pictures are on the computer of {name}: they show once it is online",
186
+ takeOffline: "On the computer of {name}: take it once it is online",
187
+ placeholder: "What did you make with Ta…",
188
+ addImage: "Add a picture",
189
+ removeImage: "Remove the picture",
190
+ attach: "Attach",
191
+ attachNone: "Nothing",
192
+ keep: "Keep",
193
+ keep3: "3 days",
194
+ keep30: "A month",
195
+ keep180: "Half a year",
196
+ keep0: "For good",
197
+ publish: "Post",
198
+ publishing: "Posting…",
199
+ cancel: "Cancel",
200
+ notNow: "Not now",
201
+ draftHead: "Post to Moments?",
202
+ draftHint: "Only your friends see it.",
203
+ draftPosted: "Posted to Moments",
204
+ draftDeclined: "Not posted.",
205
+ viewPost: "See it",
206
+ failed: "That did not work: {message}",
207
+ toolDraft: "Draft a post",
208
+ oldApp: "This needs a newer Ta",
209
+ noFriendsPage: "Friends are kept in Rooms: turn Rooms on in Extensions first",
210
+ me: "Me",
211
+ imageAlt: "A picture of {name}",
212
+ allowAsk: "Friends may ask Ta",
213
+ allowAskHint: "Ta answers from this post alone; you see it all",
214
+ comment: "Comment",
215
+ askTa: "Ask Ta",
216
+ askTaHint: "The Ta of {name} answers from this post",
217
+ commentPlaceholder: "Comment",
218
+ replyPlaceholder: "Reply to {name}",
219
+ askPlaceholder: "Ask the Ta of {name}, say how it was made",
220
+ theirTa: "Ta of {name}",
221
+ replyWord: "to",
222
+ answerWord: "to",
223
+ askWord: "asks",
224
+ pending: "Goes once {name} is online",
225
+ sending: "Sending",
226
+ deleteTalkTitle: "Delete this comment?",
227
+ deleteAnswerTitle: "Delete Ta's answer?",
228
+ deleteAnswerBody: "Or tap it to reply, adding to it or putting it right.",
229
+ deleteTalk: "Delete"
230
+ };
231
+ var MomentsWords;
232
+ ((MomentsWords) => {
233
+ function of(language) {
234
+ return /^zh/i.test(language) ? zh : en;
235
+ }
236
+ MomentsWords.of = of;
237
+ function format(text, values = {}) {
238
+ return text.replace(/\{(\w+)\}/g, (_, name) => String(values[name] ?? ""));
239
+ }
240
+ MomentsWords.format = format;
241
+ function ago(words, at, now, language) {
242
+ const minutes = Math.floor((now - at) / 60000);
243
+ if (minutes < 1) {
244
+ return words.justNow;
245
+ }
246
+ if (minutes < 60) {
247
+ return format(words.minutes, { n: minutes });
248
+ }
249
+ if (minutes < 24 * 60) {
250
+ return format(words.hours, { n: Math.floor(minutes / 60) });
251
+ }
252
+ const days = Math.floor(minutes / (24 * 60));
253
+ if (days === 1) {
254
+ return words.yesterday;
255
+ }
256
+ if (days < 7) {
257
+ return format(words.days, { n: days });
258
+ }
259
+ return new Date(at).toLocaleDateString(/^zh/i.test(language) ? "zh-CN" : undefined, { month: "numeric", day: "numeric" });
260
+ }
261
+ MomentsWords.ago = ago;
262
+ })(MomentsWords ||= {});
263
+
264
+ // web-src/context.ts
265
+ var React;
266
+ var pi;
267
+ function bind(api) {
268
+ pi = api;
269
+ React = api.React;
270
+ }
271
+ function t(key, values) {
272
+ return MomentsWords.format(MomentsWords.of(pi.ui.language)[key], values);
273
+ }
274
+ function message(error) {
275
+ return error instanceof Error ? error.message.replace(/^.*?Error: /, "") : String(error);
276
+ }
277
+ function failed(error) {
278
+ pi.ui.notify(t("failed", { message: message(error) }), "error");
279
+ }
280
+ function useBusy() {
281
+ const idle = () => [false, async (action) => await action()];
282
+ return (pi.ui.useBusy ?? idle)();
283
+ }
284
+ function icon(name, fallback = "Circle") {
285
+ return pi.ui.icons[name] ?? pi.ui.icons[fallback];
286
+ }
287
+
288
+ // ../ta-protocol/esm/common/access-protocol.js
289
+ var TaAccessServer = Symbol("TaAccessServer");
290
+ // ../ta-protocol/esm/common/auth-protocol.js
291
+ var TaAuthServer = Symbol("TaAuthServer");
292
+ // ../ta-protocol/esm/common/gateway-protocol.js
293
+ var TaGatewayServer = Symbol("TaGatewayServer");
294
+ // ../ta-protocol/esm/common/location.js
295
+ var TaLocation;
296
+ (function(TaLocation2) {
297
+ TaLocation2.SSH = "ssh://";
298
+ const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
299
+ function isRemote(location) {
300
+ return location.startsWith(TaLocation2.SSH);
301
+ }
302
+ TaLocation2.isRemote = isRemote;
303
+ function parse(location) {
304
+ if (!isRemote(location)) {
305
+ return;
306
+ }
307
+ const rest = location.slice(TaLocation2.SSH.length);
308
+ const slash = rest.indexOf("/");
309
+ const host2 = slash < 0 ? rest : rest.slice(0, slash);
310
+ const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
311
+ if (!isHost(host2)) {
312
+ throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
313
+ }
314
+ return { host: host2, path: path2 };
315
+ }
316
+ TaLocation2.parse = parse;
317
+ function isHost(host2) {
318
+ return HOST.test(host2);
319
+ }
320
+ TaLocation2.isHost = isHost;
321
+ const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
322
+ function readHost(input) {
323
+ const words = input.trim().split(/\s+/).filter(Boolean);
324
+ if (words[0] === "ssh") {
325
+ words.shift();
326
+ }
327
+ let destination;
328
+ let port;
329
+ let user;
330
+ const options = [];
331
+ for (let i = 0;i < words.length; i++) {
332
+ const word = words[i];
333
+ const glued = /^-([pl])(.+)$/.exec(word);
334
+ if (word === "-p" || word === "-l" || glued) {
335
+ const value = glued ? glued[2] : words[++i];
336
+ if (value === undefined) {
337
+ return { error: "invalid" };
338
+ }
339
+ if ((glued ? glued[1] : word[1]) === "p") {
340
+ port = value;
341
+ } else {
342
+ user = value;
343
+ }
344
+ } else if (word === "-o" || word.startsWith("-o")) {
345
+ const value = word === "-o" ? words[++i] : word.slice(2);
346
+ const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
347
+ if (!option) {
348
+ options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
349
+ } else if (option[1].toLowerCase() === "port") {
350
+ port = option[2];
351
+ } else {
352
+ user = option[2];
353
+ }
354
+ } else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
355
+ options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
356
+ } else if (destination === undefined) {
357
+ destination = word;
358
+ } else {
359
+ return { error: "invalid" };
360
+ }
361
+ }
362
+ if (options.length > 0) {
363
+ return { error: "options", options };
364
+ }
365
+ if (!destination) {
366
+ return { error: "empty" };
367
+ }
368
+ let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
369
+ if (user && !host2.includes("@")) {
370
+ host2 = `${user}@${host2}`;
371
+ }
372
+ if (port) {
373
+ if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
374
+ return { error: "invalid" };
375
+ }
376
+ host2 = port === "22" ? host2 : `${host2}:${port}`;
377
+ }
378
+ return isHost(host2) ? { host: host2 } : { error: "invalid" };
379
+ }
380
+ TaLocation2.readHost = readHost;
381
+ function ssh(host2, path2 = "") {
382
+ return `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
383
+ }
384
+ TaLocation2.ssh = ssh;
385
+ function hostLabel(host2) {
386
+ const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
387
+ return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
388
+ }
389
+ TaLocation2.hostLabel = hostLabel;
390
+ function host(location) {
391
+ var _a;
392
+ return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
393
+ }
394
+ TaLocation2.host = host;
395
+ function path(location) {
396
+ var _a;
397
+ var _b;
398
+ return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
399
+ }
400
+ TaLocation2.path = path;
401
+ function parent(location) {
402
+ const remote = parse(location);
403
+ if (remote) {
404
+ const above = remote.path ? parentPath(remote.path) : undefined;
405
+ return above === undefined ? undefined : ssh(remote.host, above);
406
+ }
407
+ return parentPath(location);
408
+ }
409
+ TaLocation2.parent = parent;
410
+ function child(location, name) {
411
+ const remote = parse(location);
412
+ if (remote) {
413
+ return ssh(remote.host, childPath(remote.path || "/", name));
414
+ }
415
+ return childPath(location, name);
416
+ }
417
+ TaLocation2.child = child;
418
+ function basename(location) {
419
+ const remote = parse(location);
420
+ const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
421
+ const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
422
+ return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
423
+ }
424
+ TaLocation2.basename = basename;
425
+ function homeRelative(location) {
426
+ var _a;
427
+ const remote = parse(location);
428
+ const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
429
+ const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
430
+ return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
431
+ }
432
+ TaLocation2.homeRelative = homeRelative;
433
+ function isAbsolute(location) {
434
+ if (homeRelative(location) !== undefined) {
435
+ return false;
436
+ }
437
+ return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
438
+ }
439
+ TaLocation2.isAbsolute = isAbsolute;
440
+ function parentPath(path2) {
441
+ const trimmed = path2.replace(/[\\/]+$/, "");
442
+ const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
443
+ if (at < 0) {
444
+ return;
445
+ }
446
+ const head = trimmed.slice(0, at);
447
+ return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
448
+ }
449
+ function childPath(path2, name) {
450
+ const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
451
+ return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
452
+ }
453
+ function normalize(path2) {
454
+ const squeezed = `/${path2}`.replace(/\/+/g, "/");
455
+ return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
456
+ }
457
+ })(TaLocation || (TaLocation = {}));
458
+ // ../ta-protocol/esm/common/package-protocol.js
459
+ var TaPackageServer = Symbol("TaPackageServer");
460
+ var TaPackageTextUtil;
461
+ (function(TaPackageTextUtil2) {
462
+ function pick(text, language) {
463
+ var _a, _b, _c, _d;
464
+ if (text === undefined || typeof text === "string") {
465
+ return text;
466
+ }
467
+ return (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[language.split("-")[0]]) !== null && _b !== undefined ? _b : text.en) !== null && _c !== undefined ? _c : text["en-US"]) !== null && _d !== undefined ? _d : Object.values(text)[0];
468
+ }
469
+ TaPackageTextUtil2.pick = pick;
470
+ })(TaPackageTextUtil || (TaPackageTextUtil = {}));
471
+ // ../ta-protocol/esm/common/relay-protocol.js
472
+ var TaRelayServer = Symbol("TaRelayServer");
473
+ // ../ta-protocol/esm/common/remote-protocol.js
474
+ var TaRemoteServer = Symbol("TaRemoteServer");
475
+ // ../ta-protocol/esm/common/room-protocol.js
476
+ var TaRoomServer = Symbol("TaRoomServer");
477
+ var TaRoomWatchUtil;
478
+ (function(TaRoomWatchUtil2) {
479
+ function of(messages, state) {
480
+ const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
481
+ return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
482
+ }
483
+ TaRoomWatchUtil2.of = of;
484
+ function union(watches) {
485
+ let messages = false;
486
+ const state = [];
487
+ for (const watch of watches) {
488
+ messages || (messages = watch.messages);
489
+ state.push(...watch.state);
490
+ }
491
+ return of(messages, messages ? [] : state);
492
+ }
493
+ TaRoomWatchUtil2.union = union;
494
+ function same(a, b) {
495
+ return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
496
+ `) === b.state.join(`
497
+ `);
498
+ }
499
+ TaRoomWatchUtil2.same = same;
500
+ function hears(watch, event) {
501
+ if (event.type === "message") {
502
+ return watch.messages;
503
+ }
504
+ if (event.type === "state") {
505
+ return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
506
+ }
507
+ return true;
508
+ }
509
+ TaRoomWatchUtil2.hears = hears;
510
+ })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
511
+ // ../ta-protocol/esm/common/settings-protocol.js
512
+ var TaSettingsServer = Symbol("TaSettingsServer");
513
+ // ../ta-protocol/esm/common/ta-extension-host.js
514
+ var TA_HOST_EVENT = "ta:host";
515
+ var TaHostUtil;
516
+ (function(TaHostUtil2) {
517
+ TaHostUtil2.WAIT_MS = 1000;
518
+ function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
519
+ return new Promise((resolve) => {
520
+ let heard = false;
521
+ let answered = false;
522
+ const timer = setTimeout(() => resolve(undefined), waitMs);
523
+ const request = {
524
+ name,
525
+ heard: () => {
526
+ heard = true;
527
+ },
528
+ resolve: (answer) => {
529
+ answered = true;
530
+ clearTimeout(timer);
531
+ resolve(answer);
532
+ }
533
+ };
534
+ events.emit(TA_HOST_EVENT, request);
535
+ if (!heard && !answered) {
536
+ clearTimeout(timer);
537
+ resolve(undefined);
538
+ }
539
+ });
540
+ }
541
+ TaHostUtil2.reach = reach;
542
+ })(TaHostUtil || (TaHostUtil = {}));
543
+ var TA_ASK_ENTRY = "ta-ask";
544
+ var TaAskUtil;
545
+ (function(TaAskUtil2) {
546
+ const LENGTH = 120;
547
+ function entry(question) {
548
+ const line = question.replace(/\s+/g, " ").trim();
549
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
550
+ }
551
+ TaAskUtil2.entry = entry;
552
+ function asking(entries) {
553
+ var _a;
554
+ for (let i = entries.length - 1;i >= 0; i--) {
555
+ const entry2 = entries[i];
556
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
557
+ return;
558
+ }
559
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
560
+ return read(entry2);
561
+ }
562
+ }
563
+ return;
564
+ }
565
+ TaAskUtil2.asking = asking;
566
+ function next(asked, entry2) {
567
+ var _a;
568
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
569
+ return;
570
+ }
571
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
572
+ }
573
+ TaAskUtil2.next = next;
574
+ function read(found) {
575
+ var _a;
576
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
577
+ if (typeof question !== "string" || !question.trim()) {
578
+ return;
579
+ }
580
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
581
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
582
+ }
583
+ })(TaAskUtil || (TaAskUtil = {}));
584
+ // ../ta-protocol/esm/common/ta-protocol.js
585
+ var TaServer = Symbol("TaServer");
586
+ var TaClient = Symbol("TaClient");
587
+ var TaErrorUtil;
588
+ (function(TaErrorUtil2) {
589
+ function code(error) {
590
+ var _a;
591
+ var _b;
592
+ const failure = error;
593
+ const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
594
+ return typeof code2 === "string" ? code2 : undefined;
595
+ }
596
+ TaErrorUtil2.code = code;
597
+ })(TaErrorUtil || (TaErrorUtil = {}));
598
+ var TaSlashCommandUtil;
599
+ (function(TaSlashCommandUtil2) {
600
+ function description(command, language) {
601
+ var _a, _b;
602
+ const { descriptions } = command;
603
+ return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
604
+ }
605
+ TaSlashCommandUtil2.description = description;
606
+ })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
607
+ var TaMessageContext;
608
+ (function(TaMessageContext2) {
609
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
610
+ function wrap(context, message2) {
611
+ return `<context>
612
+ ${context}
613
+ </context>
614
+ ${message2}`;
615
+ }
616
+ TaMessageContext2.wrap = wrap;
617
+ function strip(message2) {
618
+ return message2.replace(BLOCK, "");
619
+ }
620
+ TaMessageContext2.strip = strip;
621
+ function read(message2) {
622
+ var _a;
623
+ const block = (_a = BLOCK.exec(message2)) === null || _a === undefined ? undefined : _a[0];
624
+ return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
625
+ }
626
+ TaMessageContext2.read = read;
627
+ })(TaMessageContext || (TaMessageContext = {}));
628
+ var TaMessageSource;
629
+ (function(TaMessageSource2) {
630
+ TaMessageSource2.DOUBLE = "ta:double";
631
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
632
+ function mark(message2, from, detail) {
633
+ if (/^[/!]/.test(message2) || of(message2)) {
634
+ return message2;
635
+ }
636
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
637
+ const context = TaMessageContext.read(message2);
638
+ return TaMessageContext.wrap(context === undefined ? line : `${context}
639
+ ${line}`, TaMessageContext.strip(message2));
640
+ }
641
+ TaMessageSource2.mark = mark;
642
+ function of(message2) {
643
+ const context = TaMessageContext.read(message2);
644
+ const match = context === undefined ? null : LINE.exec(context);
645
+ return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
646
+ }
647
+ TaMessageSource2.of = of;
648
+ })(TaMessageSource || (TaMessageSource = {}));
649
+ var TaImageNote;
650
+ (function(TaImageNote2) {
651
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
652
+ function strip(text) {
653
+ const lines = text.split(`
654
+ `);
655
+ const kept = lines.filter((line) => !NOTE.test(line.trim()));
656
+ if (kept.length === lines.length) {
657
+ return text;
658
+ }
659
+ return kept.join(`
660
+ `).replace(/\n+$/, "").replace(/^\n+/, "");
661
+ }
662
+ TaImageNote2.strip = strip;
663
+ })(TaImageNote || (TaImageNote = {}));
664
+ var TaImageSize;
665
+ (function(TaImageSize2) {
666
+ const JPEG_BYTES = 256 * 1024;
667
+ function of(base64) {
668
+ var _a, _b, _c;
669
+ let bytes;
670
+ try {
671
+ const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
672
+ bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
673
+ } catch (_d) {
674
+ return;
675
+ }
676
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
677
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
678
+ }
679
+ TaImageSize2.of = of;
680
+ function u16be(bytes, at) {
681
+ return bytes[at] << 8 | bytes[at + 1];
682
+ }
683
+ function u16le(bytes, at) {
684
+ return bytes[at] | bytes[at + 1] << 8;
685
+ }
686
+ function u24le(bytes, at) {
687
+ return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
688
+ }
689
+ function u32be(bytes, at) {
690
+ return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
691
+ }
692
+ function text(bytes, at, length) {
693
+ return String.fromCharCode(...bytes.subarray(at, at + length));
694
+ }
695
+ function png(bytes) {
696
+ return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
697
+ }
698
+ function gif(bytes) {
699
+ return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
700
+ }
701
+ function webp(bytes) {
702
+ if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
703
+ return;
704
+ }
705
+ switch (text(bytes, 12, 4)) {
706
+ case "VP8 ":
707
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
708
+ case "VP8L": {
709
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
710
+ return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
711
+ }
712
+ case "VP8X":
713
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
714
+ default:
715
+ return;
716
+ }
717
+ }
718
+ function jpeg(bytes) {
719
+ if (bytes[0] !== 255 || bytes[1] !== 216) {
720
+ return;
721
+ }
722
+ let at = 2;
723
+ while (at + 9 < bytes.length) {
724
+ if (bytes[at] !== 255) {
725
+ return;
726
+ }
727
+ const marker = bytes[at + 1];
728
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
729
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
730
+ }
731
+ at += 2 + u16be(bytes, at + 2);
732
+ }
733
+ return;
734
+ }
735
+ })(TaImageSize || (TaImageSize = {}));
736
+ var TaAgentSummary;
737
+ (function(TaAgentSummary2) {
738
+ const START = /^\s*<conversation_history_summary>/;
739
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
740
+ function read(text) {
741
+ if (!START.test(text)) {
742
+ return;
743
+ }
744
+ return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
745
+ }
746
+ TaAgentSummary2.read = read;
747
+ function strip(text) {
748
+ return text.replace(BLOCK, "");
749
+ }
750
+ TaAgentSummary2.strip = strip;
751
+ })(TaAgentSummary || (TaAgentSummary = {}));
752
+ var TaSkillUse;
753
+ (function(TaSkillUse2) {
754
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
755
+ function parse(message2) {
756
+ var _a;
757
+ const match = BLOCK.exec(message2);
758
+ if (!match) {
759
+ return;
760
+ }
761
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
762
+ }
763
+ TaSkillUse2.parse = parse;
764
+ function command(use) {
765
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
766
+ }
767
+ TaSkillUse2.command = command;
768
+ })(TaSkillUse || (TaSkillUse = {}));
769
+ // ../ta-protocol/esm/common/team-protocol.js
770
+ var TA_UNDECLARED = "extensions.install";
771
+ var TaPermissionUtil;
772
+ (function(TaPermissionUtil2) {
773
+ function read(pi2) {
774
+ const given = pi2 === null || pi2 === undefined ? undefined : pi2.permissions;
775
+ const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
776
+ const host2 = map(given === null || given === undefined ? undefined : given.host);
777
+ const tools = map(given === null || given === undefined ? undefined : given.tools);
778
+ return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
779
+ }
780
+ TaPermissionUtil2.read = read;
781
+ function host(manifest, method, kind) {
782
+ var _a, _b, _c, _d;
783
+ const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
784
+ const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
785
+ return (_d = (_c = (_b = kind ? own(`${method}:${kind}`) : undefined) !== null && _b !== undefined ? _b : own(method)) !== null && _c !== undefined ? _c : own("*")) !== null && _d !== undefined ? _d : TA_UNDECLARED;
786
+ }
787
+ TaPermissionUtil2.host = host;
788
+ })(TaPermissionUtil || (TaPermissionUtil = {}));
789
+ var action = (id, en2, zh2, more = {}) => ({
790
+ id,
791
+ area: id.split(".")[0],
792
+ title: { en: en2, "zh-CN": zh2 },
793
+ ...more
794
+ });
795
+ var TA_ACTIONS = [
796
+ action("chat.view", "See conversations", "查看对话"),
797
+ action("chat.send", "Send in conversations", "在对话里发消息"),
798
+ action("chat.create", "Start conversations", "新建对话"),
799
+ action("chat.stop", "Stop a reply", "停止回复"),
800
+ action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话"),
801
+ action("chat.share", "Share by a link", "生成分享链接"),
802
+ action("agent.view", "See agents", "查看智能体"),
803
+ action("agent.use", "Talk with agents", "和智能体对话"),
804
+ action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体"),
805
+ action("channel.view", "See channels", "查看频道"),
806
+ action("channel.post", "Post in channels", "在频道里发言"),
807
+ action("channel.manage", "Create and change channels", "新建、管理频道"),
808
+ action("task.view", "See tasks", "查看任务"),
809
+ action("task.create", "Hand out tasks", "派任务"),
810
+ action("task.manage", "Take over and stop tasks", "接管、停止任务"),
811
+ action("files.read", "Read files", "读文件", { scoped: true }),
812
+ action("files.write", "Change files", "改文件", { scoped: true }),
813
+ action("commands.run", "Let Ta run commands", "让 Ta 运行命令", { scoped: true, risky: true }),
814
+ action("commands.terminal", "Open terminals", "打开终端", { scoped: true, risky: true }),
815
+ action("hosts.use", "Use remote hosts", "使用远程主机", { risky: true }),
816
+ action("models.use", "Use the models", "使用模型"),
817
+ action("models.manage", "Sign in to models", "登录和更换模型账号"),
818
+ action("cron.view", "See scheduled tasks", "查看定时任务"),
819
+ action("cron.manage", "Change scheduled tasks", "管理定时任务"),
820
+ action("extensions.use", "Use extensions", "使用扩展"),
821
+ action("extensions.install", "Install and turn off extensions", "安装、停用扩展"),
822
+ action("settings.view", "See settings", "查看设置"),
823
+ action("settings.manage", "Change settings", "修改设置"),
824
+ action("members.view", "See members", "查看成员"),
825
+ action("members.invite", "Invite people", "邀请别人"),
826
+ action("members.approve", "Answer requests", "处理申请"),
827
+ action("members.roles", "Change roles and members", "管理角色和成员"),
828
+ action("audit.view", "See the record", "查看记录")
829
+ ];
830
+ var TaActionUtil;
831
+ (function(TaActionUtil2) {
832
+ const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
833
+ function info(id) {
834
+ return byId.get(id);
835
+ }
836
+ TaActionUtil2.info = info;
837
+ function title(id, language) {
838
+ const found = byId.get(id);
839
+ return found ? language.startsWith("zh") ? found.title["zh-CN"] : found.title.en : id;
840
+ }
841
+ TaActionUtil2.title = title;
842
+ function inside(dir, path) {
843
+ const base = dir.replace(/\/+$/, "");
844
+ return path === base || path.startsWith(`${base}/`) || base === "";
845
+ }
846
+ TaActionUtil2.inside = inside;
847
+ })(TaActionUtil || (TaActionUtil = {}));
848
+ // ../ta-protocol/esm/common/workspace-protocol.js
849
+ var TaWorkspaceServer = Symbol("TaWorkspaceServer");
850
+ var TaTerminalServer = Symbol("TaTerminalServer");
851
+ var TaExcludedFiles;
852
+ (function(TaExcludedFiles2) {
853
+ TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
854
+ function has(name) {
855
+ return TaExcludedFiles2.NAMES.includes(name);
856
+ }
857
+ TaExcludedFiles2.has = has;
858
+ function filter(entries) {
859
+ return entries.filter((entry) => !has(entry.name));
860
+ }
861
+ TaExcludedFiles2.filter = filter;
862
+ })(TaExcludedFiles || (TaExcludedFiles = {}));
863
+ var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
864
+ // web-src/moments-protocol.ts
865
+ var NAME = "@celljs/ta-moments";
866
+ var VIEW = `${NAME}/moments`;
867
+ var DRAFT_TYPE = "ta-moments-draft";
868
+ var DRAFT_TOOL = "draft_moment";
869
+ var Keys;
870
+ ((Keys) => {
871
+ Keys.DECIDED = "decided";
872
+ Keys.SHARES = "shares";
873
+ Keys.REV = "rev";
874
+ Keys.SEEN = "seen";
875
+ Keys.PICKED = "picked";
876
+ Keys.TOLD = "told";
877
+ Keys.OUTBOX = "outbox";
878
+ Keys.HEARD = "heard";
879
+ Keys.SESSIONS = "sessions";
880
+ Keys.PALS = "pals";
881
+ })(Keys ||= {});
882
+ var StateKeys;
883
+ ((StateKeys) => {
884
+ StateKeys.POST = "post:";
885
+ StateKeys.IMG = "img:";
886
+ StateKeys.LIKE = "like:";
887
+ StateKeys.TOOK = "took:";
888
+ })(StateKeys ||= {});
889
+ var Limits;
890
+ ((Limits) => {
891
+ Limits.TEXT = 1000;
892
+ Limits.TITLE = 80;
893
+ Limits.IMAGES = 3;
894
+ Limits.IMAGE_CHARS = 240 * 1024;
895
+ Limits.THUMB_CHARS = 3000;
896
+ Limits.PART_CHARS = 48 * 1024;
897
+ Limits.POSTS = 40;
898
+ Limits.DRAFT_IMAGE_BYTES = 12 * 1024 * 1024;
899
+ Limits.CACHE_BYTES = 200 * 1024 * 1024;
900
+ Limits.ASK_AGAIN_MS = 60000;
901
+ Limits.DAYS = [3, 30, 180, 0];
902
+ Limits.DEFAULT_DAYS = 30;
903
+ Limits.TALK_TEXT = 300;
904
+ Limits.ANSWER_TEXT = 800;
905
+ Limits.TALK = 60;
906
+ Limits.TALK_PAGE_BYTES = 32 * 1024;
907
+ Limits.ASKS_A_DAY = 20;
908
+ Limits.OUTBOX = 50;
909
+ Limits.NOTES = 4000;
910
+ })(Limits ||= {});
911
+
912
+ // web-src/image-util.ts
913
+ var THUMB_SIDE = 24;
914
+ var SIDES = [1440, 1200, 1024, 860, 720, 600];
915
+ var QUALITIES = [0.82, 0.72, 0.62];
916
+ var ImageUtil;
917
+ ((ImageUtil) => {
918
+ async function blobOf(source) {
919
+ return typeof source === "string" ? (await fetch(source)).blob() : source;
920
+ }
921
+ ImageUtil.blobOf = blobOf;
922
+ async function compress(source) {
923
+ const bitmap = await createImageBitmap(await blobOf(source));
924
+ try {
925
+ for (const side of SIDES) {
926
+ const scale = Math.min(1, side / Math.max(bitmap.width, bitmap.height));
927
+ const w = Math.max(1, Math.round(bitmap.width * scale));
928
+ const h = Math.max(1, Math.round(bitmap.height * scale));
929
+ const canvas = document.createElement("canvas");
930
+ canvas.width = w;
931
+ canvas.height = h;
932
+ const context = canvas.getContext("2d");
933
+ if (!context) {
934
+ throw new Error("No canvas to draw on.");
935
+ }
936
+ context.fillStyle = "#fff";
937
+ context.fillRect(0, 0, w, h);
938
+ context.drawImage(bitmap, 0, 0, w, h);
939
+ for (const quality of QUALITIES) {
940
+ const data = canvas.toDataURL("image/jpeg", quality);
941
+ if (data.length <= Limits.IMAGE_CHARS) {
942
+ return { data, thumb: thumbOf(bitmap), w, h };
943
+ }
944
+ }
945
+ }
946
+ throw new Error("The picture is too large.");
947
+ } finally {
948
+ bitmap.close();
949
+ }
950
+ }
951
+ ImageUtil.compress = compress;
952
+ function thumbOf(bitmap) {
953
+ const scale = THUMB_SIDE / Math.max(bitmap.width, bitmap.height);
954
+ const canvas = document.createElement("canvas");
955
+ canvas.width = Math.max(1, Math.round(bitmap.width * scale));
956
+ canvas.height = Math.max(1, Math.round(bitmap.height * scale));
957
+ const context = canvas.getContext("2d");
958
+ if (!context) {
959
+ return "";
960
+ }
961
+ context.fillStyle = "#fff";
962
+ context.fillRect(0, 0, canvas.width, canvas.height);
963
+ context.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
964
+ const thumb = canvas.toDataURL("image/jpeg", 0.5);
965
+ return thumb.length <= Limits.THUMB_CHARS ? thumb : "";
966
+ }
967
+ function single(w, h, max) {
968
+ const ratio = Math.min(Math.max(h / w, 0.5), 2);
969
+ return ratio >= 1 ? { width: Math.round(max / ratio), height: max } : { width: max, height: Math.round(max * ratio) };
970
+ }
971
+ ImageUtil.single = single;
972
+ })(ImageUtil ||= {});
973
+
974
+ // web-src/editor.tsx
975
+ var KEEP = { 3: "keep3", 30: "keep30", 180: "keep180", 0: "keep0" };
976
+ function useOwnPackages(enabled) {
977
+ const [packages, setPackages] = React.useState([]);
978
+ React.useEffect(() => {
979
+ let live = true;
980
+ if (enabled) {
981
+ pi.packages.listPackages().then((all) => live && setPackages(all.filter((info) => info.origin !== "builtin" && info.origin !== "temporary"))).catch(() => {
982
+ return;
983
+ });
984
+ }
985
+ return () => {
986
+ live = false;
987
+ };
988
+ }, [enabled]);
989
+ return packages;
990
+ }
991
+ function titleOf(info) {
992
+ const title = info.title;
993
+ if (typeof title === "string") {
994
+ return title;
995
+ }
996
+ return title && (title[pi.ui.language] ?? title[pi.ui.language.split("-")[0]] ?? title.en) || info.name;
997
+ }
998
+ function PostEditor({ text: first, images, attach: firstAttach, pickPackage, onPost, onCancel, cancelLabel, autoFocus }) {
999
+ const [text, setText] = React.useState(first);
1000
+ const [pictures, setPictures] = React.useState([]);
1001
+ const [adding, setAdding] = React.useState(0);
1002
+ const [attach, setAttach] = React.useState(firstAttach);
1003
+ const [days, setDays] = React.useState(Limits.DEFAULT_DAYS);
1004
+ const [ask, setAsk] = React.useState(true);
1005
+ const [busy, run] = useBusy();
1006
+ const input = React.useRef(null);
1007
+ const area = React.useRef(null);
1008
+ const packages = useOwnPackages(!!pickPackage || firstAttach?.kind === "package");
1009
+ const add = React.useCallback(async (sources) => {
1010
+ setAdding((count) => count + sources.length);
1011
+ for (const source of sources) {
1012
+ try {
1013
+ const picture = await ImageUtil.compress(source);
1014
+ setPictures((list) => list.length < Limits.IMAGES ? [...list, picture] : list);
1015
+ } catch (error) {
1016
+ failed(error);
1017
+ } finally {
1018
+ setAdding((count) => count - 1);
1019
+ }
1020
+ }
1021
+ }, []);
1022
+ React.useEffect(() => {
1023
+ images?.then((list) => add(list.slice(0, Limits.IMAGES)));
1024
+ }, [images, add]);
1025
+ React.useEffect(() => {
1026
+ if (autoFocus) {
1027
+ area.current?.focus();
1028
+ }
1029
+ }, [autoFocus]);
1030
+ React.useLayoutEffect(() => {
1031
+ const box = area.current;
1032
+ if (box) {
1033
+ box.style.height = "auto";
1034
+ box.style.height = `${Math.min(box.scrollHeight, 260)}px`;
1035
+ }
1036
+ }, [text]);
1037
+ const Plus = icon("ImagePlus", "Plus");
1038
+ const X = icon("X");
1039
+ const Package = icon("PackageOpen");
1040
+ const Link = icon("Link");
1041
+ const named = attach?.kind === "package" ? packages.find((info) => info.name === attach.name) : undefined;
1042
+ const attachTitle = attach?.kind === "package" ? named ? titleOf(named) : attach.name : attach?.kind === "link" ? attach.title || attach.link : "";
1043
+ const empty = !text.trim() && !pictures.length && !attach;
1044
+ const post = () => void run(async () => {
1045
+ try {
1046
+ await onPost({ text: text.trim(), images: pictures, ...attach ? { attach } : {}, days, ask });
1047
+ } catch (error) {
1048
+ failed(error);
1049
+ }
1050
+ });
1051
+ return /* @__PURE__ */ React.createElement("div", {
1052
+ className: "tmo-editor"
1053
+ }, /* @__PURE__ */ React.createElement("textarea", {
1054
+ ref: area,
1055
+ className: "tmo-editor-text",
1056
+ value: text,
1057
+ maxLength: Limits.TEXT,
1058
+ placeholder: t("placeholder"),
1059
+ rows: 3,
1060
+ onChange: (event) => setText(event.target.value)
1061
+ }), /* @__PURE__ */ React.createElement("div", {
1062
+ className: "tmo-editor-images"
1063
+ }, pictures.map((picture, index) => /* @__PURE__ */ React.createElement("div", {
1064
+ key: picture.data.slice(-24) + index,
1065
+ className: "tmo-thumb"
1066
+ }, /* @__PURE__ */ React.createElement("img", {
1067
+ src: picture.data,
1068
+ alt: ""
1069
+ }), /* @__PURE__ */ React.createElement("button", {
1070
+ type: "button",
1071
+ className: "tmo-thumb-x",
1072
+ "aria-label": t("removeImage"),
1073
+ onClick: () => setPictures((list) => list.filter((_, at) => at !== index))
1074
+ }, X && /* @__PURE__ */ React.createElement(X, {
1075
+ size: 12
1076
+ })))), Array.from({ length: adding }, (_, index) => /* @__PURE__ */ React.createElement("div", {
1077
+ key: `adding-${index}`,
1078
+ className: "tmo-thumb tmo-thumb-busy"
1079
+ }, /* @__PURE__ */ React.createElement("span", {
1080
+ className: "ta-spinner"
1081
+ }))), pictures.length + adding < Limits.IMAGES && /* @__PURE__ */ React.createElement("button", {
1082
+ type: "button",
1083
+ className: "tmo-thumb tmo-thumb-add",
1084
+ "aria-label": t("addImage"),
1085
+ onClick: () => input.current?.click()
1086
+ }, Plus && /* @__PURE__ */ React.createElement(Plus, {
1087
+ size: 20
1088
+ })), /* @__PURE__ */ React.createElement("input", {
1089
+ ref: input,
1090
+ type: "file",
1091
+ accept: "image/*",
1092
+ multiple: true,
1093
+ hidden: true,
1094
+ onChange: (event) => {
1095
+ add([...event.target.files ?? []].slice(0, Limits.IMAGES - pictures.length));
1096
+ event.target.value = "";
1097
+ }
1098
+ })), pickPackage && !(attach?.kind === "link") ? /* @__PURE__ */ React.createElement("label", {
1099
+ className: "tmo-editor-row"
1100
+ }, /* @__PURE__ */ React.createElement("span", {
1101
+ className: "tmo-editor-label"
1102
+ }, t("attach")), /* @__PURE__ */ React.createElement("select", {
1103
+ className: "tmo-select",
1104
+ value: attach?.kind === "package" ? attach.name : "",
1105
+ onChange: (event) => setAttach(event.target.value ? { kind: "package", name: event.target.value } : undefined)
1106
+ }, /* @__PURE__ */ React.createElement("option", {
1107
+ value: ""
1108
+ }, t("attachNone")), packages.map((info) => /* @__PURE__ */ React.createElement("option", {
1109
+ key: info.id,
1110
+ value: info.name
1111
+ }, titleOf(info))))) : attach && /* @__PURE__ */ React.createElement("div", {
1112
+ className: "tmo-chip"
1113
+ }, attach.kind === "package" ? Package && /* @__PURE__ */ React.createElement(Package, {
1114
+ size: 14
1115
+ }) : Link && /* @__PURE__ */ React.createElement(Link, {
1116
+ size: 14
1117
+ }), /* @__PURE__ */ React.createElement("span", {
1118
+ className: "tmo-chip-text"
1119
+ }, attachTitle), /* @__PURE__ */ React.createElement("button", {
1120
+ type: "button",
1121
+ className: "tmo-chip-x",
1122
+ "aria-label": t("cancel"),
1123
+ onClick: () => setAttach(undefined)
1124
+ }, X && /* @__PURE__ */ React.createElement(X, {
1125
+ size: 12
1126
+ }))), /* @__PURE__ */ React.createElement("div", {
1127
+ className: "tmo-editor-row"
1128
+ }, /* @__PURE__ */ React.createElement("span", {
1129
+ className: "tmo-editor-label"
1130
+ }, t("keep")), /* @__PURE__ */ React.createElement("div", {
1131
+ className: "tmo-segments"
1132
+ }, Limits.DAYS.map((value) => /* @__PURE__ */ React.createElement("button", {
1133
+ key: value,
1134
+ type: "button",
1135
+ "aria-pressed": days === value,
1136
+ className: `tmo-segment${days === value ? " tmo-on" : ""}`,
1137
+ onClick: () => setDays(value)
1138
+ }, t(KEEP[value]))))), /* @__PURE__ */ React.createElement("label", {
1139
+ className: "tmo-editor-row tmo-editor-check"
1140
+ }, /* @__PURE__ */ React.createElement("input", {
1141
+ type: "checkbox",
1142
+ checked: ask,
1143
+ onChange: (event) => setAsk(event.target.checked)
1144
+ }), /* @__PURE__ */ React.createElement("span", null, t("allowAsk")), /* @__PURE__ */ React.createElement("span", {
1145
+ className: "tmo-quiet tmo-small"
1146
+ }, t("allowAskHint"))), /* @__PURE__ */ React.createElement("div", {
1147
+ className: "tmo-editor-actions"
1148
+ }, /* @__PURE__ */ React.createElement("button", {
1149
+ type: "button",
1150
+ className: "ta-button",
1151
+ disabled: busy,
1152
+ onClick: onCancel
1153
+ }, cancelLabel), /* @__PURE__ */ React.createElement("button", {
1154
+ type: "button",
1155
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
1156
+ disabled: busy || empty || adding > 0,
1157
+ onClick: post
1158
+ }, busy && /* @__PURE__ */ React.createElement("span", {
1159
+ className: "ta-spinner ta-busy-mark ta-on-brand"
1160
+ }), /* @__PURE__ */ React.createElement("span", null, busy ? t("publishing") : t("publish")))));
1161
+ }
1162
+
1163
+ // web-src/store.ts
1164
+ class MomentsStore {
1165
+ state;
1166
+ error;
1167
+ seen = 0;
1168
+ focus;
1169
+ listeners = new Set;
1170
+ pictures = new Map;
1171
+ loading;
1172
+ again = false;
1173
+ stop;
1174
+ start() {
1175
+ this.stop = pi.storage.onChange((keys) => {
1176
+ if (keys.includes(Keys.REV)) {
1177
+ this.load();
1178
+ }
1179
+ if (keys.includes(Keys.SEEN)) {
1180
+ this.readSeen();
1181
+ }
1182
+ });
1183
+ this.readSeen();
1184
+ this.load();
1185
+ return () => this.stop?.();
1186
+ }
1187
+ subscribe = (listener) => {
1188
+ this.listeners.add(listener);
1189
+ return () => this.listeners.delete(listener);
1190
+ };
1191
+ get = () => this.state;
1192
+ load() {
1193
+ if (this.loading) {
1194
+ this.again = true;
1195
+ return this.loading;
1196
+ }
1197
+ this.loading = (async () => {
1198
+ do {
1199
+ this.again = false;
1200
+ try {
1201
+ this.state = await pi.callHost("state");
1202
+ this.error = undefined;
1203
+ } catch (error) {
1204
+ this.error = error;
1205
+ }
1206
+ this.emit();
1207
+ } while (this.again);
1208
+ })().finally(() => {
1209
+ this.loading = undefined;
1210
+ });
1211
+ return this.loading;
1212
+ }
1213
+ images(room, post) {
1214
+ const key = `${room}:${post}`;
1215
+ let found = this.pictures.get(key);
1216
+ if (!found) {
1217
+ found = pi.callHost("images", room, post).catch(() => []);
1218
+ this.pictures.set(key, found);
1219
+ found.then((list) => list.length && list.every(Boolean) ? undefined : this.pictures.delete(key));
1220
+ }
1221
+ return found;
1222
+ }
1223
+ show(room, post) {
1224
+ this.focus = `${room}:${post}`;
1225
+ this.emit();
1226
+ }
1227
+ async markSeen() {
1228
+ const latest = Math.max(0, ...(this.state?.posts ?? []).filter((post) => !post.mine).map((post) => post.at));
1229
+ if (latest > this.seen) {
1230
+ this.seen = latest;
1231
+ this.emit();
1232
+ await pi.storage.set(Keys.SEEN, latest);
1233
+ }
1234
+ }
1235
+ async readSeen() {
1236
+ const seen = await pi.storage.get(Keys.SEEN).catch(() => 0);
1237
+ if (typeof seen === "number" && seen !== this.seen) {
1238
+ this.seen = seen;
1239
+ this.emit();
1240
+ }
1241
+ }
1242
+ emit() {
1243
+ for (const listener of this.listeners) {
1244
+ listener();
1245
+ }
1246
+ }
1247
+ }
1248
+ var store = new MomentsStore;
1249
+ function useMoments() {
1250
+ return React.useSyncExternalStore(store.subscribe, store.get);
1251
+ }
1252
+ function useSeen() {
1253
+ return React.useSyncExternalStore(store.subscribe, () => store.seen);
1254
+ }
1255
+
1256
+ // web-src/draft-card.tsx
1257
+ function decisions(value) {
1258
+ return value && typeof value === "object" ? value : {};
1259
+ }
1260
+ function useDecided(key) {
1261
+ const [decided, setDecided] = React.useState();
1262
+ React.useEffect(() => {
1263
+ let live = true;
1264
+ const read = () => void pi.storage.get(Keys.DECIDED).then((value) => live && setDecided(decisions(value)[key]), () => {
1265
+ return;
1266
+ });
1267
+ read();
1268
+ const stop = pi.storage.onChange((keys) => keys.includes(Keys.DECIDED) && read());
1269
+ return () => {
1270
+ live = false;
1271
+ stop();
1272
+ };
1273
+ }, [key]);
1274
+ return decided;
1275
+ }
1276
+ function DraftView({ draft }) {
1277
+ const decided = useDecided(draft.key);
1278
+ const [hidden, setHidden] = React.useState(false);
1279
+ const images = React.useMemo(() => Promise.all(Array.from({ length: draft.images }, (_, index) => pi.callHost("draftImage", draft.key, index))).then((list) => list.filter((item) => !!item)), [draft.key, draft.images]);
1280
+ const Aperture = icon("Aperture", "Sparkles");
1281
+ if (decided || hidden) {
1282
+ const posted = decided && "posted" in decided;
1283
+ return /* @__PURE__ */ React.createElement("div", {
1284
+ className: "tmo-draft tmo-draft-done"
1285
+ }, Aperture && /* @__PURE__ */ React.createElement(Aperture, {
1286
+ size: 14
1287
+ }), /* @__PURE__ */ React.createElement("span", {
1288
+ className: posted ? "tmo-good" : "tmo-quiet"
1289
+ }, posted ? t("draftPosted") : t("draftDeclined")), posted && /* @__PURE__ */ React.createElement("button", {
1290
+ type: "button",
1291
+ className: "tmo-link",
1292
+ onClick: () => void pi.ui.showView(VIEW)
1293
+ }, t("viewPost")));
1294
+ }
1295
+ return /* @__PURE__ */ React.createElement("div", {
1296
+ className: "tmo-draft"
1297
+ }, /* @__PURE__ */ React.createElement("div", {
1298
+ className: "tmo-draft-head"
1299
+ }, Aperture && /* @__PURE__ */ React.createElement(Aperture, {
1300
+ size: 14
1301
+ }), /* @__PURE__ */ React.createElement("span", null, t("draftHead")), /* @__PURE__ */ React.createElement("span", {
1302
+ className: "tmo-quiet tmo-small"
1303
+ }, t("draftHint"))), /* @__PURE__ */ React.createElement(PostEditor, {
1304
+ text: draft.text,
1305
+ images,
1306
+ attach: draft.attach,
1307
+ cancelLabel: t("notNow"),
1308
+ onCancel: () => {
1309
+ setHidden(true);
1310
+ pi.callHost("decline", draft.key).catch(() => {
1311
+ return;
1312
+ });
1313
+ },
1314
+ onPost: async (input) => {
1315
+ await pi.callHost("publish", { ...input, key: draft.key, ...draft.notes ? { notes: draft.notes } : {} });
1316
+ await store.load();
1317
+ }
1318
+ }));
1319
+ }
1320
+ function DraftMessage({ message: message2 }) {
1321
+ const draft = message2.details;
1322
+ if (!draft || typeof draft.key !== "string") {
1323
+ return null;
1324
+ }
1325
+ return /* @__PURE__ */ React.createElement(DraftView, {
1326
+ draft
1327
+ });
1328
+ }
1329
+
1330
+ // web-src/friends.tsx
1331
+ function show(component) {
1332
+ if (!pi.ui.custom) {
1333
+ pi.ui.notify(t("oldApp"), "warning");
1334
+ return;
1335
+ }
1336
+ pi.ui.custom(component);
1337
+ }
1338
+ function Face({ id, size = 40 }) {
1339
+ const Face2 = pi.ui.Face;
1340
+ return Face2 ? /* @__PURE__ */ React.createElement(Face2, {
1341
+ seed: id,
1342
+ size
1343
+ }) : /* @__PURE__ */ React.createElement("span", {
1344
+ className: "tmo-face",
1345
+ style: { width: size, height: size }
1346
+ });
1347
+ }
1348
+ var FRIENDS_VIEW = "@celljs/ta-rooms/friends";
1349
+ function openFriends() {
1350
+ pi.ui.showView(FRIENDS_VIEW).then((shown) => shown || pi.ui.notify(t("noFriendsPage"), "warning"));
1351
+ }
1352
+
1353
+ // web-src/page.tsx
1354
+ function ComposeDialog({ close }) {
1355
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
1356
+ title: t("post"),
1357
+ onClose: close
1358
+ }, /* @__PURE__ */ React.createElement(PostEditor, {
1359
+ text: "",
1360
+ pickPackage: true,
1361
+ autoFocus: true,
1362
+ cancelLabel: t("cancel"),
1363
+ onCancel: close,
1364
+ onPost: async (input) => {
1365
+ await pi.callHost("publish", input);
1366
+ close();
1367
+ await store.load();
1368
+ }
1369
+ }));
1370
+ }
1371
+ function MomentsHead() {
1372
+ const Post = icon("Aperture", "Plus");
1373
+ return /* @__PURE__ */ React.createElement("div", {
1374
+ className: "tmo-head"
1375
+ }, /* @__PURE__ */ React.createElement("span", {
1376
+ className: "tmo-head-title"
1377
+ }, t("title")), /* @__PURE__ */ React.createElement("div", {
1378
+ className: "tmo-head-end"
1379
+ }, /* @__PURE__ */ React.createElement("button", {
1380
+ type: "button",
1381
+ className: "tmo-icon-button",
1382
+ "aria-label": t("post"),
1383
+ title: t("post"),
1384
+ onClick: () => show(ComposeDialog)
1385
+ }, Post && /* @__PURE__ */ React.createElement(Post, {
1386
+ size: 18
1387
+ }))));
1388
+ }
1389
+ function viewer(images, first, name) {
1390
+ return function Viewer({ close }) {
1391
+ const [at, setAt] = React.useState(first);
1392
+ const Viewer2 = pi.ui.ImageViewer;
1393
+ return /* @__PURE__ */ React.createElement(pi.ui.FullScreen, {
1394
+ className: "tmo-viewer"
1395
+ }, /* @__PURE__ */ React.createElement(Viewer2, {
1396
+ src: images[at],
1397
+ alt: t("imageAlt", { name }),
1398
+ autoFocus: true,
1399
+ onBackground: close,
1400
+ ...at > 0 ? { onPrevious: () => setAt(at - 1) } : {},
1401
+ ...at < images.length - 1 ? { onNext: () => setAt(at + 1) } : {}
1402
+ }), /* @__PURE__ */ React.createElement("button", {
1403
+ type: "button",
1404
+ className: "tmo-viewer-x",
1405
+ "aria-label": t("cancel"),
1406
+ onClick: close
1407
+ }, (() => {
1408
+ const X = icon("X");
1409
+ return X && /* @__PURE__ */ React.createElement(X, {
1410
+ size: 20
1411
+ });
1412
+ })()));
1413
+ };
1414
+ }
1415
+ function Picture({ post, index, data, square }) {
1416
+ const thumb = post.images[index]?.thumb;
1417
+ if (data) {
1418
+ return /* @__PURE__ */ React.createElement("img", {
1419
+ src: data,
1420
+ alt: t("imageAlt", { name: post.author.name })
1421
+ });
1422
+ }
1423
+ return thumb ? /* @__PURE__ */ React.createElement("img", {
1424
+ className: "tmo-thumb-blur",
1425
+ src: thumb,
1426
+ alt: "",
1427
+ "data-square": square || undefined
1428
+ }) : /* @__PURE__ */ React.createElement("span", {
1429
+ className: "tmo-image-wait"
1430
+ });
1431
+ }
1432
+ function PostImages({ post }) {
1433
+ const [images, setImages] = React.useState();
1434
+ const state = useMoments();
1435
+ React.useEffect(() => {
1436
+ let live = true;
1437
+ if (state) {
1438
+ store.images(post.room, post.id).then((list) => live && setImages(list));
1439
+ }
1440
+ return () => {
1441
+ live = false;
1442
+ };
1443
+ }, [post.room, post.id, state]);
1444
+ if (!post.images.length) {
1445
+ return null;
1446
+ }
1447
+ const here = images?.filter(Boolean) ?? [];
1448
+ const open = (index) => images?.[index] && show(viewer(here, here.indexOf(images[index]), post.author.name));
1449
+ const waiting = !post.mine && !post.online && (!images || images.some((data) => !data));
1450
+ const note = waiting && /* @__PURE__ */ React.createElement("div", {
1451
+ className: "tmo-wait-note"
1452
+ }, t("waitPictures", { name: post.author.name }));
1453
+ if (post.images.length === 1) {
1454
+ const size = ImageUtil.single(post.images[0].w, post.images[0].h, 220);
1455
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
1456
+ className: "tmo-images"
1457
+ }, /* @__PURE__ */ React.createElement("button", {
1458
+ type: "button",
1459
+ className: "tmo-image",
1460
+ style: size,
1461
+ onClick: () => open(0)
1462
+ }, /* @__PURE__ */ React.createElement(Picture, {
1463
+ post,
1464
+ index: 0,
1465
+ data: images?.[0]
1466
+ }))), note);
1467
+ }
1468
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
1469
+ className: "tmo-images tmo-grid"
1470
+ }, post.images.map((_, index) => /* @__PURE__ */ React.createElement("button", {
1471
+ key: index,
1472
+ type: "button",
1473
+ className: "tmo-image tmo-square",
1474
+ onClick: () => open(index)
1475
+ }, /* @__PURE__ */ React.createElement(Picture, {
1476
+ post,
1477
+ index,
1478
+ data: images?.[index],
1479
+ square: true
1480
+ })))), note);
1481
+ }
1482
+ function AttachCard({ post, attach }) {
1483
+ const [busy, run] = useBusy();
1484
+ const offline = attach.kind === "package" && !attach.source && !post.online && !post.mine;
1485
+ const Kind = icon(attach.kind === "package" ? "PackageOpen" : "Link");
1486
+ const take = () => void run(async () => {
1487
+ try {
1488
+ if (attach.kind === "link") {
1489
+ await pi.callHost("took", post.room, post.id).catch(() => {
1490
+ return;
1491
+ });
1492
+ if (pi.openLink) {
1493
+ await pi.openLink(attach.link);
1494
+ } else {
1495
+ window.open(attach.link, "_blank", "noopener");
1496
+ }
1497
+ return;
1498
+ }
1499
+ const { sessionFile } = await pi.callHost("take", post.room, post.id);
1500
+ if (sessionFile) {
1501
+ await pi.openChat?.(sessionFile);
1502
+ }
1503
+ } catch (error) {
1504
+ failed(error);
1505
+ }
1506
+ });
1507
+ const label = attach.kind === "link" ? t("open") : post.tookByMe ? t("takeAgain") : t("take");
1508
+ return /* @__PURE__ */ React.createElement("div", {
1509
+ className: "tmo-attach"
1510
+ }, /* @__PURE__ */ React.createElement("span", {
1511
+ className: "tmo-attach-icon"
1512
+ }, Kind && /* @__PURE__ */ React.createElement(Kind, {
1513
+ size: 18
1514
+ })), /* @__PURE__ */ React.createElement("div", {
1515
+ className: "tmo-attach-text"
1516
+ }, /* @__PURE__ */ React.createElement("span", {
1517
+ className: "tmo-attach-title"
1518
+ }, attach.title), /* @__PURE__ */ React.createElement("span", {
1519
+ className: "tmo-attach-line"
1520
+ }, attach.kind === "package" ? offline ? t("takeOffline", { name: post.author.name }) : attach.summary || t("packageHint") : t("linkKind"))), !post.mine && /* @__PURE__ */ React.createElement("button", {
1521
+ type: "button",
1522
+ className: `ta-button${post.tookByMe || offline ? "" : " ta-primary"}${busy ? " ta-busy" : ""}`,
1523
+ disabled: busy || offline,
1524
+ onClick: take
1525
+ }, busy && /* @__PURE__ */ React.createElement("span", {
1526
+ className: `ta-spinner ta-busy-mark${post.tookByMe ? "" : " ta-on-brand"}`
1527
+ }), /* @__PURE__ */ React.createElement("span", null, label)));
1528
+ }
1529
+ function names(people, me) {
1530
+ const words = MomentsWords.of(pi.ui.language);
1531
+ return people.map((person) => person.id === me ? words.me : person.name).join(/^zh/i.test(pi.ui.language) ? "、" : ", ");
1532
+ }
1533
+ function TalkLine({ post, entry, me, onReply }) {
1534
+ const own = entry.by.id === me && !entry.double;
1535
+ const answer = entry.double && post.mine;
1536
+ const who = entry.double ? t("theirTa", { name: post.mine ? names([post.author], me) : post.author.name }) : names([entry.by], me);
1537
+ const tap = async () => {
1538
+ if (own || answer) {
1539
+ const yes = await pi.ui.confirm(answer ? t("deleteAnswerTitle") : t("deleteTalkTitle"), answer ? t("deleteAnswerBody") : "", {
1540
+ confirmLabel: t("deleteTalk"),
1541
+ danger: true
1542
+ });
1543
+ if (yes) {
1544
+ await pi.callHost("unsay", post.room, post.id, entry.id).catch(failed);
1545
+ await store.load();
1546
+ }
1547
+ return;
1548
+ }
1549
+ onReply(entry.double ? post.author : entry.by);
1550
+ };
1551
+ const Spark = icon("Sparkles");
1552
+ return /* @__PURE__ */ React.createElement("button", {
1553
+ type: "button",
1554
+ className: `tmo-talk-line${entry.pending ? " tmo-pending" : ""}`,
1555
+ onClick: () => void tap()
1556
+ }, entry.double && Spark && /* @__PURE__ */ React.createElement("span", {
1557
+ className: "tmo-talk-spark"
1558
+ }, /* @__PURE__ */ React.createElement(Spark, {
1559
+ size: 11
1560
+ })), /* @__PURE__ */ React.createElement("b", null, who), entry.ask && /* @__PURE__ */ React.createElement("span", {
1561
+ className: "tmo-talk-word tmo-talk-word-end"
1562
+ }, t("askWord")), entry.to && !entry.ask && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
1563
+ className: "tmo-talk-word"
1564
+ }, entry.double ? t("answerWord") : t("replyWord")), /* @__PURE__ */ React.createElement("b", null, names([entry.to], me))), /* @__PURE__ */ React.createElement("span", {
1565
+ className: "tmo-talk-colon"
1566
+ }, /^zh/i.test(pi.ui.language) ? ":" : ": "), /* @__PURE__ */ React.createElement("span", {
1567
+ className: "tmo-talk-text"
1568
+ }, entry.text), entry.pending && /* @__PURE__ */ React.createElement("span", {
1569
+ className: "tmo-talk-wait"
1570
+ }, post.online ? t("sending") : t("pending", { name: post.author.name })));
1571
+ }
1572
+ function TalkBox({ post, writing, close }) {
1573
+ const Composer = pi.ui.Composer;
1574
+ const placeholder = writing.ask ? t("askPlaceholder", { name: post.author.name }) : writing.to ? t("replyPlaceholder", { name: writing.to.name }) : t("commentPlaceholder");
1575
+ return /* @__PURE__ */ React.createElement("div", {
1576
+ className: "tmo-talk-box"
1577
+ }, /* @__PURE__ */ React.createElement(Composer, {
1578
+ key: `${writing.ask ? "ask" : "say"}:${writing.to?.id ?? ""}`,
1579
+ placeholder,
1580
+ onSend: async (text) => {
1581
+ await pi.callHost("say", post.room, post.id, text, { ...writing.to ? { to: writing.to.id } : {}, ...writing.ask ? { ask: true } : {} });
1582
+ close();
1583
+ await store.load();
1584
+ }
1585
+ }), /* @__PURE__ */ React.createElement("button", {
1586
+ type: "button",
1587
+ className: "tmo-link tmo-talk-cancel",
1588
+ onClick: close
1589
+ }, t("cancel")));
1590
+ }
1591
+ function PostView({ post, me, now }) {
1592
+ const [writing, setWriting] = React.useState();
1593
+ const [liking, like] = useBusy();
1594
+ const [removing, remove] = useBusy();
1595
+ const Heart = icon("Heart");
1596
+ const Trash = icon("Trash2");
1597
+ const Took = icon("PackageOpen");
1598
+ const words = MomentsWords.of(pi.ui.language);
1599
+ const left = post.until !== undefined ? Math.ceil((post.until - now) / 86400000) : undefined;
1600
+ const Spark = icon("Sparkles");
1601
+ const Comment = icon("MessageCircle");
1602
+ return /* @__PURE__ */ React.createElement("article", {
1603
+ className: "tmo-post",
1604
+ "data-post": `${post.room}:${post.id}`
1605
+ }, /* @__PURE__ */ React.createElement(Face, {
1606
+ id: post.author.id,
1607
+ size: 42
1608
+ }), /* @__PURE__ */ React.createElement("div", {
1609
+ className: "tmo-post-body"
1610
+ }, /* @__PURE__ */ React.createElement("div", {
1611
+ className: "tmo-name"
1612
+ }, post.author.name), post.why && /* @__PURE__ */ React.createElement("div", {
1613
+ className: "tmo-why",
1614
+ title: t("whyHint")
1615
+ }, Spark && /* @__PURE__ */ React.createElement(Spark, {
1616
+ size: 13
1617
+ }), /* @__PURE__ */ React.createElement("span", null, post.why)), post.text && /* @__PURE__ */ React.createElement("div", {
1618
+ className: "tmo-text"
1619
+ }, post.text), /* @__PURE__ */ React.createElement(PostImages, {
1620
+ post
1621
+ }), post.attach && /* @__PURE__ */ React.createElement(AttachCard, {
1622
+ post,
1623
+ attach: post.attach
1624
+ }), /* @__PURE__ */ React.createElement("div", {
1625
+ className: "tmo-meta"
1626
+ }, /* @__PURE__ */ React.createElement("span", null, MomentsWords.ago(words, post.at, now, pi.ui.language)), post.mine && left !== undefined && /* @__PURE__ */ React.createElement("span", null, left <= 1 ? t("expiresSoon") : t("expires", { days: left })), post.mine && /* @__PURE__ */ React.createElement("button", {
1627
+ type: "button",
1628
+ className: "tmo-link",
1629
+ disabled: removing,
1630
+ onClick: () => void remove(async () => {
1631
+ if (await pi.ui.confirm(t("deleteTitle"), t("deleteBody"), { confirmLabel: t("deletePost"), danger: true })) {
1632
+ await pi.callHost("remove", post.id).catch(failed);
1633
+ await store.load();
1634
+ }
1635
+ })
1636
+ }, Trash && /* @__PURE__ */ React.createElement(Trash, {
1637
+ size: 13
1638
+ }), /* @__PURE__ */ React.createElement("span", null, t("deletePost"))), /* @__PURE__ */ React.createElement("span", {
1639
+ className: "tmo-grow"
1640
+ }), post.ask && /* @__PURE__ */ React.createElement("button", {
1641
+ type: "button",
1642
+ className: `tmo-ask${writing?.ask ? " tmo-on" : ""}`,
1643
+ title: t("askTaHint", { name: post.author.name }),
1644
+ onClick: () => setWriting(writing?.ask ? undefined : { ask: true })
1645
+ }, Spark && /* @__PURE__ */ React.createElement(Spark, {
1646
+ size: 13
1647
+ }), /* @__PURE__ */ React.createElement("span", null, t("askTa"))), /* @__PURE__ */ React.createElement("button", {
1648
+ type: "button",
1649
+ className: `tmo-like${writing && !writing.ask ? " tmo-on-talk" : ""}`,
1650
+ "aria-label": t("comment"),
1651
+ title: t("comment"),
1652
+ onClick: () => setWriting(writing && !writing.ask && !writing.to ? undefined : {})
1653
+ }, Comment && /* @__PURE__ */ React.createElement(Comment, {
1654
+ size: 16
1655
+ })), /* @__PURE__ */ React.createElement("button", {
1656
+ type: "button",
1657
+ className: `tmo-like${post.liked ? " tmo-on" : ""}`,
1658
+ "aria-pressed": post.liked,
1659
+ "aria-label": post.liked ? t("unlike") : t("like"),
1660
+ title: post.liked ? t("unlike") : t("like"),
1661
+ disabled: liking,
1662
+ onClick: () => void like(async () => {
1663
+ await pi.callHost("like", post.room, post.id, !post.liked).catch(failed);
1664
+ await store.load();
1665
+ })
1666
+ }, Heart && /* @__PURE__ */ React.createElement(Heart, {
1667
+ size: 16
1668
+ }))), (post.likes.length > 0 || post.took.length > 0 || post.talk.length > 0) && /* @__PURE__ */ React.createElement("div", {
1669
+ className: "tmo-marks"
1670
+ }, post.likes.length > 0 && /* @__PURE__ */ React.createElement("div", {
1671
+ className: "tmo-marks-line"
1672
+ }, Heart && /* @__PURE__ */ React.createElement(Heart, {
1673
+ size: 12
1674
+ }), /* @__PURE__ */ React.createElement("span", null, names(post.likes, me))), post.took.length > 0 && /* @__PURE__ */ React.createElement("div", {
1675
+ className: "tmo-marks-line"
1676
+ }, Took && /* @__PURE__ */ React.createElement(Took, {
1677
+ size: 12
1678
+ }), /* @__PURE__ */ React.createElement("span", null, t("tookBy", { names: names(post.took, me) }))), post.talk.length > 0 && /* @__PURE__ */ React.createElement("div", {
1679
+ className: `tmo-talk${post.likes.length || post.took.length ? " tmo-talk-split" : ""}`
1680
+ }, post.talk.map((entry) => /* @__PURE__ */ React.createElement(TalkLine, {
1681
+ key: entry.id,
1682
+ post,
1683
+ entry,
1684
+ me,
1685
+ onReply: (to) => setWriting({ to })
1686
+ })))), writing && /* @__PURE__ */ React.createElement(TalkBox, {
1687
+ post,
1688
+ writing,
1689
+ close: () => setWriting(undefined)
1690
+ })));
1691
+ }
1692
+ function FriendsRow() {
1693
+ const state = useMoments();
1694
+ const friends = state?.friends ?? [];
1695
+ const Chevron = icon("ChevronRight");
1696
+ const GroupFace = pi.ui.GroupFace;
1697
+ return /* @__PURE__ */ React.createElement("button", {
1698
+ type: "button",
1699
+ className: "tmo-friends-row",
1700
+ onClick: openFriends
1701
+ }, /* @__PURE__ */ React.createElement("span", {
1702
+ className: "tmo-friends-label"
1703
+ }, t("friends")), state?.asking ? /* @__PURE__ */ React.createElement("span", {
1704
+ className: "tmo-dot"
1705
+ }) : null, /* @__PURE__ */ React.createElement("span", {
1706
+ className: "tmo-grow"
1707
+ }), friends.length > 0 && GroupFace && /* @__PURE__ */ React.createElement(GroupFace, {
1708
+ members: friends.slice(0, 4).map((friend) => ({ seed: friend.id })),
1709
+ size: 24
1710
+ }), /* @__PURE__ */ React.createElement("span", {
1711
+ className: "tmo-quiet"
1712
+ }, friends.length ? t("friendsCount", { n: friends.length }) : t("friendsNone")), Chevron && /* @__PURE__ */ React.createElement("span", {
1713
+ className: "tmo-quiet tmo-chevron"
1714
+ }, /* @__PURE__ */ React.createElement(Chevron, {
1715
+ size: 16
1716
+ })));
1717
+ }
1718
+ function MomentsPage() {
1719
+ const state = useMoments();
1720
+ const now = Date.now();
1721
+ const shown = pi.ui.useView?.(VIEW)?.shown ?? true;
1722
+ React.useEffect(() => {
1723
+ store.load();
1724
+ }, []);
1725
+ React.useEffect(() => {
1726
+ if (state && shown) {
1727
+ store.markSeen();
1728
+ }
1729
+ }, [state, shown]);
1730
+ const focus = React.useSyncExternalStore(store.subscribe, () => store.focus);
1731
+ React.useEffect(() => {
1732
+ if (!state || !focus || !shown) {
1733
+ return;
1734
+ }
1735
+ const element = document.querySelector(`.tmo-post[data-post="${CSS.escape(focus)}"]`);
1736
+ store.focus = undefined;
1737
+ if (element) {
1738
+ element.scrollIntoView({ block: "center" });
1739
+ element.classList.add("tmo-focus");
1740
+ setTimeout(() => element.classList.remove("tmo-focus"), 1600);
1741
+ } else {
1742
+ pi.ui.notify(t("postGone"));
1743
+ }
1744
+ }, [state, focus, shown]);
1745
+ if (!pi.rooms) {
1746
+ return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1747
+ title: t("oldApp")
1748
+ });
1749
+ }
1750
+ if (!state) {
1751
+ return store.error ? /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1752
+ title: String(store.error),
1753
+ tone: "error"
1754
+ }) : /* @__PURE__ */ React.createElement(pi.ui.Skeleton, null);
1755
+ }
1756
+ const Add = icon("UserPlus");
1757
+ return /* @__PURE__ */ React.createElement("section", {
1758
+ className: "tmo-page",
1759
+ "aria-label": t("title")
1760
+ }, /* @__PURE__ */ React.createElement("div", {
1761
+ className: "tmo-feed"
1762
+ }, /* @__PURE__ */ React.createElement(FriendsRow, null), state.posts.length ? state.posts.map((post) => /* @__PURE__ */ React.createElement(PostView, {
1763
+ key: `${post.room}:${post.id}`,
1764
+ post,
1765
+ me: state.me.id,
1766
+ now
1767
+ })) : state.friends.length ? /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1768
+ title: t("noPosts"),
1769
+ hint: t("noPostsHint")
1770
+ }) : /* @__PURE__ */ React.createElement("div", {
1771
+ className: "tmo-empty"
1772
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1773
+ title: t("emptyTitle"),
1774
+ hint: t("emptyHint"),
1775
+ compact: true
1776
+ }), /* @__PURE__ */ React.createElement("button", {
1777
+ type: "button",
1778
+ className: "ta-button ta-primary",
1779
+ onClick: openFriends
1780
+ }, Add && /* @__PURE__ */ React.createElement(Add, {
1781
+ size: 14
1782
+ }), " ", t("addFriend")))));
1783
+ }
1784
+ function MomentsMark() {
1785
+ const state = useMoments();
1786
+ const seen = useSeen();
1787
+ const latest = state?.posts.find((post) => !post.mine);
1788
+ if (!latest || latest.at <= seen) {
1789
+ return null;
1790
+ }
1791
+ return /* @__PURE__ */ React.createElement("span", {
1792
+ className: "tmo-mark"
1793
+ }, /* @__PURE__ */ React.createElement(Face, {
1794
+ id: latest.author.id,
1795
+ size: 26
1796
+ }), /* @__PURE__ */ React.createElement("i", {
1797
+ className: "tmo-mark-dot"
1798
+ }));
1799
+ }
1800
+
1801
+ // web-src/style.ts
1802
+ var STYLE = `
1803
+ .tmo-quiet { color: var(--ta-muted); }
1804
+ .tmo-small { font-size: calc(12px * var(--ta-font-scale)); }
1805
+ .tmo-center { text-align: center; }
1806
+ .tmo-good { color: var(--ta-green); }
1807
+ .tmo-grow { flex: 1; }
1808
+ .tmo-link { display: inline-flex; align-items: center; gap: 3px; padding: 2px 4px; border: 0; border-radius: 6px; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
1809
+ .tmo-link:hover { background: var(--ta-hover); }
1810
+ .tmo-link:disabled { opacity: .5; cursor: default; }
1811
+ .tmo-icon-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ta-secondary); cursor: pointer; -webkit-tap-highlight-color: transparent; }
1812
+ .tmo-icon-button:hover { background: var(--ta-hover); color: var(--ta-text); }
1813
+ .tmo-face { display: inline-block; flex: none; border-radius: 50%; background: var(--ta-raised); }
1814
+ /* The head of the page */
1815
+ .tmo-head { position: relative; display: flex; align-items: center; justify-content: center; flex: 1; min-width: 0; height: 100%; padding: 0 84px; }
1816
+ .tmo-head-title { font-weight: 600; font-size: calc(14.5px * var(--ta-font-scale)); }
1817
+ .tmo-head-end { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: flex; gap: 2px; }
1818
+ /* The page: one column, as WeChat's Moments */
1819
+ .tmo-page { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overscroll-behavior: none; background: var(--ta-main); color: var(--ta-text); }
1820
+ .tmo-feed { display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; padding: 6px 14px calc(28px + env(safe-area-inset-bottom)); box-sizing: border-box; }
1821
+ .tmo-card { margin: 4px 0 8px; padding: 2px 8px; border-radius: 14px; background: var(--ta-raised); }
1822
+ .tmo-friends-row { display: flex; align-items: center; gap: 8px; min-height: 48px; margin: 2px 0 6px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--ta-raised); color: var(--ta-text); font: inherit; font-size: calc(14px * var(--ta-font-scale)); text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; }
1823
+ .tmo-friends-row:hover, .tmo-friends-row:active { background: var(--ta-hover); }
1824
+ .tmo-friends-label { font-weight: 500; }
1825
+ .tmo-friends-row .ta-face { --ta-face-ring: var(--ta-raised); }
1826
+ .tmo-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ta-yellow); }
1827
+ .tmo-empty { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 48px 0 24px; text-align: center; }
1828
+ /* A post: the face, then the name, words, pictures, what to take, when and the heart */
1829
+ .tmo-post { display: flex; gap: 12px; padding: 16px 2px 14px; border-bottom: 1px solid var(--ta-border-muted); }
1830
+ .tmo-post .ta-face { --ta-face-ring: var(--ta-main); }
1831
+ .tmo-post-body { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
1832
+ .tmo-name { font-weight: 600; color: var(--ta-link); font-size: calc(14.5px * var(--ta-font-scale)); line-height: 1.3; }
1833
+ .tmo-why { display: flex; align-items: flex-start; gap: 5px; align-self: flex-start; max-width: 100%; padding: 3px 8px; border-radius: 7px; background: color-mix(in srgb, var(--ta-yellow) 14%, transparent); color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.45; }
1834
+ .tmo-why svg { flex: none; position: relative; top: 2px; color: var(--ta-yellow); }
1835
+ .tmo-post.tmo-focus { animation: tmo-focus 1.6s ease-out; }
1836
+ @keyframes tmo-focus { from { background: var(--ta-hover); } to { background: transparent; } }
1837
+ .tmo-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; font-size: calc(14.5px * var(--ta-font-scale)); }
1838
+ .tmo-images { display: flex; }
1839
+ .tmo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; max-width: 300px; }
1840
+ .tmo-image { position: relative; display: block; padding: 0; border: 0; border-radius: 6px; overflow: hidden; background: var(--ta-raised); cursor: zoom-in; }
1841
+ .tmo-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
1842
+ .tmo-square { aspect-ratio: 1; width: 100%; }
1843
+ .tmo-image img.tmo-thumb-blur { filter: blur(10px) saturate(1.1); transform: scale(1.15); }
1844
+ .tmo-wait-note { margin-top: -2px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1845
+ .tmo-image-wait { display: block; width: 100%; height: 100%; min-height: 60px; background: var(--ta-hover); animation: tmo-wait 1.2s ease-in-out infinite alternate; }
1846
+ @keyframes tmo-wait { from { opacity: .45; } to { opacity: 1; } }
1847
+ .tmo-attach { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; border-radius: 10px; background: var(--ta-raised); }
1848
+ .tmo-attach-icon { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--ta-card); color: var(--ta-secondary); }
1849
+ .tmo-attach-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
1850
+ .tmo-attach-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1851
+ .tmo-attach-line { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
1852
+ .tmo-attach .ta-button { flex: none; }
1853
+ .tmo-meta { display: flex; align-items: center; gap: 10px; min-height: 28px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1854
+ .tmo-meta .tmo-link { color: var(--ta-muted); }
1855
+ .tmo-meta .tmo-link:hover { color: var(--ta-red); }
1856
+ .tmo-like { display: grid; place-items: center; width: 32px; height: 28px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ta-muted); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color 120ms, transform 120ms; }
1857
+ .tmo-like:hover { background: var(--ta-hover); color: var(--ta-text); }
1858
+ .tmo-like.tmo-on { color: var(--ta-red); }
1859
+ .tmo-like.tmo-on svg { fill: currentColor; }
1860
+ .tmo-chevron { display: inline-flex; }
1861
+ .tmo-like:active { transform: scale(.88); }
1862
+ .tmo-marks { display: flex; flex-direction: column; gap: 4px; padding: 7px 10px; border-radius: 8px; background: var(--ta-raised); font-size: calc(12.5px * var(--ta-font-scale)); color: var(--ta-link); }
1863
+ .tmo-marks-line { display: flex; align-items: baseline; gap: 6px; overflow-wrap: anywhere; }
1864
+ .tmo-marks-line svg { flex: none; position: relative; top: 1px; color: var(--ta-muted); }
1865
+ /* Words on a post, in the box of the likes */
1866
+ .tmo-talk { display: flex; flex-direction: column; gap: 1px; color: var(--ta-text); }
1867
+ .tmo-talk-split { margin-top: 3px; padding-top: 6px; border-top: 1px solid var(--ta-border-muted); }
1868
+ .tmo-talk-line { display: block; width: 100%; padding: 2px 3px; margin: 0 -3px; border: 0; border-radius: 5px; background: none; color: inherit; font: inherit; line-height: 1.55; text-align: left; overflow-wrap: anywhere; cursor: pointer; -webkit-tap-highlight-color: transparent; }
1869
+ .tmo-talk-line:hover, .tmo-talk-line:active { background: var(--ta-hover); }
1870
+ .tmo-talk-line b { font-weight: 500; color: var(--ta-link); }
1871
+ .tmo-talk-word { margin: 0 4px; color: var(--ta-muted); }
1872
+ .tmo-talk-word-end { margin-right: 0; }
1873
+ .tmo-talk-spark { position: relative; top: 1px; margin-right: 3px; color: var(--ta-yellow); }
1874
+ .tmo-talk-text { white-space: pre-wrap; }
1875
+ .tmo-talk-wait { margin-left: 6px; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); }
1876
+ .tmo-pending .tmo-talk-text { color: var(--ta-secondary); }
1877
+ .tmo-ask { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 9px; border: 0; border-radius: 8px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; -webkit-tap-highlight-color: transparent; }
1878
+ .tmo-ask svg { color: var(--ta-yellow); }
1879
+ .tmo-ask:hover, .tmo-ask.tmo-on { background: var(--ta-hover); color: var(--ta-text); }
1880
+ .tmo-like.tmo-on-talk { color: var(--ta-text); background: var(--ta-hover); }
1881
+ .tmo-talk-box { display: flex; flex-direction: column; gap: 2px; }
1882
+ .tmo-talk-cancel { align-self: flex-end; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1883
+ .tmo-editor-check { gap: 7px; cursor: pointer; font-size: calc(13px * var(--ta-font-scale)); }
1884
+ .tmo-editor-check input { margin: 0; accent-color: var(--ta-brand, var(--ta-link)); }
1885
+ /* A picture over the page */
1886
+ .tmo-viewer { background: rgba(0, 0, 0, .92); }
1887
+ .tmo-viewer-x { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .14); color: #fff; cursor: pointer; }
1888
+ /* Rows of friends and of those asking */
1889
+ .tmo-rows { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
1890
+ .tmo-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 4px; }
1891
+ .tmo-row .ta-face { --ta-face-ring: var(--ta-raised); }
1892
+ .tmo-row-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
1893
+ .tmo-row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1894
+ .tmo-row-line { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
1895
+ .tmo-row-end { display: flex; gap: 6px; flex: none; }
1896
+ .tmo-section { margin: 0 0 2px; font-size: calc(12px * var(--ta-font-scale)); font-weight: 500; color: var(--ta-muted); }
1897
+ .tmo-friends { display: flex; flex-direction: column; gap: 10px; min-width: min(380px, 80vw); }
1898
+ .tmo-friends .tmo-row .ta-face { --ta-face-ring: var(--ta-card); }
1899
+ .tmo-wide { justify-content: center; width: 100%; }
1900
+ /* The link that adds a friend */
1901
+ .tmo-invite { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: min(340px, 80vw); text-align: center; }
1902
+ .tmo-qr { display: grid; place-items: center; width: 200px; height: 200px; padding: 10px; border-radius: 14px; background: #fff; }
1903
+ .tmo-qr-busy { background: var(--ta-raised); }
1904
+ .tmo-invite-hint { margin: 0; max-width: 320px; line-height: 1.55; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); }
1905
+ .tmo-invite-actions { display: flex; gap: 8px; justify-content: center; }
1906
+ .tmo-add { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: min(320px, 80vw); padding-top: 4px; text-align: center; }
1907
+ .tmo-add .ta-face { --ta-face-ring: var(--ta-card); }
1908
+ .tmo-add-name { font-weight: 600; font-size: calc(16px * var(--ta-font-scale)); }
1909
+ .tmo-add-body { margin: 0 0 6px; max-width: 300px; color: var(--ta-secondary); line-height: 1.55; font-size: calc(13px * var(--ta-font-scale)); }
1910
+ /* Writing a post, in a dialog or in Ta's card */
1911
+ .tmo-editor { display: flex; flex-direction: column; gap: 10px; min-width: min(420px, 82vw); }
1912
+ .tmo-editor-text { width: 100%; min-height: 72px; box-sizing: border-box; padding: 9px 11px; border: 1px solid var(--ta-border-field); border-radius: 10px; background: var(--ta-main); color: var(--ta-text); font: inherit; font-size: calc(14px * var(--ta-font-scale)); line-height: 1.55; resize: none; }
1913
+ .tmo-editor-text:focus { outline: none; border-color: var(--ta-border-focus); }
1914
+ .tmo-editor-images { display: flex; flex-wrap: wrap; gap: 8px; }
1915
+ .tmo-thumb { position: relative; display: grid; place-items: center; width: 72px; height: 72px; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--ta-raised); color: var(--ta-muted); }
1916
+ .tmo-thumb img { width: 100%; height: 100%; object-fit: cover; }
1917
+ .tmo-thumb-add { border: 1px dashed var(--ta-border-field); background: none; cursor: pointer; }
1918
+ .tmo-thumb-add:hover { color: var(--ta-text); border-color: var(--ta-muted); }
1919
+ .tmo-thumb-x { position: absolute; top: 3px; right: 3px; display: grid; place-items: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; }
1920
+ .tmo-editor-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
1921
+ .tmo-editor-label { flex: none; min-width: 34px; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); }
1922
+ .tmo-select { flex: 1; min-width: 0; max-width: 320px; height: 32px; padding: 0 8px; 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)); }
1923
+ .tmo-segments { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border-radius: 9px; background: var(--ta-raised); }
1924
+ .tmo-segment { min-height: 28px; padding: 0 10px; border: 0; border-radius: 7px; background: none; color: var(--ta-secondary); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
1925
+ .tmo-segment.tmo-on { background: var(--ta-segment, var(--ta-card)); color: var(--ta-text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
1926
+ .tmo-chip { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; max-width: 100%; padding: 5px 6px 5px 10px; border-radius: 8px; background: var(--ta-raised); color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); }
1927
+ .tmo-chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-text); }
1928
+ .tmo-chip-x { display: grid; place-items: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--ta-muted); cursor: pointer; }
1929
+ .tmo-chip-x:hover { background: var(--ta-hover); color: var(--ta-text); }
1930
+ .tmo-editor-actions { display: flex; justify-content: flex-end; gap: 8px; }
1931
+ [data-touch] .tmo-editor-actions .ta-button, [data-touch] .tmo-attach .ta-button { min-height: 38px; }
1932
+ /* Ta's draft, in its conversation */
1933
+ .tmo-draft { display: flex; flex-direction: column; gap: 10px; margin: 4px 0; padding: 12px; max-width: 560px; border: 1px solid var(--ta-border-muted); border-radius: 12px; background: var(--ta-card); }
1934
+ .tmo-draft .tmo-editor { min-width: 0; }
1935
+ .tmo-draft-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 500; font-size: calc(13px * var(--ta-font-scale)); }
1936
+ .tmo-draft-head .tmo-small { font-weight: 400; }
1937
+ .tmo-draft-done { flex-direction: row; align-items: center; gap: 6px; padding: 8px 12px; font-size: calc(12.5px * var(--ta-font-scale)); }
1938
+ /* By Moments under Discover */
1939
+ .tmo-mark { position: relative; display: inline-flex; }
1940
+ .tmo-mark .ta-face { --ta-face-ring: var(--ta-list-cell, var(--ta-main)); }
1941
+ .tmo-mark-dot { position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--ta-yellow); box-shadow: 0 0 0 2px var(--ta-list-cell, var(--ta-main)); }
1942
+ @media (prefers-reduced-motion: reduce) { .tmo-image-wait { animation: none; } .tmo-like { transition: none; } }
1943
+ `;
1944
+ function injectStyle() {
1945
+ const element = document.createElement("style");
1946
+ element.dataset.taPackage = "ta-moments";
1947
+ element.textContent = STYLE;
1948
+ document.head.appendChild(element);
1949
+ return () => element.remove();
1950
+ }
1951
+
1952
+ // web-src/index.tsx
1953
+ function activate(pi2) {
1954
+ bind(pi2);
1955
+ const removeStyle = injectStyle();
1956
+ pi2.registerView("moments", {
1957
+ title: () => t("title"),
1958
+ icon: icon("Aperture", "Users"),
1959
+ render: MomentsPage,
1960
+ head: MomentsHead,
1961
+ mark: MomentsMark,
1962
+ discover: true,
1963
+ order: 80
1964
+ });
1965
+ pi2.registerMessageRenderer(DRAFT_TYPE, DraftMessage);
1966
+ pi2.registerOpener((link) => {
1967
+ const target = link.type === "url" ? MomentsBrief.parse(link.url) : undefined;
1968
+ if (!target) {
1969
+ return false;
1970
+ }
1971
+ store.show(target.room, target.post);
1972
+ store.load();
1973
+ pi2.ui.showView(VIEW);
1974
+ return true;
1975
+ }, { specific: true });
1976
+ pi2.registerToolRenderer?.((name, next) => name === DRAFT_TOOL ? { renderCall: (args) => ({ verb: t("toolDraft"), target: typeof args.text === "string" ? args.text.trim().slice(0, 40) : "" }) } : next());
1977
+ const stop = pi2.rooms ? store.start() : () => {
1978
+ return;
1979
+ };
1980
+ return () => {
1981
+ stop();
1982
+ removeStyle();
1983
+ };
1984
+ }
1985
+ export {
1986
+ activate as default
1987
+ };