@coda-console/friends 0.3.1 → 0.5.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 +14 -3
- package/lib/avatar.mjs +86 -0
- package/lib/friends.mjs +13 -0
- package/lib/outbox.mjs +1 -12
- package/lib/view-members.mjs +50 -0
- package/package.json +1 -1
- package/view/app.mjs +463 -243
- package/view/cropper.mjs +106 -0
- package/view/dom.mjs +22 -0
- package/view/style.css +187 -47
- package/lib/view-machine.mjs +0 -42
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,203 @@
|
|
|
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
|
+
.page > section:not(.hero) > * + * { margin-top: 10px; }
|
|
69
|
+
|
|
70
|
+
/* 点阵柔光渐变 Banner */
|
|
71
|
+
.banner { position: relative; height: 84px;
|
|
72
|
+
background:
|
|
73
|
+
radial-gradient(circle at 88% -10%, color-mix(in srgb, var(--c) 34%, transparent), transparent 55%),
|
|
74
|
+
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%); }
|
|
75
|
+
.banner::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
|
|
76
|
+
background-image: radial-gradient(color-mix(in srgb, var(--bg) 70%, transparent) 1px, transparent 1.5px); background-size: 14px 14px; }
|
|
77
|
+
.banner.small { height: 60px; }
|
|
78
|
+
.banner-acts { position: absolute; top: 12px; right: 12px; z-index: 1; display: flex; gap: 6px; }
|
|
79
|
+
.pill { height: 28px; padding: 0 12px; border: 0; border-radius: 999px; font-size: .92em; font-weight: 600; color: var(--fg);
|
|
80
|
+
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); }
|
|
81
|
+
.pill.strong { background: var(--fg); color: var(--bg); }
|
|
82
|
+
|
|
83
|
+
/* 跨界方圆头像 */
|
|
84
|
+
.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; }
|
|
85
|
+
.av img, .av svg, .av canvas { width: 100%; height: 100%; display: block; object-fit: cover; }
|
|
86
|
+
.av.k-identicon svg { padding: 6%; }
|
|
87
|
+
.av.lg { width: 100%; height: 100%; border-radius: 17px; font-size: 30px; }
|
|
88
|
+
.av.lg.k-emoji { font-size: 36px; }
|
|
89
|
+
.av.md { width: 100%; height: 100%; border-radius: 14px; font-size: 24px; }
|
|
90
|
+
.av.sm { width: 44px; height: 44px; border-radius: 13px; font-size: 18px; }
|
|
91
|
+
.av.sm.k-emoji { font-size: 22px; }
|
|
92
|
+
.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); }
|
|
93
|
+
.av-ring.md { width: 62px; height: 62px; padding: 3px; border-radius: 18px; }
|
|
94
|
+
.av-ring.lg { width: 70px; height: 70px; }
|
|
95
|
+
button.av-ring { transition: transform .14s ease; }
|
|
96
|
+
button.av-ring:active:not(:disabled) { transform: scale(.96); }
|
|
97
|
+
.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); }
|
|
98
|
+
|
|
99
|
+
/* Hero 名片卡 */
|
|
100
|
+
.hero { border-radius: 22px; border: 1px solid var(--line); background: var(--bg); overflow: hidden; box-shadow: 0 8px 24px rgba(0, 0, 0, .06); }
|
|
101
|
+
.hero-body { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
102
|
+
.hero-id { display: flex; align-items: flex-start; gap: 14px; min-width: 0; }
|
|
103
|
+
.hero-id > .av-ring { margin-top: -46px; position: relative; z-index: 1; }
|
|
104
|
+
.hero-names { min-width: 0; padding-bottom: 2px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
|
|
105
|
+
.name-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
|
|
106
|
+
.hero-name { margin: 0; font-size: 1.6em; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
|
|
107
|
+
.tag { padding: 2px 7px; border-radius: 6px; background: var(--c-soft); color: var(--c-ink); font-size: .82em; font-weight: 600; white-space: nowrap; }
|
|
108
|
+
.fp { padding: 3px 8px; border: 0; border-radius: 8px; background: var(--fill); color: var(--fg2); font-size: .85em; }
|
|
109
|
+
|
|
110
|
+
/* Bento 状态条 */
|
|
111
|
+
.bento { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
|
112
|
+
.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; }
|
|
113
|
+
.tile-k { font-size: .78em; font-weight: 600; letter-spacing: .04em; color: var(--fg3); }
|
|
114
|
+
.tile-v { display: flex; align-items: center; gap: 6px; font-weight: 650; min-width: 0; }
|
|
115
|
+
.tile-s { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font-size: .88em; color: var(--fg2); min-width: 0; }
|
|
116
|
+
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
|
|
117
|
+
.ok-dot { background: var(--green); } .warn-dot { background: var(--orange); } .off-dot { background: var(--fg3); }
|
|
118
|
+
|
|
119
|
+
/* 好友列表 */
|
|
120
|
+
.sec { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 1em; font-weight: 650; color: var(--fg2); }
|
|
121
|
+
.count { padding: 0 7px; border-radius: 999px; font-size: .85em; background: var(--fill); font-variant-numeric: tabular-nums; }
|
|
122
|
+
.friends { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
|
|
123
|
+
.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; }
|
|
124
|
+
.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; }
|
|
125
|
+
.f-tile:active { transform: scale(.99); }
|
|
126
|
+
.f-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
127
|
+
.f-name { font-weight: 650; font-size: 1.05em; }
|
|
128
|
+
.f-meta { font-family: var(--mono); font-size: .85em; color: var(--fg3); }
|
|
129
|
+
.badge { flex: none; padding: 1px 7px; border-radius: 6px; font-size: .85em; font-weight: 550; white-space: nowrap; background: var(--fill); color: var(--fg2); }
|
|
130
|
+
.badge.bound { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
|
|
131
|
+
.badge.pending { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
|
|
132
|
+
.badge.conflict { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
|
|
133
|
+
.empty { padding: 22px 16px; text-align: center; border: 1px dashed var(--line); border-radius: 14px; }
|
|
134
|
+
|
|
135
|
+
/* 弹层:窄屏底部抽屉,宽屏居中模态;只罩住页面可见的部分(document 框架给出 visible-top / visible-height)。 */
|
|
136
|
+
.scrim { position: absolute; left: 0; right: 0; top: var(--coda-visible-top, 0); height: var(--coda-visible-height, 100%); z-index: 20;
|
|
137
|
+
display: flex; align-items: flex-end; justify-content: center; background: color-mix(in srgb, #000 34%, transparent); }
|
|
138
|
+
.dialog { width: 100%; max-height: calc(100% - 24px); display: flex; flex-direction: column; overflow: hidden;
|
|
139
|
+
background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 40px rgba(0, 0, 0, .22); }
|
|
140
|
+
.grabber { flex: none; width: 36px; height: 5px; margin: 7px auto 0; border-radius: 3px; background: color-mix(in srgb, var(--fg) 22%, transparent); }
|
|
141
|
+
.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); }
|
|
142
|
+
.dlg-head h3 { margin: 0; font-size: 1.12em; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
143
|
+
.dlg-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; }
|
|
144
|
+
.dlg-body:last-child { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
|
|
145
|
+
.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); }
|
|
146
|
+
|
|
147
|
+
/* 迷你名片(编辑预览、好友详情) */
|
|
148
|
+
.mini-card { border-radius: 18px; border: 1px solid var(--line); background: var(--bg); overflow: hidden; }
|
|
149
|
+
.mini-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 6px; }
|
|
150
|
+
.mini-body > .av-ring { margin-top: -30px; z-index: 1; }
|
|
151
|
+
.mini-body.row { flex-direction: row; align-items: flex-end; gap: 12px; }
|
|
152
|
+
.mini-body.row > .av-ring { margin-top: -34px; }
|
|
153
|
+
.mini-names { flex: 1 1 auto; min-width: 0; padding-bottom: 2px; }
|
|
154
|
+
.mini-name { font-size: 1.25em; font-weight: 700; }
|
|
155
|
+
|
|
156
|
+
/* 编辑名片 */
|
|
157
|
+
.ed-cols { display: grid; gap: 16px; }
|
|
158
|
+
.ed-controls { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
|
|
159
|
+
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill); }
|
|
160
|
+
.seg button { height: 28px; border: 0; border-radius: 7px; background: none; color: var(--fg2); font-size: .92em; font-weight: 550; }
|
|
161
|
+
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
|
|
162
|
+
.pane { display: flex; flex-direction: column; gap: 8px; }
|
|
163
|
+
.crop-box { position: relative; width: min(240px, 100%); aspect-ratio: 1; margin: 0 auto; border-radius: 18px; overflow: hidden; cursor: grab; touch-action: none;
|
|
164
|
+
-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); }
|
|
165
|
+
.crop-box.dragging { cursor: grabbing; }
|
|
166
|
+
.crop-canvas { display: block; width: 100%; height: 100%; }
|
|
167
|
+
.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;
|
|
168
|
+
background:
|
|
169
|
+
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),
|
|
170
|
+
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);
|
|
171
|
+
transition: opacity .15s; }
|
|
172
|
+
.crop-box:not(.dragging) .crop-grid { background: none; }
|
|
173
|
+
.zoom-row { display: flex; align-items: center; gap: 8px; font-size: .9em; }
|
|
174
|
+
.zoom-row input { flex: 1 1 auto; }
|
|
175
|
+
.zoom-value { min-width: 3.2em; text-align: right; color: var(--fg2); }
|
|
176
|
+
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
|
|
177
|
+
.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; }
|
|
178
|
+
.emoji-opt[aria-pressed="true"] { border-color: var(--fg); }
|
|
179
|
+
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; max-width: 280px; }
|
|
180
|
+
.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); }
|
|
181
|
+
.swatch[aria-pressed="true"] { border-color: var(--fg); }
|
|
182
|
+
|
|
183
|
+
/* 好友详情 */
|
|
184
|
+
.facts { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: baseline; }
|
|
185
|
+
.facts dt { color: var(--fg2); font-size: .92em; }
|
|
186
|
+
.facts dd { margin: 0; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
|
187
|
+
.key-full { overflow-wrap: anywhere; word-break: break-all; }
|
|
188
|
+
.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; }
|
|
189
|
+
|
|
190
|
+
@media (min-width: 680px) {
|
|
191
|
+
.page { padding: 18px 24px 28px; gap: 20px; }
|
|
192
|
+
.hero-body { padding: 14px 20px 18px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 320px); align-items: end; column-gap: 18px; }
|
|
193
|
+
.hero-body > .hint, .hero-body > .ok, .hero-body > .error, .hero-body > .progress { grid-column: 1 / -1; }
|
|
194
|
+
.hero-body > .bento { grid-row: 1; grid-column: 2; }
|
|
195
|
+
.hero-id { align-self: start; }
|
|
196
|
+
.friends { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
|
197
|
+
.scrim { align-items: center; padding: 20px; }
|
|
198
|
+
.dialog { max-width: 560px; max-height: calc(100% - 40px); border-radius: 14px; box-shadow: 0 22px 60px rgba(0, 0, 0, .26); }
|
|
199
|
+
.grabber { display: none; }
|
|
200
|
+
.dlg-head { padding-top: 12px; }
|
|
201
|
+
.dlg-body:last-child, .dlg-foot { padding-bottom: 12px; }
|
|
202
|
+
.ed-cols { grid-template-columns: 220px minmax(0, 1fr); align-items: start; }
|
|
203
|
+
}
|
package/lib/view-machine.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// 页面选机器与发消息的纯逻辑:多台机器都提供这页时,页面须指明消息发往哪台。不碰 Coda 的 Node API;页面和单测都加载它。
|
|
2
|
-
|
|
3
|
-
export function reachableMachines(coda) {
|
|
4
|
-
const list = Array.isArray(coda?.machines) ? coda.machines : [coda?.machine];
|
|
5
|
-
const seen = new Set();
|
|
6
|
-
return list.filter(m => {
|
|
7
|
-
if (typeof m?.id !== 'string' || !m.id || m.unreachable || seen.has(m.id)) return false;
|
|
8
|
-
seen.add(m.id);
|
|
9
|
-
return true;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function pickMachine(coda, savedId) {
|
|
14
|
-
const ids = reachableMachines(coda).map(m => m.id);
|
|
15
|
-
if (typeof savedId === 'string' && ids.includes(savedId)) return savedId;
|
|
16
|
-
const own = coda?.machine?.id;
|
|
17
|
-
if (ids.includes(own)) return own;
|
|
18
|
-
return ids[0] ?? own ?? null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 入队瞬间固定目标机器与代际(getEpoch,调用方每次选机自增);轮到它发送时选择已变,就整条丢弃,不发往新机器、也不报错。
|
|
22
|
-
// 发送失败交给 onError(error, msg, machine, epoch),不吞;只收当前目标机器的回包。send 返回的 Promise 以「是否发出」收尾。
|
|
23
|
-
export function createMachineBridge({ coda, getMachine, getEpoch, onMessage, onError, targetWindow = globalThis }) {
|
|
24
|
-
let chain = Promise.resolve();
|
|
25
|
-
const send = msg => {
|
|
26
|
-
const machine = getMachine(), epoch = getEpoch?.();
|
|
27
|
-
chain = chain.then(async () => {
|
|
28
|
-
if (getMachine() !== machine || getEpoch?.() !== epoch) return false;
|
|
29
|
-
try { await coda.postMessage(msg, machine ? { machine } : undefined); return true; } catch (error) { onError(error, msg, machine, epoch); return false; }
|
|
30
|
-
});
|
|
31
|
-
return chain;
|
|
32
|
-
};
|
|
33
|
-
const listener = event => {
|
|
34
|
-
const d = event.data;
|
|
35
|
-
if (!(d && typeof d === 'object' && typeof d.type === 'string')) return;
|
|
36
|
-
const current = getMachine();
|
|
37
|
-
if (event.machine?.id && current && event.machine.id !== current) return;
|
|
38
|
-
onMessage(d, event);
|
|
39
|
-
};
|
|
40
|
-
targetWindow.addEventListener('message', listener);
|
|
41
|
-
return { send, dispose: () => targetWindow.removeEventListener('message', listener) };
|
|
42
|
-
}
|