/**
 * @since Last modified: 2024-07-20 16:03:41
 * @function fadeIn
 * @description Let the hidden element or element with transparency be completely displayed.
 * @param {object} options  - The parameters of fade in.
 * @param {getEl} [options.el]  - The target node.The writing is the same as getEl.
 * @param {string} [options.display=block]  - The display of box.Can be filled in:'block'|'flex'|'inline-flex'|'inline-block'|'grid'.
 * @param {curve} [options.curve=easeOut]  - Animation curve.Can be filled in:'linear'|'ease'|'easeIn'|'easeOut'|'easeInOut'|'easeOutIn'.
 * @param {number} [options.duration=200]  - The duration of fade in.The unit is ms.
 * @param {fn_cb_ease_app} [options.doing]  - The call back in progress.Support parameters:"frame" , "step" and "value"(opacity value).
 * @param {fn_cb_ease_app} [options.done]  - The call back after completion.Support parameters:"frame" , "step" and "value"(opacity value).
 * @returns {*} - The the target dom.
 * @see {@link https://codepen.io/axui/pen/gOqEdWx|demo @ codepen}
 * @example
 * ax.fadeIn({el:'#demo'});
 * <!--return the target dom-->
 */
'use strict';
import getEl from "./getEl";
import elState from "./elState";
import ease from "./ease";
import style from "./style";
let fadeIn = ({ el, display = 'block', doing, done, duration = 200, curve = 'easeOut' }) => {
    let target = getEl(el);
    if (!target) {
        throw new Error('The target node does not exist!');
    }
    let state = elState(target), opacity = parseFloat(style(target).opacity), from = { opacity: 0 };
    if (opacity === 1) {
        return target;
    }
    if (state.isHidden) {
        from.opacity = 0;
        target.style.display = display;
        target.style.opacity = 0;
    }
    else if (state.isCalc && opacity !== 1) {
        from.opacity = opacity;
    }
    ease({
        from,
        to: { opacity: 1 },
        duration,
        curve,
        doing: (e) => {
            target.style.opacity = e.value.opacity;
            doing && doing.call(target, { frame: e.frame, value: e.value.opacity, step: e.step });
        }, done: (e) => {
            target.style.opacity = 1;
            done && done.call(target, { frame: e.frame, value: e.value.opacity, step: e.step });
        }
    });
    return target;
};
export default fadeIn;
