@qzsy/dsh-image-viewer 0.2.0 → 0.2.1

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
@@ -33,6 +33,10 @@ dsh plugin add @qzsy/dsh-image-viewer
33
33
 
34
34
  系统开启“减少动态效果”时,所有动画直接跳到终态。
35
35
 
36
+ ## 桌面端窗口边缘
37
+
38
+ DSH 桌面应用(Electron)会把 Windows 右上角的窗口按钮、macOS 左上角的红绿灯画在网页之上。查看器和标注编辑器的顶栏按宿主发布的安全边距(`--dsh-frame-overlay-top`,Windows 为标题栏高度 + 20px,macOS 为 68px,原生全屏时降到 20px)下移,不会落在窗口按钮下面;同时图片的最大显示宽度固定为视口的 90%,标注画布同理,任何窗口尺寸下都不会被顶栏或窗口控件遮挡。
39
+
36
40
  ## 标注后发送
37
41
 
38
42
  查看器顶部的铅笔按钮打开标注编辑器(类似 ChatGPT / iOS 标记):
@@ -61,6 +65,7 @@ dsh plugin add @qzsy/dsh-image-viewer
61
65
  bun run build # dist/index.js + dist/client.js
62
66
  bun run typecheck
63
67
  node test/smoke.mjs # jsdom 冒烟测试:查看器
68
+ node test/layout.mjs # jsdom 布局测试:90% 宽度上限与桌面窗口留白
64
69
  node test/editor.mjs # jsdom 冒烟测试:标注与注入输入框
65
70
  ~~~
66
71
 
package/dist/client.js CHANGED
@@ -166,6 +166,51 @@ window.__ModuleLoader__.load({
166
166
 
167
167
  const reduceMotion = () => media('(prefers-reduced-motion: reduce)');
168
168
 
169
+ /**
170
+ * Top strip reserved by the host shell: on the Desktop app the Windows
171
+ * caption buttons / macOS traffic lights are drawn above the page, so the
172
+ * shell publishes `--dsh-frame-overlay-top` (clearance + 20px) for dialogs
173
+ * and menus. A plain browser publishes nothing, so this returns 0.
174
+ */
175
+ function frameTop() {
176
+ try {
177
+ const html = document.documentElement;
178
+ // Unregistered custom properties keep `calc(a + b)`; resolve the px terms.
179
+ const raw = String(getComputedStyle(html).getPropertyValue('--dsh-frame-overlay-top') || '').trim();
180
+ const resolved = calcPx(raw);
181
+ if (resolved > 0) return resolved;
182
+ // Fallback: the caption height the Desktop shell writes inline.
183
+ const caption = parseFloat(html.style.getPropertyValue('--dsh-windows-titlebar-height') || '');
184
+ if (Number.isFinite(caption) && caption > 0) return caption + 20;
185
+ if (html.getAttribute('data-platform') === 'darwin') return 68;
186
+ return 0;
187
+ } catch {
188
+ return 0;
189
+ }
190
+ }
191
+
192
+ /** `48px`, `calc(40px + 20px)` or `calc(48px + 20px)` -> number of px. */
193
+ function calcPx(text) {
194
+ if (text === '') return 0;
195
+ if (/^-?\d*\.?\d+(px)?$/.test(text)) return parseFloat(text);
196
+ const body = text.replace(/^calc\(/, '').replace(/\)$/, '');
197
+ const terms = body.match(/[+-]?\s*\d*\.?\d+px/g);
198
+ if (terms === null) return 0;
199
+ let total = 0;
200
+ for (const term of terms) {
201
+ const value = parseFloat(term.replace(/\s/g, ''));
202
+ if (!Number.isFinite(value)) return 0;
203
+ total += value;
204
+ }
205
+ return total;
206
+ }
207
+
208
+ /** Keep the overlay's own top bar below the shell's window chrome. */
209
+ function chromeInset(root) {
210
+ const top = frameTop();
211
+ root.style.setProperty('--qiv-top-inset', (top > 0 ? top : 10) + 'px');
212
+ }
213
+
169
214
  function format(text, params) {
170
215
  return String(text).replace(/\{(\w+)\}/g, (match, key) =>
171
216
  params !== undefined && params !== null && key in params ? String(params[key]) : match,
@@ -366,7 +411,7 @@ window.__ModuleLoader__.load({
366
411
  @keyframes qiv-rot{to{transform:rotate(360deg)}}
367
412
  .qiv-chrome{transition:opacity .22s ease}
368
413
  [${ROOT_ATTR}][data-chrome=hidden] .qiv-chrome,[${ROOT_ATTR}][data-state=closing] .qiv-chrome,[${ROOT_ATTR}][data-state=opening] .qiv-chrome,[${ROOT_ATTR}][data-gesture=dismiss] .qiv-chrome,[${ROOT_ATTR}][data-gesture=pinch] .qiv-chrome{opacity:0;pointer-events:none}
369
- .qiv-top{position:absolute;left:0;right:0;top:0;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:calc(env(safe-area-inset-top,0px) + 10px) calc(env(safe-area-inset-right,0px) + 12px) 18px calc(env(safe-area-inset-left,0px) + 18px);background:linear-gradient(rgba(0,0,0,.5),rgba(0,0,0,0))}
414
+ .qiv-top{position:absolute;left:0;right:0;top:0;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:calc(env(safe-area-inset-top,0px) + var(--qiv-top-inset,10px)) calc(env(safe-area-inset-right,0px) + 12px) 18px calc(env(safe-area-inset-left,0px) + 18px);background:linear-gradient(rgba(0,0,0,.5),rgba(0,0,0,0))}
370
415
  .qiv-count{font-size:14px;font-weight:600;letter-spacing:.02em;font-variant-numeric:tabular-nums;text-shadow:0 1px 2px rgba(0,0,0,.5)}
371
416
  .qiv-actions{display:flex;gap:8px;margin-left:auto}
372
417
  .qiv-btn{appearance:none;width:40px;height:40px;padding:0;border:0;border-radius:999px;background:rgba(255,255,255,.14);color:inherit;display:grid;place-items:center;cursor:pointer;text-decoration:none;-webkit-backdrop-filter:blur(14px);backdrop-filter:blur(14px);transition:background-color .15s,opacity .15s}
@@ -504,6 +549,8 @@ window.__ModuleLoader__.load({
504
549
  function openViewer(items, startIndex, t, onDestroyed) {
505
550
  const n = items.length;
506
551
  const coarse = media('(pointer: coarse)');
552
+ /** Window-chrome strip the shell paints above the page (Desktop app only). */
553
+ let chromeTop = frameTop();
507
554
  const restoreFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
508
555
  const s = { x: 0, y: 0, scale: 1, clip: 0, radius: 0, bg: 0, alpha: 1, trackX: 0 };
509
556
  const slides = new Map();
@@ -529,6 +576,7 @@ window.__ModuleLoader__.load({
529
576
  //#region dom
530
577
  const root = h('div', 'qiv', { role: 'dialog', 'aria-modal': 'true', 'aria-label': t('dialog'), tabindex: '-1' });
531
578
  root.setAttribute(ROOT_ATTR, '');
579
+ chromeInset(root);
532
580
  root.dataset.state = 'opening';
533
581
  if (coarse) root.setAttribute('data-coarse', '');
534
582
  if (n <= 1) root.setAttribute('data-single', '');
@@ -577,8 +625,11 @@ window.__ModuleLoader__.load({
577
625
 
578
626
  //#region geometry
579
627
  function pads() {
580
- if (coarse) return { x: 0, y: 0 };
581
- return { x: n > 1 ? 76 : 32, y: n > 1 ? 84 : 64 };
628
+ // The image never exceeds 90% of the viewport width, and never slides
629
+ // under the shell's window chrome or our own top bar.
630
+ const x = Math.max(coarse ? 8 : 24, vw * 0.05);
631
+ const y = Math.max(coarse ? 12 : n > 1 ? 84 : 64, chromeTop + 28);
632
+ return { x, y };
582
633
  }
583
634
 
584
635
  /** Displayed size at scale 1, and its ratio to natural pixels. */
@@ -1294,6 +1345,9 @@ window.__ModuleLoader__.load({
1294
1345
  function onResize() {
1295
1346
  vw = root.clientWidth || window.innerWidth;
1296
1347
  vh = root.clientHeight || window.innerHeight;
1348
+ // Native fullscreen drops the shell's chrome strip, so re-read it.
1349
+ chromeTop = frameTop();
1350
+ chromeInset(root);
1297
1351
  anim.stop(['x', 'y', 'scale', 'trackX']);
1298
1352
  s.trackX = 0;
1299
1353
  clearOutgoing();
@@ -1712,6 +1766,7 @@ window.__ModuleLoader__.load({
1712
1766
  */
1713
1767
  function openEditor(item, t, hooks) {
1714
1768
  const root = h('div', 'qie', { [EDIT_ATTR]: '', [IGNORE_ATTR]: '', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('edit.dialog'), tabindex: '-1' });
1769
+ chromeInset(root);
1715
1770
  const btn = (className, label, icon, extra) => {
1716
1771
  const b = h('button', className, { type: 'button', 'aria-label': label, title: label, ...(extra || {}) });
1717
1772
  b.innerHTML = icon;
@@ -1818,7 +1873,8 @@ window.__ModuleLoader__.load({
1818
1873
  const aw = area.clientWidth || window.innerWidth;
1819
1874
  const ah = area.clientHeight || window.innerHeight * 0.7;
1820
1875
  if (W === 0 || H === 0) return;
1821
- const k = Math.min((aw - 24) / W, (ah - 24) / H);
1876
+ // The canvas keeps the same 90% width cap as the viewer.
1877
+ const k = Math.min((aw * 0.9) / W, (ah - 24) / H);
1822
1878
  fitW = Math.max(1, W * k);
1823
1879
  fitH = Math.max(1, H * k);
1824
1880
  stage.style.width = fitW + 'px';
@@ -2429,7 +2485,7 @@ window.__ModuleLoader__.load({
2429
2485
  const EDIT_CSS = `
2430
2486
  [${EDIT_ATTR}]{position:fixed;inset:0;z-index:2147483001;display:flex;flex-direction:column;background:#000;color:#fff;font:13px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;overscroll-behavior:contain;outline:none;--qie-ink:#ff3b30}
2431
2487
  [${EDIT_ATTR}] *{box-sizing:border-box}
2432
- .qie-top{position:relative;flex:none;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:8px;padding:calc(env(safe-area-inset-top,0px) + 10px) calc(env(safe-area-inset-right,0px) + 14px) 10px calc(env(safe-area-inset-left,0px) + 14px)}
2488
+ .qie-top{position:relative;flex:none;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:8px;padding:calc(env(safe-area-inset-top,0px) + var(--qiv-top-inset,10px)) calc(env(safe-area-inset-right,0px) + 14px) 10px calc(env(safe-area-inset-left,0px) + 14px)}
2433
2489
  .qie-round,.qie-tool,.qie-shape{appearance:none;border:0;padding:0;color:inherit;display:grid;place-items:center;cursor:pointer;transition:background-color .15s,opacity .15s}
2434
2490
  .qie-round{width:44px;height:44px;border-radius:999px;background:rgba(255,255,255,.14)}
2435
2491
  .qie-round:hover{background:rgba(255,255,255,.24)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qzsy/dsh-image-viewer",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "iPhone Photos-style full-screen image viewer for the DSH conversation: zoom from thumbnail, pinch/double-tap zoom, momentum pan, swipe between images, swipe down to close; annotate an image and drop it into the chat box.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@
57
57
  "scripts": {
58
58
  "build": "bun run ../../scripts/build-package.mjs .",
59
59
  "typecheck": "bun exec tsc -p tsconfig.json --noEmit",
60
- "test": "node test/smoke.mjs && node test/editor.mjs"
60
+ "test": "node test/smoke.mjs && node test/layout.mjs && node test/editor.mjs"
61
61
  },
62
62
  "dshBuild": {
63
63
  "host": "src/index.ts",