UNPKG

qmsg

Version:

一款优雅的页面消息提示插件,兼容性良好,无任何依赖。

3 lines (2 loc) 27.6 kB
"use strict";const t={get PLUGIN_NAME(){return"qmsg"},get NAMESPACE(){return"qmsg"},INS_DEFAULT:{},get config(){return{parent:document.body||document.documentElement,useShadowRoot:!0,shadowRootMode:"open",animation:!0,autoClose:!0,listenEventToPauseAutoClose:!0,content:"",isHTML:!1,position:"top",showClose:!1,maxNums:5,onClose:null,showIcon:!0,showMoreContent:!1,showReverse:!1,timeout:2500,type:"info",zIndex:5e4,style:"",customClass:"",isLimitWidth:!1,limitWidthNum:200,limitWidthWrap:"no-wrap",consoleLogContent:!1,afterRender:null}}},e={info:'\n\t\t<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">\n\t\t\t<path d="M512 64q190.016 4.992 316.512 131.488T960 512q-4.992 190.016-131.488 316.512T512 960q-190.016-4.992-316.512-131.488T64 512q4.992-190.016 131.488-316.512T512 64zm67.008 275.008q26.016 0 43.008-15.488t16.992-41.504-16.992-41.504-42.496-15.488-42.496 15.488-16.992 41.504 16.992 41.504 42.016 15.488zm12 360q0-6.016.992-16T592 664l-52.992 60.992q-8 8.992-16.512 14.016T508 742.016q-8.992-4-8-14.016l88-276.992q4.992-28-8.992-48t-44.992-24q-35.008.992-76.512 29.504t-72.512 72.512v15.008q-.992 10.016 0 19.008l52.992-60.992q8-8.992 16.512-14.016T468 437.024q10.016 4.992 7.008 16l-87.008 276q-7.008 24.992 7.008 44.512T444 800.032q50.016-.992 84-28.992t63.008-72z" fill="#909399"/>\n\t\t</svg>',warning:'\n\n\t\t<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">\n\t\t\t<path d="M512 64C264.64 64 64 264.64 64 512c0 247.424 200.64 448 448 448 247.488 0 448-200.576 448-448 0-247.36-200.512-448-448-448zm0 704c-26.432 0-48-21.504-48-48s21.568-48 48-48c26.624 0 48 21.504 48 48s-21.376 48-48 48zm48-240c0 26.56-21.376 48-48 48-26.432 0-48-21.44-48-48V304c0-26.56 21.568-48 48-48 26.624 0 48 21.44 48 48v224z" fill="#E6A23C"/>\n\t\t</svg>',error:'\n\n\t\t<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">\n\t\t\t<path d="M512 64C264.58 64 64 264.58 64 512s200.58 448 448 448 448-200.57 448-448S759.42 64 512 64zm158.39 561.14a32 32 0 1 1-45.25 45.26L512 557.26 398.86 670.4a32 32 0 0 1-45.25-45.26L466.75 512 353.61 398.86a32 32 0 0 1 45.25-45.25L512 466.74l113.14-113.13a32 32 0 0 1 45.25 45.25L557.25 512z" fill="#F56C6C"/>\n\t\t</svg>',success:'\n\n\t\t<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16">\n\t\t\t<path d="M512 64q190.016 4.992 316.512 131.488T960 512q-4.992 190.016-131.488 316.512T512 960q-190.016-4.992-316.512-131.488T64 512q4.992-190.016 131.488-316.512T512 64zm-56 536l-99.008-99.008q-12-11.008-27.488-11.008t-27.008 11.488-11.488 26.496 11.008 27.008l127.008 127.008q11.008 11.008 27.008 11.008t27.008-11.008l263.008-263.008q15.008-15.008 9.504-36.512t-27.008-27.008-36.512 9.504z" fill="#67C23A"/>\n\t\t</svg>',loading:'\n\t\t<svg class="animate-turn" width="16" height="16" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">\n\t\t\t<path fill="#fff" fill-opacity=".01" d="M0 0h48v48H0z"/>\n\t\t\t<path d="M4 24c0 11.046 8.954 20 20 20s20-8.954 20-20S35.046 4 24 4" stroke="#409eff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>\n\t\t\t<path d="M36 24c0-6.627-5.373-12-12-12s-12 5.373-12 12 5.373 12 12 12" stroke="#409eff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>\n\t\t</svg>'},n={insInfoList:[],remove(t){let e=!1;for(let s=0;s<n.insInfoList.length;s++)if(n.insInfoList[s].uuid===t){n.insInfoList.splice(s,1),e=!0;break}return e}},s=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,i=536870912,r=1073741824,o=new WeakMap;var a;const l=((t,e)=>n=>{const o=e.get(n);let a=void 0===o?n.size:o<r?o+1:0;if(!n.has(a))return t(n,a);if(n.size<i){for(;n.has(a);)a=Math.floor(Math.random()*r);return t(n,a)}if(n.size>s)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;n.has(a);)a=Math.floor(Math.random()*s);return t(n,a)})((a=o,(t,e)=>(a.set(t,e),e)),o),c=new WeakMap,m=new WeakMap,g=new Map([[0,null]]),u=new Map([[0,null]]),h=(t=>{const e=(n=t,{...n,connect:({call:t})=>async()=>{const{port1:e,port2:n}=new MessageChannel,s=await t("connect",{port:e},[e]);return c.set(n,s),n},disconnect:({call:t})=>async e=>{const n=c.get(e);if(void 0===n)throw new Error("The given port is not connected.");await t("disconnect",{portId:n})},isSupported:({call:t})=>()=>t("isSupported")});var n;return t=>{const n=(t=>{if(m.has(t))return m.get(t);const e=new Map;return m.set(t,e),e})(t);t.addEventListener("message",({data:t})=>{const{id:e}=t;if(null!==e&&n.has(e)){const{reject:s,resolve:i}=n.get(e);n.delete(e),void 0===t.error?i(t.result):s(new Error(t.error.message))}}),(t=>"function"==typeof t.start)(t)&&t.start();const s=(e,s=null,i=[])=>new Promise((r,o)=>{const a=l(n);n.set(a,{reject:o,resolve:r}),null===s?t.postMessage({id:a,method:e},i):t.postMessage({id:a,method:e,params:s},i)}),i=(e,n,s=[])=>{t.postMessage({id:null,method:e,params:n},s)};let r={};for(const[t,n]of Object.entries(e))r={...r,[t]:n({call:s,notify:i})};return{...r}}})({clearInterval:({call:t})=>e=>{"symbol"==typeof g.get(e)&&(g.set(e,null),t("clear",{timerId:e,timerType:"interval"}).then(()=>{g.delete(e)}))},clearTimeout:({call:t})=>e=>{"symbol"==typeof u.get(e)&&(u.set(e,null),t("clear",{timerId:e,timerType:"timeout"}).then(()=>{u.delete(e)}))},setInterval:({call:t})=>(e,n=0,...s)=>{const i=Symbol(),r=l(g);g.set(r,i);const o=()=>t("set",{delay:n,now:performance.timeOrigin+performance.now(),timerId:r,timerType:"interval"}).then(()=>{const t=g.get(r);if(void 0===t)throw new Error("The timer is in an undefined state.");t===i&&(e(...s),g.get(r)===i&&o())});return o(),r},setTimeout:({call:t})=>(e,n=0,...s)=>{const i=Symbol(),r=l(u);return u.set(r,i),t("set",{delay:n,now:performance.timeOrigin+performance.now(),timerId:r,timerType:"timeout"}).then(()=>{const t=u.get(r);if(void 0===t)throw new Error("The timer is in an undefined state.");t===i&&(u.delete(r),e(...s))}),r}}),d=((t,e)=>{let n=null;return()=>{if(null!==n)return n;const s=new Blob([e],{type:"application/javascript; charset=utf-8"}),i=URL.createObjectURL(s);return n=t(i),setTimeout(()=>URL.revokeObjectURL(i)),n}})(t=>{const e=new Worker(t);return h(e)},'(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),l=t(c);e.addUniqueNumber=l,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o(\'The handler of the method called "\'.concat(t,\'" returned an unexpected result.\'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o(\'The requested method called "\'.concat(e,\'" is not supported.\'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o(\'The handler of the method called "\'.concat(t,\'" returned no required result.\'),e))(i);const l=r instanceof Promise?await r:r;if(null===a){if(void 0!==l.result)throw s(i)}else{if(void 0===l.result)throw s(i);const{result:e,transferables:r=[]}=l;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,()=>{n(),t.close(),u.delete(o)}),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o(\'The specified parameter called "portId" with the given value "\'.concat(e,\'" does not identify a port connected to this worker.\'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise(e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])})){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),l=(e,t,r=()=>!0)=>{const n=c(l,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},d=(e,t)=>r=>{const n=t.get(r);if(void 0===n)return Promise.resolve(!1);const[o,s]=n;return e(o),t.delete(r),s(!1),Promise.resolve(!0)},f=(e,t,r,n)=>(o,s,a)=>{const i=o+s-t.timeOrigin,u=i-t.now();return new Promise(t=>{e.set(a,[r(n,u,i,e,t,a),t])})},m=new Map,h=d(globalThis.clearTimeout,m),p=new Map,v=d(globalThis.clearTimeout,p),w=((e,t)=>{const r=(n,o,s,a)=>{const i=n-e.now();i>0?o.set(a,[t(r,i,n,o,s,a),s]):(o.delete(a),s(!0))};return r})(performance,globalThis.setTimeout),g=f(m,performance,globalThis.setTimeout,w),T=f(p,performance,globalThis.setTimeout,w);l(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?h(e):v(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?g:T)(e,t,r)})})})()})();'),p={getNameSpacify(...e){let n=t.NAMESPACE;for(let t=0;t<e.length;++t)n+="-"+e[t];return n},isNumber:t=>/^\d+$/.test(t),getUUID:()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}),mergeArgs(t="",e){const n={};if(0===arguments.length)return n;if(null!=e){if(n.content=t,"object"==typeof e&&null!=e)return Object.assign(n,e)}else{if("object"==typeof t&&null!=t)return Object.assign(n,t);n.content=t}return n},toDynamicObject(t,...e){const n=Object.assign({},t??{});return Object.keys(n).forEach(t=>{let s=n[t];Object.defineProperty(n,t,{get(){const n=e.findIndex(e=>"object"==typeof e&&null!=e&&e.hasOwnProperty.call(e,t));if(-1!==n){return e[n][t]}return s},set(t){s=t}})}),n},setTimeout(t,e){try{return((...t)=>d().setTimeout(...t))(t,e)}catch{return globalThis.setTimeout(t,e)}},clearTimeout(t){try{null!=t&&(e=t,d().clearTimeout(e))}catch{}finally{globalThis.clearTimeout(t)}var e},setInterval(t,e){try{return((...t)=>d().setInterval(...t))(t,e)}catch{return globalThis.setInterval(t,e)}},clearInterval(t){try{null!=t&&(e=t,d().clearInterval(e))}catch{}finally{globalThis.clearInterval(t)}var e},setSafeHTML(t,e){try{t.innerHTML=e}catch{if(!globalThis.trustedTypes)throw new Error("QmsgUtils trustedTypes is not defined");{const n=globalThis.trustedTypes.createPolicy("safe-innerHTML",{createHTML:t=>t});t.innerHTML=n.createHTML(e)}}}},f={$state:{opening:"MessageMoveIn",done:"",closing:"MessageMoveOut"},$name:{startNameList:["animationName","WebkitAnimationName","MozAnimationName","msAnimationName","OAnimationName"],endNameList:["animationend","webkitAnimationEnd","mozAnimationEnd","MSAnimationEnd","oanimationend"]},__CAN_ANIMATION__:void 0,get CAN_ANIMATION(){return this.__CAN_ANIMATION__=this.__CAN_ANIMATION__??null!=this.getStyleAnimationNameValue(document.createElement("div")),this.__CAN_ANIMATION__},getStyleAnimationNameValue(t){for(let e=0;e<this.$name.startNameList.length;e++){const n=this.$name.startNameList[e],s=t.style[n];if(null!=s)return s}},setStyleAnimationName(t,e=""){this.$name.startNameList.forEach(n=>{n in t.style&&(t.style[n]=e)})}},w={css:'\n @charset "utf-8";\r\n.qmsg.qmsg-wrapper {\r\n position: fixed;\r\n top: 16px;\r\n left: 0;\r\n z-index: 50000;\r\n display: flex;\r\n box-sizing: border-box;\r\n margin: 0;\r\n padding: 0;\r\n width: 100%;\r\n color: rgba(0, 0, 0, 0.55);\r\n list-style: none;\r\n font-variant: tabular-nums;\r\n font-size: 13px;\r\n line-height: 1;\r\n font-feature-settings: "tnum";\r\n pointer-events: none;\r\n flex-direction: column;\r\n}\r\n.qmsg.qmsg-data-position-center,\r\n.qmsg.qmsg-data-position-left,\r\n.qmsg.qmsg-data-position-right {\r\n position: fixed;\r\n top: 50%;\r\n left: 50%;\r\n transform: translate(-50%, -50%);\r\n}\r\n.qmsg.qmsg-data-position-bottom,\r\n.qmsg.qmsg-data-position-bottomleft,\r\n.qmsg.qmsg-data-position-bottomright {\r\n position: fixed;\r\n top: unset;\r\n bottom: 0;\r\n bottom: 8px;\r\n left: 50%;\r\n transform: translate(-50%, 0);\r\n}\r\n.qmsg.qmsg-data-position-bottomleft .qmsg-item,\r\n.qmsg.qmsg-data-position-left .qmsg-item,\r\n.qmsg.qmsg-data-position-topleft .qmsg-item {\r\n text-align: left;\r\n}\r\n.qmsg.qmsg-data-position-bottom .qmsg-item,\r\n.qmsg.qmsg-data-position-center .qmsg-item,\r\n.qmsg.qmsg-data-position-top .qmsg-item {\r\n text-align: center;\r\n}\r\n.qmsg.qmsg-data-position-bottomright .qmsg-item,\r\n.qmsg.qmsg-data-position-right .qmsg-item,\r\n.qmsg.qmsg-data-position-topright .qmsg-item {\r\n text-align: right;\r\n}\r\n.qmsg .qmsg-item {\r\n position: relative;\r\n padding: 8px;\r\n text-align: center;\r\n -webkit-animation-duration: 0.3s;\r\n animation-duration: 0.3s;\r\n}\r\n.qmsg .qmsg-item .qmsg-count {\r\n position: absolute;\r\n top: -4px;\r\n left: -4px;\r\n display: inline-block;\r\n height: 16px;\r\n min-width: 16px;\r\n border-radius: 2px;\r\n background-color: red;\r\n color: #fff;\r\n text-align: center;\r\n font-size: 12px;\r\n line-height: 16px;\r\n -webkit-animation-duration: 0.3s;\r\n animation-duration: 0.3s;\r\n}\r\n.qmsg .qmsg-item:first-child {\r\n margin-top: -8px;\r\n}\r\n.qmsg .qmsg-content {\r\n position: relative;\r\n display: inline-block;\r\n padding: 10px 12px;\r\n max-width: 80%;\r\n min-width: 40px;\r\n border-radius: 4px;\r\n background: #fff;\r\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\r\n text-align: center;\r\n pointer-events: all;\r\n}\r\n.qmsg .qmsg-content [class^="qmsg-content-"] {\r\n display: flex;\r\n align-items: center;\r\n}\r\n.qmsg .qmsg-icon {\r\n position: relative;\r\n top: 1px;\r\n display: inline-block;\r\n margin-right: 8px;\r\n color: inherit;\r\n vertical-align: -0.125em;\r\n text-align: center;\r\n text-transform: none;\r\n font-style: normal;\r\n font-size: 16px;\r\n line-height: 0;\r\n text-rendering: optimizeLegibility;\r\n -webkit-font-smoothing: antialiased;\r\n -moz-osx-font-smoothing: grayscale;\r\n}\r\n.qmsg .qmsg-icon svg {\r\n display: inline-block;\r\n}\r\n.qmsg .qmsg-content .qmsg-show-more-content {\r\n display: flex;\r\n align-items: center;\r\n white-space: unset;\r\n overflow: unset;\r\n text-overflow: unset;\r\n padding-right: unset;\r\n}\r\n.qmsg .qmsg-content-info .qmsg-icon {\r\n color: #1890ff;\r\n}\r\n.qmsg .qmsg-icon-close {\r\n margin: 0;\r\n margin-left: 8px;\r\n padding: 0;\r\n outline: 0;\r\n border: none;\r\n background-color: transparent;\r\n color: rgba(0, 0, 0, 0.45);\r\n font-size: 12px;\r\n cursor: pointer;\r\n transition: color 0.3s;\r\n}\r\n.qmsg .qmsg-icon-close:hover > svg path {\r\n stroke: #555;\r\n}\r\n.qmsg .qmsg-icon-close.qmsg-show-more-content {\r\n position: unset;\r\n overflow: unset;\r\n padding-left: 6px;\r\n margin-right: 0;\r\n}\r\n.qmsg .animate-turn {\r\n animation: MessageTurn 1s linear infinite;\r\n -webkit-animation: MessageTurn 1s linear infinite;\r\n}\r\n\n\n @keyframes MessageTurn {\r\n 0% {\r\n -webkit-transform: rotate(0);\r\n }\r\n 25% {\r\n -webkit-transform: rotate(90deg);\r\n }\r\n 50% {\r\n -webkit-transform: rotate(180deg);\r\n }\r\n 75% {\r\n -webkit-transform: rotate(270deg);\r\n }\r\n 100% {\r\n -webkit-transform: rotate(360deg);\r\n }\r\n}\r\n@-webkit-keyframes MessageTurn {\r\n 0% {\r\n -webkit-transform: rotate(0);\r\n }\r\n 25% {\r\n -webkit-transform: rotate(90deg);\r\n }\r\n 50% {\r\n -webkit-transform: rotate(180deg);\r\n }\r\n 75% {\r\n -webkit-transform: rotate(270deg);\r\n }\r\n 100% {\r\n -webkit-transform: rotate(360deg);\r\n }\r\n}\r\n@-webkit-keyframes MessageMoveOut {\r\n 0% {\r\n max-height: 150px;\r\n opacity: 1;\r\n }\r\n to {\r\n max-height: 0;\r\n opacity: 0;\r\n }\r\n}\r\n@keyframes MessageMoveOut {\r\n 0% {\r\n max-height: 150px;\r\n opacity: 1;\r\n }\r\n to {\r\n max-height: 0;\r\n opacity: 0;\r\n }\r\n}\r\n@-webkit-keyframes MessageMoveIn {\r\n 0% {\r\n opacity: 0;\r\n transform: translateY(-100%);\r\n transform-origin: 0 0;\r\n }\r\n to {\r\n opacity: 1;\r\n transform: translateY(0);\r\n transform-origin: 0 0;\r\n }\r\n}\r\n@keyframes MessageMoveIn {\r\n 0% {\r\n opacity: 0;\r\n transform: translateY(-100%);\r\n transform-origin: 0 0;\r\n }\r\n to {\r\n opacity: 1;\r\n transform: translateY(0);\r\n transform-origin: 0 0;\r\n }\r\n}\r\n@-webkit-keyframes MessageShake {\r\n 0%,\r\n 100% {\r\n opacity: 1;\r\n transform: translateX(0);\r\n }\r\n 25%,\r\n 75% {\r\n opacity: 0.75;\r\n transform: translateX(-4px);\r\n }\r\n 50% {\r\n opacity: 0.25;\r\n transform: translateX(4px);\r\n }\r\n}\r\n@keyframes MessageShake {\r\n 0%,\r\n 100% {\r\n opacity: 1;\r\n transform: translateX(0);\r\n }\r\n 25%,\r\n 75% {\r\n opacity: 0.75;\r\n transform: translateX(-4px);\r\n }\r\n 50% {\r\n opacity: 0.25;\r\n transform: translateX(4px);\r\n }\r\n}\r\n\n ',getStyleElement(){const e=document.createElement("style");return e.setAttribute("type","text/css"),e.setAttribute("data-type",t.PLUGIN_NAME),p.setSafeHTML(e,w.css),e}};class y{timeId=void 0;startTime;endTime;setting;uuid;state;repeatNum;$Qmsg;constructor(e,n){this.timeId=void 0,this.startTime=Date.now(),this.endTime=null,this.setting=p.toDynamicObject(t.config,e,t.INS_DEFAULT),this.uuid=n,this.state="opening",this.$Qmsg=document.createElement("div"),this.repeatNum=1,this.detectionType(),this.init();("function"==typeof this.setting.consoleLogContent?this.setting.consoleLogContent(this):this.setting.consoleLogContent)&&console.log(this.setting.content),"function"==typeof this.setting.afterRender&&this.setting.afterRender(this)}getSetting(){return this.setting}getRepeatNum(){return this.repeatNum}setRepeatNum(t){this.repeatNum=t}setRepeatNumIncreasing(){this.repeatNum++}init(){const n=this;this.setting.customClass&&"string"==typeof this.setting.customClass&&this.$Qmsg.classList.add(this.setting.customClass);const s=e[this.setting.type||"info"];let i=p.getNameSpacify("content-"+this.setting.type||"info");this.setting.showClose&&(i+=" "+p.getNameSpacify("content-with-close"));const r=this.setting.content||"";let o="";this.setting.showMoreContent&&(i+="qmsg-show-more-content",o+="qmsg-show-more-content");let a="";this.setting.showClose&&(a=`<i class="qmsg-icon qmsg-icon-close ${o}">\n\t<svg width="16" height="16" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">\n\t\t<rect width="48" height="48" fill="white" fill-opacity="0.01"/>\n\t\t<path d="M14 14L34 34" stroke="#909399" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>\n\t\t<path d="M14 34L34 14" stroke="#909399" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>\n\t</svg></i>`);const l=document.createElement("span"),c=p.getNameSpacify("data-position",this.setting.position.toLowerCase());if(this.setting.isHTML?p.setSafeHTML(l,r):l.innerText=r,this.setting.isLimitWidth){let t=this.setting.limitWidthNum;"string"==typeof t?p.isNumber(t)&&(t+="px"):t=t.toString()+"px",l.style.maxWidth=t,l.style.width=t,"no-wrap"===this.setting.limitWidthWrap?l.style.whiteSpace="nowrap":"ellipsis"===this.setting.limitWidthWrap?(l.style.whiteSpace="nowrap",l.style.overflow="hidden",l.style.textOverflow="ellipsis"):"wrap"===this.setting.limitWidthWrap&&(l.style.whiteSpace="")}p.setSafeHTML(this.$Qmsg,`\n\t\t\t<div class="qmsg-content">\n\t\t\t\t<div class="${i}">\n\t\t\t\t${this.setting.showIcon?`<i class="qmsg-icon">${s}</i>`:""}\n\t\t\t\t\t${l.outerHTML}\n\t\t\t\t\t${a}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t`);const m=this.$Qmsg.querySelector(".qmsg-content");let g,u,h;if(this.$Qmsg.classList.add(p.getNameSpacify("item")),this.$Qmsg.setAttribute(p.getNameSpacify("uuid"),this.uuid),g=document.querySelector(".qmsg-shadow-container"),u=this.setting.useShadowRoot?g?.shadowRoot:g,!g){if(g=document.createElement("div"),g.className="qmsg-shadow-container",u=this.setting.useShadowRoot?g.attachShadow({mode:this.setting.shadowRootMode}):g,u.appendChild(w.getStyleElement()),null!=this.setting.style){const t=document.createElement("style");t.setAttribute("type","text/css"),t.setAttribute("data-id",this.uuid),p.setSafeHTML(t,this.setting.style),m.insertAdjacentElement("afterend",t)}this.setting.parent.appendChild(g)}if(null==u)throw new Error("QmsgInst "+t.PLUGIN_NAME+" $shadowRoot is null");h=u.querySelector(`.${t.NAMESPACE}.${c}`),h||(h=document.createElement("div"),h.classList.add(t.NAMESPACE,p.getNameSpacify("wrapper"),p.getNameSpacify("is-initialized"),c),u.appendChild(h)),this.setting.showReverse?h.style.flexDirection="column-reverse":h.style.flexDirection="column";let d=this.setting.zIndex;if("function"==typeof d&&(d=d()),isNaN(d)||(h.style.zIndex=d.toString()),h.appendChild(this.$Qmsg),this.setState(this.$Qmsg,"opening"),this.setting.showClose){const t=this.$Qmsg.querySelector(".qmsg-icon-close");t&&t.addEventListener("click",t=>{n.close()})}const y=t=>{f.getStyleAnimationNameValue(n.$Qmsg)===f.$state.closing&&(n.endTime=Date.now(),n.destroy()),f.setStyleAnimationName(n.$Qmsg)};if(f.$name.endNameList.forEach(function(t){n.$Qmsg.addEventListener(t,y)}),this.setting.autoClose&&this.setting.listenEventToPauseAutoClose){this.resetAutoCloseTimer();const t=t=>{this.clearAutoCloseTimer()},e=t=>{null==this.timeId?this.startAutoCloseTimer():console.warn("QmsgInst timeId is not null,mouseenter may be not first trigger,timeId:"+this.timeId)};let n=!1;this.$Qmsg.addEventListener("mouseenter",t),this.$Qmsg.addEventListener("mouseleave",e),this.$Qmsg.addEventListener("touchstart",s=>{n||(n=!0,this.$Qmsg.removeEventListener("mouseenter",t),this.$Qmsg.removeEventListener("mouseleave",e)),t()}),this.$Qmsg.addEventListener("touchend",e),this.$Qmsg.addEventListener("touchcancel",e)}}detectionType(){null!=this.setting.timeout&&"string"==typeof this.setting.timeout&&(this.setting.timeout=parseInt(this.setting.timeout)),isNaN(this.setting.timeout)&&(this.setting.timeout=t.config.timeout),null!=this.setting.timeout&&parseInt(this.setting.timeout.toString())>=0&&parseInt(this.setting.timeout.toString())<=Number.MAX_VALUE||(this.setting.timeout=t.config.timeout),"function"==typeof this.setting.zIndex&&(this.setting.zIndex=this.setting.zIndex()),null!=this.setting.zIndex&&"string"==typeof this.setting.zIndex&&(this.setting.zIndex=parseInt(this.setting.zIndex)),isNaN(this.setting.zIndex)&&(this.setting.zIndex="function"==typeof t.config.zIndex?t.config.zIndex():t.config.zIndex)}setState(t,e){e&&f.$state[e]&&(this.state=e,f.setStyleAnimationName(t,f.$state[e]))}setMsgCount(){const t=p.getNameSpacify("count"),e=`div.${p.getNameSpacify("data-position",this.setting.position.toLowerCase())} [class^="qmsg-content-"]`,n=this.$Qmsg.querySelector(e);if(!n)throw new Error("QmsgInst $content is null");let s=n.querySelector("."+t);s||(s=document.createElement("span"),s.classList.add(t),n.appendChild(s));const i=this.getRepeatNum();p.setSafeHTML(s,i.toString()),f.setStyleAnimationName(s),f.setStyleAnimationName(s,"MessageShake"),this.resetAutoCloseTimer()}clearAutoCloseTimer(){p.clearTimeout(this.timeId),this.timeId=void 0,this.startTime=null,this.endTime=null}startAutoCloseTimer(){this.setting.autoClose&&this.setting.listenEventToPauseAutoClose&&(this.startTime=Date.now(),this.endTime=null,this.timeId=p.setTimeout(()=>{this.close()},this.setting.timeout))}resetAutoCloseTimer(){this.clearAutoCloseTimer(),this.startAutoCloseTimer()}close(){this.setState(this.$Qmsg,"closing"),f.CAN_ANIMATION?n.remove(this.uuid):this.destroy();const t=this.setting.onClose;t&&"function"==typeof t&&t.call(this)}destroy(){this.endTime=Date.now(),this.$Qmsg.remove(),p.clearTimeout(this.timeId),n.remove(this.uuid),this.timeId=void 0}get $content(){const t=this.$Qmsg.querySelector("div[class^=qmsg-content-] > span");if(!t)throw new Error("QmsgInst $content is null");return t}setText(t){this.$content.innerText=t,this.setting.content=t}setHTML(t){const e=this.$content;p.setSafeHTML(e,t),this.setting.content=t}}function v(t={}){const e=JSON.stringify(t);let s=n.insInfoList.find(t=>t.config===e),i=s?.instance;if(null==i){const r=p.getUUID(),o={uuid:r,config:e,instance:new y(t,r)};n.insInfoList.push(o);const a=n.insInfoList.length,l=o.instance.getSetting().maxNums;if(a>l)for(let t=0;t<a-l;t++){const e=n.insInfoList[t];e&&e.instance.getSetting().autoClose&&e.instance.close()}s=o,i=o.instance}else i.getRepeatNum()?i.getRepeatNum()>=99||i.setRepeatNumIncreasing():i.setRepeatNum(2),i.setMsgCount();if(!i)throw new Error("QmsgInst is null");return i.$Qmsg.setAttribute("data-count",i?.getRepeatNum().toString()),i}const x={visibilitychange:{eventConfig:{callback(){if("visible"===document.visibilityState)for(let t=0;t<n.insInfoList.length;t++){const e=n.insInfoList[t];"loading"!==e.instance.setting.type&&null==e.instance.endTime&&null!=e.instance.startTime&&Date.now()-e.instance.startTime>=e.instance.getSetting().timeout&&e.instance.close()}},option:{capture:!0}},addEvent(){"visibilityState"in document?document.addEventListener("visibilitychange",x.visibilitychange.eventConfig.callback,x.visibilitychange.eventConfig.option):console.error("Qmsg addEvent visibilityState not support")},removeEvent(){document.removeEventListener("visibilitychange",x.visibilitychange.eventConfig.callback,x.visibilitychange.eventConfig.option)}}};!function(){try{"function"!=typeof Object.assign&&(Object.assign=function(t){if(t=Object(t),arguments.length>1){[...arguments].splice(1,arguments.length-1).forEach(e=>{for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})}return t})}catch(t){console.warn("Qmsg CompatibleProcessing Object.assign error",t)}try{"classList"in document.documentElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){const t=this;function e(e){return function(n){const s=t.className.split(/\s+/g),i=s.indexOf(n);e(s,i,n),t.className=s.join(" ")}}return{add:e(function(t,e,n){~e||t.push(n)}),remove:e(function(t,e){~e&&t.splice(e,1)}),toggle:e(function(t,e,n){~e?t.splice(e,1):t.push(n)}),contains:function(e){return!!~t.className.split(/\s+/g).indexOf(e)},item:function(e){return t.className.split(/\s+/g)[e]||null}}}})}catch(t){console.warn("Qmsg CompatibleProcessing HTMLElement.prototype.classList warning",t)}}();const b=new class{$data;$eventUtils;constructor(s){this.$data={version:"1.5.0",config:t,icon:e,instanceStorage:n},this.$eventUtils=x,this.$eventUtils.visibilitychange.addEvent(),this.config(s)}config(e){null!=e&&"object"==typeof e&&(t.INS_DEFAULT=null,t.INS_DEFAULT=e)}info(t,e){const n=p.mergeArgs(t,e);return n.type="info",v.call(this,n)}warning(t,e){const n=p.mergeArgs(t,e);return n.type="warning",v.call(this,n)}success(t,e){const n=p.mergeArgs(t,e);return n.type="success",v.call(this,n)}error(t,e){const n=p.mergeArgs(t,e);return n.type="error",v.call(this,n)}loading(t,e){const n=p.mergeArgs(t,e);return n.type="loading",n.autoClose=!1,v.call(this,n)}remove(t){n.remove(t)}closeAll(){for(let t=n.insInfoList.length-1;t>=0;t--){const e=n.insInfoList[t];e&&e.instance&&e.instance.close()}}};module.exports=b; //# sourceMappingURL=index.cjs.min.js.map