fix: zoom & rotation

This commit is contained in:
martabal 2023-12-02 02:25:10 +01:00
parent 29aa3208c6
commit 728233bf86
No known key found for this signature in database
GPG key ID: C00196E3148A52BD
4 changed files with 18 additions and 19 deletions

1
web/src/app.d.ts vendored
View file

@ -25,5 +25,6 @@ declare namespace svelteHTML {
interface HTMLAttributes<T> { interface HTMLAttributes<T> {
'on:copyImage'?: () => void; 'on:copyImage'?: () => void;
'on:zoomImage'?: () => void; 'on:zoomImage'?: () => void;
'on:rotateImage'?: () => void;
} }
} }

View file

@ -183,7 +183,7 @@
text={asset.isArchived ? 'Unarchive' : 'Archive'} text={asset.isArchived ? 'Unarchive' : 'Archive'}
/> />
<MenuOption on:click={() => onMenuClick('asProfileImage')} text="As profile picture" /> <MenuOption on:click={() => onMenuClick('asProfileImage')} text="As profile picture" />
<MenuOption on:click={() => onMenuClick('rotate')} text="Rotate left" /> <MenuOption on:click={() => onMenuClick('rotate')} text="Rotate right" />
{#if hasStackChildren} {#if hasStackChildren}
<MenuOption on:click={() => onMenuClick('unstack')} text="Un-Stack" /> <MenuOption on:click={() => onMenuClick('unstack')} text="Un-Stack" />
{/if} {/if}

View file

@ -55,7 +55,6 @@
export let album: AlbumResponseDto | null = null; export let album: AlbumResponseDto | null = null;
let reactions: ActivityResponseDto[] = []; let reactions: ActivityResponseDto[] = [];
let rotatePhotoviewer: () => Promise<void>;
const { setAssetId } = assetViewingStore; const { setAssetId } = assetViewingStore;
const { const {
restartProgress: restartSlideshowProgress, restartProgress: restartSlideshowProgress,
@ -256,6 +255,11 @@
isShowActivity = !isShowActivity; isShowActivity = !isShowActivity;
}; };
const handleRotate = () => {
const rotateImage = new CustomEvent('rotateImage');
window.dispatchEvent(rotateImage);
};
const handleKeyboardPress = (event: KeyboardEvent) => { const handleKeyboardPress = (event: KeyboardEvent) => {
if (shouldIgnoreShortcut(event)) { if (shouldIgnoreShortcut(event)) {
return; return;
@ -307,9 +311,6 @@
} }
} }
}; };
function handleRotate() {
rotatePhotoviewer();
}
const handleCloseViewer = () => { const handleCloseViewer = () => {
$isShowDetail = false; $isShowDetail = false;
@ -634,12 +635,7 @@
{#if previewStackedAsset} {#if previewStackedAsset}
{#key previewStackedAsset.id} {#key previewStackedAsset.id}
{#if previewStackedAsset.type === AssetTypeEnum.Image} {#if previewStackedAsset.type === AssetTypeEnum.Image}
<PhotoViewer <PhotoViewer asset={previewStackedAsset} on:close={closeViewer} haveFadeTransition={false} />
bind:rotate={rotatePhotoviewer}
asset={previewStackedAsset}
on:close={closeViewer}
haveFadeTransition={false}
/>
{:else} {:else}
<VideoViewer <VideoViewer
assetId={previewStackedAsset.id} assetId={previewStackedAsset.id}
@ -671,7 +667,7 @@
.endsWith('.insp'))} .endsWith('.insp'))}
<PanoramaViewer {asset} /> <PanoramaViewer {asset} />
{:else} {:else}
<PhotoViewer bind:rotate={rotatePhotoviewer} {asset} on:close={closeViewer} /> <PhotoViewer {asset} on:close={closeViewer} />
{/if} {/if}
{:else} {:else}
<VideoViewer <VideoViewer

View file

@ -12,6 +12,7 @@
export let asset: AssetResponseDto; export let asset: AssetResponseDto;
export let haveFadeTransition = true; export let haveFadeTransition = true;
export let element: HTMLDivElement | undefined = undefined;
// const orientationToRotation = (value: string): number => { // const orientationToRotation = (value: string): number => {
// switch (value) { // switch (value) {
@ -55,8 +56,8 @@
} }
}; };
export const rotate = async () => { const doRotate = async () => {
setZoomImageWheelState({ currentRotation: $zoomImageWheelState.currentRotation - 90 }); setZoomImageWheelState({ currentRotation: $zoomImageWheelState.currentRotation + 90 });
try { try {
await api.assetApi.updateAsset({ await api.assetApi.updateAsset({
id: asset.id, id: asset.id,
@ -175,13 +176,14 @@
} }
</script> </script>
<svelte:window on:keydown={handleKeypress} on:copyImage={doCopy} on:zoomImage={doZoomImage} /> <svelte:window on:keydown={handleKeypress} on:rotateImage={doRotate} on:copyImage={doCopy} on:zoomImage={doZoomImage} />
<div <div
bind:clientHeight={clientHeight} bind:this={element}
bind:clientWidth={clientWidth} bind:clientHeight
bind:clientWidth
transition:fade={{ duration: haveFadeTransition ? 150 : 0 }} transition:fade={{ duration: haveFadeTransition ? 150 : 0 }}
class="flex h-full select-none place-content-center place-items-center" class="flex h-full w-full select-none place-content-center place-items-center"
> >
{#await loadAssetData({ loadOriginal: false })} {#await loadAssetData({ loadOriginal: false })}
<LoadingSpinner /> <LoadingSpinner />
@ -193,7 +195,7 @@
alt={asset.id} alt={asset.id}
class="h-full w-full object-contain" class="h-full w-full object-contain"
draggable="false" draggable="false"
style={`width:${imgWidth}px;height:${imgHeight}px;`} style={`width:${imgWidth}px;height:${imgHeight}px;transform-origin: 0px 0px 0px;`}
/> />
</div> </div>
{/await} {/await}