dsh-plugin-table-zoom 0.1.0 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0] - 2026-08-22
4
+
5
+ - **浮窗可拖动**:不再强制居中——按住标题栏(按钮除外)拖动浮窗位置,
6
+ 自动限制在视口内不越出页面;位置与尺寸一并记忆到 localStorage,下次打开沿用。
7
+ - **Ctrl+滚轮缩放**:浮窗内按住 Ctrl 滚动滚轮,表格字体 60%–250% 缩放
8
+ (步进 10%),标题栏实时显示百分比;缩放比例随布局记忆。
9
+ - **滚动条更清晰**:正文滚动条加深加粗(WebKit 伪元素 + Firefox
10
+ `scrollbar-color`),浅色主题下也可见。
11
+ - 布局记录统一为 `{w,h,x,y,zoom}`(兼容旧 `{w,h}` 记录)。
12
+ - 测试:冒烟新增 2 项(标题栏拖拽移动 / Ctrl+滚轮缩放),
13
+ 共 selfcheck 12 项 + 冒烟 11 项。
14
+
15
+ ## [0.2.0] - 2026-08-22
16
+
17
+ - **浮窗可拖拽改尺寸**:右下角手柄调整大小(最小 320×200,上限视口减留白),
18
+ 尺寸记忆到 localStorage,下次打开自动复用;视口变化时自动收窄防溢出。
19
+ - **溢出可拖拽平移**:表格超出浮窗时,按住正文左右/上下拖动即滚动
20
+ (grab/grabbing 光标,越过 4px 阈值才视为拖动以免干扰文本选择;
21
+ 触屏保留原生滚动;拖完松手不会误关浮窗)。
22
+ - **列宽与聊天内一致**:`th/td` 增加 `max-width:min(30vw,320px);min-width:100px`,
23
+ 超宽列在浮窗内收缩换行,表格整体不再超出浮窗大小。
24
+ - 关闭浮窗时统一清理挂载的 window 监听器。
25
+ - 测试:冒烟新增 3 项(改尺寸手柄拖拽/尺寸记忆复用/溢出拖拽平移),
26
+ 共 selfcheck 12 项 + 冒烟 9 项。
27
+
3
28
  ## [0.1.0] - 2026-08-21
4
29
 
5
30
  - 新功能:**聊天表格浮窗**——聊天里 markdown 表格太长(≥9 行含表头)或
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # dsh-plugin-table-zoom
2
2
 
3
+ ![npm version](https://img.shields.io/npm/v/dsh-plugin-table-zoom)
4
+ ![License](https://img.shields.io/github/license/Pasumao/dsh-plugin-table-zoom)
5
+ ![AI Assisted](https://img.shields.io/badge/AI-Assisted-8A2BE2)
6
+
3
7
  DeepSeek Harness (dsh) Web GUI 聊天表格浮窗插件。
4
8
 
5
9
  聊天里模型输出的 markdown 表格经常**很长(行数多)或很宽(横向溢出)**,
@@ -9,14 +13,33 @@ DeepSeek Harness (dsh) Web GUI 聊天表格浮窗插件。
9
13
 
10
14
  纯前端 DOM 增强:不改核心包、不注册工具、无服务端逻辑、零运行时依赖。
11
15
 
12
- ## 效果
16
+ ## 功能
13
17
 
14
18
  - 长表(≥ 9 行含表头,或横向溢出超过 2px)表格下方出现右对齐的「⛶ 浮窗查看」按钮;
15
19
  - 短表不打扰;
16
20
  - 点击按钮弹出浮窗:标题显示「表格 · N 行 × M 列」,正文可独立滚动(横竖都行),
17
21
  关闭按钮 / Esc / 点击遮罩均可关闭,打开期间锁定聊天页滚动;
18
22
  - 浮窗头部「复制为 Markdown」按钮一键复制整表(单元格内联换行折叠、管道符转义);
19
- - 浮窗里展示的是**原表格的克隆**,聊天里的表格保持不变,也不会被重复增强。
23
+ - 浮窗里展示的是**原表格的克隆**,聊天里的表格保持不变,也不会被重复增强;
24
+ - **拖拽改尺寸**:浮窗右下角手柄可自由调整大小(最小 320×200,最大到视口留白),
25
+ 调整结果自动记忆,下次打开沿用;
26
+ - **拖拽移动**:按住标题栏可把浮窗拖到任意位置(自动限制在页面内,不会拖出屏幕),
27
+ 位置同样自动记忆;
28
+ - **Ctrl+滚轮缩放**:浮窗内按住 Ctrl 滚动滚轮,表格字体 60%–250% 缩放
29
+ (步进 10%),标题栏实时显示百分比;
30
+ - **拖拽平移**:表格超宽/超高时,按住正文任意位置即可左右/上下拖动滚动
31
+ (grab 光标提示;越过 4px 阈值才视为拖动,不干扰文本选择;触屏走原生滚动);
32
+ - **滚动条清晰**:正文滚动条加深加粗,浅色主题下也能看清;
33
+ - **列宽适配**:列宽上限与聊天内一致(`min(30vw, 320px)`),超宽列自动换行收缩,
34
+ 表格整体不再撑破浮窗。
35
+
36
+ ## 配置
37
+
38
+ 无需任何配置,安装即用:
39
+
40
+ - 不读取环境变量,不需要 API Key / token,不写配置文件;
41
+ - 长表判定阈值(≥ 9 行 / 横向溢出 2px)为内置默认值,无需调整;
42
+ - 样式跟随 DSH 主题 CSS 变量自适应,不引入独立主题配置。
20
43
 
21
44
  ## 安装
22
45
 
@@ -47,6 +70,15 @@ DeepSeek Harness (dsh) Web GUI 聊天表格浮窗插件。
47
70
  3. 在 profile 目录执行 `pnpm install`(或 `npm install`);
48
71
  4. **重启 `dsh web`**(launcher 重新拉起),新插件才会进入浏览器 bundle。
49
72
 
73
+ 源码安装(本地开发 / 调试):
74
+
75
+ ```bash
76
+ git clone https://github.com/Pasumao/dsh-plugin-table-zoom.git
77
+ cd dsh-plugin-table-zoom
78
+ npm install
79
+ # 以 link: 依赖挂载进 profile,见下方说明
80
+ ```
81
+
50
82
  > 若以本地目录开发调试,可用 `link:` 依赖替换第 1 步:
51
83
  > `"dsh-plugin-table-zoom": "link:D:/path/to/dsh-plugin-table-zoom"`。
52
84
 
@@ -76,6 +108,11 @@ npm run pack # 打包
76
108
  - 不影响其他插件:只认 `tableScroll` 容器内的表格,跳过浮窗与 image-tools
77
109
  lightbox 内的表格。
78
110
 
111
+ ## AI 生成声明
112
+
113
+ 代码与文档由 AI 辅助生成(DeepSeek Harness),均经人工审查与实机验证
114
+ (`npm run smoke`:selfcheck + 假 DOM 端到端冒烟)。
115
+
79
116
  ## License
80
117
 
81
118
  MIT
package/lib/client.js CHANGED
@@ -13,17 +13,28 @@ window.__ModuleLoader__.load({
13
13
  '.dstz-btn{appearance:none;cursor:pointer;display:inline-flex;align-items:center;gap:5px;border:1px solid var(--dsw-alias-border-l2-darkmode-thin);background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary);border-radius:999px;font-size:12px;line-height:18px;padding:3px 10px;font-family:inherit;white-space:nowrap}',
14
14
  '.dstz-btn:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-interactive-bg-active);background:var(--dsw-alias-interactive-bg-hover)}',
15
15
  '.dstz-btn:focus-visible{outline:2px solid var(--dsw-alias-interactive-bg-active);outline-offset:1px}',
16
- '.dstz-popup{position:fixed;inset:0;z-index:9999;background:rgba(8,10,18,.55);display:flex;align-items:center;justify-content:center;padding:24px}',
17
- '.dstz-panel{box-sizing:border-box;background:var(--dsw-specific-input-major);border:1px solid var(--dsw-alias-border-l2-darkmode-thin);border-radius:16px;box-shadow:var(--dsw-shadow-lv2);color:var(--dsw-alias-label-primary);width:min(92vw,960px);max-height:min(84vh,720px);flex-direction:column;display:flex;overflow:hidden;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}',
16
+ '.dstz-popup{position:fixed;inset:0;z-index:9999;background:rgba(8,10,18,.55)}',
17
+ '.dstz-panel{box-sizing:border-box;background:var(--dsw-specific-input-major);border:1px solid var(--dsw-alias-border-l2-darkmode-thin);border-radius:16px;box-shadow:var(--dsw-shadow-lv2);color:var(--dsw-alias-label-primary);width:min(92vw,960px);max-height:min(84vh,720px);flex-direction:column;display:flex;overflow:hidden;position:fixed}',
18
18
  '.dstz-panel,.dstz-panel *{box-sizing:border-box}',
19
- '.dstz-header{flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;border-bottom:1px solid var(--dsw-alias-border-l2);padding:10px 12px 10px 18px;display:flex}',
19
+ '.dstz-panel.dstz-resizing,.dstz-panel.dstz-resizing *{user-select:none;-webkit-user-select:none}',
20
+ '.dstz-header{flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;border-bottom:1px solid var(--dsw-alias-border-l2);padding:10px 12px 10px 18px;display:flex;cursor:move;touch-action:none}',
21
+ '.dstz-header.dstz-dragging{cursor:grabbing;user-select:none;-webkit-user-select:none}',
22
+ '.dstz-header button{cursor:pointer}',
20
23
  '.dstz-title{margin:0;font-size:14px;font-weight:500;line-height:20px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
21
24
  '.dstz-title small{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;margin-left:8px}',
22
25
  '.dstz-headerActions{flex-shrink:0;align-items:center;gap:8px;display:flex}',
23
- '.dstz-body{overscroll-behavior:contain;flex:auto;min-height:0;padding:14px 18px 18px;overflow:auto}',
26
+ '.dstz-body{overscroll-behavior:contain;flex:auto;min-height:0;padding:14px 18px 18px;overflow-x:auto;overflow-y:auto;scrollbar-width:thin;scrollbar-color:var(--dsw-alias-scrollbar-hover-l2, rgba(148,163,184,.65)) transparent}',
27
+ '.dstz-body::-webkit-scrollbar{width:9px;height:9px}',
28
+ '.dstz-body::-webkit-scrollbar-thumb{background:var(--dsw-alias-scrollbar-hover-l2, rgba(148,163,184,.65));border-radius:7px;border:2px solid var(--dsw-specific-input-major);background-clip:padding-box}',
29
+ '.dstz-body::-webkit-scrollbar-thumb:hover{background:var(--dsw-alias-label-secondary, rgba(148,163,184,.95))}',
30
+ '.dstz-body::-webkit-scrollbar-track{background:transparent}',
31
+ '.dstz-body::-webkit-scrollbar-corner{background:transparent}',
32
+ '.dstz-body.dstz-grabbable{cursor:grab}',
33
+ '.dstz-body.dstz-panning{cursor:grabbing;user-select:none;-webkit-user-select:none}',
24
34
  '.dstz-table{border-collapse:collapse;width:max-content;max-width:max-content;color:var(--dsw-alias-label-primary)}',
25
- '.dstz-table th{text-align:start;padding:8px 14px;border-bottom:1px solid var(--dsw-alias-border-l3);font:var(--dsw-font-markdown-table-head);white-space:nowrap}',
26
- '.dstz-table td{padding:8px 14px;border-bottom:1px solid var(--dsw-alias-border-l2);font:var(--dsw-font-markdown-table)}',
35
+ // 列宽上限与核心渲染器(tableScroll)一致:超宽列在浮窗内收缩换行,整体不溢出
36
+ '.dstz-table th{text-align:start;padding:8px 14px;border-bottom:1px solid var(--dsw-alias-border-l3);font:var(--dsw-font-markdown-table-head);max-width:min(30vw,320px);min-width:100px}',
37
+ '.dstz-table td{padding:8px 14px;border-bottom:1px solid var(--dsw-alias-border-l2);font:var(--dsw-font-markdown-table);max-width:min(30vw,320px);min-width:100px}',
27
38
  '.dstz-table tr:last-child td{border-bottom:none}',
28
39
  '.dstz-iconButton{width:28px;height:28px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:999px;place-items:center;display:grid;font-size:15px;line-height:1;padding:0}',
29
40
  '.dstz-iconButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
@@ -31,7 +42,11 @@ window.__ModuleLoader__.load({
31
42
  '.dstz-copyBtn{appearance:none;cursor:pointer;border-radius:999px;border:1px solid var(--dsw-alias-border-l2-darkmode-thin);background:0 0;color:var(--dsw-alias-label-primary);font-size:12px;line-height:18px;padding:3px 10px;font-family:inherit;white-space:nowrap}',
32
43
  '.dstz-copyBtn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}',
33
44
  '.dstz-copyBtn:disabled{cursor:default;opacity:.55}',
34
- '@media (width<=720px){.dstz-popup{padding:12px}.dstz-panel{width:min(96vw,960px);max-height:88vh}.dstz-body{padding:10px 12px 12px}}'
45
+ // 拖拽改尺寸:右下角手柄(悬停显示,不占滚动条位置)
46
+ '.dstz-resizeSE{position:absolute;right:2px;bottom:2px;width:22px;height:22px;cursor:nwse-resize;z-index:4;touch-action:none}',
47
+ '.dstz-resizeSE::after{content:"";position:absolute;right:5px;bottom:5px;width:9px;height:9px;border-right:2px solid var(--dsw-alias-label-tertiary);border-bottom:2px solid var(--dsw-alias-label-tertiary);border-bottom-right-radius:2px;pointer-events:none}',
48
+ '.dstz-resizeSE:hover::after,.dstz-panel.dstz-resizing .dstz-resizeSE::after{border-color:var(--dsw-alias-label-primary)}',
49
+ '@media (width<=720px){.dstz-panel{width:min(96vw,960px);max-height:88vh}.dstz-body{padding:10px 12px 12px}}'
35
50
  ].join('');
36
51
  var tagId = 'dsh-plugin-table-zoom/zoom.module.css';
37
52
  if (typeof document !== 'undefined' && document.querySelector('style[data-plugin-css=' + JSON.stringify(tagId) + ']') === null) {
@@ -150,6 +165,11 @@ window.__ModuleLoader__.load({
150
165
  var popup = activePopup;
151
166
  activePopup = null;
152
167
  if (typeof popup._onKey === 'function') document.removeEventListener('keydown', popup._onKey);
168
+ if (Array.isArray(popup._cleanups)) {
169
+ for (var i = 0; i < popup._cleanups.length; i++) {
170
+ try { popup._cleanups[i](); } catch (e) { /* ignore */ }
171
+ }
172
+ }
153
173
  popup.remove();
154
174
  document.body.style.overflow = lastTrigger !== null && lastTrigger.bodyOverflow !== void 0 ? lastTrigger.bodyOverflow : '';
155
175
  lastTrigger = null;
@@ -182,6 +202,293 @@ window.__ModuleLoader__.load({
182
202
  }
183
203
  }
184
204
 
205
+ // ------------------------------------------------------------------
206
+ // 浮窗布局:拖拽改大小 + 拖标题栏移动 + Ctrl+滚轮缩放 + 布局记忆
207
+ // ------------------------------------------------------------------
208
+
209
+ /** localStorage 键:记住用户最后一次手动调整的浮窗布局(尺寸/位置/缩放)。 */
210
+ var SIZE_KEY = 'dsh-plugin-table-zoom:popup-size';
211
+ var MIN_POPUP_W = 320;
212
+ var MIN_POPUP_H = 200;
213
+ /** 浮窗距视口边缘的最小留白。 */
214
+ var POPUP_MARGIN = 48;
215
+ /** Ctrl+滚轮缩放范围与步进。 */
216
+ var ZOOM_MIN = 0.6;
217
+ var ZOOM_MAX = 2.5;
218
+ var ZOOM_STEP = 0.1;
219
+
220
+ /** 把 v 限制在 [lo, hi]。 */
221
+ function clamp(v, lo, hi) {
222
+ return Math.min(Math.max(v, lo), hi);
223
+ }
224
+
225
+ /** 当前视口宽(无 DOM 环境兜底 1280)。 */
226
+ function viewportW() {
227
+ if (typeof window !== 'undefined' && typeof window.innerWidth === 'number' && window.innerWidth > 0) return window.innerWidth;
228
+ if (typeof document !== 'undefined' && document.documentElement !== null && typeof document.documentElement.clientWidth === 'number' && document.documentElement.clientWidth > 0) return document.documentElement.clientWidth;
229
+ return 1280;
230
+ }
231
+
232
+ /** 当前视口高(无 DOM 环境兜底 800)。 */
233
+ function viewportH() {
234
+ if (typeof window !== 'undefined' && typeof window.innerHeight === 'number' && window.innerHeight > 0) return window.innerHeight;
235
+ if (typeof document !== 'undefined' && document.documentElement !== null && typeof document.documentElement.clientHeight === 'number' && document.documentElement.clientHeight > 0) return document.documentElement.clientHeight;
236
+ return 800;
237
+ }
238
+
239
+ /** 读取上次记忆的浮窗布局;无记录/损坏/隐私模式返回 null。 */
240
+ function readSavedSize() {
241
+ try {
242
+ if (typeof localStorage === 'undefined') return null;
243
+ var raw = localStorage.getItem(SIZE_KEY);
244
+ if (raw === null || raw === '') return null;
245
+ var v = JSON.parse(raw);
246
+ if (v === null || typeof v !== 'object') return null;
247
+ return {
248
+ w: Number(v.w) || 0,
249
+ h: Number(v.h) || 0,
250
+ x: typeof v.x === 'number' ? v.x : null,
251
+ y: typeof v.y === 'number' ? v.y : null,
252
+ zoom: typeof v.zoom === 'number' && v.zoom > 0 ? v.zoom : 1
253
+ };
254
+ } catch (e) {
255
+ return null;
256
+ }
257
+ }
258
+
259
+ /**
260
+ * 打开浮窗时套用上次记忆的布局(尺寸/位置/缩放,按当前视口收窄)。
261
+ * 无记忆时尺寸用 CSS 默认、位置居中。返回本次生效的 {w,h,x,y,zoom}。
262
+ */
263
+ function applySavedLayout(panel) {
264
+ var v = readSavedSize();
265
+ var vw = viewportW();
266
+ var vh = viewportH();
267
+ var maxW = vw - POPUP_MARGIN;
268
+ var maxH = vh - POPUP_MARGIN;
269
+ if (maxW < MIN_POPUP_W || maxH < MIN_POPUP_H) return { w: 0, h: 0, x: 0, y: 0, zoom: 1 };
270
+ var w = v !== null && v.w > 0 ? clamp(v.w, MIN_POPUP_W, maxW) : 0;
271
+ var h = v !== null && v.h > 0 ? clamp(v.h, MIN_POPUP_H, maxH) : 0;
272
+ if (w > 0) {
273
+ panel.style.width = w + 'px';
274
+ panel.style.maxHeight = 'none';
275
+ }
276
+ if (h > 0) panel.style.height = h + 'px';
277
+ var pw = w > 0 ? w : Math.min(960, maxW);
278
+ var ph = h > 0 ? h : Math.min(720, maxH);
279
+ var x = v !== null && v.x !== null ? clamp(v.x, 0, Math.max(0, vw - pw)) : Math.round((vw - pw) / 2);
280
+ var y = v !== null && v.y !== null ? clamp(v.y, 0, Math.max(0, vh - ph)) : Math.round((vh - ph) / 2);
281
+ panel.style.left = x + 'px';
282
+ panel.style.top = y + 'px';
283
+ var zoom = v !== null ? clamp(v.zoom, ZOOM_MIN, ZOOM_MAX) : 1;
284
+ return { w: pw, h: ph, x: x, y: y, zoom: zoom };
285
+ }
286
+
287
+ /** 把面板位置限制在视口内(完全可见,不越出页面)。 */
288
+ function clampPanelPosition(panel) {
289
+ var rect = null;
290
+ try { rect = panel.getBoundingClientRect(); } catch (err) { rect = null; }
291
+ if (rect === null || typeof rect !== 'object') return;
292
+ if (typeof rect.left !== 'number' || typeof rect.top !== 'number') return;
293
+ var x = clamp(rect.left, 0, Math.max(0, viewportW() - rect.width));
294
+ var y = clamp(rect.top, 0, Math.max(0, viewportH() - rect.height));
295
+ panel.style.left = x + 'px';
296
+ panel.style.top = y + 'px';
297
+ }
298
+
299
+ /** 把面板移到 (x, y) 并限制在视口内。 */
300
+ function setPanelPosition(panel, x, y) {
301
+ var rect = null;
302
+ try { rect = panel.getBoundingClientRect(); } catch (err) { rect = null; }
303
+ if (rect === null || typeof rect !== 'object') return;
304
+ x = clamp(x, 0, Math.max(0, viewportW() - rect.width));
305
+ y = clamp(y, 0, Math.max(0, viewportH() - rect.height));
306
+ panel.style.left = x + 'px';
307
+ panel.style.top = y + 'px';
308
+ }
309
+
310
+ /** 拖拽结束后记忆当前布局(尺寸/位置/缩放;localStorage 不可用时静默跳过)。 */
311
+ function saveLayout(panel, zoom) {
312
+ try {
313
+ if (typeof localStorage === 'undefined') return;
314
+ var rect = panel.getBoundingClientRect();
315
+ if (rect === null || typeof rect !== 'object') return;
316
+ var prev = readSavedSize();
317
+ var record = {
318
+ w: Math.round(rect.width),
319
+ h: Math.round(rect.height),
320
+ x: typeof rect.left === 'number' ? Math.round(rect.left) : 0,
321
+ y: typeof rect.top === 'number' ? Math.round(rect.top) : 0,
322
+ zoom: typeof zoom === 'number' && zoom > 0 ? Math.round(zoom * 100) / 100 : (prev !== null && prev.zoom > 0 ? prev.zoom : 1)
323
+ };
324
+ localStorage.setItem(SIZE_KEY, JSON.stringify(record));
325
+ } catch (e) {
326
+ /* 隐私模式等场景忽略 */
327
+ }
328
+ }
329
+
330
+ /** 内容溢出时给正文加 grab 光标提示(可拖拽平移)。 */
331
+ function refreshGrabbable(body) {
332
+ var overX = body.scrollWidth > body.clientWidth + 1;
333
+ var overY = body.scrollHeight > body.clientHeight + 1;
334
+ if (overX || overY) body.classList.add('dstz-grabbable');
335
+ else body.classList.remove('dstz-grabbable');
336
+ }
337
+
338
+ /** 命中可交互元素(链接/按钮/输入框等)时让给默认行为,不启动拖拽。 */
339
+ function isInteractive(el) {
340
+ if (el === null || typeof el !== 'object' || typeof el.closest !== 'function') return false;
341
+ return el.closest('a,button,input,textarea,select,[contenteditable="true"],[role="button"]') !== null;
342
+ }
343
+
344
+ /**
345
+ * 给面板挂载「拖右下角改尺寸」:指针捕获 + _suppressClick 防止拖完
346
+ * 松手落在遮罩上误触发关闭。尺寸写入 inline style 并记忆到 localStorage。
347
+ * @param {object} panel - .dstz-panel 元素。
348
+ * @param {object} overlay - .dstz-popup 元素(承载 _suppressClick)。
349
+ */
350
+ function attachResize(panel, overlay) {
351
+ var handle = document.createElement('div');
352
+ handle.className = 'dstz-resizeSE';
353
+ handle.setAttribute('aria-hidden', 'true');
354
+ var state = null;
355
+ var begin = function (e) {
356
+ if (e.button !== 0) return;
357
+ if (typeof e.preventDefault === 'function') e.preventDefault();
358
+ if (typeof e.stopPropagation === 'function') e.stopPropagation();
359
+ var rect = null;
360
+ try { rect = panel.getBoundingClientRect(); } catch (err) { rect = null; }
361
+ if (rect === null || typeof rect !== 'object') return;
362
+ state = { x: e.clientX, y: e.clientY, w: rect.width, h: rect.height };
363
+ panel.style.maxHeight = 'none';
364
+ panel.classList.add('dstz-resizing');
365
+ overlay._suppressClick = true;
366
+ if (e.currentTarget !== null && e.currentTarget !== void 0 && typeof e.currentTarget.setPointerCapture === 'function') {
367
+ try { e.currentTarget.setPointerCapture(e.pointerId); } catch (err) { /* ignore */ }
368
+ }
369
+ };
370
+ var move = function (e) {
371
+ if (state === null) return;
372
+ var dx = e.clientX - state.x;
373
+ var dy = e.clientY - state.y;
374
+ var w = Math.min(Math.max(state.w + dx, MIN_POPUP_W), Math.max(MIN_POPUP_W, viewportW() - POPUP_MARGIN));
375
+ var h = Math.min(Math.max(state.h + dy, MIN_POPUP_H), Math.max(MIN_POPUP_H, viewportH() - POPUP_MARGIN));
376
+ panel.style.width = w + 'px';
377
+ panel.style.height = h + 'px';
378
+ if (typeof e.preventDefault === 'function') e.preventDefault();
379
+ };
380
+ var end = function () {
381
+ if (state === null) return;
382
+ state = null;
383
+ panel.classList.remove('dstz-resizing');
384
+ clampPanelPosition(panel);
385
+ saveLayout(panel);
386
+ window.setTimeout(function () { overlay._suppressClick = false; }, 0);
387
+ };
388
+ handle.addEventListener('pointerdown', begin);
389
+ handle.addEventListener('pointermove', move);
390
+ handle.addEventListener('pointerup', end);
391
+ handle.addEventListener('pointercancel', end);
392
+ panel.appendChild(handle);
393
+ }
394
+
395
+ /**
396
+ * 给标题栏挂载「拖拽移动」:按住标题栏(按钮除外)拖动面板位置,
397
+ * 位置限制在视口内(不越出页面);拖动结束记忆位置。
398
+ * @param {object} panel - .dstz-panel 元素(children[0] 为标题栏)。
399
+ * @param {object} overlay - .dstz-popup 元素(承载 _suppressClick)。
400
+ */
401
+ function attachMove(panel, overlay) {
402
+ var header = panel.children[0];
403
+ if (header === null || header === void 0) return;
404
+ var state = null;
405
+ header.addEventListener('pointerdown', function (e) {
406
+ if (e.button !== 0) return;
407
+ if (isInteractive(e.target)) return;
408
+ var rect = null;
409
+ try { rect = panel.getBoundingClientRect(); } catch (err) { rect = null; }
410
+ if (rect === null || typeof rect !== 'object') return;
411
+ state = { x: e.clientX, y: e.clientY, lx: rect.left, ty: rect.top, moved: false };
412
+ if (typeof header.setPointerCapture === 'function') {
413
+ try { header.setPointerCapture(e.pointerId); } catch (err) { /* ignore */ }
414
+ }
415
+ });
416
+ header.addEventListener('pointermove', function (e) {
417
+ if (state === null) return;
418
+ var dx = e.clientX - state.x;
419
+ var dy = e.clientY - state.y;
420
+ if (!state.moved && Math.abs(dx) + Math.abs(dy) < 3) return;
421
+ if (!state.moved) {
422
+ state.moved = true;
423
+ header.classList.add('dstz-dragging');
424
+ overlay._suppressClick = true;
425
+ }
426
+ setPanelPosition(panel, state.lx + dx, state.ty + dy);
427
+ if (typeof e.preventDefault === 'function') e.preventDefault();
428
+ });
429
+ var end = function () {
430
+ if (state === null) return;
431
+ var wasMoved = state.moved;
432
+ state = null;
433
+ header.classList.remove('dstz-dragging');
434
+ if (wasMoved) {
435
+ saveLayout(panel);
436
+ window.setTimeout(function () { overlay._suppressClick = false; }, 0);
437
+ }
438
+ };
439
+ header.addEventListener('pointerup', end);
440
+ header.addEventListener('pointercancel', end);
441
+ }
442
+
443
+ /**
444
+ * 给正文挂载「拖拽平移」:内容溢出时按住表格左右/上下拖动即可滚动
445
+ * (鼠标/触控笔;触屏保留原生滚动)。越过 4px 阈值才视为拖动,
446
+ * 避免干扰文本选择;拖动结束松手落在遮罩上不会误关浮窗。
447
+ * @param {object} body - .dstz-body 元素。
448
+ * @param {object} overlay - .dstz-popup 元素(承载 _suppressClick)。
449
+ */
450
+ function attachPan(body, overlay) {
451
+ var state = null;
452
+ body.addEventListener('pointerdown', function (e) {
453
+ if (e.button !== 0) return;
454
+ if (e.pointerType !== undefined && e.pointerType !== 'mouse' && e.pointerType !== 'pen') return;
455
+ if (isInteractive(e.target)) return;
456
+ var overX = body.scrollWidth > body.clientWidth + 1;
457
+ var overY = body.scrollHeight > body.clientHeight + 1;
458
+ if (!overX && !overY) return;
459
+ state = { x: e.clientX, y: e.clientY, sl: body.scrollLeft, st: body.scrollTop, moved: false };
460
+ if (typeof body.setPointerCapture === 'function') {
461
+ try { body.setPointerCapture(e.pointerId); } catch (err) { /* ignore */ }
462
+ }
463
+ });
464
+ body.addEventListener('pointermove', function (e) {
465
+ if (state === null) return;
466
+ var dx = e.clientX - state.x;
467
+ var dy = e.clientY - state.y;
468
+ if (!state.moved && Math.abs(dx) + Math.abs(dy) < 4) return;
469
+ if (!state.moved) {
470
+ state.moved = true;
471
+ body.classList.add('dstz-panning');
472
+ overlay._suppressClick = true;
473
+ if (typeof document !== 'undefined' && typeof document.getSelection === 'function') {
474
+ try { document.getSelection().removeAllRanges(); } catch (err) { /* ignore */ }
475
+ }
476
+ }
477
+ body.scrollLeft = state.sl - dx;
478
+ body.scrollTop = state.st - dy;
479
+ if (typeof e.preventDefault === 'function') e.preventDefault();
480
+ });
481
+ var end = function () {
482
+ if (state === null) return;
483
+ var wasMoved = state.moved;
484
+ state = null;
485
+ body.classList.remove('dstz-panning');
486
+ if (wasMoved) window.setTimeout(function () { overlay._suppressClick = false; }, 0);
487
+ };
488
+ body.addEventListener('pointerup', end);
489
+ body.addEventListener('pointercancel', end);
490
+ }
491
+
185
492
  /**
186
493
  * 打开表格浮窗:可滚动容器 + 表格克隆 + 头部(标题/行列数/复制/关闭)。
187
494
  * 克隆而不是移动原表格,聊天里的表格保持不变。
@@ -252,6 +559,51 @@ window.__ModuleLoader__.load({
252
559
  panel.appendChild(body);
253
560
  overlay.appendChild(panel);
254
561
 
562
+ // 拖拽改尺寸 + 拖标题栏移动 + 内容溢出拖拽平移 + 布局记忆 + Ctrl+滚轮缩放
563
+ attachResize(panel, overlay);
564
+ attachMove(panel, overlay);
565
+ attachPan(body, overlay);
566
+
567
+ var zoom = 1;
568
+ var applyZoom = function (z) {
569
+ zoom = clamp(z, ZOOM_MIN, ZOOM_MAX);
570
+ clone.style.zoom = String(zoom);
571
+ small.textContent = rowCount + ' ' + LABELS.rowsCols + ' ' + colCount
572
+ + (Math.abs(zoom - 1) > 0.001 ? ' \u00b7 ' + Math.round(zoom * 100) + '%' : '');
573
+ };
574
+ var layout = applySavedLayout(panel);
575
+ applyZoom(layout.zoom);
576
+ refreshGrabbable(body);
577
+
578
+ // Ctrl+滚轮:缩放表格字体(阻止浏览器整页缩放)
579
+ var onWheel = function (e) {
580
+ if (!e.ctrlKey) return;
581
+ if (typeof e.preventDefault === 'function') e.preventDefault();
582
+ applyZoom(e.deltaY < 0 ? zoom + ZOOM_STEP : zoom - ZOOM_STEP);
583
+ saveLayout(panel, zoom);
584
+ };
585
+ panel.addEventListener('wheel', onWheel, { passive: false });
586
+
587
+ var onWindowResize = function () {
588
+ var maxW = viewportW() - POPUP_MARGIN;
589
+ var maxH = viewportH() - POPUP_MARGIN;
590
+ var w = panel.offsetWidth;
591
+ var h = panel.offsetHeight;
592
+ if (w > maxW || h > maxH) {
593
+ panel.style.width = Math.min(w, maxW) + 'px';
594
+ panel.style.height = Math.min(h, maxH) + 'px';
595
+ }
596
+ clampPanelPosition(panel);
597
+ refreshGrabbable(body);
598
+ };
599
+ overlay._cleanups = [];
600
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
601
+ window.addEventListener('resize', onWindowResize);
602
+ overlay._cleanups.push(function () {
603
+ window.removeEventListener('resize', onWindowResize);
604
+ });
605
+ }
606
+
255
607
  lastTrigger = { bodyOverflow: document.body.style.overflow };
256
608
  document.body.style.overflow = 'hidden';
257
609
 
@@ -259,6 +611,11 @@ window.__ModuleLoader__.load({
259
611
  if (event.key === 'Escape') closePopup();
260
612
  };
261
613
  overlay.addEventListener('click', function (event) {
614
+ // 拖拽(改尺寸/平移)后松手落在遮罩上会产生一次 click,需吞掉避免误关
615
+ if (overlay._suppressClick) {
616
+ overlay._suppressClick = false;
617
+ return;
618
+ }
262
619
  if (event.target === overlay) closePopup();
263
620
  });
264
621
  document.addEventListener('keydown', onKey);
@@ -374,6 +731,14 @@ window.__ModuleLoader__.load({
374
731
  exports.upgradeTable = upgradeTable;
375
732
  exports.upgradeTables = upgradeTables;
376
733
  exports.startEnhancer = startEnhancer;
734
+ exports.attachResize = attachResize;
735
+ exports.attachMove = attachMove;
736
+ exports.attachPan = attachPan;
737
+ exports.applySavedLayout = applySavedLayout;
738
+ exports.saveLayout = saveLayout;
739
+ exports.readSavedSize = readSavedSize;
740
+ exports.clampPanelPosition = clampPanelPosition;
741
+ exports.refreshGrabbable = refreshGrabbable;
377
742
  return module.exports;
378
743
  }
379
744
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-plugin-table-zoom",
3
3
  "description": "DSH 聊天表格浮窗插件:聊天里 markdown 表格太长(行多/超宽)看不完时,表格上方自动出现「浮窗查看」按钮,点击弹出可滚动的小浮窗完整显示表格,并支持一键复制为 Markdown。纯前端 DOM 增强,不改核心包、不注册工具、无服务端逻辑。",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -6,7 +6,10 @@
6
6
  * 2. upgradeTable 在长表容器后注入「浮窗查看」按钮行,短表不注入;
7
7
  * 3. openPopup 创建浮窗(标题含行列数、表格克隆、关闭按钮),
8
8
  * closePopup 关闭并还原 body 滚动;
9
- * 4. 表格克隆在浮窗内不会被再次增强(跳过 .dstz-popup)。
9
+ * 4. 表格克隆在浮窗内不会被再次增强(跳过 .dstz-popup);
10
+ * 5. 右下角改尺寸手柄可拖拽改面板大小并记忆到 localStorage,
11
+ * 再次打开复用记忆布局;内容溢出时正文可拖拽平移;
12
+ * 标题栏可拖拽移动浮窗(不越出视口);Ctrl+滚轮缩放表格字体。
10
13
  *
11
14
  * 运行:node scripts/smoke-client.mjs
12
15
  */
@@ -251,4 +254,136 @@ ok('copyText 写入剪贴板', async () => {
251
254
  assert.equal(globalThis.__copied, '| a |\n| --- |')
252
255
  })
253
256
 
257
+ // 5) 浮窗改尺寸 + 尺寸记忆 + 拖拽平移
258
+ // 假 localStorage:验证尺寸记忆读写(真实环境缺失时各函数均已兜底)
259
+ const sizeStore = new Map()
260
+ Object.defineProperty(globalThis, 'localStorage', {
261
+ value: {
262
+ getItem: (k) => (sizeStore.has(k) ? sizeStore.get(k) : null),
263
+ setItem: (k, v) => { sizeStore.set(k, String(v)) },
264
+ removeItem: (k) => { sizeStore.delete(k) },
265
+ },
266
+ configurable: true,
267
+ })
268
+
269
+ ok('openPopup 挂载右下角改尺寸手柄并可拖拽', () => {
270
+ mod.closePopup()
271
+ const table = makeEl('table')
272
+ table.rows = []
273
+ mod.openPopup(table)
274
+ const popup = documentEl.body.children.find((c) => c.className === 'dstz-popup')
275
+ const panel = popup.children[0]
276
+ const handle = panel.children.find((c) => c.className === 'dstz-resizeSE')
277
+ assert.ok(handle !== undefined, 'resize handle not mounted')
278
+ panel.getBoundingClientRect = () => ({
279
+ width: parseInt(panel.style.width, 10) || 800,
280
+ height: parseInt(panel.style.height, 10) || 400,
281
+ })
282
+ handle.dispatch('pointerdown', { button: 0, clientX: 100, clientY: 100, pointerId: 1 })
283
+ handle.dispatch('pointermove', { clientX: 260, clientY: 160 })
284
+ assert.equal(panel.style.width, '960px')
285
+ assert.equal(panel.style.height, '460px')
286
+ assert.equal(panel.style.maxHeight, 'none')
287
+ assert.ok(popup._suppressClick === true, 'drag should suppress overlay close')
288
+ handle.dispatch('pointerup', {})
289
+ const saved = JSON.parse(sizeStore.get('dsh-plugin-table-zoom:popup-size'))
290
+ assert.equal(saved.w, 960)
291
+ assert.equal(saved.h, 460)
292
+ assert.ok(popup._suppressClick === false, 'suppress flag reset after drag')
293
+ mod.closePopup()
294
+ })
295
+
296
+ ok('applySavedLayout 复用上次记忆的布局', () => {
297
+ mod.closePopup()
298
+ const table = makeEl('table')
299
+ table.rows = []
300
+ mod.openPopup(table)
301
+ const popup = documentEl.body.children.find((c) => c.className === 'dstz-popup')
302
+ const panel = popup.children[0]
303
+ const clone = panel.children[1].children[0]
304
+ assert.equal(panel.style.width, '960px')
305
+ assert.equal(panel.style.height, '460px')
306
+ assert.equal(panel.style.maxHeight, 'none')
307
+ assert.equal(panel.style.left, '0px')
308
+ assert.equal(panel.style.top, '0px')
309
+ assert.equal(clone.style.zoom, '1')
310
+ mod.closePopup()
311
+ })
312
+
313
+ ok('溢出时正文可拖拽平移', () => {
314
+ mod.closePopup()
315
+ const table = makeEl('table')
316
+ table.rows = []
317
+ mod.openPopup(table)
318
+ const popup = documentEl.body.children.find((c) => c.className === 'dstz-popup')
319
+ const body = popup.children[0].children[1]
320
+ body.scrollWidth = 1200
321
+ body.clientWidth = 600
322
+ body.scrollHeight = 400
323
+ body.clientHeight = 300
324
+ body.scrollLeft = 300
325
+ body.scrollTop = 100
326
+ mod.refreshGrabbable(body)
327
+ assert.ok(body.classList.contains('dstz-grabbable'), 'overflow should show grab cursor')
328
+ body.dispatch('pointerdown', { button: 0, clientX: 10, clientY: 10, pointerId: 1 })
329
+ body.dispatch('pointermove', { clientX: 110, clientY: 60 })
330
+ assert.ok(body.classList.contains('dstz-panning'), 'panning class while dragging')
331
+ assert.equal(body.scrollLeft, 200)
332
+ assert.equal(body.scrollTop, 50)
333
+ assert.ok(popup._suppressClick === true, 'pan should suppress overlay close')
334
+ body.dispatch('pointerup', {})
335
+ assert.ok(!body.classList.contains('dstz-panning'), 'panning class cleared on release')
336
+ assert.ok(popup._suppressClick === false, 'suppress flag reset after pan')
337
+ mod.closePopup()
338
+ })
339
+
340
+ ok('标题栏可拖拽移动浮窗(不越出视口)', () => {
341
+ mod.closePopup()
342
+ sizeStore.delete('dsh-plugin-table-zoom:popup-size') // 清掉记忆,用默认尺寸测移动
343
+ const table = makeEl('table')
344
+ table.rows = []
345
+ mod.openPopup(table)
346
+ const popup = documentEl.body.children.find((c) => c.className === 'dstz-popup')
347
+ const panel = popup.children[0]
348
+ const header = panel.children[0]
349
+ panel.getBoundingClientRect = () => ({
350
+ width: parseInt(panel.style.width, 10) || 800,
351
+ height: parseInt(panel.style.height, 10) || 400,
352
+ left: parseInt(panel.style.left, 10) || 300,
353
+ top: parseInt(panel.style.top, 10) || 200,
354
+ })
355
+ const startLeft = parseInt(panel.style.left, 10)
356
+ const startTop = parseInt(panel.style.top, 10)
357
+ header.dispatch('pointerdown', { button: 0, clientX: 10, clientY: 10, pointerId: 1 })
358
+ header.dispatch('pointermove', { clientX: 50, clientY: 30 })
359
+ assert.ok(header.classList.contains('dstz-dragging'), 'dragging class while moving')
360
+ assert.equal(parseInt(panel.style.left, 10), startLeft + 40, 'left follows drag delta')
361
+ assert.equal(parseInt(panel.style.top, 10), startTop + 20, 'top follows drag delta')
362
+ assert.ok(popup._suppressClick === true, 'move should suppress overlay close')
363
+ header.dispatch('pointerup', {})
364
+ assert.ok(!header.classList.contains('dstz-dragging'), 'dragging class cleared on release')
365
+ assert.ok(popup._suppressClick === false, 'suppress flag reset after move')
366
+ mod.closePopup()
367
+ })
368
+
369
+ ok('Ctrl+滚轮缩放表格字体', () => {
370
+ mod.closePopup()
371
+ const table = makeEl('table')
372
+ table.rows = [{ cells: [] }, { cells: [] }]
373
+ mod.openPopup(table)
374
+ const popup = documentEl.body.children.find((c) => c.className === 'dstz-popup')
375
+ const panel = popup.children[0]
376
+ const clone = panel.children[1].children[0]
377
+ const small = panel.children[0].children[0].children[0]
378
+ assert.equal(clone.style.zoom, '1')
379
+ assert.ok(!small.textContent.includes('%'), 'zoom 1 时不显示百分比')
380
+ panel.dispatch('wheel', { ctrlKey: true, deltaY: -100 })
381
+ assert.equal(clone.style.zoom, '1.1')
382
+ assert.ok(small.textContent.includes('110%'), '标题显示缩放百分比')
383
+ panel.dispatch('wheel', { ctrlKey: true, deltaY: 100 })
384
+ assert.equal(clone.style.zoom, '1')
385
+ assert.ok(!small.textContent.includes('%'), '回到 100% 后百分比消失')
386
+ mod.closePopup()
387
+ })
388
+
254
389
  console.log(`[dsh-plugin-table-zoom] smoke-client: ${passed} passed`)
@@ -44,10 +44,24 @@ cordis.patch.yml 挂载一行,交 profile 的 dsh.profile.bundles 自
44
44
 
45
45
  - 打开:锁定 body 滚动;Esc / 关闭按钮 / 点击遮罩关闭并还原滚动;
46
46
  - 头部:标题「表格 · N 行 × M 列」+「复制为 Markdown」+ 关闭按钮;
47
- - 正文:独立滚动(横竖),表格克隆带 `dstz-table` 类,样式全部走主题 CSS 变量。
47
+ - 正文:独立滚动(横竖),表格克隆带 `dstz-table` 类,样式全部走主题 CSS 变量;
48
+ - **改尺寸**:右下角有拖拽手柄,按住可自由调整浮窗大小(最小 320×200,
49
+ 上限为视口减去遮罩留白);
50
+ - **拖拽移动**:按住标题栏(按钮除外)可拖动浮窗位置,位置限制在视口内、
51
+ 不越出页面;尺寸与位置都记忆到 `localStorage`,下次打开自动复用;
52
+ - **Ctrl+滚轮缩放**:浮窗内按住 Ctrl 滚动滚轮可放大/缩小表格字体
53
+ (60%–250%,步进 10%),标题栏实时显示百分比,缩放比例随布局一起记忆;
54
+ - **滚动条**:正文滚动条加深加粗(WebKit 伪元素 + Firefox `scrollbar-color`),
55
+ 浅色主题下也清晰可见;
56
+ - **拖拽平移**:表格内容溢出正文时,鼠标/触控笔按住表格即可左右/上下拖动
57
+ 滚动(grab/grabbing 光标提示);越过 4px 阈值才视为拖动,避免干扰文本
58
+ 选择;触屏保留浏览器原生滚动;拖完松手落在遮罩上不会误关浮窗;
59
+ - **列宽上限**:与核心渲染器 `tableScroll` 一致(`max-width:min(30vw,320px)`、
60
+ `min-width:100px`),超宽列在浮窗内收缩换行,表整体不再超出浮窗。
48
61
 
49
62
  ## 边界与不做的事
50
63
 
51
64
  - 只认 `tableScroll` 容器内的表格;浮窗内克隆表与 image-tools lightbox 内的表格跳过;
52
65
  - 不提供服务端工具/路由/配置;无 React 依赖(零运行时依赖);
53
- - 复制为 Markdown 优先 clipboard API,失败时 execCommand 兜底。
66
+ - 复制为 Markdown 优先 clipboard API,失败时 execCommand 兜底;
67
+ - 尺寸记忆依赖 localStorage,隐私模式等不可用场景静默跳过(浮窗仍可用默认尺寸)。