@inappstory/slide-api 0.1.23 → 0.1.24

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
@@ -819,13 +819,18 @@ var getAnimationFunction = function (element) {
819
819
  return function () { };
820
820
  };
821
821
  const animationApi = {
822
+ init: function (slide, animate = false) {
823
+ if (supportAnimate && animate)
824
+ return;
825
+ addClass(slide, "animation-fallback");
826
+ },
822
827
  start: function (slide, animate = false) {
823
828
  if (supportAnimate && animate) {
829
+ const elements = toArray(slide.querySelectorAll(".narrative-element-animation"));
824
830
  // for editor, todo add .reset-animation to narrative-editor-slide && clear that
825
831
  if (!hasClass(slide, "narrative-slide")) {
826
832
  addClass(slide, "reset-animation");
827
833
  }
828
- const elements = toArray(slide.querySelectorAll(".narrative-element-animation"));
829
834
  elements.forEach(element => {
830
835
  var width = element.offsetWidth;
831
836
  var height = element.offsetHeight;
@@ -911,7 +916,6 @@ const animationApi = {
911
916
  }
912
917
  }
913
918
  else {
914
- addClass(slide, "animation-fallback");
915
919
  const animations = [];
916
920
  // просто Array
917
921
  var elements = slide.querySelectorAll(".narrative-element-animation");
@@ -3219,6 +3223,7 @@ class Layer {
3219
3223
  this.sdkApi.isIOS && this._nodeRef.classList.add("_isIos");
3220
3224
  this.sdkApi.isAndroid && this._nodeRef.classList.add("_isAndroid");
3221
3225
  }
3226
+ this.sdkApi.cardAnimation?.init(this._nodeRef);
3222
3227
  const promises = this._elements.map(element => element.init(localData));
3223
3228
  return promises;
3224
3229
  }
@@ -3822,7 +3827,7 @@ class Slide {
3822
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`]; }
3823
3828
  }
3824
3829
 
3825
- class CardApi {
3830
+ let SlideApi$1 = class SlideApi {
3826
3831
  config;
3827
3832
  get layoutDirection() {
3828
3833
  // warning, detection in ctor not working, bcz sdk changes layout later
@@ -3836,7 +3841,6 @@ class CardApi {
3836
3841
  _getViewportHeight;
3837
3842
  _overlappingActionBarHeight;
3838
3843
  _separateUserAndAppPause;
3839
- _index;
3840
3844
  sdkApi;
3841
3845
  constructor(config) {
3842
3846
  this.config = config;
@@ -3847,10 +3851,10 @@ class CardApi {
3847
3851
  this._getViewportHeight = config.getViewportHeight;
3848
3852
  this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
3849
3853
  this._separateUserAndAppPause = config.separateUserAndAppPause;
3850
- this._index = config.index;
3851
- }
3852
- checkAndInitPreloadedInLayoutSlide(slideLoadedCb) {
3853
- // for sdk backward compatibility
3854
+ this.refreshSizes = proxy(this.refreshSizes, this);
3855
+ this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
3856
+ this.initListeners();
3857
+ this.refreshSizes();
3854
3858
  const slideBox = document.getElementById("narrative-slide-box");
3855
3859
  // todo via first child and its innerText - faster variant
3856
3860
  if (slideBox && slideBox.innerText.trim() !== "{%content}".replace("{", "{{").replace("}", "}}")) {
@@ -3858,45 +3862,121 @@ class CardApi {
3858
3862
  this._slideInRender = true;
3859
3863
  this._init(() => this._slideBoxRenderComplete(null)).then(({ slide, result, reason }) => {
3860
3864
  this._slide = slide;
3861
- if (slideLoadedCb != null) {
3862
- slideLoadedCb({ cardId: slide.cardId, slideIndex: slide.slideIndex, result, reason });
3865
+ if (config.slideLoadedCb != null) {
3866
+ config.slideLoadedCb({ cardId: slide.cardId, slideIndex: slide.slideIndex, result, reason });
3863
3867
  }
3864
3868
  });
3865
3869
  }
3866
3870
  }
3867
- onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen, }) {
3868
- // todo CSP violation
3869
- this._slideWrapper.style.fontSize = fontSize;
3870
- if (this.slideOffsetElement != null) {
3871
- // todo CSP violation
3872
- this.slideOffsetElement.style.setProperty("--y-offset", yOffset);
3873
- this.slideOffsetElement.style.setProperty("--x-offset", xOffset);
3874
- if (isFullscreen) {
3875
- this.slideOffsetElement.classList.add("narrative-slide-offset-fullscreen");
3876
- }
3877
- else {
3878
- this.slideOffsetElement.classList.remove("narrative-slide-offset-fullscreen");
3879
- }
3880
- }
3881
- }
3882
- get slideWrapperElement() {
3883
- return this._slideWrapper;
3884
- }
3885
- get slideOffsetElement() {
3886
- return this._slideWrapper.querySelector(".narrative-slide-offset");
3887
- }
3888
- get index() {
3889
- return this._index;
3890
- }
3891
3871
  async destroy() {
3892
3872
  if (this.slide != null) {
3893
3873
  await this.slide.onBeforeUnmount();
3894
3874
  }
3875
+ this.destroyListeners();
3895
3876
  this._state = 13 /* STATE.DESTROYED */;
3896
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";
3949
+ }
3950
+ 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";
3960
+ }
3961
+ }
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 });
3975
+ }
3976
+ }
3897
3977
  async showSlide(html) {
3898
- const slideBox = this._slideWrapper.querySelector(`.${CardApi.renderedBoxClassName}`);
3899
- const slideBoxPrerender = this._slideWrapper.querySelector(`.${CardApi.prerenderBoxClassName}`);
3978
+ const slideBox = this._slideWrapper.querySelector(`.${SlideApi.renderedBoxClassName}`);
3979
+ const slideBoxPrerender = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName}`);
3900
3980
  const _result = { cardId: this.slide?.cardId ?? 0, slideIndex: this.slide?.slideIndex ?? 0, result: false, reason: "" };
3901
3981
  if (slideBox && slideBoxPrerender) {
3902
3982
  if (this._slideInRender) {
@@ -3905,9 +3985,7 @@ class CardApi {
3905
3985
  }
3906
3986
  this._slideInInit = null;
3907
3987
  this._slideInRender = true;
3908
- if (html != null) {
3909
- slideBoxPrerender.innerHTML = html;
3910
- }
3988
+ slideBoxPrerender.innerHTML = html;
3911
3989
  const prevSlide = this.slide ? Object.assign(Object.create(Object.getPrototypeOf(this.slide)), this.slide) : null;
3912
3990
  const { slide, result, reason } = await this._init(() => this._slideBoxRenderComplete(prevSlide));
3913
3991
  this._slide = slide;
@@ -3916,7 +3994,7 @@ class CardApi {
3916
3994
  }
3917
3995
  else {
3918
3996
  _result.result = false;
3919
- _result.reason = `Element .${CardApi.renderedBoxClassName} or .${CardApi.prerenderBoxClassName} does not found in DOM`;
3997
+ _result.reason = `Element .${SlideApi.renderedBoxClassName} or .${SlideApi.prerenderBoxClassName} does not found in DOM`;
3920
3998
  }
3921
3999
  _result.cardId = this.slide.cardId;
3922
4000
  _result.slideIndex = this.slide.slideIndex;
@@ -4021,9 +4099,9 @@ class CardApi {
4021
4099
  /**
4022
4100
  * For case when SlideApi instance was created before root was attached to DOM
4023
4101
  */
4024
- this.config.refreshSizes();
4025
- const slideNodeRef = this._slideWrapper.querySelector(`.${CardApi.prerenderBoxClassName} .narrative-slide`);
4026
- const slidesNodesRefs = Array.prototype.slice.call(this._slideWrapper.querySelectorAll(`.${CardApi.prerenderBoxClassName} .narrative-slide.narrative-multi-slide`));
4102
+ this.refreshSizes();
4103
+ const slideNodeRef = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName} .narrative-slide`);
4104
+ const slidesNodesRefs = Array.prototype.slice.call(this._slideWrapper.querySelectorAll(`.${SlideApi.prerenderBoxClassName} .narrative-slide.narrative-multi-slide`));
4027
4105
  if (!slidesNodesRefs.length && slideNodeRef != null) {
4028
4106
  slidesNodesRefs.push(slideNodeRef);
4029
4107
  }
@@ -4034,7 +4112,7 @@ class CardApi {
4034
4112
  const slideReadyPromise = new Promise(resolve => {
4035
4113
  slideReadyResolve = resolve;
4036
4114
  });
4037
- const slide = new Slide(slidesNodesRefs, slideReadyPromise, this.afterAppResumeQueuePush.bind(this), this.afterStartInitQueuePush.bind(this), this.sdkApi.showNextSlide.bind(this), this.sdkApi, this._slideWrapper, () => this.layoutDirection, this.slidePauseUI.bind(this), this.slideResumeUI.bind(this), this.config.getSdkClientVariables);
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);
4038
4116
  this._slideInInit = slide;
4039
4117
  slide.activeLayer.timeline.triggerSlideLoadState();
4040
4118
  if (this.sdkApi.isAndroid) {
@@ -4096,12 +4174,12 @@ class CardApi {
4096
4174
  return;
4097
4175
  }
4098
4176
  return new Promise(resolve => {
4099
- const slideBox = this._slideWrapper.querySelector(`.${CardApi.renderedBoxClassName}`);
4100
- const slideBoxPrerender = this._slideWrapper.querySelector(`.${CardApi.prerenderBoxClassName}`);
4177
+ const slideBox = this._slideWrapper.querySelector(`.${SlideApi.renderedBoxClassName}`);
4178
+ const slideBoxPrerender = this._slideWrapper.querySelector(`.${SlideApi.prerenderBoxClassName}`);
4101
4179
  if (slideBox && slideBoxPrerender) {
4102
- slideBoxPrerender.classList.remove(CardApi.prerenderBoxClassName);
4103
- slideBox.classList.remove(CardApi.renderedBoxClassName);
4104
- slideBox.classList.add(CardApi.prerenderBoxClassName);
4180
+ slideBoxPrerender.classList.remove(SlideApi.prerenderBoxClassName);
4181
+ slideBox.classList.remove(SlideApi.renderedBoxClassName);
4182
+ slideBox.classList.add(SlideApi.prerenderBoxClassName);
4105
4183
  // pause Video - prevent triggering onDataWaiting from VODPlayer
4106
4184
  prevSlide?.activeLayer.pause(false, true, false);
4107
4185
  // 2 RAF - wait for browser render complete (CSS changes, etc.)
@@ -4125,7 +4203,7 @@ class CardApi {
4125
4203
  else {
4126
4204
  resolve();
4127
4205
  }
4128
- slideBoxPrerender.classList.add(CardApi.renderedBoxClassName);
4206
+ slideBoxPrerender.classList.add(SlideApi.renderedBoxClassName);
4129
4207
  }
4130
4208
  else {
4131
4209
  resolve();
@@ -4964,424 +5042,6 @@ class CardApi {
4964
5042
  }
4965
5043
  }
4966
5044
  }
4967
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`{
4968
- sdkApi: SDKApi;
4969
- slideWrapper: HTMLElement;
4970
- viewport: Window;
4971
- userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
4972
- slideRatio: number;
4973
- isFullscreen: boolean;
4974
- getViewportWidth: () => number;
4975
- getViewportHeight: () => number;
4976
- overlappingActionBarHeight?: number;
4977
- separateUserAndAppPause: boolean;
4978
- root: HTMLElement;
4979
- nonce?: string;
4980
- refreshSizes: () => void;
4981
- index: number;
4982
- getSdkClientVariables: GetSdkClientVariables;
4983
- }`]; }
4984
- }
4985
-
4986
- class CardsSlider {
4987
- sdkApi;
4988
- constructor(sdkApi, config) {
4989
- this.sdkApi = sdkApi;
4990
- const slideWrapper = this.createSliderElement({ slides: config.cards, nonce: config.nonce, cardRender: config.cardRender });
4991
- // todo need to clear root node before append slideWrapper?
4992
- config.root.appendChild(slideWrapper);
4993
- // cardMounted: (card: HTMLElement) => Promise<void>
4994
- requestAnimationFrame(async () => {
4995
- for (let i = 0; i < this.cardsElements.length; ++i) {
4996
- await config.onCardMounted(this.cardsElements[i], i);
4997
- }
4998
- });
4999
- }
5000
- cardsElements = [];
5001
- sliderTrack = null;
5002
- createSliderElement = ({ slides, nonce, cardRender }) => {
5003
- const style = document.createElement("style");
5004
- if (nonce != null) {
5005
- style.nonce = nonce;
5006
- }
5007
- const slider = document.createElement("div");
5008
- slider.classList.add("cards-slider");
5009
- const track = document.createElement("div");
5010
- track.classList.add("cards-slider__track");
5011
- this.sliderTrack = track;
5012
- for (let i = 0; i < slides.length; ++i) {
5013
- const slide = document.createElement("div");
5014
- slide.classList.add("cards-slider__slide");
5015
- slide.setAttribute("data-index", String(i));
5016
- this.cardsElements[i] = cardRender(slides[i]);
5017
- slide.appendChild(this.cardsElements[i]);
5018
- track.appendChild(slide);
5019
- }
5020
- const bullets = document.createElement("div");
5021
- bullets.classList.add("cards-slider__bullets");
5022
- slider.appendChild(track);
5023
- slider.appendChild(bullets);
5024
- slider.appendChild(style);
5025
- return slider;
5026
- };
5027
- showByIndex(prevIndex, newIndex) {
5028
- const width = this.cardsElements[0].clientWidth;
5029
- let offset = 0;
5030
- // todo rtl ltr
5031
- // if (newIndex > prevIndex) {
5032
- offset = -1 * newIndex * width;
5033
- // } else {
5034
- // offset = newIndex * width;
5035
- // }
5036
- console.log({ prevIndex, newIndex, offset, width });
5037
- this.sliderTrack?.style.setProperty("transition", "transform 300ms");
5038
- setTimeout(() => {
5039
- this.sliderTrack?.style.setProperty("transition", "none");
5040
- }, 300);
5041
- this.sliderTrack?.style.setProperty("transform", `translateX(${offset}px)`);
5042
- }
5043
- static get [Symbol.for("___CTOR_ARGS___")]() { return [`SDKApi`, `{
5044
- cards: Array<string>;
5045
- root: HTMLElement;
5046
- // isFullscreen: boolean;
5047
- nonce?: string;
5048
- // viewport: Window;
5049
- // userResizeHandler?: (data: { viewportWidth: number; viewportHeight: number; fontSize: number }) => void;
5050
- // VODPlayer?: typeof VODPlayer;
5051
- // overlappingActionBarHeight?: number;
5052
- cardRender: (card: string) => HTMLElement;
5053
- onCardMounted: (card: HTMLElement, index: number) => Promise<void>;
5054
- }`]; }
5055
- }
5056
-
5057
- let SlideApi$1 = class SlideApi {
5058
- config;
5059
- get layoutDirection() {
5060
- return this.activeCard.layoutDirection;
5061
- }
5062
- static renderedBoxClassName = "narrative-slide-box-rendered";
5063
- static prerenderBoxClassName = "narrative-slide-box-prerender";
5064
- _singleCardSlideWrapper;
5065
- _viewport;
5066
- _getViewportWidth;
5067
- _getViewportHeight;
5068
- _overlappingActionBarHeight;
5069
- _separateUserAndAppPause;
5070
- sdkApi;
5071
- activeCard = null;
5072
- cards = [];
5073
- multiCardsMode = 0 /* MULTI_CARDS_MODE.SINGLE */;
5074
- constructor(config) {
5075
- this.config = config;
5076
- this.sdkApi = config.sdkApi;
5077
- this._singleCardSlideWrapper = config.slideWrapper;
5078
- this._viewport = config.viewport;
5079
- this._getViewportWidth = config.getViewportWidth;
5080
- this._getViewportHeight = config.getViewportHeight;
5081
- this._overlappingActionBarHeight = config.overlappingActionBarHeight ?? 0;
5082
- this._separateUserAndAppPause = config.separateUserAndAppPause;
5083
- this.refreshSizes = proxy(this.refreshSizes, this);
5084
- this.getSdkClientVariables = proxy(this.getSdkClientVariables, this);
5085
- // create card api instance, need for refreshSizes
5086
- // default mode - single slide
5087
- this.activeCard = new CardApi({
5088
- sdkApi: this.config.sdkApi,
5089
- slideWrapper: this.config.slideWrapper,
5090
- viewport: this.config.viewport,
5091
- userResizeHandler: this.config.userResizeHandler,
5092
- slideRatio: this.config.slideRatio,
5093
- isFullscreen: this.config.isFullscreen,
5094
- getViewportWidth: this.config.getViewportWidth,
5095
- getViewportHeight: this.config.getViewportHeight,
5096
- overlappingActionBarHeight: this.config.overlappingActionBarHeight,
5097
- separateUserAndAppPause: this.config.separateUserAndAppPause,
5098
- root: this.config.root,
5099
- refreshSizes: this.refreshSizes,
5100
- index: 0,
5101
- getSdkClientVariables: this.getSdkClientVariables,
5102
- });
5103
- this.activeCard.checkAndInitPreloadedInLayoutSlide(this.config.slideLoadedCb);
5104
- this.initListeners();
5105
- this.refreshSizes();
5106
- }
5107
- get state() {
5108
- // TODO remove usage from web-sdk
5109
- return this.activeCard.state;
5110
- }
5111
- async destroy() {
5112
- await this.activeCard.destroy();
5113
- await Promise.all(this.cards.map(card => {
5114
- if (card !== this.activeCard) {
5115
- return card.destroy();
5116
- }
5117
- }));
5118
- this.destroyListeners();
5119
- }
5120
- initListeners() {
5121
- this._viewport.addEventListener("resize", this.refreshSizes);
5122
- }
5123
- destroyListeners() {
5124
- this._viewport.removeEventListener("resize", this.refreshSizes);
5125
- }
5126
- _savedViewportWidth = null;
5127
- _savedViewportHeight = null;
5128
- refreshSizes() {
5129
- const viewportWidth = this._getViewportWidth();
5130
- const viewportHeight = this._getViewportHeight();
5131
- if (this._savedViewportWidth === viewportWidth && this._savedViewportHeight === viewportHeight) {
5132
- return;
5133
- }
5134
- this._savedViewportWidth = viewportWidth;
5135
- this._savedViewportHeight = viewportHeight;
5136
- const viewportRatio = viewportWidth / viewportHeight;
5137
- let slideWidth = 0;
5138
- let slideHeight = 0;
5139
- // _ratio = 310 / 480,
5140
- const _ratio = this.config.slideRatio;
5141
- let _isFullscreen = this.config.isFullscreen;
5142
- const slideOffset = this.activeCard.slideOffsetElement;
5143
- let offset = 0;
5144
- let xOffset = "0px";
5145
- // for elements with bottom anchor (absolute position)
5146
- let yOffset = "0px";
5147
- // alert(viewportHeight);
5148
- // todo - mobile only (or isIos or isAndroid)
5149
- if (this.sdkApi.isAndroid || this.sdkApi.isIOS) {
5150
- if (viewportRatio > _ratio) {
5151
- // disable _isFullscreen if viewport small
5152
- _isFullscreen = false;
5153
- }
5154
- }
5155
- if (_isFullscreen) {
5156
- // более квадратное чем надо (desktop)
5157
- if (viewportRatio > _ratio) {
5158
- // fit by height
5159
- slideHeight = viewportHeight;
5160
- slideWidth = Math.ceil(slideHeight * _ratio);
5161
- offset = Math.ceil(slideWidth - viewportWidth) / 2;
5162
- if (slideOffset != null) {
5163
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
5164
- }
5165
- xOffset = offset + "px";
5166
- }
5167
- else {
5168
- // fit by width, top and bottom - to offscreen or fill with bg image
5169
- slideWidth = viewportWidth;
5170
- slideHeight = Math.ceil(viewportWidth / _ratio);
5171
- offset = Math.ceil(slideHeight - viewportHeight) / 2;
5172
- if (slideOffset != null) {
5173
- slideOffset.style.margin = -1 * offset + "px" + " 0 ";
5174
- }
5175
- // offset from viewport bottom to StoryBottom plus safe area offset bottom
5176
- yOffset = `calc(${offset + this._overlappingActionBarHeight}px + env(safe-area-inset-bottom))`;
5177
- // detect safe area offset
5178
- }
5179
- }
5180
- else {
5181
- // более квадратное чем надо
5182
- if (viewportRatio > _ratio) {
5183
- // fit by width, top and bottom - to offscreen
5184
- slideWidth = viewportWidth;
5185
- slideHeight = Math.ceil(viewportWidth / _ratio);
5186
- offset = Math.ceil(slideHeight - viewportHeight) / 2;
5187
- if (slideOffset != null) {
5188
- slideOffset.style.margin = -offset + "px" + " 0 ";
5189
- }
5190
- yOffset = offset + this._overlappingActionBarHeight + "px";
5191
- }
5192
- else {
5193
- // вьюпорт более вытянутый чем надо
5194
- // fit by height, sides - to offscreen
5195
- slideHeight = viewportHeight;
5196
- slideWidth = Math.ceil(slideHeight * _ratio);
5197
- offset = Math.ceil(slideWidth - viewportWidth) / 2;
5198
- if (slideOffset != null) {
5199
- slideOffset.style.margin = "0 " + -offset + "px"; // -8.5
5200
- }
5201
- xOffset = offset + "px";
5202
- }
5203
- }
5204
- const fontSizeNumber = slideWidth / 20;
5205
- const fontSize = `${fontSizeNumber}px`;
5206
- this.activeCard.onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen: _isFullscreen });
5207
- this.cards.forEach(card => {
5208
- if (card !== this.activeCard) {
5209
- card.onUpdateSizeMetrics({ fontSize, xOffset, yOffset, isFullscreen: _isFullscreen });
5210
- }
5211
- });
5212
- if (this.config.userResizeHandler != null) {
5213
- this.config.userResizeHandler({ viewportWidth, viewportHeight, fontSize: fontSizeNumber });
5214
- }
5215
- }
5216
- async showSlide(html) {
5217
- this.multiCardsMode = 0 /* MULTI_CARDS_MODE.SINGLE */;
5218
- return this.activeCard.showSlide(html);
5219
- }
5220
- cardsSlider = null;
5221
- async showSlides(cards, cardAppearance) {
5222
- this.multiCardsMode = 1 /* MULTI_CARDS_MODE.MULTIPLE */;
5223
- const cardRender = (card) => {
5224
- const slideWrapper = document.createElement("div");
5225
- slideWrapper.classList.add("narrative-slide-wrapper");
5226
- slideWrapper.classList.add("stories-viewer");
5227
- const slideOffset = document.createElement("div");
5228
- slideOffset.classList.add("narrative-slide-offset");
5229
- const slideBoxPrerender = document.createElement("div");
5230
- slideBoxPrerender.classList.add("narrative-slide-box");
5231
- slideBoxPrerender.classList.add("narrative-slide-box-prerender");
5232
- const slideBoxRendered = document.createElement("div");
5233
- slideBoxRendered.classList.add("narrative-slide-box");
5234
- slideBoxRendered.classList.add("narrative-slide-box-rendered");
5235
- const style = document.createElement("style");
5236
- if (this.config.nonce != null) {
5237
- style.nonce = this.config.nonce;
5238
- }
5239
- const paddingTop = `${String(100 / this.config.slideRatio)}%`;
5240
- // .narrative-slide-box {
5241
- // padding: <?= $slideRatioPadding ?> 0 0 0;
5242
- // }
5243
- // style.sheet?.insertRule(`.narrative-slide-box {padding: ${paddingTop} 0 0 0;`);
5244
- slideBoxRendered.style.padding = `${paddingTop} 0 0 0`;
5245
- slideBoxPrerender.style.padding = `${paddingTop} 0 0 0`;
5246
- slideBoxPrerender.innerHTML = card;
5247
- slideOffset.appendChild(slideBoxPrerender);
5248
- slideOffset.appendChild(slideBoxRendered);
5249
- slideWrapper.appendChild(slideOffset);
5250
- slideWrapper.appendChild(style);
5251
- return slideWrapper;
5252
- };
5253
- let onShowActiveCardResolver = null;
5254
- const onShowActiveCard = new Promise(resolve => {
5255
- onShowActiveCardResolver = resolve;
5256
- });
5257
- const onCardMounted = async (card, index) => {
5258
- const cardApi = new CardApi({
5259
- sdkApi: this.config.sdkApi,
5260
- slideWrapper: card,
5261
- viewport: this.config.viewport,
5262
- userResizeHandler: this.config.userResizeHandler,
5263
- slideRatio: this.config.slideRatio,
5264
- isFullscreen: this.config.isFullscreen,
5265
- getViewportWidth: this.config.getViewportWidth,
5266
- getViewportHeight: this.config.getViewportHeight,
5267
- overlappingActionBarHeight: this.config.overlappingActionBarHeight,
5268
- separateUserAndAppPause: this.config.separateUserAndAppPause,
5269
- root: this.config.root,
5270
- refreshSizes: this.refreshSizes,
5271
- index,
5272
- getSdkClientVariables: this.getSdkClientVariables,
5273
- });
5274
- this.cards[index] = cardApi;
5275
- if (index === 0) {
5276
- this.activeCard = cardApi;
5277
- }
5278
- const result = await cardApi.showSlide();
5279
- onShowActiveCardResolver(result);
5280
- // console.log({ result, index });
5281
- };
5282
- this.cardsSlider = new CardsSlider(this.sdkApi, {
5283
- root: this.config.root,
5284
- cards,
5285
- nonce: this.config.nonce,
5286
- cardRender,
5287
- onCardMounted,
5288
- });
5289
- return await onShowActiveCard;
5290
- }
5291
- handleBackpress() {
5292
- this.activeCard.handleBackpress();
5293
- }
5294
- get layoutService() {
5295
- return container.get({ identifier: "LayoutService" });
5296
- }
5297
- getLocalData() {
5298
- return this.sdkApi.getCardLocalData();
5299
- }
5300
- async slideStart(config) {
5301
- return this.activeCard.slideStart(config);
5302
- }
5303
- async slideRestart(config) {
5304
- return this.activeCard.slideRestart(config);
5305
- }
5306
- async slideUserPause() {
5307
- return this.activeCard.slideUserPause();
5308
- }
5309
- async slideUserResume() {
5310
- return this.activeCard.slideUserResume();
5311
- }
5312
- /**
5313
- * Call on app gone background
5314
- */
5315
- async slideAppPause() {
5316
- return this.activeCard.slideAppPause();
5317
- }
5318
- /**
5319
- * Call on app gone foreground after a background
5320
- */
5321
- async slideAppResume() {
5322
- return this.activeCard.slideAppResume();
5323
- }
5324
- async slideStop(options) {
5325
- return this.activeCard.slideStop(options);
5326
- }
5327
- slideTimerEnd() {
5328
- this.activeCard.slideTimerEnd();
5329
- }
5330
- enableAudio() {
5331
- this.activeCard.enableAudio();
5332
- }
5333
- disableAudio() {
5334
- this.activeCard.disableAudio();
5335
- }
5336
- get isStopped() {
5337
- return this.activeCard.isStopped;
5338
- }
5339
- afterStartInitQueuePush(cb) {
5340
- return this.activeCard.afterStartInitQueuePush(cb);
5341
- }
5342
- afterAppResumeQueuePush(cb) {
5343
- return this.activeCard.afterAppResumeQueuePush(cb);
5344
- }
5345
- get activeLayer() {
5346
- return this.activeCard.slide.activeLayer;
5347
- }
5348
- get slide() {
5349
- return this.activeCard.slide;
5350
- }
5351
- showLayer(index) {
5352
- this.activeCard.showLayer(index);
5353
- }
5354
- slideClickHandler(targetElement, navigationDirection) {
5355
- const result = this.activeCard.slideClickHandler(targetElement, navigationDirection);
5356
- if (this.multiCardsMode === 1 /* MULTI_CARDS_MODE.MULTIPLE */) {
5357
- // handle nav click via CardsSlider, not via SDK
5358
- result.canClickNext = false;
5359
- const currentIndex = this.activeCard.index;
5360
- let index = navigationDirection === "forward" ? currentIndex + 1 : currentIndex - 1;
5361
- if (index >= this.cards.length) {
5362
- index = 0;
5363
- }
5364
- else if (index < 0) {
5365
- index = this.cards.length - 1;
5366
- }
5367
- // todo async
5368
- this.cardsSlider.showByIndex(currentIndex, index);
5369
- this.activeCard = this.cards[index];
5370
- }
5371
- return result;
5372
- }
5373
- slideSwipeUpHandler() {
5374
- return this.activeCard.slideSwipeUpHandler();
5375
- }
5376
- setTextInputResult(id, text) {
5377
- this.activeCard.setTextInputResult(id, text);
5378
- }
5379
- setShareComplete(id, isSuccess) {
5380
- this.activeCard.setShareComplete(id, isSuccess);
5381
- }
5382
- setWidgetGoodsComplete(elementId) {
5383
- this.activeCard.setWidgetGoodsComplete(elementId);
5384
- }
5385
5045
  _sdkClientVariables = {};
5386
5046
  getSdkClientVariables() {
5387
5047
  return this._sdkClientVariables;
@@ -5401,8 +5061,6 @@ let SlideApi$1 = class SlideApi {
5401
5061
  getViewportHeight: () => number;
5402
5062
  overlappingActionBarHeight?: number;
5403
5063
  separateUserAndAppPause: boolean;
5404
- root: HTMLElement;
5405
- nonce?: string;
5406
5064
  }`]; }
5407
5065
  };
5408
5066
 
@@ -5454,8 +5112,6 @@ class SlideApi extends SlideApi$1 {
5454
5112
  getViewportHeight: () => slideWrapper.clientHeight,
5455
5113
  overlappingActionBarHeight: config.overlappingActionBarHeight,
5456
5114
  separateUserAndAppPause: true,
5457
- root: config.root,
5458
- nonce: config.nonce,
5459
5115
  });
5460
5116
  this.root = config.root;
5461
5117
  this.slideWrapper = slideWrapper;
@@ -17652,13 +17308,12 @@ class WidgetProducts extends WidgetBase {
17652
17308
  if (!this.linkTarget.length) {
17653
17309
  return { message: this.msgServiceError ?? "", models: [] };
17654
17310
  }
17655
- const searchParams = new URLSearchParams();
17656
- searchParams.set("id", this.linkTarget.join(","));
17311
+ let qs = `id=${this.linkTarget.join(",")}`;
17657
17312
  const sdkClientVariables = this.widgetDeps.getSdkClientVariables();
17658
17313
  if (sdkClientVariables != null && sdkClientVariables.pos != null) {
17659
- searchParams.set("pos", String(sdkClientVariables.pos));
17314
+ qs += `&pos=${String(sdkClientVariables.pos)}`;
17660
17315
  }
17661
- const path = `product/offer?${searchParams.toString()}`;
17316
+ const path = `product/offer?${qs}`;
17662
17317
  const headers = {
17663
17318
  accept: "application/json",
17664
17319
  "Content-Type": "application/json",