@use 'sass:math';

@import '../shared-styles/index';

:host {
    display: block;
    position: relative;
    line-height: 0;
}

:host ::ng-deep img {
    display: block;
    //this is required for the JS polyfill to take effect on non-supporting browsers like IE. See image.js
    font-family: 'object-fit: cover;';
    object-fit: cover;
    height: 100%;
    width: 100%;
}

// for "rounded" and empty nxFigure attribute
:host(.nx-image--auto) ::ng-deep img {
    height: auto;
}

// for all other classes like 1by1 or 1dot8by1 etc. reposition the img
:host(:not(.nx-image--auto)) ::ng-deep img {
    position: absolute;
    top: 0;
    left: 0;

    [dir='rtl'] & {
        right: 0;
        left: auto;
    }
}

:host(.nx-image--rounded) {
    padding-top: 100%;

    ::ng-deep img {
        border-radius: 50%;
        bottom: 0;
        left: 0;
        position: absolute;
        right: 0;
        top: 0;
    }
}

:host(.nx-image--1by1) {
    padding-top: 100%;
}

:host(.nx-image--1dot8by1) {
    padding-top: percentage(math.div(1, 1.8));
}

:host(.nx-image--1dot2by1) {
    padding-top: percentage(math.div(1, 1.2));
}

:host(.nx-image--1by1dot1) {
    padding-top: percentage(math.div(1.1, 1));
}

:host(.nx-image--2dot6by1) {
    padding-top: percentage(math.div(1, 2.6));
}

:host(.nx-image--1by1dot4) {
    padding-top: percentage(math.div(1.4, 1));
}
