@qzsy/dsh-image-viewer 0.2.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/README.md +17 -2
- package/dist/client.js +208 -12
- package/package.json +2 -2
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 标记):
|
|
@@ -44,16 +48,26 @@ dsh plugin add @qzsy/dsh-image-viewer
|
|
|
44
48
|
- 点 ✓ 后导出 PNG(超过 8 MB 改为 JPEG),以粘贴的方式放进对话输入框,查看器关闭,光标留在输入框,补充提示词后即可发送
|
|
45
49
|
- 找不到输入框时改为下载图片;来自其他站点且不允许跨域的图片,浏览器会禁止导出,会给出提示
|
|
46
50
|
|
|
51
|
+
## 图片文件链接
|
|
52
|
+
|
|
53
|
+
消息里的 Markdown 链接如果指向图片文件(例如 `[选品中心](docs/acceptance/prod/mobile-leader-products.png)`),点击也走这个查看器,而不是打开文件面板:
|
|
54
|
+
|
|
55
|
+
- 悬停时鼠标变成放大镜,提示这里可以点开看图
|
|
56
|
+
- 同一段消息里的多个图片链接组成一个相册,可以左右滑动切换
|
|
57
|
+
- 图片地址直接复用 DSH 已解析好的文件地址;桌面端把 `dsh-app://` 地址改写成同源 http 地址,标注后导出不会被 canvas 跨域拦下
|
|
58
|
+
- 目标不是图片的普通文件链接、以及输入框里的 `@文件` 引用,仍按原样打开
|
|
59
|
+
|
|
47
60
|
## 工作方式
|
|
48
61
|
|
|
49
62
|
插件只有客户端部分,不注册任何 Host 能力,不发起网络请求。它在 `document` 捕获阶段监听点击:
|
|
50
63
|
|
|
51
64
|
- 带 `cursor: zoom-in` 的按钮(对话中的 Markdown 图片、消息附件图片、输入框附件缩略图)
|
|
65
|
+
- 指向图片文件的文件链接按钮(见上一节)
|
|
52
66
|
- 或面积不小于 96×64 的裸 `<img>`
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
命中后阻止内置查看器(或文件面板),并收集同一滚动区域内的全部可预览图片作为相册。
|
|
55
69
|
|
|
56
|
-
以下情况保持原样:按住 Ctrl / ⌘ / Shift / Alt 点击、图片在链接内、位于导航栏 / 工具栏 /
|
|
70
|
+
以下情况保持原样:按住 Ctrl / ⌘ / Shift / Alt 点击、图片在链接内、位于导航栏 / 工具栏 / 菜单中、在可编辑区域内或输入框里,或元素(及其祖先)带有 `data-qiv-ignore` 属性。
|
|
57
71
|
|
|
58
72
|
## 开发
|
|
59
73
|
|
|
@@ -61,6 +75,7 @@ dsh plugin add @qzsy/dsh-image-viewer
|
|
|
61
75
|
bun run build # dist/index.js + dist/client.js
|
|
62
76
|
bun run typecheck
|
|
63
77
|
node test/smoke.mjs # jsdom 冒烟测试:查看器
|
|
78
|
+
node test/layout.mjs # jsdom 布局测试:90% 宽度上限与桌面窗口留白
|
|
64
79
|
node test/editor.mjs # jsdom 冒烟测试:标注与注入输入框
|
|
65
80
|
~~~
|
|
66
81
|
|
package/dist/client.js
CHANGED
|
@@ -29,6 +29,8 @@ window.__ModuleLoader__.load({
|
|
|
29
29
|
const ROOT_ATTR = 'data-qiv-root';
|
|
30
30
|
const STYLE_ATTR = 'data-qiv-style';
|
|
31
31
|
const IGNORE_ATTR = 'data-qiv-ignore';
|
|
32
|
+
/** Attribute set on image file links so they read as zoomable. */
|
|
33
|
+
const LINK_ATTR = 'data-qiv-link';
|
|
32
34
|
|
|
33
35
|
/** Horizontal gap between slides, in CSS px. */
|
|
34
36
|
const GAP = 24;
|
|
@@ -166,6 +168,51 @@ window.__ModuleLoader__.load({
|
|
|
166
168
|
|
|
167
169
|
const reduceMotion = () => media('(prefers-reduced-motion: reduce)');
|
|
168
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Top strip reserved by the host shell: on the Desktop app the Windows
|
|
173
|
+
* caption buttons / macOS traffic lights are drawn above the page, so the
|
|
174
|
+
* shell publishes `--dsh-frame-overlay-top` (clearance + 20px) for dialogs
|
|
175
|
+
* and menus. A plain browser publishes nothing, so this returns 0.
|
|
176
|
+
*/
|
|
177
|
+
function frameTop() {
|
|
178
|
+
try {
|
|
179
|
+
const html = document.documentElement;
|
|
180
|
+
// Unregistered custom properties keep `calc(a + b)`; resolve the px terms.
|
|
181
|
+
const raw = String(getComputedStyle(html).getPropertyValue('--dsh-frame-overlay-top') || '').trim();
|
|
182
|
+
const resolved = calcPx(raw);
|
|
183
|
+
if (resolved > 0) return resolved;
|
|
184
|
+
// Fallback: the caption height the Desktop shell writes inline.
|
|
185
|
+
const caption = parseFloat(html.style.getPropertyValue('--dsh-windows-titlebar-height') || '');
|
|
186
|
+
if (Number.isFinite(caption) && caption > 0) return caption + 20;
|
|
187
|
+
if (html.getAttribute('data-platform') === 'darwin') return 68;
|
|
188
|
+
return 0;
|
|
189
|
+
} catch {
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** `48px`, `calc(40px + 20px)` or `calc(48px + 20px)` -> number of px. */
|
|
195
|
+
function calcPx(text) {
|
|
196
|
+
if (text === '') return 0;
|
|
197
|
+
if (/^-?\d*\.?\d+(px)?$/.test(text)) return parseFloat(text);
|
|
198
|
+
const body = text.replace(/^calc\(/, '').replace(/\)$/, '');
|
|
199
|
+
const terms = body.match(/[+-]?\s*\d*\.?\d+px/g);
|
|
200
|
+
if (terms === null) return 0;
|
|
201
|
+
let total = 0;
|
|
202
|
+
for (const term of terms) {
|
|
203
|
+
const value = parseFloat(term.replace(/\s/g, ''));
|
|
204
|
+
if (!Number.isFinite(value)) return 0;
|
|
205
|
+
total += value;
|
|
206
|
+
}
|
|
207
|
+
return total;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Keep the overlay's own top bar below the shell's window chrome. */
|
|
211
|
+
function chromeInset(root) {
|
|
212
|
+
const top = frameTop();
|
|
213
|
+
root.style.setProperty('--qiv-top-inset', (top > 0 ? top : 10) + 'px');
|
|
214
|
+
}
|
|
215
|
+
|
|
169
216
|
function format(text, params) {
|
|
170
217
|
return String(text).replace(/\{(\w+)\}/g, (match, key) =>
|
|
171
218
|
params !== undefined && params !== null && key in params ? String(params[key]) : match,
|
|
@@ -366,7 +413,7 @@ window.__ModuleLoader__.load({
|
|
|
366
413
|
@keyframes qiv-rot{to{transform:rotate(360deg)}}
|
|
367
414
|
.qiv-chrome{transition:opacity .22s ease}
|
|
368
415
|
[${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))}
|
|
416
|
+
.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
417
|
.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
418
|
.qiv-actions{display:flex;gap:8px;margin-left:auto}
|
|
372
419
|
.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}
|
|
@@ -387,6 +434,7 @@ window.__ModuleLoader__.load({
|
|
|
387
434
|
.qiv-thumb img{display:block;width:100%;height:100%;object-fit:cover;pointer-events:none}
|
|
388
435
|
.qiv-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
389
436
|
@media (prefers-reduced-motion:reduce){.qiv-chrome,.qiv-thumb{transition:none}}
|
|
437
|
+
[${LINK_ATTR}]{cursor:zoom-in}
|
|
390
438
|
`;
|
|
391
439
|
|
|
392
440
|
function installStyles() {
|
|
@@ -411,6 +459,74 @@ window.__ModuleLoader__.load({
|
|
|
411
459
|
|
|
412
460
|
const srcOf = (img) => img.currentSrc || img.src || '';
|
|
413
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Desktop resolves workspace files to `dsh-app://app/api/file?…`. When the
|
|
464
|
+
* page itself is served over http(s), prefer that same origin so the canvas
|
|
465
|
+
* used by the annotation editor is not tainted and stays exportable.
|
|
466
|
+
*/
|
|
467
|
+
function normalizeSrc(src) {
|
|
468
|
+
try {
|
|
469
|
+
if (src.startsWith('dsh-app://app/')) {
|
|
470
|
+
const base = document.baseURI;
|
|
471
|
+
if (/^https?:/i.test(base)) return new URL(src.slice('dsh-app://app/'.length), base).href;
|
|
472
|
+
}
|
|
473
|
+
} catch {
|
|
474
|
+
// keep the original
|
|
475
|
+
}
|
|
476
|
+
return src;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function fiberOf(node) {
|
|
480
|
+
for (const key of Object.keys(node)) {
|
|
481
|
+
if (key.startsWith('__reactFiber$') || key.startsWith('__reactInternalInstance$')) return node[key];
|
|
482
|
+
}
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Depth-limited scan of a React element tree for a string `src` prop. */
|
|
487
|
+
function srcInElement(value, depth = 0) {
|
|
488
|
+
if (depth > 6 || value === null || value === undefined || typeof value !== 'object') return null;
|
|
489
|
+
const props = value.props;
|
|
490
|
+
if (props !== undefined && props !== null && typeof props === 'object') {
|
|
491
|
+
if (typeof props.src === 'string' && props.src !== '') return props.src;
|
|
492
|
+
const nested = srcInElement(props.children, depth + 1);
|
|
493
|
+
if (nested !== null) return nested;
|
|
494
|
+
}
|
|
495
|
+
if (Array.isArray(value)) {
|
|
496
|
+
for (const child of value) {
|
|
497
|
+
const found = srcInElement(child, depth + 1);
|
|
498
|
+
if (found !== null) return found;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* DSH renders a markdown link that points at a workspace file as a
|
|
506
|
+
* `<button class="…fileLink">` with no href; clicking it opens the file
|
|
507
|
+
* panel. For image files the hover card wrapped around that button is
|
|
508
|
+
* built eagerly with the already-resolved image URL, so the URL can be read
|
|
509
|
+
* from the React fiber props instead of re-implementing the app's
|
|
510
|
+
* workspace-relative path resolution. Returns null for anything else.
|
|
511
|
+
*/
|
|
512
|
+
function imageLinkOf(host) {
|
|
513
|
+
try {
|
|
514
|
+
if (host.getElementsByTagName('img').length !== 0) return null;
|
|
515
|
+
let fiber = fiberOf(host);
|
|
516
|
+
for (let up = 0; up < 14 && fiber !== null && fiber !== undefined; up += 1) {
|
|
517
|
+
const props = fiber.memoizedProps;
|
|
518
|
+
if (props !== null && props !== undefined && typeof props === 'object') {
|
|
519
|
+
const src = srcInElement(props.content);
|
|
520
|
+
if (src !== null) return { src: normalizeSrc(src), label: (host.textContent || '').trim() };
|
|
521
|
+
}
|
|
522
|
+
fiber = fiber.return;
|
|
523
|
+
}
|
|
524
|
+
} catch {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
|
|
414
530
|
/**
|
|
415
531
|
* Map a click target to a previewable image, or null to let the click
|
|
416
532
|
* through. Buttons qualify only when they wrap exactly one image and show
|
|
@@ -425,11 +541,18 @@ window.__ModuleLoader__.load({
|
|
|
425
541
|
if (host !== null) {
|
|
426
542
|
if (host.closest('a[href]') !== null) return null;
|
|
427
543
|
const imgs = host.getElementsByTagName('img');
|
|
428
|
-
if (imgs.length
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
544
|
+
if (imgs.length === 1) {
|
|
545
|
+
const img = imgs[0];
|
|
546
|
+
if (!isZoomCursor(host) && !isZoomCursor(img)) return null;
|
|
547
|
+
if (srcOf(img) === '') return null;
|
|
548
|
+
return { host, img };
|
|
549
|
+
}
|
|
550
|
+
// A markdown link to an image file: the app would open the file panel.
|
|
551
|
+
if (imgs.length === 0 && host.closest('[data-composer-seat]') === null) {
|
|
552
|
+
const link = imageLinkOf(host);
|
|
553
|
+
if (link !== null) return { host, kind: 'link', src: link.src, label: link.label };
|
|
554
|
+
}
|
|
555
|
+
return null;
|
|
433
556
|
}
|
|
434
557
|
if (node.tagName !== 'IMG') return null;
|
|
435
558
|
const img = node;
|
|
@@ -458,12 +581,31 @@ window.__ModuleLoader__.load({
|
|
|
458
581
|
}
|
|
459
582
|
|
|
460
583
|
function makeItem(trigger, scope) {
|
|
584
|
+
if (trigger.kind === 'link') {
|
|
585
|
+
// A link chip is not a thumbnail: it keeps its own size until the image
|
|
586
|
+
// loads, and it stays visible behind the viewer.
|
|
587
|
+
return {
|
|
588
|
+
el: trigger.host,
|
|
589
|
+
host: trigger.host,
|
|
590
|
+
src: trigger.src,
|
|
591
|
+
alt: trigger.label || '',
|
|
592
|
+
referrerPolicy: 'no-referrer',
|
|
593
|
+
w: 0,
|
|
594
|
+
h: 0,
|
|
595
|
+
fw0: 0,
|
|
596
|
+
fh0: 0,
|
|
597
|
+
scope,
|
|
598
|
+
inset: { x: 0, y: 0 },
|
|
599
|
+
index: 0,
|
|
600
|
+
transient: true,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
461
603
|
const img = trigger.img;
|
|
462
604
|
const rect = img.getBoundingClientRect();
|
|
463
605
|
return {
|
|
464
606
|
el: img,
|
|
465
607
|
host: trigger.host,
|
|
466
|
-
src: srcOf(img),
|
|
608
|
+
src: normalizeSrc(srcOf(img)),
|
|
467
609
|
alt: img.getAttribute('alt') || '',
|
|
468
610
|
referrerPolicy: img.referrerPolicy || '',
|
|
469
611
|
w: img.naturalWidth || 0,
|
|
@@ -478,6 +620,28 @@ window.__ModuleLoader__.load({
|
|
|
478
620
|
|
|
479
621
|
function collect(trigger) {
|
|
480
622
|
const scope = scrollerOf(trigger.host);
|
|
623
|
+
// Image links in one scroll area form one gallery, like inline images do.
|
|
624
|
+
if (trigger.kind === 'link') {
|
|
625
|
+
const seen = new Set();
|
|
626
|
+
const items = [];
|
|
627
|
+
const hosts = [...scope.querySelectorAll('button,[role="button"]')];
|
|
628
|
+
if (!hosts.includes(trigger.host)) hosts.unshift(trigger.host);
|
|
629
|
+
for (const host of hosts) {
|
|
630
|
+
if (items.length >= MAX_ITEMS) break;
|
|
631
|
+
if (seen.has(host)) continue;
|
|
632
|
+
if (host !== trigger.host && (host.closest('[data-composer-seat]') !== null || host.getElementsByTagName('img').length !== 0)) continue;
|
|
633
|
+
const link = host === trigger.host ? { src: trigger.src, label: trigger.label } : imageLinkOf(host);
|
|
634
|
+
if (link === null) continue;
|
|
635
|
+
seen.add(host);
|
|
636
|
+
const entry = host === trigger.host ? trigger : { host, kind: 'link', src: link.src, label: link.label };
|
|
637
|
+
items.push(makeItem(entry, scope));
|
|
638
|
+
}
|
|
639
|
+
items.forEach((item, i) => {
|
|
640
|
+
item.index = i;
|
|
641
|
+
});
|
|
642
|
+
const at = items.findIndex((item) => item.el === trigger.host);
|
|
643
|
+
return { items, index: at < 0 ? 0 : at };
|
|
644
|
+
}
|
|
481
645
|
const hasLayout = trigger.img.getBoundingClientRect().width > 0;
|
|
482
646
|
const seen = new Set();
|
|
483
647
|
const items = [];
|
|
@@ -504,6 +668,8 @@ window.__ModuleLoader__.load({
|
|
|
504
668
|
function openViewer(items, startIndex, t, onDestroyed) {
|
|
505
669
|
const n = items.length;
|
|
506
670
|
const coarse = media('(pointer: coarse)');
|
|
671
|
+
/** Window-chrome strip the shell paints above the page (Desktop app only). */
|
|
672
|
+
let chromeTop = frameTop();
|
|
507
673
|
const restoreFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
508
674
|
const s = { x: 0, y: 0, scale: 1, clip: 0, radius: 0, bg: 0, alpha: 1, trackX: 0 };
|
|
509
675
|
const slides = new Map();
|
|
@@ -529,6 +695,7 @@ window.__ModuleLoader__.load({
|
|
|
529
695
|
//#region dom
|
|
530
696
|
const root = h('div', 'qiv', { role: 'dialog', 'aria-modal': 'true', 'aria-label': t('dialog'), tabindex: '-1' });
|
|
531
697
|
root.setAttribute(ROOT_ATTR, '');
|
|
698
|
+
chromeInset(root);
|
|
532
699
|
root.dataset.state = 'opening';
|
|
533
700
|
if (coarse) root.setAttribute('data-coarse', '');
|
|
534
701
|
if (n <= 1) root.setAttribute('data-single', '');
|
|
@@ -577,8 +744,11 @@ window.__ModuleLoader__.load({
|
|
|
577
744
|
|
|
578
745
|
//#region geometry
|
|
579
746
|
function pads() {
|
|
580
|
-
|
|
581
|
-
|
|
747
|
+
// The image never exceeds 90% of the viewport width, and never slides
|
|
748
|
+
// under the shell's window chrome or our own top bar.
|
|
749
|
+
const x = Math.max(coarse ? 8 : 24, vw * 0.05);
|
|
750
|
+
const y = Math.max(coarse ? 12 : n > 1 ? 84 : 64, chromeTop + 28);
|
|
751
|
+
return { x, y };
|
|
582
752
|
}
|
|
583
753
|
|
|
584
754
|
/** Displayed size at scale 1, and its ratio to natural pixels. */
|
|
@@ -768,7 +938,8 @@ window.__ModuleLoader__.load({
|
|
|
768
938
|
function hideSource(item) {
|
|
769
939
|
if (hiddenItem === item) return;
|
|
770
940
|
showSource();
|
|
771
|
-
|
|
941
|
+
// Link chips stay visible: hiding a text link would look like a gap.
|
|
942
|
+
if (item && item.transient !== true && item.el.isConnected) {
|
|
772
943
|
item.prevVisibility = item.el.style.visibility;
|
|
773
944
|
item.el.style.visibility = 'hidden';
|
|
774
945
|
hiddenItem = item;
|
|
@@ -1294,6 +1465,9 @@ window.__ModuleLoader__.load({
|
|
|
1294
1465
|
function onResize() {
|
|
1295
1466
|
vw = root.clientWidth || window.innerWidth;
|
|
1296
1467
|
vh = root.clientHeight || window.innerHeight;
|
|
1468
|
+
// Native fullscreen drops the shell's chrome strip, so re-read it.
|
|
1469
|
+
chromeTop = frameTop();
|
|
1470
|
+
chromeInset(root);
|
|
1297
1471
|
anim.stop(['x', 'y', 'scale', 'trackX']);
|
|
1298
1472
|
s.trackX = 0;
|
|
1299
1473
|
clearOutgoing();
|
|
@@ -1712,6 +1886,7 @@ window.__ModuleLoader__.load({
|
|
|
1712
1886
|
*/
|
|
1713
1887
|
function openEditor(item, t, hooks) {
|
|
1714
1888
|
const root = h('div', 'qie', { [EDIT_ATTR]: '', [IGNORE_ATTR]: '', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('edit.dialog'), tabindex: '-1' });
|
|
1889
|
+
chromeInset(root);
|
|
1715
1890
|
const btn = (className, label, icon, extra) => {
|
|
1716
1891
|
const b = h('button', className, { type: 'button', 'aria-label': label, title: label, ...(extra || {}) });
|
|
1717
1892
|
b.innerHTML = icon;
|
|
@@ -1818,7 +1993,8 @@ window.__ModuleLoader__.load({
|
|
|
1818
1993
|
const aw = area.clientWidth || window.innerWidth;
|
|
1819
1994
|
const ah = area.clientHeight || window.innerHeight * 0.7;
|
|
1820
1995
|
if (W === 0 || H === 0) return;
|
|
1821
|
-
|
|
1996
|
+
// The canvas keeps the same 90% width cap as the viewer.
|
|
1997
|
+
const k = Math.min((aw * 0.9) / W, (ah - 24) / H);
|
|
1822
1998
|
fitW = Math.max(1, W * k);
|
|
1823
1999
|
fitH = Math.max(1, H * k);
|
|
1824
2000
|
stage.style.width = fitW + 'px';
|
|
@@ -2429,7 +2605,7 @@ window.__ModuleLoader__.load({
|
|
|
2429
2605
|
const EDIT_CSS = `
|
|
2430
2606
|
[${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
2607
|
[${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)}
|
|
2608
|
+
.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
2609
|
.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
2610
|
.qie-round{width:44px;height:44px;border-radius:999px;background:rgba(255,255,255,.14)}
|
|
2435
2611
|
.qie-round:hover{background:rgba(255,255,255,.24)}
|
|
@@ -2481,6 +2657,25 @@ window.__ModuleLoader__.load({
|
|
|
2481
2657
|
//#endregion
|
|
2482
2658
|
|
|
2483
2659
|
//#region click interception
|
|
2660
|
+
/**
|
|
2661
|
+
* Mark image file links with a zoom cursor before the first click, so the
|
|
2662
|
+
* transcript reads as "this opens the viewer" rather than "this opens a file".
|
|
2663
|
+
* Resolved lazily on hover and cached on the element itself.
|
|
2664
|
+
*/
|
|
2665
|
+
function installLinkAffordance() {
|
|
2666
|
+
const seen = new WeakSet();
|
|
2667
|
+
const onOver = (event) => {
|
|
2668
|
+
const node = event.target;
|
|
2669
|
+
if (!(node instanceof Element)) return;
|
|
2670
|
+
const host = node.closest('button,[role="button"]');
|
|
2671
|
+
if (host === null || seen.has(host) || host.closest(`[${ROOT_ATTR}],[${EDIT_ATTR}]`) !== null) return;
|
|
2672
|
+
seen.add(host);
|
|
2673
|
+
if (imageLinkOf(host) !== null) host.setAttribute(LINK_ATTR, '');
|
|
2674
|
+
};
|
|
2675
|
+
document.addEventListener('pointerover', onOver, true);
|
|
2676
|
+
return () => document.removeEventListener('pointerover', onOver, true);
|
|
2677
|
+
}
|
|
2678
|
+
|
|
2484
2679
|
function installInterceptor(t) {
|
|
2485
2680
|
let viewer = null;
|
|
2486
2681
|
const onClick = (e) => {
|
|
@@ -2534,6 +2729,7 @@ window.__ModuleLoader__.load({
|
|
|
2534
2729
|
}
|
|
2535
2730
|
ctx.effect(() => installStyles(), 'image-viewer: styles');
|
|
2536
2731
|
ctx.effect(() => installInterceptor(t), 'image-viewer: click interceptor');
|
|
2732
|
+
ctx.effect(() => installLinkAffordance(), 'image-viewer: image-link affordance');
|
|
2537
2733
|
}
|
|
2538
2734
|
//#endregion
|
|
2539
2735
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qzsy/dsh-image-viewer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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 && node test/link.mjs"
|
|
61
61
|
},
|
|
62
62
|
"dshBuild": {
|
|
63
63
|
"host": "src/index.ts",
|