@inappstory/slide-api 0.1.45 → 0.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1069,10 +1069,10 @@ class EsModuleSdkApi {
1069
1069
  onWidgetRequireResumeUI() {
1070
1070
  return this.sdkBinding.onWidgetRequireResumeUI();
1071
1071
  }
1072
- getCardServerData(cardId) {
1073
- return this.sdkBinding.getCardServerData(cardId);
1072
+ getCardServerData() {
1073
+ return this.sdkBinding.getCardServerData();
1074
1074
  }
1075
- updateCardServerDataLocally(cardId, data) {
1075
+ updateCardServerDataLocally(data) {
1076
1076
  return this.sdkBinding.updateCardServerDataLocally(data);
1077
1077
  }
1078
1078
  showNextSlide(duration) {
@@ -1111,8 +1111,8 @@ class EsModuleSdkApi {
1111
1111
  setCardLocalData(keyValue, sendToServer) {
1112
1112
  this.sdkBinding.setCardLocalData(keyValue, sendToServer);
1113
1113
  }
1114
- getWidgetsSharedData(cardId, widget) {
1115
- return this.sdkBinding.getWidgetsSharedData(cardId, widget);
1114
+ getWidgetsSharedData(widget) {
1115
+ return this.sdkBinding.getWidgetsSharedData(widget);
1116
1116
  }
1117
1117
  vibrate(pattern) {
1118
1118
  navigator.vibrate(pattern);
@@ -1224,6 +1224,9 @@ class EsModuleSdkApi {
1224
1224
  productCartClicked() {
1225
1225
  this.sdkBinding.productCartClicked();
1226
1226
  }
1227
+ onVerticalScrollChange(data) {
1228
+ this.sdkBinding.onVerticalScrollChange(data);
1229
+ }
1227
1230
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKInterface`]; }
1228
1231
  }
1229
1232
 
@@ -1466,7 +1469,7 @@ class PromocodeLocalRepository {
1466
1469
  this.sdkApi = sdkApi;
1467
1470
  }
1468
1471
  init({ localData, cardId }) {
1469
- const savedData = this.sdkApi.getCardServerData(cardId) ?? {};
1472
+ const savedData = this.sdkApi.getCardServerData() ?? {};
1470
1473
  this.localData = extend({}, savedData, localData ?? {});
1471
1474
  }
1472
1475
  getPromocode() {
@@ -3611,6 +3614,64 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
3611
3614
  return null;
3612
3615
  };
3613
3616
 
3617
+ class LayerVerticalScrollNotifier {
3618
+ scrollable;
3619
+ cardId;
3620
+ slideIndex;
3621
+ layerIndex;
3622
+ scrollView;
3623
+ onVerticalScrollChange;
3624
+ constructor(scrollable, cardId, slideIndex, layerIndex, scrollView, onVerticalScrollChange) {
3625
+ this.scrollable = scrollable;
3626
+ this.cardId = cardId;
3627
+ this.slideIndex = slideIndex;
3628
+ this.layerIndex = layerIndex;
3629
+ this.scrollView = scrollView;
3630
+ this.onVerticalScrollChange = onVerticalScrollChange;
3631
+ // Store context
3632
+ this.onScroll = this.onScroll.bind(this);
3633
+ this.onUpdateSizeMetrics();
3634
+ }
3635
+ scrollViewHeight = 0;
3636
+ scrollHeight = 0;
3637
+ start() {
3638
+ // emit event with actual scrollPercent at layer start - for SDK synchronization
3639
+ this.onScroll();
3640
+ if (this.scrollable && this.scrollView != null) {
3641
+ this.scrollView.addEventListener("scroll", this.onScroll);
3642
+ }
3643
+ }
3644
+ onUpdateSizeMetrics(metrics) {
3645
+ if (this.scrollView != null) {
3646
+ this.scrollViewHeight = this.scrollView.getBoundingClientRect().height;
3647
+ this.scrollHeight = this.scrollView.scrollHeight;
3648
+ }
3649
+ }
3650
+ onScroll(event) {
3651
+ this.emitEvent(this.scrollView?.scrollTop);
3652
+ }
3653
+ emitEvent(scrollY = 0) {
3654
+ const height = this.scrollHeight - this.scrollViewHeight;
3655
+ // scroll / (full scroll height - viewport height)
3656
+ let scrollPercent = (scrollY / (height > 0 ? height : 1)) * 100;
3657
+ scrollPercent = Math.min(100, Math.round(scrollPercent));
3658
+ this.onVerticalScrollChange({
3659
+ scrollY,
3660
+ scrollPercent,
3661
+ isScrollableLayer: this.scrollable,
3662
+ cardId: this.cardId,
3663
+ slideIndex: this.slideIndex,
3664
+ layerIndex: this.layerIndex,
3665
+ });
3666
+ }
3667
+ destroy() {
3668
+ if (this.scrollable && this.scrollView != null) {
3669
+ this.scrollView.removeEventListener("scroll", this.onScroll);
3670
+ }
3671
+ }
3672
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`boolean`, `number`, `number`, `number`, `HTMLElement | null`, `SDKApi["onVerticalScrollChange"]`]; }
3673
+ }
3674
+
3614
3675
  var TimelineDisabledState;
3615
3676
  (function (TimelineDisabledState) {
3616
3677
  TimelineDisabledState[TimelineDisabledState["disabled"] = 0] = "disabled";
@@ -3879,6 +3940,7 @@ class SlideTimeline {
3879
3940
  class Layer {
3880
3941
  _nodeRef;
3881
3942
  _slide;
3943
+ _layerIndex;
3882
3944
  _slideReadyPromise;
3883
3945
  _afterAppResumeQueuePush;
3884
3946
  _afterStartInitQueuePush;
@@ -3895,12 +3957,16 @@ class Layer {
3895
3957
  _duration;
3896
3958
  _disabledTimer;
3897
3959
  _disabledNavigation;
3960
+ _scrollable;
3961
+ _scrollView;
3962
+ _layerVerticalScrollNotifier;
3898
3963
  _elements = [];
3899
3964
  _timeline;
3900
3965
  _widgetDeps;
3901
- constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3966
+ constructor(_nodeRef, _slide, _layerIndex, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3902
3967
  this._nodeRef = _nodeRef;
3903
3968
  this._slide = _slide;
3969
+ this._layerIndex = _layerIndex;
3904
3970
  this._slideReadyPromise = _slideReadyPromise;
3905
3971
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3906
3972
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
@@ -3917,6 +3983,9 @@ class Layer {
3917
3983
  this._duration = parseInt(this._nodeRef.getAttribute("data-duration") ?? "") || DEFAULT_SLIDE_DURATION;
3918
3984
  this._disabledTimer = this._nodeRef.getAttribute("data-disable-timer") === "1";
3919
3985
  this._disabledNavigation = this._nodeRef.getAttribute("data-disable-navigation") === "1";
3986
+ this._scrollable = this._nodeRef.getAttribute("data-scrollable") === "1";
3987
+ this._scrollView = _nodeRef.querySelector(".narrative-layer-scroll-view");
3988
+ this._layerVerticalScrollNotifier = new LayerVerticalScrollNotifier(this._scrollable, this._cardId, this._slideIndex, this._layerIndex, this._scrollView, this.slideApiDeps.onVerticalScrollChange.bind(this.slideApiDeps));
3920
3989
  this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.slideApiDeps);
3921
3990
  this._widgetDeps = {
3922
3991
  slideApiDeps: this.slideApiDeps,
@@ -3948,7 +4017,7 @@ class Layer {
3948
4017
  this._slideResumeUI();
3949
4018
  }
3950
4019
  };
3951
- const _elementsNodes = this._nodeRef.querySelectorAll(".narrative-slide-elements .narrative-element:not(.narrative-element-child-element)");
4020
+ const _elementsNodes = this._nodeRef.querySelectorAll(".narrative-slide-elements .narrative-element:not(.narrative-element-child-element), .narrative-slide-background .narrative-element:not(.narrative-element-child-element)");
3952
4021
  let layerWithWidgetQuest = false;
3953
4022
  _elementsNodes.forEach(item => {
3954
4023
  let element = tryCreateFromHtmlElement(item, this, {
@@ -3965,7 +4034,7 @@ class Layer {
3965
4034
  });
3966
4035
  // console.log({ _elementsNodes }, this._elements);
3967
4036
  /**
3968
- * Special behaviour for widget Quest
4037
+ * Special behavior for widget Quest
3969
4038
  * if current slide/layer without WidgetQuest element explicit but story has type Quest
3970
4039
  * - then init WidgetQuest with layer instead of WidgetQuest element (required for WidgetQuest slides navigation)
3971
4040
  */
@@ -3987,6 +4056,9 @@ class Layer {
3987
4056
  const promises = this._elements.map(element => element.init(localData));
3988
4057
  return promises;
3989
4058
  }
4059
+ onUpdateSizeMetrics(metrics) {
4060
+ this._layerVerticalScrollNotifier?.onUpdateSizeMetrics(metrics);
4061
+ }
3990
4062
  onAfterAllMediaResourcesLoaded() {
3991
4063
  if (this.slideApiDeps.isIOS) ;
3992
4064
  this._initTextFit();
@@ -4042,6 +4114,9 @@ class Layer {
4042
4114
  get disabledNavigation() {
4043
4115
  return this._disabledNavigation;
4044
4116
  }
4117
+ get scrollable() {
4118
+ return this._scrollable;
4119
+ }
4045
4120
  get videoElement() {
4046
4121
  for (const element of this._elements) {
4047
4122
  if (Video.isTypeOf(element)) {
@@ -4171,6 +4246,15 @@ class Layer {
4171
4246
  _animationPauseCb;
4172
4247
  _animationResumeCb;
4173
4248
  async start(muted = true) {
4249
+ if (this._layerVerticalScrollNotifier === null) {
4250
+ this._layerVerticalScrollNotifier = new LayerVerticalScrollNotifier(this._scrollable, this._cardId, this._slideIndex, this._layerIndex, this._scrollView, this.slideApiDeps.onVerticalScrollChange.bind(this.slideApiDeps));
4251
+ }
4252
+ // push _layerVerticalScrollNotifier?.start to EventLoop queue
4253
+ // complete story_slide_start, after that - call _layerVerticalScrollNotifier
4254
+ // prevent call _layerVerticalScrollNotifier before storyStarted SDK callback
4255
+ setTimeout(() => {
4256
+ this._layerVerticalScrollNotifier?.start();
4257
+ });
4174
4258
  const videoElement = this.videoElement;
4175
4259
  let currentTime = 0;
4176
4260
  if (videoElement != null) {
@@ -4201,6 +4285,8 @@ class Layer {
4201
4285
  return { currentTime };
4202
4286
  }
4203
4287
  async stop(options) {
4288
+ this._layerVerticalScrollNotifier?.destroy();
4289
+ this._layerVerticalScrollNotifier = null;
4204
4290
  this.videoElement?.stop(options);
4205
4291
  this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
4206
4292
  for (const element of this._elements) {
@@ -4291,7 +4377,7 @@ class Layer {
4291
4377
  get isLayerForcePaused() {
4292
4378
  return this.elements.some(element => element.isLayerForcePaused);
4293
4379
  }
4294
- 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`]; }
4380
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`HTMLElement`, `Slide`, `number`, `Promise`, `(cb: () => void) => void`, `(cb: () => void) => void`, `ISlideApiDeps`, `HTMLElement`, `() => "ltr" | "rtl"`, `() => Promise<void>`, `() => Promise<void>`, `GetSdkClientVariables`]; }
4295
4381
  }
4296
4382
  const TextFit = (function () {
4297
4383
  const defaultSettings = {
@@ -4505,9 +4591,12 @@ class Slide {
4505
4591
  if (!this._slidesNodesRefs.length) {
4506
4592
  throw new Error("No slides found.");
4507
4593
  }
4508
- 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));
4594
+ this._layers = this._slidesNodesRefs.map((item, layerIndex) => new Layer(item, this, layerIndex, this._slideReadyPromise, this._afterAppResumeQueuePush, this._afterStartInitQueuePush, this.slideApiDeps, this._slideRoot, this._getLayoutDirection, this._slidePauseUI, this._slideResumeUI, this._getSdkClientVariables));
4509
4595
  this._activeLayer = this._layers[0];
4510
4596
  }
4597
+ onUpdateSizeMetrics(metrics) {
4598
+ this.layers.forEach(layer => layer.onUpdateSizeMetrics(metrics));
4599
+ }
4511
4600
  _activeLayer;
4512
4601
  get activeLayer() {
4513
4602
  return this._activeLayer;
@@ -4670,6 +4759,7 @@ let SlideApi$1 = class SlideApi {
4670
4759
  }
4671
4760
  this.slideOffsetElement.style.margin = slideOffsetMargin;
4672
4761
  }
4762
+ this.slide?.onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, slideOffsetMargin });
4673
4763
  }
4674
4764
  get slideWrapperElement() {
4675
4765
  return this._slideWrapper;
@@ -5528,7 +5618,7 @@ let SlideApi$1 = class SlideApi {
5528
5618
  if (element) {
5529
5619
  propagation = false;
5530
5620
  this.slideApiDeps.setCardLocalData({}, true);
5531
- this.slideApiDeps.updateCardServerDataLocally(this.slide.cardId, {});
5621
+ this.slideApiDeps.updateCardServerDataLocally({});
5532
5622
  // window._resetTimers();
5533
5623
  // сделать async в ios
5534
5624
  let slideIndex = this.slide.slideIndex;
@@ -5826,8 +5916,8 @@ class SlideApiDepsMultiSlideMode {
5826
5916
  onWidgetRequireResumeUI() {
5827
5917
  return this.sdkApi.onWidgetRequireResumeUI();
5828
5918
  }
5829
- getWidgetsSharedData(cardId, widget) {
5830
- return this.sdkApi.getWidgetsSharedData(cardId, widget);
5919
+ getWidgetsSharedData(widget) {
5920
+ return this.sdkApi.getWidgetsSharedData(widget);
5831
5921
  }
5832
5922
  showToast(text) {
5833
5923
  return this.sdkApi.showToast(text);
@@ -5915,14 +6005,14 @@ class SlideApiDepsMultiSlideMode {
5915
6005
  getCardLocalData() {
5916
6006
  return this.sdkApi.getCardLocalData();
5917
6007
  }
5918
- getCardServerData(cardId) {
5919
- return this.sdkApi.getCardServerData(cardId);
6008
+ getCardServerData() {
6009
+ return this.sdkApi.getCardServerData();
5920
6010
  }
5921
6011
  get cardAnimation() {
5922
6012
  return this.sdkApi.cardAnimation;
5923
6013
  }
5924
- updateCardServerDataLocally(cardId, data) {
5925
- this.sdkApi.updateCardServerDataLocally(cardId, data);
6014
+ updateCardServerDataLocally(data) {
6015
+ this.sdkApi.updateCardServerDataLocally(data);
5926
6016
  }
5927
6017
  get isExistsShowNextCard() {
5928
6018
  return this.sdkApi.isExistsShowNextCard;
@@ -5964,6 +6054,9 @@ class SlideApiDepsMultiSlideMode {
5964
6054
  productCartClicked() {
5965
6055
  this.sdkApi.productCartClicked();
5966
6056
  }
6057
+ onVerticalScrollChange(data) {
6058
+ this.sdkApi.onVerticalScrollChange(data);
6059
+ }
5967
6060
  /**
5968
6061
  * For single slide mode - proxy these methods via SDKApi
5969
6062
  * =================================================================================================================
@@ -6003,8 +6096,8 @@ class SlideApiDepsSingleSlideMode {
6003
6096
  onWidgetRequireResumeUI() {
6004
6097
  return this.sdkApi.onWidgetRequireResumeUI();
6005
6098
  }
6006
- getWidgetsSharedData(cardId, widget) {
6007
- return this.sdkApi.getWidgetsSharedData(cardId, widget);
6099
+ getWidgetsSharedData(widget) {
6100
+ return this.sdkApi.getWidgetsSharedData(widget);
6008
6101
  }
6009
6102
  showToast(text) {
6010
6103
  return this.sdkApi.showToast(text);
@@ -6092,14 +6185,14 @@ class SlideApiDepsSingleSlideMode {
6092
6185
  getCardLocalData() {
6093
6186
  return this.sdkApi.getCardLocalData();
6094
6187
  }
6095
- getCardServerData(cardId) {
6096
- return this.sdkApi.getCardServerData(cardId);
6188
+ getCardServerData() {
6189
+ return this.sdkApi.getCardServerData();
6097
6190
  }
6098
6191
  get cardAnimation() {
6099
6192
  return this.sdkApi.cardAnimation;
6100
6193
  }
6101
- updateCardServerDataLocally(cardId, data) {
6102
- this.sdkApi.updateCardServerDataLocally(cardId, data);
6194
+ updateCardServerDataLocally(data) {
6195
+ this.sdkApi.updateCardServerDataLocally(data);
6103
6196
  }
6104
6197
  get isExistsShowNextCard() {
6105
6198
  return this.sdkApi.isExistsShowNextCard;
@@ -6163,6 +6256,9 @@ class SlideApiDepsSingleSlideMode {
6163
6256
  showNextSlide(duration) {
6164
6257
  this.sdkApi.showNextSlide(duration);
6165
6258
  }
6259
+ onVerticalScrollChange(data) {
6260
+ this.sdkApi.onVerticalScrollChange(data);
6261
+ }
6166
6262
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`]; }
6167
6263
  }
6168
6264
 
@@ -7532,7 +7628,7 @@ class WidgetBase {
7532
7628
  this.submitButtonView = this.submitButtonAnimatedView.querySelector(".submit-button-view");
7533
7629
  }
7534
7630
  }
7535
- this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
7631
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData();
7536
7632
  this.localData = extend({}, this.savedData ?? {}, this.options.localData ?? {});
7537
7633
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
7538
7634
  ++WidgetBase.widgetIndex;
@@ -7554,7 +7650,7 @@ class WidgetBase {
7554
7650
  * @param localData
7555
7651
  */
7556
7652
  onRefreshUserData(localData) {
7557
- this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
7653
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData();
7558
7654
  this.localData = extend({}, this.savedData ?? {}, localData);
7559
7655
  }
7560
7656
  onStart() {
@@ -18986,7 +19082,7 @@ class WidgetPoll extends WidgetBase {
18986
19082
  displayPercents(selectedVariantIndex, filled = false) {
18987
19083
  let pollAllocation = [0, 0];
18988
19084
  let pollAllocationTs = undefined;
18989
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
19085
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("poll" /* Widgets.Poll */);
18990
19086
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
18991
19087
  pollAllocation = sharedData[this.elementId];
18992
19088
  if (isObject$1(sharedData[this.elementId])) {
@@ -23194,7 +23290,7 @@ class WidgetRangeSlider extends WidgetBase {
23194
23290
  total_user: 0,
23195
23291
  };
23196
23292
  let answerAllocationTs = undefined;
23197
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
23293
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("rangeSlider" /* Widgets.RangeSlider */);
23198
23294
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
23199
23295
  answerAllocation = sharedData[this.elementId];
23200
23296
  answerAllocationTs = sharedData.ts;
@@ -24891,7 +24987,7 @@ class WidgetVote extends WidgetBase {
24891
24987
  // voteAllocation[7]
24892
24988
  let voteAllocation = [];
24893
24989
  let voteAllocationTs = undefined;
24894
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
24990
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("vote" /* Widgets.Vote */);
24895
24991
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
24896
24992
  voteAllocation = sharedData[this.elementId];
24897
24993
  if (isObject$1(sharedData[this.elementId])) {
@@ -25295,7 +25391,7 @@ class WidgetReactions extends WidgetBase {
25295
25391
  this.element.classList.add("narrative-element-reactions--done");
25296
25392
  }
25297
25393
  getReactionsSummary() {
25298
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "reactions" /* Widgets.Reactions */);
25394
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("reactions" /* Widgets.Reactions */);
25299
25395
  let allocation = [];
25300
25396
  let timestamp = null;
25301
25397
  if (this.hasValidSharedData(sharedData)) {