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