Files
vanillajs-seed/node_modules/pnotify/dist/es/PNotifyDesktop.js
2019-04-12 20:01:07 +02:00

2 lines
9.3 KiB
JavaScript

import PNotify from"./PNotify.js";let permission;const Notification=window.Notification;let notify=(t,i,e,n)=>(notify="Notification"in window?(t,i,e,n)=>{const o=new Notification(t,i);return"NotificationEvent"in window?(o.addEventListener("notificationclick",e),o.addEventListener("close",n)):"addEventListener"in o?(o.addEventListener("click",e),o.addEventListener("close",n)):(o.onclick=e,o.onclose=n),o}:"mozNotification"in navigator?(t,i,e,n)=>{const o=navigator.mozNotification.createNotification(t,i.body,i.icon).show();return o.onclick=e,o.onclose=n,o}:"webkitNotifications"in window?(t,i,e,n)=>{const o=window.webkitNotifications.createNotification(i.icon,t,i.body);return o.onclick=e,o.onclose=n,o}:(t,i,e,n)=>null)(t,i,e,n);function data(){return Object.assign({_notice:null,_options:{}},PNotify.modules.Desktop.defaults)}var methods={initModule(t){this.set(t);const{_notice:i}=this.get();this.set({_oldAnimation:i.get().animation}),i.on("state",({changed:t,current:e,previous:n})=>{t.animation&&(void 0===n.animation||"none"!==e.animation||"none"===n.animation&&e.animation!==this.get()._oldAnimation)&&this.set({_oldAnimation:e.animation}),t._animatingClass&&(""===e._animatingClass||0!==permission&&this.get().fallback||!this.get().desktop||i.set({_animatingClass:""}))}),this.get().desktop&&(0===(permission=PNotify.modules.Desktop.checkPermission())?(i.set({animation:"none"}),i.addModuleClass("ui-pnotify-desktop-hide"),this.genNotice()):this.get().fallback||i.set({autoDisplay:!1}))},update(){const{_notice:t}=this.get();if(0!==permission&&this.get().fallback||!this.get().desktop)return t.set({animation:this.get()._oldAnimation}),void t.removeModuleClass("ui-pnotify-desktop-hide");t.set({animation:"none"}),t.addModuleClass("ui-pnotify-desktop-hide"),this.genNotice()},beforeOpen(){if(this.get().desktop&&0!==permission&&PNotify.modules.Desktop.permission(),0!==permission&&this.get().fallback||!this.get().desktop)return;const{_desktop:t}=this.get();t&&"show"in t&&(this.get()._notice.set({_moduleIsNoticeOpen:!0}),t.show())},beforeClose(){if(0!==permission&&this.get().fallback||!this.get().desktop)return;const{_desktop:t}=this.get();t&&"close"in t&&(t.close(),this.get()._notice.set({_moduleIsNoticeOpen:!1}))},genNotice(){const{_notice:t,icon:i}=this.get();if(null===i)switch(t.get().type){case"error":this.set({_icon:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gQJATQg7e6HvQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAABr0lEQVRYw8WXu0oDQRSGv7hRSFYrLTTWKihaqUgUJO+gphBLL1jYpPSCVcAggpWthYhC7Ows9An0IbSPkMRCw8ZmFuI6yczs9cAPuzNz5v92brtrESxGARtokkCcAg2hk7jNl4G2R/m4zFPAiwTgWdRFHnmJuaulOAAaPQDqUZvv9DB3tR0lwIcGwHtU5uca5q4qYZvngJbHpAZ8CtU8dS1gLEyAisegBGTFKWiL65KnzVlY5uOSId6VtNuTtMupOu/TAHiQlNmSskHNXCOAGWBeUp7VhFoApoMAXAOWJoCszBJ9+ALY6vL0JiPgjsKmKUAaOOoBZwIAcNxlJLsCrAOTIQJMAWu62y4LOIqT7lGS96TIcYCMDkBZ46h1gB+PHI28ssq8X/G6DaqG8Piz2DrjVjGXbtSBy46F5QAHwJAizwZugKKscs7gSaqS/KpB/qxsFxwafhf6Odb/eblJi8BGwJdW26BtURxQpMU83hmaDQsNiPtvYMSwj3tgAqDgYzU7wJdHjo9+CgBvEW47lV5Tgj5DMtG0xIfESkIAF+522gdWxTzGEX3i9+6KpOMXF5UBt0NKJCAAAAAASUVORK5CYII="});break;case"success":this.set({_icon:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAA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oBTl8lSwINoSuXKjrv4F4FBh61zlKUKvgn7/e5ZEngMEDgLdFSieHaAT42LpgTMVbqC24B54Bi4twV9E6cnDcw6PFj+RSo/l6rlSlldhx4AAAAASUVORK5CYII="})}else!1===i?this.set({_icon:null}):this.set({_icon:i});let{tag:e}=this.get();this.get()._tag&&null===e||this.set({_tag:null===e?"PNotify-"+Math.round(1e6*Math.random()):e});const n={body:this.get().text||t.get().text,tag:this.get()._tag};t.get().hide||(n.requireInteraction=!0),null!==this.get()._icon&&(n.icon=this.get()._icon),Object.apply(n,this.get().options);const o=notify(this.get().title||t.get().title,n,()=>{t.fire("click",{target:o})},()=>{t.close()});t.set({_moduleIsNoticeOpen:!0}),this.set({_desktop:o}),!("close"in o)&&"cancel"in o&&(o.close=(()=>{o.cancel()}))}};function setup(t){t.key="Desktop",t.defaults={desktop:!1,fallback:!0,icon:null,tag:null,title:null,text:null,options:{}},t.init=(i=>new t({target:document.body})),t.permission=(()=>{void 0!==Notification&&"requestPermission"in Notification?Notification.requestPermission():"webkitNotifications"in window&&window.webkitNotifications.requestPermission()}),t.checkPermission=(()=>void 0!==Notification&&"permission"in Notification?"granted"===Notification.permission?0:1:"webkitNotifications"in window&&0==window.webkitNotifications.checkPermission()?0:1),permission=t.checkPermission(),PNotify.modules.Desktop=t}function add_css(){var t=createElement("style");t.id="svelte-xbgnx4-style",t.textContent="[ui-pnotify].ui-pnotify-desktop-hide.ui-pnotify{left:-10000px !important;display:none !important}",append(document.head,t)}function create_main_fragment(t,i){return{c:noop,m:noop,p:noop,d:noop}}function PNotifyDesktop(t){init(this,t),this._state=assign(data(),t.data),this._intro=!0,document.getElementById("svelte-xbgnx4-style")||add_css(),this._fragment=create_main_fragment(this,this._state),t.target&&(this._fragment.c(),this._mount(t.target,t.anchor))}function createElement(t){return document.createElement(t)}function append(t,i){t.appendChild(i)}function noop(){}function init(t,i){t._handlers=blankObject(),t._slots=blankObject(),t._bind=i._bind,t._staged={},t.options=i,t.root=i.root||t,t.store=i.store||t.root.store,i.root||(t._beforecreate=[],t._oncreate=[],t._aftercreate=[])}function assign(t,i){for(var e in i)t[e]=i[e];return t}function destroy(t){this.destroy=noop,this.fire("destroy"),this.set=noop,this._fragment.d(!1!==t),this._fragment=null,this._state={}}function get(){return this._state}function fire(t,i){var e=t in this._handlers&&this._handlers[t].slice();if(e)for(var n=0;n<e.length;n+=1){var o=e[n];if(!o.__calling)try{o.__calling=!0,o.call(this,i)}finally{o.__calling=!1}}}function on(t,i){var e=this._handlers[t]||(this._handlers[t]=[]);return e.push(i),{cancel:function(){var t=e.indexOf(i);~t&&e.splice(t,1)}}}function set(t){this._set(assign({},t)),this.root._lock||flush(this.root)}function _set(t){var i=this._state,e={},n=!1;for(var o in t=assign(this._staged,t),this._staged={},t)this._differs(t[o],i[o])&&(e[o]=n=!0);n&&(this._state=assign(assign({},i),t),this._recompute(e,this._state),this._bind&&this._bind(e,this._state),this._fragment&&(this.fire("state",{changed:e,current:this._state,previous:i}),this._fragment.p(e,this._state),this.fire("update",{changed:e,current:this._state,previous:i})))}function _stage(t){assign(this._staged,t)}function _mount(t,i){this._fragment[this._fragment.i?"i":"m"](t,i||null)}function _differs(t,i){return t!=t?i==i:t!==i||t&&"object"==typeof t||"function"==typeof t}function blankObject(){return Object.create(null)}function flush(t){t._lock=!0,callAll(t._beforecreate),callAll(t._oncreate),callAll(t._aftercreate),t._lock=!1}function callAll(t){for(;t&&t.length;)t.shift()()}assign(PNotifyDesktop.prototype,{destroy:destroy,get:get,fire:fire,on:on,set:set,_set:_set,_stage:_stage,_mount:_mount,_differs:_differs}),assign(PNotifyDesktop.prototype,methods),PNotifyDesktop.prototype._recompute=noop,setup(PNotifyDesktop);export default PNotifyDesktop;
//# sourceMappingURL=PNotifyDesktop.js.map