@vnejs/uis.react.video 0.1.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.
@@ -0,0 +1,3 @@
1
+ import { type VideoProps } from "./Video.types.js";
2
+ export declare const Video: ({ src, loop, isPlaying, transition, opacity, volume, className, onEnded, }: VideoProps) => import("react").JSX.Element;
3
+ //# sourceMappingURL=Video.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.d.ts","sourceRoot":"","sources":["../src/Video.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,eAAO,MAAM,KAAK,GAAI,4EASnB,UAAU,gCAqDZ,CAAC"}
package/dist/Video.js ADDED
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef } from "react";
3
+ import { b } from "./Video.styles.js";
4
+ const TRANSPARENT_IMAGE = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxIDEiLz4=";
5
+ export const Video = ({ src = "", loop = false, isPlaying = true, transition = 0, opacity = null, volume = 1, className = "", onEnded, }) => {
6
+ const videoRef = useRef(null);
7
+ const style = useMemo(() => {
8
+ const result = {
9
+ transition: transition ? `${transition}ms` : "none",
10
+ };
11
+ if (opacity !== null)
12
+ result.opacity = opacity;
13
+ return result;
14
+ }, [transition, opacity]);
15
+ useEffect(() => {
16
+ const video = videoRef.current;
17
+ if (!video)
18
+ return;
19
+ video.volume = volume;
20
+ video.loop = loop;
21
+ if (!isPlaying) {
22
+ video.pause();
23
+ video.currentTime = 0;
24
+ return;
25
+ }
26
+ if (src)
27
+ void video.play().catch(() => undefined);
28
+ }, [src, loop, volume, isPlaying]);
29
+ const handleEnded = useCallback(() => {
30
+ if (loop)
31
+ return;
32
+ videoRef.current?.pause();
33
+ onEnded?.();
34
+ }, [loop, onEnded]);
35
+ if (!src)
36
+ return null;
37
+ return (_jsx("video", { ref: videoRef, className: b({}, [className]), style: style, src: src, loop: loop, playsInline: true, muted: false, poster: TRANSPARENT_IMAGE, crossOrigin: "anonymous", disablePictureInPicture: true, onEnded: handleEnded }));
38
+ };
39
+ //# sourceMappingURL=Video.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.js","sourceRoot":"","sources":["../src/Video.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAIhE,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,MAAM,iBAAiB,GAAG,4GAA4G,CAAC;AAEvI,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EACpB,GAAG,GAAG,EAAE,EACR,IAAI,GAAG,KAAK,EACZ,SAAS,GAAG,IAAI,EAChB,UAAU,GAAG,CAAC,EACd,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,CAAC,EACV,SAAS,GAAG,EAAE,EACd,OAAO,GACI,EAAE,EAAE;IACf,MAAM,QAAQ,GAAG,MAAM,CAAmB,IAAI,CAAC,CAAC;IAEhD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,MAAM,GAAoC;YAC9C,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,CAAC,CAAC,CAAC,MAAM;SACpD,CAAC;QAEF,IAAI,OAAO,KAAK,IAAI;YAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QAE/C,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAE1B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QACtB,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC;YACtB,OAAO;QACT,CAAC;QAED,IAAI,GAAG;YAAE,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAEnC,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;QACnC,IAAI,IAAI;YAAE,OAAO;QAEjB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC1B,OAAO,EAAE,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAEpB,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IAEtB,OAAO,CACL,gBACE,GAAG,EAAE,QAAQ,EACb,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAC7B,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,WAAW,QACX,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,iBAAiB,EACzB,WAAW,EAAC,WAAW,EACvB,uBAAuB,QACvB,OAAO,EAAE,WAAW,GACpB,CACH,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const b: any;
2
+ //# sourceMappingURL=Video.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.styles.d.ts","sourceRoot":"","sources":["../src/Video.styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC,KAAc,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { cn, injectStyles, sel } from "@vnejs/uis.utils";
2
+ export const b = cn("Video");
3
+ const CSS = `
4
+ ${sel(b())} {
5
+ display: block;
6
+ position: absolute;
7
+ width: 100%;
8
+ height: 100%;
9
+ object-fit: cover;
10
+ object-position: center;
11
+ }
12
+ `;
13
+ injectStyles(CSS);
14
+ //# sourceMappingURL=Video.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.styles.js","sourceRoot":"","sources":["../src/Video.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;AAE7B,MAAM,GAAG,GAAG;EACV,GAAG,CAAC,CAAC,EAAE,CAAC;;;;;;;;CAQT,CAAC;AAEF,YAAY,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { CssInsertValueNumber } from "@vnejs/uis.utils";
2
+ export type VideoProps = {
3
+ src?: string;
4
+ loop?: boolean;
5
+ isPlaying?: boolean;
6
+ transition?: CssInsertValueNumber;
7
+ opacity?: CssInsertValueNumber | null;
8
+ volume?: number;
9
+ className?: string;
10
+ onEnded?: () => void;
11
+ };
12
+ //# sourceMappingURL=Video.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.types.d.ts","sourceRoot":"","sources":["../src/Video.types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Video.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Video.types.js","sourceRoot":"","sources":["../src/Video.types.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export type { VideoProps } from "./Video.types.js";
2
+ export { Video } from "./Video.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Video } from "./Video.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@vnejs/uis.react.video",
3
+ "version": "0.1.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "scripts": {
7
+ "build": "npx @vnejs/monorepo package",
8
+ "publish:major:uis:react": "npm run publish:major",
9
+ "publish:minor:uis:react": "npm run publish:minor",
10
+ "publish:patch:uis:react": "npm run publish:patch",
11
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
12
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
13
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
14
+ },
15
+ "peerDependencies": {
16
+ "@vnejs/uis.utils": "~0.1.0"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "tsconfig.json"
22
+ ]
23
+ }
@@ -0,0 +1,16 @@
1
+ import { cn, injectStyles, sel } from "@vnejs/uis.utils";
2
+
3
+ export const b = cn("Video");
4
+
5
+ const CSS = `
6
+ ${sel(b())} {
7
+ display: block;
8
+ position: absolute;
9
+ width: 100%;
10
+ height: 100%;
11
+ object-fit: cover;
12
+ object-position: center;
13
+ }
14
+ `;
15
+
16
+ injectStyles(CSS);
package/src/Video.tsx ADDED
@@ -0,0 +1,71 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from "react";
2
+
3
+ import { type VideoProps } from "./Video.types.js";
4
+
5
+ import { b } from "./Video.styles.js";
6
+
7
+ const TRANSPARENT_IMAGE = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxIDEiLz4=";
8
+
9
+ export const Video = ({
10
+ src = "",
11
+ loop = false,
12
+ isPlaying = true,
13
+ transition = 0,
14
+ opacity = null,
15
+ volume = 1,
16
+ className = "",
17
+ onEnded,
18
+ }: VideoProps) => {
19
+ const videoRef = useRef<HTMLVideoElement>(null);
20
+
21
+ const style = useMemo(() => {
22
+ const result: Record<string, string | number> = {
23
+ transition: transition ? `${transition}ms` : "none",
24
+ };
25
+
26
+ if (opacity !== null) result.opacity = opacity;
27
+
28
+ return result;
29
+ }, [transition, opacity]);
30
+
31
+ useEffect(() => {
32
+ const video = videoRef.current;
33
+ if (!video) return;
34
+
35
+ video.volume = volume;
36
+ video.loop = loop;
37
+
38
+ if (!isPlaying) {
39
+ video.pause();
40
+ video.currentTime = 0;
41
+ return;
42
+ }
43
+
44
+ if (src) void video.play().catch(() => undefined);
45
+ }, [src, loop, volume, isPlaying]);
46
+
47
+ const handleEnded = useCallback(() => {
48
+ if (loop) return;
49
+
50
+ videoRef.current?.pause();
51
+ onEnded?.();
52
+ }, [loop, onEnded]);
53
+
54
+ if (!src) return null;
55
+
56
+ return (
57
+ <video
58
+ ref={videoRef}
59
+ className={b({}, [className])}
60
+ style={style}
61
+ src={src}
62
+ loop={loop}
63
+ playsInline
64
+ muted={false}
65
+ poster={TRANSPARENT_IMAGE}
66
+ crossOrigin="anonymous"
67
+ disablePictureInPicture
68
+ onEnded={handleEnded}
69
+ />
70
+ );
71
+ };
@@ -0,0 +1,12 @@
1
+ import type { CssInsertValueNumber } from "@vnejs/uis.utils";
2
+
3
+ export type VideoProps = {
4
+ src?: string;
5
+ loop?: boolean;
6
+ isPlaying?: boolean;
7
+ transition?: CssInsertValueNumber;
8
+ opacity?: CssInsertValueNumber | null;
9
+ volume?: number;
10
+ className?: string;
11
+ onEnded?: () => void;
12
+ };
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { VideoProps } from "./Video.types.js";
2
+ export { Video } from "./Video.js";
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.react.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": [
8
+ "src/**/*.ts",
9
+ "src/**/*.tsx",
10
+ "../../../globals.d.ts"
11
+ ],
12
+ "exclude": [
13
+ "dist",
14
+ "node_modules",
15
+ "src/**/*.stories.tsx"
16
+ ]
17
+ }