@inappstory/slide-api 0.1.24 → 0.1.26

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) {
@@ -1133,6 +1133,9 @@ class EsModuleSdkApi {
1133
1133
  getCardSessionValue(element, key) {
1134
1134
  return this.sdkBinding.getCardSessionValue(key);
1135
1135
  }
1136
+ isSdkSupportUpdateTimeline() {
1137
+ return true;
1138
+ }
1136
1139
  updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
1137
1140
  this.sdkBinding.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
1138
1141
  }
@@ -1173,9 +1176,79 @@ class EsModuleSdkApi {
1173
1176
  isSdkSupportCorrectPauseResumeLifecycle() {
1174
1177
  return true;
1175
1178
  }
1179
+ emitEvent(name, event) {
1180
+ this.sdkBinding.onEvent(name, event);
1181
+ }
1182
+ onCardLoadingStateChange(state, reason) {
1183
+ // console.log("onCardLoadingStateChange", { state });
1184
+ this.sdkBinding.onCardLoadingStateChange(state, reason);
1185
+ }
1176
1186
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKInterface`]; }
1177
1187
  }
1178
1188
 
1189
+ class CardLoadingStateController {
1190
+ onCardLoadingStateChange;
1191
+ constructor(onCardLoadingStateChange) {
1192
+ this.onCardLoadingStateChange = onCardLoadingStateChange;
1193
+ }
1194
+ timeout = 300;
1195
+ onSetLoadStartState() {
1196
+ this.onBeforeStateChanged();
1197
+ // prevent micro loaders in UI
1198
+ if (this.currentState === 1 /* CARD_LOADING_STATE.LOADED */) {
1199
+ this.deferredDataWaitingStateTimerId = window.setTimeout(() => {
1200
+ this.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */);
1201
+ this.dataWaitingStartedAt = Date.now();
1202
+ }, this.timeout);
1203
+ }
1204
+ else {
1205
+ this.onCardLoadingStateChange(0 /* CARD_LOADING_STATE.LOADING */);
1206
+ this.dataWaitingStartedAt = Date.now();
1207
+ }
1208
+ this.currentState = 0 /* CARD_LOADING_STATE.LOADING */;
1209
+ }
1210
+ onSetLoadEndState() {
1211
+ this.onBeforeStateChanged();
1212
+ // prevent micro loaders in UI
1213
+ const delay = this.timeout;
1214
+ let dataWaitingLoaderSpent = delay;
1215
+ if (this.dataWaitingStartedAt != null) {
1216
+ dataWaitingLoaderSpent = Date.now() - this.dataWaitingStartedAt;
1217
+ }
1218
+ if (dataWaitingLoaderSpent < delay) {
1219
+ this.deferredResumeStateTimerId = window.setTimeout(() => this.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */), dataWaitingLoaderSpent - delay);
1220
+ }
1221
+ else {
1222
+ this.onCardLoadingStateChange(1 /* CARD_LOADING_STATE.LOADED */);
1223
+ }
1224
+ this.currentState = 1 /* CARD_LOADING_STATE.LOADED */;
1225
+ }
1226
+ onSetLoadErrorState(reason) {
1227
+ this.onBeforeStateChanged();
1228
+ this.onCardLoadingStateChange(2 /* CARD_LOADING_STATE.LOADING_ERROR */, reason);
1229
+ this.currentState = 2 /* CARD_LOADING_STATE.LOADING_ERROR */;
1230
+ }
1231
+ currentState = 0 /* CARD_LOADING_STATE.LOADING */;
1232
+ deferredDataWaitingStateTimerId = null;
1233
+ deferredResumeStateTimerId = null;
1234
+ dataWaitingStartedAt = null;
1235
+ clearDeferredDataWaitingStateTimerId() {
1236
+ if (this.deferredDataWaitingStateTimerId != null) {
1237
+ window.clearTimeout(this.deferredDataWaitingStateTimerId);
1238
+ }
1239
+ }
1240
+ clearDeferredResumeStateTimerId() {
1241
+ if (this.deferredResumeStateTimerId != null) {
1242
+ window.clearTimeout(this.deferredResumeStateTimerId);
1243
+ }
1244
+ }
1245
+ onBeforeStateChanged() {
1246
+ this.clearDeferredDataWaitingStateTimerId();
1247
+ this.clearDeferredResumeStateTimerId();
1248
+ }
1249
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`(state: CARD_LOADING_STATE, reason?: string) => void`]; }
1250
+ }
1251
+
1179
1252
  const DEFAULT_SLIDE_DURATION = 10000;
1180
1253
 
1181
1254
  class DataInput {
@@ -1199,6 +1272,9 @@ class DataInput {
1199
1272
  return element instanceof DataInput;
1200
1273
  }
1201
1274
  mediaElementsLoadingPromises = [];
1275
+ get nodeRef() {
1276
+ return this._elementNodeRef;
1277
+ }
1202
1278
  init(localData) {
1203
1279
  try {
1204
1280
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1249,6 +1325,9 @@ class Barcode {
1249
1325
  this._widgetDeps = _widgetDeps;
1250
1326
  }
1251
1327
  mediaElementsLoadingPromises = [];
1328
+ get nodeRef() {
1329
+ return this._elementNodeRef;
1330
+ }
1252
1331
  init(localData) {
1253
1332
  try {
1254
1333
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1286,36 +1365,311 @@ class ClickableBase {
1286
1365
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`]; }
1287
1366
  }
1288
1367
 
1368
+ class PromocodeNetworkError extends Error {
1369
+ }
1370
+ class PromocodeServiceError extends Error {
1371
+ }
1372
+ class PromocodeNoMoreCodes extends Error {
1373
+ }
1374
+ class PromocodeApi {
1375
+ sdkApi;
1376
+ messages;
1377
+ constructor(sdkApi, messages) {
1378
+ this.sdkApi = sdkApi;
1379
+ this.messages = messages;
1380
+ }
1381
+ async fetchPromoCode(params) {
1382
+ const path = this.getPromotionalCodeFetchPath(params);
1383
+ const headers = {
1384
+ accept: "application/json",
1385
+ "Content-Type": "application/json",
1386
+ };
1387
+ const [response] = await Promise.all([
1388
+ this.sdkApi.sendApiRequest(path, "POST", null, headers, null, "fetch-promo-code"),
1389
+ new Promise(resolve => setTimeout(resolve, 300)),
1390
+ ]);
1391
+ const { status, data } = response;
1392
+ if (status === 200 || status === 201) {
1393
+ const promocode = data?.code;
1394
+ if (promocode) {
1395
+ return { promocode, status };
1396
+ }
1397
+ throw new PromocodeNoMoreCodes(this.messages.noMoreCodes);
1398
+ }
1399
+ if (status === 12163 || status === 12002) {
1400
+ throw new PromocodeNetworkError(this.messages.networkError);
1401
+ }
1402
+ throw new PromocodeServiceError(this.messages.serviceError);
1403
+ }
1404
+ getPromotionalCodeFetchPath(params) {
1405
+ switch (params.card.type) {
1406
+ case 4 /* CARD_TYPE.IN_APP_MESSAGING */:
1407
+ return `inappmessaging/message/${params.card.id}/widget/${params.elementId}/promo-code/${params.promocodeId}`;
1408
+ default:
1409
+ return `story/${params.card.id}/widget/${params.elementId}/promo-code/${params.promocodeId}`;
1410
+ }
1411
+ }
1412
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Pick`, `{
1413
+ noMoreCodes?: string;
1414
+ networkError?: string;
1415
+ serviceError?: string;
1416
+ }`]; }
1417
+ }
1418
+
1419
+ class PromocodeLocalRepository {
1420
+ elementId;
1421
+ sdkApi;
1422
+ localData = {};
1423
+ constructor(elementId, sdkApi) {
1424
+ this.elementId = elementId;
1425
+ this.sdkApi = sdkApi;
1426
+ }
1427
+ init({ localData, cardId }) {
1428
+ const savedData = this.sdkApi.getCardServerData(cardId) ?? {};
1429
+ this.localData = extend({}, savedData, localData ?? {});
1430
+ }
1431
+ getPromocode() {
1432
+ return this.localData["_pcl_g_" + this.elementId + "_pc"];
1433
+ }
1434
+ savePromocodeByStatus(promocode, status) {
1435
+ if (status === 201)
1436
+ this.savePromocodeWithTime(promocode);
1437
+ else
1438
+ this.savePromocode(promocode);
1439
+ }
1440
+ savePromocodeWithTime(promocode) {
1441
+ this.localData["_pcl_g_" + this.elementId + "_pc_fetched_at"] = Math.round(new Date().getTime() / 1000);
1442
+ this.localData["_&ts_pcl_g_" + this.elementId + "_pc_fetched_at"] = Math.round(new Date().getTime() / 1000);
1443
+ this.savePromocode(promocode);
1444
+ }
1445
+ savePromocode(promocode) {
1446
+ this.localData["_pcl_g_" + this.elementId + "_pc"] = promocode;
1447
+ this.setCardLocalData(this.localData);
1448
+ }
1449
+ async setCardLocalData(newLocalData) {
1450
+ const localData = await this.sdkApi.getCardLocalData();
1451
+ const mergedData = extend({}, localData, newLocalData);
1452
+ await this.sdkApi.setCardLocalData(mergedData, true);
1453
+ }
1454
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`string`, `ISlideApiDeps`]; }
1455
+ }
1456
+
1457
+ var PromocodeLinkState;
1458
+ (function (PromocodeLinkState) {
1459
+ PromocodeLinkState[PromocodeLinkState["Idle"] = 0] = "Idle";
1460
+ PromocodeLinkState[PromocodeLinkState["Fetched"] = 1] = "Fetched";
1461
+ PromocodeLinkState[PromocodeLinkState["Error"] = 2] = "Error";
1462
+ })(PromocodeLinkState || (PromocodeLinkState = {}));
1463
+ const PROMOCODE_PLACEHOLDER = "%__ias_pc%";
1464
+ class PromocodeLink {
1465
+ element;
1466
+ layer;
1467
+ widgetDeps;
1468
+ state = PromocodeLinkState.Idle;
1469
+ promocode = null;
1470
+ promocodeId;
1471
+ linkTemplate;
1472
+ textContent;
1473
+ button;
1474
+ elementId;
1475
+ card;
1476
+ api;
1477
+ localRepository;
1478
+ constructor(element, layer, widgetDeps) {
1479
+ this.element = element;
1480
+ this.layer = layer;
1481
+ this.widgetDeps = widgetDeps;
1482
+ this.elementId = getValueOrException(getTagData(this.element, "elementId"), "Empty elementId");
1483
+ this.promocodeId = getTagData(this.element, "linkTarget") ?? "";
1484
+ this.linkTemplate = getTagData(this.element, "linkTemplate") ?? "";
1485
+ this.button = this.element.querySelector(".narrative-element-text-lines");
1486
+ this.textContent = this.button?.textContent ?? "";
1487
+ this.card = this.getCard();
1488
+ this.api = new PromocodeApi(this.widgetDeps.slideApiDeps, {
1489
+ networkError: getTagData(this.element, "msgNetworkError") ?? "",
1490
+ serviceError: getTagData(this.element, "msgServiceError") ?? "",
1491
+ noMoreCodes: getTagData(this.element, "msgNoMoreCodes") ?? "",
1492
+ });
1493
+ this.localRepository = new PromocodeLocalRepository(this.elementId, this.widgetDeps.slideApiDeps);
1494
+ }
1495
+ get nodeRef() {
1496
+ return this.element;
1497
+ }
1498
+ mediaElementsLoadingPromises = [];
1499
+ init(localData) {
1500
+ this.localRepository.init({ localData: localData ?? {}, cardId: this.card.id });
1501
+ this.state = PromocodeLinkState.Idle;
1502
+ const promocode = this.localRepository.getPromocode();
1503
+ if (promocode) {
1504
+ this.state = PromocodeLinkState.Fetched;
1505
+ this.showPromocode(promocode);
1506
+ this.promocode = promocode;
1507
+ }
1508
+ return Promise.resolve(true);
1509
+ }
1510
+ onPause() { }
1511
+ onResume() { }
1512
+ onStop() { }
1513
+ onBeforeUnmount() {
1514
+ return Promise.resolve();
1515
+ }
1516
+ handleClick() {
1517
+ switch (this.state) {
1518
+ case PromocodeLinkState.Idle:
1519
+ return false;
1520
+ case PromocodeLinkState.Fetched:
1521
+ this.openPromocodeUrl();
1522
+ return true;
1523
+ case PromocodeLinkState.Error:
1524
+ this.loadPromocode(this.promocodeId).catch(() => { });
1525
+ break;
1526
+ }
1527
+ return false;
1528
+ }
1529
+ get isLayerForcePaused() {
1530
+ return false;
1531
+ }
1532
+ onStart() {
1533
+ this.element.classList.add("active");
1534
+ this.loadPromocode(this.promocodeId).catch(() => { });
1535
+ }
1536
+ openPromocodeUrl() {
1537
+ if (!this.promocode)
1538
+ return;
1539
+ const target = this.linkTemplate.replaceAll(PROMOCODE_PLACEHOLDER, this.promocode);
1540
+ this.layer.layoutService.env.setTimeout(() => {
1541
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target } });
1542
+ });
1543
+ }
1544
+ async loadPromocode(promocodeId) {
1545
+ try {
1546
+ this.state = PromocodeLinkState.Idle;
1547
+ this.showLoader();
1548
+ const promocode = await this.getPromocode({
1549
+ promocodeId,
1550
+ card: this.card,
1551
+ elementId: this.elementId,
1552
+ });
1553
+ this.state = PromocodeLinkState.Fetched;
1554
+ this.promocode = promocode;
1555
+ this.showPromocode(promocode);
1556
+ return promocode;
1557
+ }
1558
+ catch (error) {
1559
+ this.handleLoadPromocodeError(error);
1560
+ throw error;
1561
+ }
1562
+ finally {
1563
+ this.hideLoader();
1564
+ }
1565
+ }
1566
+ async getPromocode(params) {
1567
+ if (this.promocode)
1568
+ return this.promocode;
1569
+ let promocode = this.localRepository.getPromocode();
1570
+ if (!promocode) {
1571
+ const result = await this.api.fetchPromoCode(params);
1572
+ promocode = result.promocode;
1573
+ this.localRepository.savePromocodeByStatus(promocode, result.status);
1574
+ }
1575
+ this.promocode = promocode;
1576
+ return promocode;
1577
+ }
1578
+ handleLoadPromocodeError(error) {
1579
+ this.state = PromocodeLinkState.Error;
1580
+ this.showErrorMessage(getTagData(this.element, "msgTryAgain") ?? "");
1581
+ if (error.message.length) {
1582
+ this.widgetDeps.slideApiDeps.showToast(error.message);
1583
+ }
1584
+ }
1585
+ showPromocode(promocode) {
1586
+ if (!this.button)
1587
+ return;
1588
+ this.button.textContent = this.textContent.replaceAll(PROMOCODE_PLACEHOLDER, promocode);
1589
+ }
1590
+ showErrorMessage(message) {
1591
+ if (!this.button)
1592
+ return;
1593
+ this.button.textContent = message;
1594
+ }
1595
+ getCard() {
1596
+ const slide = getValueOrException(this.element.closest(".narrative-slide"), "Empty slide");
1597
+ return {
1598
+ id: getValueOrException(getTagDataAsNumber(slide, "id"), "Empty cardId"),
1599
+ type: getValueOrException(getTagDataAsNumber(slide, "cardType"), "Empty card type"),
1600
+ };
1601
+ }
1602
+ showLoader() {
1603
+ if (!this.isTransparentElement())
1604
+ addClass(this.element, "loader");
1605
+ }
1606
+ hideLoader() {
1607
+ removeClass(this.element, "loader");
1608
+ }
1609
+ isTransparentElement() {
1610
+ if (this.element) {
1611
+ try {
1612
+ const color = window.getComputedStyle(this.element).color;
1613
+ if (color === "transparent" || color === "rgba(0, 0, 0, 0)" || color === "rgba(0,0,0,0)") {
1614
+ return true;
1615
+ }
1616
+ }
1617
+ catch (err) {
1618
+ console.error(err);
1619
+ }
1620
+ }
1621
+ return false;
1622
+ }
1623
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `WidgetDeps`]; }
1624
+ }
1625
+
1289
1626
  class Button extends ClickableBase {
1290
1627
  _elementNodeRef;
1291
- _layer;
1628
+ layer;
1629
+ widgetDeps;
1292
1630
  static _className = "narrative-element-link";
1631
+ isPromotionalCode;
1632
+ promocodeLink = null;
1293
1633
  static className() {
1294
1634
  return Button._className;
1295
1635
  }
1296
- constructor(_elementNodeRef, _layer) {
1636
+ static isTypeOf(element) {
1637
+ return element instanceof Button;
1638
+ }
1639
+ constructor(_elementNodeRef, layer, widgetDeps) {
1297
1640
  super(_elementNodeRef);
1298
1641
  this._elementNodeRef = _elementNodeRef;
1299
- this._layer = _layer;
1642
+ this.layer = layer;
1643
+ this.widgetDeps = widgetDeps;
1644
+ this.isPromotionalCode = getTagData(_elementNodeRef, "linkType") === "promocode";
1645
+ if (this.isPromotionalCode) {
1646
+ this.promocodeLink = new PromocodeLink(_elementNodeRef, layer, widgetDeps);
1647
+ }
1648
+ }
1649
+ get nodeRef() {
1650
+ return this._elementNodeRef;
1300
1651
  }
1301
1652
  mediaElementsLoadingPromises = [];
1302
- init(localData) {
1303
- return Promise.resolve(true);
1653
+ async init(localData) {
1654
+ await this.promocodeLink?.init(localData);
1655
+ return true;
1304
1656
  }
1305
1657
  onPause() { }
1306
1658
  onResume() { }
1307
- onStart() { }
1659
+ onStart() {
1660
+ this.promocodeLink?.onStart();
1661
+ }
1308
1662
  onStop() { }
1309
1663
  onBeforeUnmount() {
1310
1664
  return Promise.resolve();
1311
1665
  }
1312
1666
  handleClick() {
1313
- return false;
1667
+ return this.promocodeLink?.handleClick() ?? true;
1314
1668
  }
1315
1669
  get isLayerForcePaused() {
1316
1670
  return false;
1317
1671
  }
1318
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`]; }
1672
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `WidgetDeps`]; }
1319
1673
  }
1320
1674
 
1321
1675
  class Copy {
@@ -1336,6 +1690,9 @@ class Copy {
1336
1690
  this._widgetDeps = _widgetDeps;
1337
1691
  }
1338
1692
  mediaElementsLoadingPromises = [];
1693
+ get nodeRef() {
1694
+ return this._elementNodeRef;
1695
+ }
1339
1696
  init(localData) {
1340
1697
  try {
1341
1698
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1385,6 +1742,9 @@ class DateCountdown {
1385
1742
  this._widgetDeps = _widgetDeps;
1386
1743
  }
1387
1744
  mediaElementsLoadingPromises = [];
1745
+ get nodeRef() {
1746
+ return this._elementNodeRef;
1747
+ }
1388
1748
  init(localData) {
1389
1749
  try {
1390
1750
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1439,6 +1799,9 @@ class Poll {
1439
1799
  return element instanceof Poll;
1440
1800
  }
1441
1801
  mediaElementsLoadingPromises = [];
1802
+ get nodeRef() {
1803
+ return this._elementNodeRef;
1804
+ }
1442
1805
  init(localData) {
1443
1806
  try {
1444
1807
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1494,6 +1857,9 @@ class PollLayers {
1494
1857
  return element instanceof PollLayers;
1495
1858
  }
1496
1859
  mediaElementsLoadingPromises = [];
1860
+ get nodeRef() {
1861
+ return this._elementNodeRef;
1862
+ }
1497
1863
  init(localData) {
1498
1864
  try {
1499
1865
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1544,6 +1910,9 @@ class Products {
1544
1910
  return element instanceof Products;
1545
1911
  }
1546
1912
  mediaElementsLoadingPromises = [];
1913
+ get nodeRef() {
1914
+ return this._elementNodeRef;
1915
+ }
1547
1916
  init(localData) {
1548
1917
  try {
1549
1918
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1603,6 +1972,9 @@ class Quest {
1603
1972
  return element instanceof Quest;
1604
1973
  }
1605
1974
  mediaElementsLoadingPromises = [];
1975
+ get nodeRef() {
1976
+ return this._elementNodeRef;
1977
+ }
1606
1978
  init(localData) {
1607
1979
  return this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
1608
1980
  }
@@ -1651,6 +2023,9 @@ class Quiz {
1651
2023
  return element instanceof Quiz;
1652
2024
  }
1653
2025
  mediaElementsLoadingPromises = [];
2026
+ get nodeRef() {
2027
+ return this._elementNodeRef;
2028
+ }
1654
2029
  init(localData) {
1655
2030
  try {
1656
2031
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1704,6 +2079,9 @@ class QuizGrouped {
1704
2079
  return element instanceof QuizGrouped;
1705
2080
  }
1706
2081
  mediaElementsLoadingPromises = [];
2082
+ get nodeRef() {
2083
+ return this._elementNodeRef;
2084
+ }
1707
2085
  init(localData) {
1708
2086
  try {
1709
2087
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1757,6 +2135,9 @@ class RangeSlider {
1757
2135
  return element instanceof RangeSlider;
1758
2136
  }
1759
2137
  mediaElementsLoadingPromises = [];
2138
+ get nodeRef() {
2139
+ return this._elementNodeRef;
2140
+ }
1760
2141
  init(localData) {
1761
2142
  try {
1762
2143
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1810,6 +2191,9 @@ class Rate {
1810
2191
  return element instanceof Rate;
1811
2192
  }
1812
2193
  mediaElementsLoadingPromises = [];
2194
+ get nodeRef() {
2195
+ return this._elementNodeRef;
2196
+ }
1813
2197
  init(localData) {
1814
2198
  try {
1815
2199
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1866,6 +2250,9 @@ class Share {
1866
2250
  return element instanceof Share;
1867
2251
  }
1868
2252
  mediaElementsLoadingPromises = [];
2253
+ get nodeRef() {
2254
+ return this._elementNodeRef;
2255
+ }
1869
2256
  init(localData) {
1870
2257
  try {
1871
2258
  this._widgetApi.init(this._elementNodeRef, this._layersNodesRefs, localData, this._widgetCallbacks, this._widgetDeps);
@@ -1913,6 +2300,9 @@ class SwipeUpItems {
1913
2300
  return element instanceof SwipeUpItems;
1914
2301
  }
1915
2302
  mediaElementsLoadingPromises = [];
2303
+ get nodeRef() {
2304
+ return this._elementNodeRef;
2305
+ }
1916
2306
  init(localData) {
1917
2307
  return Promise.resolve(true);
1918
2308
  }
@@ -1956,6 +2346,9 @@ class Test {
1956
2346
  return element instanceof Test;
1957
2347
  }
1958
2348
  mediaElementsLoadingPromises = [];
2349
+ get nodeRef() {
2350
+ return this._elementNodeRef;
2351
+ }
1959
2352
  init(localData) {
1960
2353
  try {
1961
2354
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2009,6 +2402,9 @@ class Tooltip {
2009
2402
  this._widgetDeps = _widgetDeps;
2010
2403
  }
2011
2404
  mediaElementsLoadingPromises = [];
2405
+ get nodeRef() {
2406
+ return this._elementNodeRef;
2407
+ }
2012
2408
  init(localData) {
2013
2409
  try {
2014
2410
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2056,6 +2452,9 @@ class Vote {
2056
2452
  this._widgetDeps = _widgetDeps;
2057
2453
  }
2058
2454
  mediaElementsLoadingPromises = [];
2455
+ get nodeRef() {
2456
+ return this._elementNodeRef;
2457
+ }
2059
2458
  init(localData) {
2060
2459
  try {
2061
2460
  this._widgetApi.init(this._elementNodeRef, localData, this._widgetCallbacks, this._widgetDeps);
@@ -2097,6 +2496,9 @@ class Text {
2097
2496
  this._layer = _layer;
2098
2497
  }
2099
2498
  mediaElementsLoadingPromises = [];
2499
+ get nodeRef() {
2500
+ return this._elementNodeRef;
2501
+ }
2100
2502
  init(localData) {
2101
2503
  return Promise.resolve(true);
2102
2504
  }
@@ -2220,6 +2622,9 @@ class Image extends ClickableBase {
2220
2622
  this.mediaElementsLoadingPromises = mediaElements.map(waitForImageHtmlElementLoad);
2221
2623
  }
2222
2624
  mediaElementsLoadingPromises = [];
2625
+ get nodeRef() {
2626
+ return this._elementNodeRef;
2627
+ }
2223
2628
  init(localData) {
2224
2629
  return Promise.resolve(true);
2225
2630
  }
@@ -2254,6 +2659,9 @@ class SwipeUp {
2254
2659
  return element instanceof SwipeUp;
2255
2660
  }
2256
2661
  mediaElementsLoadingPromises = [];
2662
+ get nodeRef() {
2663
+ return this._elementNodeRef;
2664
+ }
2257
2665
  init(localData) {
2258
2666
  return Promise.resolve(true);
2259
2667
  }
@@ -2280,7 +2688,7 @@ class Video {
2280
2688
  _elementNodeRef;
2281
2689
  _layer;
2282
2690
  _VideoPlayer;
2283
- _sdkApi;
2691
+ _slideApiDeps;
2284
2692
  static _className = "narrative-element-video";
2285
2693
  static className() {
2286
2694
  return Video._className;
@@ -2290,11 +2698,11 @@ class Video {
2290
2698
  _vodData;
2291
2699
  _vodPlayerInstance = null;
2292
2700
  _videoStateAdapter = null;
2293
- constructor(_elementNodeRef, _layer, _VideoPlayer, _sdkApi) {
2701
+ constructor(_elementNodeRef, _layer, _VideoPlayer, _slideApiDeps) {
2294
2702
  this._elementNodeRef = _elementNodeRef;
2295
2703
  this._layer = _layer;
2296
2704
  this._VideoPlayer = _VideoPlayer;
2297
- this._sdkApi = _sdkApi;
2705
+ this._slideApiDeps = _slideApiDeps;
2298
2706
  const _video = this._elementNodeRef.querySelector("video");
2299
2707
  if (!_video) {
2300
2708
  return;
@@ -2350,6 +2758,9 @@ class Video {
2350
2758
  return element instanceof Video;
2351
2759
  }
2352
2760
  mediaElementsLoadingPromises = [];
2761
+ get nodeRef() {
2762
+ return this._elementNodeRef;
2763
+ }
2353
2764
  init(localData) {
2354
2765
  return Promise.resolve(true);
2355
2766
  }
@@ -2369,6 +2780,9 @@ class Video {
2369
2780
  // console.log("onBeforeUnmount")
2370
2781
  return await this._destroyVODPlayer();
2371
2782
  }
2783
+ get durationMs() {
2784
+ return this._video.duration * 1000;
2785
+ }
2372
2786
  _initVOD(vodData) {
2373
2787
  const onWaiting = () => {
2374
2788
  /**
@@ -2394,7 +2808,7 @@ class Video {
2394
2808
  // TODO via class instead of data attr
2395
2809
  if (this._video.getAttribute("data-waiting") === "1") {
2396
2810
  this._video.setAttribute("data-waiting", "0");
2397
- this._layer.timeline.slideResumed(this._video.currentTime * 1000);
2811
+ this._layer.timeline.slideResumed(() => this._video.currentTime * 1000);
2398
2812
  // @ts-ignore
2399
2813
  // _log(`playing: ${this._video.currentTime}`, true);
2400
2814
  // clearTimeout(window.synthErrorId);
@@ -2478,13 +2892,13 @@ class Video {
2478
2892
  });
2479
2893
  }
2480
2894
  _convertMpdUrls(mpd_) {
2481
- if (this._sdkApi.isWeb) {
2895
+ if (this._slideApiDeps.isWeb) {
2482
2896
  return mpd_;
2483
2897
  }
2484
2898
  if (isObject(mpd_) && mpd_.adaptiveFormats != null && Array.isArray(mpd_.adaptiveFormats)) {
2485
2899
  const mpd = { ...mpd_ };
2486
2900
  for (let i = 0; i < mpd.adaptiveFormats.length; ++i) {
2487
- mpd.adaptiveFormats[i].url = `${this._sdkApi.isAndroid ? `http://vod-asset/` : `vod-asset://`}${mpd.adaptiveFormats[i].cacheName}`;
2901
+ mpd.adaptiveFormats[i].url = `${this._slideApiDeps.isAndroid ? `http://vod-asset/` : `vod-asset://`}${mpd.adaptiveFormats[i].cacheName}`;
2488
2902
  }
2489
2903
  return mpd;
2490
2904
  }
@@ -2519,7 +2933,13 @@ class Video {
2519
2933
  get videoStartedPromise() {
2520
2934
  return this._videoStartedPromise;
2521
2935
  }
2522
- start(muted = true, loop = true) {
2936
+ get isLooped() {
2937
+ if (this._video != null) {
2938
+ return this._video?.loop;
2939
+ }
2940
+ return false;
2941
+ }
2942
+ start(muted = true, getIsLooped) {
2523
2943
  this._videoStartedPromise = new Promise(async (resolve) => {
2524
2944
  // invariant - always wait for mediaElementsLoadingPromises
2525
2945
  // else call of _initVOD can start and onAllMediaLoaded failed
@@ -2533,7 +2953,7 @@ class Video {
2533
2953
  // console.log("Video:start => this._video.pause()");
2534
2954
  this._video.pause();
2535
2955
  this._video.currentTime = 0;
2536
- this._video.loop = loop;
2956
+ this._video.loop = getIsLooped();
2537
2957
  // remove init class
2538
2958
  // if vod - create VoD player
2539
2959
  if (this._video.getAttribute("data-default-muted") !== "1") {
@@ -2546,13 +2966,13 @@ class Video {
2546
2966
  this._video.currentTime = 0;
2547
2967
  this._elementNodeRef.classList.remove("init");
2548
2968
  resolve({
2549
- currentTime: this._video.currentTime,
2969
+ getVideoCurrentTime: () => this._video.currentTime,
2550
2970
  });
2551
2971
  })
2552
2972
  .catch(error => {
2553
2973
  console.error(error);
2554
2974
  resolve({
2555
- currentTime: this._video.currentTime,
2975
+ getVideoCurrentTime: () => this._video.currentTime,
2556
2976
  });
2557
2977
  });
2558
2978
  }
@@ -2561,14 +2981,14 @@ class Video {
2561
2981
  this._video.currentTime = 0;
2562
2982
  this._elementNodeRef.classList.remove("init");
2563
2983
  resolve({
2564
- currentTime: this._video.currentTime,
2984
+ getVideoCurrentTime: () => this._video.currentTime,
2565
2985
  });
2566
2986
  }, 0);
2567
2987
  }
2568
2988
  }
2569
2989
  else {
2570
2990
  resolve({
2571
- currentTime: 0,
2991
+ getVideoCurrentTime: () => 0,
2572
2992
  });
2573
2993
  }
2574
2994
  });
@@ -2604,7 +3024,7 @@ class Video {
2604
3024
  // console.log("resolve 1.1", { ts });
2605
3025
  this._video.currentTime = ts;
2606
3026
  }
2607
- resolve({ currentTime: this._video.currentTime });
3027
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2608
3028
  })
2609
3029
  .catch(error => {
2610
3030
  console.error(error);
@@ -2612,7 +3032,7 @@ class Video {
2612
3032
  if (this._video.currentTime < ts) {
2613
3033
  this._video.currentTime = ts;
2614
3034
  }
2615
- resolve({ currentTime: this._video.currentTime });
3035
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2616
3036
  });
2617
3037
  }
2618
3038
  else {
@@ -2621,7 +3041,7 @@ class Video {
2621
3041
  if (this._video.currentTime < ts) {
2622
3042
  this._video.currentTime = ts;
2623
3043
  }
2624
- resolve({ currentTime: this._video.currentTime });
3044
+ resolve({ getVideoCurrentTime: () => this._video.currentTime });
2625
3045
  }, 0);
2626
3046
  }
2627
3047
  });
@@ -2675,7 +3095,7 @@ class Video {
2675
3095
  this._video.muted = true;
2676
3096
  }
2677
3097
  }
2678
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `typeof VideoPlayer | undefined`, `SDKApi`]; }
3098
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Layer`, `typeof VideoPlayer | undefined`, `ISlideApiDeps`]; }
2679
3099
  }
2680
3100
  // class VideoStateAdapter {
2681
3101
  //
@@ -2769,7 +3189,12 @@ class VideoStateAdapter {
2769
3189
  }
2770
3190
  // todo - add debounce
2771
3191
  this._playingCheckerId = window.setTimeout(() => {
3192
+ // console.log({now: Date.now(), _timeupdate: this._timeupdate, currentTime: this._video.currentTime, duration: this._video.duration});
2772
3193
  if (Date.now() - this._timeupdate >= this._maxDiff / 2) {
3194
+ // prevent onWaiting triggering if the video has ended
3195
+ if (Math.round(this._video.currentTime) >= Math.round(this._video.duration)) {
3196
+ return;
3197
+ }
2773
3198
  this._state = 2 /* VIDEO_STATE.WAITING */;
2774
3199
  this._triggerUpdate();
2775
3200
  }
@@ -2852,7 +3277,7 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
2852
3277
  case Text.className():
2853
3278
  return new Text(nodeRef, layer);
2854
3279
  case Button.className():
2855
- return new Button(nodeRef, layer);
3280
+ return new Button(nodeRef, layer, widgetDeps);
2856
3281
  case Image.className():
2857
3282
  return new Image(nodeRef, layer);
2858
3283
  case SwipeUp.className():
@@ -2860,7 +3285,7 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
2860
3285
  case SwipeUpItems.className():
2861
3286
  return new SwipeUpItems(nodeRef, layer);
2862
3287
  case Video.className():
2863
- return new Video(nodeRef, layer, layoutApi.VideoPlayer, layer.sdkApi);
3288
+ return new Video(nodeRef, layer, layoutApi.VideoPlayer, layer.slideApiDeps);
2864
3289
  //////// widgets ///////
2865
3290
  case Copy.className():
2866
3291
  return layoutApi.widgetCopyApi ? new Copy(nodeRef, layer, layoutApi.widgetCopyApi, widgetCallbacks, widgetDeps) : null;
@@ -2918,20 +3343,23 @@ class SlideTimeline {
2918
3343
  slideDisabledTimer;
2919
3344
  slideReady;
2920
3345
  _afterAppResumeQueuePush;
2921
- sdkApi;
2922
- constructor(slideIndex, slideDuration, slideDisabledTimer, slideReady, _afterAppResumeQueuePush, sdkApi) {
3346
+ slideApiDeps;
3347
+ constructor(slideIndex, slideDuration, slideDisabledTimer, slideReady, _afterAppResumeQueuePush, slideApiDeps) {
2923
3348
  this.slideIndex = slideIndex;
2924
3349
  this.slideDuration = slideDuration;
2925
3350
  this.slideDisabledTimer = slideDisabledTimer;
2926
3351
  this.slideReady = slideReady;
2927
3352
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
2928
- this.sdkApi = sdkApi;
3353
+ this.slideApiDeps = slideApiDeps;
2929
3354
  this.timelineDisabledState = this.slideDisabledTimer ? TimelineDisabledState.disabled : TimelineDisabledState.enabled;
2930
3355
  }
2931
3356
  resumedAt = new Date().getTime();
2932
3357
  timeSpent = 0;
2933
3358
  timelineDisabledState;
2934
3359
  currentState = "stop" /* TIMELINE_ACTION.STOP */;
3360
+ deferredDataWaitingStateTimerId = null;
3361
+ deferredResumeStateTimerId = null;
3362
+ dataWaitingStartedAt = null;
2935
3363
  static get layoutService() {
2936
3364
  return container.get({ identifier: "LayoutService" });
2937
3365
  }
@@ -2939,22 +3367,10 @@ class SlideTimeline {
2939
3367
  return SlideTimeline.layoutService;
2940
3368
  }
2941
3369
  get isSDKSupportUpdateTimeline() {
2942
- if (this.sdkApi.isAndroid) {
2943
- return Boolean(SlideTimeline.layoutService.env.Android && "updateTimeline" in SlideTimeline.layoutService.env.Android);
2944
- }
2945
- else if (this.sdkApi.isIOS) {
2946
- const mh = SlideTimeline.layoutService.env?.webkit?.messageHandlers ?? {};
2947
- return "updateTimeline" in mh;
2948
- }
2949
- else if (this.sdkApi.isWeb) {
2950
- return true;
2951
- }
2952
- else {
2953
- return false;
2954
- }
3370
+ return this.slideApiDeps.isSdkSupportUpdateTimeline();
2955
3371
  }
2956
3372
  get isSdkSupportTimelineOnBeforeStart() {
2957
- return this.sdkApi.isSdkSupportTimelineOnBeforeStart();
3373
+ return this.slideApiDeps.isSdkSupportTimelineOnBeforeStart();
2958
3374
  }
2959
3375
  get index() {
2960
3376
  return this.slideIndex;
@@ -2962,6 +3378,9 @@ class SlideTimeline {
2962
3378
  get isTimelineDisabled() {
2963
3379
  return this.timelineDisabledState === TimelineDisabledState.disabled;
2964
3380
  }
3381
+ get durationMs() {
3382
+ return this.slideDuration;
3383
+ }
2965
3384
  async updateTimeline(action, showLoader = false, showError = false) {
2966
3385
  // два кейса
2967
3386
  // когда есть слои и у слоя вызываем showLayer который вызывает startTimer до старта слайда, потом start от sdk
@@ -2990,13 +3409,15 @@ class SlideTimeline {
2990
3409
  //@ts-ignore
2991
3410
  // window._log(`updateTimeline 1, a: ${action} ct: ${currentTime} d: ${duration} tds: ${this.timelineDisabledState}`, true);
2992
3411
  await this.slideReady.then();
2993
- //@ts-ignore
2994
3412
  // window._log(`updateTimeline, a: ${action} ct: ${currentTime} d: ${duration} tds: ${this.timelineDisabledState}`, true);
2995
- // console.trace(`updateTimeline ${action} slideIndex: ${this.slideIndex} currentTime:${currentTime} duration:${duration} tds: ${this.timelineDisabledState}`);
2996
- this.sdkApi.updateTimeline(this.slideIndex, action, currentTime, duration, showLoader, showError);
3413
+ // console.trace(`updateTimeline ${action} slideIndex: ${this.slideIndex} currentTime:${currentTime} duration:${duration} tds: ${this.timelineDisabledState} showLoader: ${showLoader} showError: ${showError}`);
3414
+ this.slideApiDeps.updateTimeline(this.slideIndex, action, currentTime, duration, showLoader, showError);
3415
+ if (action === "pause" /* TIMELINE_ACTION.PAUSE */ && showLoader) {
3416
+ this.dataWaitingStartedAt = Date.now();
3417
+ }
2997
3418
  }
2998
3419
  /**
2999
- * trigger timeline update for new slide in sdk, before slide strat event (prevent timeout in timeline while we wait for video start)
3420
+ * trigger timeline update for new slide in sdk, before slide start event (prevent timeout in timeline while we wait for video start)
3000
3421
  */
3001
3422
  triggerSlideLoadState() {
3002
3423
  if (this.isSDKSupportUpdateTimeline && this.isSdkSupportTimelineOnBeforeStart) {
@@ -3009,7 +3430,7 @@ class SlideTimeline {
3009
3430
  if (this.timelineDisabledState === TimelineDisabledState.disabled) {
3010
3431
  duration = 0;
3011
3432
  }
3012
- this.sdkApi.updateTimeline(this.slideIndex, "before_start" /* TIMELINE_ACTION.BEFORE_START */, 0, duration, false, false);
3433
+ this.slideApiDeps.updateTimeline(this.slideIndex, "before_start" /* TIMELINE_ACTION.BEFORE_START */, 0, duration, false, false);
3013
3434
  }
3014
3435
  }
3015
3436
  /**
@@ -3018,6 +3439,7 @@ class SlideTimeline {
3018
3439
  */
3019
3440
  slideStarted() {
3020
3441
  // console.trace("slideStarted");
3442
+ this.onBeforeStateChanged();
3021
3443
  if (this.isSDKSupportUpdateTimeline) {
3022
3444
  this.resumedAt = new Date().getTime();
3023
3445
  this.timeSpent = 0; // for case when instance exists, but we return to slide again
@@ -3026,6 +3448,7 @@ class SlideTimeline {
3026
3448
  }
3027
3449
  slideRestarted() {
3028
3450
  // console.trace("slideRestarted");
3451
+ this.onBeforeStateChanged();
3029
3452
  if (this.isSDKSupportUpdateTimeline) {
3030
3453
  this.resumedAt = new Date().getTime();
3031
3454
  this.timeSpent = 0;
@@ -3035,11 +3458,12 @@ class SlideTimeline {
3035
3458
  /**
3036
3459
  *
3037
3460
  */
3038
- slidePaused(videoCurrentTime) {
3461
+ slidePaused(currentTime) {
3039
3462
  // console.trace("slidePaused");
3463
+ this.onBeforeStateChanged();
3040
3464
  if (this.isSDKSupportUpdateTimeline) {
3041
- if (videoCurrentTime != null) {
3042
- this.timeSpent = Math.round(videoCurrentTime);
3465
+ if (currentTime != null) {
3466
+ this.timeSpent = Math.round(currentTime);
3043
3467
  }
3044
3468
  else {
3045
3469
  const globalCurrentTime = new Date().getTime();
@@ -3049,28 +3473,46 @@ class SlideTimeline {
3049
3473
  this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */);
3050
3474
  }
3051
3475
  else {
3052
- this.sdkApi.cardPausedCallback(videoCurrentTime);
3476
+ this.slideApiDeps.cardPausedCallback(currentTime);
3053
3477
  }
3054
3478
  }
3055
- slideResumed(videoCurrentTime) {
3479
+ slideResumed(getVideoCurrentTime) {
3056
3480
  // console.trace("slideResumed");
3481
+ this.onBeforeStateChanged();
3057
3482
  // @ts-ignore
3058
3483
  // window._log(`updateTimeline slideResumed ${videoCurrentTime}`, true);
3059
- if (this.isSDKSupportUpdateTimeline) {
3060
- if (videoCurrentTime != null) {
3061
- this.timeSpent = Math.round(videoCurrentTime);
3484
+ // dataWaitingStartedAt
3485
+ const slideResume = () => {
3486
+ if (this.isSDKSupportUpdateTimeline) {
3487
+ if (getVideoCurrentTime != null) {
3488
+ this.timeSpent = Math.round(getVideoCurrentTime());
3489
+ }
3490
+ this.resumedAt = new Date().getTime();
3491
+ this.updateTimeline("start" /* TIMELINE_ACTION.START */);
3062
3492
  }
3063
- this.resumedAt = new Date().getTime();
3064
- this.updateTimeline("start" /* TIMELINE_ACTION.START */);
3493
+ else {
3494
+ this.slideApiDeps.cardResumedCallback(getVideoCurrentTime != null ? getVideoCurrentTime() : null);
3495
+ }
3496
+ };
3497
+ // prevent micro loaders in UI
3498
+ const delay = 300;
3499
+ let dataWaitingLoaderSpent = delay;
3500
+ if (this.dataWaitingStartedAt != null) {
3501
+ dataWaitingLoaderSpent = Date.now() - this.dataWaitingStartedAt;
3502
+ }
3503
+ if (dataWaitingLoaderSpent < delay) {
3504
+ this.deferredResumeStateTimerId = window.setTimeout(slideResume, dataWaitingLoaderSpent - delay);
3065
3505
  }
3066
3506
  else {
3067
- this.sdkApi.cardResumedCallback(videoCurrentTime);
3507
+ slideResume();
3068
3508
  }
3069
3509
  }
3070
3510
  slideStopped() {
3071
3511
  // console.trace("slideStopped");
3512
+ this.onBeforeStateChanged();
3072
3513
  if (this.isSDKSupportUpdateTimeline) {
3073
3514
  this.updateTimeline("stop" /* TIMELINE_ACTION.STOP */);
3515
+ // console.log(`TIMELINE_ACTION -> slideStopped, index: ${this.slideIndex}`);
3074
3516
  }
3075
3517
  }
3076
3518
  /**
@@ -3078,6 +3520,7 @@ class SlideTimeline {
3078
3520
  * used by widgets
3079
3521
  */
3080
3522
  startDisabledTimeline(fallback) {
3523
+ this.onBeforeStateChanged();
3081
3524
  // if app is paused (in background) - don't call start timeline (Android issues)
3082
3525
  // @ts-ignore
3083
3526
  // window._log(`Push startDisabledTimeline to queue at state: ${window.slideApi.state}, time: ${new Date().getTime()}`, true);
@@ -3097,6 +3540,7 @@ class SlideTimeline {
3097
3540
  }
3098
3541
  onSlideDataWaiting(videoCurrentTime) {
3099
3542
  // console.trace("onSlideDataWaiting");
3543
+ this.onBeforeStateChanged();
3100
3544
  // @ts-ignore
3101
3545
  // window._log(`updateTimeline onSlideDataWaiting ${videoCurrentTime}`, true);
3102
3546
  if (videoCurrentTime != null) {
@@ -3107,10 +3551,20 @@ class SlideTimeline {
3107
3551
  let spent = globalCurrentTime - this.resumedAt;
3108
3552
  this.timeSpent += spent;
3109
3553
  }
3110
- this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3554
+ // prevent micro loaders in UI
3555
+ if (this.currentState === "start" /* TIMELINE_ACTION.START */) {
3556
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, false, false);
3557
+ this.deferredDataWaitingStateTimerId = window.setTimeout(() => {
3558
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3559
+ }, 300);
3560
+ }
3561
+ else {
3562
+ this.updateTimeline("pause" /* TIMELINE_ACTION.PAUSE */, true, false);
3563
+ }
3111
3564
  }
3112
3565
  onSlideError(videoCurrentTime) {
3113
3566
  // console.trace("onSlideError");
3567
+ this.onBeforeStateChanged();
3114
3568
  if (videoCurrentTime != null) {
3115
3569
  this.timeSpent = Math.round(videoCurrentTime);
3116
3570
  }
@@ -3121,7 +3575,21 @@ class SlideTimeline {
3121
3575
  }
3122
3576
  this.updateTimeline("stop" /* TIMELINE_ACTION.STOP */, false, true);
3123
3577
  }
3124
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`number`, `number`, `boolean`, `Promise`, `(cb: () => void) => void`, `SDKApi`]; }
3578
+ clearDeferredDataWaitingStateTimerId() {
3579
+ if (this.deferredDataWaitingStateTimerId != null) {
3580
+ window.clearTimeout(this.deferredDataWaitingStateTimerId);
3581
+ }
3582
+ }
3583
+ clearDeferredResumeStateTimerId() {
3584
+ if (this.deferredResumeStateTimerId != null) {
3585
+ window.clearTimeout(this.deferredResumeStateTimerId);
3586
+ }
3587
+ }
3588
+ onBeforeStateChanged() {
3589
+ this.clearDeferredDataWaitingStateTimerId();
3590
+ this.clearDeferredResumeStateTimerId();
3591
+ }
3592
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`number`, `number`, `boolean`, `Promise`, `(cb: () => void) => void`, `ISlideApiDeps`]; }
3125
3593
  }
3126
3594
 
3127
3595
  class Layer {
@@ -3130,8 +3598,7 @@ class Layer {
3130
3598
  _slideReadyPromise;
3131
3599
  _afterAppResumeQueuePush;
3132
3600
  _afterStartInitQueuePush;
3133
- _showNextSlide;
3134
- sdkApi;
3601
+ slideApiDeps;
3135
3602
  _slideRoot;
3136
3603
  _getLayoutDirection;
3137
3604
  _slidePauseUI;
@@ -3147,14 +3614,13 @@ class Layer {
3147
3614
  _elements = [];
3148
3615
  _timeline;
3149
3616
  _widgetDeps;
3150
- constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, _showNextSlide, sdkApi, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3617
+ constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3151
3618
  this._nodeRef = _nodeRef;
3152
3619
  this._slide = _slide;
3153
3620
  this._slideReadyPromise = _slideReadyPromise;
3154
3621
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3155
3622
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
3156
- this._showNextSlide = _showNextSlide;
3157
- this.sdkApi = sdkApi;
3623
+ this.slideApiDeps = slideApiDeps;
3158
3624
  this._slideRoot = _slideRoot;
3159
3625
  this._getLayoutDirection = _getLayoutDirection;
3160
3626
  this._slidePauseUI = _slidePauseUI;
@@ -3167,16 +3633,16 @@ class Layer {
3167
3633
  this._duration = parseInt(this._nodeRef.getAttribute("data-duration") ?? "") || DEFAULT_SLIDE_DURATION;
3168
3634
  this._disabledTimer = this._nodeRef.getAttribute("data-disable-timer") === "1";
3169
3635
  this._disabledNavigation = this._nodeRef.getAttribute("data-disable-navigation") === "1";
3170
- this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.sdkApi);
3636
+ this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.slideApiDeps);
3171
3637
  this._widgetDeps = {
3172
- sdkApi: this.sdkApi,
3638
+ slideApiDeps: this.slideApiDeps,
3173
3639
  slideRoot: this._slideRoot,
3174
3640
  getLayoutDirection: this._getLayoutDirection,
3175
3641
  getSdkClientVariables: this._getSdkClientVariables,
3176
3642
  };
3177
3643
  const onWidgetComplete = (cardId, slideIndex) => {
3178
3644
  // todo if nothing more widgets with disabled timers - we can start layer timeline
3179
- const fallback = () => this._showNextSlide(DEFAULT_SLIDE_DURATION);
3645
+ const fallback = () => this.slideApiDeps.showNextSlide(DEFAULT_SLIDE_DURATION);
3180
3646
  // для android sdk важно чтобы этот метод вызывался только после slide_start
3181
3647
  this._afterStartInitQueuePush(() => {
3182
3648
  this._timeline.startDisabledTimeline(fallback);
@@ -3218,17 +3684,17 @@ class Layer {
3218
3684
  }
3219
3685
  }
3220
3686
  init(localData) {
3221
- if (this.sdkApi.isIOS || this.sdkApi.isAndroid) {
3687
+ if (this.slideApiDeps.isIOS || this.slideApiDeps.isAndroid) {
3222
3688
  this._nodeRef.classList.add("_app");
3223
- this.sdkApi.isIOS && this._nodeRef.classList.add("_isIos");
3224
- this.sdkApi.isAndroid && this._nodeRef.classList.add("_isAndroid");
3689
+ this.slideApiDeps.isIOS && this._nodeRef.classList.add("_isIos");
3690
+ this.slideApiDeps.isAndroid && this._nodeRef.classList.add("_isAndroid");
3225
3691
  }
3226
- this.sdkApi.cardAnimation?.init(this._nodeRef);
3692
+ this.slideApiDeps.cardAnimation?.init(this._nodeRef);
3227
3693
  const promises = this._elements.map(element => element.init(localData));
3228
3694
  return promises;
3229
3695
  }
3230
3696
  onAfterAllMediaResourcesLoaded() {
3231
- if (this.sdkApi.isIOS) ;
3697
+ if (this.slideApiDeps.isIOS) ;
3232
3698
  this._initTextFit();
3233
3699
  }
3234
3700
  get nodeRef() {
@@ -3247,7 +3713,10 @@ class Layer {
3247
3713
  return container.get({ identifier: "LayoutService" });
3248
3714
  }
3249
3715
  getLocalData() {
3250
- return this.sdkApi.getCardLocalData();
3716
+ return this.slideApiDeps.getCardLocalData();
3717
+ }
3718
+ findElementByNodeRef(nodeRef) {
3719
+ return this._elements.find(element => element.nodeRef === nodeRef);
3251
3720
  }
3252
3721
  get isQuest() {
3253
3722
  return this._nodeRef.getAttribute("data-quest-count") != null;
@@ -3400,14 +3869,19 @@ class Layer {
3400
3869
  const videoElement = this.videoElement;
3401
3870
  let currentTime = 0;
3402
3871
  if (videoElement != null) {
3403
- let videoLoop = false;
3404
- if (this.timeline.isTimelineDisabled) {
3405
- videoLoop = true;
3406
- }
3407
- currentTime = (await videoElement.start(muted, videoLoop)).currentTime;
3872
+ const getVideoIsLooped = () => {
3873
+ let videoLoop = false;
3874
+ if (this.timeline.isTimelineDisabled || this.timeline.durationMs > videoElement.durationMs) {
3875
+ videoLoop = true;
3876
+ }
3877
+ // console.log({videoLoop, isTimelineDisabled: this.timeline.isTimelineDisabled, timelineDurationMs: this.timeline.durationMs, videoElementDurationMs: videoElement.durationMs});
3878
+ return videoLoop;
3879
+ };
3880
+ // todo - need to convert to ms ?
3881
+ currentTime = (await videoElement.start(muted, getVideoIsLooped)).getVideoCurrentTime();
3408
3882
  }
3409
- if (this.sdkApi.cardAnimation) {
3410
- this._animationPauseCb = this.sdkApi.cardAnimation.start(this._nodeRef);
3883
+ if (this.slideApiDeps.cardAnimation) {
3884
+ this._animationPauseCb = this.slideApiDeps.cardAnimation.start(this._nodeRef);
3411
3885
  }
3412
3886
  for (const element of this._elements) {
3413
3887
  element.onStart();
@@ -3423,7 +3897,7 @@ class Layer {
3423
3897
  }
3424
3898
  async stop(options) {
3425
3899
  this.videoElement?.stop(options);
3426
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3900
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3427
3901
  for (const element of this._elements) {
3428
3902
  element.onPause();
3429
3903
  }
@@ -3434,7 +3908,7 @@ class Layer {
3434
3908
  }
3435
3909
  stopInternal(options) {
3436
3910
  this.videoElement?.stop(options);
3437
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3911
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3438
3912
  for (const element of this._elements) {
3439
3913
  element.onPause();
3440
3914
  }
@@ -3446,17 +3920,21 @@ class Layer {
3446
3920
  return new Promise(resolve => {
3447
3921
  const cb = () => {
3448
3922
  let currentTime = this.videoElement?.pause(resetVideoTime) ?? null;
3923
+ if (this.videoElement?.isLooped) {
3924
+ // skip currentTime from looped video (bcz in that case video time does not associated with timeline)
3925
+ currentTime = null;
3926
+ }
3927
+ if (currentTime != null) {
3928
+ currentTime *= 1000;
3929
+ }
3449
3930
  if (stopAnimation) {
3450
- this.sdkApi.cardAnimation?.stop(this._nodeRef);
3931
+ this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
3451
3932
  }
3452
3933
  else {
3453
3934
  if (this._animationPauseCb != null && isFunction(this._animationPauseCb)) {
3454
3935
  this._animationResumeCb = this._animationPauseCb(false);
3455
3936
  }
3456
3937
  }
3457
- if (currentTime != null) {
3458
- currentTime *= 1000;
3459
- }
3460
3938
  for (const element of this._elements) {
3461
3939
  element.onPause();
3462
3940
  }
@@ -3476,26 +3954,23 @@ class Layer {
3476
3954
  }
3477
3955
  async resume() {
3478
3956
  return new Promise(resolve => {
3479
- const cb = ({ currentTime }) => {
3957
+ const cb = ({ getVideoCurrentTime }) => {
3480
3958
  // console.log("resumed cb with currentTime", { currentTime });
3481
- if (currentTime != null) {
3482
- currentTime *= 1000;
3483
- }
3484
3959
  if (isFunction(this._animationResumeCb)) {
3485
3960
  this._animationResumeCb();
3486
3961
  }
3487
3962
  for (const element of this._elements) {
3488
3963
  element.onResume();
3489
3964
  }
3490
- this.timeline.slideResumed(currentTime);
3491
- resolve({ currentTime });
3965
+ this.timeline.slideResumed(getVideoCurrentTime != null ? () => getVideoCurrentTime() * 1000 : undefined);
3966
+ resolve({ currentTime: getVideoCurrentTime != null ? getVideoCurrentTime() : null });
3492
3967
  };
3493
3968
  const videoStartedPromise = this.videoElement?.resume();
3494
3969
  if (videoStartedPromise != null && videoStartedPromise.then != null) {
3495
3970
  videoStartedPromise.then(cb);
3496
3971
  }
3497
3972
  else {
3498
- cb({ currentTime: null });
3973
+ cb({ getVideoCurrentTime: undefined });
3499
3974
  }
3500
3975
  });
3501
3976
  }
@@ -3511,7 +3986,7 @@ class Layer {
3511
3986
  get isLayerForcePaused() {
3512
3987
  return this.elements.some(element => element.isLayerForcePaused);
3513
3988
  }
3514
- 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`]; }
3989
+ 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`]; }
3515
3990
  }
3516
3991
  const TextFit = (function () {
3517
3992
  const defaultSettings = {
@@ -3702,8 +4177,7 @@ class Slide {
3702
4177
  _slideReadyPromise;
3703
4178
  _afterAppResumeQueuePush;
3704
4179
  _afterStartInitQueuePush;
3705
- _showNextSlide;
3706
- sdkApi;
4180
+ slideApiDeps;
3707
4181
  _slideRoot;
3708
4182
  _getLayoutDirection;
3709
4183
  _slidePauseUI;
@@ -3711,13 +4185,12 @@ class Slide {
3711
4185
  _getSdkClientVariables;
3712
4186
  _layers;
3713
4187
  _start;
3714
- constructor(_slidesNodesRefs, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, _showNextSlide, sdkApi, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
4188
+ constructor(_slidesNodesRefs, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3715
4189
  this._slidesNodesRefs = _slidesNodesRefs;
3716
4190
  this._slideReadyPromise = _slideReadyPromise;
3717
4191
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3718
4192
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
3719
- this._showNextSlide = _showNextSlide;
3720
- this.sdkApi = sdkApi;
4193
+ this.slideApiDeps = slideApiDeps;
3721
4194
  this._slideRoot = _slideRoot;
3722
4195
  this._getLayoutDirection = _getLayoutDirection;
3723
4196
  this._slidePauseUI = _slidePauseUI;
@@ -3727,7 +4200,7 @@ class Slide {
3727
4200
  if (!this._slidesNodesRefs.length) {
3728
4201
  throw new Error("No slides found.");
3729
4202
  }
3730
- 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));
4203
+ 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));
3731
4204
  this._activeLayer = this._layers[0];
3732
4205
  }
3733
4206
  _activeLayer;
@@ -3747,7 +4220,7 @@ class Slide {
3747
4220
  if (multiSlideApi != null && this.layers.length > 1) {
3748
4221
  try {
3749
4222
  multiSlideApi.init(this.layersNodesRefs, localData, {
3750
- sdkApi: this.sdkApi,
4223
+ slideApiDeps: this.slideApiDeps,
3751
4224
  slideRoot: this._slideRoot,
3752
4225
  getLayoutDirection: this._getLayoutDirection,
3753
4226
  getSdkClientVariables: this._getSdkClientVariables,
@@ -3824,7 +4297,7 @@ class Slide {
3824
4297
  get disabledNavigation() {
3825
4298
  return this._activeLayer.disabledNavigation;
3826
4299
  }
3827
- 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`]; }
4300
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Array`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `ISlideApiDeps`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
3828
4301
  }
3829
4302
 
3830
4303
  let SlideApi$1 = class SlideApi {
@@ -3841,20 +4314,29 @@ let SlideApi$1 = class SlideApi {
3841
4314
  _getViewportHeight;
3842
4315
  _overlappingActionBarHeight;
3843
4316
  _separateUserAndAppPause;
3844
- sdkApi;
4317
+ _index;
4318
+ slideApiDeps;
3845
4319
  constructor(config) {
3846
4320
  this.config = config;
3847
- this.sdkApi = config.sdkApi;
4321
+ this.slideApiDeps = config.slideApiDeps;
3848
4322
  this._slideWrapper = config.slideWrapper;
3849
4323
  this._viewport = config.viewport;
3850
4324
  this._getViewportWidth = config.getViewportWidth;
3851
4325
  this._getViewportHeight = config.getViewportHeight;
3852
4326
  this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
3853
4327
  this._separateUserAndAppPause = config.separateUserAndAppPause;
3854
- this.refreshSizes = proxy(this.refreshSizes, this);
3855
- this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
3856
- this.initListeners();
3857
- this.refreshSizes();
4328
+ this._index = config.index;
4329
+ }
4330
+ static checkPreloadedInLayoutSlide() {
4331
+ // for sdk backward compatibility
4332
+ const slideBox = document.getElementById("narrative-slide-box");
4333
+ if (slideBox && slideBox.innerText.trim() !== "{%content}".replace("{", "{{").replace("}", "}}")) {
4334
+ return true;
4335
+ }
4336
+ return false;
4337
+ }
4338
+ initPreloadedInLayoutSlide(slideLoadedCb) {
4339
+ // for sdk backward compatibility
3858
4340
  const slideBox = document.getElementById("narrative-slide-box");
3859
4341
  // todo via first child and its innerText - faster variant
3860
4342
  if (slideBox && slideBox.innerText.trim() !== "{%content}".replace("{", "{{").replace("}", "}}")) {
@@ -3862,117 +4344,42 @@ let SlideApi$1 = class SlideApi {
3862
4344
  this._slideInRender = true;
3863
4345
  this._init(() => this._slideBoxRenderComplete(null)).then(({ slide, result, reason }) => {
3864
4346
  this._slide = slide;
3865
- if (config.slideLoadedCb != null) {
3866
- config.slideLoadedCb({ cardId: slide.cardId, slideIndex: slide.slideIndex, result, reason });
4347
+ if (slideLoadedCb != null) {
4348
+ slideLoadedCb({ cardId: slide.cardId, slideIndex: slide.slideIndex, result, reason });
3867
4349
  }
3868
4350
  });
3869
4351
  }
3870
4352
  }
3871
- async destroy() {
3872
- if (this.slide != null) {
3873
- await this.slide.onBeforeUnmount();
3874
- }
3875
- this.destroyListeners();
3876
- this._state = 13 /* STATE.DESTROYED */;
3877
- }
3878
- initListeners() {
3879
- this._viewport.addEventListener("resize", this.refreshSizes);
3880
- }
3881
- destroyListeners() {
3882
- this._viewport.removeEventListener("resize", this.refreshSizes);
3883
- }
3884
- _savedViewportWidth = null;
3885
- _savedViewportHeight = null;
3886
- refreshSizes() {
3887
- const viewportWidth = this._getViewportWidth();
3888
- const viewportHeight = this._getViewportHeight();
3889
- if (this._savedViewportWidth === viewportWidth && this._savedViewportHeight === viewportHeight) {
3890
- return;
3891
- }
3892
- this._savedViewportWidth = viewportWidth;
3893
- this._savedViewportHeight = viewportHeight;
3894
- const viewportRatio = viewportWidth / viewportHeight;
3895
- let slideWidth = 0;
3896
- let slideHeight = 0;
3897
- // _ratio = 310 / 480,
3898
- const _ratio = this.config.slideRatio;
3899
- let _isFullscreen = this.config.isFullscreen;
3900
- const slideOffset = this._slideWrapper.querySelector(".narrative-slide-offset");
3901
- let offset = 0;
3902
- let xOffset = "0px";
3903
- // for elements with bottom anchor (absolute position)
3904
- let yOffset = "0px";
3905
- // alert(viewportHeight);
3906
- // todo - mobile only (or isIos or isAndroid)
3907
- if (this.sdkApi.isAndroid || this.sdkApi.isIOS) {
3908
- if (viewportRatio > _ratio) {
3909
- // disable _isFullscreen if viewport small
3910
- _isFullscreen = false;
3911
- }
3912
- }
3913
- if (_isFullscreen) {
3914
- // более квадратное чем надо (desktop)
3915
- if (viewportRatio > _ratio) {
3916
- // fit by height
3917
- slideHeight = viewportHeight;
3918
- slideWidth = Math.ceil(slideHeight * _ratio);
3919
- offset = Math.ceil(slideWidth - viewportWidth) / 2;
3920
- if (slideOffset != null) {
3921
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
3922
- }
3923
- xOffset = offset + "px";
3924
- }
3925
- else {
3926
- // fit by width, top and bottom - to offscreen or fill with bg image
3927
- slideWidth = viewportWidth;
3928
- slideHeight = Math.ceil(viewportWidth / _ratio);
3929
- offset = Math.ceil(slideHeight - viewportHeight) / 2;
3930
- if (slideOffset != null) {
3931
- slideOffset.style.margin = -1 * offset + "px" + " 0 ";
3932
- }
3933
- // offset from viewport bottom to StoryBottom plus safe area offset bottom
3934
- yOffset = `calc(${offset + this._overlappingActionBarHeight}px + env(safe-area-inset-bottom))`;
3935
- // detect safe area offset
3936
- }
3937
- }
3938
- else {
3939
- // более квадратное чем надо
3940
- if (viewportRatio > _ratio) {
3941
- // fit by width, top and bottom - to offscreen
3942
- slideWidth = viewportWidth;
3943
- slideHeight = Math.ceil(viewportWidth / _ratio);
3944
- offset = Math.ceil(slideHeight - viewportHeight) / 2;
3945
- if (slideOffset != null) {
3946
- slideOffset.style.margin = -offset + "px" + " 0 ";
3947
- }
3948
- yOffset = offset + this._overlappingActionBarHeight + "px";
4353
+ onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, slideOffsetMargin }) {
4354
+ // todo CSP violation
4355
+ this._slideWrapper.style.fontSize = fontSize;
4356
+ if (this.slideOffsetElement != null) {
4357
+ // todo CSP violation
4358
+ this.slideOffsetElement.style.setProperty("--y-offset", yOffset);
4359
+ this.slideOffsetElement.style.setProperty("--x-offset", xOffset);
4360
+ if (isFullscreen) {
4361
+ this.slideOffsetElement.classList.add("narrative-slide-offset-fullscreen");
3949
4362
  }
3950
4363
  else {
3951
- // вьюпорт более вытянутый чем надо
3952
- // fit by height, sides - to offscreen
3953
- slideHeight = viewportHeight;
3954
- slideWidth = Math.ceil(slideHeight * _ratio);
3955
- offset = Math.ceil(slideWidth - viewportWidth) / 2;
3956
- if (slideOffset != null) {
3957
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
3958
- }
3959
- xOffset = offset + "px";
4364
+ this.slideOffsetElement.classList.remove("narrative-slide-offset-fullscreen");
3960
4365
  }
4366
+ this.slideOffsetElement.style.margin = slideOffsetMargin;
3961
4367
  }
3962
- const fontSize = slideWidth / 20;
3963
- // todo CSP violation
3964
- this._slideWrapper.style.fontSize = fontSize + "px";
3965
- if (slideOffset != null) {
3966
- // todo CSP violation
3967
- slideOffset.style.setProperty("--y-offset", yOffset);
3968
- slideOffset.style.setProperty("--x-offset", xOffset);
3969
- }
3970
- if (_isFullscreen) {
3971
- slideOffset?.classList.add("narrative-slide-offset-fullscreen");
3972
- }
3973
- if (this.config.userResizeHandler != null) {
3974
- this.config.userResizeHandler({ viewportWidth, viewportHeight, fontSize });
4368
+ }
4369
+ get slideWrapperElement() {
4370
+ return this._slideWrapper;
4371
+ }
4372
+ get slideOffsetElement() {
4373
+ return this._slideWrapper.querySelector(".narrative-slide-offset");
4374
+ }
4375
+ get index() {
4376
+ return this._index;
4377
+ }
4378
+ async destroy() {
4379
+ if (this.slide != null) {
4380
+ await this.slide.onBeforeUnmount();
3975
4381
  }
4382
+ this._state = 13 /* STATE.DESTROYED */;
3976
4383
  }
3977
4384
  async showSlide(html) {
3978
4385
  const slideBox = this._slideWrapper.querySelector(`.${SlideApi.renderedBoxClassName}`);
@@ -3985,7 +4392,9 @@ let SlideApi$1 = class SlideApi {
3985
4392
  }
3986
4393
  this._slideInInit = null;
3987
4394
  this._slideInRender = true;
3988
- slideBoxPrerender.innerHTML = html;
4395
+ if (html != null) {
4396
+ slideBoxPrerender.innerHTML = html;
4397
+ }
3989
4398
  const prevSlide = this.slide ? Object.assign(Object.create(Object.getPrototypeOf(this.slide)), this.slide) : null;
3990
4399
  const { slide, result, reason } = await this._init(() => this._slideBoxRenderComplete(prevSlide));
3991
4400
  this._slide = slide;
@@ -4007,7 +4416,7 @@ let SlideApi$1 = class SlideApi {
4007
4416
  return container.get({ identifier: "LayoutService" });
4008
4417
  }
4009
4418
  getLocalData() {
4010
- return this.sdkApi.getCardLocalData();
4419
+ return this.slideApiDeps.getCardLocalData();
4011
4420
  }
4012
4421
  _fontsInit = false;
4013
4422
  _initAndLoadFonts(fonts) {
@@ -4099,7 +4508,7 @@ let SlideApi$1 = class SlideApi {
4099
4508
  /**
4100
4509
  * For case when SlideApi instance was created before root was attached to DOM
4101
4510
  */
4102
- this.refreshSizes();
4511
+ // this.config.refreshSizes(this);
4103
4512
  const slideNodeRef = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName} .narrative-slide`);
4104
4513
  const slidesNodesRefs = Array.prototype.slice.call(this._slideWrapper.querySelectorAll(`.${SlideApi.prerenderBoxClassName} .narrative-slide.narrative-multi-slide`));
4105
4514
  if (!slidesNodesRefs.length && slideNodeRef != null) {
@@ -4112,17 +4521,18 @@ let SlideApi$1 = class SlideApi {
4112
4521
  const slideReadyPromise = new Promise(resolve => {
4113
4522
  slideReadyResolve = resolve;
4114
4523
  });
4115
- const slide = new Slide(slidesNodesRefs, slideReadyPromise, this.afterAppResumeQueuePush.bind(this), this.afterStartInitQueuePush.bind(this), this.sdkApi.showNextSlide.bind(this), this.sdkApi, this._slideWrapper, () => this.layoutDirection, this.slidePauseUI.bind(this), this.slideResumeUI.bind(this), this.getSdkClientVariables);
4524
+ 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);
4116
4525
  this._slideInInit = slide;
4526
+ // todo - call via DI
4117
4527
  slide.activeLayer.timeline.triggerSlideLoadState();
4118
- if (this.sdkApi.isAndroid) {
4528
+ if (this.slideApiDeps.isAndroid) {
4119
4529
  this._afterStartInitQueue = [];
4120
4530
  }
4121
4531
  this._afterAppResumeQueue = [];
4122
4532
  const result = { slide, result: false, reason: "" };
4123
4533
  try {
4124
4534
  const onAllMediaLoaded = this._onAllMediaLoaded(slide);
4125
- const fontsPromise = this._initAndLoadFonts(this.sdkApi.getCardFonts());
4535
+ const fontsPromise = this._initAndLoadFonts(this.slideApiDeps.getCardFonts());
4126
4536
  const mediaAndFontsPromise = Promise.all([onAllMediaLoaded, fontsPromise]).then(() => {
4127
4537
  this.layoutService.env.clearTimeout(mediaResourcesTimeoutId);
4128
4538
  });
@@ -4221,7 +4631,7 @@ let SlideApi$1 = class SlideApi {
4221
4631
  this._slideConfig = config;
4222
4632
  // start deferred fncs from widgets
4223
4633
  // important - Android only
4224
- if (this.sdkApi.isAndroid && this._afterStartInitQueue && Array.isArray(this._afterStartInitQueue)) {
4634
+ if (this.slideApiDeps.isAndroid && this._afterStartInitQueue && Array.isArray(this._afterStartInitQueue)) {
4225
4635
  for (const job of this._afterStartInitQueue) {
4226
4636
  if (isFunction(job)) {
4227
4637
  job();
@@ -4275,7 +4685,7 @@ let SlideApi$1 = class SlideApi {
4275
4685
  this._state = 9 /* STATE.USER_PAUSED */;
4276
4686
  };
4277
4687
  // todo move to Android adapter
4278
- if (this.sdkApi.isAndroid && !this.sdkApi.isSdkSupportCorrectPauseResumeLifecycle()) {
4688
+ if (this.slideApiDeps.isAndroid && !this.slideApiDeps.isSdkSupportCorrectPauseResumeLifecycle()) {
4279
4689
  this._pauseCbTimer = this.layoutService.env.setTimeout(pauseCb, 300);
4280
4690
  }
4281
4691
  else {
@@ -4334,7 +4744,9 @@ let SlideApi$1 = class SlideApi {
4334
4744
  this._state = 5 /* STATE.RESUMED */;
4335
4745
  }
4336
4746
  async slideStop(options) {
4337
- if (!(this._state === 3 /* STATE.STARTED */ || this._state === 5 /* STATE.RESUMED */ || this._state === 9 /* STATE.USER_PAUSED */)) {
4747
+ // console.log(`TIMELINE_ACTION -> STOP, index: ${this.slide.slideIndex}, state: ${this._state}`);
4748
+ // из состояния START (слайд (например с видео) еще не стартовал) тоже позволяем прерывать - чтобы был правильный LC при быстром пролистывании слайдера
4749
+ if (!(this._state === 2 /* STATE.START */ || this._state === 3 /* STATE.STARTED */ || this._state === 5 /* STATE.RESUMED */ || this._state === 9 /* STATE.USER_PAUSED */)) {
4338
4750
  return;
4339
4751
  }
4340
4752
  this._state = 11 /* STATE.STOP */;
@@ -4349,10 +4761,10 @@ let SlideApi$1 = class SlideApi {
4349
4761
  const defaultAction = () => {
4350
4762
  const nextSlideIndex = this.slide.slideIndex + 1;
4351
4763
  if (nextSlideIndex >= 0 && nextSlideIndex < this.slide.slideCount) {
4352
- this.sdkApi.showCardSlide(nextSlideIndex);
4764
+ this.slideApiDeps.showCardSlide(nextSlideIndex);
4353
4765
  }
4354
4766
  else {
4355
- this.sdkApi.cardShowNext();
4767
+ this.slideApiDeps.cardShowNext();
4356
4768
  }
4357
4769
  };
4358
4770
  if (this.activeLayer.questElement) {
@@ -4399,7 +4811,7 @@ let SlideApi$1 = class SlideApi {
4399
4811
  if (!isFunction(cb)) {
4400
4812
  return false;
4401
4813
  }
4402
- if (this.sdkApi.isAndroid && this._state === 0 /* STATE.INIT */) {
4814
+ if (this.slideApiDeps.isAndroid && this._state === 0 /* STATE.INIT */) {
4403
4815
  this._afterStartInitQueue.push(cb);
4404
4816
  }
4405
4817
  else {
@@ -4528,7 +4940,7 @@ let SlideApi$1 = class SlideApi {
4528
4940
  if (this.layoutService.layoutApi.widgetVoteApi) {
4529
4941
  if (this.layoutService.layoutApi.widgetVoteApi.click(element)) {
4530
4942
  this.layoutService.env.setTimeout(() => {
4531
- this.sdkApi.showNextSlide(0);
4943
+ this.slideApiDeps.showNextSlide(0);
4532
4944
  });
4533
4945
  }
4534
4946
  result.canClickNext = false;
@@ -4552,7 +4964,7 @@ let SlideApi$1 = class SlideApi {
4552
4964
  }
4553
4965
  if (element) {
4554
4966
  this.layoutService.env.setTimeout(() => {
4555
- this.sdkApi.showNextSlide(0);
4967
+ this.slideApiDeps.showNextSlide(0);
4556
4968
  });
4557
4969
  result.canClickNext = false;
4558
4970
  return result;
@@ -4580,7 +4992,7 @@ let SlideApi$1 = class SlideApi {
4580
4992
  if (this.layoutService.layoutApi.widgetRangeSliderApi) {
4581
4993
  if (this.layoutService.layoutApi.widgetRangeSliderApi.click(element)) {
4582
4994
  this.layoutService.env.setTimeout(() => {
4583
- this.sdkApi.showNextSlide(0);
4995
+ this.slideApiDeps.showNextSlide(0);
4584
4996
  });
4585
4997
  }
4586
4998
  result.canClickNext = false;
@@ -4787,18 +5199,18 @@ let SlideApi$1 = class SlideApi {
4787
5199
  }
4788
5200
  if (element) {
4789
5201
  propagation = false;
4790
- this.sdkApi.setCardLocalData({}, true);
4791
- this.sdkApi.updateCardServerDataLocally(this.slide.cardId, {});
5202
+ this.slideApiDeps.setCardLocalData({}, true);
5203
+ this.slideApiDeps.updateCardServerDataLocally(this.slide.cardId, {});
4792
5204
  // window._resetTimers();
4793
5205
  // сделать async в ios
4794
5206
  let slideIndex = this.slide.slideIndex;
4795
5207
  // prevent simultaneous call _showNarrativeSlide and _showLayer - prevent 2 calls of initAfterLoad (break video start on iOS)
4796
5208
  if (slideIndex === 0) {
4797
5209
  // for story repeat on the first slide with layers
4798
- this.sdkApi.showLayer(0);
5210
+ this.slideApiDeps.showLayer(0);
4799
5211
  }
4800
5212
  else {
4801
- this.sdkApi.showCardSlide(0); // сделать ее async
5213
+ this.slideApiDeps.showCardSlide(0); // сделать ее async
4802
5214
  }
4803
5215
  }
4804
5216
  // todo в каждом виджете делать выход через
@@ -4886,44 +5298,44 @@ let SlideApi$1 = class SlideApi {
4886
5298
  // this.activeLayer.timeline.slidePaused(0);
4887
5299
  // return {handled: true};
4888
5300
  }
4889
- if (this.sdkApi.isAndroid && linkTargetAndroid) {
5301
+ if (this.slideApiDeps.isAndroid && linkTargetAndroid) {
4890
5302
  linkTarget = linkTargetAndroid;
4891
5303
  }
4892
- if (this.sdkApi.isIOS && linkTargetIos) {
5304
+ if (this.slideApiDeps.isIOS && linkTargetIos) {
4893
5305
  linkTarget = linkTargetIos;
4894
5306
  }
4895
- if (this.sdkApi.isWeb && linkTargetWeb) {
5307
+ if (this.slideApiDeps.isWeb && linkTargetWeb) {
4896
5308
  linkTarget = linkTargetWeb;
4897
5309
  }
4898
5310
  // for btn(link) without url (openGame, openStory, closeCard, products, goods, etc)
4899
5311
  let statisticWidgetValue = linkType;
4900
5312
  let statisticWidgetEventType = "w-link";
4901
5313
  if (linkType === "closeStory" || linkType === "closeIAM") {
4902
- this.layoutService.env.setTimeout(() => this.sdkApi.closeCard("click"));
5314
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.closeCard("click"));
4903
5315
  handled = true;
4904
5316
  }
4905
5317
  else if (linkType && linkTarget) {
4906
5318
  if (linkType === "story") {
4907
5319
  // storyId: number, slideIndex: number
4908
- this.layoutService.env.setTimeout(() => this.sdkApi.openStory(parseInt(linkTarget), 0));
5320
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.openStory(parseInt(linkTarget), 0));
4909
5321
  handled = true;
4910
5322
  }
4911
5323
  else if (linkType === "slide") {
4912
5324
  const __slideIndex = parseInt(linkTarget);
4913
5325
  const __slideCount = this.slide.slideCount;
4914
5326
  if (__slideIndex >= 0 && __slideIndex < __slideCount) {
4915
- this.layoutService.env.setTimeout(() => this.sdkApi.showCardSlide(__slideIndex));
5327
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.showCardSlide(__slideIndex));
4916
5328
  handled = true;
4917
5329
  }
4918
5330
  }
4919
5331
  else if (linkType === "game") {
4920
- this.layoutService.env.setTimeout(() => this.sdkApi.openGame(linkTarget));
5332
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.openGame(linkTarget));
4921
5333
  handled = true;
4922
5334
  }
4923
5335
  else if (linkType === "layer") {
4924
5336
  const layerIndex = parseInt(linkTarget);
4925
5337
  if (layerIndex >= 0) {
4926
- this.layoutService.env.setTimeout(() => this.sdkApi.showLayer(layerIndex));
5338
+ this.layoutService.env.setTimeout(() => this.slideApiDeps.showLayer(layerIndex));
4927
5339
  handled = true;
4928
5340
  }
4929
5341
  }
@@ -4931,7 +5343,7 @@ let SlideApi$1 = class SlideApi {
4931
5343
  // traditional link, with url
4932
5344
  statisticWidgetValue = linkTarget;
4933
5345
  this.layoutService.env.setTimeout(() => {
4934
- this.sdkApi.openUrl({
5346
+ this.slideApiDeps.openUrl({
4935
5347
  type: isSwipeUpAction ? "swipeUpLink" : "link",
4936
5348
  link: {
4937
5349
  type: "url",
@@ -4941,6 +5353,12 @@ let SlideApi$1 = class SlideApi {
4941
5353
  });
4942
5354
  handled = true;
4943
5355
  }
5356
+ else if (linkType === "promocode") {
5357
+ handled = this.activeLayer.findElementByNodeRef(element)?.handleClick() ?? true;
5358
+ if (!handled) {
5359
+ return { handled: true };
5360
+ }
5361
+ }
4944
5362
  else if (linkType === "products") {
4945
5363
  if (this.layoutService.layoutApi.widgetProductsApi) {
4946
5364
  this.layoutService.layoutApi.widgetProductsApi.click(element);
@@ -4950,7 +5368,7 @@ let SlideApi$1 = class SlideApi {
4950
5368
  else if (linkType === "swipe-up-items") {
4951
5369
  const target = linkTarget;
4952
5370
  this.layoutService.env.setTimeout(() => {
4953
- this.sdkApi.openUrl({
5371
+ this.slideApiDeps.openUrl({
4954
5372
  type: "swipeUpItems",
4955
5373
  link: {
4956
5374
  type: "json",
@@ -4986,7 +5404,7 @@ let SlideApi$1 = class SlideApi {
4986
5404
  baseFields.message_id = cardId;
4987
5405
  break;
4988
5406
  }
4989
- this.sdkApi.sendStatisticEvent(statisticWidgetEventType, {
5407
+ this.slideApiDeps.sendStatisticEvent(statisticWidgetEventType, {
4990
5408
  i: cardId,
4991
5409
  si: slideIndex,
4992
5410
  wi: elementId,
@@ -5042,28 +5460,1403 @@ let SlideApi$1 = class SlideApi {
5042
5460
  }
5043
5461
  }
5044
5462
  }
5045
- _sdkClientVariables = {};
5046
- getSdkClientVariables() {
5047
- return this._sdkClientVariables;
5048
- }
5049
- setSdkClientVariables(variables) {
5050
- this._sdkClientVariables = variables;
5051
- }
5052
5463
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
5053
- sdkApi: SDKApi;
5464
+ slideApiDeps: ISlideApiDeps;
5054
5465
  slideWrapper: HTMLElement;
5055
5466
  viewport: Window;
5056
5467
  userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5057
5468
  slideRatio: number;
5058
5469
  isFullscreen: boolean;
5059
- slideLoadedCb?: (data: { cardId: number; slideIndex: number; result: boolean; reason?: string }) => void;
5060
5470
  getViewportWidth: () => number;
5061
5471
  getViewportHeight: () => number;
5062
5472
  overlappingActionBarHeight?: number;
5063
5473
  separateUserAndAppPause: boolean;
5474
+ root: HTMLElement;
5475
+ nonce?: string;
5476
+ // refreshSizes: (slide: SlideApi) => void;
5477
+ index: number;
5478
+ getSdkClientVariables: GetSdkClientVariables;
5064
5479
  }`]; }
5065
5480
  };
5066
5481
 
5482
+ class SlideApiDepsMultiSlideMode {
5483
+ sdkApi;
5484
+ slider;
5485
+ constructor(sdkApi, slider) {
5486
+ this.sdkApi = sdkApi;
5487
+ this.slider = slider;
5488
+ }
5489
+ getWidgetsSharedData(cardId, widget) {
5490
+ return this.sdkApi.getWidgetsSharedData(cardId, widget);
5491
+ }
5492
+ showToast(text) {
5493
+ return this.sdkApi.showToast(text);
5494
+ }
5495
+ writeToClipboard(data) {
5496
+ return this.sdkApi.writeToClipboard(data);
5497
+ }
5498
+ get isExistsShare() {
5499
+ return this.sdkApi.isExistsShare;
5500
+ }
5501
+ share(id, config) {
5502
+ this.sdkApi.share(id, config);
5503
+ }
5504
+ get sdkCanSendShareComplete() {
5505
+ return this.sdkApi.sdkCanSendShareComplete;
5506
+ }
5507
+ shareSlideScreenshot(shareId, hideElementsSelector, shareText) {
5508
+ this.sdkApi.shareSlideScreenshot(shareId, hideElementsSelector, shareText);
5509
+ }
5510
+ setCardSessionValue(element, key, value) {
5511
+ this.sdkApi.setCardSessionValue(element, key, value);
5512
+ }
5513
+ getCardSessionValue(element, key) {
5514
+ return this.sdkApi.getCardSessionValue(element, key);
5515
+ }
5516
+ getCardFonts() {
5517
+ return this.sdkApi.getCardFonts();
5518
+ }
5519
+ disableVerticalSwipeGesture() {
5520
+ this.sdkApi.disableVerticalSwipeGesture();
5521
+ }
5522
+ enableVerticalSwipeGesture() {
5523
+ this.sdkApi.enableVerticalSwipeGesture();
5524
+ }
5525
+ disableBackpress() {
5526
+ this.sdkApi.disableBackpress();
5527
+ }
5528
+ enableBackpress() {
5529
+ this.sdkApi.enableBackpress();
5530
+ }
5531
+ closeCard(reason) {
5532
+ this.sdkApi.closeCard(reason);
5533
+ }
5534
+ openStory(id, index) {
5535
+ // TODO rewrite with Promise - for usage story loading states in Button
5536
+ this.sdkApi.openStory(id, index);
5537
+ }
5538
+ openGame(gameInstanceId) {
5539
+ // TODO rewrite with Promise - for usage game loading states in Button
5540
+ this.sdkApi.openGame(gameInstanceId);
5541
+ }
5542
+ openUrl(data) {
5543
+ this.sdkApi.openUrl(data);
5544
+ }
5545
+ get isAndroid() {
5546
+ return this.sdkApi.isAndroid;
5547
+ }
5548
+ get isWeb() {
5549
+ return this.sdkApi.isWeb;
5550
+ }
5551
+ get isIOS() {
5552
+ return this.sdkApi.isIOS;
5553
+ }
5554
+ get isExistsShowCardTextInput() {
5555
+ return this.sdkApi.isExistsShowCardTextInput;
5556
+ }
5557
+ showCardTextInput(id, data) {
5558
+ this.sdkApi.showCardTextInput(id, data);
5559
+ }
5560
+ vibrate(pattern) {
5561
+ this.sdkApi.vibrate(pattern);
5562
+ }
5563
+ sendApiRequest(url, method, params, headers, data, profilingKey) {
5564
+ return this.sdkApi.sendApiRequest(url, method, params, headers, data, profilingKey);
5565
+ }
5566
+ sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2) {
5567
+ this.sdkApi.sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2);
5568
+ }
5569
+ setCardLocalData(keyValue, sendToServer) {
5570
+ this.sdkApi.setCardLocalData(keyValue, sendToServer);
5571
+ }
5572
+ getCardLocalData() {
5573
+ return this.sdkApi.getCardLocalData();
5574
+ }
5575
+ getCardServerData(cardId) {
5576
+ return this.sdkApi.getCardServerData(cardId);
5577
+ }
5578
+ get cardAnimation() {
5579
+ return this.sdkApi.cardAnimation;
5580
+ }
5581
+ updateCardServerDataLocally(cardId, data) {
5582
+ this.sdkApi.updateCardServerDataLocally(cardId, data);
5583
+ }
5584
+ get isExistsShowNextCard() {
5585
+ return this.sdkApi.isExistsShowNextCard;
5586
+ }
5587
+ cardShowNext() {
5588
+ return;
5589
+ // skip action in multislide mode (business logic)
5590
+ // this.sdkApi.cardShowNext();
5591
+ }
5592
+ /** @deprecated, used only in native sdk **/
5593
+ cardPausedCallback(currentTime) {
5594
+ this.sdkApi.cardPausedCallback(currentTime);
5595
+ }
5596
+ /** @deprecated, used only in native sdk **/
5597
+ cardResumedCallback(currentTime) {
5598
+ this.sdkApi.cardResumedCallback(currentTime);
5599
+ }
5600
+ disableHorizontalSwipeGesture() {
5601
+ this.sdkApi.disableHorizontalSwipeGesture();
5602
+ }
5603
+ enableHorizontalSwipeGesture() {
5604
+ this.sdkApi.enableHorizontalSwipeGesture();
5605
+ }
5606
+ isExistsShowLayer() {
5607
+ return this.sdkApi.isExistsShowLayer();
5608
+ }
5609
+ showLayer(index) {
5610
+ this.sdkApi.showLayer(index);
5611
+ }
5612
+ /**
5613
+ * For single slide mode - proxy these methods via SDKApi
5614
+ * =================================================================================================================
5615
+ */
5616
+ get isExistsShowCardSlide() {
5617
+ return true;
5618
+ }
5619
+ showCardSlide(index) {
5620
+ this.slider.showByIndex(index);
5621
+ }
5622
+ isSdkSupportUpdateTimeline() {
5623
+ return true;
5624
+ }
5625
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
5626
+ this.slider.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
5627
+ }
5628
+ isSdkSupportTimelineOnBeforeStart() {
5629
+ return true;
5630
+ }
5631
+ isSdkSupportCorrectPauseResumeLifecycle() {
5632
+ return true;
5633
+ }
5634
+ showNextSlide(duration) {
5635
+ this.slider.showNextSlide();
5636
+ }
5637
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`, `ISlider`]; }
5638
+ }
5639
+
5640
+ class SlideApiDepsSingleSlideMode {
5641
+ sdkApi;
5642
+ constructor(sdkApi) {
5643
+ this.sdkApi = sdkApi;
5644
+ }
5645
+ getWidgetsSharedData(cardId, widget) {
5646
+ return this.sdkApi.getWidgetsSharedData(cardId, widget);
5647
+ }
5648
+ showToast(text) {
5649
+ return this.sdkApi.showToast(text);
5650
+ }
5651
+ writeToClipboard(data) {
5652
+ return this.sdkApi.writeToClipboard(data);
5653
+ }
5654
+ get isExistsShare() {
5655
+ return this.sdkApi.isExistsShare;
5656
+ }
5657
+ share(id, config) {
5658
+ this.sdkApi.share(id, config);
5659
+ }
5660
+ get sdkCanSendShareComplete() {
5661
+ return this.sdkApi.sdkCanSendShareComplete;
5662
+ }
5663
+ shareSlideScreenshot(shareId, hideElementsSelector, shareText) {
5664
+ this.sdkApi.shareSlideScreenshot(shareId, hideElementsSelector, shareText);
5665
+ }
5666
+ setCardSessionValue(element, key, value) {
5667
+ this.sdkApi.setCardSessionValue(element, key, value);
5668
+ }
5669
+ getCardSessionValue(element, key) {
5670
+ return this.sdkApi.getCardSessionValue(element, key);
5671
+ }
5672
+ getCardFonts() {
5673
+ return this.sdkApi.getCardFonts();
5674
+ }
5675
+ disableVerticalSwipeGesture() {
5676
+ this.sdkApi.disableVerticalSwipeGesture();
5677
+ }
5678
+ enableVerticalSwipeGesture() {
5679
+ this.sdkApi.enableVerticalSwipeGesture();
5680
+ }
5681
+ disableBackpress() {
5682
+ this.sdkApi.disableBackpress();
5683
+ }
5684
+ enableBackpress() {
5685
+ this.sdkApi.enableBackpress();
5686
+ }
5687
+ closeCard(reason) {
5688
+ this.sdkApi.closeCard(reason);
5689
+ }
5690
+ openStory(id, index) {
5691
+ // TODO rewrite with Promise - for usage story loading states in Button
5692
+ this.sdkApi.openStory(id, index);
5693
+ }
5694
+ openGame(gameInstanceId) {
5695
+ // TODO rewrite with Promise - for usage game loading states in Button
5696
+ this.sdkApi.openGame(gameInstanceId);
5697
+ }
5698
+ openUrl(data) {
5699
+ this.sdkApi.openUrl(data);
5700
+ }
5701
+ get isAndroid() {
5702
+ return this.sdkApi.isAndroid;
5703
+ }
5704
+ get isWeb() {
5705
+ return this.sdkApi.isWeb;
5706
+ }
5707
+ get isIOS() {
5708
+ return this.sdkApi.isIOS;
5709
+ }
5710
+ get isExistsShowCardTextInput() {
5711
+ return this.sdkApi.isExistsShowCardTextInput;
5712
+ }
5713
+ showCardTextInput(id, data) {
5714
+ this.sdkApi.showCardTextInput(id, data);
5715
+ }
5716
+ vibrate(pattern) {
5717
+ this.sdkApi.vibrate(pattern);
5718
+ }
5719
+ sendApiRequest(url, method, params, headers, data, profilingKey) {
5720
+ return this.sdkApi.sendApiRequest(url, method, params, headers, data, profilingKey);
5721
+ }
5722
+ sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2) {
5723
+ this.sdkApi.sendStatisticEvent(name, data, devPayload, forceEnableStatisticV2);
5724
+ }
5725
+ setCardLocalData(keyValue, sendToServer) {
5726
+ this.sdkApi.setCardLocalData(keyValue, sendToServer);
5727
+ }
5728
+ getCardLocalData() {
5729
+ return this.sdkApi.getCardLocalData();
5730
+ }
5731
+ getCardServerData(cardId) {
5732
+ return this.sdkApi.getCardServerData(cardId);
5733
+ }
5734
+ get cardAnimation() {
5735
+ return this.sdkApi.cardAnimation;
5736
+ }
5737
+ updateCardServerDataLocally(cardId, data) {
5738
+ this.sdkApi.updateCardServerDataLocally(cardId, data);
5739
+ }
5740
+ get isExistsShowNextCard() {
5741
+ return this.sdkApi.isExistsShowNextCard;
5742
+ }
5743
+ cardShowNext() {
5744
+ this.sdkApi.cardShowNext();
5745
+ }
5746
+ /** @deprecated, used only in native sdk **/
5747
+ cardPausedCallback(currentTime) {
5748
+ this.sdkApi.cardPausedCallback(currentTime);
5749
+ }
5750
+ /** @deprecated, used only in native sdk **/
5751
+ cardResumedCallback(currentTime) {
5752
+ this.sdkApi.cardResumedCallback(currentTime);
5753
+ }
5754
+ disableHorizontalSwipeGesture() {
5755
+ this.sdkApi.disableHorizontalSwipeGesture();
5756
+ }
5757
+ enableHorizontalSwipeGesture() {
5758
+ this.sdkApi.enableHorizontalSwipeGesture();
5759
+ }
5760
+ isExistsShowLayer() {
5761
+ return this.sdkApi.isExistsShowLayer();
5762
+ }
5763
+ showLayer(index) {
5764
+ this.sdkApi.showLayer(index);
5765
+ }
5766
+ /**
5767
+ * For single slide mode - proxy these methods via SDKApi
5768
+ */
5769
+ get isExistsShowCardSlide() {
5770
+ return this.sdkApi.isExistsShowCardSlide;
5771
+ }
5772
+ showCardSlide(index) {
5773
+ this.sdkApi.showCardSlide(index);
5774
+ }
5775
+ isSdkSupportUpdateTimeline() {
5776
+ return this.sdkApi.isSdkSupportUpdateTimeline();
5777
+ }
5778
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
5779
+ this.sdkApi.updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
5780
+ }
5781
+ isSdkSupportTimelineOnBeforeStart() {
5782
+ return this.sdkApi.isSdkSupportTimelineOnBeforeStart();
5783
+ }
5784
+ isSdkSupportCorrectPauseResumeLifecycle() {
5785
+ return this.sdkApi.isSdkSupportCorrectPauseResumeLifecycle();
5786
+ }
5787
+ showNextSlide(duration) {
5788
+ this.sdkApi.showNextSlide(duration);
5789
+ }
5790
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`]; }
5791
+ }
5792
+
5793
+ class SlideTimer {
5794
+ requestStartTimer;
5795
+ requestCancelTimer;
5796
+ updateCb;
5797
+ doneCb;
5798
+ constructor(requestStartTimer, requestCancelTimer, updateCb, doneCb) {
5799
+ this.requestStartTimer = requestStartTimer;
5800
+ this.requestCancelTimer = requestCancelTimer;
5801
+ this.updateCb = updateCb;
5802
+ this.doneCb = doneCb;
5803
+ }
5804
+ duration;
5805
+ timeLeft;
5806
+ _pause = true;
5807
+ _stop = true;
5808
+ _started = false;
5809
+ start(duration) {
5810
+ this.duration = duration;
5811
+ this.stop();
5812
+ this.timeLeft = this.duration;
5813
+ this._pause = false;
5814
+ this._stop = false;
5815
+ this._started = true;
5816
+ this.tick();
5817
+ }
5818
+ stop() {
5819
+ this._stop = true;
5820
+ this._started = false;
5821
+ if (this.timerId != null) {
5822
+ this.requestCancelTimer(this.timerId);
5823
+ this.timerId = null;
5824
+ }
5825
+ // this.updateCb(0);
5826
+ }
5827
+ pause() {
5828
+ this._pause = true;
5829
+ if (this.timerId != null) {
5830
+ this.requestCancelTimer(this.timerId);
5831
+ this.timerId = null;
5832
+ }
5833
+ }
5834
+ resume(currentTime = undefined, duration = 0) {
5835
+ this._pause = false;
5836
+ if (!this._started) {
5837
+ this.start(duration);
5838
+ }
5839
+ else {
5840
+ if (currentTime != null) {
5841
+ // timeLeft correction
5842
+ this.timeLeft = this.duration - currentTime;
5843
+ }
5844
+ this.tick();
5845
+ }
5846
+ }
5847
+ timerId;
5848
+ tick() {
5849
+ if (this._stop) {
5850
+ return;
5851
+ }
5852
+ const rafStartTime = new Date().getTime();
5853
+ this.timerId = this.requestStartTimer(() => {
5854
+ if (this._stop) {
5855
+ return;
5856
+ }
5857
+ const dtDiff = new Date().getTime() - rafStartTime;
5858
+ this.timeLeft -= dtDiff;
5859
+ let progressPercent = Math.round(((this.duration - this.timeLeft) / this.duration) * 100 * 10000) / 10000;
5860
+ if (progressPercent > 100) {
5861
+ progressPercent = 100;
5862
+ }
5863
+ this.updateCb(progressPercent);
5864
+ if (progressPercent < 100) {
5865
+ if (this._pause !== true) {
5866
+ this.tick();
5867
+ }
5868
+ }
5869
+ else {
5870
+ this.doneCb();
5871
+ }
5872
+ });
5873
+ }
5874
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`(callback: () => void) => number`, `(timerId: number) => void`, `(progressPercent: number) => void`, `() => void`]; }
5875
+ }
5876
+
5877
+ /**
5878
+ * usage TS interface with ctor
5879
+ * https://blog.logrocket.com/writing-constructor-typescript/
5880
+ *
5881
+ * @param ctor
5882
+ * @param slides
5883
+ * @param getLayoutDirection
5884
+ */
5885
+ function createTimelineController(ctor, slides, getLayoutDirection) {
5886
+ return new ctor(slides, getLayoutDirection);
5887
+ }
5888
+ class TimelineController {
5889
+ slides;
5890
+ getLayoutDirection;
5891
+ constructor(slides, getLayoutDirection) {
5892
+ this.slides = slides;
5893
+ this.getLayoutDirection = getLayoutDirection;
5894
+ }
5895
+ onSlideTimerUpdate(index, progressPercent) {
5896
+ this.slides[index]?.updateTimelineProgress(progressPercent, true);
5897
+ }
5898
+ onSlideBeforeStart(index) {
5899
+ // fill to 100% all previous slides
5900
+ for (let i = 0; i < index; ++i) {
5901
+ this.slides[i]?.updateTimelineProgress(100, false);
5902
+ }
5903
+ // fill to 0% all next slides (for user revert direction)
5904
+ for (let i = index + 1; i < this.slides.length; ++i) {
5905
+ this.slides[i]?.updateTimelineProgress(0, false);
5906
+ }
5907
+ // activate current slide
5908
+ this.slides[index]?.updateTimelineProgress(0, true);
5909
+ }
5910
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Array`, `GetLayoutDirection`]; }
5911
+ }
5912
+
5913
+ class Slider {
5914
+ config;
5915
+ constructor(config) {
5916
+ this.config = config;
5917
+ for (let i = 0; i < config.slides.length; ++i) {
5918
+ const item = {
5919
+ called: false,
5920
+ firstRenderCall: null,
5921
+ firstRenderCallPromise: null,
5922
+ };
5923
+ item.firstRenderCallPromise = new Promise(resolver => {
5924
+ item.firstRenderCall = resolver;
5925
+ });
5926
+ this.slidesFirstRenders[i] = item;
5927
+ }
5928
+ const slideWrapper = this.createSliderElement({
5929
+ slides: config.slides,
5930
+ nonce: config.nonce,
5931
+ slideRender: config.slideRender,
5932
+ navbarAppearance: config.navbarAppearance,
5933
+ });
5934
+ config.root.appendChild(slideWrapper);
5935
+ this.slideWrapperElement = slideWrapper;
5936
+ this.timelineController = createTimelineController(TimelineController, this.slides, this.config.getLayoutDirection.bind(this));
5937
+ // cardMounted: (card: HTMLElement) => Promise<void>
5938
+ requestAnimationFrame(async () => {
5939
+ await Promise.all(this.slides.map((slide, index) => config.onSlideMounted(slide.element, index)));
5940
+ });
5941
+ }
5942
+ isAnimating = false;
5943
+ activeIndex = -1;
5944
+ get activeSlide() {
5945
+ return this.slides[this.activeIndex];
5946
+ }
5947
+ slides = [];
5948
+ sliderTrack = null;
5949
+ bulletsContainer = null;
5950
+ slidesFirstRenders = [];
5951
+ slideWrapperElement;
5952
+ timelineController;
5953
+ assembleNavbarCssVariables(navbarAppearance) {
5954
+ let css = "";
5955
+ if (navbarAppearance.edge_offset != null) {
5956
+ css += `--navbar-edge-offset: ${navbarAppearance.edge_offset};`;
5957
+ }
5958
+ if (navbarAppearance.active_timeline_width != null) {
5959
+ css += `--navbar-active-timeline_width: ${navbarAppearance.active_timeline_width};`;
5960
+ }
5961
+ if (navbarAppearance.background_color != null) {
5962
+ css += `--navbar-background-color: ${navbarAppearance.background_color};`;
5963
+ }
5964
+ if (navbarAppearance.border_radius != null) {
5965
+ css += `--navbar-border-radius: ${navbarAppearance.border_radius};`;
5966
+ }
5967
+ if (navbarAppearance.drop_shadow_blur != null) {
5968
+ css += `--navbar-drop-shadow-blur: ${navbarAppearance.drop_shadow_blur};`;
5969
+ }
5970
+ if (navbarAppearance.drop_shadow_color != null) {
5971
+ css += `--navbar-drop-shadow-color: ${navbarAppearance.drop_shadow_color};`;
5972
+ }
5973
+ if (navbarAppearance.drop_shadow_x_offset != null) {
5974
+ css += `--navbar-drop-shadow-x-offset: ${navbarAppearance.drop_shadow_x_offset};`;
5975
+ }
5976
+ if (navbarAppearance.drop_shadow_y_offset != null) {
5977
+ css += `--navbar-drop-shadow-y-offset: ${navbarAppearance.drop_shadow_y_offset};`;
5978
+ }
5979
+ if (navbarAppearance.timeline_background_color != null) {
5980
+ css += `--navbar-timeline-background-color: ${navbarAppearance.timeline_background_color};`;
5981
+ }
5982
+ if (navbarAppearance.timeline_fill_color != null) {
5983
+ css += `--navbar-timeline-fill-color: ${navbarAppearance.timeline_fill_color};`;
5984
+ }
5985
+ if (navbarAppearance.timeline_size != null) {
5986
+ css += `--navbar-timeline-size: ${navbarAppearance.timeline_size};`;
5987
+ }
5988
+ if (navbarAppearance.timelines_gap != null) {
5989
+ css += `--navbar-timelines-gap: ${navbarAppearance.timelines_gap};`;
5990
+ }
5991
+ if (navbarAppearance.vertical_padding != null) {
5992
+ css += `--navbar-vertical-padding: ${navbarAppearance.vertical_padding};`;
5993
+ }
5994
+ if (navbarAppearance.horizontal_padding != null) {
5995
+ css += `--navbar-horizontal-padding: ${navbarAppearance.horizontal_padding};`;
5996
+ }
5997
+ return `.cards-slider {${css}`;
5998
+ }
5999
+ createSliderElement = ({ slides, nonce, slideRender, navbarAppearance, }) => {
6000
+ const style = document.createElement("style");
6001
+ if (nonce != null) {
6002
+ style.nonce = nonce;
6003
+ }
6004
+ style.innerText = this.assembleNavbarCssVariables(navbarAppearance);
6005
+ const slider = document.createElement("div");
6006
+ slider.classList.add("cards-slider");
6007
+ const track = document.createElement("div");
6008
+ track.classList.add("cards-slider__track");
6009
+ this.sliderTrack = track;
6010
+ const [bullets, updateTimelineProgress] = this.createBulletPoints(slides.length, this.config.getLayoutDirection.bind(this), navbarAppearance.position);
6011
+ this.bulletsContainer = bullets;
6012
+ this.slides = slides.map((slide, i) => ({
6013
+ element: slideRender(slide, i, this.slidesFirstRenders[i].firstRenderCallPromise),
6014
+ timer: new SlideTimer(cb => window.requestAnimationFrame(cb), handle => window.cancelAnimationFrame(handle), progressPercent => this.timelineController.onSlideTimerUpdate(i, progressPercent), this.onSlideTimerEnd.bind(this)),
6015
+ updateTimelineProgress: (progressPercent, isActive) => updateTimelineProgress(i, progressPercent, isActive),
6016
+ }));
6017
+ for (let i = 0; i < this.slides.length; ++i) {
6018
+ const slideElement = document.createElement("div");
6019
+ slideElement.classList.add("cards-slider__slide");
6020
+ slideElement.setAttribute("data-index", String(i));
6021
+ slideElement.appendChild(this.slides[i].element);
6022
+ track.appendChild(slideElement);
6023
+ }
6024
+ slider.appendChild(track);
6025
+ const safeAreaView = document.createElement("div");
6026
+ safeAreaView.classList.add("safe-area-view", "inset-0", "non-touchable");
6027
+ const safeAreaRelativeZoneView = document.createElement("div");
6028
+ safeAreaRelativeZoneView.classList.add("safe-area-relative-zone-view");
6029
+ safeAreaRelativeZoneView.appendChild(bullets);
6030
+ safeAreaView.appendChild(safeAreaRelativeZoneView);
6031
+ slider.appendChild(safeAreaView);
6032
+ slider.appendChild(style);
6033
+ return slider;
6034
+ };
6035
+ createBulletPoints(count, getLayoutDirection, position) {
6036
+ const bullets = document.createElement("div");
6037
+ bullets.classList.add("cards-slider__navbar");
6038
+ if (position === 0) {
6039
+ bullets.classList.add("cards-slider__navbar--position-none");
6040
+ }
6041
+ else if (position === 1) {
6042
+ bullets.classList.add("cards-slider__navbar--position-top");
6043
+ }
6044
+ else if (position === 2) {
6045
+ bullets.classList.add("cards-slider__navbar--position-bottom");
6046
+ }
6047
+ else {
6048
+ // default
6049
+ bullets.classList.add("cards-slider__navbar--position-bottom");
6050
+ }
6051
+ bullets.dir = getLayoutDirection();
6052
+ for (let i = 0; i < count; ++i) {
6053
+ const bullet = document.createElement("div");
6054
+ bullet.classList.add("cards-slider__timeline", "touchable");
6055
+ bullet.setAttribute("data-index", String(i));
6056
+ bullet.onclick = (e) => {
6057
+ e.stopPropagation();
6058
+ e.preventDefault();
6059
+ const bullet = e.target;
6060
+ if (bullet != null) {
6061
+ const index = bullet.dataset.index;
6062
+ if (index != null) {
6063
+ this.showByIndex(parseInt(index));
6064
+ }
6065
+ }
6066
+ };
6067
+ const bulletFill = document.createElement("div");
6068
+ bulletFill.classList.add("cards-slider__timeline-fill");
6069
+ bullet.append(bulletFill);
6070
+ bullets.appendChild(bullet);
6071
+ }
6072
+ // const onUpdateActiveIndex = (activeIndex: number) => {
6073
+ // if (activeIndex >= 0 && activeIndex < count) {
6074
+ // for (const bullet of bullets.querySelectorAll(".cards-slider__bullet--active")) {
6075
+ // bullet.classList.toggle("cards-slider__bullet--active");
6076
+ // }
6077
+ // bullets.querySelector(`.cards-slider__bullet[data-index="${activeIndex}"]`)?.classList.toggle("cards-slider__bullet--active");
6078
+ // }
6079
+ // };
6080
+ const onUpdateTimelineProgress = (index, progress, isActive) => {
6081
+ if (index >= 0 && index < count) {
6082
+ const bullet = bullets.querySelector(`.cards-slider__timeline:nth-child(${index + 1})`);
6083
+ const bulletFill = bullet?.querySelector(".cards-slider__timeline-fill");
6084
+ bullet?.classList[isActive ? "add" : "remove"]("cards-slider__timeline--active");
6085
+ if (bulletFill != null) {
6086
+ // todo remove progress after slide changed?
6087
+ if (this.config.getLayoutDirection() === "rtl") {
6088
+ progress = -1 * progress;
6089
+ }
6090
+ bulletFill.style.setProperty("transform", `translateX(${progress}%)`);
6091
+ }
6092
+ }
6093
+ };
6094
+ return [bullets, onUpdateTimelineProgress];
6095
+ }
6096
+ async showByIndex(newIndex) {
6097
+ const prevIndex = this.activeIndex;
6098
+ if (this.isAnimating)
6099
+ return prevIndex;
6100
+ if (newIndex === prevIndex)
6101
+ return prevIndex;
6102
+ if (prevIndex !== -1) {
6103
+ // skip for slider start
6104
+ this.config.onSlideLeft(this.slides[prevIndex].element, prevIndex);
6105
+ await this.config.onSlideStop();
6106
+ }
6107
+ const { index, loadingError } = await this.initAndRenderSlide(newIndex);
6108
+ if (loadingError) {
6109
+ // todo via updateTimeline ????
6110
+ this.config.onSlideLoadingError(index, loadingError);
6111
+ }
6112
+ if (!loadingError) {
6113
+ this.onShowSlide(index);
6114
+ }
6115
+ await this.slideTo(index);
6116
+ if (!loadingError) {
6117
+ this.config.onSlideStart();
6118
+ }
6119
+ return newIndex;
6120
+ }
6121
+ async showNextSlide() {
6122
+ const prevIndex = this.activeIndex;
6123
+ if (this.isAnimating)
6124
+ return prevIndex;
6125
+ const newIndex = prevIndex + 1;
6126
+ if (newIndex < 0 || newIndex >= this.slides.length) {
6127
+ return null;
6128
+ }
6129
+ if (prevIndex !== -1) {
6130
+ // skip for slider start
6131
+ this.config.onSlideLeft(this.slides[prevIndex].element, prevIndex);
6132
+ await this.config.onSlideStop();
6133
+ }
6134
+ const { index, loadingError } = await this.initAndRenderSlide(newIndex);
6135
+ if (loadingError) {
6136
+ // todo via updateTimeline ????
6137
+ this.config.onSlideLoadingError(index, loadingError);
6138
+ }
6139
+ if (!loadingError) {
6140
+ this.onShowSlide(index);
6141
+ }
6142
+ await this.slideTo(index);
6143
+ if (!loadingError) {
6144
+ this.config.onSlideStart();
6145
+ }
6146
+ return newIndex;
6147
+ }
6148
+ async initAndRenderSlide(index) {
6149
+ this.config.onBeforeLoadSlide(index);
6150
+ let showSlidePromise;
6151
+ if (!this.slidesFirstRenders[index].called) {
6152
+ // first render call
6153
+ this.slidesFirstRenders[index].called = true;
6154
+ showSlidePromise = new Promise(resolve => {
6155
+ this.slidesFirstRenders[index].firstRenderCall(resolve);
6156
+ }).then(_ => _);
6157
+ }
6158
+ else {
6159
+ showSlidePromise = this.config.onBeforeShowSlide(this.slides[index].element, index);
6160
+ }
6161
+ try {
6162
+ const { moveToIndex } = await showSlidePromise;
6163
+ if (moveToIndex !== index) {
6164
+ index = moveToIndex;
6165
+ // jump to necessary slide (from WidgetQuest for instance)
6166
+ return this.initAndRenderSlide(index);
6167
+ }
6168
+ else {
6169
+ return { index, loadingError: undefined };
6170
+ }
6171
+ }
6172
+ catch (loadingError) {
6173
+ // catch loading error
6174
+ // this.config.onSlideLoadingError(index, e as string);
6175
+ console.error(loadingError);
6176
+ return { index, loadingError: loadingError };
6177
+ }
6178
+ }
6179
+ onShowSlide(index) {
6180
+ // this.updateBulletActiveIndex(index);
6181
+ this.config.onShowSlide(this.slides[index].element, index);
6182
+ // this.config.onSlideStart();
6183
+ }
6184
+ onUpdateSizeMetrics(metrics) {
6185
+ // this.slideTo(this.activeIndex, 0);
6186
+ }
6187
+ getSlideOffset(index) {
6188
+ if (!this.slides.length)
6189
+ return 0;
6190
+ const k = this.config.getLayoutDirection() === "ltr" ? -1 : 1;
6191
+ const cardWidth = this.slides[0].element.clientWidth;
6192
+ return k * index * cardWidth;
6193
+ }
6194
+ async slideTo(index, speed = 300) {
6195
+ if (index < 0 || index > this.slides.length - 1 || this.isAnimating)
6196
+ return;
6197
+ const cardOffset = this.getSlideOffset(index);
6198
+ await this.translateTo(cardOffset, speed);
6199
+ this.activeIndex = index;
6200
+ }
6201
+ setTranslate(value) {
6202
+ this.sliderTrack?.style.setProperty("transform", `translateX(${value}px)`);
6203
+ }
6204
+ setTransition(duration = 300) {
6205
+ this.sliderTrack?.style.setProperty("transition", `transform ${duration}ms`);
6206
+ }
6207
+ async translateTo(translate, speed) {
6208
+ if (this.isAnimating)
6209
+ return;
6210
+ this.setTransition(speed);
6211
+ this.setTranslate(translate);
6212
+ if (speed > 0) {
6213
+ this.isAnimating = true;
6214
+ await this.waitTransitionEnd();
6215
+ this.isAnimating = false;
6216
+ }
6217
+ }
6218
+ waitTransitionEnd() {
6219
+ const sliderTrack = this.sliderTrack;
6220
+ if (!sliderTrack)
6221
+ return Promise.resolve();
6222
+ return new Promise(resolve => {
6223
+ const handler = (e) => {
6224
+ if (e.propertyName === "transform") {
6225
+ sliderTrack.style.transitionDuration = "0ms";
6226
+ resolve();
6227
+ }
6228
+ };
6229
+ sliderTrack.addEventListener("transitionend", handler, { once: true });
6230
+ });
6231
+ }
6232
+ destroy() {
6233
+ this.activeSlide?.timer.stop();
6234
+ if (this.slideWrapperElement != null && this.config.root != null) {
6235
+ this.config.root.removeChild(this.slideWrapperElement);
6236
+ }
6237
+ }
6238
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
6239
+ switch (action) {
6240
+ case "before_start" /* TIMELINE_ACTION.BEFORE_START */: {
6241
+ // switch timeline to active slide and wait for start (wait VOD loading)
6242
+ // console.log("TIMELINE_ACTION.BEFORE_START", { activeSlide: this.activeSlide, duration });
6243
+ this.timelineController.onSlideBeforeStart(slideIndex);
6244
+ break;
6245
+ }
6246
+ case "start" /* TIMELINE_ACTION.START */: {
6247
+ this.config.onSlideDataResume();
6248
+ // also start after data waiting or pause
6249
+ // destroy on IAM closing
6250
+ // console.log("TIMELINE_ACTION.START", {
6251
+ // activeSlide: this.activeSlide,
6252
+ // index: this.activeIndex,
6253
+ // duration,
6254
+ // });
6255
+ let resumeTimer = false;
6256
+ if (duration > 0) {
6257
+ // skip timer start for slide/layer with disabled timeline
6258
+ resumeTimer = true;
6259
+ }
6260
+ if (currentTime === duration) {
6261
+ // skip timer start for already ended layer timeline
6262
+ // skip timer start for already ended layer timeline
6263
+ resumeTimer = false;
6264
+ }
6265
+ if (resumeTimer) {
6266
+ this.activeSlide?.timer.resume(currentTime, duration);
6267
+ }
6268
+ break;
6269
+ }
6270
+ case "pause" /* TIMELINE_ACTION.PAUSE */: {
6271
+ if (showLoader) {
6272
+ this.config.onSlideDataWaiting();
6273
+ }
6274
+ this.activeSlide?.timer.pause();
6275
+ // console.log("TIMELINE_ACTION.PAUSE", { activeSlide: this.activeSlide, duration });
6276
+ break;
6277
+ }
6278
+ case "stop" /* TIMELINE_ACTION.STOP */: {
6279
+ // loading error
6280
+ if (showError) {
6281
+ this.config.onSlideDataError();
6282
+ }
6283
+ this.activeSlide?.timer.stop();
6284
+ // todo нужен STOP когда вручную переключаем слайд на другой
6285
+ // console.log("TIMELINE_ACTION.STOP", { activeSlide: this.activeSlide, duration });
6286
+ break;
6287
+ }
6288
+ }
6289
+ }
6290
+ // private onSlideTimerUpdate(progress: number) {
6291
+ // this.updateTimelineProgress(this.activeIndex, progress);
6292
+ // }
6293
+ async onSlideTimerEnd() {
6294
+ await this.config.onSlideStop();
6295
+ this.config.onSlideTimerEnd();
6296
+ }
6297
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
6298
+ slides: Array<T>;
6299
+ root: HTMLElement;
6300
+ nonce?: string;
6301
+ navbarAppearance: NavbarAppearance;
6302
+ slideRender: SlideRender<T>;
6303
+ onSlideMounted: OnSlideMounted;
6304
+ onBeforeShowSlide: OnBeforeShowSlide;
6305
+ onBeforeLoadSlide: OnBeforeLoadSlide;
6306
+ onSlideLoadingError: OnSlideLoadingError;
6307
+ onShowSlide: OnShowSlide;
6308
+ onSlideLeft: OnSlideLeft;
6309
+ getLayoutDirection: GetLayoutDirection;
6310
+
6311
+ onSlideTimerEnd: OnSlideTimerEnd;
6312
+ onSlideStart: OnSlideStart;
6313
+ onSlideStop: OnSlideStop;
6314
+ onSlideDataWaiting: OnSlideDataWaiting;
6315
+ onSlideDataResume: OnSlideDataResume;
6316
+ onSlideDataError: OnSlideDataError;
6317
+ }`]; }
6318
+ }
6319
+
6320
+ class CardApi {
6321
+ config;
6322
+ get layoutDirection() {
6323
+ return this.activeSlide.layoutDirection;
6324
+ }
6325
+ static renderedBoxClassName = "narrative-slide-box-rendered";
6326
+ static prerenderBoxClassName = "narrative-slide-box-prerender";
6327
+ _singleCardSlideWrapper;
6328
+ _viewport;
6329
+ _getViewportWidth;
6330
+ _getViewportHeight;
6331
+ _overlappingActionBarHeight;
6332
+ _separateUserAndAppPause;
6333
+ _useSdkCacheForMultislideMode;
6334
+ sdkApi;
6335
+ activeSlide = null;
6336
+ slides = [];
6337
+ slidesMode = 0 /* SLIDES_MODE.SINGLE */;
6338
+ cardLoadingStateController = null;
6339
+ sizeMetrics = {
6340
+ fontSize: "0px",
6341
+ isFullscreen: false,
6342
+ slideOffsetMargin: "0px",
6343
+ xOffset: "0px",
6344
+ yOffset: "0px",
6345
+ };
6346
+ constructor(config) {
6347
+ this.config = config;
6348
+ this.sdkApi = config.sdkApi;
6349
+ this._singleCardSlideWrapper = config.slideWrapper;
6350
+ this._viewport = config.viewport;
6351
+ this._getViewportWidth = config.getViewportWidth;
6352
+ this._getViewportHeight = config.getViewportHeight;
6353
+ this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
6354
+ this._separateUserAndAppPause = config.separateUserAndAppPause;
6355
+ this._useSdkCacheForMultislideMode = config.useSdkCacheForMultislideMode;
6356
+ this.refreshSizes = proxy(this.refreshSizes, this);
6357
+ this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
6358
+ this.refreshSizes();
6359
+ // todo - возможность не создавать slideApi в ctor (это не нужно для multislide mode)
6360
+ // но тогда все методы должны обходить случай когда activeSlide undefined
6361
+ this.activeSlide = new SlideApi$1({
6362
+ slideApiDeps: new SlideApiDepsSingleSlideMode(this.config.sdkApi),
6363
+ slideWrapper: this.config.slideWrapper,
6364
+ viewport: this.config.viewport,
6365
+ userResizeHandler: this.config.userResizeHandler,
6366
+ slideRatio: this.config.slideRatio,
6367
+ isFullscreen: this.config.isFullscreen,
6368
+ getViewportWidth: this.config.getViewportWidth,
6369
+ getViewportHeight: this.config.getViewportHeight,
6370
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6371
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6372
+ root: this.config.root,
6373
+ index: 0,
6374
+ getSdkClientVariables: this.getSdkClientVariables,
6375
+ });
6376
+ this.activeSlide.onUpdateSizeMetrics(this.sizeMetrics);
6377
+ if (SlideApi$1.checkPreloadedInLayoutSlide()) {
6378
+ this.activeSlide.initPreloadedInLayoutSlide(this.config.slideLoadedCb);
6379
+ }
6380
+ this.initListeners();
6381
+ }
6382
+ get state() {
6383
+ // TODO remove usage from web-sdk
6384
+ return this.activeSlide.state;
6385
+ }
6386
+ async destroy() {
6387
+ await this.activeSlide.destroy();
6388
+ await Promise.all(this.slides.map(({ slide }) => {
6389
+ if (slide !== this.activeSlide) {
6390
+ return slide?.destroy();
6391
+ }
6392
+ }));
6393
+ this.destroyListeners();
6394
+ }
6395
+ initListeners() {
6396
+ // @ts-ignore
6397
+ this._viewport.addEventListener("resize", this.refreshSizes);
6398
+ }
6399
+ destroyListeners() {
6400
+ // @ts-ignore
6401
+ this._viewport.removeEventListener("resize", this.refreshSizes);
6402
+ // todo call via activeSlide.refreshSizes
6403
+ }
6404
+ _savedViewportWidth = null;
6405
+ _savedViewportHeight = null;
6406
+ refreshSizes() {
6407
+ const viewportWidth = this._getViewportWidth();
6408
+ const viewportHeight = this._getViewportHeight();
6409
+ if (this._savedViewportWidth === viewportWidth && this._savedViewportHeight === viewportHeight) {
6410
+ return;
6411
+ }
6412
+ this._savedViewportWidth = viewportWidth;
6413
+ this._savedViewportHeight = viewportHeight;
6414
+ const viewportRatio = viewportWidth / viewportHeight;
6415
+ let slideWidth = 0;
6416
+ let slideHeight = 0;
6417
+ // _ratio = 310 / 480,
6418
+ const _ratio = this.config.slideRatio;
6419
+ let _isFullscreen = this.config.isFullscreen;
6420
+ let offset = 0;
6421
+ let xOffset = "0px";
6422
+ // for elements with bottom anchor (absolute position)
6423
+ let yOffset = "0px";
6424
+ // todo - mobile only (or isIos or isAndroid)
6425
+ if (this.sdkApi.isAndroid || this.sdkApi.isIOS) {
6426
+ if (viewportRatio > _ratio) {
6427
+ // disable _isFullscreen if viewport small
6428
+ _isFullscreen = false;
6429
+ }
6430
+ }
6431
+ let slideOffsetMargin = "";
6432
+ if (_isFullscreen) {
6433
+ // более квадратное чем надо (desktop)
6434
+ if (viewportRatio > _ratio) {
6435
+ // fit by height
6436
+ slideHeight = viewportHeight;
6437
+ slideWidth = Math.ceil(slideHeight * _ratio);
6438
+ offset = Math.ceil(slideWidth - viewportWidth) / 2;
6439
+ slideOffsetMargin = "0 " + -offset + "px"; // -8.5
6440
+ xOffset = offset + "px";
6441
+ }
6442
+ else {
6443
+ // fit by width, top and bottom - to offscreen or fill with bg image
6444
+ slideWidth = viewportWidth;
6445
+ slideHeight = Math.ceil(viewportWidth / _ratio);
6446
+ offset = Math.ceil(slideHeight - viewportHeight) / 2;
6447
+ slideOffsetMargin = -1 * offset + "px" + " 0 ";
6448
+ // offset from viewport bottom to StoryBottom plus safe area offset bottom
6449
+ yOffset = `calc(${offset + this._overlappingActionBarHeight}px + env(safe-area-inset-bottom))`;
6450
+ // detect safe area offset
6451
+ }
6452
+ }
6453
+ else {
6454
+ // более квадратное чем надо
6455
+ if (viewportRatio > _ratio) {
6456
+ // fit by width, top and bottom - to offscreen
6457
+ slideWidth = viewportWidth;
6458
+ slideHeight = Math.ceil(viewportWidth / _ratio);
6459
+ offset = Math.ceil(slideHeight - viewportHeight) / 2;
6460
+ slideOffsetMargin = -offset + "px" + " 0 ";
6461
+ yOffset = offset + this._overlappingActionBarHeight + "px";
6462
+ }
6463
+ else {
6464
+ // вьюпорт более вытянутый чем надо
6465
+ // fit by height, sides - to offscreen
6466
+ slideHeight = viewportHeight;
6467
+ slideWidth = Math.ceil(slideHeight * _ratio);
6468
+ offset = Math.ceil(slideWidth - viewportWidth) / 2;
6469
+ slideOffsetMargin = "0 " + -offset + "px"; // -8.5
6470
+ xOffset = offset + "px";
6471
+ }
6472
+ }
6473
+ const fontSizeNumber = slideWidth / 20;
6474
+ const fontSize = `${fontSizeNumber}px`;
6475
+ const sizeMetrics = { fontSize, xOffset, yOffset, isFullscreen: _isFullscreen, slideOffsetMargin };
6476
+ this.sizeMetrics = sizeMetrics;
6477
+ this.activeSlide?.onUpdateSizeMetrics(sizeMetrics);
6478
+ this.slides.forEach(({ slide }) => {
6479
+ if (slide !== this.activeSlide) {
6480
+ slide?.onUpdateSizeMetrics(sizeMetrics);
6481
+ }
6482
+ });
6483
+ this.slider?.onUpdateSizeMetrics(sizeMetrics);
6484
+ if (this.config.userResizeHandler != null) {
6485
+ this.config.userResizeHandler({ viewportWidth, viewportHeight, fontSize: fontSizeNumber });
6486
+ }
6487
+ }
6488
+ async showSlide(html) {
6489
+ this.slidesMode = 0 /* SLIDES_MODE.SINGLE */;
6490
+ if (this.activeSlide == null) {
6491
+ this.activeSlide = new SlideApi$1({
6492
+ slideApiDeps: new SlideApiDepsSingleSlideMode(this.config.sdkApi),
6493
+ slideWrapper: this.config.slideWrapper,
6494
+ viewport: this.config.viewport,
6495
+ userResizeHandler: this.config.userResizeHandler,
6496
+ slideRatio: this.config.slideRatio,
6497
+ isFullscreen: this.config.isFullscreen,
6498
+ getViewportWidth: this.config.getViewportWidth,
6499
+ getViewportHeight: this.config.getViewportHeight,
6500
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6501
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6502
+ root: this.config.root,
6503
+ // refreshSizes: this.refreshSizes,
6504
+ index: 0,
6505
+ getSdkClientVariables: this.getSdkClientVariables,
6506
+ });
6507
+ this.activeSlide.onUpdateSizeMetrics(this.sizeMetrics);
6508
+ }
6509
+ return this.activeSlide.showSlide(html);
6510
+ }
6511
+ slider = null;
6512
+ async showSlides(slides, cardAppearance, index = 0) {
6513
+ this.slidesMode = 1 /* SLIDES_MODE.MULTIPLE */;
6514
+ if (this.cardLoadingStateController === null) {
6515
+ this.cardLoadingStateController = new CardLoadingStateController(this.sdkApi.onCardLoadingStateChange.bind(this.sdkApi));
6516
+ }
6517
+ this.cardLoadingStateController.onSetLoadStartState();
6518
+ slides.forEach((content, index) => {
6519
+ if (this.slides[index] == null) {
6520
+ const item = { content, resourcesReadyPromise: null };
6521
+ if (this._useSdkCacheForMultislideMode) {
6522
+ item.resourcesReadyPromise = new Promise((resolve, reject) => {
6523
+ item.resourcesReadyPromisesResolver = { resolve, reject };
6524
+ });
6525
+ }
6526
+ else {
6527
+ item.resourcesReadyPromise = Promise.resolve();
6528
+ }
6529
+ this.slides[index] = item;
6530
+ }
6531
+ else {
6532
+ // for case when sdk call setSlideInCacheStatus before showSlides and for slideReloading (after loading error)
6533
+ this.slides[index].content = content;
6534
+ if (this.slides[index].resourcesReadyPromise == null) {
6535
+ if (this._useSdkCacheForMultislideMode) {
6536
+ this.slides[index].resourcesReadyPromise = new Promise((resolve, reject) => {
6537
+ this.slides[index].resourcesReadyPromisesResolver = { resolve, reject };
6538
+ });
6539
+ }
6540
+ else {
6541
+ this.slides[index].resourcesReadyPromise = Promise.resolve();
6542
+ }
6543
+ }
6544
+ }
6545
+ });
6546
+ const onBeforeShowSlide = (slideElement, index) => {
6547
+ if (this.slides[index].slide == null) {
6548
+ const slideApi = new SlideApi$1({
6549
+ slideApiDeps: new SlideApiDepsMultiSlideMode(this.config.sdkApi, this.slider),
6550
+ slideWrapper: slideElement,
6551
+ viewport: this.config.viewport,
6552
+ userResizeHandler: this.config.userResizeHandler,
6553
+ slideRatio: this.config.slideRatio,
6554
+ isFullscreen: this.config.isFullscreen,
6555
+ getViewportWidth: this.config.getViewportWidth,
6556
+ getViewportHeight: this.config.getViewportHeight,
6557
+ overlappingActionBarHeight: this.config.overlappingActionBarHeight,
6558
+ separateUserAndAppPause: this.config.separateUserAndAppPause,
6559
+ root: this.config.root,
6560
+ index,
6561
+ getSdkClientVariables: this.getSdkClientVariables,
6562
+ });
6563
+ slideApi.onUpdateSizeMetrics(this.sizeMetrics);
6564
+ this.slides[index].slide = slideApi;
6565
+ // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6566
+ // пока вызов убран из за того что init жестко завязан на single slide mode
6567
+ this.activeSlide = this.slides[index].slide;
6568
+ return this.slides[index].slide.showSlide().then(_ => ({ moveToIndex: index }));
6569
+ }
6570
+ else {
6571
+ // quot - // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6572
+ // // пока вызов убран из за того что init жестко завязан на single slide mode
6573
+ // из-за того что перед показом нет приватного вызова SlideApi::_init пока что нужно руками вызывать
6574
+ // slide.activeLayer.timeline.triggerSlideLoadState();
6575
+ // для того чтобы запустить TIMELINE_ACTION.BEFORE_START что нужно для таймлайна слайдера
6576
+ // todo убрать в случае если будем вызывать new SlideApi перед каждым показом слайда
6577
+ this.slides[index].slide.activeLayer.timeline.triggerSlideLoadState();
6578
+ }
6579
+ this.activeSlide = this.slides[index].slide;
6580
+ // TODO handle moveToIndex
6581
+ // return resolve or reject with reason
6582
+ // TODO для виджета квест нужно при каждом показе слайда инициализировать виджет???
6583
+ // пока вызов убран из за того что init жестко завязан на single slide mode
6584
+ // return this.slides[index].slide.showSlide().then(_ => ({ moveToIndex: index }));
6585
+ return Promise.resolve({ moveToIndex: index });
6586
+ // вызываем здесь cardLoadingState - loading
6587
+ // новый cb - onSlideShowError - там вызов cardLoadingState error - через cardLoadingStateManager
6588
+ // в onShowSlide- cardLoadingState load done
6589
+ // внутри слайдера - обрабатываем moveToIndex
6590
+ };
6591
+ const onBeforeLoadSlide = index => {
6592
+ this.cardLoadingStateController.onSetLoadStartState();
6593
+ };
6594
+ const onSlideLoadingError = (index, reason) => {
6595
+ this.cardLoadingStateController.onSetLoadErrorState(reason);
6596
+ };
6597
+ const onShowSlide = (slide, index) => {
6598
+ this.cardLoadingStateController.onSetLoadEndState();
6599
+ this.sdkApi.emitEvent("showSlide", { cardId: this.slides[index]?.slide?.slide.cardId ?? 0, index });
6600
+ // if (index === 0) {
6601
+ // this.activeSlide = slideApi;
6602
+ // }
6603
+ // const { result, cardId, slideIndex, reason } = await slideApi.showSlide();
6604
+ // if (index === 0) {
6605
+ // if (result) {
6606
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADED);
6607
+ // this.sdkApi.emitEvent("showSlide", { cardId: this.activeSlide.slide.cardId, index });
6608
+ // } else {
6609
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADING, reason);
6610
+ // }
6611
+ // }
6612
+ //
6613
+ // onShowActiveCardResolver({ cardId, slideIndex });
6614
+ };
6615
+ const onSlideLeft = (slide, index) => {
6616
+ this.sdkApi.emitEvent("slideLeft", { cardId: this.slides[index]?.slide?.slide.cardId ?? 0, index });
6617
+ };
6618
+ const slideRender = ({ content, canMediaMount }, index, onBeforeShowSlideDuringMounting) => {
6619
+ const slideWrapper = document.createElement("div");
6620
+ slideWrapper.classList.add("narrative-slide-wrapper");
6621
+ slideWrapper.classList.add("stories-viewer");
6622
+ const slideOffset = document.createElement("div");
6623
+ slideOffset.classList.add("narrative-slide-offset");
6624
+ const slideBoxPrerender = document.createElement("div");
6625
+ slideBoxPrerender.classList.add("narrative-slide-box");
6626
+ slideBoxPrerender.classList.add("narrative-slide-box-prerender");
6627
+ const slideBoxRendered = document.createElement("div");
6628
+ slideBoxRendered.classList.add("narrative-slide-box");
6629
+ slideBoxRendered.classList.add("narrative-slide-box-rendered");
6630
+ const style = document.createElement("style");
6631
+ if (this.config.nonce != null) {
6632
+ style.nonce = this.config.nonce;
6633
+ }
6634
+ const paddingTop = `${String(100 / this.config.slideRatio)}%`;
6635
+ // .narrative-slide-box {
6636
+ // padding: <?= $slideRatioPadding ?> 0 0 0;
6637
+ // }
6638
+ // style.sheet?.insertRule(`.narrative-slide-box {padding: ${paddingTop} 0 0 0;`);
6639
+ slideBoxRendered.style.padding = `${paddingTop} 0 0 0`;
6640
+ slideBoxPrerender.style.padding = `${paddingTop} 0 0 0`;
6641
+ // slideBoxPrerender.innerHTML = card;
6642
+ // extract and mount solid or gradient bg color (w/o bg image)
6643
+ onBeforeShowSlideDuringMounting.then(callback => {
6644
+ callback(canMediaMount.then(() => {
6645
+ // mount slide media content (after cache is ready event)
6646
+ slideBoxPrerender.innerHTML = content;
6647
+ // create slideApi
6648
+ // call init, init should return moveToIndex
6649
+ return onBeforeShowSlide(slideWrapper, index);
6650
+ }));
6651
+ });
6652
+ slideOffset.appendChild(slideBoxPrerender);
6653
+ slideOffset.appendChild(slideBoxRendered);
6654
+ slideWrapper.appendChild(slideOffset);
6655
+ slideWrapper.appendChild(style);
6656
+ return slideWrapper;
6657
+ };
6658
+ new Promise(resolve => {
6659
+ });
6660
+ // onContentMounted
6661
+ const onSlideMounted = async (slideElement, index) => {
6662
+ // if (index === 0) {
6663
+ // this.activeSlide = slideApi;
6664
+ // }
6665
+ //
6666
+ // const { result, cardId, slideIndex, reason } = await slideApi.showSlide();
6667
+ //
6668
+ //
6669
+ // if (index === 0) {
6670
+ // if (result) {
6671
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADED);
6672
+ // this.sdkApi.emitEvent("showSlide", { cardId: this.activeSlide.slide.cardId, index });
6673
+ // } else {
6674
+ // this.sdkApi.onCardLoadingStateChange(CARD_LOADING_STATE.LOADING, reason);
6675
+ // }
6676
+ // }
6677
+ //
6678
+ // onShowActiveCardResolver({ cardId, slideIndex });
6679
+ };
6680
+ if (this.slider != null) {
6681
+ this.slider.destroy();
6682
+ }
6683
+ this.slider = new Slider({
6684
+ root: this.config.root,
6685
+ slides: this.slides.map(({ content, resourcesReadyPromise }) => ({
6686
+ content,
6687
+ canMediaMount: resourcesReadyPromise,
6688
+ })),
6689
+ nonce: this.config.nonce,
6690
+ navbarAppearance: cardAppearance.navbar ?? {},
6691
+ slideRender,
6692
+ onSlideMounted,
6693
+ onBeforeShowSlide,
6694
+ onBeforeLoadSlide,
6695
+ onSlideLoadingError,
6696
+ onShowSlide,
6697
+ onSlideLeft,
6698
+ getLayoutDirection: () => this.layoutDirection,
6699
+ onSlideTimerEnd: () => this.activeSlide.slideTimerEnd(),
6700
+ onSlideStart: () => {
6701
+ // return Promise.resolve({currentTime: 0});
6702
+ this.cardLoadingStateController.onSetLoadEndState();
6703
+ return this.activeSlide.slideStart({ muted: true });
6704
+ },
6705
+ onSlideStop: () => this.activeSlide.slideStop({ prepareForRestart: 1 /* ON_SLIDE_STOP_PREPARE_FOR_RESTART.PREPARE */ }),
6706
+ onSlideDataWaiting: () => this.cardLoadingStateController.onSetLoadStartState(),
6707
+ onSlideDataResume: () => this.cardLoadingStateController.onSetLoadEndState(),
6708
+ onSlideDataError: () => this.cardLoadingStateController.onSetLoadEndState(),
6709
+ });
6710
+ await this.slider.showByIndex(index);
6711
+ // return await onShowActiveCard;
6712
+ }
6713
+ handleBackpress() {
6714
+ this.activeSlide.handleBackpress();
6715
+ }
6716
+ get layoutService() {
6717
+ return container.get({ identifier: "LayoutService" });
6718
+ }
6719
+ getLocalData() {
6720
+ return this.sdkApi.getCardLocalData();
6721
+ }
6722
+ async slideStart(config) {
6723
+ return this.activeSlide.slideStart(config);
6724
+ }
6725
+ async slideRestart(config) {
6726
+ return this.activeSlide.slideRestart(config);
6727
+ }
6728
+ async slideUserPause() {
6729
+ return this.activeSlide.slideUserPause();
6730
+ }
6731
+ async slideUserResume() {
6732
+ return this.activeSlide.slideUserResume();
6733
+ }
6734
+ /**
6735
+ * Call on app gone background
6736
+ */
6737
+ async slideAppPause() {
6738
+ return this.activeSlide.slideAppPause();
6739
+ }
6740
+ /**
6741
+ * Call on app gone foreground after a background
6742
+ */
6743
+ async slideAppResume() {
6744
+ return this.activeSlide.slideAppResume();
6745
+ }
6746
+ async slideStop(options) {
6747
+ return this.activeSlide.slideStop(options);
6748
+ }
6749
+ slideTimerEnd() {
6750
+ this.activeSlide.slideTimerEnd();
6751
+ }
6752
+ enableAudio() {
6753
+ this.activeSlide.enableAudio();
6754
+ }
6755
+ disableAudio() {
6756
+ this.activeSlide.disableAudio();
6757
+ }
6758
+ get isStopped() {
6759
+ return this.activeSlide.isStopped;
6760
+ }
6761
+ afterStartInitQueuePush(cb) {
6762
+ return this.activeSlide.afterStartInitQueuePush(cb);
6763
+ }
6764
+ afterAppResumeQueuePush(cb) {
6765
+ return this.activeSlide.afterAppResumeQueuePush(cb);
6766
+ }
6767
+ get activeLayer() {
6768
+ return this.activeSlide.slide.activeLayer;
6769
+ }
6770
+ get slide() {
6771
+ return this.activeSlide.slide;
6772
+ }
6773
+ showLayer(index) {
6774
+ this.activeSlide.showLayer(index);
6775
+ }
6776
+ slideClickHandler(targetElement, navigationDirection) {
6777
+ const result = this.activeSlide.slideClickHandler(targetElement, navigationDirection);
6778
+ // todo make via strategy pattern, singleSlide and multiSlide impl
6779
+ if (this.slidesMode === 1 /* SLIDES_MODE.MULTIPLE */ && result.canClickNext) {
6780
+ result.canClickNext = false; // handle nav click via CardsSlider, not via SDK
6781
+ const currentIndex = this.activeSlide.index;
6782
+ /**
6783
+ * business logic - avoid action on side slides click
6784
+ */
6785
+ if (currentIndex === 0 && navigationDirection === "backward") {
6786
+ return result;
6787
+ }
6788
+ if (currentIndex === this.slides.length - 1 && navigationDirection === "forward") {
6789
+ return result;
6790
+ }
6791
+ let index = navigationDirection === "forward" ? currentIndex + 1 : currentIndex - 1;
6792
+ if (index >= this.slides.length) {
6793
+ index = 0;
6794
+ }
6795
+ else if (index < 0) {
6796
+ index = this.slides.length - 1;
6797
+ }
6798
+ this.slider.showByIndex(index).then(index => {
6799
+ if (currentIndex === index)
6800
+ return;
6801
+ this.activeSlide = this.slides[index].slide;
6802
+ });
6803
+ }
6804
+ return result;
6805
+ }
6806
+ slideSwipeUpHandler() {
6807
+ return this.activeSlide.slideSwipeUpHandler();
6808
+ }
6809
+ setTextInputResult(id, text) {
6810
+ this.activeSlide.setTextInputResult(id, text);
6811
+ }
6812
+ setShareComplete(id, isSuccess) {
6813
+ this.activeSlide.setShareComplete(id, isSuccess);
6814
+ }
6815
+ setWidgetGoodsComplete(elementId) {
6816
+ this.activeSlide.setWidgetGoodsComplete(elementId);
6817
+ }
6818
+ _sdkClientVariables = {};
6819
+ getSdkClientVariables() {
6820
+ return this._sdkClientVariables;
6821
+ }
6822
+ setSdkClientVariables(variables) {
6823
+ this._sdkClientVariables = variables;
6824
+ }
6825
+ setSlideInCacheStatus(index, status) {
6826
+ if (this.slides[index] != null && this.slides[index].resourcesReadyPromisesResolver != null) {
6827
+ if (status === 1 /* SLIDE_IN_CACHE_STATUS.SUCCESS */) {
6828
+ this.slides[index].resourcesReadyPromisesResolver.resolve();
6829
+ }
6830
+ else {
6831
+ this.slides[index].resourcesReadyPromisesResolver.reject();
6832
+ }
6833
+ }
6834
+ else {
6835
+ // for call setSlideInCacheStatus before showSlides
6836
+ this.slides[index] = {
6837
+ content: "",
6838
+ resourcesReadyPromise: Promise.resolve(),
6839
+ };
6840
+ }
6841
+ }
6842
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
6843
+ sdkApi: SDKApi;
6844
+ slideWrapper: HTMLElement;
6845
+ viewport: Window;
6846
+ userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
6847
+ slideRatio: number;
6848
+ isFullscreen: boolean;
6849
+ slideLoadedCb?: (data: { cardId: number; slideIndex: number; result: boolean; reason?: string }) => void;
6850
+ getViewportWidth: () => number;
6851
+ getViewportHeight: () => number;
6852
+ overlappingActionBarHeight?: number;
6853
+ separateUserAndAppPause: boolean;
6854
+ root: HTMLElement;
6855
+ nonce?: string;
6856
+ useSdkCacheForMultislideMode: boolean;
6857
+ }`]; }
6858
+ }
6859
+
5067
6860
  const slideApiPeerDeps = {};
5068
6861
  const createSlideWrapper = ({ slideBoxRatio, nonce }) => {
5069
6862
  const slideWrapper = document.createElement("div");
@@ -5094,7 +6887,7 @@ const createSlideWrapper = ({ slideBoxRatio, nonce }) => {
5094
6887
  slideWrapper.appendChild(style);
5095
6888
  return slideWrapper;
5096
6889
  };
5097
- class SlideApi extends SlideApi$1 {
6890
+ class SlideApi extends CardApi {
5098
6891
  root;
5099
6892
  slideWrapper;
5100
6893
  constructor(_sdkInterface, config) {
@@ -5112,6 +6905,9 @@ class SlideApi extends SlideApi$1 {
5112
6905
  getViewportHeight: () => slideWrapper.clientHeight,
5113
6906
  overlappingActionBarHeight: config.overlappingActionBarHeight,
5114
6907
  separateUserAndAppPause: true,
6908
+ root: config.root,
6909
+ nonce: config.nonce,
6910
+ useSdkCacheForMultislideMode: config.useSdkCacheForMultislideMode,
5115
6911
  });
5116
6912
  this.root = config.root;
5117
6913
  this.slideWrapper = slideWrapper;
@@ -5132,6 +6928,7 @@ class SlideApi extends SlideApi$1 {
5132
6928
  userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5133
6929
  VODPlayer?: typeof VODPlayer;
5134
6930
  overlappingActionBarHeight?: number;
6931
+ useSdkCacheForMultislideMode: boolean;
5135
6932
  }`]; }
5136
6933
  }
5137
6934
 
@@ -14561,7 +16358,7 @@ class WidgetBase {
14561
16358
  this.submitButtonView = this.submitButtonAnimatedView.querySelector(".submit-button-view");
14562
16359
  }
14563
16360
  }
14564
- this.savedData = this.widgetDeps.sdkApi.getCardServerData(this.cardId);
16361
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
14565
16362
  this.localData = extend({}, this.savedData ?? {}, this.options.localData ?? {});
14566
16363
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
14567
16364
  ++WidgetBase.widgetIndex;
@@ -14583,7 +16380,7 @@ class WidgetBase {
14583
16380
  * @param localData
14584
16381
  */
14585
16382
  onRefreshUserData(localData) {
14586
- this.savedData = this.widgetDeps.sdkApi.getCardServerData(this.cardId);
16383
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
14587
16384
  this.localData = extend({}, this.savedData ?? {}, localData);
14588
16385
  }
14589
16386
  onStart() {
@@ -14633,13 +16430,13 @@ class WidgetBase {
14633
16430
  static get widgetsService() {
14634
16431
  return container.get({ identifier: "WidgetsService" });
14635
16432
  }
14636
- static getLocalData(sdkApi) {
14637
- return sdkApi.getCardLocalData();
16433
+ static getLocalData(slideApiDeps) {
16434
+ return slideApiDeps.getCardLocalData();
14638
16435
  }
14639
16436
  getLocalData() {
14640
- return this.constructor.getLocalData(this.widgetDeps.sdkApi);
16437
+ return this.constructor.getLocalData(this.widgetDeps.slideApiDeps);
14641
16438
  }
14642
- static setLocalData(sdkApi, keyValue, sendToServer, syncWithRuntimeLocalData) {
16439
+ static setLocalData(slideApiDeps, keyValue, sendToServer, syncWithRuntimeLocalData) {
14643
16440
  // push json object as string
14644
16441
  if (sendToServer === undefined) {
14645
16442
  sendToServer = true;
@@ -14654,20 +16451,20 @@ class WidgetBase {
14654
16451
  syncWithRuntimeLocalData = Boolean(syncWithRuntimeLocalData);
14655
16452
  }
14656
16453
  if (syncWithRuntimeLocalData) {
14657
- this.getLocalData(sdkApi).then(localData => {
16454
+ this.getLocalData(slideApiDeps).then(localData => {
14658
16455
  // 1 - old values, 2 - new values
14659
16456
  keyValue = extend({}, localData, keyValue);
14660
16457
  // todo make async via promise or async
14661
- sdkApi.setCardLocalData(keyValue, sendToServer);
16458
+ slideApiDeps.setCardLocalData(keyValue, sendToServer);
14662
16459
  });
14663
16460
  }
14664
16461
  else {
14665
16462
  // todo make async via promise or async
14666
- sdkApi.setCardLocalData(keyValue, sendToServer);
16463
+ slideApiDeps.setCardLocalData(keyValue, sendToServer);
14667
16464
  }
14668
16465
  }
14669
16466
  setLocalData(keyValue, sendToServer, syncWithRuntimeLocalData) {
14670
- return this.constructor.setLocalData(this.widgetDeps.sdkApi, keyValue, sendToServer, syncWithRuntimeLocalData);
16467
+ return this.constructor.setLocalData(this.widgetDeps.slideApiDeps, keyValue, sendToServer, syncWithRuntimeLocalData);
14671
16468
  }
14672
16469
  get statisticEventBaseFieldsShortForm() {
14673
16470
  return WidgetBase.getStatisticEventBaseFieldsShortForm(this.cardId, this.cardType, this.slideIndex);
@@ -14698,11 +16495,11 @@ class WidgetBase {
14698
16495
  }
14699
16496
  return data;
14700
16497
  }
14701
- static sendStatisticEventToApp(sdkApi, name, data, devPayload, options) {
14702
- sendStatisticEventToApp(sdkApi, name, data, devPayload, options);
16498
+ static sendStatisticEventToApp(slideApiDeps, name, data, devPayload, options) {
16499
+ sendStatisticEventToApp(slideApiDeps, name, data, devPayload, options);
14703
16500
  }
14704
16501
  sendStatisticEventToApp(name, data, devPayload, options) {
14705
- this.constructor.sendStatisticEventToApp(this.widgetDeps.sdkApi, name, data, devPayload, options);
16502
+ this.constructor.sendStatisticEventToApp(this.widgetDeps.slideApiDeps, name, data, devPayload, options);
14706
16503
  }
14707
16504
  onWidgetComplete() {
14708
16505
  this._widgetCallbacks.onWidgetComplete(this.cardId, this.slideIndex);
@@ -14714,14 +16511,14 @@ class WidgetBase {
14714
16511
  this._widgetCallbacks.onWidgetRequireResumeUI(this.cardId, this.slideIndex);
14715
16512
  }
14716
16513
  _showLayer(layers, selectIndex, withStatEvent = false) {
14717
- if (this.widgetDeps.sdkApi.isExistsShowLayer()) {
14718
- this.widgetDeps.sdkApi.showLayer(selectIndex);
16514
+ if (this.widgetDeps.slideApiDeps.isExistsShowLayer()) {
16515
+ this.widgetDeps.slideApiDeps.showLayer(selectIndex);
14719
16516
  }
14720
16517
  else {
14721
16518
  forEach(layers, (layer, index) => {
14722
16519
  if (index === selectIndex) {
14723
16520
  layer.classList.remove("hidden");
14724
- this.widgetDeps.sdkApi.cardAnimation?.start(layer);
16521
+ this.widgetDeps.slideApiDeps.cardAnimation?.start(layer);
14725
16522
  }
14726
16523
  else {
14727
16524
  layer.classList.add("hidden");
@@ -14871,7 +16668,7 @@ class WidgetBarcode extends WidgetBase {
14871
16668
  }
14872
16669
  catch (e) {
14873
16670
  if (this.msgBarcodeRenderError) {
14874
- this.widgetDeps.sdkApi.showToast(this.msgBarcodeRenderError);
16671
+ this.widgetDeps.slideApiDeps.showToast(this.msgBarcodeRenderError);
14875
16672
  }
14876
16673
  console.error(e);
14877
16674
  }
@@ -14934,7 +16731,7 @@ class WidgetBarcode extends WidgetBase {
14934
16731
  };
14935
16732
  const profileKey = "fetch-promo-code";
14936
16733
  Promise.all([
14937
- this.widgetDeps.sdkApi.sendApiRequest(path, "POST", null, headers, null, profileKey),
16734
+ this.widgetDeps.slideApiDeps.sendApiRequest(path, "POST", null, headers, null, profileKey),
14938
16735
  new Promise(function (t, e) {
14939
16736
  return setTimeout(t, 300);
14940
16737
  }),
@@ -14962,14 +16759,14 @@ class WidgetBarcode extends WidgetBase {
14962
16759
  this.setLocalData(this.localData, true);
14963
16760
  }
14964
16761
  else {
14965
- this.msgNoMoreCodes && this.widgetDeps.sdkApi.showToast(this.msgNoMoreCodes);
16762
+ this.msgNoMoreCodes && this.widgetDeps.slideApiDeps.showToast(this.msgNoMoreCodes);
14966
16763
  }
14967
16764
  }
14968
16765
  else if (status === 12163 || status === 12002) {
14969
- this.msgNetworkError && this.widgetDeps.sdkApi.showToast(this.msgNetworkError);
16766
+ this.msgNetworkError && this.widgetDeps.slideApiDeps.showToast(this.msgNetworkError);
14970
16767
  }
14971
16768
  else {
14972
- this.msgServiceError && this.widgetDeps.sdkApi.showToast(this.msgServiceError);
16769
+ this.msgServiceError && this.widgetDeps.slideApiDeps.showToast(this.msgServiceError);
14973
16770
  }
14974
16771
  if (!success) {
14975
16772
  this.state = 3;
@@ -15015,13 +16812,13 @@ class WidgetBarcode extends WidgetBase {
15015
16812
  }
15016
16813
  });
15017
16814
  if (this.copiedText) {
15018
- this.widgetDeps.sdkApi.showToast(this.copiedText);
16815
+ this.widgetDeps.slideApiDeps.showToast(this.copiedText);
15019
16816
  }
15020
16817
  }
15021
16818
  copyToClipboard(element) {
15022
16819
  this._select();
15023
16820
  const textValue = this.clipboardTarget ?? "";
15024
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
16821
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
15025
16822
  this.completeWidget();
15026
16823
  this._statEventCopyClick(textValue);
15027
16824
  }
@@ -15193,7 +16990,7 @@ class WidgetCopy extends WidgetBase {
15193
16990
  };
15194
16991
  const profileKey = "fetch-promo-code";
15195
16992
  Promise.all([
15196
- this.widgetDeps.sdkApi.sendApiRequest(path, "POST", null, headers, null, profileKey),
16993
+ this.widgetDeps.slideApiDeps.sendApiRequest(path, "POST", null, headers, null, profileKey),
15197
16994
  new Promise(function (t, e) {
15198
16995
  return setTimeout(t, 300);
15199
16996
  }),
@@ -15220,14 +17017,14 @@ class WidgetCopy extends WidgetBase {
15220
17017
  this.setLocalData(this.localData, true);
15221
17018
  }
15222
17019
  else {
15223
- this.msgNoMoreCodes && this.widgetDeps.sdkApi.showToast(this.msgNoMoreCodes);
17020
+ this.msgNoMoreCodes && this.widgetDeps.slideApiDeps.showToast(this.msgNoMoreCodes);
15224
17021
  }
15225
17022
  }
15226
17023
  else if (status === 12163 || status === 12002) {
15227
- this.msgNetworkError && this.widgetDeps.sdkApi.showToast(this.msgNetworkError);
17024
+ this.msgNetworkError && this.widgetDeps.slideApiDeps.showToast(this.msgNetworkError);
15228
17025
  }
15229
17026
  else {
15230
- this.msgServiceError && this.widgetDeps.sdkApi.showToast(this.msgServiceError);
17027
+ this.msgServiceError && this.widgetDeps.slideApiDeps.showToast(this.msgServiceError);
15231
17028
  }
15232
17029
  if (!success) {
15233
17030
  this.state = 3;
@@ -15279,7 +17076,7 @@ class WidgetCopy extends WidgetBase {
15279
17076
  copyToClipboard(element) {
15280
17077
  this._select();
15281
17078
  const textValue = this.clipboardTarget ?? "";
15282
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
17079
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
15283
17080
  this.completeWidget();
15284
17081
  this._statEventCopyClick(textValue);
15285
17082
  }
@@ -15421,12 +17218,12 @@ class WidgetDataInput extends WidgetBase {
15421
17218
  return true;
15422
17219
  }
15423
17220
  this.elementRect = this.element.getBoundingClientRect();
15424
- if (this.widgetDeps.sdkApi.isAndroid || this.widgetDeps.sdkApi.isWeb) {
17221
+ if (this.widgetDeps.slideApiDeps.isAndroid || this.widgetDeps.slideApiDeps.isWeb) {
15425
17222
  this.slide.classList.add("blured");
15426
17223
  }
15427
17224
  this.slide.classList.add("data-input-editing");
15428
17225
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
15429
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17226
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
15430
17227
  const data = JSON.parse(dataString);
15431
17228
  data.size = getElementBounding(this.env, this.elementRect);
15432
17229
  if (!this.disableTimer) {
@@ -15447,7 +17244,7 @@ class WidgetDataInput extends WidgetBase {
15447
17244
  catch (e) {
15448
17245
  console.error(e);
15449
17246
  }
15450
- this.widgetDeps.sdkApi.showCardTextInput(this.id, data);
17247
+ this.widgetDeps.slideApiDeps.showCardTextInput(this.id, data);
15451
17248
  this._statEventFocusIn();
15452
17249
  }
15453
17250
  return false;
@@ -15746,7 +17543,7 @@ class WidgetDateCountdown extends WidgetBase {
15746
17543
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Partial`, `WidgetCallbacks`, `WidgetDeps`]; }
15747
17544
  }
15748
17545
 
15749
- const displaySlide = function (slides, localData, sdkApi) {
17546
+ const displaySlide = function (slides, localData, slideApiDeps) {
15750
17547
  const multiSlideItem = slides[0];
15751
17548
  let cardId = undefined;
15752
17549
  let cardType = 1 /* CARD_TYPE.STORY */;
@@ -15811,7 +17608,7 @@ const displaySlide = function (slides, localData, sdkApi) {
15811
17608
  if (slides.length > 0) {
15812
17609
  var slide = slides[0];
15813
17610
  slide.classList.remove("hidden");
15814
- sdkApi.cardAnimation?.start(slide);
17611
+ slideApiDeps.cardAnimation?.start(slide);
15815
17612
  return;
15816
17613
  }
15817
17614
  score = 0;
@@ -15840,19 +17637,19 @@ const displaySlide = function (slides, localData, sdkApi) {
15840
17637
  if (index === selectedIndex) {
15841
17638
  slide.classList.remove("hidden");
15842
17639
  undefinedResult = false;
15843
- sdkApi.cardAnimation?.start(slide);
15844
- _sendStatEvent(sdkApi, cardId, cardType, slideIndex, selectedIndex);
17640
+ slideApiDeps.cardAnimation?.start(slide);
17641
+ _sendStatEvent(slideApiDeps, cardId, cardType, slideIndex, selectedIndex);
15845
17642
  }
15846
17643
  });
15847
17644
  }
15848
17645
  if (undefinedResult) {
15849
17646
  console.warn("undefinedResult layer index");
15850
- sdkApi.showLayer(0);
17647
+ slideApiDeps.showLayer(0);
15851
17648
  }
15852
17649
  };
15853
- const _sendStatEvent = function (sdkApi, cardId, cardType, slideIndex, layerIndex) {
17650
+ const _sendStatEvent = function (slideApiDeps, cardId, cardType, slideIndex, layerIndex) {
15854
17651
  try {
15855
- WidgetBase.sendStatisticEventToApp(sdkApi, "layout-show", {
17652
+ WidgetBase.sendStatisticEventToApp(slideApiDeps, "layout-show", {
15856
17653
  ...WidgetBase.getStatisticEventBaseFieldsShortForm(cardId, cardType, slideIndex),
15857
17654
  li: layerIndex,
15858
17655
  }, {
@@ -15867,7 +17664,7 @@ const _sendStatEvent = function (sdkApi, cardId, cardType, slideIndex, layerInde
15867
17664
  class WidgetMultiSlide {
15868
17665
  static api = {
15869
17666
  init: function (slides, localData, widgetDeps) {
15870
- displaySlide(slides, localData, widgetDeps.sdkApi);
17667
+ displaySlide(slides, localData, widgetDeps.slideApiDeps);
15871
17668
  },
15872
17669
  };
15873
17670
  }
@@ -16035,13 +17832,13 @@ class WidgetPoll extends WidgetBase {
16035
17832
  if (index !== -1) {
16036
17833
  this.elementRect = this.element.getBoundingClientRect();
16037
17834
  if (this.getUseResponseOnFirstButton && index === 0) {
16038
- if (this.widgetDeps.sdkApi.isAndroid) {
17835
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
16039
17836
  this.slide.classList.add("blured");
16040
17837
  }
16041
17838
  this.slide.classList.add("data-input-editing");
16042
17839
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
16043
17840
  this.selectedVariant = index;
16044
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17841
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
16045
17842
  const data = JSON.parse(dataString);
16046
17843
  data.size = getElementBounding(this.env, this.elementRect);
16047
17844
  if (!this.disableTimer) {
@@ -16063,19 +17860,19 @@ class WidgetPoll extends WidgetBase {
16063
17860
  catch (e) {
16064
17861
  console.error(e);
16065
17862
  }
16066
- this.widgetDeps.sdkApi.showCardTextInput(`${this.id}_first`, data);
17863
+ this.widgetDeps.slideApiDeps.showCardTextInput(`${this.id}_first`, data);
16067
17864
  }
16068
17865
  this._statEventPollAnswer();
16069
17866
  return false;
16070
17867
  }
16071
17868
  else if (this.getUseResponseOnSecondButton && index === 1) {
16072
- if (this.widgetDeps.sdkApi.isAndroid) {
17869
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
16073
17870
  this.slide.classList.add("blured");
16074
17871
  }
16075
17872
  this.slide.classList.add("data-input-editing");
16076
17873
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
16077
17874
  this.selectedVariant = index;
16078
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
17875
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
16079
17876
  const data = JSON.parse(dataString);
16080
17877
  data.size = getElementBounding(this.env, this.elementRect);
16081
17878
  if (!this.disableTimer) {
@@ -16096,7 +17893,7 @@ class WidgetPoll extends WidgetBase {
16096
17893
  catch (e) {
16097
17894
  console.error(e);
16098
17895
  }
16099
- this.widgetDeps.sdkApi.showCardTextInput(`${this.id}_second`, data);
17896
+ this.widgetDeps.slideApiDeps.showCardTextInput(`${this.id}_second`, data);
16100
17897
  }
16101
17898
  this._statEventPollAnswer();
16102
17899
  return false;
@@ -16139,7 +17936,7 @@ class WidgetPoll extends WidgetBase {
16139
17936
  displayPercents(selectedVariantIndex, filled = false) {
16140
17937
  let pollAllocation = [0, 0];
16141
17938
  let pollAllocationTs = undefined;
16142
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
17939
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
16143
17940
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
16144
17941
  pollAllocation = sharedData[this.elementId];
16145
17942
  if (isObject$1(sharedData[this.elementId])) {
@@ -17320,7 +19117,7 @@ class WidgetProducts extends WidgetBase {
17320
19117
  };
17321
19118
  const profileKey = "fetch-products";
17322
19119
  try {
17323
- const response = await this.widgetDeps.sdkApi.sendApiRequest(path, "GET", null, headers, null, profileKey);
19120
+ const response = await this.widgetDeps.slideApiDeps.sendApiRequest(path, "GET", null, headers, null, profileKey);
17324
19121
  // console.log({response});
17325
19122
  const status = response.status;
17326
19123
  if (status === 200 || status === 201) {
@@ -17446,15 +19243,15 @@ class WidgetProducts extends WidgetBase {
17446
19243
  this.isOpen = true;
17447
19244
  // prevent next slide navigation gesture
17448
19245
  this.isClickCapturedByWidget = true;
17449
- this.widgetDeps.sdkApi.disableHorizontalSwipeGesture();
17450
- this.widgetDeps.sdkApi.disableVerticalSwipeGesture();
17451
- this.widgetDeps.sdkApi.disableBackpress();
19246
+ this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
19247
+ this.widgetDeps.slideApiDeps.disableVerticalSwipeGesture();
19248
+ this.widgetDeps.slideApiDeps.disableBackpress();
17452
19249
  this._statEventWidgetOpen(this.currentModels);
17453
19250
  this.initSwipeGestureDetector();
17454
19251
  }
17455
19252
  else {
17456
19253
  if (result.message) {
17457
- this.widgetDeps.sdkApi.showToast(result.message);
19254
+ this.widgetDeps.slideApiDeps.showToast(result.message);
17458
19255
  }
17459
19256
  }
17460
19257
  this.element.classList.remove("loader");
@@ -17466,13 +19263,13 @@ class WidgetProducts extends WidgetBase {
17466
19263
  this.productsView?.classList.add("ias-products-container-view--hidden");
17467
19264
  this.element.classList.remove("hidden");
17468
19265
  this.isClickCapturedByWidget = false;
17469
- this.widgetDeps.sdkApi.enableHorizontalSwipeGesture();
19266
+ this.widgetDeps.slideApiDeps.enableHorizontalSwipeGesture();
17470
19267
  if (this.swipeGestureDetector != null) {
17471
19268
  this.swipeGestureDetector.destroy();
17472
19269
  this.swipeGestureDetector = null;
17473
19270
  }
17474
- this.widgetDeps.sdkApi.enableVerticalSwipeGesture();
17475
- this.widgetDeps.sdkApi.enableBackpress();
19271
+ this.widgetDeps.slideApiDeps.enableVerticalSwipeGesture();
19272
+ this.widgetDeps.slideApiDeps.enableBackpress();
17476
19273
  const onClosed = () => {
17477
19274
  this.productsView?.removeEventListener("animationend", onClosed);
17478
19275
  this.productsView?.parentElement?.removeChild(this.productsView);
@@ -17532,7 +19329,7 @@ class WidgetProducts extends WidgetBase {
17532
19329
  e.preventDefault();
17533
19330
  this._statEventWidgetCardClick(offer);
17534
19331
  if (offer.url) {
17535
- this.widgetDeps.sdkApi.openUrl({ type: "link", link: { type: "url", target: offer.url } });
19332
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target: offer.url } });
17536
19333
  }
17537
19334
  };
17538
19335
  card.appendChild(figure);
@@ -17763,10 +19560,10 @@ class WidgetQuest extends WidgetBase {
17763
19560
  super.onRefreshUserData(localData);
17764
19561
  }
17765
19562
  setCardSessionValue(name, value) {
17766
- this.widgetDeps.sdkApi.setCardSessionValue(this.element, name, value);
19563
+ this.widgetDeps.slideApiDeps.setCardSessionValue(this.element, name, value);
17767
19564
  }
17768
19565
  getCardSessionValue(name) {
17769
- return this.widgetDeps.sdkApi.getCardSessionValue(this.element, name);
19566
+ return this.widgetDeps.slideApiDeps.getCardSessionValue(this.element, name);
17770
19567
  }
17771
19568
  init() {
17772
19569
  if (this.localData) {
@@ -17785,8 +19582,8 @@ class WidgetQuest extends WidgetBase {
17785
19582
  // global flag - был сделан переход на нужный слайд, больше не нужно повторять за эту сессию
17786
19583
  // perform showStorySlide with lastSlideIdx only on story open first time (not on second slide, etc)
17787
19584
  this.setCardSessionValue("__storyQuestSlideChanged", "1");
17788
- if (this.widgetDeps.sdkApi.isExistsShowCardSlide) {
17789
- this.widgetDeps.sdkApi.showCardSlide(lastSlideIdx);
19585
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19586
+ this.widgetDeps.slideApiDeps.showCardSlide(lastSlideIdx);
17790
19587
  return false;
17791
19588
  }
17792
19589
  }
@@ -17797,8 +19594,8 @@ class WidgetQuest extends WidgetBase {
17797
19594
  // если этого слайда нет в роутинге (сработал переход по таймеру в app)
17798
19595
  const routes = this._getRoutes();
17799
19596
  if (routes[0].indexOf(this.slideIndex) === -1 && this.finalSlide) {
17800
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17801
- this.widgetDeps.sdkApi.cardShowNext();
19597
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19598
+ this.widgetDeps.slideApiDeps.cardShowNext();
17802
19599
  return false;
17803
19600
  }
17804
19601
  }
@@ -17844,10 +19641,10 @@ class WidgetQuest extends WidgetBase {
17844
19641
  this._selectAnswer(index, slideIndex);
17845
19642
  this.setLocalData(this.localData, true);
17846
19643
  this.env.setTimeout(() => {
17847
- if (slideIndex >= 0 && slideIndex < this.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19644
+ if (slideIndex >= 0 && slideIndex < this.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
17848
19645
  // global flag - был сделан переход на нужный слайд, больше не нужно повторять за эту сессию
17849
19646
  this.setCardSessionValue("__storyQuestSlideChanged", "1");
17850
- this.widgetDeps.sdkApi.showCardSlide(slideIndex);
19647
+ this.widgetDeps.slideApiDeps.showCardSlide(slideIndex);
17851
19648
  }
17852
19649
  }, 100);
17853
19650
  }
@@ -17919,12 +19716,12 @@ class WidgetQuest extends WidgetBase {
17919
19716
  else {
17920
19717
  // by routing - move back
17921
19718
  moveTo = this._routeMvPtrBack();
17922
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
17923
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19719
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19720
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
17924
19721
  }
17925
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19722
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
17926
19723
  // allow move to start - for broken route history
17927
- this.widgetDeps.sdkApi.showCardSlide(0);
19724
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
17928
19725
  }
17929
19726
  }
17930
19727
  return result;
@@ -17940,8 +19737,8 @@ class WidgetQuest extends WidgetBase {
17940
19737
  if (directionForward) {
17941
19738
  if (this.navigationNextSlide === -1) {
17942
19739
  // this is the final slide - exit from this quest
17943
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17944
- this.widgetDeps.sdkApi.cardShowNext();
19740
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19741
+ this.widgetDeps.slideApiDeps.cardShowNext();
17945
19742
  }
17946
19743
  result.continueDefaultNavigation = false;
17947
19744
  return result;
@@ -17950,11 +19747,11 @@ class WidgetQuest extends WidgetBase {
17950
19747
  if (nextSlideIndex < this.slideCount) {
17951
19748
  this._addNewRouteHistory(nextSlideIndex);
17952
19749
  this.setLocalData(this.localData, true);
17953
- this.widgetDeps.sdkApi.showCardSlide(nextSlideIndex);
19750
+ this.widgetDeps.slideApiDeps.showCardSlide(nextSlideIndex);
17954
19751
  }
17955
19752
  else {
17956
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17957
- this.widgetDeps.sdkApi.cardShowNext();
19753
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19754
+ this.widgetDeps.slideApiDeps.cardShowNext();
17958
19755
  }
17959
19756
  }
17960
19757
  }
@@ -17967,12 +19764,12 @@ class WidgetQuest extends WidgetBase {
17967
19764
  else {
17968
19765
  // by routing - move back
17969
19766
  moveTo = this._routeMvPtrBack();
17970
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
17971
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19767
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19768
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
17972
19769
  }
17973
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19770
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
17974
19771
  // allow move to start - for broken route history
17975
- this.widgetDeps.sdkApi.showCardSlide(0);
19772
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
17976
19773
  }
17977
19774
  }
17978
19775
  }
@@ -17987,11 +19784,11 @@ class WidgetQuest extends WidgetBase {
17987
19784
  if (nextSlideIndex < this.slideCount) {
17988
19785
  this._addNewRouteHistory(nextSlideIndex);
17989
19786
  this.setLocalData(this.localData, true);
17990
- this.widgetDeps.sdkApi.showCardSlide(nextSlideIndex);
19787
+ this.widgetDeps.slideApiDeps.showCardSlide(nextSlideIndex);
17991
19788
  }
17992
19789
  else {
17993
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
17994
- this.widgetDeps.sdkApi.cardShowNext();
19790
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19791
+ this.widgetDeps.slideApiDeps.cardShowNext();
17995
19792
  }
17996
19793
  }
17997
19794
  }
@@ -18004,12 +19801,12 @@ class WidgetQuest extends WidgetBase {
18004
19801
  else {
18005
19802
  // by routing - move back
18006
19803
  moveTo = this._routeMvPtrBack();
18007
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18008
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19804
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19805
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18009
19806
  }
18010
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19807
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18011
19808
  // allow move to start - for broken route history
18012
- this.widgetDeps.sdkApi.showCardSlide(0);
19809
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18013
19810
  }
18014
19811
  }
18015
19812
  }
@@ -18024,20 +19821,20 @@ class WidgetQuest extends WidgetBase {
18024
19821
  // setLocalData(this.localData, true);
18025
19822
  // window._showNarrativeSlide(nextSlideIndex);
18026
19823
  // } else {
18027
- if (this.widgetDeps.sdkApi.isExistsShowNextCard) {
18028
- this.widgetDeps.sdkApi.cardShowNext();
19824
+ if (this.widgetDeps.slideApiDeps.isExistsShowNextCard) {
19825
+ this.widgetDeps.slideApiDeps.cardShowNext();
18029
19826
  }
18030
19827
  // }
18031
19828
  }
18032
19829
  else {
18033
19830
  // by routing - move back
18034
19831
  moveTo = this._routeMvPtrBack();
18035
- if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
18036
- this.widgetDeps.sdkApi.showCardSlide(moveTo);
19832
+ if (moveTo !== false && moveTo >= 0 && moveTo < event.slideCount && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
19833
+ this.widgetDeps.slideApiDeps.showCardSlide(moveTo);
18037
19834
  }
18038
- if (moveTo === false && this.widgetDeps.sdkApi.isExistsShowCardSlide) {
19835
+ if (moveTo === false && this.widgetDeps.slideApiDeps.isExistsShowCardSlide) {
18039
19836
  // allow move to start - for broken route history
18040
- this.widgetDeps.sdkApi.showCardSlide(0);
19837
+ this.widgetDeps.slideApiDeps.showCardSlide(0);
18041
19838
  }
18042
19839
  }
18043
19840
  }
@@ -18827,7 +20624,7 @@ class WidgetRangeSlider extends WidgetBase {
18827
20624
  total_user: 0,
18828
20625
  };
18829
20626
  let answerAllocationTs = undefined;
18830
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
20627
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
18831
20628
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
18832
20629
  answerAllocation = sharedData[this.elementId];
18833
20630
  answerAllocationTs = sharedData.ts;
@@ -18927,7 +20724,7 @@ class WidgetRangeSlider extends WidgetBase {
18927
20724
  }
18928
20725
  e.preventDefault();
18929
20726
  this.isClickCapturedBySlider = true;
18930
- this.widgetDeps.sdkApi.disableHorizontalSwipeGesture();
20727
+ this.widgetDeps.slideApiDeps.disableHorizontalSwipeGesture();
18931
20728
  if (!this.maxHandlePos) {
18932
20729
  this.update(true, false);
18933
20730
  }
@@ -18957,7 +20754,7 @@ class WidgetRangeSlider extends WidgetBase {
18957
20754
  handleEnd(e) {
18958
20755
  this.env.requestAnimationFrame(() => {
18959
20756
  this.isClickCapturedBySlider = false;
18960
- this.widgetDeps.sdkApi.enableHorizontalSwipeGesture();
20757
+ this.widgetDeps.slideApiDeps.enableHorizontalSwipeGesture();
18961
20758
  });
18962
20759
  // e.preventDefault();
18963
20760
  this.widgetDeps.slideRoot.removeEventListener("touchmove", this.handleMove);
@@ -19022,7 +20819,7 @@ class WidgetRangeSlider extends WidgetBase {
19022
20819
  if (this.value !== this.prevSnapValue) {
19023
20820
  this.prevSnapValue = this.value;
19024
20821
  try {
19025
- this.widgetDeps.sdkApi.vibrate(20);
20822
+ this.widgetDeps.slideApiDeps.vibrate(20);
19026
20823
  }
19027
20824
  catch (e) {
19028
20825
  console.error(e);
@@ -19269,12 +21066,12 @@ class WidgetRate extends WidgetBase {
19269
21066
  if (this.showDialogOnLowRate) {
19270
21067
  this.elementRect = this.element.getBoundingClientRect();
19271
21068
  this._selectStar(this.selectedStar, false);
19272
- if (this.widgetDeps.sdkApi.isAndroid) {
21069
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
19273
21070
  this.slide.classList.add("blured");
19274
21071
  }
19275
21072
  this.slide.classList.add("data-input-editing");
19276
21073
  const dataString = this.element.dataset["clientdialogwidgetconfig"];
19277
- if (this.widgetDeps.sdkApi.isExistsShowCardTextInput && dataString) {
21074
+ if (this.widgetDeps.slideApiDeps.isExistsShowCardTextInput && dataString) {
19278
21075
  const data = JSON.parse(dataString);
19279
21076
  data.size = getElementBounding(this.env, this.elementRect);
19280
21077
  if (!this.disableTimer) {
@@ -19296,7 +21093,7 @@ class WidgetRate extends WidgetBase {
19296
21093
  catch (e) {
19297
21094
  console.error(e);
19298
21095
  }
19299
- this.widgetDeps.sdkApi.showCardTextInput(this.id, data);
21096
+ this.widgetDeps.slideApiDeps.showCardTextInput(this.id, data);
19300
21097
  }
19301
21098
  }
19302
21099
  else {
@@ -19308,17 +21105,17 @@ class WidgetRate extends WidgetBase {
19308
21105
  }
19309
21106
  else if (value + 1 >= this.submitToStoresMin && value + 1 <= this.submitToStoresMax) {
19310
21107
  let target = null;
19311
- if (this.widgetDeps.sdkApi.isAndroid) {
21108
+ if (this.widgetDeps.slideApiDeps.isAndroid) {
19312
21109
  target = getTagData(this.element, "androidLink");
19313
21110
  }
19314
- else if (this.widgetDeps.sdkApi.isIOS) {
21111
+ else if (this.widgetDeps.slideApiDeps.isIOS) {
19315
21112
  target = getTagData(this.element, "appleLink");
19316
21113
  }
19317
21114
  this._selectStar(value, true);
19318
21115
  this.completeWidget();
19319
21116
  this._statEventRateUsAnswer("");
19320
21117
  if (this.submitToStores && target) {
19321
- this.widgetDeps.sdkApi.openUrl({ type: "link", link: { type: "url", target } });
21118
+ this.widgetDeps.slideApiDeps.openUrl({ type: "link", link: { type: "url", target } });
19322
21119
  }
19323
21120
  }
19324
21121
  else {
@@ -19467,12 +21264,12 @@ class WidgetShare extends WidgetBase {
19467
21264
  }
19468
21265
  share() {
19469
21266
  if (!this.btnDisabled) {
19470
- if (this.widgetDeps.sdkApi.isExistsShare) {
19471
- if (this.widgetDeps.sdkApi.sdkCanSendShareComplete) {
21267
+ if (this.widgetDeps.slideApiDeps.isExistsShare) {
21268
+ if (this.widgetDeps.slideApiDeps.sdkCanSendShareComplete) {
19472
21269
  this.btnDisabled = true;
19473
21270
  }
19474
21271
  if (this.shareType === "url" || this.shareType === "story") {
19475
- this.widgetDeps.sdkApi.share(this.id, {
21272
+ this.widgetDeps.slideApiDeps.share(this.id, {
19476
21273
  url: this.shareTarget, // sdk old versions
19477
21274
  text: this.shareTarget,
19478
21275
  title: null,
@@ -19480,7 +21277,7 @@ class WidgetShare extends WidgetBase {
19480
21277
  });
19481
21278
  }
19482
21279
  else if (this.shareType === "slide") {
19483
- this.widgetDeps.sdkApi.shareSlideScreenshot(this.id, "[data-element-id='" + this.elementId + "']", this.shareTarget ? this.shareTarget : undefined);
21280
+ this.widgetDeps.slideApiDeps.shareSlideScreenshot(this.id, "[data-element-id='" + this.elementId + "']", this.shareTarget ? this.shareTarget : undefined);
19484
21281
  }
19485
21282
  }
19486
21283
  }
@@ -20086,9 +21883,9 @@ class WidgetTooltip extends WidgetBase {
20086
21883
  copyToClipboard(element) {
20087
21884
  const textValue = this.template1ClipboardTarget ?? "";
20088
21885
  if (textValue) {
20089
- this.widgetDeps.sdkApi.writeToClipboard({ type: "text", textValue });
21886
+ this.widgetDeps.slideApiDeps.writeToClipboard({ type: "text", textValue });
20090
21887
  if (this.template1CopiedText) {
20091
- this.widgetDeps.sdkApi.showToast(this.template1CopiedText);
21888
+ this.widgetDeps.slideApiDeps.showToast(this.template1CopiedText);
20092
21889
  }
20093
21890
  }
20094
21891
  this._statEventWidgetCopyClick(textValue);
@@ -20467,7 +22264,7 @@ class WidgetVote extends WidgetBase {
20467
22264
  // voteAllocation[7]
20468
22265
  let voteAllocation = [];
20469
22266
  let voteAllocationTs = undefined;
20470
- const sharedData = this.widgetDeps.sdkApi.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
22267
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
20471
22268
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
20472
22269
  voteAllocation = sharedData[this.elementId];
20473
22270
  if (isObject$1(sharedData[this.elementId])) {