@yoamigo.com/core 0.3.12 → 0.3.13

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
@@ -901,7 +901,7 @@ var BuilderSelectionManager = class {
901
901
  if (window.location.pathname !== pagePath) {
902
902
  await this.navigateAndWait(pagePath);
903
903
  }
904
- await new Promise((resolve) => setTimeout(resolve, 100));
904
+ await this.waitForPageContent();
905
905
  const buffer = await this.capturePageAsArrayBuffer();
906
906
  if (buffer) {
907
907
  this.sendToParent(
@@ -948,6 +948,34 @@ var BuilderSelectionManager = class {
948
948
  });
949
949
  });
950
950
  }
951
+ /**
952
+ * Wait for page content to be rendered (scrollHeight > 0)
953
+ * Polls until content appears or timeout (max 2 seconds)
954
+ */
955
+ async waitForPageContent() {
956
+ const MAX_WAIT_MS = 2e3;
957
+ const POLL_INTERVAL_MS = 50;
958
+ const startTime = Date.now();
959
+ while (Date.now() - startTime < MAX_WAIT_MS) {
960
+ const height = this.getPageHeight();
961
+ if (height > 0) {
962
+ await new Promise((resolve) => requestAnimationFrame(resolve));
963
+ return;
964
+ }
965
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
966
+ }
967
+ console.warn("[BuilderSelection] waitForPageContent timed out - page may not have rendered");
968
+ }
969
+ /**
970
+ * Get page height using multiple fallbacks
971
+ */
972
+ getPageHeight() {
973
+ const bodyScrollHeight = document.body?.scrollHeight || 0;
974
+ const docScrollHeight = document.documentElement?.scrollHeight || 0;
975
+ const bodyOffsetHeight = document.body?.offsetHeight || 0;
976
+ const docOffsetHeight = document.documentElement?.offsetHeight || 0;
977
+ return Math.max(bodyScrollHeight, docScrollHeight, bodyOffsetHeight, docOffsetHeight);
978
+ }
951
979
  /**
952
980
  * Capture current page as ArrayBuffer (for zero-copy transfer)
953
981
  */
@@ -959,8 +987,12 @@ var BuilderSelectionManager = class {
959
987
  ;
960
988
  el.style.display = "none";
961
989
  });
962
- const scrollHeight = document.body.scrollHeight;
990
+ const scrollHeight = this.getPageHeight();
963
991
  console.log("[BuilderSelection] capturePageAsArrayBuffer - scrollHeight:", scrollHeight);
992
+ if (scrollHeight === 0) {
993
+ console.warn("[BuilderSelection] Skipping capture - page has no height");
994
+ return null;
995
+ }
964
996
  const canvas = await html2canvas(document.body, {
965
997
  scale: 1,
966
998
  // Full resolution
package/dist/lib.js CHANGED
@@ -860,7 +860,7 @@ var BuilderSelectionManager = class {
860
860
  if (window.location.pathname !== pagePath) {
861
861
  await this.navigateAndWait(pagePath);
862
862
  }
863
- await new Promise((resolve) => setTimeout(resolve, 100));
863
+ await this.waitForPageContent();
864
864
  const buffer = await this.capturePageAsArrayBuffer();
865
865
  if (buffer) {
866
866
  this.sendToParent(
@@ -907,6 +907,34 @@ var BuilderSelectionManager = class {
907
907
  });
908
908
  });
909
909
  }
910
+ /**
911
+ * Wait for page content to be rendered (scrollHeight > 0)
912
+ * Polls until content appears or timeout (max 2 seconds)
913
+ */
914
+ async waitForPageContent() {
915
+ const MAX_WAIT_MS = 2e3;
916
+ const POLL_INTERVAL_MS = 50;
917
+ const startTime = Date.now();
918
+ while (Date.now() - startTime < MAX_WAIT_MS) {
919
+ const height = this.getPageHeight();
920
+ if (height > 0) {
921
+ await new Promise((resolve) => requestAnimationFrame(resolve));
922
+ return;
923
+ }
924
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
925
+ }
926
+ console.warn("[BuilderSelection] waitForPageContent timed out - page may not have rendered");
927
+ }
928
+ /**
929
+ * Get page height using multiple fallbacks
930
+ */
931
+ getPageHeight() {
932
+ const bodyScrollHeight = document.body?.scrollHeight || 0;
933
+ const docScrollHeight = document.documentElement?.scrollHeight || 0;
934
+ const bodyOffsetHeight = document.body?.offsetHeight || 0;
935
+ const docOffsetHeight = document.documentElement?.offsetHeight || 0;
936
+ return Math.max(bodyScrollHeight, docScrollHeight, bodyOffsetHeight, docOffsetHeight);
937
+ }
910
938
  /**
911
939
  * Capture current page as ArrayBuffer (for zero-copy transfer)
912
940
  */
@@ -918,8 +946,12 @@ var BuilderSelectionManager = class {
918
946
  ;
919
947
  el.style.display = "none";
920
948
  });
921
- const scrollHeight = document.body.scrollHeight;
949
+ const scrollHeight = this.getPageHeight();
922
950
  console.log("[BuilderSelection] capturePageAsArrayBuffer - scrollHeight:", scrollHeight);
951
+ if (scrollHeight === 0) {
952
+ console.warn("[BuilderSelection] Skipping capture - page has no height");
953
+ return null;
954
+ }
923
955
  const canvas = await html2canvas(document.body, {
924
956
  scale: 1,
925
957
  // Full resolution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoamigo.com/core",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "Core components, router, and utilities for YoAmigo templates",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",