@barabel324/react-player 0.0.0 → 0.0.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.
- package/README.md +26 -68
- package/dist/index-B4aQ3fZe.js +44 -0
- package/dist/index-CEYCN7W2.js +40 -0
- package/dist/index-CtwCLqA8.js +76 -0
- package/dist/index-DY6LmZAq.js +60 -0
- package/dist/{index-COqINEuJ.js → index-DqNJQSqH.js} +40 -38
- package/dist/react-player.css +1 -1
- package/dist/react-player.d.ts +4 -0
- package/dist/react-player.js +1 -1
- package/package.json +1 -2
- package/dist/index-0qY1-A4q.js +0 -74
- package/dist/index-3eLEuMe8.js +0 -41
- package/dist/index-C-0pNFYJ.js +0 -61
- package/dist/index-CSgcS1fk.js +0 -47
package/README.md
CHANGED
|
@@ -1,69 +1,27 @@
|
|
|
1
|
-
# React
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
28
|
-
|
|
29
|
-
// Other configs...
|
|
30
|
-
],
|
|
31
|
-
languageOptions: {
|
|
32
|
-
parserOptions: {
|
|
33
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
34
|
-
tsconfigRootDir: import.meta.dirname,
|
|
35
|
-
},
|
|
36
|
-
// other options...
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
])
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
// eslint.config.js
|
|
46
|
-
import reactX from 'eslint-plugin-react-x'
|
|
47
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
48
|
-
|
|
49
|
-
export default tseslint.config([
|
|
50
|
-
globalIgnores(['dist']),
|
|
51
|
-
{
|
|
52
|
-
files: ['**/*.{ts,tsx}'],
|
|
53
|
-
extends: [
|
|
54
|
-
// Other configs...
|
|
55
|
-
// Enable lint rules for React
|
|
56
|
-
reactX.configs['recommended-typescript'],
|
|
57
|
-
// Enable lint rules for React DOM
|
|
58
|
-
reactDom.configs.recommended,
|
|
59
|
-
],
|
|
60
|
-
languageOptions: {
|
|
61
|
-
parserOptions: {
|
|
62
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
63
|
-
tsconfigRootDir: import.meta.dirname,
|
|
64
|
-
},
|
|
65
|
-
// other options...
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
])
|
|
1
|
+
# React Player
|
|
2
|
+
|
|
3
|
+
`React Player` — компонент для воспроизведения видео.
|
|
4
|
+
Он анализирует переданную ссылку и автоматически выбирает подходящий плеер.
|
|
5
|
+
Если ссылка не поддерживается, используется стандартный HTML-тег `<video>`.
|
|
6
|
+
|
|
7
|
+
## Поддерживаемые плееры
|
|
8
|
+
- **YouTube** — ссылка берётся через кнопку «Поделиться»;
|
|
9
|
+
- **RuTube** — ссылка берётся из атрибута `src` тега `<iframe>`, доступного в коде вставки при выборе «Поделиться»;
|
|
10
|
+
- **VK** — используется прямая ссылка на видео.
|
|
11
|
+
|
|
12
|
+
## Превью
|
|
13
|
+
Можно указать изображение-превью, которое будет отображаться до загрузки плеера.
|
|
14
|
+
|
|
15
|
+
## Пропсы
|
|
16
|
+
- preview - ссылка на изображение, необязательно
|
|
17
|
+
- url - ссылка на видео, обязательный
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
type TPlayer = {
|
|
21
|
+
preview?: {
|
|
22
|
+
src: string;
|
|
23
|
+
alt: string;
|
|
24
|
+
};
|
|
25
|
+
url: string;
|
|
26
|
+
}
|
|
69
27
|
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { u as d, P as t } from "./index-DqNJQSqH.js";
|
|
3
|
+
import { useRef as i, useImperativeHandle as P } from "react";
|
|
4
|
+
const v = ({
|
|
5
|
+
className: n,
|
|
6
|
+
ref: r,
|
|
7
|
+
url: s
|
|
8
|
+
}) => {
|
|
9
|
+
const e = i(null), o = d(), a = () => {
|
|
10
|
+
o({
|
|
11
|
+
type: t.hideButton
|
|
12
|
+
});
|
|
13
|
+
}, l = () => {
|
|
14
|
+
o({
|
|
15
|
+
type: t.showButton
|
|
16
|
+
});
|
|
17
|
+
}, c = () => {
|
|
18
|
+
o({
|
|
19
|
+
type: t.canplay
|
|
20
|
+
});
|
|
21
|
+
}, u = () => {
|
|
22
|
+
e.current && (a(), e.current.play().catch((p) => {
|
|
23
|
+
console.error(p);
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
return P(r, () => ({
|
|
27
|
+
play: u
|
|
28
|
+
})), /* @__PURE__ */ y(
|
|
29
|
+
"video",
|
|
30
|
+
{
|
|
31
|
+
className: n,
|
|
32
|
+
ref: e,
|
|
33
|
+
controls: !0,
|
|
34
|
+
src: s,
|
|
35
|
+
preload: "auto",
|
|
36
|
+
onPlay: a,
|
|
37
|
+
onPause: l,
|
|
38
|
+
onCanPlay: c
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
v as default
|
|
44
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { u as p } from "./index-DqNJQSqH.js";
|
|
3
|
+
import { useRef as c, useImperativeHandle as f, useEffect as l } from "react";
|
|
4
|
+
const w = ({
|
|
5
|
+
className: t,
|
|
6
|
+
ref: a,
|
|
7
|
+
url: s
|
|
8
|
+
}) => {
|
|
9
|
+
const e = c(null), n = p(), o = () => {
|
|
10
|
+
e.current && e.current.contentWindow?.postMessage(JSON.stringify({
|
|
11
|
+
type: "player:play",
|
|
12
|
+
data: {}
|
|
13
|
+
}), "*");
|
|
14
|
+
};
|
|
15
|
+
return f(a, () => ({
|
|
16
|
+
play: o
|
|
17
|
+
})), l(() => {
|
|
18
|
+
const r = (u) => {
|
|
19
|
+
if (!e.current) return;
|
|
20
|
+
JSON.parse(u.data).type === "player:ready" && n({ type: "canplay" });
|
|
21
|
+
};
|
|
22
|
+
return window.addEventListener("message", r), () => {
|
|
23
|
+
window.removeEventListener("message", r);
|
|
24
|
+
};
|
|
25
|
+
}, []), /* @__PURE__ */ i(
|
|
26
|
+
"iframe",
|
|
27
|
+
{
|
|
28
|
+
className: t,
|
|
29
|
+
ref: e,
|
|
30
|
+
width: "100%",
|
|
31
|
+
height: "100%",
|
|
32
|
+
src: s,
|
|
33
|
+
allowFullScreen: !0,
|
|
34
|
+
frameBorder: "0"
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
w as default
|
|
40
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as a, useImperativeHandle as l, useEffect as u } from "react";
|
|
3
|
+
import { u as p } from "./index-DqNJQSqH.js";
|
|
4
|
+
const m = async () => new Promise((t, n) => {
|
|
5
|
+
if (window.VK?.VideoPlayer) {
|
|
6
|
+
t(window.VK);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const o = "https://vk.com/js/api/videoplayer.js";
|
|
10
|
+
if (Array.from(document.scripts).find(
|
|
11
|
+
(r) => r.src === o
|
|
12
|
+
)) {
|
|
13
|
+
const r = setInterval(() => {
|
|
14
|
+
window.VK?.VideoPlayer && (clearInterval(r), t(window.VK));
|
|
15
|
+
}, 300);
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
clearInterval(r), n(new Error("VK Video API timeout"));
|
|
18
|
+
}, 15e3);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const e = document.createElement("script");
|
|
22
|
+
e.src = o, e.async = !0, e.onload = () => {
|
|
23
|
+
const r = () => {
|
|
24
|
+
window.VK?.VideoPlayer ? t(window.VK) : setTimeout(r, 300);
|
|
25
|
+
};
|
|
26
|
+
r();
|
|
27
|
+
}, e.onerror = () => {
|
|
28
|
+
n(new Error("Failed to load VK Video API"));
|
|
29
|
+
};
|
|
30
|
+
const c = document.getElementsByTagName("script")[0];
|
|
31
|
+
c.parentNode?.insertBefore(e, c);
|
|
32
|
+
}), f = (t) => {
|
|
33
|
+
const n = /^https:\/\/vkvideo\.ru\/video(-\d+)_(\d+)$/, o = t.match(n);
|
|
34
|
+
if (!o)
|
|
35
|
+
throw new Error(`Некорректный формат ссылки ${t}`);
|
|
36
|
+
const i = o[1], e = o[2];
|
|
37
|
+
return `https://vkvideo.ru/video_ext.php?oid=${i}&id=${e}`;
|
|
38
|
+
}, h = ({
|
|
39
|
+
className: t,
|
|
40
|
+
ref: n,
|
|
41
|
+
url: o
|
|
42
|
+
}) => {
|
|
43
|
+
const i = a(null), e = a(null), c = p(), r = () => {
|
|
44
|
+
e.current && e.current.play?.();
|
|
45
|
+
};
|
|
46
|
+
return l(n, () => ({
|
|
47
|
+
play: r
|
|
48
|
+
})), u(() => {
|
|
49
|
+
if (i.current)
|
|
50
|
+
return m().then((s) => {
|
|
51
|
+
e.current = s.VideoPlayer(i.current), c({ type: "canplay" });
|
|
52
|
+
}).catch((s) => {
|
|
53
|
+
console.error(s);
|
|
54
|
+
}), () => {
|
|
55
|
+
e.current && e.current.destroy();
|
|
56
|
+
};
|
|
57
|
+
}, []), /* @__PURE__ */ d(
|
|
58
|
+
"iframe",
|
|
59
|
+
{
|
|
60
|
+
className: t,
|
|
61
|
+
width: "100%",
|
|
62
|
+
height: "100%",
|
|
63
|
+
ref: i,
|
|
64
|
+
src: `${f(o)}&js_api=1`,
|
|
65
|
+
allow: "autoplay; fullscreen; accelerometer; gyroscope; picture-in-picture; encrypted-media",
|
|
66
|
+
"data-testid": "embed-iframe",
|
|
67
|
+
frameBorder: "0",
|
|
68
|
+
scrolling: "no",
|
|
69
|
+
title: "player",
|
|
70
|
+
allowFullScreen: !0
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
h as default
|
|
76
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as s, useImperativeHandle as p, useEffect as y } from "react";
|
|
3
|
+
import { u as f } from "./index-DqNJQSqH.js";
|
|
4
|
+
const m = (t) => {
|
|
5
|
+
const n = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/, o = t.match(n);
|
|
6
|
+
return o && o[7].length === 11 ? o[7] : "";
|
|
7
|
+
}, w = async () => await new Promise((t) => {
|
|
8
|
+
if (window.YT)
|
|
9
|
+
t(window.YT);
|
|
10
|
+
else {
|
|
11
|
+
const n = "https://www.youtube.com/iframe_api", r = Array.from(document.querySelectorAll("script")).find((e) => e.src === n) ?? document.createElement("script");
|
|
12
|
+
if (r.src) {
|
|
13
|
+
const e = setInterval(() => {
|
|
14
|
+
window.YT?.PlayerState && (t(window.YT), clearInterval(e));
|
|
15
|
+
}, 300);
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
clearInterval(e);
|
|
18
|
+
}, 6e4);
|
|
19
|
+
} else {
|
|
20
|
+
r.src = n;
|
|
21
|
+
const e = document.getElementsByTagName("script")[0];
|
|
22
|
+
e.parentNode && e.parentNode.insertBefore(r, e), window.onYouTubeIframeAPIReady = () => {
|
|
23
|
+
t(window.YT);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}), Y = ({
|
|
28
|
+
className: t,
|
|
29
|
+
ref: n,
|
|
30
|
+
url: o
|
|
31
|
+
}) => {
|
|
32
|
+
const r = s(null), e = s(null), i = f(), u = (a) => {
|
|
33
|
+
e.current = a.target, i({
|
|
34
|
+
type: "canplay"
|
|
35
|
+
});
|
|
36
|
+
}, d = () => {
|
|
37
|
+
e.current?.playVideo && e.current.playVideo();
|
|
38
|
+
};
|
|
39
|
+
return p(n, () => ({
|
|
40
|
+
play: d
|
|
41
|
+
})), y(() => {
|
|
42
|
+
if (!r.current) return;
|
|
43
|
+
const a = m(o);
|
|
44
|
+
w().then((c) => {
|
|
45
|
+
new c.Player(r.current, {
|
|
46
|
+
width: "100%",
|
|
47
|
+
height: "100%",
|
|
48
|
+
videoId: a,
|
|
49
|
+
events: {
|
|
50
|
+
onReady: u
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}).catch((c) => {
|
|
54
|
+
console.error(c);
|
|
55
|
+
});
|
|
56
|
+
}, []), /* @__PURE__ */ l("div", { className: t, ref: r });
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
Y as default
|
|
60
|
+
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { jsx as s, jsxs as y } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as
|
|
3
|
-
import
|
|
2
|
+
import { createContext as d, useContext as v, useReducer as $, lazy as p, useMemo as C, useRef as k } from "react";
|
|
3
|
+
import m from "classix";
|
|
4
4
|
const n = {
|
|
5
5
|
show: "show",
|
|
6
6
|
hide: "hide",
|
|
7
7
|
showButton: "showButton",
|
|
8
8
|
hideButton: "hideButton",
|
|
9
9
|
canplay: "canplay"
|
|
10
|
-
},
|
|
10
|
+
}, P = {
|
|
11
11
|
showButton: !1,
|
|
12
12
|
showPreview: !0,
|
|
13
13
|
canplay: !1
|
|
14
|
-
},
|
|
14
|
+
}, N = (e, t) => {
|
|
15
15
|
const { type: r } = t;
|
|
16
16
|
switch (r) {
|
|
17
17
|
case n.show:
|
|
@@ -27,58 +27,58 @@ const n = {
|
|
|
27
27
|
default:
|
|
28
28
|
return e;
|
|
29
29
|
}
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
const [t, r] =
|
|
33
|
-
return /* @__PURE__ */ s(
|
|
34
|
-
},
|
|
35
|
-
const e =
|
|
30
|
+
}, b = d(P), f = d(() => {
|
|
31
|
+
}), E = ({ children: e }) => {
|
|
32
|
+
const [t, r] = $(N, P);
|
|
33
|
+
return /* @__PURE__ */ s(b.Provider, { value: t, children: /* @__PURE__ */ s(f.Provider, { value: r, children: e }) });
|
|
34
|
+
}, R = () => {
|
|
35
|
+
const e = v(b);
|
|
36
36
|
if (e === void 0)
|
|
37
37
|
throw new Error("usePlayerState нужно использовать внутри PlayerProvider");
|
|
38
38
|
return e;
|
|
39
|
-
},
|
|
40
|
-
const e =
|
|
39
|
+
}, S = () => {
|
|
40
|
+
const e = v(f);
|
|
41
41
|
if (e === void 0)
|
|
42
42
|
throw new Error("usePlayerDispatch нужно использовать внутри PlayerProvider");
|
|
43
43
|
return e;
|
|
44
|
-
},
|
|
45
|
-
parent:
|
|
46
|
-
},
|
|
44
|
+
}, T = "idmrp-button-play", g = {
|
|
45
|
+
parent: T
|
|
46
|
+
}, D = ({
|
|
47
47
|
className: e,
|
|
48
48
|
onClick: t
|
|
49
49
|
}) => /* @__PURE__ */ s(
|
|
50
50
|
"button",
|
|
51
51
|
{
|
|
52
|
-
className:
|
|
52
|
+
className: m(g.parent, e),
|
|
53
53
|
type: "button",
|
|
54
54
|
onClick: t
|
|
55
55
|
}
|
|
56
|
-
), c = "player-preview", u = {
|
|
56
|
+
), c = "idmrp-player-preview", u = {
|
|
57
57
|
parent: c,
|
|
58
58
|
wrapper: `${c}__wrapper`,
|
|
59
59
|
button: `${c}__button`,
|
|
60
60
|
preview: `${c}__preview`,
|
|
61
61
|
player: `${c}__player`
|
|
62
|
-
},
|
|
62
|
+
}, V = ({
|
|
63
63
|
className: e,
|
|
64
64
|
preview: t,
|
|
65
65
|
onPlay: r,
|
|
66
66
|
children: a
|
|
67
67
|
}) => {
|
|
68
|
-
const { showButton: i, showPreview: l, canplay:
|
|
69
|
-
|
|
68
|
+
const { showButton: i, showPreview: l, canplay: B } = R(), x = S(), _ = () => {
|
|
69
|
+
B && (x({
|
|
70
70
|
type: n.hide
|
|
71
71
|
}), r && r());
|
|
72
72
|
};
|
|
73
|
-
return /* @__PURE__ */ y("div", { className:
|
|
73
|
+
return /* @__PURE__ */ y("div", { className: m(u.parent, e), children: [
|
|
74
74
|
(i || t && l) && /* @__PURE__ */ y(
|
|
75
75
|
"div",
|
|
76
76
|
{
|
|
77
77
|
className: u.wrapper,
|
|
78
|
-
onClick:
|
|
78
|
+
onClick: _,
|
|
79
79
|
children: [
|
|
80
80
|
i && /* @__PURE__ */ s(
|
|
81
|
-
|
|
81
|
+
D,
|
|
82
82
|
{
|
|
83
83
|
className: u.button
|
|
84
84
|
}
|
|
@@ -94,44 +94,46 @@ const n = {
|
|
|
94
94
|
rutube: "rutube",
|
|
95
95
|
video: "video",
|
|
96
96
|
vk: "vk"
|
|
97
|
-
},
|
|
98
|
-
[o.youtube]: p(async () => await import("./index-
|
|
99
|
-
[o.rutube]: p(async () => await import("./index-
|
|
100
|
-
[o.video]: p(async () => await import("./index-
|
|
101
|
-
[o.vk]: p(async () => await import("./index-
|
|
102
|
-
},
|
|
97
|
+
}, j = {
|
|
98
|
+
[o.youtube]: p(async () => await import("./index-DY6LmZAq.js")),
|
|
99
|
+
[o.rutube]: p(async () => await import("./index-CEYCN7W2.js")),
|
|
100
|
+
[o.video]: p(async () => await import("./index-B4aQ3fZe.js")),
|
|
101
|
+
[o.vk]: p(async () => await import("./index-CtwCLqA8.js"))
|
|
102
|
+
}, A = (e) => {
|
|
103
103
|
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)\/.+$/;
|
|
104
104
|
return r.test(e) ? o.rutube : t.test(e) ? o.youtube : a.test(e) ? o.vk : o.video;
|
|
105
|
-
},
|
|
106
|
-
parent:
|
|
105
|
+
}, w = "idmrp-player", h = {
|
|
106
|
+
parent: w,
|
|
107
|
+
player: `${w}__player`
|
|
107
108
|
}, L = ({
|
|
108
109
|
url: e,
|
|
109
110
|
preview: t
|
|
110
111
|
}) => {
|
|
111
112
|
const r = C(() => {
|
|
112
|
-
const l =
|
|
113
|
-
return
|
|
114
|
-
}, [e]), a =
|
|
113
|
+
const l = A(e);
|
|
114
|
+
return j[l];
|
|
115
|
+
}, [e]), a = k(null), i = () => {
|
|
115
116
|
a.current && a.current.play();
|
|
116
117
|
};
|
|
117
118
|
return /* @__PURE__ */ s(
|
|
118
|
-
|
|
119
|
+
V,
|
|
119
120
|
{
|
|
120
|
-
className:
|
|
121
|
+
className: h.parent,
|
|
121
122
|
preview: t,
|
|
122
123
|
onPlay: i,
|
|
123
124
|
children: /* @__PURE__ */ s(
|
|
124
125
|
r,
|
|
125
126
|
{
|
|
127
|
+
className: h.player,
|
|
126
128
|
ref: a,
|
|
127
129
|
url: e
|
|
128
130
|
}
|
|
129
131
|
)
|
|
130
132
|
}
|
|
131
133
|
);
|
|
132
|
-
}, I = (e) => /* @__PURE__ */ s(
|
|
134
|
+
}, I = (e) => /* @__PURE__ */ s(E, { children: /* @__PURE__ */ s(L, { ...e }) });
|
|
133
135
|
export {
|
|
134
136
|
n as P,
|
|
135
137
|
I as a,
|
|
136
|
-
|
|
138
|
+
S as u
|
|
137
139
|
};
|
package/dist/react-player.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.button-play{--button-play-size: 3.375rem;position:relative;width:var(--button-play-size);min-width:var(--button-play-size);height:var(--button-play-size);background-color:var(--
|
|
1
|
+
.idmrp-button-play{--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%}.idmrp-button-play: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%)}.idmrp-player-preview{position:relative;width:100%;height:100%;object-fit:cover}.idmrp-player-preview .idmrp-player-preview__wrapper{position:absolute;inset:0;cursor:pointer}.idmrp-player-preview .idmrp-player-preview__button{z-index:2;position:absolute;top:50%;left:50%;transform:translate(-50%) translateY(-50%)}.idmrp-player-preview .idmrp-player-preview__preview{z-index:1;position:absolute;top:0;left:0;width:100%;height:100%;object-fit:cover}.idmrp-player-preview .idmrp-player-preview__player{width:100%;height:100%}.idmrp-player .idmrp-player__player{display:block;width:100%;height:100%;object-fit:cover;object-position:center}
|
package/dist/react-player.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ declare type FCClass<P = object> = React.FC<P & React.PropsWithChildren & {
|
|
|
7
7
|
export declare const Player: FCClass<TPlayer>;
|
|
8
8
|
|
|
9
9
|
declare type TPlayer = {
|
|
10
|
+
/** Превью для видео */
|
|
10
11
|
preview?: TPlayerPreview['preview'];
|
|
12
|
+
/** Ссылка на видео */
|
|
11
13
|
url: TPlayerBase['url'];
|
|
12
14
|
};
|
|
13
15
|
|
|
@@ -22,7 +24,9 @@ declare type TPlayerBaseMethods = {
|
|
|
22
24
|
|
|
23
25
|
declare type TPlayerPreview = {
|
|
24
26
|
preview?: {
|
|
27
|
+
/** Адрес изображения */
|
|
25
28
|
src: string;
|
|
29
|
+
/** Альт изображения */
|
|
26
30
|
alt: string;
|
|
27
31
|
};
|
|
28
32
|
onPlay?: () => void;
|
package/dist/react-player.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barabel324/react-player",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/react-player.js",
|
|
6
6
|
"exports": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"classix": "^2.2.2",
|
|
23
22
|
"react": "^19.1.1",
|
|
24
23
|
"react-dom": "^19.1.1"
|
|
25
24
|
},
|
package/dist/index-0qY1-A4q.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as s, useImperativeHandle as d, useEffect as l } from "react";
|
|
3
|
-
import { u } from "./index-COqINEuJ.js";
|
|
4
|
-
const p = async () => new Promise((o, i) => {
|
|
5
|
-
if (window.VK?.VideoPlayer) {
|
|
6
|
-
o(window.VK);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const r = "https://vk.com/js/api/videoplayer.js";
|
|
10
|
-
if (Array.from(document.scripts).find(
|
|
11
|
-
(e) => e.src === r
|
|
12
|
-
)) {
|
|
13
|
-
const e = setInterval(() => {
|
|
14
|
-
window.VK?.VideoPlayer && (clearInterval(e), o(window.VK));
|
|
15
|
-
}, 300);
|
|
16
|
-
setTimeout(() => {
|
|
17
|
-
clearInterval(e), i(new Error("VK Video API timeout"));
|
|
18
|
-
}, 15e3);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const t = document.createElement("script");
|
|
22
|
-
t.src = r, t.async = !0, t.onload = () => {
|
|
23
|
-
const e = () => {
|
|
24
|
-
window.VK?.VideoPlayer ? o(window.VK) : setTimeout(e, 300);
|
|
25
|
-
};
|
|
26
|
-
e();
|
|
27
|
-
}, t.onerror = () => {
|
|
28
|
-
i(new Error("Failed to load VK Video API"));
|
|
29
|
-
};
|
|
30
|
-
const c = document.getElementsByTagName("script")[0];
|
|
31
|
-
c.parentNode?.insertBefore(t, c);
|
|
32
|
-
}), m = (o) => {
|
|
33
|
-
const i = /^https:\/\/vkvideo\.ru\/video(-\d+)_(\d+)$/, r = o.match(i);
|
|
34
|
-
if (!r)
|
|
35
|
-
throw new Error(`Некорректный формат ссылки ${o}`);
|
|
36
|
-
const n = r[1], t = r[2];
|
|
37
|
-
return `https://vkvideo.ru/video_ext.php?oid=${n}&id=${t}`;
|
|
38
|
-
}, V = ({
|
|
39
|
-
ref: o,
|
|
40
|
-
url: i
|
|
41
|
-
}) => {
|
|
42
|
-
const r = s(null), n = s(null), t = u(), c = () => {
|
|
43
|
-
n.current && n.current.play?.();
|
|
44
|
-
};
|
|
45
|
-
return d(o, () => ({
|
|
46
|
-
play: c
|
|
47
|
-
})), l(() => {
|
|
48
|
-
if (r.current)
|
|
49
|
-
return p().then((e) => {
|
|
50
|
-
n.current = e.VideoPlayer(r.current), t({ type: "canplay" });
|
|
51
|
-
}).catch((e) => {
|
|
52
|
-
console.error(e);
|
|
53
|
-
}), () => {
|
|
54
|
-
n.current && n.current.destroy();
|
|
55
|
-
};
|
|
56
|
-
}, []), /* @__PURE__ */ a(
|
|
57
|
-
"iframe",
|
|
58
|
-
{
|
|
59
|
-
width: "100%",
|
|
60
|
-
height: "100%",
|
|
61
|
-
ref: r,
|
|
62
|
-
src: `${m(i)}&js_api=1`,
|
|
63
|
-
allow: "autoplay; fullscreen; accelerometer; gyroscope; picture-in-picture; encrypted-media",
|
|
64
|
-
"data-testid": "embed-iframe",
|
|
65
|
-
frameBorder: "0",
|
|
66
|
-
scrolling: "no",
|
|
67
|
-
title: "player",
|
|
68
|
-
allowFullScreen: !0
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
export {
|
|
73
|
-
V as default
|
|
74
|
-
};
|
package/dist/index-3eLEuMe8.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
-
import { u as p } from "./index-COqINEuJ.js";
|
|
3
|
-
import { useRef as c, useImperativeHandle as i, useEffect as l } from "react";
|
|
4
|
-
const f = "player-rutube", m = {
|
|
5
|
-
parent: f
|
|
6
|
-
}, h = ({
|
|
7
|
-
ref: t,
|
|
8
|
-
url: a
|
|
9
|
-
}) => {
|
|
10
|
-
const e = c(null), s = p(), n = () => {
|
|
11
|
-
e.current && e.current.contentWindow?.postMessage(JSON.stringify({
|
|
12
|
-
type: "player:play",
|
|
13
|
-
data: {}
|
|
14
|
-
}), "*");
|
|
15
|
-
};
|
|
16
|
-
return i(t, () => ({
|
|
17
|
-
play: n
|
|
18
|
-
})), l(() => {
|
|
19
|
-
const r = (o) => {
|
|
20
|
-
if (!e.current) return;
|
|
21
|
-
JSON.parse(o.data).type === "player:ready" && s({ type: "canplay" });
|
|
22
|
-
};
|
|
23
|
-
return window.addEventListener("message", r), () => {
|
|
24
|
-
window.removeEventListener("message", r);
|
|
25
|
-
};
|
|
26
|
-
}, []), /* @__PURE__ */ u(
|
|
27
|
-
"iframe",
|
|
28
|
-
{
|
|
29
|
-
ref: e,
|
|
30
|
-
width: "100%",
|
|
31
|
-
height: "100%",
|
|
32
|
-
src: a,
|
|
33
|
-
allowFullScreen: !0,
|
|
34
|
-
frameBorder: "0",
|
|
35
|
-
className: m.parent
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
h as default
|
|
41
|
-
};
|
package/dist/index-C-0pNFYJ.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as s, useImperativeHandle as d, useEffect as p } from "react";
|
|
3
|
-
import { u as y } from "./index-COqINEuJ.js";
|
|
4
|
-
const m = (r) => {
|
|
5
|
-
const a = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/, t = r.match(a);
|
|
6
|
-
return t && t[7].length === 11 ? t[7] : "";
|
|
7
|
-
}, f = async () => await new Promise((r) => {
|
|
8
|
-
if (window.YT)
|
|
9
|
-
r(window.YT);
|
|
10
|
-
else {
|
|
11
|
-
const a = "https://www.youtube.com/iframe_api", n = Array.from(document.querySelectorAll("script")).find((e) => e.src === a) ?? document.createElement("script");
|
|
12
|
-
if (n.src) {
|
|
13
|
-
const e = setInterval(() => {
|
|
14
|
-
window.YT?.PlayerState && (r(window.YT), clearInterval(e));
|
|
15
|
-
}, 300);
|
|
16
|
-
setTimeout(() => {
|
|
17
|
-
clearInterval(e);
|
|
18
|
-
}, 6e4);
|
|
19
|
-
} else {
|
|
20
|
-
n.src = a;
|
|
21
|
-
const e = document.getElementsByTagName("script")[0];
|
|
22
|
-
e.parentNode && e.parentNode.insertBefore(n, e), window.onYouTubeIframeAPIReady = () => {
|
|
23
|
-
r(window.YT);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}), w = "player-youtube", h = {
|
|
28
|
-
parent: w
|
|
29
|
-
}, b = ({
|
|
30
|
-
ref: r,
|
|
31
|
-
url: a
|
|
32
|
-
}) => {
|
|
33
|
-
const t = s(null), n = s(null), e = y(), i = (o) => {
|
|
34
|
-
n.current = o.target, e({
|
|
35
|
-
type: "canplay"
|
|
36
|
-
});
|
|
37
|
-
}, u = () => {
|
|
38
|
-
n.current?.playVideo && n.current.playVideo();
|
|
39
|
-
};
|
|
40
|
-
return d(r, () => ({
|
|
41
|
-
play: u
|
|
42
|
-
})), p(() => {
|
|
43
|
-
if (!t.current) return;
|
|
44
|
-
const o = m(a);
|
|
45
|
-
f().then((c) => {
|
|
46
|
-
new c.Player(t.current, {
|
|
47
|
-
width: "100%",
|
|
48
|
-
height: "100%",
|
|
49
|
-
videoId: o,
|
|
50
|
-
events: {
|
|
51
|
-
onReady: i
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}).catch((c) => {
|
|
55
|
-
console.error(c);
|
|
56
|
-
});
|
|
57
|
-
}, []), /* @__PURE__ */ l("div", { className: h.parent, ref: t });
|
|
58
|
-
};
|
|
59
|
-
export {
|
|
60
|
-
b as default
|
|
61
|
-
};
|
package/dist/index-CSgcS1fk.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
-
import { u as y, P as t } from "./index-COqINEuJ.js";
|
|
3
|
-
import d from "classix";
|
|
4
|
-
import { useRef as m, useImperativeHandle as P } from "react";
|
|
5
|
-
const f = "player-video", h = {
|
|
6
|
-
parent: f
|
|
7
|
-
}, A = ({
|
|
8
|
-
className: r,
|
|
9
|
-
ref: n,
|
|
10
|
-
url: s
|
|
11
|
-
}) => {
|
|
12
|
-
const e = m(null), a = y(), o = () => {
|
|
13
|
-
a({
|
|
14
|
-
type: t.hideButton
|
|
15
|
-
});
|
|
16
|
-
}, l = () => {
|
|
17
|
-
a({
|
|
18
|
-
type: t.showButton
|
|
19
|
-
});
|
|
20
|
-
}, c = () => {
|
|
21
|
-
a({
|
|
22
|
-
type: t.canplay
|
|
23
|
-
});
|
|
24
|
-
}, p = () => {
|
|
25
|
-
e.current && (o(), e.current.play().catch((u) => {
|
|
26
|
-
console.error(u);
|
|
27
|
-
}));
|
|
28
|
-
};
|
|
29
|
-
return P(n, () => ({
|
|
30
|
-
play: p
|
|
31
|
-
})), /* @__PURE__ */ i(
|
|
32
|
-
"video",
|
|
33
|
-
{
|
|
34
|
-
className: d(h.parent, r),
|
|
35
|
-
ref: e,
|
|
36
|
-
controls: !0,
|
|
37
|
-
src: s,
|
|
38
|
-
preload: "auto",
|
|
39
|
-
onPlay: o,
|
|
40
|
-
onPause: l,
|
|
41
|
-
onCanPlay: c
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
export {
|
|
46
|
-
A as default
|
|
47
|
-
};
|