@cloud-ru/ds-site-media 0.0.0-stage → 1.1.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/CHANGELOG.md +10 -0
- package/LICENSE +201 -0
- package/README.md +167 -2
- package/dist/cjs/components/SiteImage/SiteImage.d.ts +10 -0
- package/dist/cjs/components/SiteImage/SiteImage.js +8 -0
- package/dist/cjs/components/SiteImage/index.d.ts +1 -0
- package/dist/cjs/components/SiteImage/index.js +17 -0
- package/dist/cjs/components/SiteVideo/SiteVideo.d.ts +15 -0
- package/dist/cjs/components/SiteVideo/SiteVideo.js +16 -0
- package/dist/cjs/components/SiteVideo/VideoContent.d.ts +4 -0
- package/dist/cjs/components/SiteVideo/VideoContent.js +27 -0
- package/dist/cjs/components/SiteVideo/index.d.ts +1 -0
- package/dist/cjs/components/SiteVideo/index.js +17 -0
- package/dist/cjs/components/SiteVideo/styles.module.css +15 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/constants.d.ts +31 -0
- package/dist/cjs/constants.js +34 -0
- package/dist/cjs/helperComponents/EmbedPlayer/EmbedPlayer.d.ts +10 -0
- package/dist/cjs/helperComponents/EmbedPlayer/EmbedPlayer.js +108 -0
- package/dist/cjs/helperComponents/EmbedPlayer/index.d.ts +1 -0
- package/dist/cjs/helperComponents/EmbedPlayer/index.js +17 -0
- package/dist/cjs/helperComponents/EmbedPlayer/styles.module.css +15 -0
- package/dist/cjs/helperComponents/NativePlayer/NativePlayer.d.ts +2 -0
- package/dist/cjs/helperComponents/NativePlayer/NativePlayer.js +106 -0
- package/dist/cjs/helperComponents/NativePlayer/hooks.d.ts +13 -0
- package/dist/cjs/helperComponents/NativePlayer/hooks.js +140 -0
- package/dist/cjs/helperComponents/NativePlayer/index.d.ts +1 -0
- package/dist/cjs/helperComponents/NativePlayer/index.js +17 -0
- package/dist/cjs/helperComponents/NativePlayer/styles.module.css +39 -0
- package/dist/cjs/helperComponents/NativePlayer/types.d.ts +6 -0
- package/dist/cjs/helperComponents/NativePlayer/types.js +2 -0
- package/dist/cjs/helperComponents/NativePlayer/utils.d.ts +19 -0
- package/dist/cjs/helperComponents/NativePlayer/utils.js +24 -0
- package/dist/cjs/helperComponents/PlayerError/PlayerError.d.ts +5 -0
- package/dist/cjs/helperComponents/PlayerError/PlayerError.js +15 -0
- package/dist/cjs/helperComponents/PlayerError/index.d.ts +1 -0
- package/dist/cjs/helperComponents/PlayerError/index.js +17 -0
- package/dist/cjs/helperComponents/PlayerError/styles.module.css +32 -0
- package/dist/cjs/helperComponents/SpeedSelect/SpeedSelect.d.ts +7 -0
- package/dist/cjs/helperComponents/SpeedSelect/SpeedSelect.js +30 -0
- package/dist/cjs/helperComponents/SpeedSelect/index.d.ts +1 -0
- package/dist/cjs/helperComponents/SpeedSelect/index.js +17 -0
- package/dist/cjs/helperComponents/SpeedSelect/styles.module.css +7 -0
- package/dist/cjs/helperComponents/Toolbar/PlaybackControls.d.ts +6 -0
- package/dist/cjs/helperComponents/Toolbar/PlaybackControls.js +23 -0
- package/dist/cjs/helperComponents/Toolbar/Timeline.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/Timeline.js +23 -0
- package/dist/cjs/helperComponents/Toolbar/TimelinePreview.d.ts +8 -0
- package/dist/cjs/helperComponents/Toolbar/TimelinePreview.js +21 -0
- package/dist/cjs/helperComponents/Toolbar/Toolbar.d.ts +14 -0
- package/dist/cjs/helperComponents/Toolbar/Toolbar.js +19 -0
- package/dist/cjs/helperComponents/Toolbar/ToolbarButton.d.ts +12 -0
- package/dist/cjs/helperComponents/Toolbar/ToolbarButton.js +14 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/index.js +17 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/useTimeline.d.ts +10 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/useTimeline.js +32 -0
- package/dist/cjs/helperComponents/Toolbar/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Toolbar/index.js +17 -0
- package/dist/cjs/helperComponents/Toolbar/styles.module.css +115 -0
- package/dist/cjs/helperComponents/Toolbar/types.d.ts +5 -0
- package/dist/cjs/helperComponents/Toolbar/types.js +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByKey.d.ts +1 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByKey.js +20 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByPointer.d.ts +5 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByPointer.js +7 -0
- package/dist/cjs/helperComponents/Toolbar/utils/index.d.ts +6 -0
- package/dist/cjs/helperComponents/Toolbar/utils/index.js +22 -0
- package/dist/cjs/helperComponents/Toolbar/utils/restart.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/restart.js +7 -0
- package/dist/cjs/helperComponents/Toolbar/utils/seek.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/seek.js +6 -0
- package/dist/cjs/helperComponents/Toolbar/utils/setVolume.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/setVolume.js +10 -0
- package/dist/cjs/helperComponents/Toolbar/utils/toggleMute.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/toggleMute.js +9 -0
- package/dist/cjs/helperComponents/VideoPlayButton/VideoPlayButton.d.ts +10 -0
- package/dist/cjs/helperComponents/VideoPlayButton/VideoPlayButton.js +18 -0
- package/dist/cjs/helperComponents/VideoPlayButton/index.d.ts +1 -0
- package/dist/cjs/helperComponents/VideoPlayButton/index.js +17 -0
- package/dist/cjs/helperComponents/VideoPlayButton/styles.module.css +100 -0
- package/dist/cjs/hocs/withPlayerClassName.d.ts +3 -0
- package/dist/cjs/hocs/withPlayerClassName.js +15 -0
- package/dist/cjs/hooks/useFullscreen.d.ts +6 -0
- package/dist/cjs/hooks/useFullscreen.js +32 -0
- package/dist/cjs/hooks/usePlayerState.d.ts +11 -0
- package/dist/cjs/hooks/usePlayerState.js +60 -0
- package/dist/cjs/hooks/useSpriteFrames.d.ts +2 -0
- package/dist/cjs/hooks/useSpriteFrames.js +32 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/locale/index.d.ts +83 -0
- package/dist/cjs/locale/index.js +46 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shared/types.d.ts +8 -0
- package/dist/cjs/shared/types.js +2 -0
- package/dist/cjs/style.css +323 -0
- package/dist/cjs/types.d.ts +15 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/embed.d.ts +8 -0
- package/dist/cjs/utils/embed.js +74 -0
- package/dist/cjs/utils/format.d.ts +2 -0
- package/dist/cjs/utils/format.js +17 -0
- package/dist/cjs/utils/fullscreen.d.ts +5 -0
- package/dist/cjs/utils/fullscreen.js +29 -0
- package/dist/cjs/utils/index.d.ts +6 -0
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/loadSpriteFrames.d.ts +3 -0
- package/dist/cjs/utils/loadSpriteFrames.js +9 -0
- package/dist/cjs/utils/source.d.ts +5 -0
- package/dist/cjs/utils/source.js +19 -0
- package/dist/cjs/utils/sprite.d.ts +3 -0
- package/dist/cjs/utils/sprite.js +41 -0
- package/dist/cjs/utils/url.d.ts +1 -0
- package/dist/cjs/utils/url.js +15 -0
- package/dist/esm/components/SiteImage/SiteImage.d.ts +10 -0
- package/dist/esm/components/SiteImage/SiteImage.js +5 -0
- package/dist/esm/components/SiteImage/index.d.ts +1 -0
- package/dist/esm/components/SiteImage/index.js +1 -0
- package/dist/esm/components/SiteVideo/SiteVideo.d.ts +15 -0
- package/dist/esm/components/SiteVideo/SiteVideo.js +10 -0
- package/dist/esm/components/SiteVideo/VideoContent.d.ts +4 -0
- package/dist/esm/components/SiteVideo/VideoContent.js +21 -0
- package/dist/esm/components/SiteVideo/index.d.ts +1 -0
- package/dist/esm/components/SiteVideo/index.js +1 -0
- package/dist/esm/components/SiteVideo/styles.module.css +15 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/constants.d.ts +31 -0
- package/dist/esm/constants.js +31 -0
- package/dist/esm/helperComponents/EmbedPlayer/EmbedPlayer.d.ts +10 -0
- package/dist/esm/helperComponents/EmbedPlayer/EmbedPlayer.js +102 -0
- package/dist/esm/helperComponents/EmbedPlayer/index.d.ts +1 -0
- package/dist/esm/helperComponents/EmbedPlayer/index.js +1 -0
- package/dist/esm/helperComponents/EmbedPlayer/styles.module.css +15 -0
- package/dist/esm/helperComponents/NativePlayer/NativePlayer.d.ts +2 -0
- package/dist/esm/helperComponents/NativePlayer/NativePlayer.js +100 -0
- package/dist/esm/helperComponents/NativePlayer/hooks.d.ts +13 -0
- package/dist/esm/helperComponents/NativePlayer/hooks.js +101 -0
- package/dist/esm/helperComponents/NativePlayer/index.d.ts +1 -0
- package/dist/esm/helperComponents/NativePlayer/index.js +1 -0
- package/dist/esm/helperComponents/NativePlayer/styles.module.css +39 -0
- package/dist/esm/helperComponents/NativePlayer/types.d.ts +6 -0
- package/dist/esm/helperComponents/NativePlayer/types.js +1 -0
- package/dist/esm/helperComponents/NativePlayer/utils.d.ts +19 -0
- package/dist/esm/helperComponents/NativePlayer/utils.js +20 -0
- package/dist/esm/helperComponents/PlayerError/PlayerError.d.ts +5 -0
- package/dist/esm/helperComponents/PlayerError/PlayerError.js +9 -0
- package/dist/esm/helperComponents/PlayerError/index.d.ts +1 -0
- package/dist/esm/helperComponents/PlayerError/index.js +1 -0
- package/dist/esm/helperComponents/PlayerError/styles.module.css +32 -0
- package/dist/esm/helperComponents/SpeedSelect/SpeedSelect.d.ts +7 -0
- package/dist/esm/helperComponents/SpeedSelect/SpeedSelect.js +24 -0
- package/dist/esm/helperComponents/SpeedSelect/index.d.ts +1 -0
- package/dist/esm/helperComponents/SpeedSelect/index.js +1 -0
- package/dist/esm/helperComponents/SpeedSelect/styles.module.css +7 -0
- package/dist/esm/helperComponents/Toolbar/PlaybackControls.d.ts +6 -0
- package/dist/esm/helperComponents/Toolbar/PlaybackControls.js +17 -0
- package/dist/esm/helperComponents/Toolbar/Timeline.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/Timeline.js +17 -0
- package/dist/esm/helperComponents/Toolbar/TimelinePreview.d.ts +8 -0
- package/dist/esm/helperComponents/Toolbar/TimelinePreview.js +15 -0
- package/dist/esm/helperComponents/Toolbar/Toolbar.d.ts +14 -0
- package/dist/esm/helperComponents/Toolbar/Toolbar.js +13 -0
- package/dist/esm/helperComponents/Toolbar/ToolbarButton.d.ts +12 -0
- package/dist/esm/helperComponents/Toolbar/ToolbarButton.js +11 -0
- package/dist/esm/helperComponents/Toolbar/hooks/index.d.ts +1 -0
- package/dist/esm/helperComponents/Toolbar/hooks/index.js +1 -0
- package/dist/esm/helperComponents/Toolbar/hooks/useTimeline.d.ts +10 -0
- package/dist/esm/helperComponents/Toolbar/hooks/useTimeline.js +29 -0
- package/dist/esm/helperComponents/Toolbar/index.d.ts +1 -0
- package/dist/esm/helperComponents/Toolbar/index.js +1 -0
- package/dist/esm/helperComponents/Toolbar/styles.module.css +115 -0
- package/dist/esm/helperComponents/Toolbar/types.d.ts +5 -0
- package/dist/esm/helperComponents/Toolbar/types.js +1 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByKey.d.ts +1 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByKey.js +17 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByPointer.d.ts +5 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByPointer.js +4 -0
- package/dist/esm/helperComponents/Toolbar/utils/index.d.ts +6 -0
- package/dist/esm/helperComponents/Toolbar/utils/index.js +6 -0
- package/dist/esm/helperComponents/Toolbar/utils/restart.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/restart.js +4 -0
- package/dist/esm/helperComponents/Toolbar/utils/seek.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/seek.js +3 -0
- package/dist/esm/helperComponents/Toolbar/utils/setVolume.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/setVolume.js +7 -0
- package/dist/esm/helperComponents/Toolbar/utils/toggleMute.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/toggleMute.js +6 -0
- package/dist/esm/helperComponents/VideoPlayButton/VideoPlayButton.d.ts +10 -0
- package/dist/esm/helperComponents/VideoPlayButton/VideoPlayButton.js +12 -0
- package/dist/esm/helperComponents/VideoPlayButton/index.d.ts +1 -0
- package/dist/esm/helperComponents/VideoPlayButton/index.js +1 -0
- package/dist/esm/helperComponents/VideoPlayButton/styles.module.css +100 -0
- package/dist/esm/hocs/withPlayerClassName.d.ts +3 -0
- package/dist/esm/hocs/withPlayerClassName.js +9 -0
- package/dist/esm/hooks/useFullscreen.d.ts +6 -0
- package/dist/esm/hooks/useFullscreen.js +29 -0
- package/dist/esm/hooks/usePlayerState.d.ts +11 -0
- package/dist/esm/hooks/usePlayerState.js +57 -0
- package/dist/esm/hooks/useSpriteFrames.d.ts +2 -0
- package/dist/esm/hooks/useSpriteFrames.js +29 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/locale/index.d.ts +83 -0
- package/dist/esm/locale/index.js +43 -0
- package/dist/esm/shared/types.d.ts +8 -0
- package/dist/esm/shared/types.js +1 -0
- package/dist/esm/style.css +323 -0
- package/dist/esm/types.d.ts +15 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/embed.d.ts +8 -0
- package/dist/esm/utils/embed.js +69 -0
- package/dist/esm/utils/format.d.ts +2 -0
- package/dist/esm/utils/format.js +13 -0
- package/dist/esm/utils/fullscreen.d.ts +5 -0
- package/dist/esm/utils/fullscreen.js +26 -0
- package/dist/esm/utils/index.d.ts +6 -0
- package/dist/esm/utils/index.js +6 -0
- package/dist/esm/utils/loadSpriteFrames.d.ts +3 -0
- package/dist/esm/utils/loadSpriteFrames.js +6 -0
- package/dist/esm/utils/source.d.ts +5 -0
- package/dist/esm/utils/source.js +14 -0
- package/dist/esm/utils/sprite.d.ts +3 -0
- package/dist/esm/utils/sprite.js +37 -0
- package/dist/esm/utils/url.d.ts +1 -0
- package/dist/esm/utils/url.js +12 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +57 -3
- package/src/components/SiteImage/SiteImage.tsx +16 -0
- package/src/components/SiteImage/index.ts +1 -0
- package/src/components/SiteVideo/SiteVideo.tsx +28 -0
- package/src/components/SiteVideo/VideoContent.tsx +29 -0
- package/src/components/SiteVideo/index.ts +1 -0
- package/src/components/SiteVideo/styles.module.scss +19 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +36 -0
- package/src/helperComponents/EmbedPlayer/EmbedPlayer.tsx +179 -0
- package/src/helperComponents/EmbedPlayer/index.ts +1 -0
- package/src/helperComponents/EmbedPlayer/styles.module.scss +18 -0
- package/src/helperComponents/NativePlayer/NativePlayer.tsx +168 -0
- package/src/helperComponents/NativePlayer/hooks.ts +115 -0
- package/src/helperComponents/NativePlayer/index.ts +1 -0
- package/src/helperComponents/NativePlayer/styles.module.scss +41 -0
- package/src/helperComponents/NativePlayer/types.ts +7 -0
- package/src/helperComponents/NativePlayer/utils.ts +29 -0
- package/src/helperComponents/PlayerError/PlayerError.tsx +18 -0
- package/src/helperComponents/PlayerError/index.ts +1 -0
- package/src/helperComponents/PlayerError/styles.module.scss +29 -0
- package/src/helperComponents/SpeedSelect/SpeedSelect.tsx +67 -0
- package/src/helperComponents/SpeedSelect/index.ts +1 -0
- package/src/helperComponents/SpeedSelect/styles.module.scss +9 -0
- package/src/helperComponents/Toolbar/PlaybackControls.tsx +104 -0
- package/src/helperComponents/Toolbar/Timeline.tsx +55 -0
- package/src/helperComponents/Toolbar/TimelinePreview.tsx +33 -0
- package/src/helperComponents/Toolbar/Toolbar.tsx +42 -0
- package/src/helperComponents/Toolbar/ToolbarButton.tsx +46 -0
- package/src/helperComponents/Toolbar/hooks/index.ts +1 -0
- package/src/helperComponents/Toolbar/hooks/useTimeline.ts +43 -0
- package/src/helperComponents/Toolbar/index.ts +1 -0
- package/src/helperComponents/Toolbar/styles.module.scss +138 -0
- package/src/helperComponents/Toolbar/types.ts +1 -0
- package/src/helperComponents/Toolbar/utils/getTimeByKey.ts +18 -0
- package/src/helperComponents/Toolbar/utils/getTimeByPointer.ts +11 -0
- package/src/helperComponents/Toolbar/utils/index.ts +6 -0
- package/src/helperComponents/Toolbar/utils/restart.ts +6 -0
- package/src/helperComponents/Toolbar/utils/seek.ts +5 -0
- package/src/helperComponents/Toolbar/utils/setVolume.ts +10 -0
- package/src/helperComponents/Toolbar/utils/toggleMute.ts +9 -0
- package/src/helperComponents/VideoPlayButton/VideoPlayButton.tsx +39 -0
- package/src/helperComponents/VideoPlayButton/index.ts +1 -0
- package/src/helperComponents/VideoPlayButton/styles.module.scss +112 -0
- package/src/hocs/withPlayerClassName.ts +11 -0
- package/src/hooks/useFullscreen.ts +39 -0
- package/src/hooks/usePlayerState.ts +80 -0
- package/src/hooks/useSpriteFrames.ts +39 -0
- package/src/index.ts +4 -0
- package/src/locale/index.ts +47 -0
- package/src/shared/types.ts +8 -0
- package/src/types.ts +15 -0
- package/src/utils/embed.ts +95 -0
- package/src/utils/format.ts +16 -0
- package/src/utils/fullscreen.ts +34 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/loadSpriteFrames.ts +8 -0
- package/src/utils/source.ts +22 -0
- package/src/utils/sprite.ts +48 -0
- package/src/utils/url.ts +13 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SEEK_STEP } from '../../../constants';
|
|
2
|
+
|
|
3
|
+
export function getTimeByKey(key: string, currentTime: number, duration: number) {
|
|
4
|
+
switch (key) {
|
|
5
|
+
case 'ArrowLeft':
|
|
6
|
+
case 'ArrowDown':
|
|
7
|
+
return Math.max(0, currentTime - SEEK_STEP);
|
|
8
|
+
case 'ArrowRight':
|
|
9
|
+
case 'ArrowUp':
|
|
10
|
+
return Math.min(duration, currentTime + SEEK_STEP);
|
|
11
|
+
case 'Home':
|
|
12
|
+
return 0;
|
|
13
|
+
case 'End':
|
|
14
|
+
return duration;
|
|
15
|
+
default:
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TimelinePosition } from '../types';
|
|
2
|
+
|
|
3
|
+
export function getTimeByPointer(
|
|
4
|
+
clientX: number,
|
|
5
|
+
{ left, width }: { left: number; width: number },
|
|
6
|
+
duration: number,
|
|
7
|
+
): TimelinePosition {
|
|
8
|
+
const ratio = width > 0 ? Math.min(1, Math.max(0, (clientX - left) / width)) : 0;
|
|
9
|
+
|
|
10
|
+
return { time: ratio * duration, offset: ratio * width, width };
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useAdaptiveLayout } from '@cloud-ru/ds-adaptive';
|
|
2
|
+
import { PausePlayerSVG, PlayPlayerSVG } from '@cloud-ru/ds-icons/interface/web';
|
|
3
|
+
import { KeyboardEvent, MouseEvent } from 'react';
|
|
4
|
+
|
|
5
|
+
import { TEST_IDS } from '../../constants';
|
|
6
|
+
import { siteMediaLocale } from '../../locale';
|
|
7
|
+
import styles from './styles.module.scss';
|
|
8
|
+
|
|
9
|
+
type VideoPlayButtonProps = {
|
|
10
|
+
playing: boolean;
|
|
11
|
+
visible: boolean;
|
|
12
|
+
compact?: boolean;
|
|
13
|
+
onClick(event: MouseEvent<HTMLButtonElement>): void;
|
|
14
|
+
onKeyDown?(event: KeyboardEvent<HTMLButtonElement>): void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function VideoPlayButton({ playing, visible, compact = false, onClick, onKeyDown }: VideoPlayButtonProps) {
|
|
18
|
+
const { layoutType } = useAdaptiveLayout();
|
|
19
|
+
const { t } = siteMediaLocale.useTranslations();
|
|
20
|
+
const Icon = playing ? PausePlayerSVG : PlayPlayerSVG;
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<button
|
|
24
|
+
type='button'
|
|
25
|
+
className={styles.surface}
|
|
26
|
+
data-layout-type={layoutType}
|
|
27
|
+
data-visible={visible}
|
|
28
|
+
data-compact={compact}
|
|
29
|
+
data-test-id={TEST_IDS.playButton}
|
|
30
|
+
aria-label={playing ? t('pause') : t('play')}
|
|
31
|
+
onClick={onClick}
|
|
32
|
+
onKeyDown={onKeyDown}
|
|
33
|
+
>
|
|
34
|
+
<span className={styles.circle} aria-hidden>
|
|
35
|
+
<Icon className={styles.icon} />
|
|
36
|
+
</span>
|
|
37
|
+
</button>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './VideoPlayButton';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
@use 'sass:list';
|
|
2
|
+
@use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
|
|
3
|
+
|
|
4
|
+
$layouts: (
|
|
5
|
+
'desktop': (
|
|
6
|
+
base.$sn-primitive-dimension-80,
|
|
7
|
+
base.$sn-density-icon-l,
|
|
8
|
+
),
|
|
9
|
+
'desktopSmall': (
|
|
10
|
+
base.$sn-primitive-dimension-80,
|
|
11
|
+
base.$sn-density-icon-l,
|
|
12
|
+
),
|
|
13
|
+
'tablet': (
|
|
14
|
+
base.$sn-primitive-dimension-64,
|
|
15
|
+
base.$sn-density-icon-m,
|
|
16
|
+
),
|
|
17
|
+
'mobile': (
|
|
18
|
+
base.$sn-primitive-dimension-40,
|
|
19
|
+
base.$sn-density-icon-s,
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
.surface {
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
|
|
26
|
+
position: absolute;
|
|
27
|
+
inset: 0;
|
|
28
|
+
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
|
|
33
|
+
width: 100%;
|
|
34
|
+
height: 100%;
|
|
35
|
+
margin: 0;
|
|
36
|
+
padding: 0;
|
|
37
|
+
border: 0;
|
|
38
|
+
border-radius: inherit;
|
|
39
|
+
|
|
40
|
+
color: base.$sn-theme-color-available-inversion-textMain;
|
|
41
|
+
|
|
42
|
+
opacity: 0;
|
|
43
|
+
background: base.$sn-theme-color-blackout;
|
|
44
|
+
|
|
45
|
+
transition: opacity 0.15s ease-in-out;
|
|
46
|
+
|
|
47
|
+
&[data-visible='true'],
|
|
48
|
+
&:focus-visible {
|
|
49
|
+
opacity: 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&:focus-visible {
|
|
53
|
+
outline: base.$sn-primitive-strokeWeight-strokeMedium solid base.$sn-theme-color-primary-accent;
|
|
54
|
+
outline-offset: calc(-1 * #{base.$sn-primitive-strokeWeight-strokeMedium});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&[data-compact='true'] {
|
|
58
|
+
inset: 0;
|
|
59
|
+
|
|
60
|
+
width: fit-content;
|
|
61
|
+
height: fit-content;
|
|
62
|
+
margin: auto;
|
|
63
|
+
border-radius: base.$sn-primitive-dimension-full;
|
|
64
|
+
|
|
65
|
+
background: transparent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.circle {
|
|
70
|
+
position: relative;
|
|
71
|
+
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
|
|
76
|
+
border-radius: base.$sn-primitive-dimension-full;
|
|
77
|
+
|
|
78
|
+
background: base.$sn-theme-color-blackout;
|
|
79
|
+
|
|
80
|
+
&::after {
|
|
81
|
+
pointer-events: none;
|
|
82
|
+
content: '';
|
|
83
|
+
|
|
84
|
+
position: absolute;
|
|
85
|
+
inset: 0;
|
|
86
|
+
|
|
87
|
+
border-radius: inherit;
|
|
88
|
+
|
|
89
|
+
opacity: 0;
|
|
90
|
+
background: base.$sn-theme-color-blackout;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.surface:hover &::after {
|
|
94
|
+
opacity: 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.icon {
|
|
99
|
+
z-index: 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@each $layout, $dimensions in $layouts {
|
|
103
|
+
.surface[data-layout-type='#{$layout}'] .circle {
|
|
104
|
+
width: list.nth($dimensions, 1);
|
|
105
|
+
height: list.nth($dimensions, 1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.surface[data-layout-type='#{$layout}'] svg.icon {
|
|
109
|
+
width: list.nth($dimensions, 2) !important;
|
|
110
|
+
height: list.nth($dimensions, 2) !important;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { cloneElement, isValidElement, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Добавляет класс прямым элементам video и iframe, сохраняя классы пользователя. */
|
|
5
|
+
export function withPlayerClassName(video: ReactNode, className: string): ReactNode {
|
|
6
|
+
if (!isValidElement<{ className?: string }>(video) || (video.type !== 'video' && video.type !== 'iframe')) {
|
|
7
|
+
return video;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return cloneElement(video, { className: cn(video.props.className, className) });
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isBrowser } from '@cloud-ru/ds-utils';
|
|
2
|
+
import { RefObject, useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import Player from 'video.js/dist/types/player';
|
|
4
|
+
|
|
5
|
+
import { changeFullscreen } from '../utils/fullscreen';
|
|
6
|
+
|
|
7
|
+
export function useFullscreen(rootRef: RefObject<HTMLElement>, player: Player | null) {
|
|
8
|
+
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const root = rootRef.current;
|
|
12
|
+
|
|
13
|
+
if (!root) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ownerDocument = root.ownerDocument;
|
|
18
|
+
const update = () => {
|
|
19
|
+
setIsFullscreen(ownerDocument.fullscreenElement === root || Boolean(player?.isFullscreen()));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
update();
|
|
23
|
+
ownerDocument.addEventListener('fullscreenchange', update);
|
|
24
|
+
player?.on('fullscreenchange', update);
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
ownerDocument.removeEventListener('fullscreenchange', update);
|
|
28
|
+
player?.off('fullscreenchange', update);
|
|
29
|
+
};
|
|
30
|
+
}, [rootRef, player]);
|
|
31
|
+
|
|
32
|
+
const toggleFullscreen = useCallback(() => {
|
|
33
|
+
if (isBrowser() && rootRef.current) {
|
|
34
|
+
changeFullscreen(rootRef.current, player);
|
|
35
|
+
}
|
|
36
|
+
}, [rootRef, player]);
|
|
37
|
+
|
|
38
|
+
return { isFullscreen, toggleFullscreen };
|
|
39
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import Player from 'video.js/dist/types/player';
|
|
3
|
+
|
|
4
|
+
export type PlayerState = {
|
|
5
|
+
isPlaying: boolean;
|
|
6
|
+
isMuted: boolean;
|
|
7
|
+
volume: number;
|
|
8
|
+
currentTime: number;
|
|
9
|
+
duration: number;
|
|
10
|
+
buffered: [number, number][];
|
|
11
|
+
rate: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const INITIAL_STATE: PlayerState = {
|
|
15
|
+
isPlaying: false,
|
|
16
|
+
isMuted: false,
|
|
17
|
+
volume: 100,
|
|
18
|
+
currentTime: 0,
|
|
19
|
+
duration: 0,
|
|
20
|
+
buffered: [],
|
|
21
|
+
rate: 1,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const PLAYER_EVENTS = [
|
|
25
|
+
'play',
|
|
26
|
+
'pause',
|
|
27
|
+
'ended',
|
|
28
|
+
'timeupdate',
|
|
29
|
+
'durationchange',
|
|
30
|
+
'loadedmetadata',
|
|
31
|
+
'progress',
|
|
32
|
+
'volumechange',
|
|
33
|
+
'ratechange',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
function readState(player: Player): PlayerState {
|
|
37
|
+
const timeRanges = player.buffered();
|
|
38
|
+
const buffered: [number, number][] = [];
|
|
39
|
+
|
|
40
|
+
for (let index = 0; index < timeRanges.length; index++) {
|
|
41
|
+
buffered.push([timeRanges.start(index), timeRanges.end(index)]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const volume = player.volume() ?? 1;
|
|
45
|
+
const duration = player.duration() ?? 0;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
isPlaying: !player.paused(),
|
|
49
|
+
isMuted: Boolean(player.muted()) || volume === 0,
|
|
50
|
+
volume: Math.round(volume * 100),
|
|
51
|
+
currentTime: player.currentTime() ?? 0,
|
|
52
|
+
duration: Number.isFinite(duration) ? duration : 0,
|
|
53
|
+
buffered,
|
|
54
|
+
rate: player.playbackRate() ?? 1,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function usePlayerState(player: Player | null) {
|
|
59
|
+
const [state, setState] = useState<PlayerState>(INITIAL_STATE);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!player) {
|
|
63
|
+
setState(INITIAL_STATE);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const update = () => {
|
|
68
|
+
setState(readState(player));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
update();
|
|
72
|
+
player.on(PLAYER_EVENTS, update);
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
player.off(PLAYER_EVENTS, update);
|
|
76
|
+
};
|
|
77
|
+
}, [player]);
|
|
78
|
+
|
|
79
|
+
return state;
|
|
80
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { SPRITE_VTT_NAME } from '../constants';
|
|
4
|
+
import { SpriteFrame } from '../shared/types';
|
|
5
|
+
import { isHlsLink, loadSpriteFrames, resolveUrl } from '../utils';
|
|
6
|
+
|
|
7
|
+
export function useSpriteFrames(link: string, enabled: boolean) {
|
|
8
|
+
const [frames, setFrames] = useState<SpriteFrame[]>([]);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setFrames([]);
|
|
12
|
+
|
|
13
|
+
const url = enabled && isHlsLink(link) ? resolveUrl(SPRITE_VTT_NAME, link) : undefined;
|
|
14
|
+
|
|
15
|
+
if (!url) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const controller = new AbortController();
|
|
20
|
+
|
|
21
|
+
loadSpriteFrames(url, controller.signal)
|
|
22
|
+
.then(result => {
|
|
23
|
+
if (!controller.signal.aborted) {
|
|
24
|
+
setFrames(result);
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.catch(() => {
|
|
28
|
+
if (!controller.signal.aborted) {
|
|
29
|
+
setFrames([]);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
controller.abort();
|
|
35
|
+
};
|
|
36
|
+
}, [link, enabled]);
|
|
37
|
+
|
|
38
|
+
return frames;
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineLocale, defineMessages } from '@cloud-ru/ds-locale';
|
|
2
|
+
|
|
3
|
+
const SITE_MEDIA_MESSAGES = defineMessages({
|
|
4
|
+
'en-GB': {
|
|
5
|
+
player: 'Video player',
|
|
6
|
+
play: 'Play',
|
|
7
|
+
pause: 'Pause',
|
|
8
|
+
mute: 'Mute',
|
|
9
|
+
unmute: 'Unmute',
|
|
10
|
+
volume: 'Volume',
|
|
11
|
+
seek: 'Seek',
|
|
12
|
+
rewind: 'Back 10 seconds',
|
|
13
|
+
forward: 'Forward 10 seconds',
|
|
14
|
+
restart: 'Restart',
|
|
15
|
+
speed: 'Playback speed',
|
|
16
|
+
enterFullscreen: 'Enter fullscreen',
|
|
17
|
+
exitFullscreen: 'Exit fullscreen',
|
|
18
|
+
errorTitle: 'Video unavailable',
|
|
19
|
+
errorDescription: 'Check your connection or try again later.',
|
|
20
|
+
retry: 'Try again',
|
|
21
|
+
loading: 'Loading video',
|
|
22
|
+
},
|
|
23
|
+
'ru-RU': {
|
|
24
|
+
player: 'Видеоплеер',
|
|
25
|
+
play: 'Воспроизвести',
|
|
26
|
+
pause: 'Пауза',
|
|
27
|
+
mute: 'Выключить звук',
|
|
28
|
+
unmute: 'Включить звук',
|
|
29
|
+
volume: 'Громкость',
|
|
30
|
+
seek: 'Перемотка',
|
|
31
|
+
rewind: 'Назад на 10 секунд',
|
|
32
|
+
forward: 'Вперёд на 10 секунд',
|
|
33
|
+
restart: 'Сначала',
|
|
34
|
+
speed: 'Скорость воспроизведения',
|
|
35
|
+
enterFullscreen: 'На весь экран',
|
|
36
|
+
exitFullscreen: 'Выйти из полноэкранного режима',
|
|
37
|
+
errorTitle: 'Видео недоступно',
|
|
38
|
+
errorDescription: 'Проверьте подключение или повторите попытку позже.',
|
|
39
|
+
retry: 'Повторить',
|
|
40
|
+
loading: 'Загрузка видео',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export type SiteMediaMessages = (typeof SITE_MEDIA_MESSAGES)['en-GB'];
|
|
45
|
+
|
|
46
|
+
/** Переводы видеоплеера и его элементов управления. */
|
|
47
|
+
export const siteMediaLocale = defineLocale('@cloud-ru/ds-site-media', SITE_MEDIA_MESSAGES);
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Источник видео. Для YouTube и Rutube используются элементы управления провайдера. */
|
|
2
|
+
export type VideoPlayerProps = {
|
|
3
|
+
/** URL файла MP4, плейлиста HLS, ролика YouTube или Rutube. */
|
|
4
|
+
src: string;
|
|
5
|
+
/** Обложка перед началом воспроизведения. */
|
|
6
|
+
poster?: string;
|
|
7
|
+
/** Показать управление и кнопку Play. По умолчанию `true`. */
|
|
8
|
+
controls?: boolean;
|
|
9
|
+
/** Автоматический запуск без звука, если разрешён браузером. */
|
|
10
|
+
autoPlay?: boolean;
|
|
11
|
+
/** Отключить звук. */
|
|
12
|
+
muted?: boolean;
|
|
13
|
+
/** Повторять видео. */
|
|
14
|
+
loop?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export type EmbedSource = {
|
|
2
|
+
provider: 'youtube' | 'rutube';
|
|
3
|
+
src: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export function getEmbedSource(link: string): EmbedSource | undefined {
|
|
7
|
+
let url: URL;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
url = new URL(link);
|
|
11
|
+
} catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!['https:', 'http:'].includes(url.protocol)) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const host = url.hostname.toLowerCase();
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
[
|
|
23
|
+
'youtube.com',
|
|
24
|
+
'www.youtube.com',
|
|
25
|
+
'm.youtube.com',
|
|
26
|
+
'youtube-nocookie.com',
|
|
27
|
+
'www.youtube-nocookie.com',
|
|
28
|
+
'youtu.be',
|
|
29
|
+
].includes(host)
|
|
30
|
+
) {
|
|
31
|
+
const id =
|
|
32
|
+
host === 'youtu.be'
|
|
33
|
+
? url.pathname.slice(1)
|
|
34
|
+
: (url.searchParams.get('v') ?? url.pathname.match(/^\/(?:embed|shorts)\/([^/]+)/)?.[1]);
|
|
35
|
+
|
|
36
|
+
if (id && /^[a-zA-Z0-9_-]{11}$/.test(id)) {
|
|
37
|
+
return { provider: 'youtube', src: 'https://www.youtube.com/embed/' + id + '?enablejsapi=1&playsinline=1' };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (host === 'rutube.ru' || host === 'www.rutube.ru') {
|
|
42
|
+
const id = url.pathname.match(/^\/(?:video|play\/embed)\/([a-zA-Z0-9_-]+)/)?.[1];
|
|
43
|
+
|
|
44
|
+
if (id) {
|
|
45
|
+
return { provider: 'rutube', src: 'https://rutube.ru/play/embed/' + id };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Разбор сообщений встраиваемого плеера на границе postMessage. */
|
|
53
|
+
export function parseEmbedMessage(data: unknown): Record<string, unknown> | undefined {
|
|
54
|
+
try {
|
|
55
|
+
const value: unknown = typeof data === 'string' ? JSON.parse(data) : data;
|
|
56
|
+
|
|
57
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
58
|
+
? (value as Record<string, unknown>)
|
|
59
|
+
: undefined;
|
|
60
|
+
} catch {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getEmbedPlaying(
|
|
66
|
+
provider: EmbedSource['provider'],
|
|
67
|
+
message: Record<string, unknown>,
|
|
68
|
+
): boolean | undefined {
|
|
69
|
+
if (provider === 'rutube' && message.type === 'player:changeState') {
|
|
70
|
+
const data = parseEmbedMessage(message.data);
|
|
71
|
+
|
|
72
|
+
if (data?.state === 'playing') {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (data?.state === 'paused' || data?.state === 'stopped') {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const info = parseEmbedMessage(message.info);
|
|
82
|
+
const state = message.event === 'onStateChange' ? message.info : info?.playerState;
|
|
83
|
+
|
|
84
|
+
if (provider === 'youtube' && (message.event === 'onStateChange' || message.event === 'infoDelivery')) {
|
|
85
|
+
if (state === 1) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (state === 0 || state === 2) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function formatTime(totalSeconds: number) {
|
|
2
|
+
const seconds = Math.max(0, Math.floor(totalSeconds));
|
|
3
|
+
const hours = Math.floor(seconds / 3600);
|
|
4
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
5
|
+
const restSeconds = String(seconds % 60).padStart(2, '0');
|
|
6
|
+
|
|
7
|
+
if (hours > 0) {
|
|
8
|
+
return `${hours}:${String(minutes).padStart(2, '0')}:${restSeconds}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return `${minutes}:${restSeconds}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function formatRate(rate: number) {
|
|
15
|
+
return `${String(rate).replace('.', ',')}x`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Player from 'video.js/dist/types/player';
|
|
2
|
+
|
|
3
|
+
type FullscreenPlayer = Pick<Player, 'isFullscreen' | 'requestFullscreen' | 'exitFullscreen'>;
|
|
4
|
+
|
|
5
|
+
/** Повторный запрос требует нового действия пользователя; автоматический retry не устраняет запрет браузера. */
|
|
6
|
+
export async function changeFullscreen(root: HTMLElement, player: FullscreenPlayer | null) {
|
|
7
|
+
const ownerDocument = root.ownerDocument;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
if (ownerDocument.fullscreenElement) {
|
|
11
|
+
await ownerDocument.exitFullscreen();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (player?.isFullscreen()) {
|
|
16
|
+
await player.exitFullscreen();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (root.requestFullscreen) {
|
|
21
|
+
await root.requestFullscreen();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await player?.requestFullscreen();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && ['TypeError', 'NotAllowedError', 'SecurityError'].includes(error.name)) {
|
|
28
|
+
console.warn('SiteVideo: fullscreen request denied. Check browser permissions and user activation.', error);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.error('SiteVideo: failed to change fullscreen mode.', error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SpriteFrame } from '../shared/types';
|
|
2
|
+
import { parseSpriteVtt } from './sprite';
|
|
3
|
+
|
|
4
|
+
/** Необязательные кадры предпросмотра: недоступный VTT не препятствует проигрыванию. */
|
|
5
|
+
export async function loadSpriteFrames(url: string, signal: AbortSignal): Promise<SpriteFrame[]> {
|
|
6
|
+
const response = await fetch(url, { signal });
|
|
7
|
+
return response.ok ? parseSpriteVtt(await response.text(), url) : [];
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SiteVideoProps } from '../components';
|
|
2
|
+
import { VideoPlayerProps } from '../types';
|
|
3
|
+
|
|
4
|
+
const HLS_REGEXP = /\.m3u8(?:$|[?#])/i;
|
|
5
|
+
|
|
6
|
+
export function isHlsLink(link: string) {
|
|
7
|
+
return HLS_REGEXP.test(link);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getSourceType(link: string) {
|
|
11
|
+
return isHlsLink(link) ? 'application/x-mpegURL' : 'video/mp4';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isVideoPlayerContent(video: SiteVideoProps['video']): video is VideoPlayerProps {
|
|
15
|
+
return (
|
|
16
|
+
typeof video === 'object' &&
|
|
17
|
+
video !== null &&
|
|
18
|
+
video !== undefined &&
|
|
19
|
+
'src' in video &&
|
|
20
|
+
typeof video.src === 'string'
|
|
21
|
+
);
|
|
22
|
+
}
|