@yoamigo.com/core 0.3.12 → 0.3.14

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