eat-js-sdk 2.0.50 → 2.0.52

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.
@@ -5151,6 +5151,10 @@ const BREAKPOINTS = {
5151
5151
  MD: 732,
5152
5152
  LG: 1196
5153
5153
  };
5154
+ const LAYOUT_CONFIG = {
5155
+ DEFAULT_IMAGE_HEIGHT: 200,
5156
+ IMAGE_PADDING: 200
5157
+ };
5154
5158
  const STIMULUS_MAX_WORD_LENGTH_BEFORE_OVERFLOW = 80;
5155
5159
  const MODES = {
5156
5160
  SESSION: "session",
@@ -7790,30 +7794,37 @@ function getDynamicMarginTop(containerElement) {
7790
7794
  }
7791
7795
  const windowHeight = window.innerHeight;
7792
7796
  const contentHeight = containerElement.scrollHeight;
7793
- const offsetTop = containerElement.offsetTop;
7794
- const availableSpace = windowHeight - offsetTop;
7795
- if (availableSpace <= 0 || contentHeight <= 0) {
7797
+ if (contentHeight <= 0 || windowHeight <= 0) {
7796
7798
  return "margin-top: 0px";
7797
7799
  }
7798
- const marginTop = Math.max(0, (availableSpace - contentHeight) / 2);
7799
- return `margin-top: ${marginTop}px`;
7800
+ const rect = containerElement.getBoundingClientRect();
7801
+ const images = containerElement.querySelectorAll("img");
7802
+ const hasUnloadedImages = Array.from(images).some((img) => !img.complete);
7803
+ let adjustedHeight = contentHeight;
7804
+ if (hasUnloadedImages && images.length > 0) {
7805
+ const firstImg = images[0];
7806
+ const estimatedImgHeight = firstImg.naturalHeight || LAYOUT_CONFIG.DEFAULT_IMAGE_HEIGHT;
7807
+ adjustedHeight = Math.max(contentHeight, estimatedImgHeight + LAYOUT_CONFIG.IMAGE_PADDING);
7808
+ }
7809
+ const containerTop = rect.top;
7810
+ const availableSpace = windowHeight - containerTop;
7811
+ if (adjustedHeight < availableSpace) {
7812
+ const marginTop = (availableSpace - adjustedHeight) / 2;
7813
+ return `margin-top: ${Math.max(0, marginTop)}px`;
7814
+ }
7815
+ return "margin-top: 0px";
7800
7816
  }
7801
7817
  function getWindowHeight() {
7802
7818
  if (typeof window === "undefined") {
7803
7819
  return { value: 0, cleanup: () => {
7804
7820
  } };
7805
7821
  }
7806
- let height = /* @__PURE__ */ state(proxy(window.innerHeight));
7807
- const updateHeight = () => {
7808
- set(height, window.innerHeight, true);
7809
- };
7810
- window.addEventListener("resize", updateHeight);
7822
+ let height = proxy(window.innerHeight);
7811
7823
  return {
7812
7824
  get value() {
7813
- return get$1(height);
7825
+ return height;
7814
7826
  },
7815
7827
  cleanup: () => {
7816
- window.removeEventListener("resize", updateHeight);
7817
7828
  }
7818
7829
  };
7819
7830
  }
@@ -8576,32 +8587,11 @@ function PromptContainer($$anchor, $$props) {
8576
8587
  let windowHeight = getWindowHeight();
8577
8588
  let contentLoader = /* @__PURE__ */ user_derived(() => useContentLoader(get$1(containerElement)));
8578
8589
  let dynamicMarginTop = /* @__PURE__ */ state("margin-top: 0px");
8579
- const RESIZE_DEBOUNCE_DELAY = 150;
8580
8590
  user_effect(() => {
8581
8591
  if (windowHeight.value > 0 && get$1(containerElement) && get$1(contentLoader).isLoaded) {
8582
- set(dynamicMarginTop, getDynamicMarginTop(get$1(containerElement)), true);
8583
- }
8584
- });
8585
- user_effect(() => {
8586
- if (windowHeight.value > 0 && get$1(containerElement) && get$1(contentLoader).isLoaded) {
8587
- let resizeTimeout;
8588
- const handleResize = () => {
8589
- clearTimeout(resizeTimeout);
8590
- resizeTimeout = window.setTimeout(
8591
- () => {
8592
- const newMargin = getDynamicMarginTop(get$1(containerElement));
8593
- if (newMargin !== get$1(dynamicMarginTop)) {
8594
- set(dynamicMarginTop, newMargin, true);
8595
- }
8596
- },
8597
- RESIZE_DEBOUNCE_DELAY
8598
- );
8599
- };
8600
- window.addEventListener("resize", handleResize);
8601
- return () => {
8602
- clearTimeout(resizeTimeout);
8603
- window.removeEventListener("resize", handleResize);
8604
- };
8592
+ requestAnimationFrame(() => {
8593
+ set(dynamicMarginTop, getDynamicMarginTop(get$1(containerElement)), true);
8594
+ });
8605
8595
  }
8606
8596
  });
8607
8597
  let isStimulusModalOpen = /* @__PURE__ */ state(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eat-js-sdk",
3
- "version": "2.0.50",
3
+ "version": "2.0.52",
4
4
  "change version": "2.0.0",
5
5
  "description": "Authoring tool frontend SDK",
6
6
  "contributors": [