@coda-console/resource-manager 0.4.0 → 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/view/icons.mjs CHANGED
@@ -1,16 +1,52 @@
1
- // 图标:页面里自己画的 SVG,形状近似 SF Symbol,不打包 Apple 的符号。颜色都是 currentColor,由 CSS 定。
1
+ // 图标:页面里自己画的 SVG,形状近似 SF Symbol,不打包 Apple 的符号,也不用任何第三方素材。颜色都是 currentColor,由 CSS 定:
2
+ // 种类图标带 tone-* 类(颜色见 style.css 的 --tone-*),没有色调的(工具条、菜单的图标)跟随所在位置的文字色。
2
3
  import { EntryKind } from './protocol.mjs';
3
4
 
4
5
  const SVG_NS = 'http://www.w3.org/2000/svg';
5
6
 
6
- // 描边图标的 24×24 画法;folder 是填充的,单独标。
7
+ // 描边图标的 24×24 画法;folder 是填充的,单独标。形状 [标签, 属性, 文字?]:个别形状用自己的 fill、stroke、opacity 盖过根上的,文字放第三项。
8
+ const PAGE = [['path', { d: 'M7 3h7l5 5v11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z' }], ['path', { d: 'M14 3v5h5' }]];
9
+ const FILLED = { fill: 'currentColor', stroke: 'none' };
10
+ // 语言类:淡底加字母,不是任何语言的徽标;字母用 text,字体跟页面。
11
+ const badge = (letters, size = 10.5) => [
12
+ ['rect', { x: 2, y: 3, width: 20, height: 18, rx: 4.5, ...FILLED, opacity: 0.16 }],
13
+ ['text', { x: 12, y: Number((12 + size * 0.36).toFixed(2)), 'text-anchor': 'middle', 'font-size': size, 'font-weight': 700, ...FILLED }, letters],
14
+ ];
7
15
  const SHAPES = {
8
16
  folder: { fill: true, shapes: [['path', { d: 'M3 7.2C3 5.98 3.98 5 5.2 5h4.05c.6 0 1.17.24 1.59.66L12 6.8h6.8C20.02 6.8 21 7.78 21 9v8.8c0 1.22-.98 2.2-2.2 2.2H5.2C3.98 20 3 19.02 3 17.8V7.2z' }]] },
9
- doc: { shapes: [['path', { d: 'M7 3h7l5 5v11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z' }], ['path', { d: 'M14 3v5h5' }], ['path', { d: 'M9 13h6M9 17h4' }]] },
10
- code: { shapes: [['path', { d: 'M7 3h7l5 5v11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z' }], ['path', { d: 'M14 3v5h5' }], ['path', { d: 'M10.5 12.5 8.5 15l2 2.5M13.5 12.5l2 2.5-2 2.5' }]] },
11
- image: { shapes: [['rect', { x: 3.5, y: 4.5, width: 17, height: 15, rx: 2.5 }], ['circle', { cx: 9, cy: 10, r: 1.6 }], ['path', { d: 'm4 17 4.5-4.5 3.5 3.5 3-3 5 5' }]] },
17
+ doc: { shapes: PAGE },
18
+ text: { shapes: [...PAGE, ['path', { d: 'M9 13h6M9 17h4' }]] },
19
+ code: { shapes: [...PAGE, ['path', { d: 'M10.5 12.5 8.5 15l2 2.5M13.5 12.5l2 2.5-2 2.5' }]] },
20
+ ts: { shapes: badge('TS') },
21
+ js: { shapes: badge('JS') },
22
+ py: { shapes: badge('Py') },
23
+ go: { shapes: badge('Go') },
24
+ rs: { shapes: badge('Rs') },
25
+ swift: { shapes: badge('Sw') },
26
+ c: { shapes: badge('C', 12) },
27
+ java: { shapes: badge('Jv') },
28
+ ruby: { shapes: badge('Rb') },
29
+ md: { shapes: badge('MD', 9.5) },
30
+ pdf: { shapes: badge('PDF', 8) },
31
+ json: { shapes: [['path', { d: 'M9 4C6.5 4 7 7 7 9c0 2-1 3-2.5 3C6 12 7 13 7 15c0 2-.5 5 2 5M15 4c2.5 0 2 3 2 5 0 2 1 3 2.5 3-1.5 0-2.5 1-2.5 3 0 2 .5 5-2 5' }]] },
32
+ html: { shapes: [['path', { d: 'M8.5 7 3.5 12l5 5M15.5 7l5 5-5 5' }]] },
33
+ css: { shapes: [['path', { d: 'M9.5 4 8 20M16 4l-1.5 16M5 9h15M4 15h15' }]] },
34
+ config: { shapes: [['path', { d: 'M4 7h9M17 7h3M4 17h3M11 17h9' }], ['circle', { cx: 15, cy: 7, r: 2.3 }], ['circle', { cx: 9, cy: 17, r: 2.3 }]] },
35
+ shell: { shapes: [['rect', { x: 3, y: 4, width: 18, height: 16, rx: 3.5 }], ['path', { d: 'm7 9.5 3 2.5-3 2.5M12.5 15.5H17' }]] },
36
+ image: { shapes: [['rect', { x: 3, y: 4, width: 18, height: 16, rx: 3 }], ['circle', { cx: 8.7, cy: 9.5, r: 1.6, ...FILLED }], ['path', { d: 'm4 17.5 4.5-4.5 3.5 3.5 3-3 5 5' }]] },
37
+ video: { shapes: [['rect', { x: 3, y: 5, width: 18, height: 14, rx: 3 }], ['path', { d: 'M10 9v6l5-3z', ...FILLED }]] },
38
+ audio: { shapes: [['path', { d: 'M9 18V6l10-2v12' }], ['circle', { cx: 6.5, cy: 18, r: 2.5 }], ['circle', { cx: 16.5, cy: 16, r: 2.5 }]] },
39
+ archive: { shapes: [...PAGE, ['path', { d: 'M10 3h2v2h-2zM12 5h2v2h-2zM10 7h2v2h-2zM12 9h2v2h-2z', ...FILLED }], ['rect', { x: 10, y: 12, width: 4, height: 5, rx: 1, 'stroke-width': 1.5 }]] },
40
+ sheet: { shapes: [['rect', { x: 3, y: 4, width: 18, height: 16, rx: 3 }], ['path', { d: 'M3 10h18M3 15h18M10 10v10' }]] },
41
+ database: { shapes: [['ellipse', { cx: 12, cy: 6, rx: 8, ry: 3 }], ['path', { d: 'M4 6v12c0 1.7 3.6 3 8 3s8-1.3 8-3V6M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3' }]] },
42
+ font: { shapes: [['text', { x: 12, y: 17.5, 'text-anchor': 'middle', 'font-size': 16, 'font-weight': 600, ...FILLED }, 'Aa']] },
43
+ lock: { shapes: [['rect', { x: 5, y: 10.5, width: 14, height: 10, rx: 2.5 }], ['path', { d: 'M8.5 10.5V8a3.5 3.5 0 0 1 7 0v2.5' }]] },
44
+ git: { shapes: [['circle', { cx: 7, cy: 6, r: 2.2 }], ['circle', { cx: 7, cy: 18, r: 2.2 }], ['circle', { cx: 17, cy: 8, r: 2.2 }], ['path', { d: 'M7 8.2v7.6M17 10.2c0 3-3 3.8-10 5' }]] },
45
+ env: { shapes: [['circle', { cx: 8, cy: 12, r: 4 }], ['path', { d: 'M12 12h9M18 12v3.5M21 12v2.5' }]] },
46
+ manifest: { shapes: [['path', { d: 'M12 3 4 7.5v9L12 21l8-4.5v-9L12 3zM4 7.5 12 12l8-4.5M12 12v9' }]] },
47
+ license: { shapes: [...PAGE, ['circle', { cx: 11.5, cy: 13.5, r: 2.5, 'stroke-width': 1.5 }], ['path', { d: 'm10 15.5-1 3.5 2.5-1 2.5 1-1-3.5', 'stroke-width': 1.5 }]] },
12
48
  link: { shapes: [['path', { d: 'M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1' }], ['path', { d: 'M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1' }]] },
13
- other: { shapes: [['path', { d: 'M7 3h7l5 5v11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z' }], ['path', { d: 'M14 3v5h5' }], ['path', { d: 'M9.5 14.5h5' }]] },
49
+ other: { shapes: [...PAGE, ['path', { d: 'M9.5 14.5h5' }]] },
14
50
  chevron: { shapes: [['path', { d: 'm9 5 7 7-7 7' }]] },
15
51
  warning: { shapes: [['path', { d: 'M12 4 2.8 19.5h18.4L12 4z' }], ['path', { d: 'M12 10v4.5M12 17.2v.1' }]] },
16
52
  back: { shapes: [['path', { d: 'm15 5-7 7 7 7' }]] },
@@ -22,35 +58,116 @@ const SHAPES = {
22
58
  turn: { shapes: [['path', { d: 'M5 18v-4a4 4 0 0 1 4-4h10' }], ['path', { d: 'm15 6 4 4-4 4' }]] },
23
59
  };
24
60
 
25
- // 扩展名表:不在表里的文件都是文档。
26
- const BY_EXT = {
27
- code: ['js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx', 'json', 'yml', 'yaml', 'toml', 'html', 'css', 'scss', 'vue', 'py', 'rb', 'go', 'rs', 'java', 'kt', 'swift',
28
- 'c', 'h', 'cpp', 'hpp', 'cs', 'php', 'lua', 'sh', 'bash', 'zsh', 'sql', 'xml'],
29
- image: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'ico', 'bmp', 'heic', 'avif'],
61
+ // 种类表:种类文字(属性页)和图标(目录树、预览头部)查同一张,不另写一份。
62
+ // glyph 是上面 SHAPES 里的图标名,每种一个图标;tone 是色调名,颜色在 style.css 的 --tone-*:accent 是强调色(文件夹),muted 不上色(链接、特殊文件不能打开,跟随三级文字色)。
63
+ const KINDS = {
64
+ dir: { glyph: 'folder', tone: 'accent', label: '文件夹' },
65
+ link: { glyph: 'link', tone: 'muted', label: '链接' },
66
+ other: { glyph: 'other', tone: 'muted', label: '特殊文件' },
67
+ file: { glyph: 'doc', tone: 'gray', label: '其他文件' },
68
+ text: { glyph: 'text', tone: 'gray', label: '文本' },
69
+ markdown: { glyph: 'md', tone: 'blue', label: 'Markdown 文档' },
70
+ typescript: { glyph: 'ts', tone: 'blue', label: 'TypeScript' },
71
+ javascript: { glyph: 'js', tone: 'yellow', label: 'JavaScript' },
72
+ python: { glyph: 'py', tone: 'green', label: 'Python' },
73
+ go: { glyph: 'go', tone: 'teal', label: 'Go' },
74
+ rust: { glyph: 'rs', tone: 'orange', label: 'Rust' },
75
+ swift: { glyph: 'swift', tone: 'orange', label: 'Swift' },
76
+ c: { glyph: 'c', tone: 'blue', label: 'C / C++' },
77
+ java: { glyph: 'java', tone: 'red', label: 'Java / Kotlin' },
78
+ ruby: { glyph: 'ruby', tone: 'red', label: 'Ruby' },
79
+ code: { glyph: 'code', tone: 'gray', label: '源代码' },
80
+ json: { glyph: 'json', tone: 'yellow', label: 'JSON' },
81
+ html: { glyph: 'html', tone: 'orange', label: 'HTML / XML' },
82
+ css: { glyph: 'css', tone: 'purple', label: 'CSS' },
83
+ yaml: { glyph: 'config', tone: 'pink', label: 'YAML / TOML' },
84
+ shell: { glyph: 'shell', tone: 'green', label: 'Shell 脚本' },
85
+ image: { glyph: 'image', tone: 'purple', label: '图片' },
86
+ video: { glyph: 'video', tone: 'pink', label: '视频' },
87
+ audio: { glyph: 'audio', tone: 'pink', label: '音频' },
88
+ pdf: { glyph: 'pdf', tone: 'red', label: 'PDF 文档' },
89
+ archive: { glyph: 'archive', tone: 'orange', label: '压缩包' },
90
+ sheet: { glyph: 'sheet', tone: 'green', label: '表格' },
91
+ database: { glyph: 'database', tone: 'teal', label: '数据库' },
92
+ font: { glyph: 'font', tone: 'gray', label: '字体' },
93
+ lock: { glyph: 'lock', tone: 'gray', label: '锁文件' },
94
+ git: { glyph: 'git', tone: 'orange', label: 'Git 配置' },
95
+ env: { glyph: 'env', tone: 'yellow', label: '环境变量' },
96
+ manifest: { glyph: 'manifest', tone: 'green', label: '包清单' },
97
+ license: { glyph: 'license', tone: 'gray', label: '许可证' },
30
98
  };
31
- const EXT_ICON = new Map(Object.entries(BY_EXT).flatMap(([name, exts]) => exts.map(ext => [ext, name])));
32
-
33
- // 图标名:目录、链接、其他按种类;文件按扩展名(不分大小写;.gitignore 这类点开头的没有扩展名),没有匹配的是文档。
34
- export function iconFor({ kind, name }) {
35
- if (kind === EntryKind.DIR) return 'folder';
36
- if (kind === EntryKind.LINK) return 'link';
37
- if (kind === EntryKind.OTHER) return 'other';
38
- const dot = name.lastIndexOf('.');
39
- return (dot > 0 && EXT_ICON.get(name.slice(dot + 1).toLowerCase())) || 'doc';
99
+
100
+ // 文件名(小写)优先,再按扩展名(小写);都不在表里的是「其他文件」。
101
+ const NAMES = {
102
+ git: ['.gitignore', '.gitattributes', '.gitmodules', '.gitconfig', '.gitkeep', '.mailmap'],
103
+ env: ['.env', '.envrc'],
104
+ manifest: ['package.json', 'cargo.toml', 'go.mod', 'pyproject.toml', 'requirements.txt', 'gemfile', 'package.swift', 'pom.xml', 'build.gradle', 'composer.json', 'setup.py'],
105
+ lock: ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'cargo.lock', 'gemfile.lock', 'poetry.lock', 'go.sum', 'composer.lock', 'bun.lockb', 'podfile.lock'],
106
+ license: ['license', 'licence', 'copying', 'unlicense', 'license.md', 'license.txt', 'licence.md', 'licence.txt', 'copying.md', 'copying.txt'],
107
+ };
108
+ const EXTENSIONS = {
109
+ text: ['txt', 'text', 'log', 'rtf'],
110
+ markdown: ['md', 'markdown', 'mdx'],
111
+ typescript: ['ts', 'tsx', 'mts', 'cts'],
112
+ javascript: ['js', 'mjs', 'cjs', 'jsx'],
113
+ python: ['py', 'pyw', 'pyi'],
114
+ go: ['go'],
115
+ rust: ['rs'],
116
+ swift: ['swift'],
117
+ c: ['c', 'h', 'cc', 'cpp', 'cxx', 'hpp', 'hh'],
118
+ java: ['java', 'kt', 'kts'],
119
+ ruby: ['rb', 'erb'],
120
+ code: ['vue', 'scss', 'sass', 'less', 'cs', 'php', 'lua', 'sql', 'dart', 'scala', 'r', 'pl'],
121
+ json: ['json', 'jsonc', 'json5'],
122
+ html: ['html', 'htm', 'xml', 'xhtml', 'plist'],
123
+ css: ['css'],
124
+ yaml: ['yml', 'yaml', 'toml'],
125
+ shell: ['sh', 'bash', 'zsh', 'fish'],
126
+ image: ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'ico', 'bmp', 'heic', 'avif', 'tif', 'tiff'],
127
+ video: ['mp4', 'mov', 'm4v', 'avi', 'mkv', 'webm'],
128
+ audio: ['mp3', 'wav', 'm4a', 'aac', 'flac', 'ogg', 'aiff'],
129
+ pdf: ['pdf'],
130
+ archive: ['zip', 'tar', 'gz', 'tgz', 'bz2', 'xz', '7z', 'rar'],
131
+ sheet: ['csv', 'tsv', 'xls', 'xlsx', 'numbers', 'ods'],
132
+ database: ['db', 'sqlite', 'sqlite3'],
133
+ font: ['ttf', 'otf', 'woff', 'woff2'],
134
+ };
135
+ const invert = table => new Map(Object.entries(table).flatMap(([id, keys]) => keys.map(key => [key, id])));
136
+ const BY_NAME = invert(NAMES), BY_EXT = invert(EXTENSIONS);
137
+
138
+ // 一个条目的种类:{ glyph, tone, label }。目录、链接、其他按种类;文件先按整个文件名,再按扩展名(点开头的名字没有扩展名)。
139
+ // 指向工作目录内的链接按目标的种类显示(条目自己的 kind 已经是目标的)。
140
+ export function kindOf({ kind, name }) {
141
+ if (kind === EntryKind.DIR) return KINDS.dir;
142
+ if (kind === EntryKind.LINK) return KINDS.link;
143
+ if (kind === EntryKind.OTHER) return KINDS.other;
144
+ const lower = String(name).toLowerCase(), dot = lower.lastIndexOf('.');
145
+ return KINDS[BY_NAME.get(lower) ?? (lower.startsWith('.env.') ? 'env' : undefined) ?? (dot > 0 ? BY_EXT.get(lower.slice(dot + 1)) : undefined) ?? 'file'];
40
146
  }
41
147
 
42
- // 造一个 SVG 元素;size 是点数,CSS 可以按平台覆盖。
148
+ // 图标名:种类表里的 glyph。
149
+ export const iconFor = entry => kindOf(entry).glyph;
150
+
151
+ // 图标名到色调:从种类表来,一个图标只能有一种色调(icons.test 查)。没有色调(muted)和不在表里的图标(箭头、返回这些)不带类。
152
+ const TONE_OF = new Map(Object.values(KINDS).filter(({ tone }) => tone !== 'muted').map(({ glyph, tone }) => [glyph, tone]));
153
+
154
+ // 造一个 SVG 元素;size 是点数,CSS 可以按平台覆盖。种类图标带 tone-* 类,颜色由 CSS 定。
43
155
  export function icon(name, size = 16) {
44
156
  const { fill = false, shapes } = SHAPES[name];
45
157
  const svg = document.createElementNS(SVG_NS, 'svg');
46
158
  const attrs = { width: size, height: size, viewBox: '0 0 24 24', 'aria-hidden': 'true', ...(fill
47
159
  ? { fill: 'currentColor' }
48
160
  : { fill: 'none', stroke: 'currentColor', 'stroke-width': 1.8, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }) };
161
+ if (TONE_OF.has(name)) attrs.class = `tone-${TONE_OF.get(name)}`;
49
162
  for (const [key, value] of Object.entries(attrs)) svg.setAttribute(key, value);
50
- for (const [tag, shape] of shapes) {
163
+ for (const [tag, shape, text] of shapes) {
51
164
  const node = document.createElementNS(SVG_NS, tag);
52
165
  for (const [key, value] of Object.entries(shape)) node.setAttribute(key, value);
166
+ if (text !== undefined) node.textContent = text;
53
167
  svg.append(node);
54
168
  }
55
169
  return svg;
56
170
  }
171
+
172
+ // 给测试:两张表本身,不是复制。
173
+ export { KINDS, SHAPES };
package/view/index.html CHANGED
@@ -12,6 +12,7 @@
12
12
  <div id="tree" class="pane tree" role="tree"></div>
13
13
  <div id="preview" class="pane preview"></div>
14
14
  <div id="notice" class="pane empty secondary"></div>
15
+ <div id="info" class="pane preview info"></div>
15
16
  </main>
16
17
  <div id="menu" class="menu" role="menu" hidden></div>
17
18
  <div id="hint" class="hint" role="status" hidden></div>
package/view/info.mjs ADDED
@@ -0,0 +1,117 @@
1
+ // 属性页:一个文件、文件夹或链接的属性。只管显示:属性和文件夹大小由页面经 stat、size 取,这里不知道聊天和目录树。
2
+ // 设计见 docs/design/phase-3.md 第 13.8 节。进入、返回和原生返回的声明在页面(app.mjs)。
3
+ import { h } from './dom.mjs';
4
+ import { dirSizeText, fileSizeText, formatFullDate, modeText } from './format.mjs';
5
+ import { icon, kindOf } from './icons.mjs';
6
+ import { EntryKind } from './protocol.mjs';
7
+
8
+ // el:#info 面板。选项:
9
+ // stat(path) → Promise<statted 回答>;size(path, signal) → Promise<sized 回答>,signal 中止后请求静默作废(连接层同时通知模块停止统计);
10
+ // rootPath():根目录的绝对路径,拼完整路径用;round():页面的数据轮次,每次 changed 加一;
11
+ // back:给了就在头部最左边放「返回」(Mac,和没有原生返回的环境)。
12
+ export function mountInfo(el, { stat, size, rootPath, round, back = null }) {
13
+ const head = h('div', { class: 'phead' }), body = h('div', { class: 'pbody ibody selectable' });
14
+ el.replaceChildren(head, body);
15
+
16
+ let path = null, seed = null;
17
+ let reply = null, failure = null; // 属性的回答;取属性失败的原因
18
+ let sizing = null; // 文件夹大小这一次统计:{ abort, round, phase: 'running' | 'done' | 'failed', result, message }
19
+ let token = 0; // 取属性的序号:新的取代旧的,旧的回答不再用
20
+
21
+ const entry = () => reply ?? seed;
22
+ // 指向工作目录内的链接按目标显示:种类和图标看目标的名字(链接自己叫什么不管),没有目标的(外链接)看自己。
23
+ const shownKind = () => {
24
+ const { kind, name } = entry(), target = reply?.target;
25
+ return kindOf({ kind, name: target ? target.slice(target.lastIndexOf('/') + 1) : name });
26
+ };
27
+ const kindText = () => {
28
+ const base = shownKind().label;
29
+ if (entry().kind === EntryKind.LINK) return `${base}(指向工作目录外或已失效)`;
30
+ return reply?.link ? `${base}(链接)` : base;
31
+ };
32
+
33
+ const row = (label, value) => h('div', { class: 'irow' }, h('span', { class: 'ilabel secondary' }, label), h('div', { class: 'ivalue' }, value));
34
+ const link = (label, run) => h('button', { class: 'link', onclick: run }, label);
35
+ const note = (title, detail, action) => h('div', { class: 'empty' }, h('p', {}, title), detail ? h('p', { class: 'secondary' }, detail) : null, action ? link(action.label, action.run) : null);
36
+
37
+ // 文件夹大小这一行:计算中、结果(上一轮的标「上次统计」)、失败。结果可能不全(没统计完),也可能是上一轮的,这两种都放「重新统计」。
38
+ function sizeRow() {
39
+ if (sizing.phase === 'running') return row('大小', '计算中…');
40
+ if (sizing.phase === 'failed') return row('大小', [h('span', { class: 'warn' }, `统计失败:${sizing.message}`), ' ', link('重新统计', startSize)]);
41
+ const old = sizing.round !== round();
42
+ return row('大小', [dirSizeText(sizing.result), old ? ' · 上次统计' : '', ...(old || !sizing.result.complete ? [' ', link('重新统计', startSize)] : [])]);
43
+ }
44
+
45
+ function paint() {
46
+ const focused = body.contains(document.activeElement);
47
+ const { name, kind } = entry(), where = path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : '工作目录';
48
+ head.replaceChildren(...(back ? [h('button', { class: 'icon', 'aria-label': '返回', title: '返回', onclick: back }, icon('back', 18))] : []),
49
+ h('span', { class: 'pico', 'aria-hidden': 'true' }, icon(shownKind().glyph, 22)),
50
+ h('div', { class: 'grow' }, h('div', { class: 'pname truncate', title: path }, name), h('div', { class: 'pmeta caption secondary truncate' }, '属性')));
51
+ if (failure !== null) body.replaceChildren(note('读不到属性', failure, { label: '重试', run: () => load() }));
52
+ else if (reply === null) body.replaceChildren(h('div', { class: 'empty secondary' }, h('p', {}, '读取中…')));
53
+ else {
54
+ const { size: bytes, target, mtimeMs, birthtimeMs, mode } = reply;
55
+ body.replaceChildren(
56
+ row('种类', kindText()),
57
+ ...(kind === EntryKind.DIR && sizing ? [sizeRow()] : Number.isInteger(bytes) ? [row('大小', fileSizeText(bytes))] : []),
58
+ ...(target !== undefined ? [row('链接到', target)] : []),
59
+ row('位置', where),
60
+ row('完整路径', `${rootPath()}/${path}`),
61
+ ...(Number.isInteger(mtimeMs) ? [row('修改时间', formatFullDate(mtimeMs))] : []),
62
+ ...(Number.isInteger(birthtimeMs) ? [row('创建时间', formatFullDate(birthtimeMs))] : []),
63
+ ...(Number.isInteger(mode) ? [row('权限', modeText(mode))] : []),
64
+ );
65
+ }
66
+ if (focused) { body.tabIndex = -1; body.focus(); } // 重画换掉了聚焦的按钮:焦点留在属性页里
67
+ }
68
+
69
+ // 取属性。文件夹第一次取到时开始统计;之后(changed 重取)不自动重新统计,只把已有的结果标成上次统计。
70
+ async function load() {
71
+ const mine = ++token, asked = path;
72
+ failure = null;
73
+ if (reply === null) paint();
74
+ try {
75
+ const next = await stat(asked);
76
+ if (mine !== token) return;
77
+ reply = next;
78
+ if (next.kind === EntryKind.DIR && sizing === null) startSize();
79
+ } catch (error) {
80
+ if (error.stale || mine !== token) return;
81
+ failure = error.message;
82
+ }
83
+ paint();
84
+ }
85
+
86
+ // 统计文件夹:新的开始时旧的先中止(连接层告诉模块停)。关闭、换会话、根目录变化时也走中止,等待不会拖到超时。
87
+ function startSize() {
88
+ sizing?.abort.abort();
89
+ const abort = new AbortController(), mine = sizing = { abort, round: round(), phase: 'running' }, asked = path;
90
+ paint();
91
+ size(asked, abort.signal).then(result => Object.assign(mine, { phase: 'done', result }), error => {
92
+ if (error.stale) return null; // 取消、换会话:静默
93
+ return Object.assign(mine, { phase: 'failed', message: error.message });
94
+ }).then(done => { if (done && sizing === mine) paint(); });
95
+ }
96
+
97
+ return {
98
+ // seed:目录树里这一行(名字、种类),属性回来之前先画头部。
99
+ open(next, row) {
100
+ this.close();
101
+ path = next;
102
+ seed = { name: row.name, kind: row.kind };
103
+ load();
104
+ },
105
+ // 一轮结束:重取属性,不自动重新统计;已有的统计结果马上标成上次统计(页面的数据轮次变了)。
106
+ refresh() { if (path !== null) { if (reply !== null) paint(); load(); } },
107
+ close() {
108
+ sizing?.abort.abort();
109
+ sizing = null;
110
+ token++;
111
+ path = seed = reply = failure = null;
112
+ head.replaceChildren();
113
+ body.replaceChildren();
114
+ },
115
+ get path() { return path; },
116
+ };
117
+ }
package/view/menu.mjs ADDED
@@ -0,0 +1,76 @@
1
+ // 菜单:Mac 右键、iPhone 长按的行菜单,Mac 选中文字的右键菜单,iPhone 的 ⋯ 和 Mac 原生「更多」弹出的菜单都用它,树页和文件页各挂一个。
2
+ // 菜单开着时点菜单外只关菜单、紧接着的那次点击不交给页面;Escape、窗口失焦关闭;页面里别的滚动区域滚动时由页面调 hide。
3
+ import { icon } from './icons.mjs';
4
+
5
+ // el:页面里的 #menu。open 之后的位置按安全区夹住(横屏时客户端不替页面留);offsetWidth 在显示后才量得到。
6
+ // 高度有上限(style.css 的 .menu):内容多时在菜单里滚动,不超出安全区。
7
+ export function mountMenu(el) {
8
+ let opener = null; // 打开菜单的按钮;用点打开的没有
9
+ let current = null; // 这一次打开的标记:关闭之后留在手里的按钮不再响应
10
+
11
+ // anchor:按钮元素或同样有 getBoundingClientRect 的假锚点(菜单贴在它下面、右对齐)或 { clientX, clientY } 的点。
12
+ // items:[{ label, run, checked?, radio? } | { separator: true } | { heading }],checked 不是 undefined 的带对勾(radio 的是单选,其余是开关);
13
+ // 分隔线和小标题不是菜单项,不可点。title 写在菜单顶上:iPhone 没有 title 悬停,长文件名在行里被截断,这里看全;detail 是它下面的一行小字。
14
+ function open(anchor, { title, detail, items }) {
15
+ hide();
16
+ const mine = current = {};
17
+ const head = [];
18
+ if (title !== undefined) head.push(Object.assign(document.createElement('p'), { className: 'menu-path secondary', textContent: title }));
19
+ if (detail !== undefined) head.push(Object.assign(document.createElement('p'), { className: 'menu-info secondary caption', textContent: detail }));
20
+ const checkable = items.some(item => item.checked !== undefined); // 有开关项时,每一项都留出对勾的位置,文字才对齐
21
+ el.replaceChildren(...head, ...items.map(({ label, run, checked, radio, separator, heading }) => {
22
+ if (separator) return Object.assign(document.createElement('hr'), { className: 'menu-sep' });
23
+ if (heading !== undefined) return Object.assign(document.createElement('p'), { className: 'menu-head secondary caption', textContent: heading });
24
+ const button = document.createElement('button'), name = document.createElement('span');
25
+ name.textContent = label;
26
+ if (checkable) {
27
+ const mark = document.createElement('span');
28
+ mark.className = 'check';
29
+ if (checked) mark.append(icon('check', 16));
30
+ button.append(mark);
31
+ }
32
+ button.append(name);
33
+ button.setAttribute('role', checked === undefined ? 'menuitem' : radio ? 'menuitemradio' : 'menuitemcheckbox');
34
+ if (checked !== undefined) button.setAttribute('aria-checked', String(checked));
35
+ button.addEventListener('click', () => {
36
+ if (current !== mine) return; // 菜单已经关了(或换成了别的):留在手里的按钮不再响应
37
+ hide();
38
+ run();
39
+ });
40
+ return button;
41
+ }));
42
+ el.hidden = false;
43
+ el.scrollTop = 0;
44
+ const box = anchor.getBoundingClientRect?.();
45
+ const x = box ? box.right - el.offsetWidth : anchor.clientX, y = box ? box.bottom + 4 : anchor.clientY;
46
+ el.style.left = `max(var(--safe-left), min(${x}px, calc(100vw - var(--safe-right) - ${el.offsetWidth + 4}px)))`;
47
+ el.style.top = `max(var(--safe-top), min(${y}px, calc(100vh - var(--safe-bottom) - ${el.offsetHeight + 4}px)))`;
48
+ if (box) { opener = anchor; opener.setAttribute?.('aria-expanded', 'true'); }
49
+ }
50
+
51
+ function hide() {
52
+ current = null;
53
+ el.hidden = true;
54
+ opener?.setAttribute?.('aria-expanded', 'false');
55
+ opener = null;
56
+ }
57
+
58
+ // 菜单开着时点菜单外:只关菜单,紧接着的那次点击不交给页面。
59
+ let dismissed = false;
60
+ document.addEventListener('pointerdown', event => {
61
+ dismissed = !el.hidden && !el.contains(event.target);
62
+ if (!el.contains(event.target)) hide();
63
+ }, true);
64
+ document.addEventListener('click', event => {
65
+ if (dismissed) { dismissed = false; event.stopPropagation(); }
66
+ }, true);
67
+ document.addEventListener('keydown', event => { if (event.key === 'Escape') hide(); });
68
+ window.addEventListener('blur', hide);
69
+
70
+ return {
71
+ open, hide,
72
+ get hidden() { return el.hidden; },
73
+ // 谁打开的菜单:同一个按钮再次激活就关闭(键盘激活没有 pointerdown,上面那条规则管不到)。
74
+ get opener() { return opener; },
75
+ };
76
+ }
package/view/preview.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  // 文件预览:只接收路径和读块的能力,不依赖树的状态。readFile 是纯逻辑;mountPreview 才碰 DOM。
2
+ import { h } from './dom.mjs';
2
3
  import { formatSize } from './format.mjs';
3
4
  import { icon, iconFor } from './icons.mjs';
4
5
  import { ContentKind, EntryKind, ErrorCode, IMAGE_LIMIT, TEXT_LIMIT, imageType } from './protocol.mjs';
6
+ import { clippedSelection, linesOf } from './selection.mjs';
5
7
 
6
8
  function fromBase64(data) {
7
9
  const binary = atob(data), bytes = new Uint8Array(binary.length);
@@ -48,20 +50,13 @@ export async function readFile(read, { prev = null, onProgress = () => {}, cance
48
50
  const formatTime = ms => new Date(ms).toLocaleString('zh-CN', { hour12: false });
49
51
  export const lineCount = text => (text === '' ? 1 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0));
50
52
 
51
- const h = (tag, attributes = {}, ...children) => {
52
- const node = document.createElement(tag);
53
- for (const [key, value] of Object.entries(attributes)) {
54
- if (key.startsWith('on')) node.addEventListener(key.slice(2), value); else if (value != null && value !== false) node.setAttribute(key, value);
55
- }
56
- node.append(...children.flat().filter(child => child != null));
57
- return node;
58
- };
59
-
60
53
  // read(path, offset) → Promise<chunk 回答>,会话换了会以 stale 错误拒绝;copy(text) 复制路径。
61
54
  // actions:头部在「复制路径」旁额外加的按钮 [{ label, icon, run(path) }],预览不知道它们做什么。
62
55
  // copyInHead:false 时头部不放「复制路径」(iPhone 放在底部工具条),由页面调 copyPath()。
63
56
  // back:给了就在头部最左边放「返回」(Mac 侧栏预览:原生工具栏项目只能在右侧);文件页和 iPhone 不传。
64
- export function mountPreview(el, { read, copy, actions = [], copyInHead = true, back = null }) {
57
+ // selectionMenu(event, { path, text, startLine, endLine }):给了就接管正文里选中文字的右键(只有 Mac 传);预览不知道菜单里是什么。
58
+ // 选区为空、或裁到正文里之后为空时不接管,走系统默认。内容和行号在这里取好,交出去之后和选区无关。
59
+ export function mountPreview(el, { read, copy, actions = [], copyInHead = true, back = null, selectionMenu = null }) {
65
60
  const name = h('div', { class: 'pname truncate' }), meta = h('div', { class: 'pmeta caption secondary truncate' }, ' ');
66
61
  const fileIcon = h('span', { class: 'pico', 'aria-hidden': 'true' });
67
62
  // 图标按钮:可访问名称和 Mac 的悬停提示都是 label;没有图标的退回文字。
@@ -99,7 +94,9 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
99
94
  setMeta([dir, lines, formatSize(result.size), note].filter(Boolean).join(' · '), `修改于 ${formatTime(result.mtimeMs)}`);
100
95
  if (result.kind === ContentKind.TEXT) {
101
96
  const gutter = h('pre', { class: 'gutter', 'aria-hidden': 'true' }, Array.from({ length: lineCount(result.text) }, (_, i) => i + 1).join('\n'));
102
- body.replaceChildren(h('div', { class: 'code' }, gutter, h('pre', { class: 'text selectable' }, result.text)));
97
+ const text = h('pre', { class: 'text selectable' }, result.text);
98
+ if (selectionMenu) text.addEventListener('contextmenu', event => onSelect(event, text));
99
+ body.replaceChildren(h('div', { class: 'code' }, gutter, text));
103
100
  } else if (result.kind === ContentKind.IMAGE && result.bytes.length > 0) {
104
101
  objectUrl = URL.createObjectURL(new Blob([result.bytes], { type: imageType(path) }));
105
102
  body.replaceChildren(h('div', { class: 'image' }, h('img', { src: objectUrl, alt: path, draggable: 'false' })));
@@ -109,6 +106,13 @@ export function mountPreview(el, { read, copy, actions = [], copyInHead = true,
109
106
  }
110
107
  }
111
108
 
109
+ function onSelect(event, text) {
110
+ const picked = clippedSelection(text);
111
+ if (!picked) return;
112
+ event.preventDefault();
113
+ selectionMenu(event, { path, text: picked.text, ...linesOf(text.textContent, picked.start, picked.start + picked.text.length) });
114
+ }
115
+
112
116
  function failure(error, silent, retry) {
113
117
  if (error.stale) return;
114
118
  if (error.code === ErrorCode.NOT_FOUND) { shown = null; setMeta(' '); return notice('文件已不存在', path); }
package/view/protocol.mjs CHANGED
@@ -11,18 +11,30 @@ export const IMAGE_LIMIT = 8 * 1024 * 1024;
11
11
  // 前这么多字节里有 NUL 就当二进制(照 Coda 判断二进制的惯例)。
12
12
  export const SNIFF_BYTES = 8000;
13
13
  export const REQUEST_ID_MAX = 64;
14
+ // 输入框草稿的文字上限(UTF-16 单元);拼完超过就不写。
15
+ export const DRAFT_LIMIT = 100_000;
14
16
 
15
17
  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
+ HELLO: 'hello', REFRESH: 'refresh', LIST: 'list', READ: 'read', STAT: 'stat', DIR_SIZE: 'dir_size', ADD_TEXT: 'add_text',
19
+ DIR_SIZE_CANCEL: 'dir_size_cancel', // 没有回答
20
+ SESSION: 'session', ROOT: 'root', CHANGED: 'changed',
21
+ LISTED: 'listed', CHUNK: 'chunk', STATTED: 'statted', SIZED: 'sized', ADDED: 'added',
18
22
  });
19
23
 
24
+ // 请求 → 回答的类型。模块回答、页面分发都查这一张。
25
+ export const ReplyOf = Object.freeze({
26
+ [Type.LIST]: Type.LISTED, [Type.READ]: Type.CHUNK, [Type.STAT]: Type.STATTED,
27
+ [Type.DIR_SIZE]: Type.SIZED, [Type.ADD_TEXT]: Type.ADDED,
28
+ });
29
+ export const isReply = type => Object.values(ReplyOf).includes(type);
30
+
20
31
  export const RootState = Object.freeze({ READY: 'ready', NONE: 'none', PREPARING: 'preparing', GONE: 'gone' });
21
32
 
22
33
  export const ErrorCode = Object.freeze({
23
34
  NO_ROOT: 'no_root', INVALID_PATH: 'invalid_path', OUTSIDE_ROOT: 'outside_root', NOT_FOUND: 'not_found',
24
35
  NOT_DIR: 'not_dir', NOT_FILE: 'not_file', DENIED: 'denied', CURSOR_EXPIRED: 'cursor_expired',
25
36
  INVALID_OFFSET: 'invalid_offset', INVALID_SORT: 'invalid_sort', TOO_LARGE: 'too_large', IO: 'io_error',
37
+ DRAFT_FAILED: 'draft_failed', DRAFT_TOO_LONG: 'draft_too_long',
26
38
  });
27
39
 
28
40
  // 目录排序:值是下面四种之一,缺省(请求不带 sort)是名称。方向由排序键决定,只在 lib/tree.mjs 里定义一处。
@@ -0,0 +1,33 @@
1
+ // 预览里选中的文字:裁到正文元素里面,算出覆盖的行。DOM 的部分只用 Range 的标准方法,行号是纯函数。
2
+ const START_TO_START = 0, END_TO_END = 2; // Range.START_TO_START、Range.END_TO_END
3
+
4
+ // el 是正文(一个 pre 加一个文本节点)。选区为空或和 el 不相交返回 null;
5
+ // 否则把选区裁到 el 里,返回 { text, start }:裁剪后的文字和它在 el 文字里的起点(UTF-16 偏移)。裁剪后为空也返回 null。
6
+ // 选区的起点或终点落在 el 外面(跨出正文、从行号列开始拖)时,裁掉外面的部分。
7
+ export function clippedSelection(el, selection = globalThis.getSelection?.()) {
8
+ if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null;
9
+ const range = selection.getRangeAt(0);
10
+ if (!range.intersectsNode(el)) return null;
11
+ const whole = document.createRange();
12
+ whole.selectNodeContents(el);
13
+ const clipped = range.cloneRange();
14
+ if (range.compareBoundaryPoints(START_TO_START, whole) < 0) clipped.setStart(whole.startContainer, whole.startOffset);
15
+ if (range.compareBoundaryPoints(END_TO_END, whole) > 0) clipped.setEnd(whole.endContainer, whole.endOffset);
16
+ const text = clipped.toString();
17
+ if (text === '') return null;
18
+ const before = whole.cloneRange();
19
+ before.setEnd(clipped.startContainer, clipped.startOffset);
20
+ return { text, start: before.toString().length };
21
+ }
22
+
23
+ const lineAt = (text, offset) => {
24
+ let line = 1;
25
+ for (let at = text.indexOf('\n'); at !== -1 && at < offset; at = text.indexOf('\n', at + 1)) line++;
26
+ return line;
27
+ };
28
+
29
+ // 选中 text[start, end) 覆盖的行(从 1 数)。选区的结尾正好在行首时(如三击选行,选区包含那一行的换行)不算下一行。
30
+ export function linesOf(text, start, end) {
31
+ const last = end > start && text[end - 1] === '\n' ? end - 1 : end;
32
+ return { startLine: lineAt(text, start), endLine: lineAt(text, Math.max(start, last)) };
33
+ }
package/view/style.css CHANGED
@@ -1,4 +1,5 @@
1
- /* 资源管理器的页面,颜色、字体、字号只用 App 给的 --coda-* 变量(插件视图的主题变量)。 */
1
+ /* 资源管理器的页面,颜色、字体、字号只用 App 给的 --coda-* 变量(插件视图的主题变量)。
2
+ 唯一的例外是下面的 --tone-*:种类图标的色调,主题变量里没有这一组。 */
2
3
  :root {
3
4
  --hover: var(--coda-hover, var(--coda-fill, rgba(0,0,0,.05)));
4
5
  --line: var(--coda-separator, rgba(0,0,0,.1));
@@ -10,6 +11,20 @@
10
11
  font: var(--coda-font-size, 13px)/1.45 var(--coda-font, -apple-system, system-ui, sans-serif);
11
12
  color: var(--coda-foreground, #1d1d1f); background: transparent;
12
13
  }
14
+ /* 种类图标的色调。图标是 currentColor,.tone-* 把颜色给到 svg 上;文件夹用强调色,链接和特殊文件没有色调,跟随三级文字色。
15
+ 两种外观下,在 --coda-background 和 --coda-card 上的对比度都不低于 3:1(harness 读真实计算值检查);改色值要重新跑。 */
16
+ :root {
17
+ --tone-gray: #6b6b72; --tone-blue: #2a68b8; --tone-yellow: #946a00; --tone-green: #26803f; --tone-teal: #12788f;
18
+ --tone-orange: #b85a14; --tone-red: #c0303a; --tone-purple: #7447bd; --tone-pink: #b8326f;
19
+ }
20
+ :root.coda-dark {
21
+ --tone-gray: #a3a3a9; --tone-blue: #6aa9ec; --tone-yellow: #e3b63e; --tone-green: #63c77f; --tone-teal: #58c3dd;
22
+ --tone-orange: #f0964f; --tone-red: #f0717a; --tone-purple: #ac87ec; --tone-pink: #ee77ac;
23
+ }
24
+ .tone-accent { color: var(--coda-accent, #0a84ff); }
25
+ .tone-gray { color: var(--tone-gray); } .tone-blue { color: var(--tone-blue); } .tone-yellow { color: var(--tone-yellow); }
26
+ .tone-green { color: var(--tone-green); } .tone-teal { color: var(--tone-teal); } .tone-orange { color: var(--tone-orange); }
27
+ .tone-red { color: var(--tone-red); } .tone-purple { color: var(--tone-purple); } .tone-pink { color: var(--tone-pink); }
13
28
  * { box-sizing: border-box; }
14
29
  html, body { margin: 0; height: 100%; }
15
30
  body { display: flex; flex-direction: column; overflow: hidden; -webkit-user-select: none; user-select: none;
@@ -31,7 +46,7 @@ p { margin: 0; }
31
46
  .pane.off { visibility: hidden; pointer-events: none; }
32
47
  .empty { display: grid; align-content: start; justify-items: center; gap: 6px; padding: 32px 20px; text-align: center; }
33
48
  .notice-icon { display: grid; place-items: center; margin-bottom: 6px; color: var(--coda-secondary, #6e6e73); }
34
- .notice-icon svg { display: block; }
49
+ .notice-icon svg { display: block; color: inherit; } /* 说明区的图标不上色 */
35
50
 
36
51
  /* 页内工具条:iPhone 树页在顶部(返回、根目录名、⋯),文件页在底部(.bottom:返回、刷新、复制路径)。没有 coda.toolbar 的其他平台(harness)是一条文字按钮。 */
37
52
  .bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
@@ -53,6 +68,10 @@ p { margin: 0; }
53
68
  .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));
54
69
  border-radius: var(--coda-radius, 6px); white-space: nowrap; cursor: default; }
55
70
  .row.sel { background: var(--coda-selection, var(--hover)); }
71
+ /* Mac 的缩进线:每一层一条,在祖先箭头(14 点宽)的中心,按行的 --d 画重复渐变,不增加 DOM。
72
+ 用 ::after(::before 是 iPhone 的分隔线),画在行背景的上面,悬停、选中的 background 盖不掉。 */
73
+ .coda-mac .row::after { content: ''; position: absolute; top: 0; bottom: 0; left: calc(var(--pad) + 6.5px); width: calc(var(--indent) * var(--d, 0)); pointer-events: none;
74
+ background: repeating-linear-gradient(to right, var(--coda-separator, var(--line)) 0 1px, transparent 1px var(--indent)); }
56
75
  .row.more, .row.retry { color: var(--coda-accent, #0a84ff); cursor: pointer; }
57
76
  .row.status { display: block; overflow: hidden; text-overflow: ellipsis; line-height: var(--row-h); color: var(--coda-secondary, #6e6e73); }
58
77
  .row.dead .name, .row.dead .ico { color: var(--coda-tertiary, #a1a1a6); }
@@ -93,7 +112,9 @@ button.icon svg { display: block; }
93
112
 
94
113
  #notice:focus { outline: none; }
95
114
  .menu { position: fixed; z-index: 10; width: max-content; max-width: min(280px, calc(100vw - var(--safe-left) - var(--safe-right) - 8px)); padding: 4px; border: 1px solid var(--coda-outline, var(--line)); border-radius: var(--coda-radius-card, 10px);
96
- background: var(--coda-card, var(--coda-background, #fff)); }
115
+ background: var(--coda-card, var(--coda-background, #fff));
116
+ /* 高度有上限:内容多(长路径加五项)时在菜单里滚动,不超出安全区;位置由 menu.mjs 夹在安全区内。 */
117
+ max-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 8px); overflow-y: auto; overscroll-behavior: contain; }
97
118
  .menu button { display: flex; align-items: center; gap: 6px; width: 100%; padding: 5px 10px; border-radius: var(--coda-radius, 6px); }
98
119
  .check { flex: none; display: grid; place-items: center; width: 16px; color: var(--coda-accent, #0a84ff); }
99
120
  .check svg { display: block; }
@@ -104,9 +125,20 @@ button.icon svg { display: block; }
104
125
  .menu-head { padding: 4px 10px 2px; font-weight: 600; }
105
126
  .pmeta.warn { color: var(--coda-orange, #b25000); }
106
127
 
128
+ /* 底部的短提示:普通的是前景色(成功),.warn 是橙色(失败)。 */
107
129
  .hint { position: fixed; left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); bottom: calc(8px + var(--safe-bottom)); z-index: 10;
108
130
  padding: 8px 12px; border: 1px solid var(--coda-outline, var(--line)); border-radius: var(--coda-radius-card, 10px);
109
- background: var(--coda-card, var(--coda-background, #fff)); color: var(--coda-orange, #b25000); }
131
+ background: var(--coda-card, var(--coda-background, #fff)); color: var(--coda-foreground, #1d1d1f); }
132
+ .hint.warn { color: var(--coda-orange, #b25000); }
133
+
134
+ /* 属性页:头部和正文同预览(.preview 的 .phead、.pbody);正文是 标签 值 两列,值可以折行、可以选中。 */
135
+ .ibody { padding: 8px 12px calc(12px + var(--safe-bottom)); }
136
+ .irow { display: flex; gap: 12px; padding: 5px 0; }
137
+ .ilabel { flex: none; width: 5.5em; text-align: right; }
138
+ .ivalue { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
139
+ .ivalue .warn { color: var(--coda-orange, #b25000); }
140
+ .coda-ios .irow { flex-direction: column; gap: 0; padding: 8px 4px; }
141
+ .coda-ios .ilabel { width: auto; text-align: left; font-size: .85em; }
110
142
 
111
143
  /* 悬停只在有鼠标时:触摸后不会留着。 */
112
144
  @media (hover: hover) {
@@ -135,7 +167,7 @@ button.icon svg { display: block; }
135
167
  .coda-ios .meta { display: none; }
136
168
  .coda-ios .chev { order: 9; width: 14px; }
137
169
  .coda-ios .row.dir .chev { color: var(--coda-accent, #0a84ff); }
138
- .coda-ios .row.file .chev svg { visibility: visible; }
170
+ .coda-ios .row.file .chev svg { visibility: inherit; } /* 不写 visible:目录树被属性页盖住(visibility: hidden)时,箭头不能透出来 */
139
171
  .coda-ios .row.dead .chev { display: none; }
140
172
  .coda-ios button { min-height: 44px; min-width: 44px; }
141
173
  .coda-ios .bar { gap: 0; padding: 0 8px; }
@@ -150,5 +182,5 @@ button.icon svg { display: block; }
150
182
  .coda-ios .menu-head { padding: 6px 12px 2px; }
151
183
 
152
184
  /* 横屏:客户端隐藏导航栏,页面自己给返回。近似 verticalSizeClass 的判断,不等价(iPad、Duo 不单独适配)。 */
153
- .bar .exit { display: none; }
154
- @media (orientation: landscape) and (max-height: 500px) { .coda-ios .bar .exit { display: inline-flex; } }
185
+ .bar .exit, .bar.exit-only { display: none; } /* 只有返回的工具条(属性页):返回不显示,整条也不占高度 */
186
+ @media (orientation: landscape) and (max-height: 500px) { .coda-ios .bar .exit { display: inline-flex; } .coda-ios .bar.exit-only { display: flex; } }