@qzsy/dsh-image-viewer 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +11 -3
- package/dist/client.js +183 -28
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 qzsy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 qzsy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -33,14 +33,16 @@ dsh plugin add @qzsy/dsh-image-viewer
|
|
|
33
33
|
|
|
34
34
|
系统开启“减少动态效果”时,所有动画直接跳到终态。
|
|
35
35
|
|
|
36
|
-
## 右键菜单
|
|
36
|
+
## 右键菜单 / 长按操作面板
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
在预览里右键任意图片,弹出两项操作(触屏上长按图片,从底部滑出操作面板):
|
|
39
39
|
|
|
40
40
|
- **复制图片**:把图片以 PNG 写进系统剪贴板,可以直接粘贴到聊天框、文档或设计工具。原图不是 PNG 时会先转码;来自其他站点、浏览器禁止跨域读取的图片会给出提示。
|
|
41
41
|
- **复制图片路径**:复制图片在磁盘上的真实路径(例如 `D:\shots\a.png`);不是本地文件(外链、data: 图片)时复制完整 URL。
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
桌面端是贴着鼠标的浮层菜单;`Esc` 或 `Tab` 收起菜单(`Esc` 再按一次才关闭查看器),`↑` `↓` 在菜单项间移动,`Enter` 执行,点击菜单外任意位置、滚轮、翻页或窗口尺寸变化都会自动收起。
|
|
44
|
+
|
|
45
|
+
触屏与触控笔(`pointer: coarse`,包括 iPad 和手机浏览器)改用底部操作面板:半透明遮罩之上滑出圆角面板,顶部是抓手与图片文件名,下面两行操作加一行“取消”,底部按 `env(safe-area-inset-bottom)` 让开 iPhone 手势条。长按 500ms 触发并带一次轻震动;点遮罩、点“取消”、下拉面板超过 72px 或按 `Esc` 都收起面板,查看器保持打开。
|
|
44
46
|
|
|
45
47
|
## 桌面端窗口边缘
|
|
46
48
|
|
|
@@ -78,6 +80,12 @@ DSH 桌面应用(Electron)会把 Windows 右上角的窗口按钮、macOS
|
|
|
78
80
|
|
|
79
81
|
以下情况保持原样:按住 Ctrl / ⌘ / Shift / Alt 点击、图片在链接内、位于导航栏 / 工具栏 / 菜单中、在可编辑区域内或输入框里,或元素(及其祖先)带有 `data-qiv-ignore` 属性。
|
|
80
82
|
|
|
83
|
+
对话框里的图片同样可以点开:插件面板常把详情弹层渲染成 `role="dialog" aria-modal="true"`,那里的截图正是最需要放大看的。只有查看器 / 标注器自己和 `data-qiv-ignore` 例外。
|
|
84
|
+
|
|
85
|
+
## 层级
|
|
86
|
+
|
|
87
|
+
查看器、标注器和提示条都会通过 popover API 进入浏览器的**顶层(top layer)**,而不是只靠 `z-index`。插件面板如果把弹层做成 `popover`(`@qzsy/dsh-super-kanban` 的悬浮看板就是这样),它的内容会盖住任何普通层元素;进入顶层之后查看器才能盖回去。没有 popover API 的旧浏览器退回原来的固定定位 + `z-index`。
|
|
88
|
+
|
|
81
89
|
## 开发
|
|
82
90
|
|
|
83
91
|
~~~bash
|
package/dist/client.js
CHANGED
|
@@ -32,6 +32,36 @@ window.__ModuleLoader__.load({
|
|
|
32
32
|
/** Attribute set on image file links so they read as zoomable. */
|
|
33
33
|
const LINK_ATTR = 'data-qiv-link';
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The popover API is the only way above a plugin panel that puts its own overlay in the top
|
|
37
|
+
* layer: super-kanban's floating board is a `popover`, so its detail sheet (and anything
|
|
38
|
+
* inside it) paints above every z-index, including this viewer.
|
|
39
|
+
*/
|
|
40
|
+
const TOP_LAYER = typeof HTMLElement !== 'undefined' && typeof HTMLElement.prototype.showPopover === 'function';
|
|
41
|
+
|
|
42
|
+
/** Show a root in the top layer; falls back to the plain fixed overlay on old engines. */
|
|
43
|
+
function enterTopLayer(node) {
|
|
44
|
+
if (!TOP_LAYER) return false;
|
|
45
|
+
try {
|
|
46
|
+
node.setAttribute('popover', 'manual');
|
|
47
|
+
node.showPopover();
|
|
48
|
+
return true;
|
|
49
|
+
} catch {
|
|
50
|
+
// `popover` without `showPopover()` would be display:none, so undo the attribute too.
|
|
51
|
+
node.removeAttribute('popover');
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function leaveTopLayer(node) {
|
|
57
|
+
if (!TOP_LAYER) return;
|
|
58
|
+
try {
|
|
59
|
+
node.hidePopover();
|
|
60
|
+
} catch {
|
|
61
|
+
// already closed or removed
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
35
65
|
/** Horizontal gap between slides, in CSS px. */
|
|
36
66
|
const GAP = 24;
|
|
37
67
|
/** Movement before a press becomes a drag. */
|
|
@@ -106,6 +136,7 @@ window.__ModuleLoader__.load({
|
|
|
106
136
|
'menu.copyFailed': '复制失败',
|
|
107
137
|
'menu.blocked': '图片来自其他站点,浏览器不允许复制',
|
|
108
138
|
'menu.unsupported': '当前环境不支持复制图片',
|
|
139
|
+
'menu.cancel': '取消',
|
|
109
140
|
};
|
|
110
141
|
const en = {
|
|
111
142
|
dialog: 'Image viewer',
|
|
@@ -156,6 +187,7 @@ window.__ModuleLoader__.load({
|
|
|
156
187
|
'menu.copyFailed': 'Copy failed',
|
|
157
188
|
'menu.blocked': 'This image comes from another site and the browser blocks copying it.',
|
|
158
189
|
'menu.unsupported': 'This environment cannot copy images.',
|
|
190
|
+
'menu.cancel': 'Cancel',
|
|
159
191
|
};
|
|
160
192
|
|
|
161
193
|
//#region utilities
|
|
@@ -410,12 +442,14 @@ window.__ModuleLoader__.load({
|
|
|
410
442
|
ellipse: svg('<ellipse cx="12" cy="12" rx="8.5" ry="6"/>'),
|
|
411
443
|
arrow: svg('<path d="M5 19L19 5M10 5h9v9"/>'),
|
|
412
444
|
line: svg('<path d="M5 19L19 5"/>'),
|
|
445
|
+
copy: svg('<rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M15.5 9V6.5A2.5 2.5 0 0013 4H6.5A2.5 2.5 0 004 6.5V13a2.5 2.5 0 002.5 2.5H9"/>'),
|
|
446
|
+
path: svg('<path d="M10.2 13.8a4.5 4.5 0 006.4 0l2.6-2.6a4.5 4.5 0 00-6.4-6.4l-1.5 1.5"/><path d="M13.8 10.2a4.5 4.5 0 00-6.4 0l-2.6 2.6a4.5 4.5 0 006.4 6.4l1.5-1.5"/>'),
|
|
413
447
|
};
|
|
414
448
|
//#endregion
|
|
415
449
|
|
|
416
450
|
//#region styles
|
|
417
451
|
const CSS = `
|
|
418
|
-
[${ROOT_ATTR}]{position:fixed;inset:0;z-index:2147483000;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;overscroll-behavior:contain;outline:none;color:#fff;font:13px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;cursor:default}
|
|
452
|
+
[${ROOT_ATTR}]{position:fixed;inset:0;z-index:2147483000;margin:0;width:auto;height:auto;max-width:none;max-height:none;padding:0;border:0;background:transparent;overflow:hidden;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;overscroll-behavior:contain;outline:none;color:#fff;font:13px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;cursor:default}
|
|
419
453
|
[${ROOT_ATTR}] *{box-sizing:border-box}
|
|
420
454
|
.qiv-bg{position:absolute;inset:0;background:#000}
|
|
421
455
|
.qiv-track{position:absolute;inset:0;overflow:hidden}
|
|
@@ -452,11 +486,24 @@ window.__ModuleLoader__.load({
|
|
|
452
486
|
.qiv-thumb img{display:block;width:100%;height:100%;object-fit:cover;pointer-events:none}
|
|
453
487
|
.qiv-menu{position:fixed;z-index:2147483005;min-width:188px;max-width:calc(100vw - 16px);padding:4px;border-radius:12px;background:rgba(38,38,40,.97);box-shadow:0 12px 32px rgba(0,0,0,.55),0 0 0 1px rgba(255,255,255,.08);color:#fff;font:13px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;animation:qiv-menu-in .12s ease-out}
|
|
454
488
|
@keyframes qiv-menu-in{from{opacity:0;transform:scale(.96)}to{opacity:1;transform:none}}
|
|
455
|
-
.qiv-menu-item{appearance:none;display:
|
|
489
|
+
.qiv-menu-item{appearance:none;display:flex;align-items:center;gap:9px;width:100%;padding:9px 12px;border:0;border-radius:8px;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
456
490
|
.qiv-menu-item:hover,.qiv-menu-item:focus-visible{background:rgba(255,255,255,.14);outline:none}
|
|
457
491
|
.qiv-menu-item[disabled]{opacity:.5;cursor:default}
|
|
492
|
+
.qiv-menu-glyph{flex:none;display:grid;place-items:center;opacity:.85}
|
|
493
|
+
.qiv-menu-glyph svg{width:18px;height:18px}
|
|
494
|
+
.qiv-menu-text{min-width:0;overflow:hidden;text-overflow:ellipsis}
|
|
495
|
+
.qiv-sheet-scrim{position:fixed;inset:0;z-index:2147483004;display:flex;align-items:flex-end;justify-content:center;box-sizing:border-box;background:rgba(0,0,0,.42);animation:qiv-scrim-in .18s ease-out}
|
|
496
|
+
@keyframes qiv-scrim-in{from{opacity:0}to{opacity:1}}
|
|
497
|
+
.qiv-sheet{position:relative;left:auto;top:auto;width:100%;min-width:0;max-width:520px;box-sizing:border-box;max-height:min(72vh,520px);overflow-y:auto;overscroll-behavior:contain;touch-action:pan-y;padding:6px 8px calc(env(safe-area-inset-bottom,0px) + 8px);border-radius:18px 18px 0 0;background:rgba(38,38,40,.98);box-shadow:0 -18px 48px rgba(0,0,0,.55),0 0 0 1px rgba(255,255,255,.08);animation:qiv-sheet-in .22s cubic-bezier(.2,.8,.2,1)}
|
|
498
|
+
@keyframes qiv-sheet-in{from{transform:translateY(100%)}to{transform:translateY(0)}}
|
|
499
|
+
.qiv-sheet-grab{width:36px;height:4px;margin:6px auto 8px;border-radius:999px;background:rgba(255,255,255,.28)}
|
|
500
|
+
.qiv-sheet-head{padding:0 10px 8px;font-size:12px;font-weight:600;letter-spacing:.02em;color:rgba(255,255,255,.62);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
501
|
+
.qiv-sheet-items{display:flex;flex-direction:column;gap:1px}
|
|
502
|
+
.qiv-sheet .qiv-menu-item{height:46px;padding:0 10px;border-radius:10px;font-size:14px}
|
|
503
|
+
.qiv-sheet-cancel{justify-content:center;height:46px;margin-top:6px;border-radius:10px;background:rgba(255,255,255,.1);font-weight:600}
|
|
504
|
+
.qiv-sheet-cancel:hover,.qiv-sheet-cancel:focus-visible{background:rgba(255,255,255,.18)}
|
|
458
505
|
.qiv-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
459
|
-
@media (prefers-reduced-motion:reduce){.qiv-chrome,.qiv-thumb{transition:none}.qiv-menu{animation:none}}
|
|
506
|
+
@media (prefers-reduced-motion:reduce){.qiv-chrome,.qiv-thumb{transition:none}.qiv-menu,.qiv-sheet,.qiv-sheet-scrim{animation:none}}
|
|
460
507
|
[${LINK_ATTR}]{cursor:zoom-in}
|
|
461
508
|
`;
|
|
462
509
|
|
|
@@ -563,7 +610,10 @@ window.__ModuleLoader__.load({
|
|
|
563
610
|
*/
|
|
564
611
|
function resolveTrigger(node) {
|
|
565
612
|
if (!(node instanceof Element)) return null;
|
|
566
|
-
|
|
613
|
+
// Dialogs are fair game: a plugin panel renders its detail sheet as `role="dialog"
|
|
614
|
+
// aria-modal="true"`, and the screenshots inside it are exactly what people want to
|
|
615
|
+
// enlarge. Only our own viewer/editor and `data-qiv-ignore` hosts stay hands-off.
|
|
616
|
+
if (node.closest(`[${ROOT_ATTR}],[${EDIT_ATTR}],[${IGNORE_ATTR}],[contenteditable="true"]`) !== null) return null;
|
|
567
617
|
const host = node.closest('button,[role="button"]');
|
|
568
618
|
if (host !== null) {
|
|
569
619
|
if (host.closest('a[href]') !== null) return null;
|
|
@@ -711,6 +761,12 @@ window.__ModuleLoader__.load({
|
|
|
711
761
|
let editor = null;
|
|
712
762
|
/** Open context menu, or null. It lives in <body>, above the viewer. */
|
|
713
763
|
let menu = null;
|
|
764
|
+
/** Dimmed backdrop of the bottom sheet, or null. */
|
|
765
|
+
let menuScrim = null;
|
|
766
|
+
/** Last pointer kind on the image: touch/pen menus open as a bottom sheet. */
|
|
767
|
+
let menuTouch = false;
|
|
768
|
+
/** Ignore the contextmenu that touch screens fire after a long press. */
|
|
769
|
+
let suppressContextUntil = 0;
|
|
714
770
|
let gesture = null;
|
|
715
771
|
let samples = [];
|
|
716
772
|
let tapTimer = 0;
|
|
@@ -772,6 +828,10 @@ window.__ModuleLoader__.load({
|
|
|
772
828
|
}
|
|
773
829
|
//#region context menu
|
|
774
830
|
function closeMenu(refocus) {
|
|
831
|
+
if (menuScrim !== null) {
|
|
832
|
+
menuScrim.remove();
|
|
833
|
+
menuScrim = null;
|
|
834
|
+
}
|
|
775
835
|
if (menu === null) return;
|
|
776
836
|
const node = menu;
|
|
777
837
|
menu = null;
|
|
@@ -785,9 +845,16 @@ window.__ModuleLoader__.load({
|
|
|
785
845
|
}
|
|
786
846
|
}
|
|
787
847
|
|
|
788
|
-
function menuItem(label, run) {
|
|
848
|
+
function menuItem(label, run, icon) {
|
|
789
849
|
const button = h('button', 'qiv-menu-item', { type: 'button', role: 'menuitem', tabindex: '-1' });
|
|
790
|
-
|
|
850
|
+
if (icon) {
|
|
851
|
+
const glyph = h('span', 'qiv-menu-glyph');
|
|
852
|
+
glyph.innerHTML = icon;
|
|
853
|
+
button.append(glyph);
|
|
854
|
+
}
|
|
855
|
+
const text = h('span', 'qiv-menu-text');
|
|
856
|
+
text.textContent = label;
|
|
857
|
+
button.append(text);
|
|
791
858
|
button.addEventListener('click', () => {
|
|
792
859
|
if (menu === null) return;
|
|
793
860
|
run(button);
|
|
@@ -795,37 +862,110 @@ window.__ModuleLoader__.load({
|
|
|
795
862
|
return button;
|
|
796
863
|
}
|
|
797
864
|
|
|
798
|
-
function
|
|
799
|
-
closeMenu();
|
|
865
|
+
function menuAction(kind) {
|
|
800
866
|
const item = items[index];
|
|
801
|
-
|
|
802
|
-
const copy = menuItem(t('menu.copyImage'), async (button) => {
|
|
803
|
-
button.disabled = true;
|
|
804
|
-
closeMenu();
|
|
805
|
-
const result = await copyImage(item.src);
|
|
806
|
-
toast(t(result === 'ok' ? 'menu.copiedImage' : result === 'blocked' ? 'menu.blocked' : result === 'unsupported' ? 'menu.unsupported' : 'menu.copyFailed'));
|
|
807
|
-
});
|
|
808
|
-
const path = menuItem(t('menu.copyPath'), async (button) => {
|
|
867
|
+
return async (button) => {
|
|
809
868
|
button.disabled = true;
|
|
810
869
|
closeMenu();
|
|
870
|
+
if (kind === 'copy') {
|
|
871
|
+
const result = await copyImage(item.src);
|
|
872
|
+
toast(t(result === 'ok' ? 'menu.copiedImage' : result === 'blocked' ? 'menu.blocked' : result === 'unsupported' ? 'menu.unsupported' : 'menu.copyFailed'));
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
811
875
|
const address = addressOf(item.src);
|
|
812
876
|
const ok = address !== null && (await copyText(address));
|
|
813
877
|
toast(t(ok ? 'menu.copiedPath' : 'menu.copyFailed'));
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Slide the sheet away on a downward drag, like a native action sheet.
|
|
883
|
+
* Runs before the tap logic because the sheet swallows its own pointers.
|
|
884
|
+
*/
|
|
885
|
+
function sheetDrag(node, scrim, cancel) {
|
|
886
|
+
let drag = null;
|
|
887
|
+
node.addEventListener('pointerdown', (e) => {
|
|
888
|
+
if (e.pointerType === 'mouse' && e.button !== 0) return;
|
|
889
|
+
if (e.target instanceof Element && e.target.closest('.qiv-menu-item') !== null) return;
|
|
890
|
+
drag = { id: e.pointerId, y: e.clientY, dy: 0, t: now() };
|
|
891
|
+
try {
|
|
892
|
+
node.setPointerCapture(e.pointerId);
|
|
893
|
+
} catch {
|
|
894
|
+
// capture is best-effort
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
node.addEventListener('pointermove', (e) => {
|
|
898
|
+
if (drag === null || e.pointerId !== drag.id) return;
|
|
899
|
+
drag.dy = Math.max(0, e.clientY - drag.y);
|
|
900
|
+
node.style.animation = 'none';
|
|
901
|
+
node.style.transform = `translateY(${drag.dy}px)`;
|
|
902
|
+
scrim.style.opacity = String(clamp(1 - drag.dy / Math.max(160, vh * 0.32), 0.2, 1));
|
|
814
903
|
});
|
|
815
|
-
|
|
904
|
+
const end = (e) => {
|
|
905
|
+
if (drag === null || e.pointerId !== drag.id) return;
|
|
906
|
+
const dy = drag.dy;
|
|
907
|
+
const v = dy / Math.max(1, now() - drag.t);
|
|
908
|
+
drag = null;
|
|
909
|
+
try {
|
|
910
|
+
node.releasePointerCapture(e.pointerId);
|
|
911
|
+
} catch {
|
|
912
|
+
// already released
|
|
913
|
+
}
|
|
914
|
+
if (dy > 72 || v > 0.5) {
|
|
915
|
+
closeMenu(true);
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
node.style.transform = '';
|
|
919
|
+
scrim.style.opacity = '';
|
|
920
|
+
};
|
|
921
|
+
node.addEventListener('pointerup', end);
|
|
922
|
+
node.addEventListener('pointercancel', end);
|
|
923
|
+
cancel.addEventListener('click', () => closeMenu(true));
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Open the image actions. Right click on a pointer device anchors a popover
|
|
928
|
+
* at the cursor; touch and pen get a bottom sheet with a scrim instead.
|
|
929
|
+
*/
|
|
930
|
+
function openMenu(x, y, sheet) {
|
|
931
|
+
closeMenu();
|
|
932
|
+
const node = sheet === true ? sheetNode() : anchoredNode(x, y);
|
|
816
933
|
document.body.append(node);
|
|
817
|
-
menu = node;
|
|
818
|
-
|
|
819
|
-
const rect = node.getBoundingClientRect();
|
|
820
|
-
node.style.left = clamp(x, 8, Math.max(8, window.innerWidth - rect.width - 8)) + 'px';
|
|
821
|
-
node.style.top = clamp(y, 8, Math.max(8, window.innerHeight - rect.height - 8)) + 'px';
|
|
934
|
+
menu = node.classList.contains('qiv-menu') ? node : node.querySelector('.qiv-menu');
|
|
935
|
+
const first = menu.querySelector('.qiv-menu-item');
|
|
822
936
|
try {
|
|
823
|
-
|
|
937
|
+
first.focus({ preventScroll: true });
|
|
824
938
|
} catch {
|
|
825
939
|
// focus is best-effort
|
|
826
940
|
}
|
|
827
941
|
}
|
|
828
942
|
|
|
943
|
+
function anchoredNode(x, y) {
|
|
944
|
+
const node = h('div', 'qiv-menu', { role: 'menu', 'aria-label': t('menu.label') });
|
|
945
|
+
node.append(menuItem(t('menu.copyImage'), menuAction('copy'), ICON.copy), menuItem(t('menu.copyPath'), menuAction('path'), ICON.path));
|
|
946
|
+
// Keep the popover on screen: clamp after it has its own size.
|
|
947
|
+
const rect = node.getBoundingClientRect();
|
|
948
|
+
node.style.left = clamp(x, 8, Math.max(8, window.innerWidth - rect.width - 8)) + 'px';
|
|
949
|
+
node.style.top = clamp(y, 8, Math.max(8, window.innerHeight - rect.height - 8)) + 'px';
|
|
950
|
+
return node;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function sheetNode() {
|
|
954
|
+
const scrim = h('div', 'qiv-sheet-scrim');
|
|
955
|
+
const node = h('div', 'qiv-menu qiv-sheet', { role: 'menu', 'aria-label': t('menu.label'), tabindex: '-1' });
|
|
956
|
+
const head = h('div', 'qiv-sheet-head');
|
|
957
|
+
head.textContent = fileName(items[index].src) || t('menu.label');
|
|
958
|
+
const body = h('div', 'qiv-sheet-items');
|
|
959
|
+
body.append(menuItem(t('menu.copyImage'), menuAction('copy'), ICON.copy), menuItem(t('menu.copyPath'), menuAction('path'), ICON.path));
|
|
960
|
+
const cancel = menuItem(t('menu.cancel'), () => {});
|
|
961
|
+
cancel.classList.add('qiv-sheet-cancel');
|
|
962
|
+
node.append(h('div', 'qiv-sheet-grab'), head, body, cancel);
|
|
963
|
+
scrim.append(node);
|
|
964
|
+
menuScrim = scrim;
|
|
965
|
+
sheetDrag(node, scrim, cancel);
|
|
966
|
+
return scrim;
|
|
967
|
+
}
|
|
968
|
+
|
|
829
969
|
function onDocDown(e) {
|
|
830
970
|
if (menu === null) return;
|
|
831
971
|
if (e.target instanceof Node && menu.contains(e.target)) return;
|
|
@@ -835,7 +975,9 @@ window.__ModuleLoader__.load({
|
|
|
835
975
|
root.addEventListener('contextmenu', (e) => {
|
|
836
976
|
if (closing || destroyed || editor !== null) return;
|
|
837
977
|
e.preventDefault();
|
|
838
|
-
|
|
978
|
+
// A long press already opened the sheet; ignore the follow-up event.
|
|
979
|
+
if (menu !== null || now() < suppressContextUntil) return;
|
|
980
|
+
openMenu(e.clientX || vw / 2, e.clientY || vh / 2, menuTouch || coarse.matches);
|
|
839
981
|
});
|
|
840
982
|
document.addEventListener('pointerdown', onDocDown, true);
|
|
841
983
|
//#endregion
|
|
@@ -1275,11 +1417,12 @@ window.__ModuleLoader__.load({
|
|
|
1275
1417
|
// capture is best-effort
|
|
1276
1418
|
}
|
|
1277
1419
|
const p = { x: e.clientX, y: e.clientY, type: e.pointerType || 'mouse' };
|
|
1420
|
+
menuTouch = p.type !== 'mouse';
|
|
1278
1421
|
pointers.set(e.pointerId, p);
|
|
1279
1422
|
anim.stop(['x', 'y', 'scale', 'bg', 'alpha', 'trackX']);
|
|
1280
1423
|
if (pointers.size === 1) {
|
|
1281
1424
|
startSingle(e.pointerId, p);
|
|
1282
|
-
// Touch screens have no right click: a still finger opens the
|
|
1425
|
+
// Touch screens have no right click: a still finger opens the actions.
|
|
1283
1426
|
if (p.type !== 'mouse') {
|
|
1284
1427
|
const x = p.x;
|
|
1285
1428
|
const y = p.y;
|
|
@@ -1289,7 +1432,14 @@ window.__ModuleLoader__.load({
|
|
|
1289
1432
|
if (gesture === null || gesture.mode !== 'pending' || pointers.size !== 1) return;
|
|
1290
1433
|
gesture.mode = 'menu';
|
|
1291
1434
|
setGesture(null);
|
|
1292
|
-
|
|
1435
|
+
suppressContextUntil = now() + 900;
|
|
1436
|
+
try {
|
|
1437
|
+
// A short tick confirms the press; iOS Safari has no vibrate.
|
|
1438
|
+
window.navigator.vibrate?.(10);
|
|
1439
|
+
} catch {
|
|
1440
|
+
// haptics are best-effort
|
|
1441
|
+
}
|
|
1442
|
+
openMenu(x, y, true);
|
|
1293
1443
|
}, LONG_PRESS_MS);
|
|
1294
1444
|
}
|
|
1295
1445
|
} else if (pointers.size === 2) startPinch();
|
|
@@ -1678,6 +1828,7 @@ window.__ModuleLoader__.load({
|
|
|
1678
1828
|
document.removeEventListener('pointerdown', onDocDown, true);
|
|
1679
1829
|
window.removeEventListener('keydown', onKey, true);
|
|
1680
1830
|
window.removeEventListener('resize', onResize);
|
|
1831
|
+
leaveTopLayer(root);
|
|
1681
1832
|
root.remove();
|
|
1682
1833
|
if (restore && restoreFocus !== null && restoreFocus.isConnected) {
|
|
1683
1834
|
try {
|
|
@@ -1729,6 +1880,7 @@ window.__ModuleLoader__.load({
|
|
|
1729
1880
|
nextBtn.addEventListener('click', () => go(1));
|
|
1730
1881
|
|
|
1731
1882
|
document.body.appendChild(root);
|
|
1883
|
+
enterTopLayer(root);
|
|
1732
1884
|
vw = root.clientWidth || window.innerWidth;
|
|
1733
1885
|
vh = root.clientHeight || window.innerHeight;
|
|
1734
1886
|
|
|
@@ -1867,6 +2019,7 @@ window.__ModuleLoader__.load({
|
|
|
1867
2019
|
const node = h('div', 'qiv-toast', { role: 'status', [IGNORE_ATTR]: '' });
|
|
1868
2020
|
node.textContent = text;
|
|
1869
2021
|
document.body.appendChild(node);
|
|
2022
|
+
enterTopLayer(node);
|
|
1870
2023
|
requestAnimationFrame(() => node.setAttribute('data-show', ''));
|
|
1871
2024
|
setTimeout(() => {
|
|
1872
2025
|
node.removeAttribute('data-show');
|
|
@@ -2749,6 +2902,7 @@ window.__ModuleLoader__.load({
|
|
|
2749
2902
|
c.width = 0;
|
|
2750
2903
|
c.height = 0;
|
|
2751
2904
|
}
|
|
2905
|
+
leaveTopLayer(root);
|
|
2752
2906
|
root.remove();
|
|
2753
2907
|
void restore;
|
|
2754
2908
|
}
|
|
@@ -2852,6 +3006,7 @@ window.__ModuleLoader__.load({
|
|
|
2852
3006
|
setColor(color, false);
|
|
2853
3007
|
syncHistory();
|
|
2854
3008
|
document.body.appendChild(root);
|
|
3009
|
+
enterTopLayer(root);
|
|
2855
3010
|
try {
|
|
2856
3011
|
doneBtn.focus({ preventScroll: true });
|
|
2857
3012
|
} catch {
|
|
@@ -2869,7 +3024,7 @@ window.__ModuleLoader__.load({
|
|
|
2869
3024
|
}
|
|
2870
3025
|
|
|
2871
3026
|
const EDIT_CSS = `
|
|
2872
|
-
[${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}
|
|
3027
|
+
[${EDIT_ATTR}]{position:fixed;inset:0;z-index:2147483001;margin:0;width:auto;height:auto;padding:0;border:0;overflow:hidden;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}
|
|
2873
3028
|
[${EDIT_ATTR}] *{box-sizing:border-box}
|
|
2874
3029
|
.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)}
|
|
2875
3030
|
.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}
|
|
@@ -2916,7 +3071,7 @@ window.__ModuleLoader__.load({
|
|
|
2916
3071
|
.qie-done[disabled]{opacity:.5;cursor:default}
|
|
2917
3072
|
[${EDIT_ATTR}][data-busy] .qie-done svg{display:none}
|
|
2918
3073
|
[${EDIT_ATTR}][data-busy] .qie-done::after{content:"";width:22px;height:22px;border-radius:50%;border:2.5px solid rgba(255,255,255,.35);border-top-color:#fff;animation:qiv-rot .8s linear infinite}
|
|
2919
|
-
.qiv-toast{position:fixed;left:50%;bottom:calc(env(safe-area-inset-bottom,0px) + 96px);z-index:2147483002;transform:translate(-50%,8px);max-width:calc(100vw - 32px);padding:10px 16px;border-radius:12px;background:rgba(30,30,32,.94);color:#fff;font:13px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;box-shadow:0 8px 24px rgba(0,0,0,.35);opacity:0;transition:opacity .2s,transform .2s;pointer-events:none}
|
|
3074
|
+
.qiv-toast{position:fixed;left:50%;bottom:calc(env(safe-area-inset-bottom,0px) + 96px);top:auto;right:auto;margin:0;width:max-content;height:auto;border:0;z-index:2147483002;transform:translate(-50%,8px);max-width:calc(100vw - 32px);padding:10px 16px;border-radius:12px;background:rgba(30,30,32,.94);color:#fff;font:13px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;box-shadow:0 8px 24px rgba(0,0,0,.35);opacity:0;transition:opacity .2s,transform .2s;pointer-events:none}
|
|
2920
3075
|
.qiv-toast[data-show]{opacity:1;transform:translate(-50%,0)}
|
|
2921
3076
|
@media (prefers-reduced-motion:reduce){[${EDIT_ATTR}][data-settle] .qie-stage,.qiv-toast{transition:none}}
|
|
2922
3077
|
`;
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Image Viewer",
|
|
4
|
-
"description": "Full-screen viewer for conversation images with iPhone Photos-style gestures: zoom from thumbnail, pinch and double-tap zoom, momentum pan, swipe between images, swipe down to close; right-click
|
|
4
|
+
"description": "Full-screen viewer for conversation images with iPhone Photos-style gestures: zoom from thumbnail, pinch and double-tap zoom, momentum pan, swipe between images, swipe down to close; right-click or long-press on touch to copy the image or its path (a bottom sheet on touch); annotate with pen and shapes, then drop the result into the chat box."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "图片查看器",
|
|
4
|
-
"description": "点击对话中的图片全屏查看,交互接近 iPhone
|
|
4
|
+
"description": "点击对话中的图片全屏查看,交互接近 iPhone 相册:从缩略图放大打开,双指/双击缩放,惯性拖动,左右滑动切换图片,下滑关闭;右键或手机上长按可复制图片本身或图片路径(触屏从底部滑出操作面板);可在图片上画笔、形状标注,完成后自动放进输入框。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qzsy/dsh-image-viewer",
|
|
3
|
-
"version": "0.
|
|
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; right-click to copy the image or its path; annotate an image and drop it into the chat box.",
|
|
3
|
+
"version": "0.5.0",
|
|
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; right-click or long-press to copy the image or its path (a bottom sheet on touch); annotate an image and drop it into the chat box.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "qzsy",
|
|
@@ -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/layout.mjs && node test/editor.mjs && node test/link.mjs && node test/menu.mjs"
|
|
60
|
+
"test": "node test/smoke.mjs && node test/layout.mjs && node test/editor.mjs && node test/link.mjs && node test/menu.mjs && node test/modal.mjs && node test/toplayer.mjs"
|
|
61
61
|
},
|
|
62
62
|
"dshBuild": {
|
|
63
63
|
"host": "src/index.ts",
|