@coda-console/resource-manager 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +69 -2
- package/lib/content.mjs +36 -0
- package/lib/paths.mjs +47 -0
- package/lib/root.mjs +26 -0
- package/lib/tree.mjs +74 -0
- package/main.mjs +137 -0
- package/package.json +24 -4
- package/view/app.mjs +277 -0
- package/view/bar.mjs +26 -0
- package/view/connection.mjs +109 -0
- package/view/file-app.mjs +142 -0
- package/view/file.html +17 -0
- package/view/icons.mjs +56 -0
- package/view/index.html +20 -0
- package/view/model.mjs +222 -0
- package/view/notice.mjs +26 -0
- package/view/preview.mjs +162 -0
- package/view/protocol.mjs +49 -0
- package/view/style.css +139 -0
- package/view/tree.mjs +169 -0
package/view/model.mjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// 页面的纯状态:目录树、状态保留。不碰 DOM,请求与代次在 connection.mjs,设计见 docs/design/phase-1.md 第 6、7 节。
|
|
2
|
+
import { ErrorCode, RootState, Type } from './protocol.mjs';
|
|
3
|
+
|
|
4
|
+
export const STATE_LIMIT = 96 * 1024;
|
|
5
|
+
export const MAX_PARALLEL = 8;
|
|
6
|
+
export const MAX_LOADED = 100_000; // 读回保存的条数时认的上界(view 侧校验用),与服务端的条目上限各自独立
|
|
7
|
+
// 恢复时每个目录最多取够这么多条(约 10 页):#reload 串行取够才显示,条数太大返回后会等很久。
|
|
8
|
+
// 只管「按保存的条数恢复」,用户已经翻出来的条数不受限;也和 lib/tree.mjs 的目录上限无关。
|
|
9
|
+
export const RESTORE_LIMIT = 20_000;
|
|
10
|
+
const MAX_LOADED_DIRS = 500;
|
|
11
|
+
const HIDDEN = new Set(['.git', '.DS_Store']);
|
|
12
|
+
export const isHidden = name => HIDDEN.has(name);
|
|
13
|
+
export const joinPath = (dir, name) => (dir ? `${dir}/${name}` : name);
|
|
14
|
+
const inside = (path, dir) => path === dir || path.startsWith(`${dir}/`);
|
|
15
|
+
|
|
16
|
+
async function pool(items, limit, fn) {
|
|
17
|
+
let index = 0;
|
|
18
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
19
|
+
while (index < items.length) await fn(items[index++]);
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 根目录不可用时,树页和文件页显示的说明。root 为 null 表示还没收到。
|
|
24
|
+
export function noticeText(root, session) {
|
|
25
|
+
if (!root) return '正在读取…';
|
|
26
|
+
if (!session) return '没有打开的会话。';
|
|
27
|
+
return {
|
|
28
|
+
[RootState.NONE]: '这个会话没有可浏览的工作目录。',
|
|
29
|
+
[RootState.PREPARING]: '工作树还在准备,好了会自动显示。',
|
|
30
|
+
[RootState.GONE]: '工作目录已不存在,可能已随归档收回。再发消息会重建,之后自动恢复。',
|
|
31
|
+
}[root.state] ?? '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class Model {
|
|
35
|
+
session = null;
|
|
36
|
+
root = null; // 收到 root 之前是 null
|
|
37
|
+
dirs = new Map(); // path → { entries, next, loaded, loading, error, token }
|
|
38
|
+
expanded = new Set(); // 不变量:展开的目录,它的每一级上层也展开
|
|
39
|
+
wanted = new Map(); // 恢复状态时各目录要取够的条数,第一次取用后删掉
|
|
40
|
+
selected = null;
|
|
41
|
+
showHidden = false;
|
|
42
|
+
|
|
43
|
+
constructor({ link, onChange = () => {} }) { Object.assign(this, { link, onChange }); }
|
|
44
|
+
|
|
45
|
+
get ready() { return this.root?.state === RootState.READY; }
|
|
46
|
+
|
|
47
|
+
// 模块来的消息统一从这里进。session 带上这个会话保存的状态;返回值同各个处理方法。
|
|
48
|
+
receive(message, saved = null) {
|
|
49
|
+
switch (message.type) {
|
|
50
|
+
case Type.SESSION: return this.onSession(message, saved);
|
|
51
|
+
case Type.ROOT: return this.onRoot(message);
|
|
52
|
+
case Type.CHANGED: return this.onChanged(message);
|
|
53
|
+
case Type.LISTED: case Type.CHUNK: return this.link.receive(message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 换会话:清空一切,展开状态换成这个会话保存的。
|
|
58
|
+
onSession({ generation, session }, saved = null) {
|
|
59
|
+
this.link.reset(generation);
|
|
60
|
+
this.session = session ?? null;
|
|
61
|
+
this.root = null;
|
|
62
|
+
this.dirs = new Map();
|
|
63
|
+
this.wanted = new Map(Object.entries(saved?.loaded ?? {}).map(([path, count]) => [path, Math.min(count, RESTORE_LIMIT)]));
|
|
64
|
+
const paths = (saved?.expanded ?? []).filter(path => path !== '');
|
|
65
|
+
this.expanded = new Set(paths.filter(path => !path.includes('/') || paths.includes(path.slice(0, path.lastIndexOf('/')))));
|
|
66
|
+
this.selected = saved?.selected ?? null;
|
|
67
|
+
this.onChange();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 只换根目录状态,不动会话状态;ready 时重新取全部。
|
|
71
|
+
onRoot({ generation, state, path }) {
|
|
72
|
+
if (generation !== this.link.generation) return null;
|
|
73
|
+
this.root = { state, path };
|
|
74
|
+
this.onChange();
|
|
75
|
+
return state === RootState.READY ? this.refresh() : Promise.resolve();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onChanged({ generation }) {
|
|
79
|
+
return generation === this.link.generation && this.ready ? this.refresh() : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 重新取根和全部已展开的目录,并行不超过 8 个。
|
|
83
|
+
refresh() {
|
|
84
|
+
if (!this.ready) return Promise.resolve();
|
|
85
|
+
const { generation } = this.link;
|
|
86
|
+
return pool(['', ...this.expanded], MAX_PARALLEL, path => this.#reload(path, generation));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 取够已加载的条数,一次替换;同目录有更新的请求就作废这一个。
|
|
90
|
+
async #reload(path, generation) {
|
|
91
|
+
if (this.link.generation !== generation) return; // 排队时会话已换,旧任务不碰新会话
|
|
92
|
+
let dir = this.dirs.get(path);
|
|
93
|
+
if (!dir) this.dirs.set(path, dir = { entries: [], next: null, loaded: false, loading: false, error: null, token: 0, pages: 0 });
|
|
94
|
+
const token = ++dir.token, want = Math.max(dir.entries.length, this.wanted.get(path) ?? 0);
|
|
95
|
+
dir.loading = true;
|
|
96
|
+
this.onChange();
|
|
97
|
+
const current = () => this.link.generation === generation && this.dirs.get(path) === dir && dir.token === token;
|
|
98
|
+
try {
|
|
99
|
+
const entries = [];
|
|
100
|
+
let next = null, pages = 0;
|
|
101
|
+
do {
|
|
102
|
+
const reply = await this.link.call('list', { path, cursor: next });
|
|
103
|
+
if (this.link.generation !== generation) return; // 回答到了、继续前会话换了,不再取下一页
|
|
104
|
+
entries.push(...reply.entries);
|
|
105
|
+
next = reply.nextCursor ?? null;
|
|
106
|
+
pages++;
|
|
107
|
+
} while (next && entries.length < want);
|
|
108
|
+
if (!current()) return;
|
|
109
|
+
Object.assign(dir, { entries, next, loaded: true, error: null, pages });
|
|
110
|
+
this.wanted.delete(path); // 成功后才删:取页失败后重试还要取够保存的条数
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.stale || !current()) return;
|
|
113
|
+
if (error.code === ErrorCode.NOT_FOUND && path !== '') this.#drop(path);
|
|
114
|
+
else if (error.code !== ErrorCode.NO_ROOT) dir.error = { code: error.code, message: error.message };
|
|
115
|
+
} finally {
|
|
116
|
+
if (current()) dir.loading = false;
|
|
117
|
+
this.onChange();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#drop(path) {
|
|
122
|
+
for (const key of [...this.dirs.keys()]) if (inside(key, path)) this.dirs.delete(key);
|
|
123
|
+
for (const key of [...this.expanded]) if (inside(key, path)) this.expanded.delete(key);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
toggle(path) {
|
|
127
|
+
if (this.expanded.has(path)) {
|
|
128
|
+
for (const key of [...this.expanded]) if (inside(key, path)) this.expanded.delete(key);
|
|
129
|
+
for (const key of [...this.dirs.keys()]) if (key !== '' && inside(key, path)) this.dirs.delete(key);
|
|
130
|
+
this.onChange();
|
|
131
|
+
} else {
|
|
132
|
+
this.expanded.add(path);
|
|
133
|
+
this.retry(path);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
retry(path) { return this.ready ? this.#reload(path, this.link.generation) : Promise.resolve(); }
|
|
138
|
+
|
|
139
|
+
// 「再显示」:取下一页接在后面。
|
|
140
|
+
async loadMore(path) {
|
|
141
|
+
const dir = this.dirs.get(path), { generation } = this.link;
|
|
142
|
+
if (!dir?.next || dir.loading || !this.ready) return;
|
|
143
|
+
const token = ++dir.token;
|
|
144
|
+
dir.loading = true;
|
|
145
|
+
this.onChange();
|
|
146
|
+
const current = () => this.link.generation === generation && this.dirs.get(path) === dir && dir.token === token;
|
|
147
|
+
try {
|
|
148
|
+
const reply = await this.link.call('list', { path, cursor: dir.next });
|
|
149
|
+
if (!current()) return;
|
|
150
|
+
dir.entries = dir.entries.concat(reply.entries);
|
|
151
|
+
Object.assign(dir, { next: reply.nextCursor ?? null, error: null, pages: dir.pages + 1 });
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (!error.stale && current()) dir.error = { code: error.code, message: error.message };
|
|
154
|
+
} finally {
|
|
155
|
+
if (current()) dir.loading = false;
|
|
156
|
+
this.onChange();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
select(path) { this.selected = path; this.onChange(); }
|
|
161
|
+
setShowHidden(on) { this.showHidden = on; this.onChange(); }
|
|
162
|
+
// loaded:取过不止一页的目录已加载的条数,只存条数不存内容;第一页每次都会重新取,不用存。
|
|
163
|
+
snapshot() {
|
|
164
|
+
const loaded = {};
|
|
165
|
+
for (const [path, dir] of this.dirs) if (dir.pages > 1 && dir.entries.length > 0) loaded[path] = dir.entries.length;
|
|
166
|
+
return { expanded: [...this.expanded], selected: this.selected, loaded };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ---- 状态保留:setState 没有会话维度,内部按会话分开 ----
|
|
171
|
+
|
|
172
|
+
export const byteSize = value => new TextEncoder().encode(JSON.stringify(value)).length;
|
|
173
|
+
const depth = path => path.split('/').length;
|
|
174
|
+
const strings = (value, max) => (Array.isArray(value) ? value.filter(s => typeof s === 'string' && s.length <= 1024).slice(0, max) : []);
|
|
175
|
+
|
|
176
|
+
const parseLoaded = raw => Object.fromEntries(Object.entries(raw && typeof raw === 'object' ? raw : {})
|
|
177
|
+
.filter(([path, count]) => path.length <= 1024 && Number.isSafeInteger(count) && count > 0 && count <= MAX_LOADED).slice(0, MAX_LOADED_DIRS));
|
|
178
|
+
|
|
179
|
+
// 读回来的值可能是别的版本或坏的,只认自己的形状。
|
|
180
|
+
export function parseState(raw) {
|
|
181
|
+
const state = { v: 1, seq: 0, hidden: false, sessions: {} };
|
|
182
|
+
if (!raw || typeof raw !== 'object' || raw.v !== 1) return state;
|
|
183
|
+
state.hidden = raw.hidden === true;
|
|
184
|
+
state.seq = Number.isSafeInteger(raw.seq) ? raw.seq : 0;
|
|
185
|
+
for (const [id, item] of Object.entries(raw.sessions ?? {})) {
|
|
186
|
+
if (!item || typeof item !== 'object') continue;
|
|
187
|
+
const scroll = item.scroll ?? {}, num = n => (Number.isFinite(n) && n >= 0 ? n : 0);
|
|
188
|
+
state.sessions[id] = {
|
|
189
|
+
at: Number.isSafeInteger(item.at) ? item.at : 0, expanded: strings(item.expanded, 5000),
|
|
190
|
+
selected: typeof item.selected === 'string' && item.selected.length <= 1024 ? item.selected : null,
|
|
191
|
+
scroll: { tree: num(scroll.tree), top: num(scroll.top), left: num(scroll.left) },
|
|
192
|
+
};
|
|
193
|
+
const loaded = parseLoaded(item.loaded);
|
|
194
|
+
if (Object.keys(loaded).length > 0) state.sessions[id].loaded = loaded;
|
|
195
|
+
}
|
|
196
|
+
return state;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function putSession(state, session, record) {
|
|
200
|
+
state.seq++;
|
|
201
|
+
state.sessions[session] = { ...record, at: state.seq };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 总量不超过 limit(序列化后的 UTF-8 字节):先淘汰最旧的会话,再从深到浅裁当前会话的展开目录,最后兜底清空。不抛。
|
|
205
|
+
export function trimState(state, keep, limit = STATE_LIMIT) {
|
|
206
|
+
const next = { ...state, sessions: { ...state.sessions } };
|
|
207
|
+
const fits = () => byteSize(next) <= limit;
|
|
208
|
+
const others = Object.keys(next.sessions).filter(id => id !== keep).sort((a, b) => next.sessions[a].at - next.sessions[b].at);
|
|
209
|
+
for (const id of others) { if (fits()) return next; delete next.sessions[id]; }
|
|
210
|
+
let current = next.sessions[keep];
|
|
211
|
+
if (fits() || !current) return fits() ? next : { ...next, sessions: {} };
|
|
212
|
+
// 条数只影响返回后的滚动落点,比展开状态先舍。
|
|
213
|
+
current = next.sessions[keep] = { ...current, loaded: {} };
|
|
214
|
+
if (fits()) return next;
|
|
215
|
+
// 按层级从浅到深排,取最长的、放得下的前缀;前缀仍然满足「上层也展开」。
|
|
216
|
+
const sorted = [...current.expanded].sort((a, b) => depth(a) - depth(b));
|
|
217
|
+
let low = 0, high = sorted.length;
|
|
218
|
+
const withCount = count => { next.sessions[keep] = { ...current, expanded: sorted.slice(0, count) }; return fits(); };
|
|
219
|
+
while (low < high) { const mid = (low + high + 1) >> 1; if (withCount(mid)) low = mid; else high = mid - 1; }
|
|
220
|
+
if (withCount(low)) return next;
|
|
221
|
+
return { ...next, sessions: {} };
|
|
222
|
+
}
|
package/view/notice.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// 说明区:大号图标加一段文字,或「没连上 + 原因 + 重试」。树页和文件页共用。
|
|
2
|
+
// 重画会换掉正在聚焦的按钮:焦点留在说明区里(有重试按钮就落在它上面),不丢到页面外。
|
|
3
|
+
import { icon } from './icons.mjs';
|
|
4
|
+
|
|
5
|
+
const text = content => Object.assign(document.createElement('p'), { textContent: content });
|
|
6
|
+
|
|
7
|
+
export function showNotice(el, { text: message, failure, retry, glyph = 'folder' }) {
|
|
8
|
+
const focused = el.contains(document.activeElement);
|
|
9
|
+
let target = el;
|
|
10
|
+
const mark = document.createElement('span');
|
|
11
|
+
mark.className = 'notice-icon';
|
|
12
|
+
if (failure === undefined) {
|
|
13
|
+
mark.append(icon(glyph, 44));
|
|
14
|
+
el.replaceChildren(mark, text(message));
|
|
15
|
+
} else {
|
|
16
|
+
const button = document.createElement('button'), reason = text(failure);
|
|
17
|
+
mark.append(icon('warning', 44));
|
|
18
|
+
reason.className = 'secondary';
|
|
19
|
+
button.className = 'link';
|
|
20
|
+
button.textContent = '重试';
|
|
21
|
+
button.addEventListener('click', retry);
|
|
22
|
+
el.replaceChildren(mark, text('没有连上资源管理器的后台'), reason, button);
|
|
23
|
+
target = button;
|
|
24
|
+
}
|
|
25
|
+
if (focused) { el.tabIndex = -1; target.focus(); }
|
|
26
|
+
}
|
package/view/preview.mjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// 文件预览:只接收路径和读块的能力,不依赖树的状态。readFile 是纯逻辑;mountPreview 才碰 DOM。
|
|
2
|
+
import { icon, iconFor } from './icons.mjs';
|
|
3
|
+
import { ContentKind, EntryKind, ErrorCode, IMAGE_LIMIT, TEXT_LIMIT, imageType } from './protocol.mjs';
|
|
4
|
+
|
|
5
|
+
function fromBase64(data) {
|
|
6
|
+
const binary = atob(data), bytes = new Uint8Array(binary.length);
|
|
7
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
8
|
+
return bytes;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 一块一块读完一个文件。read(offset) 返回 chunk 回答。
|
|
12
|
+
// 文本把所有块拼成字节后再解码,多字节字符被块边界切开也没关系。
|
|
13
|
+
// 传入 prev(上次的 size、mtimeMs)时,没变就只返回 { same: true };读的途中文件变了就重读,最多三次。
|
|
14
|
+
export async function readFile(read, { prev = null, onProgress = () => {}, cancelled = () => false } = {}) {
|
|
15
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
16
|
+
let chunk = await read(0);
|
|
17
|
+
if (prev && chunk.size === prev.size && chunk.mtimeMs === prev.mtimeMs) return { same: true };
|
|
18
|
+
const { kind, size, mtimeMs } = chunk;
|
|
19
|
+
const total = kind === ContentKind.TEXT ? Math.min(size, TEXT_LIMIT) : kind === ContentKind.IMAGE && size <= IMAGE_LIMIT ? size : 0;
|
|
20
|
+
const parts = [];
|
|
21
|
+
let got = 0, moved = false;
|
|
22
|
+
for (;;) {
|
|
23
|
+
const bytes = fromBase64(chunk.data);
|
|
24
|
+
parts.push(bytes);
|
|
25
|
+
got += bytes.length;
|
|
26
|
+
onProgress(got, total);
|
|
27
|
+
if (chunk.eof || bytes.length === 0) break;
|
|
28
|
+
if (cancelled()) return { cancelled: true };
|
|
29
|
+
chunk = await read(got);
|
|
30
|
+
if (chunk.size !== size || chunk.mtimeMs !== mtimeMs) { moved = true; break; }
|
|
31
|
+
}
|
|
32
|
+
if (moved) continue;
|
|
33
|
+
const all = new Uint8Array(got);
|
|
34
|
+
let at = 0;
|
|
35
|
+
for (const part of parts) { all.set(part, at); at += part.length; }
|
|
36
|
+
const result = { same: false, kind, size, mtimeMs, bytes: all, truncated: kind === ContentKind.TEXT && size > TEXT_LIMIT };
|
|
37
|
+
if (kind === ContentKind.TEXT) {
|
|
38
|
+
result.text = new TextDecoder().decode(all);
|
|
39
|
+
if (result.truncated && result.text.endsWith('�')) result.text = result.text.slice(0, -1); // 1 MiB 处可能切在字符中间
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
const error = new Error('文件一直在变化,稍后再试');
|
|
44
|
+
throw Object.assign(error, { code: ErrorCode.IO });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function formatSize(bytes) {
|
|
48
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
49
|
+
const units = ['KiB', 'MiB', 'GiB'];
|
|
50
|
+
let value = bytes / 1024, unit = 0;
|
|
51
|
+
while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit++; }
|
|
52
|
+
return `${value.toFixed(value < 10 ? 1 : 0)} ${units[unit]}`;
|
|
53
|
+
}
|
|
54
|
+
const formatTime = ms => new Date(ms).toLocaleString('zh-CN', { hour12: false });
|
|
55
|
+
export const lineCount = text => (text === '' ? 1 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0));
|
|
56
|
+
|
|
57
|
+
const h = (tag, attributes = {}, ...children) => {
|
|
58
|
+
const node = document.createElement(tag);
|
|
59
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
60
|
+
if (key.startsWith('on')) node.addEventListener(key.slice(2), value); else if (value != null && value !== false) node.setAttribute(key, value);
|
|
61
|
+
}
|
|
62
|
+
node.append(...children.flat().filter(child => child != null));
|
|
63
|
+
return node;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// read(path, offset) → Promise<chunk 回答>,会话换了会以 stale 错误拒绝;copy(text) 复制路径。
|
|
67
|
+
// actions:头部在「复制路径」旁额外加的按钮 [{ label, icon, run(path) }],预览不知道它们做什么。
|
|
68
|
+
// copyInHead:false 时头部不放「复制路径」(iPhone 放在底部工具条),由页面调 copyPath()。
|
|
69
|
+
// back:给了就在头部最左边放「返回」(Mac 侧栏预览:原生工具栏项目只能在右侧);文件页和 iPhone 不传。
|
|
70
|
+
export function mountPreview(el, { read, copy, actions = [], copyInHead = true, back = null }) {
|
|
71
|
+
const name = h('div', { class: 'pname truncate' }), meta = h('div', { class: 'pmeta caption secondary truncate' }, ' ');
|
|
72
|
+
const fileIcon = h('span', { class: 'pico', 'aria-hidden': 'true' });
|
|
73
|
+
// 图标按钮:可访问名称和 Mac 的悬停提示都是 label;没有图标的退回文字。
|
|
74
|
+
const action = (label, glyph, run) => h('button', { class: glyph ? 'icon' : 'link', 'aria-label': label, title: label, onclick: run }, glyph ? icon(glyph, 18) : label);
|
|
75
|
+
const copyPath = () => path !== null && copy(path);
|
|
76
|
+
const retryButton = h('button', { class: 'link', onclick: () => load(null, true), hidden: true }, '重试');
|
|
77
|
+
const body = h('div', { class: 'pbody' });
|
|
78
|
+
const extra = actions.map(({ label, icon: glyph, run }) => action(label, glyph, () => path !== null && run(path)));
|
|
79
|
+
el.replaceChildren(h('div', { class: 'phead' }, ...(back ? [action('返回', 'back', back)] : []), fileIcon, h('div', { class: 'grow' }, name, meta), retryButton,
|
|
80
|
+
...(copyInHead ? [action('复制路径', 'copy', copyPath)] : []), ...extra), body);
|
|
81
|
+
|
|
82
|
+
let path = null, token = 0, shown = null, objectUrl = null; // shown:当前显示的 { size, mtimeMs }
|
|
83
|
+
let metaText = ' ', metaTitle = '', stale = null; // stale:后台刷新失败的原因,此时正文还是上次的
|
|
84
|
+
// 更新失败的提示占用元信息那一行,重试按钮在头部,所以正文不会被顶动。
|
|
85
|
+
const paintMeta = () => {
|
|
86
|
+
meta.textContent = stale ? `更新失败:${stale}` : metaText;
|
|
87
|
+
meta.title = stale ?? metaTitle;
|
|
88
|
+
meta.classList.toggle('warn', stale !== null);
|
|
89
|
+
retryButton.hidden = stale === null;
|
|
90
|
+
};
|
|
91
|
+
const setMeta = (text, title = '') => { metaText = text; metaTitle = title; stale = null; paintMeta(); };
|
|
92
|
+
const setStale = reason => { stale = reason; paintMeta(); };
|
|
93
|
+
const revoke = () => { if (objectUrl) URL.revokeObjectURL(objectUrl); objectUrl = null; };
|
|
94
|
+
const notice = (title, detail, action) => body.replaceChildren(h('div', { class: 'empty' },
|
|
95
|
+
h('p', {}, title), detail ? h('p', { class: 'secondary' }, detail) : null,
|
|
96
|
+
action ? h('button', { class: 'link', onclick: action.run }, action.label) : null));
|
|
97
|
+
|
|
98
|
+
function show(result) {
|
|
99
|
+
revoke();
|
|
100
|
+
shown = { size: result.size, mtimeMs: result.mtimeMs };
|
|
101
|
+
// 元信息:目录 · 行数 · 大小;根目录下的文件没有目录,非文本没有行数。修改时间放进 title。
|
|
102
|
+
const dir = path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '';
|
|
103
|
+
const lines = result.kind === ContentKind.TEXT ? `${lineCount(result.text)} 行` : '';
|
|
104
|
+
const note = result.truncated ? `只显示前 ${formatSize(TEXT_LIMIT)}` : '';
|
|
105
|
+
setMeta([dir, lines, formatSize(result.size), note].filter(Boolean).join(' · '), `修改于 ${formatTime(result.mtimeMs)}`);
|
|
106
|
+
if (result.kind === ContentKind.TEXT) {
|
|
107
|
+
const gutter = h('pre', { class: 'gutter', 'aria-hidden': 'true' }, Array.from({ length: lineCount(result.text) }, (_, i) => i + 1).join('\n'));
|
|
108
|
+
body.replaceChildren(h('div', { class: 'code' }, gutter, h('pre', { class: 'text selectable' }, result.text)));
|
|
109
|
+
} else if (result.kind === ContentKind.IMAGE && result.bytes.length > 0) {
|
|
110
|
+
objectUrl = URL.createObjectURL(new Blob([result.bytes], { type: imageType(path) }));
|
|
111
|
+
body.replaceChildren(h('div', { class: 'image' }, h('img', { src: objectUrl, alt: path, draggable: 'false' })));
|
|
112
|
+
} else {
|
|
113
|
+
const big = result.kind === ContentKind.IMAGE ? `图片超过 ${formatSize(IMAGE_LIMIT)},不预览。` : '二进制文件,不预览。';
|
|
114
|
+
notice(big, `${formatSize(result.size)},修改于 ${formatTime(result.mtimeMs)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function failure(error, silent, retry) {
|
|
119
|
+
if (error.stale) return;
|
|
120
|
+
if (error.code === ErrorCode.NOT_FOUND) { shown = null; setMeta(' '); return notice('文件已不存在', path); }
|
|
121
|
+
if (silent && shown) return setStale(error.message); // 后台刷新失败:保留正文,提示原因
|
|
122
|
+
notice('读不到这个文件', error.message, { label: '重试', run: retry });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// silent:刷新。没变化不重画;变了就换内容,并尽量留在原来的滚动位置。
|
|
126
|
+
async function load(scroll, silent) {
|
|
127
|
+
const mine = ++token, mark = () => mine === token;
|
|
128
|
+
if (!silent) { shown = null; setMeta('读取中…'); revoke(); body.replaceChildren(); }
|
|
129
|
+
try {
|
|
130
|
+
const result = await readFile(offset => read(path, offset), {
|
|
131
|
+
prev: silent ? shown : null, cancelled: () => !mark(),
|
|
132
|
+
onProgress: (got, total) => { if (mark() && !silent && total > TEXT_LIMIT / 4) setMeta(`读取中 ${formatSize(got)} / ${formatSize(total)}`); },
|
|
133
|
+
});
|
|
134
|
+
if (!mark() || result.cancelled) return;
|
|
135
|
+
if (result.same) return setStale(null);
|
|
136
|
+
const keep = scroll ?? { top: body.scrollTop, left: body.scrollLeft };
|
|
137
|
+
show(result);
|
|
138
|
+
body.scrollTop = keep.top; body.scrollLeft = keep.left;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (mark()) failure(error, silent, () => load(null, false));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
open(next, scroll = null) {
|
|
146
|
+
path = next;
|
|
147
|
+
const base = next.split('/').pop();
|
|
148
|
+
name.textContent = base;
|
|
149
|
+
name.title = next;
|
|
150
|
+
fileIcon.replaceChildren(icon(iconFor({ kind: EntryKind.FILE, name: base }), 22));
|
|
151
|
+
return load(scroll, false);
|
|
152
|
+
},
|
|
153
|
+
copyPath,
|
|
154
|
+
refresh() { return path === null ? undefined : load(null, true); },
|
|
155
|
+
// 内容的来源变了(根目录换了位置):旧正文不能留,也不能按元数据判断「没变」。
|
|
156
|
+
reload() { return path === null ? undefined : load(null, false); },
|
|
157
|
+
close() { token++; path = null; shown = null; setMeta(' '); revoke(); body.replaceChildren(); },
|
|
158
|
+
scroll: () => ({ top: body.scrollTop, left: body.scrollLeft }),
|
|
159
|
+
onScroll: fn => body.addEventListener('scroll', fn, { passive: true }),
|
|
160
|
+
get path() { return path; },
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// 模块和页面共用的消息格式与上限。只用浏览器和 Node 都有的东西。
|
|
2
|
+
|
|
3
|
+
// 宿主按 JSON.stringify({ message }).length 计量,超过的消息会被丢弃。
|
|
4
|
+
export const MESSAGE_LIMIT = 128 * 1024;
|
|
5
|
+
export const CHUNK_BYTES = 64 * 1024;
|
|
6
|
+
// 目录一页的上限(序列化后的 UTF-8 字节,含信封);信封(类型、代次、请求号、游标)留给下面这些字节。
|
|
7
|
+
export const PAGE_BYTES = 96 * 1024;
|
|
8
|
+
export const ENVELOPE_BYTES = 4096;
|
|
9
|
+
export const TEXT_LIMIT = 1024 * 1024;
|
|
10
|
+
export const IMAGE_LIMIT = 8 * 1024 * 1024;
|
|
11
|
+
// 前这么多字节里有 NUL 就当二进制(同 Coda 的 worktree-changes)。
|
|
12
|
+
export const SNIFF_BYTES = 8000;
|
|
13
|
+
export const REQUEST_ID_MAX = 64;
|
|
14
|
+
|
|
15
|
+
export const Type = Object.freeze({
|
|
16
|
+
HELLO: 'hello', REFRESH: 'refresh', LIST: 'list', READ: 'read',
|
|
17
|
+
SESSION: 'session', ROOT: 'root', CHANGED: 'changed', LISTED: 'listed', CHUNK: 'chunk',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const RootState = Object.freeze({ READY: 'ready', NONE: 'none', PREPARING: 'preparing', GONE: 'gone' });
|
|
21
|
+
|
|
22
|
+
export const ErrorCode = Object.freeze({
|
|
23
|
+
NO_ROOT: 'no_root', INVALID_PATH: 'invalid_path', OUTSIDE_ROOT: 'outside_root', NOT_FOUND: 'not_found',
|
|
24
|
+
NOT_DIR: 'not_dir', NOT_FILE: 'not_file', DENIED: 'denied', INVALID_CURSOR: 'invalid_cursor',
|
|
25
|
+
INVALID_OFFSET: 'invalid_offset', TOO_LARGE: 'too_large', IO: 'io_error',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// 目录条目的 kind:dir、file;link 是指向工作目录外或已失效的链接;other 是不能打开的(套接字、名字含控制字符等)。
|
|
29
|
+
// 指向工作目录内的链接按目标显示成 dir 或 file,并带 link: true。
|
|
30
|
+
export const EntryKind = Object.freeze({ DIR: 'dir', FILE: 'file', LINK: 'link', OTHER: 'other' });
|
|
31
|
+
// 文件块的 kind。
|
|
32
|
+
export const ContentKind = Object.freeze({ TEXT: 'text', IMAGE: 'image', BINARY: 'binary' });
|
|
33
|
+
|
|
34
|
+
const IMAGE_TYPES = {
|
|
35
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', svg: 'image/svg+xml',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 按扩展名给出图片的 MIME 类型,不是图片返回 null。
|
|
39
|
+
export function imageType(name) {
|
|
40
|
+
const dot = String(name).lastIndexOf('.');
|
|
41
|
+
return dot < 0 ? null : IMAGE_TYPES[name.slice(dot + 1).toLowerCase()] ?? null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const messageSize = message => JSON.stringify({ message }).length;
|
|
45
|
+
|
|
46
|
+
// 带 code 的错误,模块里到处抛,主模块转成回答里的 error。
|
|
47
|
+
export function fail(code, message) {
|
|
48
|
+
return Object.assign(new Error(message), { code, protocol: true });
|
|
49
|
+
}
|
package/view/style.css
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/* 资源管理器的页面,颜色、字体、字号只用 App 给的 --coda-* 变量(docs/plugins.md「视图」)。 */
|
|
2
|
+
:root {
|
|
3
|
+
--hover: var(--coda-hover, var(--coda-fill, rgba(0,0,0,.05)));
|
|
4
|
+
--line: var(--coda-separator, rgba(0,0,0,.1));
|
|
5
|
+
--row-h: calc(var(--coda-font-size, 13px) * 2);
|
|
6
|
+
--indent: 12px; --pad: 6px;
|
|
7
|
+
/* 安全区:横屏时客户端不替页面留,页面自己按这几个值留白;变量便于 harness 模拟。 */
|
|
8
|
+
--safe-top: env(safe-area-inset-top, 0px); --safe-right: env(safe-area-inset-right, 0px);
|
|
9
|
+
--safe-bottom: env(safe-area-inset-bottom, 0px); --safe-left: env(safe-area-inset-left, 0px);
|
|
10
|
+
font: var(--coda-font-size, 13px)/1.45 var(--coda-font, -apple-system, system-ui, sans-serif);
|
|
11
|
+
color: var(--coda-foreground, #1d1d1f); background: transparent;
|
|
12
|
+
}
|
|
13
|
+
* { box-sizing: border-box; }
|
|
14
|
+
html, body { margin: 0; height: 100%; }
|
|
15
|
+
body { display: flex; flex-direction: column; overflow: hidden; -webkit-user-select: none; user-select: none;
|
|
16
|
+
padding: var(--safe-top) var(--safe-right) 0 var(--safe-left); }
|
|
17
|
+
.selectable { -webkit-user-select: text; user-select: text; }
|
|
18
|
+
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: inherit; cursor: pointer; }
|
|
19
|
+
button:focus-visible { outline: 2px solid var(--coda-accent, #0a84ff); outline-offset: 2px; border-radius: 6px; }
|
|
20
|
+
button.link { color: var(--coda-accent, #0a84ff); }
|
|
21
|
+
p { margin: 0; }
|
|
22
|
+
.secondary { color: var(--coda-secondary, #6e6e73); }
|
|
23
|
+
.caption { font-size: .85em; }
|
|
24
|
+
.grow { flex: 1 1 auto; min-width: 0; }
|
|
25
|
+
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
26
|
+
[hidden] { display: none !important; }
|
|
27
|
+
|
|
28
|
+
/* 三个面板叠在同一处,只切可见性:隐藏的树保留滚动位置,切换不改变布局。 */
|
|
29
|
+
#stage { position: relative; flex: 1 1 auto; min-height: 0; }
|
|
30
|
+
.pane { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: var(--safe-bottom); }
|
|
31
|
+
.pane.off { visibility: hidden; pointer-events: none; }
|
|
32
|
+
.empty { display: grid; align-content: start; justify-items: center; gap: 6px; padding: 32px 20px; text-align: center; }
|
|
33
|
+
.notice-icon { display: grid; place-items: center; margin-bottom: 6px; color: var(--coda-secondary, #6e6e73); }
|
|
34
|
+
.notice-icon svg { display: block; }
|
|
35
|
+
|
|
36
|
+
/* 页内工具条:iPhone 树页在顶部(返回、根目录名、⋯),文件页在底部(.bottom:返回、刷新、复制路径)。没有 coda.toolbar 的其他平台(harness)是一条文字按钮。 */
|
|
37
|
+
.bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
|
|
38
|
+
.bar button { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: var(--coda-radius, 6px); color: var(--coda-secondary, #6e6e73); }
|
|
39
|
+
.bar button.on { color: var(--coda-accent, #0a84ff); }
|
|
40
|
+
.bar svg { display: block; flex: none; }
|
|
41
|
+
.bar-title { padding: 0 8px; font-weight: 600; }
|
|
42
|
+
.bar.bottom { padding-bottom: var(--safe-bottom); border-top: 1px solid var(--line); border-bottom: 0; } /* 操作区 44 点(iPhone)之外只加安全区 */
|
|
43
|
+
|
|
44
|
+
/* 树:只画可见的一段,行高固定(tree.mjs 量 .row 的高度)。
|
|
45
|
+
Mac 是侧栏列表:左右缩进 8 点,行有圆角,选中用 --coda-selection。 */
|
|
46
|
+
.section { padding: 10px 16px 4px; font-size: .85em; font-weight: 600; color: var(--coda-secondary, #6e6e73); cursor: default; }
|
|
47
|
+
.spacer { position: relative; margin: 0 8px; }
|
|
48
|
+
.win { position: absolute; left: 0; right: 0; top: 0; }
|
|
49
|
+
/* 缩进按行的 --d(深度)算,iPhone 的分隔线起点也用它。 */
|
|
50
|
+
.row { position: relative; display: flex; align-items: center; gap: 4px; height: var(--row-h); padding: 0 8px 0 calc(var(--indent) * var(--d, 0) + var(--pad));
|
|
51
|
+
border-radius: var(--coda-radius, 6px); white-space: nowrap; cursor: default; }
|
|
52
|
+
.row.sel { background: var(--coda-selection, var(--hover)); }
|
|
53
|
+
.row.more, .row.retry { color: var(--coda-accent, #0a84ff); cursor: pointer; }
|
|
54
|
+
.row.status { display: block; overflow: hidden; text-overflow: ellipsis; line-height: var(--row-h); color: var(--coda-secondary, #6e6e73); }
|
|
55
|
+
.row.dead .name, .row.dead .ico { color: var(--coda-tertiary, #a1a1a6); }
|
|
56
|
+
.chev { flex: none; display: grid; place-items: center; width: 14px; font-size: .8em; color: var(--coda-secondary, #6e6e73); }
|
|
57
|
+
.chev svg { display: block; }
|
|
58
|
+
.row.open .chev svg { transform: rotate(90deg); }
|
|
59
|
+
.row.file .chev svg { visibility: hidden; } /* Mac 的文件只留空槽,名字才对齐 */
|
|
60
|
+
.ico { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
61
|
+
.ico svg { display: block; }
|
|
62
|
+
.row.dir .ico { color: var(--coda-accent, #0a84ff); }
|
|
63
|
+
.name { flex: 1 1 auto; min-width: 0; }
|
|
64
|
+
.tail { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
65
|
+
.tail:empty { display: none; }
|
|
66
|
+
.tail svg { display: block; }
|
|
67
|
+
.tail.warn { color: var(--coda-orange, #b25000); }
|
|
68
|
+
|
|
69
|
+
/* 预览:头部永远占一行名字加一行说明,加载和失败只换下面的内容。 */
|
|
70
|
+
.preview { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; } /* 底部的安全区归文件页的工具条 */
|
|
71
|
+
.phead button { flex: none; white-space: nowrap; }
|
|
72
|
+
.phead { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
|
|
73
|
+
.pico { flex: none; display: grid; place-items: center; color: var(--coda-secondary, #6e6e73); }
|
|
74
|
+
.pico svg { display: block; }
|
|
75
|
+
button.icon { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; border-radius: var(--coda-radius, 6px); color: var(--coda-secondary, #6e6e73); }
|
|
76
|
+
button.icon svg { display: block; }
|
|
77
|
+
.pname { font-weight: 600; }
|
|
78
|
+
.pbody { flex: 1 1 auto; min-height: 0; overflow: auto; }
|
|
79
|
+
.code { display: flex; width: max-content; min-width: 100%; font: .9em/1.55 var(--coda-mono, ui-monospace, Menlo, monospace); }
|
|
80
|
+
.code pre { margin: 0; font: inherit; }
|
|
81
|
+
.gutter { position: sticky; left: 0; flex: none; padding: 6px 8px 6px 12px; text-align: right; background: var(--coda-background, #fff);
|
|
82
|
+
color: var(--coda-tertiary, #a1a1a6); -webkit-user-select: none; user-select: none; }
|
|
83
|
+
.text { flex: 1 0 auto; padding: 6px 12px 6px 4px; tab-size: 4; }
|
|
84
|
+
.image { display: grid; place-items: start center; padding: 12px; }
|
|
85
|
+
.image img { max-width: 100%; height: auto; border-radius: var(--coda-radius, 6px); background: var(--coda-secondary-background, transparent); }
|
|
86
|
+
|
|
87
|
+
#notice:focus { outline: none; }
|
|
88
|
+
.menu { position: fixed; z-index: 10; min-width: 150px; padding: 4px; border: 1px solid var(--coda-outline, var(--line)); border-radius: var(--coda-radius-card, 10px);
|
|
89
|
+
background: var(--coda-card, var(--coda-background, #fff)); }
|
|
90
|
+
.menu button { display: flex; align-items: center; gap: 6px; width: 100%; padding: 5px 10px; border-radius: var(--coda-radius, 6px); }
|
|
91
|
+
.check { flex: none; display: grid; place-items: center; width: 16px; color: var(--coda-accent, #0a84ff); }
|
|
92
|
+
.check svg { display: block; }
|
|
93
|
+
.menu-path { max-width: 280px; padding: 4px 10px 6px; overflow-wrap: anywhere; }
|
|
94
|
+
.pmeta.warn { color: var(--coda-orange, #b25000); }
|
|
95
|
+
|
|
96
|
+
.hint { position: fixed; left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); bottom: calc(8px + var(--safe-bottom)); z-index: 10;
|
|
97
|
+
padding: 8px 12px; border: 1px solid var(--coda-outline, var(--line)); border-radius: var(--coda-radius-card, 10px);
|
|
98
|
+
background: var(--coda-card, var(--coda-background, #fff)); color: var(--coda-orange, #b25000); }
|
|
99
|
+
|
|
100
|
+
/* 悬停只在有鼠标时:触摸后不会留着。 */
|
|
101
|
+
@media (hover: hover) {
|
|
102
|
+
.bar button:hover, button.icon:hover { background: var(--hover); }
|
|
103
|
+
.row.entry:hover { background: var(--hover); }
|
|
104
|
+
.row.entry.sel:hover { background: var(--coda-selection, var(--hover)); }
|
|
105
|
+
.menu button:hover { background: var(--coda-selection, var(--hover)); }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* iPhone:行和按钮至少 44 点;行高在这里定,tree.mjs 量 .row 得到,不另写一份。
|
|
109
|
+
目录树是 Coda 卡片外形的分组列表:.spacer 就是卡片(高度已等于全部行高),首尾圆角不用逐行判断。 */
|
|
110
|
+
.coda-ios { --row-h: 44px; --indent: 20px; --pad: 16px; }
|
|
111
|
+
.coda-ios .section { display: none; } /* 根目录名归页内工具条 */
|
|
112
|
+
.coda-ios .spacer { margin: 8px 16px; overflow: hidden; border-radius: var(--coda-radius-card, 12px); background: var(--coda-card, var(--coda-secondary-background, #fff)); }
|
|
113
|
+
/* 描边用伪元素:不占尺寸,spacer 加 border 会让内容区少 2 点,末行被裁。 */
|
|
114
|
+
.coda-ios .spacer::after { content: ''; position: absolute; inset: 0; border: 1px solid var(--coda-outline, var(--line)); border-radius: inherit; pointer-events: none; }
|
|
115
|
+
.coda-ios .row { gap: 8px; padding-right: 16px; border-radius: 0; }
|
|
116
|
+
.coda-ios .row + .row::before { content: ''; position: absolute; top: 0; right: 0; height: 1px; background: var(--coda-separator, var(--line));
|
|
117
|
+
left: calc(var(--pad) + var(--indent) * var(--d, 0) + 22px + 8px); } /* 从图标之后开始 */
|
|
118
|
+
.coda-ios .row.sel + .row::before, .coda-ios .row.sel::before { background: transparent; }
|
|
119
|
+
.coda-ios .row { -webkit-touch-callout: none; } /* 长按由页面接管,不弹系统菜单;选择和拖动另外已关 */
|
|
120
|
+
.coda-ios .row.entry:active { background: var(--hover); }
|
|
121
|
+
.coda-ios .ico svg { width: 22px; height: 22px; }
|
|
122
|
+
.coda-ios .chev { order: 9; width: 14px; }
|
|
123
|
+
.coda-ios .row.dir .chev { color: var(--coda-accent, #0a84ff); }
|
|
124
|
+
.coda-ios .row.file .chev svg { visibility: visible; }
|
|
125
|
+
.coda-ios .row.dead .chev { display: none; }
|
|
126
|
+
.coda-ios button { min-height: 44px; min-width: 44px; }
|
|
127
|
+
.coda-ios .bar { gap: 0; padding: 0 8px; }
|
|
128
|
+
.coda-ios .bar button { gap: 6px; padding: 0 12px; border-radius: var(--coda-radius, 10px); color: var(--coda-accent, #0a84ff); }
|
|
129
|
+
.coda-ios .bar button.icon { padding: 0; justify-content: center; }
|
|
130
|
+
.coda-ios .bar.bottom { padding: 0 8px var(--safe-bottom); }
|
|
131
|
+
.coda-ios .bar.bottom button { flex: 1 1 0; justify-content: center; } /* 横排单行:横屏只有 390 点高 */
|
|
132
|
+
.coda-ios .phead { padding: 4px 12px; gap: 4px; }
|
|
133
|
+
.coda-ios .phead button { padding: 0 8px; }
|
|
134
|
+
.coda-ios .code { font-size: .8em; } /* 窄屏多看些:17 点下约 13.6 点 */
|
|
135
|
+
.coda-ios .menu button { padding: 0 12px; }
|
|
136
|
+
|
|
137
|
+
/* 横屏:客户端隐藏导航栏,页面自己给返回。近似 verticalSizeClass 的判断,不等价(iPad、Duo 不单独适配)。 */
|
|
138
|
+
.bar .exit { display: none; }
|
|
139
|
+
@media (orientation: landscape) and (max-height: 500px) { .coda-ios .bar .exit { display: inline-flex; } }
|