@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.js CHANGED
@@ -553,6 +553,21 @@ var expandScrollableContent = async (page, options = {}) => {
553
553
  const scrollableOverflow = /* @__PURE__ */ new Set(["auto", "scroll", "overlay"]);
554
554
  return scrollableOverflow.has(overflowY) || scrollableOverflow.has(overflow);
555
555
  };
556
+ const measureNeededHeight = (el) => {
557
+ if (!el) return 0;
558
+ const scrollHeight = Math.ceil(el.scrollHeight || 0);
559
+ if (scrollHeight <= 0) return 0;
560
+ if (isDocumentElement(el)) {
561
+ return scrollHeight;
562
+ }
563
+ const rect = el.getBoundingClientRect();
564
+ if (!rect || rect.width <= 0 || rect.height <= 0) {
565
+ return 0;
566
+ }
567
+ const documentTop = Math.max(0, Math.ceil(rect.top + (window.scrollY || window.pageYOffset || 0)));
568
+ return documentTop + scrollHeight;
569
+ };
570
+ const scrollableElements = [];
556
571
  candidates.forEach((el) => {
557
572
  const style = window.getComputedStyle(el);
558
573
  const rect = el.getBoundingClientRect();
@@ -562,13 +577,14 @@ var expandScrollableContent = async (page, options = {}) => {
562
577
  if (!isScrollableY(el, style)) {
563
578
  return;
564
579
  }
565
- const scrollHeight = Math.ceil(el.scrollHeight || 0);
566
- if (scrollHeight <= 0) {
580
+ const neededHeight = measureNeededHeight(el);
581
+ if (neededHeight <= 0) {
567
582
  return;
568
583
  }
569
- if (scrollHeight > maxHeight) {
570
- maxHeight = scrollHeight;
584
+ if (neededHeight > maxHeight) {
585
+ maxHeight = neededHeight;
571
586
  }
587
+ scrollableElements.push(el);
572
588
  if (isDocumentElement(el)) {
573
589
  return;
574
590
  }
@@ -584,6 +600,7 @@ var expandScrollableContent = async (page, options = {}) => {
584
600
  el.classList.add(className);
585
601
  }
586
602
  if (forceScrollableHeight) {
603
+ const scrollHeight = Math.ceil(el.scrollHeight || 0);
587
604
  el.style.setProperty("overflow", "visible", "important");
588
605
  el.style.setProperty("height", `${scrollHeight}px`, "important");
589
606
  el.style.setProperty("min-height", `${scrollHeight}px`, "important");
@@ -594,10 +611,16 @@ var expandScrollableContent = async (page, options = {}) => {
594
611
  el.style.height = "auto";
595
612
  el.style.maxHeight = "none";
596
613
  });
614
+ scrollableElements.forEach((el) => {
615
+ const neededHeight = measureNeededHeight(el);
616
+ if (neededHeight > maxHeight) {
617
+ maxHeight = neededHeight;
618
+ }
619
+ });
597
620
  return maxHeight;
598
621
  }, {
599
622
  className: EXPANDED_SCROLLABLE_CLASS,
600
- forceScrollableHeight: Boolean(options.forceScrollableHeight),
623
+ forceScrollableHeight: options.forceScrollableHeight !== false,
601
624
  visibleOnly: options.visibleOnly !== false
602
625
  });
603
626
  };
@@ -6273,18 +6296,15 @@ var DEFAULT_STRIP_PROMPT_MAX_LINES = 3;
6273
6296
  var DEFAULT_STRIP_CONTENT_SAFE_PADDING_X = 12;
6274
6297
  var DEFAULT_STRIP_TEXT_WIDTH_SAFETY = 10;
6275
6298
  var DEFAULT_BROWSER_COMPOSITOR_VIEWPORT_HEIGHT = 1200;
6276
- var MOBILE_STRIP_HEIGHT = 104;
6299
+ var MOBILE_STRIP_HEIGHT = 78;
6277
6300
  var MOBILE_STRIP_PADDING_X = 14;
6278
6301
  var MOBILE_STRIP_PADDING_Y = 13;
6279
6302
  var MOBILE_STRIP_ROW_HEIGHT = 22;
6280
- var MOBILE_STRIP_ROW_GAP = 7;
6303
+ var MOBILE_STRIP_ROW_GAP = 8;
6281
6304
  var MOBILE_STRIP_LABEL_FONT_SIZE = 12.5;
6282
6305
  var MOBILE_STRIP_VALUE_FONT_SIZE = 13.5;
6283
- var MOBILE_STRIP_LABEL_WIDTH = 45;
6284
- var MOBILE_STRIP_PROMPT_LABEL_WIDTH = 60;
6285
- var MOBILE_STRIP_LOC_LABEL_WIDTH = 30;
6286
- var MOBILE_STRIP_IP_LABEL_WIDTH = 22;
6287
- var MOBILE_STRIP_META_GAP = 12;
6306
+ var MOBILE_STRIP_META_GAP = 16;
6307
+ var MOBILE_STRIP_VALUE_WIDTH_SAFETY = 10;
6288
6308
  var WEAK_LOCATION_VALUES = /* @__PURE__ */ new Set(["cn", "\u4E2D\u56FD"]);
6289
6309
  var LOCATION_NETWORK_SUFFIX_PATTERNS = [
6290
6310
  /(?:中国)?移动$/i,
@@ -6681,9 +6701,10 @@ var readImageInfo = (buffer) => {
6681
6701
  height: 0
6682
6702
  };
6683
6703
  };
6684
- var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height }) => {
6704
+ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageHeight }) => {
6685
6705
  const safeWidth = Math.max(1, Number(width) || 1);
6686
6706
  const safeHeight = Math.max(1, Number(height) || 1);
6707
+ const safeImageHeight = Math.max(1, Number(imageHeight || height) || 1);
6687
6708
  return `
6688
6709
  <!doctype html>
6689
6710
  <html lang="zh-CN">
@@ -6712,10 +6733,11 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height }) => {
6712
6733
 
6713
6734
  #pk-base-image {
6714
6735
  position: absolute;
6715
- inset: 0;
6736
+ top: 0;
6737
+ left: 0;
6716
6738
  display: block;
6717
6739
  width: ${safeWidth}px;
6718
- height: ${safeHeight}px;
6740
+ height: ${safeImageHeight}px;
6719
6741
  }
6720
6742
 
6721
6743
  #pk-overlay {
@@ -6749,7 +6771,8 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
6749
6771
  try {
6750
6772
  const renderPage = renderScope.page;
6751
6773
  const safeWidth = Math.max(1, Number(imageInfo.width) || 1);
6752
- const safeHeight = Math.max(1, Number(imageInfo.height) || 1);
6774
+ const safeImageHeight = Math.max(1, Number(imageInfo.imageHeight || imageInfo.height) || 1);
6775
+ const safeHeight = Math.max(safeImageHeight, Number(imageInfo.height) || safeImageHeight);
6753
6776
  const viewportHeight = Math.max(
6754
6777
  1,
6755
6778
  Math.min(safeHeight, DEFAULT_BROWSER_COMPOSITOR_VIEWPORT_HEIGHT)
@@ -6763,7 +6786,8 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
6763
6786
  imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
6764
6787
  overlaySvg,
6765
6788
  width: safeWidth,
6766
- height: safeHeight
6789
+ height: safeHeight,
6790
+ imageHeight: safeImageHeight
6767
6791
  }), {
6768
6792
  waitUntil: "load"
6769
6793
  });
@@ -7410,15 +7434,15 @@ var renderMobileStripText = ({
7410
7434
  label,
7411
7435
  value,
7412
7436
  labelX,
7437
+ valueX,
7413
7438
  y,
7414
7439
  valueWidth,
7415
- labelWidth = MOBILE_STRIP_LABEL_WIDTH,
7416
7440
  fontFamily
7417
7441
  }) => {
7418
7442
  const safeLabel = normalizeWhitespace(label) || "-";
7419
7443
  const safeValue = fitTextWithEllipsis(
7420
7444
  Array.from(normalizeWhitespace(value) || "-"),
7421
- Math.max(18, valueWidth),
7445
+ Math.max(18, valueWidth - MOBILE_STRIP_VALUE_WIDTH_SAFETY),
7422
7446
  MOBILE_STRIP_VALUE_FONT_SIZE
7423
7447
  );
7424
7448
  return `
@@ -7433,7 +7457,7 @@ var renderMobileStripText = ({
7433
7457
  dominant-baseline="middle"
7434
7458
  >${escapeXml(safeLabel)}</text>
7435
7459
  <text
7436
- x="${labelX + labelWidth}"
7460
+ x="${valueX}"
7437
7461
  y="${y}"
7438
7462
  fill="#111111"
7439
7463
  font-family="${fontFamily}"
@@ -7443,9 +7467,9 @@ var renderMobileStripText = ({
7443
7467
  >${escapeXml(safeValue)}</text>
7444
7468
  `;
7445
7469
  };
7446
- var renderMobileStrip = ({ meta, width, height, fontFamily }) => {
7470
+ var renderMobileStrip = ({ meta, width, baseHeight, fontFamily }) => {
7447
7471
  const stripHeight = MOBILE_STRIP_HEIGHT;
7448
- const stripY = height - stripHeight;
7472
+ const stripY = baseHeight;
7449
7473
  const contentX = MOBILE_STRIP_PADDING_X;
7450
7474
  const contentWidth = Math.max(1, width - MOBILE_STRIP_PADDING_X * 2);
7451
7475
  const prompt = findStripSegment(meta.stripSegments, "prompt");
@@ -7454,63 +7478,70 @@ var renderMobileStrip = ({ meta, width, height, fontFamily }) => {
7454
7478
  const ip = findStripSegment(meta.stripSegments, "ip");
7455
7479
  const row1Y = stripY + MOBILE_STRIP_PADDING_Y + MOBILE_STRIP_ROW_HEIGHT / 2;
7456
7480
  const row2Y = row1Y + MOBILE_STRIP_ROW_HEIGHT + MOBILE_STRIP_ROW_GAP;
7457
- const row3Y = row2Y + MOBILE_STRIP_ROW_HEIGHT + MOBILE_STRIP_ROW_GAP;
7458
- const promptValueWidth = contentWidth - MOBILE_STRIP_PROMPT_LABEL_WIDTH;
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,
7481
+ const rightColumnX = Math.min(
7482
+ width - MOBILE_STRIP_PADDING_X - 112,
7462
7483
  Math.max(
7463
- locValueX + 80 + MOBILE_STRIP_META_GAP,
7464
- contentX + Math.round(contentWidth * 0.52)
7484
+ contentX + 200,
7485
+ contentX + Math.round(contentWidth * 0.62)
7465
7486
  )
7466
7487
  );
7488
+ const leftValueX = contentX + 48;
7489
+ const rightValueX = rightColumnX + 28;
7490
+ const promptValueWidth = Math.max(
7491
+ 28,
7492
+ rightColumnX - leftValueX - MOBILE_STRIP_META_GAP
7493
+ );
7494
+ const timeValueWidth = Math.max(
7495
+ 28,
7496
+ rightColumnX - leftValueX - MOBILE_STRIP_META_GAP
7497
+ );
7467
7498
  const locValueWidth = Math.max(
7468
7499
  28,
7469
- ipLabelX - locValueX - MOBILE_STRIP_META_GAP
7500
+ width - MOBILE_STRIP_PADDING_X - rightValueX
7470
7501
  );
7471
7502
  const ipValueWidth = Math.max(
7472
7503
  28,
7473
- width - MOBILE_STRIP_PADDING_X - (ipLabelX + MOBILE_STRIP_IP_LABEL_WIDTH)
7504
+ width - MOBILE_STRIP_PADDING_X - rightValueX
7474
7505
  );
7475
7506
  return `
7476
7507
  <g id="strip">
7477
7508
  <rect x="0" y="${stripY}" width="${width}" height="${stripHeight}" fill="#ffffff" fill-opacity="0.985" />
7478
7509
  <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.36))}" height="2" fill="url(#stripAccent)" />
7510
+ <rect x="${contentX}" y="${stripY}" width="${Math.max(96, Math.round(width * 0.34))}" height="2" fill="url(#stripAccent)" />
7480
7511
  ${renderMobileStripText({
7481
7512
  label: "Prompt",
7482
7513
  value: prompt.rawValue || prompt.value || "-",
7483
7514
  labelX: contentX,
7515
+ valueX: leftValueX,
7484
7516
  y: row1Y,
7485
7517
  valueWidth: promptValueWidth,
7486
- labelWidth: MOBILE_STRIP_PROMPT_LABEL_WIDTH,
7487
7518
  fontFamily
7488
7519
  })}
7489
7520
  ${renderMobileStripText({
7490
- label: "Time",
7491
- value: time.rawValue || time.value || "-",
7492
- labelX: contentX,
7493
- y: row2Y,
7494
- valueWidth: promptValueWidth,
7495
- labelWidth: MOBILE_STRIP_LABEL_WIDTH,
7521
+ label: "Loc",
7522
+ value: location.rawValue || location.value || "-",
7523
+ labelX: rightColumnX,
7524
+ valueX: rightValueX,
7525
+ y: row1Y,
7526
+ valueWidth: locValueWidth,
7496
7527
  fontFamily
7497
7528
  })}
7498
7529
  ${renderMobileStripText({
7499
- label: "Loc",
7500
- value: location.rawValue || location.value || "-",
7530
+ label: "Time",
7531
+ value: time.rawValue || time.value || "-",
7501
7532
  labelX: contentX,
7502
- y: row3Y,
7503
- valueWidth: locValueWidth,
7504
- labelWidth: MOBILE_STRIP_LOC_LABEL_WIDTH,
7533
+ valueX: leftValueX,
7534
+ y: row2Y,
7535
+ valueWidth: timeValueWidth,
7505
7536
  fontFamily
7506
7537
  })}
7507
7538
  ${renderMobileStripText({
7508
7539
  label: "IP",
7509
7540
  value: ip.rawValue || ip.value || "-",
7510
- labelX: ipLabelX,
7511
- y: row3Y,
7541
+ labelX: rightColumnX,
7542
+ valueX: rightValueX,
7543
+ y: row2Y,
7512
7544
  valueWidth: ipValueWidth,
7513
- labelWidth: MOBILE_STRIP_IP_LABEL_WIDTH,
7514
7545
  fontFamily
7515
7546
  })}
7516
7547
  </g>
@@ -7523,7 +7554,8 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
7523
7554
  return "";
7524
7555
  }
7525
7556
  const width = Math.max(1, Number(imageWidth) || 1);
7526
- const height = Math.max(1, Number(imageHeight) || 1);
7557
+ const baseHeight = Math.max(1, Number(imageHeight) || 1);
7558
+ const canvasHeight = normalizeDevice(meta.device) === Device.Mobile && hasStrip ? baseHeight + MOBILE_STRIP_HEIGHT : baseHeight;
7527
7559
  const fontFamily = escapeXml(buildFontFamily());
7528
7560
  const parts = [];
7529
7561
  if (hasWatermark) {
@@ -7536,7 +7568,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
7536
7568
  const startX = -Math.round(cellWidth * 0.16);
7537
7569
  const startY = -Math.round(cellHeight * 0.12);
7538
7570
  const cols = Math.ceil((width + cellWidth * 1.1) / cellWidth) + 1;
7539
- const rows = Math.ceil((height + cellHeight * 0.9) / cellHeight) + 1;
7571
+ const rows = Math.ceil((baseHeight + cellHeight * 0.9) / cellHeight) + 1;
7540
7572
  const stamps = [];
7541
7573
  for (let row = 0; row < rows; row += 1) {
7542
7574
  for (let col = 0; col < cols; col += 1) {
@@ -7568,11 +7600,11 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
7568
7600
  parts.push(renderMobileStrip({
7569
7601
  meta,
7570
7602
  width,
7571
- height,
7603
+ baseHeight,
7572
7604
  fontFamily
7573
7605
  }));
7574
7606
  return `
7575
- <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
7607
+ <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${canvasHeight}" viewBox="0 0 ${width} ${canvasHeight}">
7576
7608
  <defs>
7577
7609
  <linearGradient id="stripAccent" x1="0%" y1="0%" x2="100%" y2="0%">
7578
7610
  <stop offset="0%" stop-color="#111111" stop-opacity="0.98" />
@@ -7591,7 +7623,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
7591
7623
  const contentWidth = width - contentStartX - DEFAULT_STRIP_PADDING_RIGHT;
7592
7624
  const stripLayout = buildStripLayout(meta.stripSegments, contentWidth);
7593
7625
  const stripHeight = stripLayout.height;
7594
- const stripY = height - stripHeight;
7626
+ const stripY = baseHeight - stripHeight;
7595
7627
  const logoY = Number((stripY + (stripHeight - logoSize) / 2).toFixed(2));
7596
7628
  let stripContentSvg = "";
7597
7629
  const centerY = stripY + stripHeight / 2 + 1;
@@ -7680,7 +7712,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
7680
7712
  `);
7681
7713
  }
7682
7714
  return `
7683
- <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
7715
+ <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${canvasHeight}" viewBox="0 0 ${width} ${canvasHeight}">
7684
7716
  <defs>
7685
7717
  <linearGradient id="stripAccent" x1="0%" y1="0%" x2="100%" y2="0%">
7686
7718
  <stop offset="0%" stop-color="#111111" stop-opacity="0.98" />
@@ -7704,11 +7736,17 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
7704
7736
  logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
7705
7737
  return buffer;
7706
7738
  }
7739
+ const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
7740
+ const outputImageInfo = isMobileStrip ? {
7741
+ ...imageInfo,
7742
+ imageHeight: imageInfo.height,
7743
+ height: imageInfo.height + MOBILE_STRIP_HEIGHT
7744
+ } : imageInfo;
7707
7745
  const overlaySvg = buildWatermarkifySvg(meta, imageInfo.width, imageInfo.height);
7708
7746
  if (!overlaySvg) {
7709
7747
  return buffer;
7710
7748
  }
7711
- return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, imageInfo);
7749
+ return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
7712
7750
  };
7713
7751
 
7714
7752
  // src/internals/compression.js