Skip to content

Improve HTML-to-PAGX fidelity and optimize generated PAGX#3596

Merged
shlzxjp merged 30 commits into
Tencent:mainfrom
OnionsYu:feature/onionsyu_import_html3
Jul 21, 2026
Merged

Improve HTML-to-PAGX fidelity and optimize generated PAGX#3596
shlzxjp merged 30 commits into
Tencent:mainfrom
OnionsYu:feature/onionsyu_import_html3

Conversation

@OnionsYu

@OnionsYu OnionsYu commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

概述

本 PR 提升 HTML → PAGX 转换链路的还原准确性和健壮性,并通过精简冗余图层减小生成的 PAGX 体积。改动覆盖 html-snapshot、HTML 导入器和 PAGX 优化器。

主要改动

html-snapshot

  • 统一处理 <html> / <body> 盒模型、画布视口和滚动位置,修复基准图垂直偏移、视口相对定位偏差及 scroll-behavior: smooth 导致的截取错位。
  • 截图前自动滚动以触发懒加载内容,并限制最大截图高度;当页面依赖流式或视口布局时,基准图与子集截图会共同回退,保证两者可比。
  • 对无法忠实转换的 flex 交叉轴布局保留绝对定位,避免丢失子元素的 align-self
  • 使用内联 SVG 保留逐边的 dashed / dotted 边框效果。
  • eval 报告新增实时源页面 iframe,并支持切换各列的显示状态。

HTML → PAGX 导入器

  • <img>data-* 属性保留到图层 customData;对于缺失或无效的 src,生成占位图片资源而不是丢弃图层。
  • 完整处理 CSS background 简写及声明顺序,保留背景颜色、最上层背景图片/渐变、位置、尺寸和重复方式,并让 background-color 正确绘制在图片下方。
  • 支持将 background-blend-mode 映射到对应 Fill 的混合模式。
  • 支持将 brightness()contrast()saturate()grayscale()sepia()invert()opacity()hue-rotate() 等 CSS filter 转换为 ColorMatrixFilter
  • polygon()path()circle()ellipse()inset() 等 CSS clip-path 基本形状重建为轮廓遮罩,并支持 clipPathUnits="objectBoundingBox"
  • 修复本地背景图路径生成的 url() 破坏 XML 解析的问题,并保证导入的 Text 节点始终包含明确的 fontFamilyfontStyle

PAGX 优化

  • 单行 span 直接生成 Text,避免额外的 TextBox 包装。
  • 新增单子图层折叠规则,移除冗余 Layer 嵌套,同时保留 composition、动画、数据绑定、标识和 padding 等语义。

测试

  • 扩充 HTML 导入器测试,覆盖背景、filter、clip-path、图片属性、字体及异常资源等场景。
  • 新增 PAGX 优化器测试,覆盖图层折叠、规范化和资源清理。
  • 新增 html-snapshot 测试,覆盖背景图 URL、虚线边框和图片 data-* 属性。

OnionsYu added 6 commits July 15, 2026 15:04
… capture and clamp capture height to a renderable max.
…ort to the body canvas before capture, matching the baseline.
…eping cross-axis-unfaithful layouts absolute.
…ing them as inline SVG lines instead of downgrading to solid strips.
@codecov-commenter

codecov-commenter commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.24358% with 155 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.75%. Comparing base (1df68e9) to head (2d07c75).

Files with missing lines Patch % Lines
src/pagx/html/importer/HTMLElementEmitter.cpp 57.14% 44 Missing and 40 partials ⚠️
src/pagx/PAGXOptimizer.cpp 71.42% 12 Missing and 16 partials ⚠️
test/src/PAGXHTMLImporterTest.cpp 96.86% 3 Missing and 11 partials ⚠️
src/pagx/html/importer/HTMLDetail.cpp 87.62% 0 Missing and 12 partials ⚠️
src/pagx/html/importer/HTMLValueParser.cpp 91.15% 6 Missing and 4 partials ⚠️
src/pagx/html/importer/HTMLLayerBuilder.cpp 91.89% 0 Missing and 3 partials ⚠️
src/pagx/html/importer/HTMLStyleCascade.cpp 75.00% 0 Missing and 3 partials ⚠️
src/pagx/html/importer/HTMLSubsetPropertyTable.cpp 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3596      +/-   ##
==========================================
+ Coverage   82.56%   82.75%   +0.18%     
==========================================
  Files         707      707              
  Lines       91382    92777    +1395     
  Branches    25871    26188     +317     
==========================================
+ Hits        75452    76776    +1324     
  Misses      10436    10436              
- Partials     5494     5565      +71     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

OnionsYu added 2 commits July 17, 2026 14:00
…mporter so they surface as PAGX layer customData.
…t by emitting a placeholder image resource instead of dropping the layer, and always serialize the required Image source attribute.
@OnionsYu
OnionsYu requested a review from kevingpqi123 as a code owner July 17, 2026 06:36
OnionsYu added 8 commits July 17, 2026 15:22
…ng HTML import so color, gradient, image, position, size and repeat survive property filtering instead of being dropped and losing the box fill.
…tomData instead of the layer during HTML import, so image-carried custom data travels with the image resource.
…esolves to a local path by emitting single-quoted url() in html-snapshot, so it no longer prematurely closes the style attribute and breaks the importer's XML parse.
… instead of wrapping every label in a TextBox, and add a general optimizer rule that collapses redundant single-child Layer nesting while preserving composition, animation and databind semantics.
…ce's customData instead of the layer during HTML import, so image-carried custom data travels with the image resource."

This reverts commit a87637a.
…e by defaulting the base face to Regular so fontFamily and fontStyle are always present.
@OnionsYu OnionsYu changed the title Improve html-snapshot fidelity for borders, flex layout, viewport positioning, and lazy content Improve HTML-to-PAGX import robustness and html-snapshot fidelity, and add a single-child Layer collapse optimizer Jul 20, 2026
Comment thread src/pagx/PAGXOptimizer.cpp Outdated
Comment thread src/pagx/html/importer/HTMLDetail.cpp
Comment thread src/pagx/html/importer/HTMLElementEmitter.cpp
Comment thread src/pagx/html/importer/HTMLTextFragmentBuilder.cpp Outdated
Comment thread src/pagx/html/importer/HTMLParserContext.cpp Outdated
Comment thread tools/html-snapshot/lib/browser-snapshot.ts Outdated
Comment thread test/src/PAGXHTMLImporterTest.cpp Outdated
Comment thread test/src/PAGXOptimizerTest.cpp
…scape quoted url paths and warn on conflicting data attributes.
@OnionsYu
OnionsYu force-pushed the feature/onionsyu_import_html3 branch from f5a1385 to ea47ec0 Compare July 20, 2026 08:35
@OnionsYu
OnionsYu force-pushed the feature/onionsyu_import_html3 branch from eaf45fe to d3b2f07 Compare July 21, 2026 03:18
OnionsYu added 5 commits July 21, 2026 14:16
… not captured mid-animation.

Force scroll-behavior:auto on <html>/<body> in prepareBodyForSnapshot, the
autoscroll warm-up, and baseline captureBodyRect so scrollTo(0,0) jumps to the
origin instead of easing. On pages with html{scroll-behavior:smooth} the reset
was animated, so geometry was measured while the page was still scrolled down,
offsetting the whole subset (top:-1542px with a matching blank band at the
bottom of the canvas).

Also share the canvas-viewport resize guard between the subset and the baseline
so both revert together on fluid / viewport-driven pages.
…rate, grayscale, sepia, invert, opacity, hue-rotate) to a ColorMatrixFilter during HTML import, clamping amounts to the browser range.
…e during HTML import, keeping the background-color Fill underneath as the blend backdrop while leaving the bottom-most background layer unblended.
…) into a contour mask during HTML import and honor clipPathUnits=objectBoundingBox, keeping the snapshot and subset filters in sync.
@OnionsYu OnionsYu changed the title Improve HTML-to-PAGX import robustness and html-snapshot fidelity, and add a single-child Layer collapse optimizer Improve HTML-to-PAGX fidelity and optimize generated PAGX Jul 21, 2026
Comment thread src/pagx/html/importer/HTMLElementEmitter.cpp Outdated
Comment thread test/src/PAGXHTMLImporterTest.cpp
Comment thread test/src/PAGXHTMLImporterTest.cpp
Comment thread src/pagx/html/importer/HTMLLayerBuilder.cpp
Comment thread tools/html-snapshot/eval/baseline.js
@shlzxjp
shlzxjp merged commit e5a9ad0 into Tencent:main Jul 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants