eat-js-sdk 2.0.50 → 2.0.51

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",
@@ -7789,14 +7793,25 @@ function getDynamicMarginTop(containerElement) {
7789
7793
  return "margin-top: 0px";
7790
7794
  }
7791
7795
  const windowHeight = window.innerHeight;
7792
- const contentHeight = containerElement.scrollHeight;
7793
- const offsetTop = containerElement.offsetTop;
7794
- const availableSpace = windowHeight - offsetTop;
7795
- if (availableSpace <= 0 || contentHeight <= 0) {
7796
+ let contentHeight = containerElement.scrollHeight;
7797
+ const rect = containerElement.getBoundingClientRect();
7798
+ const images = containerElement.querySelectorAll("img");
7799
+ const hasUnloadedImages = Array.from(images).some((img) => !img.complete);
7800
+ if (hasUnloadedImages && images.length > 0) {
7801
+ const firstImg = images[0];
7802
+ const estimatedImgHeight = firstImg.naturalHeight || LAYOUT_CONFIG.DEFAULT_IMAGE_HEIGHT;
7803
+ contentHeight = Math.max(contentHeight, estimatedImgHeight + LAYOUT_CONFIG.IMAGE_PADDING);
7804
+ }
7805
+ if (contentHeight <= 0) {
7796
7806
  return "margin-top: 0px";
7797
7807
  }
7798
- const marginTop = Math.max(0, (availableSpace - contentHeight) / 2);
7799
- return `margin-top: ${marginTop}px`;
7808
+ const containerTop = rect.top;
7809
+ const availableSpace = windowHeight - containerTop;
7810
+ if (contentHeight < availableSpace) {
7811
+ const marginTop = (availableSpace - contentHeight) / 2;
7812
+ return `margin-top: ${Math.max(0, marginTop)}px`;
7813
+ }
7814
+ return "margin-top: 0px";
7800
7815
  }
7801
7816
  function getWindowHeight() {
7802
7817
  if (typeof window === "undefined") {
@@ -8576,32 +8591,11 @@ function PromptContainer($$anchor, $$props) {
8576
8591
  let windowHeight = getWindowHeight();
8577
8592
  let contentLoader = /* @__PURE__ */ user_derived(() => useContentLoader(get$1(containerElement)));
8578
8593
  let dynamicMarginTop = /* @__PURE__ */ state("margin-top: 0px");
8579
- const RESIZE_DEBOUNCE_DELAY = 150;
8580
- user_effect(() => {
8581
- if (windowHeight.value > 0 && get$1(containerElement) && get$1(contentLoader).isLoaded) {
8582
- set(dynamicMarginTop, getDynamicMarginTop(get$1(containerElement)), true);
8583
- }
8584
- });
8585
8594
  user_effect(() => {
8586
8595
  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
- };
8596
+ requestAnimationFrame(() => {
8597
+ set(dynamicMarginTop, getDynamicMarginTop(get$1(containerElement)), true);
8598
+ });
8605
8599
  }
8606
8600
  });
8607
8601
  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.51",
4
4
  "change version": "2.0.0",
5
5
  "description": "Authoring tool frontend SDK",
6
6
  "contributors": [