@coda-console/friends 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/lib/avatar.mjs +86 -0
- package/lib/friends.mjs +13 -0
- package/lib/outbox.mjs +1 -12
- package/package.json +1 -1
- package/view/app.mjs +394 -124
- package/view/cropper.mjs +106 -0
- package/view/dom.mjs +22 -0
- package/view/style.css +192 -47
package/README.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
管理本机的 Accord 身份、个人名片与熟人好友通道(`coda/accord@1`)。
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
5
|
+
- **我的名片**:名片卡显示昵称、头像、主题色与本机公钥短码(点按复制),下方状态条给出已互认好友数(有待互认、冲突时提示)与身份、证书状态;多台机器提供这页时顶部可切换,连不上的机器置灰并注明原因。
|
|
6
|
+
- **编辑名片**:头像可选照片、几何纹(按公钥生成)、Emoji 或字标(昵称首字,写进 `emoji`)。照片从本机选图,在弹层里拖动、缩放裁成 512×512,优先编 WebP(不支持时用 JPEG),上传到 `coda-view://blob/content` 后把内容指针写进名片的 `avatar`;只改昵称、颜色不重新上传,换成非照片头像时写 `avatar: null` 清除。名片以公开的 `profile` / `self` 记录发布;本机绑定了代签证书、`profile` 被拒(`forbidden`)时改发可代签的社交名片 `friends/card` / `self`。
|
|
7
|
+
- **添加好友**:点名片上的「添加好友」,粘贴对方给的邀请(JSON、`coda-friend://` 链接或多行 `key=value`),接受后自动尝试互认。暂需由对方提供 friend 角色入网码。
|
|
8
|
+
- **好友列表**:实时跟随好友表变化,宽屏双列;显示好友的照片头像(读不出时退回 Emoji、几何纹或首字,点「刷新」重试)。点好友打开详情:完整公钥、节点名、本机备注、重新互认、二次确认后移除。
|
|
8
9
|
- **社交网关 `friends/social@1`**:业务无关,别的插件(在 `optionalUses` 里声明)经它读好友与好友分享的记录、向好友发布与撤回记录、发私信与动态、实时跟随私信与动态,不必各自处理没有身份、证书过期和重试。
|
|
9
10
|
|
|
10
11
|
## 社交网关
|
package/lib/avatar.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// 好友页头像与 Accord 状态的纯逻辑:头像地址、回退链、确定性几何纹、身份与好友统计。
|
|
2
|
+
// 页面(WKWebView)与 Node 单测都直接加载它,所以只用标准 JS 和 ./friends.mjs,不拼 HTML。
|
|
3
|
+
|
|
4
|
+
import { certStateOf, readContentPointer, shortAuthor } from './friends.mjs';
|
|
5
|
+
|
|
6
|
+
/** 头像图片的大小上限,与客户端和后端的 5 MiB 一致。 */
|
|
7
|
+
export const BLOB_MAX_BYTES = 5 * 1024 * 1024;
|
|
8
|
+
|
|
9
|
+
const CONTROL_CHARS = /[\p{Cc}\u2028\u2029]/gu;
|
|
10
|
+
const AUTHOR = /^ed25519:([0-9a-f]{64})$/;
|
|
11
|
+
const MAX_EMOJI = 8;
|
|
12
|
+
|
|
13
|
+
const clean = text => typeof text === 'string' ? text.replace(CONTROL_CHARS, '').trim() : '';
|
|
14
|
+
const machineQuery = machine => typeof machine === 'string' && machine.trim() ? `?coda-machine=${encodeURIComponent(machine.trim())}` : '';
|
|
15
|
+
|
|
16
|
+
/** 头像指针的读取地址:指针不合法(或为空)给 null;多机空间里带上 machine。 */
|
|
17
|
+
export function blobReadUrl(pointer, machine) {
|
|
18
|
+
const p = readContentPointer(pointer);
|
|
19
|
+
return p ? `coda-view://blob/${p.owner}/content/${p.sha256}${machineQuery(machine)}` : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 上传头像的地址;多机空间里带上 machine。 */
|
|
23
|
+
export const blobUploadUrl = machine => `coda-view://blob/content${machineQuery(machine)}`;
|
|
24
|
+
|
|
25
|
+
/** 一串字节的确定性混合(FNV-1a 作种,mulberry32 取数),给几何纹用。 */
|
|
26
|
+
function* stream(bytes) {
|
|
27
|
+
let seed = 0x811c9dc5;
|
|
28
|
+
for (const byte of bytes) seed = Math.imul(seed ^ byte, 0x01000193) >>> 0;
|
|
29
|
+
for (;;) {
|
|
30
|
+
seed = (seed + 0x6d2b79f5) >>> 0;
|
|
31
|
+
let t = seed;
|
|
32
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
33
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
34
|
+
yield (t ^ (t >>> 14)) >>> 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 5×5 水平轴对称的几何纹(`grid[r][c] === grid[r][4 - c]`):同一个 author 永远同一张,
|
|
40
|
+
* 不会全空也不会全满。合法的 `ed25519:<64 位十六进制>` 取公钥字节推导,其余非空串取其字符码兜底。
|
|
41
|
+
*/
|
|
42
|
+
export function identiconPattern(author) {
|
|
43
|
+
const text = String(author ?? '');
|
|
44
|
+
const hex = AUTHOR.exec(text)?.[1];
|
|
45
|
+
const bytes = hex ? Array.from({ length: 32 }, (_, i) => parseInt(hex.slice(i * 2, i * 2 + 2), 16)) : [...text].map(ch => ch.codePointAt(0));
|
|
46
|
+
for (const draw of stream(bytes)) {
|
|
47
|
+
const grid = Array.from({ length: 5 }, (_, r) => {
|
|
48
|
+
const half = [0, 1, 2].map(c => ((draw >>> (r * 3 + c)) & 1) === 1);
|
|
49
|
+
return [half[0], half[1], half[2], half[1], half[0]];
|
|
50
|
+
});
|
|
51
|
+
const active = grid.flat().filter(Boolean).length;
|
|
52
|
+
if (active >= 8 && active <= 18) return grid;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 昵称等文本的首字:清掉控制字符与首尾空白后取第一个 Unicode 字符,ASCII 字母转大写,空则给 fallback。 */
|
|
57
|
+
export function initialChar(text, fallback = '友') {
|
|
58
|
+
const first = [...clean(text)][0];
|
|
59
|
+
return first ? (/^[a-z]$/.test(first) ? first.toUpperCase() : first) : fallback;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 决定头像怎么展示,只返回纯数据:
|
|
64
|
+
* 有可读的图片指针且没失败 → photo;否则有 emoji(1–8 字)→ emoji;否则有合法 author(且 prefer 不是 monogram)→ identicon;否则 monogram。
|
|
65
|
+
* photo 带 `fallback`:图片加载失败时直接换用的描述。
|
|
66
|
+
*/
|
|
67
|
+
export function resolveAvatar({ avatar, emoji, author, name, fallback = '友', machine, photoFailed = false, prefer = 'auto' } = {}) {
|
|
68
|
+
const url = photoFailed ? null : blobReadUrl(avatar, machine);
|
|
69
|
+
if (url) return { kind: 'photo', url, fallback: resolveAvatar({ avatar, emoji, author, name, fallback, machine, photoFailed: true, prefer }) };
|
|
70
|
+
const mark = clean(emoji);
|
|
71
|
+
if (mark && [...mark].length <= MAX_EMOJI) return { kind: 'emoji', emoji: mark };
|
|
72
|
+
if (prefer !== 'monogram' && AUTHOR.test(author ?? '')) return { kind: 'identicon', grid: identiconPattern(author), author };
|
|
73
|
+
return { kind: 'monogram', text: initialChar(name, fallback) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 本机 Accord 身份与证书状态(判定见 friends.mjs 的 certStateOf),加上好友统计。
|
|
78
|
+
*/
|
|
79
|
+
export function accordStatusSummary(entry, rows = []) {
|
|
80
|
+
const certificate = entry?.status?.certificate;
|
|
81
|
+
const author = entry?.spec?.author ?? null;
|
|
82
|
+
const until = [certificate?.until, certificate?.expiresAt].find(value => Number.isFinite(value) && value > 0);
|
|
83
|
+
const count = status => rows.filter(row => row.status === status).length;
|
|
84
|
+
return { cert: certStateOf(entry), author, short: shortAuthor(author), certUntil: until ?? null,
|
|
85
|
+
friends: { total: rows.length, bound: count('bound'), pending: count('pending'), conflict: count('conflict') } };
|
|
86
|
+
}
|
package/lib/friends.mjs
CHANGED
|
@@ -217,6 +217,19 @@ export function shortAuthor(author) {
|
|
|
217
217
|
return match ? match[1].slice(0, 8) : '';
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/**
|
|
221
|
+
* 本机 Accord 记录(`coda/accord@1` 的 local)的证书状态:状态里写了 `certificate` 的按它判:null 没有身份,
|
|
222
|
+
* `active` 为 true 才是可发布,其余要换证书;旧宿主不写这个键,有作者就当可发布(发布遇 invalid_state 再落到需要证书)。
|
|
223
|
+
*/
|
|
224
|
+
export function certStateOf(accord) {
|
|
225
|
+
const status = accord?.status;
|
|
226
|
+
if (status && typeof status === 'object' && Object.hasOwn(status, 'certificate')) {
|
|
227
|
+
if (status.certificate === null) return 'no_identity';
|
|
228
|
+
return status.certificate?.active === true ? 'active' : 'needs_cert';
|
|
229
|
+
}
|
|
230
|
+
return accord?.spec?.author ? 'active' : 'no_identity';
|
|
231
|
+
}
|
|
232
|
+
|
|
220
233
|
// ---- 好友列表 ----
|
|
221
234
|
|
|
222
235
|
const RANK = { conflict: 0, pending: 1, bound: 2 };
|
package/lib/outbox.mjs
CHANGED
|
@@ -47,18 +47,7 @@ export function checkPublish({ kind, id, body, audience = ['public'] } = {}) {
|
|
|
47
47
|
return { kind, id, body: JSON.parse(text), audience: [...audience] };
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
* 本机 Accord 记录(`coda/accord@1` 的 local)的证书状态:状态里写了 `certificate` 的按它判:null 没有身份,
|
|
52
|
-
* `active` 为 true 才是可发布,其余要换证书;旧宿主不写这个键,有作者就当可发布(发布遇 invalid_state 再落到需要证书)。
|
|
53
|
-
*/
|
|
54
|
-
export function certStateOf(accord) {
|
|
55
|
-
const status = accord?.status;
|
|
56
|
-
if (status && typeof status === 'object' && Object.hasOwn(status, 'certificate')) {
|
|
57
|
-
if (status.certificate === null) return 'no_identity';
|
|
58
|
-
return status.certificate?.active === true ? 'active' : 'needs_cert';
|
|
59
|
-
}
|
|
60
|
-
return accord?.spec?.author ? 'active' : 'no_identity';
|
|
61
|
-
}
|
|
50
|
+
export { certStateOf } from './friends.mjs';
|
|
62
51
|
|
|
63
52
|
const canonical = value => {
|
|
64
53
|
if (Array.isArray(value)) return value.map(canonical);
|
package/package.json
CHANGED
package/view/app.mjs
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
|
-
// 好友页:本机 Accord
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
1
|
+
// 好友页:本机 Accord 身份与名片(Hero + 状态条)、编辑名片(含本地选图裁剪上传)、好友列表与详情、添加好友。
|
|
2
|
+
// Accord 的读写(coda/accord@1)都在这里按交互发起;备注只经模块存在本机。好友的昵称、备注、节点名等外来数据一律用
|
|
3
|
+
// textContent / DOM API 渲染,从不拼 HTML 字符串;头像图片地址只来自 resolveAvatar(经 readContentPointer 白名单校验)。
|
|
4
|
+
import { accordStatusSummary, blobUploadUrl, initialChar, resolveAvatar } from '../lib/avatar.mjs';
|
|
5
|
+
import { CARD_KIND, COLORS, cardFallbackNotice, checked, mergeFriendRows, mergeProfileAndCard, normalizeCardInput, normalizeContentPointer, parseInvite,
|
|
6
|
+
readCardRecord, readProfileRecord, shortAuthor } from '../lib/friends.mjs';
|
|
7
|
+
import { createMachineBridge, pickMachine } from '../lib/view-machine.mjs';
|
|
8
|
+
import { createCropper } from './cropper.mjs';
|
|
9
|
+
import { fill, h, identiconSvg, svg } from './dom.mjs';
|
|
6
10
|
|
|
7
11
|
const ACCORD = 'coda/accord@1', LOCAL = { kind: ACCORD, id: 'local' };
|
|
8
12
|
const coda = window.coda;
|
|
9
13
|
const root = document.getElementById('root');
|
|
10
14
|
const COLOR_NAMES = { blue: '蓝', orange: '橙', green: '绿', purple: '紫', pink: '粉', teal: '青', gray: '灰' };
|
|
11
15
|
const STATUS_TEXT = { bound: '已互认', pending: '待互认', conflict: '密钥冲突' };
|
|
16
|
+
const MODES = [['photo', '照片'], ['identicon', '几何纹'], ['emoji', 'Emoji'], ['monogram', '字标']];
|
|
17
|
+
const EMOJIS = ['😀', '😎', '🦊', '🐱', '🐼', '🌿', '☕', '🎧', '🚀', '⚡', '🌙', '✨'];
|
|
18
|
+
const UPLOAD_ERRORS = { 404: '当前客户端还不支持上传头像,请升级 Coda 后再试', 413: '图片太大(超过 5 MiB),请换一张' };
|
|
12
19
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
16
|
-
if (value === undefined || value === null || value === false) continue;
|
|
17
|
-
if (key.startsWith('on')) node.addEventListener(key.slice(2), value); else node.setAttribute(key, value === true ? '' : value);
|
|
18
|
-
}
|
|
19
|
-
node.append(...children.flat().filter(c => c !== null && c !== undefined && c !== false));
|
|
20
|
-
return node;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const newState = () => ({ author: null, friends: [], profiles: [], cards: [], notes: {}, loaded: false, problem: null, notesProblem: null, editing: null, removing: null, busy: new Set(), notice: new Map() });
|
|
20
|
+
const newState = () => ({ entry: null, author: null, friends: [], profiles: [], cards: [], notes: {}, loaded: false, problem: null, notesProblem: null,
|
|
21
|
+
busy: new Set(), notice: new Map(), detail: null, removing: null, failedPhotos: new Set() });
|
|
24
22
|
const state = newState();
|
|
25
23
|
let currentMachine = pickMachine(coda, coda.getState?.()?.machine);
|
|
26
24
|
// 读写都发往当前选中的机器;单机时不指明。多步操作在入口取一次,之后不再读 currentMachine。
|
|
27
25
|
const via = () => (currentMachine ? { machine: currentMachine } : undefined);
|
|
26
|
+
// 头像图片的读写地址只在多机空间里带 machine。
|
|
27
|
+
const multiMachine = () => Array.isArray(coda.machines) && coda.machines.length > 1;
|
|
28
|
+
const blobMachine = () => (multiMachine() ? currentMachine : null);
|
|
28
29
|
// 每次选机自增(A → B → A 也不同):旧机器的订阅回调、异步回写,凭它丢弃。
|
|
29
30
|
let selectionGen = 0;
|
|
31
|
+
// 编辑名片的会话代际:每次打开、关闭编辑弹层或切机自增;旧会话的发布做完后不碰新会话的弹层、按钮、提示和裁剪。
|
|
32
|
+
let editorGen = 0;
|
|
33
|
+
function say(target, text, kind = 'hint') { target.className = kind; target.textContent = text; }
|
|
30
34
|
|
|
31
35
|
// ---- 备注:经模块存在本机 ----
|
|
32
36
|
const pendingReplies = new Map();
|
|
@@ -69,23 +73,23 @@ async function readProfiles() {
|
|
|
69
73
|
if (cards.status === 'fulfilled') state.cards = cards.value?.records ?? [];
|
|
70
74
|
const failed = [profiles, cards].find(read => read.status === 'rejected');
|
|
71
75
|
state.problem = failed ? `读不到好友名片:${failed.reason?.message ?? failed.reason}` : null;
|
|
72
|
-
|
|
76
|
+
loadOwn();
|
|
73
77
|
draw();
|
|
74
78
|
}
|
|
75
|
-
|
|
79
|
+
// 本机已发布的名片(Hero 展示它);编辑弹层另有一份草稿,打开时从它拷贝。
|
|
80
|
+
const blankOwn = () => ({ name: '', emoji: '', color: 'blue', avatar: undefined });
|
|
76
81
|
const own = blankOwn();
|
|
77
82
|
const latestOwn = (records, read) => records.map(read).filter(p => p && p.author === state.author).sort((a, b) => b.version - a.version)[0];
|
|
78
|
-
//
|
|
83
|
+
// 与好友列表同一条合并规则(profile 写了的优先,缺的由 friends/card 补);头像随名片带着,重新发布不会把它丢掉或带回已清除的。
|
|
79
84
|
function loadOwn() {
|
|
80
85
|
const mine = mergeProfileAndCard(latestOwn(state.profiles, readProfileRecord), latestOwn(state.cards, readCardRecord));
|
|
81
|
-
if (
|
|
82
|
-
Object.assign(own, { name: mine.name, emoji: mine.emoji ?? '', color: mine.color ?? 'blue', avatar: mine.avatarPresent ? mine.avatar : undefined });
|
|
83
|
-
syncOwnForm();
|
|
86
|
+
if (mine) Object.assign(own, { name: mine.name, emoji: mine.emoji ?? '', color: mine.color ?? 'blue', avatar: mine.avatarPresent ? mine.avatar : undefined });
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
let watching = null;
|
|
87
90
|
function onChange({ type, entry }) {
|
|
88
91
|
if (type === 'DELETED' || !entry) return;
|
|
92
|
+
state.entry = entry;
|
|
89
93
|
state.author = entry.spec?.author ?? null;
|
|
90
94
|
state.friends = entry.status?.friends ?? [];
|
|
91
95
|
state.loaded = true;
|
|
@@ -107,80 +111,305 @@ async function start() {
|
|
|
107
111
|
if (gen === selectionGen) draw();
|
|
108
112
|
}
|
|
109
113
|
|
|
114
|
+
// ---- 头像 ----
|
|
115
|
+
// 按 resolveAvatar 的描述画头像;图片加载失败记下地址、就地换成它的 fallback,重绘时不再试(点「刷新」清空重试)。
|
|
116
|
+
function avatar(desc, size) {
|
|
117
|
+
const node = h('span', { 'aria-hidden': 'true' });
|
|
118
|
+
const show = d => {
|
|
119
|
+
if (d.kind === 'photo' && state.failedPhotos.has(d.url)) return show(d.fallback);
|
|
120
|
+
node.className = `av ${size} k-${d.kind}`;
|
|
121
|
+
if (d.kind === 'photo') node.replaceChildren(h('img', { src: d.url, alt: '', draggable: 'false', onerror: () => { state.failedPhotos.add(d.url); show(d.fallback); } }));
|
|
122
|
+
else if (d.kind === 'identicon') node.replaceChildren(identiconSvg(d.grid));
|
|
123
|
+
else node.textContent = d.kind === 'emoji' ? d.emoji : d.text;
|
|
124
|
+
};
|
|
125
|
+
show(desc);
|
|
126
|
+
return node;
|
|
127
|
+
}
|
|
128
|
+
const ownAvatar = () => resolveAvatar({ avatar: own.avatar, emoji: own.emoji, author: state.author, name: own.name, machine: blobMachine() });
|
|
129
|
+
const rowAvatar = row => resolveAvatar({ avatar: row.avatar, emoji: row.emoji, author: row.author, name: row.title, machine: blobMachine() });
|
|
130
|
+
const cameraIcon = () => svg('svg', { viewBox: '0 0 24 24', width: 11, height: 11, fill: 'none', stroke: 'currentColor', 'stroke-width': 2.4, 'aria-hidden': 'true' },
|
|
131
|
+
svg('path', { d: 'M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z' }), svg('circle', { cx: 12, cy: 13, r: 4 }));
|
|
132
|
+
|
|
133
|
+
// ---- 弹层:宽屏居中模态,窄屏底部抽屉;同一时间只开一个 ----
|
|
134
|
+
let openDialog = null;
|
|
135
|
+
function makeDialog({ title, close: closeLabel, onClose, foot }) {
|
|
136
|
+
const heading = h('h3', {}, title), body = h('div', { class: 'dlg-body' });
|
|
137
|
+
const panel = h('div', { class: 'dialog', role: 'dialog', 'aria-modal': 'true' }, h('div', { class: 'grabber', 'aria-hidden': 'true' }),
|
|
138
|
+
h('div', { class: 'dlg-head' }, heading, h('button', { class: 'btn quiet small', type: 'button', onclick: () => closeDialog() }, closeLabel)),
|
|
139
|
+
body, foot ? h('div', { class: 'dlg-foot' }, foot) : null);
|
|
140
|
+
const scrim = h('div', { class: 'scrim', onclick: e => { if (e.target === scrim) closeDialog(); } }, panel);
|
|
141
|
+
scrim.hidden = true;
|
|
142
|
+
return { scrim, heading, body, onClose };
|
|
143
|
+
}
|
|
144
|
+
function showDialog(dialog) {
|
|
145
|
+
if (openDialog && openDialog !== dialog) closeDialog();
|
|
146
|
+
dialog.scrim.hidden = false;
|
|
147
|
+
openDialog = dialog;
|
|
148
|
+
coda.scroll?.(false)?.catch(() => {});
|
|
149
|
+
}
|
|
150
|
+
function closeDialog() {
|
|
151
|
+
const dialog = openDialog;
|
|
152
|
+
if (!dialog) return;
|
|
153
|
+
openDialog = null;
|
|
154
|
+
dialog.scrim.hidden = true;
|
|
155
|
+
dialog.onClose?.();
|
|
156
|
+
coda.scroll?.(true)?.catch(() => {});
|
|
157
|
+
}
|
|
158
|
+
addEventListener('keydown', e => { if (e.key === 'Escape' && openDialog) closeDialog(); });
|
|
159
|
+
|
|
110
160
|
// ---- 多台机器提供这页时,选看哪台 ----
|
|
111
|
-
const machineBar = h('
|
|
161
|
+
const machineBar = h('nav', { class: 'machines', 'aria-label': '选择机器' });
|
|
112
162
|
function drawMachines() {
|
|
113
|
-
const machines =
|
|
163
|
+
const machines = Array.isArray(coda.machines) ? coda.machines : [];
|
|
114
164
|
machineBar.hidden = machines.length < 2;
|
|
115
|
-
machineBar
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
165
|
+
fill(machineBar, ...(machines.length < 2 ? [] : machines.map(m => {
|
|
166
|
+
if (m.unreachable) {
|
|
167
|
+
const why = m.unreachable === true ? '暂时连不上' : String(m.unreachable);
|
|
168
|
+
return h('button', { class: 'm-pill', type: 'button', disabled: true, title: `不可达:${why}`, 'aria-label': `${m.name || m.id}(不可达:${why})` },
|
|
169
|
+
h('span', { class: 'm-dot off' }), m.name || m.id, h('small', { class: 'm-why' }, '不可达'));
|
|
170
|
+
}
|
|
171
|
+
return h('button', { class: 'm-pill', type: 'button', 'aria-pressed': String(m.id === currentMachine), onclick: () => switchMachine(m.id) }, h('span', { class: 'm-dot' }), m.name || m.id);
|
|
119
172
|
})));
|
|
120
173
|
}
|
|
121
174
|
function switchMachine(id) {
|
|
122
175
|
if (id === currentMachine) return;
|
|
123
176
|
currentMachine = id;
|
|
124
177
|
selectionGen++;
|
|
178
|
+
editorGen++;
|
|
125
179
|
coda.setState?.({ machine: currentMachine });
|
|
126
180
|
reading++;
|
|
127
181
|
watching?.then(w => w?.dispose?.(), () => {});
|
|
128
182
|
watching = null;
|
|
129
183
|
for (const [rid, wait] of [...pendingReplies]) { pendingReplies.delete(rid); wait.reject(new Error('已切换机器')); }
|
|
184
|
+
closeDialog();
|
|
130
185
|
Object.assign(state, newState());
|
|
131
186
|
Object.assign(own, blankOwn());
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for (const target of [ownForm.message, identity.message, invite.message]) say(target, '');
|
|
187
|
+
editor.publish.disabled = false; invite.button.disabled = false;
|
|
188
|
+
for (const target of [hero.message, editor.message, invite.message]) say(target, '');
|
|
135
189
|
drawMachines();
|
|
136
190
|
draw();
|
|
137
191
|
start();
|
|
138
192
|
}
|
|
139
193
|
|
|
140
|
-
// ----
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
194
|
+
// ---- 我的名片:Hero 与状态条 ----
|
|
195
|
+
const hero = {
|
|
196
|
+
card: h('section', { class: 'hero' }),
|
|
197
|
+
avatar: h('button', { class: 'av-ring', type: 'button', 'aria-label': '更换头像', title: '更换头像', onclick: () => openEditor() }),
|
|
198
|
+
name: h('h2', { class: 'hero-name selectable' }),
|
|
199
|
+
key: h('button', { class: 'fp mono', type: 'button', onclick: copyKey }),
|
|
200
|
+
lead: h('p', { class: 'hint' }),
|
|
145
201
|
message: h('p', { class: 'hint' }),
|
|
146
|
-
|
|
202
|
+
friends: h('div', { class: 'tile' }),
|
|
203
|
+
cert: h('div', { class: 'tile' }),
|
|
204
|
+
};
|
|
205
|
+
hero.card.append(
|
|
206
|
+
h('div', { class: 'banner' }, h('div', { class: 'banner-acts' },
|
|
207
|
+
h('button', { class: 'pill', type: 'button', onclick: () => openEditor() }, '编辑名片'),
|
|
208
|
+
h('button', { class: 'pill strong', type: 'button', onclick: () => showDialog(invite.dialog) }, '添加好友'))),
|
|
209
|
+
h('div', { class: 'hero-body' },
|
|
210
|
+
h('div', { class: 'hero-id' }, hero.avatar, h('div', { class: 'hero-names' }, h('div', { class: 'name-line' }, hero.name, h('span', { class: 'tag' }, '我的名片')), hero.key)),
|
|
211
|
+
hero.lead, hero.message,
|
|
212
|
+
h('div', { class: 'bento' }, hero.friends, hero.cert)));
|
|
213
|
+
const CERT = {
|
|
214
|
+
active: { dot: 'ok-dot', text: '可发布' },
|
|
215
|
+
needs_cert: { dot: 'warn-dot', text: '需要证书', sub: '需绑定或续期代签证书:前往客户端「设置 › 身份」处理后再发布名片' },
|
|
216
|
+
no_identity: { dot: 'off-dot', text: '未建身份', sub: '前往客户端「设置 › 身份」创建' },
|
|
147
217
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
onclick: () => { own.touched = true; own.color = color; syncOwnForm(); } })));
|
|
218
|
+
const formatTime = ms => new Date(ms).toLocaleString('zh-CN', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
219
|
+
function tile(node, label, value, sub, dot) {
|
|
220
|
+
fill(node, h('span', { class: 'tile-k' }, label), h('span', { class: 'tile-v' }, dot ? h('span', { class: `dot ${dot}` }) : null, value), sub);
|
|
152
221
|
}
|
|
153
|
-
function
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
} catch (e) { if (live()) say(ownForm.message, `没有发布成功:${e.message}`, 'error'); }
|
|
177
|
-
if (live()) ownForm.button.disabled = false;
|
|
222
|
+
function drawHero(shown) {
|
|
223
|
+
hero.card.className = `hero c-${own.color}`;
|
|
224
|
+
hero.avatar.replaceChildren(avatar(ownAvatar(), 'lg'), h('span', { class: 'cam' }, cameraIcon()));
|
|
225
|
+
hero.name.textContent = own.name || (state.loaded ? '还没有名片' : '读取中…');
|
|
226
|
+
hero.lead.textContent = own.name || !state.loaded ? '' : '点「编辑名片」设置昵称、头像和主题色,好友就能认出你。名片对所有人公开。';
|
|
227
|
+
hero.lead.hidden = !hero.lead.textContent;
|
|
228
|
+
const summary = accordStatusSummary(state.entry, shown);
|
|
229
|
+
hero.key.disabled = !state.author;
|
|
230
|
+
hero.key.textContent = state.author ? `ed25519:${summary.short}… · 复制` : !state.loaded ? '读取中…' : summary.cert === 'no_identity' ? '未建身份' : '未取得公钥';
|
|
231
|
+
hero.key.title = state.author ? '复制完整公钥' : '';
|
|
232
|
+
if (!state.loaded) {
|
|
233
|
+
tile(hero.friends, '好友', '读取中…');
|
|
234
|
+
tile(hero.cert, '身份', '读取中…');
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const { bound, pending, conflict, total } = summary.friends;
|
|
238
|
+
tile(hero.friends, '好友', `${bound} 位已互认`, h('span', { class: 'tile-s' },
|
|
239
|
+
conflict ? h('span', { class: 'badge conflict' }, `${conflict} 冲突`) : null,
|
|
240
|
+
pending ? h('span', { class: 'badge pending' }, `${pending} 待互认`) : null,
|
|
241
|
+
conflict || pending ? null : total ? '全部已互认' : '还没有好友'));
|
|
242
|
+
const cert = CERT[summary.cert];
|
|
243
|
+
const sub = summary.cert === 'active' ? (summary.certUntil ? `证书有效至 ${formatTime(summary.certUntil)}` : '名片可正常发布') : cert.sub;
|
|
244
|
+
tile(hero.cert, '身份', cert.text, h('span', { class: 'tile-s' }, sub), cert.dot);
|
|
178
245
|
}
|
|
179
|
-
const identity = { key: h('span', { class: 'key mono selectable' }), copy: h('button', { class: 'btn quiet small', type: 'button', onclick: copyKey }, '复制公钥'), message: h('p', { class: 'hint' }) };
|
|
180
246
|
async function copyKey() {
|
|
181
247
|
if (!state.author) return;
|
|
182
248
|
const gen = selectionGen;
|
|
183
|
-
try { await coda.copy(state.author); if (gen === selectionGen) say(
|
|
249
|
+
try { await coda.copy(state.author); if (gen === selectionGen) say(hero.message, '公钥已复制', 'ok'); } catch (e) { if (gen === selectionGen) say(hero.message, `复制失败:${e.message}`, 'error'); }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---- 编辑名片 ----
|
|
253
|
+
// 草稿:mode 决定头像怎么发;avatar 是沿用的已有图片指针(清除照片后为 null),新选的图在 cropper 里。
|
|
254
|
+
const draft = { name: '', color: 'blue', mode: 'identicon', emoji: '', avatar: null };
|
|
255
|
+
const preview = { canvas: h('canvas', { class: 'preview-canvas', width: 144, height: 144 }) };
|
|
256
|
+
const cropper = createCropper({ onChange: () => { if (draft.mode === 'photo' && cropper.ready) mirrorCrop(); } });
|
|
257
|
+
function mirrorCrop() {
|
|
258
|
+
const ctx = preview.canvas.getContext('2d');
|
|
259
|
+
ctx.clearRect(0, 0, 144, 144);
|
|
260
|
+
ctx.drawImage(cropper.canvas, 0, 0, 144, 144);
|
|
261
|
+
}
|
|
262
|
+
const editor = {
|
|
263
|
+
dialog: null,
|
|
264
|
+
preview: h('div', { class: 'mini-card' }),
|
|
265
|
+
modes: h('div', { class: 'seg', role: 'group', 'aria-label': '头像类型' }),
|
|
266
|
+
file: h('input', { type: 'file', accept: 'image/*', onchange: pickFile }),
|
|
267
|
+
photo: h('div', { class: 'pane' }),
|
|
268
|
+
emoji: h('input', { type: 'text', maxlength: '8', placeholder: '自定义 Emoji(1–8 字)', autocomplete: 'off', oninput: e => { draft.emoji = e.target.value; syncEditor(); } }),
|
|
269
|
+
emojis: h('div', { class: 'emoji-grid' }),
|
|
270
|
+
other: h('p', { class: 'hint' }),
|
|
271
|
+
name: h('input', { type: 'text', maxlength: '40', placeholder: '昵称(1–40 字)', autocomplete: 'off', oninput: e => { draft.name = e.target.value; syncPreview(); } }),
|
|
272
|
+
swatches: h('div', { class: 'swatches', role: 'group', 'aria-label': '主题色' }),
|
|
273
|
+
message: h('p', { class: 'hint' }),
|
|
274
|
+
publish: h('button', { class: 'btn', type: 'button', onclick: publishCard }, '发布名片'),
|
|
275
|
+
};
|
|
276
|
+
editor.file.hidden = true;
|
|
277
|
+
editor.emojiPane = h('div', { class: 'pane' }, editor.emojis, editor.emoji);
|
|
278
|
+
editor.dialog = makeDialog({ title: '编辑名片', close: '取消', onClose: () => { editorGen++; cropper.clear(); },
|
|
279
|
+
foot: [editor.message, h('span', { class: 'spacer' }), editor.publish] });
|
|
280
|
+
editor.dialog.body.append(h('div', { class: 'ed-cols' },
|
|
281
|
+
h('div', { class: 'ed-preview' }, editor.preview, h('p', { class: 'hint center' }, '实时预览 · 好友看到的效果')),
|
|
282
|
+
h('div', { class: 'ed-controls' },
|
|
283
|
+
h('span', { class: 'lbl' }, '头像'), editor.modes, editor.file, editor.photo, editor.emojiPane, editor.other,
|
|
284
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, '昵称'), editor.name),
|
|
285
|
+
h('div', { class: 'field' }, h('span', { class: 'lbl' }, '主题色'), editor.swatches))));
|
|
286
|
+
|
|
287
|
+
const modeOf = card => (card.avatar ? 'photo' : !card.emoji ? 'identicon' : card.emoji === initialChar(card.name, '') ? 'monogram' : 'emoji');
|
|
288
|
+
function openEditor() {
|
|
289
|
+
editorGen++;
|
|
290
|
+
cropper.clear();
|
|
291
|
+
editor.publish.disabled = false;
|
|
292
|
+
Object.assign(draft, { name: own.name, color: own.color, mode: modeOf(own), emoji: own.emoji, avatar: own.avatar ?? null });
|
|
293
|
+
editor.name.value = draft.name;
|
|
294
|
+
editor.emoji.value = draft.mode === 'emoji' ? draft.emoji : '';
|
|
295
|
+
if (draft.mode !== 'emoji') draft.emoji = '';
|
|
296
|
+
say(editor.message, '');
|
|
297
|
+
syncEditor();
|
|
298
|
+
showDialog(editor.dialog);
|
|
299
|
+
}
|
|
300
|
+
function draftAvatar() {
|
|
301
|
+
const author = state.author, name = draft.name;
|
|
302
|
+
if (draft.mode === 'photo') return resolveAvatar({ avatar: draft.avatar, emoji: own.emoji, author, name, machine: blobMachine() });
|
|
303
|
+
if (draft.mode === 'emoji') return resolveAvatar({ emoji: draft.emoji, author, name });
|
|
304
|
+
if (draft.mode === 'monogram') return { kind: 'monogram', text: initialChar(name) };
|
|
305
|
+
return resolveAvatar({ author, name });
|
|
306
|
+
}
|
|
307
|
+
function syncPreview() {
|
|
308
|
+
const fresh = draft.mode === 'photo' && cropper.ready;
|
|
309
|
+
editor.preview.className = `mini-card c-${draft.color}`;
|
|
310
|
+
editor.preview.replaceChildren(h('div', { class: 'banner small' }),
|
|
311
|
+
h('div', { class: 'mini-body' },
|
|
312
|
+
h('span', { class: 'av-ring md' }, fresh ? h('span', { class: 'av md k-photo' }, preview.canvas) : avatar(draftAvatar(), 'md')),
|
|
313
|
+
h('div', { class: 'mini-name truncate' }, draft.name.trim() || '未命名'),
|
|
314
|
+
state.author ? h('div', { class: 'mono secondary' }, `@${shortAuthor(state.author)}`) : null));
|
|
315
|
+
if (fresh) mirrorCrop();
|
|
316
|
+
if (draft.mode === 'monogram') editor.other.textContent = `以昵称首字「${initialChar(draft.name)}」作头像,昵称改了它跟着变。`;
|
|
317
|
+
}
|
|
318
|
+
function syncEditor() {
|
|
319
|
+
editor.modes.replaceChildren(...MODES.map(([mode, label]) => h('button', { type: 'button', 'aria-pressed': String(draft.mode === mode), onclick: () => { draft.mode = mode; syncEditor(); } }, label)));
|
|
320
|
+
editor.photo.hidden = draft.mode !== 'photo';
|
|
321
|
+
editor.emojiPane.hidden = draft.mode !== 'emoji';
|
|
322
|
+
editor.other.hidden = draft.mode !== 'identicon' && draft.mode !== 'monogram';
|
|
323
|
+
editor.other.textContent = draft.mode === 'identicon' ? (state.author ? '由你的公钥确定性生成的 5×5 几何纹,换设备也一样。' : '取得身份后按公钥生成几何纹;现在先以昵称首字代替。') : '';
|
|
324
|
+
const choose = h('button', { class: 'btn quiet small', type: 'button', onclick: () => editor.file.click() }, cropper.ready || draft.avatar ? '换一张' : '选择图片');
|
|
325
|
+
const clear = cropper.ready || draft.avatar ? h('button', { class: 'btn danger small', type: 'button', onclick: clearPhoto }, '清除照片') : null;
|
|
326
|
+
fill(editor.photo, ...(cropper.ready
|
|
327
|
+
? [cropper.box, h('div', { class: 'zoom-row' }, h('span', { class: 'secondary' }, '缩放'), cropper.zoom, cropper.zoomText),
|
|
328
|
+
h('div', { class: 'actions' }, choose, h('button', { class: 'btn quiet small', type: 'button', onclick: () => cropper.reset() }, '重置裁切'), clear),
|
|
329
|
+
h('p', { class: 'hint' }, '拖动图片调整位置;发布时导出 512×512 的正方形头像。')]
|
|
330
|
+
: [h('p', { class: 'hint' }, draft.avatar ? '正在使用已发布的照片。' : '从本机选一张图片,裁剪成正方形头像。'), h('div', { class: 'actions' }, choose, clear)]));
|
|
331
|
+
editor.emojis.replaceChildren(...EMOJIS.map(mark => h('button', { type: 'button', class: 'emoji-opt', 'aria-label': `Emoji ${mark}`, 'aria-pressed': String(draft.emoji === mark),
|
|
332
|
+
onclick: () => { draft.emoji = mark; editor.emoji.value = mark; syncEditor(); } }, mark)));
|
|
333
|
+
editor.swatches.replaceChildren(...COLORS.map(color => h('button', { class: `swatch c-${color}`, type: 'button', 'aria-label': `主题色:${COLOR_NAMES[color]}`, 'aria-pressed': String(draft.color === color),
|
|
334
|
+
onclick: () => { draft.color = color; syncEditor(); } })));
|
|
335
|
+
syncPreview();
|
|
336
|
+
}
|
|
337
|
+
function pickFile(e) {
|
|
338
|
+
const file = e.target.files?.[0];
|
|
339
|
+
e.target.value = '';
|
|
340
|
+
if (!file) return;
|
|
341
|
+
say(editor.message, '');
|
|
342
|
+
cropper.load(file).then(loaded => { if (loaded) { draft.mode = 'photo'; syncEditor(); } }, error => { say(editor.message, error.message, 'error'); syncEditor(); });
|
|
343
|
+
}
|
|
344
|
+
function clearPhoto() {
|
|
345
|
+
cropper.clear();
|
|
346
|
+
draft.avatar = null;
|
|
347
|
+
draft.mode = 'identicon';
|
|
348
|
+
syncEditor();
|
|
349
|
+
}
|
|
350
|
+
// 发布用的名片字段:原名片有图而这次不用照片,就显式写 avatar: null 清除;照片模式没换图就沿用已有指针,不重复上传。
|
|
351
|
+
function draftFields() {
|
|
352
|
+
const fields = { name: draft.name, color: draft.color }, drop = own.avatar ? null : undefined;
|
|
353
|
+
if (draft.mode === 'photo') {
|
|
354
|
+
if (!cropper.ready && !draft.avatar) throw new Error('请先选择一张图片,或换用其他头像类型');
|
|
355
|
+
return { ...fields, emoji: own.emoji, avatar: cropper.ready ? undefined : draft.avatar };
|
|
356
|
+
}
|
|
357
|
+
if (draft.mode === 'emoji') {
|
|
358
|
+
if (!draft.emoji.trim()) throw new Error('请选一个或输入一个 Emoji');
|
|
359
|
+
return { ...fields, emoji: draft.emoji, avatar: drop };
|
|
360
|
+
}
|
|
361
|
+
// 字标不扩协议:把昵称首字写进 emoji,双方都按 emoji 显示。
|
|
362
|
+
return { ...fields, emoji: draft.mode === 'monogram' ? initialChar(draft.name, '') : undefined, avatar: drop };
|
|
363
|
+
}
|
|
364
|
+
async function uploadAvatar(blob, machine) {
|
|
365
|
+
let response;
|
|
366
|
+
try { response = await fetch(blobUploadUrl(machine), { method: 'POST', headers: { 'Content-Type': blob.type }, body: blob }); }
|
|
367
|
+
catch (e) { throw new Error(`头像上传失败(网络错误:${e.message})`); }
|
|
368
|
+
if (!response.ok) throw new Error(UPLOAD_ERRORS[response.status] ?? `头像上传失败(HTTP ${response.status})`);
|
|
369
|
+
const { owner, path, sha256, mime, size, name } = await response.json();
|
|
370
|
+
return normalizeContentPointer({ owner, path, sha256, mime, size, name });
|
|
371
|
+
}
|
|
372
|
+
// 发 profile;绑定了代签证书时 profile 须由客户端根签,这里发不了:改发可代签的社交名片 friends/card,好友一样看得到。
|
|
373
|
+
async function publishBody(body, opts, author, live) {
|
|
374
|
+
try {
|
|
375
|
+
await coda.call(LOCAL, 'publish', { kind: 'profile', id: 'self', body, audience: ['public'] }, opts);
|
|
376
|
+
return '名片已发布,好友会看到它';
|
|
377
|
+
} catch (e) {
|
|
378
|
+
if (e?.code !== 'forbidden') throw e;
|
|
379
|
+
await coda.call(LOCAL, 'publish', { kind: CARD_KIND, id: 'self', body, audience: ['public'] }, opts);
|
|
380
|
+
// 缓存的 state.profiles 可能还没读完或读失败了:现查一次本机作者的根签 profile,查不出来就不承诺。已切机就不必查了。
|
|
381
|
+
if (!live()) return null;
|
|
382
|
+
let rooted = null;
|
|
383
|
+
try { rooted = ((await coda.query(LOCAL, 'records', { kind: 'profile', author, limit: 1 }, opts))?.records ?? []).some(record => readProfileRecord(record)); } catch { /* 按没读出来提示 */ }
|
|
384
|
+
return cardFallbackNotice(rooted);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
// 上传与发布都绑定入口时的机器与代际:途中切了机,仍在原机器做完,但不往新机器的页面写任何状态。
|
|
388
|
+
async function publishCard() {
|
|
389
|
+
const upload = draft.mode === 'photo' && cropper.ready;
|
|
390
|
+
let body;
|
|
391
|
+
try { body = normalizeCardInput(draftFields()); } catch (e) { return say(editor.message, e.message, 'error'); }
|
|
392
|
+
const gen = selectionGen, session = editorGen, opts = via(), machine = blobMachine(), author = state.author, live = () => gen === selectionGen;
|
|
393
|
+
const current = () => live() && session === editorGen;
|
|
394
|
+
editor.publish.disabled = true;
|
|
395
|
+
try {
|
|
396
|
+
if (upload) {
|
|
397
|
+
say(editor.message, '正在处理图片…', 'progress');
|
|
398
|
+
const blob = await cropper.export();
|
|
399
|
+
if (current()) say(editor.message, '正在上传头像…', 'progress');
|
|
400
|
+
body = { ...body, avatar: await uploadAvatar(blob, machine) };
|
|
401
|
+
}
|
|
402
|
+
if (current()) say(editor.message, '正在发布…', 'progress');
|
|
403
|
+
const notice = await publishBody(body, opts, author, live);
|
|
404
|
+
if (live()) readProfiles();
|
|
405
|
+
if (current()) {
|
|
406
|
+
// 关弹层会让会话代际自增,所以先恢复按钮。
|
|
407
|
+
editor.publish.disabled = false;
|
|
408
|
+
closeDialog();
|
|
409
|
+
say(hero.message, notice, 'ok');
|
|
410
|
+
}
|
|
411
|
+
} catch (e) { if (current()) say(editor.message, `没有发布成功:${e.message}`, 'error'); }
|
|
412
|
+
if (current()) editor.publish.disabled = false;
|
|
184
413
|
}
|
|
185
414
|
|
|
186
415
|
// ---- 添加好友 ----
|
|
@@ -195,6 +424,17 @@ const invite = {
|
|
|
195
424
|
button: h('button', { class: 'btn', type: 'button', onclick: submitInvite }, '接受邀请'),
|
|
196
425
|
hidden: {},
|
|
197
426
|
};
|
|
427
|
+
invite.dialog = makeDialog({ title: '添加好友', close: '关闭' });
|
|
428
|
+
invite.dialog.body.append(h('div', { class: 'stack' },
|
|
429
|
+
h('p', { class: 'hint' }, '暂需由对方提供 friend 角色入网码,后续将支持客户端一键生成邀请。'),
|
|
430
|
+
invite.paste,
|
|
431
|
+
h('details', {}, h('summary', {}, '分字段填写'), h('div', { class: 'fields' },
|
|
432
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'control(入网地址)'), invite.control),
|
|
433
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'authKey(入网码)'), invite.authKey),
|
|
434
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'linkId'), invite.linkId),
|
|
435
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'scope'), invite.scope),
|
|
436
|
+
h('label', { class: 'field' }, h('span', { class: 'lbl' }, 'peerNode'), invite.peerNode))),
|
|
437
|
+
h('div', { class: 'line' }, invite.button), invite.message));
|
|
198
438
|
// hostname、peerPort 只随识别出的那份邀请:手改入网地址或入网码就是另一份邀请了,丢掉;改 linkId、scope、peerNode 不算。
|
|
199
439
|
function dropHidden() { invite.hidden = {}; }
|
|
200
440
|
function parsePaste() {
|
|
@@ -242,11 +482,11 @@ async function submitInvite() {
|
|
|
242
482
|
try {
|
|
243
483
|
await coda.call(LOCAL, 'handshake', { node, ...(peerNode ? { peerNode } : {}) }, opts);
|
|
244
484
|
if (live()) say(invite.message, '好友已添加并完成互认', 'ok');
|
|
245
|
-
} catch (e) { if (live()) say(invite.message, `已加入通道,但互认暂未完成(${e.message}
|
|
485
|
+
} catch (e) { if (live()) say(invite.message, `已加入通道,但互认暂未完成(${e.message})。可稍后在好友详情里点「重新互认」重试`, 'error'); }
|
|
246
486
|
if (live()) invite.button.disabled = false;
|
|
247
487
|
}
|
|
248
488
|
|
|
249
|
-
// ----
|
|
489
|
+
// ---- 好友列表与详情 ----
|
|
250
490
|
const list = h('div');
|
|
251
491
|
const countBadge = h('span', { class: 'count' });
|
|
252
492
|
function rows() { return mergeFriendRows({ friends: state.friends, profiles: state.profiles, cards: state.cards, notes: state.notes }); }
|
|
@@ -267,47 +507,93 @@ async function remove(row) {
|
|
|
267
507
|
try { await coda.call(LOCAL, 'remove', { node: row.node }, opts); }
|
|
268
508
|
catch (e) { failure = { kind: 'error', text: `移除失败:${e.message}` }; }
|
|
269
509
|
if (gen !== selectionGen) return;
|
|
270
|
-
|
|
271
|
-
state.
|
|
510
|
+
state.busy.delete(row.node);
|
|
511
|
+
if (failure) state.notice.set(row.node, failure);
|
|
512
|
+
else {
|
|
513
|
+
state.notice.delete(row.node); state.removing = null;
|
|
514
|
+
if (state.detail === row.node) closeDialog();
|
|
515
|
+
}
|
|
516
|
+
draw();
|
|
272
517
|
}
|
|
273
518
|
async function saveNote(row, text) {
|
|
274
519
|
const gen = selectionGen;
|
|
275
|
-
state.
|
|
520
|
+
state.busy.add(row.node); state.notice.set(row.node, { kind: 'progress', text: '正在保存备注…' }); draw();
|
|
276
521
|
let saved, failure;
|
|
277
522
|
try { saved = await ask(text.trim() ? 'notes.set' : 'notes.delete', { node: row.node, note: text }); }
|
|
278
523
|
catch (e) { failure = { kind: 'error', text: `备注没存下:${e.message}` }; }
|
|
279
524
|
if (gen !== selectionGen) return;
|
|
280
|
-
|
|
525
|
+
state.busy.delete(row.node);
|
|
526
|
+
if (failure) state.notice.set(row.node, failure);
|
|
527
|
+
else {
|
|
528
|
+
state.notes = saved;
|
|
529
|
+
state.notice.set(row.node, { kind: 'ok', text: text.trim() ? '备注已保存' : '备注已清空' });
|
|
530
|
+
if (state.detail === row.node) detail.note.value = rows().find(r => r.node === row.node)?.note ?? '';
|
|
531
|
+
}
|
|
281
532
|
draw();
|
|
282
533
|
}
|
|
283
534
|
|
|
284
|
-
|
|
535
|
+
const detail = {
|
|
536
|
+
dialog: makeDialog({ title: '好友', close: '完成', onClose: () => { state.detail = null; state.removing = null; } }),
|
|
537
|
+
card: h('div'),
|
|
538
|
+
info: h('dl', { class: 'facts' }),
|
|
539
|
+
note: h('input', { type: 'text', maxlength: '40', placeholder: '备注名(只存在本机,不会发给好友)', autocomplete: 'off',
|
|
540
|
+
onkeydown: e => { if (e.key === 'Enter') noteAction(row => saveNote(row, detail.note.value)); } }),
|
|
541
|
+
noteButtons: h('div', { class: 'line' }),
|
|
542
|
+
actions: h('div', { class: 'actions split' }),
|
|
543
|
+
notice: h('div'),
|
|
544
|
+
};
|
|
545
|
+
detail.dialog.body.append(h('div', { class: 'stack' }, detail.card, detail.info,
|
|
546
|
+
h('div', { class: 'field' }, h('span', { class: 'lbl' }, '本机备注'), h('div', { class: 'line nowrap' }, detail.note, detail.noteButtons)),
|
|
547
|
+
detail.actions, detail.notice));
|
|
548
|
+
const detailRow = () => rows().find(row => row.node === state.detail);
|
|
549
|
+
function noteAction(run) { const row = detailRow(); if (row && !state.busy.has(row.node)) run(row); }
|
|
550
|
+
function openDetail(row) {
|
|
551
|
+
state.detail = row.node; state.removing = null;
|
|
552
|
+
detail.note.value = row.note;
|
|
553
|
+
drawDetail();
|
|
554
|
+
showDialog(detail.dialog);
|
|
555
|
+
}
|
|
556
|
+
function fact(label, ...value) { return [h('dt', {}, label), h('dd', { class: 'selectable' }, ...value)]; }
|
|
557
|
+
async function copyFriendKey(row) {
|
|
558
|
+
const gen = selectionGen;
|
|
559
|
+
try { await coda.copy(row.author); if (gen === selectionGen) { state.notice.set(row.node, { kind: 'ok', text: '公钥已复制' }); draw(); } }
|
|
560
|
+
catch (e) { if (gen === selectionGen) { state.notice.set(row.node, { kind: 'error', text: `复制失败:${e.message}` }); draw(); } }
|
|
561
|
+
}
|
|
562
|
+
function drawDetail() {
|
|
563
|
+
const row = detailRow();
|
|
564
|
+
if (!row) return;
|
|
285
565
|
const busy = state.busy.has(row.node), notice = state.notice.get(row.node);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
h('
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
566
|
+
detail.dialog.heading.textContent = row.title;
|
|
567
|
+
detail.card.replaceChildren(h('div', { class: `mini-card c-${row.color}` }, h('div', { class: 'banner small' }),
|
|
568
|
+
h('div', { class: 'mini-body row' }, h('span', { class: 'av-ring lg' }, avatar(rowAvatar(row), 'lg')),
|
|
569
|
+
h('div', { class: 'mini-names' }, h('div', { class: 'mini-name truncate selectable' }, row.title),
|
|
570
|
+
row.note && row.profileName ? h('div', { class: 'secondary truncate selectable' }, `原名 ${row.profileName}`) : null),
|
|
571
|
+
h('span', { class: `badge ${row.status}` }, STATUS_TEXT[row.status]))));
|
|
572
|
+
detail.info.replaceChildren(
|
|
573
|
+
...fact('公钥', row.author ? h('span', { class: 'mono key-full' }, row.author) : h('span', { class: 'secondary' }, '密钥未互认'),
|
|
574
|
+
row.author ? h('button', { class: 'btn quiet small', type: 'button', onclick: () => copyFriendKey(row) }, '复制公钥') : null),
|
|
575
|
+
...fact('节点', h('span', { class: 'mono' }, row.peerNode ?? row.node)),
|
|
576
|
+
...fact('连接', STATUS_TEXT[row.status]));
|
|
577
|
+
fill(detail.noteButtons,
|
|
578
|
+
h('button', { class: 'btn small', type: 'button', disabled: busy, onclick: () => noteAction(r => saveNote(r, detail.note.value)) }, '保存'),
|
|
579
|
+
row.note ? h('button', { class: 'btn quiet small', type: 'button', disabled: busy, onclick: () => noteAction(r => saveNote(r, '')) }, '清空') : null);
|
|
580
|
+
detail.actions.replaceChildren(...(state.removing === row.node
|
|
581
|
+
? [h('span', { class: 'secondary' }, '移除后不再同步这位好友,确定吗?'), h('span', { class: 'spacer' }),
|
|
302
582
|
h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => remove(row) }, '确认移除'),
|
|
303
|
-
h('button', { class: 'btn quiet small', type: 'button', onclick: () => { state.removing = null; draw(); } }, '
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
583
|
+
h('button', { class: 'btn quiet small', type: 'button', onclick: () => { state.removing = null; draw(); } }, '再想想')]
|
|
584
|
+
: [h('button', { class: 'btn quiet small', type: 'button', disabled: busy, onclick: () => handshake(row) }, '重新互认'), h('span', { class: 'spacer' }),
|
|
585
|
+
h('button', { class: 'btn danger small', type: 'button', disabled: busy, onclick: () => { state.removing = row.node; draw(); } }, '移除好友…')]));
|
|
586
|
+
fill(detail.notice,
|
|
587
|
+
row.status === 'conflict' ? h('p', { class: 'warn-box' }, '对方的密钥与之前互认的不一致,可能换了设备或身份。确认是本人后可「重新互认」,否则建议移除。') : null,
|
|
588
|
+
notice ? h('p', { class: notice.kind }, notice.text) : null);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function friendTile(row) {
|
|
592
|
+
const secondary = [row.note && row.profileName ? row.profileName : null, row.short ? `@${row.short}` : '密钥未互认'].filter(Boolean).join(' · ');
|
|
593
|
+
return h('li', {}, h('button', { class: `f-tile c-${row.color}`, type: 'button', 'aria-label': `${row.title},${STATUS_TEXT[row.status]}`, onclick: () => openDetail(row) },
|
|
594
|
+
avatar(rowAvatar(row), 'sm'),
|
|
595
|
+
h('span', { class: 'f-info' }, h('span', { class: 'f-name truncate' }, row.title), h('span', { class: 'f-meta truncate' }, secondary)),
|
|
596
|
+
h('span', { class: `badge ${row.status}` }, STATUS_TEXT[row.status])));
|
|
311
597
|
}
|
|
312
598
|
|
|
313
599
|
const problem = h('p', { class: 'error selectable' });
|
|
@@ -315,39 +601,23 @@ function draw() {
|
|
|
315
601
|
const problems = [state.notesProblem, state.problem].filter(Boolean).join(';');
|
|
316
602
|
problem.textContent = problems;
|
|
317
603
|
problem.hidden = !problems;
|
|
318
|
-
identity.key.textContent = state.author ? `ed25519:${shortAuthor(state.author)}…` : state.loaded ? '未取得' : '读取中…';
|
|
319
|
-
identity.copy.disabled = !state.author;
|
|
320
604
|
const shown = rows();
|
|
605
|
+
drawHero(shown);
|
|
321
606
|
countBadge.textContent = String(shown.length);
|
|
322
607
|
countBadge.hidden = !shown.length;
|
|
323
|
-
list.replaceChildren(shown.length ? h('ul', { class: '
|
|
324
|
-
: h('p', { class: 'empty' }, state.loaded ? '
|
|
608
|
+
list.replaceChildren(shown.length ? h('ul', { class: 'friends' }, shown.map(friendTile))
|
|
609
|
+
: h('p', { class: 'empty' }, state.loaded ? '还没有好友。点上方「添加好友」,粘贴对方发来的邀请即可。' : '正在读取…'));
|
|
610
|
+
if (state.detail !== null) { if (detailRow()) drawDetail(); else closeDialog(); }
|
|
325
611
|
}
|
|
326
612
|
|
|
327
|
-
root.replaceChildren(h('div', { class: 'page' }, machineBar, problem,
|
|
328
|
-
h('section', {}, h('h2', {
|
|
329
|
-
|
|
330
|
-
h('div', { class: 'fields' }, h('label', { class: 'field' }, h('span', {}, '昵称'), ownForm.name), h('label', { class: 'field' }, h('span', {}, '头像'), ownForm.emoji)),
|
|
331
|
-
h('div', { class: 'field' }, h('span', { class: 'secondary' }, '主题色'), ownForm.swatches),
|
|
332
|
-
h('div', { class: 'line' }, ownForm.button), ownForm.message,
|
|
333
|
-
h('p', { class: 'hint' }, '名片对所有人公开,只含昵称、头像和主题色。'))),
|
|
334
|
-
h('section', {}, h('h2', {}, '添加好友'), h('div', { class: 'card' },
|
|
335
|
-
h('p', { class: 'hint' }, '暂需由对方提供 friend 角色入网码,后续将支持客户端一键生成邀请。'),
|
|
336
|
-
invite.paste,
|
|
337
|
-
h('details', {}, h('summary', {}, '分字段填写'), h('div', { class: 'fields' },
|
|
338
|
-
h('label', { class: 'field' }, h('span', {}, 'control(入网地址)'), invite.control),
|
|
339
|
-
h('label', { class: 'field' }, h('span', {}, 'authKey(入网码)'), invite.authKey),
|
|
340
|
-
h('label', { class: 'field' }, h('span', {}, 'linkId'), invite.linkId),
|
|
341
|
-
h('label', { class: 'field' }, h('span', {}, 'scope'), invite.scope),
|
|
342
|
-
h('label', { class: 'field' }, h('span', {}, 'peerNode'), invite.peerNode))),
|
|
343
|
-
h('div', { class: 'line' }, invite.button), invite.message)),
|
|
344
|
-
h('section', {}, h('h2', {}, '好友', countBadge), list)));
|
|
345
|
-
syncOwnForm();
|
|
613
|
+
root.replaceChildren(h('div', { class: 'page' }, machineBar, problem, hero.card,
|
|
614
|
+
h('section', {}, h('h2', { class: 'sec' }, '好友', countBadge), list)),
|
|
615
|
+
editor.dialog.scrim, detail.dialog.scrim, invite.dialog.scrim);
|
|
346
616
|
drawMachines();
|
|
617
|
+
syncEditor();
|
|
347
618
|
draw();
|
|
348
619
|
|
|
349
|
-
|
|
350
|
-
coda.on('toolbar', ({ id } = {}) => { if (id === 'refresh') refresh(); });
|
|
620
|
+
coda.on('toolbar', ({ id } = {}) => { if (id === 'refresh') { state.failedPhotos.clear(); draw(); readProfiles(); } });
|
|
351
621
|
coda.toolbar([{ id: 'refresh', label: '刷新', icon: 'arrow.clockwise', kind: 'button' }]).catch(() => {});
|
|
352
622
|
coda.header({ text: '好友' }).catch(() => {});
|
|
353
623
|
start();
|
package/view/cropper.mjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// 头像裁剪:本地选的图放进 1:1 方框,拖动平移(Pointer Events,鼠标与触控都走它)、滑块缩放 1.0×–3.0×,
|
|
2
|
+
// 导出 512×512 的压缩图。图片只经 URL.createObjectURL 读进来,换图、清除时回收地址。
|
|
3
|
+
import { BLOB_MAX_BYTES } from '../lib/avatar.mjs';
|
|
4
|
+
import { h } from './dom.mjs';
|
|
5
|
+
|
|
6
|
+
export const OUTPUT_SIZE = 512;
|
|
7
|
+
const VIEW = 440, MIN_ZOOM = 1, MAX_ZOOM = 3;
|
|
8
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
9
|
+
const toBlob = (canvas, type, quality) => new Promise(resolve => canvas.toBlob(resolve, type, quality));
|
|
10
|
+
|
|
11
|
+
/** 先试 WebP 0.86;浏览器不会编 WebP(退回别的格式或给 null)或超限,就用 JPEG 0.86,仍超限降到 0.72。 */
|
|
12
|
+
export async function encodeAvatar(canvas) {
|
|
13
|
+
const webp = await toBlob(canvas, 'image/webp', 0.86);
|
|
14
|
+
if (webp?.type === 'image/webp' && webp.size <= BLOB_MAX_BYTES) return webp;
|
|
15
|
+
for (const quality of [0.86, 0.72]) {
|
|
16
|
+
const jpeg = await toBlob(canvas, 'image/jpeg', quality);
|
|
17
|
+
if (jpeg && jpeg.size <= BLOB_MAX_BYTES) return jpeg;
|
|
18
|
+
}
|
|
19
|
+
throw new Error('图片压缩后仍超过 5 MiB,请换一张');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** onChange 在画面变化(载入、拖动、缩放、清除)后调用,给实时预览用。 */
|
|
23
|
+
export function createCropper({ onChange } = {}) {
|
|
24
|
+
let crop = null, url = null, drag = null, loading = 0;
|
|
25
|
+
const canvas = h('canvas', { class: 'crop-canvas', width: VIEW, height: VIEW });
|
|
26
|
+
const zoomText = h('span', { class: 'mono zoom-value' }, '1.0×');
|
|
27
|
+
const zoom = h('input', { type: 'range', min: MIN_ZOOM, max: MAX_ZOOM, step: '0.01', value: '1', 'aria-label': '缩放',
|
|
28
|
+
oninput: e => { if (crop) { crop.zoom = clamp(Number(e.target.value), MIN_ZOOM, MAX_ZOOM); draw(); } } });
|
|
29
|
+
const box = h('div', { class: 'crop-box', role: 'img', 'aria-label': '拖动调整头像位置',
|
|
30
|
+
onpointerdown: e => {
|
|
31
|
+
if (!crop) return;
|
|
32
|
+
box.setPointerCapture(e.pointerId);
|
|
33
|
+
drag = { id: e.pointerId, x: e.clientX, y: e.clientY, ox: crop.x, oy: crop.y, ratio: VIEW / (box.clientWidth || VIEW) };
|
|
34
|
+
box.className = 'crop-box dragging';
|
|
35
|
+
},
|
|
36
|
+
onpointermove: e => {
|
|
37
|
+
if (!drag || e.pointerId !== drag.id) return;
|
|
38
|
+
crop.x = drag.ox + (e.clientX - drag.x) * drag.ratio;
|
|
39
|
+
crop.y = drag.oy + (e.clientY - drag.y) * drag.ratio;
|
|
40
|
+
draw();
|
|
41
|
+
},
|
|
42
|
+
onpointerup: end, onpointercancel: end,
|
|
43
|
+
}, canvas, h('div', { class: 'crop-grid', 'aria-hidden': 'true' }));
|
|
44
|
+
function end() { drag = null; box.className = 'crop-box'; }
|
|
45
|
+
|
|
46
|
+
// 图按「铺满方框」缩放后再乘 zoom;平移限制在不露出空白的范围里。
|
|
47
|
+
function layout(size) {
|
|
48
|
+
const { img } = crop, scale = Math.max(size / img.naturalWidth, size / img.naturalHeight) * crop.zoom;
|
|
49
|
+
const width = img.naturalWidth * scale, height = img.naturalHeight * scale;
|
|
50
|
+
return { scale, width, height, x: (size - width) / 2 + crop.x * (size / VIEW), y: (size - height) / 2 + crop.y * (size / VIEW) };
|
|
51
|
+
}
|
|
52
|
+
function draw() {
|
|
53
|
+
const ctx = canvas.getContext('2d');
|
|
54
|
+
ctx.clearRect(0, 0, VIEW, VIEW);
|
|
55
|
+
if (crop) {
|
|
56
|
+
const { width, height } = layout(VIEW);
|
|
57
|
+
crop.x = clamp(crop.x, -(width - VIEW) / 2, (width - VIEW) / 2);
|
|
58
|
+
crop.y = clamp(crop.y, -(height - VIEW) / 2, (height - VIEW) / 2);
|
|
59
|
+
const at = layout(VIEW);
|
|
60
|
+
ctx.drawImage(crop.img, at.x, at.y, at.width, at.height);
|
|
61
|
+
zoomText.textContent = `${crop.zoom.toFixed(1)}×`;
|
|
62
|
+
}
|
|
63
|
+
onChange?.();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 换一张:先回收上一张的地址;读的途中又换了或清除了,就不再用这张。
|
|
67
|
+
async function load(file) {
|
|
68
|
+
clear();
|
|
69
|
+
const mine = ++loading, img = new Image();
|
|
70
|
+
url = URL.createObjectURL(file);
|
|
71
|
+
try {
|
|
72
|
+
await new Promise((resolve, reject) => { img.onload = resolve; img.onerror = () => reject(new Error('读不出这张图片,请换一张')); img.src = url; });
|
|
73
|
+
} catch (e) { if (mine === loading) clear(); throw e; }
|
|
74
|
+
if (mine !== loading) return false;
|
|
75
|
+
crop = { img, zoom: MIN_ZOOM, x: 0, y: 0 };
|
|
76
|
+
zoom.value = String(MIN_ZOOM);
|
|
77
|
+
draw();
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
function reset() {
|
|
81
|
+
if (!crop) return;
|
|
82
|
+
Object.assign(crop, { zoom: MIN_ZOOM, x: 0, y: 0 });
|
|
83
|
+
zoom.value = String(MIN_ZOOM);
|
|
84
|
+
draw();
|
|
85
|
+
}
|
|
86
|
+
function clear() {
|
|
87
|
+
loading++;
|
|
88
|
+
if (url) URL.revokeObjectURL(url);
|
|
89
|
+
url = null; crop = null; drag = null;
|
|
90
|
+
box.className = 'crop-box';
|
|
91
|
+
zoom.value = String(MIN_ZOOM); zoomText.textContent = '1.0×';
|
|
92
|
+
draw();
|
|
93
|
+
}
|
|
94
|
+
// 方框里看到的部分画到 512×512 上(先铺白底,JPEG 没有透明);画面在调用时就定下,之后再换图不影响这次导出。
|
|
95
|
+
function exportBlob() {
|
|
96
|
+
const out = document.createElement('canvas');
|
|
97
|
+
out.width = OUTPUT_SIZE; out.height = OUTPUT_SIZE;
|
|
98
|
+
const ctx = out.getContext('2d'), at = layout(OUTPUT_SIZE);
|
|
99
|
+
ctx.fillStyle = '#fff';
|
|
100
|
+
ctx.fillRect(0, 0, OUTPUT_SIZE, OUTPUT_SIZE);
|
|
101
|
+
ctx.drawImage(crop.img, at.x, at.y, at.width, at.height);
|
|
102
|
+
return encodeAvatar(out);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { box, canvas, zoom, zoomText, load, reset, clear, export: exportBlob, get ready() { return Boolean(crop); } };
|
|
106
|
+
}
|
package/view/dom.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// 好友页建节点的小工具:只用 DOM API(createElement / createElementNS / textContent),不拼 HTML。
|
|
2
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
3
|
+
|
|
4
|
+
const present = children => children.flat().filter(c => c !== null && c !== undefined && c !== false);
|
|
5
|
+
|
|
6
|
+
function build(node, attrs, children) {
|
|
7
|
+
for (const [key, value] of Object.entries(attrs ?? {})) {
|
|
8
|
+
if (value === undefined || value === null || value === false) continue;
|
|
9
|
+
if (key.startsWith('on')) node.addEventListener(key.slice(2), value); else node.setAttribute(key, value === true ? '' : value);
|
|
10
|
+
}
|
|
11
|
+
node.append(...present(children));
|
|
12
|
+
return node;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** replaceChildren,但跳过 null / undefined / false(原生的会把它们当文字插进去)。 */
|
|
16
|
+
export const fill = (node, ...children) => node.replaceChildren(...present(children));
|
|
17
|
+
export const h = (tag, attrs = {}, ...children) => build(document.createElement(tag), attrs, children);
|
|
18
|
+
export const svg = (tag, attrs = {}, ...children) => build(document.createElementNS(SVG_NS, tag), attrs, children);
|
|
19
|
+
|
|
20
|
+
/** 5×5 几何纹(identiconPattern 的格子)画成矢量 SVG,颜色随 currentColor。 */
|
|
21
|
+
export const identiconSvg = grid => svg('svg', { viewBox: '-1 -1 7 7', 'shape-rendering': 'crispEdges', 'aria-hidden': 'true' },
|
|
22
|
+
grid.flatMap((row, r) => row.map((on, c) => (on ? svg('rect', { x: c, y: r, width: 1, height: 1, fill: 'currentColor' }) : null))));
|
package/view/style.css
CHANGED
|
@@ -1,63 +1,208 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* 好友页「活的极客名片 · Bento」:颜色只取 App 给的 --coda-* 变量(带回退),手机优先,>= 680px 宽屏。 */
|
|
2
2
|
:root {
|
|
3
|
+
color-scheme: light dark;
|
|
4
|
+
--fg: var(--coda-foreground, CanvasText);
|
|
5
|
+
--fg2: var(--coda-secondary, #6e6e73);
|
|
6
|
+
--fg3: var(--coda-tertiary, #8e8e93);
|
|
7
|
+
--bg: var(--coda-background, Canvas);
|
|
8
|
+
--card: var(--coda-card, color-mix(in srgb, var(--fg) 4%, var(--bg)));
|
|
9
|
+
--fill: var(--coda-fill, rgba(120, 120, 128, .12));
|
|
10
|
+
--line: var(--coda-separator, rgba(120, 120, 128, .24));
|
|
11
|
+
--accent: var(--coda-accent, #0a84ff);
|
|
12
|
+
--green: var(--coda-green, #34c759);
|
|
13
|
+
--orange: var(--coda-orange, #ff9500);
|
|
14
|
+
--red: var(--coda-red, #ff3b30);
|
|
15
|
+
--mono: var(--coda-mono, ui-monospace, Menlo, monospace);
|
|
3
16
|
font: var(--coda-font-size, 13px)/1.45 var(--coda-font, -apple-system, system-ui, sans-serif);
|
|
4
|
-
color: var(--
|
|
17
|
+
color: var(--fg); background: transparent;
|
|
5
18
|
}
|
|
6
19
|
* { box-sizing: border-box; }
|
|
20
|
+
[hidden] { display: none !important; }
|
|
7
21
|
html, body { margin: 0; }
|
|
8
22
|
button, input, select, textarea { font: inherit; color: inherit; }
|
|
9
23
|
button { cursor: pointer; }
|
|
10
24
|
button:disabled { opacity: .5; cursor: default; }
|
|
11
|
-
:focus-visible { outline: 2px solid var(--
|
|
25
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
|
|
12
26
|
.selectable { -webkit-user-select: text; user-select: text; }
|
|
13
|
-
.mono { font-family: var(--
|
|
14
|
-
.secondary { color: var(--
|
|
27
|
+
.mono { font-family: var(--mono); font-size: .92em; }
|
|
28
|
+
.secondary { color: var(--fg2); }
|
|
15
29
|
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
16
30
|
.spacer { flex: 1 1 auto; }
|
|
31
|
+
.center { text-align: center; }
|
|
17
32
|
|
|
18
|
-
.page { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; }
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.count { padding: 0 6px; border-radius: 8px; font-size: .85em; background: var(--coda-fill, rgba(120, 120, 128, .12)); color: var(--coda-secondary, #6e6e73); }
|
|
23
|
-
.card { padding: 12px; border-radius: var(--coda-radius-card, 12px); background: var(--coda-card, rgba(120, 120, 128, .08)); border: 1px solid var(--coda-separator, rgba(60, 60, 67, .18)); display: flex; flex-direction: column; gap: 10px; }
|
|
24
|
-
.hint { margin: 0; color: var(--coda-secondary, #6e6e73); font-size: .92em; }
|
|
25
|
-
.error { margin: 0; color: var(--coda-red, #ff3b30); overflow-wrap: anywhere; }
|
|
26
|
-
.ok { margin: 0; color: var(--coda-green, #34c759); }
|
|
27
|
-
.progress { margin: 0; color: var(--coda-secondary, #6e6e73); }
|
|
28
|
-
.empty { margin: 0; color: var(--coda-secondary, #6e6e73); }
|
|
29
|
-
|
|
33
|
+
.page { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
|
|
34
|
+
.hint, .progress, .empty { margin: 0; color: var(--fg2); font-size: .92em; }
|
|
35
|
+
.error { margin: 0; color: var(--red); overflow-wrap: anywhere; }
|
|
36
|
+
.ok { margin: 0; color: var(--green); overflow-wrap: anywhere; }
|
|
30
37
|
.line { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
.line.nowrap { flex-wrap: nowrap; }
|
|
39
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
40
|
+
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
41
|
+
.actions.split { padding-top: 12px; border-top: 1px solid var(--line); }
|
|
42
|
+
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
|
|
43
|
+
.lbl { display: block; color: var(--fg2); font-size: .88em; font-weight: 600; }
|
|
44
|
+
.fields { display: flex; flex-wrap: wrap; gap: 10px; }
|
|
45
|
+
.fields > .field { flex: 1 1 140px; }
|
|
46
|
+
input, textarea { width: 100%; min-width: 0; padding: 8px 10px; border-radius: var(--coda-radius, 9px); border: 1px solid var(--line); background: var(--bg); outline: none; }
|
|
47
|
+
input:focus, textarea:focus { border-color: var(--accent); }
|
|
34
48
|
textarea { min-height: 84px; resize: vertical; }
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.machines { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
38
|
-
.btn.quiet[aria-pressed="true"] { background: var(--coda-accent, #0a84ff); color: #fff; }
|
|
39
|
-
.btn.danger { background: color-mix(in srgb, var(--coda-red, #ff3b30) 14%, transparent); color: var(--coda-red, #ff3b30); }
|
|
40
|
-
.btn.small { padding: 3px 10px; font-weight: 500; font-size: .92em; }
|
|
41
|
-
details > summary { cursor: pointer; color: var(--coda-secondary, #6e6e73); }
|
|
49
|
+
input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--fg); }
|
|
50
|
+
details > summary { cursor: pointer; color: var(--fg2); }
|
|
42
51
|
details[open] > summary { margin-bottom: 10px; }
|
|
43
|
-
.fields { display: flex; flex-wrap: wrap; gap: 10px; }
|
|
44
52
|
|
|
45
|
-
.
|
|
46
|
-
.
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
.
|
|
63
|
-
.
|
|
53
|
+
.btn { padding: 7px 14px; border-radius: var(--coda-radius, 9px); border: 0; font-weight: 600; background: var(--accent); color: #fff; white-space: nowrap; }
|
|
54
|
+
.btn.quiet { background: var(--fill); color: var(--fg); }
|
|
55
|
+
.btn.danger { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
|
|
56
|
+
.btn.small { padding: 4px 11px; font-weight: 550; font-size: .92em; }
|
|
57
|
+
|
|
58
|
+
/* 主题色:每个色类给出 --c,再派生柔和底色与前景色,浅/深色都跟着背景走。 */
|
|
59
|
+
.c-blue { --c: var(--coda-blue, #0a84ff); } .c-orange { --c: var(--coda-orange, #ff9500); } .c-green { --c: var(--coda-green, #34c759); }
|
|
60
|
+
.c-purple { --c: var(--coda-purple, #af52de); } .c-pink { --c: var(--coda-pink, #ff2d55); } .c-teal { --c: var(--coda-teal, #30b0c7); }
|
|
61
|
+
.c-gray { --c: var(--coda-gray, #8e8e93); }
|
|
62
|
+
.c-blue, .c-orange, .c-green, .c-purple, .c-pink, .c-teal, .c-gray {
|
|
63
|
+
--c-soft: color-mix(in srgb, var(--c) 16%, var(--bg));
|
|
64
|
+
--c-ink: color-mix(in srgb, var(--c) 78%, var(--fg));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* 多机切换条 */
|
|
68
|
+
.machines { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
69
|
+
.m-pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border: 0; border-radius: 8px; background: var(--fill); color: var(--fg2); font-size: .92em; font-weight: 550; }
|
|
70
|
+
.m-pill[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
|
|
71
|
+
.m-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
|
|
72
|
+
.m-dot.off { background: var(--fg3); }
|
|
73
|
+
.m-why { font-size: .85em; color: var(--fg3); }
|
|
74
|
+
|
|
75
|
+
/* 点阵柔光渐变 Banner */
|
|
76
|
+
.banner { position: relative; height: 84px;
|
|
77
|
+
background:
|
|
78
|
+
radial-gradient(circle at 88% -10%, color-mix(in srgb, var(--c) 34%, transparent), transparent 55%),
|
|
79
|
+
linear-gradient(125deg, color-mix(in srgb, var(--c) 12%, var(--bg)) 0%, color-mix(in srgb, var(--c) 30%, var(--bg)) 55%, color-mix(in srgb, var(--c) 52%, var(--bg)) 100%); }
|
|
80
|
+
.banner::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
|
|
81
|
+
background-image: radial-gradient(color-mix(in srgb, var(--bg) 70%, transparent) 1px, transparent 1.5px); background-size: 14px 14px; }
|
|
82
|
+
.banner.small { height: 60px; }
|
|
83
|
+
.banner-acts { position: absolute; top: 12px; right: 12px; z-index: 1; display: flex; gap: 6px; }
|
|
84
|
+
.pill { height: 28px; padding: 0 12px; border: 0; border-radius: 999px; font-size: .92em; font-weight: 600; color: var(--fg);
|
|
85
|
+
background: color-mix(in srgb, var(--bg) 86%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }
|
|
86
|
+
.pill.strong { background: var(--fg); color: var(--bg); }
|
|
87
|
+
|
|
88
|
+
/* 跨界方圆头像 */
|
|
89
|
+
.av { display: grid; place-items: center; overflow: hidden; flex: none; background: var(--c-soft, var(--fill)); color: var(--c-ink, var(--fg)); font-weight: 700; line-height: 1; }
|
|
90
|
+
.av img, .av svg, .av canvas { width: 100%; height: 100%; display: block; object-fit: cover; }
|
|
91
|
+
.av.k-identicon svg { padding: 6%; }
|
|
92
|
+
.av.lg { width: 100%; height: 100%; border-radius: 17px; font-size: 30px; }
|
|
93
|
+
.av.lg.k-emoji { font-size: 36px; }
|
|
94
|
+
.av.md { width: 100%; height: 100%; border-radius: 14px; font-size: 24px; }
|
|
95
|
+
.av.sm { width: 44px; height: 44px; border-radius: 13px; font-size: 18px; }
|
|
96
|
+
.av.sm.k-emoji { font-size: 22px; }
|
|
97
|
+
.av-ring { position: relative; flex: none; display: block; width: 78px; height: 78px; padding: 3.5px; border: 0; border-radius: 22px; background: var(--bg); box-shadow: 0 4px 14px rgba(0, 0, 0, .14); }
|
|
98
|
+
.av-ring.md { width: 62px; height: 62px; padding: 3px; border-radius: 18px; }
|
|
99
|
+
.av-ring.lg { width: 70px; height: 70px; }
|
|
100
|
+
button.av-ring { transition: transform .14s ease; }
|
|
101
|
+
button.av-ring:active:not(:disabled) { transform: scale(.96); }
|
|
102
|
+
.cam { position: absolute; right: -4px; bottom: -4px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--fg); color: var(--bg); border: 2.5px solid var(--bg); }
|
|
103
|
+
|
|
104
|
+
/* Hero 名片卡 */
|
|
105
|
+
.hero { border-radius: 22px; border: 1px solid var(--line); background: var(--bg); overflow: hidden; box-shadow: 0 8px 24px rgba(0, 0, 0, .06); }
|
|
106
|
+
.hero-body { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
107
|
+
.hero-id { display: flex; align-items: flex-start; gap: 14px; min-width: 0; }
|
|
108
|
+
.hero-id > .av-ring { margin-top: -46px; position: relative; z-index: 1; }
|
|
109
|
+
.hero-names { min-width: 0; padding-bottom: 2px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
|
|
110
|
+
.name-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
|
|
111
|
+
.hero-name { margin: 0; font-size: 1.6em; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
|
|
112
|
+
.tag { padding: 2px 7px; border-radius: 6px; background: var(--c-soft); color: var(--c-ink); font-size: .82em; font-weight: 600; white-space: nowrap; }
|
|
113
|
+
.fp { padding: 3px 8px; border: 0; border-radius: 8px; background: var(--fill); color: var(--fg2); font-size: .85em; }
|
|
114
|
+
|
|
115
|
+
/* Bento 状态条 */
|
|
116
|
+
.bento { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
|
117
|
+
.tile { min-width: 0; padding: 9px 11px; border-radius: 13px; border: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; gap: 2px; }
|
|
118
|
+
.tile-k { font-size: .78em; font-weight: 600; letter-spacing: .04em; color: var(--fg3); }
|
|
119
|
+
.tile-v { display: flex; align-items: center; gap: 6px; font-weight: 650; min-width: 0; }
|
|
120
|
+
.tile-s { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font-size: .88em; color: var(--fg2); min-width: 0; }
|
|
121
|
+
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
|
|
122
|
+
.ok-dot { background: var(--green); } .warn-dot { background: var(--orange); } .off-dot { background: var(--fg3); }
|
|
123
|
+
|
|
124
|
+
/* 好友列表 */
|
|
125
|
+
.sec { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 1em; font-weight: 650; color: var(--fg2); }
|
|
126
|
+
.count { padding: 0 7px; border-radius: 999px; font-size: .85em; background: var(--fill); font-variant-numeric: tabular-nums; }
|
|
127
|
+
.friends { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
|
|
128
|
+
.f-tile { position: relative; width: 100%; display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); text-align: left; overflow: hidden; }
|
|
129
|
+
.f-tile::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--c); opacity: .7; }
|
|
130
|
+
.f-tile:active { transform: scale(.99); }
|
|
131
|
+
.f-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
132
|
+
.f-name { font-weight: 650; font-size: 1.05em; }
|
|
133
|
+
.f-meta { font-family: var(--mono); font-size: .85em; color: var(--fg3); }
|
|
134
|
+
.badge { flex: none; padding: 1px 7px; border-radius: 6px; font-size: .85em; font-weight: 550; white-space: nowrap; background: var(--fill); color: var(--fg2); }
|
|
135
|
+
.badge.bound { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
|
|
136
|
+
.badge.pending { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
|
|
137
|
+
.badge.conflict { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
|
|
138
|
+
.empty { padding: 22px 16px; text-align: center; border: 1px dashed var(--line); border-radius: 14px; }
|
|
139
|
+
|
|
140
|
+
/* 弹层:窄屏底部抽屉,宽屏居中模态;只罩住页面可见的部分(document 框架给出 visible-top / visible-height)。 */
|
|
141
|
+
.scrim { position: absolute; left: 0; right: 0; top: var(--coda-visible-top, 0); height: var(--coda-visible-height, 100%); z-index: 20;
|
|
142
|
+
display: flex; align-items: flex-end; justify-content: center; background: color-mix(in srgb, #000 34%, transparent); }
|
|
143
|
+
.dialog { width: 100%; max-height: calc(100% - 24px); display: flex; flex-direction: column; overflow: hidden;
|
|
144
|
+
background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 40px rgba(0, 0, 0, .22); }
|
|
145
|
+
.grabber { flex: none; width: 36px; height: 5px; margin: 7px auto 0; border-radius: 3px; background: color-mix(in srgb, var(--fg) 22%, transparent); }
|
|
146
|
+
.dlg-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 16px 10px; border-bottom: 1px solid var(--line); }
|
|
147
|
+
.dlg-head h3 { margin: 0; font-size: 1.12em; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
148
|
+
.dlg-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; }
|
|
149
|
+
.dlg-body:last-child { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
|
|
150
|
+
.dlg-foot { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
|
|
151
|
+
|
|
152
|
+
/* 迷你名片(编辑预览、好友详情) */
|
|
153
|
+
.mini-card { border-radius: 18px; border: 1px solid var(--line); background: var(--bg); overflow: hidden; }
|
|
154
|
+
.mini-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 6px; }
|
|
155
|
+
.mini-body > .av-ring { margin-top: -30px; z-index: 1; }
|
|
156
|
+
.mini-body.row { flex-direction: row; align-items: flex-end; gap: 12px; }
|
|
157
|
+
.mini-body.row > .av-ring { margin-top: -34px; }
|
|
158
|
+
.mini-names { flex: 1 1 auto; min-width: 0; padding-bottom: 2px; }
|
|
159
|
+
.mini-name { font-size: 1.25em; font-weight: 700; }
|
|
160
|
+
|
|
161
|
+
/* 编辑名片 */
|
|
162
|
+
.ed-cols { display: grid; gap: 16px; }
|
|
163
|
+
.ed-controls { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
|
164
|
+
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill); }
|
|
165
|
+
.seg button { height: 28px; border: 0; border-radius: 7px; background: none; color: var(--fg2); font-size: .92em; font-weight: 550; }
|
|
166
|
+
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
|
|
167
|
+
.pane { display: flex; flex-direction: column; gap: 8px; }
|
|
168
|
+
.crop-box { position: relative; width: min(240px, 100%); aspect-ratio: 1; margin: 0 auto; border-radius: 18px; overflow: hidden; cursor: grab; touch-action: none;
|
|
169
|
+
-webkit-user-select: none; user-select: none; background: color-mix(in srgb, var(--fg) 88%, var(--bg)); box-shadow: 0 6px 20px rgba(0, 0, 0, .16); }
|
|
170
|
+
.crop-box.dragging { cursor: grabbing; }
|
|
171
|
+
.crop-canvas { display: block; width: 100%; height: 100%; }
|
|
172
|
+
.crop-grid { position: absolute; inset: 0; pointer-events: none; border-radius: 18px; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85); opacity: .75;
|
|
173
|
+
background:
|
|
174
|
+
linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255, 255, 255, .35) 0 calc(33.33% + .5px), transparent 0 calc(66.66% - .5px), rgba(255, 255, 255, .35) 0 calc(66.66% + .5px), transparent 0),
|
|
175
|
+
linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255, 255, 255, .35) 0 calc(33.33% + .5px), transparent 0 calc(66.66% - .5px), rgba(255, 255, 255, .35) 0 calc(66.66% + .5px), transparent 0);
|
|
176
|
+
transition: opacity .15s; }
|
|
177
|
+
.crop-box:not(.dragging) .crop-grid { background: none; }
|
|
178
|
+
.zoom-row { display: flex; align-items: center; gap: 8px; font-size: .9em; }
|
|
179
|
+
.zoom-row input { flex: 1 1 auto; }
|
|
180
|
+
.zoom-value { min-width: 3.2em; text-align: right; color: var(--fg2); }
|
|
181
|
+
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
|
|
182
|
+
.emoji-opt { aspect-ratio: 1; display: grid; place-items: center; border-radius: 10px; border: 2px solid transparent; background: var(--card); font-size: 1.4em; padding: 0; }
|
|
183
|
+
.emoji-opt[aria-pressed="true"] { border-color: var(--fg); }
|
|
184
|
+
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; max-width: 280px; }
|
|
185
|
+
.swatch { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; padding: 0; background: var(--c); box-shadow: inset 0 0 0 2px var(--bg); }
|
|
186
|
+
.swatch[aria-pressed="true"] { border-color: var(--fg); }
|
|
187
|
+
|
|
188
|
+
/* 好友详情 */
|
|
189
|
+
.facts { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: baseline; }
|
|
190
|
+
.facts dt { color: var(--fg2); font-size: .92em; }
|
|
191
|
+
.facts dd { margin: 0; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
|
192
|
+
.key-full { overflow-wrap: anywhere; word-break: break-all; }
|
|
193
|
+
.warn-box { margin: 0 0 8px; padding: 9px 11px; border-radius: 11px; background: color-mix(in srgb, var(--red) 11%, transparent); color: var(--red); font-size: .92em; }
|
|
194
|
+
|
|
195
|
+
@media (min-width: 680px) {
|
|
196
|
+
.page { padding: 18px 24px 28px; gap: 20px; }
|
|
197
|
+
.hero-body { padding: 14px 20px 18px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px); align-items: end; column-gap: 18px; }
|
|
198
|
+
.hero-body > .hint, .hero-body > .ok, .hero-body > .error, .hero-body > .progress { grid-column: 1 / -1; }
|
|
199
|
+
.hero-body > .bento { grid-row: 1; grid-column: 2; }
|
|
200
|
+
.hero-id { align-self: start; }
|
|
201
|
+
.friends { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
|
202
|
+
.scrim { align-items: center; padding: 20px; }
|
|
203
|
+
.dialog { max-width: 560px; max-height: calc(100% - 40px); border-radius: 14px; box-shadow: 0 22px 60px rgba(0, 0, 0, .26); }
|
|
204
|
+
.grabber { display: none; }
|
|
205
|
+
.dlg-head { padding-top: 12px; }
|
|
206
|
+
.dlg-body:last-child, .dlg-foot { padding-bottom: 12px; }
|
|
207
|
+
.ed-cols { grid-template-columns: 220px minmax(0, 1fr); align-items: start; }
|
|
208
|
+
}
|