@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.js CHANGED
@@ -1067,10 +1067,10 @@ class EsModuleSdkApi {
1067
1067
  onWidgetRequireResumeUI() {
1068
1068
  return this.sdkBinding.onWidgetRequireResumeUI();
1069
1069
  }
1070
- getCardServerData(cardId) {
1071
- return this.sdkBinding.getCardServerData(cardId);
1070
+ getCardServerData() {
1071
+ return this.sdkBinding.getCardServerData();
1072
1072
  }
1073
- updateCardServerDataLocally(cardId, data) {
1073
+ updateCardServerDataLocally(data) {
1074
1074
  return this.sdkBinding.updateCardServerDataLocally(data);
1075
1075
  }
1076
1076
  showNextSlide(duration) {
@@ -1109,8 +1109,8 @@ class EsModuleSdkApi {
1109
1109
  setCardLocalData(keyValue, sendToServer) {
1110
1110
  this.sdkBinding.setCardLocalData(keyValue, sendToServer);
1111
1111
  }
1112
- getWidgetsSharedData(cardId, widget) {
1113
- return this.sdkBinding.getWidgetsSharedData(cardId, widget);
1112
+ getWidgetsSharedData(widget) {
1113
+ return this.sdkBinding.getWidgetsSharedData(widget);
1114
1114
  }
1115
1115
  vibrate(pattern) {
1116
1116
  navigator.vibrate(pattern);
@@ -1222,6 +1222,9 @@ class EsModuleSdkApi {
1222
1222
  productCartClicked() {
1223
1223
  this.sdkBinding.productCartClicked();
1224
1224
  }
1225
+ onVerticalScrollChange(data) {
1226
+ this.sdkBinding.onVerticalScrollChange(data);
1227
+ }
1225
1228
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKInterface`]; }
1226
1229
  }
1227
1230
 
@@ -1464,7 +1467,7 @@ class PromocodeLocalRepository {
1464
1467
  this.sdkApi = sdkApi;
1465
1468
  }
1466
1469
  init({ localData, cardId }) {
1467
- const savedData = this.sdkApi.getCardServerData(cardId) ?? {};
1470
+ const savedData = this.sdkApi.getCardServerData() ?? {};
1468
1471
  this.localData = extend({}, savedData, localData ?? {});
1469
1472
  }
1470
1473
  getPromocode() {
@@ -3609,6 +3612,64 @@ const tryCreateFromHtmlElement = (nodeRef, layer, widgetCallbacks, widgetDeps) =
3609
3612
  return null;
3610
3613
  };
3611
3614
 
3615
+ class LayerVerticalScrollNotifier {
3616
+ scrollable;
3617
+ cardId;
3618
+ slideIndex;
3619
+ layerIndex;
3620
+ scrollView;
3621
+ onVerticalScrollChange;
3622
+ constructor(scrollable, cardId, slideIndex, layerIndex, scrollView, onVerticalScrollChange) {
3623
+ this.scrollable = scrollable;
3624
+ this.cardId = cardId;
3625
+ this.slideIndex = slideIndex;
3626
+ this.layerIndex = layerIndex;
3627
+ this.scrollView = scrollView;
3628
+ this.onVerticalScrollChange = onVerticalScrollChange;
3629
+ // Store context
3630
+ this.onScroll = this.onScroll.bind(this);
3631
+ this.onUpdateSizeMetrics();
3632
+ }
3633
+ scrollViewHeight = 0;
3634
+ scrollHeight = 0;
3635
+ start() {
3636
+ // emit event with actual scrollPercent at layer start - for SDK synchronization
3637
+ this.onScroll();
3638
+ if (this.scrollable && this.scrollView != null) {
3639
+ this.scrollView.addEventListener("scroll", this.onScroll);
3640
+ }
3641
+ }
3642
+ onUpdateSizeMetrics(metrics) {
3643
+ if (this.scrollView != null) {
3644
+ this.scrollViewHeight = this.scrollView.getBoundingClientRect().height;
3645
+ this.scrollHeight = this.scrollView.scrollHeight;
3646
+ }
3647
+ }
3648
+ onScroll(event) {
3649
+ this.emitEvent(this.scrollView?.scrollTop);
3650
+ }
3651
+ emitEvent(scrollY = 0) {
3652
+ const height = this.scrollHeight - this.scrollViewHeight;
3653
+ // scroll / (full scroll height - viewport height)
3654
+ let scrollPercent = (scrollY / (height > 0 ? height : 1)) * 100;
3655
+ scrollPercent = Math.min(100, Math.round(scrollPercent));
3656
+ this.onVerticalScrollChange({
3657
+ scrollY,
3658
+ scrollPercent,
3659
+ isScrollableLayer: this.scrollable,
3660
+ cardId: this.cardId,
3661
+ slideIndex: this.slideIndex,
3662
+ layerIndex: this.layerIndex,
3663
+ });
3664
+ }
3665
+ destroy() {
3666
+ if (this.scrollable && this.scrollView != null) {
3667
+ this.scrollView.removeEventListener("scroll", this.onScroll);
3668
+ }
3669
+ }
3670
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`boolean`, `number`, `number`, `number`, `HTMLElement | null`, `SDKApi["onVerticalScrollChange"]`]; }
3671
+ }
3672
+
3612
3673
  var TimelineDisabledState;
3613
3674
  (function (TimelineDisabledState) {
3614
3675
  TimelineDisabledState[TimelineDisabledState["disabled"] = 0] = "disabled";
@@ -3877,6 +3938,7 @@ class SlideTimeline {
3877
3938
  class Layer {
3878
3939
  _nodeRef;
3879
3940
  _slide;
3941
+ _layerIndex;
3880
3942
  _slideReadyPromise;
3881
3943
  _afterAppResumeQueuePush;
3882
3944
  _afterStartInitQueuePush;
@@ -3893,12 +3955,16 @@ class Layer {
3893
3955
  _duration;
3894
3956
  _disabledTimer;
3895
3957
  _disabledNavigation;
3958
+ _scrollable;
3959
+ _scrollView;
3960
+ _layerVerticalScrollNotifier;
3896
3961
  _elements = [];
3897
3962
  _timeline;
3898
3963
  _widgetDeps;
3899
- constructor(_nodeRef, _slide, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3964
+ constructor(_nodeRef, _slide, _layerIndex, _slideReadyPromise, _afterAppResumeQueuePush, _afterStartInitQueuePush, slideApiDeps, _slideRoot, _getLayoutDirection, _slidePauseUI, _slideResumeUI, _getSdkClientVariables) {
3900
3965
  this._nodeRef = _nodeRef;
3901
3966
  this._slide = _slide;
3967
+ this._layerIndex = _layerIndex;
3902
3968
  this._slideReadyPromise = _slideReadyPromise;
3903
3969
  this._afterAppResumeQueuePush = _afterAppResumeQueuePush;
3904
3970
  this._afterStartInitQueuePush = _afterStartInitQueuePush;
@@ -3915,6 +3981,9 @@ class Layer {
3915
3981
  this._duration = parseInt(this._nodeRef.getAttribute("data-duration") ?? "") || DEFAULT_SLIDE_DURATION;
3916
3982
  this._disabledTimer = this._nodeRef.getAttribute("data-disable-timer") === "1";
3917
3983
  this._disabledNavigation = this._nodeRef.getAttribute("data-disable-navigation") === "1";
3984
+ this._scrollable = this._nodeRef.getAttribute("data-scrollable") === "1";
3985
+ this._scrollView = _nodeRef.querySelector(".narrative-layer-scroll-view");
3986
+ this._layerVerticalScrollNotifier = new LayerVerticalScrollNotifier(this._scrollable, this._cardId, this._slideIndex, this._layerIndex, this._scrollView, this.slideApiDeps.onVerticalScrollChange.bind(this.slideApiDeps));
3918
3987
  this._timeline = new SlideTimeline(this._slideIndex, this._duration, this._disabledTimer, this._slideReadyPromise, this._afterAppResumeQueuePush, this.slideApiDeps);
3919
3988
  this._widgetDeps = {
3920
3989
  slideApiDeps: this.slideApiDeps,
@@ -3946,7 +4015,7 @@ class Layer {
3946
4015
  this._slideResumeUI();
3947
4016
  }
3948
4017
  };
3949
- const _elementsNodes = this._nodeRef.querySelectorAll(".narrative-slide-elements .narrative-element:not(.narrative-element-child-element)");
4018
+ 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)");
3950
4019
  let layerWithWidgetQuest = false;
3951
4020
  _elementsNodes.forEach(item => {
3952
4021
  let element = tryCreateFromHtmlElement(item, this, {
@@ -3963,7 +4032,7 @@ class Layer {
3963
4032
  });
3964
4033
  // console.log({ _elementsNodes }, this._elements);
3965
4034
  /**
3966
- * Special behaviour for widget Quest
4035
+ * Special behavior for widget Quest
3967
4036
  * if current slide/layer without WidgetQuest element explicit but story has type Quest
3968
4037
  * - then init WidgetQuest with layer instead of WidgetQuest element (required for WidgetQuest slides navigation)
3969
4038
  */
@@ -3985,6 +4054,9 @@ class Layer {
3985
4054
  const promises = this._elements.map(element => element.init(localData));
3986
4055
  return promises;
3987
4056
  }
4057
+ onUpdateSizeMetrics(metrics) {
4058
+ this._layerVerticalScrollNotifier?.onUpdateSizeMetrics(metrics);
4059
+ }
3988
4060
  onAfterAllMediaResourcesLoaded() {
3989
4061
  if (this.slideApiDeps.isIOS) ;
3990
4062
  this._initTextFit();
@@ -4040,6 +4112,9 @@ class Layer {
4040
4112
  get disabledNavigation() {
4041
4113
  return this._disabledNavigation;
4042
4114
  }
4115
+ get scrollable() {
4116
+ return this._scrollable;
4117
+ }
4043
4118
  get videoElement() {
4044
4119
  for (const element of this._elements) {
4045
4120
  if (Video.isTypeOf(element)) {
@@ -4169,6 +4244,15 @@ class Layer {
4169
4244
  _animationPauseCb;
4170
4245
  _animationResumeCb;
4171
4246
  async start(muted = true) {
4247
+ if (this._layerVerticalScrollNotifier === null) {
4248
+ this._layerVerticalScrollNotifier = new LayerVerticalScrollNotifier(this._scrollable, this._cardId, this._slideIndex, this._layerIndex, this._scrollView, this.slideApiDeps.onVerticalScrollChange.bind(this.slideApiDeps));
4249
+ }
4250
+ // push _layerVerticalScrollNotifier?.start to EventLoop queue
4251
+ // complete story_slide_start, after that - call _layerVerticalScrollNotifier
4252
+ // prevent call _layerVerticalScrollNotifier before storyStarted SDK callback
4253
+ setTimeout(() => {
4254
+ this._layerVerticalScrollNotifier?.start();
4255
+ });
4172
4256
  const videoElement = this.videoElement;
4173
4257
  let currentTime = 0;
4174
4258
  if (videoElement != null) {
@@ -4199,6 +4283,8 @@ class Layer {
4199
4283
  return { currentTime };
4200
4284
  }
4201
4285
  async stop(options) {
4286
+ this._layerVerticalScrollNotifier?.destroy();
4287
+ this._layerVerticalScrollNotifier = null;
4202
4288
  this.videoElement?.stop(options);
4203
4289
  this.slideApiDeps.cardAnimation?.stop(this._nodeRef);
4204
4290
  for (const element of this._elements) {
@@ -4289,7 +4375,7 @@ class Layer {
4289
4375
  get isLayerForcePaused() {
4290
4376
  return this.elements.some(element => element.isLayerForcePaused);
4291
4377
  }
4292
- 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`]; }
4378
+ 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`]; }
4293
4379
  }
4294
4380
  const TextFit = (function () {
4295
4381
  const defaultSettings = {
@@ -4503,9 +4589,12 @@ class Slide {
4503
4589
  if (!this._slidesNodesRefs.length) {
4504
4590
  throw new Error("No slides found.");
4505
4591
  }
4506
- 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));
4592
+ 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));
4507
4593
  this._activeLayer = this._layers[0];
4508
4594
  }
4595
+ onUpdateSizeMetrics(metrics) {
4596
+ this.layers.forEach(layer => layer.onUpdateSizeMetrics(metrics));
4597
+ }
4509
4598
  _activeLayer;
4510
4599
  get activeLayer() {
4511
4600
  return this._activeLayer;
@@ -4668,6 +4757,7 @@ let SlideApi$1 = class SlideApi {
4668
4757
  }
4669
4758
  this.slideOffsetElement.style.margin = slideOffsetMargin;
4670
4759
  }
4760
+ this.slide?.onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, slideOffsetMargin });
4671
4761
  }
4672
4762
  get slideWrapperElement() {
4673
4763
  return this._slideWrapper;
@@ -5526,7 +5616,7 @@ let SlideApi$1 = class SlideApi {
5526
5616
  if (element) {
5527
5617
  propagation = false;
5528
5618
  this.slideApiDeps.setCardLocalData({}, true);
5529
- this.slideApiDeps.updateCardServerDataLocally(this.slide.cardId, {});
5619
+ this.slideApiDeps.updateCardServerDataLocally({});
5530
5620
  // window._resetTimers();
5531
5621
  // сделать async в ios
5532
5622
  let slideIndex = this.slide.slideIndex;
@@ -5824,8 +5914,8 @@ class SlideApiDepsMultiSlideMode {
5824
5914
  onWidgetRequireResumeUI() {
5825
5915
  return this.sdkApi.onWidgetRequireResumeUI();
5826
5916
  }
5827
- getWidgetsSharedData(cardId, widget) {
5828
- return this.sdkApi.getWidgetsSharedData(cardId, widget);
5917
+ getWidgetsSharedData(widget) {
5918
+ return this.sdkApi.getWidgetsSharedData(widget);
5829
5919
  }
5830
5920
  showToast(text) {
5831
5921
  return this.sdkApi.showToast(text);
@@ -5913,14 +6003,14 @@ class SlideApiDepsMultiSlideMode {
5913
6003
  getCardLocalData() {
5914
6004
  return this.sdkApi.getCardLocalData();
5915
6005
  }
5916
- getCardServerData(cardId) {
5917
- return this.sdkApi.getCardServerData(cardId);
6006
+ getCardServerData() {
6007
+ return this.sdkApi.getCardServerData();
5918
6008
  }
5919
6009
  get cardAnimation() {
5920
6010
  return this.sdkApi.cardAnimation;
5921
6011
  }
5922
- updateCardServerDataLocally(cardId, data) {
5923
- this.sdkApi.updateCardServerDataLocally(cardId, data);
6012
+ updateCardServerDataLocally(data) {
6013
+ this.sdkApi.updateCardServerDataLocally(data);
5924
6014
  }
5925
6015
  get isExistsShowNextCard() {
5926
6016
  return this.sdkApi.isExistsShowNextCard;
@@ -5962,6 +6052,9 @@ class SlideApiDepsMultiSlideMode {
5962
6052
  productCartClicked() {
5963
6053
  this.sdkApi.productCartClicked();
5964
6054
  }
6055
+ onVerticalScrollChange(data) {
6056
+ this.sdkApi.onVerticalScrollChange(data);
6057
+ }
5965
6058
  /**
5966
6059
  * For single slide mode - proxy these methods via SDKApi
5967
6060
  * =================================================================================================================
@@ -6001,8 +6094,8 @@ class SlideApiDepsSingleSlideMode {
6001
6094
  onWidgetRequireResumeUI() {
6002
6095
  return this.sdkApi.onWidgetRequireResumeUI();
6003
6096
  }
6004
- getWidgetsSharedData(cardId, widget) {
6005
- return this.sdkApi.getWidgetsSharedData(cardId, widget);
6097
+ getWidgetsSharedData(widget) {
6098
+ return this.sdkApi.getWidgetsSharedData(widget);
6006
6099
  }
6007
6100
  showToast(text) {
6008
6101
  return this.sdkApi.showToast(text);
@@ -6090,14 +6183,14 @@ class SlideApiDepsSingleSlideMode {
6090
6183
  getCardLocalData() {
6091
6184
  return this.sdkApi.getCardLocalData();
6092
6185
  }
6093
- getCardServerData(cardId) {
6094
- return this.sdkApi.getCardServerData(cardId);
6186
+ getCardServerData() {
6187
+ return this.sdkApi.getCardServerData();
6095
6188
  }
6096
6189
  get cardAnimation() {
6097
6190
  return this.sdkApi.cardAnimation;
6098
6191
  }
6099
- updateCardServerDataLocally(cardId, data) {
6100
- this.sdkApi.updateCardServerDataLocally(cardId, data);
6192
+ updateCardServerDataLocally(data) {
6193
+ this.sdkApi.updateCardServerDataLocally(data);
6101
6194
  }
6102
6195
  get isExistsShowNextCard() {
6103
6196
  return this.sdkApi.isExistsShowNextCard;
@@ -6161,6 +6254,9 @@ class SlideApiDepsSingleSlideMode {
6161
6254
  showNextSlide(duration) {
6162
6255
  this.sdkApi.showNextSlide(duration);
6163
6256
  }
6257
+ onVerticalScrollChange(data) {
6258
+ this.sdkApi.onVerticalScrollChange(data);
6259
+ }
6164
6260
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`]; }
6165
6261
  }
6166
6262
 
@@ -7530,7 +7626,7 @@ class WidgetBase {
7530
7626
  this.submitButtonView = this.submitButtonAnimatedView.querySelector(".submit-button-view");
7531
7627
  }
7532
7628
  }
7533
- this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
7629
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData();
7534
7630
  this.localData = extend({}, this.savedData ?? {}, this.options.localData ?? {});
7535
7631
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
7536
7632
  ++WidgetBase.widgetIndex;
@@ -7552,7 +7648,7 @@ class WidgetBase {
7552
7648
  * @param localData
7553
7649
  */
7554
7650
  onRefreshUserData(localData) {
7555
- this.savedData = this.widgetDeps.slideApiDeps.getCardServerData(this.cardId);
7651
+ this.savedData = this.widgetDeps.slideApiDeps.getCardServerData();
7556
7652
  this.localData = extend({}, this.savedData ?? {}, localData);
7557
7653
  }
7558
7654
  onStart() {
@@ -18984,7 +19080,7 @@ class WidgetPoll extends WidgetBase {
18984
19080
  displayPercents(selectedVariantIndex, filled = false) {
18985
19081
  let pollAllocation = [0, 0];
18986
19082
  let pollAllocationTs = undefined;
18987
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "poll" /* Widgets.Poll */);
19083
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("poll" /* Widgets.Poll */);
18988
19084
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
18989
19085
  pollAllocation = sharedData[this.elementId];
18990
19086
  if (isObject$1(sharedData[this.elementId])) {
@@ -23192,7 +23288,7 @@ class WidgetRangeSlider extends WidgetBase {
23192
23288
  total_user: 0,
23193
23289
  };
23194
23290
  let answerAllocationTs = undefined;
23195
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "rangeSlider" /* Widgets.RangeSlider */);
23291
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("rangeSlider" /* Widgets.RangeSlider */);
23196
23292
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
23197
23293
  answerAllocation = sharedData[this.elementId];
23198
23294
  answerAllocationTs = sharedData.ts;
@@ -24889,7 +24985,7 @@ class WidgetVote extends WidgetBase {
24889
24985
  // voteAllocation[7]
24890
24986
  let voteAllocation = [];
24891
24987
  let voteAllocationTs = undefined;
24892
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "vote" /* Widgets.Vote */);
24988
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("vote" /* Widgets.Vote */);
24893
24989
  if (sharedData && sharedData[this.elementId] != null && (isObject$1(sharedData[this.elementId]) || isArray(sharedData[this.elementId]))) {
24894
24990
  voteAllocation = sharedData[this.elementId];
24895
24991
  if (isObject$1(sharedData[this.elementId])) {
@@ -25293,7 +25389,7 @@ class WidgetReactions extends WidgetBase {
25293
25389
  this.element.classList.add("narrative-element-reactions--done");
25294
25390
  }
25295
25391
  getReactionsSummary() {
25296
- const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData(this.cardId, "reactions" /* Widgets.Reactions */);
25392
+ const sharedData = this.widgetDeps.slideApiDeps.getWidgetsSharedData("reactions" /* Widgets.Reactions */);
25297
25393
  let allocation = [];
25298
25394
  let timestamp = null;
25299
25395
  if (this.hasValidSharedData(sharedData)) {