@skrillex1224/playwright-toolkit 2.1.228 → 2.1.229
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 +64 -49
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +64 -49
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6273,18 +6273,15 @@ var DEFAULT_STRIP_PROMPT_MAX_LINES = 3;
|
|
|
6273
6273
|
var DEFAULT_STRIP_CONTENT_SAFE_PADDING_X = 12;
|
|
6274
6274
|
var DEFAULT_STRIP_TEXT_WIDTH_SAFETY = 10;
|
|
6275
6275
|
var DEFAULT_BROWSER_COMPOSITOR_VIEWPORT_HEIGHT = 1200;
|
|
6276
|
-
var MOBILE_STRIP_HEIGHT =
|
|
6276
|
+
var MOBILE_STRIP_HEIGHT = 78;
|
|
6277
6277
|
var MOBILE_STRIP_PADDING_X = 14;
|
|
6278
6278
|
var MOBILE_STRIP_PADDING_Y = 13;
|
|
6279
6279
|
var MOBILE_STRIP_ROW_HEIGHT = 22;
|
|
6280
|
-
var MOBILE_STRIP_ROW_GAP =
|
|
6280
|
+
var MOBILE_STRIP_ROW_GAP = 8;
|
|
6281
6281
|
var MOBILE_STRIP_LABEL_FONT_SIZE = 12.5;
|
|
6282
6282
|
var MOBILE_STRIP_VALUE_FONT_SIZE = 13.5;
|
|
6283
|
-
var
|
|
6284
|
-
var
|
|
6285
|
-
var MOBILE_STRIP_LOC_LABEL_WIDTH = 30;
|
|
6286
|
-
var MOBILE_STRIP_IP_LABEL_WIDTH = 22;
|
|
6287
|
-
var MOBILE_STRIP_META_GAP = 12;
|
|
6283
|
+
var MOBILE_STRIP_META_GAP = 16;
|
|
6284
|
+
var MOBILE_STRIP_VALUE_WIDTH_SAFETY = 10;
|
|
6288
6285
|
var WEAK_LOCATION_VALUES = /* @__PURE__ */ new Set(["cn", "\u4E2D\u56FD"]);
|
|
6289
6286
|
var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
6290
6287
|
/(?:中国)?移动$/i,
|
|
@@ -6681,9 +6678,10 @@ var readImageInfo = (buffer) => {
|
|
|
6681
6678
|
height: 0
|
|
6682
6679
|
};
|
|
6683
6680
|
};
|
|
6684
|
-
var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height }) => {
|
|
6681
|
+
var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageHeight }) => {
|
|
6685
6682
|
const safeWidth = Math.max(1, Number(width) || 1);
|
|
6686
6683
|
const safeHeight = Math.max(1, Number(height) || 1);
|
|
6684
|
+
const safeImageHeight = Math.max(1, Number(imageHeight || height) || 1);
|
|
6687
6685
|
return `
|
|
6688
6686
|
<!doctype html>
|
|
6689
6687
|
<html lang="zh-CN">
|
|
@@ -6712,10 +6710,11 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height }) => {
|
|
|
6712
6710
|
|
|
6713
6711
|
#pk-base-image {
|
|
6714
6712
|
position: absolute;
|
|
6715
|
-
|
|
6713
|
+
top: 0;
|
|
6714
|
+
left: 0;
|
|
6716
6715
|
display: block;
|
|
6717
6716
|
width: ${safeWidth}px;
|
|
6718
|
-
height: ${
|
|
6717
|
+
height: ${safeImageHeight}px;
|
|
6719
6718
|
}
|
|
6720
6719
|
|
|
6721
6720
|
#pk-overlay {
|
|
@@ -6749,7 +6748,8 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
6749
6748
|
try {
|
|
6750
6749
|
const renderPage = renderScope.page;
|
|
6751
6750
|
const safeWidth = Math.max(1, Number(imageInfo.width) || 1);
|
|
6752
|
-
const
|
|
6751
|
+
const safeImageHeight = Math.max(1, Number(imageInfo.imageHeight || imageInfo.height) || 1);
|
|
6752
|
+
const safeHeight = Math.max(safeImageHeight, Number(imageInfo.height) || safeImageHeight);
|
|
6753
6753
|
const viewportHeight = Math.max(
|
|
6754
6754
|
1,
|
|
6755
6755
|
Math.min(safeHeight, DEFAULT_BROWSER_COMPOSITOR_VIEWPORT_HEIGHT)
|
|
@@ -6763,7 +6763,8 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
6763
6763
|
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
6764
6764
|
overlaySvg,
|
|
6765
6765
|
width: safeWidth,
|
|
6766
|
-
height: safeHeight
|
|
6766
|
+
height: safeHeight,
|
|
6767
|
+
imageHeight: safeImageHeight
|
|
6767
6768
|
}), {
|
|
6768
6769
|
waitUntil: "load"
|
|
6769
6770
|
});
|
|
@@ -7410,15 +7411,15 @@ var renderMobileStripText = ({
|
|
|
7410
7411
|
label,
|
|
7411
7412
|
value,
|
|
7412
7413
|
labelX,
|
|
7414
|
+
valueX,
|
|
7413
7415
|
y,
|
|
7414
7416
|
valueWidth,
|
|
7415
|
-
labelWidth = MOBILE_STRIP_LABEL_WIDTH,
|
|
7416
7417
|
fontFamily
|
|
7417
7418
|
}) => {
|
|
7418
7419
|
const safeLabel = normalizeWhitespace(label) || "-";
|
|
7419
7420
|
const safeValue = fitTextWithEllipsis(
|
|
7420
7421
|
Array.from(normalizeWhitespace(value) || "-"),
|
|
7421
|
-
Math.max(18, valueWidth),
|
|
7422
|
+
Math.max(18, valueWidth - MOBILE_STRIP_VALUE_WIDTH_SAFETY),
|
|
7422
7423
|
MOBILE_STRIP_VALUE_FONT_SIZE
|
|
7423
7424
|
);
|
|
7424
7425
|
return `
|
|
@@ -7433,7 +7434,7 @@ var renderMobileStripText = ({
|
|
|
7433
7434
|
dominant-baseline="middle"
|
|
7434
7435
|
>${escapeXml(safeLabel)}</text>
|
|
7435
7436
|
<text
|
|
7436
|
-
x="${
|
|
7437
|
+
x="${valueX}"
|
|
7437
7438
|
y="${y}"
|
|
7438
7439
|
fill="#111111"
|
|
7439
7440
|
font-family="${fontFamily}"
|
|
@@ -7443,9 +7444,9 @@ var renderMobileStripText = ({
|
|
|
7443
7444
|
>${escapeXml(safeValue)}</text>
|
|
7444
7445
|
`;
|
|
7445
7446
|
};
|
|
7446
|
-
var renderMobileStrip = ({ meta, width,
|
|
7447
|
+
var renderMobileStrip = ({ meta, width, baseHeight, fontFamily }) => {
|
|
7447
7448
|
const stripHeight = MOBILE_STRIP_HEIGHT;
|
|
7448
|
-
const stripY =
|
|
7449
|
+
const stripY = baseHeight;
|
|
7449
7450
|
const contentX = MOBILE_STRIP_PADDING_X;
|
|
7450
7451
|
const contentWidth = Math.max(1, width - MOBILE_STRIP_PADDING_X * 2);
|
|
7451
7452
|
const prompt = findStripSegment(meta.stripSegments, "prompt");
|
|
@@ -7454,63 +7455,70 @@ var renderMobileStrip = ({ meta, width, height, fontFamily }) => {
|
|
|
7454
7455
|
const ip = findStripSegment(meta.stripSegments, "ip");
|
|
7455
7456
|
const row1Y = stripY + MOBILE_STRIP_PADDING_Y + MOBILE_STRIP_ROW_HEIGHT / 2;
|
|
7456
7457
|
const row2Y = row1Y + MOBILE_STRIP_ROW_HEIGHT + MOBILE_STRIP_ROW_GAP;
|
|
7457
|
-
const
|
|
7458
|
-
|
|
7459
|
-
const locValueX = contentX + MOBILE_STRIP_LOC_LABEL_WIDTH;
|
|
7460
|
-
const ipLabelX = Math.min(
|
|
7461
|
-
width - MOBILE_STRIP_PADDING_X - MOBILE_STRIP_IP_LABEL_WIDTH - 70,
|
|
7458
|
+
const rightColumnX = Math.min(
|
|
7459
|
+
width - MOBILE_STRIP_PADDING_X - 112,
|
|
7462
7460
|
Math.max(
|
|
7463
|
-
|
|
7464
|
-
contentX + Math.round(contentWidth * 0.
|
|
7461
|
+
contentX + 200,
|
|
7462
|
+
contentX + Math.round(contentWidth * 0.62)
|
|
7465
7463
|
)
|
|
7466
7464
|
);
|
|
7465
|
+
const leftValueX = contentX + 48;
|
|
7466
|
+
const rightValueX = rightColumnX + 28;
|
|
7467
|
+
const promptValueWidth = Math.max(
|
|
7468
|
+
28,
|
|
7469
|
+
rightColumnX - leftValueX - MOBILE_STRIP_META_GAP
|
|
7470
|
+
);
|
|
7471
|
+
const timeValueWidth = Math.max(
|
|
7472
|
+
28,
|
|
7473
|
+
rightColumnX - leftValueX - MOBILE_STRIP_META_GAP
|
|
7474
|
+
);
|
|
7467
7475
|
const locValueWidth = Math.max(
|
|
7468
7476
|
28,
|
|
7469
|
-
|
|
7477
|
+
width - MOBILE_STRIP_PADDING_X - rightValueX
|
|
7470
7478
|
);
|
|
7471
7479
|
const ipValueWidth = Math.max(
|
|
7472
7480
|
28,
|
|
7473
|
-
width - MOBILE_STRIP_PADDING_X -
|
|
7481
|
+
width - MOBILE_STRIP_PADDING_X - rightValueX
|
|
7474
7482
|
);
|
|
7475
7483
|
return `
|
|
7476
7484
|
<g id="strip">
|
|
7477
7485
|
<rect x="0" y="${stripY}" width="${width}" height="${stripHeight}" fill="#ffffff" fill-opacity="0.985" />
|
|
7478
7486
|
<rect x="0" y="${stripY}" width="${width}" height="1" fill="#111111" fill-opacity="0.10" />
|
|
7479
|
-
<rect x="${contentX}" y="${stripY}" width="${Math.max(96, Math.round(width * 0.
|
|
7487
|
+
<rect x="${contentX}" y="${stripY}" width="${Math.max(96, Math.round(width * 0.34))}" height="2" fill="url(#stripAccent)" />
|
|
7480
7488
|
${renderMobileStripText({
|
|
7481
7489
|
label: "Prompt",
|
|
7482
7490
|
value: prompt.rawValue || prompt.value || "-",
|
|
7483
7491
|
labelX: contentX,
|
|
7492
|
+
valueX: leftValueX,
|
|
7484
7493
|
y: row1Y,
|
|
7485
7494
|
valueWidth: promptValueWidth,
|
|
7486
|
-
labelWidth: MOBILE_STRIP_PROMPT_LABEL_WIDTH,
|
|
7487
7495
|
fontFamily
|
|
7488
7496
|
})}
|
|
7489
7497
|
${renderMobileStripText({
|
|
7490
|
-
label: "
|
|
7491
|
-
value:
|
|
7492
|
-
labelX:
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7498
|
+
label: "Loc",
|
|
7499
|
+
value: location.rawValue || location.value || "-",
|
|
7500
|
+
labelX: rightColumnX,
|
|
7501
|
+
valueX: rightValueX,
|
|
7502
|
+
y: row1Y,
|
|
7503
|
+
valueWidth: locValueWidth,
|
|
7496
7504
|
fontFamily
|
|
7497
7505
|
})}
|
|
7498
7506
|
${renderMobileStripText({
|
|
7499
|
-
label: "
|
|
7500
|
-
value:
|
|
7507
|
+
label: "Time",
|
|
7508
|
+
value: time.rawValue || time.value || "-",
|
|
7501
7509
|
labelX: contentX,
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7510
|
+
valueX: leftValueX,
|
|
7511
|
+
y: row2Y,
|
|
7512
|
+
valueWidth: timeValueWidth,
|
|
7505
7513
|
fontFamily
|
|
7506
7514
|
})}
|
|
7507
7515
|
${renderMobileStripText({
|
|
7508
7516
|
label: "IP",
|
|
7509
7517
|
value: ip.rawValue || ip.value || "-",
|
|
7510
|
-
labelX:
|
|
7511
|
-
|
|
7518
|
+
labelX: rightColumnX,
|
|
7519
|
+
valueX: rightValueX,
|
|
7520
|
+
y: row2Y,
|
|
7512
7521
|
valueWidth: ipValueWidth,
|
|
7513
|
-
labelWidth: MOBILE_STRIP_IP_LABEL_WIDTH,
|
|
7514
7522
|
fontFamily
|
|
7515
7523
|
})}
|
|
7516
7524
|
</g>
|
|
@@ -7523,7 +7531,8 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7523
7531
|
return "";
|
|
7524
7532
|
}
|
|
7525
7533
|
const width = Math.max(1, Number(imageWidth) || 1);
|
|
7526
|
-
const
|
|
7534
|
+
const baseHeight = Math.max(1, Number(imageHeight) || 1);
|
|
7535
|
+
const canvasHeight = normalizeDevice(meta.device) === Device.Mobile && hasStrip ? baseHeight + MOBILE_STRIP_HEIGHT : baseHeight;
|
|
7527
7536
|
const fontFamily = escapeXml(buildFontFamily());
|
|
7528
7537
|
const parts = [];
|
|
7529
7538
|
if (hasWatermark) {
|
|
@@ -7536,7 +7545,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7536
7545
|
const startX = -Math.round(cellWidth * 0.16);
|
|
7537
7546
|
const startY = -Math.round(cellHeight * 0.12);
|
|
7538
7547
|
const cols = Math.ceil((width + cellWidth * 1.1) / cellWidth) + 1;
|
|
7539
|
-
const rows = Math.ceil((
|
|
7548
|
+
const rows = Math.ceil((baseHeight + cellHeight * 0.9) / cellHeight) + 1;
|
|
7540
7549
|
const stamps = [];
|
|
7541
7550
|
for (let row = 0; row < rows; row += 1) {
|
|
7542
7551
|
for (let col = 0; col < cols; col += 1) {
|
|
@@ -7568,11 +7577,11 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7568
7577
|
parts.push(renderMobileStrip({
|
|
7569
7578
|
meta,
|
|
7570
7579
|
width,
|
|
7571
|
-
|
|
7580
|
+
baseHeight,
|
|
7572
7581
|
fontFamily
|
|
7573
7582
|
}));
|
|
7574
7583
|
return `
|
|
7575
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${
|
|
7584
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${canvasHeight}" viewBox="0 0 ${width} ${canvasHeight}">
|
|
7576
7585
|
<defs>
|
|
7577
7586
|
<linearGradient id="stripAccent" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
7578
7587
|
<stop offset="0%" stop-color="#111111" stop-opacity="0.98" />
|
|
@@ -7591,7 +7600,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7591
7600
|
const contentWidth = width - contentStartX - DEFAULT_STRIP_PADDING_RIGHT;
|
|
7592
7601
|
const stripLayout = buildStripLayout(meta.stripSegments, contentWidth);
|
|
7593
7602
|
const stripHeight = stripLayout.height;
|
|
7594
|
-
const stripY =
|
|
7603
|
+
const stripY = baseHeight - stripHeight;
|
|
7595
7604
|
const logoY = Number((stripY + (stripHeight - logoSize) / 2).toFixed(2));
|
|
7596
7605
|
let stripContentSvg = "";
|
|
7597
7606
|
const centerY = stripY + stripHeight / 2 + 1;
|
|
@@ -7680,7 +7689,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
7680
7689
|
`);
|
|
7681
7690
|
}
|
|
7682
7691
|
return `
|
|
7683
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${
|
|
7692
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${canvasHeight}" viewBox="0 0 ${width} ${canvasHeight}">
|
|
7684
7693
|
<defs>
|
|
7685
7694
|
<linearGradient id="stripAccent" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
7686
7695
|
<stop offset="0%" stop-color="#111111" stop-opacity="0.98" />
|
|
@@ -7704,11 +7713,17 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
7704
7713
|
logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
7705
7714
|
return buffer;
|
|
7706
7715
|
}
|
|
7716
|
+
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
7717
|
+
const outputImageInfo = isMobileStrip ? {
|
|
7718
|
+
...imageInfo,
|
|
7719
|
+
imageHeight: imageInfo.height,
|
|
7720
|
+
height: imageInfo.height + MOBILE_STRIP_HEIGHT
|
|
7721
|
+
} : imageInfo;
|
|
7707
7722
|
const overlaySvg = buildWatermarkifySvg(meta, imageInfo.width, imageInfo.height);
|
|
7708
7723
|
if (!overlaySvg) {
|
|
7709
7724
|
return buffer;
|
|
7710
7725
|
}
|
|
7711
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg,
|
|
7726
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
7712
7727
|
};
|
|
7713
7728
|
|
|
7714
7729
|
// src/internals/compression.js
|