@@ -24,6 +24,7 @@ import {CSSParsedCounterDeclaration, CSSParsedPseudoDeclaration} from '../css/in
2424import { getQuote } from '../css/property-descriptors/quotes' ;
2525import { Context } from '../core/context' ;
2626import { DebuggerType , isDebugging } from '../core/debugger' ;
27+ import { getObjectFitSize , OBJECT_FIT , objectFit } from '../css/property-descriptors/object-fit' ;
2728
2829export interface CloneOptions {
2930 ignoreElements ?: ( element : Element ) => boolean ;
@@ -256,9 +257,38 @@ export class DocumentCloner {
256257
257258 try {
258259 if ( ctx ) {
259- ctx . drawImage ( video , 0 , 0 , canvas . width , canvas . height ) ;
260- if ( ! this . options . allowTaint ) {
261- ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) ;
260+ const elObjectFit = objectFit . parse (
261+ this . context ,
262+ video . ownerDocument . defaultView ?. getComputedStyle ( video ) . objectFit ?? ''
263+ ) ;
264+ if ( elObjectFit == OBJECT_FIT . CONTAIN || elObjectFit == OBJECT_FIT . COVER ) {
265+ const dimension = getObjectFitSize (
266+ elObjectFit == OBJECT_FIT . CONTAIN ,
267+ video . offsetWidth ,
268+ video . offsetHeight ,
269+ video . videoWidth ,
270+ video . videoHeight
271+ ) ;
272+
273+ ctx . drawImage (
274+ video ,
275+ 0 ,
276+ 0 ,
277+ video . videoWidth ,
278+ video . videoHeight ,
279+ dimension . x ,
280+ dimension . y ,
281+ dimension . width ,
282+ dimension . height
283+ ) ;
284+ if ( ! this . options . allowTaint ) {
285+ ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) ;
286+ }
287+ } else {
288+ ctx . drawImage ( video , 0 , 0 , canvas . width , canvas . height ) ;
289+ if ( ! this . options . allowTaint ) {
290+ ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) ;
291+ }
262292 }
263293 }
264294 return canvas ;
0 commit comments