PageSourceSearch

https://www.iol.pt/js/iol.comercial.js?1790354800286

js iol.pt collected 2026-10-01 08:37:05 UTC 60,747 bytes, 1,435 lines download raw bytes

1'use strict';
2
3/*! *****************************************************************************
4Copyright (c) Microsoft Corporation.
5
6Permission to use, copy, modify, and/or distribute this software for any
7purpose with or without fee is hereby granted.
8
9THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15PERFORMANCE OF THIS SOFTWARE.
16***************************************************************************** */
17/* global Reflect, Promise */
18
19
20var __assign = function() {
21    __assign = Object.assign || function __assign(t) {
22        for (var s, i = 1, n = arguments.length; i < n; i++) {
23            s = arguments[i];
24            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
25        }
26        return t;
27    };
28    return __assign.apply(this, arguments);
29};
30
31function __awaiter(thisArg, _arguments, P, generator) {
32    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33    return new (P || (P = Promise))(function (resolve, reject) {
34        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37        step((generator = generator.apply(thisArg, [])).next());
38    });
39}
40
41function __generator(thisArg, body) {
42    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44    function verb(n) { return function (v) { return step([n, v]); }; }
45    function step(op) {
46        if (f) throw new TypeError("Generator is already executing.");
47        while (_) try {
48            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49            if (y = 0, t) op = [op[0] & 2, t.value];
50            switch (op[0]) {
51                case 0: case 1: t = op; break;
52                case 4: _.label++; return { value: op[1], done: false };
53                case 5: _.label++; y = op[1]; op = [0]; continue;
54                case 7: op = _.ops.pop(); _.trys.pop(); continue;
55                default:
56                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60                    if (t[2]) _.ops.pop();
61                    _.trys.pop(); continue;
62            }
63            op = body.call(thisArg, _);
64        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66    }
67}
68
69var IOLScriptLoaderModule = /** @class */ (function () {
70    function IOLScriptLoaderModule() {
71        this.promises = [];
72    }
73    IOLScriptLoaderModule.prototype.addScript = function (url) {
74        if (!this.isScriptLoaded(url)) {
75            var promise = new Promise(function (resolve, reject) {
76                var script = document.createElement("script");
77                script.src = url;
78                script.addEventListener("load", function () { return resolve(script); }, false);
79                script.addEventListener("error", function () { return reject(script); }, false);
80                document.body.appendChild(script);
81            });
82            this.promises.push(promise);
83        }
84    };
85    IOLScriptLoaderModule.prototype.isScriptLoaded = function (url) {
86        return document.querySelector("script[src=\"" + url + "\"]") !== null;
87    };
88    IOLScriptLoaderModule.prototype.addStyle = function (url) {
89        if (!this.isStyleLoaded(url)) {
90            var promise = new Promise(function (resolve, reject) {
91                var link = document.createElement("link");
92                link.setAttribute("rel", "stylesheet");
93                link.setAttribute("type", "text/css");
94                link.setAttribute("href", url);
95                link.addEventListener("load", function () { return resolve(link); }, false);
96                link.addEventListener("error", function () { return reject(link); }, false);
97                document.body.appendChild(link);
98            });
99            this.promises.push(promise);
100        }
101    };
102    IOLScriptLoaderModule.prototype.isStyleLoaded = function (url) {
103        return document.querySelector("link[href=\"" + url + "\"]") !== null;
104    };
105    IOLScriptLoaderModule.prototype.onLoaded = function (onLoaded, onError) {
106        Promise.all(this.promises).then(function () { return onLoaded(); }, function () { return onError(); });
107    };
108    return IOLScriptLoaderModule;
109}());
110
111var IOLComercialSlotModel = /** @class */ (function () {
112    function IOLComercialSlotModel(name, sizes, viewport, formatName, targets, isRefreshable, extraCSS) {
113        this.name = name;
114        this.sizes = sizes;
115        this.viewports = viewport;
116        this.formatName = formatName;
117        this.key_values = targets;
118        this.isRefreshable = isRefreshable;
119        this.extraCSS = extraCSS;
120    }
121    return IOLComercialSlotModel;
122}());
123
124//INTER [1, 1]
125//BILLBOARDXL [ "fluid",  [2,1], [970,250], [989,250]]
126//BILLBOARD [[970,250], [989,250]]
127//LEADERBOARD [[728,90], [320,50]]
128//MPU [300,250]
129//MPUHALF [[300,250], [300,600]]
130//MPU2 [300,250]
131//INCONTENT [3, 3]
132//BRANDED  ["fluid"]
133//POPIN [340, 100]
134//ANCHOR[320, 50]
135var IOLComercialFormatCreator = /** @class */ (function () {
136    function IOLComercialFormatCreator() {
137    }
138    IOLComercialFormatCreator.createSlotModel = function (slotID, formatName, position) {
139        return IOLComercialFormatCreator.FORMAT_CREATOR[formatName.toUpperCase()](slotID, position);
140    };
141    IOLComercialFormatCreator.FORMAT_CREATOR = {
142        INTER: function (slotID) {
143            return new IOLComercialSlotModel(slotID, [[1, 1]], undefined, "INTER", { pos: "inter" }, false, "");
144        },
145        BILLBOARD_XL: function (slotID) {
146            return new IOLComercialSlotModel(slotID, [[970, 250], [980, 250], [320, 100], "fluid", [2, 1], [4, 4], [5, 5
146]], [
147                {
148                    viewport: [980, 600],
149                    sizes: [[970, 250], [980, 250], "fluid", [2, 1], [4, 4], [5, 5]]
150                },
151                {
152                    viewport: [0, 0],
153                    sizes: [[320, 100], "fluid", [2, 1], [4, 4], [5, 5]]
154                }
155            ], "BILLBOARDXL", {
156                pos: "billboardxl"
157            }, false, "iol-comercial-placement-label");
158        },
159        POPIN: function (slotID) {
160            return new IOLComercialSlotModel(slotID, [[340, 100]], undefined, "POPIN", {
161                pos: "popin"
162            }, true, "");
163        },
164        INCONTENT: function (slotID) {
165            return new IOLComercialSlotModel(slotID, [[3, 3]], undefined, "INCONTENT", {
166                pos: "incontent"
167            }, true, "");
168        },
169        MPU_HALF: function (slotID) {
170            return new IOLComercialSlotModel(slotID, [[300, 250], [300, 600]], undefined, "MPU_HALF", {
171                pos: "mpuhalf"
172            }, true, "iol-comercial-placement-label");
173        },
174        MPU: function (slotID) {
175            return new IOLComercialSlotModel(slotID, [[300, 250]], undefined, "MPU", {
176                pos: "mpu"
177            }, true, "iol-comercial-placement-label");
178        },
179        MPU2: function (slotID) {
180            return new IOLComercialSlotModel(slotID, [[300, 250]], undefined, "MPU2", {
181                pos: "mpu2"
182            }, true, "iol-comercial-placement-label");
183        },
184        MPUHALF_GAL: function (slotID) {
185            return new IOLComercialSlotModel(slotID, [[300, 250], [300, 600]], undefined, "MPUHALF_GAL", {
186                pos: "mpuhalf_gal"
187            }, true, "iol-comercial-placement-label");
188        },
189        MPUGAL: function (slotID) {
190            return new IOLComercialSlotModel(slotID, [[300, 250]], undefined, "MPUGAL", {
191                pos: "mpugal"
192            }, true, "iol-comercial-placement-label");
193        },
194        ANCHOR: function (slotID) {
195            return new IOLComercialSlotModel(slotID, [[320, 50]], undefined, "ANCHOR", {
196                pos: "anchor"
197            }, true, "iol-comercial-placement-label");
198        },
199        BRANDED: function (slotID) {
200            return new IOLComercialSlotModel(slotID, ["fluid"], undefined, "BRANDED_CONTENT", { pos: "branded" }, true, "iol-comercial-placement-label");
201        },
202        IOL_BRANDED: function (slotID) {
203            return new IOLComercialSlotModel(slotID, ["fluid"], undefined, "IOL_BRANDED_CONTENT", {
204                pos: "iol_branded"
205            }, true, "iol-comercial-placement-label");
206        },
207        LEADERBOARD: function (slotID) {
208            return new IOLComercialSlotModel(slotID, [
209                [728, 90],
210                [320, 50],
211                [970, 250],
212                [980, 250]
213            ], [
214                {
215                    viewport: [728, 600],
216                    sizes: [[728, 90]]
217                },
218                {
219                    viewport: [320, 400],
220                    sizes: [[320, 50], [320, 100]]
221                },
222                {
223                    viewport: [970, 600],
224                    sizes: [[970, 250], [728, 90]]
225                },
226                {
227                    viewport: [980, 600],
228                    sizes: [[980, 250], [970, 250], [728, 90]]
229                }
230            ], "LDB", {
231                pos: "ldb"
232            }, true, "iol-comercial-placement-label");
233        },
234        LEADERBOARD2: function (slotID) {
235            return new IOLComercialSlotModel(slotID, [
236                [728, 90],
237                [320, 50]
238            ], [
239                {
240                    viewport: [728, 600],
241                    sizes: [[728, 90]]
242                },
243                {
244                    viewport: [320, 400],
245                    sizes: [[320, 50]]
246                }
247            ], "LDB2", {
248                pos: "ldb2"
249            }, true, "iol-comercial-placement-label");
250        },
251        BILLBOARD_LEADERBOARD: function (slotID) {
252            return new IOLComercialSlotModel(slotID, [
253                [970, 250],
254                [980, 250],
255                [728, 90],
256                [320, 50]
257            ], [
258                {
259                    viewport: [980, 600],
260                    sizes: [
261                        [970, 250],
262                        [980, 250],
263                        [728, 90]
264                    ]
265                },
266                {
267                    viewport: [728, 600],
268                    sizes: [[728, 90]]
269                },
270                {
271                    viewport: [320, 400],
272                    sizes: [[320, 50]]
273                }
274            ], "LDB", {
275                pos: "ldb"
276            }, true, "iol-comercial-placement-label");
277        },
278        "SPONSOR": function (slotID, position) {
279            return new IOLComercialSlotModel(slotID, ["fluid"], undefined, "SPONSOR" + (position ? position : '1'), {
280                pos: "sponsor" + (position ? position : '1')
281            }, true, "iol-comercial-placement-label");
282        },
283        AUDIO: function (slotID) {
284            return new IOLComercialSlotModel(slotID, [[1, 1]], undefined, "AUDIO", { pos: "audio" }, true, "iol-comercial-placement-label");
285        },
286        OUTSTREAM: function (slotID) {
287            return new IOLComercialSlotModel(slotID, [[640, 480]], undefined, "OUTSTREAM", {
288                pos: "outstream"
289            }, true, "iol-comercial-placement-label");
290        },
291        AUTOPROMO: function (slotID) {
292            return new IOLComercialSlotModel(slotID, [[6, 6]], undefined, "AUTOPROMO", { pos: "autopromo" }, false, "");
293        },
294        L_BAND: function (slotID) {
295            return new IOLComercialSlotModel(slotID, [[7, 7]], undefined, "L_BAND", { pos: "LBAND" }, false, "");
296        }
297    };
298    return IOLComercialFormatCreator;
299}());
300
301var bidders = {
302    criteo: {
303        bidder: "criteo",
304        params: {
305            pubid: "110947",
306            networkId: "3705"
307        }
308    },
309    ttd: {
310        bidder: "ttd",
311        params: {
312            publisherId: "1",
313            supplySourceId: "direct64qhs3p1"
314        }
315    },
316    improvedigital: {
317        bidder: "improvedigital",
318        params: {
319            // MediaCapital_Web_RON_Display (banner only; Web_RON_Video is 23506262, Inapp_RON_Display is 23506264)
320            placementId: 23506263,
321            publisherId: 2673
322        }
323    },
324    rubicon: {
325        bidder: "rubicon",
326        params: {
327            accountId: 14478,
328            siteId: 501028,
329            zoneId: 3960619
330        }
331    }
332};
333
334// Floor rules as ad ops define them, in the shape the back office will publish.
335// "*" means any: RON for site, Int for country, cross for device. The most specific
336// matching rule wins, so a missing site falls back to RON and a missing country to Int.
337//   site     project passed to IOLComercial (iol_news, cnn, selfie, tvi, ...)
338//   country  ISO 3166-1 alpha-2 code
339//   device   "desktop" (web) | "mobile" (web mobile)
340//   floor    in `currency`, before `adjustmentPercent` is applied
341var rule = function (site, country, device, size, floor) {
342    return ({ site: site, country: country, device: device, size: size, floor: floor });
343};
344var DEFAULT_FLOOR_SETTINGS = {
345    version: "builtin-2026-09-21",
346    currency: "EUR",
347    adjustmentPercent: 0,
348    rules: [
349        // RON, Int
350        rule("*", "*", "desktop", "300x250", 0.28),
351        rule("*", "*", "mobile", "300x250", 0.42),
352        rule("*", "*", "*", "300x600", 0.51),
353        rule("*", "*", "*", "320x50", 0.10),
354        rule("*", "*", "*", "728x90", 0.10),
355        rule("*", "*", "*", "970x250", 0.10),
356        // RON, Portugal
357        rule("*", "PT", "*", "300x250", 0.50),
358        rule("*", "PT", "*", "300x600", 3.50),
359        rule("*", "PT", "*", "320x50", 0.50),
360        rule("*", "PT", "*", "728x90", 1.00),
361        rule("*", "PT", "*", "970x250", 7.50),
362        // RON, other countries
363        rule("*", "AO", "*", "300x250", 0.10),
364        rule("*", "AO", "*", "300x600", 0.08),
365        rule("*", "AO", "*", "728x90", 0.19),
366        rule("*", "AO", "*", "970x250", 0.01),
367        rule("*", "BE", "*", "300x250", 0.50),
368        rule("*", "BE", "*", "300x600", 0.47),
369        rule("*", "BE", "*", "728x90", 0.48),
370        rule("*", "BE", "*", "970x250", 0.83),
371        rule("*", "BR", "*", "300x250", 0.27),
372        rule("*", "BR", "*", "300x600", 0.50),
373        rule("*", "BR", "*", "728x90", 0.34),
374        rule("*", "BR", "*", "970x250", 0.52),
375        rule("*", "CA", "*", "300x250", 0.28),
376        rule("*", "CA", "*", "300x600", 0.28),
377        rule("*", "CA", "*", "728x90", 0.30),
378        rule("*", "CA", "*", "970x250", 0.28),
379        rule("*", "CH", "*", "300x250", 0.52),
380        rule("*", "CH", "*", "300x600", 0.67),
381        rule("*", "CH", "*", "728x90", 0.55),
382        rule("*", "CH", "*", "970x250", 0.62),
383        rule("*", "DE", "*", "300x250", 0.28),
384        rule("*", "DE", "*", "300x600", 0.10),
385        rule("*", "DE", "*", "728x90", 0.28),
386        rule("*", "DE", "*", "970x250", 0.35),
387        rule("*", "ES", "*", "300x250", 0.37),
388        rule("*", "ES", "*", "300x600", 0.10),
389        rule("*", "ES", "*", "728x90", 0.57),
390        rule("*", "ES", "*", "970x250", 0.40),
391        rule("*", "FR", "*", "300x250", 0.11),
392        rule("*", "FR", "*", "300x600", 0.17),
393        rule("*", "FR", "*", "728x90", 0.34),
394        rule("*", "FR", "*", "970x250", 0.28),
395        rule("*", "GB", "*", "300x250", 0.21),
396        rule("*", "GB", "*", "300x600", 0.28),
397        rule("*", "GB", "*", "728x90", 0.22),
398        rule("*", "GB", "*", "970x250", 0.70),
399        rule("*", "LU", "*", "300x250", 0.28),
400        rule("*", "LU", "*", "300x600", 0.28),
401        rule("*", "LU", "*", "728x90", 0.48),
402        rule("*", "LU", "*", "970x250", 0.40),
403        rule("*", "MZ", "*", "300x250", 0.10),
404        rule("*", "NL", "*", "300x250", 0.22),
405        rule("*", "US", "*", "300x250", 0.61),
406        rule("*", "US", "*", "300x600", 0.70),
407        rule("*", "US", "*", "728x90", 0.34),
408        rule("*", "US", "*", "970x250", 0.81),
409        // CNN
410        rule("cnn", "PT", "*", "300x250", 0.75),
411        // Selfie
412        rule("selfie", "PT", "*", "300x250", 0.10),
413        rule("selfie", "PT", "*", "300x600", 0.10),
414        rule("selfie", "PT", "*", "320x50", 0.10),
415        rule("selfie", "PT", "*", "728x90", 0.10),
416        rule("selfie", "PT", "*", "970x250", 4.00)
417    ]
418};
419
420// Timezones per country, from the IANA zone.tab, for the countries that have floor rules.
421// Any other timezone resolves to no country, which falls back to the Int rules.
422var COUNTRY_TIMEZONES = {
423    PT: ["Europe/Lisbon", "Atlantic/Madeira", "Atlantic/Azores"],
424    ES: ["Europe/Madrid", "Africa/Ceuta", "Atlantic/Canary"],
425    FR: ["Europe/Paris"],
426    DE: ["Europe/Berlin", "Europe/Busingen"],
427    BE: ["Europe/Brussels"],
428    NL: ["Europe/Amsterdam"],
429    LU: ["Europe/Luxembourg"],
430    CH: ["Europe/Zurich"],
431    GB: ["Europe/London"],
432    AO: ["Africa/Luanda"],
433    MZ: ["Africa/Maputo"],
434    BR: [
435        "America/Noronha", "America/Belem", "America/Fortaleza", "America/Recife", "America/Araguaina",
436        "America/Maceio", "America/Bahia", "America/Sao_Paulo", "America/Campo_Grande", "America/Cuiaba",
437        "America/Santarem", "America/Porto_Velho", "America/Boa_Vista", "America/Manaus", "America/Eirunepe",
438        "America/Rio_Branco"
439    ],
440    CA: [
441        "America/St_Johns", "America/Halifax", "America/Glace_Bay", "America/Moncton", "America/Goose_Bay",
442        "America/Blanc-Sablon", "America/Toronto", "America/Iqaluit", "America/Atikokan", "America/Winnipeg",
443        "America/Resolute", "America/Rankin_Inlet", "America/Regina", "America/Swift_Current", "America/Edmonton",
444        "America/Cambridge_Bay", "America/Inuvik", "America/Vancouver", "America/Creston", "America/Dawson_Creek",
445        "America/Fort_Nelson", "America/Whitehorse", "America/Dawson"
446    ],
447    US: [
448        "America/New_York", "America/Detroit", "America/Kentucky/Louisville", "America/Kentucky/Monticello",
449        "America/Indiana/Indianapolis", "America/Indiana/Vincennes", "America/Indiana/Winamac",
450        "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Vevay", "America/Chicago",
451        "America/Indiana/Tell_City", "America/Indiana/Knox", "America/Menominee", "America/North_Dakota/Center",
452        "America/North_Dakota/New_Salem", "America/North_Dakota/Beulah", "America/Denver", "America/Boise",
453        "America/Phoenix", "America/Los_Angeles", "America/Anchorage", "America/Juneau", "America/Sitka",
454        "America/Metlakatla", "America/Yakutat", "America/Nome", "America/Adak", "Pacific/Honolulu",
455        // older names some browsers still report
456        "America/Indianapolis", "America/Louisville"
457    ]
458};
459// Privacy modes (Firefox resistFingerprinting, Tor) report these instead of the real zone.
460var MASKED_TIMEZONES = ["UTC", "GMT", "Etc/UTC", "Etc/GMT", "Etc/Greenwich"];
461var TIMEZONE_COUNTRY = {};
462Object.keys(COUNTRY_TIMEZONES).forEach(function (country) {
463    COUNTRY_TIMEZONES[country].forEach(function (timeZone) {
464        TIMEZONE_COUNTRY[timeZone] = country;
465    });
466});
467function readTimeZone() {
468    try {
469        if (typeof Intl === "undefined" || !Intl.DateTimeFormat) {
470            return null;
471        }
472        var resolved = Intl.DateTimeFormat().resolvedOptions();
473        return resolved && resolved.timeZone ? resolved.timeZone : null;
474    }
475    catch (e) {
476        return null;
477    }
478}
479function readLanguage() {
480    var nav = navigator;
481    var language = (nav && (nav.language || nav.userLanguage)) || "";
482    return String(language).toLowerCase();
483}
484function detectCountry() {
485    var timeZone = readTimeZone();
486    if (timeZone && MASKED_TIMEZONES.indexOf(timeZone) === -1) {
487        return { country: TIMEZONE_COUNTRY[timeZone] || null, source: "timezone" };
488    }
489    if (readLanguage() === "pt-pt") {
490        return { country: "PT", source: "language" };
491    }
492    return { country: null, source: "unknown" };
493}
494// Phones count as mobile; tablets report a desktop-class browser and count as desktop.
495function detectDevice() {
496    var nav = navigator;
497    if (nav.userAgentData && typeof nav.userAgentData.mobile === "boolean") {
498        return nav.userAgentData.mobile ? "mobile" : "desktop";
499    }
500    var mobileUserAgent = /Mobi|iPhone|iPod|Android.*Mobile|Windows Phone|BlackBerry|Opera Mini/i;
501    return mobileUserAgent.test(nav.userAgent || "") ? "mobile" : "desktop";
502}
503
504var ANY = "*";
505var DEVICES = [ANY, "desktop", "mobile"];
506var MAX_ADJUSTMENT_PERCENT = 50;
507function normalizeRule(raw) {
508    if (!raw || typeof raw !== "object") {
509        return null;
510    }
511    var site = String(raw.site || "").toLowerCase();
512    var country = String(raw.country || "").toUpperCase();
513    var device = String(raw.device || "").toLowerCase();
514    var size = String(raw.size || "").toLowerCase();
515    var floor = Number(raw.floor);
516    var valid = site !== "" &&
517        (country === ANY || /^[A-Z]{2}$/.test(country)) &&
518        DEVICES.indexOf(device) !== -1 &&
519        /^\d+x\d+$/.test(size) &&
520        typeof raw.floor === "number" && isFinite(floor) && floor >= 0;
521    return valid ? { site: site, country: country, device: device, size: size, floor: floor } : null;
522}
523// Drops invalid and duplicate rules and bounds the adjustment, so a bad entry
524// (from the back office, later) degrades one rule instead of breaking all floors.
525function sanitizeFloorSettings(input) {
526    var problems = [];
527    var seen = {};
528    var rules = [];
529    (input && Array.isArray(input.rules) ? input.rules : []).forEach(function (raw, index) {
530        var rule = normalizeRule(raw);
531        if (!rule) {
532            problems.push("rule " + index + " is invalid and was ignored: " + JSON.stringify(raw));
533            return;
534        }
535        var key = [rule.site, rule.country, rule.device, rule.size].join("|");
536        if (seen[key]) {
537            problems.push("rule " + index + " duplicates " + key + " and was ignored");
538            return;
539        }
540        seen[key] = true;
541        rules.push(rule);
542    });
543    var adjustmentPercent = Number(input && input.adjustmentPercent) || 0;
544    if (Math.abs(adjustmentPercent) > MAX_ADJUSTMENT_PERCENT) {
545        problems.push("adjustmentPercent " + adjustmentPercent + " is outside \u00B1" + MAX_ADJUSTMENT_PERCENT + " and was capped");
546        adjustmentPercent = Math.max(-MAX_ADJUSTMENT_PERCENT, Math.min(MAX_ADJUSTMENT_PERCENT, adjustmentPercent));
547    }
548    return {
549        settings: {
550            version: String((input && input.version) || "unknown"),
551            currency: String((input && input.currency) || "EUR"),
552            adjustmentPercent: adjustmentPercent,
553            rules: rules
554        },
555        problems: problems
556    };
557}
558function matches(ruleValue, visitorValue) {
559    return ruleValue === ANY || ruleValue === visitorValue;
560}
561// The most specific rule wins; on a tie, site beats country, which beats device.
562function specificity(rule) {
563    var site = rule.site !== ANY ? 1 : 0;
564    var country = rule.country !== ANY ? 1 : 0;
565    var device = rule.device !== ANY ? 1 : 0;
566    return (site + country + device) * 8 + site * 4 + country * 2 + device;
567}
568function applyAdjustment(floor, percent) {
569    if (floor <= 0) {
570        return 0;
571    }
572    return Math.max(0.01, Math.round(floor * (100 + percent)) / 100);
573}
574function resolveFloors(settings, visitor) {
575    var best = {};
576    settings.rules.forEach(function (rule) {
577        if (!matches(rule.site, visitor.site) || !matches(rule.country, visitor.country) || !matches(rule.device, visitor.device)) {
578            return;
579        }
580        var current = best[rule.size];
581        if (!current || specificity(rule) > specificity(current)) {
582            best[rule.size] = rule;
583        }
584    });
585    return Object.keys(best).map(function (size) { return ({
586        size: size,
587        rule: best[size],
588        floor: applyAdjustment(best[size].floor, settings.adjustmentPercent)
589    }); });
590}
591function buildFloorsConfig(development, site, input) {
592    if (input === void 0) { input = DEFAULT_FLOOR_SETTINGS; }
593    if (development) {
594        return { enabled: false };
595    }
596    var _a = sanitizeFloorSettings(input), settings = _a.settings, problems = _a.problems;
597    var _b = detectCountry(), country = _b.country, source = _b.source;
598    var visitor = { site: String(site || "").toLowerCase(), country: country, device: detectDevice() };
599    var resolved = resolveFloors(settings, visitor);
600    if (localStorage.getItem("pbdebug") === "1") {
601        console.log("Prebid floors:", JSON.stringify({
602            version: settings.version,
603            adjustmentPercent: settings.adjustmentPercent,
604            site: visitor.site,
605            country: visitor.country || "Int",
606            countrySource: source,
607            timeZone: readTimeZone(),
608            device: visitor.device
609        }));
610        console.table(resolved.map(function (r) { return ({
611            size: r.size,
612            site: r.rule.site,
613            country: r.rule.country,
614            device: r.rule.device,
615            rate: r.rule.floor,
616            floor: r.floor
617        }); }));
618        problems.forEach(function (problem) { return console.warn("Prebid floors:", problem); });
619    }
620    if (!resolved.length) {
621        return { enabled: false };
622    }
623    var values = {};
624    var lowest = Infinity;
625    resolved.forEach(function (r) {
626        values["banner|" + r.size] = r.floor;
627        lowest = Math.min(lowest, r.floor);
628    });
629    return {
630        enabled: true,
631        floorMin: lowest,
632        enforcement: {
633            enforceJS: true,
634            floorDeals: false
635        },
636        data: {
637            currency: settings.currency,
638            modelVersion: settings.version,
639            schema: {
640                fields: ["mediaType", "size"]
641            },
642            values: values,
643            default: lowest
644        }
645    };
646}
647
648function allowedPrebidSizes(size) {
649    // let allowedSizes = ["300x250", "300x600", "320x50", "728x90", "970x250", "Pre-roll", "Mid-roll", "Post-roll", "Incontent video"];
650    var allowedSizes = ["300x250", "300x600", "320x50", "728x90", "970x250"];
651    return allowedSizes.includes(size);
652}
653function createPrebidAdUnit(slotID, formatName) {
654    var debugMode = localStorage.getItem("pbdebug") === "1";
655    var slotModel = IOLComercialFormatCreator.createSlotModel(slotID, formatName, 0);
656    var validSizes = slotModel.sizes
657        .filter(function (s) { return Array.isArray(s) && s.length === 2 && s.every(Number.isFinite); })
658        .filter(function (_a) {
659        var w = _a[0], h = _a[1];
660        return allowedPrebidSizes(w + "x" + h);
661    }); // <-- filter by allowed sizes
662    if (!validSizes.length) {
663        return null;
664    }
665    var bidderKeys = Object.keys(bidders);
666    var adUnit = {
667        code: slotID,
668        mediaTypes: {
669            banner: {
670                sizes: validSizes,
671                // ...(hasFluid && { fluid: true }),
672            },
673        },
674        bids: bidderKeys.map(function (key) {
675            var baseConfig = __assign({}, bidders[key]);
676            if (key === "rubicon") {
677                var mappedSizes = mapRubiconSizes(validSizes);
678                if (!mappedSizes.length) {
679                    return null;
680                }
681                return __assign(__assign({}, baseConfig), { params: __assign(__assign({}, baseConfig.params), { sizes: mappedSizes }) });
682            }
683            return baseConfig;
684        }).filter(Boolean),
685    };
686    if (debugMode) {
687        console.log("Prebid adUnit built:", formatName, JSON.stringify(adUnit, null, 2));
688    }
689    return adUnit;
690}
691function setPrebidBidderSettings(pbjs) {
692    pbjs.bidderSettings = pbjs.bidderSettings || {};
693    pbjs.bidderSettings.criteo = { storageAllowed: true };
694    pbjs.bidderSettings.rubicon = { storageAllowed: true };
695    pbjs.bidderSettings.ttd = { storageAllowed: true };
696    pbjs.bidderSettings.improvedigital = { storageAllowed: true };
697}
698function setPrebidConfig(pbjs, site) {
699    var environment = document.location.host.includes("localhost") ||
700        document.location.host.includes("dev.");
701    var debugMode = localStorage.getItem("pbdebug") === "1";
702    pbjs.setConfig({
703        debug: debugMode,
704        enableTIDs: true,
705        s2sConfig: null,
706        enableSendAllBids: false,
707        bidderTimeout: 1200,
708        bidderSequence: "random",
709        auctionOptions: {
710            suppressStaleRender: true
711        },
712        currency: {
713            adServerCurrency: "EUR",
714            defaultRates: {
715                EUR: { USD: 1.15 },
716                USD: { EUR: 0.87 }
717            }
718        },
719        priceGranularity: {
720            buckets: [{
721                    precision: 2,
722                    min: 0,
723                    max: 20,
724                    increment: 0.01
725                }]
726        },
727        floors: buildFloorsConfig(environment, site),
728        consentManagement: {
729            gdpr: {
730                cmpApi: "iab",
731                timeout: 8000
732            }
733        },
734        userSync: {
735            userIds: [
736                {
737                    name: "id5Id",
738                    params: {
739                        partner: "1839"
740                    },
741                    storage: {
742                        type: "cookie",
743                        name: "id5id",
744                        expires: 365
745                    }
746                }
747            ]
748        },
749        targetingControls: {
750            alwaysIncludeDeals: false
751        }
752    });
753}
754function mapRubiconSizes(pixelSizes) {
755    // Map of sizes to Rubicon IDs, defined inside the function
756    var RUBICON_SIZE_MAP = {
757        "468x60": 1,
758        "728x90": 2,
759        "120x600": 8,
760        "160x600": 9,
761        "300x600": 10,
762        "300x250": 15,
763        "336x280": 16,
764        "320x50": 43,
765        "300x50": 44,
766        "970x90": 55,
767        "970x250": 57,
768        "320x100": 117
769    };
770    return pixelSizes
771        .filter(function (size) {
772        return Array.isArray(size) &&
773            size.length === 2 &&
774            typeof size[0] === "number" &&
775            typeof size[1] === "number";
776    })
777        .map(function (_a) {
778        var _b;
779        var w = _a[0], h = _a[1];
780        var key = w + "x" + h;
781        return (_b = RUBICON_SIZE_MAP[key]) !== null && _b !== void 0 ? _b : null;
782    })
783        .filter(function (id) { return id !== null; });
784}
785
786// declare var window: Window & { iol?: { onUserLoggedIn?: () => void } & {} };
787var IOLComercialPlatform = /** @class */ (function () {
788    function IOLComercialPlatform(AMUnit, project) {
789        this.hasPreloaded = false;
790        this.AMUnit = AMUnit;
791        this.project = project;
792        this.AMGoogleTag = {};
793        this.pbjs = window.pbjs = window.pbjs || { cmd: [] };
794        setPrebidBidderSettings(this.pbjs);
795        this.prebidConfigured = false;
796        this.prebidListenersAttached = false;
797        this.slotQueue = [];
798        this.slotsIndex = {};
799        this.refreshableSlotsIndex = [];
800        this.noPubProducts = [7, 8, 9, 12, 13, 14];
801        this.noPubPremiumProducts = [13, 14];
802        this.correlator = Date.now();
803        this.location = document.querySelector("meta[property='og:site_name']")
804            ? document
805                .querySelector("meta[property='og:site_name']")
806                .getAttribute("content")
807            : "";
808        this.tags = this.getArticleTags();
809        this.section = this.getSectionTags();
810        this.ctags = this.getControlTags();
811        this.pubTag = this.getPubTag();
812        this.projTag = this.getProjTag();
813    }
814    IOLComercialPlatform.prototype.loadDependencies = function (action) {
815        var _this = this;
816        var scriptLoader = new IOLScriptLoaderModule();
817        scriptLoader.addScript("https://www.googletagservices.com/tag/js/gpt.js");
818        scriptLoader.addScript("https://cdn.iol.pt/js/utils/Modules/IOLComercial/prebid/prebid.js");
819        // scriptLoader.addScript("http://localhost:8080/js/prebid10.15.0.js");
820        scriptLoader.onLoaded(function () { return __awaiter(_this, void 0, void 0, function () {
821            var _a;
822            return __generator(this, function (_b) {
823                switch (_b.label) {
824                    case 0:
825                        this.AMGoogleTag = window["googletag"] || {};
826                        console.info("IOLCOMERCIAL: Dependencies successufly loaded");
827                        action();
828                        _b.label = 1;
829                    case 1:
830                        _b.trys.push([1, 3, , 4]);
831                        _a = this;
832                        return [4 /*yield*/, this.getIOLAnalyticsCookieValue()];
833                    case 2:
834                        _a.ppID = _b.sent();
835                        return [3 /*break*/, 4];
836                    case 3:
837                        _b.sent();
838                        return [3 /*break*/, 4];
839                    case 4: return [2 /*return*/];
840                }
841            });
842        }); }, function () {
843            console.error("IOLCOMERCIAL: Cannot load dependencies");
844        });
845    };
846    IOLComercialPlatform.prototype.getIOLAnalyticsCookieValue = function () {
847        var cookie = document.cookie.split(";");
848        var iola = cookie.find(function (el) {
849            if (el.includes("_iola")) {
850                return true;
851            }
852        });
853        if (iola) {
854            var ids = iola.split("_iola=");
855            var id = ids[1];
856            return id || undefined;
857        }
858    };
859    IOLComercialPlatform.prototype.getArticleTags = function () {
860        var _this = this;
861        var _a, _b, _c, _d;
862        var ioltags = document.querySelector("meta[property='iol:tags']");
863        var iolprogramme = document.querySelector("meta[property='iol:programme_name']");
864        var metatags = (_b = (_a = ioltags === null || ioltags === void 0 ? void 0 : ioltags.getAttribute("content")) === null || _a === void 0 ? void 0 : _a.split(", ")) !== null && _b !== void 0 ? _b : [];
865        var programmetags = (_d = (_c = iolprogramme === null || iolprogramme === void 0 ? void 0 : iolprogramme.getAttribute("content")) === null || _c === void 0 ? void 0 : _c.split(", ")) !== null && _d !== void 0 ? _d : [];
866        var tags = metatags.concat(programmetags).filter(function (n) { return n; });
867        var originURL = window.location.origin;
868        var homepage = originURL + '/';
869        if (window.location.href === homepage) {
870            tags.push("homepage");
871            console.log("tags: ", tags);
872        }
873        var tagList = [];
874        if (tags.length > 0) {
875            tagList = Array.from(new Set(tags.map(function (element) { return _this.tagConverter(element); })));
876        }
877        // Add "homepage" if we are on the homepage
878        return tagList;
879    };
880    IOLComercialPlatform.prototype.tagConverter = function (s) {
881        var lower = s.toLowerCase();
882        var normal = lower.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
883        return normal.replace(/ /g, "");
884    };
885    IOLComercialPlatform.prototype.getPubTag = function () {
886        var metatag = document.querySelector("meta[property='iol:pub_tag']");
887        var pubtag = (metatag === null || metatag === void 0 ? void 0 : metatag.getAttribute("content")) || "";
888        if (pubtag) {
889            var sectionList = this.tagConverter(pubtag);
890            return sectionList;
891        }
892    };
893    IOLComercialPlatform.prototype.getSectionTags = function () {
894        var metapsection = document.querySelector("meta[property='iol:parent_section']");
895        var metasection = document.querySelector("meta[property='iol:section']");
896        var psection = (metapsection === null || metapsection === void 0 ? void 0 : metapsection.getAttribute("content")) || "";
897        var section = (metasection === null || metasection === void 0 ? void 0 : metasection.getAttribute("content")) || "";
898        var sectionList = [
899            this.tagConverter(psection),
900            this.tagConverter(section)
901        ];
902        return sectionList;
903    };
904    IOLComercialPlatform.prototype.getControlTags = function () {
905        var _this = this;
906        var metactag = document.querySelector("meta[property='iol:ctags']");
907        var ctags = (metactag === null || metactag === void 0 ? void 0 : metactag.getAttribute("content")) || "";
908        var ctagList = [];
909        if (ctags !== "") {
910            var arr = ctags.split(", ");
911            ctagList = arr.map(function (element) {
912                return _this.tagConverter(element);
913            });
914        }
915        return ctagList;
916    };
917    IOLComercialPlatform.prototype.getProjTag = function () {
918        var _a;
919        var projTag = ((_a = document.querySelector("meta[property='iol:project']")) === null || _a === void 0 ? void 0 : _a.getAttribute("content")) || "";
920        return projTag ? this.tagConverter(projTag) : "";
921    };
922    IOLComercialPlatform.prototype.isPlatformLoadedCorrectly = function () {
923        return !(Object.keys(this.AMGoogleTag).length === 0 &&
924            this.AMGoogleTag.constructor === Object);
925    };
926    IOLComercialPlatform.prototype.preloadMainPlacements = function () {
927        var _this = this;
928        if (!this.isPlatformLoadedCorrectly()) {
929            console.error("IOLCOMERCIAL: No googletag available");
930            return;
931        }
932        this.loadPlacements(false);
933        this.AMGoogleTag.cmd.push(function () {
934            var _a, _b, _c, _d;
935            _this.AMGoogleTag.pubads().enableSingleRequest();
936            _this.AMGoogleTag.pubads().setSafeFrameConfig({
937                allowOverlayExpansion: true,
938                allowPushExpansion: true,
939                sandbox: true,
940            });
941            _this.AMGoogleTag.pubads().enableLazyLoad({
942                // Fetch slots within 2 viewports.
943                fetchMarginPercent: 200,
944                // Render slots within 1 viewports.
945                renderMarginPercent: 100,
946                // Double the above values on mobile, where viewports are smaller
947                // and users tend to scroll faster.
948                mobileScaling: 1.5,
949            });
950            _this.AMGoogleTag.pubads().collapseEmptyDivs(true);
951            _this.AMGoogleTag.pubads().setPublisherProvidedId(_this.ppID);
952            var isTVIPlayer = _this.location === "TVI Player";
953            if (((_a = _this.tags) === null || _a === void 0 ? void 0 : _a.length) > 0) {
954                console.log('tags', _this.tags);
955                _this.AMGoogleTag.pubads().setTargeting("category", _this.tags);
956            }
957            else if (isTVIPlayer && ((_b = _this.tags) === null || _b === void 0 ? void 0 : _b[0]) !== "tviplayer") {
958                _this.AMGoogleTag.pubads().setTargeting("programa", _this.tags[0]);
959            }
960            // Set targeting based on live pubTag
961            if (_this.pubTag) {
962                _this.AMGoogleTag.pubads().setTargeting("lives", _this.pubTag);
963            }
964            // Set universal targeting if ctags exist
965            if (((_c = _this.ctags) === null || _c === void 0 ? void 0 : _c.length) > 0) {
966                _this.AMGoogleTag.pubads().setTargeting("universal", _this.ctags);
967            }
968            // Set targeting based on section
969            if (((_d = _this.section) === null || _d === void 0 ? void 0 : _d.length) > 0) {
970                var _e = _this.section, parentSection = _e[0], section = _e[1];
971                if (parentSection) {
972                    _this.AMGoogleTag.pubads().setTargeting("parentsection", parentSection);
973                }
974                if (section) {
975                    _this.AMGoogleTag.pubads().setTargeting("section", section);
976                }
977            }
978            if (_this.projTag) {
979                _this.AMGoogleTag.pubads().setTargeting("project", _this.projTag);
980            }
981            _this.AMGoogleTag.pubads().disableInitialLoad();
982            _this.AMGoogleTag.enableServices();
983            console.info("IOLCOMERCIAL: Preloaded " + Object.keys(_this.slotsIndex).length);
984            _this.hasPreloaded = true;
985        });
986    };
987    IOLComercialPlatform.prototype.loadNewPlacements = function () {
988        if (this.hasPreloaded) {
989            var loaded = Object.keys(this.slotsIndex).length;
990            this.loadPlacements(true);
991            console.info("IOLCOMERCIAL: " + (Object.keys(this.slotsIndex).length - loaded) + " were loaded");
992        }
993        else {
994            console.info("IOLCOMERCIAL: waiting for preloading.");
995        }
996    };
997    IOLComercialPlatform.prototype.loadAllPlacementsIntoPage = function () {
998        var _this = this;
999        var adSlots = document.querySelectorAll('.iol-comercial-placement-loaded');
1000        adSlots.forEach(function (slot) {
1001            if (_this.isAboveFold(slot, 200)) {
1002                _this.AMGoogleTag.cmd.push(function () {
1003                    _this._runPrebidForSlot(slot.id, function () {
1004                        _this.refresh(slot.id);
1005                        slot.classList.add("iol-comercial-placement-displayed");
1006                        console.log("IO - display ad: " + slot.id);
1007                    });
1008                });
1009            }
1010            else {
1011                _this.lazyLoadAdSlot(slot);
1012            }
1013        });
1014    };
1015    IOLComercialPlatform.prototype.refresh = function (slotName) {
1016        var _this = this;
1017        if (!this.isPlatformLoadedCorrectly()) {
1018            console.error("IOLCOMERCIAL: No googletag available");
1019            return;
1020        }
1021        var refreshSlots = this.refreshableSlotsIndex;
1022        if (slotName) {
1023            var slot = this.slotsIndex[slotName];
1024            refreshSlots = slot ? [slot["AMslot"]] : undefined;
1025        }
1026        if (refreshSlots) {
1027            this.AMGoogleTag.cmd.push(function () {
1028                _this.AMGoogleTag.pubads().refresh(refreshSlots, {
1029                    changeCorrelator: false
1030                });
1031            });
1032            console.info("IOLCOMERCIAL: Refreshed with sucess (" + (slotName ? slotName : "all") + ")");
1033        }
1034        else {
1035            console.error("\"IOLCOMERCIAL: Couldn't refresh (" + slotName + " doesn't exists)");
1036        }
1037    };
1038    IOLComercialPlatform.prototype.refreshDisplayedSlots = function () {
1039        var _this = this;
1040        var adSlotsDisplayed = document.querySelectorAll('.iol-comercial-placement-displayed');
1041        var refreshSlots = [];
1042        adSlotsDisplayed.forEach(function (slot) {
1043            if (_this.slotsIndex[slot.id] && _this.slotsIndex[slot.id].isRefreshable) {
1044                refreshSlots.push(_this.slotsIndex[slot.id]["AMslot"]);
1045            }
1046        });
1047        this.AMGoogleTag.cmd.push(function () {
1048            _this.AMGoogleTag.pubads().refresh(refreshSlots, {
1049                changeCorrelator: false
1050            });
1051        });
1052    };
1053    IOLComercialPlatform.prototype.createNewPlacement = function (divID) {
1054        var element = document.getElementById(divID);
1055        var slotId = element.id;
1056        var slotFormat = element["dataset"]["iolComercialFormat"];
1057        var slotPositionStr = element["dataset"]["iolComercialFormatPosition"];
1058        var slotPosition;
1059        try {
1060            slotPosition = slotPositionStr ? parseInt(slotPositionStr) : undefined;
1061        }
1062        catch (_a) {
1063            slotPosition = undefined;
1064        }
1065        if (this.checkRestrictions(element)) {
1066            var slot = IOLComercialFormatCreator.createSlotModel(slotId, slotFormat, slotPosition);
1067            this.addNewPlacement(slot);
1068        }
1069        else {
1070            element.remove();
1071        }
1072    };
1073    IOLComercialPlatform.prototype.createSlot = function (slot) {
1074        var _this = this;
1075        this.AMGoogleTag.cmd.push(function () {
1076            var AMslot = undefined;
1077            //begin of anchor
1078            if (slot.formatName == "ANCHOR") {
1079                AMslot = _this.AMGoogleTag.defineOutOfPageSlot(_this.AMUnit + "/" + slot.formatName, _this.AMGoogleTag.enums.OutOfPageFormat.BOTTOM_ANCHOR);
1080            }
1081            else {
1082                AMslot = _this.AMGoogleTag.defineSlot(_this.AMUnit + "/" + slot.formatName, slot.sizes, slot.name);
1083            }
1084            //Defining Viewports
1085            if (slot.viewports) {
1086                var mapping_1 = _this.AMGoogleTag.sizeMapping();
1087                slot.viewports.forEach(function (vp) {
1088                    mapping_1.addSize(vp["viewport"], vp["sizes"]);
1089                });
1090                AMslot = AMslot.defineSizeMapping(mapping_1.build());
1091            }
1092            AMslot.addService(_this.AMGoogleTag.pubads()).setTargeting("sizes", slot.sizes);
1093            //Define Targeting
1094            if (slot.key_values) {
1095                for (var _i = 0, _a = Object.entries(slot.key_values); _i < _a.length; _i++) {
1096                    var _b = _a[_i], key = _b[0], value = _b[1];
1097                    AMslot = AMslot.setTargeting(key, value);
1098                }
1099            }
1100            slot["AMslot"] = AMslot;
1101            _this.slotsIndex[slot.name] = slot;
1102            //this.AMGoogleTag.display(slot.name);
1103            if (slot.isRefreshable) {
1104                _this.refreshableSlotsIndex.push(AMslot);
1105            }
1106        });
1107    };
1108    IOLComercialPlatform.prototype.loadPlacements = function (shouldDisplay) {
1109        var _this = this;
1110        while (this.slotQueue.length > 0)
1111            this.createSlot(this.slotQueue.pop());
1112        var placement = document.querySelectorAll(".iol-comercial-placement");
1113        placement.forEach(function (element) {
1114            var slotId = element.id;
1115            var slotFormat = element["dataset"]["iolComercialFormat"];
1116            var slotPositionStr = element["dataset"]["iolComercialFormatPosition"];
1117            var slotPosition;
1118            try {
1119                slotPosition = slotPositionStr ? parseInt(slotPositionStr) : undefined;
1120            }
1121            catch (_a) {
1122                slotPosition = undefined;
1123            }
1124            if (_this.checkRestrictions(element)) {
1125                var slot = IOLComercialFormatCreator.createSlotModel(slotId, slotFormat, slotPosition);
1126                _this.addNewPlacement(slot);
1127                element.classList.add("iol-comercial-placement-loaded");
1128                element.classList.remove("iol-comercial-placement");
1129                if (slot.extraCSS)
1130                    element.classList.add(slot.extraCSS);
1131                if (shouldDisplay)
1132                    _this.refresh(slotId);
1133            }
1134            else {
1135                element.remove();
1136            }
1137        });
1138    };
1139    IOLComercialPlatform.prototype.addNewPlacement = function (slot) {
1140        if (!slot)
1141            return;
1142        if (!this.isPlatformLoadedCorrectly()) {
1143            this.slotQueue.push(slot);
1144            console.error("IOLCOMERCIAL: Added to queue");
1145            return;
1146        }
1147        if (this.slotsIndex[slot.name]) {
1148            console.error("IOLCOMERCIAL: Slot name already exists");
1149            return;
1150        }
1151        this.createSlot(slot);
1152    };
1153    IOLComercialPlatform.prototype.checkRestrictions = function (element) {
1154        return this.checkScreenRestriction(element);
1155    };
1156    IOLComercialPlatform.prototype.checkScreenRestriction = function (element) {
1157        var screenWidth = window.innerWidth;
1158        var screenMinRestriction = element["dataset"]["iolComercialMinScreenWitdh"];
1159        var screenMaxRestriction = element["dataset"]["iolComercialMaxScreenWitdh"];
1160        if (!screenMinRestriction && !screenMaxRestriction)
1161            return true;
1162        try {
1163            screenMinRestriction = screenMinRestriction
1164                ? parseInt(screenMinRestriction)
1165                : undefined;
1166            screenMaxRestriction = screenMaxRestriction
1167                ? parseInt(screenMaxRestriction)
1168                : undefined;
1169            if (screenMinRestriction &&
1170                !screenMaxRestriction &&
1171                screenWidth > screenMinRestriction)
1172                return true;
1173            if (screenMaxRestriction &&
1174                !screenMinRestriction &&
1175                screenWidth < screenMaxRestriction)
1176                return true;
1177            if (screenMinRestriction &&
1178                screenMaxRestriction &&
1179                screenWidth > screenMinRestriction &&
1180                screenWidth < screenMaxRestriction)
1181                return true;
1182        }
1183        catch (error) {
1184            console.error("IOLCOMERCIAL: Screen Restriction not valid.");
1185        }
1186        return false;
1187    };
1188    IOLComercialPlatform.prototype.shouldAdsBeLoaded = function (project) {
1189        var sluserx1 = localStorage.getItem("userx1");
1190        if (!sluserx1)
1191            return true;
1192        var user;
1193        try {
1194            user = JSON.parse(sluserx1);
1195        }
1196        catch (_a) {
1197            return true;
1198        }
1199        var subscribedProducts = user === null || user === void 0 ? void 0 : user.subscribedProducts;
1200        if (!(subscribedProducts === null || subscribedProducts === void 0 ? void 0 : subscribedProducts.length))
1201            return true;
1202        var noAdsProducts = project === "tviplayer"
1203            ? this.noPubProducts
1204            : this.noPubPremiumProducts;
1205        var isSubbed = noAdsProducts.some(function (p) {
1206            return subscribedProducts.includes(p);
1207        });
1208        return !isSubbed;
1209    };
1210    IOLComercialPlatform.prototype.removeAllPlacements = function () {
1211        var placement = document.querySelectorAll(".iol-comercial-placement");
1212        placement.forEach(function (element) {
1213            element.remove();
1214        });
1215    };
1216    IOLComercialPlatform.prototype.removeAllPlacementWrappers = function () {
1217        console.info("IOLCOMERCIAL: removing ads wrappers");
1218        var placement = document.querySelectorAll(".mcd-hidden-block");
1219        placement.forEach(function (element) {
1220            element.remove();
1221        });
1222    };
1223    IOLComercialPlatform.prototype.lazyLoadAdSlot = function (slot) {
1224        var _this = this;
1225        var observer = new IntersectionObserver(function (entries) {
1226            entries.forEach(function (entry) {
1227                if (entry.isIntersecting) {
1228                    _this.AMGoogleTag.cmd.push(function () {
1229                        _this._runPrebidForSlot(slot.id, function () {
1230                            _this.refresh(slot.id);
1231                            slot.classList.add("iol-comercial-placement-displayed");
1232                            console.log("IO - display ad: " + slot.id);
1233                        });
1234                    });
1235                    observer.unobserve(slot);
1236                }
1237            });
1238        }, {
1239            rootMargin: '250px'
1240        });
1241        observer.observe(slot);
1242    };
1243    IOLComercialPlatform.prototype.isAboveFold = function (element, threshold) {
1244        if (threshold === void 0) { threshold = 0; }
1245        var rect = element.getBoundingClientRect();
1246        return rect.top < (window.innerHeight + threshold);
1247    };
1248    IOLComercialPlatform.prototype.ensurePrebidConfigured = function (pbjs) {
1249        if (this.prebidConfigured)
1250            return;
1251        setPrebidConfig(pbjs, this.project);
1252        this.prebidConfigured = true;
1253    };
1254    IOLComercialPlatform.prototype.attachPrebidListeners = function (pbjs) {
1255        if (this.prebidListenersAttached)
1256            return;
1257        this.prebidListenersAttached = true;
1258        var debugMode = localStorage.getItem("pbdebug") === "1";
1259        pbjs.onEvent("bidResponse", function (bid) {
1260            if (debugMode)
1261                console.log("bidResponse:", bid);
1262        });
1263        pbjs.onEvent("noBid", function (info) {
1264            if (debugMode)
1265                console.log("noBid:", info);
1266        });
1267        pbjs.onEvent("auctionEnd", function (data) {
1268            if (debugMode)
1269                console.log("auctionEnd:", data);
1270        });
1271    };
1272    IOLComercialPlatform.prototype._runPrebidForSlot = function (slotId, done) {
1273        var _this = this;
1274        var pbjs = window["pbjs"];
1275        if (!pbjs || !pbjs.que) {
1276            console.warn("Prebid not ready, skipping bids for slot:", slotId);
1277            done();
1278            return;
1279        }
1280        var debugMode = localStorage.getItem("pbdebug") === "1";
1281        pbjs.que.push(function () {
1282            var _a, _b, _c;
1283            // apply your global Prebid config
1284            _this.ensurePrebidConfigured(pbjs);
1285            var el = document.getElementById(slotId);
1286            if (!el) {
1287                // console.warn("Slot not found:", slotId);
1288                done();
1289                return;
1290            }
1291            var format = el.getAttribute("data-iol-comercial-format") || "LEADERBOARD";
1292            var adUnit = createPrebidAdUnit(slotId, format);
1293            if (adUnit == null) {
1294                done();
1295                return;
1296            }
1297            if (!adUnit.bids || adUnit.bids.length === 0) {
1298                if (debugMode) {
1299                    console.info("Skipping Prebid auction for " + slotId + " \u2014 no bidders configured.");
1300                }
1301                done();
1302                return;
1303            }
1304            var hasValidSizes = ((_c = (_b = (_a = adUnit.mediaTypes) === null || _a === void 0 ? void 0 : _a.banner) === null || _b === void 0 ? void 0 : _b.sizes) === null || _c === void 0 ? void 0 : _c.length) &&
1305                adUnit.mediaTypes.banner.sizes.every(function (s) { return Array.isArray(s) && s.length === 2 && s.every(Number.isFinite); });
1306            if (!hasValidSizes) {
1307                console.info("Skipping Prebid auction for " + slotId + " \u2014 no valid sizes defined.");
1308                done();
1309                return;
1310            }
1311            // register the adUnit
1312            pbjs.removeAdUnit(adUnit.code);
1313            pbjs.addAdUnits([adUnit]);
1314            if (debugMode) {
1315                console.group("Prebid Debug for " + slotId);
1316                console.log("All ad units currently registered:", pbjs.adUnits);
1317            }
1318            _this.attachPrebidListeners(pbjs);
1319            pbjs.requestBids({
1320                adUnits: [adUnit],
1321                timeout: 3000,
1322                bidsBackHandler: function () {
1323                    if (debugMode) {
1324                        console.info("Prebid: Auction for  " + adUnit.code);
1325                    }
1326                    var winningBids = pbjs.getHighestCpmBids(adUnit.code);
1327                    var hasBids = winningBids.length > 0;
1328                    if (hasBids) {
1329                        if (debugMode) {
1330                            console.info("Prebid: Bids found for " + adUnit.code + ", winning bid:", winningBids[0]);
1331                        }
1332                    }
1333                    else {
1334                        if (debugMode) {
1335                            console.info("Prebid: No bids for " + adUnit.code);
1336                        }
1337                    }
1338                    pbjs.setTargetingForGPTAsync([adUnit.code]);
1339                    done();
1340                }
1341            });
1342        });
1343    };
1344    return IOLComercialPlatform;
1345}());
1346
1347var IOLComercial = /** @class */ (function () {
1348    function IOLComercial(project, platform, section, contentType, quantcast) {
1349        var _this = this;
1350        //ADUNIT RULE: code/project/platform/section/contentType/format
1351        this.AMCode = "130294768";
1352        this.project = project;
1353        this.platform = platform;
1354        this.pageSection = section;
1355        this.pageContentType = contentType;
1356        var AMUnit = "/" + this.AMCode + "/" + this.project + "/" + this.platform;
1357        if (this.pageSection) {
1358            AMUnit += "/" + this.pageSection;
1359        }
1360        if (this.pageContentType) {
1361            AMUnit += "/" + this.pageContentType;
1362        }
1363        this.iolComercialPlatform = new IOLComercialPlatform(AMUnit, this.project);
1364        if (this.iolComercialPlatform.shouldAdsBeLoaded(this.project)) {
1365            this.iolComercialPlatform.loadDependencies(function () {
1366                _this.loadStyle();
1367                _this.iolComercialPlatform.preloadMainPlacements();
1368                var development = document.location.host.includes("localhost") || document.location.host.includes("dev.");
1369                if (quantcast && !development) {
1370                    _this.waitForQuantcast();
1371                }
1372                else {
1373                    if (development)
1374                        console.info("IOLCOMERCIAL: DEV MODE");
1375                    _this.iolComercialPlatform.loadAllPlacementsIntoPage();
1376                }
1377            });
1378        }
1379        else {
1380            this.iolComercialPlatform.removeAllPlacements();
1381            this.iolComercialPlatform.removeAllPlacementWrappers();
1382            this.iolComercialPlatform.loadDependencies(function () { });
1383        }
1384    }
1385    IOLComercial.prototype.refreshSlot = function (slotname) {
1386        this.iolComercialPlatform.refresh(slotname);
1387    };
1388    IOLComercial.prototype.refreshAllSlots = function () {
1389        this.iolComercialPlatform.refreshDisplayedSlots();
1390    };
1391    IOLComercial.prototype.addNewPlacementByName = function (divID) {
1392        this.iolComercialPlatform.createNewPlacement(divID);
1393    };
1394    IOLComercial.prototype.loadNewPlacements = function () {
1395        this.iolComercialPlatform.loadNewPlacements();
1396    };
1397    IOLComercial.prototype.loadStyle = function () {
1398        var head = document.head || document.getElementsByTagName("head")[0];
1399        var style = document.createElement("style");
1400        var css = ".iol-comercial-placement-label > div:before {\n                  content:'PUBLICIDADE';\n                  display:block;\n                  text-align: center;\n                  color:#808080;\n                  font-size: 9px;\n                  font-family: 'Arial';\n                  line-height: 16px;\n              }\n              [data-iol-comercial-format=\"MPU2\"], [data-iol-comercial-format=\"MPU_HALF\"] {\n                > div{\n                    margin-top:16px;\n                    &:before {\n                        margin-top: -16px;\n                    }\n                }\n            }";
1401        style.type = "text/css";
1402        style.appendChild(document.createTextNode(css));
1403        head.appendChild(style);
1404    };
1405    IOLComercial.prototype.waitForQuantcast = function () {
1406        var _this = this;
1407        var count = 0;
1408        var consentCheckInterval = setInterval(function () {
1409            var _a;
1410            if (window["__tcfapi"] || count == 60) {
1411                try {
1412                    (_a = window["__tcfapi"]) === null || _a === void 0 ? void 0 : _a.call(window, "addEventListener", 2, function (tcData, success) {
1413                        if (success && tcData.tcString) {
1414                            _this.iolComercialPlatform.loadAllPlacementsIntoPage();
1415                            window["__tcfapi"]("removeEventListener", 2, function (success) {
1416                                if (success)
1417                                    console.info("IOLCOMERCIAL: Quantcast listener removed");
1418                            }, tcData.listenerId);
1419                        }
1420                    });
1421                    clearInterval(consentCheckInterval);
1422                }
1423                catch (error) {
1424                    console.error(error);
1425                    clearInterval(consentCheckInterval);
1426                    console.error("IOLCOMERCIAL: CMP not loaded");
1427                }
1428            }
1429            count++;
1430        }, 100);
1431    };
1432    return IOLComercial;
1433}());
1434
1435window.IOLComercial = IOLComercial;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.