@barabel324/react-player 0.0.0 → 0.0.2

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 CHANGED
@@ -1,69 +1,27 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## Expanding the ESLint configuration
11
-
12
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
-
14
- ```js
15
- export default tseslint.config([
16
- globalIgnores(['dist']),
17
- {
18
- files: ['**/*.{ts,tsx}'],
19
- extends: [
20
- // Other configs...
21
-
22
- // Remove tseslint.configs.recommended and replace with this
23
- ...tseslint.configs.recommendedTypeChecked,
24
- // Alternatively, use this for stricter rules
25
- ...tseslint.configs.strictTypeChecked,
26
- // Optionally, add this for stylistic rules
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,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-Dnbs5lXl.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
+ };
@@ -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-Dnbs5lXl.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,44 @@
1
+ import { jsx as y } from "react/jsx-runtime";
2
+ import { u as d, P as t } from "./index-Dnbs5lXl.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
+ };
@@ -1,13 +1,12 @@
1
1
  import { jsx as s, jsxs as y } from "react/jsx-runtime";
2
- import { createContext as w, useContext as h, useReducer as x, lazy as p, useMemo as C, useRef as $ } from "react";
3
- import d from "classix";
2
+ import { createContext as d, useContext as v, useReducer as _, lazy as p, useMemo as $, useRef as C } from "react";
4
3
  const n = {
5
4
  show: "show",
6
5
  hide: "hide",
7
6
  showButton: "showButton",
8
7
  hideButton: "hideButton",
9
8
  canplay: "canplay"
10
- }, v = {
9
+ }, P = {
11
10
  showButton: !1,
12
11
  showPreview: !0,
13
12
  canplay: !1
@@ -27,58 +26,58 @@ const n = {
27
26
  default:
28
27
  return e;
29
28
  }
30
- }, P = w(v), m = w(() => {
31
- }), _ = ({ children: e }) => {
32
- const [t, r] = x(k, v);
33
- return /* @__PURE__ */ s(P.Provider, { value: t, children: /* @__PURE__ */ s(m.Provider, { value: r, children: e }) });
34
- }, N = () => {
35
- const e = h(P);
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);
36
35
  if (e === void 0)
37
36
  throw new Error("usePlayerState нужно использовать внутри PlayerProvider");
38
37
  return e;
39
- }, E = () => {
40
- const e = h(m);
38
+ }, R = () => {
39
+ const e = v(b);
41
40
  if (e === void 0)
42
41
  throw new Error("usePlayerDispatch нужно использовать внутри PlayerProvider");
43
42
  return e;
44
- }, R = "button-play", S = {
45
- parent: R
46
- }, T = ({
43
+ }, S = "idmrp-button-play", T = {
44
+ parent: S
45
+ }, g = ({
47
46
  className: e,
48
47
  onClick: t
49
48
  }) => /* @__PURE__ */ s(
50
49
  "button",
51
50
  {
52
- className: d(S.parent, e),
51
+ className: [T.parent, e].join(" "),
53
52
  type: "button",
54
53
  onClick: t
55
54
  }
56
- ), c = "player-preview", u = {
55
+ ), c = "idmrp-player-preview", u = {
57
56
  parent: c,
58
57
  wrapper: `${c}__wrapper`,
59
58
  button: `${c}__button`,
60
59
  preview: `${c}__preview`,
61
60
  player: `${c}__player`
62
- }, g = ({
61
+ }, j = ({
63
62
  className: e,
64
63
  preview: t,
65
64
  onPlay: r,
66
65
  children: a
67
66
  }) => {
68
- const { showButton: i, showPreview: l, canplay: b } = N(), f = E(), B = () => {
69
- b && (f({
67
+ const { showButton: i, showPreview: l, canplay: f } = E(), B = R(), x = () => {
68
+ f && (B({
70
69
  type: n.hide
71
70
  }), r && r());
72
71
  };
73
- return /* @__PURE__ */ y("div", { className: d(u.parent, e), children: [
72
+ return /* @__PURE__ */ y("div", { className: [u.parent, e].join(" "), children: [
74
73
  (i || t && l) && /* @__PURE__ */ y(
75
74
  "div",
76
75
  {
77
76
  className: u.wrapper,
78
- onClick: B,
77
+ onClick: x,
79
78
  children: [
80
79
  i && /* @__PURE__ */ s(
81
- T,
80
+ g,
82
81
  {
83
82
  className: u.button
84
83
  }
@@ -95,43 +94,45 @@ const n = {
95
94
  video: "video",
96
95
  vk: "vk"
97
96
  }, D = {
98
- [o.youtube]: p(async () => await import("./index-C-0pNFYJ.js")),
99
- [o.rutube]: p(async () => await import("./index-3eLEuMe8.js")),
100
- [o.video]: p(async () => await import("./index-CSgcS1fk.js")),
101
- [o.vk]: p(async () => await import("./index-0qY1-A4q.js"))
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"))
102
101
  }, V = (e) => {
103
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)\/.+$/;
104
103
  return r.test(e) ? o.rutube : t.test(e) ? o.youtube : a.test(e) ? o.vk : o.video;
105
- }, j = "player", A = {
106
- parent: j
107
- }, L = ({
104
+ }, w = "idmrp-player", h = {
105
+ parent: w,
106
+ player: `${w}__player`
107
+ }, A = ({
108
108
  url: e,
109
109
  preview: t
110
110
  }) => {
111
- const r = C(() => {
111
+ const r = $(() => {
112
112
  const l = V(e);
113
113
  return D[l];
114
- }, [e]), a = $(null), i = () => {
114
+ }, [e]), a = C(null), i = () => {
115
115
  a.current && a.current.play();
116
116
  };
117
117
  return /* @__PURE__ */ s(
118
- g,
118
+ j,
119
119
  {
120
- className: A.parent,
120
+ className: h.parent,
121
121
  preview: t,
122
122
  onPlay: i,
123
123
  children: /* @__PURE__ */ s(
124
124
  r,
125
125
  {
126
+ className: h.player,
126
127
  ref: a,
127
128
  url: e
128
129
  }
129
130
  )
130
131
  }
131
132
  );
132
- }, I = (e) => /* @__PURE__ */ s(_, { children: /* @__PURE__ */ s(L, { ...e }) });
133
+ }, Y = (e) => /* @__PURE__ */ s(N, { children: /* @__PURE__ */ s(A, { ...e }) });
133
134
  export {
134
135
  n as P,
135
- I as a,
136
- E as u
136
+ Y as a,
137
+ R as u
137
138
  };
@@ -0,0 +1,40 @@
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { u as p } from "./index-Dnbs5lXl.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
+ };
@@ -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(--color-green-200);border-radius:50%}.button-play:before{content:"";position:absolute;top:50%;left:58%;border:.3125rem solid transparent;border-left:.5625rem solid var(--color-beige-100);transform:translate(-50%,-50%)}.player-preview{position:relative;width:100%;height:100%;object-fit:cover}.player-preview .player-preview__wrapper{position:absolute;inset:0;cursor:pointer}.player-preview .player-preview__button{z-index:2;position:absolute;top:50%;left:50%;transform:translate(-50%) translateY(-50%)}.player-preview .player-preview__preview{z-index:1;position:absolute;top:0;left:0;width:100%;height:100%;object-fit:cover}.player-preview .player-preview__player{width:100%;height:100%}.player{position:relative;margin:50px;width:300px;height:300px}.player-youtube,.player-rutube{display:block;width:100%;height:100%}.player-video{display:block;width:100%;height:100%;object-fit:cover;object-position:center}
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}
@@ -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;
@@ -1,4 +1,4 @@
1
- import { a as e } from "./index-COqINEuJ.js";
1
+ import { a as e } from "./index-Dnbs5lXl.js";
2
2
  export {
3
3
  e as Player
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barabel324/react-player",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
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
  },
@@ -30,7 +29,6 @@
30
29
  "@types/react": "^19.1.10",
31
30
  "@types/react-dom": "^19.1.7",
32
31
  "@vitejs/plugin-react": "^5.0.0",
33
- "classix": "^2.2.2",
34
32
  "eslint": "^9.33.0",
35
33
  "eslint-plugin-react-hooks": "^5.2.0",
36
34
  "eslint-plugin-react-refresh": "^0.4.20",
@@ -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
- };
@@ -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
- };
@@ -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
- };
@@ -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
- };