@streamlayer/react 1.20.7 → 1.21.0

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