@inappstory/slide-api 0.1.23 → 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.js CHANGED
@@ -561,8 +561,8 @@ const getWinWidth = function (env) {
561
561
  const getWinHeight = function (env) {
562
562
  return env.innerHeight || env.document.documentElement.clientHeight || env.document.body.clientHeight;
563
563
  };
564
- const sendStatisticEventToApp = function (sdkApi, name, data, devPayload, options) {
565
- sdkApi.sendStatisticEvent(name, data, devPayload, options?.forceEnableStatisticV2 ?? false);
564
+ const sendStatisticEventToApp = function (slideApiDeps, name, data, devPayload, options) {
565
+ slideApiDeps.sendStatisticEvent(name, data, devPayload, options?.forceEnableStatisticV2 ?? false);
566
566
  };
567
567
  const getValueOrException = function (value, message) {
568
568
  if (value == null) {
@@ -819,13 +819,18 @@ var getAnimationFunction = function (element) {
819
819
  return function () { };
820
820
  };
821
821
  const animationApi = {
822
+ init: function (slide, animate = false) {
823
+ if (supportAnimate && animate)
824
+ return;
825
+ addClass(slide, "animation-fallback");
826
+ },
822
827
  start: function (slide, animate = false) {
823
828
  if (supportAnimate && animate) {
829
+ const elements = toArray(slide.querySelectorAll(".narrative-element-animation"));
824
830
  // for editor, todo add .reset-animation to narrative-editor-slide && clear that
825
831
  if (!hasClass(slide, "narrative-slide")) {
826
832
  addClass(slide, "reset-animation");
827
833
  }
828
- const elements = toArray(slide.querySelectorAll(".narrative-element-animation"));
829
834
  elements.forEach(element => {
830
835
  var width = element.offsetWidth;
831
836
  var height = element.offsetHeight;
@@ -911,7 +916,6 @@ const animationApi = {
911
916
  }
912
917
  }
913
918
  else {
914
- addClass(slide, "animation-fallback");
915
919
  const animations = [];
916
920
  // просто Array
917
921
  var elements = slide.querySelectorAll(".narrative-element-animation");
@@ -1169,6 +1173,13 @@ class EsModuleSdkApi {
1169
1173
  isSdkSupportCorrectPauseResumeLifecycle() {
1170
1174
  return true;
1171
1175
  }
1176
+ emitEvent(name, event) {
1177
+ this.sdkBinding.onEvent(name, event);
1178
+ }
1179
+ onCardLoadingStateChange(state, reason) {
1180
+ console.log("onCardLoadingStateChange", { state });
1181
+ this.sdkBinding.onCardLoadingStateChange(state, reason);
1182
+ }
1172
1183
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKInterface`]; }
1173
1184
  }
1174
1185
 
@@ -1195,6 +1206,9 @@ class DataInput {
1195
1206
  return element instanceof DataInput;
1196
1207
  }
1197
1208
  mediaElementsLoadingPromises = [];
1209
+ get nodeRef() {
1210
+ return this._elementNodeRef;
1211
+ }
1198
1212
  init(localData) {
1199
1213
  try {
1200
1214
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1245,6 +1259,9 @@ class Barcode {
1245
1259
  this._widgetDeps = _widgetDeps;
1246
1260
  }
1247
1261
  mediaElementsLoadingPromises = [];
1262
+ get nodeRef() {
1263
+ return this._elementNodeRef;
1264
+ }
1248
1265
  init(localData) {
1249
1266
  try {
1250
1267
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1282,36 +1299,311 @@ class ClickableBase {
1282
1299
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`]; }
1283
1300
  }
1284
1301
 
1302
+ class PromocodeNetworkError extends Error {
1303
+ }
1304
+ class PromocodeServiceError extends Error {
1305
+ }
1306
+ class PromocodeNoMoreCodes extends Error {
1307
+ }
1308
+ class PromocodeApi {
1309
+ sdkApi;
1310
+ messages;
1311
+ constructor(sdkApi, messages) {
1312
+ this.sdkApi = sdkApi;
1313
+ this.messages = messages;
1314
+ }
1315
+ async fetchPromoCode(params) {
1316
+ const path = this.getPromotionalCodeFetchPath(params);
1317
+ const headers = {
1318
+ accept: "application/json",
1319
+ "Content-Type": "application/json",
1320
+ };
1321
+ const [response] = await Promise.all([
1322
+ this.sdkApi.sendApiRequest(path, "POST", null, headers, null, "fetch-promo-code"),
1323
+ new Promise(resolve => setTimeout(resolve, 300)),
1324
+ ]);
1325
+ const { status, data } = response;
1326
+ if (status === 200 || status === 201) {
1327
+ const promocode = data?.code;
1328
+ if (promocode) {
1329
+ return { promocode, status };
1330
+ }
1331
+ throw new PromocodeNoMoreCodes(this.messages.noMoreCodes);
1332
+ }
1333
+ if (status === 12163 || status === 12002) {
1334
+ throw new PromocodeNetworkError(this.messages.networkError);
1335
+ }
1336
+ throw new PromocodeServiceError(this.messages.serviceError);
1337
+ }
1338
+ getPromotionalCodeFetchPath(params) {
1339
+ switch (params.card.type) {
1340
+ case 4 /* CARD_TYPE.IN_APP_MESSAGING */:
1341
+ return `inappmessaging/message/${params.card.id}/widget/${params.elementId}/promo-code/${params.promocodeId}`;
1342
+ default:
1343
+ return `story/${params.card.id}/widget/${params.elementId}/promo-code/${params.promocodeId}`;
1344
+ }
1345
+ }
1346
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Pick`, `{
1347
+ noMoreCodes?: string;
1348
+ networkError?: string;
1349
+ serviceError?: string;
1350
+ }`]; }
1351
+ }
1352
+
1353
+ class PromocodeLocalRepository {
1354
+ elementId;
1355
+ sdkApi;
1356
+ localData = {};
1357
+ constructor(elementId, sdkApi) {
1358
+ this.elementId = elementId;
1359
+ this.sdkApi = sdkApi;
1360
+ }
1361
+ init({ localData, cardId }) {
1362
+ const savedData = this.sdkApi.getCardServerData(cardId) ?? {};
1363
+ this.localData = extend({}, savedData, localData ?? {});
1364
+ }
1365
+ getPromocode() {
1366
+ return this.localData["_pcl_g_" + this.elementId + "_pc"];
1367
+ }
1368
+ savePromocodeByStatus(promocode, status) {
1369
+ if (status === 201)
1370
+ this.savePromocodeWithTime(promocode);
1371
+ else
1372
+ this.savePromocode(promocode);
1373
+ }
1374
+ savePromocodeWithTime(promocode) {
1375
+ this.localData["_pcl_g_" + this.elementId + "_pc_fetched_at"] = Math.round(new Date().getTime() / 1000);
1376
+ this.localData["_&ts_pcl_g_" + this.elementId + "_pc_fetched_at"] = Math.round(new Date().getTime() / 1000);
1377
+ this.savePromocode(promocode);
1378
+ }
1379
+ savePromocode(promocode) {
1380
+ this.localData["_pcl_g_" + this.elementId + "_pc"] = promocode;
1381
+ this.setCardLocalData(this.localData);
1382
+ }
1383
+ async setCardLocalData(newLocalData) {
1384
+ const localData = await this.sdkApi.getCardLocalData();
1385
+ const mergedData = extend({}, localData, newLocalData);
1386
+ await this.sdkApi.setCardLocalData(mergedData, true);
1387
+ }
1388
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`string`, `ISlideApiDeps`]; }
1389
+ }
1390
+
1391
+ var PromocodeLinkState;
1392
+ (function (PromocodeLinkState) {
1393
+ PromocodeLinkState[PromocodeLinkState["Idle"] = 0] = "Idle";
1394
+ PromocodeLinkState[PromocodeLinkState["Fetched"] = 1] = "Fetched";
1395
+ PromocodeLinkState[PromocodeLinkState["Error"] = 2] = "Error";
1396
+ })(PromocodeLinkState || (PromocodeLinkState = {}));
1397
+ const PROMOCODE_PLACEHOLDER = "%__ias_pc%";
1398
+ class PromocodeLink {
1399
+ element;
1400
+ layer;
1401
+ widgetDeps;
1402
+ state = PromocodeLinkState.Idle;
1403
+ promocode = null;
1404
+ promocodeId;
1405
+ linkTemplate;
1406
+ textContent;
1407
+ button;
1408
+ elementId;
1409
+ card;
1410
+ api;
1411
+ localRepository;
1412
+ constructor(element, layer, widgetDeps) {
1413
+ this.element = element;
1414
+ this.layer = layer;
1415
+ this.widgetDeps = widgetDeps;
1416
+ this.elementId = getValueOrException(getTagData(this.element, "elementId"), "Empty elementId");
1417
+ this.promocodeId = getTagData(this.element, "linkTarget") ?? "";
1418
+ this.linkTemplate = getTagData(this.element, "linkTemplate") ?? "";
1419
+ this.button = this.element.querySelector(".narrative-element-text-lines");
1420
+ this.textContent = this.button?.textContent ?? "";
1421
+ this.card = this.getCard();
1422
+ this.api = new PromocodeApi(this.widgetDeps.slideApiDeps, {
1423
+ networkError: getTagData(this.element, "msgNetworkError") ?? "",
1424
+ serviceError: getTagData(this.element, "msgServiceError") ?? "",
1425
+ noMoreCodes: getTagData(this.element, "msgNoMoreCodes") ?? "",
1426
+ });
1427
+ this.localRepository = new PromocodeLocalRepository(this.elementId, this.widgetDeps.slideApiDeps);
1428
+ }
1429
+ get nodeRef() {
1430
+ return this.element;
1431
+ }
1432
+ mediaElementsLoadingPromises = [];
1433
+ init(localData) {
1434
+ this.localRepository.init({ localData: localData ?? {}, cardId: this.card.id });
1435
+ this.state = PromocodeLinkState.Idle;
1436
+ const promocode = this.localRepository.getPromocode();
1437
+ if (promocode) {
1438
+ this.state = PromocodeLinkState.Fetched;
1439
+ this.showPromocode(promocode);
1440
+ this.promocode = promocode;
1441
+ }
1442
+ return Promise.resolve(true);
1443
+ }
1444
+ onPause() { }
1445
+ onResume() { }
1446
+ onStop() { }
1447
+ onBeforeUnmount() {
1448
+ return Promise.resolve();
1449
+ }
1450
+ handleClick() {
1451
+ switch (this.state) {
1452
+ case PromocodeLinkState.Idle:
1453
+ return false;
1454
+ case PromocodeLinkState.Fetched:
1455
+ this.openPromocodeUrl();
1456
+ return true;
1457
+ case PromocodeLinkState.Error:
1458
+ this.loadPromocode(this.promocodeId).catch(() => { });
1459
+ break;
1460
+ }
1461
+ return false;
1462
+ }
1463
+ get isLayerForcePaused() {
1464
+ return false;
1465
+ }
1466
+ onStart() {
1467
+ this.element.classList.add("active");
1468
+ this.loadPromocode(this.promocodeId).catch(() => { });
1469
+ }
1470
+ openPromocodeUrl() {
1471
+ if (!this.promocode)
1472
+ return;
1473
+ const target = this.linkTemplate.replaceAll(PROMOCODE_PLACEHOLDER, this.promocode);
1474
+ this.layer.layoutService.env.setTimeout(() => {
1475
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target } });
1476
+ });
1477
+ }
1478
+ async loadPromocode(promocodeId) {
1479
+ try {
1480
+ this.state = PromocodeLinkState.Idle;
1481
+ this.showLoader();
1482
+ const promocode = await this.getPromocode({
1483
+ promocodeId,
1484
+ card: this.card,
1485
+ elementId: this.elementId,
1486
+ });
1487
+ this.state = PromocodeLinkState.Fetched;
1488
+ this.promocode = promocode;
1489
+ this.showPromocode(promocode);
1490
+ return promocode;
1491
+ }
1492
+ catch (error) {
1493
+ this.handleLoadPromocodeError(error);
1494
+ throw error;
1495
+ }
1496
+ finally {
1497
+ this.hideLoader();
1498
+ }
1499
+ }
1500
+ async getPromocode(params) {
1501
+ if (this.promocode)
1502
+ return this.promocode;
1503
+ let promocode = this.localRepository.getPromocode();
1504
+ if (!promocode) {
1505
+ const result = await this.api.fetchPromoCode(params);
1506
+ promocode = result.promocode;
1507
+ this.localRepository.savePromocodeByStatus(promocode, result.status);
1508
+ }
1509
+ this.promocode = promocode;
1510
+ return promocode;
1511
+ }
1512
+ handleLoadPromocodeError(error) {
1513
+ this.state = PromocodeLinkState.Error;
1514
+ this.showErrorMessage(getTagData(this.element, "msgTryAgain") ?? "");
1515
+ if (error.message.length) {
1516
+ this.widgetDeps.slideApiDeps.showToast(error.message);
1517
+ }
1518
+ }
1519
+ showPromocode(promocode) {
1520
+ if (!this.button)
1521
+ return;
1522
+ this.button.textContent = this.textContent.replaceAll(PROMOCODE_PLACEHOLDER, promocode);
1523
+ }
1524
+ showErrorMessage(message) {
1525
+ if (!this.button)
1526
+ return;
1527
+ this.button.textContent = message;
1528
+ }
1529
+ getCard() {
1530
+ const slide = getValueOrException(this.element.closest(".narrative-slide"), "Empty slide");
1531
+ return {
1532
+ id: getValueOrException(getTagDataAsNumber(slide, "id"), "Empty cardId"),
1533
+ type: getValueOrException(getTagDataAsNumber(slide, "cardType"), "Empty card type"),
1534
+ };
1535
+ }
1536
+ showLoader() {
1537
+ if (!this.isTransparentElement())
1538
+ addClass(this.element, "loader");
1539
+ }
1540
+ hideLoader() {
1541
+ removeClass(this.element, "loader");
1542
+ }
1543
+ isTransparentElement() {
1544
+ if (this.element) {
1545
+ try {
1546
+ const color = window.getComputedStyle(this.element).color;
1547
+ if (color === "transparent" || color === "rgba(0, 0, 0, 0)" || color === "rgba(0,0,0,0)") {
1548
+ return true;
1549
+ }
1550
+ }
1551
+ catch (err) {
1552
+ console.error(err);
1553
+ }
1554
+ }
1555
+ return false;
1556
+ }
1557
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `WidgetDeps`]; }
1558
+ }
1559
+
1285
1560
  class Button extends ClickableBase {
1286
1561
  _elementNodeRef;
1287
- _layer;
1562
+ layer;
1563
+ widgetDeps;
1288
1564
  static _className = "narrative-element-link";
1565
+ isPromotionalCode;
1566
+ promocodeLink = null;
1289
1567
  static className() {
1290
1568
  return Button._className;
1291
1569
  }
1292
- constructor(_elementNodeRef, _layer) {
1570
+ static isTypeOf(element) {
1571
+ return element instanceof Button;
1572
+ }
1573
+ constructor(_elementNodeRef, layer, widgetDeps) {
1293
1574
  super(_elementNodeRef);
1294
1575
  this._elementNodeRef = _elementNodeRef;
1295
- this._layer = _layer;
1576
+ this.layer = layer;
1577
+ this.widgetDeps = widgetDeps;
1578
+ this.isPromotionalCode = getTagData(_elementNodeRef, "linkType") === "promocode";
1579
+ if (this.isPromotionalCode) {
1580
+ this.promocodeLink = new PromocodeLink(_elementNodeRef, layer, widgetDeps);
1581
+ }
1582
+ }
1583
+ get nodeRef() {
1584
+ return this._elementNodeRef;
1296
1585
  }
1297
1586
  mediaElementsLoadingPromises = [];
1298
- init(localData) {
1299
- return Promise.resolve(true);
1587
+ async init(localData) {
1588
+ await this.promocodeLink?.init(localData);
1589
+ return true;
1300
1590
  }
1301
1591
  onPause() { }
1302
1592
  onResume() { }
1303
- onStart() { }
1593
+ onStart() {
1594
+ this.promocodeLink?.onStart();
1595
+ }
1304
1596
  onStop() { }
1305
1597
  onBeforeUnmount() {
1306
1598
  return Promise.resolve();
1307
1599
  }
1308
1600
  handleClick() {
1309
- return false;
1601
+ return this.promocodeLink?.handleClick() ?? true;
1310
1602
  }
1311
1603
  get isLayerForcePaused() {
1312
1604
  return false;
1313
1605
  }
1314
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`]; }
1606
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `WidgetDeps`]; }
1315
1607
  }
1316
1608
 
1317
1609
  class Copy {
@@ -1332,6 +1624,9 @@ class Copy {
1332
1624
  this._widgetDeps = _widgetDeps;
1333
1625
  }
1334
1626
  mediaElementsLoadingPromises = [];
1627
+ get nodeRef() {
1628
+ return this._elementNodeRef;
1629
+ }
1335
1630
  init(localData) {
1336
1631
  try {
1337
1632
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1381,6 +1676,9 @@ class DateCountdown {
1381
1676
  this._widgetDeps = _widgetDeps;
1382
1677
  }
1383
1678
  mediaElementsLoadingPromises = [];
1679
+ get nodeRef() {
1680
+ return this._elementNodeRef;
1681
+ }
1384
1682
  init(localData) {
1385
1683
  try {
1386
1684
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1435,6 +1733,9 @@ class Poll {
1435
1733
  return element instanceof Poll;
1436
1734
  }
1437
1735
  mediaElementsLoadingPromises = [];
1736
+ get nodeRef() {
1737
+ return this._elementNodeRef;
1738
+ }
1438
1739
  init(localData) {
1439
1740
  try {
1440
1741
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1490,6 +1791,9 @@ class PollLayers {
1490
1791
  return element instanceof PollLayers;
1491
1792
  }
1492
1793
  mediaElementsLoadingPromises = [];
1794
+ get nodeRef() {
1795
+ return this._elementNodeRef;
1796
+ }
1493
1797
  init(localData) {
1494
1798
  try {
1495
1799
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1540,6 +1844,9 @@ class Products {
1540
1844
  return element instanceof Products;
1541
1845
  }
1542
1846
  mediaElementsLoadingPromises = [];
1847
+ get nodeRef() {
1848
+ return this._elementNodeRef;
1849
+ }
1543
1850
  init(localData) {
1544
1851
  try {
1545
1852
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1599,6 +1906,9 @@ class Quest {
1599
1906
  return element instanceof Quest;
1600
1907
  }
1601
1908
  mediaElementsLoadingPromises = [];
1909
+ get nodeRef() {
1910
+ return this._elementNodeRef;
1911
+ }
1602
1912
  init(localData) {
1603
1913
  return this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
1604
1914
  }
@@ -1647,6 +1957,9 @@ class Quiz {
1647
1957
  return element instanceof Quiz;
1648
1958
  }
1649
1959
  mediaElementsLoadingPromises = [];
1960
+ get nodeRef() {
1961
+ return this._elementNodeRef;
1962
+ }
1650
1963
  init(localData) {
1651
1964
  try {
1652
1965
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1700,6 +2013,9 @@ class QuizGrouped {
1700
2013
  return element instanceof QuizGrouped;
1701
2014
  }
1702
2015
  mediaElementsLoadingPromises = [];
2016
+ get nodeRef() {
2017
+ return this._elementNodeRef;
2018
+ }
1703
2019
  init(localData) {
1704
2020
  try {
1705
2021
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1753,6 +2069,9 @@ class RangeSlider {
1753
2069
  return element instanceof RangeSlider;
1754
2070
  }
1755
2071
  mediaElementsLoadingPromises = [];
2072
+ get nodeRef() {
2073
+ return this._elementNodeRef;
2074
+ }
1756
2075
  init(localData) {
1757
2076
  try {
1758
2077
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1806,6 +2125,9 @@ class Rate {
1806
2125
  return element instanceof Rate;
1807
2126
  }
1808
2127
  mediaElementsLoadingPromises = [];
2128
+ get nodeRef() {
2129
+ return this._elementNodeRef;
2130
+ }
1809
2131
  init(localData) {
1810
2132
  try {
1811
2133
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1862,6 +2184,9 @@ class Share {
1862
2184
  return element instanceof Share;
1863
2185
  }
1864
2186
  mediaElementsLoadingPromises = [];
2187
+ get nodeRef() {
2188
+ return this._elementNodeRef;
2189
+ }
1865
2190
  init(localData) {
1866
2191
  try {
1867
2192
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1909,6 +2234,9 @@ class SwipeUpItems {
1909
2234
  return element instanceof SwipeUpItems;
1910
2235
  }
1911
2236
  mediaElementsLoadingPromises = [];
2237
+ get nodeRef() {
2238
+ return this._elementNodeRef;
2239
+ }
1912
2240
  init(localData) {
1913
2241
  return Promise.resolve(true);
1914
2242
  }
@@ -1952,6 +2280,9 @@ class Test {
1952
2280
  return element instanceof Test;
1953
2281
  }
1954
2282
  mediaElementsLoadingPromises = [];
2283
+ get nodeRef() {
2284
+ return this._elementNodeRef;
2285
+ }
1955
2286
  init(localData) {
1956
2287
  try {
1957
2288
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2005,6 +2336,9 @@ class Tooltip {
2005
2336
  this._widgetDeps = _widgetDeps;
2006
2337
  }
2007
2338
  mediaElementsLoadingPromises = [];
2339
+ get nodeRef() {
2340
+ return this._elementNodeRef;
2341
+ }
2008
2342
  init(localData) {
2009
2343
  try {
2010
2344
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2052,6 +2386,9 @@ class Vote {
2052
2386
  this._widgetDeps = _widgetDeps;
2053
2387
  }
2054
2388
  mediaElementsLoadingPromises = [];
2389
+ get nodeRef() {
2390
+ return this._elementNodeRef;
2391
+ }
2055
2392
  init(localData) {
2056
2393
  try {
2057
2394
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2093,6 +2430,9 @@ class Text {
2093
2430
  this._layer = _layer;
2094
2431
  }
2095
2432
  mediaElementsLoadingPromises = [];
2433
+ get nodeRef() {
2434
+ return this._elementNodeRef;
2435
+ }
2096
2436
  init(localData) {
2097
2437
  return Promise.resolve(true);
2098
2438
  }
@@ -2216,6 +2556,9 @@ class Image extends ClickableBase {
2216
2556
  this.mediaElementsLoadingPromises = mediaElements.map(waitForImageHtmlElementLoad);
2217
2557
  }
2218
2558
  mediaElementsLoadingPromises = [];
2559
+ get nodeRef() {
2560
+ return this._elementNodeRef;
2561
+ }
2219
2562
  init(localData) {
2220
2563
  return Promise.resolve(true);
2221
2564
  }
@@ -2250,6 +2593,9 @@ class SwipeUp {
2250
2593
  return element instanceof SwipeUp;
2251
2594
  }
2252
2595
  mediaElementsLoadingPromises = [];
2596
+ get nodeRef() {
2597
+ return this._elementNodeRef;
2598
+ }
2253
2599
  init(localData) {
2254
2600
  return Promise.resolve(true);
2255
2601
  }
@@ -2276,7 +2622,7 @@ class Video {
2276
2622
  _elementNodeRef;
2277
2623
  _layer;
2278
2624
  _VideoPlayer;
2279
- _sdkApi;
2625
+ _slideApiDeps;
2280
2626
  static _className = "narrative-element-video";
2281
2627
  static className() {
2282
2628
  return Video._className;
@@ -2286,11 +2632,11 @@ class Video {
2286
2632
  _vodData;
2287
2633
  _vodPlayerInstance = null;
2288
2634
  _videoStateAdapter = null;
2289
- constructor(_elementNodeRef, _layer, _VideoPlayer, _sdkApi) {
2635
+ constructor(_elementNodeRef, _layer, _VideoPlayer, _slideApiDeps) {
2290
2636
  this._elementNodeRef = _elementNodeRef;
2291
2637
  this._layer = _layer;
2292
2638
  this._VideoPlayer = _VideoPlayer;
2293
- this._sdkApi = _sdkApi;
2639
+ this._slideApiDeps = _slideApiDeps;
2294
2640
  const _video = this._elementNodeRef.querySelector("video");
2295
2641
  if (!_video) {
2296
2642
  return;
@@ -2346,6 +2692,9 @@ class Video {
2346
2692
  return element instanceof Video;
2347
2693
  }
2348
2694
  mediaElementsLoadingPromises = [];
2695
+ get nodeRef() {
2696
+ return this._elementNodeRef;
2697
+ }
2349
2698
  init(localData) {
2350
2699
  return Promise.resolve(true);
2351
2700
  }
@@ -2365,6 +2714,9 @@ class Video {
2365
2714
  // console.log("onBeforeUnmount")
2366
2715
  return await this._destroyVODPlayer();
2367
2716
  }
2717
+ get durationMs() {
2718
+ return this._video.duration * 1000;
2719
+ }
2368
2720
  _initVOD(vodData) {
2369
2721
  const onWaiting = () => {
2370
2722
  /**
@@ -2390,7 +2742,7 @@ class Video {
2390
2742
  // TODO via class instead of data attr
2391
2743
  if (this._video.getAttribute("data-waiting") === "1") {
2392
2744
  this._video.setAttribute("data-waiting", "0");
2393
- this._layer.timeline.slideResumed(this._video.currentTime * 1000);
2745
+ this._layer.timeline.slideResumed(() => this._video.currentTime * 1000);
2394
2746
  // @ts-ignore
2395
2747
  // _log(`playing: ${this._video.currentTime}`, true);
2396
2748
  // clearTimeout(window.synthErrorId);
@@ -2474,13 +2826,13 @@ class Video {
2474
2826
  });
2475
2827
  }
2476
2828
  _convertMpdUrls(mpd_) {
2477
- if (this._sdkApi.isWeb) {
2829
+ if (this._slideApiDeps.isWeb) {
2478
2830
  return mpd_;
2479
2831
  }
2480
2832
  if (isObject(mpd_) && mpd_.adaptiveFormats != null && Array.isArray(mpd_.adaptiveFormats)) {
2481
2833
  const mpd = { ...mpd_ };
2482
2834
  for (let i = 0; i < mpd.adaptiveFormats.length; ++i) {
2483
- mpd.adaptiveFormats[i].url = `${this._sdkApi.isAndroid ? `http://vod-asset/` : `vod-asset://`}${mpd.adaptiveFormats[i].cacheName}`;
2835
+ mpd.adaptiveFormats[i].url = `${this._slideApiDeps.isAndroid ? `http://vod-asset/` : `vod-asset://`}${mpd.adaptiveFormats[i].cacheName}`;
2484
2836
  }
2485
2837
  return mpd;
2486
2838
  }
@@ -2515,7 +2867,13 @@ class Video {
2515
2867
  get videoStartedPromise() {
2516
2868
  return this._videoStartedPromise;
2517
2869
  }
2518
- start(muted = true, loop = true) {
2870
+ get isLooped() {
2871
+ if (this._video != null) {
2872
+ return this._video?.loop;
2873
+ }
2874
+ return false;
2875
+ }
2876
+ start(muted = true, getIsLooped) {
2519
2877
  this._videoStartedPromise = new Promise(async (resolve) => {
2520
2878
  // invariant - always wait for mediaElementsLoadingPromises
2521
2879
  // else call of _initVOD can start and onAllMediaLoaded failed
@@ -2529,7 +2887,7 @@ class Video {
2529
2887
  // console.log("Video:start => this._video.pause()");
2530
2888
  this._video.pause();
2531
2889
  this._video.currentTime = 0;
2532
- this._video.loop = loop;
2890
+ this._video.loop = getIsLooped();
2533
2891
  // remove init class
2534
2892
  // if vod - create VoD player
2535
2893
  if (this._video.getAttribute("data-default-muted") !== "1") {
@@ -2542,13 +2900,13 @@ class Video {
2542
2900
  this._video.currentTime = 0;
2543
2901
  this._elementNodeRef.classList.remove("init");
2544
2902
  resolve({
2545
- currentTime: this._video.currentTime,
2903
+ getVideoCurrentTime: () => this._video.currentTime,
2546
2904
  });
2547
2905
  })
2548
2906
  .catch(error => {
2549
2907
  console.error(error);
2550
2908
  resolve({
2551
- currentTime: this._video.currentTime,
2909
+ getVideoCurrentTime: () => this._video.currentTime,
2552
2910
  });
2553
2911
  });
2554
2912
  }
@@ -2557,14 +2915,14 @@ class Video {
2557
2915
  this._video.currentTime = 0;
2558
2916
  this._elementNodeRef.classList.remove("init");
2559
2917
  resolve({
2560
- currentTime: this._video.currentTime,
2918
+ getVideoCurrentTime: () => this._video.currentTime,
2561
2919
  });
2562
2920
  }, 0);
2563
2921
  }
2564
2922
  }
2565
2923
  else {
2566
2924
  resolve({
2567
- currentTime: 0,
2925
+ getVideoCurrentTime: () => 0,
2568
2926
  });
2569
2927
  }
2570
2928
  });
@@ -2600,7 +2958,7 @@ class Video {
2600
2958
  // console.log("resolve 1.1", { ts });
2601
2959
  this._video.currentTime = ts;
2602
2960
  }
2603
- resolve({ currentTime: this._video.currentTime });
2961
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2604
2962
  })
2605
2963
  .catch(error => {
2606
2964
  console.error(error);
@@ -2608,7 +2966,7 @@ class Video {
2608
2966
  if (this._video.currentTime < ts) {
2609
2967
  this._video.currentTime = ts;
2610
2968
  }
2611
- resolve({ currentTime: this._video.currentTime });
2969
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2612
2970
  });
2613
2971
  }
2614
2972
  else {
@@ -2617,7 +2975,7 @@ class Video {
2617
2975
  if (this._video.currentTime < ts) {
2618
2976
  this._video.currentTime = ts;
2619
2977
  }
2620
- resolve({ currentTime: this._video.currentTime });
2978
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2621
2979
  }, 0);
2622
2980
  }
2623
2981
  });
@@ -2671,7 +3029,7 @@ class Video {
2671
3029
  this._video.muted = true;
2672
3030
  }
2673
3031
  }
2674
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `typeof VideoPlayer | undefined`, `SDKApi`]; }
3032
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `typeof VideoPlayer | undefined`, `ISlideApiDeps`]; }
2675
3033
  }
2676
3034
  // class VideoStateAdapter {
2677
3035
  //
@@ -2765,7 +3123,12 @@ class VideoStateAdapter {
2765
3123
  }
2766
3124
  // todo - add debounce
2767
3125
  this._playingCheckerId = window.setTimeout(() => {
3126
+ // console.log({now: Date.now(), _timeupdate: this._timeupdate, currentTime: this._video.currentTime, duration: this._video.duration});
2768
3127
  if (Date.now() - this._timeupdate >= this._maxDiff / 2) {
3128
+ // prevent onWaiting triggering if the video has ended
3129
+ if (Math.round(this._video.currentTime) >= Math.round(this._video.duration)) {
3130
+ return;
3131
+ }
2769
3132
  this._state = 2 /* VIDEO_STATE.WAITING */;
2770
3133
  this._triggerUpdate();
2771
3134
  }
@@ -2848,7 +3211,7 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
2848
3211
  case Text.className():
2849
3212
  return new Text(nodeRef, layer);
2850
3213
  case Button.className():
2851
- return new Button(nodeRef, layer);
3214
+ return new Button(nodeRef, layer, widgetDeps);
2852
3215
  case Image.className():
2853
3216
  return new Image(nodeRef, layer);
2854
3217
  case SwipeUp.className():
@@ -2856,7 +3219,7 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
2856
3219
  case SwipeUpItems.className():
2857
3220
  return new SwipeUpItems(nodeRef, layer);
2858
3221
  case Video.className():
2859
- return new Video(nodeRef, layer, layoutApi.VideoPlayer, layer.sdkApi);
3222
+ return new Video(nodeRef, layer, layoutApi.VideoPlayer, layer.slideApiDeps);
2860
3223
  //////// widgets ///////
2861
3224
  case Copy.className():
2862
3225
  return layoutApi.widgetCopyApi ? new Copy(nodeRef, layer, layoutApi.widgetCopyApi, widgetCallbacks, widgetDeps) : null;
@@ -2914,20 +3277,23 @@ class SlideTimeline {
2914
3277
  slideDisabledTimer;
2915
3278
  slideReady;
2916
3279
  _afterAppResumeQueuePush;
2917
- sdkApi;
2918
- constructor(slideIndex, slideDuration, slideDisabledTimer, slideReady, _afterAppResumeQueuePush, sdkApi) {
3280
+ slideApiDeps;
3281
+ constructor(slideIndex, slideDuration, slideDisabledTimer, slideReady, _afterAppResumeQueuePush, slideApiDeps) {
2919
3282
  this.slideIndex = slideIndex;
2920
3283
  this.slideDuration = slideDuration;
2921
3284
  this.slideDisabledTimer = slideDisabledTimer;
2922
3285
  this.slideReady = slideReady;
2923
3286
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
2924
- this.sdkApi = sdkApi;
3287
+ this.slideApiDeps = slideApiDeps;
2925
3288
  this.timelineDisabledState = this.slideDisabledTimer ? TimelineDisabledState.disabled : TimelineDisabledState.enabled;
2926
3289
  }
2927
3290
  resumedAt = new Date().getTime();
2928
3291
  timeSpent = 0;
2929
3292
  timelineDisabledState;
2930
3293
  currentState = "stop" /* TIMELINE_ACTION.STOP */;
3294
+ deferredDataWaitingStateTimerId = null;
3295
+ deferredResumeStateTimerId = null;
3296
+ dataWaitingStartedAt = null;
2931
3297
  static get layoutService() {
2932
3298
  return container.get({ identifier: "LayoutService" });
2933
3299
  }
@@ -2935,14 +3301,14 @@ class SlideTimeline {
2935
3301
  return SlideTimeline.layoutService;
2936
3302
  }
2937
3303
  get isSDKSupportUpdateTimeline() {
2938
- if (this.sdkApi.isAndroid) {
3304
+ if (this.slideApiDeps.isAndroid) {
2939
3305
  return Boolean(SlideTimeline.layoutService.env.Android && "updateTimeline" in SlideTimeline.layoutService.env.Android);
2940
3306
  }
2941
- else if (this.sdkApi.isIOS) {
3307
+ else if (this.slideApiDeps.isIOS) {
2942
3308
  const mh = SlideTimeline.layoutService.env?.webkit?.messageHandlers ?? {};
2943
3309
  return "updateTimeline" in mh;
2944
3310
  }
2945
- else if (this.sdkApi.isWeb) {
3311
+ else if (this.slideApiDeps.isWeb) {
2946
3312
  return true;
2947
3313
  }
2948
3314
  else {
@@ -2950,7 +3316,7 @@ class SlideTimeline {
2950
3316
  }
2951
3317
  }
2952
3318
  get isSdkSupportTimelineOnBeforeStart() {
2953
- return this.sdkApi.isSdkSupportTimelineOnBeforeStart();
3319
+ return this.slideApiDeps.isSdkSupportTimelineOnBeforeStart();
2954
3320
  }
2955
3321
  get index() {
2956
3322
  return this.slideIndex;
@@ -2958,6 +3324,9 @@ class SlideTimeline {
2958
3324
  get isTimelineDisabled() {
2959
3325
  return this.timelineDisabledState === TimelineDisabledState.disabled;
2960
3326
  }
3327
+ get durationMs() {
3328
+ return this.slideDuration;
3329
+ }
2961
3330
  async updateTimeline(action, showLoader = false, showError = false) {
2962
3331
  // два кейса
2963
3332
  // когда есть слои и у слоя вызываем showLayer который вызывает startTimer до старта слайда, потом start от sdk
@@ -2986,13 +3355,15 @@ class SlideTimeline {
2986
3355
  //@ts-ignore
2987
3356
  // window._log(`updateTimeline 1, a: ${action} ct: ${currentTime} d: ${duration} tds: ${this.timelineDisabledState}`, true);
2988
3357
  await this.slideReady.then();
2989
- //@ts-ignore
2990
3358
  // window._log(`updateTimeline, a: ${action} ct: ${currentTime} d: ${duration} tds: ${this.timelineDisabledState}`, true);
2991
- // console.trace(`updateTimeline ${action} slideIndex: ${this.slideIndex} currentTime:${currentTime} duration:${duration} tds: ${this.timelineDisabledState}`);
2992
- this.sdkApi.updateTimeline(this.slideIndex, action, currentTime, duration, showLoader, showError);
3359
+ // console.trace(`updateTimeline ${action} slideIndex: ${this.slideIndex} currentTime:${currentTime} duration:${duration} tds: ${this.timelineDisabledState} showLoader: ${showLoader} showError: ${showError}`);
3360
+ this.slideApiDeps.updateTimeline(this.slideIndex, action, currentTime, duration, showLoader, showError);
3361
+ if (action === "pause" /* TIMELINE_ACTION.PAUSE */ && showLoader) {
3362
+ this.dataWaitingStartedAt = Date.now();
3363
+ }
2993
3364
  }
2994
3365
  /**
2995
- * trigger timeline update for new slide in sdk, before slide strat event (prevent timeout in timeline while we wait for video start)
3366
+ * trigger timeline update for new slide in sdk, before slide start event (prevent timeout in timeline while we wait for video start)
2996
3367
  */
2997
3368
  triggerSlideLoadState() {
2998
3369
  if (this.isSDKSupportUpdateTimeline && this.isSdkSupportTimelineOnBeforeStart) {
@@ -3005,7 +3376,7 @@ class SlideTimeline {
3005
3376
  if (this.timelineDisabledState === TimelineDisabledState.disabled) {
3006
3377
  duration = 0;
3007
3378
  }
3008
- this.sdkApi.updateTimeline(this.slideIndex, "before_start" /* TIMELINE_ACTION.BEFORE_START */, 0, duration, false, false);
3379
+ this.slideApiDeps.updateTimeline(this.slideIndex, "before_start" /* TIMELINE_ACTION.BEFORE_START */, 0, duration, false, false);
3009
3380
  }
3010
3381
  }
3011
3382
  /**
@@ -3014,6 +3385,7 @@ class SlideTimeline {
3014
3385
  */
3015
3386
  slideStarted() {
3016
3387
  // console.trace("slideStarted");
3388
+ this.onBeforeStateChanged();
3017
3389
  if (this.isSDKSupportUpdateTimeline) {
3018
3390
  this.resumedAt = new Date().getTime();
3019
3391
  this.timeSpent = 0; // for case when instance exists, but we return to slide again
@@ -3022,6 +3394,7 @@ class SlideTimeline {
3022
3394
  }
3023
3395
  slideRestarted() {
3024
3396
  // console.trace("slideRestarted");
3397
+ this.onBeforeStateChanged();
3025
3398
  if (this.isSDKSupportUpdateTimeline) {
3026
3399
  this.resumedAt = new Date().getTime();
3027
3400
  this.timeSpent = 0;
@@ -3031,11 +3404,12 @@ class SlideTimeline {
3031
3404
  /**
3032
3405
  *
3033
3406
  */
3034
- slidePaused(videoCurrentTime) {
3407
+ slidePaused(currentTime) {
3035
3408
  // console.trace("slidePaused");
3409
+ this.onBeforeStateChanged();
3036
3410
  if (this.isSDKSupportUpdateTimeline) {
3037
- if (videoCurrentTime != null) {
3038
- this.timeSpent = Math.round(videoCurrentTime);
3411
+ if (currentTime != null) {
3412
+ this.timeSpent = Math.round(currentTime);
3039
3413
  }
3040
3414
  else {
3041
3415
  const globalCurrentTime = new Date().getTime();
@@ -3045,26 +3419,43 @@ class SlideTimeline {
3045
3419
  this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */);
3046
3420
  }
3047
3421
  else {
3048
- this.sdkApi.cardPausedCallback(videoCurrentTime);
3422
+ this.slideApiDeps.cardPausedCallback(currentTime);
3049
3423
  }
3050
3424
  }
3051
- slideResumed(videoCurrentTime) {
3425
+ slideResumed(getVideoCurrentTime) {
3052
3426
  // console.trace("slideResumed");
3427
+ this.onBeforeStateChanged();
3053
3428
  // @ts-ignore
3054
3429
  // window._log(`updateTimeline slideResumed ${videoCurrentTime}`, true);
3055
- if (this.isSDKSupportUpdateTimeline) {
3056
- if (videoCurrentTime != null) {
3057
- this.timeSpent = Math.round(videoCurrentTime);
3430
+ // dataWaitingStartedAt
3431
+ const slideResume = () => {
3432
+ if (this.isSDKSupportUpdateTimeline) {
3433
+ if (getVideoCurrentTime != null) {
3434
+ this.timeSpent = Math.round(getVideoCurrentTime());
3435
+ }
3436
+ this.resumedAt = new Date().getTime();
3437
+ this.updateTimeline("start" /* TIMELINE_ACTION.START */);
3058
3438
  }
3059
- this.resumedAt = new Date().getTime();
3060
- this.updateTimeline("start" /* TIMELINE_ACTION.START */);
3439
+ else {
3440
+ this.slideApiDeps.cardResumedCallback(getVideoCurrentTime != null ? getVideoCurrentTime() : null);
3441
+ }
3442
+ };
3443
+ // prevent micro loaders in UI
3444
+ const delay = 300;
3445
+ let dataWaitingLoaderSpent = delay;
3446
+ if (this.dataWaitingStartedAt != null) {
3447
+ dataWaitingLoaderSpent = Date.now() - this.dataWaitingStartedAt;
3448
+ }
3449
+ if (dataWaitingLoaderSpent < delay) {
3450
+ this.deferredResumeStateTimerId = window.setTimeout(slideResume, dataWaitingLoaderSpent - delay);
3061
3451
  }
3062
3452
  else {
3063
- this.sdkApi.cardResumedCallback(videoCurrentTime);
3453
+ slideResume();
3064
3454
  }
3065
3455
  }
3066
3456
  slideStopped() {
3067
3457
  // console.trace("slideStopped");
3458
+ this.onBeforeStateChanged();
3068
3459
  if (this.isSDKSupportUpdateTimeline) {
3069
3460
  this.updateTimeline("stop" /* TIMELINE_ACTION.STOP */);
3070
3461
  }
@@ -3074,6 +3465,7 @@ class SlideTimeline {
3074
3465
  * used by widgets
3075
3466
  */
3076
3467
  startDisabledTimeline(fallback) {
3468
+ this.onBeforeStateChanged();
3077
3469
  // if app is paused (in background) - don't call start timeline (Android issues)
3078
3470
  // @ts-ignore
3079
3471
  // window._log(`Push startDisabledTimeline to queue at state: ${window.slideApi.state}, time: ${new Date().getTime()}`, true);
@@ -3093,6 +3485,7 @@ class SlideTimeline {
3093
3485
  }
3094
3486
  onSlideDataWaiting(videoCurrentTime) {
3095
3487
  // console.trace("onSlideDataWaiting");
3488
+ this.onBeforeStateChanged();
3096
3489
  // @ts-ignore
3097
3490
  // window._log(`updateTimeline onSlideDataWaiting ${videoCurrentTime}`, true);
3098
3491
  if (videoCurrentTime != null) {
@@ -3103,10 +3496,20 @@ class SlideTimeline {
3103
3496
  let spent = globalCurrentTime - this.resumedAt;
3104
3497
  this.timeSpent += spent;
3105
3498
  }
3106
- this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3499
+ // prevent micro loaders in UI
3500
+ if (this.currentState === "start" /* TIMELINE_ACTION.START */) {
3501
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, false, false);
3502
+ this.deferredDataWaitingStateTimerId = window.setTimeout(() => {
3503
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3504
+ }, 300);
3505
+ }
3506
+ else {
3507
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3508
+ }
3107
3509
  }
3108
3510
  onSlideError(videoCurrentTime) {
3109
3511
  // console.trace("onSlideError");
3512
+ this.onBeforeStateChanged();
3110
3513
  if (videoCurrentTime != null) {
3111
3514
  this.timeSpent = Math.round(videoCurrentTime);
3112
3515
  }
@@ -3117,7 +3520,21 @@ class SlideTimeline {
3117
3520
  }
3118
3521
  this.updateTimeline("stop" /* TIMELINE_ACTION.STOP */, false, true);
3119
3522
  }
3120
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`number`, `number`, `boolean`, `Promise`, `(cb: () => void) => void`, `SDKApi`]; }
3523
+ clearDeferredDataWaitingStateTimerId() {
3524
+ if (this.deferredDataWaitingStateTimerId != null) {
3525
+ window.clearTimeout(this.deferredDataWaitingStateTimerId);
3526
+ }
3527
+ }
3528
+ clearDeferredResumeStateTimerId() {
3529
+ if (this.deferredResumeStateTimerId != null) {
3530
+ window.clearTimeout(this.deferredResumeStateTimerId);
3531
+ }
3532
+ }
3533
+ onBeforeStateChanged() {
3534
+ this.clearDeferredDataWaitingStateTimerId();
3535
+ this.clearDeferredResumeStateTimerId();
3536
+ }
3537
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`number`, `number`, `boolean`, `Promise`, `(cb: () => void) => void`, `ISlideApiDeps`]; }
3121
3538
  }
3122
3539
 
3123
3540
  class Layer {
@@ -3126,8 +3543,7 @@ class Layer {
3126
3543
  _slideReadyPromise;
3127
3544
  _afterAppResumeQueuePush;
3128
3545
  _afterStartInitQueuePush;
3129
- _showNextSlide;
3130
- sdkApi;
3546
+ slideApiDeps;
3131
3547
  _slideRoot;
3132
3548
  _getLayoutDirection;
3133
3549
  _slidePauseUI;
@@ -3143,14 +3559,13 @@ class Layer {
3143
3559
  _elements = [];
3144
3560
  _timeline;
3145
3561
  _widgetDeps;
3146
- constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, _showNextSlide, sdkApi, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3562
+ constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3147
3563
  this._nodeRef = _nodeRef;
3148
3564
  this._slide = _slide;
3149
3565
  this._slideReadyPromise = _slideReadyPromise;
3150
3566
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3151
3567
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
3152
- this._showNextSlide = _showNextSlide;
3153
- this.sdkApi = sdkApi;
3568
+ this.slideApiDeps = slideApiDeps;
3154
3569
  this._slideRoot = _slideRoot;
3155
3570
  this._getLayoutDirection = _getLayoutDirection;
3156
3571
  this._slidePauseUI = _slidePauseUI;
@@ -3163,16 +3578,16 @@ class Layer {
3163
3578
  this._duration = parseInt(this._nodeRef.getAttribute("data-duration") ?? "") || DEFAULT_SLIDE_DURATION;
3164
3579
  this._disabledTimer = this._nodeRef.getAttribute("data-disable-timer") === "1";
3165
3580
  this._disabledNavigation = this._nodeRef.getAttribute("data-disable-navigation") === "1";
3166
- this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.sdkApi);
3581
+ this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.slideApiDeps);
3167
3582
  this._widgetDeps = {
3168
- sdkApi: this.sdkApi,
3583
+ slideApiDeps: this.slideApiDeps,
3169
3584
  slideRoot: this._slideRoot,
3170
3585
  getLayoutDirection: this._getLayoutDirection,
3171
3586
  getSdkClientVariables: this._getSdkClientVariables,
3172
3587
  };
3173
3588
  const onWidgetComplete = (cardId, slideIndex) => {
3174
3589
  // todo if nothing more widgets with disabled timers - we can start layer timeline
3175
- const fallback = () => this._showNextSlide(DEFAULT_SLIDE_DURATION);
3590
+ const fallback = () => this.slideApiDeps.showNextSlide(DEFAULT_SLIDE_DURATION);
3176
3591
  // для android sdk важно чтобы этот метод вызывался только после slide_start
3177
3592
  this._afterStartInitQueuePush(() => {
3178
3593
  this._timeline.startDisabledTimeline(fallback);
@@ -3214,16 +3629,17 @@ class Layer {
3214
3629
  }
3215
3630
  }
3216
3631
  init(localData) {
3217
- if (this.sdkApi.isIOS || this.sdkApi.isAndroid) {
3632
+ if (this.slideApiDeps.isIOS || this.slideApiDeps.isAndroid) {
3218
3633
  this._nodeRef.classList.add("_app");
3219
- this.sdkApi.isIOS && this._nodeRef.classList.add("_isIos");
3220
- this.sdkApi.isAndroid && this._nodeRef.classList.add("_isAndroid");
3634
+ this.slideApiDeps.isIOS && this._nodeRef.classList.add("_isIos");
3635
+ this.slideApiDeps.isAndroid && this._nodeRef.classList.add("_isAndroid");
3221
3636
  }
3637
+ this.slideApiDeps.cardAnimation?.init(this._nodeRef);
3222
3638
  const promises = this._elements.map(element => element.init(localData));
3223
3639
  return promises;
3224
3640
  }
3225
3641
  onAfterAllMediaResourcesLoaded() {
3226
- if (this.sdkApi.isIOS) ;
3642
+ if (this.slideApiDeps.isIOS) ;
3227
3643
  this._initTextFit();
3228
3644
  }
3229
3645
  get nodeRef() {
@@ -3242,7 +3658,10 @@ class Layer {
3242
3658
  return container.get({ identifier: "LayoutService" });
3243
3659
  }
3244
3660
  getLocalData() {
3245
- return this.sdkApi.getCardLocalData();
3661
+ return this.slideApiDeps.getCardLocalData();
3662
+ }
3663
+ findElementByNodeRef(nodeRef) {
3664
+ return this._elements.find(element => element.nodeRef === nodeRef);
3246
3665
  }
3247
3666
  get isQuest() {
3248
3667
  return this._nodeRef.getAttribute("data-quest-count") != null;
@@ -3395,14 +3814,19 @@ class Layer {
3395
3814
  const videoElement = this.videoElement;
3396
3815
  let currentTime = 0;
3397
3816
  if (videoElement != null) {
3398
- let videoLoop = false;
3399
- if (this.timeline.isTimelineDisabled) {
3400
- videoLoop = true;
3401
- }
3402
- currentTime = (await videoElement.start(muted, videoLoop)).currentTime;
3817
+ const getVideoIsLooped = () => {
3818
+ let videoLoop = false;
3819
+ if (this.timeline.isTimelineDisabled || this.timeline.durationMs > videoElement.durationMs) {
3820
+ videoLoop = true;
3821
+ }
3822
+ // console.log({videoLoop, isTimelineDisabled: this.timeline.isTimelineDisabled, timelineDurationMs: this.timeline.durationMs, videoElementDurationMs: videoElement.durationMs});
3823
+ return videoLoop;
3824
+ };
3825
+ // todo - need to convert to ms ?
3826
+ currentTime = (await videoElement.start(muted, getVideoIsLooped)).getVideoCurrentTime();
3403
3827
  }
3404
- if (this.sdkApi.cardAnimation) {
3405
- this._animationPauseCb = this.sdkApi.cardAnimation.start(this._nodeRef);
3828
+ if (this.slideApiDeps.cardAnimation) {
3829
+ this._animationPauseCb = this.slideApiDeps.cardAnimation.start(this._nodeRef);
3406
3830
  }
3407
3831
  for (const element of this._elements) {
3408
3832
  element.onStart();
@@ -3418,7 +3842,7 @@ class Layer {
3418
3842
  }
3419
3843
  async stop(options) {
3420
3844
  this.videoElement?.stop(options);
3421
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3845
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3422
3846
  for (const element of this._elements) {
3423
3847
  element.onPause();
3424
3848
  }
@@ -3429,7 +3853,7 @@ class Layer {
3429
3853
  }
3430
3854
  stopInternal(options) {
3431
3855
  this.videoElement?.stop(options);
3432
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3856
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3433
3857
  for (const element of this._elements) {
3434
3858
  element.onPause();
3435
3859
  }
@@ -3441,17 +3865,21 @@ class Layer {
3441
3865
  return new Promise(resolve => {
3442
3866
  const cb = () => {
3443
3867
  let currentTime = this.videoElement?.pause(resetVideoTime) ?? null;
3868
+ if (this.videoElement?.isLooped) {
3869
+ // skip currentTime from looped video (bcz in that case video time does not associated with timeline)
3870
+ currentTime = null;
3871
+ }
3872
+ if (currentTime != null) {
3873
+ currentTime *= 1000;
3874
+ }
3444
3875
  if (stopAnimation) {
3445
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3876
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3446
3877
  }
3447
3878
  else {
3448
3879
  if (this._animationPauseCb != null && isFunction(this._animationPauseCb)) {
3449
3880
  this._animationResumeCb = this._animationPauseCb(false);
3450
3881
  }
3451
3882
  }
3452
- if (currentTime != null) {
3453
- currentTime *= 1000;
3454
- }
3455
3883
  for (const element of this._elements) {
3456
3884
  element.onPause();
3457
3885
  }
@@ -3471,26 +3899,23 @@ class Layer {
3471
3899
  }
3472
3900
  async resume() {
3473
3901
  return new Promise(resolve => {
3474
- const cb = ({ currentTime }) => {
3902
+ const cb = ({ getVideoCurrentTime }) => {
3475
3903
  // console.log("resumed cb with currentTime", { currentTime });
3476
- if (currentTime != null) {
3477
- currentTime *= 1000;
3478
- }
3479
3904
  if (isFunction(this._animationResumeCb)) {
3480
3905
  this._animationResumeCb();
3481
3906
  }
3482
3907
  for (const element of this._elements) {
3483
3908
  element.onResume();
3484
3909
  }
3485
- this.timeline.slideResumed(currentTime);
3486
- resolve({ currentTime });
3910
+ this.timeline.slideResumed(getVideoCurrentTime != null ? () => getVideoCurrentTime() * 1000 : undefined);
3911
+ resolve({ currentTime: getVideoCurrentTime != null ? getVideoCurrentTime() : null });
3487
3912
  };
3488
3913
  const videoStartedPromise = this.videoElement?.resume();
3489
3914
  if (videoStartedPromise != null && videoStartedPromise.then != null) {
3490
3915
  videoStartedPromise.then(cb);
3491
3916
  }
3492
3917
  else {
3493
- cb({ currentTime: null });
3918
+ cb({ getVideoCurrentTime: undefined });
3494
3919
  }
3495
3920
  });
3496
3921
  }
@@ -3506,7 +3931,7 @@ class Layer {
3506
3931
  get isLayerForcePaused() {
3507
3932
  return this.elements.some(element => element.isLayerForcePaused);
3508
3933
  }
3509
- 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`]; }
3934
+ 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`]; }
3510
3935
  }
3511
3936
  const TextFit = (function () {
3512
3937
  const defaultSettings = {
@@ -3697,8 +4122,7 @@ class Slide {
3697
4122
  _slideReadyPromise;
3698
4123
  _afterAppResumeQueuePush;
3699
4124
  _afterStartInitQueuePush;
3700
- _showNextSlide;
3701
- sdkApi;
4125
+ slideApiDeps;
3702
4126
  _slideRoot;
3703
4127
  _getLayoutDirection;
3704
4128
  _slidePauseUI;
@@ -3706,13 +4130,12 @@ class Slide {
3706
4130
  _getSdkClientVariables;
3707
4131
  _layers;
3708
4132
  _start;
3709
- constructor(_slidesNodesRefs, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, _showNextSlide, sdkApi, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
4133
+ constructor(_slidesNodesRefs, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3710
4134
  this._slidesNodesRefs = _slidesNodesRefs;
3711
4135
  this._slideReadyPromise = _slideReadyPromise;
3712
4136
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3713
4137
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
3714
- this._showNextSlide = _showNextSlide;
3715
- this.sdkApi = sdkApi;
4138
+ this.slideApiDeps = slideApiDeps;
3716
4139
  this._slideRoot = _slideRoot;
3717
4140
  this._getLayoutDirection = _getLayoutDirection;
3718
4141
  this._slidePauseUI = _slidePauseUI;
@@ -3722,7 +4145,7 @@ class Slide {
3722
4145
  if (!this._slidesNodesRefs.length) {
3723
4146
  throw new Error("No slides found.");
3724
4147
  }
3725
- 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));
4148
+ 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));
3726
4149
  this._activeLayer = this._layers[0];
3727
4150
  }
3728
4151
  _activeLayer;
@@ -3742,7 +4165,7 @@ class Slide {
3742
4165
  if (multiSlideApi != null && this.layers.length > 1) {
3743
4166
  try {
3744
4167
  multiSlideApi.init(this.layersNodesRefs, localData, {
3745
- sdkApi: this.sdkApi,
4168
+ slideApiDeps: this.slideApiDeps,
3746
4169
  slideRoot: this._slideRoot,
3747
4170
  getLayoutDirection: this._getLayoutDirection,
3748
4171
  getSdkClientVariables: this._getSdkClientVariables,
@@ -3819,10 +4242,10 @@ class Slide {
3819
4242
  get disabledNavigation() {
3820
4243
  return this._activeLayer.disabledNavigation;
3821
4244
  }
3822
- 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`]; }
4245
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Array`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `ISlideApiDeps`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
3823
4246
  }
3824
4247
 
3825
- class CardApi {
4248
+ let SlideApi$1 = class SlideApi {
3826
4249
  config;
3827
4250
  get layoutDirection() {
3828
4251
  // warning, detection in ctor not working, bcz sdk changes layout later
@@ -3837,10 +4260,10 @@ class CardApi {
3837
4260
  _overlappingActionBarHeight;
3838
4261
  _separateUserAndAppPause;
3839
4262
  _index;
3840
- sdkApi;
4263
+ slideApiDeps;
3841
4264
  constructor(config) {
3842
4265
  this.config = config;
3843
- this.sdkApi = config.sdkApi;
4266
+ this.slideApiDeps = config.slideApiDeps;
3844
4267
  this._slideWrapper = config.slideWrapper;
3845
4268
  this._viewport = config.viewport;
3846
4269
  this._getViewportWidth = config.getViewportWidth;
@@ -3849,7 +4272,15 @@ class CardApi {
3849
4272
  this._separateUserAndAppPause = config.separateUserAndAppPause;
3850
4273
  this._index = config.index;
3851
4274
  }
3852
- checkAndInitPreloadedInLayoutSlide(slideLoadedCb) {
4275
+ static checkPreloadedInLayoutSlide() {
4276
+ // for sdk backward compatibility
4277
+ const slideBox = document.getElementById("narrative-slide-box");
4278
+ if (slideBox && slideBox.innerText.trim() !== "{%content}".replace("{", "{{").replace("}", "}}")) {
4279
+ return true;
4280
+ }
4281
+ return false;
4282
+ }
4283
+ initPreloadedInLayoutSlide(slideLoadedCb) {
3853
4284
  // for sdk backward compatibility
3854
4285
  const slideBox = document.getElementById("narrative-slide-box");
3855
4286
  // todo via first child and its innerText - faster variant
@@ -3864,7 +4295,7 @@ class CardApi {
3864
4295
  });
3865
4296
  }
3866
4297
  }
3867
- onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, }) {
4298
+ onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, slideOffsetMargin }) {
3868
4299
  // todo CSP violation
3869
4300
  this._slideWrapper.style.fontSize = fontSize;
3870
4301
  if (this.slideOffsetElement != null) {
@@ -3877,6 +4308,7 @@ class CardApi {
3877
4308
  else {
3878
4309
  this.slideOffsetElement.classList.remove("narrative-slide-offset-fullscreen");
3879
4310
  }
4311
+ this.slideOffsetElement.style.margin = slideOffsetMargin;
3880
4312
  }
3881
4313
  }
3882
4314
  get slideWrapperElement() {
@@ -3895,8 +4327,8 @@ class CardApi {
3895
4327
  this._state = 13 /* STATE.DESTROYED */;
3896
4328
  }
3897
4329
  async showSlide(html) {
3898
- const slideBox = this._slideWrapper.querySelector(`.${CardApi.renderedBoxClassName}`);
3899
- const slideBoxPrerender = this._slideWrapper.querySelector(`.${CardApi.prerenderBoxClassName}`);
4330
+ const slideBox = this._slideWrapper.querySelector(`.${SlideApi.renderedBoxClassName}`);
4331
+ const slideBoxPrerender = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName}`);
3900
4332
  const _result = { cardId: this.slide?.cardId ?? 0, slideIndex: this.slide?.slideIndex ?? 0, result: false, reason: "" };
3901
4333
  if (slideBox && slideBoxPrerender) {
3902
4334
  if (this._slideInRender) {
@@ -3916,7 +4348,7 @@ class CardApi {
3916
4348
  }
3917
4349
  else {
3918
4350
  _result.result = false;
3919
- _result.reason = `Element .${CardApi.renderedBoxClassName} or .${CardApi.prerenderBoxClassName} does not found in DOM`;
4351
+ _result.reason = `Element .${SlideApi.renderedBoxClassName} or .${SlideApi.prerenderBoxClassName} does not found in DOM`;
3920
4352
  }
3921
4353
  _result.cardId = this.slide.cardId;
3922
4354
  _result.slideIndex = this.slide.slideIndex;
@@ -3929,7 +4361,7 @@ class CardApi {
3929
4361
  return container.get({ identifier: "LayoutService" });
3930
4362
  }
3931
4363
  getLocalData() {
3932
- return this.sdkApi.getCardLocalData();
4364
+ return this.slideApiDeps.getCardLocalData();
3933
4365
  }
3934
4366
  _fontsInit = false;
3935
4367
  _initAndLoadFonts(fonts) {
@@ -4021,9 +4453,9 @@ class CardApi {
4021
4453
  /**
4022
4454
  * For case when SlideApi instance was created before root was attached to DOM
4023
4455
  */
4024
- this.config.refreshSizes();
4025
- const slideNodeRef = this._slideWrapper.querySelector(`.${CardApi.prerenderBoxClassName} .narrative-slide`);
4026
- const slidesNodesRefs = Array.prototype.slice.call(this._slideWrapper.querySelectorAll(`.${CardApi.prerenderBoxClassName} .narrative-slide.narrative-multi-slide`));
4456
+ // this.config.refreshSizes(this);
4457
+ const slideNodeRef = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName} .narrative-slide`);
4458
+ const slidesNodesRefs = Array.prototype.slice.call(this._slideWrapper.querySelectorAll(`.${SlideApi.prerenderBoxClassName} .narrative-slide.narrative-multi-slide`));
4027
4459
  if (!slidesNodesRefs.length && slideNodeRef != null) {
4028
4460
  slidesNodesRefs.push(slideNodeRef);
4029
4461
  }
@@ -4034,17 +4466,18 @@ class CardApi {
4034
4466
  const slideReadyPromise = new Promise(resolve => {
4035
4467
  slideReadyResolve = resolve;
4036
4468
  });
4037
- 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.config.getSdkClientVariables);
4469
+ 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);
4038
4470
  this._slideInInit = slide;
4471
+ // todo - call via DI
4039
4472
  slide.activeLayer.timeline.triggerSlideLoadState();
4040
- if (this.sdkApi.isAndroid) {
4473
+ if (this.slideApiDeps.isAndroid) {
4041
4474
  this._afterStartInitQueue = [];
4042
4475
  }
4043
4476
  this._afterAppResumeQueue = [];
4044
4477
  const result = { slide, result: false, reason: "" };
4045
4478
  try {
4046
4479
  const onAllMediaLoaded = this._onAllMediaLoaded(slide);
4047
- const fontsPromise = this._initAndLoadFonts(this.sdkApi.getCardFonts());
4480
+ const fontsPromise = this._initAndLoadFonts(this.slideApiDeps.getCardFonts());
4048
4481
  const mediaAndFontsPromise = Promise.all([onAllMediaLoaded, fontsPromise]).then(() => {
4049
4482
  this.layoutService.env.clearTimeout(mediaResourcesTimeoutId);
4050
4483
  });
@@ -4096,12 +4529,12 @@ class CardApi {
4096
4529
  return;
4097
4530
  }
4098
4531
  return new Promise(resolve => {
4099
- const slideBox = this._slideWrapper.querySelector(`.${CardApi.renderedBoxClassName}`);
4100
- const slideBoxPrerender = this._slideWrapper.querySelector(`.${CardApi.prerenderBoxClassName}`);
4532
+ const slideBox = this._slideWrapper.querySelector(`.${SlideApi.renderedBoxClassName}`);
4533
+ const slideBoxPrerender = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName}`);
4101
4534
  if (slideBox && slideBoxPrerender) {
4102
- slideBoxPrerender.classList.remove(CardApi.prerenderBoxClassName);
4103
- slideBox.classList.remove(CardApi.renderedBoxClassName);
4104
- slideBox.classList.add(CardApi.prerenderBoxClassName);
4535
+ slideBoxPrerender.classList.remove(SlideApi.prerenderBoxClassName);
4536
+ slideBox.classList.remove(SlideApi.renderedBoxClassName);
4537
+ slideBox.classList.add(SlideApi.prerenderBoxClassName);
4105
4538
  // pause Video - prevent triggering onDataWaiting from VODPlayer
4106
4539
  prevSlide?.activeLayer.pause(false, true, false);
4107
4540
  // 2 RAF - wait for browser render complete (CSS changes, etc.)
@@ -4125,7 +4558,7 @@ class CardApi {
4125
4558
  else {
4126
4559
  resolve();
4127
4560
  }
4128
- slideBoxPrerender.classList.add(CardApi.renderedBoxClassName);
4561
+ slideBoxPrerender.classList.add(SlideApi.renderedBoxClassName);
4129
4562
  }
4130
4563
  else {
4131
4564
  resolve();
@@ -4143,7 +4576,7 @@ class CardApi {
4143
4576
  this._slideConfig = config;
4144
4577
  // start deferred fncs from widgets
4145
4578
  // important - Android only
4146
- if (this.sdkApi.isAndroid && this._afterStartInitQueue && Array.isArray(this._afterStartInitQueue)) {
4579
+ if (this.slideApiDeps.isAndroid && this._afterStartInitQueue && Array.isArray(this._afterStartInitQueue)) {
4147
4580
  for (const job of this._afterStartInitQueue) {
4148
4581
  if (isFunction(job)) {
4149
4582
  job();
@@ -4197,7 +4630,7 @@ class CardApi {
4197
4630
  this._state = 9 /* STATE.USER_PAUSED */;
4198
4631
  };
4199
4632
  // todo move to Android adapter
4200
- if (this.sdkApi.isAndroid && !this.sdkApi.isSdkSupportCorrectPauseResumeLifecycle()) {
4633
+ if (this.slideApiDeps.isAndroid && !this.slideApiDeps.isSdkSupportCorrectPauseResumeLifecycle()) {
4201
4634
  this._pauseCbTimer = this.layoutService.env.setTimeout(pauseCb, 300);
4202
4635
  }
4203
4636
  else {
@@ -4271,10 +4704,10 @@ class CardApi {
4271
4704
  const defaultAction = () => {
4272
4705
  const nextSlideIndex = this.slide.slideIndex + 1;
4273
4706
  if (nextSlideIndex >= 0 && nextSlideIndex < this.slide.slideCount) {
4274
- this.sdkApi.showCardSlide(nextSlideIndex);
4707
+ this.slideApiDeps.showCardSlide(nextSlideIndex);
4275
4708
  }
4276
4709
  else {
4277
- this.sdkApi.cardShowNext();
4710
+ this.slideApiDeps.cardShowNext();
4278
4711
  }
4279
4712
  };
4280
4713
  if (this.activeLayer.questElement) {
@@ -4321,7 +4754,7 @@ class CardApi {
4321
4754
  if (!isFunction(cb)) {
4322
4755
  return false;
4323
4756
  }
4324
- if (this.sdkApi.isAndroid && this._state === 0 /* STATE.INIT */) {
4757
+ if (this.slideApiDeps.isAndroid && this._state === 0 /* STATE.INIT */) {
4325
4758
  this._afterStartInitQueue.push(cb);
4326
4759
  }
4327
4760
  else {
@@ -4450,7 +4883,7 @@ class CardApi {
4450
4883
  if (this.layoutService.layoutApi.widgetVoteApi) {
4451
4884
  if (this.layoutService.layoutApi.widgetVoteApi.click(element)) {
4452
4885
  this.layoutService.env.setTimeout(() => {
4453
- this.sdkApi.showNextSlide(0);
4886
+ this.slideApiDeps.showNextSlide(0);
4454
4887
  });
4455
4888
  }
4456
4889
  result.canClickNext = false;
@@ -4474,7 +4907,7 @@ class CardApi {
4474
4907
  }
4475
4908
  if (element) {
4476
4909
  this.layoutService.env.setTimeout(() => {
4477
- this.sdkApi.showNextSlide(0);
4910
+ this.slideApiDeps.showNextSlide(0);
4478
4911
  });
4479
4912
  result.canClickNext = false;
4480
4913
  return result;
@@ -4502,7 +4935,7 @@ class CardApi {
4502
4935
  if (this.layoutService.layoutApi.widgetRangeSliderApi) {
4503
4936
  if (this.layoutService.layoutApi.widgetRangeSliderApi.click(element)) {
4504
4937
  this.layoutService.env.setTimeout(() => {
4505
- this.sdkApi.showNextSlide(0);
4938
+ this.slideApiDeps.showNextSlide(0);
4506
4939
  });
4507
4940
  }
4508
4941
  result.canClickNext = false;
@@ -4709,18 +5142,18 @@ class CardApi {
4709
5142
  }
4710
5143
  if (element) {
4711
5144
  propagation = false;
4712
- this.sdkApi.setCardLocalData({}, true);
4713
- this.sdkApi.updateCardServerDataLocally(this.slide.cardId, {});
5145
+ this.slideApiDeps.setCardLocalData({}, true);
5146
+ this.slideApiDeps.updateCardServerDataLocally(this.slide.cardId, {});
4714
5147
  // window._resetTimers();
4715
5148
  // сделать async в ios
4716
5149
  let slideIndex = this.slide.slideIndex;
4717
5150
  // prevent simultaneous call _showNarrativeSlide and _showLayer - prevent 2 calls of initAfterLoad (break video start on iOS)
4718
5151
  if (slideIndex === 0) {
4719
5152
  // for story repeat on the first slide with layers
4720
- this.sdkApi.showLayer(0);
5153
+ this.slideApiDeps.showLayer(0);
4721
5154
  }
4722
5155
  else {
4723
- this.sdkApi.showCardSlide(0); // сделать ее async
5156
+ this.slideApiDeps.showCardSlide(0); // сделать ее async
4724
5157
  }
4725
5158
  }
4726
5159
  // todo в каждом виджете делать выход через
@@ -4808,44 +5241,44 @@ class CardApi {
4808
5241
  // this.activeLayer.timeline.slidePaused(0);
4809
5242
  // return {handled: true};
4810
5243
  }
4811
- if (this.sdkApi.isAndroid && linkTargetAndroid) {
5244
+ if (this.slideApiDeps.isAndroid && linkTargetAndroid) {
4812
5245
  linkTarget = linkTargetAndroid;
4813
5246
  }
4814
- if (this.sdkApi.isIOS && linkTargetIos) {
5247
+ if (this.slideApiDeps.isIOS && linkTargetIos) {
4815
5248
  linkTarget = linkTargetIos;
4816
5249
  }
4817
- if (this.sdkApi.isWeb && linkTargetWeb) {
5250
+ if (this.slideApiDeps.isWeb && linkTargetWeb) {
4818
5251
  linkTarget = linkTargetWeb;
4819
5252
  }
4820
5253
  // for btn(link) without url (openGame, openStory, closeCard, products, goods, etc)
4821
5254
  let statisticWidgetValue = linkType;
4822
5255
  let statisticWidgetEventType = "w-link";
4823
5256
  if (linkType === "closeStory" || linkType === "closeIAM") {
4824
- this.layoutService.env.setTimeout(() => this.sdkApi.closeCard("click"));
5257
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.closeCard("click"));
4825
5258
  handled = true;
4826
5259
  }
4827
5260
  else if (linkType && linkTarget) {
4828
5261
  if (linkType === "story") {
4829
5262
  // storyId: number, slideIndex: number
4830
- this.layoutService.env.setTimeout(() => this.sdkApi.openStory(parseInt(linkTarget), 0));
5263
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.openStory(parseInt(linkTarget), 0));
4831
5264
  handled = true;
4832
5265
  }
4833
5266
  else if (linkType === "slide") {
4834
5267
  const __slideIndex = parseInt(linkTarget);
4835
5268
  const __slideCount = this.slide.slideCount;
4836
5269
  if (__slideIndex >= 0 && __slideIndex < __slideCount) {
4837
- this.layoutService.env.setTimeout(() => this.sdkApi.showCardSlide(__slideIndex));
5270
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.showCardSlide(__slideIndex));
4838
5271
  handled = true;
4839
5272
  }
4840
5273
  }
4841
5274
  else if (linkType === "game") {
4842
- this.layoutService.env.setTimeout(() => this.sdkApi.openGame(linkTarget));
5275
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.openGame(linkTarget));
4843
5276
  handled = true;
4844
5277
  }
4845
5278
  else if (linkType === "layer") {
4846
5279
  const layerIndex = parseInt(linkTarget);
4847
5280
  if (layerIndex >= 0) {
4848
- this.layoutService.env.setTimeout(() => this.sdkApi.showLayer(layerIndex));
5281
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.showLayer(layerIndex));
4849
5282
  handled = true;
4850
5283
  }
4851
5284
  }
@@ -4853,7 +5286,7 @@ class CardApi {
4853
5286
  // traditional link, with url
4854
5287
  statisticWidgetValue = linkTarget;
4855
5288
  this.layoutService.env.setTimeout(() => {
4856
- this.sdkApi.openUrl({
5289
+ this.slideApiDeps.openUrl({
4857
5290
  type: isSwipeUpAction ? "swipeUpLink" : "link",
4858
5291
  link: {
4859
5292
  type: "url",
@@ -4863,6 +5296,12 @@ class CardApi {
4863
5296
  });
4864
5297
  handled = true;
4865
5298
  }
5299
+ else if (linkType === "promocode") {
5300
+ handled = this.activeLayer.findElementByNodeRef(element)?.handleClick() ?? true;
5301
+ if (!handled) {
5302
+ return { handled: true };
5303
+ }
5304
+ }
4866
5305
  else if (linkType === "products") {
4867
5306
  if (this.layoutService.layoutApi.widgetProductsApi) {
4868
5307
  this.layoutService.layoutApi.widgetProductsApi.click(element);
@@ -4872,7 +5311,7 @@ class CardApi {
4872
5311
  else if (linkType === "swipe-up-items") {
4873
5312
  const target = linkTarget;
4874
5313
  this.layoutService.env.setTimeout(() => {
4875
- this.sdkApi.openUrl({
5314
+ this.slideApiDeps.openUrl({
4876
5315
  type: "swipeUpItems",
4877
5316
  link: {
4878
5317
  type: "json",
@@ -4908,7 +5347,7 @@ class CardApi {
4908
5347
  baseFields.message_id = cardId;
4909
5348
  break;
4910
5349
  }
4911
- this.sdkApi.sendStatisticEvent(statisticWidgetEventType, {
5350
+ this.slideApiDeps.sendStatisticEvent(statisticWidgetEventType, {
4912
5351
  i: cardId,
4913
5352
  si: slideIndex,
4914
5353
  wi: elementId,
@@ -4965,7 +5404,7 @@ class CardApi {
4965
5404
  }
4966
5405
  }
4967
5406
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
4968
- sdkApi: SDKApi;
5407
+ slideApiDeps: ISlideApiDeps;
4969
5408
  slideWrapper: HTMLElement;
4970
5409
  viewport: Window;
4971
5410
  userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
@@ -4977,29 +5416,435 @@ class CardApi {
4977
5416
  separateUserAndAppPause: boolean;
4978
5417
  root: HTMLElement;
4979
5418
  nonce?: string;
4980
- refreshSizes: () => void;
5419
+ // refreshSizes: (slide: SlideApi) => void;
4981
5420
  index: number;
4982
5421
  getSdkClientVariables: GetSdkClientVariables;
4983
5422
  }`]; }
5423
+ };
5424
+
5425
+ class SlideApiDepsMultiSlideMode {
5426
+ sdkApi;
5427
+ slider;
5428
+ constructor(sdkApi, slider) {
5429
+ this.sdkApi = sdkApi;
5430
+ this.slider = slider;
5431
+ }
5432
+ getWidgetsSharedData(cardId, widget) {
5433
+ return this.sdkApi.getWidgetsSharedData(cardId, widget);
5434
+ }
5435
+ showToast(text) {
5436
+ return this.sdkApi.showToast(text);
5437
+ }
5438
+ writeToClipboard(data) {
5439
+ return this.sdkApi.writeToClipboard(data);
5440
+ }
5441
+ get isExistsShare() {
5442
+ return this.sdkApi.isExistsShare;
5443
+ }
5444
+ share(id, config) {
5445
+ this.sdkApi.share(id, config);
5446
+ }
5447
+ get sdkCanSendShareComplete() {
5448
+ return this.sdkApi.sdkCanSendShareComplete;
5449
+ }
5450
+ shareSlideScreenshot(shareId, hideElementsSelector, shareText) {
5451
+ this.sdkApi.shareSlideScreenshot(shareId, hideElementsSelector, shareText);
5452
+ }
5453
+ setCardSessionValue(element, key, value) {
5454
+ this.sdkApi.setCardSessionValue(element, key, value);
5455
+ }
5456
+ getCardSessionValue(element, key) {
5457
+ return this.sdkApi.getCardSessionValue(element, key);
5458
+ }
5459
+ getCardFonts() {
5460
+ return this.sdkApi.getCardFonts();
5461
+ }
5462
+ disableVerticalSwipeGesture() {
5463
+ this.sdkApi.disableVerticalSwipeGesture();
5464
+ }
5465
+ enableVerticalSwipeGesture() {
5466
+ this.sdkApi.enableVerticalSwipeGesture();
5467
+ }
5468
+ disableBackpress() {
5469
+ this.sdkApi.disableBackpress();
5470
+ }
5471
+ enableBackpress() {
5472
+ this.sdkApi.enableBackpress();
5473
+ }
5474
+ closeCard(reason) {
5475
+ this.sdkApi.closeCard(reason);
5476
+ }
5477
+ openStory(id, index) {
5478
+ // TODO rewrite with Promise - for usage story loading states in Button
5479
+ this.sdkApi.openStory(id, index);
5480
+ }
5481
+ openGame(gameInstanceId) {
5482
+ // TODO rewrite with Promise - for usage game loading states in Button
5483
+ this.sdkApi.openGame(gameInstanceId);
5484
+ }
5485
+ openUrl(data) {
5486
+ this.sdkApi.openUrl(data);
5487
+ }
5488
+ get isAndroid() {
5489
+ return this.sdkApi.isAndroid;
5490
+ }
5491
+ get isWeb() {
5492
+ return this.sdkApi.isWeb;
5493
+ }
5494
+ get isIOS() {
5495
+ return this.sdkApi.isIOS;
5496
+ }
5497
+ get isExistsShowCardTextInput() {
5498
+ return this.sdkApi.isExistsShowCardTextInput;
5499
+ }
5500
+ showCardTextInput(id, data) {
5501
+ this.sdkApi.showCardTextInput(id, data);
5502
+ }
5503
+ vibrate(pattern) {
5504
+ this.sdkApi.vibrate(pattern);
5505
+ }
5506
+ sendApiRequest(url, method, params, headers, data, profilingKey) {
5507
+ return this.sdkApi.sendApiRequest(url, method, params, headers, data, profilingKey);
5508
+ }
5509
+ sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2) {
5510
+ this.sdkApi.sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2);
5511
+ }
5512
+ setCardLocalData(keyValue, sendToServer) {
5513
+ this.sdkApi.setCardLocalData(keyValue, sendToServer);
5514
+ }
5515
+ getCardLocalData() {
5516
+ return this.sdkApi.getCardLocalData();
5517
+ }
5518
+ getCardServerData(cardId) {
5519
+ return this.sdkApi.getCardServerData(cardId);
5520
+ }
5521
+ get cardAnimation() {
5522
+ return this.sdkApi.cardAnimation;
5523
+ }
5524
+ updateCardServerDataLocally(cardId, data) {
5525
+ this.sdkApi.updateCardServerDataLocally(cardId, data);
5526
+ }
5527
+ get isExistsShowNextCard() {
5528
+ return this.sdkApi.isExistsShowNextCard;
5529
+ }
5530
+ cardShowNext() {
5531
+ this.sdkApi.cardShowNext();
5532
+ }
5533
+ /** @deprecated, used only in native sdk **/
5534
+ cardPausedCallback(currentTime) {
5535
+ this.sdkApi.cardPausedCallback(currentTime);
5536
+ }
5537
+ /** @deprecated, used only in native sdk **/
5538
+ cardResumedCallback(currentTime) {
5539
+ this.sdkApi.cardResumedCallback(currentTime);
5540
+ }
5541
+ disableHorizontalSwipeGesture() {
5542
+ this.sdkApi.disableHorizontalSwipeGesture();
5543
+ }
5544
+ enableHorizontalSwipeGesture() {
5545
+ this.sdkApi.enableHorizontalSwipeGesture();
5546
+ }
5547
+ isExistsShowLayer() {
5548
+ return this.sdkApi.isExistsShowLayer();
5549
+ }
5550
+ showLayer(index) {
5551
+ this.sdkApi.showLayer(index);
5552
+ }
5553
+ /**
5554
+ * For single slide mode - proxy these methods via SDKApi
5555
+ * =================================================================================================================
5556
+ */
5557
+ get isExistsShowCardSlide() {
5558
+ return true;
5559
+ }
5560
+ showCardSlide(index) {
5561
+ this.slider.showByIndex(index);
5562
+ }
5563
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
5564
+ this.slider.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
5565
+ }
5566
+ isSdkSupportTimelineOnBeforeStart() {
5567
+ return true;
5568
+ }
5569
+ isSdkSupportCorrectPauseResumeLifecycle() {
5570
+ return true;
5571
+ }
5572
+ showNextSlide(duration) {
5573
+ this.slider.showNextSlide();
5574
+ }
5575
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`, `ISlider`]; }
4984
5576
  }
4985
5577
 
4986
- class CardsSlider {
5578
+ class SlideApiDepsSingleSlideMode {
4987
5579
  sdkApi;
4988
- constructor(sdkApi, config) {
5580
+ constructor(sdkApi) {
4989
5581
  this.sdkApi = sdkApi;
4990
- const slideWrapper = this.createSliderElement({ slides: config.cards, nonce: config.nonce, cardRender: config.cardRender });
4991
- // todo need to clear root node before append slideWrapper?
5582
+ }
5583
+ getWidgetsSharedData(cardId, widget) {
5584
+ return this.sdkApi.getWidgetsSharedData(cardId, widget);
5585
+ }
5586
+ showToast(text) {
5587
+ return this.sdkApi.showToast(text);
5588
+ }
5589
+ writeToClipboard(data) {
5590
+ return this.sdkApi.writeToClipboard(data);
5591
+ }
5592
+ get isExistsShare() {
5593
+ return this.sdkApi.isExistsShare;
5594
+ }
5595
+ share(id, config) {
5596
+ this.sdkApi.share(id, config);
5597
+ }
5598
+ get sdkCanSendShareComplete() {
5599
+ return this.sdkApi.sdkCanSendShareComplete;
5600
+ }
5601
+ shareSlideScreenshot(shareId, hideElementsSelector, shareText) {
5602
+ this.sdkApi.shareSlideScreenshot(shareId, hideElementsSelector, shareText);
5603
+ }
5604
+ setCardSessionValue(element, key, value) {
5605
+ this.sdkApi.setCardSessionValue(element, key, value);
5606
+ }
5607
+ getCardSessionValue(element, key) {
5608
+ return this.sdkApi.getCardSessionValue(element, key);
5609
+ }
5610
+ getCardFonts() {
5611
+ return this.sdkApi.getCardFonts();
5612
+ }
5613
+ disableVerticalSwipeGesture() {
5614
+ this.sdkApi.disableVerticalSwipeGesture();
5615
+ }
5616
+ enableVerticalSwipeGesture() {
5617
+ this.sdkApi.enableVerticalSwipeGesture();
5618
+ }
5619
+ disableBackpress() {
5620
+ this.sdkApi.disableBackpress();
5621
+ }
5622
+ enableBackpress() {
5623
+ this.sdkApi.enableBackpress();
5624
+ }
5625
+ closeCard(reason) {
5626
+ this.sdkApi.closeCard(reason);
5627
+ }
5628
+ openStory(id, index) {
5629
+ // TODO rewrite with Promise - for usage story loading states in Button
5630
+ this.sdkApi.openStory(id, index);
5631
+ }
5632
+ openGame(gameInstanceId) {
5633
+ // TODO rewrite with Promise - for usage game loading states in Button
5634
+ this.sdkApi.openGame(gameInstanceId);
5635
+ }
5636
+ openUrl(data) {
5637
+ this.sdkApi.openUrl(data);
5638
+ }
5639
+ get isAndroid() {
5640
+ return this.sdkApi.isAndroid;
5641
+ }
5642
+ get isWeb() {
5643
+ return this.sdkApi.isWeb;
5644
+ }
5645
+ get isIOS() {
5646
+ return this.sdkApi.isIOS;
5647
+ }
5648
+ get isExistsShowCardTextInput() {
5649
+ return this.sdkApi.isExistsShowCardTextInput;
5650
+ }
5651
+ showCardTextInput(id, data) {
5652
+ this.sdkApi.showCardTextInput(id, data);
5653
+ }
5654
+ vibrate(pattern) {
5655
+ this.sdkApi.vibrate(pattern);
5656
+ }
5657
+ sendApiRequest(url, method, params, headers, data, profilingKey) {
5658
+ return this.sdkApi.sendApiRequest(url, method, params, headers, data, profilingKey);
5659
+ }
5660
+ sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2) {
5661
+ this.sdkApi.sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2);
5662
+ }
5663
+ setCardLocalData(keyValue, sendToServer) {
5664
+ this.sdkApi.setCardLocalData(keyValue, sendToServer);
5665
+ }
5666
+ getCardLocalData() {
5667
+ return this.sdkApi.getCardLocalData();
5668
+ }
5669
+ getCardServerData(cardId) {
5670
+ return this.sdkApi.getCardServerData(cardId);
5671
+ }
5672
+ get cardAnimation() {
5673
+ return this.sdkApi.cardAnimation;
5674
+ }
5675
+ updateCardServerDataLocally(cardId, data) {
5676
+ this.sdkApi.updateCardServerDataLocally(cardId, data);
5677
+ }
5678
+ get isExistsShowNextCard() {
5679
+ return this.sdkApi.isExistsShowNextCard;
5680
+ }
5681
+ cardShowNext() {
5682
+ this.sdkApi.cardShowNext();
5683
+ }
5684
+ /** @deprecated, used only in native sdk **/
5685
+ cardPausedCallback(currentTime) {
5686
+ this.sdkApi.cardPausedCallback(currentTime);
5687
+ }
5688
+ /** @deprecated, used only in native sdk **/
5689
+ cardResumedCallback(currentTime) {
5690
+ this.sdkApi.cardResumedCallback(currentTime);
5691
+ }
5692
+ disableHorizontalSwipeGesture() {
5693
+ this.sdkApi.disableHorizontalSwipeGesture();
5694
+ }
5695
+ enableHorizontalSwipeGesture() {
5696
+ this.sdkApi.enableHorizontalSwipeGesture();
5697
+ }
5698
+ isExistsShowLayer() {
5699
+ return this.sdkApi.isExistsShowLayer();
5700
+ }
5701
+ showLayer(index) {
5702
+ this.sdkApi.showLayer(index);
5703
+ }
5704
+ /**
5705
+ * For single slide mode - proxy these methods via SDKApi
5706
+ */
5707
+ get isExistsShowCardSlide() {
5708
+ return this.sdkApi.isExistsShowCardSlide;
5709
+ }
5710
+ showCardSlide(index) {
5711
+ this.sdkApi.showCardSlide(index);
5712
+ }
5713
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
5714
+ this.sdkApi.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
5715
+ }
5716
+ isSdkSupportTimelineOnBeforeStart() {
5717
+ return this.sdkApi.isSdkSupportTimelineOnBeforeStart();
5718
+ }
5719
+ isSdkSupportCorrectPauseResumeLifecycle() {
5720
+ return this.sdkApi.isSdkSupportCorrectPauseResumeLifecycle();
5721
+ }
5722
+ showNextSlide(duration) {
5723
+ this.sdkApi.showNextSlide(duration);
5724
+ }
5725
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`]; }
5726
+ }
5727
+
5728
+ class SlideTimer {
5729
+ requestStartTimer;
5730
+ requestCancelTimer;
5731
+ updateCb;
5732
+ doneCb;
5733
+ constructor(requestStartTimer, requestCancelTimer, updateCb, doneCb) {
5734
+ this.requestStartTimer = requestStartTimer;
5735
+ this.requestCancelTimer = requestCancelTimer;
5736
+ this.updateCb = updateCb;
5737
+ this.doneCb = doneCb;
5738
+ }
5739
+ duration;
5740
+ timeLeft;
5741
+ _pause = true;
5742
+ _stop = true;
5743
+ _started = false;
5744
+ start(duration) {
5745
+ this.duration = duration;
5746
+ this.stop();
5747
+ this.timeLeft = this.duration;
5748
+ this._pause = false;
5749
+ this._stop = false;
5750
+ this._started = true;
5751
+ this.tick();
5752
+ }
5753
+ stop() {
5754
+ this._stop = true;
5755
+ this._started = false;
5756
+ if (this.timerId != null) {
5757
+ this.requestCancelTimer(this.timerId);
5758
+ this.timerId = null;
5759
+ }
5760
+ // this.updateCb(0);
5761
+ }
5762
+ pause() {
5763
+ this._pause = true;
5764
+ if (this.timerId != null) {
5765
+ this.requestCancelTimer(this.timerId);
5766
+ this.timerId = null;
5767
+ }
5768
+ }
5769
+ resume(duration = 0) {
5770
+ this._pause = false;
5771
+ if (!this._started) {
5772
+ this.start(duration);
5773
+ }
5774
+ else {
5775
+ this.tick();
5776
+ }
5777
+ }
5778
+ timerId;
5779
+ tick() {
5780
+ if (this._stop) {
5781
+ return;
5782
+ }
5783
+ const rafStartTime = new Date().getTime();
5784
+ this.timerId = this.requestStartTimer(() => {
5785
+ if (this._stop) {
5786
+ return;
5787
+ }
5788
+ const dtDiff = new Date().getTime() - rafStartTime;
5789
+ this.timeLeft -= dtDiff;
5790
+ let progress = Math.round(((this.duration - this.timeLeft) / this.duration) * 100 * 10000) / 10000;
5791
+ if (progress > 100) {
5792
+ progress = 100;
5793
+ }
5794
+ this.updateCb(progress);
5795
+ if (progress < 100) {
5796
+ if (this._pause !== true) {
5797
+ this.tick();
5798
+ }
5799
+ }
5800
+ else {
5801
+ this.doneCb();
5802
+ }
5803
+ });
5804
+ }
5805
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`(callback: () => void) => number`, `(timerId: number) => void`, `(progress: number) => void`, `() => void`]; }
5806
+ }
5807
+
5808
+ class Slider {
5809
+ config;
5810
+ constructor(config) {
5811
+ this.config = config;
5812
+ for (let i = 0; i < config.slides.length; ++i) {
5813
+ const item = {
5814
+ called: false,
5815
+ firstRenderCall: null,
5816
+ firstRenderCallPromise: null,
5817
+ };
5818
+ item.firstRenderCallPromise = new Promise(resolver => {
5819
+ item.firstRenderCall = resolver;
5820
+ });
5821
+ this.slidesFirstRenders[i] = item;
5822
+ }
5823
+ const slideWrapper = this.createSliderElement({
5824
+ slides: config.slides,
5825
+ nonce: config.nonce,
5826
+ slideRender: config.slideRender,
5827
+ });
4992
5828
  config.root.appendChild(slideWrapper);
5829
+ this.slideWrapperElement = slideWrapper;
4993
5830
  // cardMounted: (card: HTMLElement) => Promise<void>
4994
5831
  requestAnimationFrame(async () => {
4995
- for (let i = 0; i < this.cardsElements.length; ++i) {
4996
- await config.onCardMounted(this.cardsElements[i], i);
4997
- }
5832
+ await Promise.all(this.slides.map((slide, index) => config.onSlideMounted(slide.element, index)));
4998
5833
  });
4999
5834
  }
5000
- cardsElements = [];
5835
+ isAnimating = false;
5836
+ activeIndex = -1;
5837
+ get activeSlide() {
5838
+ return this.slides[this.activeIndex];
5839
+ }
5840
+ slides = [];
5001
5841
  sliderTrack = null;
5002
- createSliderElement = ({ slides, nonce, cardRender }) => {
5842
+ bulletsContainer = null;
5843
+ slidesFirstRenders = [];
5844
+ slideWrapperElement;
5845
+ updateBulletActiveIndex;
5846
+ updateTimelineProgress;
5847
+ createSliderElement = ({ slides, nonce, slideRender }) => {
5003
5848
  const style = document.createElement("style");
5004
5849
  if (nonce != null) {
5005
5850
  style.nonce = nonce;
@@ -5013,35 +5858,255 @@ class CardsSlider {
5013
5858
  const slide = document.createElement("div");
5014
5859
  slide.classList.add("cards-slider__slide");
5015
5860
  slide.setAttribute("data-index", String(i));
5016
- this.cardsElements[i] = cardRender(slides[i]);
5017
- slide.appendChild(this.cardsElements[i]);
5861
+ this.slides[i] = {
5862
+ element: slideRender(slides[i], i, this.slidesFirstRenders[i].firstRenderCallPromise),
5863
+ timer: new SlideTimer(cb => window.requestAnimationFrame(cb), handle => window.cancelAnimationFrame(handle), this.onSlideTimerUpdate.bind(this), this.onSlideTimerEnd.bind(this)),
5864
+ };
5865
+ slide.appendChild(this.slides[i].element);
5018
5866
  track.appendChild(slide);
5019
5867
  }
5020
- const bullets = document.createElement("div");
5021
- bullets.classList.add("cards-slider__bullets");
5868
+ const [bullets, updateBulletActiveIndex, updateTimelineProgress] = this.createBulletPoints(slides.length);
5869
+ this.bulletsContainer = bullets;
5870
+ this.updateBulletActiveIndex = updateBulletActiveIndex.bind(this);
5871
+ this.updateTimelineProgress = updateTimelineProgress.bind(this);
5022
5872
  slider.appendChild(track);
5023
5873
  slider.appendChild(bullets);
5024
5874
  slider.appendChild(style);
5025
5875
  return slider;
5026
5876
  };
5027
- showByIndex(prevIndex, newIndex) {
5028
- const width = this.cardsElements[0].clientWidth;
5029
- let offset = 0;
5030
- // todo rtl ltr
5031
- // if (newIndex > prevIndex) {
5032
- offset = -1 * newIndex * width;
5033
- // } else {
5034
- // offset = newIndex * width;
5035
- // }
5036
- console.log({ prevIndex, newIndex, offset, width });
5037
- this.sliderTrack?.style.setProperty("transition", "transform 300ms");
5038
- setTimeout(() => {
5039
- this.sliderTrack?.style.setProperty("transition", "none");
5040
- }, 300);
5041
- this.sliderTrack?.style.setProperty("transform", `translateX(${offset}px)`);
5877
+ createBulletPoints(count) {
5878
+ const bullets = document.createElement("div");
5879
+ bullets.classList.toggle("cards-slider__bullets");
5880
+ for (let i = 0; i < count; ++i) {
5881
+ const bullet = document.createElement("div");
5882
+ bullet.classList.add("cards-slider__bullet");
5883
+ bullet.setAttribute("data-index", String(i));
5884
+ bullet.onclick = (e) => {
5885
+ e.stopPropagation();
5886
+ e.preventDefault();
5887
+ const bullet = e.target;
5888
+ if (bullet != null) {
5889
+ const index = bullet.dataset.index;
5890
+ if (index != null) {
5891
+ this.showByIndex(parseInt(index));
5892
+ }
5893
+ }
5894
+ };
5895
+ const bulletFill = document.createElement("div");
5896
+ bulletFill.classList.add("cards-slider__bullet-fill");
5897
+ bullet.append(bulletFill);
5898
+ bullets.appendChild(bullet);
5899
+ }
5900
+ const onUpdateActiveIndex = (activeIndex) => {
5901
+ if (activeIndex >= 0 && activeIndex < count) {
5902
+ for (const bullet of bullets.querySelectorAll(".cards-slider__bullet--active")) {
5903
+ bullet.classList.toggle("cards-slider__bullet--active");
5904
+ }
5905
+ bullets.querySelector(`.cards-slider__bullet[data-index="${activeIndex}"]`)?.classList.toggle("cards-slider__bullet--active");
5906
+ }
5907
+ };
5908
+ const onUpdateTimelineProgress = (index, progress) => {
5909
+ if (index >= 0 && index < count) {
5910
+ const bullet = bullets.querySelector(`.cards-slider__bullet:nth-child(${index + 1}) .cards-slider__bullet-fill`);
5911
+ if (bullet != null) {
5912
+ // todo RTL
5913
+ //need (in css) right: 100% instead of left -100%;
5914
+ // todo remove progress after slide changed?
5915
+ bullet.style.setProperty("transform", `translateX(${progress}%)`);
5916
+ // transform: `translateZ(0) translateX(${
5917
+ // index < this.$props.index
5918
+ // ? "100%"
5919
+ // : index === this.$props.index
5920
+ // ? `${this.$props.timePercent}%`
5921
+ // : "0%"
5922
+ // })`,
5923
+ }
5924
+ }
5925
+ };
5926
+ return [bullets, onUpdateActiveIndex, onUpdateTimelineProgress];
5927
+ }
5928
+ async showByIndex(newIndex) {
5929
+ const prevIndex = this.activeIndex;
5930
+ if (this.isAnimating)
5931
+ return prevIndex;
5932
+ if (prevIndex !== -1) {
5933
+ // skip for slider start
5934
+ this.config.onSlideLeft(this.slides[prevIndex].element, prevIndex);
5935
+ this.config.onSlideStop();
5936
+ }
5937
+ const { index, loadingError } = await this.initAndRenderSlide(newIndex);
5938
+ if (loadingError) {
5939
+ // todo via updateTimeline ????
5940
+ this.config.onSlideLoadingError(index, loadingError);
5941
+ }
5942
+ await this.slideTo(index);
5943
+ if (!loadingError) {
5944
+ this.onShowSlide(index);
5945
+ }
5946
+ return newIndex;
5947
+ }
5948
+ async showNextSlide() {
5949
+ const prevIndex = this.activeIndex;
5950
+ if (this.isAnimating)
5951
+ return prevIndex;
5952
+ const newIndex = prevIndex + 1;
5953
+ if (newIndex < 0 || newIndex >= this.slides.length) {
5954
+ return null;
5955
+ }
5956
+ if (prevIndex !== -1) {
5957
+ // skip for slider start
5958
+ this.config.onSlideLeft(this.slides[prevIndex].element, prevIndex);
5959
+ this.config.onSlideStop();
5960
+ }
5961
+ const { index, loadingError } = await this.initAndRenderSlide(newIndex);
5962
+ if (loadingError) {
5963
+ // todo via updateTimeline ????
5964
+ this.config.onSlideLoadingError(index, loadingError);
5965
+ }
5966
+ await this.slideTo(index);
5967
+ if (!loadingError) {
5968
+ this.onShowSlide(index);
5969
+ }
5970
+ return newIndex;
5971
+ }
5972
+ async initAndRenderSlide(index) {
5973
+ this.config.onBeforeLoadSlide(index);
5974
+ let showSlidePromise;
5975
+ if (!this.slidesFirstRenders[index].called) {
5976
+ // first render call
5977
+ this.slidesFirstRenders[index].called = true;
5978
+ showSlidePromise = new Promise(resolve => {
5979
+ this.slidesFirstRenders[index].firstRenderCall(resolve);
5980
+ }).then(_ => _);
5981
+ }
5982
+ else {
5983
+ showSlidePromise = this.config.onBeforeShowSlide(this.slides[index].element, index);
5984
+ }
5985
+ try {
5986
+ const { moveToIndex } = await showSlidePromise;
5987
+ if (moveToIndex !== index) {
5988
+ index = moveToIndex;
5989
+ // jump to necessary slide (from WidgetQuest for instance)
5990
+ return this.initAndRenderSlide(index);
5991
+ }
5992
+ else {
5993
+ return { index, loadingError: undefined };
5994
+ }
5995
+ }
5996
+ catch (loadingError) {
5997
+ // catch loading error
5998
+ // this.config.onSlideLoadingError(index, e as string);
5999
+ console.error(loadingError);
6000
+ return { index, loadingError: loadingError };
6001
+ }
6002
+ }
6003
+ onShowSlide(index) {
6004
+ this.updateBulletActiveIndex(index);
6005
+ this.config.onShowSlide(this.slides[index].element, index);
6006
+ this.config.onSlideStart();
5042
6007
  }
5043
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`, `{
5044
- cards: Array<string>;
6008
+ onUpdateSizeMetrics(metrics) {
6009
+ // this.slideTo(this.activeIndex, 0);
6010
+ }
6011
+ getSlideOffset(index) {
6012
+ if (!this.slides.length)
6013
+ return 0;
6014
+ const k = this.config.getLayoutDirection() === "ltr" ? -1 : 1;
6015
+ const cardWidth = this.slides[0].element.clientWidth;
6016
+ return k * index * cardWidth;
6017
+ }
6018
+ async slideTo(index, speed = 300) {
6019
+ if (index < 0 || index > this.slides.length - 1 || this.isAnimating)
6020
+ return;
6021
+ const cardOffset = this.getSlideOffset(index);
6022
+ await this.translateTo(cardOffset, speed);
6023
+ this.activeIndex = index;
6024
+ }
6025
+ setTranslate(value) {
6026
+ this.sliderTrack?.style.setProperty("transform", `translateX(${value}px)`);
6027
+ }
6028
+ setTransition(duration = 300) {
6029
+ this.sliderTrack?.style.setProperty("transition", `transform ${duration}ms`);
6030
+ }
6031
+ async translateTo(translate, speed) {
6032
+ if (this.isAnimating)
6033
+ return;
6034
+ this.setTransition(speed);
6035
+ this.setTranslate(translate);
6036
+ if (speed > 0) {
6037
+ this.isAnimating = true;
6038
+ await this.waitTransitionEnd();
6039
+ this.isAnimating = false;
6040
+ }
6041
+ }
6042
+ waitTransitionEnd() {
6043
+ const sliderTrack = this.sliderTrack;
6044
+ if (!sliderTrack)
6045
+ return Promise.resolve();
6046
+ return new Promise(resolve => {
6047
+ const handler = (e) => {
6048
+ if (e.propertyName === "transform") {
6049
+ sliderTrack.style.transitionDuration = "0ms";
6050
+ resolve();
6051
+ }
6052
+ };
6053
+ sliderTrack.addEventListener("transitionend", handler, { once: true });
6054
+ });
6055
+ }
6056
+ destroy() {
6057
+ this.activeSlide?.timer.stop();
6058
+ if (this.slideWrapperElement != null && this.config.root != null) {
6059
+ this.config.root.removeChild(this.slideWrapperElement);
6060
+ }
6061
+ }
6062
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
6063
+ switch (action) {
6064
+ case "before_start" /* TIMELINE_ACTION.BEFORE_START */: {
6065
+ // switch timeline to active slide and wait for start (wait VOD loading)
6066
+ console.log("TIMELINE_ACTION.BEFORE_START", { activeSlide: this.activeSlide, duration });
6067
+ break;
6068
+ }
6069
+ case "start" /* TIMELINE_ACTION.START */: {
6070
+ this.config.onSlideDataResume();
6071
+ // also start after data waiting or pause
6072
+ // window.setTimeout(() => {
6073
+ // this.config.onSlideStop();
6074
+ // this.config.onSlideTimerEnd();
6075
+ // }, 10000);
6076
+ // destroy on IAM closing
6077
+ console.log("TIMELINE_ACTION.START", { activeSlide: this.activeSlide, index: this.activeIndex, duration });
6078
+ this.activeSlide?.timer.resume(duration);
6079
+ break;
6080
+ }
6081
+ case "pause" /* TIMELINE_ACTION.PAUSE */: {
6082
+ if (showLoader) {
6083
+ this.config.onSlideDataWaiting();
6084
+ }
6085
+ this.activeSlide?.timer.pause();
6086
+ console.log("TIMELINE_ACTION.PAUSE", { activeSlide: this.activeSlide, duration });
6087
+ break;
6088
+ }
6089
+ case "stop" /* TIMELINE_ACTION.STOP */: {
6090
+ // loading error
6091
+ if (showError) {
6092
+ this.config.onSlideDataError();
6093
+ }
6094
+ this.activeSlide?.timer.stop();
6095
+ // todo нужен STOP когда вручную переключаем слайд на другой
6096
+ console.log("TIMELINE_ACTION.STOP", { activeSlide: this.activeSlide, duration });
6097
+ break;
6098
+ }
6099
+ }
6100
+ }
6101
+ onSlideTimerUpdate(progress) {
6102
+ this.updateTimelineProgress(this.activeIndex, progress);
6103
+ }
6104
+ onSlideTimerEnd() {
6105
+ this.config.onSlideStop();
6106
+ this.config.onSlideTimerEnd();
6107
+ }
6108
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
6109
+ slides: Array<T>;
5045
6110
  root: HTMLElement;
5046
6111
  // isFullscreen: boolean;
5047
6112
  nonce?: string;
@@ -5049,15 +6114,28 @@ class CardsSlider {
5049
6114
  // userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5050
6115
  // VODPlayer?: typeof VODPlayer;
5051
6116
  // overlappingActionBarHeight?: number;
5052
- cardRender: (card: string) => HTMLElement;
5053
- onCardMounted: (card: HTMLElement, index: number) => Promise<void>;
6117
+ slideRender: SlideRender<T>;
6118
+ onSlideMounted: OnSlideMounted;
6119
+ onBeforeShowSlide: OnBeforeShowSlide;
6120
+ onBeforeLoadSlide: OnBeforeLoadSlide;
6121
+ onSlideLoadingError: OnSlideLoadingError;
6122
+ onShowSlide: OnShowSlide;
6123
+ onSlideLeft: OnSlideLeft;
6124
+ getLayoutDirection: GetLayoutDirection;
6125
+
6126
+ onSlideTimerEnd: OnSlideTimerEnd;
6127
+ onSlideStart: OnSlideStart;
6128
+ onSlideStop: OnSlideStop;
6129
+ onSlideDataWaiting: OnSlideDataWaiting;
6130
+ onSlideDataResume: OnSlideDataResume;
6131
+ onSlideDataError: OnSlideDataError;
5054
6132
  }`]; }
5055
6133
  }
5056
6134
 
5057
- let SlideApi$1 = class SlideApi {
6135
+ class CardApi {
5058
6136
  config;
5059
6137
  get layoutDirection() {
5060
- return this.activeCard.layoutDirection;
6138
+ return this.activeSlide.layoutDirection;
5061
6139
  }
5062
6140
  static renderedBoxClassName = "narrative-slide-box-rendered";
5063
6141
  static prerenderBoxClassName = "narrative-slide-box-prerender";
@@ -5067,10 +6145,18 @@ let SlideApi$1 = class SlideApi {
5067
6145
  _getViewportHeight;
5068
6146
  _overlappingActionBarHeight;
5069
6147
  _separateUserAndAppPause;
6148
+ _useSdkCacheForMultislideMode;
5070
6149
  sdkApi;
5071
- activeCard = null;
5072
- cards = [];
5073
- multiCardsMode = 0 /* MULTI_CARDS_MODE.SINGLE */;
6150
+ activeSlide = null;
6151
+ slides = [];
6152
+ slidesMode = 0 /* SLIDES_MODE.SINGLE */;
6153
+ sizeMetrics = {
6154
+ fontSize: "0px",
6155
+ isFullscreen: false,
6156
+ slideOffsetMargin: "0px",
6157
+ xOffset: "0px",
6158
+ yOffset: "0px",
6159
+ };
5074
6160
  constructor(config) {
5075
6161
  this.config = config;
5076
6162
  this.sdkApi = config.sdkApi;
@@ -5080,12 +6166,14 @@ let SlideApi$1 = class SlideApi {
5080
6166
  this._getViewportHeight = config.getViewportHeight;
5081
6167
  this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
5082
6168
  this._separateUserAndAppPause = config.separateUserAndAppPause;
6169
+ this._useSdkCacheForMultislideMode = config.useSdkCacheForMultislideMode;
5083
6170
  this.refreshSizes = proxy(this.refreshSizes, this);
5084
6171
  this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
5085
- // create card api instance, need for refreshSizes
5086
- // default mode - single slide
5087
- this.activeCard = new CardApi({
5088
- sdkApi: this.config.sdkApi,
6172
+ this.refreshSizes();
6173
+ // todo - возможность не создавать slideApi в ctor (это не нужно для multislide mode)
6174
+ // но тогда все методы должны обходить случай когда activeSlide undefined
6175
+ this.activeSlide = new SlideApi$1({
6176
+ slideApiDeps: new SlideApiDepsSingleSlideMode(this.config.sdkApi),
5089
6177
  slideWrapper: this.config.slideWrapper,
5090
6178
  viewport: this.config.viewport,
5091
6179
  userResizeHandler: this.config.userResizeHandler,
@@ -5096,32 +6184,36 @@ let SlideApi$1 = class SlideApi {
5096
6184
  overlappingActionBarHeight: this.config.overlappingActionBarHeight,
5097
6185
  separateUserAndAppPause: this.config.separateUserAndAppPause,
5098
6186
  root: this.config.root,
5099
- refreshSizes: this.refreshSizes,
5100
6187
  index: 0,
5101
6188
  getSdkClientVariables: this.getSdkClientVariables,
5102
6189
  });
5103
- this.activeCard.checkAndInitPreloadedInLayoutSlide(this.config.slideLoadedCb);
6190
+ this.activeSlide.onUpdateSizeMetrics(this.sizeMetrics);
6191
+ if (SlideApi$1.checkPreloadedInLayoutSlide()) {
6192
+ this.activeSlide.initPreloadedInLayoutSlide(this.config.slideLoadedCb);
6193
+ }
5104
6194
  this.initListeners();
5105
- this.refreshSizes();
5106
6195
  }
5107
6196
  get state() {
5108
6197
  // TODO remove usage from web-sdk
5109
- return this.activeCard.state;
6198
+ return this.activeSlide.state;
5110
6199
  }
5111
6200
  async destroy() {
5112
- await this.activeCard.destroy();
5113
- await Promise.all(this.cards.map(card => {
5114
- if (card !== this.activeCard) {
5115
- return card.destroy();
6201
+ await this.activeSlide.destroy();
6202
+ await Promise.all(this.slides.map(({ slide }) => {
6203
+ if (slide !== this.activeSlide) {
6204
+ return slide?.destroy();
5116
6205
  }
5117
6206
  }));
5118
6207
  this.destroyListeners();
5119
6208
  }
5120
6209
  initListeners() {
6210
+ // @ts-ignore
5121
6211
  this._viewport.addEventListener("resize", this.refreshSizes);
5122
6212
  }
5123
6213
  destroyListeners() {
6214
+ // @ts-ignore
5124
6215
  this._viewport.removeEventListener("resize", this.refreshSizes);
6216
+ // todo call via activeSlide.refreshSizes
5125
6217
  }
5126
6218
  _savedViewportWidth = null;
5127
6219
  _savedViewportHeight = null;
@@ -5139,12 +6231,10 @@ let SlideApi$1 = class SlideApi {
5139
6231
  // _ratio = 310 / 480,
5140
6232
  const _ratio = this.config.slideRatio;
5141
6233
  let _isFullscreen = this.config.isFullscreen;
5142
- const slideOffset = this.activeCard.slideOffsetElement;
5143
6234
  let offset = 0;
5144
6235
  let xOffset = "0px";
5145
6236
  // for elements with bottom anchor (absolute position)
5146
6237
  let yOffset = "0px";
5147
- // alert(viewportHeight);
5148
6238
  // todo - mobile only (or isIos or isAndroid)
5149
6239
  if (this.sdkApi.isAndroid || this.sdkApi.isIOS) {
5150
6240
  if (viewportRatio > _ratio) {
@@ -5152,6 +6242,7 @@ let SlideApi$1 = class SlideApi {
5152
6242
  _isFullscreen = false;
5153
6243
  }
5154
6244
  }
6245
+ let slideOffsetMargin = "";
5155
6246
  if (_isFullscreen) {
5156
6247
  // более квадратное чем надо (desktop)
5157
6248
  if (viewportRatio > _ratio) {
@@ -5159,9 +6250,7 @@ let SlideApi$1 = class SlideApi {
5159
6250
  slideHeight = viewportHeight;
5160
6251
  slideWidth = Math.ceil(slideHeight * _ratio);
5161
6252
  offset = Math.ceil(slideWidth - viewportWidth) / 2;
5162
- if (slideOffset != null) {
5163
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
5164
- }
6253
+ slideOffsetMargin = "0 " + -offset + "px"; // -8.5
5165
6254
  xOffset = offset + "px";
5166
6255
  }
5167
6256
  else {
@@ -5169,9 +6258,7 @@ let SlideApi$1 = class SlideApi {
5169
6258
  slideWidth = viewportWidth;
5170
6259
  slideHeight = Math.ceil(viewportWidth / _ratio);
5171
6260
  offset = Math.ceil(slideHeight - viewportHeight) / 2;
5172
- if (slideOffset != null) {
5173
- slideOffset.style.margin = -1 * offset + "px" + " 0 ";
5174
- }
6261
+ slideOffsetMargin = -1 * offset + "px" + " 0 ";
5175
6262
  // offset from viewport bottom to StoryBottom plus safe area offset bottom
5176
6263
  yOffset = `calc(${offset + this._overlappingActionBarHeight}px + env(safe-area-inset-bottom))`;
5177
6264
  // detect safe area offset
@@ -5184,9 +6271,7 @@ let SlideApi$1 = class SlideApi {
5184
6271
  slideWidth = viewportWidth;
5185
6272
  slideHeight = Math.ceil(viewportWidth / _ratio);
5186
6273
  offset = Math.ceil(slideHeight - viewportHeight) / 2;
5187
- if (slideOffset != null) {
5188
- slideOffset.style.margin = -offset + "px" + " 0 ";
5189
- }
6274
+ slideOffsetMargin = -offset + "px" + " 0 ";
5190
6275
  yOffset = offset + this._overlappingActionBarHeight + "px";
5191
6276
  }
5192
6277
  else {
@@ -5195,32 +6280,144 @@ let SlideApi$1 = class SlideApi {
5195
6280
  slideHeight = viewportHeight;
5196
6281
  slideWidth = Math.ceil(slideHeight * _ratio);
5197
6282
  offset = Math.ceil(slideWidth - viewportWidth) / 2;
5198
- if (slideOffset != null) {
5199
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
5200
- }
6283
+ slideOffsetMargin = "0 " + -offset + "px"; // -8.5
5201
6284
  xOffset = offset + "px";
5202
6285
  }
5203
6286
  }
5204
6287
  const fontSizeNumber = slideWidth / 20;
5205
6288
  const fontSize = `${fontSizeNumber}px`;
5206
- this.activeCard.onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen: _isFullscreen });
5207
- this.cards.forEach(card => {
5208
- if (card !== this.activeCard) {
5209
- card.onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen: _isFullscreen });
6289
+ const sizeMetrics = { fontSize, xOffset, yOffset, isFullscreen: _isFullscreen, slideOffsetMargin };
6290
+ this.sizeMetrics = sizeMetrics;
6291
+ this.activeSlide?.onUpdateSizeMetrics(sizeMetrics);
6292
+ this.slides.forEach(({ slide }) => {
6293
+ if (slide !== this.activeSlide) {
6294
+ slide?.onUpdateSizeMetrics(sizeMetrics);
5210
6295
  }
5211
6296
  });
6297
+ this.slider?.onUpdateSizeMetrics(sizeMetrics);
5212
6298
  if (this.config.userResizeHandler != null) {
5213
6299
  this.config.userResizeHandler({ viewportWidth, viewportHeight, fontSize: fontSizeNumber });
5214
6300
  }
5215
6301
  }
5216
6302
  async showSlide(html) {
5217
- this.multiCardsMode = 0 /* MULTI_CARDS_MODE.SINGLE */;
5218
- return this.activeCard.showSlide(html);
5219
- }
5220
- cardsSlider = null;
5221
- async showSlides(cards, cardAppearance) {
5222
- this.multiCardsMode = 1 /* MULTI_CARDS_MODE.MULTIPLE */;
5223
- const cardRender = (card) => {
6303
+ this.slidesMode = 0 /* SLIDES_MODE.SINGLE */;
6304
+ if (this.activeSlide == null) {
6305
+ this.activeSlide = new SlideApi$1({
6306
+ slideApiDeps: new SlideApiDepsSingleSlideMode(this.config.sdkApi),
6307
+ slideWrapper: this.config.slideWrapper,
6308
+ viewport: this.config.viewport,
6309
+ userResizeHandler: this.config.userResizeHandler,
6310
+ slideRatio: this.config.slideRatio,
6311
+ isFullscreen: this.config.isFullscreen,
6312
+ getViewportWidth: this.config.getViewportWidth,
6313
+ getViewportHeight: this.config.getViewportHeight,
6314
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6315
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6316
+ root: this.config.root,
6317
+ // refreshSizes: this.refreshSizes,
6318
+ index: 0,
6319
+ getSdkClientVariables: this.getSdkClientVariables,
6320
+ });
6321
+ this.activeSlide.onUpdateSizeMetrics(this.sizeMetrics);
6322
+ }
6323
+ return this.activeSlide.showSlide(html);
6324
+ }
6325
+ slider = null;
6326
+ async showSlides(slides, cardAppearance, index = 0) {
6327
+ this.slidesMode = 1 /* SLIDES_MODE.MULTIPLE */;
6328
+ this.sdkApi.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */);
6329
+ slides.forEach((content, index) => {
6330
+ if (this.slides[index] == null) {
6331
+ const item = { content, resourcesReadyPromise: null };
6332
+ if (this._useSdkCacheForMultislideMode) {
6333
+ item.resourcesReadyPromise = new Promise((resolve, reject) => {
6334
+ item.resourcesReadyPromisesResolver = { resolve, reject };
6335
+ });
6336
+ }
6337
+ else {
6338
+ item.resourcesReadyPromise = Promise.resolve();
6339
+ }
6340
+ this.slides[index] = item;
6341
+ }
6342
+ else {
6343
+ // for case when sdk call setSlideInCacheStatus before showSlides and for slideReloading (after loading error)
6344
+ this.slides[index].content = content;
6345
+ if (this.slides[index].resourcesReadyPromise == null) {
6346
+ if (this._useSdkCacheForMultislideMode) {
6347
+ this.slides[index].resourcesReadyPromise = new Promise((resolve, reject) => {
6348
+ this.slides[index].resourcesReadyPromisesResolver = { resolve, reject };
6349
+ });
6350
+ }
6351
+ else {
6352
+ this.slides[index].resourcesReadyPromise = Promise.resolve();
6353
+ }
6354
+ }
6355
+ }
6356
+ });
6357
+ const onBeforeShowSlide = (slideElement, index) => {
6358
+ if (this.slides[index].slide == null) {
6359
+ const slideApi = new SlideApi$1({
6360
+ slideApiDeps: new SlideApiDepsMultiSlideMode(this.config.sdkApi, this.slider),
6361
+ slideWrapper: slideElement,
6362
+ viewport: this.config.viewport,
6363
+ userResizeHandler: this.config.userResizeHandler,
6364
+ slideRatio: this.config.slideRatio,
6365
+ isFullscreen: this.config.isFullscreen,
6366
+ getViewportWidth: this.config.getViewportWidth,
6367
+ getViewportHeight: this.config.getViewportHeight,
6368
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6369
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6370
+ root: this.config.root,
6371
+ index,
6372
+ getSdkClientVariables: this.getSdkClientVariables,
6373
+ });
6374
+ slideApi.onUpdateSizeMetrics(this.sizeMetrics);
6375
+ this.slides[index].slide = slideApi;
6376
+ // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6377
+ // пока вызов убран из за того что init жестко завязан на single slide mode
6378
+ this.activeSlide = this.slides[index].slide;
6379
+ return this.slides[index].slide.showSlide().then(_ => ({ moveToIndex: index }));
6380
+ }
6381
+ this.activeSlide = this.slides[index].slide;
6382
+ // TODO handle moveToIndex
6383
+ // return resolve or reject with reason
6384
+ // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6385
+ // пока вызов убран из за того что init жестко завязан на single slide mode
6386
+ // return this.slides[index].slide.showSlide().then(_ => ({ moveToIndex: index }));
6387
+ return Promise.resolve({ moveToIndex: index });
6388
+ // вызываем здесь cardLoadingState - loading
6389
+ // новый cb - onSlideShowError - там вызов cardLoadingState error - через cardLoadingStateManager
6390
+ // в onShowSlide- cardLoadingState load done
6391
+ // внутри слайдера - обрабатываем moveToIndex
6392
+ };
6393
+ const onBeforeLoadSlide = index => {
6394
+ this.sdkApi.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */);
6395
+ };
6396
+ const onSlideLoadingError = (index, reason) => {
6397
+ this.sdkApi.onCardLoadingStateChange(2 /* CARD_LOADING_STATE.LOADING_ERROR */, reason);
6398
+ };
6399
+ const onShowSlide = (slide, index) => {
6400
+ this.sdkApi.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */);
6401
+ this.sdkApi.emitEvent("showSlide", { cardId: this.slides[index]?.slide?.slide.cardId ?? 0, index });
6402
+ // if (index === 0) {
6403
+ // this.activeSlide = slideApi;
6404
+ // }
6405
+ // const { result, cardId, slideIndex, reason } = await slideApi.showSlide();
6406
+ // if (index === 0) {
6407
+ // if (result) {
6408
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADED);
6409
+ // this.sdkApi.emitEvent("showSlide", { cardId: this.activeSlide.slide.cardId, index });
6410
+ // } else {
6411
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADING, reason);
6412
+ // }
6413
+ // }
6414
+ //
6415
+ // onShowActiveCardResolver({ cardId, slideIndex });
6416
+ };
6417
+ const onSlideLeft = (slide, index) => {
6418
+ this.sdkApi.emitEvent("slideLeft", { cardId: this.slides[index]?.slide?.slide.cardId ?? 0, index });
6419
+ };
6420
+ const slideRender = ({ content, canMediaMount }, index, onBeforeShowSlideDuringMounting) => {
5224
6421
  const slideWrapper = document.createElement("div");
5225
6422
  slideWrapper.classList.add("narrative-slide-wrapper");
5226
6423
  slideWrapper.classList.add("stories-viewer");
@@ -5243,53 +6440,78 @@ let SlideApi$1 = class SlideApi {
5243
6440
  // style.sheet?.insertRule(`.narrative-slide-box {padding: ${paddingTop} 0 0 0;`);
5244
6441
  slideBoxRendered.style.padding = `${paddingTop} 0 0 0`;
5245
6442
  slideBoxPrerender.style.padding = `${paddingTop} 0 0 0`;
5246
- slideBoxPrerender.innerHTML = card;
6443
+ // slideBoxPrerender.innerHTML = card;
6444
+ // extract and mount solid or gradient bg color (w/o bg image)
6445
+ onBeforeShowSlideDuringMounting.then(callback => {
6446
+ callback(canMediaMount.then(() => {
6447
+ // mount slide media content (after cache is ready event)
6448
+ slideBoxPrerender.innerHTML = content;
6449
+ // create slideApi
6450
+ // call init, init should return moveToIndex
6451
+ return onBeforeShowSlide(slideWrapper, index);
6452
+ }));
6453
+ });
5247
6454
  slideOffset.appendChild(slideBoxPrerender);
5248
6455
  slideOffset.appendChild(slideBoxRendered);
5249
6456
  slideWrapper.appendChild(slideOffset);
5250
6457
  slideWrapper.appendChild(style);
5251
6458
  return slideWrapper;
5252
6459
  };
5253
- let onShowActiveCardResolver = null;
5254
- const onShowActiveCard = new Promise(resolve => {
5255
- onShowActiveCardResolver = resolve;
6460
+ new Promise(resolve => {
5256
6461
  });
5257
- const onCardMounted = async (card, index) => {
5258
- const cardApi = new CardApi({
5259
- sdkApi: this.config.sdkApi,
5260
- slideWrapper: card,
5261
- viewport: this.config.viewport,
5262
- userResizeHandler: this.config.userResizeHandler,
5263
- slideRatio: this.config.slideRatio,
5264
- isFullscreen: this.config.isFullscreen,
5265
- getViewportWidth: this.config.getViewportWidth,
5266
- getViewportHeight: this.config.getViewportHeight,
5267
- overlappingActionBarHeight: this.config.overlappingActionBarHeight,
5268
- separateUserAndAppPause: this.config.separateUserAndAppPause,
5269
- root: this.config.root,
5270
- refreshSizes: this.refreshSizes,
5271
- index,
5272
- getSdkClientVariables: this.getSdkClientVariables,
5273
- });
5274
- this.cards[index] = cardApi;
5275
- if (index === 0) {
5276
- this.activeCard = cardApi;
5277
- }
5278
- const result = await cardApi.showSlide();
5279
- onShowActiveCardResolver(result);
5280
- // console.log({ result, index });
6462
+ // onContentMounted
6463
+ const onSlideMounted = async (slideElement, index) => {
6464
+ // if (index === 0) {
6465
+ // this.activeSlide = slideApi;
6466
+ // }
6467
+ //
6468
+ // const { result, cardId, slideIndex, reason } = await slideApi.showSlide();
6469
+ //
6470
+ //
6471
+ // if (index === 0) {
6472
+ // if (result) {
6473
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADED);
6474
+ // this.sdkApi.emitEvent("showSlide", { cardId: this.activeSlide.slide.cardId, index });
6475
+ // } else {
6476
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADING, reason);
6477
+ // }
6478
+ // }
6479
+ //
6480
+ // onShowActiveCardResolver({ cardId, slideIndex });
5281
6481
  };
5282
- this.cardsSlider = new CardsSlider(this.sdkApi, {
6482
+ if (this.slider != null) {
6483
+ this.slider.destroy();
6484
+ }
6485
+ this.slider = new Slider({
5283
6486
  root: this.config.root,
5284
- cards,
6487
+ slides: this.slides.map(({ content, resourcesReadyPromise }) => ({
6488
+ content,
6489
+ canMediaMount: resourcesReadyPromise,
6490
+ })),
5285
6491
  nonce: this.config.nonce,
5286
- cardRender,
5287
- onCardMounted,
6492
+ slideRender,
6493
+ onSlideMounted,
6494
+ onBeforeShowSlide,
6495
+ onBeforeLoadSlide,
6496
+ onSlideLoadingError,
6497
+ onShowSlide,
6498
+ onSlideLeft,
6499
+ getLayoutDirection: () => this.layoutDirection,
6500
+ onSlideTimerEnd: () => this.activeSlide.slideTimerEnd(),
6501
+ onSlideStart: () => {
6502
+ this.sdkApi.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */);
6503
+ return this.activeSlide.slideStart({ muted: true });
6504
+ },
6505
+ onSlideStop: () => this.activeSlide.slideStop({ prepareForRestart: 1 /* ON_SLIDE_STOP_PREPARE_FOR_RESTART.PREPARE */ }),
6506
+ onSlideDataWaiting: () => this.sdkApi.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */),
6507
+ onSlideDataResume: () => this.sdkApi.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */),
6508
+ onSlideDataError: () => this.sdkApi.onCardLoadingStateChange(2 /* CARD_LOADING_STATE.LOADING_ERROR */),
5288
6509
  });
5289
- return await onShowActiveCard;
6510
+ await this.slider.showByIndex(index);
6511
+ // return await onShowActiveCard;
5290
6512
  }
5291
6513
  handleBackpress() {
5292
- this.activeCard.handleBackpress();
6514
+ this.activeSlide.handleBackpress();
5293
6515
  }
5294
6516
  get layoutService() {
5295
6517
  return container.get({ identifier: "LayoutService" });
@@ -5298,89 +6520,91 @@ let SlideApi$1 = class SlideApi {
5298
6520
  return this.sdkApi.getCardLocalData();
5299
6521
  }
5300
6522
  async slideStart(config) {
5301
- return this.activeCard.slideStart(config);
6523
+ return this.activeSlide.slideStart(config);
5302
6524
  }
5303
6525
  async slideRestart(config) {
5304
- return this.activeCard.slideRestart(config);
6526
+ return this.activeSlide.slideRestart(config);
5305
6527
  }
5306
6528
  async slideUserPause() {
5307
- return this.activeCard.slideUserPause();
6529
+ return this.activeSlide.slideUserPause();
5308
6530
  }
5309
6531
  async slideUserResume() {
5310
- return this.activeCard.slideUserResume();
6532
+ return this.activeSlide.slideUserResume();
5311
6533
  }
5312
6534
  /**
5313
6535
  * Call on app gone background
5314
6536
  */
5315
6537
  async slideAppPause() {
5316
- return this.activeCard.slideAppPause();
6538
+ return this.activeSlide.slideAppPause();
5317
6539
  }
5318
6540
  /**
5319
6541
  * Call on app gone foreground after a background
5320
6542
  */
5321
6543
  async slideAppResume() {
5322
- return this.activeCard.slideAppResume();
6544
+ return this.activeSlide.slideAppResume();
5323
6545
  }
5324
6546
  async slideStop(options) {
5325
- return this.activeCard.slideStop(options);
6547
+ return this.activeSlide.slideStop(options);
5326
6548
  }
5327
6549
  slideTimerEnd() {
5328
- this.activeCard.slideTimerEnd();
6550
+ this.activeSlide.slideTimerEnd();
5329
6551
  }
5330
6552
  enableAudio() {
5331
- this.activeCard.enableAudio();
6553
+ this.activeSlide.enableAudio();
5332
6554
  }
5333
6555
  disableAudio() {
5334
- this.activeCard.disableAudio();
6556
+ this.activeSlide.disableAudio();
5335
6557
  }
5336
6558
  get isStopped() {
5337
- return this.activeCard.isStopped;
6559
+ return this.activeSlide.isStopped;
5338
6560
  }
5339
6561
  afterStartInitQueuePush(cb) {
5340
- return this.activeCard.afterStartInitQueuePush(cb);
6562
+ return this.activeSlide.afterStartInitQueuePush(cb);
5341
6563
  }
5342
6564
  afterAppResumeQueuePush(cb) {
5343
- return this.activeCard.afterAppResumeQueuePush(cb);
6565
+ return this.activeSlide.afterAppResumeQueuePush(cb);
5344
6566
  }
5345
6567
  get activeLayer() {
5346
- return this.activeCard.slide.activeLayer;
6568
+ return this.activeSlide.slide.activeLayer;
5347
6569
  }
5348
6570
  get slide() {
5349
- return this.activeCard.slide;
6571
+ return this.activeSlide.slide;
5350
6572
  }
5351
6573
  showLayer(index) {
5352
- this.activeCard.showLayer(index);
6574
+ this.activeSlide.showLayer(index);
5353
6575
  }
5354
6576
  slideClickHandler(targetElement, navigationDirection) {
5355
- const result = this.activeCard.slideClickHandler(targetElement, navigationDirection);
5356
- if (this.multiCardsMode === 1 /* MULTI_CARDS_MODE.MULTIPLE */) {
5357
- // handle nav click via CardsSlider, not via SDK
5358
- result.canClickNext = false;
5359
- const currentIndex = this.activeCard.index;
6577
+ const result = this.activeSlide.slideClickHandler(targetElement, navigationDirection);
6578
+ // todo make via strategy pattern, singleSlide and multiSlide impl
6579
+ if (this.slidesMode === 1 /* SLIDES_MODE.MULTIPLE */ && result.canClickNext) {
6580
+ result.canClickNext = false; // handle nav click via CardsSlider, not via SDK
6581
+ const currentIndex = this.activeSlide.index;
5360
6582
  let index = navigationDirection === "forward" ? currentIndex + 1 : currentIndex - 1;
5361
- if (index >= this.cards.length) {
6583
+ if (index >= this.slides.length) {
5362
6584
  index = 0;
5363
6585
  }
5364
6586
  else if (index < 0) {
5365
- index = this.cards.length - 1;
6587
+ index = this.slides.length - 1;
5366
6588
  }
5367
- // todo async
5368
- this.cardsSlider.showByIndex(currentIndex, index);
5369
- this.activeCard = this.cards[index];
6589
+ this.slider.showByIndex(index).then(index => {
6590
+ if (currentIndex === index)
6591
+ return;
6592
+ this.activeSlide = this.slides[index].slide;
6593
+ });
5370
6594
  }
5371
6595
  return result;
5372
6596
  }
5373
6597
  slideSwipeUpHandler() {
5374
- return this.activeCard.slideSwipeUpHandler();
6598
+ return this.activeSlide.slideSwipeUpHandler();
5375
6599
  }
5376
6600
  setTextInputResult(id, text) {
5377
- this.activeCard.setTextInputResult(id, text);
6601
+ this.activeSlide.setTextInputResult(id, text);
5378
6602
  }
5379
6603
  setShareComplete(id, isSuccess) {
5380
- this.activeCard.setShareComplete(id, isSuccess);
6604
+ this.activeSlide.setShareComplete(id, isSuccess);
5381
6605
  }
5382
6606
  setWidgetGoodsComplete(elementId) {
5383
- this.activeCard.setWidgetGoodsComplete(elementId);
6607
+ this.activeSlide.setWidgetGoodsComplete(elementId);
5384
6608
  }
5385
6609
  _sdkClientVariables = {};
5386
6610
  getSdkClientVariables() {
@@ -5389,6 +6613,23 @@ let SlideApi$1 = class SlideApi {
5389
6613
  setSdkClientVariables(variables) {
5390
6614
  this._sdkClientVariables = variables;
5391
6615
  }
6616
+ setSlideInCacheStatus(index, status) {
6617
+ if (this.slides[index] != null && this.slides[index].resourcesReadyPromisesResolver != null) {
6618
+ if (status === 1 /* SLIDE_IN_CACHE_STATUS.SUCCESS */) {
6619
+ this.slides[index].resourcesReadyPromisesResolver.resolve();
6620
+ }
6621
+ else {
6622
+ this.slides[index].resourcesReadyPromisesResolver.reject();
6623
+ }
6624
+ }
6625
+ else {
6626
+ // for call setSlideInCacheStatus before showSlides
6627
+ this.slides[index] = {
6628
+ content: "",
6629
+ resourcesReadyPromise: Promise.resolve(),
6630
+ };
6631
+ }
6632
+ }
5392
6633
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
5393
6634
  sdkApi: SDKApi;
5394
6635
  slideWrapper: HTMLElement;
@@ -5403,8 +6644,9 @@ let SlideApi$1 = class SlideApi {
5403
6644
  separateUserAndAppPause: boolean;
5404
6645
  root: HTMLElement;
5405
6646
  nonce?: string;
6647
+ useSdkCacheForMultislideMode: boolean;
5406
6648
  }`]; }
5407
- };
6649
+ }
5408
6650
 
5409
6651
  const slideApiPeerDeps = {};
5410
6652
  const createSlideWrapper = ({ slideBoxRatio, nonce }) => {
@@ -5436,7 +6678,7 @@ const createSlideWrapper = ({ slideBoxRatio, nonce }) => {
5436
6678
  slideWrapper.appendChild(style);
5437
6679
  return slideWrapper;
5438
6680
  };
5439
- class SlideApi extends SlideApi$1 {
6681
+ class SlideApi extends CardApi {
5440
6682
  root;
5441
6683
  slideWrapper;
5442
6684
  constructor(_sdkInterface, config) {
@@ -5456,6 +6698,7 @@ class SlideApi extends SlideApi$1 {
5456
6698
  separateUserAndAppPause: true,
5457
6699
  root: config.root,
5458
6700
  nonce: config.nonce,
6701
+ useSdkCacheForMultislideMode: config.useSdkCacheForMultislideMode,
5459
6702
  });
5460
6703
  this.root = config.root;
5461
6704
  this.slideWrapper = slideWrapper;
@@ -5476,6 +6719,7 @@ class SlideApi extends SlideApi$1 {
5476
6719
  userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5477
6720
  VODPlayer?: typeof VODPlayer;
5478
6721
  overlappingActionBarHeight?: number;
6722
+ useSdkCacheForMultislideMode: boolean;
5479
6723
  }`]; }
5480
6724
  }
5481
6725
 
@@ -14905,7 +16149,7 @@ class WidgetBase {
14905
16149
  this.submitButtonView = this.submitButtonAnimatedView.querySelector(".submit-button-view");
14906
16150
  }
14907
16151
  }
14908
- this.savedData = this.widgetDeps.sdkApi.getCardServerData(this.cardId);
16152
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
14909
16153
  this.localData = extend({}, this.savedData ?? {}, this.options.localData ?? {});
14910
16154
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
14911
16155
  ++WidgetBase.widgetIndex;
@@ -14927,7 +16171,7 @@ class WidgetBase {
14927
16171
  * @param localData
14928
16172
  */
14929
16173
  onRefreshUserData(localData) {
14930
- this.savedData = this.widgetDeps.sdkApi.getCardServerData(this.cardId);
16174
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
14931
16175
  this.localData = extend({}, this.savedData ?? {}, localData);
14932
16176
  }
14933
16177
  onStart() {
@@ -14977,13 +16221,13 @@ class WidgetBase {
14977
16221
  static get widgetsService() {
14978
16222
  return container.get({ identifier: "WidgetsService" });
14979
16223
  }
14980
- static getLocalData(sdkApi) {
14981
- return sdkApi.getCardLocalData();
16224
+ static getLocalData(slideApiDeps) {
16225
+ return slideApiDeps.getCardLocalData();
14982
16226
  }
14983
16227
  getLocalData() {
14984
- return this.constructor.getLocalData(this.widgetDeps.sdkApi);
16228
+ return this.constructor.getLocalData(this.widgetDeps.slideApiDeps);
14985
16229
  }
14986
- static setLocalData(sdkApi, keyValue, sendToServer, syncWithRuntimeLocalData) {
16230
+ static setLocalData(slideApiDeps, keyValue, sendToServer, syncWithRuntimeLocalData) {
14987
16231
  // push json object as string
14988
16232
  if (sendToServer === undefined) {
14989
16233
  sendToServer = true;
@@ -14998,20 +16242,20 @@ class WidgetBase {
14998
16242
  syncWithRuntimeLocalData = Boolean(syncWithRuntimeLocalData);
14999
16243
  }
15000
16244
  if (syncWithRuntimeLocalData) {
15001
- this.getLocalData(sdkApi).then(localData => {
16245
+ this.getLocalData(slideApiDeps).then(localData => {
15002
16246
  // 1 - old values, 2 - new values
15003
16247
  keyValue = extend({}, localData, keyValue);
15004
16248
  // todo make async via promise or async
15005
- sdkApi.setCardLocalData(keyValue, sendToServer);
16249
+ slideApiDeps.setCardLocalData(keyValue, sendToServer);
15006
16250
  });
15007
16251
  }
15008
16252
  else {
15009
16253
  // todo make async via promise or async
15010
- sdkApi.setCardLocalData(keyValue, sendToServer);
16254
+ slideApiDeps.setCardLocalData(keyValue, sendToServer);
15011
16255
  }
15012
16256
  }
15013
16257
  setLocalData(keyValue, sendToServer, syncWithRuntimeLocalData) {
15014
- return this.constructor.setLocalData(this.widgetDeps.sdkApi, keyValue, sendToServer, syncWithRuntimeLocalData);
16258
+ return this.constructor.setLocalData(this.widgetDeps.slideApiDeps, keyValue, sendToServer, syncWithRuntimeLocalData);
15015
16259
  }
15016
16260
  get statisticEventBaseFieldsShortForm() {
15017
16261
  return WidgetBase.getStatisticEventBaseFieldsShortForm(this.cardId, this.cardType, this.slideIndex);
@@ -15042,11 +16286,11 @@ class WidgetBase {
15042
16286
  }
15043
16287
  return data;
15044
16288
  }
15045
- static sendStatisticEventToApp(sdkApi, name, data, devPayload, options) {
15046
- sendStatisticEventToApp(sdkApi, name, data, devPayload, options);
16289
+ static sendStatisticEventToApp(slideApiDeps, name, data, devPayload, options) {
16290
+ sendStatisticEventToApp(slideApiDeps, name, data, devPayload, options);
15047
16291
  }
15048
16292
  sendStatisticEventToApp(name, data, devPayload, options) {
15049
- this.constructor.sendStatisticEventToApp(this.widgetDeps.sdkApi, name, data, devPayload, options);
16293
+ this.constructor.sendStatisticEventToApp(this.widgetDeps.slideApiDeps, name, data, devPayload, options);
15050
16294
  }
15051
16295
  onWidgetComplete() {
15052
16296
  this._widgetCallbacks.onWidgetComplete(this.cardId, this.slideIndex);
@@ -15058,14 +16302,14 @@ class WidgetBase {
15058
16302
  this._widgetCallbacks.onWidgetRequireResumeUI(this.cardId, this.slideIndex);
15059
16303
  }
15060
16304
  _showLayer(layers, selectIndex, withStatEvent = false) {
15061
- if (this.widgetDeps.sdkApi.isExistsShowLayer()) {
15062
- this.widgetDeps.sdkApi.showLayer(selectIndex);
16305
+ if (this.widgetDeps.slideApiDeps.isExistsShowLayer()) {
16306
+ this.widgetDeps.slideApiDeps.showLayer(selectIndex);
15063
16307
  }
15064
16308
  else {
15065
16309
  forEach(layers, (layer, index) => {
15066
16310
  if (index === selectIndex) {
15067
16311
  layer.classList.remove("hidden");
15068
- this.widgetDeps.sdkApi.cardAnimation?.start(layer);
16312
+ this.widgetDeps.slideApiDeps.cardAnimation?.start(layer);
15069
16313
  }
15070
16314
  else {
15071
16315
  layer.classList.add("hidden");
@@ -15215,7 +16459,7 @@ class WidgetBarcode extends WidgetBase {
15215
16459
  }
15216
16460
  catch (e) {
15217
16461
  if (this.msgBarcodeRenderError) {
15218
- this.widgetDeps.sdkApi.showToast(this.msgBarcodeRenderError);
16462
+ this.widgetDeps.slideApiDeps.showToast(this.msgBarcodeRenderError);
15219
16463
  }
15220
16464
  console.error(e);
15221
16465
  }
@@ -15278,7 +16522,7 @@ class WidgetBarcode extends WidgetBase {
15278
16522
  };
15279
16523
  const profileKey = "fetch-promo-code";
15280
16524
  Promise.all([
15281
- this.widgetDeps.sdkApi.sendApiRequest(path, "POST", null, headers, null, profileKey),
16525
+ this.widgetDeps.slideApiDeps.sendApiRequest(path, "POST", null, headers, null, profileKey),
15282
16526
  new Promise(function (t, e) {
15283
16527
  return setTimeout(t, 300);
15284
16528
  }),
@@ -15306,14 +16550,14 @@ class WidgetBarcode extends WidgetBase {
15306
16550
  this.setLocalData(this.localData, true);
15307
16551
  }
15308
16552
  else {
15309
- this.msgNoMoreCodes && this.widgetDeps.sdkApi.showToast(this.msgNoMoreCodes);
16553
+ this.msgNoMoreCodes && this.widgetDeps.slideApiDeps.showToast(this.msgNoMoreCodes);
15310
16554
  }
15311
16555
  }
15312
16556
  else if (status === 12163 || status === 12002) {
15313
- this.msgNetworkError && this.widgetDeps.sdkApi.showToast(this.msgNetworkError);
16557
+ this.msgNetworkError && this.widgetDeps.slideApiDeps.showToast(this.msgNetworkError);
15314
16558
  }
15315
16559
  else {
15316
- this.msgServiceError && this.widgetDeps.sdkApi.showToast(this.msgServiceError);
16560
+ this.msgServiceError && this.widgetDeps.slideApiDeps.showToast(this.msgServiceError);
15317
16561
  }
15318
16562
  if (!success) {
15319
16563
  this.state = 3;
@@ -15359,13 +16603,13 @@ class WidgetBarcode extends WidgetBase {
15359
16603
  }
15360
16604
  });
15361
16605
  if (this.copiedText) {
15362
- this.widgetDeps.sdkApi.showToast(this.copiedText);
16606
+ this.widgetDeps.slideApiDeps.showToast(this.copiedText);
15363
16607
  }
15364
16608
  }
15365
16609
  copyToClipboard(element) {
15366
16610
  this._select();
15367
16611
  const textValue = this.clipboardTarget ?? "";
15368
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
16612
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
15369
16613
  this.completeWidget();
15370
16614
  this._statEventCopyClick(textValue);
15371
16615
  }
@@ -15537,7 +16781,7 @@ class WidgetCopy extends WidgetBase {
15537
16781
  };
15538
16782
  const profileKey = "fetch-promo-code";
15539
16783
  Promise.all([
15540
- this.widgetDeps.sdkApi.sendApiRequest(path, "POST", null, headers, null, profileKey),
16784
+ this.widgetDeps.slideApiDeps.sendApiRequest(path, "POST", null, headers, null, profileKey),
15541
16785
  new Promise(function (t, e) {
15542
16786
  return setTimeout(t, 300);
15543
16787
  }),
@@ -15564,14 +16808,14 @@ class WidgetCopy extends WidgetBase {
15564
16808
  this.setLocalData(this.localData, true);
15565
16809
  }
15566
16810
  else {
15567
- this.msgNoMoreCodes && this.widgetDeps.sdkApi.showToast(this.msgNoMoreCodes);
16811
+ this.msgNoMoreCodes && this.widgetDeps.slideApiDeps.showToast(this.msgNoMoreCodes);
15568
16812
  }
15569
16813
  }
15570
16814
  else if (status === 12163 || status === 12002) {
15571
- this.msgNetworkError && this.widgetDeps.sdkApi.showToast(this.msgNetworkError);
16815
+ this.msgNetworkError && this.widgetDeps.slideApiDeps.showToast(this.msgNetworkError);
15572
16816
  }
15573
16817
  else {
15574
- this.msgServiceError && this.widgetDeps.sdkApi.showToast(this.msgServiceError);
16818
+ this.msgServiceError && this.widgetDeps.slideApiDeps.showToast(this.msgServiceError);
15575
16819
  }
15576
16820
  if (!success) {
15577
16821
  this.state = 3;
@@ -15623,7 +16867,7 @@ class WidgetCopy extends WidgetBase {
15623
16867
  copyToClipboard(element) {
15624
16868
  this._select();
15625
16869
  const textValue = this.clipboardTarget ?? "";
15626
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
16870
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
15627
16871
  this.completeWidget();
15628
16872
  this._statEventCopyClick(textValue);
15629
16873
  }
@@ -15765,12 +17009,12 @@ class WidgetDataInput extends WidgetBase {
15765
17009
  return true;
15766
17010
  }
15767
17011
  this.elementRect = this.element.getBoundingClientRect();
15768
- if (this.widgetDeps.sdkApi.isAndroid || this.widgetDeps.sdkApi.isWeb) {
17012
+ if (this.widgetDeps.slideApiDeps.isAndroid || this.widgetDeps.slideApiDeps.isWeb) {
15769
17013
  this.slide.classList.add("blured");
15770
17014
  }
15771
17015
  this.slide.classList.add("data-input-editing");
15772
17016
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
15773
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17017
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
15774
17018
  const data = JSON.parse(dataString);
15775
17019
  data.size = getElementBounding(this.env, this.elementRect);
15776
17020
  if (!this.disableTimer) {
@@ -15791,7 +17035,7 @@ class WidgetDataInput extends WidgetBase {
15791
17035
  catch (e) {
15792
17036
  console.error(e);
15793
17037
  }
15794
- this.widgetDeps.sdkApi.showCardTextInput(this.id, data);
17038
+ this.widgetDeps.slideApiDeps.showCardTextInput(this.id, data);
15795
17039
  this._statEventFocusIn();
15796
17040
  }
15797
17041
  return false;
@@ -16090,7 +17334,7 @@ class WidgetDateCountdown extends WidgetBase {
16090
17334
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Partial`, `WidgetCallbacks`, `WidgetDeps`]; }
16091
17335
  }
16092
17336
 
16093
- const displaySlide = function (slides, localData, sdkApi) {
17337
+ const displaySlide = function (slides, localData, slideApiDeps) {
16094
17338
  const multiSlideItem = slides[0];
16095
17339
  let cardId = undefined;
16096
17340
  let cardType = 1 /* CARD_TYPE.STORY */;
@@ -16155,7 +17399,7 @@ const displaySlide = function (slides, localData, sdkApi) {
16155
17399
  if (slides.length > 0) {
16156
17400
  var slide = slides[0];
16157
17401
  slide.classList.remove("hidden");
16158
- sdkApi.cardAnimation?.start(slide);
17402
+ slideApiDeps.cardAnimation?.start(slide);
16159
17403
  return;
16160
17404
  }
16161
17405
  score = 0;
@@ -16184,19 +17428,19 @@ const displaySlide = function (slides, localData, sdkApi) {
16184
17428
  if (index === selectedIndex) {
16185
17429
  slide.classList.remove("hidden");
16186
17430
  undefinedResult = false;
16187
- sdkApi.cardAnimation?.start(slide);
16188
- _sendStatEvent(sdkApi, cardId, cardType, slideIndex, selectedIndex);
17431
+ slideApiDeps.cardAnimation?.start(slide);
17432
+ _sendStatEvent(slideApiDeps, cardId, cardType, slideIndex, selectedIndex);
16189
17433
  }
16190
17434
  });
16191
17435
  }
16192
17436
  if (undefinedResult) {
16193
17437
  console.warn("undefinedResult layer index");
16194
- sdkApi.showLayer(0);
17438
+ slideApiDeps.showLayer(0);
16195
17439
  }
16196
17440
  };
16197
- const _sendStatEvent = function (sdkApi, cardId, cardType, slideIndex, layerIndex) {
17441
+ const _sendStatEvent = function (slideApiDeps, cardId, cardType, slideIndex, layerIndex) {
16198
17442
  try {
16199
- WidgetBase.sendStatisticEventToApp(sdkApi, "layout-show", {
17443
+ WidgetBase.sendStatisticEventToApp(slideApiDeps, "layout-show", {
16200
17444
  ...WidgetBase.getStatisticEventBaseFieldsShortForm(cardId, cardType, slideIndex),
16201
17445
  li: layerIndex,
16202
17446
  }, {
@@ -16211,7 +17455,7 @@ const _sendStatEvent = function (sdkApi, cardId, cardType, slideIndex, layerInde
16211
17455
  class WidgetMultiSlide {
16212
17456
  static api = {
16213
17457
  init: function (slides, localData, widgetDeps) {
16214
- displaySlide(slides, localData, widgetDeps.sdkApi);
17458
+ displaySlide(slides, localData, widgetDeps.slideApiDeps);
16215
17459
  },
16216
17460
  };
16217
17461
  }
@@ -16379,13 +17623,13 @@ class WidgetPoll extends WidgetBase {
16379
17623
  if (index !== -1) {
16380
17624
  this.elementRect = this.element.getBoundingClientRect();
16381
17625
  if (this.getUseResponseOnFirstButton && index === 0) {
16382
- if (this.widgetDeps.sdkApi.isAndroid) {
17626
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
16383
17627
  this.slide.classList.add("blured");
16384
17628
  }
16385
17629
  this.slide.classList.add("data-input-editing");
16386
17630
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
16387
17631
  this.selectedVariant = index;
16388
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17632
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
16389
17633
  const data = JSON.parse(dataString);
16390
17634
  data.size = getElementBounding(this.env, this.elementRect);
16391
17635
  if (!this.disableTimer) {
@@ -16407,19 +17651,19 @@ class WidgetPoll extends WidgetBase {
16407
17651
  catch (e) {
16408
17652
  console.error(e);
16409
17653
  }
16410
- this.widgetDeps.sdkApi.showCardTextInput(`${this.id}_first`, data);
17654
+ this.widgetDeps.slideApiDeps.showCardTextInput(`${this.id}_first`, data);
16411
17655
  }
16412
17656
  this._statEventPollAnswer();
16413
17657
  return false;
16414
17658
  }
16415
17659
  else if (this.getUseResponseOnSecondButton && index === 1) {
16416
- if (this.widgetDeps.sdkApi.isAndroid) {
17660
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
16417
17661
  this.slide.classList.add("blured");
16418
17662
  }
16419
17663
  this.slide.classList.add("data-input-editing");
16420
17664
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
16421
17665
  this.selectedVariant = index;
16422
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17666
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
16423
17667
  const data = JSON.parse(dataString);
16424
17668
  data.size = getElementBounding(this.env, this.elementRect);
16425
17669
  if (!this.disableTimer) {
@@ -16440,7 +17684,7 @@ class WidgetPoll extends WidgetBase {
16440
17684
  catch (e) {
16441
17685
  console.error(e);
16442
17686
  }
16443
- this.widgetDeps.sdkApi.showCardTextInput(`${this.id}_second`, data);
17687
+ this.widgetDeps.slideApiDeps.showCardTextInput(`${this.id}_second`, data);
16444
17688
  }
16445
17689
  this._statEventPollAnswer();
16446
17690
  return false;
@@ -16483,7 +17727,7 @@ class WidgetPoll extends WidgetBase {
16483
17727
  displayPercents(selectedVariantIndex, filled = false) {
16484
17728
  let pollAllocation = [0, 0];
16485
17729
  let pollAllocationTs = undefined;
16486
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
17730
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
16487
17731
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
16488
17732
  pollAllocation = sharedData[this.elementId];
16489
17733
  if (isObject$1(sharedData[this.elementId])) {
@@ -17652,20 +18896,19 @@ class WidgetProducts extends WidgetBase {
17652
18896
  if (!this.linkTarget.length) {
17653
18897
  return { message: this.msgServiceError ?? "", models: [] };
17654
18898
  }
17655
- const searchParams = new URLSearchParams();
17656
- searchParams.set("id", this.linkTarget.join(","));
18899
+ let qs = `id=${this.linkTarget.join(",")}`;
17657
18900
  const sdkClientVariables = this.widgetDeps.getSdkClientVariables();
17658
18901
  if (sdkClientVariables != null && sdkClientVariables.pos != null) {
17659
- searchParams.set("pos", String(sdkClientVariables.pos));
18902
+ qs += `&pos=${String(sdkClientVariables.pos)}`;
17660
18903
  }
17661
- const path = `product/offer?${searchParams.toString()}`;
18904
+ const path = `product/offer?${qs}`;
17662
18905
  const headers = {
17663
18906
  accept: "application/json",
17664
18907
  "Content-Type": "application/json",
17665
18908
  };
17666
18909
  const profileKey = "fetch-products";
17667
18910
  try {
17668
- const response = await this.widgetDeps.sdkApi.sendApiRequest(path, "GET", null, headers, null, profileKey);
18911
+ const response = await this.widgetDeps.slideApiDeps.sendApiRequest(path, "GET", null, headers, null, profileKey);
17669
18912
  // console.log({response});
17670
18913
  const status = response.status;
17671
18914
  if (status === 200 || status === 201) {
@@ -17791,15 +19034,15 @@ class WidgetProducts extends WidgetBase {
17791
19034
  this.isOpen = true;
17792
19035
  // prevent next slide navigation gesture
17793
19036
  this.isClickCapturedByWidget = true;
17794
- this.widgetDeps.sdkApi.disableHorizontalSwipeGesture();
17795
- this.widgetDeps.sdkApi.disableVerticalSwipeGesture();
17796
- this.widgetDeps.sdkApi.disableBackpress();
19037
+ this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
19038
+ this.widgetDeps.slideApiDeps.disableVerticalSwipeGesture();
19039
+ this.widgetDeps.slideApiDeps.disableBackpress();
17797
19040
  this._statEventWidgetOpen(this.currentModels);
17798
19041
  this.initSwipeGestureDetector();
17799
19042
  }
17800
19043
  else {
17801
19044
  if (result.message) {
17802
- this.widgetDeps.sdkApi.showToast(result.message);
19045
+ this.widgetDeps.slideApiDeps.showToast(result.message);
17803
19046
  }
17804
19047
  }
17805
19048
  this.element.classList.remove("loader");
@@ -17811,13 +19054,13 @@ class WidgetProducts extends WidgetBase {
17811
19054
  this.productsView?.classList.add("ias-products-container-view--hidden");
17812
19055
  this.element.classList.remove("hidden");
17813
19056
  this.isClickCapturedByWidget = false;
17814
- this.widgetDeps.sdkApi.enableHorizontalSwipeGesture();
19057
+ this.widgetDeps.slideApiDeps.enableHorizontalSwipeGesture();
17815
19058
  if (this.swipeGestureDetector != null) {
17816
19059
  this.swipeGestureDetector.destroy();
17817
19060
  this.swipeGestureDetector = null;
17818
19061
  }
17819
- this.widgetDeps.sdkApi.enableVerticalSwipeGesture();
17820
- this.widgetDeps.sdkApi.enableBackpress();
19062
+ this.widgetDeps.slideApiDeps.enableVerticalSwipeGesture();
19063
+ this.widgetDeps.slideApiDeps.enableBackpress();
17821
19064
  const onClosed = () => {
17822
19065
  this.productsView?.removeEventListener("animationend", onClosed);
17823
19066
  this.productsView?.parentElement?.removeChild(this.productsView);
@@ -17877,7 +19120,7 @@ class WidgetProducts extends WidgetBase {
17877
19120
  e.preventDefault();
17878
19121
  this._statEventWidgetCardClick(offer);
17879
19122
  if (offer.url) {
17880
- this.widgetDeps.sdkApi.openUrl({ type: "link", link: { type: "url", target: offer.url } });
19123
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target: offer.url } });
17881
19124
  }
17882
19125
  };
17883
19126
  card.appendChild(figure);
@@ -18108,10 +19351,10 @@ class WidgetQuest extends WidgetBase {
18108
19351
  super.onRefreshUserData(localData);
18109
19352
  }
18110
19353
  setCardSessionValue(name, value) {
18111
- this.widgetDeps.sdkApi.setCardSessionValue(this.element, name, value);
19354
+ this.widgetDeps.slideApiDeps.setCardSessionValue(this.element, name, value);
18112
19355
  }
18113
19356
  getCardSessionValue(name) {
18114
- return this.widgetDeps.sdkApi.getCardSessionValue(this.element, name);
19357
+ return this.widgetDeps.slideApiDeps.getCardSessionValue(this.element, name);
18115
19358
  }
18116
19359
  init() {
18117
19360
  if (this.localData) {
@@ -18130,8 +19373,8 @@ class WidgetQuest extends WidgetBase {
18130
19373
  // global flag - был сделан переход на нужный слайд, больше не нужно повторять за эту сессию
18131
19374
  // perform showStorySlide with lastSlideIdx only on story open first time (not on second slide, etc)
18132
19375
  this.setCardSessionValue("__storyQuestSlideChanged", "1");
18133
- if (this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18134
- this.widgetDeps.sdkApi.showCardSlide(lastSlideIdx);
19376
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19377
+ this.widgetDeps.slideApiDeps.showCardSlide(lastSlideIdx);
18135
19378
  return false;
18136
19379
  }
18137
19380
  }
@@ -18142,8 +19385,8 @@ class WidgetQuest extends WidgetBase {
18142
19385
  // если этого слайда нет в роутинге (сработал переход по таймеру в app)
18143
19386
  const routes = this._getRoutes();
18144
19387
  if (routes[0].indexOf(this.slideIndex) === -1 && this.finalSlide) {
18145
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18146
- this.widgetDeps.sdkApi.cardShowNext();
19388
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19389
+ this.widgetDeps.slideApiDeps.cardShowNext();
18147
19390
  return false;
18148
19391
  }
18149
19392
  }
@@ -18189,10 +19432,10 @@ class WidgetQuest extends WidgetBase {
18189
19432
  this._selectAnswer(index, slideIndex);
18190
19433
  this.setLocalData(this.localData, true);
18191
19434
  this.env.setTimeout(() => {
18192
- if (slideIndex >= 0 && slideIndex < this.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19435
+ if (slideIndex >= 0 && slideIndex < this.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18193
19436
  // global flag - был сделан переход на нужный слайд, больше не нужно повторять за эту сессию
18194
19437
  this.setCardSessionValue("__storyQuestSlideChanged", "1");
18195
- this.widgetDeps.sdkApi.showCardSlide(slideIndex);
19438
+ this.widgetDeps.slideApiDeps.showCardSlide(slideIndex);
18196
19439
  }
18197
19440
  }, 100);
18198
19441
  }
@@ -18264,12 +19507,12 @@ class WidgetQuest extends WidgetBase {
18264
19507
  else {
18265
19508
  // by routing - move back
18266
19509
  moveTo = this._routeMvPtrBack();
18267
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18268
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19510
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19511
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18269
19512
  }
18270
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19513
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18271
19514
  // allow move to start - for broken route history
18272
- this.widgetDeps.sdkApi.showCardSlide(0);
19515
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18273
19516
  }
18274
19517
  }
18275
19518
  return result;
@@ -18285,8 +19528,8 @@ class WidgetQuest extends WidgetBase {
18285
19528
  if (directionForward) {
18286
19529
  if (this.navigationNextSlide === -1) {
18287
19530
  // this is the final slide - exit from this quest
18288
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18289
- this.widgetDeps.sdkApi.cardShowNext();
19531
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19532
+ this.widgetDeps.slideApiDeps.cardShowNext();
18290
19533
  }
18291
19534
  result.continueDefaultNavigation = false;
18292
19535
  return result;
@@ -18295,11 +19538,11 @@ class WidgetQuest extends WidgetBase {
18295
19538
  if (nextSlideIndex < this.slideCount) {
18296
19539
  this._addNewRouteHistory(nextSlideIndex);
18297
19540
  this.setLocalData(this.localData, true);
18298
- this.widgetDeps.sdkApi.showCardSlide(nextSlideIndex);
19541
+ this.widgetDeps.slideApiDeps.showCardSlide(nextSlideIndex);
18299
19542
  }
18300
19543
  else {
18301
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18302
- this.widgetDeps.sdkApi.cardShowNext();
19544
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19545
+ this.widgetDeps.slideApiDeps.cardShowNext();
18303
19546
  }
18304
19547
  }
18305
19548
  }
@@ -18312,12 +19555,12 @@ class WidgetQuest extends WidgetBase {
18312
19555
  else {
18313
19556
  // by routing - move back
18314
19557
  moveTo = this._routeMvPtrBack();
18315
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18316
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19558
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19559
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18317
19560
  }
18318
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19561
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18319
19562
  // allow move to start - for broken route history
18320
- this.widgetDeps.sdkApi.showCardSlide(0);
19563
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18321
19564
  }
18322
19565
  }
18323
19566
  }
@@ -18332,11 +19575,11 @@ class WidgetQuest extends WidgetBase {
18332
19575
  if (nextSlideIndex < this.slideCount) {
18333
19576
  this._addNewRouteHistory(nextSlideIndex);
18334
19577
  this.setLocalData(this.localData, true);
18335
- this.widgetDeps.sdkApi.showCardSlide(nextSlideIndex);
19578
+ this.widgetDeps.slideApiDeps.showCardSlide(nextSlideIndex);
18336
19579
  }
18337
19580
  else {
18338
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18339
- this.widgetDeps.sdkApi.cardShowNext();
19581
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19582
+ this.widgetDeps.slideApiDeps.cardShowNext();
18340
19583
  }
18341
19584
  }
18342
19585
  }
@@ -18349,12 +19592,12 @@ class WidgetQuest extends WidgetBase {
18349
19592
  else {
18350
19593
  // by routing - move back
18351
19594
  moveTo = this._routeMvPtrBack();
18352
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18353
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19595
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19596
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18354
19597
  }
18355
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19598
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18356
19599
  // allow move to start - for broken route history
18357
- this.widgetDeps.sdkApi.showCardSlide(0);
19600
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18358
19601
  }
18359
19602
  }
18360
19603
  }
@@ -18369,20 +19612,20 @@ class WidgetQuest extends WidgetBase {
18369
19612
  // setLocalData(this.localData, true);
18370
19613
  // window._showNarrativeSlide(nextSlideIndex);
18371
19614
  // } else {
18372
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18373
- this.widgetDeps.sdkApi.cardShowNext();
19615
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19616
+ this.widgetDeps.slideApiDeps.cardShowNext();
18374
19617
  }
18375
19618
  // }
18376
19619
  }
18377
19620
  else {
18378
19621
  // by routing - move back
18379
19622
  moveTo = this._routeMvPtrBack();
18380
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18381
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19623
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19624
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18382
19625
  }
18383
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19626
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18384
19627
  // allow move to start - for broken route history
18385
- this.widgetDeps.sdkApi.showCardSlide(0);
19628
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18386
19629
  }
18387
19630
  }
18388
19631
  }
@@ -19172,7 +20415,7 @@ class WidgetRangeSlider extends WidgetBase {
19172
20415
  total_user: 0,
19173
20416
  };
19174
20417
  let answerAllocationTs = undefined;
19175
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
20418
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
19176
20419
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
19177
20420
  answerAllocation = sharedData[this.elementId];
19178
20421
  answerAllocationTs = sharedData.ts;
@@ -19272,7 +20515,7 @@ class WidgetRangeSlider extends WidgetBase {
19272
20515
  }
19273
20516
  e.preventDefault();
19274
20517
  this.isClickCapturedBySlider = true;
19275
- this.widgetDeps.sdkApi.disableHorizontalSwipeGesture();
20518
+ this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
19276
20519
  if (!this.maxHandlePos) {
19277
20520
  this.update(true, false);
19278
20521
  }
@@ -19302,7 +20545,7 @@ class WidgetRangeSlider extends WidgetBase {
19302
20545
  handleEnd(e) {
19303
20546
  this.env.requestAnimationFrame(() => {
19304
20547
  this.isClickCapturedBySlider = false;
19305
- this.widgetDeps.sdkApi.enableHorizontalSwipeGesture();
20548
+ this.widgetDeps.slideApiDeps.enableHorizontalSwipeGesture();
19306
20549
  });
19307
20550
  // e.preventDefault();
19308
20551
  this.widgetDeps.slideRoot.removeEventListener("touchmove", this.handleMove);
@@ -19367,7 +20610,7 @@ class WidgetRangeSlider extends WidgetBase {
19367
20610
  if (this.value !== this.prevSnapValue) {
19368
20611
  this.prevSnapValue = this.value;
19369
20612
  try {
19370
- this.widgetDeps.sdkApi.vibrate(20);
20613
+ this.widgetDeps.slideApiDeps.vibrate(20);
19371
20614
  }
19372
20615
  catch (e) {
19373
20616
  console.error(e);
@@ -19614,12 +20857,12 @@ class WidgetRate extends WidgetBase {
19614
20857
  if (this.showDialogOnLowRate) {
19615
20858
  this.elementRect = this.element.getBoundingClientRect();
19616
20859
  this._selectStar(this.selectedStar, false);
19617
- if (this.widgetDeps.sdkApi.isAndroid) {
20860
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
19618
20861
  this.slide.classList.add("blured");
19619
20862
  }
19620
20863
  this.slide.classList.add("data-input-editing");
19621
20864
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
19622
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
20865
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
19623
20866
  const data = JSON.parse(dataString);
19624
20867
  data.size = getElementBounding(this.env, this.elementRect);
19625
20868
  if (!this.disableTimer) {
@@ -19641,7 +20884,7 @@ class WidgetRate extends WidgetBase {
19641
20884
  catch (e) {
19642
20885
  console.error(e);
19643
20886
  }
19644
- this.widgetDeps.sdkApi.showCardTextInput(this.id, data);
20887
+ this.widgetDeps.slideApiDeps.showCardTextInput(this.id, data);
19645
20888
  }
19646
20889
  }
19647
20890
  else {
@@ -19653,17 +20896,17 @@ class WidgetRate extends WidgetBase {
19653
20896
  }
19654
20897
  else if (value + 1 >= this.submitToStoresMin && value + 1 <= this.submitToStoresMax) {
19655
20898
  let target = null;
19656
- if (this.widgetDeps.sdkApi.isAndroid) {
20899
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
19657
20900
  target = getTagData(this.element, "androidLink");
19658
20901
  }
19659
- else if (this.widgetDeps.sdkApi.isIOS) {
20902
+ else if (this.widgetDeps.slideApiDeps.isIOS) {
19660
20903
  target = getTagData(this.element, "appleLink");
19661
20904
  }
19662
20905
  this._selectStar(value, true);
19663
20906
  this.completeWidget();
19664
20907
  this._statEventRateUsAnswer("");
19665
20908
  if (this.submitToStores && target) {
19666
- this.widgetDeps.sdkApi.openUrl({ type: "link", link: { type: "url", target } });
20909
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target } });
19667
20910
  }
19668
20911
  }
19669
20912
  else {
@@ -19812,12 +21055,12 @@ class WidgetShare extends WidgetBase {
19812
21055
  }
19813
21056
  share() {
19814
21057
  if (!this.btnDisabled) {
19815
- if (this.widgetDeps.sdkApi.isExistsShare) {
19816
- if (this.widgetDeps.sdkApi.sdkCanSendShareComplete) {
21058
+ if (this.widgetDeps.slideApiDeps.isExistsShare) {
21059
+ if (this.widgetDeps.slideApiDeps.sdkCanSendShareComplete) {
19817
21060
  this.btnDisabled = true;
19818
21061
  }
19819
21062
  if (this.shareType === "url" || this.shareType === "story") {
19820
- this.widgetDeps.sdkApi.share(this.id, {
21063
+ this.widgetDeps.slideApiDeps.share(this.id, {
19821
21064
  url: this.shareTarget, // sdk old versions
19822
21065
  text: this.shareTarget,
19823
21066
  title: null,
@@ -19825,7 +21068,7 @@ class WidgetShare extends WidgetBase {
19825
21068
  });
19826
21069
  }
19827
21070
  else if (this.shareType === "slide") {
19828
- this.widgetDeps.sdkApi.shareSlideScreenshot(this.id, "[data-element-id='" + this.elementId + "']", this.shareTarget ? this.shareTarget : undefined);
21071
+ this.widgetDeps.slideApiDeps.shareSlideScreenshot(this.id, "[data-element-id='" + this.elementId + "']", this.shareTarget ? this.shareTarget : undefined);
19829
21072
  }
19830
21073
  }
19831
21074
  }
@@ -20431,9 +21674,9 @@ class WidgetTooltip extends WidgetBase {
20431
21674
  copyToClipboard(element) {
20432
21675
  const textValue = this.template1ClipboardTarget ?? "";
20433
21676
  if (textValue) {
20434
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
21677
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
20435
21678
  if (this.template1CopiedText) {
20436
- this.widgetDeps.sdkApi.showToast(this.template1CopiedText);
21679
+ this.widgetDeps.slideApiDeps.showToast(this.template1CopiedText);
20437
21680
  }
20438
21681
  }
20439
21682
  this._statEventWidgetCopyClick(textValue);
@@ -20812,7 +22055,7 @@ class WidgetVote extends WidgetBase {
20812
22055
  // voteAllocation[7]
20813
22056
  let voteAllocation = [];
20814
22057
  let voteAllocationTs = undefined;
20815
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
22058
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
20816
22059
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
20817
22060
  voteAllocation = sharedData[this.elementId];
20818
22061
  if (isObject$1(sharedData[this.elementId])) {