feat: enhance background image handling and opacity management#2068
Merged
feat: enhance background image handling and opacity management#2068
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the image primitive to support background-like layout controls (cover/contain/fill/auto + positioning/offset/scale) by reusing the background image drawing pipeline, and refactors background sizing to be expressed via backgroundMode shorthands.
Changes:
- Add
imageMode/imagePosition/imageScale/imageOffsetX|Ysupport to image rendering and clip behavior when layout can overflow. - Replace
backgroundSizingusage withbackgroundModeshorthands likeno-repeat-coveracross rendering contributions and browser demos. - Improve background image sizing when resources report
width/height = 0by using intrinsic dimensions (naturalWidth/Height,videoWidth/Height) and add/adjust unit tests.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/vrender/tests/browser/src/pages/image.ts | Updates browser demo page to showcase image sizing modes and live SVG swapping. |
| packages/vrender/tests/browser/src/pages/background.ts | Migrates demo usage from backgroundSizing to backgroundMode sizing shorthands. |
| packages/vrender-core/src/render/contributions/render/image-render.ts | Implements image layout drawing via drawBackgroundImage and adds layout-based clipping logic. |
| packages/vrender-core/src/render/contributions/render/draw-contribution.ts | Stops forwarding backgroundSizing from stage attributes into background render params. |
| packages/vrender-core/src/render/contributions/render/contributions/text-contribution-render.ts | Removes backgroundSizing plumbing from text background rendering contribution. |
| packages/vrender-core/src/render/contributions/render/contributions/group-contribution-render.ts | Removes backgroundSizing plumbing from group background rendering contribution. |
| packages/vrender-core/src/render/contributions/render/contributions/base-contribution-render.ts | Introduces backgroundMode sizing shorthands resolution + intrinsic size detection for image-like resources. |
| packages/vrender-core/src/interface/graphic/image.ts | Adds new image layout attributes to the image attribute interface. |
| packages/vrender-core/src/interface/graphic.ts | Expands backgroundMode typing to include no-repeat sizing shorthands and removes backgroundSizing. |
| packages/vrender-core/src/graphic/image.ts | Ensures image layout attributes participate in update tagging and non-animatable attribute config. |
| packages/vrender-core/src/graphic/config.ts | Sets defaults for new image layout attributes and removes backgroundSizing defaults. |
| packages/vrender-core/tests/image/image-layout.test.ts | Adds unit tests for image layout modes and layout-driven clipping. |
| packages/vrender-core/tests/background/background-image-layout.test.ts | Updates background layout tests for backgroundMode shorthands and new resolver behavior. |
Comments suppressed due to low confidence (1)
packages/vrender-core/src/render/contributions/render/contributions/base-contribution-render.ts:114
IBackgroundImageDrawParams/drawBackgroundImageno longer accept or resolvebackgroundSizing. If existing callers still setbackgroundSizingon attributes (previously supported), the sizing choice will be dropped and behavior will change. To avoid regressions, consider reintroducingbackgroundSizing?: BackgroundSizinghere (deprecated) and lettingresolveBackgroundDrawModeprefer it whenbackgroundModeisno-repeatand not one of theno-repeat-*shorthands.
export type IBackgroundImageDrawParams = {
backgroundMode: IGraphicAttribute['backgroundMode'];
backgroundFit: boolean;
backgroundKeepAspectRatio: boolean;
backgroundScale?: number;
backgroundOffsetX?: number;
backgroundOffsetY?: number;
backgroundPosition?: IGraphicAttribute['backgroundPosition'];
};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xuefei1313
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
🐞 Bugserver case id
💡 Background and solution
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough