mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(common): remove unnecessary parseFloat from ng_optimized_image directive. (#48527)
There is no need to parse clientWidth/clientHeight/naturalWidth/naturalHeight on HTMLImageElement as there is no sign of other types being returned on everygreen browers. PR Close #48527
This commit is contained in:
parent
687ab0447b
commit
b3fca32a79
1 changed files with 5 additions and 8 deletions
|
|
@ -775,16 +775,13 @@ function assertNoImageDistortion(
|
|||
dir: NgOptimizedImage, img: HTMLImageElement, renderer: Renderer2) {
|
||||
const removeListenerFn = renderer.listen(img, 'load', () => {
|
||||
removeListenerFn();
|
||||
// TODO: `clientWidth`, `clientHeight`, `naturalWidth` and `naturalHeight`
|
||||
// are typed as number, but we run `parseFloat` (which accepts strings only).
|
||||
// Verify whether `parseFloat` is needed in the cases below.
|
||||
const renderedWidth = parseFloat(img.clientWidth as any);
|
||||
const renderedHeight = parseFloat(img.clientHeight as any);
|
||||
const renderedWidth = img.clientWidth;
|
||||
const renderedHeight = img.clientHeight;
|
||||
const renderedAspectRatio = renderedWidth / renderedHeight;
|
||||
const nonZeroRenderedDimensions = renderedWidth !== 0 && renderedHeight !== 0;
|
||||
|
||||
const intrinsicWidth = parseFloat(img.naturalWidth as any);
|
||||
const intrinsicHeight = parseFloat(img.naturalHeight as any);
|
||||
const intrinsicWidth = img.naturalWidth;
|
||||
const intrinsicHeight = img.naturalHeight;
|
||||
const intrinsicAspectRatio = intrinsicWidth / intrinsicHeight;
|
||||
|
||||
const suppliedWidth = dir.width!;
|
||||
|
|
@ -888,7 +885,7 @@ function assertNonZeroRenderedHeight(
|
|||
dir: NgOptimizedImage, img: HTMLImageElement, renderer: Renderer2) {
|
||||
const removeListenerFn = renderer.listen(img, 'load', () => {
|
||||
removeListenerFn();
|
||||
const renderedHeight = parseFloat(img.clientHeight as any);
|
||||
const renderedHeight = img.clientHeight;
|
||||
if (dir.fill && renderedHeight === 0) {
|
||||
console.warn(formatRuntimeError(
|
||||
RuntimeErrorCode.INVALID_INPUT,
|
||||
|
|
|
|||
Loading…
Reference in a new issue