@streamlayer/react 1.20.7 → 1.21.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.
@@ -1,254 +1,291 @@
1
- import { jsx as o, jsxs as I } from "react/jsx-runtime";
2
- import { j as K, k as V, s as p, i as L, l as F, n as M, e as _, u as $, d as j, h as q } from "./provider.js";
1
+ import { jsx as l, jsxs as L } from "react/jsx-runtime";
2
+ import { j as K, k as M, i as k, s as m, l as _, n as $, e as F, u as N, d as j, h as q } from "./provider.js";
3
3
  import "nanostores";
4
- import { useRef as x, useCallback as k, useState as C, useEffect as b, Component as z } from "react";
4
+ import { useRef as D, useCallback as I, useState as R, useEffect as T, Component as O } from "react";
5
5
  import "@nanostores/react";
6
6
  import "lodash.throttle";
7
7
  import "react-dom";
8
8
  import "react-countup";
9
- import { c as N } from "./vast-client.min-B0NUra1B.js";
10
- const G = {}, H = new N(), w = V(G), E = K("ui:gam-static"), R = (r) => new Promise((e, n) => {
11
- const s = new Image();
12
- s.onload = () => e(r), s.onerror = () => n(), s.src = r;
13
- }), D = () => {
14
- const r = x(0);
15
- return [k(async (e) => {
16
- var n, s, c, a, l, t, u, i, h, m, f;
17
- if ((n = w.get()[e]) != null && n.imageSrc)
9
+ import { c as z } from "./vast-client.min-B0NUra1B.js";
10
+ const G = {}, J = new z(), w = M(G), E = K("ui:gam-static"), U = (e) => new Promise((s, t) => {
11
+ const a = new Image();
12
+ a.onload = () => s(e), a.onerror = () => t(), a.src = e;
13
+ }), V = () => {
14
+ const e = D(0);
15
+ return [I(async (s) => {
16
+ var t, a, r, c, d, n, h, i, y, g, f;
17
+ if ((t = w.get()[s]) != null && t.imageSrc)
18
18
  return { success: !0 };
19
19
  const v = Date.now();
20
- r.current = v, w.setKey(e, { url: e });
20
+ e.current = v, w.setKey(s, { id: "", url: s });
21
21
  try {
22
- const d = await H.get(e);
23
- if (E.debug(d, "parsedVAST"), r.current === v && w.get()[e].url) {
24
- const y = d.ads.find((g) => g.creatives.length > 0);
25
- if (y) {
26
- E.debug(y, "validAd");
27
- const g = y.creatives.find((S) => S.type === "nonlinear");
28
- if (g) {
29
- E.debug(g, "nonlinear");
30
- const S = (c = (s = g.variations) == null ? void 0 : s[0]) == null ? void 0 : c.staticResource, B = (l = (a = g.variations) == null ? void 0 : a[0]) == null ? void 0 : l.nonlinearClickThroughURLTemplate;
31
- if (S)
32
- return await R(S), w.setKey(e, { url: e, imageSrc: S, adUrl: B }), { success: !0 };
22
+ k.emit("exposedPauseAd", {
23
+ action: "load",
24
+ payload: {}
25
+ });
26
+ const u = await J.get(s);
27
+ if (E.debug(u, "parsedVAST"), e.current === v && w.get()[s].url) {
28
+ const o = u.ads.find((p) => p.creatives.length > 0);
29
+ if (o) {
30
+ E.debug(o, "validAd");
31
+ const p = o.creatives.find((A) => A.type === "nonlinear");
32
+ if (p) {
33
+ E.debug(p, "nonlinear");
34
+ const A = (r = (a = p.variations) == null ? void 0 : a[0]) == null ? void 0 : r.staticResource, C = (d = (c = p.variations) == null ? void 0 : c[0]) == null ? void 0 : d.nonlinearClickThroughURLTemplate;
35
+ if (A)
36
+ return await U(A), w.setKey(s, {
37
+ id: o.id || "",
38
+ url: s,
39
+ imageSrc: A,
40
+ adUrl: C
41
+ }), k.emit("exposedPauseAd", {
42
+ action: "loaded",
43
+ payload: {
44
+ id: o.id || ""
45
+ }
46
+ }), { success: !0 };
33
47
  }
34
- const A = y.creatives.find((S) => S.type === "companion");
35
- E.debug(A, "companion");
36
- const T = (h = (i = (u = (t = A == null ? void 0 : A.variations) == null ? void 0 : t[0]) == null ? void 0 : u.staticResources) == null ? void 0 : i[0]) == null ? void 0 : h.url, P = (f = (m = A == null ? void 0 : A.variations) == null ? void 0 : m[0]) == null ? void 0 : f.companionClickThroughURLTemplate;
37
- if (T)
38
- return await R(T), w.setKey(e, { url: e, imageSrc: T, adUrl: P }), { success: !0 };
48
+ const P = o.creatives.find((A) => A.type === "companion");
49
+ E.debug(P, "companion");
50
+ const b = (y = (i = (h = (n = P == null ? void 0 : P.variations) == null ? void 0 : n[0]) == null ? void 0 : h.staticResources) == null ? void 0 : i[0]) == null ? void 0 : y.url, S = (f = (g = P == null ? void 0 : P.variations) == null ? void 0 : g[0]) == null ? void 0 : f.companionClickThroughURLTemplate;
51
+ if (b)
52
+ return await U(b), w.setKey(s, {
53
+ id: o.id || "",
54
+ url: s,
55
+ imageSrc: b,
56
+ adUrl: S
57
+ }), k.emit("exposedPauseAd", {
58
+ action: "loaded",
59
+ payload: {
60
+ id: o.id || ""
61
+ }
62
+ }), { success: !0 };
39
63
  }
40
64
  }
41
- } catch (d) {
42
- console.error("Error parsing VAST", d);
65
+ } catch (u) {
66
+ console.error("Error parsing VAST", u);
43
67
  }
44
68
  return { success: !1 };
45
69
  }, []), w];
46
- }, O = /* @__PURE__ */ p("div")({
70
+ }, Q = /* @__PURE__ */ m("div")({
47
71
  name: "PauseAdOverlay",
48
72
  class: "pw9gih8",
49
73
  propsAsIs: !1
50
- }), J = /* @__PURE__ */ p("div")({
74
+ }), H = /* @__PURE__ */ m("div")({
51
75
  name: "PauseAdContent",
52
76
  class: "p8lpomy",
53
77
  propsAsIs: !1
54
- }), Q = /* @__PURE__ */ p("div")({
55
- name: "PauseAdGradientRight",
78
+ }), W = /* @__PURE__ */ m("div")({
79
+ name: "PauseAdTopLeft",
56
80
  class: "pv7u167",
57
81
  propsAsIs: !1
58
- }), W = /* @__PURE__ */ p("div")({
59
- name: "PauseAdGradientBottom",
82
+ }), X = /* @__PURE__ */ m("h2")({
83
+ name: "PauseAdTitle",
60
84
  class: "p1kh2yb0",
61
85
  propsAsIs: !1
62
- }), X = /* @__PURE__ */ p("div")({
63
- name: "PauseAdTopLeft",
86
+ }), Y = /* @__PURE__ */ m("p")({
87
+ name: "PauseAdCaption",
64
88
  class: "pl8f94x",
65
89
  propsAsIs: !1
66
- }), Y = /* @__PURE__ */ p("h2")({
67
- name: "PauseAdTitle",
90
+ }), Z = /* @__PURE__ */ m("div")({
91
+ name: "PauseAdBottomLeft",
68
92
  class: "p1m6zmrt",
69
93
  propsAsIs: !1
70
- }), Z = /* @__PURE__ */ p("p")({
71
- name: "PauseAdCaption",
94
+ }), ee = /* @__PURE__ */ m("button")({
95
+ name: "PauseAdPlayButton",
72
96
  class: "pm3vwfa",
73
97
  propsAsIs: !1
74
- }), ee = /* @__PURE__ */ p("div")({
75
- name: "PauseAdBottomLeft",
98
+ }), se = /* @__PURE__ */ m("div")({
99
+ name: "PauseAdSidebarGradient",
76
100
  class: "p1tibuhw",
77
101
  propsAsIs: !1
78
- }), re = /* @__PURE__ */ p("button")({
79
- name: "PauseAdPlayButton",
80
- class: "ptqqrqd",
81
- propsAsIs: !1
82
- }), se = /* @__PURE__ */ p("div")({
102
+ }), re = /* @__PURE__ */ m("div")({
83
103
  name: "PauseAdSidebar",
84
- class: "p14estxv",
104
+ class: "ptqqrqd",
85
105
  propsAsIs: !1
86
- }), te = /* @__PURE__ */ p("span")({
106
+ }), te = /* @__PURE__ */ m("span")({
87
107
  name: "PauseAdTitleDescription",
88
- class: "p1dpvfl1",
108
+ class: "p14estxv",
89
109
  propsAsIs: !1
90
- }), U = /* @__PURE__ */ p("img")({
110
+ }), B = /* @__PURE__ */ m("img")({
91
111
  name: "ExternalAdContainer",
92
- class: "ezfmabr",
112
+ class: "e1dpvfl1",
93
113
  propsAsIs: !1
94
- }), ne = ({ vastUrl: r }) => {
95
- var e;
96
- const [, n] = D(), s = _(n, { keys: [r] });
97
- return (e = s == null ? void 0 : s[r]) != null && e.imageSrc ? s[r].adUrl ? /* @__PURE__ */ o("a", { href: s[r].adUrl, target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ o(U, { src: s[r].imageSrc }) }) : /* @__PURE__ */ o(U, { src: s[r].imageSrc }) : null;
98
- }, oe = ({ isClosing: r, title: e, caption: n, onPlay: s, onClose: c, vastUrl: a, options: l }) => {
99
- const t = (l == null ? void 0 : l.showPauseButton) ?? !0, { ref: u, focusSelf: i } = F.useFocusable({
114
+ }), oe = ({ vastUrl: e, isDesktop: s }) => {
115
+ var t;
116
+ const [, a] = V(), r = F(a, { keys: [e] });
117
+ return T(() => {
118
+ r && r[e] && r[e].imageSrc && r[e].id && k.emit("exposedPauseAd", {
119
+ action: "rendered",
120
+ payload: {
121
+ id: r[e].id
122
+ }
123
+ });
124
+ }, [r, e]), (t = r == null ? void 0 : r[e]) != null && t.imageSrc ? !r[e].adUrl || !s ? /* @__PURE__ */ l(B, { src: r[e].imageSrc }) : /* @__PURE__ */ l(
125
+ "a",
126
+ {
127
+ onClick: () => {
128
+ k.emit("exposedPauseAd", {
129
+ action: "navigated",
130
+ payload: {
131
+ id: r[e].id
132
+ }
133
+ });
134
+ },
135
+ href: r[e].adUrl,
136
+ target: "_blank",
137
+ rel: "noopener noreferrer",
138
+ children: /* @__PURE__ */ l(B, { src: r[e].imageSrc })
139
+ }
140
+ ) : null;
141
+ }, ae = ({ isClosing: e, title: s, caption: t, onPlay: a, onClose: r, vastUrl: c, options: d, isDesktop: n }) => {
142
+ const h = (d == null ? void 0 : d.showPauseButton) ?? !0, { ref: i, focusSelf: y } = _.useFocusable({
100
143
  focusKey: "sl-pause-ad-play",
101
- onEnterRelease: s,
144
+ onEnterRelease: a,
102
145
  isFocusBoundary: !0,
103
146
  forceFocus: !0
104
147
  });
105
- return b(() => {
106
- u.current && i();
107
- }, [u, i]), b(() => {
108
- const h = (m) => {
109
- const f = m.keyCode;
110
- if (f === 461 || f === 10009 || f === 27 || f === 8) {
111
- m.preventDefault(), m.stopPropagation(), m.stopImmediatePropagation(), c == null || c();
148
+ return T(() => {
149
+ i.current && y();
150
+ }, [i, y]), T(() => {
151
+ if (!r)
152
+ return () => {
153
+ };
154
+ const g = (f) => {
155
+ const v = f.keyCode;
156
+ if (v === 461 || v === 10009 || v === 27 || v === 8) {
157
+ f.preventDefault(), f.stopPropagation(), f.stopImmediatePropagation(), r();
112
158
  return;
113
159
  }
114
160
  };
115
- return window.addEventListener("keydown", h, { capture: !0 }), () => window.removeEventListener("keydown", h, { capture: !0 });
116
- }, [c]), /* @__PURE__ */ o(O, { className: M(r && "pause-ad-closing"), children: /* @__PURE__ */ I(J, { children: [
117
- /* @__PURE__ */ o(Q, {}),
118
- /* @__PURE__ */ o(W, {}),
119
- /* @__PURE__ */ I(X, { children: [
120
- /* @__PURE__ */ o(Y, { children: e }),
121
- /* @__PURE__ */ o(Z, { children: n })
161
+ return window.addEventListener("keydown", g, { capture: !0 }), () => window.removeEventListener("keydown", g, { capture: !0 });
162
+ }, [r]), /* @__PURE__ */ l(Q, { className: $("SL_PauseAdOverlay", e && "pause-ad-closing"), children: /* @__PURE__ */ L(H, { children: [
163
+ /* @__PURE__ */ L(W, { children: [
164
+ /* @__PURE__ */ l(X, { children: s }),
165
+ /* @__PURE__ */ l(Y, { children: t })
122
166
  ] }),
123
- t && /* @__PURE__ */ o(ee, { children: /* @__PURE__ */ o(
124
- re,
167
+ h && /* @__PURE__ */ l(Z, { children: /* @__PURE__ */ l(
168
+ ee,
125
169
  {
126
- ref: u,
127
- onClick: s,
128
- onMouseEnter: () => u.current.focus(),
170
+ ref: i,
171
+ onClick: a,
172
+ onMouseEnter: () => i.current.focus(),
129
173
  "aria-label": "Resume playback"
130
174
  }
131
175
  ) }),
132
- /* @__PURE__ */ I(se, { children: [
133
- a && /* @__PURE__ */ o(ne, { vastUrl: a }),
134
- /* @__PURE__ */ o(te, { children: "ADVERTISEMENT" })
135
- ] })
176
+ /* @__PURE__ */ l(se, { className: "SL_PauseAdSidebar", children: /* @__PURE__ */ L(re, { children: [
177
+ c && /* @__PURE__ */ l(oe, { isDesktop: n, vastUrl: c }),
178
+ /* @__PURE__ */ l(te, { children: "ADVERTISEMENT" })
179
+ ] }) })
136
180
  ] }) });
137
- }, ae = ({
138
- showPauseAd: r,
139
- vastUrls: e,
140
- title: n,
141
- caption: s,
142
- onPlay: c,
143
- onClose: a,
144
- onRender: l,
145
- options: t
146
- }) => {
147
- const u = (t == null ? void 0 : t.pauseAdDelay) ?? 5e3, [i, h] = C(!1), [m, f] = C(!1), v = x(), d = e == null ? void 0 : e[0].url, y = x(d);
148
- y.current = d;
149
- const [g, A] = D();
150
- return b(() => {
151
- if (r && d) {
152
- L.emit("exposedPauseAd", {
181
+ }, ne = ({ showPauseAd: e, vastUrls: s, title: t, caption: a, sdk: r, onClose: c, onRender: d, options: n, isDesktop: h }) => {
182
+ const i = (n == null ? void 0 : n.pauseAdDelay) ?? 5e3, [y, g] = R(!1), [f, v] = R(!1), u = D(), o = s == null ? void 0 : s[0].url, p = D(o);
183
+ p.current = o;
184
+ const [P, b] = V(), S = I(() => {
185
+ c && (k.emit("exposedPauseAd", {
186
+ action: "closed",
187
+ payload: {}
188
+ }), c());
189
+ }, [c]), A = I(() => {
190
+ r.controlVideoPlayer({ play: !0 });
191
+ }, [r]);
192
+ return T(() => {
193
+ if (e && o) {
194
+ k.emit("exposedPauseAd", {
153
195
  action: "enabled",
154
196
  payload: {}
155
- }), g(d).then((P) => {
156
- y.current === d && (P == null ? void 0 : P.success) !== !0 && (clearTimeout(v.current), a == null || a());
197
+ }), P(o).then((x) => {
198
+ p.current === o && (x == null ? void 0 : x.success) !== !0 && (clearTimeout(u.current), S == null || S());
157
199
  }).catch(() => {
158
- y.current === d && (clearTimeout(v.current), a == null || a());
200
+ p.current === o && (clearTimeout(u.current), S == null || S());
159
201
  });
160
- const T = () => {
161
- var P;
162
- (P = A.get()[y.current]) != null && P.imageSrc ? (clearTimeout(v.current), f(!1), h(!0), L.emit("exposedPauseAd", {
163
- action: "rendered",
164
- payload: {}
165
- })) : v.current = setTimeout(() => {
166
- T();
202
+ const C = () => {
203
+ const x = b.get()[p.current];
204
+ x != null && x.imageSrc ? (clearTimeout(u.current), v(!1), g(!0)) : u.current = setTimeout(() => {
205
+ C();
167
206
  }, 200);
168
207
  };
169
- v.current = setTimeout(() => {
170
- T();
171
- }, u);
208
+ u.current = setTimeout(() => {
209
+ C();
210
+ }, i);
172
211
  } else
173
- L.emit("exposedPauseAd", {
212
+ k.emit("exposedPauseAd", {
174
213
  action: "disabled",
175
214
  payload: {}
176
- }), f(!0), v.current = setTimeout(() => {
177
- h(!1);
215
+ }), v(!0), u.current = setTimeout(() => {
216
+ g(!1);
178
217
  }, 400);
179
218
  return () => {
180
- v.current && clearTimeout(v.current);
219
+ u.current && clearTimeout(u.current);
181
220
  };
182
- }, [A, g, a, u, r, d]), b(() => {
183
- l == null || l({ rendered: i });
184
- }, [i, l]), b(() => () => {
185
- l == null || l({ rendered: !1 });
186
- }, [l]), i ? /* @__PURE__ */ o(
187
- oe,
221
+ }, [b, P, S, i, e, o]), T(() => {
222
+ d == null || d({ rendered: y });
223
+ }, [y, d]), T(() => () => {
224
+ d == null || d({ rendered: !1 });
225
+ }, [d]), y ? /* @__PURE__ */ l(
226
+ ae,
188
227
  {
189
- onClose: a,
190
- isClosing: m,
191
- title: n,
192
- caption: s,
193
- onPlay: c,
194
- vastUrl: d,
195
- options: t
228
+ onClose: S,
229
+ isClosing: f,
230
+ title: t,
231
+ caption: a,
232
+ onPlay: A,
233
+ vastUrl: o,
234
+ options: n,
235
+ isDesktop: h
196
236
  }
197
237
  ) : null;
198
- }, le = ({
199
- showPauseAd: r,
200
- pauseAdVastUrl: e,
201
- videoPlayerController: n,
202
- onRenderPauseAd: s,
203
- onClosePauseAd: c,
204
- children: a,
205
- options: l
238
+ }, ie = ({
239
+ showPauseAd: e,
240
+ pauseAdVastUrl: s,
241
+ videoPlayerController: t,
242
+ onRenderPauseAd: a,
243
+ onClosePauseAd: r,
244
+ children: c,
245
+ options: d
206
246
  }) => {
207
- const t = $(), u = j(), i = x(), h = k(() => {
208
- c == null || c();
209
- }, [c]), m = k(() => {
210
- t == null || t.controlVideoPlayer({ play: !0 });
211
- }, [t]);
212
- return b(() => t ? (n && (i.current = n, t.addVideoPlayerController(i.current)), () => {
213
- i.current && t.removeVideoPlayerController(i.current);
247
+ const n = N(), h = j(), i = D();
248
+ return T(() => n ? (t && (i.current = t, n.addVideoPlayerController(i.current)), () => {
249
+ i.current && n.removeVideoPlayerController(i.current);
214
250
  }) : () => {
215
- }, [t, n]), t ? /* @__PURE__ */ o("div", { className: "StreamLayerSDK", children: /* @__PURE__ */ I(
251
+ }, [n, t]), n ? /* @__PURE__ */ l("div", { className: "StreamLayerSDK", children: /* @__PURE__ */ L(
216
252
  q,
217
253
  {
218
- style: { position: "relative" },
219
- customTheme: u.theme,
220
- themeMode: u.themeMode,
254
+ style: c ? { position: "relative" } : {},
255
+ customTheme: h.theme,
256
+ themeMode: h.themeMode,
221
257
  children: [
222
- a,
223
- e && /* @__PURE__ */ o(
224
- ae,
258
+ c,
259
+ s && /* @__PURE__ */ l(
260
+ ne,
225
261
  {
226
- showPauseAd: r,
227
- vastUrls: e,
228
- onClose: h,
229
- onRender: s,
230
- onPlay: m,
231
- options: l
262
+ sdk: n,
263
+ showPauseAd: e,
264
+ vastUrls: s,
265
+ onClose: r,
266
+ onRender: a,
267
+ options: d,
268
+ isDesktop: !0
232
269
  }
233
270
  )
234
271
  ]
235
272
  }
236
- ) }) : a;
273
+ ) }) : c;
237
274
  };
238
- class ye extends z {
239
- constructor(e) {
240
- super(e), this.state = { hasError: !1 };
275
+ class fe extends O {
276
+ constructor(s) {
277
+ super(s), this.state = { hasError: !1 };
241
278
  }
242
279
  static getDerivedStateFromError() {
243
280
  return { hasError: !0 };
244
281
  }
245
- componentDidCatch(e, n) {
246
- console.error(e, n.componentStack);
282
+ componentDidCatch(s, t) {
283
+ console.error(s, t.componentStack);
247
284
  }
248
285
  render() {
249
- return this.state.hasError ? this.props.children : /* @__PURE__ */ o(le, { ...this.props });
286
+ return this.state.hasError ? this.props.children : /* @__PURE__ */ l(ie, { ...this.props });
250
287
  }
251
288
  }
252
289
  export {
253
- ye as StreamLayerPauseAd
290
+ fe as StreamLayerPauseAd
254
291
  };