|
1 | | -import { useEffect, useState } from 'react'; |
| 1 | +import { CSSProperties, useEffect, useMemo, useState } from 'react'; |
2 | 2 | import { Alert, Result, Spin } from 'antd'; |
3 | 3 | import clsx from 'clsx'; |
4 | 4 | import { useAtom, useAtomValue, useSetAtom } from 'jotai'; |
@@ -55,6 +55,30 @@ const App = () => { |
55 | 55 | setShouldSwapDimensions(videoRotation === 90 || videoRotation === 270); |
56 | 56 | }, [videoRotation]); |
57 | 57 |
|
| 58 | + const videoStyle = useMemo(() => { |
| 59 | + const baseStyle = { |
| 60 | + transformOrigin: 'center', |
| 61 | + maxWidth: shouldSwapDimensions ? '100vh' : '100%', |
| 62 | + maxHeight: shouldSwapDimensions ? '100vw' : '100%' |
| 63 | + }; |
| 64 | + |
| 65 | + if (videoScale === 0) { |
| 66 | + return { |
| 67 | + ...baseStyle, |
| 68 | + width: shouldSwapDimensions ? '100vh' : '100%', |
| 69 | + height: shouldSwapDimensions ? '100vw' : '100%', |
| 70 | + objectFit: 'contain', |
| 71 | + transform: `rotate(${videoRotation}deg)` |
| 72 | + }; |
| 73 | + } |
| 74 | + |
| 75 | + return { |
| 76 | + ...baseStyle, |
| 77 | + objectFit: 'scale-down', |
| 78 | + transform: `scale(${videoScale}) rotate(${videoRotation}deg)` |
| 79 | + }; |
| 80 | + }, [videoScale, videoRotation, shouldSwapDimensions]); |
| 81 | + |
58 | 82 | function initResolution() { |
59 | 83 | const resolution = storage.getVideoResolution(); |
60 | 84 | if (resolution) { |
@@ -130,13 +154,7 @@ const App = () => { |
130 | 154 | shouldSwapDimensions ? 'min-h-[640px] min-w-[360px]' : 'min-h-[360px] min-w-[640px]', |
131 | 155 | mouseStyle |
132 | 156 | )} |
133 | | - style={{ |
134 | | - transform: `scale(${videoScale}) rotate(${videoRotation}deg)`, |
135 | | - transformOrigin: 'center', |
136 | | - maxWidth: shouldSwapDimensions ? '100vh' : '100%', |
137 | | - maxHeight: shouldSwapDimensions ? '100vw' : '100%', |
138 | | - objectFit: 'scale-down' |
139 | | - }} |
| 157 | + style={videoStyle as CSSProperties} |
140 | 158 | autoPlay |
141 | 159 | playsInline |
142 | 160 | /> |
|
0 commit comments