@skrillex1224/playwright-toolkit 2.1.228 → 2.1.230
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 +92 -54
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +92 -54
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -580,6 +580,21 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
580
580
|
const scrollableOverflow = /* @__PURE__ */ new Set(["auto", "scroll", "overlay"]);
|
|
581
581
|
return scrollableOverflow.has(overflowY) || scrollableOverflow.has(overflow);
|
|
582
582
|
};
|
|
583
|
+
const measureNeededHeight = (el) => {
|
|
584
|
+
if (!el) return 0;
|
|
585
|
+
const scrollHeight = Math.ceil(el.scrollHeight || 0);
|
|
586
|
+
if (scrollHeight <= 0) return 0;
|
|
587
|
+
if (isDocumentElement(el)) {
|
|
588
|
+
return scrollHeight;
|
|
589
|
+
}
|
|
590
|
+
const rect = el.getBoundingClientRect();
|
|
591
|
+
if (!rect || rect.width <= 0 || rect.height <= 0) {
|
|
592
|
+
return 0;
|
|
593
|
+
}
|
|
594
|
+
const documentTop = Math.max(0, Math.ceil(rect.top + (window.scrollY || window.pageYOffset || 0)));
|
|
595
|
+
return documentTop + scrollHeight;
|
|
596
|
+
};
|
|
597
|
+
const scrollableElements = [];
|
|
583
598
|
candidates.forEach((el) => {
|
|
584
599
|
const style = window.getComputedStyle(el);
|
|
585
600
|
const rect = el.getBoundingClientRect();
|
|
@@ -589,13 +604,14 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
589
604
|
if (!isScrollableY(el, style)) {
|
|
590
605
|
return;
|
|
591
606
|
}
|
|
592
|
-
const
|
|
593
|
-
if (
|
|
607
|
+
const neededHeight = measureNeededHeight(el);
|
|
608
|
+
if (neededHeight <= 0) {
|
|
594
609
|
return;
|
|
595
610
|
}
|
|
596
|
-
if (
|
|
597
|
-
maxHeight =
|
|
611
|
+
if (neededHeight > maxHeight) {
|
|
612
|
+
maxHeight = neededHeight;
|
|
598
613
|
}
|
|
614
|
+
scrollableElements.push(el);
|
|
599
615
|
if (isDocumentElement(el)) {
|
|
600
616
|
return;
|
|
601
617
|
}
|
|
@@ -611,6 +627,7 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
611
627
|
el.classList.add(className);
|
|
612
628
|
}
|
|
613
629
|
if (forceScrollableHeight) {
|
|
630
|
+
const scrollHeight = Math.ceil(el.scrollHeight || 0);
|
|
614
631
|
el.style.setProperty("overflow", "visible", "important");
|
|
615
632
|
el.style.setProperty("height", `${scrollHeight}px`, "important");
|
|
616
633
|
el.style.setProperty("min-height", `${scrollHeight}px`, "important");
|
|
@@ -621,10 +638,16 @@ var expandScrollableContent = async (page, options = {}) => {
|
|
|
621
638
|
el.style.height = "auto";
|
|
622
639
|
el.style.maxHeight = "none";
|
|
623
640
|
});
|
|
641
|
+
scrollableElements.forEach((el) => {
|
|
642
|
+
const neededHeight = measureNeededHeight(el);
|
|
643
|
+
if (neededHeight > maxHeight) {
|
|
644
|
+
maxHeight = neededHeight;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
624
647
|
return maxHeight;
|
|
625
648
|
}, {
|
|
626
649
|
className: EXPANDED_SCROLLABLE_CLASS,
|
|
627
|
-
forceScrollableHeight:
|
|
650
|
+
forceScrollableHeight: options.forceScrollableHeight !== false,
|
|
628
651
|
visibleOnly: options.visibleOnly !== false
|
|
629
652
|
});
|
|
630
653
|
};
|
|
@@ -6301,18 +6324,15 @@ var DEFAULT_STRIP_PROMPT_MAX_LINES = 3;
|
|
|
6301
6324
|
var DEFAULT_STRIP_CONTENT_SAFE_PADDING_X = 12;
|
|
6302
6325
|
var DEFAULT_STRIP_TEXT_WIDTH_SAFETY = 10;
|
|
6303
6326
|
var DEFAULT_BROWSER_COMPOSITOR_VIEWPORT_HEIGHT = 1200;
|
|
6304
|
-
var MOBILE_STRIP_HEIGHT =
|
|
6327
|
+
var MOBILE_STRIP_HEIGHT = 78;
|
|
6305
6328
|
var MOBILE_STRIP_PADDING_X = 14;
|
|
6306
6329
|
var MOBILE_STRIP_PADDING_Y = 13;
|
|
6307
6330
|
var MOBILE_STRIP_ROW_HEIGHT = 22;
|
|
6308
|
-
var MOBILE_STRIP_ROW_GAP =
|
|
6331
|
+
var MOBILE_STRIP_ROW_GAP = 8;
|
|
6309
6332
|
var MOBILE_STRIP_LABEL_FONT_SIZE = 12.5;
|
|
6310
6333
|
var MOBILE_STRIP_VALUE_FONT_SIZE = 13.5;
|
|
6311
|
-
var
|
|
6312
|
-
var
|
|
6313
|
-
var MOBILE_STRIP_LOC_LABEL_WIDTH = 30;
|
|
6314
|
-
var MOBILE_STRIP_IP_LABEL_WIDTH = 22;
|
|
6315
|
-
var MOBILE_STRIP_META_GAP = 12;
|
|
6334
|
+
var MOBILE_STRIP_META_GAP = 16;
|
|
6335
|
+
var MOBILE_STRIP_VALUE_WIDTH_SAFETY = 10;
|
|
6316
6336
|
var WEAK_LOCATION_VALUES = /* @__PURE__ */ new Set(["cn", "\u4E2D\u56FD"]);
|
|
6317
6337
|
var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
6318
6338
|
/(?:中国)?移动$/i,
|
|
@@ -6709,9 +6729,10 @@ var readImageInfo = (buffer) => {
|
|
|
6709
6729
|
height: 0
|
|
6710
6730
|
};
|
|
6711
6731
|
};
|
|
6712
|
-
var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height }) => {
|
|
6732
|
+
var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageHeight }) => {
|
|
6713
6733
|
const safeWidth = Math.max(1, Number(width) || 1);
|
|
6714
6734
|
const safeHeight = Math.max(1, Number(height) || 1);
|
|
6735
|
+
const safeImageHeight = Math.max(1, Number(imageHeight || height) || 1);
|
|
6715
6736
|
return `
|
|
6716
6737
|
<!doctype html>
|
|
6717
6738
|
<html lang="zh-CN">
|
|
@@ -6740,10 +6761,11 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height }) => {
|
|
|
6740
6761
|
|
|
6741
6762
|
#pk-base-image {
|
|
6742
6763
|
position: absolute;
|
|
6743
|
-
|
|
6764
|
+
top: 0;
|
|
6765
|
+
left: 0;
|
|
6744
6766
|
display: block;
|
|
6745
6767
|
width: ${safeWidth}px;
|
|
6746
|
-
height: ${
|
|
6768
|
+
height: ${safeImageHeight}px;
|
|
6747
6769
|
}
|
|
6748
6770
|
|
|
6749
6771
|
#pk-overlay {
|
|
@@ -6777,7 +6799,8 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
6777
6799
|
try {
|
|
6778
6800
|
const renderPage = renderScope.page;
|
|
6779
6801
|
const safeWidth = Math.max(1, Number(imageInfo.width) || 1);
|
|
6780
|
-
const
|
|
6802
|
+
const safeImageHeight = Math.max(1, Number(imageInfo.imageHeight || imageInfo.height) || 1);
|
|
6803
|
+
const safeHeight = Math.max(safeImageHeight, Number(imageInfo.height) || safeImageHeight);
|
|
6781
6804
|
const viewportHeight = Math.max(
|
|
6782
6805
|
1,
|
|
6783
6806
|
Math.min(safeHeight, DEFAULT_BROWSER_COMPOSITOR_VIEWPORT_HEIGHT)
|
|
@@ -6791,7 +6814,8 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
6791
6814
|
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
6792
6815
|
overlaySvg,
|
|
6793
6816
|
width: safeWidth,
|
|
6794
|
-
height: safeHeight
|
|
6817
|
+
height: safeHeight,
|
|
6818
|
+
imageHeight: safeImageHeight
|
|
6795
6819
|
}), {
|
|
6796
6820
|
waitUntil: "load"
|
|
6797
6821
|
});
|
|
@@ -7438,15 +7462,15 @@ var renderMobileStripText = ({
|
|
|
7438
7462
|
label,
|
|
7439
7463
|
value,
|
|
7440
7464
|
labelX,
|
|
7465
|
+
valueX,
|
|
7441
7466
|
y,
|
|
7442
7467
|
valueWidth,
|
|
7443
|
-
labelWidth = MOBILE_STRIP_LABEL_WIDTH,
|
|
7444
7468
|
fontFamily
|
|
7445
7469
|
}) => {
|
|
7446
7470
|
const safeLabel = normalizeWhitespace(label) || "-";
|
|
7447
7471
|
const safeValue = fitTextWithEllipsis(
|
|
7448
7472
|
Array.from(normalizeWhitespace(value) || "-"),
|
|
7449
|
-
Math.max(18, valueWidth),
|
|
7473
|
+
Math.max(18, valueWidth - MOBILE_STRIP_VALUE_WIDTH_SAFETY),
|
|
7450
7474
|
MOBILE_STRIP_VALUE_FONT_SIZE
|
|
7451
7475
|
);
|
|
7452
7476
|
return `
|
|
@@ -7461,7 +7485,7 @@ var renderMobileStripText = ({
|
|
|
7461
7485
|
dominant-baseline="middle"
|
|
7462
7486
|
>${escapeXml(safeLabel)}</text>
|
|
7463
7487
|
<text
|
|
7464
|
-
x="${
|
|
7488
|
+
x="${valueX}"
|
|
7465
7489
|
y="${y}"
|
|
7466
7490
|
fill="#111111"
|
|
7467
7491
|
font-family="${fontFamily}"
|
|
@@ -7471,9 +7495,9 @@ var renderMobileStripText = ({
|
|
|
7471
7495
|
>${escapeXml(safeValue)}</text>
|
|
7472
7496
|
`;
|
|
7473
7497
|
};
|
|
7474
|
-
var renderMobileStrip = ({ meta, width,
|
|
7498
|
+
var renderMobileStrip = ({ meta, width, baseHeight, fontFamily }) => {
|
|
7475
7499
|
const stripHeight = MOBILE_STRIP_HEIGHT;
|
|
7476
|
-
const stripY =
|
|
7500
|
+
const stripY = baseHeight;
|
|
7477
7501
|
const contentX = MOBILE_STRIP_PADDING_X;
|
|
7478
7502
|
const contentWidth = Math.max(1, width - MOBILE_STRIP_PADDING_X * 2);
|
|
7479
7503
|
const prompt = findStripSegment(meta.stripSegments, "prompt");
|
|
@@ -7482,63 +7506,70 @@ var renderMobileStrip = ({ meta, width, height, fontFamily }) => {
|
|
|
7482
7506
|
const ip = findStripSegment(meta.stripSegments, "ip");
|
|
7483
7507
|
const row1Y = stripY + MOBILE_STRIP_PADDING_Y + MOBILE_STRIP_ROW_HEIGHT / 2;
|
|
7484
7508
|
const row2Y = row1Y + MOBILE_STRIP_ROW_HEIGHT + MOBILE_STRIP_ROW_GAP;
|
|
7485
|
-
const
|
|
7486
|
-
|
|
7487
|
-
const locValueX = contentX + MOBILE_STRIP_LOC_LABEL_WIDTH;
|
|
7488
|
-
const ipLabelX = Math.min(
|
|
7489
|
-
width - MOBILE_STRIP_PADDING_X - MOBILE_STRIP_IP_LABEL_WIDTH - 70,
|
|
7509
|
+
const rightColumnX = Math.min(
|
|
7510
|
+
width - MOBILE_STRIP_PADDING_X - 112,
|
|
7490
7511
|
Math.max(
|
|
7491
|
-
|
|
7492
|
-
contentX + Math.round(contentWidth * 0.
|
|
7512
|
+
contentX + 200,
|
|
7513
|
+
contentX + Math.round(contentWidth * 0.62)
|
|
7493
7514
|
)
|
|
7494
7515
|
);
|
|
7516
|
+
const leftValueX = contentX + 48;
|
|
7517
|
+
const rightValueX = rightColumnX + 28;
|
|
7518
|
+
const promptValueWidth = Math.max(
|
|
7519
|
+
28,
|
|
7520
|
+
rightColumnX - leftValueX - MOBILE_STRIP_META_GAP
|
|
7521
|
+
);
|
|
7522
|
+
const timeValueWidth = Math.max(
|
|
7523
|
+
28,
|
|
7524
|
+
rightColumnX - leftValueX - MOBILE_STRIP_META_GAP
|
|
7525
|
+
);
|
|
7495
7526
|
const locValueWidth = Math.max(
|
|
7496
7527
|
28,
|
|
7497
|
-
|
|
7528
|
+
width - MOBILE_STRIP_PADDING_X - rightValueX
|
|
7498
7529
|
);
|
|
7499
7530
|
const ipValueWidth = Math.max(
|
|
7500
7531
|
28,
|
|
7501
|
-
width - MOBILE_STRIP_PADDING_X -
|
|
7532
|
+
width - MOBILE_STRIP_PADDING_X - rightValueX
|
|
7502
7533
|
);
|
|
7503
7534
|
return `
|
|
7504
7535
|
<g id="strip">
|
|
7505
7536
|
<rect x="0" y="${stripY}" width="${width}" height="${stripHeight}" fill="#ffffff" fill-opacity="0.985" />
|
|
7506
7537
|
<rect x="0" y="${stripY}" width="${width}" height="1" fill="#111111" fill-opacity="0.10" />
|
|
7507
|
-
<rect x="${contentX}" y="${stripY}" width="${Math.max(96, Math.round(width * 0.
|
|
7538
|
+
<rect x="${contentX}" y="${stripY}" width="${Math.max(96, Math.round(width * 0.34))}" height="2" fill="url(#stripAccent)" />
|
|
7508
7539
|
${renderMobileStripText({
|
|
7509
7540
|
label: "Prompt",
|
|
7510
7541
|
value: prompt.rawValue || prompt.value || "-",
|
|
7511
7542
|
labelX: contentX,
|
|
7543
|
+
valueX: leftValueX,
|
|
7512
7544
|
y: row1Y,
|
|
7513
7545
|
valueWidth: promptValueWidth,
|
|
7514
|
-
labelWidth: MOBILE_STRIP_PROMPT_LABEL_WIDTH,
|
|
7515
7546
|
fontFamily
|
|
7516
7547
|
})}
|
|
7517
7548
|
${renderMobileStripText({
|
|
7518
|
-
label: "
|
|
7519
|
-
value:
|
|
7520
|
-
labelX:
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7549
|
+
label: "Loc",
|
|
7550
|
+
value: location.rawValue || location.value || "-",
|
|
7551
|
+
labelX: rightColumnX,
|
|
7552
|
+
valueX: rightValueX,
|
|
7553
|
+
y: row1Y,
|
|
7554
|
+
valueWidth: locValueWidth,
|
|
7524
7555
|
fontFamily
|
|
7525
7556
|
})}
|
|
7526
7557
|
${renderMobileStripText({
|
|
7527
|
-
label: "
|
|
7528
|
-
value:
|
|
7558
|
+
label: "Time",
|
|
7559
|
+
value: time.rawValue || time.value || "-",
|
|
7529
7560
|
labelX: contentX,
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7561
|
+
valueX: leftValueX,
|
|
7562
|
+
y: row2Y,
|
|
7563
|
+
valueWidth: timeValueWidth,
|
|
7533
7564
|
fontFamily
|
|
7534
7565
|
})}
|
|
7535
7566
|
${renderMobileStripText({
|
|
7536
7567
|
label: "IP",
|
|
7537
7568
|
value: ip.rawValue || ip.value || "-",
|
|
7538
|
-
labelX:
|
|
7539
|
-
|
|
7569
|
+
labelX: rightColumnX,
|
|
7570
|
+
valueX: rightValueX,
|
|
7571
|
+
y: row2Y,
|
|
7540
7572
|
valueWidth: ipValueWidth,
|
|
7541
|
-
labelWidth: MOBILE_STRIP_IP_LABEL_WIDTH,
|
|
7542
7573
|
fontFamily
|
|
7543
7574
|
})}
|
|
7544
7575
|
</g>
|
|
@@ -7551,7 +7582,8 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7551
7582
|
return "";
|
|
7552
7583
|
}
|
|
7553
7584
|
const width = Math.max(1, Number(imageWidth) || 1);
|
|
7554
|
-
const
|
|
7585
|
+
const baseHeight = Math.max(1, Number(imageHeight) || 1);
|
|
7586
|
+
const canvasHeight = normalizeDevice(meta.device) === Device.Mobile && hasStrip ? baseHeight + MOBILE_STRIP_HEIGHT : baseHeight;
|
|
7555
7587
|
const fontFamily = escapeXml(buildFontFamily());
|
|
7556
7588
|
const parts = [];
|
|
7557
7589
|
if (hasWatermark) {
|
|
@@ -7564,7 +7596,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7564
7596
|
const startX = -Math.round(cellWidth * 0.16);
|
|
7565
7597
|
const startY = -Math.round(cellHeight * 0.12);
|
|
7566
7598
|
const cols = Math.ceil((width + cellWidth * 1.1) / cellWidth) + 1;
|
|
7567
|
-
const rows = Math.ceil((
|
|
7599
|
+
const rows = Math.ceil((baseHeight + cellHeight * 0.9) / cellHeight) + 1;
|
|
7568
7600
|
const stamps = [];
|
|
7569
7601
|
for (let row = 0; row < rows; row += 1) {
|
|
7570
7602
|
for (let col = 0; col < cols; col += 1) {
|
|
@@ -7596,11 +7628,11 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7596
7628
|
parts.push(renderMobileStrip({
|
|
7597
7629
|
meta,
|
|
7598
7630
|
width,
|
|
7599
|
-
|
|
7631
|
+
baseHeight,
|
|
7600
7632
|
fontFamily
|
|
7601
7633
|
}));
|
|
7602
7634
|
return `
|
|
7603
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${
|
|
7635
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${canvasHeight}" viewBox="0 0 ${width} ${canvasHeight}">
|
|
7604
7636
|
<defs>
|
|
7605
7637
|
<linearGradient id="stripAccent" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
7606
7638
|
<stop offset="0%" stop-color="#111111" stop-opacity="0.98" />
|
|
@@ -7619,7 +7651,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7619
7651
|
const contentWidth = width - contentStartX - DEFAULT_STRIP_PADDING_RIGHT;
|
|
7620
7652
|
const stripLayout = buildStripLayout(meta.stripSegments, contentWidth);
|
|
7621
7653
|
const stripHeight = stripLayout.height;
|
|
7622
|
-
const stripY =
|
|
7654
|
+
const stripY = baseHeight - stripHeight;
|
|
7623
7655
|
const logoY = Number((stripY + (stripHeight - logoSize) / 2).toFixed(2));
|
|
7624
7656
|
let stripContentSvg = "";
|
|
7625
7657
|
const centerY = stripY + stripHeight / 2 + 1;
|
|
@@ -7708,7 +7740,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7708
7740
|
`);
|
|
7709
7741
|
}
|
|
7710
7742
|
return `
|
|
7711
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${
|
|
7743
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${canvasHeight}" viewBox="0 0 ${width} ${canvasHeight}">
|
|
7712
7744
|
<defs>
|
|
7713
7745
|
<linearGradient id="stripAccent" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
7714
7746
|
<stop offset="0%" stop-color="#111111" stop-opacity="0.98" />
|
|
@@ -7732,11 +7764,17 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
7732
7764
|
logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
7733
7765
|
return buffer;
|
|
7734
7766
|
}
|
|
7767
|
+
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
7768
|
+
const outputImageInfo = isMobileStrip ? {
|
|
7769
|
+
...imageInfo,
|
|
7770
|
+
imageHeight: imageInfo.height,
|
|
7771
|
+
height: imageInfo.height + MOBILE_STRIP_HEIGHT
|
|
7772
|
+
} : imageInfo;
|
|
7735
7773
|
const overlaySvg = buildWatermarkifySvg(meta, imageInfo.width, imageInfo.height);
|
|
7736
7774
|
if (!overlaySvg) {
|
|
7737
7775
|
return buffer;
|
|
7738
7776
|
}
|
|
7739
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg,
|
|
7777
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
7740
7778
|
};
|
|
7741
7779
|
|
|
7742
7780
|
// src/internals/compression.js
|