@qzsy/dsh-image-viewer 0.4.1 → 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 +6 -0
- package/dist/client.js +42 -4
- package/package.json +2 -2
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
|
@@ -80,6 +80,12 @@ DSH 桌面应用(Electron)会把 Windows 右上角的窗口按钮、macOS
|
|
|
80
80
|
|
|
81
81
|
以下情况保持原样:按住 Ctrl / ⌘ / Shift / Alt 点击、图片在链接内、位于导航栏 / 工具栏 / 菜单中、在可编辑区域内或输入框里,或元素(及其祖先)带有 `data-qiv-ignore` 属性。
|
|
82
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
|
+
|
|
83
89
|
## 开发
|
|
84
90
|
|
|
85
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. */
|
|
@@ -419,7 +449,7 @@ window.__ModuleLoader__.load({
|
|
|
419
449
|
|
|
420
450
|
//#region styles
|
|
421
451
|
const CSS = `
|
|
422
|
-
[${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}
|
|
423
453
|
[${ROOT_ATTR}] *{box-sizing:border-box}
|
|
424
454
|
.qiv-bg{position:absolute;inset:0;background:#000}
|
|
425
455
|
.qiv-track{position:absolute;inset:0;overflow:hidden}
|
|
@@ -580,7 +610,10 @@ window.__ModuleLoader__.load({
|
|
|
580
610
|
*/
|
|
581
611
|
function resolveTrigger(node) {
|
|
582
612
|
if (!(node instanceof Element)) return null;
|
|
583
|
-
|
|
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;
|
|
584
617
|
const host = node.closest('button,[role="button"]');
|
|
585
618
|
if (host !== null) {
|
|
586
619
|
if (host.closest('a[href]') !== null) return null;
|
|
@@ -1795,6 +1828,7 @@ window.__ModuleLoader__.load({
|
|
|
1795
1828
|
document.removeEventListener('pointerdown', onDocDown, true);
|
|
1796
1829
|
window.removeEventListener('keydown', onKey, true);
|
|
1797
1830
|
window.removeEventListener('resize', onResize);
|
|
1831
|
+
leaveTopLayer(root);
|
|
1798
1832
|
root.remove();
|
|
1799
1833
|
if (restore && restoreFocus !== null && restoreFocus.isConnected) {
|
|
1800
1834
|
try {
|
|
@@ -1846,6 +1880,7 @@ window.__ModuleLoader__.load({
|
|
|
1846
1880
|
nextBtn.addEventListener('click', () => go(1));
|
|
1847
1881
|
|
|
1848
1882
|
document.body.appendChild(root);
|
|
1883
|
+
enterTopLayer(root);
|
|
1849
1884
|
vw = root.clientWidth || window.innerWidth;
|
|
1850
1885
|
vh = root.clientHeight || window.innerHeight;
|
|
1851
1886
|
|
|
@@ -1984,6 +2019,7 @@ window.__ModuleLoader__.load({
|
|
|
1984
2019
|
const node = h('div', 'qiv-toast', { role: 'status', [IGNORE_ATTR]: '' });
|
|
1985
2020
|
node.textContent = text;
|
|
1986
2021
|
document.body.appendChild(node);
|
|
2022
|
+
enterTopLayer(node);
|
|
1987
2023
|
requestAnimationFrame(() => node.setAttribute('data-show', ''));
|
|
1988
2024
|
setTimeout(() => {
|
|
1989
2025
|
node.removeAttribute('data-show');
|
|
@@ -2866,6 +2902,7 @@ window.__ModuleLoader__.load({
|
|
|
2866
2902
|
c.width = 0;
|
|
2867
2903
|
c.height = 0;
|
|
2868
2904
|
}
|
|
2905
|
+
leaveTopLayer(root);
|
|
2869
2906
|
root.remove();
|
|
2870
2907
|
void restore;
|
|
2871
2908
|
}
|
|
@@ -2969,6 +3006,7 @@ window.__ModuleLoader__.load({
|
|
|
2969
3006
|
setColor(color, false);
|
|
2970
3007
|
syncHistory();
|
|
2971
3008
|
document.body.appendChild(root);
|
|
3009
|
+
enterTopLayer(root);
|
|
2972
3010
|
try {
|
|
2973
3011
|
doneBtn.focus({ preventScroll: true });
|
|
2974
3012
|
} catch {
|
|
@@ -2986,7 +3024,7 @@ window.__ModuleLoader__.load({
|
|
|
2986
3024
|
}
|
|
2987
3025
|
|
|
2988
3026
|
const EDIT_CSS = `
|
|
2989
|
-
[${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}
|
|
2990
3028
|
[${EDIT_ATTR}] *{box-sizing:border-box}
|
|
2991
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)}
|
|
2992
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}
|
|
@@ -3033,7 +3071,7 @@ window.__ModuleLoader__.load({
|
|
|
3033
3071
|
.qie-done[disabled]{opacity:.5;cursor:default}
|
|
3034
3072
|
[${EDIT_ATTR}][data-busy] .qie-done svg{display:none}
|
|
3035
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}
|
|
3036
|
-
.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}
|
|
3037
3075
|
.qiv-toast[data-show]{opacity:1;transform:translate(-50%,0)}
|
|
3038
3076
|
@media (prefers-reduced-motion:reduce){[${EDIT_ATTR}][data-settle] .qie-stage,.qiv-toast{transition:none}}
|
|
3039
3077
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qzsy/dsh-image-viewer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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; 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",
|
|
@@ -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",
|