@barabel324/react-player 0.0.5 → 0.0.7
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/README.md +100 -9
- package/dist/css.d.ts +2 -0
- package/dist/{index-Cu3vJcLM.js → index-Bu1TBomL.js} +1 -1
- package/dist/index-Cqi0pvqf.js +175 -0
- package/dist/{index-BKNjwSFg.js → index-Cr0yHksH.js} +2 -2
- package/dist/{index-1pgUfxhC.js → index-DECHm14m.js} +1 -1
- package/dist/{index-DsBO-KZz.js → index-pr5RFd69.js} +13 -13
- package/dist/react-player.css +1 -1
- package/dist/react-player.d.ts +45 -0
- package/dist/react-player.js +1 -1
- package/package.json +17 -10
- package/dist/index-Dnbs5lXl.js +0 -138
package/README.md
CHANGED
|
@@ -10,21 +10,112 @@
|
|
|
10
10
|
- **VK** — используется прямая ссылка на видео.
|
|
11
11
|
|
|
12
12
|
## Превью
|
|
13
|
-
Можно указать изображение-превью, которое будет отображаться до загрузки плеера.
|
|
13
|
+
Можно указать изображение-превью, которое будет отображаться до загрузки плеера. Как только плеер загрузится, отобразится кнопка, при нажатии которого превью уйдет, и запустится плеер.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
preview: {
|
|
17
|
+
src: string;
|
|
18
|
+
alt: string;
|
|
19
|
+
};
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Кастомизация
|
|
23
|
+
В плеер можно кастомизировать изображение и кнопку, которые будут показываться, если есть превью.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const components={
|
|
27
|
+
button,
|
|
28
|
+
previewPicture
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
const PlayButton = () => (
|
|
34
|
+
<button>▶ Play</button>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const PreviewImage = () => (
|
|
38
|
+
<img src='src/img' />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
<Player
|
|
42
|
+
url={url}
|
|
43
|
+
components={{
|
|
44
|
+
button: PlayButton,
|
|
45
|
+
previewPicture: PreviewImage,
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Также можно прокинуть класс на сам плеер, если есть превью.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
classNames={
|
|
54
|
+
player: 'custom-class'
|
|
55
|
+
}
|
|
56
|
+
```
|
|
14
57
|
|
|
15
58
|
## Стили
|
|
16
|
-
Импорт
|
|
59
|
+
Импорт такой:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import '@barabel324/react-player/css';
|
|
63
|
+
```
|
|
17
64
|
|
|
18
65
|
## Пропсы
|
|
19
|
-
- preview - ссылка на изображение, необязательно
|
|
20
|
-
- url - ссылка на видео, обязательный
|
|
21
66
|
|
|
22
67
|
```ts
|
|
23
68
|
type TPlayer = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
69
|
+
/** Превью для видео */
|
|
70
|
+
preview?: TPlayerPreview['preview'];
|
|
71
|
+
/** Ссылка на видео */
|
|
72
|
+
url: TPlayerBase['url'];
|
|
73
|
+
/** кастомные компоненты либы */
|
|
74
|
+
components?: TComponents;
|
|
75
|
+
/** кастомные классы для компонентов либы */
|
|
76
|
+
classNames?: TClassNames;
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Минимальный пример
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { Player } from '@barabel324/react-player';
|
|
84
|
+
import '@barabel324/react-player/css';
|
|
85
|
+
|
|
86
|
+
const urls = {
|
|
87
|
+
youtube: 'https://www.youtube.com/watch?v=0r9iEuDCnrw',
|
|
88
|
+
video: 'https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4',
|
|
89
|
+
rutube: 'https://rutube.ru/play/embed/20c1db3c9680dd6c11c5196e115389c3/',
|
|
90
|
+
vk: 'https://vkvideo.ru/video-230010077_456239088',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const urlsValues = Object.values(urls);
|
|
94
|
+
|
|
95
|
+
const App = () => {
|
|
96
|
+
return (
|
|
97
|
+
<div>
|
|
98
|
+
{urlsValues.map((url, index) => {
|
|
99
|
+
return (
|
|
100
|
+
<div
|
|
101
|
+
key={index}
|
|
102
|
+
style={{
|
|
103
|
+
margin: 50,
|
|
104
|
+
width: 300,
|
|
105
|
+
height: 300,
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<Player
|
|
109
|
+
preview={{
|
|
110
|
+
src: 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRicvXHENnmfMs08gwqqleKpIFIDyYXvABiotI69IImEyfxZBXVIos5QqecafJKRFV5a76EttukpAtA0O6-y9ujsgrgpwb0TbLedjYNo38',
|
|
111
|
+
alt: 'preview',
|
|
112
|
+
}}
|
|
113
|
+
url={url}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
27
120
|
};
|
|
28
|
-
url: string;
|
|
29
|
-
}
|
|
30
121
|
```
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { jsx as o, jsxs as d } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as b, useContext as f, useReducer as k, lazy as v, useMemo as N, useRef as C } from "react";
|
|
3
|
+
function h() {
|
|
4
|
+
let e, t = "", r = 0;
|
|
5
|
+
for (; r < arguments.length; ) (e = arguments[r++]) && typeof e == "string" && (t && (t += " "), t += e);
|
|
6
|
+
return t;
|
|
7
|
+
}
|
|
8
|
+
const a = {
|
|
9
|
+
show: "show",
|
|
10
|
+
hide: "hide",
|
|
11
|
+
showButton: "showButton",
|
|
12
|
+
hideButton: "hideButton",
|
|
13
|
+
canplay: "canplay"
|
|
14
|
+
}, m = {
|
|
15
|
+
showButton: !1,
|
|
16
|
+
showPreview: !0,
|
|
17
|
+
canplay: !1
|
|
18
|
+
}, E = (e, t) => {
|
|
19
|
+
const { type: r } = t;
|
|
20
|
+
switch (r) {
|
|
21
|
+
case a.show:
|
|
22
|
+
return { ...e, showButton: !0, showPreview: !0 };
|
|
23
|
+
case a.hide:
|
|
24
|
+
return { ...e, showButton: !1, showPreview: !1 };
|
|
25
|
+
case a.showButton:
|
|
26
|
+
return { ...e, showButton: !0 };
|
|
27
|
+
case a.hideButton:
|
|
28
|
+
return { ...e, showButton: !1 };
|
|
29
|
+
case a.canplay:
|
|
30
|
+
return { ...e, canplay: !0, showButton: !0 };
|
|
31
|
+
default:
|
|
32
|
+
return e;
|
|
33
|
+
}
|
|
34
|
+
}, B = b(m), x = b(() => {
|
|
35
|
+
}), R = ({ children: e }) => {
|
|
36
|
+
const [t, r] = k(E, m);
|
|
37
|
+
return /* @__PURE__ */ o(B.Provider, { value: t, children: /* @__PURE__ */ o(x.Provider, { value: r, children: e }) });
|
|
38
|
+
}, S = () => {
|
|
39
|
+
const e = f(B);
|
|
40
|
+
if (e === void 0)
|
|
41
|
+
throw new Error("usePlayerState нужно использовать внутри PlayerProvider");
|
|
42
|
+
return e;
|
|
43
|
+
}, T = () => {
|
|
44
|
+
const e = f(x);
|
|
45
|
+
if (e === void 0)
|
|
46
|
+
throw new Error("usePlayerDispatch нужно использовать внутри PlayerProvider");
|
|
47
|
+
return e;
|
|
48
|
+
}, $ = "_button_1xali_2", D = {
|
|
49
|
+
button: $
|
|
50
|
+
}, V = ({
|
|
51
|
+
className: e,
|
|
52
|
+
onClick: t
|
|
53
|
+
}) => /* @__PURE__ */ o(
|
|
54
|
+
"button",
|
|
55
|
+
{
|
|
56
|
+
className: h(
|
|
57
|
+
D.button,
|
|
58
|
+
e
|
|
59
|
+
),
|
|
60
|
+
type: "button",
|
|
61
|
+
onClick: t
|
|
62
|
+
}
|
|
63
|
+
), j = "_playerPreview_so1s6_1", A = "_playerPreview__wrapper_so1s6_7", L = "_playerPreview__button_so1s6_12", O = "_playerPreview__preview_so1s6_19", Y = "_playerPreview__player_so1s6_28", y = {
|
|
64
|
+
playerPreview: j,
|
|
65
|
+
playerPreview__wrapper: A,
|
|
66
|
+
playerPreview__button: L,
|
|
67
|
+
playerPreview__preview: O,
|
|
68
|
+
playerPreview__player: Y
|
|
69
|
+
}, z = ({
|
|
70
|
+
className: e,
|
|
71
|
+
preview: t,
|
|
72
|
+
onPlay: r,
|
|
73
|
+
children: n,
|
|
74
|
+
ButtonComponent: u,
|
|
75
|
+
PreviewPictureComponent: l
|
|
76
|
+
}) => {
|
|
77
|
+
const { showButton: p, showPreview: c, canplay: _ } = S(), i = T(), P = () => {
|
|
78
|
+
_ && (i({
|
|
79
|
+
type: a.hide
|
|
80
|
+
}), r && r());
|
|
81
|
+
}, w = !!t || !!l;
|
|
82
|
+
return /* @__PURE__ */ d(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
className: h(
|
|
86
|
+
y.playerPreview,
|
|
87
|
+
e
|
|
88
|
+
),
|
|
89
|
+
children: [
|
|
90
|
+
(p || t && c) && /* @__PURE__ */ d(
|
|
91
|
+
"div",
|
|
92
|
+
{
|
|
93
|
+
className: y.playerPreview__wrapper,
|
|
94
|
+
onClick: P,
|
|
95
|
+
children: [
|
|
96
|
+
p && (u ? /* @__PURE__ */ o(u, {}) : /* @__PURE__ */ o(
|
|
97
|
+
V,
|
|
98
|
+
{
|
|
99
|
+
className: y.playerPreview__button
|
|
100
|
+
}
|
|
101
|
+
)),
|
|
102
|
+
w && c && (l ? /* @__PURE__ */ o(l, {}) : t && /* @__PURE__ */ o("img", { className: y.playerPreview__preview, src: t.src, alt: t.alt ?? "preview" }))
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ o("div", { className: y.playerPreview__player, children: n })
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}, s = {
|
|
111
|
+
youtube: "youtube",
|
|
112
|
+
rutube: "rutube",
|
|
113
|
+
video: "video",
|
|
114
|
+
vk: "vk"
|
|
115
|
+
}, I = {
|
|
116
|
+
[s.youtube]: v(async () => await import("./index-DECHm14m.js")),
|
|
117
|
+
[s.rutube]: v(async () => await import("./index-pr5RFd69.js")),
|
|
118
|
+
[s.video]: v(async () => await import("./index-Bu1TBomL.js")),
|
|
119
|
+
[s.vk]: v(async () => await import("./index-Cr0yHksH.js"))
|
|
120
|
+
}, M = (e) => {
|
|
121
|
+
const t = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/, r = /^(?:https?:\/\/)?(?:rutu\.be\/|rutube\.ru(\/play\/))/, n = /^(?:https?:\/\/)?(?:www\.|m\.)?(?:vk\.com|vkvideo\.ru)\/.+$/;
|
|
122
|
+
return r.test(e) ? s.rutube : t.test(e) ? s.youtube : n.test(e) ? s.vk : s.video;
|
|
123
|
+
}, U = "_player_1afml_1", q = {
|
|
124
|
+
player: U
|
|
125
|
+
}, F = ({
|
|
126
|
+
children: e,
|
|
127
|
+
hasPreview: t,
|
|
128
|
+
...r
|
|
129
|
+
}) => t ? /* @__PURE__ */ o(
|
|
130
|
+
z,
|
|
131
|
+
{
|
|
132
|
+
...r,
|
|
133
|
+
children: e
|
|
134
|
+
}
|
|
135
|
+
) : e, G = ({
|
|
136
|
+
className: e,
|
|
137
|
+
url: t,
|
|
138
|
+
preview: r,
|
|
139
|
+
classNames: n,
|
|
140
|
+
components: u
|
|
141
|
+
}) => {
|
|
142
|
+
const l = n?.player, p = u?.button, c = u?.previewPicture, _ = N(() => {
|
|
143
|
+
const g = M(t);
|
|
144
|
+
return I[g];
|
|
145
|
+
}, [t]), i = C(null), P = () => {
|
|
146
|
+
i.current && i.current.play();
|
|
147
|
+
}, w = !!r || !!c;
|
|
148
|
+
return /* @__PURE__ */ o(
|
|
149
|
+
F,
|
|
150
|
+
{
|
|
151
|
+
hasPreview: w,
|
|
152
|
+
className: e,
|
|
153
|
+
preview: r,
|
|
154
|
+
onPlay: P,
|
|
155
|
+
ButtonComponent: p,
|
|
156
|
+
PreviewPictureComponent: c,
|
|
157
|
+
children: /* @__PURE__ */ o(
|
|
158
|
+
_,
|
|
159
|
+
{
|
|
160
|
+
className: h(
|
|
161
|
+
l ?? q.player,
|
|
162
|
+
!w && e
|
|
163
|
+
),
|
|
164
|
+
ref: i,
|
|
165
|
+
url: t
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}, K = (e) => /* @__PURE__ */ o(R, { children: /* @__PURE__ */ o(G, { ...e }) });
|
|
171
|
+
export {
|
|
172
|
+
a as P,
|
|
173
|
+
K as a,
|
|
174
|
+
T as u
|
|
175
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as a, useImperativeHandle as l, useEffect as u } from "react";
|
|
3
|
-
import { u as p } from "./index-
|
|
3
|
+
import { u as p } from "./index-Cqi0pvqf.js";
|
|
4
4
|
const m = async () => new Promise((t, n) => {
|
|
5
5
|
if (window.VK?.VideoPlayer) {
|
|
6
6
|
t(window.VK);
|
|
@@ -54,7 +54,7 @@ const m = async () => new Promise((t, n) => {
|
|
|
54
54
|
}), () => {
|
|
55
55
|
e.current && e.current.destroy();
|
|
56
56
|
};
|
|
57
|
-
}, []), /* @__PURE__ */ d(
|
|
57
|
+
}, [c]), /* @__PURE__ */ d(
|
|
58
58
|
"iframe",
|
|
59
59
|
{
|
|
60
60
|
className: t,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as s, useImperativeHandle as p, useEffect as y } from "react";
|
|
3
|
-
import { u as f } from "./index-
|
|
3
|
+
import { u as f } from "./index-Cqi0pvqf.js";
|
|
4
4
|
const m = (t) => {
|
|
5
5
|
const n = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/, o = t.match(n);
|
|
6
6
|
return o && o[7].length === 11 ? o[7] : "";
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
-
import { u as p } from "./index-
|
|
2
|
+
import { u as p } from "./index-Cqi0pvqf.js";
|
|
3
3
|
import { useRef as c, useImperativeHandle as f, useEffect as l } from "react";
|
|
4
4
|
const w = ({
|
|
5
|
-
className:
|
|
6
|
-
ref:
|
|
7
|
-
url:
|
|
5
|
+
className: a,
|
|
6
|
+
ref: s,
|
|
7
|
+
url: n
|
|
8
8
|
}) => {
|
|
9
|
-
const e = c(null),
|
|
9
|
+
const e = c(null), r = p(), o = () => {
|
|
10
10
|
e.current && e.current.contentWindow?.postMessage(JSON.stringify({
|
|
11
11
|
type: "player:play",
|
|
12
12
|
data: {}
|
|
13
13
|
}), "*");
|
|
14
14
|
};
|
|
15
|
-
return f(
|
|
15
|
+
return f(s, () => ({
|
|
16
16
|
play: o
|
|
17
17
|
})), l(() => {
|
|
18
|
-
const
|
|
18
|
+
const t = (u) => {
|
|
19
19
|
if (!e.current) return;
|
|
20
|
-
JSON.parse(u.data).type === "player:ready" &&
|
|
20
|
+
JSON.parse(u.data).type === "player:ready" && r({ type: "canplay" });
|
|
21
21
|
};
|
|
22
|
-
return window.addEventListener("message",
|
|
23
|
-
window.removeEventListener("message",
|
|
22
|
+
return window.addEventListener("message", t), () => {
|
|
23
|
+
window.removeEventListener("message", t);
|
|
24
24
|
};
|
|
25
|
-
}, []), /* @__PURE__ */ i(
|
|
25
|
+
}, [r]), /* @__PURE__ */ i(
|
|
26
26
|
"iframe",
|
|
27
27
|
{
|
|
28
|
-
className:
|
|
28
|
+
className: a,
|
|
29
29
|
ref: e,
|
|
30
30
|
width: "100%",
|
|
31
31
|
height: "100%",
|
|
32
|
-
src:
|
|
32
|
+
src: n,
|
|
33
33
|
allowFullScreen: !0,
|
|
34
34
|
frameBorder: "0"
|
|
35
35
|
}
|
package/dist/react-player.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
1
|
+
._button_1xali_2{--idmrp-button-play-size: 3.375rem;--idmrp-button-play-bg: #2D3C31;--idmrp-button-play-triangle-color: #E3DFD7;position:relative;width:var(--idmrp-button-play-size);min-width:var(--idmrp-button-play-size);height:var(--idmrp-button-play-size);background-color:var(--idmrp-button-play-bg);border-radius:50%}._button_1xali_2:before{content:"";position:absolute;top:50%;left:58%;border:.3125rem solid transparent;border-left:.5625rem solid var(--idmrp-button-play-triangle-color);transform:translate(-50%,-50%)}._playerPreview_so1s6_1{position:relative;width:100%;height:100%;object-fit:cover}._playerPreview__wrapper_so1s6_7{position:absolute;inset:0;cursor:pointer}._playerPreview__button_so1s6_12{z-index:2;position:absolute;top:50%;left:50%;transform:translate(-50%) translateY(-50%)}._playerPreview__preview_so1s6_19{z-index:1;position:absolute;top:0;left:0;width:100%;height:100%;object-fit:cover}._playerPreview__player_so1s6_28{width:100%;height:100%}._player_1afml_1{display:block;width:100%;height:100%;object-fit:cover;object-position:center}
|
package/dist/react-player.d.ts
CHANGED
|
@@ -1,16 +1,59 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
|
|
3
|
+
/** Утилитарный дженерик для обозначения функционального компонента с пропсами children и className */
|
|
3
4
|
declare type FCClass<P = object> = React.FC<P & React.PropsWithChildren & {
|
|
4
5
|
className?: string;
|
|
5
6
|
}>;
|
|
6
7
|
|
|
8
|
+
declare type KeysWithClassNames = {
|
|
9
|
+
[K in keyof TMapComponents]: TMapComponents[K] extends {
|
|
10
|
+
className: string;
|
|
11
|
+
} ? K : never;
|
|
12
|
+
}[keyof TMapComponents];
|
|
13
|
+
|
|
14
|
+
declare type KeysWithComponent = {
|
|
15
|
+
[K in keyof TMapComponents]: TMapComponents[K] extends {
|
|
16
|
+
component: FCClass;
|
|
17
|
+
} ? K : never;
|
|
18
|
+
}[keyof TMapComponents];
|
|
19
|
+
|
|
7
20
|
export declare const Player: FCClass<TPlayer>;
|
|
8
21
|
|
|
22
|
+
declare type TClassNames = {
|
|
23
|
+
[K in KeysWithClassNames]?: TMapComponents[K]['className'];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
declare type TComponents = {
|
|
27
|
+
[K in KeysWithComponent]?: TMapComponents[K]['component'];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
declare type TMapComponents = {
|
|
31
|
+
/** изображение превью */
|
|
32
|
+
previewPicture: {
|
|
33
|
+
/** компонент изображения */
|
|
34
|
+
component: FCClass;
|
|
35
|
+
};
|
|
36
|
+
/** кнопка, которая отображаентся, когда видео загрузилось */
|
|
37
|
+
button: {
|
|
38
|
+
/** компонент кнопки */
|
|
39
|
+
component: FCClass;
|
|
40
|
+
};
|
|
41
|
+
/** Плеер */
|
|
42
|
+
player: {
|
|
43
|
+
/** класс кнопки */
|
|
44
|
+
className: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
9
48
|
export declare type TPlayer = {
|
|
10
49
|
/** Превью для видео */
|
|
11
50
|
preview?: TPlayerPreview['preview'];
|
|
12
51
|
/** Ссылка на видео */
|
|
13
52
|
url: TPlayerBase['url'];
|
|
53
|
+
/** кастомные компоненты либы */
|
|
54
|
+
components?: TComponents;
|
|
55
|
+
/** кастомные классы для компонентов либы */
|
|
56
|
+
classNames?: TClassNames;
|
|
14
57
|
};
|
|
15
58
|
|
|
16
59
|
declare type TPlayerBase = {
|
|
@@ -29,6 +72,8 @@ declare type TPlayerPreview = {
|
|
|
29
72
|
/** Альт изображения */
|
|
30
73
|
alt: string;
|
|
31
74
|
};
|
|
75
|
+
PreviewPictureComponent?: FCClass<Record<string, any>>;
|
|
76
|
+
ButtonComponent?: FCClass<Record<string, any>>;
|
|
32
77
|
onPlay?: () => void;
|
|
33
78
|
};
|
|
34
79
|
|
package/dist/react-player.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barabel324/react-player",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/react-player.js",
|
|
6
6
|
"types": "./dist/react-player.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"import": "./dist/react-player.js"
|
|
10
|
+
},
|
|
11
|
+
"./css": {
|
|
12
|
+
"import": "./dist/react-player.css",
|
|
13
|
+
"types": "./dist/css.d.ts"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"files": [
|
|
@@ -20,26 +24,29 @@
|
|
|
20
24
|
"dev": "vite",
|
|
21
25
|
"build": "tsc -b && vite build",
|
|
22
26
|
"lint": "eslint .",
|
|
27
|
+
"lintFix": "eslint . --fix",
|
|
23
28
|
"preview": "vite preview",
|
|
24
29
|
"prepublishOnly": "npm run build"
|
|
25
30
|
},
|
|
26
31
|
"peerDependencies": {
|
|
27
|
-
"react": "^19.
|
|
28
|
-
"react-dom": "^19.
|
|
32
|
+
"react": "^19.2.3",
|
|
33
|
+
"react-dom": "^19.2.3"
|
|
29
34
|
},
|
|
30
35
|
"devDependencies": {
|
|
31
36
|
"@eslint/js": "^9.33.0",
|
|
32
37
|
"@microsoft/api-extractor": "^7.52.11",
|
|
38
|
+
"@stylistic/eslint-plugin": "^5.7.1",
|
|
33
39
|
"@types/node": "^24.2.1",
|
|
34
|
-
"@types/react": "^19.
|
|
35
|
-
"@types/react-dom": "^19.
|
|
40
|
+
"@types/react": "^19.2.5",
|
|
41
|
+
"@types/react-dom": "^19.2.3",
|
|
36
42
|
"@vitejs/plugin-react": "^5.0.0",
|
|
37
|
-
"
|
|
38
|
-
"eslint
|
|
39
|
-
"eslint-plugin-react-
|
|
43
|
+
"classix": "^2.2.6",
|
|
44
|
+
"eslint": "^9.39.1",
|
|
45
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
46
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
40
47
|
"globals": "^16.3.0",
|
|
41
|
-
"react": "^19.
|
|
42
|
-
"react-dom": "^19.
|
|
48
|
+
"react": "^19.2.3",
|
|
49
|
+
"react-dom": "^19.2.3",
|
|
43
50
|
"sass-embedded": "^1.90.0",
|
|
44
51
|
"typescript": "~5.8.3",
|
|
45
52
|
"typescript-eslint": "^8.39.1",
|
package/dist/index-Dnbs5lXl.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { jsx as s, jsxs as y } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as d, useContext as v, useReducer as _, lazy as p, useMemo as $, useRef as C } from "react";
|
|
3
|
-
const n = {
|
|
4
|
-
show: "show",
|
|
5
|
-
hide: "hide",
|
|
6
|
-
showButton: "showButton",
|
|
7
|
-
hideButton: "hideButton",
|
|
8
|
-
canplay: "canplay"
|
|
9
|
-
}, P = {
|
|
10
|
-
showButton: !1,
|
|
11
|
-
showPreview: !0,
|
|
12
|
-
canplay: !1
|
|
13
|
-
}, k = (e, t) => {
|
|
14
|
-
const { type: r } = t;
|
|
15
|
-
switch (r) {
|
|
16
|
-
case n.show:
|
|
17
|
-
return { ...e, showButton: !0, showPreview: !0 };
|
|
18
|
-
case n.hide:
|
|
19
|
-
return { ...e, showButton: !1, showPreview: !1 };
|
|
20
|
-
case n.showButton:
|
|
21
|
-
return { ...e, showButton: !0 };
|
|
22
|
-
case n.hideButton:
|
|
23
|
-
return { ...e, showButton: !1 };
|
|
24
|
-
case n.canplay:
|
|
25
|
-
return { ...e, canplay: !0, showButton: !0 };
|
|
26
|
-
default:
|
|
27
|
-
return e;
|
|
28
|
-
}
|
|
29
|
-
}, m = d(P), b = d(() => {
|
|
30
|
-
}), N = ({ children: e }) => {
|
|
31
|
-
const [t, r] = _(k, P);
|
|
32
|
-
return /* @__PURE__ */ s(m.Provider, { value: t, children: /* @__PURE__ */ s(b.Provider, { value: r, children: e }) });
|
|
33
|
-
}, E = () => {
|
|
34
|
-
const e = v(m);
|
|
35
|
-
if (e === void 0)
|
|
36
|
-
throw new Error("usePlayerState нужно использовать внутри PlayerProvider");
|
|
37
|
-
return e;
|
|
38
|
-
}, R = () => {
|
|
39
|
-
const e = v(b);
|
|
40
|
-
if (e === void 0)
|
|
41
|
-
throw new Error("usePlayerDispatch нужно использовать внутри PlayerProvider");
|
|
42
|
-
return e;
|
|
43
|
-
}, S = "idmrp-button-play", T = {
|
|
44
|
-
parent: S
|
|
45
|
-
}, g = ({
|
|
46
|
-
className: e,
|
|
47
|
-
onClick: t
|
|
48
|
-
}) => /* @__PURE__ */ s(
|
|
49
|
-
"button",
|
|
50
|
-
{
|
|
51
|
-
className: [T.parent, e].join(" "),
|
|
52
|
-
type: "button",
|
|
53
|
-
onClick: t
|
|
54
|
-
}
|
|
55
|
-
), c = "idmrp-player-preview", u = {
|
|
56
|
-
parent: c,
|
|
57
|
-
wrapper: `${c}__wrapper`,
|
|
58
|
-
button: `${c}__button`,
|
|
59
|
-
preview: `${c}__preview`,
|
|
60
|
-
player: `${c}__player`
|
|
61
|
-
}, j = ({
|
|
62
|
-
className: e,
|
|
63
|
-
preview: t,
|
|
64
|
-
onPlay: r,
|
|
65
|
-
children: a
|
|
66
|
-
}) => {
|
|
67
|
-
const { showButton: i, showPreview: l, canplay: f } = E(), B = R(), x = () => {
|
|
68
|
-
f && (B({
|
|
69
|
-
type: n.hide
|
|
70
|
-
}), r && r());
|
|
71
|
-
};
|
|
72
|
-
return /* @__PURE__ */ y("div", { className: [u.parent, e].join(" "), children: [
|
|
73
|
-
(i || t && l) && /* @__PURE__ */ y(
|
|
74
|
-
"div",
|
|
75
|
-
{
|
|
76
|
-
className: u.wrapper,
|
|
77
|
-
onClick: x,
|
|
78
|
-
children: [
|
|
79
|
-
i && /* @__PURE__ */ s(
|
|
80
|
-
g,
|
|
81
|
-
{
|
|
82
|
-
className: u.button
|
|
83
|
-
}
|
|
84
|
-
),
|
|
85
|
-
t && l && /* @__PURE__ */ s("img", { className: u.preview, src: t.src, alt: t.alt ?? "preview" })
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
),
|
|
89
|
-
/* @__PURE__ */ s("div", { className: u.player, children: a })
|
|
90
|
-
] });
|
|
91
|
-
}, o = {
|
|
92
|
-
youtube: "youtube",
|
|
93
|
-
rutube: "rutube",
|
|
94
|
-
video: "video",
|
|
95
|
-
vk: "vk"
|
|
96
|
-
}, D = {
|
|
97
|
-
[o.youtube]: p(async () => await import("./index-1pgUfxhC.js")),
|
|
98
|
-
[o.rutube]: p(async () => await import("./index-DsBO-KZz.js")),
|
|
99
|
-
[o.video]: p(async () => await import("./index-Cu3vJcLM.js")),
|
|
100
|
-
[o.vk]: p(async () => await import("./index-BKNjwSFg.js"))
|
|
101
|
-
}, V = (e) => {
|
|
102
|
-
const t = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/, r = /^(?:https?:\/\/)?(?:rutu\.be\/|rutube\.ru(\/play\/))/, a = /^(?:https?:\/\/)?(?:www\.|m\.)?(?:vk\.com|vkvideo\.ru)\/.+$/;
|
|
103
|
-
return r.test(e) ? o.rutube : t.test(e) ? o.youtube : a.test(e) ? o.vk : o.video;
|
|
104
|
-
}, w = "idmrp-player", h = {
|
|
105
|
-
parent: w,
|
|
106
|
-
player: `${w}__player`
|
|
107
|
-
}, A = ({
|
|
108
|
-
url: e,
|
|
109
|
-
preview: t
|
|
110
|
-
}) => {
|
|
111
|
-
const r = $(() => {
|
|
112
|
-
const l = V(e);
|
|
113
|
-
return D[l];
|
|
114
|
-
}, [e]), a = C(null), i = () => {
|
|
115
|
-
a.current && a.current.play();
|
|
116
|
-
};
|
|
117
|
-
return /* @__PURE__ */ s(
|
|
118
|
-
j,
|
|
119
|
-
{
|
|
120
|
-
className: h.parent,
|
|
121
|
-
preview: t,
|
|
122
|
-
onPlay: i,
|
|
123
|
-
children: /* @__PURE__ */ s(
|
|
124
|
-
r,
|
|
125
|
-
{
|
|
126
|
-
className: h.player,
|
|
127
|
-
ref: a,
|
|
128
|
-
url: e
|
|
129
|
-
}
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
}, Y = (e) => /* @__PURE__ */ s(N, { children: /* @__PURE__ */ s(A, { ...e }) });
|
|
134
|
-
export {
|
|
135
|
-
n as P,
|
|
136
|
-
Y as a,
|
|
137
|
-
R as u
|
|
138
|
-
};
|