class BladewindNotification { title; message; type; dismissInSeconds; name; timeoutName; colours; constructor({ title = "", message = "", type = "success", dismissInSeconds = 15, size = "regular", name = null }) { this.title = title; this.message = message; this.type = type; this.dismissInSeconds = (dismissInSeconds || 15) * 1000; this.name = name || Math.floor((Math.random() * 10000) + 1); this.name = `notification-${this.name}`; this.timeoutName = this.name.replace('notification-', 'timeout_'); this.colours = { "success": {"border": "border-green-500/50", "bg": "bg-green-200/80"}, "error": {"border": "border-red-500/50", "bg": "bg-red-200/80"}, "warning": {"border": "border-yellow-500/50", "bg": "bg-amber-200/80"}, "info": {"border": "border-blue-500/50", "bg": "bg-blue-200/80"}, }; this.size = size; this.sizes = { "small": { "container": "sm:!max-w-[350px]", "modal_icon": "!size-10", "close": "size-6", "heading": "text-base", "message": "text-sm" }, "regular": { "container": "sm:!max-w-[450px]", "modal_icon": "!size-14", "close": "size-6", "heading": "text-lg", "message": "text-sm" }, "big": { "container": "sm:!max-w-[550px]", "modal_icon": "!size-16", "close": "size-6", "heading": "text-3xl", "message": "text-base" } }; this.setContainerSize(); } show = () => { if (domEl(`.${this.name}`)) { clearTimeout(this.timeoutName); domEl(`.${this.name}`).remove(); } domEl('.bw-notification-container').insertAdjacentHTML('beforeend', this.template()); animateCSS(`.${this.name}`, 'fadeInRight').then(() => { this.timeoutName = setTimeout(() => { this.hide(); }, this.dismissInSeconds); this.closable(); }); } hide = () => { animateCSS(`.${this.name}`, 'fadeOutRight').then(() => { domEl(`.${this.name}`).remove(); clearTimeout(this.timeoutName); }); } closable = () => { domEl(`.${this.name} .close`).addEventListener('click', () => { this.hide(); }); } setContainerSize = () => { changeCss('.bw-notification-container', this.sizes[this.size].container, 'add'); } modalIcon = () => { changeCss(`.bw-notification-icons .${this.type}`, this.sizes[this.size].modal_icon, 'add'); changeCss(`.bw-notification-icons .${this.type}`, 'hidden', 'remove'); return domEl(`.bw-notification-icons .${this.type}`).outerHTML.replaceAll('[type]', this.typeColour(this.type)); } template = () => { return `