@barabel324/react-player 0.0.8 → 0.0.9

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
@@ -23,15 +23,23 @@ preview: {
23
23
  В плеер можно кастомизировать изображение и кнопку, которые будут показываться, если есть превью.
24
24
 
25
25
  ```ts
26
- const components={
27
- button,
28
- previewPicture
26
+ components={
27
+ button: {
28
+ /** компонент */
29
+ component: FCClass;
30
+ /** его пропсы */
31
+ props?: Record<string, any>;
32
+ },
33
+ previewPicture: {
34
+ component: FCClass;
35
+ props?: Record<string, any>;
36
+ },
29
37
  }
30
38
  ```
31
39
 
32
40
  ```tsx
33
- const PlayButton = () => (
34
- <button>▶ Play</button>
41
+ const PlayButton = (props) => (
42
+ <button {...props}>▶ Play</button>
35
43
  );
36
44
 
37
45
  const PreviewImage = () => (
@@ -41,8 +49,15 @@ const PreviewImage = () => (
41
49
  <Player
42
50
  url={url}
43
51
  components={{
44
- button: () => PlayButton,
45
- previewPicture: () => PreviewImage,
52
+ button: {
53
+ component: PlayButton,
54
+ props: {
55
+ type: "button"
56
+ }
57
+ },
58
+ previewPicture: {
59
+ component: PreviewImage,
60
+ },
46
61
  }}
47
62
  />
48
63
  ```
@@ -1,5 +1,5 @@
1
1
  import { jsx as y } from "react/jsx-runtime";
2
- import { u as d, P as t } from "./index-B8sUd3YU.js";
2
+ import { u as d, P as t } from "./index-Cnbw2ZkR.js";
3
3
  import { useRef as i, useImperativeHandle as P } from "react";
4
4
  const v = ({
5
5
  className: n,
@@ -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-B8sUd3YU.js";
3
+ import { u as p } from "./index-Cnbw2ZkR.js";
4
4
  const m = async () => new Promise((t, n) => {
5
5
  if (window.VK?.VideoPlayer) {
6
6
  t(window.VK);
@@ -1,5 +1,5 @@
1
1
  import { jsx as i } from "react/jsx-runtime";
2
- import { u as p } from "./index-B8sUd3YU.js";
2
+ import { u as p } from "./index-Cnbw2ZkR.js";
3
3
  import { useRef as c, useImperativeHandle as f, useEffect as l } from "react";
4
4
  const w = ({
5
5
  className: a,
@@ -1,11 +1,11 @@
1
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 C, useRef as N } from "react";
2
+ import { createContext as b, useContext as f, useReducer as k, lazy as _, useMemo as N, useRef as E } from "react";
3
3
  function h() {
4
4
  let e, t = "", r = 0;
5
5
  for (; r < arguments.length; ) (e = arguments[r++]) && typeof e == "string" && (t && (t += " "), t += e);
6
6
  return t;
7
7
  }
8
- const a = {
8
+ const u = {
9
9
  show: "show",
10
10
  hide: "hide",
11
11
  showButton: "showButton",
@@ -15,32 +15,32 @@ const a = {
15
15
  showButton: !1,
16
16
  showPreview: !0,
17
17
  canplay: !1
18
- }, E = (e, t) => {
18
+ }, R = (e, t) => {
19
19
  const { type: r } = t;
20
20
  switch (r) {
21
- case a.show:
21
+ case u.show:
22
22
  return { ...e, showButton: !0, showPreview: !0 };
23
- case a.hide:
23
+ case u.hide:
24
24
  return { ...e, showButton: !1, showPreview: !1 };
25
- case a.showButton:
25
+ case u.showButton:
26
26
  return { ...e, showButton: !0 };
27
- case a.hideButton:
27
+ case u.hideButton:
28
28
  return { ...e, showButton: !1 };
29
- case a.canplay:
29
+ case u.canplay:
30
30
  return { ...e, canplay: !0, showButton: !0 };
31
31
  default:
32
32
  return e;
33
33
  }
34
34
  }, B = b(m), x = b(() => {
35
- }), R = ({ children: e }) => {
36
- const [t, r] = k(E, m);
35
+ }), S = ({ children: e }) => {
36
+ const [t, r] = k(R, m);
37
37
  return /* @__PURE__ */ o(B.Provider, { value: t, children: /* @__PURE__ */ o(x.Provider, { value: r, children: e }) });
38
- }, S = () => {
38
+ }, T = () => {
39
39
  const e = f(B);
40
40
  if (e === void 0)
41
41
  throw new Error("usePlayerState нужно использовать внутри PlayerProvider");
42
42
  return e;
43
- }, T = () => {
43
+ }, C = () => {
44
44
  const e = f(x);
45
45
  if (e === void 0)
46
46
  throw new Error("usePlayerDispatch нужно использовать внутри PlayerProvider");
@@ -70,15 +70,15 @@ const a = {
70
70
  className: e,
71
71
  preview: t,
72
72
  onPlay: r,
73
- children: n,
74
- renderButton: u,
75
- renderPreviewPicture: l
73
+ children: l,
74
+ buttonComponent: a,
75
+ previewPictureComponent: n
76
76
  }) => {
77
- const { showButton: p, showPreview: c, canplay: _ } = S(), i = T(), P = () => {
78
- _ && (i({
79
- type: a.hide
77
+ const { showButton: p, showPreview: c, canplay: v } = T(), i = C(), P = () => {
78
+ v && (i({
79
+ type: u.hide
80
80
  }), r && r());
81
- }, w = !!t || !!l;
81
+ }, w = !!t || !!n;
82
82
  return /* @__PURE__ */ d(
83
83
  "div",
84
84
  {
@@ -93,17 +93,17 @@ const a = {
93
93
  className: y.playerPreview__wrapper,
94
94
  onClick: P,
95
95
  children: [
96
- p && (u ? u() : /* @__PURE__ */ o(
96
+ p && (a ? /* @__PURE__ */ o(a.component, { ...a.props }) : /* @__PURE__ */ o(
97
97
  V,
98
98
  {
99
99
  className: y.playerPreview__button
100
100
  }
101
101
  )),
102
- w && c && (l ? l() : t && /* @__PURE__ */ o("img", { className: y.playerPreview__preview, src: t.src, alt: t.alt ?? "preview" }))
102
+ w && c && (n ? /* @__PURE__ */ o(n.component, { ...n.props }) : t && /* @__PURE__ */ o("img", { className: y.playerPreview__preview, src: t.src, alt: t.alt ?? "preview" }))
103
103
  ]
104
104
  }
105
105
  ),
106
- /* @__PURE__ */ o("div", { className: y.playerPreview__player, children: n })
106
+ /* @__PURE__ */ o("div", { className: y.playerPreview__player, children: l })
107
107
  ]
108
108
  }
109
109
  );
@@ -113,13 +113,13 @@ const a = {
113
113
  video: "video",
114
114
  vk: "vk"
115
115
  }, I = {
116
- [s.youtube]: v(async () => await import("./index-Dj9G-CFc.js")),
117
- [s.rutube]: v(async () => await import("./index-P3WMQDqC.js")),
118
- [s.video]: v(async () => await import("./index-CczXORYY.js")),
119
- [s.vk]: v(async () => await import("./index-C8oYhGns.js"))
116
+ [s.youtube]: _(async () => await import("./index-deKi-pBj.js")),
117
+ [s.rutube]: _(async () => await import("./index-Ce-Fa46G.js")),
118
+ [s.video]: _(async () => await import("./index-Byq3YiGh.js")),
119
+ [s.vk]: _(async () => await import("./index-C0CG6pEe.js"))
120
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;
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\/))/, l = /^(?:https?:\/\/)?(?:www\.|m\.)?(?:vk\.com|vkvideo\.ru)\/.+$/;
122
+ return r.test(e) ? s.rutube : t.test(e) ? s.youtube : l.test(e) ? s.vk : s.video;
123
123
  }, U = "_player_1afml_1", q = {
124
124
  player: U
125
125
  }, F = ({
@@ -136,13 +136,13 @@ const a = {
136
136
  className: e,
137
137
  url: t,
138
138
  preview: r,
139
- classNames: n,
140
- components: u
139
+ classNames: l,
140
+ components: a
141
141
  }) => {
142
- const l = n?.player, p = u?.button, c = u?.previewPicture, _ = C(() => {
142
+ const n = l?.player, p = a?.button, c = a?.previewPicture, v = N(() => {
143
143
  const g = M(t);
144
144
  return I[g];
145
- }, [t]), i = N(null), P = () => {
145
+ }, [t]), i = E(null), P = () => {
146
146
  i.current && i.current.play();
147
147
  }, w = !!r || !!c;
148
148
  return /* @__PURE__ */ o(
@@ -152,13 +152,13 @@ const a = {
152
152
  className: e,
153
153
  preview: r,
154
154
  onPlay: P,
155
- renderButton: p,
156
- renderPreviewPicture: c,
155
+ buttonComponent: p,
156
+ previewPictureComponent: c,
157
157
  children: /* @__PURE__ */ o(
158
- _,
158
+ v,
159
159
  {
160
160
  className: h(
161
- l ?? q.player,
161
+ n ?? q.player,
162
162
  !w && e
163
163
  ),
164
164
  ref: i,
@@ -167,9 +167,9 @@ const a = {
167
167
  )
168
168
  }
169
169
  );
170
- }, K = (e) => /* @__PURE__ */ o(R, { children: /* @__PURE__ */ o(G, { ...e }) });
170
+ }, K = (e) => /* @__PURE__ */ o(S, { children: /* @__PURE__ */ o(G, { ...e }) });
171
171
  export {
172
- a as P,
172
+ u as P,
173
173
  K as a,
174
- T as u
174
+ C as u
175
175
  };
@@ -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-B8sUd3YU.js";
3
+ import { u as f } from "./index-Cnbw2ZkR.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,4 +1,3 @@
1
- import { ReactNode } from 'react';
2
1
  import { RefObject } from 'react';
3
2
 
4
3
  /** Утилитарный дженерик для обозначения функционального компонента с пропсами children и className */
@@ -14,7 +13,7 @@ declare type KeysWithClassNames = {
14
13
 
15
14
  declare type KeysWithComponent = {
16
15
  [K in keyof TMapComponents]: TMapComponents[K] extends {
17
- component: () => ReactNode;
16
+ component: TComp;
18
17
  } ? K : never;
19
18
  }[keyof TMapComponents];
20
19
 
@@ -24,6 +23,11 @@ declare type TClassNames = {
24
23
  [K in KeysWithClassNames]?: TMapComponents[K]['className'];
25
24
  };
26
25
 
26
+ declare type TComp = {
27
+ component: FCClass;
28
+ props?: Record<string, any>;
29
+ };
30
+
27
31
  declare type TComponents = {
28
32
  [K in KeysWithComponent]?: TMapComponents[K]['component'];
29
33
  };
@@ -32,12 +36,12 @@ declare type TMapComponents = {
32
36
  /** изображение превью */
33
37
  previewPicture: {
34
38
  /** компонент изображения */
35
- component: () => ReactNode;
39
+ component: TComp;
36
40
  };
37
41
  /** кнопка, которая отображаентся, когда видео загрузилось */
38
42
  button: {
39
43
  /** компонент кнопки */
40
- component: () => ReactNode;
44
+ component: TComp;
41
45
  };
42
46
  /** Плеер */
43
47
  player: {
@@ -73,8 +77,8 @@ declare type TPlayerPreview = {
73
77
  /** Альт изображения */
74
78
  alt: string;
75
79
  };
76
- renderPreviewPicture?: () => ReactNode;
77
- renderButton?: () => ReactNode;
80
+ previewPictureComponent?: TComp;
81
+ buttonComponent?: TComp;
78
82
  onPlay?: () => void;
79
83
  };
80
84
 
@@ -1,4 +1,4 @@
1
- import { a as e } from "./index-B8sUd3YU.js";
1
+ import { a as e } from "./index-Cnbw2ZkR.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.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/react-player.js",
6
6
  "types": "./dist/react-player.d.ts",