mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
2.1 KiB
JavaScript
1 line
2.1 KiB
JavaScript
(()=>{return(t,a)=>{var s;(function(t){t["Default"]="default";t["Info"]="info";t["Success"]="success";t["Error"]="error"})(s||(s={}));let e;class r{constructor(t="",a="",e=s.Default){this.creationTime=new Date;this.type=e;this.message=t;this.title=a;this.duration=3e3;this.randomKey=Math.floor(Math.random()*(Number.MAX_SAFE_INTEGER+1))}show(){r.containerVM.cards.splice(0,0,this);if(this.duration!==undefined){setTimeout(()=>this.dismiss(),this.duration)}}dismiss(){if(r.containerVM.cards.includes(this)){r.containerVM.cards.splice(r.containerVM.cards.indexOf(this),1)}}get element(){return dq(`.toast-card[data-key='${this.key}']`)}get key(){return this.creationTime.toISOString()+`[${this.randomKey}]`}static get containerVM(){if(!e){r.createToastContainer()}return e}static createToastContainer(){if(!document.querySelector(".toast-card-container")){document.body.insertAdjacentHTML("beforeend",`\n<transition-group class="toast-card-container" name="toast-card-container" tag="div">\n<toast-card v-for="card of cards" :data-key="card.key" :key="card.key" :card="card"></toast-card>\n</transition-group>`);e=new Vue({el:".toast-card-container",components:{"toast-card":{props:["card"],template:`\n<div class="toast-card icons-enabled visible" :class="'toast-' + card.type">\n<div class="toast-card-border"></div>\n<div class="toast-card-header">\n<h1 class="toast-card-title">{{card.title}}</h1>\n<div class="toast-card-dismiss" @click="card.dismiss()">\n<svg style="width:22px;height:22px" viewBox="0 0 24 24">\n<path\n d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" />\n</svg>\n</div>\n</div>\n<div class="toast-card-message" v-html="card.message"></div>\n</div>\n`}},data:{cards:[]}})}}static internalShow(t,a,s,e){const n=new r(t,a,e);n.duration=s;n.show();return n}static show(t,a,e){return this.internalShow(t,a,e,s.Default)}static info(t,a,e){return this.internalShow(t,a,e,s.Info)}static success(t,a,e){return this.internalShow(t,a,e,s.Success)}static error(t,a,e){return this.internalShow(t,a,e,s.Error)}}a.applyStyle("toastStyle");return{export:r}}})(); |