11import { DefaultAttribute } from '../../src/graphic/config' ;
22import {
33 DefaultBaseBackgroundRenderContribution ,
4- drawBackgroundImage
4+ drawBackgroundImage ,
5+ resolveBackgroundDrawMode
56} from '../../src/render/contributions/render/contributions/base-contribution-render' ;
67import { DefaultGroupBackgroundRenderContribution } from '../../src/render/contributions/render/contributions/group-contribution-render' ;
78import { DefaultTextBackgroundRenderContribution } from '../../src/render/contributions/render/contributions/text-contribution-render' ;
@@ -101,24 +102,103 @@ describe('background image layout', () => {
101102 const context = createContext ( ) ;
102103
103104 drawBackgroundImage ( context as any , createImage ( 200 , 100 ) , createBounds ( 0 , 0 , 100 , 100 ) as any , {
104- backgroundMode : 'no-repeat' ,
105+ backgroundMode : 'no-repeat-contain ' ,
105106 backgroundFit : true ,
106107 backgroundKeepAspectRatio : true ,
107- backgroundSizing : 'contain' ,
108108 backgroundPosition : 'bottom-right'
109109 } ) ;
110110
111111 expect ( context . drawImage ) . toHaveBeenCalledWith ( expect . anything ( ) , 0 , 50 , 100 , 50 ) ;
112112 } ) ;
113113
114+ test ( 'resolves legacy no-repeat config and sizing shorthands correctly' , ( ) => {
115+ // Legacy: backgroundFit + backgroundKeepAspectRatio
116+ expect (
117+ resolveBackgroundDrawMode ( {
118+ backgroundMode : 'no-repeat' ,
119+ backgroundFit : true ,
120+ backgroundKeepAspectRatio : true
121+ } )
122+ ) . toEqual ( {
123+ backgroundRepeatMode : 'no-repeat' ,
124+ backgroundSizing : 'cover'
125+ } ) ;
126+
127+ expect (
128+ resolveBackgroundDrawMode ( {
129+ backgroundMode : 'no-repeat' ,
130+ backgroundFit : true ,
131+ backgroundKeepAspectRatio : false
132+ } )
133+ ) . toEqual ( {
134+ backgroundRepeatMode : 'no-repeat' ,
135+ backgroundSizing : 'fill'
136+ } ) ;
137+
138+ expect (
139+ resolveBackgroundDrawMode ( {
140+ backgroundMode : 'no-repeat' ,
141+ backgroundFit : false ,
142+ backgroundKeepAspectRatio : true
143+ } )
144+ ) . toEqual ( {
145+ backgroundRepeatMode : 'no-repeat' ,
146+ backgroundSizing : 'auto'
147+ } ) ;
148+
149+ // Shorthands: override backgroundFit/backgroundKeepAspectRatio
150+ expect (
151+ resolveBackgroundDrawMode ( {
152+ backgroundMode : 'no-repeat-contain' ,
153+ backgroundFit : true ,
154+ backgroundKeepAspectRatio : false
155+ } )
156+ ) . toEqual ( {
157+ backgroundRepeatMode : 'no-repeat' ,
158+ backgroundSizing : 'contain'
159+ } ) ;
160+
161+ expect (
162+ resolveBackgroundDrawMode ( {
163+ backgroundMode : 'no-repeat-cover' ,
164+ backgroundFit : false ,
165+ backgroundKeepAspectRatio : false
166+ } )
167+ ) . toEqual ( {
168+ backgroundRepeatMode : 'no-repeat' ,
169+ backgroundSizing : 'cover'
170+ } ) ;
171+
172+ expect (
173+ resolveBackgroundDrawMode ( {
174+ backgroundMode : 'no-repeat-fill' ,
175+ backgroundFit : false ,
176+ backgroundKeepAspectRatio : true
177+ } )
178+ ) . toEqual ( {
179+ backgroundRepeatMode : 'no-repeat' ,
180+ backgroundSizing : 'fill'
181+ } ) ;
182+
183+ expect (
184+ resolveBackgroundDrawMode ( {
185+ backgroundMode : 'no-repeat-auto' ,
186+ backgroundFit : true ,
187+ backgroundKeepAspectRatio : true
188+ } )
189+ ) . toEqual ( {
190+ backgroundRepeatMode : 'no-repeat' ,
191+ backgroundSizing : 'auto'
192+ } ) ;
193+ } ) ;
194+
114195 test ( 'supports fill layout with scaling and centered alignment' , ( ) => {
115196 const context = createContext ( ) ;
116197
117198 drawBackgroundImage ( context as any , createImage ( 20 , 10 ) , createBounds ( 0 , 0 , 100 , 100 ) as any , {
118199 backgroundMode : 'no-repeat' ,
119200 backgroundFit : true ,
120201 backgroundKeepAspectRatio : false ,
121- backgroundSizing : 'fill' ,
122202 backgroundScale : 0.5 ,
123203 backgroundPosition : 'center'
124204 } ) ;
@@ -133,7 +213,6 @@ describe('background image layout', () => {
133213 backgroundMode : 'no-repeat' ,
134214 backgroundFit : false ,
135215 backgroundKeepAspectRatio : true ,
136- backgroundSizing : 'auto' ,
137216 backgroundPosition : [ '50%' , '100%' ]
138217 } ) ;
139218
@@ -148,7 +227,7 @@ describe('background image layout', () => {
148227 {
149228 attribute : {
150229 background : { background : 'image-key' } ,
151- backgroundSizing : 'contain' ,
230+ backgroundMode : 'no-repeat- contain' ,
152231 backgroundPosition : 'center' ,
153232 backgroundClip : true
154233 } ,
@@ -168,7 +247,7 @@ describe('background image layout', () => {
168247 { } as any
169248 ) ;
170249
171- expect ( contribution . capturedParams . backgroundSizing ) . toBe ( 'contain' ) ;
250+ expect ( contribution . capturedParams . backgroundMode ) . toBe ( 'no-repeat- contain' ) ;
172251 expect ( contribution . capturedParams . backgroundPosition ) . toBe ( 'center' ) ;
173252 expect ( context . clip ) . toHaveBeenCalled ( ) ;
174253 } ) ;
@@ -181,7 +260,7 @@ describe('background image layout', () => {
181260 {
182261 attribute : {
183262 background : 'image-key' ,
184- backgroundSizing : 'contain' ,
263+ backgroundMode : 'no-repeat- contain' ,
185264 backgroundPosition : 'bottom-right' ,
186265 backgroundClip : true
187266 } ,
@@ -202,7 +281,7 @@ describe('background image layout', () => {
202281 { } as any
203282 ) ;
204283
205- expect ( contribution . capturedParams . backgroundSizing ) . toBe ( 'contain' ) ;
284+ expect ( contribution . capturedParams . backgroundMode ) . toBe ( 'no-repeat- contain' ) ;
206285 expect ( contribution . capturedParams . backgroundPosition ) . toBe ( 'bottom-right' ) ;
207286 expect ( context . clip ) . toHaveBeenCalled ( ) ;
208287 } ) ;
@@ -224,7 +303,8 @@ describe('background image layout', () => {
224303 dx : 5 ,
225304 dy : 6
226305 } ,
227- backgroundSizing : 'auto' ,
306+ backgroundMode : 'no-repeat' ,
307+ backgroundFit : false ,
228308 backgroundPosition : 'bottom-right' ,
229309 backgroundClip : true ,
230310 backgroundCornerRadius : 0
@@ -250,7 +330,8 @@ describe('background image layout', () => {
250330 expect ( contribution . capturedBounds . y1 ) . toBe ( 26 ) ;
251331 expect ( contribution . capturedBounds . width ( ) ) . toBe ( 30 ) ;
252332 expect ( contribution . capturedBounds . height ( ) ) . toBe ( 40 ) ;
253- expect ( contribution . capturedParams . backgroundSizing ) . toBe ( 'auto' ) ;
333+ expect ( contribution . capturedParams . backgroundMode ) . toBe ( 'no-repeat' ) ;
334+ expect ( contribution . capturedParams . backgroundFit ) . toBe ( false ) ;
254335 expect ( contribution . capturedParams . backgroundPosition ) . toBe ( 'bottom-right' ) ;
255336 expect ( context . clip ) . toHaveBeenCalled ( ) ;
256337 } ) ;
@@ -267,7 +348,6 @@ describe('background image layout', () => {
267348 backgroundMode : 'no-repeat' ,
268349 backgroundFit : true ,
269350 backgroundKeepAspectRatio : true ,
270- backgroundSizing : 'cover' ,
271351 backgroundPosition : 'center' ,
272352 backgroundScale : 1 ,
273353 backgroundOffsetX : 0 ,
0 commit comments