@skrillex1224/playwright-toolkit 2.1.237 → 2.1.238
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.cjs +85 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +85 -0
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -749,6 +749,84 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
749
749
|
expandDocumentElements: options.expandDocumentElements === true
|
|
750
750
|
});
|
|
751
751
|
};
|
|
752
|
+
var pinBottomAffixedElements = async (page, options = {}) => {
|
|
753
|
+
return await page.evaluate(({ className, targetHeight }) => {
|
|
754
|
+
const viewportHeight = window.innerHeight || document.documentElement?.clientHeight || document.body?.clientHeight || 0;
|
|
755
|
+
const safeTargetHeight = Math.ceil(Number(targetHeight) || 0);
|
|
756
|
+
const deltaY = safeTargetHeight - viewportHeight;
|
|
757
|
+
if (deltaY <= 1) {
|
|
758
|
+
return 0;
|
|
759
|
+
}
|
|
760
|
+
const isVisible = (el, style, rect) => {
|
|
761
|
+
if (!el || !style || !rect) return false;
|
|
762
|
+
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
if (Number(style.opacity) === 0) return false;
|
|
766
|
+
return rect.width > 0 && rect.height > 0;
|
|
767
|
+
};
|
|
768
|
+
const bottomThreshold = Math.max(24, Math.min(96, viewportHeight * 0.12));
|
|
769
|
+
const maxAffixedHeight = Math.max(56, viewportHeight * 0.65);
|
|
770
|
+
const candidates = [];
|
|
771
|
+
document.querySelectorAll("*").forEach((el) => {
|
|
772
|
+
const style = window.getComputedStyle(el);
|
|
773
|
+
const position = String(style.position || "").toLowerCase();
|
|
774
|
+
if (position !== "fixed" && position !== "sticky") return;
|
|
775
|
+
const rect = el.getBoundingClientRect();
|
|
776
|
+
if (!isVisible(el, style, rect)) return;
|
|
777
|
+
if (rect.height > maxAffixedHeight) return;
|
|
778
|
+
if (rect.bottom < viewportHeight - bottomThreshold) return;
|
|
779
|
+
const bottom = Number.parseFloat(style.bottom);
|
|
780
|
+
const hasBottomRule = Number.isFinite(bottom) && bottom <= Math.max(160, viewportHeight * 0.25);
|
|
781
|
+
const isNearViewportBottom = rect.bottom >= viewportHeight - bottomThreshold;
|
|
782
|
+
if (!hasBottomRule && !isNearViewportBottom) return;
|
|
783
|
+
candidates.push(el);
|
|
784
|
+
});
|
|
785
|
+
const candidateSet = new Set(candidates);
|
|
786
|
+
const topLevelCandidates = candidates.filter((el) => {
|
|
787
|
+
for (let parent = el.parentElement; parent; parent = parent.parentElement) {
|
|
788
|
+
if (candidateSet.has(parent)) return false;
|
|
789
|
+
}
|
|
790
|
+
return true;
|
|
791
|
+
});
|
|
792
|
+
topLevelCandidates.forEach((el) => {
|
|
793
|
+
if (!Object.prototype.hasOwnProperty.call(el.dataset, "pkBottomPinned")) {
|
|
794
|
+
el.dataset.pkBottomPinned = "1";
|
|
795
|
+
el.dataset.pkOrigTranslate = el.style.getPropertyValue("translate") || "";
|
|
796
|
+
el.dataset.pkOrigTranslatePriority = el.style.getPropertyPriority("translate") || "";
|
|
797
|
+
}
|
|
798
|
+
el.classList.add(className);
|
|
799
|
+
el.style.setProperty("translate", `0 ${Math.round(deltaY)}px`, "important");
|
|
800
|
+
});
|
|
801
|
+
return topLevelCandidates.length;
|
|
802
|
+
}, {
|
|
803
|
+
className: EXPANDED_SCROLLABLE_CLASS,
|
|
804
|
+
targetHeight: options.targetHeight
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
var restoreBottomAffixedElements = async (page) => {
|
|
808
|
+
await page.evaluate((className) => {
|
|
809
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
810
|
+
const expansionKeys = [
|
|
811
|
+
"pkOrigOverflow",
|
|
812
|
+
"pkOrigHeight",
|
|
813
|
+
"pkOrigMinHeight",
|
|
814
|
+
"pkOrigMaxHeight"
|
|
815
|
+
];
|
|
816
|
+
document.querySelectorAll('[data-pk-bottom-pinned="1"]').forEach((el) => {
|
|
817
|
+
if (hasOwn(el.dataset, "pkOrigTranslate")) {
|
|
818
|
+
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
819
|
+
delete el.dataset.pkOrigTranslate;
|
|
820
|
+
delete el.dataset.pkOrigTranslatePriority;
|
|
821
|
+
}
|
|
822
|
+
delete el.dataset.pkBottomPinned;
|
|
823
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn(el.dataset, key));
|
|
824
|
+
if (!stillExpanded) {
|
|
825
|
+
el.classList.remove(className);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
}, EXPANDED_SCROLLABLE_CLASS);
|
|
829
|
+
};
|
|
752
830
|
var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
753
831
|
const originalViewport = await resolveCurrentViewportSize(page);
|
|
754
832
|
const maxHeight = toPositiveInteger(options.maxHeight, DEFAULT_MAX_HEIGHT);
|
|
@@ -769,6 +847,10 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
769
847
|
height: targetHeight
|
|
770
848
|
});
|
|
771
849
|
viewportResized = true;
|
|
850
|
+
} else {
|
|
851
|
+
await pinBottomAffixedElements(page, { targetHeight }).catch((error) => {
|
|
852
|
+
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u5E95\u5143\u7D20\u91CD\u5B9A\u4F4D\u5931\u8D25: ${error?.message || error}`);
|
|
853
|
+
});
|
|
772
854
|
}
|
|
773
855
|
if (settleMs > 0) {
|
|
774
856
|
await (0, import_delay.default)(settleMs);
|
|
@@ -873,6 +955,9 @@ var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
873
955
|
maxClipHeight: state.targetHeight
|
|
874
956
|
});
|
|
875
957
|
} finally {
|
|
958
|
+
await restoreBottomAffixedElements(page).catch((error) => {
|
|
959
|
+
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u5E95\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
960
|
+
});
|
|
876
961
|
if (options.restore) {
|
|
877
962
|
await restoreExpandedFullPageScreenshot(page, state);
|
|
878
963
|
}
|