-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add limited support for objectPosition property
- Loading branch information
1 parent
29fe2e4
commit 940de75
Showing
3 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function getPreserveAspectRatio( | ||
objectFit: string, | ||
objectPosition?: string | ||
) { | ||
if (objectFit !== 'contain' && objectFit !== 'cover') { | ||
return 'none' | ||
} | ||
|
||
let align = 'xMidYMid' | ||
|
||
if (objectPosition) { | ||
const parts = objectPosition.split(' ') | ||
|
||
if (parts.length === 2) { | ||
const [x, y] = parts | ||
|
||
if (x === 'left') { | ||
align = 'xMin' | ||
} else if (x === 'right') { | ||
align = 'xMax' | ||
} else { | ||
align = 'XMid' | ||
} | ||
|
||
if (y === 'top') { | ||
align += 'YMin' | ||
} else if (y === 'bottom') { | ||
align += 'YMax' | ||
} else { | ||
align += 'YMid' | ||
} | ||
} | ||
} | ||
|
||
return align + (objectFit === 'cover' ? ' slice' : '') | ||
} |
This file contains 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
This file contains 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