import{Y as t,Z as i,o as a,j as s,w as o,a0 as n,m as e,y as r,z as h,B as m}from"./index-d4baa715.js";import{c as l}from"./createAnimation.a561e009.js";import{_ as c}from"./_plugin-vue_export-helper.1b428a4d.js";const d=c({name:"uv-transition",mixins:[t,i],emits:["click","change"],props:{show:{type:Boolean,default:!1},mode:{type:[Array,String,null],default:()=>"fade"},duration:{type:[String,Number],default:300},timingFunction:{type:String,default:"ease-out"},customClass:{type:String,default:""},cellChild:{type:Boolean,default:!1}},data:()=>({isShow:!1,transform:"",opacity:1,animationData:{},durationTime:300,config:{}}),watch:{show:{handler(t){t?this.open():this.isShow&&this.close()},immediate:!0}},computed:{transformStyles(){const t={transform:this.transform,opacity:this.opacity,...this.$uv.addStyle(this.customStyle),"transition-duration":this.duration/1e3+"s"};return this.$uv.addStyle(t,"string")}},created(){this.config={duration:this.duration,timingFunction:this.timingFunction,transformOrigin:"50% 50%",delay:0},this.durationTime=this.duration},methods:{init(t={}){t.duration&&(this.durationTime=t.duration),this.animation=l(Object.assign(this.config,t),this)},onClick(){this.$emit("click",{detail:this.isShow})},step(t,i={}){if(this.animation){for(let i in t)try{"object"==typeof t[i]?this.animation[i](...t[i]):this.animation[i](t[i])}catch(a){console.error(`方法 ${i} 不存在`)}return this.animation.step(i),this}},run(t){this.animation&&this.animation.run(t)},open(){clearTimeout(this.timer),this.transform="",this.isShow=!0;let{opacity:t,transform:i}=this.styleInit(!1);void 0!==t&&(this.opacity=t),this.transform=i,this.$nextTick((()=>{this.timer=setTimeout((()=>{this.animation=l(this.config,this),this.tranfromInit(!1).step(),this.animation.run(),this.opacity=1,this.$emit("change",{detail:this.isShow})}),20)}))},close(t){this.animation&&this.tranfromInit(!0).step().run((()=>{this.isShow=!1,this.animationData=null,this.animation=null;let{opacity:t,transform:i}=this.styleInit(!1);this.opacity=t||1,this.transform=i,this.$emit("change",{detail:this.isShow})}))},styleInit(t){let i={transform:""},a=(t,a)=>{"fade"===a?i.opacity=this.animationType(t)[a]:i.transform+=this.animationType(t)[a]+" "};return"string"==typeof this.mode?a(t,this.mode):this.mode.forEach((i=>{a(t,i)})),i},tranfromInit(t){let i=(t,i)=>{let a=null;"fade"===i?a=t?0:1:(a=t?"-100%":"0","zoom-in"===i&&(a=t?.8:1),"zoom-out"===i&&(a=t?1.2:1),"slide-right"===i&&(a=t?"100%":"0"),"slide-bottom"===i&&(a=t?"100%":"0")),this.animation[this.animationMode()[i]](a)};return"string"==typeof this.mode?i(t,this.mode):this.mode.forEach((a=>{i(t,a)})),this.animation},animationType:t=>({fade:t?1:0,"slide-top":`translateY(${t?"0":"-100%"})`,"slide-right":`translateX(${t?"0":"100%"})`,"slide-bottom":`translateY(${t?"0":"100%"})`,"slide-left":`translateX(${t?"0":"-100%"})`,"zoom-in":`scaleX(${t?1:.8}) scaleY(${t?1:.8})`,"zoom-out":`scaleX(${t?1:1.2}) scaleY(${t?1:1.2})`}),animationMode:()=>({fade:"opacity","slide-top":"translateY","slide-right":"translateX","slide-bottom":"translateY","slide-left":"translateX","zoom-in":"scale","zoom-out":"scale"}),toLine:t=>t.replace(/([A-Z])/g,"-$1").toLowerCase()}},[["render",function(t,i,l,c,d,u){const f=m;return d.isShow?(a(),s(f,{key:0,ref:"ani",animation:d.animationData,class:e(l.customClass),style:r(u.transformStyles),onClick:u.onClick},{default:o((()=>[n(t.$slots,"default")])),_:3},8,["animation","class","style","onClick"])):h("",!0)}]]);export{d as _};
