Skip to content

Commit 2375c52

Browse files
committed
feat: Add "Auto" video scaling option and dynamically adjust video object-fit and transform based on scale value.
1 parent d77f67d commit 2375c52

4 files changed

Lines changed: 38 additions & 17 deletions

File tree

browser/src/App.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { CSSProperties, useEffect, useMemo, useState } from 'react';
22
import { Alert, Result, Spin } from 'antd';
33
import clsx from 'clsx';
44
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
@@ -55,6 +55,30 @@ const App = () => {
5555
setShouldSwapDimensions(videoRotation === 90 || videoRotation === 270);
5656
}, [videoRotation]);
5757

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+
5882
function initResolution() {
5983
const resolution = storage.getVideoResolution();
6084
if (resolution) {
@@ -130,13 +154,7 @@ const App = () => {
130154
shouldSwapDimensions ? 'min-h-[640px] min-w-[360px]' : 'min-h-[360px] min-w-[640px]',
131155
mouseStyle
132156
)}
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}
140158
autoPlay
141159
playsInline
142160
/>

browser/src/components/menu/video/scale.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ import { useTranslation } from 'react-i18next';
88
import { videoScaleAtom } from '@/jotai/device.ts';
99
import * as storage from '@/libs/storage';
1010

11-
const ScaleList = [
12-
{ label: '200', value: 2 },
13-
{ label: '150', value: 1.5 },
14-
{ label: '100', value: 1 },
15-
{ label: '75', value: 0.75 },
16-
{ label: '50', value: 0.5 }
17-
];
18-
1911
export const Scale = (): ReactElement => {
2012
const { t } = useTranslation();
2113

2214
const [videoScale, setVideoScale] = useAtom(videoScaleAtom);
2315

16+
const ScaleList = [
17+
{ label: t('video.auto'), value: 0 },
18+
{ label: '200', value: 2 },
19+
{ label: '150', value: 1.5 },
20+
{ label: '100', value: 1 },
21+
{ label: '75', value: 0.75 },
22+
{ label: '50', value: 0.5 }
23+
];
24+
2425
useEffect(() => {
2526
const scale = storage.getVideoScale();
2627
if (scale) {
@@ -45,7 +46,7 @@ export const Scale = (): ReactElement => {
4546
onClick={() => updateScale(item.value)}
4647
>
4748
<span>{item.label}</span>
48-
<PercentIcon size={12} />
49+
{item.value > 0 && <PercentIcon size={12} />}
4950
</div>
5051
))}
5152
</>

browser/src/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const en = {
2525
video: {
2626
resolution: 'Resolution',
2727
scale: 'Scale',
28+
auto: "Auto",
2829
rotation: 'Rotation',
2930
customResolution: 'Custom',
3031
device: 'Device',

browser/src/i18n/locales/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const zh = {
2323
video: {
2424
resolution: '分辨率',
2525
scale: '缩放',
26+
auto: '自动',
2627
rotation: '旋转',
2728
customResolution: '自定义',
2829
device: '设备',

0 commit comments

Comments
 (0)