dsh-ui-font-scale 0.0.0-stage → 1.2.2

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 CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # 界面字号 (dsh-ui-font-scale)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 把 DSH 的界面整体放大一档:侧边栏、设置、菜单、按钮、标签、标题栏的文字、行高和小控件高度都会变大,
4
+ 但会话正文仍由「通用设置 → 字号大小」控制,不会被这个插件改写。
5
+
6
+ ## 为什么需要它
7
+
8
+ DSH 目前只提供会话内容的字号设置。界面本身的字号和行高来自组件样式,没有单独的调节项;
9
+ 这个插件把界面基准字号从 `13px` 调到 `14px`(默认,约 1.077 倍),并按同一比例重写界面样式中的
10
+ 字号、行高以及较小的纵向尺寸(按钮/输入框高度、上下内边距),因此不需要修改应用安装包,
11
+ 也不会影响后续升级。横向宽度保持不变。
12
+
13
+ ## 使用
14
+
15
+ 安装并重启 DSH 后立即生效。打开「设置 → 通用设置」,在「字号大小」下方会多出一行
16
+ 「界面字号」,可选 13px / 14px / 15px / 16px,默认 14px。
17
+ 选择后立即生效,并会记住上次的选择。
18
+
19
+ 也可以在开发者工具控制台调整(会保存在本机):
20
+
21
+ ```js
22
+ __dshUiFontScale.setSize(15) // 再大一点
23
+ __dshUiFontScale.setSize(14) // 恢复默认的一档
24
+ __dshUiFontScale.disable() // 关闭缩放,恢复原始界面
25
+ __dshUiFontScale.enable() // 重新开启
26
+ ```
27
+
28
+ ## 安装
29
+
30
+ 在 DSH 中打开「设置 → 插件 → 添加插件」,输入包名 `dsh-ui-font-scale` 并安装(插件市场里搜索「界面字号」也可以)。安装完成后重启 DSH,再进入「设置 → 通用设置 → 界面字号」调整。
31
+
32
+ 开发调试时也可以克隆源码,用本地目录安装;这种方式会链接到本地目录,目录不能删除,只建议开发时使用。
33
+
34
+ 插件按 DSH `0.2.2-rc.5`(桌面端 `2.0.24-next`)的界面结构编写;DSH 大版本更新后如果界面 token 或插槽改名,可能需要同步调整。
35
+
36
+ ## 边界
37
+
38
+ - 同步调整字号、行高和较小的纵向尺寸(高度、上下内边距),横向宽度和会话正文保持不变。
39
+ - 不修改会话正文:正文继续使用 DSH 的 `--dsh-content-font-size`。
40
+ - 为避免破坏布局,只处理较小的固定像素值:行高 ≤ 48px、高度 ≤ 80px、上下间距 ≤ 32px;
41
+ 百分比、`calc()`、`em` 等相对值不处理。
42
+ - 极少数使用固定像素宽度并截断文本的标签可能更早出现省略号。
43
+ - 固定高度且内容不可滚动的第三方控件,在 16px 时可能出现轻微裁切。
44
+
45
+ ## 卸载
46
+
47
+ 在「设置 → 插件」中移除本插件并重启 DSH 即可恢复原始界面。
package/client.js ADDED
@@ -0,0 +1,600 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-ui-font-scale',
3
+ factory(require) {
4
+ 'use strict';
5
+
6
+ const React = require('react');
7
+ const BASE_FONT_SIZE = 13;
8
+ const FONT_SIZES = [13, 14, 15, 16];
9
+ const DEFAULT_FONT_SIZE = 14;
10
+ const DEFAULT_SCALE = DEFAULT_FONT_SIZE / BASE_FONT_SIZE;
11
+ const MIN_SCALE = 1;
12
+ const MAX_SCALE = FONT_SIZES[FONT_SIZES.length - 1] / BASE_FONT_SIZE;
13
+ const STORAGE_KEY = 'dsh-ui-font-scale:factor';
14
+
15
+ function scaleForSize(size) {
16
+ return size / BASE_FONT_SIZE;
17
+ }
18
+
19
+ function sizeForScale(scale) {
20
+ const pixels = BASE_FONT_SIZE * scale;
21
+ let nearest = FONT_SIZES[0];
22
+ for (const size of FONT_SIZES) {
23
+ if (Math.abs(size - pixels) < Math.abs(nearest - pixels)) nearest = size;
24
+ }
25
+ return nearest;
26
+ }
27
+
28
+ const TOKEN_NAMES = [
29
+ 'xl-24',
30
+ 'l-20',
31
+ 'm-18',
32
+ 'base-16',
33
+ 'base-strong-16',
34
+ 's-14',
35
+ 's-strong-14',
36
+ 'xs-13',
37
+ 'xs-strong-13',
38
+ 'xxs-12',
39
+ 'xxs-strong-12',
40
+ 'xxxs-11',
41
+ 'xxxs-strong-11',
42
+ ];
43
+
44
+ const TOKEN_FALLBACKS = {
45
+ 'xl-24': '600 24px/32px var(--dsw-font-family)',
46
+ 'l-20': '500 20px/28px var(--dsw-font-family)',
47
+ 'm-18': '500 16px/28px var(--dsw-font-family)',
48
+ 'base-16': '16px/24px var(--dsw-font-family)',
49
+ 'base-strong-16': '500 16px/24px var(--dsw-font-family)',
50
+ 's-14': '14px/22px var(--dsw-font-family)',
51
+ 's-strong-14': '500 14px/22px var(--dsw-font-family)',
52
+ 'xs-13': '13px/20px var(--dsw-font-family)',
53
+ 'xs-strong-13': '500 13px/20px var(--dsw-font-family)',
54
+ 'xxs-12': '12px/18px var(--dsw-font-family)',
55
+ 'xxs-strong-12': '500 12px/18px var(--dsw-font-family)',
56
+ 'xxxs-11': '11px/14px var(--dsw-font-family)',
57
+ 'xxxs-strong-11': '500 11px/14px var(--dsw-font-family)',
58
+ };
59
+
60
+ const VERTICAL_PROPERTIES = [
61
+ 'line-height',
62
+ 'height',
63
+ 'min-height',
64
+ 'max-height',
65
+ 'padding-top',
66
+ 'padding-bottom',
67
+ 'margin-top',
68
+ 'margin-bottom',
69
+ ];
70
+
71
+ const CONTENT_SELECTOR = /\.markdown\b|\[data-conversation|\.md-|\.code(?:_|\.|\b)|\.codeBlock/i;
72
+ const CHROME_SELECTOR = /titlebar|window-controls|windowControls|data-windows-titlebar|scrollbar/i;
73
+
74
+ function clampScale(value) {
75
+ const number = Number(value);
76
+ if (!Number.isFinite(number)) return DEFAULT_SCALE;
77
+ return Math.min(MAX_SCALE, Math.max(MIN_SCALE, Math.round(number * 1000) / 1000));
78
+ }
79
+
80
+ function readState() {
81
+ try {
82
+ const raw = window.localStorage.getItem(STORAGE_KEY);
83
+ if (raw === 'off') return { scale: DEFAULT_SCALE, disabled: true };
84
+ if (raw !== null && raw !== '') return { scale: clampScale(raw), disabled: false };
85
+ } catch (error) {
86
+ /* Storage can be unavailable; the default still applies. */
87
+ }
88
+ return { scale: DEFAULT_SCALE, disabled: false };
89
+ }
90
+
91
+ const initial = readState();
92
+ let factor = initial.scale;
93
+ let disabled = initial.disabled;
94
+ let observer;
95
+ let scanTimer;
96
+ let retryTimer;
97
+ let scheduled = [];
98
+ let installed = false;
99
+
100
+ const ruleOriginals = new Map();
101
+ const tokenOriginals = new Map();
102
+ const verticalOriginals = new Map();
103
+
104
+ function formatPx(value) {
105
+ const rounded = Math.round(value * 100) / 100;
106
+ if (Number.isInteger(rounded)) return `${rounded}px`;
107
+ return `${String(rounded).replace(/0+$/, '').replace(/\.$/, '')}px`;
108
+ }
109
+
110
+ function hasContentVariable(value) {
111
+ return /var\(\s*--dsh-(?:content|code|terminal)-/i.test(value);
112
+ }
113
+
114
+ /** Scale every px length in a font-size-like value, preserving other units. */
115
+ function scalePxText(value) {
116
+ if (typeof value !== 'string' || value === '' || hasContentVariable(value)) return value;
117
+ return value.replace(/(-?(?:\d+\.?\d*|\.\d+))px\b/gi, (match, number) => {
118
+ const amount = Number(number);
119
+ if (!Number.isFinite(amount) || amount === 0) return match;
120
+ return formatPx(amount * factor);
121
+ });
122
+ }
123
+
124
+ /** A font shorthand owns a size and an optional /line-height; scale both. */
125
+ function scaleFontShorthand(value) {
126
+ if (typeof value !== 'string' || value === '' || hasContentVariable(value)) return value;
127
+ return value.replace(/(-?(?:\d+\.?\d*|\.\d+))px\b/gi, (match, number) => {
128
+ const amount = Number(number);
129
+ if (!Number.isFinite(amount) || amount === 0) return match;
130
+ return formatPx(amount * factor);
131
+ });
132
+ }
133
+
134
+ function restoreProperty(style, property, value, priority) {
135
+ if (value) style.setProperty(property, value, priority);
136
+ else style.removeProperty(property);
137
+ }
138
+
139
+ function parseSinglePx(value) {
140
+ const match = /^(-?(?:\d+\.?\d*|\.\d+))px$/i.exec(String(value || '').trim());
141
+ return match === null ? null : Number(match[1]);
142
+ }
143
+
144
+ function verticalLimit(property) {
145
+ if (property === 'line-height') return 48;
146
+ if (property === 'height' || property === 'min-height' || property === 'max-height') return 80;
147
+ return 32;
148
+ }
149
+
150
+ function skipVerticalRule(rule) {
151
+ const selector = rule.selectorText || '';
152
+ if (selector === '') return true;
153
+ if (CONTENT_SELECTOR.test(selector) || CHROME_SELECTOR.test(selector)) return true;
154
+ return /^(?:\*|html|body|:root|#root)(?:\b|$)/i.test(selector.trim());
155
+ }
156
+
157
+ function savedVertical(rule, property) {
158
+ const saved = verticalOriginals.get(rule);
159
+ return saved === undefined ? undefined : saved.get(property);
160
+ }
161
+
162
+ function rememberVertical(rule, property, style, value) {
163
+ let saved = verticalOriginals.get(rule);
164
+ if (saved === undefined) {
165
+ saved = new Map();
166
+ verticalOriginals.set(rule, saved);
167
+ }
168
+ if (!saved.has(property)) saved.set(property, { value, priority: style.getPropertyPriority(property) });
169
+ return saved.get(property);
170
+ }
171
+
172
+ function scaleVerticalValue(value) {
173
+ const amount = parseSinglePx(value);
174
+ if (amount === null || amount === 0) return null;
175
+ return formatPx(amount * factor);
176
+ }
177
+
178
+ function scaleSquareWidth(rule, style, height) {
179
+ const saved = savedVertical(rule, 'width');
180
+ const raw = saved === undefined ? style.getPropertyValue('width') : saved.value;
181
+ const width = parseSinglePx(raw);
182
+ if (width === null || Math.abs(width) <= 1 || Math.abs(width) > 80) return;
183
+ if (Math.abs(Math.abs(width) - Math.abs(height)) > 1) return;
184
+ const original = saved === undefined ? rememberVertical(rule, 'width', style, raw) : saved;
185
+ style.setProperty('width', scaleVerticalValue(original.value), original.priority);
186
+ }
187
+
188
+ function scaleVertical(rule, style, property) {
189
+ const saved = savedVertical(rule, property);
190
+ if (saved === undefined) {
191
+ const raw = style.getPropertyValue(property);
192
+ if (raw === '' || hasContentVariable(raw)) return;
193
+ const amount = parseSinglePx(raw);
194
+ if (amount === null || Math.abs(amount) <= 1 || Math.abs(amount) > verticalLimit(property)) return;
195
+ rememberVertical(rule, property, style, raw);
196
+ return;
197
+ }
198
+ if (!saved.value) return;
199
+ style.setProperty(property, scaleVerticalValue(saved.value), saved.priority);
200
+ if (property === 'height') {
201
+ const height = parseSinglePx(saved.value);
202
+ if (height !== null) scaleSquareWidth(rule, style, height);
203
+ }
204
+ }
205
+
206
+ function scaleRule(rule) {
207
+ const style = rule.style;
208
+ if (!style) return;
209
+
210
+ let original = ruleOriginals.get(rule);
211
+ if (original === undefined) {
212
+ const font = style.getPropertyValue('font');
213
+ const fontSize = style.getPropertyValue('font-size');
214
+ if (font || fontSize) {
215
+ original = {
216
+ font,
217
+ fontPriority: style.getPropertyPriority('font'),
218
+ fontSize,
219
+ fontSizePriority: style.getPropertyPriority('font-size'),
220
+ };
221
+ ruleOriginals.set(rule, original);
222
+ }
223
+ }
224
+
225
+ const vertical = !skipVerticalRule(rule);
226
+ if (vertical) {
227
+ for (const property of VERTICAL_PROPERTIES) scaleVertical(rule, style, property);
228
+ }
229
+
230
+ if (original !== undefined) {
231
+ if (original.font) style.setProperty('font', scaleFontShorthand(original.font), original.fontPriority);
232
+ if (original.fontSize) style.setProperty('font-size', scalePxText(original.fontSize), original.fontSizePriority);
233
+ }
234
+
235
+ if (vertical) {
236
+ for (const property of VERTICAL_PROPERTIES) scaleVertical(rule, style, property);
237
+ }
238
+ }
239
+
240
+ function walkRules(rules) {
241
+ if (!rules) return;
242
+ for (let index = 0; index < rules.length; index += 1) {
243
+ const rule = rules[index];
244
+ try {
245
+ if (rule.type === 1) scaleRule(rule);
246
+ if (rule.cssRules && rule.cssRules.length) walkRules(rule.cssRules);
247
+ else if (rule.styleSheet) walkRules(rule.styleSheet.cssRules);
248
+ } catch (error) {
249
+ /* A single inaccessible rule must not stop the scan. */
250
+ }
251
+ }
252
+ }
253
+
254
+ function applyTokens() {
255
+ const body = document.body;
256
+ if (!body) return;
257
+ const computed = window.getComputedStyle(body);
258
+ for (const name of TOKEN_NAMES) {
259
+ const property = `--dsw-font-${name}`;
260
+ let original = tokenOriginals.get(property);
261
+ if (original === undefined) {
262
+ original = computed.getPropertyValue(property).trim() || TOKEN_FALLBACKS[name];
263
+ if (!original) continue;
264
+ tokenOriginals.set(property, original);
265
+ }
266
+ const scaled = scaleFontShorthand(original);
267
+ body.style.setProperty(property, scaled, 'important');
268
+ const size = scaled.match(/(-?(?:\d+\.?\d*|\.\d+))px\b/);
269
+ if (size) {
270
+ const sizeProperty = `${property}-font-size`;
271
+ if (!tokenOriginals.has(sizeProperty)) {
272
+ tokenOriginals.set(sizeProperty, computed.getPropertyValue(sizeProperty).trim() || `${size[1]}px`);
273
+ }
274
+ body.style.setProperty(sizeProperty, formatPx(Number(size[1])), 'important');
275
+ }
276
+ const lineHeight = scaled.match(/\/\s*(-?(?:\d+\.?\d*|\.\d+))px/);
277
+ if (lineHeight) {
278
+ const lineHeightProperty = `${property}-line-height`;
279
+ if (!tokenOriginals.has(lineHeightProperty)) {
280
+ tokenOriginals.set(lineHeightProperty, computed.getPropertyValue(lineHeightProperty).trim() || `${lineHeight[1]}px`);
281
+ }
282
+ body.style.setProperty(lineHeightProperty, formatPx(Number(lineHeight[1])), 'important');
283
+ }
284
+ }
285
+ }
286
+
287
+ function scan() {
288
+ if (disabled || !document.body) return;
289
+ const sheets = Array.from(document.styleSheets);
290
+ for (const sheet of sheets) {
291
+ try {
292
+ if (sheet.disabled) continue;
293
+ walkRules(sheet.cssRules);
294
+ } catch (error) {
295
+ /* Cross-origin and still-loading sheets are skipped. */
296
+ }
297
+ }
298
+ applyTokens();
299
+ document.documentElement.dataset.dshUiFontScale = String(factor);
300
+ document.documentElement.style.setProperty('--dsh-ui-scale', String(factor));
301
+ }
302
+
303
+ function scheduleScan() {
304
+ if (disabled) return;
305
+ window.clearTimeout(scanTimer);
306
+ scanTimer = window.setTimeout(scan, 60);
307
+ }
308
+
309
+ function onResourceLoad(event) {
310
+ const target = event.target;
311
+ if (target && (target.tagName === 'LINK' || target.tagName === 'STYLE')) scheduleScan();
312
+ }
313
+
314
+ function startObserver() {
315
+ if (observer !== undefined) return;
316
+ observer = new MutationObserver(scheduleScan);
317
+ observer.observe(document.head, { childList: true, subtree: true });
318
+ document.addEventListener('load', onResourceLoad, true);
319
+ }
320
+
321
+ function restore() {
322
+ for (const [rule, original] of ruleOriginals) {
323
+ try {
324
+ restoreProperty(rule.style, 'font', original.font, original.fontPriority);
325
+ restoreProperty(rule.style, 'font-size', original.fontSize, original.fontSizePriority);
326
+ } catch (error) {
327
+ /* A detached rule is already inert. */
328
+ }
329
+ }
330
+ ruleOriginals.clear();
331
+
332
+ for (const [rule, saved] of verticalOriginals) {
333
+ try {
334
+ for (const [property, original] of saved) {
335
+ restoreProperty(rule.style, property, original.value, original.priority);
336
+ }
337
+ } catch (error) {
338
+ /* A detached rule is already inert. */
339
+ }
340
+ }
341
+ verticalOriginals.clear();
342
+
343
+ const body = document.body;
344
+ if (body) {
345
+ for (const property of tokenOriginals.keys()) body.style.removeProperty(property);
346
+ }
347
+ tokenOriginals.clear();
348
+ delete document.documentElement.dataset.dshUiFontScale;
349
+ document.documentElement.style.removeProperty('--dsh-ui-scale');
350
+ }
351
+
352
+ function setSize(size) {
353
+ return setScale(scaleForSize(size));
354
+ }
355
+
356
+ function setScale(next) {
357
+ factor = clampScale(next);
358
+ disabled = false;
359
+ try {
360
+ window.localStorage.setItem(STORAGE_KEY, String(factor));
361
+ } catch (error) {
362
+ /* Keep the in-memory choice when storage is unavailable. */
363
+ }
364
+ restore();
365
+ scan();
366
+ startObserver();
367
+ announce();
368
+ return factor;
369
+ }
370
+
371
+ function enable() {
372
+ if (!disabled) return factor;
373
+ disabled = false;
374
+ try {
375
+ window.localStorage.setItem(STORAGE_KEY, String(factor));
376
+ } catch (error) {
377
+ /* Keep the in-memory choice when storage is unavailable. */
378
+ }
379
+ scan();
380
+ startObserver();
381
+ announce();
382
+ return factor;
383
+ }
384
+
385
+ function disable() {
386
+ disabled = true;
387
+ try {
388
+ window.localStorage.setItem(STORAGE_KEY, 'off');
389
+ } catch (error) {
390
+ /* The current page still restores. */
391
+ }
392
+ restore();
393
+ announce();
394
+ return factor;
395
+ }
396
+
397
+ function announce() {
398
+ try {
399
+ window.dispatchEvent(new CustomEvent('dsh-ui-font-scale', {
400
+ detail: { scale: factor, size: sizeForScale(factor) },
401
+ }));
402
+ } catch (error) {
403
+ /* Older embedded browsers may lack CustomEvent. */
404
+ }
405
+ }
406
+
407
+ function rowText() {
408
+ const language = (document.documentElement.getAttribute('lang') || navigator.language || 'zh').toLowerCase();
409
+ if (language.indexOf('zh') === 0) {
410
+ return {
411
+ title: '界面字号',
412
+ description: '界面文字与控件整体放大,不影响会话内容。',
413
+ suffix: '(默认)',
414
+ };
415
+ }
416
+ return {
417
+ title: 'Interface font size',
418
+ description: 'Scales interface text, line height and control size; conversation text stays unchanged.',
419
+ suffix: ' (default)',
420
+ };
421
+ }
422
+
423
+ const rowStyle = {
424
+ display: 'flex',
425
+ alignItems: 'center',
426
+ gap: 'calc(8px * var(--dsh-ui-scale, 1))',
427
+ padding: 'calc(16px * var(--dsh-ui-scale, 1)) 0',
428
+ borderBottom: '0.5px solid var(--dsw-alias-border-l2)',
429
+ };
430
+ const rowTextStyle = {
431
+ flex: '1 1 auto',
432
+ minWidth: 0,
433
+ display: 'flex',
434
+ flexDirection: 'column',
435
+ gap: 'calc(4px * var(--dsh-ui-scale, 1))',
436
+ paddingRight: '24px',
437
+ };
438
+ const titleStyle = {
439
+ fontSize: 'var(--dsw-font-s-14-font-size, 14px)',
440
+ fontWeight: 400,
441
+ lineHeight: 'var(--dsw-font-s-14-line-height, 22px)',
442
+ color: 'var(--dsw-alias-label-primary)',
443
+ };
444
+ const descriptionStyle = {
445
+ fontSize: 'var(--dsw-font-xxs-12-font-size, 12px)',
446
+ fontWeight: 400,
447
+ lineHeight: 'var(--dsw-font-xxs-12-line-height, 18px)',
448
+ color: 'var(--dsw-alias-label-tertiary)',
449
+ textWrap: 'pretty',
450
+ };
451
+ const selectStyle = {
452
+ flex: 'none',
453
+ height: 'calc(36px * var(--dsh-ui-scale, 1))',
454
+ padding: '0 calc(12px * var(--dsh-ui-scale, 1))',
455
+ border: 'none',
456
+ borderRadius: 'var(--dsw-radius-md)',
457
+ background: 'var(--dsw-alias-bg-module-platform)',
458
+ color: 'var(--dsw-alias-label-primary)',
459
+ fontFamily: 'inherit',
460
+ fontSize: 'var(--dsw-font-s-14-font-size, 14px)',
461
+ lineHeight: 'var(--dsw-font-s-14-line-height, 22px)',
462
+ cursor: 'pointer',
463
+ };
464
+
465
+ function createSettingsRow() {
466
+ return function SettingsRow() {
467
+ const api = window.__dshUiFontScale;
468
+ const [value, setValue] = React.useState(() => sizeForScale(api ? api.scale : DEFAULT_SCALE));
469
+ const text = rowText();
470
+ const onChange = (event) => {
471
+ const next = Number(event.currentTarget.value);
472
+ const applied = api ? api.set(scaleForSize(next)) : scaleForSize(next);
473
+ setValue(sizeForScale(applied));
474
+ };
475
+ const baseId = React.useId();
476
+ const titleId = `${baseId}-title`;
477
+ const descriptionId = `${baseId}-description`;
478
+ React.useEffect(() => {
479
+ const onScale = (event) => {
480
+ const next = event && event.detail ? event.detail.scale : undefined;
481
+ if (typeof next === 'number') setValue(sizeForScale(next));
482
+ };
483
+ window.addEventListener('dsh-ui-font-scale', onScale);
484
+ return () => window.removeEventListener('dsh-ui-font-scale', onScale);
485
+ }, []);
486
+ return React.createElement(
487
+ 'div',
488
+ { style: rowStyle },
489
+ React.createElement(
490
+ 'div',
491
+ { style: rowTextStyle },
492
+ React.createElement('div', { id: titleId, style: titleStyle }, text.title),
493
+ React.createElement('div', { id: descriptionId, style: descriptionStyle }, text.description),
494
+ ),
495
+ React.createElement(
496
+ 'select',
497
+ {
498
+ value: String(value),
499
+ onChange,
500
+ style: selectStyle,
501
+ 'aria-labelledby': titleId,
502
+ 'aria-describedby': descriptionId,
503
+ },
504
+ FONT_SIZES.map((size) => React.createElement(
505
+ 'option',
506
+ { key: size, value: String(size) },
507
+ `${size}px${size === DEFAULT_FONT_SIZE ? text.suffix : ''}`,
508
+ )),
509
+ ),
510
+ );
511
+ };
512
+ }
513
+
514
+ const SettingsRow = createSettingsRow();
515
+
516
+ function start() {
517
+ if (!document.body) {
518
+ retryTimer = window.setTimeout(start, 50);
519
+ return;
520
+ }
521
+ scan();
522
+ if (disabled) return;
523
+ startObserver();
524
+ for (const delay of [0, 250, 1000, 3000]) {
525
+ scheduled.push(window.setTimeout(scheduleScan, delay));
526
+ }
527
+ }
528
+
529
+ function install() {
530
+ if (installed) return () => {};
531
+ installed = true;
532
+
533
+ Object.defineProperty(window, '__dshUiFontScale', {
534
+ configurable: true,
535
+ value: {
536
+ installed: true,
537
+ get scale() {
538
+ return factor;
539
+ },
540
+ get size() {
541
+ return sizeForScale(factor);
542
+ },
543
+ get sizes() {
544
+ return FONT_SIZES.slice();
545
+ },
546
+ get disabled() {
547
+ return disabled;
548
+ },
549
+ set: setScale,
550
+ setSize,
551
+ enable,
552
+ disable,
553
+ rescan: scan,
554
+ },
555
+ });
556
+
557
+ start();
558
+
559
+ return () => {
560
+ installed = false;
561
+ window.clearTimeout(scanTimer);
562
+ window.clearTimeout(retryTimer);
563
+ for (const handle of scheduled) window.clearTimeout(handle);
564
+ scheduled = [];
565
+ if (observer !== undefined) {
566
+ observer.disconnect();
567
+ observer = undefined;
568
+ }
569
+ document.removeEventListener('load', onResourceLoad, true);
570
+ restore();
571
+ delete window.__dshUiFontScale;
572
+ };
573
+ }
574
+
575
+ return {
576
+ inject: ['slots'],
577
+ apply(ctx) {
578
+ let dispose;
579
+ try {
580
+ dispose = install();
581
+ } catch (error) {
582
+ console.error('[dsh-ui-font-scale] failed to start', error);
583
+ return;
584
+ }
585
+ if (typeof ctx.effect === 'function') ctx.effect(() => dispose);
586
+ else window.addEventListener('pagehide', dispose, { once: true });
587
+
588
+ try {
589
+ ctx.slots.inject('settings.general.item', () => ctx.slots.register({
590
+ name: 'settings.general.item',
591
+ id: 'ui-font-scale',
592
+ order: 11.5,
593
+ }, SettingsRow));
594
+ } catch (error) {
595
+ console.error('[dsh-ui-font-scale] failed to register settings row', error);
596
+ }
597
+ },
598
+ };
599
+ },
600
+ });
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: ui-font-scale
3
+ name: dsh-ui-font-scale
package/docs/DETAIL.md ADDED
@@ -0,0 +1,38 @@
1
+ # 界面字号
2
+
3
+ ## 功能
4
+
5
+ - 启动时扫描页面样式,将界面基准字号从 13px 调到 14px(默认,约 `1.077` 倍)。
6
+ - 同步放大 DSH 的 UI 排版 token(`--dsw-font-*`)及其 `-font-size`、`-line-height` 分量。
7
+ - 按同一比例放大较小的纵向尺寸:`line-height`、`height`、`min/max-height`、上下 `padding` / `margin`。
8
+ - 跳过 `--dsh-content-font-size`、代码字号和终端字号,以及 `.markdown` / `[data-conversation]` 等正文区域,因此会话正文尺寸保持不变。
9
+ - 监听后续加载的样式表,懒加载的面板和对话框也会应用缩放。
10
+ - 在「设置 → 通用设置 → 界面字号」提供 13px / 14px / 15px / 16px 的下拉选择,修改后立即生效并持久化。
11
+
12
+ ## 缩放范围
13
+
14
+ 默认是 14px(`14/13 ≈ 1.077`):界面最小字号 13px 变为 14px,12px 约为 13px,11px 约为 12px;选择 16px 时比例为 `16/13 ≈ 1.231`。
15
+
16
+ 为避免破坏布局,只处理较小的固定像素值:行高 ≤ 48px、高度 ≤ 80px、上下间距 ≤ 32px;
17
+ 百分比、`vh`、`em`、`calc()` 等相对值不处理,横向宽度保持不变(正方形图标会等比放大)。
18
+ 固定高度控件在放大后由内容撑开,不强行裁切。
19
+
20
+ ## 控制台接口
21
+
22
+ ```js
23
+ __dshUiFontScale.size // 当前基准字号(13–16)
24
+ __dshUiFontScale.scale // 当前比例
25
+ __dshUiFontScale.setSize(15) // 按字号修改并持久化
26
+ __dshUiFontScale.set(1.1) // 按比例修改(高级)
27
+ __dshUiFontScale.disable() // 关闭并持久化
28
+ __dshUiFontScale.enable() // 重新开启
29
+ __dshUiFontScale.rescan() // 手动重新扫描样式
30
+ ```
31
+
32
+ 设置保存在浏览器 localStorage 的 `dsh-ui-font-scale:factor` 键中。
33
+
34
+ ## 限制
35
+
36
+ - 只处理 CSS 中声明的像素值,不处理内联样式和 SVG 文本。
37
+ - 正文区域按选择器跳过;若第三方面板没有使用 DSH 的正文标记,其内部固定尺寸仍会随界面缩放。
38
+ - DSH 大版本升级后若界面 token 更名,插件会退化为只缩放固定像素字号,但仍可正常使用。
package/icon.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
2
+ <rect width="64" height="64" rx="14" fill="#2b6cb0"/>
3
+ <path d="M15 47 26.4 18h5.8L43.6 47h-6.1l-2.3-6.9H23.4L21.1 47Zm10-12h8.4l-4.2-12.7Z" fill="#fff"/>
4
+ <path d="M49 37v13M42.5 43.5h13" fill="none" stroke="#fff" stroke-width="3.4" stroke-linecap="round"/>
5
+ </svg>
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Host-side entry for the interface font scale bundle.
3
+ *
4
+ * The visible work happens in the web client (`client.js`); the bundle still
5
+ * needs a Host entry so it appears in the profile plugin inventory.
6
+ */
7
+ export function apply() {}
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Interface font size",
4
+ "description": "Scales sidebar, settings, menus, and other interface text up one step without changing conversation text.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "界面字号",
4
+ "description": "把侧边栏、设置、菜单等界面文字整体放大一档,不改变会话内容字号。",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
- {
2
- "name": "dsh-ui-font-scale",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "dsh-ui-font-scale",
3
+ "version": "1.2.2",
4
+ "description": "Scale DSH interface typography one step larger without changing conversation text.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./client": "./client.js",
9
+ "./locale/*.json": "./locale/*.json",
10
+ "./icon": "./icon.svg"
11
+ },
12
+ "files": [
13
+ "index.js",
14
+ "client.js",
15
+ "cordis.patch.yml",
16
+ "locale/*.json",
17
+ "icon.svg",
18
+ "README.md",
19
+ "docs"
20
+ ],
21
+ "engines": {
22
+ "dsh": "0.2.2-rc.5"
23
+ },
24
+ "dsh": {
25
+ "manifestVersion": 1,
26
+ "bundle": {
27
+ "patch": "./cordis.patch.yml"
28
+ },
29
+ "client": {
30
+ "platform": "web",
31
+ "immediately": true
32
+ }
33
+ },
34
+ "keywords": [
35
+ "dsh",
36
+ "dsh-plugin",
37
+ "deepseek-harness",
38
+ "ui",
39
+ "font-size",
40
+ "typography"
41
+ ],
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/MaximeMET/dsh-ui-font-scale.git"
45
+ },
46
+ "homepage": "https://github.com/MaximeMET/dsh-ui-font-scale#readme",
47
+ "bugs": {
48
+ "url": "https://github.com/MaximeMET/dsh-ui-font-scale/issues"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ }
53
+ }