solid-toast
Advanced tools
Comparing version 0.3.0-alpha.0 to 0.3.0
@@ -1,2 +0,2 @@ | ||
function t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function e(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?t(Object(o),!0).forEach((function(t){n(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function n(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,s=!1;try{for(n=n.call(t);!(a=(r=n.next()).done)&&(i.push(r.value),!e||i.length!==e);a=!0);}catch(t){s=!0,o=t}finally{try{a||null==n.return||n.return()}finally{if(s)throw o}}return i}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}Object.defineProperty(exports,"__esModule",{value:!0});var s,c=require("solid-js"),u=require("solid-js/store"),l=require("solid-js/web"),f=function(t,e){return function(t){return"function"==typeof t}(t)?t(e):t};exports.ActionType=void 0,(s=exports.ActionType||(exports.ActionType={}))[s.ADD_TOAST=0]="ADD_TOAST",s[s.UPDATE_TOAST=1]="UPDATE_TOAST",s[s.UPSERT_TOAST=2]="UPSERT_TOAST",s[s.DISMISS_TOAST=3]="DISMISS_TOAST",s[s.REMOVE_TOAST=4]="REMOVE_TOAST",s[s.START_PAUSE=5]="START_PAUSE",s[s.END_PAUSE=6]="END_PAUSE";var p,d=o(u.createStore({toasts:[],pausedAt:void 0}),2),v=d[0],m=d[1],y=new Map,h=function(t,e){if(!y.has(t)){var n=setTimeout((function(){y.delete(t),g({type:exports.ActionType.REMOVE_TOAST,toastId:t})}),e);y.set(t,n)}},g=function t(n){switch(n.type){case exports.ActionType.ADD_TOAST:m("toasts",(function(t){var e=t;return[n.toast].concat(r(e))}));break;case exports.ActionType.DISMISS_TOAST:var o=n.toastId,i=v.toasts;if(o){var a=i.find((function(t){return t.id===o}));a&&h(o,a.unmountDelay),m("toasts",(function(t){return t.id===o}),u.produce((function(t){return t.visible=!1})))}else i.forEach((function(t){h(t.id,t.unmountDelay)})),m("toasts",(function(t){return void 0!==t.id}),u.produce((function(t){return t.visible=!1})));break;case exports.ActionType.REMOVE_TOAST:if(!n.toastId){m("toasts",[]);break}m("toasts",(function(t){return t.filter((function(t){return t.id!==n.toastId}))}));break;case exports.ActionType.UPDATE_TOAST:n.toast.id&&function(t){var e=y.get(t);y.delete(t),e&&clearTimeout(e)}(n.toast.id),m("toasts",(function(t){return t.id===n.toast.id}),(function(t){return e(e({},t),n.toast)}));break;case exports.ActionType.UPSERT_TOAST:v.toasts.find((function(t){return t.id===n.toast.id}))?t({type:exports.ActionType.UPDATE_TOAST,toast:n.toast}):t({type:exports.ActionType.ADD_TOAST,toast:n.toast});break;case exports.ActionType.START_PAUSE:m("pausedAt",Date.now());break;case exports.ActionType.END_PAUSE:var s=n.time-(v.pausedAt||0);m(u.produce((function(t){t.pausedAt=void 0,t.toasts.forEach((function(t){t.pauseDuration+=s}))})))}},T={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},b={id:"",icon:"",unmountDelay:500,duration:3e3,ariaProps:{role:"status","aria-live":"polite"},className:"",style:{},position:"top-right",iconTheme:{}},A={position:"top-right",toastOptions:b,gutter:8,containerStyle:{},containerClassName:""},S={position:"fixed","z-index":9999,top:"16px",bottom:"16px",left:"16px",right:"16px","pointer-events":"none"},x=(p=0,function(){return String(++p)}),_={display:"flex","align-items":"center",color:"#363636","box-shadow":"0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05)","max-width":"350px","pointer-events":"auto",padding:"8px 10px","border-radius":"4px","line-height":"1.3","will-change":"transform"},O={display:"flex","align-items":"center",flex:"1 1 auto",margin:"4px 10px","white-space":"pre-line"},E={"flex-shrink":0,"min-width":"20px","min-height":"20px",display:"flex","align-items":"center","justify-content":"center","text-align":"center"},w=function(t){return{calcMode:"spline",keyTimes:"0; 1",keySplines:t}},C=o(c.createSignal(A),2),D=C[0],k=C[1],N=function(t){var n,r,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"blank",a=arguments.length>2?arguments[2]:void 0;return e(e(e(e({},b),D().toastOptions),a),{},{type:i,message:t,pauseDuration:0,createdAt:Date.now(),visible:!0,id:a.id||x(),style:e(e(e({},b.style),null===(n=D().toastOptions)||void 0===n?void 0:n.style),a.style),duration:a.duration||(null===(r=D().toastOptions)||void 0===r?void 0:r.duration)||T[i],position:a.position||(null===(o=D().toastOptions)||void 0===o?void 0:o.position)||D().position||b.position})},P=function(t){return function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=v.toasts.find((function(t){return t.id===r.id})),i=N(n,t,e(e({},o),{},{duration:void 0},r));return g({type:exports.ActionType.UPSERT_TOAST,toast:i}),i.id}},$=function(t,e){return P("blank")(t,e)};$.error=P("error"),$.success=P("success"),$.loading=P("loading"),$.custom=P("custom"),$.dismiss=function(t){g({type:exports.ActionType.DISMISS_TOAST,toastId:t})},$.promise=function(t,n,r){var o=$.loading(n.loading,e({},r));return t.then((function(t){return $.success(f(n.success,t),e({id:o},r)),t})).catch((function(t){$.error(f(n.error,t),e({id:o},r))})),t},$.remove=function(t){g({type:exports.ActionType.REMOVE_TOAST,toastId:t})};var I=l.template("<div><style>.sldt-active{z-index:9999;}.sldt-active>*{pointer-events:auto;}</style></div>",4),M=l.template("<div></div>",2),j=l.template("<div><div></div></div>",4),F=function(t){var n,r,o;return c.createEffect((function(){if(n){var e=function(t,e){return(t.position||e).includes("top")?1:-1}(t.toast,t.position);t.toast.visible?n.animate([{transform:"translate3d(0,".concat(-200*e,"%,0) scale(.6)"),opacity:.5},{transform:"translate3d(0,0,0) scale(1)",opacity:1}],{duration:350,fill:"forwards",easing:"cubic-bezier(.21,1.02,.73,1)"}):n.animate([{transform:"translate3d(0,0,-1px) scale(1)",opacity:1},{transform:"translate3d(0,".concat(-150*e,"%,-1px) scale(.4)"),opacity:0}],{duration:400,fill:"forwards",easing:"cubic-bezier(.06,.71,.55,1)"})}})),console.log("CLASSSNAME",t.toast.className),r=j.cloneNode(!0),o=r.firstChild,"function"==typeof n?n(r):n=r,l.insert(r,l.createComponent(c.Switch,{get children(){return[l.createComponent(c.Match,{get when(){return t.toast.icon},get children(){var e=M.cloneNode(!0);return l.insert(e,(function(){return t.toast.icon})),l.effect((function(t){return l.style(e,E,t)})),e}}),l.createComponent(c.Match,{get when(){return"loading"===t.toast.type},get children(){var e=M.cloneNode(!0);return l.insert(e,l.createComponent(Q,l.mergeProps((function(){return t.toast.iconTheme})))),l.effect((function(t){return l.style(e,E,t)})),e}}),l.createComponent(c.Match,{get when(){return"success"===t.toast.type},get children(){var e=M.cloneNode(!0);return l.insert(e,l.createComponent(G,l.mergeProps((function(){return t.toast.iconTheme})))),l.effect((function(t){return l.style(e,E,t)})),e}}),l.createComponent(c.Match,{get when(){return"error"===t.toast.type},get children(){var e=M.cloneNode(!0);return l.insert(e,l.createComponent(J,l.mergeProps((function(){return t.toast.iconTheme})))),l.effect((function(t){return l.style(e,E,t)})),e}})]}}),o),l.spread(o,(function(){return t.toast.ariaProps}),!1,!0),l.insert(o,(function(){return f(t.toast.message,t.toast)})),l.effect((function(n){var i=t.toast.className,a=e(e({},_),t.toast.style),s=O;return i!==n._v$&&l.className(r,n._v$=i),n._v$2=l.style(r,a,n._v$2),n._v$3=l.style(o,s,n._v$3),n}),{_v$:void 0,_v$2:void 0,_v$3:void 0}),r},U=l.template("<div></div>",2),R=function(t){var n=function(){var n=t.toast.position||b.position,r=function(t,e){var n=v.toasts,r=D().gutter||A.gutter||8,o=n.filter((function(t){return(t.position||e)===e&&t.height})),i=o.findIndex((function(e){return e.id===t.id})),a=o.filter((function(t,e){return e<i&&t.visible})).length;return o.slice(0,a).reduce((function(t,e){return t+r+(e.height||0)}),0)}(t.toast,n),o=function(t,n){var r=t.includes("top")?{top:0,"margin-top":"".concat(n,"px")}:{bottom:0,"margin-bottom":"".concat(n,"px")},o=t.includes("center")?{"justify-content":"center"}:t.includes("right")?{"justify-content":"flex-end"}:{};return e(e({left:0,right:0,display:"flex",position:"absolute",transition:"all 230ms cubic-bezier(.21,1.02,.73,1)"},r),o)}(n,r);return o},r=o(c.createSignal(n()),2),i=r[0],a=r[1];c.createEffect((function(){var t=n();a(t)}));var s=void 0;return c.onMount((function(){s&&function(t,e){var n=t.getBoundingClientRect();n.height!==e.height&&g({type:exports.ActionType.UPDATE_TOAST,toast:{id:e.id,height:n.height}})}(s,t.toast)})),function(){var e=U.cloneNode(!0);e.addEventListener("mouseleave",(function(){return g({type:exports.ActionType.END_PAUSE,time:Date.now()})})),e.addEventListener("mouseenter",(function(){return g({type:exports.ActionType.START_PAUSE,time:Date.now()})}));var n;return"function"==typeof s?s(e):s=e,l.insert(e,(n=l.memo((function(){return"custom"===t.toast.type}),!0),function(){return n()?f(t.toast.message,t.toast):l.createComponent(F,{get toast(){return t.toast},get position(){return t.toast.position||b.position}})})),l.effect((function(n){var r=i(),o=t.toast.visible?"sldt-active":"";return n._v$=l.style(e,r,n._v$),o!==n._v$2&&l.className(e,n._v$2=o),n}),{_v$:void 0,_v$2:void 0}),e}()},z=l.template('<svg><circle cx="16" cy="16" r="0"><animate attributeName="opacity" values="0; 1; 1"></animate><animate attributeName="r" values="0; 17.5; 16"></animate></circle></svg>',8,!0),B=l.template('<svg><circle cx="16" cy="16" r="12"><animate attributeName="opacity" values="1; 0"></animate><animate attributeName="r" values="12; 26"></animate></circle></svg>',8,!0),V=function(t){var e,n,r,o={dur:"0.35s",begin:"100ms",fill:"freeze",calcMode:"spline",keyTimes:"0; 0.6; 1",keySplines:"0.25 0.71 0.4 0.88; .59 .22 .87 .63"};return e=z.cloneNode(!0),n=e.firstChild,r=n.nextSibling,l.spread(n,o,!0,!1),l.spread(r,o,!0,!1),l.effect((function(){return l.setAttribute(e,"fill",t.fill)})),e},q=function(t){var n,r,o,i=e({dur:"1s",begin:t.begin||"320ms",fill:"freeze"},w("0.0 0.0 0.2 1"));return n=B.cloneNode(!0),r=n.firstChild,o=r.nextSibling,l.spread(r,i,!0,!1),l.spread(o,i,!0,!1),l.effect((function(){return l.setAttribute(n,"fill",t.fill)})),n},L=l.template('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="22" stroke-dashoffset="22" stroke-linecap="round" stroke-miterlimit="10" d="M9.8,17.2l3.8,3.6c0.1,0.1,0.3,0.1,0.4,0l9.6-9.7"><animate attributeName="stroke-dashoffset" values="22;0" dur="0.25s" begin="250ms" fill="freeze"></animate></path></svg>',6),G=function(t){var e,n,r,o=t.primary||"#34C759";return e=L.cloneNode(!0),n=e.firstChild,r=n.firstChild,e.style.setProperty("overflow","visible"),l.insert(e,l.createComponent(V,{fill:o}),n),l.insert(e,l.createComponent(q,{fill:o,begin:"350ms"}),n),l.spread(r,(function(){return w("0.0, 0.0, 0.58, 1.0")}),!0,!1),l.effect((function(){return l.setAttribute(n,"stroke",t.secondary||"#FCFCFC")})),e},H=l.template('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="9" stroke-dashoffset="9" stroke-linecap="round" d="M16,7l0,9"><animate attributeName="stroke-dashoffset" values="9;0" dur="0.2s" begin="250ms" fill="freeze"></animate></path><circle cx="16" cy="23" r="2.5" opacity="0"><animate attributeName="opacity" values="0;1" dur="0.25s" begin="350ms" fill="freeze"></animate></circle></svg>',10),J=function(t){var e,n,r,o,i,a=t.primary||"#FF3B30";return e=H.cloneNode(!0),n=e.firstChild,r=n.firstChild,o=n.nextSibling,i=o.firstChild,e.style.setProperty("overflow","visible"),l.insert(e,l.createComponent(V,{fill:a}),n),l.insert(e,l.createComponent(q,{fill:a}),n),l.spread(r,(function(){return w("0.0, 0.0, 0.58, 1.0")}),!0,!1),l.spread(i,(function(){return w("0.0, 0.0, 0.58, 1.0")}),!0,!1),l.effect((function(e){var r=t.secondary||"#FFFFFF",i=t.secondary||"#FFFFFF";return r!==e._v$&&l.setAttribute(n,"stroke",e._v$=r),i!==e._v$2&&l.setAttribute(o,"fill",e._v$2=i),e}),{_v$:void 0,_v$2:void 0}),e},K=l.template('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c1.5,1.8,2.5,4,2.5,6.6c0,5.5-4.5,10-10,10S6,21.6,6,16S10.5,6,16,6z"></path><path fill="none" stroke-width="4" stroke-linecap="round" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c0.6,0.7,1.1,1.4,1.5,2.2"><animateTransform attributeName="transform" type="rotate" from="0 16 16" to="360 16 16" dur="0.75s" repeatCount="indefinite"></animateTransform></path></svg>',8),Q=function(t){return e=K.cloneNode(!0),n=e.firstChild,r=n.nextSibling,e.style.setProperty("overflow","visible"),l.effect((function(e){var o=t.primary||"#E5E7EB",i=t.secondary||"#4b5563";return o!==e._v$&&l.setAttribute(n,"stroke",e._v$=o),i!==e._v$2&&l.setAttribute(r,"stroke",e._v$2=i),e}),{_v$:void 0,_v$2:void 0}),e;var e,n,r},W=$;exports.Toaster=function(t){return c.createEffect((function(){!function(t){k((function(n){var r,o,i,a;return{containerClassName:null!==(r=t.containerClassName)&&void 0!==r?r:n.containerClassName,containerStyle:null!==(o=t.containerStyle)&&void 0!==o?o:n.containerStyle,gutter:null!==(i=t.gutter)&&void 0!==i?i:n.gutter,position:null!==(a=t.position)&&void 0!==a?a:n.position,toastOptions:e({},t.toastOptions)}}))}(t)})),c.createEffect((function(){var t=function(){var t=v.pausedAt,e=v.toasts;if(!t){var n=Date.now(),r=e.map((function(t){if(t.duration!==1/0){var e=(t.duration||0)+t.pauseDuration-(n-t.createdAt);if(!(e<=0))return setTimeout((function(){g({type:exports.ActionType.DISMISS_TOAST,toastId:t.id})}),e);t.visible&&g({type:exports.ActionType.DISMISS_TOAST,toastId:t.id})}}));return r}}();c.onCleanup((function(){t&&t.forEach((function(t){return t&&clearTimeout(t)}))}))})),(n=I.cloneNode(!0)).firstChild,l.insert(n,l.createComponent(c.For,{get each(){return v.toasts},children:function(t){return l.createComponent(R,{toast:t})}}),null),l.effect((function(r){var o=e(e({},S),t.containerStyle),i=t.containerClassName;return r._v$=l.style(n,o,r._v$),i!==r._v$2&&l.className(n,r._v$2=i),r}),{_v$:void 0,_v$2:void 0}),n;var n},exports.default=W,exports.resolveValue=f,exports.toast=$; | ||
Object.defineProperty(exports,"__esModule",{value:!0});var t=require("solid-js"),e=require("solid-js/store"),o=require("solid-js/web");const s=(t,e)=>(t=>"function"==typeof t)(t)?t(e):t;var i;exports.ActionType=void 0,(i=exports.ActionType||(exports.ActionType={}))[i.ADD_TOAST=0]="ADD_TOAST",i[i.UPDATE_TOAST=1]="UPDATE_TOAST",i[i.UPSERT_TOAST=2]="UPSERT_TOAST",i[i.DISMISS_TOAST=3]="DISMISS_TOAST",i[i.REMOVE_TOAST=4]="REMOVE_TOAST",i[i.START_PAUSE=5]="START_PAUSE",i[i.END_PAUSE=6]="END_PAUSE";const[r,n]=e.createStore({toasts:[],pausedAt:void 0}),a=new Map,c=(t,e)=>{if(a.has(t))return;const o=setTimeout((()=>{a.delete(t),l({type:exports.ActionType.REMOVE_TOAST,toastId:t})}),e);a.set(t,o)},l=t=>{switch(t.type){case exports.ActionType.ADD_TOAST:n("toasts",(e=>{const o=e;return[t.toast,...o]}));break;case exports.ActionType.DISMISS_TOAST:const{toastId:o}=t,s=r.toasts;if(o){const t=s.find((t=>t.id===o));t&&c(o,t.unmountDelay),n("toasts",(t=>t.id===o),e.produce((t=>t.visible=!1)))}else s.forEach((t=>{c(t.id,t.unmountDelay)})),n("toasts",(t=>void 0!==t.id),e.produce((t=>t.visible=!1)));break;case exports.ActionType.REMOVE_TOAST:if(!t.toastId){n("toasts",[]);break}n("toasts",(e=>e.filter((e=>e.id!==t.toastId))));break;case exports.ActionType.UPDATE_TOAST:t.toast.id&&(t=>{const e=a.get(t);a.delete(t),e&&clearTimeout(e)})(t.toast.id),n("toasts",(e=>e.id===t.toast.id),(e=>({...e,...t.toast})));break;case exports.ActionType.UPSERT_TOAST:r.toasts.find((e=>e.id===t.toast.id))?l({type:exports.ActionType.UPDATE_TOAST,toast:t.toast}):l({type:exports.ActionType.ADD_TOAST,toast:t.toast});break;case exports.ActionType.START_PAUSE:n("pausedAt",Date.now());break;case exports.ActionType.END_PAUSE:const i=t.time-(r.pausedAt||0);n(e.produce((t=>{t.pausedAt=void 0,t.toasts.forEach((t=>{t.pauseDuration+=i}))})))}},p={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},d={id:"",icon:"",unmountDelay:500,duration:3e3,ariaProps:{role:"status","aria-live":"polite"},className:"",style:{},position:"top-right",iconTheme:{}},u={position:"top-right",toastOptions:d,gutter:8,containerStyle:{},containerClassName:""},m={position:"fixed","z-index":9999,top:"16px",bottom:"16px",left:"16px",right:"16px","pointer-events":"none"},f=(()=>{let t=0;return()=>String(++t)})(),v={display:"flex","align-items":"center",color:"#363636","box-shadow":"0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05)","max-width":"350px","pointer-events":"auto",padding:"8px 10px","border-radius":"4px","line-height":"1.3","will-change":"transform"},y={display:"flex","align-items":"center",flex:"1 1 auto",margin:"4px 10px","white-space":"pre-line"},T={"flex-shrink":0,"min-width":"20px","min-height":"20px",display:"flex","align-items":"center","justify-content":"center","text-align":"center"},h=t=>({calcMode:"spline",keyTimes:"0; 1",keySplines:t}),[g,A]=t.createSignal(u),S=t=>(e,o={})=>{const s=r.toasts.find((t=>t.id===o.id)),i=((t,e="blank",o)=>({...d,...g().toastOptions,...o,type:e,message:t,pauseDuration:0,createdAt:Date.now(),visible:!0,id:o.id||f(),style:{...d.style,...g().toastOptions?.style,...o.style},duration:o.duration||g().toastOptions?.duration||p[e],position:o.position||g().toastOptions?.position||g().position||d.position}))(e,t,{...s,duration:void 0,...o});return l({type:exports.ActionType.UPSERT_TOAST,toast:i}),i.id},x=(t,e)=>S("blank")(t,e);x.error=S("error"),x.success=S("success"),x.loading=S("loading"),x.custom=S("custom"),x.dismiss=t=>{l({type:exports.ActionType.DISMISS_TOAST,toastId:t})},x.promise=(t,e,o)=>{const i=x.loading(e.loading,{...o});return t.then((t=>(x.success(s(e.success,t),{id:i,...o}),t))).catch((t=>{x.error(s(e.error,t),{id:i,...o})})),t},x.remove=t=>{l({type:exports.ActionType.REMOVE_TOAST,toastId:t})};const _=o.template("<div><style>.sldt-active{z-index:9999;}.sldt-active>*{pointer-events:auto;}</style></div>",4),b=o.template("<div></div>",2),E=o.template("<div><div></div></div>",4),C=e=>{let i;return t.createEffect((()=>{if(!i)return;const t=((t,e)=>(t.position||e).includes("top")?1:-1)(e.toast,e.position);e.toast.visible?i.animate([{transform:`translate3d(0,${-200*t}%,0) scale(.6)`,opacity:.5},{transform:"translate3d(0,0,0) scale(1)",opacity:1}],{duration:350,fill:"forwards",easing:"cubic-bezier(.21,1.02,.73,1)"}):i.animate([{transform:"translate3d(0,0,-1px) scale(1)",opacity:1},{transform:`translate3d(0,${-150*t}%,-1px) scale(.4)`,opacity:0}],{duration:400,fill:"forwards",easing:"cubic-bezier(.06,.71,.55,1)"})})),console.log("CLASSSNAME",e.toast.className),(()=>{const r=E.cloneNode(!0),n=r.firstChild;return"function"==typeof i?i(r):i=r,o.insert(r,o.createComponent(t.Switch,{get children(){return[o.createComponent(t.Match,{get when(){return e.toast.icon},get children(){const t=b.cloneNode(!0);return o.insert(t,(()=>e.toast.icon)),o.effect((e=>o.style(t,T,e))),t}}),o.createComponent(t.Match,{get when(){return"loading"===e.toast.type},get children(){const t=b.cloneNode(!0);return o.insert(t,o.createComponent(R,o.mergeProps((()=>e.toast.iconTheme)))),o.effect((e=>o.style(t,T,e))),t}}),o.createComponent(t.Match,{get when(){return"success"===e.toast.type},get children(){const t=b.cloneNode(!0);return o.insert(t,o.createComponent(M,o.mergeProps((()=>e.toast.iconTheme)))),o.effect((e=>o.style(t,T,e))),t}}),o.createComponent(t.Match,{get when(){return"error"===e.toast.type},get children(){const t=b.cloneNode(!0);return o.insert(t,o.createComponent(F,o.mergeProps((()=>e.toast.iconTheme)))),o.effect((e=>o.style(t,T,e))),t}})]}}),n),o.spread(n,(()=>e.toast.ariaProps),!1,!0),o.insert(n,(()=>s(e.toast.message,e.toast))),o.effect((t=>{const s=e.toast.className,i={...v,...e.toast.style},a=y;return s!==t._v$&&o.className(r,t._v$=s),t._v$2=o.style(r,i,t._v$2),t._v$3=o.style(n,a,t._v$3),t}),{_v$:void 0,_v$2:void 0,_v$3:void 0}),r})()},O=o.template("<div></div>",2),$=e=>{const i=()=>{const t=e.toast.position||d.position,o=((t,e)=>{const{toasts:o}=r,s=g().gutter||u.gutter||8,i=o.filter((t=>(t.position||e)===e&&t.height)),n=i.findIndex((e=>e.id===t.id)),a=i.filter(((t,e)=>e<n&&t.visible)).length;return i.slice(0,a).reduce(((t,e)=>t+s+(e.height||0)),0)})(e.toast,t),s=((t,e)=>({left:0,right:0,display:"flex",position:"absolute",transition:"all 230ms cubic-bezier(.21,1.02,.73,1)",...t.includes("top")?{top:0,"margin-top":`${e}px`}:{bottom:0,"margin-bottom":`${e}px`},...t.includes("center")?{"justify-content":"center"}:t.includes("right")?{"justify-content":"flex-end"}:{}}))(t,o);return s},[n,a]=t.createSignal(i());let c;return t.createEffect((()=>{const t=i();a(t)})),t.onMount((()=>{c&&((t,e)=>{const o=t.getBoundingClientRect();o.height!==e.height&&l({type:exports.ActionType.UPDATE_TOAST,toast:{id:e.id,height:o.height}})})(c,e.toast)})),(()=>{const t=O.cloneNode(!0);t.addEventListener("mouseleave",(()=>l({type:exports.ActionType.END_PAUSE,time:Date.now()}))),t.addEventListener("mouseenter",(()=>l({type:exports.ActionType.START_PAUSE,time:Date.now()})));return"function"==typeof c?c(t):c=t,o.insert(t,(()=>{const t=o.memo((()=>"custom"===e.toast.type),!0);return()=>t()?s(e.toast.message,e.toast):o.createComponent(C,{get toast(){return e.toast},get position(){return e.toast.position||d.position}})})()),o.effect((s=>{const i=n(),r=e.toast.visible?"sldt-active":"";return s._v$=o.style(t,i,s._v$),r!==s._v$2&&o.className(t,s._v$2=r),s}),{_v$:void 0,_v$2:void 0}),t})()},N=o.template('<svg><circle cx="16" cy="16" r="0"><animate attributeName="opacity" values="0; 1; 1"></animate><animate attributeName="r" values="0; 17.5; 16"></animate></circle></svg>',8,!0),k=o.template('<svg><circle cx="16" cy="16" r="12"><animate attributeName="opacity" values="1; 0"></animate><animate attributeName="r" values="12; 26"></animate></circle></svg>',8,!0),D=t=>{const e={dur:"0.35s",begin:"100ms",fill:"freeze",calcMode:"spline",keyTimes:"0; 0.6; 1",keySplines:"0.25 0.71 0.4 0.88; .59 .22 .87 .63"};return(()=>{const s=N.cloneNode(!0),i=s.firstChild,r=i.nextSibling;return o.spread(i,e,!0,!1),o.spread(r,e,!0,!1),o.effect((()=>o.setAttribute(s,"fill",t.fill))),s})()},w=t=>{const e={dur:"1s",begin:t.begin||"320ms",fill:"freeze",...h("0.0 0.0 0.2 1")};return(()=>{const s=k.cloneNode(!0),i=s.firstChild,r=i.nextSibling;return o.spread(i,e,!0,!1),o.spread(r,e,!0,!1),o.effect((()=>o.setAttribute(s,"fill",t.fill))),s})()},P=o.template('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="22" stroke-dashoffset="22" stroke-linecap="round" stroke-miterlimit="10" d="M9.8,17.2l3.8,3.6c0.1,0.1,0.3,0.1,0.4,0l9.6-9.7"><animate attributeName="stroke-dashoffset" values="22;0" dur="0.25s" begin="250ms" fill="freeze"></animate></path></svg>',6),M=t=>{const e=t.primary||"#34C759";return(()=>{const s=P.cloneNode(!0),i=s.firstChild,r=i.firstChild;return s.style.setProperty("overflow","visible"),o.insert(s,o.createComponent(D,{fill:e}),i),o.insert(s,o.createComponent(w,{fill:e,begin:"350ms"}),i),o.spread(r,(()=>h("0.0, 0.0, 0.58, 1.0")),!0,!1),o.effect((()=>o.setAttribute(i,"stroke",t.secondary||"#FCFCFC"))),s})()},I=o.template('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="9" stroke-dashoffset="9" stroke-linecap="round" d="M16,7l0,9"><animate attributeName="stroke-dashoffset" values="9;0" dur="0.2s" begin="250ms" fill="freeze"></animate></path><circle cx="16" cy="23" r="2.5" opacity="0"><animate attributeName="opacity" values="0;1" dur="0.25s" begin="350ms" fill="freeze"></animate></circle></svg>',10),F=t=>{const e=t.primary||"#FF3B30";return(()=>{const s=I.cloneNode(!0),i=s.firstChild,r=i.firstChild,n=i.nextSibling,a=n.firstChild;return s.style.setProperty("overflow","visible"),o.insert(s,o.createComponent(D,{fill:e}),i),o.insert(s,o.createComponent(w,{fill:e}),i),o.spread(r,(()=>h("0.0, 0.0, 0.58, 1.0")),!0,!1),o.spread(a,(()=>h("0.0, 0.0, 0.58, 1.0")),!0,!1),o.effect((e=>{const s=t.secondary||"#FFFFFF",r=t.secondary||"#FFFFFF";return s!==e._v$&&o.setAttribute(i,"stroke",e._v$=s),r!==e._v$2&&o.setAttribute(n,"fill",e._v$2=r),e}),{_v$:void 0,_v$2:void 0}),s})()},U=o.template('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c1.5,1.8,2.5,4,2.5,6.6c0,5.5-4.5,10-10,10S6,21.6,6,16S10.5,6,16,6z"></path><path fill="none" stroke-width="4" stroke-linecap="round" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c0.6,0.7,1.1,1.4,1.5,2.2"><animateTransform attributeName="transform" type="rotate" from="0 16 16" to="360 16 16" dur="0.75s" repeatCount="indefinite"></animateTransform></path></svg>',8),R=t=>(()=>{const e=U.cloneNode(!0),s=e.firstChild,i=s.nextSibling;return e.style.setProperty("overflow","visible"),o.effect((e=>{const r=t.primary||"#E5E7EB",n=t.secondary||"#4b5563";return r!==e._v$&&o.setAttribute(s,"stroke",e._v$=r),n!==e._v$2&&o.setAttribute(i,"stroke",e._v$2=n),e}),{_v$:void 0,_v$2:void 0}),e})();var z=x;exports.Toaster=e=>(t.createEffect((()=>{(t=>{A((e=>({containerClassName:t.containerClassName??e.containerClassName,containerStyle:t.containerStyle??e.containerStyle,gutter:t.gutter??e.gutter,position:t.position??e.position,toastOptions:{...t.toastOptions}})))})(e)})),t.createEffect((()=>{const e=(()=>{const{pausedAt:t,toasts:e}=r;if(t)return;const o=Date.now(),s=e.map((t=>{if(t.duration===1/0)return;const e=(t.duration||0)+t.pauseDuration-(o-t.createdAt);if(!(e<=0))return setTimeout((()=>{l({type:exports.ActionType.DISMISS_TOAST,toastId:t.id})}),e);t.visible&&l({type:exports.ActionType.DISMISS_TOAST,toastId:t.id})}));return s})();t.onCleanup((()=>{e&&e.forEach((t=>t&&clearTimeout(t)))}))})),(()=>{const s=_.cloneNode(!0);return s.firstChild,o.insert(s,o.createComponent(t.For,{get each(){return r.toasts},children:t=>o.createComponent($,{toast:t})}),null),o.effect((t=>{const i={...m,...e.containerStyle},r=e.containerClassName;return t._v$=o.style(s,i,t._v$),r!==t._v$2&&o.className(s,t._v$2=r),t}),{_v$:void 0,_v$2:void 0}),s})()),exports.default=z,exports.resolveValue=s,exports.toast=x; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
function t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function e(e){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?t(Object(i),!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function n(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||o(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var r,i,o=[],a=!0,s=!1;try{for(n=n.call(t);!(a=(r=n.next()).done)&&(o.push(r.value),!e||o.length!==e);a=!0);}catch(t){s=!0,i=t}finally{try{a||null==n.return||n.return()}finally{if(s)throw i}}return o}(t,e)||o(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){if(t){if("string"==typeof t)return a(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(t,e):void 0}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}import{createSignal as s,createEffect as u,onCleanup as c,For as l,Switch as f,Match as d,onMount as v}from"solid-js";import{createStore as p,produce as m}from"solid-js/store";import{insert as y,createComponent as h,effect as g,style as b,className as S,template as T,mergeProps as _,spread as A,memo as O,setAttribute as x}from"solid-js/web";var w,E=function(t,e){return function(t){return"function"==typeof t}(t)?t(e):t};!function(t){t[t.ADD_TOAST=0]="ADD_TOAST",t[t.UPDATE_TOAST=1]="UPDATE_TOAST",t[t.UPSERT_TOAST=2]="UPSERT_TOAST",t[t.DISMISS_TOAST=3]="DISMISS_TOAST",t[t.REMOVE_TOAST=4]="REMOVE_TOAST",t[t.START_PAUSE=5]="START_PAUSE",t[t.END_PAUSE=6]="END_PAUSE"}(w||(w={}));var D,k=i(p({toasts:[],pausedAt:void 0}),2),$=k[0],N=k[1],P=new Map,I=function(t,e){if(!P.has(t)){var n=setTimeout((function(){P.delete(t),C({type:w.REMOVE_TOAST,toastId:t})}),e);P.set(t,n)}},C=function t(n){switch(n.type){case w.ADD_TOAST:N("toasts",(function(t){var e=t;return[n.toast].concat(r(e))}));break;case w.DISMISS_TOAST:var i=n.toastId,o=$.toasts;if(i){var a=o.find((function(t){return t.id===i}));a&&I(i,a.unmountDelay),N("toasts",(function(t){return t.id===i}),m((function(t){return t.visible=!1})))}else o.forEach((function(t){I(t.id,t.unmountDelay)})),N("toasts",(function(t){return void 0!==t.id}),m((function(t){return t.visible=!1})));break;case w.REMOVE_TOAST:if(!n.toastId){N("toasts",[]);break}N("toasts",(function(t){return t.filter((function(t){return t.id!==n.toastId}))}));break;case w.UPDATE_TOAST:n.toast.id&&function(t){var e=P.get(t);P.delete(t),e&&clearTimeout(e)}(n.toast.id),N("toasts",(function(t){return t.id===n.toast.id}),(function(t){return e(e({},t),n.toast)}));break;case w.UPSERT_TOAST:$.toasts.find((function(t){return t.id===n.toast.id}))?t({type:w.UPDATE_TOAST,toast:n.toast}):t({type:w.ADD_TOAST,toast:n.toast});break;case w.START_PAUSE:N("pausedAt",Date.now());break;case w.END_PAUSE:var s=n.time-($.pausedAt||0);N(m((function(t){t.pausedAt=void 0,t.toasts.forEach((function(t){t.pauseDuration+=s}))})))}},j={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},M={id:"",icon:"",unmountDelay:500,duration:3e3,ariaProps:{role:"status","aria-live":"polite"},className:"",style:{},position:"top-right",iconTheme:{}},U={position:"top-right",toastOptions:M,gutter:8,containerStyle:{},containerClassName:""},F={position:"fixed","z-index":9999,top:"16px",bottom:"16px",left:"16px",right:"16px","pointer-events":"none"},R=(D=0,function(){return String(++D)}),z={display:"flex","align-items":"center",color:"#363636","box-shadow":"0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05)","max-width":"350px","pointer-events":"auto",padding:"8px 10px","border-radius":"4px","line-height":"1.3","will-change":"transform"},B={display:"flex","align-items":"center",flex:"1 1 auto",margin:"4px 10px","white-space":"pre-line"},V={"flex-shrink":0,"min-width":"20px","min-height":"20px",display:"flex","align-items":"center","justify-content":"center","text-align":"center"},L=function(t){return{calcMode:"spline",keyTimes:"0; 1",keySplines:t}},q=i(s(U),2),G=q[0],H=q[1],J=function(t){var n,r,i,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"blank",a=arguments.length>2?arguments[2]:void 0;return e(e(e(e({},M),G().toastOptions),a),{},{type:o,message:t,pauseDuration:0,createdAt:Date.now(),visible:!0,id:a.id||R(),style:e(e(e({},M.style),null===(n=G().toastOptions)||void 0===n?void 0:n.style),a.style),duration:a.duration||(null===(r=G().toastOptions)||void 0===r?void 0:r.duration)||j[o],position:a.position||(null===(i=G().toastOptions)||void 0===i?void 0:i.position)||G().position||M.position})},K=function(t){return function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=$.toasts.find((function(t){return t.id===r.id})),o=J(n,t,e(e({},i),{},{duration:void 0},r));return C({type:w.UPSERT_TOAST,toast:o}),o.id}},Q=function(t,e){return K("blank")(t,e)};Q.error=K("error"),Q.success=K("success"),Q.loading=K("loading"),Q.custom=K("custom"),Q.dismiss=function(t){C({type:w.DISMISS_TOAST,toastId:t})},Q.promise=function(t,n,r){var i=Q.loading(n.loading,e({},r));return t.then((function(t){return Q.success(E(n.success,t),e({id:i},r)),t})).catch((function(t){Q.error(E(n.error,t),e({id:i},r))})),t},Q.remove=function(t){C({type:w.REMOVE_TOAST,toastId:t})};var W=T("<div><style>.sldt-active{z-index:9999;}.sldt-active>*{pointer-events:auto;}</style></div>",4),X=function(t){return u((function(){!function(t){H((function(n){var r,i,o,a;return{containerClassName:null!==(r=t.containerClassName)&&void 0!==r?r:n.containerClassName,containerStyle:null!==(i=t.containerStyle)&&void 0!==i?i:n.containerStyle,gutter:null!==(o=t.gutter)&&void 0!==o?o:n.gutter,position:null!==(a=t.position)&&void 0!==a?a:n.position,toastOptions:e({},t.toastOptions)}}))}(t)})),u((function(){var t=function(){var t=$.pausedAt,e=$.toasts;if(!t){var n=Date.now(),r=e.map((function(t){if(t.duration!==1/0){var e=(t.duration||0)+t.pauseDuration-(n-t.createdAt);if(!(e<=0))return setTimeout((function(){C({type:w.DISMISS_TOAST,toastId:t.id})}),e);t.visible&&C({type:w.DISMISS_TOAST,toastId:t.id})}}));return r}}();c((function(){t&&t.forEach((function(t){return t&&clearTimeout(t)}))}))})),(n=W.cloneNode(!0)).firstChild,y(n,h(l,{get each(){return $.toasts},children:function(t){return h(nt,{toast:t})}}),null),g((function(r){var i=e(e({},F),t.containerStyle),o=t.containerClassName;return r._v$=b(n,i,r._v$),o!==r._v$2&&S(n,r._v$2=o),r}),{_v$:void 0,_v$2:void 0}),n;var n},Y=T("<div></div>",2),Z=T("<div><div></div></div>",4),tt=function(t){var n,r,i;return u((function(){if(n){var e=function(t,e){return(t.position||e).includes("top")?1:-1}(t.toast,t.position);t.toast.visible?n.animate([{transform:"translate3d(0,".concat(-200*e,"%,0) scale(.6)"),opacity:.5},{transform:"translate3d(0,0,0) scale(1)",opacity:1}],{duration:350,fill:"forwards",easing:"cubic-bezier(.21,1.02,.73,1)"}):n.animate([{transform:"translate3d(0,0,-1px) scale(1)",opacity:1},{transform:"translate3d(0,".concat(-150*e,"%,-1px) scale(.4)"),opacity:0}],{duration:400,fill:"forwards",easing:"cubic-bezier(.06,.71,.55,1)"})}})),console.log("CLASSSNAME",t.toast.className),r=Z.cloneNode(!0),i=r.firstChild,"function"==typeof n?n(r):n=r,y(r,h(f,{get children(){return[h(d,{get when(){return t.toast.icon},get children(){var e=Y.cloneNode(!0);return y(e,(function(){return t.toast.icon})),g((function(t){return b(e,V,t)})),e}}),h(d,{get when(){return"loading"===t.toast.type},get children(){var e=Y.cloneNode(!0);return y(e,h(dt,_((function(){return t.toast.iconTheme})))),g((function(t){return b(e,V,t)})),e}}),h(d,{get when(){return"success"===t.toast.type},get children(){var e=Y.cloneNode(!0);return y(e,h(ut,_((function(){return t.toast.iconTheme})))),g((function(t){return b(e,V,t)})),e}}),h(d,{get when(){return"error"===t.toast.type},get children(){var e=Y.cloneNode(!0);return y(e,h(lt,_((function(){return t.toast.iconTheme})))),g((function(t){return b(e,V,t)})),e}})]}}),i),A(i,(function(){return t.toast.ariaProps}),!1,!0),y(i,(function(){return E(t.toast.message,t.toast)})),g((function(n){var o=t.toast.className,a=e(e({},z),t.toast.style),s=B;return o!==n._v$&&S(r,n._v$=o),n._v$2=b(r,a,n._v$2),n._v$3=b(i,s,n._v$3),n}),{_v$:void 0,_v$2:void 0,_v$3:void 0}),r},et=T("<div></div>",2),nt=function(t){var n=function(){var n=t.toast.position||M.position,r=function(t,e){var n=$.toasts,r=G().gutter||U.gutter||8,i=n.filter((function(t){return(t.position||e)===e&&t.height})),o=i.findIndex((function(e){return e.id===t.id})),a=i.filter((function(t,e){return e<o&&t.visible})).length;return i.slice(0,a).reduce((function(t,e){return t+r+(e.height||0)}),0)}(t.toast,n),i=function(t,n){var r=t.includes("top")?{top:0,"margin-top":"".concat(n,"px")}:{bottom:0,"margin-bottom":"".concat(n,"px")},i=t.includes("center")?{"justify-content":"center"}:t.includes("right")?{"justify-content":"flex-end"}:{};return e(e({left:0,right:0,display:"flex",position:"absolute",transition:"all 230ms cubic-bezier(.21,1.02,.73,1)"},r),i)}(n,r);return i},r=i(s(n()),2),o=r[0],a=r[1];u((function(){var t=n();a(t)}));var c=void 0;return v((function(){c&&function(t,e){var n=t.getBoundingClientRect();n.height!==e.height&&C({type:w.UPDATE_TOAST,toast:{id:e.id,height:n.height}})}(c,t.toast)})),function(){var e=et.cloneNode(!0);e.addEventListener("mouseleave",(function(){return C({type:w.END_PAUSE,time:Date.now()})})),e.addEventListener("mouseenter",(function(){return C({type:w.START_PAUSE,time:Date.now()})}));var n;return"function"==typeof c?c(e):c=e,y(e,(n=O((function(){return"custom"===t.toast.type}),!0),function(){return n()?E(t.toast.message,t.toast):h(tt,{get toast(){return t.toast},get position(){return t.toast.position||M.position}})})),g((function(n){var r=o(),i=t.toast.visible?"sldt-active":"";return n._v$=b(e,r,n._v$),i!==n._v$2&&S(e,n._v$2=i),n}),{_v$:void 0,_v$2:void 0}),e}()},rt=T('<svg><circle cx="16" cy="16" r="0"><animate attributeName="opacity" values="0; 1; 1"></animate><animate attributeName="r" values="0; 17.5; 16"></animate></circle></svg>',8,!0),it=T('<svg><circle cx="16" cy="16" r="12"><animate attributeName="opacity" values="1; 0"></animate><animate attributeName="r" values="12; 26"></animate></circle></svg>',8,!0),ot=function(t){var e,n,r,i={dur:"0.35s",begin:"100ms",fill:"freeze",calcMode:"spline",keyTimes:"0; 0.6; 1",keySplines:"0.25 0.71 0.4 0.88; .59 .22 .87 .63"};return e=rt.cloneNode(!0),n=e.firstChild,r=n.nextSibling,A(n,i,!0,!1),A(r,i,!0,!1),g((function(){return x(e,"fill",t.fill)})),e},at=function(t){var n,r,i,o=e({dur:"1s",begin:t.begin||"320ms",fill:"freeze"},L("0.0 0.0 0.2 1"));return n=it.cloneNode(!0),r=n.firstChild,i=r.nextSibling,A(r,o,!0,!1),A(i,o,!0,!1),g((function(){return x(n,"fill",t.fill)})),n},st=T('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="22" stroke-dashoffset="22" stroke-linecap="round" stroke-miterlimit="10" d="M9.8,17.2l3.8,3.6c0.1,0.1,0.3,0.1,0.4,0l9.6-9.7"><animate attributeName="stroke-dashoffset" values="22;0" dur="0.25s" begin="250ms" fill="freeze"></animate></path></svg>',6),ut=function(t){var e,n,r,i=t.primary||"#34C759";return e=st.cloneNode(!0),n=e.firstChild,r=n.firstChild,e.style.setProperty("overflow","visible"),y(e,h(ot,{fill:i}),n),y(e,h(at,{fill:i,begin:"350ms"}),n),A(r,(function(){return L("0.0, 0.0, 0.58, 1.0")}),!0,!1),g((function(){return x(n,"stroke",t.secondary||"#FCFCFC")})),e},ct=T('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="9" stroke-dashoffset="9" stroke-linecap="round" d="M16,7l0,9"><animate attributeName="stroke-dashoffset" values="9;0" dur="0.2s" begin="250ms" fill="freeze"></animate></path><circle cx="16" cy="23" r="2.5" opacity="0"><animate attributeName="opacity" values="0;1" dur="0.25s" begin="350ms" fill="freeze"></animate></circle></svg>',10),lt=function(t){var e,n,r,i,o,a=t.primary||"#FF3B30";return e=ct.cloneNode(!0),n=e.firstChild,r=n.firstChild,i=n.nextSibling,o=i.firstChild,e.style.setProperty("overflow","visible"),y(e,h(ot,{fill:a}),n),y(e,h(at,{fill:a}),n),A(r,(function(){return L("0.0, 0.0, 0.58, 1.0")}),!0,!1),A(o,(function(){return L("0.0, 0.0, 0.58, 1.0")}),!0,!1),g((function(e){var r=t.secondary||"#FFFFFF",o=t.secondary||"#FFFFFF";return r!==e._v$&&x(n,"stroke",e._v$=r),o!==e._v$2&&x(i,"fill",e._v$2=o),e}),{_v$:void 0,_v$2:void 0}),e},ft=T('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c1.5,1.8,2.5,4,2.5,6.6c0,5.5-4.5,10-10,10S6,21.6,6,16S10.5,6,16,6z"></path><path fill="none" stroke-width="4" stroke-linecap="round" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c0.6,0.7,1.1,1.4,1.5,2.2"><animateTransform attributeName="transform" type="rotate" from="0 16 16" to="360 16 16" dur="0.75s" repeatCount="indefinite"></animateTransform></path></svg>',8),dt=function(t){return e=ft.cloneNode(!0),n=e.firstChild,r=n.nextSibling,e.style.setProperty("overflow","visible"),g((function(e){var i=t.primary||"#E5E7EB",o=t.secondary||"#4b5563";return i!==e._v$&&x(n,"stroke",e._v$=i),o!==e._v$2&&x(r,"stroke",e._v$2=o),e}),{_v$:void 0,_v$2:void 0}),e;var e,n,r},vt=Q;export{w as ActionType,X as Toaster,vt as default,E as resolveValue,Q as toast}; | ||
import{createSignal as t,createEffect as e,onCleanup as i,For as s,Switch as o,Match as n,onMount as r}from"solid-js";import{createStore as a,produce as l}from"solid-js/store";import{insert as c,createComponent as d,effect as u,style as p,className as m,template as v,mergeProps as f,spread as h,memo as g,setAttribute as T}from"solid-js/web";const S=(t,e)=>(t=>"function"==typeof t)(t)?t(e):t;let y;!function(t){t[t.ADD_TOAST=0]="ADD_TOAST",t[t.UPDATE_TOAST=1]="UPDATE_TOAST",t[t.UPSERT_TOAST=2]="UPSERT_TOAST",t[t.DISMISS_TOAST=3]="DISMISS_TOAST",t[t.REMOVE_TOAST=4]="REMOVE_TOAST",t[t.START_PAUSE=5]="START_PAUSE",t[t.END_PAUSE=6]="END_PAUSE"}(y||(y={}));const[_,b]=a({toasts:[],pausedAt:void 0}),A=new Map,x=(t,e)=>{if(A.has(t))return;const i=setTimeout((()=>{A.delete(t),E({type:y.REMOVE_TOAST,toastId:t})}),e);A.set(t,i)},E=t=>{switch(t.type){case y.ADD_TOAST:b("toasts",(e=>{const i=e;return[t.toast,...i]}));break;case y.DISMISS_TOAST:const{toastId:e}=t,i=_.toasts;if(e){const t=i.find((t=>t.id===e));t&&x(e,t.unmountDelay),b("toasts",(t=>t.id===e),l((t=>t.visible=!1)))}else i.forEach((t=>{x(t.id,t.unmountDelay)})),b("toasts",(t=>void 0!==t.id),l((t=>t.visible=!1)));break;case y.REMOVE_TOAST:if(!t.toastId){b("toasts",[]);break}b("toasts",(e=>e.filter((e=>e.id!==t.toastId))));break;case y.UPDATE_TOAST:t.toast.id&&(t=>{const e=A.get(t);A.delete(t),e&&clearTimeout(e)})(t.toast.id),b("toasts",(e=>e.id===t.toast.id),(e=>({...e,...t.toast})));break;case y.UPSERT_TOAST:_.toasts.find((e=>e.id===t.toast.id))?E({type:y.UPDATE_TOAST,toast:t.toast}):E({type:y.ADD_TOAST,toast:t.toast});break;case y.START_PAUSE:b("pausedAt",Date.now());break;case y.END_PAUSE:const s=t.time-(_.pausedAt||0);b(l((t=>{t.pausedAt=void 0,t.toasts.forEach((t=>{t.pauseDuration+=s}))})))}},$={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},O={id:"",icon:"",unmountDelay:500,duration:3e3,ariaProps:{role:"status","aria-live":"polite"},className:"",style:{},position:"top-right",iconTheme:{}},k={position:"top-right",toastOptions:O,gutter:8,containerStyle:{},containerClassName:""},D={position:"fixed","z-index":9999,top:"16px",bottom:"16px",left:"16px",right:"16px","pointer-events":"none"},N=(()=>{let t=0;return()=>String(++t)})(),w={display:"flex","align-items":"center",color:"#363636","box-shadow":"0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05)","max-width":"350px","pointer-events":"auto",padding:"8px 10px","border-radius":"4px","line-height":"1.3","will-change":"transform"},C={display:"flex","align-items":"center",flex:"1 1 auto",margin:"4px 10px","white-space":"pre-line"},P={"flex-shrink":0,"min-width":"20px","min-height":"20px",display:"flex","align-items":"center","justify-content":"center","text-align":"center"},I=t=>({calcMode:"spline",keyTimes:"0; 1",keySplines:t}),[M,F]=t(k),U=t=>(e,i={})=>{const s=_.toasts.find((t=>t.id===i.id)),o=((t,e="blank",i)=>({...O,...M().toastOptions,...i,type:e,message:t,pauseDuration:0,createdAt:Date.now(),visible:!0,id:i.id||N(),style:{...O.style,...M().toastOptions?.style,...i.style},duration:i.duration||M().toastOptions?.duration||$[e],position:i.position||M().toastOptions?.position||M().position||O.position}))(e,t,{...s,duration:void 0,...i});return E({type:y.UPSERT_TOAST,toast:o}),o.id},R=(t,e)=>U("blank")(t,e);R.error=U("error"),R.success=U("success"),R.loading=U("loading"),R.custom=U("custom"),R.dismiss=t=>{E({type:y.DISMISS_TOAST,toastId:t})},R.promise=(t,e,i)=>{const s=R.loading(e.loading,{...i});return t.then((t=>(R.success(S(e.success,t),{id:s,...i}),t))).catch((t=>{R.error(S(e.error,t),{id:s,...i})})),t},R.remove=t=>{E({type:y.REMOVE_TOAST,toastId:t})};const z=v("<div><style>.sldt-active{z-index:9999;}.sldt-active>*{pointer-events:auto;}</style></div>",4),j=t=>(e((()=>{(t=>{F((e=>({containerClassName:t.containerClassName??e.containerClassName,containerStyle:t.containerStyle??e.containerStyle,gutter:t.gutter??e.gutter,position:t.position??e.position,toastOptions:{...t.toastOptions}})))})(t)})),e((()=>{const t=(()=>{const{pausedAt:t,toasts:e}=_;if(t)return;const i=Date.now(),s=e.map((t=>{if(t.duration===1/0)return;const e=(t.duration||0)+t.pauseDuration-(i-t.createdAt);if(!(e<=0))return setTimeout((()=>{E({type:y.DISMISS_TOAST,toastId:t.id})}),e);t.visible&&E({type:y.DISMISS_TOAST,toastId:t.id})}));return s})();i((()=>{t&&t.forEach((t=>t&&clearTimeout(t)))}))})),(()=>{const e=z.cloneNode(!0);return e.firstChild,c(e,d(s,{get each(){return _.toasts},children:t=>d(G,{toast:t})}),null),u((i=>{const s={...D,...t.containerStyle},o=t.containerClassName;return i._v$=p(e,s,i._v$),o!==i._v$2&&m(e,i._v$2=o),i}),{_v$:void 0,_v$2:void 0}),e})()),B=v("<div></div>",2),V=v("<div><div></div></div>",4),L=t=>{let i;return e((()=>{if(!i)return;const e=((t,e)=>(t.position||e).includes("top")?1:-1)(t.toast,t.position);t.toast.visible?i.animate([{transform:`translate3d(0,${-200*e}%,0) scale(.6)`,opacity:.5},{transform:"translate3d(0,0,0) scale(1)",opacity:1}],{duration:350,fill:"forwards",easing:"cubic-bezier(.21,1.02,.73,1)"}):i.animate([{transform:"translate3d(0,0,-1px) scale(1)",opacity:1},{transform:`translate3d(0,${-150*e}%,-1px) scale(.4)`,opacity:0}],{duration:400,fill:"forwards",easing:"cubic-bezier(.06,.71,.55,1)"})})),console.log("CLASSSNAME",t.toast.className),(()=>{const e=V.cloneNode(!0),s=e.firstChild;return"function"==typeof i?i(e):i=e,c(e,d(o,{get children(){return[d(n,{get when(){return t.toast.icon},get children(){const e=B.cloneNode(!0);return c(e,(()=>t.toast.icon)),u((t=>p(e,P,t))),e}}),d(n,{get when(){return"loading"===t.toast.type},get children(){const e=B.cloneNode(!0);return c(e,d(et,f((()=>t.toast.iconTheme)))),u((t=>p(e,P,t))),e}}),d(n,{get when(){return"success"===t.toast.type},get children(){const e=B.cloneNode(!0);return c(e,d(X,f((()=>t.toast.iconTheme)))),u((t=>p(e,P,t))),e}}),d(n,{get when(){return"error"===t.toast.type},get children(){const e=B.cloneNode(!0);return c(e,d(Z,f((()=>t.toast.iconTheme)))),u((t=>p(e,P,t))),e}})]}}),s),h(s,(()=>t.toast.ariaProps),!1,!0),c(s,(()=>S(t.toast.message,t.toast))),u((i=>{const o=t.toast.className,n={...w,...t.toast.style},r=C;return o!==i._v$&&m(e,i._v$=o),i._v$2=p(e,n,i._v$2),i._v$3=p(s,r,i._v$3),i}),{_v$:void 0,_v$2:void 0,_v$3:void 0}),e})()},q=v("<div></div>",2),G=i=>{const s=()=>{const t=i.toast.position||O.position,e=((t,e)=>{const{toasts:i}=_,s=M().gutter||k.gutter||8,o=i.filter((t=>(t.position||e)===e&&t.height)),n=o.findIndex((e=>e.id===t.id)),r=o.filter(((t,e)=>e<n&&t.visible)).length;return o.slice(0,r).reduce(((t,e)=>t+s+(e.height||0)),0)})(i.toast,t),s=((t,e)=>({left:0,right:0,display:"flex",position:"absolute",transition:"all 230ms cubic-bezier(.21,1.02,.73,1)",...t.includes("top")?{top:0,"margin-top":`${e}px`}:{bottom:0,"margin-bottom":`${e}px`},...t.includes("center")?{"justify-content":"center"}:t.includes("right")?{"justify-content":"flex-end"}:{}}))(t,e);return s},[o,n]=t(s());let a;return e((()=>{const t=s();n(t)})),r((()=>{a&&((t,e)=>{const i=t.getBoundingClientRect();i.height!==e.height&&E({type:y.UPDATE_TOAST,toast:{id:e.id,height:i.height}})})(a,i.toast)})),(()=>{const t=q.cloneNode(!0);t.addEventListener("mouseleave",(()=>E({type:y.END_PAUSE,time:Date.now()}))),t.addEventListener("mouseenter",(()=>E({type:y.START_PAUSE,time:Date.now()})));return"function"==typeof a?a(t):a=t,c(t,(()=>{const t=g((()=>"custom"===i.toast.type),!0);return()=>t()?S(i.toast.message,i.toast):d(L,{get toast(){return i.toast},get position(){return i.toast.position||O.position}})})()),u((e=>{const s=o(),n=i.toast.visible?"sldt-active":"";return e._v$=p(t,s,e._v$),n!==e._v$2&&m(t,e._v$2=n),e}),{_v$:void 0,_v$2:void 0}),t})()},H=v('<svg><circle cx="16" cy="16" r="0"><animate attributeName="opacity" values="0; 1; 1"></animate><animate attributeName="r" values="0; 17.5; 16"></animate></circle></svg>',8,!0),J=v('<svg><circle cx="16" cy="16" r="12"><animate attributeName="opacity" values="1; 0"></animate><animate attributeName="r" values="12; 26"></animate></circle></svg>',8,!0),K=t=>{const e={dur:"0.35s",begin:"100ms",fill:"freeze",calcMode:"spline",keyTimes:"0; 0.6; 1",keySplines:"0.25 0.71 0.4 0.88; .59 .22 .87 .63"};return(()=>{const i=H.cloneNode(!0),s=i.firstChild,o=s.nextSibling;return h(s,e,!0,!1),h(o,e,!0,!1),u((()=>T(i,"fill",t.fill))),i})()},Q=t=>{const e={dur:"1s",begin:t.begin||"320ms",fill:"freeze",...I("0.0 0.0 0.2 1")};return(()=>{const i=J.cloneNode(!0),s=i.firstChild,o=s.nextSibling;return h(s,e,!0,!1),h(o,e,!0,!1),u((()=>T(i,"fill",t.fill))),i})()},W=v('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="22" stroke-dashoffset="22" stroke-linecap="round" stroke-miterlimit="10" d="M9.8,17.2l3.8,3.6c0.1,0.1,0.3,0.1,0.4,0l9.6-9.7"><animate attributeName="stroke-dashoffset" values="22;0" dur="0.25s" begin="250ms" fill="freeze"></animate></path></svg>',6),X=t=>{const e=t.primary||"#34C759";return(()=>{const i=W.cloneNode(!0),s=i.firstChild,o=s.firstChild;return i.style.setProperty("overflow","visible"),c(i,d(K,{fill:e}),s),c(i,d(Q,{fill:e,begin:"350ms"}),s),h(o,(()=>I("0.0, 0.0, 0.58, 1.0")),!0,!1),u((()=>T(s,"stroke",t.secondary||"#FCFCFC"))),i})()},Y=v('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-dasharray="9" stroke-dashoffset="9" stroke-linecap="round" d="M16,7l0,9"><animate attributeName="stroke-dashoffset" values="9;0" dur="0.2s" begin="250ms" fill="freeze"></animate></path><circle cx="16" cy="23" r="2.5" opacity="0"><animate attributeName="opacity" values="0;1" dur="0.25s" begin="350ms" fill="freeze"></animate></circle></svg>',10),Z=t=>{const e=t.primary||"#FF3B30";return(()=>{const i=Y.cloneNode(!0),s=i.firstChild,o=s.firstChild,n=s.nextSibling,r=n.firstChild;return i.style.setProperty("overflow","visible"),c(i,d(K,{fill:e}),s),c(i,d(Q,{fill:e}),s),h(o,(()=>I("0.0, 0.0, 0.58, 1.0")),!0,!1),h(r,(()=>I("0.0, 0.0, 0.58, 1.0")),!0,!1),u((e=>{const i=t.secondary||"#FFFFFF",o=t.secondary||"#FFFFFF";return i!==e._v$&&T(s,"stroke",e._v$=i),o!==e._v$2&&T(n,"fill",e._v$2=o),e}),{_v$:void 0,_v$2:void 0}),i})()},tt=v('<svg viewBox="0 0 32 32" width="1.25rem" height="1.25rem"><path fill="none" stroke-width="4" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c1.5,1.8,2.5,4,2.5,6.6c0,5.5-4.5,10-10,10S6,21.6,6,16S10.5,6,16,6z"></path><path fill="none" stroke-width="4" stroke-linecap="round" stroke-miterlimit="10" d="M16,6c3,0,5.7,1.3,7.5,3.4c0.6,0.7,1.1,1.4,1.5,2.2"><animateTransform attributeName="transform" type="rotate" from="0 16 16" to="360 16 16" dur="0.75s" repeatCount="indefinite"></animateTransform></path></svg>',8),et=t=>(()=>{const e=tt.cloneNode(!0),i=e.firstChild,s=i.nextSibling;return e.style.setProperty("overflow","visible"),u((e=>{const o=t.primary||"#E5E7EB",n=t.secondary||"#4b5563";return o!==e._v$&&T(i,"stroke",e._v$=o),n!==e._v$2&&T(s,"stroke",e._v$2=n),e}),{_v$:void 0,_v$2:void 0}),e})();var it=R;export{y as ActionType,j as Toaster,it as default,S as resolveValue,R as toast}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "solid-toast", | ||
"version": "0.3.0-alpha.0", | ||
"version": "0.3.0", | ||
"description": "Customizable Toast Notifications for SolidJS", | ||
@@ -5,0 +5,0 @@ "source": "./src/index.tsx", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
155481
1546