etudes 7.1.0 → 7.2.1

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.
@@ -1,6 +1,6 @@
1
1
  import { type HTMLAttributes } from 'react';
2
2
  import { type Size } from 'spase';
3
- export type VideoProps = Omit<HTMLAttributes<HTMLVideoElement>, 'autoPlay' | 'controls' | 'loop' | 'muted' | 'playsInline' | 'poster' | 'onCanPlay' | 'onEnded' | 'onPause' | 'onPlay'> & {
3
+ export type VideoProps = Omit<HTMLAttributes<HTMLVideoElement>, 'autoPlay' | 'controls' | 'loop' | 'muted' | 'playsInline' | 'poster' | 'onCanPlay' | 'onEnded' | 'onPause' | 'onPlay' | 'onTimeUpdate'> & {
4
4
  autoLoop?: boolean;
5
5
  autoPlay?: boolean;
6
6
  hasControls?: boolean;
@@ -17,8 +17,9 @@ export type VideoProps = Omit<HTMLAttributes<HTMLVideoElement>, 'autoPlay' | 'co
17
17
  onPause?: () => void;
18
18
  onPlay?: () => void;
19
19
  onSizeChange?: (size?: Size) => void;
20
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
20
21
  };
21
- export declare const Video: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLVideoElement>, "onCanPlay" | "onEnded" | "onPause" | "onPlay" | "autoPlay" | "controls" | "loop" | "muted" | "playsInline" | "poster"> & {
22
+ export declare const Video: import("react").ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLVideoElement>, "onCanPlay" | "onEnded" | "onPause" | "onPlay" | "onTimeUpdate" | "autoPlay" | "controls" | "loop" | "muted" | "playsInline" | "poster"> & {
22
23
  autoLoop?: boolean;
23
24
  autoPlay?: boolean;
24
25
  hasControls?: boolean;
@@ -35,4 +36,5 @@ export declare const Video: import("react").ForwardRefExoticComponent<Omit<HTMLA
35
36
  onPause?: () => void;
36
37
  onPlay?: () => void;
37
38
  onSizeChange?: (size?: Size) => void;
39
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
38
40
  } & import("react").RefAttributes<HTMLVideoElement>>;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useEffect, useRef } from 'react';
3
3
  import { useVideoSize } from '../hooks/useVideoSize.js';
4
- export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls = false, isMuted = true, playsInline = true, posterSrc, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, ...props }, ref) => {
4
+ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls = false, isMuted = true, playsInline = true, posterSrc, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, onTimeUpdate, ...props }, ref) => {
5
5
  const localRef = useRef(null);
6
6
  const videoRef = ref ?? localRef;
7
7
  const size = useVideoSize({
@@ -36,7 +36,8 @@ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls
36
36
  onFullscreenChange?.(isFullscreen);
37
37
  };
38
38
  const canPlayHandler = event => {
39
- if (autoPlay && (videoRef.current?.paused ?? false)) {
39
+ const el = event.currentTarget;
40
+ if (autoPlay && el.paused) {
40
41
  play();
41
42
  }
42
43
  onCanPlay?.();
@@ -50,6 +51,10 @@ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls
50
51
  const endHandler = event => {
51
52
  onEnd?.();
52
53
  };
54
+ const timeUpdateHandler = event => {
55
+ const el = event.currentTarget;
56
+ onTimeUpdate?.(el.currentTime, el.duration);
57
+ };
53
58
  const play = () => {
54
59
  if (!videoRef.current)
55
60
  return;
@@ -60,6 +65,6 @@ export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls
60
65
  return;
61
66
  videoRef.current.pause();
62
67
  };
63
- return (_jsx("video", { ...props, ref: ref, autoPlay: autoPlay, controls: hasControls, loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, children: _jsx("source", { src: src }) }));
68
+ return (_jsx("video", { ...props, ref: ref, autoPlay: autoPlay, controls: hasControls, loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, onTimeUpdate: timeUpdateHandler, children: _jsx("source", { src: src }) }));
64
69
  });
65
70
  Object.defineProperty(Video, 'displayName', { value: 'Video', writable: false });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "7.1.0",
3
+ "version": "7.2.1",
4
4
  "description": "A study of headless React components",
5
5
  "type": "module",
6
6
  "scripts": {