@inappstory/slide-api 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -563,8 +563,8 @@ const getWinWidth = function (env) {
563
563
  const getWinHeight = function (env) {
564
564
  return env.innerHeight || env.document.documentElement.clientHeight || env.document.body.clientHeight;
565
565
  };
566
- const sendStatisticEventToApp = function (sdkApi, name, data, devPayload, options) {
567
- sdkApi.sendStatisticEvent(name, data, devPayload, options?.forceEnableStatisticV2 ?? false);
566
+ const sendStatisticEventToApp = function (slideApiDeps, name, data, devPayload, options) {
567
+ slideApiDeps.sendStatisticEvent(name, data, devPayload, options?.forceEnableStatisticV2 ?? false);
568
568
  };
569
569
  const getValueOrException = function (value, message) {
570
570
  if (value == null) {
@@ -1175,6 +1175,13 @@ class EsModuleSdkApi {
1175
1175
  isSdkSupportCorrectPauseResumeLifecycle() {
1176
1176
  return true;
1177
1177
  }
1178
+ emitEvent(name, event) {
1179
+ this.sdkBinding.onEvent(name, event);
1180
+ }
1181
+ onCardLoadingStateChange(state, reason) {
1182
+ console.log("onCardLoadingStateChange", { state });
1183
+ this.sdkBinding.onCardLoadingStateChange(state, reason);
1184
+ }
1178
1185
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKInterface`]; }
1179
1186
  }
1180
1187
 
@@ -1201,6 +1208,9 @@ class DataInput {
1201
1208
  return element instanceof DataInput;
1202
1209
  }
1203
1210
  mediaElementsLoadingPromises = [];
1211
+ get nodeRef() {
1212
+ return this._elementNodeRef;
1213
+ }
1204
1214
  init(localData) {
1205
1215
  try {
1206
1216
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1251,6 +1261,9 @@ class Barcode {
1251
1261
  this._widgetDeps = _widgetDeps;
1252
1262
  }
1253
1263
  mediaElementsLoadingPromises = [];
1264
+ get nodeRef() {
1265
+ return this._elementNodeRef;
1266
+ }
1254
1267
  init(localData) {
1255
1268
  try {
1256
1269
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1288,36 +1301,311 @@ class ClickableBase {
1288
1301
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`]; }
1289
1302
  }
1290
1303
 
1304
+ class PromocodeNetworkError extends Error {
1305
+ }
1306
+ class PromocodeServiceError extends Error {
1307
+ }
1308
+ class PromocodeNoMoreCodes extends Error {
1309
+ }
1310
+ class PromocodeApi {
1311
+ sdkApi;
1312
+ messages;
1313
+ constructor(sdkApi, messages) {
1314
+ this.sdkApi = sdkApi;
1315
+ this.messages = messages;
1316
+ }
1317
+ async fetchPromoCode(params) {
1318
+ const path = this.getPromotionalCodeFetchPath(params);
1319
+ const headers = {
1320
+ accept: "application/json",
1321
+ "Content-Type": "application/json",
1322
+ };
1323
+ const [response] = await Promise.all([
1324
+ this.sdkApi.sendApiRequest(path, "POST", null, headers, null, "fetch-promo-code"),
1325
+ new Promise(resolve => setTimeout(resolve, 300)),
1326
+ ]);
1327
+ const { status, data } = response;
1328
+ if (status === 200 || status === 201) {
1329
+ const promocode = data?.code;
1330
+ if (promocode) {
1331
+ return { promocode, status };
1332
+ }
1333
+ throw new PromocodeNoMoreCodes(this.messages.noMoreCodes);
1334
+ }
1335
+ if (status === 12163 || status === 12002) {
1336
+ throw new PromocodeNetworkError(this.messages.networkError);
1337
+ }
1338
+ throw new PromocodeServiceError(this.messages.serviceError);
1339
+ }
1340
+ getPromotionalCodeFetchPath(params) {
1341
+ switch (params.card.type) {
1342
+ case 4 /* CARD_TYPE.IN_APP_MESSAGING */:
1343
+ return `inappmessaging/message/${params.card.id}/widget/${params.elementId}/promo-code/${params.promocodeId}`;
1344
+ default:
1345
+ return `story/${params.card.id}/widget/${params.elementId}/promo-code/${params.promocodeId}`;
1346
+ }
1347
+ }
1348
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Pick`, `{
1349
+ noMoreCodes?: string;
1350
+ networkError?: string;
1351
+ serviceError?: string;
1352
+ }`]; }
1353
+ }
1354
+
1355
+ class PromocodeLocalRepository {
1356
+ elementId;
1357
+ sdkApi;
1358
+ localData = {};
1359
+ constructor(elementId, sdkApi) {
1360
+ this.elementId = elementId;
1361
+ this.sdkApi = sdkApi;
1362
+ }
1363
+ init({ localData, cardId }) {
1364
+ const savedData = this.sdkApi.getCardServerData(cardId) ?? {};
1365
+ this.localData = extend({}, savedData, localData ?? {});
1366
+ }
1367
+ getPromocode() {
1368
+ return this.localData["_pcl_g_" + this.elementId + "_pc"];
1369
+ }
1370
+ savePromocodeByStatus(promocode, status) {
1371
+ if (status === 201)
1372
+ this.savePromocodeWithTime(promocode);
1373
+ else
1374
+ this.savePromocode(promocode);
1375
+ }
1376
+ savePromocodeWithTime(promocode) {
1377
+ this.localData["_pcl_g_" + this.elementId + "_pc_fetched_at"] = Math.round(new Date().getTime() / 1000);
1378
+ this.localData["_&ts_pcl_g_" + this.elementId + "_pc_fetched_at"] = Math.round(new Date().getTime() / 1000);
1379
+ this.savePromocode(promocode);
1380
+ }
1381
+ savePromocode(promocode) {
1382
+ this.localData["_pcl_g_" + this.elementId + "_pc"] = promocode;
1383
+ this.setCardLocalData(this.localData);
1384
+ }
1385
+ async setCardLocalData(newLocalData) {
1386
+ const localData = await this.sdkApi.getCardLocalData();
1387
+ const mergedData = extend({}, localData, newLocalData);
1388
+ await this.sdkApi.setCardLocalData(mergedData, true);
1389
+ }
1390
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`string`, `ISlideApiDeps`]; }
1391
+ }
1392
+
1393
+ var PromocodeLinkState;
1394
+ (function (PromocodeLinkState) {
1395
+ PromocodeLinkState[PromocodeLinkState["Idle"] = 0] = "Idle";
1396
+ PromocodeLinkState[PromocodeLinkState["Fetched"] = 1] = "Fetched";
1397
+ PromocodeLinkState[PromocodeLinkState["Error"] = 2] = "Error";
1398
+ })(PromocodeLinkState || (PromocodeLinkState = {}));
1399
+ const PROMOCODE_PLACEHOLDER = "%__ias_pc%";
1400
+ class PromocodeLink {
1401
+ element;
1402
+ layer;
1403
+ widgetDeps;
1404
+ state = PromocodeLinkState.Idle;
1405
+ promocode = null;
1406
+ promocodeId;
1407
+ linkTemplate;
1408
+ textContent;
1409
+ button;
1410
+ elementId;
1411
+ card;
1412
+ api;
1413
+ localRepository;
1414
+ constructor(element, layer, widgetDeps) {
1415
+ this.element = element;
1416
+ this.layer = layer;
1417
+ this.widgetDeps = widgetDeps;
1418
+ this.elementId = getValueOrException(getTagData(this.element, "elementId"), "Empty elementId");
1419
+ this.promocodeId = getTagData(this.element, "linkTarget") ?? "";
1420
+ this.linkTemplate = getTagData(this.element, "linkTemplate") ?? "";
1421
+ this.button = this.element.querySelector(".narrative-element-text-lines");
1422
+ this.textContent = this.button?.textContent ?? "";
1423
+ this.card = this.getCard();
1424
+ this.api = new PromocodeApi(this.widgetDeps.slideApiDeps, {
1425
+ networkError: getTagData(this.element, "msgNetworkError") ?? "",
1426
+ serviceError: getTagData(this.element, "msgServiceError") ?? "",
1427
+ noMoreCodes: getTagData(this.element, "msgNoMoreCodes") ?? "",
1428
+ });
1429
+ this.localRepository = new PromocodeLocalRepository(this.elementId, this.widgetDeps.slideApiDeps);
1430
+ }
1431
+ get nodeRef() {
1432
+ return this.element;
1433
+ }
1434
+ mediaElementsLoadingPromises = [];
1435
+ init(localData) {
1436
+ this.localRepository.init({ localData: localData ?? {}, cardId: this.card.id });
1437
+ this.state = PromocodeLinkState.Idle;
1438
+ const promocode = this.localRepository.getPromocode();
1439
+ if (promocode) {
1440
+ this.state = PromocodeLinkState.Fetched;
1441
+ this.showPromocode(promocode);
1442
+ this.promocode = promocode;
1443
+ }
1444
+ return Promise.resolve(true);
1445
+ }
1446
+ onPause() { }
1447
+ onResume() { }
1448
+ onStop() { }
1449
+ onBeforeUnmount() {
1450
+ return Promise.resolve();
1451
+ }
1452
+ handleClick() {
1453
+ switch (this.state) {
1454
+ case PromocodeLinkState.Idle:
1455
+ return false;
1456
+ case PromocodeLinkState.Fetched:
1457
+ this.openPromocodeUrl();
1458
+ return true;
1459
+ case PromocodeLinkState.Error:
1460
+ this.loadPromocode(this.promocodeId).catch(() => { });
1461
+ break;
1462
+ }
1463
+ return false;
1464
+ }
1465
+ get isLayerForcePaused() {
1466
+ return false;
1467
+ }
1468
+ onStart() {
1469
+ this.element.classList.add("active");
1470
+ this.loadPromocode(this.promocodeId).catch(() => { });
1471
+ }
1472
+ openPromocodeUrl() {
1473
+ if (!this.promocode)
1474
+ return;
1475
+ const target = this.linkTemplate.replaceAll(PROMOCODE_PLACEHOLDER, this.promocode);
1476
+ this.layer.layoutService.env.setTimeout(() => {
1477
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target } });
1478
+ });
1479
+ }
1480
+ async loadPromocode(promocodeId) {
1481
+ try {
1482
+ this.state = PromocodeLinkState.Idle;
1483
+ this.showLoader();
1484
+ const promocode = await this.getPromocode({
1485
+ promocodeId,
1486
+ card: this.card,
1487
+ elementId: this.elementId,
1488
+ });
1489
+ this.state = PromocodeLinkState.Fetched;
1490
+ this.promocode = promocode;
1491
+ this.showPromocode(promocode);
1492
+ return promocode;
1493
+ }
1494
+ catch (error) {
1495
+ this.handleLoadPromocodeError(error);
1496
+ throw error;
1497
+ }
1498
+ finally {
1499
+ this.hideLoader();
1500
+ }
1501
+ }
1502
+ async getPromocode(params) {
1503
+ if (this.promocode)
1504
+ return this.promocode;
1505
+ let promocode = this.localRepository.getPromocode();
1506
+ if (!promocode) {
1507
+ const result = await this.api.fetchPromoCode(params);
1508
+ promocode = result.promocode;
1509
+ this.localRepository.savePromocodeByStatus(promocode, result.status);
1510
+ }
1511
+ this.promocode = promocode;
1512
+ return promocode;
1513
+ }
1514
+ handleLoadPromocodeError(error) {
1515
+ this.state = PromocodeLinkState.Error;
1516
+ this.showErrorMessage(getTagData(this.element, "msgTryAgain") ?? "");
1517
+ if (error.message.length) {
1518
+ this.widgetDeps.slideApiDeps.showToast(error.message);
1519
+ }
1520
+ }
1521
+ showPromocode(promocode) {
1522
+ if (!this.button)
1523
+ return;
1524
+ this.button.textContent = this.textContent.replaceAll(PROMOCODE_PLACEHOLDER, promocode);
1525
+ }
1526
+ showErrorMessage(message) {
1527
+ if (!this.button)
1528
+ return;
1529
+ this.button.textContent = message;
1530
+ }
1531
+ getCard() {
1532
+ const slide = getValueOrException(this.element.closest(".narrative-slide"), "Empty slide");
1533
+ return {
1534
+ id: getValueOrException(getTagDataAsNumber(slide, "id"), "Empty cardId"),
1535
+ type: getValueOrException(getTagDataAsNumber(slide, "cardType"), "Empty card type"),
1536
+ };
1537
+ }
1538
+ showLoader() {
1539
+ if (!this.isTransparentElement())
1540
+ addClass(this.element, "loader");
1541
+ }
1542
+ hideLoader() {
1543
+ removeClass(this.element, "loader");
1544
+ }
1545
+ isTransparentElement() {
1546
+ if (this.element) {
1547
+ try {
1548
+ const color = window.getComputedStyle(this.element).color;
1549
+ if (color === "transparent" || color === "rgba(0, 0, 0, 0)" || color === "rgba(0,0,0,0)") {
1550
+ return true;
1551
+ }
1552
+ }
1553
+ catch (err) {
1554
+ console.error(err);
1555
+ }
1556
+ }
1557
+ return false;
1558
+ }
1559
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `WidgetDeps`]; }
1560
+ }
1561
+
1291
1562
  class Button extends ClickableBase {
1292
1563
  _elementNodeRef;
1293
- _layer;
1564
+ layer;
1565
+ widgetDeps;
1294
1566
  static _className = "narrative-element-link";
1567
+ isPromotionalCode;
1568
+ promocodeLink = null;
1295
1569
  static className() {
1296
1570
  return Button._className;
1297
1571
  }
1298
- constructor(_elementNodeRef, _layer) {
1572
+ static isTypeOf(element) {
1573
+ return element instanceof Button;
1574
+ }
1575
+ constructor(_elementNodeRef, layer, widgetDeps) {
1299
1576
  super(_elementNodeRef);
1300
1577
  this._elementNodeRef = _elementNodeRef;
1301
- this._layer = _layer;
1578
+ this.layer = layer;
1579
+ this.widgetDeps = widgetDeps;
1580
+ this.isPromotionalCode = getTagData(_elementNodeRef, "linkType") === "promocode";
1581
+ if (this.isPromotionalCode) {
1582
+ this.promocodeLink = new PromocodeLink(_elementNodeRef, layer, widgetDeps);
1583
+ }
1584
+ }
1585
+ get nodeRef() {
1586
+ return this._elementNodeRef;
1302
1587
  }
1303
1588
  mediaElementsLoadingPromises = [];
1304
- init(localData) {
1305
- return Promise.resolve(true);
1589
+ async init(localData) {
1590
+ await this.promocodeLink?.init(localData);
1591
+ return true;
1306
1592
  }
1307
1593
  onPause() { }
1308
1594
  onResume() { }
1309
- onStart() { }
1595
+ onStart() {
1596
+ this.promocodeLink?.onStart();
1597
+ }
1310
1598
  onStop() { }
1311
1599
  onBeforeUnmount() {
1312
1600
  return Promise.resolve();
1313
1601
  }
1314
1602
  handleClick() {
1315
- return false;
1603
+ return this.promocodeLink?.handleClick() ?? true;
1316
1604
  }
1317
1605
  get isLayerForcePaused() {
1318
1606
  return false;
1319
1607
  }
1320
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`]; }
1608
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `WidgetDeps`]; }
1321
1609
  }
1322
1610
 
1323
1611
  class Copy {
@@ -1338,6 +1626,9 @@ class Copy {
1338
1626
  this._widgetDeps = _widgetDeps;
1339
1627
  }
1340
1628
  mediaElementsLoadingPromises = [];
1629
+ get nodeRef() {
1630
+ return this._elementNodeRef;
1631
+ }
1341
1632
  init(localData) {
1342
1633
  try {
1343
1634
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1387,6 +1678,9 @@ class DateCountdown {
1387
1678
  this._widgetDeps = _widgetDeps;
1388
1679
  }
1389
1680
  mediaElementsLoadingPromises = [];
1681
+ get nodeRef() {
1682
+ return this._elementNodeRef;
1683
+ }
1390
1684
  init(localData) {
1391
1685
  try {
1392
1686
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1441,6 +1735,9 @@ class Poll {
1441
1735
  return element instanceof Poll;
1442
1736
  }
1443
1737
  mediaElementsLoadingPromises = [];
1738
+ get nodeRef() {
1739
+ return this._elementNodeRef;
1740
+ }
1444
1741
  init(localData) {
1445
1742
  try {
1446
1743
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1496,6 +1793,9 @@ class PollLayers {
1496
1793
  return element instanceof PollLayers;
1497
1794
  }
1498
1795
  mediaElementsLoadingPromises = [];
1796
+ get nodeRef() {
1797
+ return this._elementNodeRef;
1798
+ }
1499
1799
  init(localData) {
1500
1800
  try {
1501
1801
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1546,6 +1846,9 @@ class Products {
1546
1846
  return element instanceof Products;
1547
1847
  }
1548
1848
  mediaElementsLoadingPromises = [];
1849
+ get nodeRef() {
1850
+ return this._elementNodeRef;
1851
+ }
1549
1852
  init(localData) {
1550
1853
  try {
1551
1854
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1605,6 +1908,9 @@ class Quest {
1605
1908
  return element instanceof Quest;
1606
1909
  }
1607
1910
  mediaElementsLoadingPromises = [];
1911
+ get nodeRef() {
1912
+ return this._elementNodeRef;
1913
+ }
1608
1914
  init(localData) {
1609
1915
  return this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
1610
1916
  }
@@ -1653,6 +1959,9 @@ class Quiz {
1653
1959
  return element instanceof Quiz;
1654
1960
  }
1655
1961
  mediaElementsLoadingPromises = [];
1962
+ get nodeRef() {
1963
+ return this._elementNodeRef;
1964
+ }
1656
1965
  init(localData) {
1657
1966
  try {
1658
1967
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1706,6 +2015,9 @@ class QuizGrouped {
1706
2015
  return element instanceof QuizGrouped;
1707
2016
  }
1708
2017
  mediaElementsLoadingPromises = [];
2018
+ get nodeRef() {
2019
+ return this._elementNodeRef;
2020
+ }
1709
2021
  init(localData) {
1710
2022
  try {
1711
2023
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1759,6 +2071,9 @@ class RangeSlider {
1759
2071
  return element instanceof RangeSlider;
1760
2072
  }
1761
2073
  mediaElementsLoadingPromises = [];
2074
+ get nodeRef() {
2075
+ return this._elementNodeRef;
2076
+ }
1762
2077
  init(localData) {
1763
2078
  try {
1764
2079
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1812,6 +2127,9 @@ class Rate {
1812
2127
  return element instanceof Rate;
1813
2128
  }
1814
2129
  mediaElementsLoadingPromises = [];
2130
+ get nodeRef() {
2131
+ return this._elementNodeRef;
2132
+ }
1815
2133
  init(localData) {
1816
2134
  try {
1817
2135
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1868,6 +2186,9 @@ class Share {
1868
2186
  return element instanceof Share;
1869
2187
  }
1870
2188
  mediaElementsLoadingPromises = [];
2189
+ get nodeRef() {
2190
+ return this._elementNodeRef;
2191
+ }
1871
2192
  init(localData) {
1872
2193
  try {
1873
2194
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1915,6 +2236,9 @@ class SwipeUpItems {
1915
2236
  return element instanceof SwipeUpItems;
1916
2237
  }
1917
2238
  mediaElementsLoadingPromises = [];
2239
+ get nodeRef() {
2240
+ return this._elementNodeRef;
2241
+ }
1918
2242
  init(localData) {
1919
2243
  return Promise.resolve(true);
1920
2244
  }
@@ -1958,6 +2282,9 @@ class Test {
1958
2282
  return element instanceof Test;
1959
2283
  }
1960
2284
  mediaElementsLoadingPromises = [];
2285
+ get nodeRef() {
2286
+ return this._elementNodeRef;
2287
+ }
1961
2288
  init(localData) {
1962
2289
  try {
1963
2290
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2011,6 +2338,9 @@ class Tooltip {
2011
2338
  this._widgetDeps = _widgetDeps;
2012
2339
  }
2013
2340
  mediaElementsLoadingPromises = [];
2341
+ get nodeRef() {
2342
+ return this._elementNodeRef;
2343
+ }
2014
2344
  init(localData) {
2015
2345
  try {
2016
2346
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2058,6 +2388,9 @@ class Vote {
2058
2388
  this._widgetDeps = _widgetDeps;
2059
2389
  }
2060
2390
  mediaElementsLoadingPromises = [];
2391
+ get nodeRef() {
2392
+ return this._elementNodeRef;
2393
+ }
2061
2394
  init(localData) {
2062
2395
  try {
2063
2396
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2099,6 +2432,9 @@ class Text {
2099
2432
  this._layer = _layer;
2100
2433
  }
2101
2434
  mediaElementsLoadingPromises = [];
2435
+ get nodeRef() {
2436
+ return this._elementNodeRef;
2437
+ }
2102
2438
  init(localData) {
2103
2439
  return Promise.resolve(true);
2104
2440
  }
@@ -2222,6 +2558,9 @@ class Image extends ClickableBase {
2222
2558
  this.mediaElementsLoadingPromises = mediaElements.map(waitForImageHtmlElementLoad);
2223
2559
  }
2224
2560
  mediaElementsLoadingPromises = [];
2561
+ get nodeRef() {
2562
+ return this._elementNodeRef;
2563
+ }
2225
2564
  init(localData) {
2226
2565
  return Promise.resolve(true);
2227
2566
  }
@@ -2256,6 +2595,9 @@ class SwipeUp {
2256
2595
  return element instanceof SwipeUp;
2257
2596
  }
2258
2597
  mediaElementsLoadingPromises = [];
2598
+ get nodeRef() {
2599
+ return this._elementNodeRef;
2600
+ }
2259
2601
  init(localData) {
2260
2602
  return Promise.resolve(true);
2261
2603
  }
@@ -2282,7 +2624,7 @@ class Video {
2282
2624
  _elementNodeRef;
2283
2625
  _layer;
2284
2626
  _VideoPlayer;
2285
- _sdkApi;
2627
+ _slideApiDeps;
2286
2628
  static _className = "narrative-element-video";
2287
2629
  static className() {
2288
2630
  return Video._className;
@@ -2292,11 +2634,11 @@ class Video {
2292
2634
  _vodData;
2293
2635
  _vodPlayerInstance = null;
2294
2636
  _videoStateAdapter = null;
2295
- constructor(_elementNodeRef, _layer, _VideoPlayer, _sdkApi) {
2637
+ constructor(_elementNodeRef, _layer, _VideoPlayer, _slideApiDeps) {
2296
2638
  this._elementNodeRef = _elementNodeRef;
2297
2639
  this._layer = _layer;
2298
2640
  this._VideoPlayer = _VideoPlayer;
2299
- this._sdkApi = _sdkApi;
2641
+ this._slideApiDeps = _slideApiDeps;
2300
2642
  const _video = this._elementNodeRef.querySelector("video");
2301
2643
  if (!_video) {
2302
2644
  return;
@@ -2352,6 +2694,9 @@ class Video {
2352
2694
  return element instanceof Video;
2353
2695
  }
2354
2696
  mediaElementsLoadingPromises = [];
2697
+ get nodeRef() {
2698
+ return this._elementNodeRef;
2699
+ }
2355
2700
  init(localData) {
2356
2701
  return Promise.resolve(true);
2357
2702
  }
@@ -2371,6 +2716,9 @@ class Video {
2371
2716
  // console.log("onBeforeUnmount")
2372
2717
  return await this._destroyVODPlayer();
2373
2718
  }
2719
+ get durationMs() {
2720
+ return this._video.duration * 1000;
2721
+ }
2374
2722
  _initVOD(vodData) {
2375
2723
  const onWaiting = () => {
2376
2724
  /**
@@ -2396,7 +2744,7 @@ class Video {
2396
2744
  // TODO via class instead of data attr
2397
2745
  if (this._video.getAttribute("data-waiting") === "1") {
2398
2746
  this._video.setAttribute("data-waiting", "0");
2399
- this._layer.timeline.slideResumed(this._video.currentTime * 1000);
2747
+ this._layer.timeline.slideResumed(() => this._video.currentTime * 1000);
2400
2748
  // @ts-ignore
2401
2749
  // _log(`playing: ${this._video.currentTime}`, true);
2402
2750
  // clearTimeout(window.synthErrorId);
@@ -2480,13 +2828,13 @@ class Video {
2480
2828
  });
2481
2829
  }
2482
2830
  _convertMpdUrls(mpd_) {
2483
- if (this._sdkApi.isWeb) {
2831
+ if (this._slideApiDeps.isWeb) {
2484
2832
  return mpd_;
2485
2833
  }
2486
2834
  if (isObject(mpd_) && mpd_.adaptiveFormats != null && Array.isArray(mpd_.adaptiveFormats)) {
2487
2835
  const mpd = { ...mpd_ };
2488
2836
  for (let i = 0; i < mpd.adaptiveFormats.length; ++i) {
2489
- mpd.adaptiveFormats[i].url = `${this._sdkApi.isAndroid ? `http://vod-asset/` : `vod-asset://`}${mpd.adaptiveFormats[i].cacheName}`;
2837
+ mpd.adaptiveFormats[i].url = `${this._slideApiDeps.isAndroid ? `http://vod-asset/` : `vod-asset://`}${mpd.adaptiveFormats[i].cacheName}`;
2490
2838
  }
2491
2839
  return mpd;
2492
2840
  }
@@ -2521,7 +2869,13 @@ class Video {
2521
2869
  get videoStartedPromise() {
2522
2870
  return this._videoStartedPromise;
2523
2871
  }
2524
- start(muted = true, loop = true) {
2872
+ get isLooped() {
2873
+ if (this._video != null) {
2874
+ return this._video?.loop;
2875
+ }
2876
+ return false;
2877
+ }
2878
+ start(muted = true, getIsLooped) {
2525
2879
  this._videoStartedPromise = new Promise(async (resolve) => {
2526
2880
  // invariant - always wait for mediaElementsLoadingPromises
2527
2881
  // else call of _initVOD can start and onAllMediaLoaded failed
@@ -2535,7 +2889,7 @@ class Video {
2535
2889
  // console.log("Video:start => this._video.pause()");
2536
2890
  this._video.pause();
2537
2891
  this._video.currentTime = 0;
2538
- this._video.loop = loop;
2892
+ this._video.loop = getIsLooped();
2539
2893
  // remove init class
2540
2894
  // if vod - create VoD player
2541
2895
  if (this._video.getAttribute("data-default-muted") !== "1") {
@@ -2548,13 +2902,13 @@ class Video {
2548
2902
  this._video.currentTime = 0;
2549
2903
  this._elementNodeRef.classList.remove("init");
2550
2904
  resolve({
2551
- currentTime: this._video.currentTime,
2905
+ getVideoCurrentTime: () => this._video.currentTime,
2552
2906
  });
2553
2907
  })
2554
2908
  .catch(error => {
2555
2909
  console.error(error);
2556
2910
  resolve({
2557
- currentTime: this._video.currentTime,
2911
+ getVideoCurrentTime: () => this._video.currentTime,
2558
2912
  });
2559
2913
  });
2560
2914
  }
@@ -2563,14 +2917,14 @@ class Video {
2563
2917
  this._video.currentTime = 0;
2564
2918
  this._elementNodeRef.classList.remove("init");
2565
2919
  resolve({
2566
- currentTime: this._video.currentTime,
2920
+ getVideoCurrentTime: () => this._video.currentTime,
2567
2921
  });
2568
2922
  }, 0);
2569
2923
  }
2570
2924
  }
2571
2925
  else {
2572
2926
  resolve({
2573
- currentTime: 0,
2927
+ getVideoCurrentTime: () => 0,
2574
2928
  });
2575
2929
  }
2576
2930
  });
@@ -2606,7 +2960,7 @@ class Video {
2606
2960
  // console.log("resolve 1.1", { ts });
2607
2961
  this._video.currentTime = ts;
2608
2962
  }
2609
- resolve({ currentTime: this._video.currentTime });
2963
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2610
2964
  })
2611
2965
  .catch(error => {
2612
2966
  console.error(error);
@@ -2614,7 +2968,7 @@ class Video {
2614
2968
  if (this._video.currentTime < ts) {
2615
2969
  this._video.currentTime = ts;
2616
2970
  }
2617
- resolve({ currentTime: this._video.currentTime });
2971
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2618
2972
  });
2619
2973
  }
2620
2974
  else {
@@ -2623,7 +2977,7 @@ class Video {
2623
2977
  if (this._video.currentTime < ts) {
2624
2978
  this._video.currentTime = ts;
2625
2979
  }
2626
- resolve({ currentTime: this._video.currentTime });
2980
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2627
2981
  }, 0);
2628
2982
  }
2629
2983
  });
@@ -2677,7 +3031,7 @@ class Video {
2677
3031
  this._video.muted = true;
2678
3032
  }
2679
3033
  }
2680
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `typeof VideoPlayer | undefined`, `SDKApi`]; }
3034
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `typeof VideoPlayer | undefined`, `ISlideApiDeps`]; }
2681
3035
  }
2682
3036
  // class VideoStateAdapter {
2683
3037
  //
@@ -2771,7 +3125,12 @@ class VideoStateAdapter {
2771
3125
  }
2772
3126
  // todo - add debounce
2773
3127
  this._playingCheckerId = window.setTimeout(() => {
3128
+ // console.log({now: Date.now(), _timeupdate: this._timeupdate, currentTime: this._video.currentTime, duration: this._video.duration});
2774
3129
  if (Date.now() - this._timeupdate >= this._maxDiff / 2) {
3130
+ // prevent onWaiting triggering if the video has ended
3131
+ if (Math.round(this._video.currentTime) >= Math.round(this._video.duration)) {
3132
+ return;
3133
+ }
2775
3134
  this._state = 2 /* VIDEO_STATE.WAITING */;
2776
3135
  this._triggerUpdate();
2777
3136
  }
@@ -2854,7 +3213,7 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
2854
3213
  case Text.className():
2855
3214
  return new Text(nodeRef, layer);
2856
3215
  case Button.className():
2857
- return new Button(nodeRef, layer);
3216
+ return new Button(nodeRef, layer, widgetDeps);
2858
3217
  case Image.className():
2859
3218
  return new Image(nodeRef, layer);
2860
3219
  case SwipeUp.className():
@@ -2862,7 +3221,7 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
2862
3221
  case SwipeUpItems.className():
2863
3222
  return new SwipeUpItems(nodeRef, layer);
2864
3223
  case Video.className():
2865
- return new Video(nodeRef, layer, layoutApi.VideoPlayer, layer.sdkApi);
3224
+ return new Video(nodeRef, layer, layoutApi.VideoPlayer, layer.slideApiDeps);
2866
3225
  //////// widgets ///////
2867
3226
  case Copy.className():
2868
3227
  return layoutApi.widgetCopyApi ? new Copy(nodeRef, layer, layoutApi.widgetCopyApi, widgetCallbacks, widgetDeps) : null;
@@ -2920,20 +3279,23 @@ class SlideTimeline {
2920
3279
  slideDisabledTimer;
2921
3280
  slideReady;
2922
3281
  _afterAppResumeQueuePush;
2923
- sdkApi;
2924
- constructor(slideIndex, slideDuration, slideDisabledTimer, slideReady, _afterAppResumeQueuePush, sdkApi) {
3282
+ slideApiDeps;
3283
+ constructor(slideIndex, slideDuration, slideDisabledTimer, slideReady, _afterAppResumeQueuePush, slideApiDeps) {
2925
3284
  this.slideIndex = slideIndex;
2926
3285
  this.slideDuration = slideDuration;
2927
3286
  this.slideDisabledTimer = slideDisabledTimer;
2928
3287
  this.slideReady = slideReady;
2929
3288
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
2930
- this.sdkApi = sdkApi;
3289
+ this.slideApiDeps = slideApiDeps;
2931
3290
  this.timelineDisabledState = this.slideDisabledTimer ? TimelineDisabledState.disabled : TimelineDisabledState.enabled;
2932
3291
  }
2933
3292
  resumedAt = new Date().getTime();
2934
3293
  timeSpent = 0;
2935
3294
  timelineDisabledState;
2936
3295
  currentState = "stop" /* TIMELINE_ACTION.STOP */;
3296
+ deferredDataWaitingStateTimerId = null;
3297
+ deferredResumeStateTimerId = null;
3298
+ dataWaitingStartedAt = null;
2937
3299
  static get layoutService() {
2938
3300
  return container.get({ identifier: "LayoutService" });
2939
3301
  }
@@ -2941,14 +3303,14 @@ class SlideTimeline {
2941
3303
  return SlideTimeline.layoutService;
2942
3304
  }
2943
3305
  get isSDKSupportUpdateTimeline() {
2944
- if (this.sdkApi.isAndroid) {
3306
+ if (this.slideApiDeps.isAndroid) {
2945
3307
  return Boolean(SlideTimeline.layoutService.env.Android && "updateTimeline" in SlideTimeline.layoutService.env.Android);
2946
3308
  }
2947
- else if (this.sdkApi.isIOS) {
3309
+ else if (this.slideApiDeps.isIOS) {
2948
3310
  const mh = SlideTimeline.layoutService.env?.webkit?.messageHandlers ?? {};
2949
3311
  return "updateTimeline" in mh;
2950
3312
  }
2951
- else if (this.sdkApi.isWeb) {
3313
+ else if (this.slideApiDeps.isWeb) {
2952
3314
  return true;
2953
3315
  }
2954
3316
  else {
@@ -2956,7 +3318,7 @@ class SlideTimeline {
2956
3318
  }
2957
3319
  }
2958
3320
  get isSdkSupportTimelineOnBeforeStart() {
2959
- return this.sdkApi.isSdkSupportTimelineOnBeforeStart();
3321
+ return this.slideApiDeps.isSdkSupportTimelineOnBeforeStart();
2960
3322
  }
2961
3323
  get index() {
2962
3324
  return this.slideIndex;
@@ -2964,6 +3326,9 @@ class SlideTimeline {
2964
3326
  get isTimelineDisabled() {
2965
3327
  return this.timelineDisabledState === TimelineDisabledState.disabled;
2966
3328
  }
3329
+ get durationMs() {
3330
+ return this.slideDuration;
3331
+ }
2967
3332
  async updateTimeline(action, showLoader = false, showError = false) {
2968
3333
  // два кейса
2969
3334
  // когда есть слои и у слоя вызываем showLayer который вызывает startTimer до старта слайда, потом start от sdk
@@ -2992,13 +3357,15 @@ class SlideTimeline {
2992
3357
  //@ts-ignore
2993
3358
  // window._log(`updateTimeline 1, a: ${action} ct: ${currentTime} d: ${duration} tds: ${this.timelineDisabledState}`, true);
2994
3359
  await this.slideReady.then();
2995
- //@ts-ignore
2996
3360
  // window._log(`updateTimeline, a: ${action} ct: ${currentTime} d: ${duration} tds: ${this.timelineDisabledState}`, true);
2997
- // console.trace(`updateTimeline ${action} slideIndex: ${this.slideIndex} currentTime:${currentTime} duration:${duration} tds: ${this.timelineDisabledState}`);
2998
- this.sdkApi.updateTimeline(this.slideIndex, action, currentTime, duration, showLoader, showError);
3361
+ // console.trace(`updateTimeline ${action} slideIndex: ${this.slideIndex} currentTime:${currentTime} duration:${duration} tds: ${this.timelineDisabledState} showLoader: ${showLoader} showError: ${showError}`);
3362
+ this.slideApiDeps.updateTimeline(this.slideIndex, action, currentTime, duration, showLoader, showError);
3363
+ if (action === "pause" /* TIMELINE_ACTION.PAUSE */ && showLoader) {
3364
+ this.dataWaitingStartedAt = Date.now();
3365
+ }
2999
3366
  }
3000
3367
  /**
3001
- * trigger timeline update for new slide in sdk, before slide strat event (prevent timeout in timeline while we wait for video start)
3368
+ * trigger timeline update for new slide in sdk, before slide start event (prevent timeout in timeline while we wait for video start)
3002
3369
  */
3003
3370
  triggerSlideLoadState() {
3004
3371
  if (this.isSDKSupportUpdateTimeline && this.isSdkSupportTimelineOnBeforeStart) {
@@ -3011,7 +3378,7 @@ class SlideTimeline {
3011
3378
  if (this.timelineDisabledState === TimelineDisabledState.disabled) {
3012
3379
  duration = 0;
3013
3380
  }
3014
- this.sdkApi.updateTimeline(this.slideIndex, "before_start" /* TIMELINE_ACTION.BEFORE_START */, 0, duration, false, false);
3381
+ this.slideApiDeps.updateTimeline(this.slideIndex, "before_start" /* TIMELINE_ACTION.BEFORE_START */, 0, duration, false, false);
3015
3382
  }
3016
3383
  }
3017
3384
  /**
@@ -3020,6 +3387,7 @@ class SlideTimeline {
3020
3387
  */
3021
3388
  slideStarted() {
3022
3389
  // console.trace("slideStarted");
3390
+ this.onBeforeStateChanged();
3023
3391
  if (this.isSDKSupportUpdateTimeline) {
3024
3392
  this.resumedAt = new Date().getTime();
3025
3393
  this.timeSpent = 0; // for case when instance exists, but we return to slide again
@@ -3028,6 +3396,7 @@ class SlideTimeline {
3028
3396
  }
3029
3397
  slideRestarted() {
3030
3398
  // console.trace("slideRestarted");
3399
+ this.onBeforeStateChanged();
3031
3400
  if (this.isSDKSupportUpdateTimeline) {
3032
3401
  this.resumedAt = new Date().getTime();
3033
3402
  this.timeSpent = 0;
@@ -3037,11 +3406,12 @@ class SlideTimeline {
3037
3406
  /**
3038
3407
  *
3039
3408
  */
3040
- slidePaused(videoCurrentTime) {
3409
+ slidePaused(currentTime) {
3041
3410
  // console.trace("slidePaused");
3411
+ this.onBeforeStateChanged();
3042
3412
  if (this.isSDKSupportUpdateTimeline) {
3043
- if (videoCurrentTime != null) {
3044
- this.timeSpent = Math.round(videoCurrentTime);
3413
+ if (currentTime != null) {
3414
+ this.timeSpent = Math.round(currentTime);
3045
3415
  }
3046
3416
  else {
3047
3417
  const globalCurrentTime = new Date().getTime();
@@ -3051,26 +3421,43 @@ class SlideTimeline {
3051
3421
  this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */);
3052
3422
  }
3053
3423
  else {
3054
- this.sdkApi.cardPausedCallback(videoCurrentTime);
3424
+ this.slideApiDeps.cardPausedCallback(currentTime);
3055
3425
  }
3056
3426
  }
3057
- slideResumed(videoCurrentTime) {
3427
+ slideResumed(getVideoCurrentTime) {
3058
3428
  // console.trace("slideResumed");
3429
+ this.onBeforeStateChanged();
3059
3430
  // @ts-ignore
3060
3431
  // window._log(`updateTimeline slideResumed ${videoCurrentTime}`, true);
3061
- if (this.isSDKSupportUpdateTimeline) {
3062
- if (videoCurrentTime != null) {
3063
- this.timeSpent = Math.round(videoCurrentTime);
3432
+ // dataWaitingStartedAt
3433
+ const slideResume = () => {
3434
+ if (this.isSDKSupportUpdateTimeline) {
3435
+ if (getVideoCurrentTime != null) {
3436
+ this.timeSpent = Math.round(getVideoCurrentTime());
3437
+ }
3438
+ this.resumedAt = new Date().getTime();
3439
+ this.updateTimeline("start" /* TIMELINE_ACTION.START */);
3064
3440
  }
3065
- this.resumedAt = new Date().getTime();
3066
- this.updateTimeline("start" /* TIMELINE_ACTION.START */);
3441
+ else {
3442
+ this.slideApiDeps.cardResumedCallback(getVideoCurrentTime != null ? getVideoCurrentTime() : null);
3443
+ }
3444
+ };
3445
+ // prevent micro loaders in UI
3446
+ const delay = 300;
3447
+ let dataWaitingLoaderSpent = delay;
3448
+ if (this.dataWaitingStartedAt != null) {
3449
+ dataWaitingLoaderSpent = Date.now() - this.dataWaitingStartedAt;
3450
+ }
3451
+ if (dataWaitingLoaderSpent < delay) {
3452
+ this.deferredResumeStateTimerId = window.setTimeout(slideResume, dataWaitingLoaderSpent - delay);
3067
3453
  }
3068
3454
  else {
3069
- this.sdkApi.cardResumedCallback(videoCurrentTime);
3455
+ slideResume();
3070
3456
  }
3071
3457
  }
3072
3458
  slideStopped() {
3073
3459
  // console.trace("slideStopped");
3460
+ this.onBeforeStateChanged();
3074
3461
  if (this.isSDKSupportUpdateTimeline) {
3075
3462
  this.updateTimeline("stop" /* TIMELINE_ACTION.STOP */);
3076
3463
  }
@@ -3080,6 +3467,7 @@ class SlideTimeline {
3080
3467
  * used by widgets
3081
3468
  */
3082
3469
  startDisabledTimeline(fallback) {
3470
+ this.onBeforeStateChanged();
3083
3471
  // if app is paused (in background) - don't call start timeline (Android issues)
3084
3472
  // @ts-ignore
3085
3473
  // window._log(`Push startDisabledTimeline to queue at state: ${window.slideApi.state}, time: ${new Date().getTime()}`, true);
@@ -3099,6 +3487,7 @@ class SlideTimeline {
3099
3487
  }
3100
3488
  onSlideDataWaiting(videoCurrentTime) {
3101
3489
  // console.trace("onSlideDataWaiting");
3490
+ this.onBeforeStateChanged();
3102
3491
  // @ts-ignore
3103
3492
  // window._log(`updateTimeline onSlideDataWaiting ${videoCurrentTime}`, true);
3104
3493
  if (videoCurrentTime != null) {
@@ -3109,10 +3498,20 @@ class SlideTimeline {
3109
3498
  let spent = globalCurrentTime - this.resumedAt;
3110
3499
  this.timeSpent += spent;
3111
3500
  }
3112
- this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3501
+ // prevent micro loaders in UI
3502
+ if (this.currentState === "start" /* TIMELINE_ACTION.START */) {
3503
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, false, false);
3504
+ this.deferredDataWaitingStateTimerId = window.setTimeout(() => {
3505
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3506
+ }, 300);
3507
+ }
3508
+ else {
3509
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3510
+ }
3113
3511
  }
3114
3512
  onSlideError(videoCurrentTime) {
3115
3513
  // console.trace("onSlideError");
3514
+ this.onBeforeStateChanged();
3116
3515
  if (videoCurrentTime != null) {
3117
3516
  this.timeSpent = Math.round(videoCurrentTime);
3118
3517
  }
@@ -3123,7 +3522,21 @@ class SlideTimeline {
3123
3522
  }
3124
3523
  this.updateTimeline("stop" /* TIMELINE_ACTION.STOP */, false, true);
3125
3524
  }
3126
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`number`, `number`, `boolean`, `Promise`, `(cb: () => void) => void`, `SDKApi`]; }
3525
+ clearDeferredDataWaitingStateTimerId() {
3526
+ if (this.deferredDataWaitingStateTimerId != null) {
3527
+ window.clearTimeout(this.deferredDataWaitingStateTimerId);
3528
+ }
3529
+ }
3530
+ clearDeferredResumeStateTimerId() {
3531
+ if (this.deferredResumeStateTimerId != null) {
3532
+ window.clearTimeout(this.deferredResumeStateTimerId);
3533
+ }
3534
+ }
3535
+ onBeforeStateChanged() {
3536
+ this.clearDeferredDataWaitingStateTimerId();
3537
+ this.clearDeferredResumeStateTimerId();
3538
+ }
3539
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`number`, `number`, `boolean`, `Promise`, `(cb: () => void) => void`, `ISlideApiDeps`]; }
3127
3540
  }
3128
3541
 
3129
3542
  class Layer {
@@ -3132,8 +3545,7 @@ class Layer {
3132
3545
  _slideReadyPromise;
3133
3546
  _afterAppResumeQueuePush;
3134
3547
  _afterStartInitQueuePush;
3135
- _showNextSlide;
3136
- sdkApi;
3548
+ slideApiDeps;
3137
3549
  _slideRoot;
3138
3550
  _getLayoutDirection;
3139
3551
  _slidePauseUI;
@@ -3149,14 +3561,13 @@ class Layer {
3149
3561
  _elements = [];
3150
3562
  _timeline;
3151
3563
  _widgetDeps;
3152
- constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, _showNextSlide, sdkApi, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3564
+ constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3153
3565
  this._nodeRef = _nodeRef;
3154
3566
  this._slide = _slide;
3155
3567
  this._slideReadyPromise = _slideReadyPromise;
3156
3568
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3157
3569
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
3158
- this._showNextSlide = _showNextSlide;
3159
- this.sdkApi = sdkApi;
3570
+ this.slideApiDeps = slideApiDeps;
3160
3571
  this._slideRoot = _slideRoot;
3161
3572
  this._getLayoutDirection = _getLayoutDirection;
3162
3573
  this._slidePauseUI = _slidePauseUI;
@@ -3169,16 +3580,16 @@ class Layer {
3169
3580
  this._duration = parseInt(this._nodeRef.getAttribute("data-duration") ?? "") || DEFAULT_SLIDE_DURATION;
3170
3581
  this._disabledTimer = this._nodeRef.getAttribute("data-disable-timer") === "1";
3171
3582
  this._disabledNavigation = this._nodeRef.getAttribute("data-disable-navigation") === "1";
3172
- this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.sdkApi);
3583
+ this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.slideApiDeps);
3173
3584
  this._widgetDeps = {
3174
- sdkApi: this.sdkApi,
3585
+ slideApiDeps: this.slideApiDeps,
3175
3586
  slideRoot: this._slideRoot,
3176
3587
  getLayoutDirection: this._getLayoutDirection,
3177
3588
  getSdkClientVariables: this._getSdkClientVariables,
3178
3589
  };
3179
3590
  const onWidgetComplete = (cardId, slideIndex) => {
3180
3591
  // todo if nothing more widgets with disabled timers - we can start layer timeline
3181
- const fallback = () => this._showNextSlide(DEFAULT_SLIDE_DURATION);
3592
+ const fallback = () => this.slideApiDeps.showNextSlide(DEFAULT_SLIDE_DURATION);
3182
3593
  // для android sdk важно чтобы этот метод вызывался только после slide_start
3183
3594
  this._afterStartInitQueuePush(() => {
3184
3595
  this._timeline.startDisabledTimeline(fallback);
@@ -3220,17 +3631,17 @@ class Layer {
3220
3631
  }
3221
3632
  }
3222
3633
  init(localData) {
3223
- if (this.sdkApi.isIOS || this.sdkApi.isAndroid) {
3634
+ if (this.slideApiDeps.isIOS || this.slideApiDeps.isAndroid) {
3224
3635
  this._nodeRef.classList.add("_app");
3225
- this.sdkApi.isIOS && this._nodeRef.classList.add("_isIos");
3226
- this.sdkApi.isAndroid && this._nodeRef.classList.add("_isAndroid");
3636
+ this.slideApiDeps.isIOS && this._nodeRef.classList.add("_isIos");
3637
+ this.slideApiDeps.isAndroid && this._nodeRef.classList.add("_isAndroid");
3227
3638
  }
3228
- this.sdkApi.cardAnimation?.init(this._nodeRef);
3639
+ this.slideApiDeps.cardAnimation?.init(this._nodeRef);
3229
3640
  const promises = this._elements.map(element => element.init(localData));
3230
3641
  return promises;
3231
3642
  }
3232
3643
  onAfterAllMediaResourcesLoaded() {
3233
- if (this.sdkApi.isIOS) ;
3644
+ if (this.slideApiDeps.isIOS) ;
3234
3645
  this._initTextFit();
3235
3646
  }
3236
3647
  get nodeRef() {
@@ -3249,7 +3660,10 @@ class Layer {
3249
3660
  return container.get({ identifier: "LayoutService" });
3250
3661
  }
3251
3662
  getLocalData() {
3252
- return this.sdkApi.getCardLocalData();
3663
+ return this.slideApiDeps.getCardLocalData();
3664
+ }
3665
+ findElementByNodeRef(nodeRef) {
3666
+ return this._elements.find(element => element.nodeRef === nodeRef);
3253
3667
  }
3254
3668
  get isQuest() {
3255
3669
  return this._nodeRef.getAttribute("data-quest-count") != null;
@@ -3402,14 +3816,19 @@ class Layer {
3402
3816
  const videoElement = this.videoElement;
3403
3817
  let currentTime = 0;
3404
3818
  if (videoElement != null) {
3405
- let videoLoop = false;
3406
- if (this.timeline.isTimelineDisabled) {
3407
- videoLoop = true;
3408
- }
3409
- currentTime = (await videoElement.start(muted, videoLoop)).currentTime;
3819
+ const getVideoIsLooped = () => {
3820
+ let videoLoop = false;
3821
+ if (this.timeline.isTimelineDisabled || this.timeline.durationMs > videoElement.durationMs) {
3822
+ videoLoop = true;
3823
+ }
3824
+ // console.log({videoLoop, isTimelineDisabled: this.timeline.isTimelineDisabled, timelineDurationMs: this.timeline.durationMs, videoElementDurationMs: videoElement.durationMs});
3825
+ return videoLoop;
3826
+ };
3827
+ // todo - need to convert to ms ?
3828
+ currentTime = (await videoElement.start(muted, getVideoIsLooped)).getVideoCurrentTime();
3410
3829
  }
3411
- if (this.sdkApi.cardAnimation) {
3412
- this._animationPauseCb = this.sdkApi.cardAnimation.start(this._nodeRef);
3830
+ if (this.slideApiDeps.cardAnimation) {
3831
+ this._animationPauseCb = this.slideApiDeps.cardAnimation.start(this._nodeRef);
3413
3832
  }
3414
3833
  for (const element of this._elements) {
3415
3834
  element.onStart();
@@ -3425,7 +3844,7 @@ class Layer {
3425
3844
  }
3426
3845
  async stop(options) {
3427
3846
  this.videoElement?.stop(options);
3428
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3847
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3429
3848
  for (const element of this._elements) {
3430
3849
  element.onPause();
3431
3850
  }
@@ -3436,7 +3855,7 @@ class Layer {
3436
3855
  }
3437
3856
  stopInternal(options) {
3438
3857
  this.videoElement?.stop(options);
3439
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3858
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3440
3859
  for (const element of this._elements) {
3441
3860
  element.onPause();
3442
3861
  }
@@ -3448,17 +3867,21 @@ class Layer {
3448
3867
  return new Promise(resolve => {
3449
3868
  const cb = () => {
3450
3869
  let currentTime = this.videoElement?.pause(resetVideoTime) ?? null;
3870
+ if (this.videoElement?.isLooped) {
3871
+ // skip currentTime from looped video (bcz in that case video time does not associated with timeline)
3872
+ currentTime = null;
3873
+ }
3874
+ if (currentTime != null) {
3875
+ currentTime *= 1000;
3876
+ }
3451
3877
  if (stopAnimation) {
3452
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3878
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3453
3879
  }
3454
3880
  else {
3455
3881
  if (this._animationPauseCb != null && isFunction(this._animationPauseCb)) {
3456
3882
  this._animationResumeCb = this._animationPauseCb(false);
3457
3883
  }
3458
3884
  }
3459
- if (currentTime != null) {
3460
- currentTime *= 1000;
3461
- }
3462
3885
  for (const element of this._elements) {
3463
3886
  element.onPause();
3464
3887
  }
@@ -3478,26 +3901,23 @@ class Layer {
3478
3901
  }
3479
3902
  async resume() {
3480
3903
  return new Promise(resolve => {
3481
- const cb = ({ currentTime }) => {
3904
+ const cb = ({ getVideoCurrentTime }) => {
3482
3905
  // console.log("resumed cb with currentTime", { currentTime });
3483
- if (currentTime != null) {
3484
- currentTime *= 1000;
3485
- }
3486
3906
  if (isFunction(this._animationResumeCb)) {
3487
3907
  this._animationResumeCb();
3488
3908
  }
3489
3909
  for (const element of this._elements) {
3490
3910
  element.onResume();
3491
3911
  }
3492
- this.timeline.slideResumed(currentTime);
3493
- resolve({ currentTime });
3912
+ this.timeline.slideResumed(getVideoCurrentTime != null ? () => getVideoCurrentTime() * 1000 : undefined);
3913
+ resolve({ currentTime: getVideoCurrentTime != null ? getVideoCurrentTime() : null });
3494
3914
  };
3495
3915
  const videoStartedPromise = this.videoElement?.resume();
3496
3916
  if (videoStartedPromise != null && videoStartedPromise.then != null) {
3497
3917
  videoStartedPromise.then(cb);
3498
3918
  }
3499
3919
  else {
3500
- cb({ currentTime: null });
3920
+ cb({ getVideoCurrentTime: undefined });
3501
3921
  }
3502
3922
  });
3503
3923
  }
@@ -3513,7 +3933,7 @@ class Layer {
3513
3933
  get isLayerForcePaused() {
3514
3934
  return this.elements.some(element => element.isLayerForcePaused);
3515
3935
  }
3516
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Slide`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `(duration: number) => void`, `SDKApi`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
3936
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Slide`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `ISlideApiDeps`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
3517
3937
  }
3518
3938
  const TextFit = (function () {
3519
3939
  const defaultSettings = {
@@ -3704,8 +4124,7 @@ class Slide {
3704
4124
  _slideReadyPromise;
3705
4125
  _afterAppResumeQueuePush;
3706
4126
  _afterStartInitQueuePush;
3707
- _showNextSlide;
3708
- sdkApi;
4127
+ slideApiDeps;
3709
4128
  _slideRoot;
3710
4129
  _getLayoutDirection;
3711
4130
  _slidePauseUI;
@@ -3713,13 +4132,12 @@ class Slide {
3713
4132
  _getSdkClientVariables;
3714
4133
  _layers;
3715
4134
  _start;
3716
- constructor(_slidesNodesRefs, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, _showNextSlide, sdkApi, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
4135
+ constructor(_slidesNodesRefs, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3717
4136
  this._slidesNodesRefs = _slidesNodesRefs;
3718
4137
  this._slideReadyPromise = _slideReadyPromise;
3719
4138
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3720
4139
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
3721
- this._showNextSlide = _showNextSlide;
3722
- this.sdkApi = sdkApi;
4140
+ this.slideApiDeps = slideApiDeps;
3723
4141
  this._slideRoot = _slideRoot;
3724
4142
  this._getLayoutDirection = _getLayoutDirection;
3725
4143
  this._slidePauseUI = _slidePauseUI;
@@ -3729,7 +4147,7 @@ class Slide {
3729
4147
  if (!this._slidesNodesRefs.length) {
3730
4148
  throw new Error("No slides found.");
3731
4149
  }
3732
- this._layers = this._slidesNodesRefs.map(item => new Layer(item, this, this._slideReadyPromise, this._afterAppResumeQueuePush, this._afterStartInitQueuePush, this._showNextSlide, this.sdkApi, this._slideRoot, this._getLayoutDirection, this._slidePauseUI, this._slideResumeUI, this._getSdkClientVariables));
4150
+ this._layers = this._slidesNodesRefs.map(item => new Layer(item, this, this._slideReadyPromise, this._afterAppResumeQueuePush, this._afterStartInitQueuePush, this.slideApiDeps, this._slideRoot, this._getLayoutDirection, this._slidePauseUI, this._slideResumeUI, this._getSdkClientVariables));
3733
4151
  this._activeLayer = this._layers[0];
3734
4152
  }
3735
4153
  _activeLayer;
@@ -3749,7 +4167,7 @@ class Slide {
3749
4167
  if (multiSlideApi != null && this.layers.length > 1) {
3750
4168
  try {
3751
4169
  multiSlideApi.init(this.layersNodesRefs, localData, {
3752
- sdkApi: this.sdkApi,
4170
+ slideApiDeps: this.slideApiDeps,
3753
4171
  slideRoot: this._slideRoot,
3754
4172
  getLayoutDirection: this._getLayoutDirection,
3755
4173
  getSdkClientVariables: this._getSdkClientVariables,
@@ -3826,7 +4244,7 @@ class Slide {
3826
4244
  get disabledNavigation() {
3827
4245
  return this._activeLayer.disabledNavigation;
3828
4246
  }
3829
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`Array`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `(duration: number) => void`, `SDKApi`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
4247
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Array`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `ISlideApiDeps`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
3830
4248
  }
3831
4249
 
3832
4250
  let SlideApi$1 = class SlideApi {
@@ -3843,20 +4261,29 @@ let SlideApi$1 = class SlideApi {
3843
4261
  _getViewportHeight;
3844
4262
  _overlappingActionBarHeight;
3845
4263
  _separateUserAndAppPause;
3846
- sdkApi;
4264
+ _index;
4265
+ slideApiDeps;
3847
4266
  constructor(config) {
3848
4267
  this.config = config;
3849
- this.sdkApi = config.sdkApi;
4268
+ this.slideApiDeps = config.slideApiDeps;
3850
4269
  this._slideWrapper = config.slideWrapper;
3851
4270
  this._viewport = config.viewport;
3852
4271
  this._getViewportWidth = config.getViewportWidth;
3853
4272
  this._getViewportHeight = config.getViewportHeight;
3854
4273
  this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
3855
4274
  this._separateUserAndAppPause = config.separateUserAndAppPause;
3856
- this.refreshSizes = proxy(this.refreshSizes, this);
3857
- this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
3858
- this.initListeners();
3859
- this.refreshSizes();
4275
+ this._index = config.index;
4276
+ }
4277
+ static checkPreloadedInLayoutSlide() {
4278
+ // for sdk backward compatibility
4279
+ const slideBox = document.getElementById("narrative-slide-box");
4280
+ if (slideBox && slideBox.innerText.trim() !== "{%content}".replace("{", "{{").replace("}", "}}")) {
4281
+ return true;
4282
+ }
4283
+ return false;
4284
+ }
4285
+ initPreloadedInLayoutSlide(slideLoadedCb) {
4286
+ // for sdk backward compatibility
3860
4287
  const slideBox = document.getElementById("narrative-slide-box");
3861
4288
  // todo via first child and its innerText - faster variant
3862
4289
  if (slideBox && slideBox.innerText.trim() !== "{%content}".replace("{", "{{").replace("}", "}}")) {
@@ -3864,117 +4291,42 @@ let SlideApi$1 = class SlideApi {
3864
4291
  this._slideInRender = true;
3865
4292
  this._init(() => this._slideBoxRenderComplete(null)).then(({ slide, result, reason }) => {
3866
4293
  this._slide = slide;
3867
- if (config.slideLoadedCb != null) {
3868
- config.slideLoadedCb({ cardId: slide.cardId, slideIndex: slide.slideIndex, result, reason });
4294
+ if (slideLoadedCb != null) {
4295
+ slideLoadedCb({ cardId: slide.cardId, slideIndex: slide.slideIndex, result, reason });
3869
4296
  }
3870
4297
  });
3871
4298
  }
3872
4299
  }
3873
- async destroy() {
3874
- if (this.slide != null) {
3875
- await this.slide.onBeforeUnmount();
3876
- }
3877
- this.destroyListeners();
3878
- this._state = 13 /* STATE.DESTROYED */;
3879
- }
3880
- initListeners() {
3881
- this._viewport.addEventListener("resize", this.refreshSizes);
3882
- }
3883
- destroyListeners() {
3884
- this._viewport.removeEventListener("resize", this.refreshSizes);
3885
- }
3886
- _savedViewportWidth = null;
3887
- _savedViewportHeight = null;
3888
- refreshSizes() {
3889
- const viewportWidth = this._getViewportWidth();
3890
- const viewportHeight = this._getViewportHeight();
3891
- if (this._savedViewportWidth === viewportWidth && this._savedViewportHeight === viewportHeight) {
3892
- return;
3893
- }
3894
- this._savedViewportWidth = viewportWidth;
3895
- this._savedViewportHeight = viewportHeight;
3896
- const viewportRatio = viewportWidth / viewportHeight;
3897
- let slideWidth = 0;
3898
- let slideHeight = 0;
3899
- // _ratio = 310 / 480,
3900
- const _ratio = this.config.slideRatio;
3901
- let _isFullscreen = this.config.isFullscreen;
3902
- const slideOffset = this._slideWrapper.querySelector(".narrative-slide-offset");
3903
- let offset = 0;
3904
- let xOffset = "0px";
3905
- // for elements with bottom anchor (absolute position)
3906
- let yOffset = "0px";
3907
- // alert(viewportHeight);
3908
- // todo - mobile only (or isIos or isAndroid)
3909
- if (this.sdkApi.isAndroid || this.sdkApi.isIOS) {
3910
- if (viewportRatio > _ratio) {
3911
- // disable _isFullscreen if viewport small
3912
- _isFullscreen = false;
3913
- }
3914
- }
3915
- if (_isFullscreen) {
3916
- // более квадратное чем надо (desktop)
3917
- if (viewportRatio > _ratio) {
3918
- // fit by height
3919
- slideHeight = viewportHeight;
3920
- slideWidth = Math.ceil(slideHeight * _ratio);
3921
- offset = Math.ceil(slideWidth - viewportWidth) / 2;
3922
- if (slideOffset != null) {
3923
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
3924
- }
3925
- xOffset = offset + "px";
3926
- }
3927
- else {
3928
- // fit by width, top and bottom - to offscreen or fill with bg image
3929
- slideWidth = viewportWidth;
3930
- slideHeight = Math.ceil(viewportWidth / _ratio);
3931
- offset = Math.ceil(slideHeight - viewportHeight) / 2;
3932
- if (slideOffset != null) {
3933
- slideOffset.style.margin = -1 * offset + "px" + " 0 ";
3934
- }
3935
- // offset from viewport bottom to StoryBottom plus safe area offset bottom
3936
- yOffset = `calc(${offset + this._overlappingActionBarHeight}px + env(safe-area-inset-bottom))`;
3937
- // detect safe area offset
3938
- }
3939
- }
3940
- else {
3941
- // более квадратное чем надо
3942
- if (viewportRatio > _ratio) {
3943
- // fit by width, top and bottom - to offscreen
3944
- slideWidth = viewportWidth;
3945
- slideHeight = Math.ceil(viewportWidth / _ratio);
3946
- offset = Math.ceil(slideHeight - viewportHeight) / 2;
3947
- if (slideOffset != null) {
3948
- slideOffset.style.margin = -offset + "px" + " 0 ";
3949
- }
3950
- yOffset = offset + this._overlappingActionBarHeight + "px";
4300
+ onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, slideOffsetMargin }) {
4301
+ // todo CSP violation
4302
+ this._slideWrapper.style.fontSize = fontSize;
4303
+ if (this.slideOffsetElement != null) {
4304
+ // todo CSP violation
4305
+ this.slideOffsetElement.style.setProperty("--y-offset", yOffset);
4306
+ this.slideOffsetElement.style.setProperty("--x-offset", xOffset);
4307
+ if (isFullscreen) {
4308
+ this.slideOffsetElement.classList.add("narrative-slide-offset-fullscreen");
3951
4309
  }
3952
4310
  else {
3953
- // вьюпорт более вытянутый чем надо
3954
- // fit by height, sides - to offscreen
3955
- slideHeight = viewportHeight;
3956
- slideWidth = Math.ceil(slideHeight * _ratio);
3957
- offset = Math.ceil(slideWidth - viewportWidth) / 2;
3958
- if (slideOffset != null) {
3959
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
3960
- }
3961
- xOffset = offset + "px";
4311
+ this.slideOffsetElement.classList.remove("narrative-slide-offset-fullscreen");
3962
4312
  }
4313
+ this.slideOffsetElement.style.margin = slideOffsetMargin;
3963
4314
  }
3964
- const fontSize = slideWidth / 20;
3965
- // todo CSP violation
3966
- this._slideWrapper.style.fontSize = fontSize + "px";
3967
- if (slideOffset != null) {
3968
- // todo CSP violation
3969
- slideOffset.style.setProperty("--y-offset", yOffset);
3970
- slideOffset.style.setProperty("--x-offset", xOffset);
3971
- }
3972
- if (_isFullscreen) {
3973
- slideOffset?.classList.add("narrative-slide-offset-fullscreen");
3974
- }
3975
- if (this.config.userResizeHandler != null) {
3976
- this.config.userResizeHandler({ viewportWidth, viewportHeight, fontSize });
4315
+ }
4316
+ get slideWrapperElement() {
4317
+ return this._slideWrapper;
4318
+ }
4319
+ get slideOffsetElement() {
4320
+ return this._slideWrapper.querySelector(".narrative-slide-offset");
4321
+ }
4322
+ get index() {
4323
+ return this._index;
4324
+ }
4325
+ async destroy() {
4326
+ if (this.slide != null) {
4327
+ await this.slide.onBeforeUnmount();
3977
4328
  }
4329
+ this._state = 13 /* STATE.DESTROYED */;
3978
4330
  }
3979
4331
  async showSlide(html) {
3980
4332
  const slideBox = this._slideWrapper.querySelector(`.${SlideApi.renderedBoxClassName}`);
@@ -3987,7 +4339,9 @@ let SlideApi$1 = class SlideApi {
3987
4339
  }
3988
4340
  this._slideInInit = null;
3989
4341
  this._slideInRender = true;
3990
- slideBoxPrerender.innerHTML = html;
4342
+ if (html != null) {
4343
+ slideBoxPrerender.innerHTML = html;
4344
+ }
3991
4345
  const prevSlide = this.slide ? Object.assign(Object.create(Object.getPrototypeOf(this.slide)), this.slide) : null;
3992
4346
  const { slide, result, reason } = await this._init(() => this._slideBoxRenderComplete(prevSlide));
3993
4347
  this._slide = slide;
@@ -4009,7 +4363,7 @@ let SlideApi$1 = class SlideApi {
4009
4363
  return container.get({ identifier: "LayoutService" });
4010
4364
  }
4011
4365
  getLocalData() {
4012
- return this.sdkApi.getCardLocalData();
4366
+ return this.slideApiDeps.getCardLocalData();
4013
4367
  }
4014
4368
  _fontsInit = false;
4015
4369
  _initAndLoadFonts(fonts) {
@@ -4101,7 +4455,7 @@ let SlideApi$1 = class SlideApi {
4101
4455
  /**
4102
4456
  * For case when SlideApi instance was created before root was attached to DOM
4103
4457
  */
4104
- this.refreshSizes();
4458
+ // this.config.refreshSizes(this);
4105
4459
  const slideNodeRef = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName} .narrative-slide`);
4106
4460
  const slidesNodesRefs = Array.prototype.slice.call(this._slideWrapper.querySelectorAll(`.${SlideApi.prerenderBoxClassName} .narrative-slide.narrative-multi-slide`));
4107
4461
  if (!slidesNodesRefs.length && slideNodeRef != null) {
@@ -4114,17 +4468,18 @@ let SlideApi$1 = class SlideApi {
4114
4468
  const slideReadyPromise = new Promise(resolve => {
4115
4469
  slideReadyResolve = resolve;
4116
4470
  });
4117
- const slide = new Slide(slidesNodesRefs, slideReadyPromise, this.afterAppResumeQueuePush.bind(this), this.afterStartInitQueuePush.bind(this), this.sdkApi.showNextSlide.bind(this), this.sdkApi, this._slideWrapper, () => this.layoutDirection, this.slidePauseUI.bind(this), this.slideResumeUI.bind(this), this.getSdkClientVariables);
4471
+ const slide = new Slide(slidesNodesRefs, slideReadyPromise, this.afterAppResumeQueuePush.bind(this), this.afterStartInitQueuePush.bind(this), this.slideApiDeps, this._slideWrapper, () => this.layoutDirection, this.slidePauseUI.bind(this), this.slideResumeUI.bind(this), this.config.getSdkClientVariables);
4118
4472
  this._slideInInit = slide;
4473
+ // todo - call via DI
4119
4474
  slide.activeLayer.timeline.triggerSlideLoadState();
4120
- if (this.sdkApi.isAndroid) {
4475
+ if (this.slideApiDeps.isAndroid) {
4121
4476
  this._afterStartInitQueue = [];
4122
4477
  }
4123
4478
  this._afterAppResumeQueue = [];
4124
4479
  const result = { slide, result: false, reason: "" };
4125
4480
  try {
4126
4481
  const onAllMediaLoaded = this._onAllMediaLoaded(slide);
4127
- const fontsPromise = this._initAndLoadFonts(this.sdkApi.getCardFonts());
4482
+ const fontsPromise = this._initAndLoadFonts(this.slideApiDeps.getCardFonts());
4128
4483
  const mediaAndFontsPromise = Promise.all([onAllMediaLoaded, fontsPromise]).then(() => {
4129
4484
  this.layoutService.env.clearTimeout(mediaResourcesTimeoutId);
4130
4485
  });
@@ -4223,7 +4578,7 @@ let SlideApi$1 = class SlideApi {
4223
4578
  this._slideConfig = config;
4224
4579
  // start deferred fncs from widgets
4225
4580
  // important - Android only
4226
- if (this.sdkApi.isAndroid && this._afterStartInitQueue && Array.isArray(this._afterStartInitQueue)) {
4581
+ if (this.slideApiDeps.isAndroid && this._afterStartInitQueue && Array.isArray(this._afterStartInitQueue)) {
4227
4582
  for (const job of this._afterStartInitQueue) {
4228
4583
  if (isFunction(job)) {
4229
4584
  job();
@@ -4277,7 +4632,7 @@ let SlideApi$1 = class SlideApi {
4277
4632
  this._state = 9 /* STATE.USER_PAUSED */;
4278
4633
  };
4279
4634
  // todo move to Android adapter
4280
- if (this.sdkApi.isAndroid && !this.sdkApi.isSdkSupportCorrectPauseResumeLifecycle()) {
4635
+ if (this.slideApiDeps.isAndroid && !this.slideApiDeps.isSdkSupportCorrectPauseResumeLifecycle()) {
4281
4636
  this._pauseCbTimer = this.layoutService.env.setTimeout(pauseCb, 300);
4282
4637
  }
4283
4638
  else {
@@ -4351,10 +4706,10 @@ let SlideApi$1 = class SlideApi {
4351
4706
  const defaultAction = () => {
4352
4707
  const nextSlideIndex = this.slide.slideIndex + 1;
4353
4708
  if (nextSlideIndex >= 0 && nextSlideIndex < this.slide.slideCount) {
4354
- this.sdkApi.showCardSlide(nextSlideIndex);
4709
+ this.slideApiDeps.showCardSlide(nextSlideIndex);
4355
4710
  }
4356
4711
  else {
4357
- this.sdkApi.cardShowNext();
4712
+ this.slideApiDeps.cardShowNext();
4358
4713
  }
4359
4714
  };
4360
4715
  if (this.activeLayer.questElement) {
@@ -4401,7 +4756,7 @@ let SlideApi$1 = class SlideApi {
4401
4756
  if (!isFunction(cb)) {
4402
4757
  return false;
4403
4758
  }
4404
- if (this.sdkApi.isAndroid && this._state === 0 /* STATE.INIT */) {
4759
+ if (this.slideApiDeps.isAndroid && this._state === 0 /* STATE.INIT */) {
4405
4760
  this._afterStartInitQueue.push(cb);
4406
4761
  }
4407
4762
  else {
@@ -4530,7 +4885,7 @@ let SlideApi$1 = class SlideApi {
4530
4885
  if (this.layoutService.layoutApi.widgetVoteApi) {
4531
4886
  if (this.layoutService.layoutApi.widgetVoteApi.click(element)) {
4532
4887
  this.layoutService.env.setTimeout(() => {
4533
- this.sdkApi.showNextSlide(0);
4888
+ this.slideApiDeps.showNextSlide(0);
4534
4889
  });
4535
4890
  }
4536
4891
  result.canClickNext = false;
@@ -4554,7 +4909,7 @@ let SlideApi$1 = class SlideApi {
4554
4909
  }
4555
4910
  if (element) {
4556
4911
  this.layoutService.env.setTimeout(() => {
4557
- this.sdkApi.showNextSlide(0);
4912
+ this.slideApiDeps.showNextSlide(0);
4558
4913
  });
4559
4914
  result.canClickNext = false;
4560
4915
  return result;
@@ -4582,7 +4937,7 @@ let SlideApi$1 = class SlideApi {
4582
4937
  if (this.layoutService.layoutApi.widgetRangeSliderApi) {
4583
4938
  if (this.layoutService.layoutApi.widgetRangeSliderApi.click(element)) {
4584
4939
  this.layoutService.env.setTimeout(() => {
4585
- this.sdkApi.showNextSlide(0);
4940
+ this.slideApiDeps.showNextSlide(0);
4586
4941
  });
4587
4942
  }
4588
4943
  result.canClickNext = false;
@@ -4789,18 +5144,18 @@ let SlideApi$1 = class SlideApi {
4789
5144
  }
4790
5145
  if (element) {
4791
5146
  propagation = false;
4792
- this.sdkApi.setCardLocalData({}, true);
4793
- this.sdkApi.updateCardServerDataLocally(this.slide.cardId, {});
5147
+ this.slideApiDeps.setCardLocalData({}, true);
5148
+ this.slideApiDeps.updateCardServerDataLocally(this.slide.cardId, {});
4794
5149
  // window._resetTimers();
4795
5150
  // сделать async в ios
4796
5151
  let slideIndex = this.slide.slideIndex;
4797
5152
  // prevent simultaneous call _showNarrativeSlide and _showLayer - prevent 2 calls of initAfterLoad (break video start on iOS)
4798
5153
  if (slideIndex === 0) {
4799
5154
  // for story repeat on the first slide with layers
4800
- this.sdkApi.showLayer(0);
5155
+ this.slideApiDeps.showLayer(0);
4801
5156
  }
4802
5157
  else {
4803
- this.sdkApi.showCardSlide(0); // сделать ее async
5158
+ this.slideApiDeps.showCardSlide(0); // сделать ее async
4804
5159
  }
4805
5160
  }
4806
5161
  // todo в каждом виджете делать выход через
@@ -4888,44 +5243,44 @@ let SlideApi$1 = class SlideApi {
4888
5243
  // this.activeLayer.timeline.slidePaused(0);
4889
5244
  // return {handled: true};
4890
5245
  }
4891
- if (this.sdkApi.isAndroid && linkTargetAndroid) {
5246
+ if (this.slideApiDeps.isAndroid && linkTargetAndroid) {
4892
5247
  linkTarget = linkTargetAndroid;
4893
5248
  }
4894
- if (this.sdkApi.isIOS && linkTargetIos) {
5249
+ if (this.slideApiDeps.isIOS && linkTargetIos) {
4895
5250
  linkTarget = linkTargetIos;
4896
5251
  }
4897
- if (this.sdkApi.isWeb && linkTargetWeb) {
5252
+ if (this.slideApiDeps.isWeb && linkTargetWeb) {
4898
5253
  linkTarget = linkTargetWeb;
4899
5254
  }
4900
5255
  // for btn(link) without url (openGame, openStory, closeCard, products, goods, etc)
4901
5256
  let statisticWidgetValue = linkType;
4902
5257
  let statisticWidgetEventType = "w-link";
4903
5258
  if (linkType === "closeStory" || linkType === "closeIAM") {
4904
- this.layoutService.env.setTimeout(() => this.sdkApi.closeCard("click"));
5259
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.closeCard("click"));
4905
5260
  handled = true;
4906
5261
  }
4907
5262
  else if (linkType && linkTarget) {
4908
5263
  if (linkType === "story") {
4909
5264
  // storyId: number, slideIndex: number
4910
- this.layoutService.env.setTimeout(() => this.sdkApi.openStory(parseInt(linkTarget), 0));
5265
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.openStory(parseInt(linkTarget), 0));
4911
5266
  handled = true;
4912
5267
  }
4913
5268
  else if (linkType === "slide") {
4914
5269
  const __slideIndex = parseInt(linkTarget);
4915
5270
  const __slideCount = this.slide.slideCount;
4916
5271
  if (__slideIndex >= 0 && __slideIndex < __slideCount) {
4917
- this.layoutService.env.setTimeout(() => this.sdkApi.showCardSlide(__slideIndex));
5272
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.showCardSlide(__slideIndex));
4918
5273
  handled = true;
4919
5274
  }
4920
5275
  }
4921
5276
  else if (linkType === "game") {
4922
- this.layoutService.env.setTimeout(() => this.sdkApi.openGame(linkTarget));
5277
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.openGame(linkTarget));
4923
5278
  handled = true;
4924
5279
  }
4925
5280
  else if (linkType === "layer") {
4926
5281
  const layerIndex = parseInt(linkTarget);
4927
5282
  if (layerIndex >= 0) {
4928
- this.layoutService.env.setTimeout(() => this.sdkApi.showLayer(layerIndex));
5283
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.showLayer(layerIndex));
4929
5284
  handled = true;
4930
5285
  }
4931
5286
  }
@@ -4933,7 +5288,7 @@ let SlideApi$1 = class SlideApi {
4933
5288
  // traditional link, with url
4934
5289
  statisticWidgetValue = linkTarget;
4935
5290
  this.layoutService.env.setTimeout(() => {
4936
- this.sdkApi.openUrl({
5291
+ this.slideApiDeps.openUrl({
4937
5292
  type: isSwipeUpAction ? "swipeUpLink" : "link",
4938
5293
  link: {
4939
5294
  type: "url",
@@ -4943,6 +5298,12 @@ let SlideApi$1 = class SlideApi {
4943
5298
  });
4944
5299
  handled = true;
4945
5300
  }
5301
+ else if (linkType === "promocode") {
5302
+ handled = this.activeLayer.findElementByNodeRef(element)?.handleClick() ?? true;
5303
+ if (!handled) {
5304
+ return { handled: true };
5305
+ }
5306
+ }
4946
5307
  else if (linkType === "products") {
4947
5308
  if (this.layoutService.layoutApi.widgetProductsApi) {
4948
5309
  this.layoutService.layoutApi.widgetProductsApi.click(element);
@@ -4952,7 +5313,7 @@ let SlideApi$1 = class SlideApi {
4952
5313
  else if (linkType === "swipe-up-items") {
4953
5314
  const target = linkTarget;
4954
5315
  this.layoutService.env.setTimeout(() => {
4955
- this.sdkApi.openUrl({
5316
+ this.slideApiDeps.openUrl({
4956
5317
  type: "swipeUpItems",
4957
5318
  link: {
4958
5319
  type: "json",
@@ -4988,7 +5349,7 @@ let SlideApi$1 = class SlideApi {
4988
5349
  baseFields.message_id = cardId;
4989
5350
  break;
4990
5351
  }
4991
- this.sdkApi.sendStatisticEvent(statisticWidgetEventType, {
5352
+ this.slideApiDeps.sendStatisticEvent(statisticWidgetEventType, {
4992
5353
  i: cardId,
4993
5354
  si: slideIndex,
4994
5355
  wi: elementId,
@@ -5044,28 +5405,1251 @@ let SlideApi$1 = class SlideApi {
5044
5405
  }
5045
5406
  }
5046
5407
  }
5047
- _sdkClientVariables = {};
5048
- getSdkClientVariables() {
5049
- return this._sdkClientVariables;
5050
- }
5051
- setSdkClientVariables(variables) {
5052
- this._sdkClientVariables = variables;
5053
- }
5054
5408
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
5055
- sdkApi: SDKApi;
5409
+ slideApiDeps: ISlideApiDeps;
5056
5410
  slideWrapper: HTMLElement;
5057
5411
  viewport: Window;
5058
5412
  userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5059
5413
  slideRatio: number;
5060
5414
  isFullscreen: boolean;
5061
- slideLoadedCb?: (data: { cardId: number; slideIndex: number; result: boolean; reason?: string }) => void;
5062
5415
  getViewportWidth: () => number;
5063
5416
  getViewportHeight: () => number;
5064
5417
  overlappingActionBarHeight?: number;
5065
5418
  separateUserAndAppPause: boolean;
5419
+ root: HTMLElement;
5420
+ nonce?: string;
5421
+ // refreshSizes: (slide: SlideApi) => void;
5422
+ index: number;
5423
+ getSdkClientVariables: GetSdkClientVariables;
5066
5424
  }`]; }
5067
5425
  };
5068
5426
 
5427
+ class SlideApiDepsMultiSlideMode {
5428
+ sdkApi;
5429
+ slider;
5430
+ constructor(sdkApi, slider) {
5431
+ this.sdkApi = sdkApi;
5432
+ this.slider = slider;
5433
+ }
5434
+ getWidgetsSharedData(cardId, widget) {
5435
+ return this.sdkApi.getWidgetsSharedData(cardId, widget);
5436
+ }
5437
+ showToast(text) {
5438
+ return this.sdkApi.showToast(text);
5439
+ }
5440
+ writeToClipboard(data) {
5441
+ return this.sdkApi.writeToClipboard(data);
5442
+ }
5443
+ get isExistsShare() {
5444
+ return this.sdkApi.isExistsShare;
5445
+ }
5446
+ share(id, config) {
5447
+ this.sdkApi.share(id, config);
5448
+ }
5449
+ get sdkCanSendShareComplete() {
5450
+ return this.sdkApi.sdkCanSendShareComplete;
5451
+ }
5452
+ shareSlideScreenshot(shareId, hideElementsSelector, shareText) {
5453
+ this.sdkApi.shareSlideScreenshot(shareId, hideElementsSelector, shareText);
5454
+ }
5455
+ setCardSessionValue(element, key, value) {
5456
+ this.sdkApi.setCardSessionValue(element, key, value);
5457
+ }
5458
+ getCardSessionValue(element, key) {
5459
+ return this.sdkApi.getCardSessionValue(element, key);
5460
+ }
5461
+ getCardFonts() {
5462
+ return this.sdkApi.getCardFonts();
5463
+ }
5464
+ disableVerticalSwipeGesture() {
5465
+ this.sdkApi.disableVerticalSwipeGesture();
5466
+ }
5467
+ enableVerticalSwipeGesture() {
5468
+ this.sdkApi.enableVerticalSwipeGesture();
5469
+ }
5470
+ disableBackpress() {
5471
+ this.sdkApi.disableBackpress();
5472
+ }
5473
+ enableBackpress() {
5474
+ this.sdkApi.enableBackpress();
5475
+ }
5476
+ closeCard(reason) {
5477
+ this.sdkApi.closeCard(reason);
5478
+ }
5479
+ openStory(id, index) {
5480
+ // TODO rewrite with Promise - for usage story loading states in Button
5481
+ this.sdkApi.openStory(id, index);
5482
+ }
5483
+ openGame(gameInstanceId) {
5484
+ // TODO rewrite with Promise - for usage game loading states in Button
5485
+ this.sdkApi.openGame(gameInstanceId);
5486
+ }
5487
+ openUrl(data) {
5488
+ this.sdkApi.openUrl(data);
5489
+ }
5490
+ get isAndroid() {
5491
+ return this.sdkApi.isAndroid;
5492
+ }
5493
+ get isWeb() {
5494
+ return this.sdkApi.isWeb;
5495
+ }
5496
+ get isIOS() {
5497
+ return this.sdkApi.isIOS;
5498
+ }
5499
+ get isExistsShowCardTextInput() {
5500
+ return this.sdkApi.isExistsShowCardTextInput;
5501
+ }
5502
+ showCardTextInput(id, data) {
5503
+ this.sdkApi.showCardTextInput(id, data);
5504
+ }
5505
+ vibrate(pattern) {
5506
+ this.sdkApi.vibrate(pattern);
5507
+ }
5508
+ sendApiRequest(url, method, params, headers, data, profilingKey) {
5509
+ return this.sdkApi.sendApiRequest(url, method, params, headers, data, profilingKey);
5510
+ }
5511
+ sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2) {
5512
+ this.sdkApi.sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2);
5513
+ }
5514
+ setCardLocalData(keyValue, sendToServer) {
5515
+ this.sdkApi.setCardLocalData(keyValue, sendToServer);
5516
+ }
5517
+ getCardLocalData() {
5518
+ return this.sdkApi.getCardLocalData();
5519
+ }
5520
+ getCardServerData(cardId) {
5521
+ return this.sdkApi.getCardServerData(cardId);
5522
+ }
5523
+ get cardAnimation() {
5524
+ return this.sdkApi.cardAnimation;
5525
+ }
5526
+ updateCardServerDataLocally(cardId, data) {
5527
+ this.sdkApi.updateCardServerDataLocally(cardId, data);
5528
+ }
5529
+ get isExistsShowNextCard() {
5530
+ return this.sdkApi.isExistsShowNextCard;
5531
+ }
5532
+ cardShowNext() {
5533
+ this.sdkApi.cardShowNext();
5534
+ }
5535
+ /** @deprecated, used only in native sdk **/
5536
+ cardPausedCallback(currentTime) {
5537
+ this.sdkApi.cardPausedCallback(currentTime);
5538
+ }
5539
+ /** @deprecated, used only in native sdk **/
5540
+ cardResumedCallback(currentTime) {
5541
+ this.sdkApi.cardResumedCallback(currentTime);
5542
+ }
5543
+ disableHorizontalSwipeGesture() {
5544
+ this.sdkApi.disableHorizontalSwipeGesture();
5545
+ }
5546
+ enableHorizontalSwipeGesture() {
5547
+ this.sdkApi.enableHorizontalSwipeGesture();
5548
+ }
5549
+ isExistsShowLayer() {
5550
+ return this.sdkApi.isExistsShowLayer();
5551
+ }
5552
+ showLayer(index) {
5553
+ this.sdkApi.showLayer(index);
5554
+ }
5555
+ /**
5556
+ * For single slide mode - proxy these methods via SDKApi
5557
+ * =================================================================================================================
5558
+ */
5559
+ get isExistsShowCardSlide() {
5560
+ return true;
5561
+ }
5562
+ showCardSlide(index) {
5563
+ this.slider.showByIndex(index);
5564
+ }
5565
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
5566
+ this.slider.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
5567
+ }
5568
+ isSdkSupportTimelineOnBeforeStart() {
5569
+ return true;
5570
+ }
5571
+ isSdkSupportCorrectPauseResumeLifecycle() {
5572
+ return true;
5573
+ }
5574
+ showNextSlide(duration) {
5575
+ this.slider.showNextSlide();
5576
+ }
5577
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`, `ISlider`]; }
5578
+ }
5579
+
5580
+ class SlideApiDepsSingleSlideMode {
5581
+ sdkApi;
5582
+ constructor(sdkApi) {
5583
+ this.sdkApi = sdkApi;
5584
+ }
5585
+ getWidgetsSharedData(cardId, widget) {
5586
+ return this.sdkApi.getWidgetsSharedData(cardId, widget);
5587
+ }
5588
+ showToast(text) {
5589
+ return this.sdkApi.showToast(text);
5590
+ }
5591
+ writeToClipboard(data) {
5592
+ return this.sdkApi.writeToClipboard(data);
5593
+ }
5594
+ get isExistsShare() {
5595
+ return this.sdkApi.isExistsShare;
5596
+ }
5597
+ share(id, config) {
5598
+ this.sdkApi.share(id, config);
5599
+ }
5600
+ get sdkCanSendShareComplete() {
5601
+ return this.sdkApi.sdkCanSendShareComplete;
5602
+ }
5603
+ shareSlideScreenshot(shareId, hideElementsSelector, shareText) {
5604
+ this.sdkApi.shareSlideScreenshot(shareId, hideElementsSelector, shareText);
5605
+ }
5606
+ setCardSessionValue(element, key, value) {
5607
+ this.sdkApi.setCardSessionValue(element, key, value);
5608
+ }
5609
+ getCardSessionValue(element, key) {
5610
+ return this.sdkApi.getCardSessionValue(element, key);
5611
+ }
5612
+ getCardFonts() {
5613
+ return this.sdkApi.getCardFonts();
5614
+ }
5615
+ disableVerticalSwipeGesture() {
5616
+ this.sdkApi.disableVerticalSwipeGesture();
5617
+ }
5618
+ enableVerticalSwipeGesture() {
5619
+ this.sdkApi.enableVerticalSwipeGesture();
5620
+ }
5621
+ disableBackpress() {
5622
+ this.sdkApi.disableBackpress();
5623
+ }
5624
+ enableBackpress() {
5625
+ this.sdkApi.enableBackpress();
5626
+ }
5627
+ closeCard(reason) {
5628
+ this.sdkApi.closeCard(reason);
5629
+ }
5630
+ openStory(id, index) {
5631
+ // TODO rewrite with Promise - for usage story loading states in Button
5632
+ this.sdkApi.openStory(id, index);
5633
+ }
5634
+ openGame(gameInstanceId) {
5635
+ // TODO rewrite with Promise - for usage game loading states in Button
5636
+ this.sdkApi.openGame(gameInstanceId);
5637
+ }
5638
+ openUrl(data) {
5639
+ this.sdkApi.openUrl(data);
5640
+ }
5641
+ get isAndroid() {
5642
+ return this.sdkApi.isAndroid;
5643
+ }
5644
+ get isWeb() {
5645
+ return this.sdkApi.isWeb;
5646
+ }
5647
+ get isIOS() {
5648
+ return this.sdkApi.isIOS;
5649
+ }
5650
+ get isExistsShowCardTextInput() {
5651
+ return this.sdkApi.isExistsShowCardTextInput;
5652
+ }
5653
+ showCardTextInput(id, data) {
5654
+ this.sdkApi.showCardTextInput(id, data);
5655
+ }
5656
+ vibrate(pattern) {
5657
+ this.sdkApi.vibrate(pattern);
5658
+ }
5659
+ sendApiRequest(url, method, params, headers, data, profilingKey) {
5660
+ return this.sdkApi.sendApiRequest(url, method, params, headers, data, profilingKey);
5661
+ }
5662
+ sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2) {
5663
+ this.sdkApi.sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2);
5664
+ }
5665
+ setCardLocalData(keyValue, sendToServer) {
5666
+ this.sdkApi.setCardLocalData(keyValue, sendToServer);
5667
+ }
5668
+ getCardLocalData() {
5669
+ return this.sdkApi.getCardLocalData();
5670
+ }
5671
+ getCardServerData(cardId) {
5672
+ return this.sdkApi.getCardServerData(cardId);
5673
+ }
5674
+ get cardAnimation() {
5675
+ return this.sdkApi.cardAnimation;
5676
+ }
5677
+ updateCardServerDataLocally(cardId, data) {
5678
+ this.sdkApi.updateCardServerDataLocally(cardId, data);
5679
+ }
5680
+ get isExistsShowNextCard() {
5681
+ return this.sdkApi.isExistsShowNextCard;
5682
+ }
5683
+ cardShowNext() {
5684
+ this.sdkApi.cardShowNext();
5685
+ }
5686
+ /** @deprecated, used only in native sdk **/
5687
+ cardPausedCallback(currentTime) {
5688
+ this.sdkApi.cardPausedCallback(currentTime);
5689
+ }
5690
+ /** @deprecated, used only in native sdk **/
5691
+ cardResumedCallback(currentTime) {
5692
+ this.sdkApi.cardResumedCallback(currentTime);
5693
+ }
5694
+ disableHorizontalSwipeGesture() {
5695
+ this.sdkApi.disableHorizontalSwipeGesture();
5696
+ }
5697
+ enableHorizontalSwipeGesture() {
5698
+ this.sdkApi.enableHorizontalSwipeGesture();
5699
+ }
5700
+ isExistsShowLayer() {
5701
+ return this.sdkApi.isExistsShowLayer();
5702
+ }
5703
+ showLayer(index) {
5704
+ this.sdkApi.showLayer(index);
5705
+ }
5706
+ /**
5707
+ * For single slide mode - proxy these methods via SDKApi
5708
+ */
5709
+ get isExistsShowCardSlide() {
5710
+ return this.sdkApi.isExistsShowCardSlide;
5711
+ }
5712
+ showCardSlide(index) {
5713
+ this.sdkApi.showCardSlide(index);
5714
+ }
5715
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
5716
+ this.sdkApi.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
5717
+ }
5718
+ isSdkSupportTimelineOnBeforeStart() {
5719
+ return this.sdkApi.isSdkSupportTimelineOnBeforeStart();
5720
+ }
5721
+ isSdkSupportCorrectPauseResumeLifecycle() {
5722
+ return this.sdkApi.isSdkSupportCorrectPauseResumeLifecycle();
5723
+ }
5724
+ showNextSlide(duration) {
5725
+ this.sdkApi.showNextSlide(duration);
5726
+ }
5727
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`]; }
5728
+ }
5729
+
5730
+ class SlideTimer {
5731
+ requestStartTimer;
5732
+ requestCancelTimer;
5733
+ updateCb;
5734
+ doneCb;
5735
+ constructor(requestStartTimer, requestCancelTimer, updateCb, doneCb) {
5736
+ this.requestStartTimer = requestStartTimer;
5737
+ this.requestCancelTimer = requestCancelTimer;
5738
+ this.updateCb = updateCb;
5739
+ this.doneCb = doneCb;
5740
+ }
5741
+ duration;
5742
+ timeLeft;
5743
+ _pause = true;
5744
+ _stop = true;
5745
+ _started = false;
5746
+ start(duration) {
5747
+ this.duration = duration;
5748
+ this.stop();
5749
+ this.timeLeft = this.duration;
5750
+ this._pause = false;
5751
+ this._stop = false;
5752
+ this._started = true;
5753
+ this.tick();
5754
+ }
5755
+ stop() {
5756
+ this._stop = true;
5757
+ this._started = false;
5758
+ if (this.timerId != null) {
5759
+ this.requestCancelTimer(this.timerId);
5760
+ this.timerId = null;
5761
+ }
5762
+ // this.updateCb(0);
5763
+ }
5764
+ pause() {
5765
+ this._pause = true;
5766
+ if (this.timerId != null) {
5767
+ this.requestCancelTimer(this.timerId);
5768
+ this.timerId = null;
5769
+ }
5770
+ }
5771
+ resume(duration = 0) {
5772
+ this._pause = false;
5773
+ if (!this._started) {
5774
+ this.start(duration);
5775
+ }
5776
+ else {
5777
+ this.tick();
5778
+ }
5779
+ }
5780
+ timerId;
5781
+ tick() {
5782
+ if (this._stop) {
5783
+ return;
5784
+ }
5785
+ const rafStartTime = new Date().getTime();
5786
+ this.timerId = this.requestStartTimer(() => {
5787
+ if (this._stop) {
5788
+ return;
5789
+ }
5790
+ const dtDiff = new Date().getTime() - rafStartTime;
5791
+ this.timeLeft -= dtDiff;
5792
+ let progress = Math.round(((this.duration - this.timeLeft) / this.duration) * 100 * 10000) / 10000;
5793
+ if (progress > 100) {
5794
+ progress = 100;
5795
+ }
5796
+ this.updateCb(progress);
5797
+ if (progress < 100) {
5798
+ if (this._pause !== true) {
5799
+ this.tick();
5800
+ }
5801
+ }
5802
+ else {
5803
+ this.doneCb();
5804
+ }
5805
+ });
5806
+ }
5807
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`(callback: () => void) => number`, `(timerId: number) => void`, `(progress: number) => void`, `() => void`]; }
5808
+ }
5809
+
5810
+ class Slider {
5811
+ config;
5812
+ constructor(config) {
5813
+ this.config = config;
5814
+ for (let i = 0; i < config.slides.length; ++i) {
5815
+ const item = {
5816
+ called: false,
5817
+ firstRenderCall: null,
5818
+ firstRenderCallPromise: null,
5819
+ };
5820
+ item.firstRenderCallPromise = new Promise(resolver => {
5821
+ item.firstRenderCall = resolver;
5822
+ });
5823
+ this.slidesFirstRenders[i] = item;
5824
+ }
5825
+ const slideWrapper = this.createSliderElement({
5826
+ slides: config.slides,
5827
+ nonce: config.nonce,
5828
+ slideRender: config.slideRender,
5829
+ });
5830
+ config.root.appendChild(slideWrapper);
5831
+ this.slideWrapperElement = slideWrapper;
5832
+ // cardMounted: (card: HTMLElement) => Promise<void>
5833
+ requestAnimationFrame(async () => {
5834
+ await Promise.all(this.slides.map((slide, index) => config.onSlideMounted(slide.element, index)));
5835
+ });
5836
+ }
5837
+ isAnimating = false;
5838
+ activeIndex = -1;
5839
+ get activeSlide() {
5840
+ return this.slides[this.activeIndex];
5841
+ }
5842
+ slides = [];
5843
+ sliderTrack = null;
5844
+ bulletsContainer = null;
5845
+ slidesFirstRenders = [];
5846
+ slideWrapperElement;
5847
+ updateBulletActiveIndex;
5848
+ updateTimelineProgress;
5849
+ createSliderElement = ({ slides, nonce, slideRender }) => {
5850
+ const style = document.createElement("style");
5851
+ if (nonce != null) {
5852
+ style.nonce = nonce;
5853
+ }
5854
+ const slider = document.createElement("div");
5855
+ slider.classList.add("cards-slider");
5856
+ const track = document.createElement("div");
5857
+ track.classList.add("cards-slider__track");
5858
+ this.sliderTrack = track;
5859
+ for (let i = 0; i < slides.length; ++i) {
5860
+ const slide = document.createElement("div");
5861
+ slide.classList.add("cards-slider__slide");
5862
+ slide.setAttribute("data-index", String(i));
5863
+ this.slides[i] = {
5864
+ element: slideRender(slides[i], i, this.slidesFirstRenders[i].firstRenderCallPromise),
5865
+ timer: new SlideTimer(cb => window.requestAnimationFrame(cb), handle => window.cancelAnimationFrame(handle), this.onSlideTimerUpdate.bind(this), this.onSlideTimerEnd.bind(this)),
5866
+ };
5867
+ slide.appendChild(this.slides[i].element);
5868
+ track.appendChild(slide);
5869
+ }
5870
+ const [bullets, updateBulletActiveIndex, updateTimelineProgress] = this.createBulletPoints(slides.length);
5871
+ this.bulletsContainer = bullets;
5872
+ this.updateBulletActiveIndex = updateBulletActiveIndex.bind(this);
5873
+ this.updateTimelineProgress = updateTimelineProgress.bind(this);
5874
+ slider.appendChild(track);
5875
+ slider.appendChild(bullets);
5876
+ slider.appendChild(style);
5877
+ return slider;
5878
+ };
5879
+ createBulletPoints(count) {
5880
+ const bullets = document.createElement("div");
5881
+ bullets.classList.toggle("cards-slider__bullets");
5882
+ for (let i = 0; i < count; ++i) {
5883
+ const bullet = document.createElement("div");
5884
+ bullet.classList.add("cards-slider__bullet");
5885
+ bullet.setAttribute("data-index", String(i));
5886
+ bullet.onclick = (e) => {
5887
+ e.stopPropagation();
5888
+ e.preventDefault();
5889
+ const bullet = e.target;
5890
+ if (bullet != null) {
5891
+ const index = bullet.dataset.index;
5892
+ if (index != null) {
5893
+ this.showByIndex(parseInt(index));
5894
+ }
5895
+ }
5896
+ };
5897
+ const bulletFill = document.createElement("div");
5898
+ bulletFill.classList.add("cards-slider__bullet-fill");
5899
+ bullet.append(bulletFill);
5900
+ bullets.appendChild(bullet);
5901
+ }
5902
+ const onUpdateActiveIndex = (activeIndex) => {
5903
+ if (activeIndex >= 0 && activeIndex < count) {
5904
+ for (const bullet of bullets.querySelectorAll(".cards-slider__bullet--active")) {
5905
+ bullet.classList.toggle("cards-slider__bullet--active");
5906
+ }
5907
+ bullets.querySelector(`.cards-slider__bullet[data-index="${activeIndex}"]`)?.classList.toggle("cards-slider__bullet--active");
5908
+ }
5909
+ };
5910
+ const onUpdateTimelineProgress = (index, progress) => {
5911
+ if (index >= 0 && index < count) {
5912
+ const bullet = bullets.querySelector(`.cards-slider__bullet:nth-child(${index + 1}) .cards-slider__bullet-fill`);
5913
+ if (bullet != null) {
5914
+ // todo RTL
5915
+ //need (in css) right: 100% instead of left -100%;
5916
+ // todo remove progress after slide changed?
5917
+ bullet.style.setProperty("transform", `translateX(${progress}%)`);
5918
+ // transform: `translateZ(0) translateX(${
5919
+ // index < this.$props.index
5920
+ // ? "100%"
5921
+ // : index === this.$props.index
5922
+ // ? `${this.$props.timePercent}%`
5923
+ // : "0%"
5924
+ // })`,
5925
+ }
5926
+ }
5927
+ };
5928
+ return [bullets, onUpdateActiveIndex, onUpdateTimelineProgress];
5929
+ }
5930
+ async showByIndex(newIndex) {
5931
+ const prevIndex = this.activeIndex;
5932
+ if (this.isAnimating)
5933
+ return prevIndex;
5934
+ if (prevIndex !== -1) {
5935
+ // skip for slider start
5936
+ this.config.onSlideLeft(this.slides[prevIndex].element, prevIndex);
5937
+ this.config.onSlideStop();
5938
+ }
5939
+ const { index, loadingError } = await this.initAndRenderSlide(newIndex);
5940
+ if (loadingError) {
5941
+ // todo via updateTimeline ????
5942
+ this.config.onSlideLoadingError(index, loadingError);
5943
+ }
5944
+ await this.slideTo(index);
5945
+ if (!loadingError) {
5946
+ this.onShowSlide(index);
5947
+ }
5948
+ return newIndex;
5949
+ }
5950
+ async showNextSlide() {
5951
+ const prevIndex = this.activeIndex;
5952
+ if (this.isAnimating)
5953
+ return prevIndex;
5954
+ const newIndex = prevIndex + 1;
5955
+ if (newIndex < 0 || newIndex >= this.slides.length) {
5956
+ return null;
5957
+ }
5958
+ if (prevIndex !== -1) {
5959
+ // skip for slider start
5960
+ this.config.onSlideLeft(this.slides[prevIndex].element, prevIndex);
5961
+ this.config.onSlideStop();
5962
+ }
5963
+ const { index, loadingError } = await this.initAndRenderSlide(newIndex);
5964
+ if (loadingError) {
5965
+ // todo via updateTimeline ????
5966
+ this.config.onSlideLoadingError(index, loadingError);
5967
+ }
5968
+ await this.slideTo(index);
5969
+ if (!loadingError) {
5970
+ this.onShowSlide(index);
5971
+ }
5972
+ return newIndex;
5973
+ }
5974
+ async initAndRenderSlide(index) {
5975
+ this.config.onBeforeLoadSlide(index);
5976
+ let showSlidePromise;
5977
+ if (!this.slidesFirstRenders[index].called) {
5978
+ // first render call
5979
+ this.slidesFirstRenders[index].called = true;
5980
+ showSlidePromise = new Promise(resolve => {
5981
+ this.slidesFirstRenders[index].firstRenderCall(resolve);
5982
+ }).then(_ => _);
5983
+ }
5984
+ else {
5985
+ showSlidePromise = this.config.onBeforeShowSlide(this.slides[index].element, index);
5986
+ }
5987
+ try {
5988
+ const { moveToIndex } = await showSlidePromise;
5989
+ if (moveToIndex !== index) {
5990
+ index = moveToIndex;
5991
+ // jump to necessary slide (from WidgetQuest for instance)
5992
+ return this.initAndRenderSlide(index);
5993
+ }
5994
+ else {
5995
+ return { index, loadingError: undefined };
5996
+ }
5997
+ }
5998
+ catch (loadingError) {
5999
+ // catch loading error
6000
+ // this.config.onSlideLoadingError(index, e as string);
6001
+ console.error(loadingError);
6002
+ return { index, loadingError: loadingError };
6003
+ }
6004
+ }
6005
+ onShowSlide(index) {
6006
+ this.updateBulletActiveIndex(index);
6007
+ this.config.onShowSlide(this.slides[index].element, index);
6008
+ this.config.onSlideStart();
6009
+ }
6010
+ onUpdateSizeMetrics(metrics) {
6011
+ // this.slideTo(this.activeIndex, 0);
6012
+ }
6013
+ getSlideOffset(index) {
6014
+ if (!this.slides.length)
6015
+ return 0;
6016
+ const k = this.config.getLayoutDirection() === "ltr" ? -1 : 1;
6017
+ const cardWidth = this.slides[0].element.clientWidth;
6018
+ return k * index * cardWidth;
6019
+ }
6020
+ async slideTo(index, speed = 300) {
6021
+ if (index < 0 || index > this.slides.length - 1 || this.isAnimating)
6022
+ return;
6023
+ const cardOffset = this.getSlideOffset(index);
6024
+ await this.translateTo(cardOffset, speed);
6025
+ this.activeIndex = index;
6026
+ }
6027
+ setTranslate(value) {
6028
+ this.sliderTrack?.style.setProperty("transform", `translateX(${value}px)`);
6029
+ }
6030
+ setTransition(duration = 300) {
6031
+ this.sliderTrack?.style.setProperty("transition", `transform ${duration}ms`);
6032
+ }
6033
+ async translateTo(translate, speed) {
6034
+ if (this.isAnimating)
6035
+ return;
6036
+ this.setTransition(speed);
6037
+ this.setTranslate(translate);
6038
+ if (speed > 0) {
6039
+ this.isAnimating = true;
6040
+ await this.waitTransitionEnd();
6041
+ this.isAnimating = false;
6042
+ }
6043
+ }
6044
+ waitTransitionEnd() {
6045
+ const sliderTrack = this.sliderTrack;
6046
+ if (!sliderTrack)
6047
+ return Promise.resolve();
6048
+ return new Promise(resolve => {
6049
+ const handler = (e) => {
6050
+ if (e.propertyName === "transform") {
6051
+ sliderTrack.style.transitionDuration = "0ms";
6052
+ resolve();
6053
+ }
6054
+ };
6055
+ sliderTrack.addEventListener("transitionend", handler, { once: true });
6056
+ });
6057
+ }
6058
+ destroy() {
6059
+ this.activeSlide?.timer.stop();
6060
+ if (this.slideWrapperElement != null && this.config.root != null) {
6061
+ this.config.root.removeChild(this.slideWrapperElement);
6062
+ }
6063
+ }
6064
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
6065
+ switch (action) {
6066
+ case "before_start" /* TIMELINE_ACTION.BEFORE_START */: {
6067
+ // switch timeline to active slide and wait for start (wait VOD loading)
6068
+ console.log("TIMELINE_ACTION.BEFORE_START", { activeSlide: this.activeSlide, duration });
6069
+ break;
6070
+ }
6071
+ case "start" /* TIMELINE_ACTION.START */: {
6072
+ this.config.onSlideDataResume();
6073
+ // also start after data waiting or pause
6074
+ // window.setTimeout(() => {
6075
+ // this.config.onSlideStop();
6076
+ // this.config.onSlideTimerEnd();
6077
+ // }, 10000);
6078
+ // destroy on IAM closing
6079
+ console.log("TIMELINE_ACTION.START", { activeSlide: this.activeSlide, index: this.activeIndex, duration });
6080
+ this.activeSlide?.timer.resume(duration);
6081
+ break;
6082
+ }
6083
+ case "pause" /* TIMELINE_ACTION.PAUSE */: {
6084
+ if (showLoader) {
6085
+ this.config.onSlideDataWaiting();
6086
+ }
6087
+ this.activeSlide?.timer.pause();
6088
+ console.log("TIMELINE_ACTION.PAUSE", { activeSlide: this.activeSlide, duration });
6089
+ break;
6090
+ }
6091
+ case "stop" /* TIMELINE_ACTION.STOP */: {
6092
+ // loading error
6093
+ if (showError) {
6094
+ this.config.onSlideDataError();
6095
+ }
6096
+ this.activeSlide?.timer.stop();
6097
+ // todo нужен STOP когда вручную переключаем слайд на другой
6098
+ console.log("TIMELINE_ACTION.STOP", { activeSlide: this.activeSlide, duration });
6099
+ break;
6100
+ }
6101
+ }
6102
+ }
6103
+ onSlideTimerUpdate(progress) {
6104
+ this.updateTimelineProgress(this.activeIndex, progress);
6105
+ }
6106
+ onSlideTimerEnd() {
6107
+ this.config.onSlideStop();
6108
+ this.config.onSlideTimerEnd();
6109
+ }
6110
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
6111
+ slides: Array<T>;
6112
+ root: HTMLElement;
6113
+ // isFullscreen: boolean;
6114
+ nonce?: string;
6115
+ // viewport: Window;
6116
+ // userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
6117
+ // VODPlayer?: typeof VODPlayer;
6118
+ // overlappingActionBarHeight?: number;
6119
+ slideRender: SlideRender<T>;
6120
+ onSlideMounted: OnSlideMounted;
6121
+ onBeforeShowSlide: OnBeforeShowSlide;
6122
+ onBeforeLoadSlide: OnBeforeLoadSlide;
6123
+ onSlideLoadingError: OnSlideLoadingError;
6124
+ onShowSlide: OnShowSlide;
6125
+ onSlideLeft: OnSlideLeft;
6126
+ getLayoutDirection: GetLayoutDirection;
6127
+
6128
+ onSlideTimerEnd: OnSlideTimerEnd;
6129
+ onSlideStart: OnSlideStart;
6130
+ onSlideStop: OnSlideStop;
6131
+ onSlideDataWaiting: OnSlideDataWaiting;
6132
+ onSlideDataResume: OnSlideDataResume;
6133
+ onSlideDataError: OnSlideDataError;
6134
+ }`]; }
6135
+ }
6136
+
6137
+ class CardApi {
6138
+ config;
6139
+ get layoutDirection() {
6140
+ return this.activeSlide.layoutDirection;
6141
+ }
6142
+ static renderedBoxClassName = "narrative-slide-box-rendered";
6143
+ static prerenderBoxClassName = "narrative-slide-box-prerender";
6144
+ _singleCardSlideWrapper;
6145
+ _viewport;
6146
+ _getViewportWidth;
6147
+ _getViewportHeight;
6148
+ _overlappingActionBarHeight;
6149
+ _separateUserAndAppPause;
6150
+ _useSdkCacheForMultislideMode;
6151
+ sdkApi;
6152
+ activeSlide = null;
6153
+ slides = [];
6154
+ slidesMode = 0 /* SLIDES_MODE.SINGLE */;
6155
+ sizeMetrics = {
6156
+ fontSize: "0px",
6157
+ isFullscreen: false,
6158
+ slideOffsetMargin: "0px",
6159
+ xOffset: "0px",
6160
+ yOffset: "0px",
6161
+ };
6162
+ constructor(config) {
6163
+ this.config = config;
6164
+ this.sdkApi = config.sdkApi;
6165
+ this._singleCardSlideWrapper = config.slideWrapper;
6166
+ this._viewport = config.viewport;
6167
+ this._getViewportWidth = config.getViewportWidth;
6168
+ this._getViewportHeight = config.getViewportHeight;
6169
+ this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
6170
+ this._separateUserAndAppPause = config.separateUserAndAppPause;
6171
+ this._useSdkCacheForMultislideMode = config.useSdkCacheForMultislideMode;
6172
+ this.refreshSizes = proxy(this.refreshSizes, this);
6173
+ this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
6174
+ this.refreshSizes();
6175
+ // todo - возможность не создавать slideApi в ctor (это не нужно для multislide mode)
6176
+ // но тогда все методы должны обходить случай когда activeSlide undefined
6177
+ this.activeSlide = new SlideApi$1({
6178
+ slideApiDeps: new SlideApiDepsSingleSlideMode(this.config.sdkApi),
6179
+ slideWrapper: this.config.slideWrapper,
6180
+ viewport: this.config.viewport,
6181
+ userResizeHandler: this.config.userResizeHandler,
6182
+ slideRatio: this.config.slideRatio,
6183
+ isFullscreen: this.config.isFullscreen,
6184
+ getViewportWidth: this.config.getViewportWidth,
6185
+ getViewportHeight: this.config.getViewportHeight,
6186
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6187
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6188
+ root: this.config.root,
6189
+ index: 0,
6190
+ getSdkClientVariables: this.getSdkClientVariables,
6191
+ });
6192
+ this.activeSlide.onUpdateSizeMetrics(this.sizeMetrics);
6193
+ if (SlideApi$1.checkPreloadedInLayoutSlide()) {
6194
+ this.activeSlide.initPreloadedInLayoutSlide(this.config.slideLoadedCb);
6195
+ }
6196
+ this.initListeners();
6197
+ }
6198
+ get state() {
6199
+ // TODO remove usage from web-sdk
6200
+ return this.activeSlide.state;
6201
+ }
6202
+ async destroy() {
6203
+ await this.activeSlide.destroy();
6204
+ await Promise.all(this.slides.map(({ slide }) => {
6205
+ if (slide !== this.activeSlide) {
6206
+ return slide?.destroy();
6207
+ }
6208
+ }));
6209
+ this.destroyListeners();
6210
+ }
6211
+ initListeners() {
6212
+ // @ts-ignore
6213
+ this._viewport.addEventListener("resize", this.refreshSizes);
6214
+ }
6215
+ destroyListeners() {
6216
+ // @ts-ignore
6217
+ this._viewport.removeEventListener("resize", this.refreshSizes);
6218
+ // todo call via activeSlide.refreshSizes
6219
+ }
6220
+ _savedViewportWidth = null;
6221
+ _savedViewportHeight = null;
6222
+ refreshSizes() {
6223
+ const viewportWidth = this._getViewportWidth();
6224
+ const viewportHeight = this._getViewportHeight();
6225
+ if (this._savedViewportWidth === viewportWidth && this._savedViewportHeight === viewportHeight) {
6226
+ return;
6227
+ }
6228
+ this._savedViewportWidth = viewportWidth;
6229
+ this._savedViewportHeight = viewportHeight;
6230
+ const viewportRatio = viewportWidth / viewportHeight;
6231
+ let slideWidth = 0;
6232
+ let slideHeight = 0;
6233
+ // _ratio = 310 / 480,
6234
+ const _ratio = this.config.slideRatio;
6235
+ let _isFullscreen = this.config.isFullscreen;
6236
+ let offset = 0;
6237
+ let xOffset = "0px";
6238
+ // for elements with bottom anchor (absolute position)
6239
+ let yOffset = "0px";
6240
+ // todo - mobile only (or isIos or isAndroid)
6241
+ if (this.sdkApi.isAndroid || this.sdkApi.isIOS) {
6242
+ if (viewportRatio > _ratio) {
6243
+ // disable _isFullscreen if viewport small
6244
+ _isFullscreen = false;
6245
+ }
6246
+ }
6247
+ let slideOffsetMargin = "";
6248
+ if (_isFullscreen) {
6249
+ // более квадратное чем надо (desktop)
6250
+ if (viewportRatio > _ratio) {
6251
+ // fit by height
6252
+ slideHeight = viewportHeight;
6253
+ slideWidth = Math.ceil(slideHeight * _ratio);
6254
+ offset = Math.ceil(slideWidth - viewportWidth) / 2;
6255
+ slideOffsetMargin = "0 " + -offset + "px"; // -8.5
6256
+ xOffset = offset + "px";
6257
+ }
6258
+ else {
6259
+ // fit by width, top and bottom - to offscreen or fill with bg image
6260
+ slideWidth = viewportWidth;
6261
+ slideHeight = Math.ceil(viewportWidth / _ratio);
6262
+ offset = Math.ceil(slideHeight - viewportHeight) / 2;
6263
+ slideOffsetMargin = -1 * offset + "px" + " 0 ";
6264
+ // offset from viewport bottom to StoryBottom plus safe area offset bottom
6265
+ yOffset = `calc(${offset + this._overlappingActionBarHeight}px + env(safe-area-inset-bottom))`;
6266
+ // detect safe area offset
6267
+ }
6268
+ }
6269
+ else {
6270
+ // более квадратное чем надо
6271
+ if (viewportRatio > _ratio) {
6272
+ // fit by width, top and bottom - to offscreen
6273
+ slideWidth = viewportWidth;
6274
+ slideHeight = Math.ceil(viewportWidth / _ratio);
6275
+ offset = Math.ceil(slideHeight - viewportHeight) / 2;
6276
+ slideOffsetMargin = -offset + "px" + " 0 ";
6277
+ yOffset = offset + this._overlappingActionBarHeight + "px";
6278
+ }
6279
+ else {
6280
+ // вьюпорт более вытянутый чем надо
6281
+ // fit by height, sides - to offscreen
6282
+ slideHeight = viewportHeight;
6283
+ slideWidth = Math.ceil(slideHeight * _ratio);
6284
+ offset = Math.ceil(slideWidth - viewportWidth) / 2;
6285
+ slideOffsetMargin = "0 " + -offset + "px"; // -8.5
6286
+ xOffset = offset + "px";
6287
+ }
6288
+ }
6289
+ const fontSizeNumber = slideWidth / 20;
6290
+ const fontSize = `${fontSizeNumber}px`;
6291
+ const sizeMetrics = { fontSize, xOffset, yOffset, isFullscreen: _isFullscreen, slideOffsetMargin };
6292
+ this.sizeMetrics = sizeMetrics;
6293
+ this.activeSlide?.onUpdateSizeMetrics(sizeMetrics);
6294
+ this.slides.forEach(({ slide }) => {
6295
+ if (slide !== this.activeSlide) {
6296
+ slide?.onUpdateSizeMetrics(sizeMetrics);
6297
+ }
6298
+ });
6299
+ this.slider?.onUpdateSizeMetrics(sizeMetrics);
6300
+ if (this.config.userResizeHandler != null) {
6301
+ this.config.userResizeHandler({ viewportWidth, viewportHeight, fontSize: fontSizeNumber });
6302
+ }
6303
+ }
6304
+ async showSlide(html) {
6305
+ this.slidesMode = 0 /* SLIDES_MODE.SINGLE */;
6306
+ if (this.activeSlide == null) {
6307
+ this.activeSlide = new SlideApi$1({
6308
+ slideApiDeps: new SlideApiDepsSingleSlideMode(this.config.sdkApi),
6309
+ slideWrapper: this.config.slideWrapper,
6310
+ viewport: this.config.viewport,
6311
+ userResizeHandler: this.config.userResizeHandler,
6312
+ slideRatio: this.config.slideRatio,
6313
+ isFullscreen: this.config.isFullscreen,
6314
+ getViewportWidth: this.config.getViewportWidth,
6315
+ getViewportHeight: this.config.getViewportHeight,
6316
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6317
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6318
+ root: this.config.root,
6319
+ // refreshSizes: this.refreshSizes,
6320
+ index: 0,
6321
+ getSdkClientVariables: this.getSdkClientVariables,
6322
+ });
6323
+ this.activeSlide.onUpdateSizeMetrics(this.sizeMetrics);
6324
+ }
6325
+ return this.activeSlide.showSlide(html);
6326
+ }
6327
+ slider = null;
6328
+ async showSlides(slides, cardAppearance, index = 0) {
6329
+ this.slidesMode = 1 /* SLIDES_MODE.MULTIPLE */;
6330
+ this.sdkApi.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */);
6331
+ slides.forEach((content, index) => {
6332
+ if (this.slides[index] == null) {
6333
+ const item = { content, resourcesReadyPromise: null };
6334
+ if (this._useSdkCacheForMultislideMode) {
6335
+ item.resourcesReadyPromise = new Promise((resolve, reject) => {
6336
+ item.resourcesReadyPromisesResolver = { resolve, reject };
6337
+ });
6338
+ }
6339
+ else {
6340
+ item.resourcesReadyPromise = Promise.resolve();
6341
+ }
6342
+ this.slides[index] = item;
6343
+ }
6344
+ else {
6345
+ // for case when sdk call setSlideInCacheStatus before showSlides and for slideReloading (after loading error)
6346
+ this.slides[index].content = content;
6347
+ if (this.slides[index].resourcesReadyPromise == null) {
6348
+ if (this._useSdkCacheForMultislideMode) {
6349
+ this.slides[index].resourcesReadyPromise = new Promise((resolve, reject) => {
6350
+ this.slides[index].resourcesReadyPromisesResolver = { resolve, reject };
6351
+ });
6352
+ }
6353
+ else {
6354
+ this.slides[index].resourcesReadyPromise = Promise.resolve();
6355
+ }
6356
+ }
6357
+ }
6358
+ });
6359
+ const onBeforeShowSlide = (slideElement, index) => {
6360
+ if (this.slides[index].slide == null) {
6361
+ const slideApi = new SlideApi$1({
6362
+ slideApiDeps: new SlideApiDepsMultiSlideMode(this.config.sdkApi, this.slider),
6363
+ slideWrapper: slideElement,
6364
+ viewport: this.config.viewport,
6365
+ userResizeHandler: this.config.userResizeHandler,
6366
+ slideRatio: this.config.slideRatio,
6367
+ isFullscreen: this.config.isFullscreen,
6368
+ getViewportWidth: this.config.getViewportWidth,
6369
+ getViewportHeight: this.config.getViewportHeight,
6370
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6371
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6372
+ root: this.config.root,
6373
+ index,
6374
+ getSdkClientVariables: this.getSdkClientVariables,
6375
+ });
6376
+ slideApi.onUpdateSizeMetrics(this.sizeMetrics);
6377
+ this.slides[index].slide = slideApi;
6378
+ // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6379
+ // пока вызов убран из за того что init жестко завязан на single slide mode
6380
+ this.activeSlide = this.slides[index].slide;
6381
+ return this.slides[index].slide.showSlide().then(_ => ({ moveToIndex: index }));
6382
+ }
6383
+ this.activeSlide = this.slides[index].slide;
6384
+ // TODO handle moveToIndex
6385
+ // return resolve or reject with reason
6386
+ // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6387
+ // пока вызов убран из за того что init жестко завязан на single slide mode
6388
+ // return this.slides[index].slide.showSlide().then(_ => ({ moveToIndex: index }));
6389
+ return Promise.resolve({ moveToIndex: index });
6390
+ // вызываем здесь cardLoadingState - loading
6391
+ // новый cb - onSlideShowError - там вызов cardLoadingState error - через cardLoadingStateManager
6392
+ // в onShowSlide- cardLoadingState load done
6393
+ // внутри слайдера - обрабатываем moveToIndex
6394
+ };
6395
+ const onBeforeLoadSlide = index => {
6396
+ this.sdkApi.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */);
6397
+ };
6398
+ const onSlideLoadingError = (index, reason) => {
6399
+ this.sdkApi.onCardLoadingStateChange(2 /* CARD_LOADING_STATE.LOADING_ERROR */, reason);
6400
+ };
6401
+ const onShowSlide = (slide, index) => {
6402
+ this.sdkApi.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */);
6403
+ this.sdkApi.emitEvent("showSlide", { cardId: this.slides[index]?.slide?.slide.cardId ?? 0, index });
6404
+ // if (index === 0) {
6405
+ // this.activeSlide = slideApi;
6406
+ // }
6407
+ // const { result, cardId, slideIndex, reason } = await slideApi.showSlide();
6408
+ // if (index === 0) {
6409
+ // if (result) {
6410
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADED);
6411
+ // this.sdkApi.emitEvent("showSlide", { cardId: this.activeSlide.slide.cardId, index });
6412
+ // } else {
6413
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADING, reason);
6414
+ // }
6415
+ // }
6416
+ //
6417
+ // onShowActiveCardResolver({ cardId, slideIndex });
6418
+ };
6419
+ const onSlideLeft = (slide, index) => {
6420
+ this.sdkApi.emitEvent("slideLeft", { cardId: this.slides[index]?.slide?.slide.cardId ?? 0, index });
6421
+ };
6422
+ const slideRender = ({ content, canMediaMount }, index, onBeforeShowSlideDuringMounting) => {
6423
+ const slideWrapper = document.createElement("div");
6424
+ slideWrapper.classList.add("narrative-slide-wrapper");
6425
+ slideWrapper.classList.add("stories-viewer");
6426
+ const slideOffset = document.createElement("div");
6427
+ slideOffset.classList.add("narrative-slide-offset");
6428
+ const slideBoxPrerender = document.createElement("div");
6429
+ slideBoxPrerender.classList.add("narrative-slide-box");
6430
+ slideBoxPrerender.classList.add("narrative-slide-box-prerender");
6431
+ const slideBoxRendered = document.createElement("div");
6432
+ slideBoxRendered.classList.add("narrative-slide-box");
6433
+ slideBoxRendered.classList.add("narrative-slide-box-rendered");
6434
+ const style = document.createElement("style");
6435
+ if (this.config.nonce != null) {
6436
+ style.nonce = this.config.nonce;
6437
+ }
6438
+ const paddingTop = `${String(100 / this.config.slideRatio)}%`;
6439
+ // .narrative-slide-box {
6440
+ // padding: <?= $slideRatioPadding ?> 0 0 0;
6441
+ // }
6442
+ // style.sheet?.insertRule(`.narrative-slide-box {padding: ${paddingTop} 0 0 0;`);
6443
+ slideBoxRendered.style.padding = `${paddingTop} 0 0 0`;
6444
+ slideBoxPrerender.style.padding = `${paddingTop} 0 0 0`;
6445
+ // slideBoxPrerender.innerHTML = card;
6446
+ // extract and mount solid or gradient bg color (w/o bg image)
6447
+ onBeforeShowSlideDuringMounting.then(callback => {
6448
+ callback(canMediaMount.then(() => {
6449
+ // mount slide media content (after cache is ready event)
6450
+ slideBoxPrerender.innerHTML = content;
6451
+ // create slideApi
6452
+ // call init, init should return moveToIndex
6453
+ return onBeforeShowSlide(slideWrapper, index);
6454
+ }));
6455
+ });
6456
+ slideOffset.appendChild(slideBoxPrerender);
6457
+ slideOffset.appendChild(slideBoxRendered);
6458
+ slideWrapper.appendChild(slideOffset);
6459
+ slideWrapper.appendChild(style);
6460
+ return slideWrapper;
6461
+ };
6462
+ new Promise(resolve => {
6463
+ });
6464
+ // onContentMounted
6465
+ const onSlideMounted = async (slideElement, index) => {
6466
+ // if (index === 0) {
6467
+ // this.activeSlide = slideApi;
6468
+ // }
6469
+ //
6470
+ // const { result, cardId, slideIndex, reason } = await slideApi.showSlide();
6471
+ //
6472
+ //
6473
+ // if (index === 0) {
6474
+ // if (result) {
6475
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADED);
6476
+ // this.sdkApi.emitEvent("showSlide", { cardId: this.activeSlide.slide.cardId, index });
6477
+ // } else {
6478
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADING, reason);
6479
+ // }
6480
+ // }
6481
+ //
6482
+ // onShowActiveCardResolver({ cardId, slideIndex });
6483
+ };
6484
+ if (this.slider != null) {
6485
+ this.slider.destroy();
6486
+ }
6487
+ this.slider = new Slider({
6488
+ root: this.config.root,
6489
+ slides: this.slides.map(({ content, resourcesReadyPromise }) => ({
6490
+ content,
6491
+ canMediaMount: resourcesReadyPromise,
6492
+ })),
6493
+ nonce: this.config.nonce,
6494
+ slideRender,
6495
+ onSlideMounted,
6496
+ onBeforeShowSlide,
6497
+ onBeforeLoadSlide,
6498
+ onSlideLoadingError,
6499
+ onShowSlide,
6500
+ onSlideLeft,
6501
+ getLayoutDirection: () => this.layoutDirection,
6502
+ onSlideTimerEnd: () => this.activeSlide.slideTimerEnd(),
6503
+ onSlideStart: () => {
6504
+ this.sdkApi.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */);
6505
+ return this.activeSlide.slideStart({ muted: true });
6506
+ },
6507
+ onSlideStop: () => this.activeSlide.slideStop({ prepareForRestart: 1 /* ON_SLIDE_STOP_PREPARE_FOR_RESTART.PREPARE */ }),
6508
+ onSlideDataWaiting: () => this.sdkApi.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */),
6509
+ onSlideDataResume: () => this.sdkApi.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */),
6510
+ onSlideDataError: () => this.sdkApi.onCardLoadingStateChange(2 /* CARD_LOADING_STATE.LOADING_ERROR */),
6511
+ });
6512
+ await this.slider.showByIndex(index);
6513
+ // return await onShowActiveCard;
6514
+ }
6515
+ handleBackpress() {
6516
+ this.activeSlide.handleBackpress();
6517
+ }
6518
+ get layoutService() {
6519
+ return container.get({ identifier: "LayoutService" });
6520
+ }
6521
+ getLocalData() {
6522
+ return this.sdkApi.getCardLocalData();
6523
+ }
6524
+ async slideStart(config) {
6525
+ return this.activeSlide.slideStart(config);
6526
+ }
6527
+ async slideRestart(config) {
6528
+ return this.activeSlide.slideRestart(config);
6529
+ }
6530
+ async slideUserPause() {
6531
+ return this.activeSlide.slideUserPause();
6532
+ }
6533
+ async slideUserResume() {
6534
+ return this.activeSlide.slideUserResume();
6535
+ }
6536
+ /**
6537
+ * Call on app gone background
6538
+ */
6539
+ async slideAppPause() {
6540
+ return this.activeSlide.slideAppPause();
6541
+ }
6542
+ /**
6543
+ * Call on app gone foreground after a background
6544
+ */
6545
+ async slideAppResume() {
6546
+ return this.activeSlide.slideAppResume();
6547
+ }
6548
+ async slideStop(options) {
6549
+ return this.activeSlide.slideStop(options);
6550
+ }
6551
+ slideTimerEnd() {
6552
+ this.activeSlide.slideTimerEnd();
6553
+ }
6554
+ enableAudio() {
6555
+ this.activeSlide.enableAudio();
6556
+ }
6557
+ disableAudio() {
6558
+ this.activeSlide.disableAudio();
6559
+ }
6560
+ get isStopped() {
6561
+ return this.activeSlide.isStopped;
6562
+ }
6563
+ afterStartInitQueuePush(cb) {
6564
+ return this.activeSlide.afterStartInitQueuePush(cb);
6565
+ }
6566
+ afterAppResumeQueuePush(cb) {
6567
+ return this.activeSlide.afterAppResumeQueuePush(cb);
6568
+ }
6569
+ get activeLayer() {
6570
+ return this.activeSlide.slide.activeLayer;
6571
+ }
6572
+ get slide() {
6573
+ return this.activeSlide.slide;
6574
+ }
6575
+ showLayer(index) {
6576
+ this.activeSlide.showLayer(index);
6577
+ }
6578
+ slideClickHandler(targetElement, navigationDirection) {
6579
+ const result = this.activeSlide.slideClickHandler(targetElement, navigationDirection);
6580
+ // todo make via strategy pattern, singleSlide and multiSlide impl
6581
+ if (this.slidesMode === 1 /* SLIDES_MODE.MULTIPLE */ && result.canClickNext) {
6582
+ result.canClickNext = false; // handle nav click via CardsSlider, not via SDK
6583
+ const currentIndex = this.activeSlide.index;
6584
+ let index = navigationDirection === "forward" ? currentIndex + 1 : currentIndex - 1;
6585
+ if (index >= this.slides.length) {
6586
+ index = 0;
6587
+ }
6588
+ else if (index < 0) {
6589
+ index = this.slides.length - 1;
6590
+ }
6591
+ this.slider.showByIndex(index).then(index => {
6592
+ if (currentIndex === index)
6593
+ return;
6594
+ this.activeSlide = this.slides[index].slide;
6595
+ });
6596
+ }
6597
+ return result;
6598
+ }
6599
+ slideSwipeUpHandler() {
6600
+ return this.activeSlide.slideSwipeUpHandler();
6601
+ }
6602
+ setTextInputResult(id, text) {
6603
+ this.activeSlide.setTextInputResult(id, text);
6604
+ }
6605
+ setShareComplete(id, isSuccess) {
6606
+ this.activeSlide.setShareComplete(id, isSuccess);
6607
+ }
6608
+ setWidgetGoodsComplete(elementId) {
6609
+ this.activeSlide.setWidgetGoodsComplete(elementId);
6610
+ }
6611
+ _sdkClientVariables = {};
6612
+ getSdkClientVariables() {
6613
+ return this._sdkClientVariables;
6614
+ }
6615
+ setSdkClientVariables(variables) {
6616
+ this._sdkClientVariables = variables;
6617
+ }
6618
+ setSlideInCacheStatus(index, status) {
6619
+ if (this.slides[index] != null && this.slides[index].resourcesReadyPromisesResolver != null) {
6620
+ if (status === 1 /* SLIDE_IN_CACHE_STATUS.SUCCESS */) {
6621
+ this.slides[index].resourcesReadyPromisesResolver.resolve();
6622
+ }
6623
+ else {
6624
+ this.slides[index].resourcesReadyPromisesResolver.reject();
6625
+ }
6626
+ }
6627
+ else {
6628
+ // for call setSlideInCacheStatus before showSlides
6629
+ this.slides[index] = {
6630
+ content: "",
6631
+ resourcesReadyPromise: Promise.resolve(),
6632
+ };
6633
+ }
6634
+ }
6635
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
6636
+ sdkApi: SDKApi;
6637
+ slideWrapper: HTMLElement;
6638
+ viewport: Window;
6639
+ userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
6640
+ slideRatio: number;
6641
+ isFullscreen: boolean;
6642
+ slideLoadedCb?: (data: { cardId: number; slideIndex: number; result: boolean; reason?: string }) => void;
6643
+ getViewportWidth: () => number;
6644
+ getViewportHeight: () => number;
6645
+ overlappingActionBarHeight?: number;
6646
+ separateUserAndAppPause: boolean;
6647
+ root: HTMLElement;
6648
+ nonce?: string;
6649
+ useSdkCacheForMultislideMode: boolean;
6650
+ }`]; }
6651
+ }
6652
+
5069
6653
  const slideApiPeerDeps = {};
5070
6654
  const createSlideWrapper = ({ slideBoxRatio, nonce }) => {
5071
6655
  const slideWrapper = document.createElement("div");
@@ -5096,7 +6680,7 @@ const createSlideWrapper = ({ slideBoxRatio, nonce }) => {
5096
6680
  slideWrapper.appendChild(style);
5097
6681
  return slideWrapper;
5098
6682
  };
5099
- class SlideApi extends SlideApi$1 {
6683
+ class SlideApi extends CardApi {
5100
6684
  root;
5101
6685
  slideWrapper;
5102
6686
  constructor(_sdkInterface, config) {
@@ -5114,6 +6698,9 @@ class SlideApi extends SlideApi$1 {
5114
6698
  getViewportHeight: () => slideWrapper.clientHeight,
5115
6699
  overlappingActionBarHeight: config.overlappingActionBarHeight,
5116
6700
  separateUserAndAppPause: true,
6701
+ root: config.root,
6702
+ nonce: config.nonce,
6703
+ useSdkCacheForMultislideMode: config.useSdkCacheForMultislideMode,
5117
6704
  });
5118
6705
  this.root = config.root;
5119
6706
  this.slideWrapper = slideWrapper;
@@ -5134,6 +6721,7 @@ class SlideApi extends SlideApi$1 {
5134
6721
  userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5135
6722
  VODPlayer?: typeof VODPlayer;
5136
6723
  overlappingActionBarHeight?: number;
6724
+ useSdkCacheForMultislideMode: boolean;
5137
6725
  }`]; }
5138
6726
  }
5139
6727
 
@@ -14563,7 +16151,7 @@ class WidgetBase {
14563
16151
  this.submitButtonView = this.submitButtonAnimatedView.querySelector(".submit-button-view");
14564
16152
  }
14565
16153
  }
14566
- this.savedData = this.widgetDeps.sdkApi.getCardServerData(this.cardId);
16154
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
14567
16155
  this.localData = extend({}, this.savedData ?? {}, this.options.localData ?? {});
14568
16156
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
14569
16157
  ++WidgetBase.widgetIndex;
@@ -14585,7 +16173,7 @@ class WidgetBase {
14585
16173
  * @param localData
14586
16174
  */
14587
16175
  onRefreshUserData(localData) {
14588
- this.savedData = this.widgetDeps.sdkApi.getCardServerData(this.cardId);
16176
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
14589
16177
  this.localData = extend({}, this.savedData ?? {}, localData);
14590
16178
  }
14591
16179
  onStart() {
@@ -14635,13 +16223,13 @@ class WidgetBase {
14635
16223
  static get widgetsService() {
14636
16224
  return container.get({ identifier: "WidgetsService" });
14637
16225
  }
14638
- static getLocalData(sdkApi) {
14639
- return sdkApi.getCardLocalData();
16226
+ static getLocalData(slideApiDeps) {
16227
+ return slideApiDeps.getCardLocalData();
14640
16228
  }
14641
16229
  getLocalData() {
14642
- return this.constructor.getLocalData(this.widgetDeps.sdkApi);
16230
+ return this.constructor.getLocalData(this.widgetDeps.slideApiDeps);
14643
16231
  }
14644
- static setLocalData(sdkApi, keyValue, sendToServer, syncWithRuntimeLocalData) {
16232
+ static setLocalData(slideApiDeps, keyValue, sendToServer, syncWithRuntimeLocalData) {
14645
16233
  // push json object as string
14646
16234
  if (sendToServer === undefined) {
14647
16235
  sendToServer = true;
@@ -14656,20 +16244,20 @@ class WidgetBase {
14656
16244
  syncWithRuntimeLocalData = Boolean(syncWithRuntimeLocalData);
14657
16245
  }
14658
16246
  if (syncWithRuntimeLocalData) {
14659
- this.getLocalData(sdkApi).then(localData => {
16247
+ this.getLocalData(slideApiDeps).then(localData => {
14660
16248
  // 1 - old values, 2 - new values
14661
16249
  keyValue = extend({}, localData, keyValue);
14662
16250
  // todo make async via promise or async
14663
- sdkApi.setCardLocalData(keyValue, sendToServer);
16251
+ slideApiDeps.setCardLocalData(keyValue, sendToServer);
14664
16252
  });
14665
16253
  }
14666
16254
  else {
14667
16255
  // todo make async via promise or async
14668
- sdkApi.setCardLocalData(keyValue, sendToServer);
16256
+ slideApiDeps.setCardLocalData(keyValue, sendToServer);
14669
16257
  }
14670
16258
  }
14671
16259
  setLocalData(keyValue, sendToServer, syncWithRuntimeLocalData) {
14672
- return this.constructor.setLocalData(this.widgetDeps.sdkApi, keyValue, sendToServer, syncWithRuntimeLocalData);
16260
+ return this.constructor.setLocalData(this.widgetDeps.slideApiDeps, keyValue, sendToServer, syncWithRuntimeLocalData);
14673
16261
  }
14674
16262
  get statisticEventBaseFieldsShortForm() {
14675
16263
  return WidgetBase.getStatisticEventBaseFieldsShortForm(this.cardId, this.cardType, this.slideIndex);
@@ -14700,11 +16288,11 @@ class WidgetBase {
14700
16288
  }
14701
16289
  return data;
14702
16290
  }
14703
- static sendStatisticEventToApp(sdkApi, name, data, devPayload, options) {
14704
- sendStatisticEventToApp(sdkApi, name, data, devPayload, options);
16291
+ static sendStatisticEventToApp(slideApiDeps, name, data, devPayload, options) {
16292
+ sendStatisticEventToApp(slideApiDeps, name, data, devPayload, options);
14705
16293
  }
14706
16294
  sendStatisticEventToApp(name, data, devPayload, options) {
14707
- this.constructor.sendStatisticEventToApp(this.widgetDeps.sdkApi, name, data, devPayload, options);
16295
+ this.constructor.sendStatisticEventToApp(this.widgetDeps.slideApiDeps, name, data, devPayload, options);
14708
16296
  }
14709
16297
  onWidgetComplete() {
14710
16298
  this._widgetCallbacks.onWidgetComplete(this.cardId, this.slideIndex);
@@ -14716,14 +16304,14 @@ class WidgetBase {
14716
16304
  this._widgetCallbacks.onWidgetRequireResumeUI(this.cardId, this.slideIndex);
14717
16305
  }
14718
16306
  _showLayer(layers, selectIndex, withStatEvent = false) {
14719
- if (this.widgetDeps.sdkApi.isExistsShowLayer()) {
14720
- this.widgetDeps.sdkApi.showLayer(selectIndex);
16307
+ if (this.widgetDeps.slideApiDeps.isExistsShowLayer()) {
16308
+ this.widgetDeps.slideApiDeps.showLayer(selectIndex);
14721
16309
  }
14722
16310
  else {
14723
16311
  forEach(layers, (layer, index) => {
14724
16312
  if (index === selectIndex) {
14725
16313
  layer.classList.remove("hidden");
14726
- this.widgetDeps.sdkApi.cardAnimation?.start(layer);
16314
+ this.widgetDeps.slideApiDeps.cardAnimation?.start(layer);
14727
16315
  }
14728
16316
  else {
14729
16317
  layer.classList.add("hidden");
@@ -14873,7 +16461,7 @@ class WidgetBarcode extends WidgetBase {
14873
16461
  }
14874
16462
  catch (e) {
14875
16463
  if (this.msgBarcodeRenderError) {
14876
- this.widgetDeps.sdkApi.showToast(this.msgBarcodeRenderError);
16464
+ this.widgetDeps.slideApiDeps.showToast(this.msgBarcodeRenderError);
14877
16465
  }
14878
16466
  console.error(e);
14879
16467
  }
@@ -14936,7 +16524,7 @@ class WidgetBarcode extends WidgetBase {
14936
16524
  };
14937
16525
  const profileKey = "fetch-promo-code";
14938
16526
  Promise.all([
14939
- this.widgetDeps.sdkApi.sendApiRequest(path, "POST", null, headers, null, profileKey),
16527
+ this.widgetDeps.slideApiDeps.sendApiRequest(path, "POST", null, headers, null, profileKey),
14940
16528
  new Promise(function (t, e) {
14941
16529
  return setTimeout(t, 300);
14942
16530
  }),
@@ -14964,14 +16552,14 @@ class WidgetBarcode extends WidgetBase {
14964
16552
  this.setLocalData(this.localData, true);
14965
16553
  }
14966
16554
  else {
14967
- this.msgNoMoreCodes && this.widgetDeps.sdkApi.showToast(this.msgNoMoreCodes);
16555
+ this.msgNoMoreCodes && this.widgetDeps.slideApiDeps.showToast(this.msgNoMoreCodes);
14968
16556
  }
14969
16557
  }
14970
16558
  else if (status === 12163 || status === 12002) {
14971
- this.msgNetworkError && this.widgetDeps.sdkApi.showToast(this.msgNetworkError);
16559
+ this.msgNetworkError && this.widgetDeps.slideApiDeps.showToast(this.msgNetworkError);
14972
16560
  }
14973
16561
  else {
14974
- this.msgServiceError && this.widgetDeps.sdkApi.showToast(this.msgServiceError);
16562
+ this.msgServiceError && this.widgetDeps.slideApiDeps.showToast(this.msgServiceError);
14975
16563
  }
14976
16564
  if (!success) {
14977
16565
  this.state = 3;
@@ -15017,13 +16605,13 @@ class WidgetBarcode extends WidgetBase {
15017
16605
  }
15018
16606
  });
15019
16607
  if (this.copiedText) {
15020
- this.widgetDeps.sdkApi.showToast(this.copiedText);
16608
+ this.widgetDeps.slideApiDeps.showToast(this.copiedText);
15021
16609
  }
15022
16610
  }
15023
16611
  copyToClipboard(element) {
15024
16612
  this._select();
15025
16613
  const textValue = this.clipboardTarget ?? "";
15026
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
16614
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
15027
16615
  this.completeWidget();
15028
16616
  this._statEventCopyClick(textValue);
15029
16617
  }
@@ -15195,7 +16783,7 @@ class WidgetCopy extends WidgetBase {
15195
16783
  };
15196
16784
  const profileKey = "fetch-promo-code";
15197
16785
  Promise.all([
15198
- this.widgetDeps.sdkApi.sendApiRequest(path, "POST", null, headers, null, profileKey),
16786
+ this.widgetDeps.slideApiDeps.sendApiRequest(path, "POST", null, headers, null, profileKey),
15199
16787
  new Promise(function (t, e) {
15200
16788
  return setTimeout(t, 300);
15201
16789
  }),
@@ -15222,14 +16810,14 @@ class WidgetCopy extends WidgetBase {
15222
16810
  this.setLocalData(this.localData, true);
15223
16811
  }
15224
16812
  else {
15225
- this.msgNoMoreCodes && this.widgetDeps.sdkApi.showToast(this.msgNoMoreCodes);
16813
+ this.msgNoMoreCodes && this.widgetDeps.slideApiDeps.showToast(this.msgNoMoreCodes);
15226
16814
  }
15227
16815
  }
15228
16816
  else if (status === 12163 || status === 12002) {
15229
- this.msgNetworkError && this.widgetDeps.sdkApi.showToast(this.msgNetworkError);
16817
+ this.msgNetworkError && this.widgetDeps.slideApiDeps.showToast(this.msgNetworkError);
15230
16818
  }
15231
16819
  else {
15232
- this.msgServiceError && this.widgetDeps.sdkApi.showToast(this.msgServiceError);
16820
+ this.msgServiceError && this.widgetDeps.slideApiDeps.showToast(this.msgServiceError);
15233
16821
  }
15234
16822
  if (!success) {
15235
16823
  this.state = 3;
@@ -15281,7 +16869,7 @@ class WidgetCopy extends WidgetBase {
15281
16869
  copyToClipboard(element) {
15282
16870
  this._select();
15283
16871
  const textValue = this.clipboardTarget ?? "";
15284
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
16872
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
15285
16873
  this.completeWidget();
15286
16874
  this._statEventCopyClick(textValue);
15287
16875
  }
@@ -15423,12 +17011,12 @@ class WidgetDataInput extends WidgetBase {
15423
17011
  return true;
15424
17012
  }
15425
17013
  this.elementRect = this.element.getBoundingClientRect();
15426
- if (this.widgetDeps.sdkApi.isAndroid || this.widgetDeps.sdkApi.isWeb) {
17014
+ if (this.widgetDeps.slideApiDeps.isAndroid || this.widgetDeps.slideApiDeps.isWeb) {
15427
17015
  this.slide.classList.add("blured");
15428
17016
  }
15429
17017
  this.slide.classList.add("data-input-editing");
15430
17018
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
15431
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17019
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
15432
17020
  const data = JSON.parse(dataString);
15433
17021
  data.size = getElementBounding(this.env, this.elementRect);
15434
17022
  if (!this.disableTimer) {
@@ -15449,7 +17037,7 @@ class WidgetDataInput extends WidgetBase {
15449
17037
  catch (e) {
15450
17038
  console.error(e);
15451
17039
  }
15452
- this.widgetDeps.sdkApi.showCardTextInput(this.id, data);
17040
+ this.widgetDeps.slideApiDeps.showCardTextInput(this.id, data);
15453
17041
  this._statEventFocusIn();
15454
17042
  }
15455
17043
  return false;
@@ -15748,7 +17336,7 @@ class WidgetDateCountdown extends WidgetBase {
15748
17336
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Partial`, `WidgetCallbacks`, `WidgetDeps`]; }
15749
17337
  }
15750
17338
 
15751
- const displaySlide = function (slides, localData, sdkApi) {
17339
+ const displaySlide = function (slides, localData, slideApiDeps) {
15752
17340
  const multiSlideItem = slides[0];
15753
17341
  let cardId = undefined;
15754
17342
  let cardType = 1 /* CARD_TYPE.STORY */;
@@ -15813,7 +17401,7 @@ const displaySlide = function (slides, localData, sdkApi) {
15813
17401
  if (slides.length > 0) {
15814
17402
  var slide = slides[0];
15815
17403
  slide.classList.remove("hidden");
15816
- sdkApi.cardAnimation?.start(slide);
17404
+ slideApiDeps.cardAnimation?.start(slide);
15817
17405
  return;
15818
17406
  }
15819
17407
  score = 0;
@@ -15842,19 +17430,19 @@ const displaySlide = function (slides, localData, sdkApi) {
15842
17430
  if (index === selectedIndex) {
15843
17431
  slide.classList.remove("hidden");
15844
17432
  undefinedResult = false;
15845
- sdkApi.cardAnimation?.start(slide);
15846
- _sendStatEvent(sdkApi, cardId, cardType, slideIndex, selectedIndex);
17433
+ slideApiDeps.cardAnimation?.start(slide);
17434
+ _sendStatEvent(slideApiDeps, cardId, cardType, slideIndex, selectedIndex);
15847
17435
  }
15848
17436
  });
15849
17437
  }
15850
17438
  if (undefinedResult) {
15851
17439
  console.warn("undefinedResult layer index");
15852
- sdkApi.showLayer(0);
17440
+ slideApiDeps.showLayer(0);
15853
17441
  }
15854
17442
  };
15855
- const _sendStatEvent = function (sdkApi, cardId, cardType, slideIndex, layerIndex) {
17443
+ const _sendStatEvent = function (slideApiDeps, cardId, cardType, slideIndex, layerIndex) {
15856
17444
  try {
15857
- WidgetBase.sendStatisticEventToApp(sdkApi, "layout-show", {
17445
+ WidgetBase.sendStatisticEventToApp(slideApiDeps, "layout-show", {
15858
17446
  ...WidgetBase.getStatisticEventBaseFieldsShortForm(cardId, cardType, slideIndex),
15859
17447
  li: layerIndex,
15860
17448
  }, {
@@ -15869,7 +17457,7 @@ const _sendStatEvent = function (sdkApi, cardId, cardType, slideIndex, layerInde
15869
17457
  class WidgetMultiSlide {
15870
17458
  static api = {
15871
17459
  init: function (slides, localData, widgetDeps) {
15872
- displaySlide(slides, localData, widgetDeps.sdkApi);
17460
+ displaySlide(slides, localData, widgetDeps.slideApiDeps);
15873
17461
  },
15874
17462
  };
15875
17463
  }
@@ -16037,13 +17625,13 @@ class WidgetPoll extends WidgetBase {
16037
17625
  if (index !== -1) {
16038
17626
  this.elementRect = this.element.getBoundingClientRect();
16039
17627
  if (this.getUseResponseOnFirstButton && index === 0) {
16040
- if (this.widgetDeps.sdkApi.isAndroid) {
17628
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
16041
17629
  this.slide.classList.add("blured");
16042
17630
  }
16043
17631
  this.slide.classList.add("data-input-editing");
16044
17632
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
16045
17633
  this.selectedVariant = index;
16046
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17634
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
16047
17635
  const data = JSON.parse(dataString);
16048
17636
  data.size = getElementBounding(this.env, this.elementRect);
16049
17637
  if (!this.disableTimer) {
@@ -16065,19 +17653,19 @@ class WidgetPoll extends WidgetBase {
16065
17653
  catch (e) {
16066
17654
  console.error(e);
16067
17655
  }
16068
- this.widgetDeps.sdkApi.showCardTextInput(`${this.id}_first`, data);
17656
+ this.widgetDeps.slideApiDeps.showCardTextInput(`${this.id}_first`, data);
16069
17657
  }
16070
17658
  this._statEventPollAnswer();
16071
17659
  return false;
16072
17660
  }
16073
17661
  else if (this.getUseResponseOnSecondButton && index === 1) {
16074
- if (this.widgetDeps.sdkApi.isAndroid) {
17662
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
16075
17663
  this.slide.classList.add("blured");
16076
17664
  }
16077
17665
  this.slide.classList.add("data-input-editing");
16078
17666
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
16079
17667
  this.selectedVariant = index;
16080
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17668
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
16081
17669
  const data = JSON.parse(dataString);
16082
17670
  data.size = getElementBounding(this.env, this.elementRect);
16083
17671
  if (!this.disableTimer) {
@@ -16098,7 +17686,7 @@ class WidgetPoll extends WidgetBase {
16098
17686
  catch (e) {
16099
17687
  console.error(e);
16100
17688
  }
16101
- this.widgetDeps.sdkApi.showCardTextInput(`${this.id}_second`, data);
17689
+ this.widgetDeps.slideApiDeps.showCardTextInput(`${this.id}_second`, data);
16102
17690
  }
16103
17691
  this._statEventPollAnswer();
16104
17692
  return false;
@@ -16141,7 +17729,7 @@ class WidgetPoll extends WidgetBase {
16141
17729
  displayPercents(selectedVariantIndex, filled = false) {
16142
17730
  let pollAllocation = [0, 0];
16143
17731
  let pollAllocationTs = undefined;
16144
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
17732
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
16145
17733
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
16146
17734
  pollAllocation = sharedData[this.elementId];
16147
17735
  if (isObject$1(sharedData[this.elementId])) {
@@ -17322,7 +18910,7 @@ class WidgetProducts extends WidgetBase {
17322
18910
  };
17323
18911
  const profileKey = "fetch-products";
17324
18912
  try {
17325
- const response = await this.widgetDeps.sdkApi.sendApiRequest(path, "GET", null, headers, null, profileKey);
18913
+ const response = await this.widgetDeps.slideApiDeps.sendApiRequest(path, "GET", null, headers, null, profileKey);
17326
18914
  // console.log({response});
17327
18915
  const status = response.status;
17328
18916
  if (status === 200 || status === 201) {
@@ -17448,15 +19036,15 @@ class WidgetProducts extends WidgetBase {
17448
19036
  this.isOpen = true;
17449
19037
  // prevent next slide navigation gesture
17450
19038
  this.isClickCapturedByWidget = true;
17451
- this.widgetDeps.sdkApi.disableHorizontalSwipeGesture();
17452
- this.widgetDeps.sdkApi.disableVerticalSwipeGesture();
17453
- this.widgetDeps.sdkApi.disableBackpress();
19039
+ this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
19040
+ this.widgetDeps.slideApiDeps.disableVerticalSwipeGesture();
19041
+ this.widgetDeps.slideApiDeps.disableBackpress();
17454
19042
  this._statEventWidgetOpen(this.currentModels);
17455
19043
  this.initSwipeGestureDetector();
17456
19044
  }
17457
19045
  else {
17458
19046
  if (result.message) {
17459
- this.widgetDeps.sdkApi.showToast(result.message);
19047
+ this.widgetDeps.slideApiDeps.showToast(result.message);
17460
19048
  }
17461
19049
  }
17462
19050
  this.element.classList.remove("loader");
@@ -17468,13 +19056,13 @@ class WidgetProducts extends WidgetBase {
17468
19056
  this.productsView?.classList.add("ias-products-container-view--hidden");
17469
19057
  this.element.classList.remove("hidden");
17470
19058
  this.isClickCapturedByWidget = false;
17471
- this.widgetDeps.sdkApi.enableHorizontalSwipeGesture();
19059
+ this.widgetDeps.slideApiDeps.enableHorizontalSwipeGesture();
17472
19060
  if (this.swipeGestureDetector != null) {
17473
19061
  this.swipeGestureDetector.destroy();
17474
19062
  this.swipeGestureDetector = null;
17475
19063
  }
17476
- this.widgetDeps.sdkApi.enableVerticalSwipeGesture();
17477
- this.widgetDeps.sdkApi.enableBackpress();
19064
+ this.widgetDeps.slideApiDeps.enableVerticalSwipeGesture();
19065
+ this.widgetDeps.slideApiDeps.enableBackpress();
17478
19066
  const onClosed = () => {
17479
19067
  this.productsView?.removeEventListener("animationend", onClosed);
17480
19068
  this.productsView?.parentElement?.removeChild(this.productsView);
@@ -17534,7 +19122,7 @@ class WidgetProducts extends WidgetBase {
17534
19122
  e.preventDefault();
17535
19123
  this._statEventWidgetCardClick(offer);
17536
19124
  if (offer.url) {
17537
- this.widgetDeps.sdkApi.openUrl({ type: "link", link: { type: "url", target: offer.url } });
19125
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target: offer.url } });
17538
19126
  }
17539
19127
  };
17540
19128
  card.appendChild(figure);
@@ -17765,10 +19353,10 @@ class WidgetQuest extends WidgetBase {
17765
19353
  super.onRefreshUserData(localData);
17766
19354
  }
17767
19355
  setCardSessionValue(name, value) {
17768
- this.widgetDeps.sdkApi.setCardSessionValue(this.element, name, value);
19356
+ this.widgetDeps.slideApiDeps.setCardSessionValue(this.element, name, value);
17769
19357
  }
17770
19358
  getCardSessionValue(name) {
17771
- return this.widgetDeps.sdkApi.getCardSessionValue(this.element, name);
19359
+ return this.widgetDeps.slideApiDeps.getCardSessionValue(this.element, name);
17772
19360
  }
17773
19361
  init() {
17774
19362
  if (this.localData) {
@@ -17787,8 +19375,8 @@ class WidgetQuest extends WidgetBase {
17787
19375
  // global flag - был сделан переход на нужный слайд, больше не нужно повторять за эту сессию
17788
19376
  // perform showStorySlide with lastSlideIdx only on story open first time (not on second slide, etc)
17789
19377
  this.setCardSessionValue("__storyQuestSlideChanged", "1");
17790
- if (this.widgetDeps.sdkApi.isExistsShowCardSlide) {
17791
- this.widgetDeps.sdkApi.showCardSlide(lastSlideIdx);
19378
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19379
+ this.widgetDeps.slideApiDeps.showCardSlide(lastSlideIdx);
17792
19380
  return false;
17793
19381
  }
17794
19382
  }
@@ -17799,8 +19387,8 @@ class WidgetQuest extends WidgetBase {
17799
19387
  // если этого слайда нет в роутинге (сработал переход по таймеру в app)
17800
19388
  const routes = this._getRoutes();
17801
19389
  if (routes[0].indexOf(this.slideIndex) === -1 && this.finalSlide) {
17802
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17803
- this.widgetDeps.sdkApi.cardShowNext();
19390
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19391
+ this.widgetDeps.slideApiDeps.cardShowNext();
17804
19392
  return false;
17805
19393
  }
17806
19394
  }
@@ -17846,10 +19434,10 @@ class WidgetQuest extends WidgetBase {
17846
19434
  this._selectAnswer(index, slideIndex);
17847
19435
  this.setLocalData(this.localData, true);
17848
19436
  this.env.setTimeout(() => {
17849
- if (slideIndex >= 0 && slideIndex < this.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19437
+ if (slideIndex >= 0 && slideIndex < this.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
17850
19438
  // global flag - был сделан переход на нужный слайд, больше не нужно повторять за эту сессию
17851
19439
  this.setCardSessionValue("__storyQuestSlideChanged", "1");
17852
- this.widgetDeps.sdkApi.showCardSlide(slideIndex);
19440
+ this.widgetDeps.slideApiDeps.showCardSlide(slideIndex);
17853
19441
  }
17854
19442
  }, 100);
17855
19443
  }
@@ -17921,12 +19509,12 @@ class WidgetQuest extends WidgetBase {
17921
19509
  else {
17922
19510
  // by routing - move back
17923
19511
  moveTo = this._routeMvPtrBack();
17924
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
17925
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19512
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19513
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
17926
19514
  }
17927
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19515
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
17928
19516
  // allow move to start - for broken route history
17929
- this.widgetDeps.sdkApi.showCardSlide(0);
19517
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
17930
19518
  }
17931
19519
  }
17932
19520
  return result;
@@ -17942,8 +19530,8 @@ class WidgetQuest extends WidgetBase {
17942
19530
  if (directionForward) {
17943
19531
  if (this.navigationNextSlide === -1) {
17944
19532
  // this is the final slide - exit from this quest
17945
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17946
- this.widgetDeps.sdkApi.cardShowNext();
19533
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19534
+ this.widgetDeps.slideApiDeps.cardShowNext();
17947
19535
  }
17948
19536
  result.continueDefaultNavigation = false;
17949
19537
  return result;
@@ -17952,11 +19540,11 @@ class WidgetQuest extends WidgetBase {
17952
19540
  if (nextSlideIndex < this.slideCount) {
17953
19541
  this._addNewRouteHistory(nextSlideIndex);
17954
19542
  this.setLocalData(this.localData, true);
17955
- this.widgetDeps.sdkApi.showCardSlide(nextSlideIndex);
19543
+ this.widgetDeps.slideApiDeps.showCardSlide(nextSlideIndex);
17956
19544
  }
17957
19545
  else {
17958
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17959
- this.widgetDeps.sdkApi.cardShowNext();
19546
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19547
+ this.widgetDeps.slideApiDeps.cardShowNext();
17960
19548
  }
17961
19549
  }
17962
19550
  }
@@ -17969,12 +19557,12 @@ class WidgetQuest extends WidgetBase {
17969
19557
  else {
17970
19558
  // by routing - move back
17971
19559
  moveTo = this._routeMvPtrBack();
17972
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
17973
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19560
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19561
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
17974
19562
  }
17975
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19563
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
17976
19564
  // allow move to start - for broken route history
17977
- this.widgetDeps.sdkApi.showCardSlide(0);
19565
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
17978
19566
  }
17979
19567
  }
17980
19568
  }
@@ -17989,11 +19577,11 @@ class WidgetQuest extends WidgetBase {
17989
19577
  if (nextSlideIndex < this.slideCount) {
17990
19578
  this._addNewRouteHistory(nextSlideIndex);
17991
19579
  this.setLocalData(this.localData, true);
17992
- this.widgetDeps.sdkApi.showCardSlide(nextSlideIndex);
19580
+ this.widgetDeps.slideApiDeps.showCardSlide(nextSlideIndex);
17993
19581
  }
17994
19582
  else {
17995
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17996
- this.widgetDeps.sdkApi.cardShowNext();
19583
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19584
+ this.widgetDeps.slideApiDeps.cardShowNext();
17997
19585
  }
17998
19586
  }
17999
19587
  }
@@ -18006,12 +19594,12 @@ class WidgetQuest extends WidgetBase {
18006
19594
  else {
18007
19595
  // by routing - move back
18008
19596
  moveTo = this._routeMvPtrBack();
18009
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18010
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19597
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19598
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18011
19599
  }
18012
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19600
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18013
19601
  // allow move to start - for broken route history
18014
- this.widgetDeps.sdkApi.showCardSlide(0);
19602
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18015
19603
  }
18016
19604
  }
18017
19605
  }
@@ -18026,20 +19614,20 @@ class WidgetQuest extends WidgetBase {
18026
19614
  // setLocalData(this.localData, true);
18027
19615
  // window._showNarrativeSlide(nextSlideIndex);
18028
19616
  // } else {
18029
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18030
- this.widgetDeps.sdkApi.cardShowNext();
19617
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19618
+ this.widgetDeps.slideApiDeps.cardShowNext();
18031
19619
  }
18032
19620
  // }
18033
19621
  }
18034
19622
  else {
18035
19623
  // by routing - move back
18036
19624
  moveTo = this._routeMvPtrBack();
18037
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18038
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19625
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19626
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18039
19627
  }
18040
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19628
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18041
19629
  // allow move to start - for broken route history
18042
- this.widgetDeps.sdkApi.showCardSlide(0);
19630
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18043
19631
  }
18044
19632
  }
18045
19633
  }
@@ -18829,7 +20417,7 @@ class WidgetRangeSlider extends WidgetBase {
18829
20417
  total_user: 0,
18830
20418
  };
18831
20419
  let answerAllocationTs = undefined;
18832
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
20420
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
18833
20421
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
18834
20422
  answerAllocation = sharedData[this.elementId];
18835
20423
  answerAllocationTs = sharedData.ts;
@@ -18929,7 +20517,7 @@ class WidgetRangeSlider extends WidgetBase {
18929
20517
  }
18930
20518
  e.preventDefault();
18931
20519
  this.isClickCapturedBySlider = true;
18932
- this.widgetDeps.sdkApi.disableHorizontalSwipeGesture();
20520
+ this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
18933
20521
  if (!this.maxHandlePos) {
18934
20522
  this.update(true, false);
18935
20523
  }
@@ -18959,7 +20547,7 @@ class WidgetRangeSlider extends WidgetBase {
18959
20547
  handleEnd(e) {
18960
20548
  this.env.requestAnimationFrame(() => {
18961
20549
  this.isClickCapturedBySlider = false;
18962
- this.widgetDeps.sdkApi.enableHorizontalSwipeGesture();
20550
+ this.widgetDeps.slideApiDeps.enableHorizontalSwipeGesture();
18963
20551
  });
18964
20552
  // e.preventDefault();
18965
20553
  this.widgetDeps.slideRoot.removeEventListener("touchmove", this.handleMove);
@@ -19024,7 +20612,7 @@ class WidgetRangeSlider extends WidgetBase {
19024
20612
  if (this.value !== this.prevSnapValue) {
19025
20613
  this.prevSnapValue = this.value;
19026
20614
  try {
19027
- this.widgetDeps.sdkApi.vibrate(20);
20615
+ this.widgetDeps.slideApiDeps.vibrate(20);
19028
20616
  }
19029
20617
  catch (e) {
19030
20618
  console.error(e);
@@ -19271,12 +20859,12 @@ class WidgetRate extends WidgetBase {
19271
20859
  if (this.showDialogOnLowRate) {
19272
20860
  this.elementRect = this.element.getBoundingClientRect();
19273
20861
  this._selectStar(this.selectedStar, false);
19274
- if (this.widgetDeps.sdkApi.isAndroid) {
20862
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
19275
20863
  this.slide.classList.add("blured");
19276
20864
  }
19277
20865
  this.slide.classList.add("data-input-editing");
19278
20866
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
19279
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
20867
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
19280
20868
  const data = JSON.parse(dataString);
19281
20869
  data.size = getElementBounding(this.env, this.elementRect);
19282
20870
  if (!this.disableTimer) {
@@ -19298,7 +20886,7 @@ class WidgetRate extends WidgetBase {
19298
20886
  catch (e) {
19299
20887
  console.error(e);
19300
20888
  }
19301
- this.widgetDeps.sdkApi.showCardTextInput(this.id, data);
20889
+ this.widgetDeps.slideApiDeps.showCardTextInput(this.id, data);
19302
20890
  }
19303
20891
  }
19304
20892
  else {
@@ -19310,17 +20898,17 @@ class WidgetRate extends WidgetBase {
19310
20898
  }
19311
20899
  else if (value + 1 >= this.submitToStoresMin && value + 1 <= this.submitToStoresMax) {
19312
20900
  let target = null;
19313
- if (this.widgetDeps.sdkApi.isAndroid) {
20901
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
19314
20902
  target = getTagData(this.element, "androidLink");
19315
20903
  }
19316
- else if (this.widgetDeps.sdkApi.isIOS) {
20904
+ else if (this.widgetDeps.slideApiDeps.isIOS) {
19317
20905
  target = getTagData(this.element, "appleLink");
19318
20906
  }
19319
20907
  this._selectStar(value, true);
19320
20908
  this.completeWidget();
19321
20909
  this._statEventRateUsAnswer("");
19322
20910
  if (this.submitToStores && target) {
19323
- this.widgetDeps.sdkApi.openUrl({ type: "link", link: { type: "url", target } });
20911
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target } });
19324
20912
  }
19325
20913
  }
19326
20914
  else {
@@ -19469,12 +21057,12 @@ class WidgetShare extends WidgetBase {
19469
21057
  }
19470
21058
  share() {
19471
21059
  if (!this.btnDisabled) {
19472
- if (this.widgetDeps.sdkApi.isExistsShare) {
19473
- if (this.widgetDeps.sdkApi.sdkCanSendShareComplete) {
21060
+ if (this.widgetDeps.slideApiDeps.isExistsShare) {
21061
+ if (this.widgetDeps.slideApiDeps.sdkCanSendShareComplete) {
19474
21062
  this.btnDisabled = true;
19475
21063
  }
19476
21064
  if (this.shareType === "url" || this.shareType === "story") {
19477
- this.widgetDeps.sdkApi.share(this.id, {
21065
+ this.widgetDeps.slideApiDeps.share(this.id, {
19478
21066
  url: this.shareTarget, // sdk old versions
19479
21067
  text: this.shareTarget,
19480
21068
  title: null,
@@ -19482,7 +21070,7 @@ class WidgetShare extends WidgetBase {
19482
21070
  });
19483
21071
  }
19484
21072
  else if (this.shareType === "slide") {
19485
- this.widgetDeps.sdkApi.shareSlideScreenshot(this.id, "[data-element-id='" + this.elementId + "']", this.shareTarget ? this.shareTarget : undefined);
21073
+ this.widgetDeps.slideApiDeps.shareSlideScreenshot(this.id, "[data-element-id='" + this.elementId + "']", this.shareTarget ? this.shareTarget : undefined);
19486
21074
  }
19487
21075
  }
19488
21076
  }
@@ -20088,9 +21676,9 @@ class WidgetTooltip extends WidgetBase {
20088
21676
  copyToClipboard(element) {
20089
21677
  const textValue = this.template1ClipboardTarget ?? "";
20090
21678
  if (textValue) {
20091
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
21679
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
20092
21680
  if (this.template1CopiedText) {
20093
- this.widgetDeps.sdkApi.showToast(this.template1CopiedText);
21681
+ this.widgetDeps.slideApiDeps.showToast(this.template1CopiedText);
20094
21682
  }
20095
21683
  }
20096
21684
  this._statEventWidgetCopyClick(textValue);
@@ -20469,7 +22057,7 @@ class WidgetVote extends WidgetBase {
20469
22057
  // voteAllocation[7]
20470
22058
  let voteAllocation = [];
20471
22059
  let voteAllocationTs = undefined;
20472
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
22060
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
20473
22061
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
20474
22062
  voteAllocation = sharedData[this.elementId];
20475
22063
  if (isObject$1(sharedData[this.elementId])) {