@@ -8,6 +8,7 @@ import { useKeyPath } from '~~/composables/keys'
88const route = useRoute ()
99
1010const imageRef = ref ()
11+ const previewRef = ref ()
1112const mode = ref <' scale' | ' real' >(' scale' )
1213const config = inject <any >(' mediaViewerConfig' )
1314
@@ -19,7 +20,7 @@ const isImage = computed(() => previewState?.stats?.mimetype?.startsWith('image/
1920
2021const dragging = ref (false )
2122const offsetX = ref (0 )
22- const offsetY = ref (0 )
23+ const offsetY = ref (75 )
2324const initialX = ref (0 )
2425const initialY = ref (0 )
2526
@@ -55,16 +56,20 @@ onBeforeUnmount(() => {
5556 imageRef .value ?.removeEventListener (' mousedown' , onMousedown )
5657})
5758
58- watch (mode , () => {
59+ watch ([mode , () => previewState ?.targetWidth ], () => {
60+ const viewportWidth = previewRef .value ?.clientWidth ?? 0
61+ const mediaWidth = previewState ?.targetWidth ?? 0
62+ const centerX = (viewportWidth - mediaWidth ) / 2
63+
5964 initialX .value = 0
6065 initialY .value = 0
61- offsetX .value = 0
62- offsetY .value = 0
66+ offsetX .value = centerX
67+ offsetY .value = 75
6368})
6469 </script >
6570
6671<template >
67- <div class =" relative overflow-hidden rounded-l n-border-base border-r preview flex items-center justify-center" >
72+ <div ref = " previewRef " class =" relative overflow-hidden rounded-l n-border-base border-r preview flex items-center justify-center" >
6873 <div v-if =" !isImage" class =" rounded flex flex-col justify-center border select-none pointer-events-none n-border-base w-[150px] h-[150px] n-bg-base object-scale-down" >
6974 <div class =" truncate w-full text-center" >
7075 {{ previewState?.stats?.name }}
@@ -92,13 +97,13 @@ watch(mode, () => {
9297 class =" prevent-drag block object-scale-down w-full max-w-full max-h-full"
9398 tabindex =" 0"
9499 >
95- <div class =" absolute left-4 right -4 top-4 flex justify-between gap-2" >
100+ <div class =" absolute actions w-full px -4 top-4 flex justify-between gap-2" >
96101 <NButton
97102 to =" /"
98- icon =" carbon:arrow-left"
99103 class =" n-bg-base"
100104 >
101- <span >Back</span >
105+ <NIcon icon =" carbon:arrow-left" />
106+ <span class =" hide-small ml-1" >Back <kbd class =" text-xs" >esc</kbd ></span >
102107 </NButton >
103108 <div >
104109 <NButton
@@ -119,7 +124,7 @@ watch(mode, () => {
119124 :disabled =" !isImage"
120125 @click =" mode = 'real'"
121126 >
122- Real-size preview
127+ Snippet preview
123128 </NButton >
124129 </div >
125130
@@ -128,7 +133,8 @@ watch(mode, () => {
128133 target =" _blank"
129134 class =" n-bg-base"
130135 >
131- Open in new tab
136+ <span class =" hide-small mr-1" >Open</span >
137+ <NIcon icon =" carbon:image-reference" />
132138 </NButton >
133139 </div >
134140 </div >
@@ -150,4 +156,23 @@ watch(mode, () => {
150156 -o-user-drag : none ;
151157 user-drag : none ;
152158}
159+
160+ .actions {
161+ container-type : inline-size;
162+ container-name : actions;
163+ }
164+ .hide-small {
165+ display : initial ;
166+ }
167+ .only-small {
168+ display : none ;
169+ }
170+ @container actions (max-width: 600px) {
171+ .hide-small {
172+ display : none ;
173+ }
174+ .only-small {
175+ display : initial ;
176+ }
177+ }
153178 </style >
0 commit comments