@yoamigo.com/core 0.3.11 → 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 +53 -11
- package/dist/lib.js +53 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -697,7 +697,6 @@ var BuilderSelectionManager = class {
|
|
|
697
697
|
// Full resolution
|
|
698
698
|
logging: false,
|
|
699
699
|
useCORS: true,
|
|
700
|
-
allowTaint: true,
|
|
701
700
|
backgroundColor: null,
|
|
702
701
|
// No background - preserve page's actual background
|
|
703
702
|
windowHeight: document.body.scrollHeight,
|
|
@@ -753,7 +752,6 @@ var BuilderSelectionManager = class {
|
|
|
753
752
|
scale: 1,
|
|
754
753
|
logging: false,
|
|
755
754
|
useCORS: true,
|
|
756
|
-
allowTaint: true,
|
|
757
755
|
backgroundColor: null
|
|
758
756
|
// Preserve transparency if any
|
|
759
757
|
});
|
|
@@ -903,7 +901,7 @@ var BuilderSelectionManager = class {
|
|
|
903
901
|
if (window.location.pathname !== pagePath) {
|
|
904
902
|
await this.navigateAndWait(pagePath);
|
|
905
903
|
}
|
|
906
|
-
await
|
|
904
|
+
await this.waitForPageContent();
|
|
907
905
|
const buffer = await this.capturePageAsArrayBuffer();
|
|
908
906
|
if (buffer) {
|
|
909
907
|
this.sendToParent(
|
|
@@ -950,6 +948,34 @@ var BuilderSelectionManager = class {
|
|
|
950
948
|
});
|
|
951
949
|
});
|
|
952
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
|
+
}
|
|
953
979
|
/**
|
|
954
980
|
* Capture current page as ArrayBuffer (for zero-copy transfer)
|
|
955
981
|
*/
|
|
@@ -961,36 +987,50 @@ var BuilderSelectionManager = class {
|
|
|
961
987
|
;
|
|
962
988
|
el.style.display = "none";
|
|
963
989
|
});
|
|
990
|
+
const scrollHeight = this.getPageHeight();
|
|
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
|
|
967
|
-
logging:
|
|
999
|
+
logging: true,
|
|
1000
|
+
// Enable logging for debugging
|
|
968
1001
|
useCORS: true,
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
windowHeight: document.body.scrollHeight,
|
|
1002
|
+
backgroundColor: "#ffffff",
|
|
1003
|
+
// White background to avoid transparent canvas issues
|
|
1004
|
+
windowHeight: scrollHeight,
|
|
973
1005
|
// Full page height
|
|
974
|
-
height:
|
|
1006
|
+
height: scrollHeight,
|
|
975
1007
|
scrollX: 0,
|
|
976
1008
|
// Render from left (no visible scroll)
|
|
977
1009
|
scrollY: 0,
|
|
978
1010
|
// Render from top (no visible scroll)
|
|
979
1011
|
onclone: async (clonedDoc) => {
|
|
980
|
-
|
|
1012
|
+
console.log("[BuilderSelection] onclone called");
|
|
1013
|
+
const lazyImages = clonedDoc.querySelectorAll('img[loading="lazy"]');
|
|
1014
|
+
console.log("[BuilderSelection] Found lazy images:", lazyImages.length);
|
|
1015
|
+
lazyImages.forEach((img) => {
|
|
981
1016
|
img.removeAttribute("loading");
|
|
982
1017
|
});
|
|
1018
|
+
const allImages = Array.from(clonedDoc.querySelectorAll("img"));
|
|
1019
|
+
console.log("[BuilderSelection] Total images to wait for:", allImages.length);
|
|
983
1020
|
await Promise.all(
|
|
984
|
-
|
|
1021
|
+
allImages.map(
|
|
985
1022
|
(img) => img.complete && img.naturalHeight !== 0 ? Promise.resolve() : new Promise((r) => {
|
|
986
1023
|
img.onload = r;
|
|
987
1024
|
img.onerror = r;
|
|
988
1025
|
})
|
|
989
1026
|
)
|
|
990
1027
|
);
|
|
1028
|
+
console.log("[BuilderSelection] All images loaded");
|
|
991
1029
|
await clonedDoc.fonts?.ready;
|
|
1030
|
+
console.log("[BuilderSelection] Fonts ready");
|
|
992
1031
|
}
|
|
993
1032
|
});
|
|
1033
|
+
console.log("[BuilderSelection] Canvas created:", canvas.width, "x", canvas.height);
|
|
994
1034
|
overlays.forEach((el) => {
|
|
995
1035
|
;
|
|
996
1036
|
el.style.display = "";
|
|
@@ -1002,7 +1042,9 @@ var BuilderSelectionManager = class {
|
|
|
1002
1042
|
console.error("[BuilderSelection] Failed to create blob from canvas");
|
|
1003
1043
|
return null;
|
|
1004
1044
|
}
|
|
1045
|
+
console.log("[BuilderSelection] Blob created, size:", blob.size, "bytes");
|
|
1005
1046
|
const buffer = await blob.arrayBuffer();
|
|
1047
|
+
console.log("[BuilderSelection] ArrayBuffer ready, size:", buffer.byteLength);
|
|
1006
1048
|
return buffer;
|
|
1007
1049
|
} catch (error) {
|
|
1008
1050
|
console.error("[BuilderSelection] Page capture failed:", error);
|
package/dist/lib.js
CHANGED
|
@@ -656,7 +656,6 @@ var BuilderSelectionManager = class {
|
|
|
656
656
|
// Full resolution
|
|
657
657
|
logging: false,
|
|
658
658
|
useCORS: true,
|
|
659
|
-
allowTaint: true,
|
|
660
659
|
backgroundColor: null,
|
|
661
660
|
// No background - preserve page's actual background
|
|
662
661
|
windowHeight: document.body.scrollHeight,
|
|
@@ -712,7 +711,6 @@ var BuilderSelectionManager = class {
|
|
|
712
711
|
scale: 1,
|
|
713
712
|
logging: false,
|
|
714
713
|
useCORS: true,
|
|
715
|
-
allowTaint: true,
|
|
716
714
|
backgroundColor: null
|
|
717
715
|
// Preserve transparency if any
|
|
718
716
|
});
|
|
@@ -862,7 +860,7 @@ var BuilderSelectionManager = class {
|
|
|
862
860
|
if (window.location.pathname !== pagePath) {
|
|
863
861
|
await this.navigateAndWait(pagePath);
|
|
864
862
|
}
|
|
865
|
-
await
|
|
863
|
+
await this.waitForPageContent();
|
|
866
864
|
const buffer = await this.capturePageAsArrayBuffer();
|
|
867
865
|
if (buffer) {
|
|
868
866
|
this.sendToParent(
|
|
@@ -909,6 +907,34 @@ var BuilderSelectionManager = class {
|
|
|
909
907
|
});
|
|
910
908
|
});
|
|
911
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
|
+
}
|
|
912
938
|
/**
|
|
913
939
|
* Capture current page as ArrayBuffer (for zero-copy transfer)
|
|
914
940
|
*/
|
|
@@ -920,36 +946,50 @@ var BuilderSelectionManager = class {
|
|
|
920
946
|
;
|
|
921
947
|
el.style.display = "none";
|
|
922
948
|
});
|
|
949
|
+
const scrollHeight = this.getPageHeight();
|
|
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
|
|
926
|
-
logging:
|
|
958
|
+
logging: true,
|
|
959
|
+
// Enable logging for debugging
|
|
927
960
|
useCORS: true,
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
windowHeight: document.body.scrollHeight,
|
|
961
|
+
backgroundColor: "#ffffff",
|
|
962
|
+
// White background to avoid transparent canvas issues
|
|
963
|
+
windowHeight: scrollHeight,
|
|
932
964
|
// Full page height
|
|
933
|
-
height:
|
|
965
|
+
height: scrollHeight,
|
|
934
966
|
scrollX: 0,
|
|
935
967
|
// Render from left (no visible scroll)
|
|
936
968
|
scrollY: 0,
|
|
937
969
|
// Render from top (no visible scroll)
|
|
938
970
|
onclone: async (clonedDoc) => {
|
|
939
|
-
|
|
971
|
+
console.log("[BuilderSelection] onclone called");
|
|
972
|
+
const lazyImages = clonedDoc.querySelectorAll('img[loading="lazy"]');
|
|
973
|
+
console.log("[BuilderSelection] Found lazy images:", lazyImages.length);
|
|
974
|
+
lazyImages.forEach((img) => {
|
|
940
975
|
img.removeAttribute("loading");
|
|
941
976
|
});
|
|
977
|
+
const allImages = Array.from(clonedDoc.querySelectorAll("img"));
|
|
978
|
+
console.log("[BuilderSelection] Total images to wait for:", allImages.length);
|
|
942
979
|
await Promise.all(
|
|
943
|
-
|
|
980
|
+
allImages.map(
|
|
944
981
|
(img) => img.complete && img.naturalHeight !== 0 ? Promise.resolve() : new Promise((r) => {
|
|
945
982
|
img.onload = r;
|
|
946
983
|
img.onerror = r;
|
|
947
984
|
})
|
|
948
985
|
)
|
|
949
986
|
);
|
|
987
|
+
console.log("[BuilderSelection] All images loaded");
|
|
950
988
|
await clonedDoc.fonts?.ready;
|
|
989
|
+
console.log("[BuilderSelection] Fonts ready");
|
|
951
990
|
}
|
|
952
991
|
});
|
|
992
|
+
console.log("[BuilderSelection] Canvas created:", canvas.width, "x", canvas.height);
|
|
953
993
|
overlays.forEach((el) => {
|
|
954
994
|
;
|
|
955
995
|
el.style.display = "";
|
|
@@ -961,7 +1001,9 @@ var BuilderSelectionManager = class {
|
|
|
961
1001
|
console.error("[BuilderSelection] Failed to create blob from canvas");
|
|
962
1002
|
return null;
|
|
963
1003
|
}
|
|
1004
|
+
console.log("[BuilderSelection] Blob created, size:", blob.size, "bytes");
|
|
964
1005
|
const buffer = await blob.arrayBuffer();
|
|
1006
|
+
console.log("[BuilderSelection] ArrayBuffer ready, size:", buffer.byteLength);
|
|
965
1007
|
return buffer;
|
|
966
1008
|
} catch (error) {
|
|
967
1009
|
console.error("[BuilderSelection] Page capture failed:", error);
|