@streamlayer/react-ui 1.20.0 → 1.22.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.
Files changed (58) hide show
  1. package/lib/app/masters/BetPack/BetPackContent/EmergencyScreen/index.d.ts +1 -0
  2. package/lib/app/masters/BetPack/BetPackContent/EmergencyScreen/index.js +11 -11
  3. package/lib/app/masters/BetPack/BetPackContent/EndScreen/index.d.ts +0 -1
  4. package/lib/app/masters/BetPack/BetPackContent/EndScreen/index.js +18 -22
  5. package/lib/app/masters/BetPack/BetPackContent/ScreenContainer/index.d.ts +0 -1
  6. package/lib/app/masters/BetPack/BetPackContent/ScreenContainer/index.js +7 -7
  7. package/lib/app/masters/BetPack/BetPackContent/ScreenContainer/useDynamicParentFont.d.ts +1 -2
  8. package/lib/app/masters/BetPack/BetPackContent/ScreenContainer/useDynamicParentFont.js +16 -19
  9. package/lib/app/masters/BetPack/BetPackContent/StartScreen/index.d.ts +0 -1
  10. package/lib/app/masters/BetPack/BetPackContent/StartScreen/index.js +25 -24
  11. package/lib/app/masters/BetPack/BetPackContent/StartScreen/styles.d.ts +1 -0
  12. package/lib/app/masters/BetPack/BetPackContent/StartScreen/styles.js +14 -9
  13. package/lib/app/masters/BetPack/BetPackContent/index.js +68 -66
  14. package/lib/app/masters/BetPack/BetPackOverlay/index.js +3 -2
  15. package/lib/app/masters/BetPack/index.js +64 -62
  16. package/lib/app/masters/BetPack/utils.d.ts +1 -1
  17. package/lib/app/masters/BetPack/utils.js +8 -7
  18. package/lib/app/masters/Features/Gamification/index.js +5 -5
  19. package/lib/app/masters/Features/index.d.ts +2 -2
  20. package/lib/app/masters/Features/index.js +1 -1
  21. package/lib/app/masters/Header/index.js +19 -23
  22. package/lib/app/masters/Notifications/Onboarding/index.d.ts +0 -1
  23. package/lib/app/masters/Notifications/Onboarding/index.js +42 -43
  24. package/lib/app/masters/Notifications/index.js +50 -55
  25. package/lib/app/masters/masters.js +60 -56
  26. package/lib/app/masters/useOrientation.d.ts +3 -0
  27. package/lib/app/masters/useOrientation.js +12 -0
  28. package/lib/app/masters/useSdkResponsive.js +2 -2
  29. package/lib/app/masters/useSdkScroll.js +12 -12
  30. package/lib/app/useSdkResponsive.js +1 -1
  31. package/lib/app/useSdkScroll.js +1 -1
  32. package/lib/assets/style.css +1 -1
  33. package/lib/index-DSi8Qgfs.js +14 -0
  34. package/lib/index-DXvAPWiE.js +3743 -0
  35. package/lib/index-tnt2CtQe.js +55 -0
  36. package/lib/ui/advertisement/overlay/externalAd/index.d.ts +1 -1
  37. package/lib/ui/advertisement/overlay/externalAd/index.js +79 -40323
  38. package/lib/ui/advertisement/overlay/externalAd/styles.d.ts +10 -0
  39. package/lib/ui/advertisement/overlay/externalAd/styles.js +49 -0
  40. package/lib/ui/advertisement/overlay/externalAd/vast-player/module.d.js +1 -0
  41. package/lib/ui/advertisement/overlay/externalAd/vast-player/useGAMPlayer.d.ts +19 -0
  42. package/lib/ui/advertisement/overlay/externalAd/vast-player/useGAMPlayer.js +33199 -0
  43. package/lib/ui/advertisement/overlay/externalAd/vast-player/useVastAds.d.ts +24 -0
  44. package/lib/ui/advertisement/overlay/externalAd/vast-player/useVastAds.js +8 -0
  45. package/lib/ui/gamification/vote/feedback/index.d.ts +1 -0
  46. package/lib/ui/gamification/vote/feedback/index.js +83 -73
  47. package/lib/ui/gamification/vote/feedback/styles.d.ts +1 -0
  48. package/lib/ui/gamification/vote/feedback/styles.js +40 -39
  49. package/lib/ui/gamification/vote/index.js +98 -95
  50. package/lib/ui/icons/index.d.ts +1 -0
  51. package/lib/ui/icons/index.js +88 -79
  52. package/lib/ui/modal/index.js +31 -34
  53. package/lib/ui/theme/breakpoints.d.ts +1 -0
  54. package/lib/ui/theme/breakpoints.js +17 -9
  55. package/lib/ui/theme/masters-theme.js +1 -0
  56. package/lib/useVastAds-Dt_tRbpd.js +1284 -0
  57. package/package.json +18 -15
  58. package/lib/index-CLJzLXks.js +0 -64
@@ -0,0 +1,1284 @@
1
+ import { useState as re, useRef as C, useEffect as U } from "react";
2
+ import { v4 as I, validate as ae, v5 as x } from "uuid";
3
+ import { a as ie } from "./index-tnt2CtQe.js";
4
+ function w() {
5
+ let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
6
+ return { id: a.id || null, adId: a.adId || null, sequence: a.sequence || null, apiFramework: a.apiFramework || null, universalAdIds: [], creativeExtensions: [] };
7
+ }
8
+ const se = ["ADCATEGORIES", "ADCOUNT", "ADPLAYHEAD", "ADSERVINGID", "ADTYPE", "APIFRAMEWORKS", "APPBUNDLE", "ASSETURI", "BLOCKEDADCATEGORIES", "BREAKMAXADLENGTH", "BREAKMAXADS", "BREAKMAXDURATION", "BREAKMINADLENGTH", "BREAKMINDURATION", "BREAKPOSITION", "CLICKPOS", "CLICKTYPE", "CLIENTUA", "CONTENTID", "CONTENTPLAYHEAD", "CONTENTURI", "DEVICEIP", "DEVICEUA", "DOMAIN", "EXTENSIONS", "GDPRCONSENT", "IFA", "IFATYPE", "INVENTORYSTATE", "LATLONG", "LIMITADTRACKING", "MEDIAMIME", "MEDIAPLAYHEAD", "OMIDPARTNER", "PAGEURL", "PLACEMENTTYPE", "PLAYERCAPABILITIES", "PLAYERSIZE", "PLAYERSTATE", "PODSEQUENCE", "REGULATIONS", "SERVERSIDE", "SERVERUA", "TRANSACTIONID", "UNIVERSALADID", "VASTVERSIONS", "VERIFICATIONVENDORS"];
9
+ function S(a) {
10
+ let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, t = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
11
+ const r = [], i = z(a);
12
+ !e.ERRORCODE || t.isCustomCode || /^[0-9]{3}$/.test(e.ERRORCODE) || (e.ERRORCODE = 900), e.CACHEBUSTING = Q(Math.round(1e8 * Math.random())), e.TIMESTAMP = (/* @__PURE__ */ new Date()).toISOString(), e.RANDOM = e.random = e.CACHEBUSTING;
13
+ for (const s in e) e[s] = G(e[s]);
14
+ for (const s in i) {
15
+ const o = i[s];
16
+ typeof o == "string" && r.push(_(o, e));
17
+ }
18
+ return r;
19
+ }
20
+ function _(a, e) {
21
+ const t = (a = D(a, e)).match(/[^[\]]+(?=])/g);
22
+ if (!t) return a;
23
+ let r = t.filter((i) => se.indexOf(i) > -1);
24
+ return r.length === 0 ? a : (r = r.reduce((i, s) => (i[s] = -1, i), {}), D(a, r));
25
+ }
26
+ function D(a, e) {
27
+ let t = a;
28
+ for (const r in e) {
29
+ const i = e[r];
30
+ t = t.replace(new RegExp("(?:\\[|%%)(".concat(r, ")(?:\\]|%%)"), "g"), i);
31
+ }
32
+ return t;
33
+ }
34
+ function z(a) {
35
+ return Array.isArray(a) ? a.map((e) => e && e.hasOwnProperty("url") ? e.url : e) : a;
36
+ }
37
+ function V(a) {
38
+ return /^(https?:\/\/|\/\/)/.test(a);
39
+ }
40
+ function P(a, e) {
41
+ for (let t = 0; t < e.length; t++) if (Y(e[t], a)) return !0;
42
+ return !1;
43
+ }
44
+ function Y(a, e) {
45
+ if (a && e) {
46
+ const t = Object.getOwnPropertyNames(a), r = Object.getOwnPropertyNames(e);
47
+ return t.length === r.length && a.id === e.id && a.url === e.url;
48
+ }
49
+ return !1;
50
+ }
51
+ function G(a) {
52
+ return encodeURIComponent(a).replace(/[!'()*]/g, (e) => "%".concat(e.charCodeAt(0).toString(16)));
53
+ }
54
+ function Q(a) {
55
+ let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
56
+ return a.toString().padStart(e, "0");
57
+ }
58
+ const f = { track: function(a, e, t) {
59
+ S(a, e, t).forEach((r) => {
60
+ typeof window < "u" && window !== null && (new Image().src = r);
61
+ });
62
+ }, resolveURLTemplates: S, extractURLsFromTemplates: z, filterUrlTemplates: function(a) {
63
+ return a.reduce((e, t) => {
64
+ const r = t.url || t;
65
+ return V(r) ? e.validUrls.push(r) : e.invalidUrls.push(r), e;
66
+ }, { validUrls: [], invalidUrls: [] });
67
+ }, containsTemplateObject: P, isTemplateObjectEqual: Y, encodeURIComponentRFC3986: G, replaceUrlMacros: _, isNumeric: function(a) {
68
+ return !isNaN(parseFloat(a)) && isFinite(a);
69
+ }, flatten: function a(e) {
70
+ return e.reduce((t, r) => t.concat(Array.isArray(r) ? a(r) : r), []);
71
+ }, joinArrayOfUniqueTemplateObjs: function() {
72
+ let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
73
+ const t = Array.isArray(a) ? a : [], r = Array.isArray(e) ? e : [];
74
+ return t.concat(r).reduce((i, s) => (P(s, i) || i.push(s), i), []);
75
+ }, isValidTimeValue: function(a) {
76
+ return Number.isFinite(a) && a >= -2;
77
+ }, addLeadingZeros: Q, isValidUrl: V, isBrowserEnvironment: function() {
78
+ return typeof window < "u";
79
+ }, formatMacrosValues: function(a) {
80
+ return typeof a != "object" ? a : JSON.stringify(a);
81
+ } };
82
+ function O(a) {
83
+ return ["true", "TRUE", "True", "1"].includes(a);
84
+ }
85
+ function ne(a) {
86
+ if (a == null) return -1;
87
+ if (f.isNumeric(a)) return parseInt(a);
88
+ const e = a.split(":");
89
+ if (e.length !== 3) return -1;
90
+ const t = e[2].split(".");
91
+ let r = parseInt(t[0]);
92
+ t.length === 2 && (r += parseFloat("0.".concat(t[1])));
93
+ const i = parseInt(60 * e[1]), s = parseInt(60 * e[0] * 60);
94
+ return isNaN(s) || isNaN(i) || isNaN(r) || i > 3600 || r > 60 ? -1 : s + i + r;
95
+ }
96
+ const l = { childByName: function(a, e) {
97
+ return Array.from(a.childNodes).find((t) => t.nodeName === e);
98
+ }, childrenByName: function(a, e) {
99
+ return Array.from(a.childNodes).filter((t) => t.nodeName === e);
100
+ }, resolveVastAdTagURI: function(a, e) {
101
+ if (!e) return a;
102
+ if (a.startsWith("//")) {
103
+ const { protocol: t } = location;
104
+ return "".concat(t).concat(a);
105
+ }
106
+ if (!a.includes("://")) {
107
+ const t = e.slice(0, e.lastIndexOf("/"));
108
+ return "".concat(t, "/").concat(a);
109
+ }
110
+ return a;
111
+ }, parseBoolean: O, parseNodeText: function(a) {
112
+ return a && (a.textContent || a.text || "").trim();
113
+ }, copyNodeAttribute: function(a, e, t) {
114
+ const r = e.getAttribute(a);
115
+ r && t.setAttribute(a, r);
116
+ }, parseAttributes: function(a) {
117
+ return Array.from(a.attributes).reduce((e, t) => (e[t.nodeName] = t.nodeValue, e), {});
118
+ }, parseDuration: ne, getStandAloneAds: function() {
119
+ return (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []).filter((a) => !parseInt(a.sequence, 10));
120
+ }, getSortedAdPods: function() {
121
+ return (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []).filter((a) => parseInt(a.sequence, 10)).sort((a, e) => a.sequence - e.sequence);
122
+ }, assignAttributes: function(a, e) {
123
+ a && Array.from(a).forEach((t) => {
124
+ let { nodeName: r, nodeValue: i } = t;
125
+ if (r && i && e.hasOwnProperty(r)) {
126
+ let s = i;
127
+ typeof e[r] == "boolean" && (s = O(s)), e[r] = s;
128
+ }
129
+ });
130
+ }, mergeWrapperAdData: function(a, e) {
131
+ var t;
132
+ a.errorURLTemplates = e.errorURLTemplates.concat(a.errorURLTemplates), a.impressionURLTemplates = e.impressionURLTemplates.concat(a.impressionURLTemplates), a.extensions = e.extensions.concat(a.extensions), e.viewableImpression.length > 0 && (a.viewableImpression = [...a.viewableImpression, ...e.viewableImpression]), a.followAdditionalWrappers = e.followAdditionalWrappers, a.allowMultipleAds = e.allowMultipleAds, a.fallbackOnNoAd = e.fallbackOnNoAd;
133
+ const r = (e.creatives || []).filter((n) => n && n.type === "companion"), i = r.reduce((n, c) => ((c.variations || []).forEach((u) => {
134
+ (u.companionClickTrackingURLTemplates || []).forEach((d) => {
135
+ f.containsTemplateObject(d, n) || n.push(d);
136
+ });
137
+ }), n), []);
138
+ a.creatives = r.concat(a.creatives);
139
+ const s = e.videoClickTrackingURLTemplates && e.videoClickTrackingURLTemplates.length, o = e.videoCustomClickURLTemplates && e.videoCustomClickURLTemplates.length;
140
+ if (a.creatives.forEach((n) => {
141
+ if (e.trackingEvents && e.trackingEvents[n.type]) for (const c in e.trackingEvents[n.type]) {
142
+ const u = e.trackingEvents[n.type][c];
143
+ Array.isArray(n.trackingEvents[c]) || (n.trackingEvents[c] = []), n.trackingEvents[c] = n.trackingEvents[c].concat(u);
144
+ }
145
+ n.type === "linear" && (s && (n.videoClickTrackingURLTemplates = n.videoClickTrackingURLTemplates.concat(e.videoClickTrackingURLTemplates)), o && (n.videoCustomClickURLTemplates = n.videoCustomClickURLTemplates.concat(e.videoCustomClickURLTemplates)), !e.videoClickThroughURLTemplate || n.videoClickThroughURLTemplate !== null && n.videoClickThroughURLTemplate !== void 0 || (n.videoClickThroughURLTemplate = e.videoClickThroughURLTemplate)), n.type === "companion" && i.length && (n.variations || []).forEach((c) => {
146
+ c.companionClickTrackingURLTemplates = f.joinArrayOfUniqueTemplateObjs(c.companionClickTrackingURLTemplates, i);
147
+ });
148
+ }), e.adVerifications && (a.adVerifications = a.adVerifications.concat(e.adVerifications)), e.blockedAdCategories && (a.blockedAdCategories = a.blockedAdCategories.concat(e.blockedAdCategories)), (t = e.creatives) !== null && t !== void 0 && t.length) {
149
+ const n = e.creatives.filter((c) => {
150
+ var u;
151
+ return ((u = c.icons) === null || u === void 0 ? void 0 : u.length) && !c.mediaFiles.length;
152
+ });
153
+ n.length && (a.creatives = a.creatives.concat(n));
154
+ }
155
+ } };
156
+ function oe(a, e) {
157
+ const t = function() {
158
+ let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
159
+ const { id: i, adId: s, sequence: o, apiFramework: n } = w(r);
160
+ return { id: i, adId: s, sequence: o, apiFramework: n, type: "companion", required: null, variations: [] };
161
+ }(e);
162
+ return t.required = a.getAttribute("required") || null, t.variations = l.childrenByName(a, "Companion").map((r) => {
163
+ const i = function() {
164
+ let n = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
165
+ return { id: n.id || null, adType: "companionAd", width: n.width || 0, height: n.height || 0, assetWidth: n.assetWidth || null, assetHeight: n.assetHeight || null, expandedWidth: n.expandedWidth || null, expandedHeight: n.expandedHeight || null, apiFramework: n.apiFramework || null, adSlotId: n.adSlotId || null, pxratio: n.pxratio || "1", renderingMode: n.renderingMode || "default", staticResources: [], htmlResources: [], iframeResources: [], adParameters: null, altText: null, companionClickThroughURLTemplate: null, companionClickTrackingURLTemplates: [], trackingEvents: {} };
166
+ }(l.parseAttributes(r));
167
+ i.htmlResources = l.childrenByName(r, "HTMLResource").reduce((n, c) => {
168
+ const u = l.parseNodeText(c);
169
+ return u ? n.concat(u) : n;
170
+ }, []), i.iframeResources = l.childrenByName(r, "IFrameResource").reduce((n, c) => {
171
+ const u = l.parseNodeText(c);
172
+ return u ? n.concat(u) : n;
173
+ }, []), i.staticResources = l.childrenByName(r, "StaticResource").reduce((n, c) => {
174
+ const u = l.parseNodeText(c);
175
+ return u ? n.concat({ url: u, creativeType: c.getAttribute("creativeType") || null }) : n;
176
+ }, []), i.altText = l.parseNodeText(l.childByName(r, "AltText")) || null;
177
+ const s = l.childByName(r, "TrackingEvents");
178
+ s && l.childrenByName(s, "Tracking").forEach((n) => {
179
+ const c = n.getAttribute("event"), u = l.parseNodeText(n);
180
+ c && u && (Array.isArray(i.trackingEvents[c]) || (i.trackingEvents[c] = []), i.trackingEvents[c].push(u));
181
+ }), i.companionClickTrackingURLTemplates = l.childrenByName(r, "CompanionClickTracking").map((n) => ({ id: n.getAttribute("id") || null, url: l.parseNodeText(n) })), i.companionClickThroughURLTemplate = l.parseNodeText(l.childByName(r, "CompanionClickThrough")) || null;
182
+ const o = l.childByName(r, "AdParameters");
183
+ return o && (i.adParameters = { value: l.parseNodeText(o), xmlEncoded: o.getAttribute("xmlEncoded") || null }), i;
184
+ }), t;
185
+ }
186
+ function le(a, e) {
187
+ let t;
188
+ const r = function() {
189
+ let c = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
190
+ const { id: u, adId: d, sequence: v, apiFramework: m } = w(c);
191
+ return { id: u, adId: d, sequence: v, apiFramework: m, type: "linear", duration: 0, skipDelay: null, mediaFiles: [], mezzanine: null, interactiveCreativeFile: null, closedCaptionFiles: [], videoClickThroughURLTemplate: null, videoClickTrackingURLTemplates: [], videoCustomClickURLTemplates: [], adParameters: null, icons: [], trackingEvents: {} };
192
+ }(e);
193
+ r.duration = l.parseDuration(l.parseNodeText(l.childByName(a, "Duration")));
194
+ const i = a.getAttribute("skipoffset");
195
+ if (i == null) r.skipDelay = null;
196
+ else if (i.charAt(i.length - 1) === "%" && r.duration !== -1) {
197
+ const c = parseInt(i, 10);
198
+ r.skipDelay = r.duration * (c / 100);
199
+ } else r.skipDelay = l.parseDuration(i);
200
+ const s = l.childByName(a, "VideoClicks");
201
+ if (s) {
202
+ const c = l.childByName(s, "ClickThrough");
203
+ r.videoClickThroughURLTemplate = c ? { id: c.getAttribute("id") || null, url: l.parseNodeText(c) } : null, l.childrenByName(s, "ClickTracking").forEach((u) => {
204
+ r.videoClickTrackingURLTemplates.push({ id: u.getAttribute("id") || null, url: l.parseNodeText(u) });
205
+ }), l.childrenByName(s, "CustomClick").forEach((u) => {
206
+ r.videoCustomClickURLTemplates.push({ id: u.getAttribute("id") || null, url: l.parseNodeText(u) });
207
+ });
208
+ }
209
+ const o = l.childByName(a, "AdParameters");
210
+ o && (r.adParameters = { value: l.parseNodeText(o), xmlEncoded: o.getAttribute("xmlEncoded") || null }), l.childrenByName(a, "TrackingEvents").forEach((c) => {
211
+ l.childrenByName(c, "Tracking").forEach((u) => {
212
+ let d = u.getAttribute("event");
213
+ const v = l.parseNodeText(u);
214
+ if (d && v) {
215
+ if (d === "progress") {
216
+ if (t = u.getAttribute("offset"), !t) return;
217
+ d = t.charAt(t.length - 1) === "%" ? "progress-".concat(t) : "progress-".concat(l.parseDuration(t));
218
+ }
219
+ Array.isArray(r.trackingEvents[d]) || (r.trackingEvents[d] = []), r.trackingEvents[d].push(v);
220
+ }
221
+ });
222
+ }), l.childrenByName(a, "MediaFiles").forEach((c) => {
223
+ l.childrenByName(c, "MediaFile").forEach((h) => {
224
+ r.mediaFiles.push(function(p) {
225
+ const g = { id: null, fileURL: null, fileSize: 0, deliveryType: "progressive", mimeType: null, mediaType: null, codec: null, bitrate: 0, minBitrate: 0, maxBitrate: 0, width: 0, height: 0, apiFramework: null, scalable: null, maintainAspectRatio: null };
226
+ g.id = p.getAttribute("id"), g.fileURL = l.parseNodeText(p), g.deliveryType = p.getAttribute("delivery"), g.codec = p.getAttribute("codec"), g.mimeType = p.getAttribute("type"), g.mediaType = p.getAttribute("mediaType") || "2D", g.apiFramework = p.getAttribute("apiFramework"), g.fileSize = parseInt(p.getAttribute("fileSize") || 0), g.bitrate = parseInt(p.getAttribute("bitrate") || 0), g.minBitrate = parseInt(p.getAttribute("minBitrate") || 0), g.maxBitrate = parseInt(p.getAttribute("maxBitrate") || 0), g.width = parseInt(p.getAttribute("width") || 0), g.height = parseInt(p.getAttribute("height") || 0);
227
+ const T = p.getAttribute("scalable");
228
+ T && typeof T == "string" && (g.scalable = l.parseBoolean(T));
229
+ const A = p.getAttribute("maintainAspectRatio");
230
+ return A && typeof A == "string" && (g.maintainAspectRatio = l.parseBoolean(A)), g;
231
+ }(h));
232
+ });
233
+ const u = l.childByName(c, "InteractiveCreativeFile");
234
+ u && (r.interactiveCreativeFile = function(h) {
235
+ const p = function() {
236
+ let g = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
237
+ return { type: g.type || null, apiFramework: g.apiFramework || null, variableDuration: l.parseBoolean(g.variableDuration), fileURL: null };
238
+ }(l.parseAttributes(h));
239
+ return p.fileURL = l.parseNodeText(h), p;
240
+ }(u));
241
+ const d = l.childByName(c, "ClosedCaptionFiles");
242
+ d && l.childrenByName(d, "ClosedCaptionFile").forEach((h) => {
243
+ const p = function() {
244
+ let g = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
245
+ return { type: g.type || null, language: g.language || null, fileURL: null };
246
+ }(l.parseAttributes(h));
247
+ p.fileURL = l.parseNodeText(h), r.closedCaptionFiles.push(p);
248
+ });
249
+ const v = l.childByName(c, "Mezzanine"), m = function(h, p) {
250
+ const g = {};
251
+ let T = !1;
252
+ return p.forEach((A) => {
253
+ h && h.getAttribute(A) ? g[A] = h.getAttribute(A) : T = !0;
254
+ }), T ? null : g;
255
+ }(v, ["delivery", "type", "width", "height"]);
256
+ if (m) {
257
+ const h = { id: null, fileURL: null, delivery: null, codec: null, type: null, width: 0, height: 0, fileSize: 0, mediaType: "2D" };
258
+ h.id = v.getAttribute("id"), h.fileURL = l.parseNodeText(v), h.delivery = m.delivery, h.codec = v.getAttribute("codec"), h.type = m.type, h.width = parseInt(m.width, 10), h.height = parseInt(m.height, 10), h.fileSize = parseInt(v.getAttribute("fileSize"), 10), h.mediaType = v.getAttribute("mediaType") || "2D", r.mezzanine = h;
259
+ }
260
+ });
261
+ const n = l.childByName(a, "Icons");
262
+ return n && l.childrenByName(n, "Icon").forEach((c) => {
263
+ r.icons.push(function(u) {
264
+ const d = { program: null, height: 0, width: 0, xPosition: 0, yPosition: 0, apiFramework: null, offset: null, duration: 0, type: null, staticResource: null, htmlResource: null, iframeResource: null, pxratio: "1", iconClickThroughURLTemplate: null, iconClickTrackingURLTemplates: [], iconViewTrackingURLTemplate: null, iconClickFallbackImages: [] };
265
+ d.program = u.getAttribute("program"), d.height = parseInt(u.getAttribute("height") || 0), d.width = parseInt(u.getAttribute("width") || 0), d.xPosition = function(m) {
266
+ return ["left", "right"].indexOf(m) !== -1 ? m : parseInt(m || 0);
267
+ }(u.getAttribute("xPosition")), d.yPosition = function(m) {
268
+ return ["top", "bottom"].indexOf(m) !== -1 ? m : parseInt(m || 0);
269
+ }(u.getAttribute("yPosition")), d.apiFramework = u.getAttribute("apiFramework"), d.pxratio = u.getAttribute("pxratio") || "1", d.offset = l.parseDuration(u.getAttribute("offset")), d.duration = l.parseDuration(u.getAttribute("duration")), l.childrenByName(u, "HTMLResource").forEach((m) => {
270
+ d.type = m.getAttribute("creativeType") || "text/html", d.htmlResource = l.parseNodeText(m);
271
+ }), l.childrenByName(u, "IFrameResource").forEach((m) => {
272
+ d.type = m.getAttribute("creativeType") || 0, d.iframeResource = l.parseNodeText(m);
273
+ }), l.childrenByName(u, "StaticResource").forEach((m) => {
274
+ d.type = m.getAttribute("creativeType") || 0, d.staticResource = l.parseNodeText(m);
275
+ });
276
+ const v = l.childByName(u, "IconClicks");
277
+ if (v) {
278
+ d.iconClickThroughURLTemplate = l.parseNodeText(l.childByName(v, "IconClickThrough")), l.childrenByName(v, "IconClickTracking").forEach((h) => {
279
+ d.iconClickTrackingURLTemplates.push({ id: h.getAttribute("id") || null, url: l.parseNodeText(h) });
280
+ });
281
+ const m = l.childByName(v, "IconClickFallbackImages");
282
+ m && l.childrenByName(m, "IconClickFallbackImage").forEach((h) => {
283
+ d.iconClickFallbackImages.push({ url: l.parseNodeText(h) || null, width: h.getAttribute("width") || null, height: h.getAttribute("height") || null });
284
+ });
285
+ }
286
+ return d.iconViewTrackingURLTemplate = l.parseNodeText(l.childByName(u, "IconViewTracking")), d;
287
+ }(c));
288
+ }), r;
289
+ }
290
+ function ce(a, e) {
291
+ const t = function() {
292
+ let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
293
+ const { id: i, adId: s, sequence: o, apiFramework: n } = w(r);
294
+ return { id: i, adId: s, sequence: o, apiFramework: n, type: "nonlinear", variations: [], trackingEvents: {} };
295
+ }(e);
296
+ return l.childrenByName(a, "TrackingEvents").forEach((r) => {
297
+ let i, s;
298
+ l.childrenByName(r, "Tracking").forEach((o) => {
299
+ i = o.getAttribute("event"), s = l.parseNodeText(o), i && s && (Array.isArray(t.trackingEvents[i]) || (t.trackingEvents[i] = []), t.trackingEvents[i].push(s));
300
+ });
301
+ }), l.childrenByName(a, "NonLinear").forEach((r) => {
302
+ const i = { id: null, width: 0, height: 0, expandedWidth: 0, expandedHeight: 0, scalable: !0, maintainAspectRatio: !0, minSuggestedDuration: 0, apiFramework: "static", adType: "nonLinearAd", type: null, staticResource: null, htmlResource: null, iframeResource: null, nonlinearClickThroughURLTemplate: null, nonlinearClickTrackingURLTemplates: [], adParameters: null };
303
+ i.id = r.getAttribute("id") || null, i.width = r.getAttribute("width"), i.height = r.getAttribute("height"), i.expandedWidth = r.getAttribute("expandedWidth"), i.expandedHeight = r.getAttribute("expandedHeight"), i.scalable = l.parseBoolean(r.getAttribute("scalable")), i.maintainAspectRatio = l.parseBoolean(r.getAttribute("maintainAspectRatio")), i.minSuggestedDuration = l.parseDuration(r.getAttribute("minSuggestedDuration")), i.apiFramework = r.getAttribute("apiFramework"), l.childrenByName(r, "HTMLResource").forEach((o) => {
304
+ i.type = o.getAttribute("creativeType") || "text/html", i.htmlResource = l.parseNodeText(o);
305
+ }), l.childrenByName(r, "IFrameResource").forEach((o) => {
306
+ i.type = o.getAttribute("creativeType") || 0, i.iframeResource = l.parseNodeText(o);
307
+ }), l.childrenByName(r, "StaticResource").forEach((o) => {
308
+ i.type = o.getAttribute("creativeType") || 0, i.staticResource = l.parseNodeText(o);
309
+ });
310
+ const s = l.childByName(r, "AdParameters");
311
+ s && (i.adParameters = { value: l.parseNodeText(s), xmlEncoded: s.getAttribute("xmlEncoded") || null }), i.nonlinearClickThroughURLTemplate = l.parseNodeText(l.childByName(r, "NonLinearClickThrough")), l.childrenByName(r, "NonLinearClickTracking").forEach((o) => {
312
+ i.nonlinearClickTrackingURLTemplates.push({ id: o.getAttribute("id") || null, url: l.parseNodeText(o) });
313
+ }), t.variations.push(i);
314
+ }), t;
315
+ }
316
+ function F(a) {
317
+ const e = [];
318
+ return a.forEach((t) => {
319
+ const r = X(t);
320
+ r && e.push(r);
321
+ }), e;
322
+ }
323
+ function X(a) {
324
+ if (a.nodeName === "#comment") return null;
325
+ const e = { name: null, value: null, attributes: {}, children: [] }, t = a.attributes, r = a.childNodes;
326
+ if (e.name = a.nodeName, a.attributes) {
327
+ for (const s in t) if (t.hasOwnProperty(s)) {
328
+ const o = t[s];
329
+ o.nodeName && o.nodeValue && (e.attributes[o.nodeName] = o.nodeValue);
330
+ }
331
+ }
332
+ for (const s in r) if (r.hasOwnProperty(s)) {
333
+ const o = X(r[s]);
334
+ o && e.children.push(o);
335
+ }
336
+ if (e.children.length === 0 || e.children.length === 1 && ["#cdata-section", "#text"].indexOf(e.children[0].name) >= 0) {
337
+ const s = l.parseNodeText(a);
338
+ s !== "" && (e.value = s), e.children = [];
339
+ }
340
+ return (i = e).value === null && Object.keys(i.attributes).length === 0 && i.children.length === 0 ? null : e;
341
+ var i;
342
+ }
343
+ function ue(a) {
344
+ return a.getAttribute("AdID") || a.getAttribute("adID") || a.getAttribute("adId") || null;
345
+ }
346
+ const y = { Wrapper: { subElements: ["VASTAdTagURI", "Impression"] }, BlockedAdCategories: { attributes: ["authority"] }, InLine: { subElements: ["AdSystem", "AdTitle", "Impression", "AdServingId", "Creatives"] }, Category: { attributes: ["authority"] }, Pricing: { attributes: ["model", "currency"] }, Verification: { oneOfinLineResources: ["JavaScriptResource", "ExecutableResource"], attributes: ["vendor"] }, UniversalAdId: { attributes: ["idRegistry"] }, JavaScriptResource: { attributes: ["apiFramework", "browserOptional"] }, ExecutableResource: { attributes: ["apiFramework", "type"] }, Tracking: { attributes: ["event"] }, Creatives: { subElements: ["Creative"] }, Creative: { subElements: ["UniversalAdId"] }, Linear: { subElements: ["MediaFiles", "Duration"] }, MediaFiles: { subElements: ["MediaFile"] }, MediaFile: { attributes: ["delivery", "type", "width", "height"] }, Mezzanine: { attributes: ["delivery", "type", "width", "height"] }, NonLinear: { oneOfinLineResources: ["StaticResource", "IFrameResource", "HTMLResource"], attributes: ["width", "height"] }, Companion: { oneOfinLineResources: ["StaticResource", "IFrameResource", "HTMLResource"], attributes: ["width", "height"] }, StaticResource: { attributes: ["creativeType"] }, Icons: { subElements: ["Icon"] }, Icon: { oneOfinLineResources: ["StaticResource", "IFrameResource", "HTMLResource"] } };
347
+ function B(a, e) {
348
+ if (!y[a.nodeName] || !y[a.nodeName].attributes) return;
349
+ const t = y[a.nodeName].attributes.filter((r) => !a.getAttribute(r));
350
+ t.length > 0 && k({ name: a.nodeName, parentName: a.parentNode.nodeName, attributes: t }, e);
351
+ }
352
+ function M(a, e, t) {
353
+ const r = y[a.nodeName], i = !t && a.nodeName !== "Wrapper";
354
+ if (!(!r || i)) {
355
+ if (r.subElements) {
356
+ const s = r.subElements.filter((o) => !l.childByName(a, o));
357
+ s.length > 0 && k({ name: a.nodeName, parentName: a.parentNode.nodeName, subElements: s }, e);
358
+ }
359
+ !t || !r.oneOfinLineResources || r.oneOfinLineResources.some((s) => l.childByName(a, s)) || k({ name: a.nodeName, parentName: a.parentNode.nodeName, oneOfResources: r.oneOfinLineResources }, e);
360
+ }
361
+ }
362
+ function W(a) {
363
+ return a.children && a.children.length !== 0;
364
+ }
365
+ function k(a, e) {
366
+ let { name: t, parentName: r, attributes: i, subElements: s, oneOfResources: o } = a, n = "Element '".concat(t, "'");
367
+ n += i ? " missing required attribute(s) '".concat(i.join(", "), "' ") : s ? " missing required sub element(s) '".concat(s.join(", "), "' ") : o ? " must provide one of the following '".concat(o.join(", "), "' ") : " is empty", e("VAST-warning", { message: n, parentElement: r, specVersion: 4.1 });
368
+ }
369
+ const de = { verifyRequiredValues: function a(e, t, r) {
370
+ if (e && e.nodeName) if (e.nodeName === "InLine" && (r = !0), B(e, t), W(e)) {
371
+ M(e, t, r);
372
+ for (let i = 0; i < e.children.length; i++) a(e.children[i], t, r);
373
+ } else l.parseNodeText(e).length === 0 && k({ name: e.nodeName, parentName: e.parentNode.nodeName }, t);
374
+ }, hasSubElements: W, emitMissingValueWarning: k, verifyRequiredAttributes: B, verifyRequiredSubElements: M };
375
+ function he(a, e) {
376
+ let { allowMultipleAds: t, followAdditionalWrappers: r } = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
377
+ const i = Array.from(a.childNodes).filter((s) => {
378
+ const o = s.nodeName.toLowerCase();
379
+ return o === "inline" || r !== !1 && o === "wrapper";
380
+ });
381
+ for (const s of i) {
382
+ if (l.copyNodeAttribute("id", a, s), l.copyNodeAttribute("sequence", a, s), l.copyNodeAttribute("adType", a, s), s.nodeName === "Wrapper") return { ad: pe(s, e), type: "WRAPPER" };
383
+ if (s.nodeName === "InLine") return { ad: me(s, e, { allowMultipleAds: t }), type: "INLINE" };
384
+ const o = s.nodeName.toLowerCase();
385
+ e("VAST-warning", { message: "<".concat(s.nodeName, o === "inline" ? "> must be written <InLine>" : "> must be written <Wrapper>"), wrongNode: s });
386
+ }
387
+ }
388
+ function me(a, e) {
389
+ let { allowMultipleAds: t } = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
390
+ return t === !1 && a.getAttribute("sequence") ? null : Z(a, e);
391
+ }
392
+ function Z(a, e) {
393
+ let t = [];
394
+ e && de.verifyRequiredValues(a, e);
395
+ const r = Array.from(a.childNodes), i = function() {
396
+ let s = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
397
+ return { id: s.id || null, sequence: s.sequence || null, adType: s.adType || null, adServingId: null, categories: [], expires: null, viewableImpression: [], system: null, title: null, description: null, advertiser: null, pricing: null, survey: null, errorURLTemplates: [], impressionURLTemplates: [], creatives: [], extensions: [], adVerifications: [], blockedAdCategories: [], followAdditionalWrappers: !0, allowMultipleAds: !1, fallbackOnNoAd: null };
398
+ }(l.parseAttributes(a));
399
+ return r.forEach((s) => {
400
+ switch (s.nodeName) {
401
+ case "Error":
402
+ i.errorURLTemplates.push(l.parseNodeText(s));
403
+ break;
404
+ case "Impression":
405
+ i.impressionURLTemplates.push({ id: s.getAttribute("id") || null, url: l.parseNodeText(s) });
406
+ break;
407
+ case "Creatives":
408
+ i.creatives = function(o) {
409
+ const n = [];
410
+ return o.forEach((c) => {
411
+ const u = { id: c.getAttribute("id") || null, adId: ue(c), sequence: c.getAttribute("sequence") || null, apiFramework: c.getAttribute("apiFramework") || null }, d = [];
412
+ let v;
413
+ l.childrenByName(c, "UniversalAdId").forEach((h) => {
414
+ const p = { idRegistry: h.getAttribute("idRegistry") || "unknown", value: l.parseNodeText(h) };
415
+ d.push(p);
416
+ });
417
+ const m = l.childByName(c, "CreativeExtensions");
418
+ m && (v = F(l.childrenByName(m, "CreativeExtension")));
419
+ for (const h in c.childNodes) {
420
+ const p = c.childNodes[h];
421
+ let g;
422
+ switch (p.nodeName) {
423
+ case "Linear":
424
+ g = le(p, u);
425
+ break;
426
+ case "NonLinearAds":
427
+ g = ce(p, u);
428
+ break;
429
+ case "CompanionAds":
430
+ g = oe(p, u);
431
+ }
432
+ g && (d && (g.universalAdIds = d), v && (g.creativeExtensions = v), n.push(g));
433
+ }
434
+ }), n;
435
+ }(l.childrenByName(s, "Creative"));
436
+ break;
437
+ case "Extensions": {
438
+ const o = l.childrenByName(s, "Extension");
439
+ i.extensions = F(o), i.adVerifications.length || (t = function(n) {
440
+ let c = null, u = [];
441
+ return n.some((d) => c = l.childByName(d, "AdVerifications")), c && (u = K(l.childrenByName(c, "Verification"))), u;
442
+ }(o));
443
+ break;
444
+ }
445
+ case "AdVerifications":
446
+ i.adVerifications = K(l.childrenByName(s, "Verification"));
447
+ break;
448
+ case "AdSystem":
449
+ i.system = { value: l.parseNodeText(s), version: s.getAttribute("version") || null };
450
+ break;
451
+ case "AdTitle":
452
+ i.title = l.parseNodeText(s);
453
+ break;
454
+ case "AdServingId":
455
+ i.adServingId = l.parseNodeText(s);
456
+ break;
457
+ case "Category":
458
+ i.categories.push({ authority: s.getAttribute("authority") || null, value: l.parseNodeText(s) });
459
+ break;
460
+ case "Expires":
461
+ i.expires = parseInt(l.parseNodeText(s), 10);
462
+ break;
463
+ case "ViewableImpression":
464
+ i.viewableImpression.push(function(o) {
465
+ const n = (c, u) => {
466
+ const d = l.parseNodeText(u);
467
+ return d && c.push(d), c;
468
+ };
469
+ return { id: o.getAttribute("id") || null, viewable: l.childrenByName(o, "Viewable").reduce(n, []), notViewable: l.childrenByName(o, "NotViewable").reduce(n, []), viewUndetermined: l.childrenByName(o, "ViewUndetermined").reduce(n, []) };
470
+ }(s));
471
+ break;
472
+ case "Description":
473
+ i.description = l.parseNodeText(s);
474
+ break;
475
+ case "Advertiser":
476
+ i.advertiser = { id: s.getAttribute("id") || null, value: l.parseNodeText(s) };
477
+ break;
478
+ case "Pricing":
479
+ i.pricing = { value: l.parseNodeText(s), model: s.getAttribute("model") || null, currency: s.getAttribute("currency") || null };
480
+ break;
481
+ case "Survey":
482
+ i.survey = { value: l.parseNodeText(s), type: s.getAttribute("type") || null };
483
+ break;
484
+ case "BlockedAdCategories":
485
+ i.blockedAdCategories.push({ authority: s.getAttribute("authority") || null, value: l.parseNodeText(s) });
486
+ }
487
+ }), t.length && (i.adVerifications = i.adVerifications.concat(t)), i;
488
+ }
489
+ function pe(a, e) {
490
+ const t = Z(a, e), r = a.getAttribute("followAdditionalWrappers"), i = a.getAttribute("allowMultipleAds"), s = a.getAttribute("fallbackOnNoAd");
491
+ t.followAdditionalWrappers = !r || l.parseBoolean(r), t.allowMultipleAds = !!i && l.parseBoolean(i), t.fallbackOnNoAd = s ? l.parseBoolean(s) : null;
492
+ let o = l.childByName(a, "VASTAdTagURI");
493
+ if (o ? t.nextWrapperURL = l.parseNodeText(o) : (o = l.childByName(a, "VASTAdTagURL"), o && (t.nextWrapperURL = l.parseNodeText(l.childByName(o, "URL")))), t.creatives.forEach((n) => {
494
+ if (["linear", "nonlinear"].includes(n.type)) {
495
+ if (n.trackingEvents) {
496
+ t.trackingEvents || (t.trackingEvents = {}), t.trackingEvents[n.type] || (t.trackingEvents[n.type] = {});
497
+ for (const c in n.trackingEvents) {
498
+ const u = n.trackingEvents[c];
499
+ Array.isArray(t.trackingEvents[n.type][c]) || (t.trackingEvents[n.type][c] = []), u.forEach((d) => {
500
+ t.trackingEvents[n.type][c].push(d);
501
+ });
502
+ }
503
+ }
504
+ n.videoClickTrackingURLTemplates && (Array.isArray(t.videoClickTrackingURLTemplates) || (t.videoClickTrackingURLTemplates = []), n.videoClickTrackingURLTemplates.forEach((c) => {
505
+ t.videoClickTrackingURLTemplates.push(c);
506
+ })), n.videoClickThroughURLTemplate && (t.videoClickThroughURLTemplate = n.videoClickThroughURLTemplate), n.videoCustomClickURLTemplates && (Array.isArray(t.videoCustomClickURLTemplates) || (t.videoCustomClickURLTemplates = []), n.videoCustomClickURLTemplates.forEach((c) => {
507
+ t.videoCustomClickURLTemplates.push(c);
508
+ }));
509
+ }
510
+ }), t.nextWrapperURL) return t;
511
+ }
512
+ function K(a) {
513
+ const e = [];
514
+ return a.forEach((t) => {
515
+ const r = { resource: null, vendor: null, browserOptional: !1, apiFramework: null, type: null, parameters: null, trackingEvents: {} }, i = Array.from(t.childNodes);
516
+ l.assignAttributes(t.attributes, r), i.forEach((o) => {
517
+ let { nodeName: n, textContent: c, attributes: u } = o;
518
+ switch (n) {
519
+ case "JavaScriptResource":
520
+ case "ExecutableResource":
521
+ r.resource = c.trim(), l.assignAttributes(u, r);
522
+ break;
523
+ case "VerificationParameters":
524
+ r.parameters = c.trim();
525
+ }
526
+ });
527
+ const s = l.childByName(t, "TrackingEvents");
528
+ s && l.childrenByName(s, "Tracking").forEach((o) => {
529
+ const n = o.getAttribute("event"), c = l.parseNodeText(o);
530
+ n && c && (Array.isArray(r.trackingEvents[n]) || (r.trackingEvents[n] = []), r.trackingEvents[n].push(c));
531
+ }), e.push(r);
532
+ }), e;
533
+ }
534
+ class J {
535
+ constructor() {
536
+ this._handlers = [];
537
+ }
538
+ on(e, t) {
539
+ if (typeof t != "function") throw new TypeError("The handler argument must be of type Function. Received type ".concat(typeof t));
540
+ if (!e) throw new TypeError("The event argument must be of type String. Received type ".concat(typeof e));
541
+ return this._handlers.push({ event: e, handler: t }), this;
542
+ }
543
+ once(e, t) {
544
+ return this.on(e, function(r, i, s) {
545
+ const o = { fired: !1, wrapFn: void 0 };
546
+ function n() {
547
+ o.fired || (r.off(i, o.wrapFn), o.fired = !0, s.bind(r)(...arguments));
548
+ }
549
+ return o.wrapFn = n, n;
550
+ }(this, e, t));
551
+ }
552
+ off(e, t) {
553
+ return this._handlers = this._handlers.filter((r) => r.event !== e || r.handler !== t), this;
554
+ }
555
+ emit(e) {
556
+ for (var t = arguments.length, r = new Array(t > 1 ? t - 1 : 0), i = 1; i < t; i++) r[i - 1] = arguments[i];
557
+ let s = !1;
558
+ return this._handlers.forEach((o) => {
559
+ o.event === "*" && (s = !0, o.handler(e, ...r)), o.event === e && (s = !0, o.handler(...r));
560
+ }), s;
561
+ }
562
+ removeAllListeners(e) {
563
+ return e ? (this._handlers = this._handlers.filter((t) => t.event !== e), this) : (this._handlers = [], this);
564
+ }
565
+ listenerCount(e) {
566
+ return this._handlers.filter((t) => t.event === e).length;
567
+ }
568
+ listeners(e) {
569
+ return this._handlers.reduce((t, r) => (r.event === e && t.push(r.handler), t), []);
570
+ }
571
+ eventNames() {
572
+ return this._handlers.map((e) => e.event);
573
+ }
574
+ }
575
+ let j = 0, b = 0;
576
+ const $ = (a, e) => {
577
+ !a || !e || a <= 0 || e <= 0 || (b = (b * j + 8 * a / e) / ++j);
578
+ }, ge = { ERRORCODE: 900, extensions: [] }, q = "VAST response version not supported";
579
+ class ve extends J {
580
+ constructor() {
581
+ let { fetcher: e } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
582
+ super(), this.maxWrapperDepth = null, this.rootErrorURLTemplates = [], this.errorURLTemplates = [], this.remainingAds = [], this.parsingOptions = {}, this.fetcher = e || null;
583
+ }
584
+ trackVastError(e, t) {
585
+ for (var r = arguments.length, i = new Array(r > 2 ? r - 2 : 0), s = 2; s < r; s++) i[s - 2] = arguments[s];
586
+ this.emit("VAST-error", Object.assign({}, ge, t, ...i)), f.track(e, t);
587
+ }
588
+ getErrorURLTemplates() {
589
+ return this.rootErrorURLTemplates.concat(this.errorURLTemplates);
590
+ }
591
+ getEstimatedBitrate() {
592
+ return b;
593
+ }
594
+ initParsingStatus() {
595
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
596
+ this.maxWrapperDepth = e.wrapperLimit || 10, this.parsingOptions = { allowMultipleAds: e.allowMultipleAds }, this.rootURL = "", this.resetParsingStatus(), $(e.byteLength, e.requestDuration);
597
+ }
598
+ resetParsingStatus() {
599
+ this.errorURLTemplates = [], this.rootErrorURLTemplates = [], this.vastVersion = null;
600
+ }
601
+ getRemainingAds(e) {
602
+ if (this.remainingAds.length === 0) return Promise.reject(new Error("No more ads are available for the given VAST"));
603
+ const t = e ? this.remainingAds : [this.remainingAds.shift()];
604
+ return this.errorURLTemplates = [], this.resolveAds(t, { wrapperDepth: 0, url: this.rootURL }).then((r) => this.buildVASTResponse(r));
605
+ }
606
+ parseVAST(e) {
607
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
608
+ return this.initParsingStatus(t), t.isRootVAST = !0, this.parse(e, t).then((r) => this.buildVASTResponse(r));
609
+ }
610
+ buildVASTResponse(e) {
611
+ const t = function(r) {
612
+ let { ads: i, errorURLTemplates: s, version: o } = r;
613
+ return { ads: i || [], errorURLTemplates: s || [], version: o || null };
614
+ }({ ads: e, errorURLTemplates: this.getErrorURLTemplates(), version: this.vastVersion });
615
+ return this.completeWrapperResolving(t), t;
616
+ }
617
+ parseVastXml(e, t) {
618
+ let { isRootVAST: r = !1, url: i = null, wrapperDepth: s = 0, allowMultipleAds: o, followAdditionalWrappers: n } = t;
619
+ if (!e || !e.documentElement || e.documentElement.nodeName !== "VAST") {
620
+ var c;
621
+ this.emit("VAST-ad-parsed", { type: "ERROR", url: i, wrapperDepth: s });
622
+ const m = (e == null || (c = e.documentElement) === null || c === void 0 ? void 0 : c.nodeName) === "VideoAdServingTemplate";
623
+ throw new Error(m ? q : "Invalid VAST XMLDocument");
624
+ }
625
+ const u = [], d = e.documentElement.childNodes, v = e.documentElement.getAttribute("version");
626
+ r && v && (this.vastVersion = v);
627
+ for (const m in d) {
628
+ const h = d[m];
629
+ if (h.nodeName === "Error") {
630
+ const p = l.parseNodeText(h);
631
+ r ? this.rootErrorURLTemplates.push(p) : this.errorURLTemplates.push(p);
632
+ } else if (h.nodeName === "Ad") {
633
+ if (this.vastVersion && parseFloat(this.vastVersion) < 3) o = !0;
634
+ else if (o === !1 && u.length > 1) break;
635
+ const p = he(h, this.emit.bind(this), { allowMultipleAds: o, followAdditionalWrappers: n });
636
+ p.ad ? (u.push(p.ad), this.emit("VAST-ad-parsed", { type: p.type, url: i, wrapperDepth: s, adIndex: u.length - 1, vastVersion: v })) : this.trackVastError(this.getErrorURLTemplates(), { ERRORCODE: 101 });
637
+ }
638
+ }
639
+ return u;
640
+ }
641
+ parse(e) {
642
+ let { url: t = null, resolveAll: r = !0, wrapperSequence: i = null, previousUrl: s = null, wrapperDepth: o = 0, isRootVAST: n = !1, followAdditionalWrappers: c, allowMultipleAds: u } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, d = [];
643
+ this.vastVersion && parseFloat(this.vastVersion) < 3 && n && (u = !0);
644
+ try {
645
+ d = this.parseVastXml(e, { isRootVAST: n, url: t, wrapperDepth: o, allowMultipleAds: u, followAdditionalWrappers: c });
646
+ } catch (v) {
647
+ return Promise.reject(v);
648
+ }
649
+ if (d.length === 1 && i != null && (d[0].sequence = i), r === !1) {
650
+ const v = l.getSortedAdPods(d), m = l.getStandAloneAds(d);
651
+ v.length ? d = v : m.length && (d = [m.shift()]), this.remainingAds = m;
652
+ }
653
+ return this.resolveAds(d, { wrapperDepth: o, previousUrl: s, url: t });
654
+ }
655
+ resolveAds() {
656
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [], { wrapperDepth: t, previousUrl: r, url: i } = arguments.length > 1 ? arguments[1] : void 0;
657
+ const s = [];
658
+ return r = i, e.forEach((o) => {
659
+ const n = this.resolveWrappers(o, t, r);
660
+ s.push(n);
661
+ }), Promise.all(s).then((o) => f.flatten(o));
662
+ }
663
+ resolveWrappers(e, t, r) {
664
+ const i = { ...e };
665
+ return new Promise((s) => {
666
+ var o;
667
+ if (t++, !i.nextWrapperURL) return delete i.nextWrapperURL, s(i);
668
+ if (!this.fetcher) return i.VASTAdTagURI = i.nextWrapperURL, delete i.nextWrapperURL, s(i);
669
+ if (t >= this.maxWrapperDepth) return i.errorCode = 302, delete i.nextWrapperURL, s(i);
670
+ i.nextWrapperURL = l.resolveVastAdTagURI(i.nextWrapperURL, r);
671
+ const n = (o = this.parsingOptions.allowMultipleAds) !== null && o !== void 0 ? o : i.allowMultipleAds, c = i.sequence;
672
+ this.fetcher.fetchVAST({ url: i.nextWrapperURL, emitter: this.emit.bind(this), maxWrapperDepth: this.maxWrapperDepth }).then((u) => this.parse(u, { url: i.nextWrapperURL, previousUrl: r, wrapperSequence: c, wrapperDepth: t, followAdditionalWrappers: i.followAdditionalWrappers, allowMultipleAds: n }).then((d) => {
673
+ if (delete i.nextWrapperURL, d.length === 0) return i.creatives = [], s(i);
674
+ d.forEach((v) => {
675
+ v && l.mergeWrapperAdData(v, i);
676
+ }), s(d);
677
+ })).catch((u) => {
678
+ i.errorCode = u.message === q ? 102 : 301, i.errorMessage = u.message, s(i);
679
+ });
680
+ });
681
+ }
682
+ completeWrapperResolving(e) {
683
+ if (e.ads.length === 0) this.trackVastError(e.errorURLTemplates, { ERRORCODE: 303 });
684
+ else for (let t = e.ads.length - 1; t >= 0; t--) {
685
+ const r = e.ads[t], i = !r.creatives.some((s) => {
686
+ var o;
687
+ return ((o = s.mediaFiles) === null || o === void 0 ? void 0 : o.length) > 0;
688
+ });
689
+ !r.errorCode && !i || r.VASTAdTagURI || (this.trackVastError(r.errorURLTemplates.concat(e.errorURLTemplates), { ERRORCODE: r.errorCode || 303 }, { ERRORMESSAGE: r.errorMessage || "" }, { extensions: r.extensions }, { system: r.system }), e.ads.splice(t, 1));
690
+ }
691
+ }
692
+ }
693
+ let R = null;
694
+ const fe = { data: {}, length: 0, getItem(a) {
695
+ return this.data[a];
696
+ }, setItem(a, e) {
697
+ this.data[a] = e, this.length = Object.keys(this.data).length;
698
+ }, removeItem(a) {
699
+ delete this.data[a], this.length = Object.keys(this.data).length;
700
+ }, clear() {
701
+ this.data = {}, this.length = 0;
702
+ } };
703
+ class Te {
704
+ constructor() {
705
+ this.storage = this.initStorage();
706
+ }
707
+ initStorage() {
708
+ if (R) return R;
709
+ try {
710
+ R = typeof window < "u" && window !== null ? window.localStorage || window.sessionStorage : null;
711
+ } catch {
712
+ R = null;
713
+ }
714
+ return R && !this.isStorageDisabled(R) || (R = fe, R.clear()), R;
715
+ }
716
+ isStorageDisabled(e) {
717
+ const t = "__VASTStorage__";
718
+ try {
719
+ if (e.setItem(t, t), e.getItem(t) !== t) return e.removeItem(t), !0;
720
+ } catch {
721
+ return !0;
722
+ }
723
+ return e.removeItem(t), !1;
724
+ }
725
+ getItem(e) {
726
+ return this.storage.getItem(e);
727
+ }
728
+ setItem(e, t) {
729
+ return this.storage.setItem(e, t);
730
+ }
731
+ removeItem(e) {
732
+ return this.storage.removeItem(e);
733
+ }
734
+ clear() {
735
+ return this.storage.clear();
736
+ }
737
+ }
738
+ const N = 12e4, Ae = { get: async function(a, e) {
739
+ try {
740
+ const t = new AbortController(), r = setTimeout(() => {
741
+ throw t.abort(), new Error("URLHandler: Request timed out after ".concat(e.timeout || N, " ms (408)"));
742
+ }, e.timeout || N), i = await fetch(a, { ...e, signal: t.signal, credentials: e.withCredentials ? "include" : "omit" }).finally(() => {
743
+ clearTimeout(r);
744
+ }), s = function(o) {
745
+ return f.isBrowserEnvironment() && window.location.protocol === "https:" && o.url.includes("http://") ? "URLHandler: Cannot go from HTTPS to HTTP." : o.status === 200 && o.ok ? null : "URLHandler: ".concat(o.statusText, " (").concat(o.status, ")");
746
+ }(i);
747
+ return s ? { error: new Error(s), statusCode: i.status } : async function(o) {
748
+ const n = await o.text();
749
+ let c;
750
+ return c = f.isBrowserEnvironment() ? new DOMParser() : new (await import("./index-DXvAPWiE.js").then((u) => u.i)).DOMParser(), { xml: c.parseFromString(n, "text/xml"), details: { byteLength: n.length, statusCode: o.status, rawXml: n } };
751
+ }(i);
752
+ } catch (t) {
753
+ return { error: t, statusCode: t.name === "AbortError" ? 408 : null };
754
+ }
755
+ } };
756
+ class Re {
757
+ constructor() {
758
+ this.URLTemplateFilters = [];
759
+ }
760
+ setOptions() {
761
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
762
+ this.urlHandler = e.urlHandler || e.urlhandler || Ae, this.fetchingOptions = { timeout: e.timeout || N, withCredentials: !!e.withCredentials };
763
+ }
764
+ addURLTemplateFilter(e) {
765
+ typeof e == "function" && this.URLTemplateFilters.push(e);
766
+ }
767
+ removeLastURLTemplateFilter() {
768
+ this.URLTemplateFilters.pop();
769
+ }
770
+ countURLTemplateFilters() {
771
+ return this.URLTemplateFilters.length;
772
+ }
773
+ clearURLTemplateFilters() {
774
+ this.URLTemplateFilters = [];
775
+ }
776
+ async fetchVAST(e) {
777
+ var t;
778
+ let { url: r, maxWrapperDepth: i, emitter: s, wrapperDepth: o = 0, previousUrl: n = null, wrapperAd: c = null } = e;
779
+ const u = Date.now();
780
+ this.URLTemplateFilters.forEach((m) => {
781
+ r = m(r);
782
+ }), s("VAST-resolving", { url: r, previousUrl: n, wrapperDepth: o, maxWrapperDepth: i, timeout: this.fetchingOptions.timeout, wrapperAd: c });
783
+ const d = await this.urlHandler.get(r, this.fetchingOptions), v = Math.round(Date.now() - u);
784
+ if (s("VAST-resolved", { url: r, previousUrl: n, wrapperDepth: o, error: (d == null ? void 0 : d.error) || null, duration: v, statusCode: (d == null ? void 0 : d.statusCode) || null, ...d == null ? void 0 : d.details }), $(d == null || (t = d.details) === null || t === void 0 ? void 0 : t.byteLength, v), d.error) throw new Error(d.error);
785
+ return d.xml;
786
+ }
787
+ }
788
+ class ke {
789
+ constructor() {
790
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, r = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : new Te();
791
+ this.cappingFreeLunch = e, this.cappingMinimumTimeInterval = t, this.fetcher = new Re(), this.vastParser = new ve({ fetcher: this.fetcher }), this.storage = r, this.lastSuccessfulAd === void 0 && (this.lastSuccessfulAd = 0), this.totalCalls === void 0 && (this.totalCalls = 0), this.totalCallsTimeout === void 0 && (this.totalCallsTimeout = 0);
792
+ }
793
+ addURLTemplateFilter(e) {
794
+ this.fetcher.addURLTemplateFilter(e);
795
+ }
796
+ removeLastURLTemplateFilter() {
797
+ this.fetcher.removeLastURLTemplateFilter();
798
+ }
799
+ countURLTemplateFilters() {
800
+ return this.fetcher.countURLTemplateFilters();
801
+ }
802
+ clearURLTemplateFilters() {
803
+ this.fetcher.clearURLTemplateFilters();
804
+ }
805
+ getParser() {
806
+ return this.vastParser;
807
+ }
808
+ get lastSuccessfulAd() {
809
+ return this.storage.getItem("vast-client-last-successful-ad");
810
+ }
811
+ set lastSuccessfulAd(e) {
812
+ this.storage.setItem("vast-client-last-successful-ad", e);
813
+ }
814
+ get totalCalls() {
815
+ return this.storage.getItem("vast-client-total-calls");
816
+ }
817
+ set totalCalls(e) {
818
+ this.storage.setItem("vast-client-total-calls", e);
819
+ }
820
+ get totalCallsTimeout() {
821
+ return this.storage.getItem("vast-client-total-calls-timeout");
822
+ }
823
+ set totalCallsTimeout(e) {
824
+ this.storage.setItem("vast-client-total-calls-timeout", e);
825
+ }
826
+ hasRemainingAds() {
827
+ return this.vastParser.remainingAds.length > 0;
828
+ }
829
+ getNextAds(e) {
830
+ return this.vastParser.getRemainingAds(e);
831
+ }
832
+ parseVAST(e) {
833
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
834
+ return this.fetcher.setOptions(t), this.vastParser.parseVAST(e, t);
835
+ }
836
+ get(e) {
837
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
838
+ const r = Date.now();
839
+ return t.hasOwnProperty("resolveAll") || (t.resolveAll = !1), this.totalCallsTimeout < r ? (this.totalCalls = 1, this.totalCallsTimeout = r + 36e5) : this.totalCalls++, new Promise((i, s) => {
840
+ if (this.cappingFreeLunch >= this.totalCalls) return s(new Error("VAST call canceled – FreeLunch capping not reached yet ".concat(this.totalCalls, "/").concat(this.cappingFreeLunch)));
841
+ const o = r - this.lastSuccessfulAd;
842
+ if (o < 0) this.lastSuccessfulAd = 0;
843
+ else if (o < this.cappingMinimumTimeInterval) return s(new Error("VAST call canceled – (".concat(this.cappingMinimumTimeInterval, ")ms minimum interval reached")));
844
+ this.vastParser.initParsingStatus(t), this.fetcher.setOptions(t), this.vastParser.rootURL = e, this.fetcher.fetchVAST({ url: e, emitter: this.vastParser.emit.bind(this.vastParser), maxWrapperDepth: this.vastParser.maxWrapperDepth }).then((n) => (t.previousUrl = e, t.isRootVAST = !0, t.url = e, this.vastParser.parse(n, t).then((c) => {
845
+ const u = this.vastParser.buildVASTResponse(c);
846
+ i(u);
847
+ }))).catch((n) => s(n));
848
+ });
849
+ }
850
+ }
851
+ class De extends J {
852
+ constructor(e, t, r) {
853
+ let i = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : null, s = arguments.length > 4 && arguments[4] !== void 0 && arguments[4];
854
+ super(), this.ad = t, this.creative = r, this.variation = i, this.muted = s, this.impressed = !1, this.skippable = !1, this.trackingEvents = {}, this.trackedProgressEvents = [], this.lastPercentage = 0, this._alreadyTriggeredQuartiles = {}, this.emitAlwaysEvents = ["creativeView", "start", "firstQuartile", "midpoint", "thirdQuartile", "complete", "resume", "pause", "rewind", "skip", "closeLinear", "close"];
855
+ for (const o in this.creative.trackingEvents) {
856
+ const n = this.creative.trackingEvents[o];
857
+ this.trackingEvents[o] = n.slice(0);
858
+ }
859
+ (function(o) {
860
+ return o.type === "linear";
861
+ })(this.creative) ? this._initLinearTracking() : this._initVariationTracking(), e && this.on("start", () => {
862
+ e.lastSuccessfulAd = Date.now();
863
+ });
864
+ }
865
+ _initLinearTracking() {
866
+ this.linear = !0, this.skipDelay = this.creative.skipDelay, this.setDuration(this.creative.duration), this.clickThroughURLTemplate = this.creative.videoClickThroughURLTemplate, this.clickTrackingURLTemplates = this.creative.videoClickTrackingURLTemplates;
867
+ }
868
+ _initVariationTracking() {
869
+ if (this.linear = !1, this.skipDelay = -1, this.variation) {
870
+ for (const e in this.variation.trackingEvents) {
871
+ const t = this.variation.trackingEvents[e];
872
+ this.trackingEvents[e] ? this.trackingEvents[e] = this.trackingEvents[e].concat(t.slice(0)) : this.trackingEvents[e] = t.slice(0);
873
+ }
874
+ this.variation.adType === "nonLinearAd" ? (this.clickThroughURLTemplate = this.variation.nonlinearClickThroughURLTemplate, this.clickTrackingURLTemplates = this.variation.nonlinearClickTrackingURLTemplates, this.setDuration(this.variation.minSuggestedDuration)) : function(e) {
875
+ return e.adType === "companionAd";
876
+ }(this.variation) && (this.clickThroughURLTemplate = this.variation.companionClickThroughURLTemplate, this.clickTrackingURLTemplates = this.variation.companionClickTrackingURLTemplates);
877
+ }
878
+ }
879
+ setDuration(e) {
880
+ f.isValidTimeValue(e) ? (this.assetDuration = e, this.quartiles = { firstQuartile: Math.round(25 * this.assetDuration) / 100, midpoint: Math.round(50 * this.assetDuration) / 100, thirdQuartile: Math.round(75 * this.assetDuration) / 100 }) : this.emit("TRACKER-error", { message: "the duration provided is not valid. duration: ".concat(e) });
881
+ }
882
+ setProgress(e) {
883
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, r = !(arguments.length > 2 && arguments[2] !== void 0) || arguments[2];
884
+ if (!f.isValidTimeValue(e) || typeof t != "object") return void this.emit("TRACKER-error", { message: "One given setProgress parameter has the wrong type. progress: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
885
+ const i = this.skipDelay || -1;
886
+ if (i === -1 || this.skippable || (i > e ? this.emit("skip-countdown", i - e) : (this.skippable = !0, this.emit("skip-countdown", 0))), this.assetDuration > 0) {
887
+ const s = Math.round(e / this.assetDuration * 100), o = [];
888
+ if (e > 0) {
889
+ o.push("start");
890
+ for (let n = this.lastPercentage; n < s; n++) o.push("progress-".concat(n + 1, "%"));
891
+ o.push("progress-".concat(e));
892
+ for (const n in this.quartiles) this.isQuartileReached(n, this.quartiles[n], e) && (o.push(n), this._alreadyTriggeredQuartiles[n] = !0);
893
+ this.lastPercentage = s;
894
+ }
895
+ o.forEach((n) => {
896
+ this.track(n, { macros: t, once: r });
897
+ }), e < this.progress && (this.track("rewind", { macros: t }), this.trackedProgressEvents && this.trackedProgressEvents.splice(0));
898
+ }
899
+ this.progress = e;
900
+ }
901
+ isQuartileReached(e, t, r) {
902
+ let i = !1;
903
+ return t <= r && !this._alreadyTriggeredQuartiles[e] && (i = !0), i;
904
+ }
905
+ setMuted(e) {
906
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
907
+ typeof e == "boolean" && typeof t == "object" ? (this.muted !== e && this.track(e ? "mute" : "unmute", { macros: t }), this.muted = e) : this.emit("TRACKER-error", { message: "One given setMuted parameter has the wrong type. muted: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
908
+ }
909
+ setPaused(e) {
910
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
911
+ typeof e == "boolean" && typeof t == "object" ? (this.paused !== e && this.track(e ? "pause" : "resume", { macros: t }), this.paused = e) : this.emit("TRACKER-error", { message: "One given setPaused parameter has the wrong type. paused: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
912
+ }
913
+ setFullscreen(e) {
914
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
915
+ typeof e == "boolean" && typeof t == "object" ? (this.fullscreen !== e && this.track(e ? "fullscreen" : "exitFullscreen", { macros: t }), this.fullscreen = e) : this.emit("TRACKER-error", { message: "One given setFullScreen parameter has the wrong type. fullscreen: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
916
+ }
917
+ setExpand(e) {
918
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
919
+ typeof e == "boolean" && typeof t == "object" ? (this.expanded !== e && (this.track(e ? "expand" : "collapse", { macros: t }), this.track(e ? "playerExpand" : "playerCollapse", { macros: t })), this.expanded = e) : this.emit("TRACKER-error", { message: "One given setExpand parameter has the wrong type. expanded: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
920
+ }
921
+ setSkipDelay(e) {
922
+ f.isValidTimeValue(e) ? this.skipDelay = e : this.emit("TRACKER-error", { message: "setSkipDelay parameter does not have a valid value. duration: ".concat(e) });
923
+ }
924
+ trackImpression() {
925
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
926
+ typeof e == "object" ? this.impressed || (this.impressed = !0, this.trackURLs(this.ad.impressionURLTemplates, e), this.track("creativeView", { macros: e })) : this.emit("TRACKER-error", { message: "trackImpression parameter has the wrong type. macros: ".concat(e) });
927
+ }
928
+ trackViewableImpression() {
929
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
930
+ typeof e == "object" ? this.ad.viewableImpression.forEach((t) => {
931
+ this.trackURLs(t.viewable, e);
932
+ }) : this.emit("TRACKER-error", { message: "trackViewableImpression given macros has the wrong type. macros: ".concat(e) });
933
+ }
934
+ trackNotViewableImpression() {
935
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
936
+ typeof e == "object" ? this.ad.viewableImpression.forEach((t) => {
937
+ this.trackURLs(t.notViewable, e);
938
+ }) : this.emit("TRACKER-error", { message: "trackNotViewableImpression given macros has the wrong type. macros: ".concat(e) });
939
+ }
940
+ trackUndeterminedImpression() {
941
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
942
+ typeof e == "object" ? this.ad.viewableImpression.forEach((t) => {
943
+ this.trackURLs(t.viewUndetermined, e);
944
+ }) : this.emit("TRACKER-error", { message: "trackUndeterminedImpression given macros has the wrong type. macros: ".concat(e) });
945
+ }
946
+ error() {
947
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, t = arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
948
+ typeof e == "object" && typeof t == "boolean" ? this.trackURLs(this.ad.errorURLTemplates, e, { isCustomCode: t }) : this.emit("TRACKER-error", { message: "One given error parameter has the wrong type. macros: ".concat(f.formatMacrosValues(e), ", isCustomCode: ").concat(t) });
949
+ }
950
+ errorWithCode(e) {
951
+ let t = arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
952
+ typeof e == "string" && typeof t == "boolean" ? (this.error({ ERRORCODE: e }, t), console.log("The method errorWithCode is deprecated, please use vast tracker error method instead")) : this.emit("TRACKER-error", { message: "One given errorWithCode parameter has the wrong type. errorCode: ".concat(e, ", isCustomCode: ").concat(t) });
953
+ }
954
+ complete() {
955
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
956
+ typeof e == "object" ? this.track("complete", { macros: e }) : this.emit("TRACKER-error", { message: "complete given macros has the wrong type. macros: ".concat(e) });
957
+ }
958
+ notUsed() {
959
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
960
+ typeof e == "object" ? (this.track("notUsed", { macros: e }), this.trackingEvents = []) : this.emit("TRACKER-error", { message: "notUsed given macros has the wrong type. macros: ".concat(e) });
961
+ }
962
+ otherAdInteraction() {
963
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
964
+ typeof e == "object" ? this.track("otherAdInteraction", { macros: e }) : this.emit("TRACKER-error", { message: "otherAdInteraction given macros has the wrong type. macros: ".concat(e) });
965
+ }
966
+ acceptInvitation() {
967
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
968
+ typeof e == "object" ? this.track("acceptInvitation", { macros: e }) : this.emit("TRACKER-error", { message: "acceptInvitation given macros has the wrong type. macros: ".concat(e) });
969
+ }
970
+ adExpand() {
971
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
972
+ typeof e == "object" ? this.track("adExpand", { macros: e }) : this.emit("TRACKER-error", { message: "adExpand given macros has the wrong type. macros: ".concat(e) });
973
+ }
974
+ adCollapse() {
975
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
976
+ typeof e == "object" ? this.track("adCollapse", { macros: e }) : this.emit("TRACKER-error", { message: "adCollapse given macros has the wrong type. macros: ".concat(e) });
977
+ }
978
+ minimize() {
979
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
980
+ typeof e == "object" ? this.track("minimize", { macros: e }) : this.emit("TRACKER-error", { message: "minimize given macros has the wrong type. macros: ".concat(e) });
981
+ }
982
+ verificationNotExecuted(e) {
983
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
984
+ if (typeof e != "string" || typeof t != "object") return void this.emit("TRACKER-error", { message: "One given verificationNotExecuted parameter has to wrong type. vendor: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
985
+ if (!this.ad || !this.ad.adVerifications || !this.ad.adVerifications.length) throw new Error("No adVerifications provided");
986
+ if (!e) throw new Error("No vendor provided, unable to find associated verificationNotExecuted");
987
+ const r = this.ad.adVerifications.find((s) => s.vendor === e);
988
+ if (!r) throw new Error("No associated verification element found for vendor: ".concat(e));
989
+ const i = r.trackingEvents;
990
+ if (i && i.verificationNotExecuted) {
991
+ const s = i.verificationNotExecuted;
992
+ this.trackURLs(s, t), this.emit("verificationNotExecuted", { trackingURLTemplates: s });
993
+ }
994
+ }
995
+ overlayViewDuration(e) {
996
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
997
+ typeof e == "string" && typeof t == "object" ? (t.ADPLAYHEAD = e, this.track("overlayViewDuration", { macros: t })) : this.emit("TRACKER-error", { message: "One given overlayViewDuration parameters has the wrong type. formattedDuration: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
998
+ }
999
+ close() {
1000
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1001
+ typeof e == "object" ? this.track(this.linear ? "closeLinear" : "close", { macros: e }) : this.emit("TRACKER-error", { message: "close given macros has the wrong type. macros: ".concat(e) });
1002
+ }
1003
+ skip() {
1004
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1005
+ typeof e == "object" ? this.track("skip", { macros: e }) : this.emit("TRACKER-error", { message: "skip given macros has the wrong type. macros: ".concat(e) });
1006
+ }
1007
+ load() {
1008
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1009
+ typeof e == "object" ? this.track("loaded", { macros: e }) : this.emit("TRACKER-error", { message: "load given macros has the wrong type. macros: ".concat(e) });
1010
+ }
1011
+ click() {
1012
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1013
+ if (e !== null && typeof e != "string" || typeof t != "object") return void this.emit("TRACKER-error", { message: "One given click parameter has the wrong type. fallbackClickThroughURL: ".concat(e, ", macros: ").concat(f.formatMacrosValues(t)) });
1014
+ this.clickTrackingURLTemplates && this.clickTrackingURLTemplates.length && this.trackURLs(this.clickTrackingURLTemplates, t);
1015
+ const r = this.clickThroughURLTemplate || e, i = { ...t };
1016
+ if (r) {
1017
+ this.progress && (i.ADPLAYHEAD = this.progressFormatted());
1018
+ const s = f.resolveURLTemplates([r], i)[0];
1019
+ this.emit("clickthrough", s);
1020
+ }
1021
+ }
1022
+ trackProgressEvents(e, t, r) {
1023
+ const i = parseFloat(e.split("-")[1]);
1024
+ Object.entries(this.trackingEvents).filter((s) => {
1025
+ let [o] = s;
1026
+ return o.startsWith("progress-");
1027
+ }).map((s) => {
1028
+ let [o, n] = s;
1029
+ return { name: o, time: parseFloat(o.split("-")[1]), urls: n };
1030
+ }).filter((s) => {
1031
+ let { time: o } = s;
1032
+ return o <= i && o > this.progress;
1033
+ }).forEach((s) => {
1034
+ let { name: o, urls: n } = s;
1035
+ !r && this.trackedProgressEvents.includes(o) || (this.emit(o, { trackingURLTemplates: n }), this.trackURLs(n, t), r ? delete this.trackingEvents[o] : this.trackedProgressEvents.push(o));
1036
+ });
1037
+ }
1038
+ track(e) {
1039
+ let { macros: t = {}, once: r = !1 } = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1040
+ if (typeof t != "object") return void this.emit("TRACKER-error", { message: "track given macros has the wrong type. macros: ".concat(t) });
1041
+ e === "closeLinear" && !this.trackingEvents[e] && this.trackingEvents.close && (e = "close"), e.startsWith("progress-") && !e.endsWith("%") && this.trackProgressEvents(e, t, r);
1042
+ const i = this.trackingEvents[e], s = this.emitAlwaysEvents.indexOf(e) > -1;
1043
+ i ? (this.emit(e, { trackingURLTemplates: i }), this.trackURLs(i, t)) : s && this.emit(e, null), r && (delete this.trackingEvents[e], s && this.emitAlwaysEvents.splice(this.emitAlwaysEvents.indexOf(e), 1));
1044
+ }
1045
+ trackURLs(e) {
1046
+ var t;
1047
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1048
+ const { validUrls: s, invalidUrls: o } = f.filterUrlTemplates(e);
1049
+ o.length && this.emit("TRACKER-error", { message: "Provided urls are malformed. url: ".concat(o) });
1050
+ const n = { ...r };
1051
+ this.linear && (this.creative && this.creative.mediaFiles && this.creative.mediaFiles[0] && this.creative.mediaFiles[0].fileURL && (n.ASSETURI = this.creative.mediaFiles[0].fileURL), this.progress && (n.ADPLAYHEAD = this.progressFormatted())), (t = this.creative) !== null && t !== void 0 && (t = t.universalAdIds) !== null && t !== void 0 && t.length && (n.UNIVERSALADID = this.creative.universalAdIds.map((c) => c.idRegistry.concat(" ", c.value)).join(",")), this.ad && (this.ad.sequence && (n.PODSEQUENCE = this.ad.sequence), this.ad.adType && (n.ADTYPE = this.ad.adType), this.ad.adServingId && (n.ADSERVINGID = this.ad.adServingId), this.ad.categories && this.ad.categories.length && (n.ADCATEGORIES = this.ad.categories.map((c) => c.value).join(",")), this.ad.blockedAdCategories && this.ad.blockedAdCategories.length && (n.BLOCKEDADCATEGORIES = this.ad.blockedAdCategories.map((c) => c.value).join(","))), f.track(s, n, i);
1052
+ }
1053
+ convertToTimecode(e) {
1054
+ if (!f.isValidTimeValue(e)) return "";
1055
+ const t = 1e3 * e, r = Math.floor(t / 36e5), i = Math.floor(t / 6e4 % 60), s = Math.floor(t / 1e3 % 60), o = Math.floor(t % 1e3);
1056
+ return "".concat(f.addLeadingZeros(r, 2), ":").concat(f.addLeadingZeros(i, 2), ":").concat(f.addLeadingZeros(s, 2), ".").concat(f.addLeadingZeros(o, 3));
1057
+ }
1058
+ progressFormatted() {
1059
+ return this.convertToTimecode(this.progress);
1060
+ }
1061
+ }
1062
+ class ye {
1063
+ constructor(e) {
1064
+ this.id = e.getAttribute("id"), this.allowMultipleAds = e.getAttribute("allowMultipleAds"), this.followRedirects = e.getAttribute("followRedirects"), this.vastAdData = null, this.adTagURI = null, this.customData = null;
1065
+ for (const t in e.childNodes) {
1066
+ const r = e.childNodes[t];
1067
+ switch (r.localName) {
1068
+ case "AdTagURI":
1069
+ this.adTagURI = {
1070
+ templateType: r.getAttribute("templateType"),
1071
+ uri: (r.textContent || r.text || "").trim()
1072
+ };
1073
+ break;
1074
+ case "VASTAdData":
1075
+ for (this.vastAdData = r.firstChild; this.vastAdData && this.vastAdData.nodeType !== 1; )
1076
+ this.vastAdData = this.vastAdData.nextSibling;
1077
+ break;
1078
+ case "CustomAdData":
1079
+ this.customData = r;
1080
+ break;
1081
+ }
1082
+ }
1083
+ }
1084
+ }
1085
+ function ee(a, e) {
1086
+ const t = [];
1087
+ for (const r in a.childNodes) {
1088
+ const i = a.childNodes[r];
1089
+ (i.nodeName === e || e === `vmap:${i.nodeName}` || i.nodeName === `vmap:${e}`) && t.push(i);
1090
+ }
1091
+ return t;
1092
+ }
1093
+ function Ee(a) {
1094
+ if (!a || !a.childNodes)
1095
+ return {};
1096
+ const e = a.childNodes, t = [];
1097
+ for (const i in e) {
1098
+ const s = e[i];
1099
+ s.nodeName === "#cdata-section" && t.push(s);
1100
+ }
1101
+ if (t && t.length > 0)
1102
+ try {
1103
+ return JSON.parse(t[0].data);
1104
+ } catch {
1105
+ }
1106
+ let r = "";
1107
+ for (const i in e) {
1108
+ const s = e[i];
1109
+ switch (s.nodeName) {
1110
+ case "#text":
1111
+ r += s.textContent.trim();
1112
+ break;
1113
+ case "#cdata-section":
1114
+ r += s.data;
1115
+ break;
1116
+ }
1117
+ }
1118
+ return r;
1119
+ }
1120
+ function L(a) {
1121
+ const e = {
1122
+ attributes: {},
1123
+ children: {},
1124
+ value: {}
1125
+ };
1126
+ e.value = Ee(a);
1127
+ const t = a.attributes;
1128
+ if (t)
1129
+ for (const i in t) {
1130
+ const s = t[i];
1131
+ s.nodeName && s.nodeValue !== void 0 && s.nodeValue !== null && (e.attributes[s.nodeName] = s.nodeValue);
1132
+ }
1133
+ const r = a.childNodes;
1134
+ if (r)
1135
+ for (const i in r) {
1136
+ const s = r[i];
1137
+ s.nodeName && s.nodeName.substring(0, 1) !== "#" && (e.children[s.nodeName] = L(s));
1138
+ }
1139
+ return e;
1140
+ }
1141
+ class be {
1142
+ constructor(e) {
1143
+ this.timeOffset = e.getAttribute("timeOffset"), this.breakType = e.getAttribute("breakType"), this.breakId = e.getAttribute("breakId"), this.repeatAfter = e.getAttribute("repeatAfter"), this.adSource = null, this.trackingEvents = [], this.extensions = [];
1144
+ for (const t in e.childNodes) {
1145
+ const r = e.childNodes[t];
1146
+ switch (r.localName) {
1147
+ case "AdSource":
1148
+ this.adSource = new ye(r);
1149
+ break;
1150
+ case "TrackingEvents":
1151
+ for (const i in r.childNodes) {
1152
+ const s = r.childNodes[i];
1153
+ s.localName === "Tracking" && this.trackingEvents.push({
1154
+ event: s.getAttribute("event"),
1155
+ uri: (s.textContent || s.text || "").trim()
1156
+ });
1157
+ }
1158
+ break;
1159
+ case "Extensions":
1160
+ this.extensions = ee(r, "Extension").map(
1161
+ (i) => L(i)
1162
+ );
1163
+ break;
1164
+ }
1165
+ }
1166
+ }
1167
+ track(e, t) {
1168
+ for (const r in this.trackingEvents) {
1169
+ const i = this.trackingEvents[r];
1170
+ if (i.event === e) {
1171
+ let { uri: s } = i;
1172
+ i.event === "error" && (s = s.replace("[ERRORCODE]", t)), this.tracker(s);
1173
+ }
1174
+ }
1175
+ }
1176
+ // Easy to overwrite tracker client for unit testing
1177
+ tracker(e) {
1178
+ if (typeof window < "u" && window !== null) {
1179
+ const t = new Image();
1180
+ t.src = e;
1181
+ }
1182
+ }
1183
+ }
1184
+ class Ne {
1185
+ constructor(e) {
1186
+ if (!e || !e.documentElement || e.documentElement.localName !== "VMAP")
1187
+ throw new Error("Not a VMAP document");
1188
+ this.version = e.documentElement.getAttribute("version"), this.adBreaks = [], this.extensions = [];
1189
+ for (const t in e.documentElement.childNodes) {
1190
+ const r = e.documentElement.childNodes[t];
1191
+ switch (r.localName) {
1192
+ case "AdBreak":
1193
+ this.adBreaks.push(new be(r));
1194
+ break;
1195
+ case "Extensions":
1196
+ this.extensions = ee(r, "Extension").map(
1197
+ (i) => L(i)
1198
+ );
1199
+ break;
1200
+ }
1201
+ }
1202
+ }
1203
+ }
1204
+ const we = (a, e) => {
1205
+ const t = goog.pal, r = new t.ConsentSettings();
1206
+ r.allowStorage = !1;
1207
+ const i = new t.NonceLoader(r);
1208
+ return async () => {
1209
+ try {
1210
+ const o = new URL(e), n = new t.NonceRequest();
1211
+ let c = localStorage.getItem("sl-device-id") || I(), u = sessionStorage.getItem("sl-ad-session-id");
1212
+ u || (u = I(), sessionStorage.setItem("sl-ad-session-id", u)), ae(c) || (c = x(`https://${c}`, x.URL)), n.adWillAutoPlay = o.searchParams.get("vpa") === "auto", n.adWillPlayMuted = o.searchParams.get("vpmute") === "1", n.continuousPlayback = !0, n.descriptionUrl = o.searchParams.get("description_url") || "", n.iconsSupported = !0, n.sessionId = c, n.supportedApiFrameworks = "2,7,9", n.videoHeight = a.clientHeight, n.videoWidth = a.clientWidth;
1213
+ const d = await i.loadNonceManager(n);
1214
+ return o.searchParams.set("givn", d.getNonce()), o.searchParams.get("is_lat") === "[placeholder]" && o.searchParams.set("is_lat", "1"), o.searchParams.get("rdid") === "[placeholder]" && o.searchParams.set("rdid", c), o.searchParams.get("correlator") === "[placeholder]" && o.searchParams.set("correlator", u), o;
1215
+ } catch (o) {
1216
+ console.log("AdsManager could not be started", o);
1217
+ return;
1218
+ }
1219
+ };
1220
+ }, Le = new ke(), Ce = (a) => a.creatives.find((e) => e.mediaFiles), Ue = (a) => {
1221
+ var t;
1222
+ const e = a == null ? void 0 : a.mediaFiles;
1223
+ return e != null && e.length && ((t = e.find((r) => r.fileURL)) == null ? void 0 : t.fileURL) || "";
1224
+ }, H = ie({
1225
+ ads: [],
1226
+ autoplay: !0,
1227
+ muted: !1
1228
+ }), Ve = (a, e) => {
1229
+ const [t, r] = re(), i = C(Date.now()), s = C(Date.now());
1230
+ return U(() => {
1231
+ if (!e || !(a != null && a.current))
1232
+ return;
1233
+ const o = we(a.current, e), n = Date.now();
1234
+ i.current = n, o().then((c) => {
1235
+ i.current === n && r(c);
1236
+ }).catch((c) => {
1237
+ console.error(c);
1238
+ });
1239
+ }, [a, e]), U(() => {
1240
+ const o = async (n, c) => {
1241
+ let u = [];
1242
+ if (n.searchParams.get("output") === "vmap") {
1243
+ const h = await fetch(n.toString()), p = new DOMParser(), g = await h.text(), T = p.parseFromString(g, "text/xml");
1244
+ u = new Ne(T).adBreaks.map((E) => E.adSource.adTagURI.uri);
1245
+ } else
1246
+ u = [n.toString()];
1247
+ const d = await Promise.all(
1248
+ u.map((h, p) => Le.get(h).then((g) => {
1249
+ if (s.current === c) {
1250
+ const T = g.ads.find((te) => te.creatives.length > 0);
1251
+ if (!T)
1252
+ return;
1253
+ const A = Ce(T), E = Ue(A);
1254
+ return {
1255
+ creative: A,
1256
+ order: p,
1257
+ mediaFileUrl: E,
1258
+ ad: T,
1259
+ raw: g
1260
+ };
1261
+ }
1262
+ }))
1263
+ ), v = n.searchParams.get("vpa") !== "click", m = n.searchParams.get("vpmute") === "1";
1264
+ H.set({
1265
+ ads: d.filter((h) => !!h),
1266
+ autoplay: v,
1267
+ muted: m
1268
+ });
1269
+ };
1270
+ if (t) {
1271
+ const n = Date.now();
1272
+ s.current = n, o(t, n);
1273
+ }
1274
+ return () => {
1275
+ s.current = 0;
1276
+ };
1277
+ }, [t]), H;
1278
+ };
1279
+ export {
1280
+ Ue as a,
1281
+ Ce as g,
1282
+ Ve as u,
1283
+ De as z
1284
+ };