@zerodevx/svelte-toast
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict";function e(){}const n=t=>t;function o(t,e){for(const n in e)t[n]=e[n];return t}function r(t){return t()}function s(){return Object.create(null)}function i(t){t.forEach(r)}function a(t){return"function"==typeof t}function c(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function l(t,n,o){t.$$.on_destroy.push(function(t,...n){if(null==t)return e;const o=t.subscribe(...n);return o.unsubscribe?()=>o.unsubscribe():o}(n,o))}const u="undefined"!=typeof window;let f=u?()=>window.performance.now():()=>Date.now(),d=u?t=>requestAnimationFrame(t):e;const p=new Set;function g(t){p.forEach((e=>{e.c(t)||(p.delete(e),e.f())})),0!==p.size&&d(g)}function m(t){let e;return 0===p.size&&d(g),{promise:new Promise((n=>{p.add(e={c:t,f:n})})),abort(){p.delete(e)}}}function h(t,e){t.appendChild(e)}function v(t,e,n){var o;const r=b(t);if(!(null===(o=r)||void 0===o?void 0:o.getElementById(e))){const t=x("style");t.id=e,t.textContent=n,$(r,t)}}function y(t){return t?t.getRootNode?t.getRootNode():t.ownerDocument:document}function b(t){const e=y(t);return e.host,e}function $(t,e){h(t.head||t,e)}function _(t,e,n){t.insertBefore(e,n||null)}function w(t){t.parentNode.removeChild(t)}function x(t){return document.createElement(t)}function k(){return t=" ",document.createTextNode(t);var t}function C(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}const z=new Set;let E,B=0;function M(t,e,n,o,r,s,i,a=0){const c=16.666/o;let l="{\n";for(let t=0;t<=1;t+=c){const o=e+(n-e)*s(t);l+=100*t+`%{${i(o,1-o)}}\n`}const u=l+`100% {${i(n,1-n)}}\n}`,f=`__svelte_${function(t){let e=5381,n=t.length;for(;n--;)e=(e<<5)-e^t.charCodeAt(n);return e>>>0}(u)}_${a}`,d=y(t);z.add(d);const p=d.__svelte_stylesheet||(d.__svelte_stylesheet=function(t){const e=x("style");return $(b(t),e),e}(t).sheet),g=d.__svelte_rules||(d.__svelte_rules={});g[f]||(g[f]=!0,p.insertRule(`@keyframes ${f} ${u}`,p.cssRules.length));const m=t.style.animation||"";return t.style.animation=`${m?`${m}, `:""}${f} ${o}ms linear ${r}ms 1 both`,B+=1,f}function S(t,e){const n=(t.style.animation||"").split(", "),o=n.filter(e?t=>t.indexOf(e)<0:t=>-1===t.indexOf("__svelte")),r=n.length-o.length;r&&(t.style.animation=o.join(", "),B-=r,B||d((()=>{B||(z.forEach((t=>{const e=t.__svelte_stylesheet;let n=e.cssRules.length;for(;n--;)e.deleteRule(n);t.__svelte_rules={}})),z.clear())})))}function j(t,e){const n=t.getBoundingClientRect();if(e.left!==n.left||e.top!==n.top){const o=getComputedStyle(t),r="none"===o.transform?"":o.transform;t.style.transform=`${r} translate(${e.left-n.left}px, ${e.top-n.top}px)`}}function A(t){E=t}const R=[],O=[],P=[],T=[],H=Promise.resolve();let L=!1;function N(t){P.push(t)}let q=!1;const D=new Set;function F(){if(!q){q=!0;do{for(let t=0;t<R.length;t+=1){const e=R[t];A(e),I(e.$$)}for(A(null),R.length=0;O.length;)O.pop()();for(let t=0;t<P.length;t+=1){const e=P[t];D.has(e)||(D.add(e),e())}P.length=0}while(R.length);for(;T.length;)T.pop()();L=!1,q=!1,D.clear()}}function I(t){if(null!==t.fragment){t.update(),i(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(N)}}let W;function G(){return W||(W=Promise.resolve(),W.then((()=>{W=null}))),W}function J(t,e,n){t.dispatchEvent(function(t,e,n=!1){const o=document.createEvent("CustomEvent");return o.initCustomEvent(t,n,!1,e),o}(`${e?"intro":"outro"}${n}`))}const K=new Set;let Q;function U(t,e){t&&t.i&&(K.delete(t),t.i(e))}function V(t,e,n,o){if(t&&t.o){if(K.has(t))return;K.add(t),Q.c.push((()=>{K.delete(t),o&&(n&&t.d(1),o())})),t.o(e)}}const X={duration:0};function Y(t,e){t.f(),function(t,e){V(t,1,1,(()=>{e.delete(t.key)}))}(t,e)}function Z(t,e,n,o){const{fragment:s,on_mount:c,on_destroy:l,after_update:u}=t.$$;s&&s.m(e,n),o||N((()=>{const e=c.map(r).filter(a);l?l.push(...e):i(e),t.$$.on_mount=[]})),u.forEach(N)}function tt(t,e){const n=t.$$;null!==n.fragment&&(i(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function et(t,e){-1===t.$$.dirty[0]&&(R.push(t),L||(L=!0,H.then(F)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function nt(t,n,o,r,a,c,l,u=[-1]){const f=E;A(t);const d=t.$$={fragment:null,ctx:null,props:c,update:e,not_equal:a,bound:s(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(f?f.$$.context:n.context||[]),callbacks:s(),dirty:u,skip_bound:!1,root:n.target||f.$$.root};l&&l(d.root);let p=!1;if(d.ctx=o?o(t,n.props||{},((e,n,...o)=>{const r=o.length?o[0]:n;return d.ctx&&a(d.ctx[e],d.ctx[e]=r)&&(!d.skip_bound&&d.bound[e]&&d.bound[e](r),p&&et(t,e)),n})):[],d.update(),p=!0,i(d.before_update),d.fragment=!!r&&r(d.ctx),n.target){if(n.hydrate){const t=function(t){return Array.from(t.childNodes)}(n.target);d.fragment&&d.fragment.l(t),t.forEach(w)}else d.fragment&&d.fragment.c();n.intro&&U(t.$$.fragment),Z(t,n.target,n.anchor,n.customElement),F()}A(f)}class ot{$destroy(){tt(this,1),this.$destroy=e}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}function rt(t){const e=t-1;return e*e*e+1}function st(t,{delay:e=0,duration:o=400,easing:r=n}={}){const s=+getComputedStyle(t).opacity;return{delay:e,duration:o,easing:r,css:t=>"opacity: "+t*s}}function it(t,{delay:e=0,duration:n=400,easing:o=rt,x:r=0,y:s=0,opacity:i=0}={}){const a=getComputedStyle(t),c=+a.opacity,l="none"===a.transform?"":a.transform,u=c*(1-i);return{delay:e,duration:n,easing:o,css:(t,e)=>`\n\t\t\ttransform: ${l} translate(${(1-t)*r}px, ${(1-t)*s}px);\n\t\t\topacity: ${c-u*e}`}}function at(t,e,n={}){const o=getComputedStyle(t),r="none"===o.transform?"":o.transform,s=e.from.width/t.clientWidth,i=e.from.height/t.clientHeight,c=(e.from.left-e.to.left)/s,l=(e.from.top-e.to.top)/i,u=Math.sqrt(c*c+l*l),{delay:f=0,duration:d=(t=>120*Math.sqrt(t)),easing:p=rt}=n;return{delay:f,duration:a(d)?d(u):d,easing:p,css:(t,e)=>`transform: ${r} translate(${e*c}px, ${e*l}px);`}}const ct=[];function lt(t,n=e){let o;const r=new Set;function s(e){if(c(t,e)&&(t=e,o)){const e=!ct.length;for(const e of r)e[1](),ct.push(e,t);if(e){for(let t=0;t<ct.length;t+=2)ct[t][0](ct[t+1]);ct.length=0}}}return{set:s,update:function(e){s(e(t))},subscribe:function(i,a=e){const c=[i,a];return r.add(c),1===r.size&&(o=n(s)||e),i(t),()=>{r.delete(c),0===r.size&&(o(),o=null)}}}}const ut={duration:4e3,dismissable:!0,initial:1,progress:0,reversed:!1,intro:{x:256},theme:{}},ft=(()=>{const{subscribe:t,update:e}=lt([]);let n=0;const o={},r=t=>t instanceof Object;return{subscribe:t,push:(t,s={})=>{const i={target:"default",...r(t)?t:{...s,msg:t}},a=o[i.target]||{},c={...ut,...a,...i,theme:{...a.theme,...i.theme},id:++n};return e((t=>c.reversed?[...t,c]:[c,...t])),n},pop:t=>{e((e=>{if(!e.length||0===t)return[];if(r(t))return e.filter((e=>t(e)));const n=t||Math.max(...e.map((t=>t.id)));return e.filter((t=>t.id!==n))}))},set:(t,n={})=>{const o=r(t)?{...t}:{...n,id:t};e((t=>{const e=t.findIndex((t=>t.id===o.id));return e>-1&&(t[e]={...t[e],...o}),t}))},_init:(t="default",e={})=>(o[t]=e,o)}})();function dt(t){return"[object Date]"===Object.prototype.toString.call(t)}function pt(t,e){if(t===e||t!=t)return()=>t;const n=typeof t;if(n!==typeof e||Array.isArray(t)!==Array.isArray(e))throw new Error("Cannot interpolate values of different type");if(Array.isArray(t)){const n=e.map(((e,n)=>pt(t[n],e)));return t=>n.map((e=>e(t)))}if("object"===n){if(!t||!e)throw new Error("Object cannot be null");if(dt(t)&&dt(e)){t=t.getTime();const n=(e=e.getTime())-t;return e=>new Date(t+e*n)}const n=Object.keys(e),o={};return n.forEach((n=>{o[n]=pt(t[n],e[n])})),t=>{const e={};return n.forEach((n=>{e[n]=o[n](t)})),e}}if("number"===n){const n=e-t;return e=>t+e*n}throw new Error(`Cannot interpolate ${n} values`)}function gt(t){v(t,"svelte-1r0vvz1","._toastItem.svelte-1r0vvz1{width:var(--toastWidth,16rem);height:var(--toastHeight,auto);min-height:var(--toastMinHeight,3.5rem);margin:var(--toastMargin,0 0 0.5rem 0);background:var(--toastBackground,rgba(66,66,66,0.9));color:var(--toastColor,#FFF);box-shadow:var(--toastBoxShadow,0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06));border-radius:var(--toastBorderRadius,0.125rem);position:relative;display:flex;flex-direction:row;align-items:center;will-change:transform,opacity;-webkit-tap-highlight-color:transparent}._toastMsg.svelte-1r0vvz1{padding:var(--toastMsgPadding,0.75rem 0.5rem);flex:1 1 0%}._toastMsg.svelte-1r0vvz1 a{pointer-events:auto}._toastBtn.svelte-1r0vvz1{width:2rem;height:100%;font:1rem sans-serif;display:flex;align-items:center;justify-content:center;cursor:pointer;outline:none;pointer-events:auto}._toastBar.svelte-1r0vvz1{display:block;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:none;position:absolute;bottom:0;width:100%;height:6px;background:transparent}._toastBar.svelte-1r0vvz1::-webkit-progress-bar{background:transparent}._toastBar.svelte-1r0vvz1::-webkit-progress-value{background:var(--toastProgressBackground,rgba(33,150,243,0.75))}._toastBar.svelte-1r0vvz1::-moz-progress-bar{background:var(--toastProgressBackground,rgba(33,150,243,0.75))}")}function mt(t){let n,o,r;return{c(){n=x("div"),n.textContent="✕",C(n,"class","_toastBtn svelte-1r0vvz1"),C(n,"role","button"),C(n,"tabindex","-1")},m(e,s){var i,a,c,l;_(e,n,s),o||(i=n,a="click",c=t[4],i.addEventListener(a,c,l),r=()=>i.removeEventListener(a,c,l),o=!0)},p:e,d(t){t&&w(n),o=!1,r()}}}function ht(t){let n,o,r,s,i,a=t[0].msg+"",c=t[0].dismissable&&mt(t);return{c(){n=x("div"),o=x("div"),r=k(),c&&c.c(),s=k(),i=x("progress"),C(o,"class","_toastMsg svelte-1r0vvz1"),C(i,"class","_toastBar svelte-1r0vvz1"),i.value=t[1],C(n,"class","_toastItem svelte-1r0vvz1")},m(t,e){_(t,n,e),h(n,o),o.innerHTML=a,h(n,r),c&&c.m(n,null),h(n,s),h(n,i)},p(t,[e]){1&e&&a!==(a=t[0].msg+"")&&(o.innerHTML=a),t[0].dismissable?c?c.p(t,e):(c=mt(t),c.c(),c.m(n,s)):c&&(c.d(1),c=null),2&e&&(i.value=t[1])},i:e,o:e,d(t){t&&w(n),c&&c.d()}}}function vt(t,e,r){let s,{item:i}=e;const a=function(t,e={}){const r=lt(t);let s,i=t;function a(a,c){if(null==t)return r.set(t=a),Promise.resolve();i=a;let l=s,u=!1,{delay:d=0,duration:p=400,easing:g=n,interpolate:h=pt}=o(o({},e),c);if(0===p)return l&&(l.abort(),l=null),r.set(t=i),Promise.resolve();const v=f()+d;let y;return s=m((e=>{if(e<v)return!0;u||(y=h(t,a),"function"==typeof p&&(p=p(t,a)),u=!0),l&&(l.abort(),l=null);const n=e-v;return n>p?(r.set(t=a),!1):(r.set(t=y(g(n/p))),!0)})),s.promise}return{set:a,update:(e,n)=>a(e(i,t),n),subscribe:r.subscribe}}(i.initial,{duration:i.duration,easing:n});l(t,a,(t=>r(1,s=t)));let c=i.initial;return t.$$set=t=>{"item"in t&&r(0,i=t.item)},t.$$.update=()=>{9&t.$$.dirty&&c!==i.progress&&(1===i.progress||0===i.progress?a.set(i.progress).then((()=>ft.pop(i.id))):a.set(i.progress),r(3,c=i.progress))},[i,s,a,c,()=>ft.pop(i.id)]}class yt extends ot{constructor(t){super(),nt(this,t,vt,ht,c,{item:0},gt)}}function bt(t){v(t,"svelte-1wt6bln","ul.svelte-1wt6bln{top:var(--toastContainerTop,1.5rem);right:var(--toastContainerRight,2rem);bottom:var(--toastContainerBottom,auto);left:var(--toastContainerLeft,auto);position:fixed;margin:0;padding:0;list-style-type:none;pointer-events:none;z-index:9999}")}function $t(t,e,n){const o=t.slice();return o[5]=e[n],o}function _t(t,o){let r,s,c,l,u,d,p,g,v=e;return s=new yt({props:{item:o[5]}}),{key:t,first:null,c(){var t;r=x("li"),(t=s.$$.fragment)&&t.c(),c=k(),C(r,"style",l=o[1](o[5].theme)),this.first=r},m(t,e){_(t,r,e),Z(s,r,null),h(r,c),g=!0},p(t,e){o=t;const n={};1&e&&(n.item=o[5]),s.$set(n),(!g||1&e&&l!==(l=o[1](o[5].theme)))&&C(r,"style",l)},r(){p=r.getBoundingClientRect()},f(){!function(t){const e=getComputedStyle(t);if("absolute"!==e.position&&"fixed"!==e.position){const{width:n,height:o}=e,r=t.getBoundingClientRect();t.style.position="absolute",t.style.width=n,t.style.height=o,j(t,r)}}(r),v(),j(r,p)},a(){v(),v=function(t,o,r,s){if(!o)return e;const i=t.getBoundingClientRect();if(o.left===i.left&&o.right===i.right&&o.top===i.top&&o.bottom===i.bottom)return e;const{delay:a=0,duration:c=300,easing:l=n,start:u=f()+a,end:d=u+c,tick:p=e,css:g}=r(t,{from:o,to:i},s);let h,v=!0,y=!1;function b(){g&&S(t,h),v=!1}return m((t=>{if(!y&&t>=u&&(y=!0),y&&t>=d&&(p(1,0),b()),!v)return!1;if(y){const e=0+1*l((t-u)/c);p(e,1-e)}return!0})),g&&(h=M(t,0,1,c,a,l,g)),a||(y=!0),p(0,1),b}(r,p,at,{duration:200})},i(t){g||(U(s.$$.fragment,t),N((()=>{d&&d.end(1),u||(u=function(t,o,r){let s,i,c=o(t,r),l=!1,u=0;function d(){s&&S(t,s)}function p(){const{delay:o=0,duration:r=300,easing:a=n,tick:p=e,css:g}=c||X;g&&(s=M(t,0,1,r,o,a,g,u++)),p(0,1);const h=f()+o,v=h+r;i&&i.abort(),l=!0,N((()=>J(t,!0,"start"))),i=m((e=>{if(l){if(e>=v)return p(1,0),J(t,!0,"end"),d(),l=!1;if(e>=h){const t=a((e-h)/r);p(t,1-t)}}return l}))}let g=!1;return{start(){g||(g=!0,S(t),a(c)?(c=c(),G().then(p)):p())},invalidate(){g=!1},end(){l&&(d(),l=!1)}}}(r,it,o[5].intro)),u.start()})),g=!0)},o(t){V(s.$$.fragment,t),u&&u.invalidate(),d=function(t,o,r){let s,c=o(t,r),l=!0;const u=Q;function d(){const{delay:o=0,duration:r=300,easing:a=n,tick:d=e,css:p}=c||X;p&&(s=M(t,1,0,r,o,a,p));const g=f()+o,h=g+r;N((()=>J(t,!1,"start"))),m((e=>{if(l){if(e>=h)return d(0,1),J(t,!1,"end"),--u.r||i(u.c),!1;if(e>=g){const t=a((e-g)/r);d(1-t,t)}}return l}))}return u.r+=1,a(c)?G().then((()=>{c=c(),d()})):d(),{end(e){e&&c.tick&&c.tick(1,0),l&&(s&&S(t,s),l=!1)}}}(r,st,{}),g=!1},d(t){t&&w(r),tt(s),t&&d&&d.end()}}}function wt(t){let e,n,o=[],r=new Map,s=t[0];const a=t=>t[5].id;for(let e=0;e<s.length;e+=1){let n=$t(t,s,e),i=a(n);r.set(i,o[e]=_t(i,n))}return{c(){e=x("ul");for(let t=0;t<o.length;t+=1)o[t].c();C(e,"class","svelte-1wt6bln")},m(t,r){_(t,e,r);for(let t=0;t<o.length;t+=1)o[t].m(e,null);n=!0},p(t,[n]){if(3&n){s=t[0],Q={r:0,c:[],p:Q};for(let t=0;t<o.length;t+=1)o[t].r();o=function(t,e,n,o,r,s,i,a,c,l,u,f){let d=t.length,p=s.length,g=d;const m={};for(;g--;)m[t[g].key]=g;const h=[],v=new Map,y=new Map;for(g=p;g--;){const t=f(r,s,g),a=n(t);let c=i.get(a);c?o&&c.p(t,e):(c=l(a,t),c.c()),v.set(a,h[g]=c),a in m&&y.set(a,Math.abs(g-m[a]))}const b=new Set,$=new Set;function _(t){U(t,1),t.m(a,u),i.set(t.key,t),u=t.first,p--}for(;d&&p;){const e=h[p-1],n=t[d-1],o=e.key,r=n.key;e===n?(u=e.first,d--,p--):v.has(r)?!i.has(o)||b.has(o)?_(e):$.has(r)?d--:y.get(o)>y.get(r)?($.add(o),_(e)):(b.add(r),d--):(c(n,i),d--)}for(;d--;){const e=t[d];v.has(e.key)||c(e,i)}for(;p;)_(h[p-1]);return h}(o,n,a,1,t,s,r,e,Y,_t,null,$t);for(let t=0;t<o.length;t+=1)o[t].a();Q.r||i(Q.c),Q=Q.p}},i(t){if(!n){for(let t=0;t<s.length;t+=1)U(o[t]);n=!0}},o(t){for(let t=0;t<o.length;t+=1)V(o[t]);n=!1},d(t){t&&w(e);for(let t=0;t<o.length;t+=1)o[t].d()}}}function xt(t,e,n){let o;l(t,ft,(t=>n(4,o=t)));let r,{options:s={}}=e,{target:i="default"}=e;return t.$$set=t=>{"options"in t&&n(2,s=t.options),"target"in t&&n(3,i=t.target)},t.$$.update=()=>{12&t.$$.dirty&&ft._init(i,s),24&t.$$.dirty&&n(0,r=o.filter((t=>t.target===i)))},[r,t=>Object.keys(t).reduce(((e,n)=>`${e}${n}:${t[n]};`),""),s,i,o]}t.SvelteToast=class extends ot{constructor(t){super(),nt(this,t,xt,wt,c,{options:2,target:3},bt)}},t.toast=ft,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).window=t.window||{})}(this,(function(t){"use strict";function e(){}const n=t=>t;function o(t,e){for(const n in e)t[n]=e[n];return t}function r(t){return t()}function s(){return Object.create(null)}function i(t){t.forEach(r)}function a(t){return"function"==typeof t}function c(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function l(t,n,o){t.$$.on_destroy.push(function(t,...n){if(null==t)return e;const o=t.subscribe(...n);return o.unsubscribe?()=>o.unsubscribe():o}(n,o))}const u="undefined"!=typeof window;let f=u?()=>window.performance.now():()=>Date.now(),d=u?t=>requestAnimationFrame(t):e;const p=new Set;function g(t){p.forEach((e=>{e.c(t)||(p.delete(e),e.f())})),0!==p.size&&d(g)}function m(t){let e;return 0===p.size&&d(g),{promise:new Promise((n=>{p.add(e={c:t,f:n})})),abort(){p.delete(e)}}}function h(t,e){t.appendChild(e)}function v(t,e,n){const o=y(t);if(!o.getElementById(e)){const t=w("style");t.id=e,t.textContent=n,b(o,t)}}function y(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e.host?e:document}function b(t,e){h(t.head||t,e)}function $(t,e,n){t.insertBefore(e,n||null)}function _(t){t.parentNode.removeChild(t)}function w(t){return document.createElement(t)}function x(){return t=" ",document.createTextNode(t);var t}function k(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}const C=new Set;let z,E=0;function B(t,e,n,o,r,s,i,a=0){const c=16.666/o;let l="{\n";for(let t=0;t<=1;t+=c){const o=e+(n-e)*s(t);l+=100*t+`%{${i(o,1-o)}}\n`}const u=l+`100% {${i(n,1-n)}}\n}`,f=`__svelte_${function(t){let e=5381,n=t.length;for(;n--;)e=(e<<5)-e^t.charCodeAt(n);return e>>>0}(u)}_${a}`,d=y(t);C.add(d);const p=d.__svelte_stylesheet||(d.__svelte_stylesheet=function(t){const e=w("style");return b(y(t),e),e}(t).sheet),g=d.__svelte_rules||(d.__svelte_rules={});g[f]||(g[f]=!0,p.insertRule(`@keyframes ${f} ${u}`,p.cssRules.length));const m=t.style.animation||"";return t.style.animation=`${m?`${m}, `:""}${f} ${o}ms linear ${r}ms 1 both`,E+=1,f}function M(t,e){const n=(t.style.animation||"").split(", "),o=n.filter(e?t=>t.indexOf(e)<0:t=>-1===t.indexOf("__svelte")),r=n.length-o.length;r&&(t.style.animation=o.join(", "),E-=r,E||d((()=>{E||(C.forEach((t=>{const e=t.__svelte_stylesheet;let n=e.cssRules.length;for(;n--;)e.deleteRule(n);t.__svelte_rules={}})),C.clear())})))}function S(t,e){const n=t.getBoundingClientRect();if(e.left!==n.left||e.top!==n.top){const o=getComputedStyle(t),r="none"===o.transform?"":o.transform;t.style.transform=`${r} translate(${e.left-n.left}px, ${e.top-n.top}px)`}}function j(t){z=t}const A=[],R=[],O=[],P=[],T=Promise.resolve();let H=!1;function L(t){O.push(t)}let N=!1;const q=new Set;function D(){if(!N){N=!0;do{for(let t=0;t<A.length;t+=1){const e=A[t];j(e),F(e.$$)}for(j(null),A.length=0;R.length;)R.pop()();for(let t=0;t<O.length;t+=1){const e=O[t];q.has(e)||(q.add(e),e())}O.length=0}while(A.length);for(;P.length;)P.pop()();H=!1,N=!1,q.clear()}}function F(t){if(null!==t.fragment){t.update(),i(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(L)}}let I;function W(){return I||(I=Promise.resolve(),I.then((()=>{I=null}))),I}function G(t,e,n){t.dispatchEvent(function(t,e,n=!1){const o=document.createEvent("CustomEvent");return o.initCustomEvent(t,n,!1,e),o}(`${e?"intro":"outro"}${n}`))}const J=new Set;let K;function Q(t,e){t&&t.i&&(J.delete(t),t.i(e))}function U(t,e,n,o){if(t&&t.o){if(J.has(t))return;J.add(t),K.c.push((()=>{J.delete(t),o&&(n&&t.d(1),o())})),t.o(e)}}const V={duration:0};function X(t,e){t.f(),function(t,e){U(t,1,1,(()=>{e.delete(t.key)}))}(t,e)}function Y(t,e,n,o){const{fragment:s,on_mount:c,on_destroy:l,after_update:u}=t.$$;s&&s.m(e,n),o||L((()=>{const e=c.map(r).filter(a);l?l.push(...e):i(e),t.$$.on_mount=[]})),u.forEach(L)}function Z(t,e){const n=t.$$;null!==n.fragment&&(i(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function tt(t,e){-1===t.$$.dirty[0]&&(A.push(t),H||(H=!0,T.then(D)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function et(t,n,o,r,a,c,l,u=[-1]){const f=z;j(t);const d=t.$$={fragment:null,ctx:null,props:c,update:e,not_equal:a,bound:s(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(f?f.$$.context:n.context||[]),callbacks:s(),dirty:u,skip_bound:!1,root:n.target||f.$$.root};l&&l(d.root);let p=!1;if(d.ctx=o?o(t,n.props||{},((e,n,...o)=>{const r=o.length?o[0]:n;return d.ctx&&a(d.ctx[e],d.ctx[e]=r)&&(!d.skip_bound&&d.bound[e]&&d.bound[e](r),p&&tt(t,e)),n})):[],d.update(),p=!0,i(d.before_update),d.fragment=!!r&&r(d.ctx),n.target){if(n.hydrate){const t=function(t){return Array.from(t.childNodes)}(n.target);d.fragment&&d.fragment.l(t),t.forEach(_)}else d.fragment&&d.fragment.c();n.intro&&Q(t.$$.fragment),Y(t,n.target,n.anchor,n.customElement),D()}j(f)}class nt{$destroy(){Z(this,1),this.$destroy=e}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}function ot(t){const e=t-1;return e*e*e+1}function rt(t,{delay:e=0,duration:o=400,easing:r=n}={}){const s=+getComputedStyle(t).opacity;return{delay:e,duration:o,easing:r,css:t=>"opacity: "+t*s}}function st(t,{delay:e=0,duration:n=400,easing:o=ot,x:r=0,y:s=0,opacity:i=0}={}){const a=getComputedStyle(t),c=+a.opacity,l="none"===a.transform?"":a.transform,u=c*(1-i);return{delay:e,duration:n,easing:o,css:(t,e)=>`\n\t\t\ttransform: ${l} translate(${(1-t)*r}px, ${(1-t)*s}px);\n\t\t\topacity: ${c-u*e}`}}function it(t,e,n={}){const o=getComputedStyle(t),r="none"===o.transform?"":o.transform,s=e.from.width/t.clientWidth,i=e.from.height/t.clientHeight,c=(e.from.left-e.to.left)/s,l=(e.from.top-e.to.top)/i,u=Math.sqrt(c*c+l*l),{delay:f=0,duration:d=(t=>120*Math.sqrt(t)),easing:p=ot}=n;return{delay:f,duration:a(d)?d(u):d,easing:p,css:(t,e)=>`transform: ${r} translate(${e*c}px, ${e*l}px);`}}const at=[];function ct(t,n=e){let o;const r=new Set;function s(e){if(c(t,e)&&(t=e,o)){const e=!at.length;for(const e of r)e[1](),at.push(e,t);if(e){for(let t=0;t<at.length;t+=2)at[t][0](at[t+1]);at.length=0}}}return{set:s,update:function(e){s(e(t))},subscribe:function(i,a=e){const c=[i,a];return r.add(c),1===r.size&&(o=n(s)||e),i(t),()=>{r.delete(c),0===r.size&&(o(),o=null)}}}}const lt={duration:4e3,dismissable:!0,initial:1,progress:0,reversed:!1,intro:{x:256},theme:{}},ut=(()=>{const{subscribe:t,update:e}=ct([]);let n=0;const o={},r=t=>t instanceof Object;return{subscribe:t,push:(t,s={})=>{const i={target:"default",...r(t)?t:{...s,msg:t}},a=o[i.target]||{},c={...lt,...a,...i,theme:{...a.theme,...i.theme},id:++n};return e((t=>c.reversed?[...t,c]:[c,...t])),n},pop:t=>{e((e=>{if(!e.length||0===t)return[];if(r(t))return e.filter((e=>t(e)));const n=t||Math.max(...e.map((t=>t.id)));return e.filter((t=>t.id!==n))}))},set:(t,n={})=>{const o=r(t)?{...t}:{...n,id:t};e((t=>{const e=t.findIndex((t=>t.id===o.id));return e>-1&&(t[e]={...t[e],...o}),t}))},_init:(t="default",e={})=>(o[t]=e,o)}})();function ft(t){return"[object Date]"===Object.prototype.toString.call(t)}function dt(t,e){if(t===e||t!=t)return()=>t;const n=typeof t;if(n!==typeof e||Array.isArray(t)!==Array.isArray(e))throw new Error("Cannot interpolate values of different type");if(Array.isArray(t)){const n=e.map(((e,n)=>dt(t[n],e)));return t=>n.map((e=>e(t)))}if("object"===n){if(!t||!e)throw new Error("Object cannot be null");if(ft(t)&&ft(e)){t=t.getTime();const n=(e=e.getTime())-t;return e=>new Date(t+e*n)}const n=Object.keys(e),o={};return n.forEach((n=>{o[n]=dt(t[n],e[n])})),t=>{const e={};return n.forEach((n=>{e[n]=o[n](t)})),e}}if("number"===n){const n=e-t;return e=>t+e*n}throw new Error(`Cannot interpolate ${n} values`)}function pt(t){v(t,"svelte-1r0vvz1","._toastItem.svelte-1r0vvz1{width:var(--toastWidth,16rem);height:var(--toastHeight,auto);min-height:var(--toastMinHeight,3.5rem);margin:var(--toastMargin,0 0 0.5rem 0);background:var(--toastBackground,rgba(66,66,66,0.9));color:var(--toastColor,#FFF);box-shadow:var(--toastBoxShadow,0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06));border-radius:var(--toastBorderRadius,0.125rem);position:relative;display:flex;flex-direction:row;align-items:center;will-change:transform,opacity;-webkit-tap-highlight-color:transparent}._toastMsg.svelte-1r0vvz1{padding:var(--toastMsgPadding,0.75rem 0.5rem);flex:1 1 0%}._toastMsg.svelte-1r0vvz1 a{pointer-events:auto}._toastBtn.svelte-1r0vvz1{width:2rem;height:100%;font:1rem sans-serif;display:flex;align-items:center;justify-content:center;cursor:pointer;outline:none;pointer-events:auto}._toastBar.svelte-1r0vvz1{display:block;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:none;position:absolute;bottom:0;width:100%;height:6px;background:transparent}._toastBar.svelte-1r0vvz1::-webkit-progress-bar{background:transparent}._toastBar.svelte-1r0vvz1::-webkit-progress-value{background:var(--toastProgressBackground,rgba(33,150,243,0.75))}._toastBar.svelte-1r0vvz1::-moz-progress-bar{background:var(--toastProgressBackground,rgba(33,150,243,0.75))}")}function gt(t){let n,o,r;return{c(){n=w("div"),n.textContent="✕",k(n,"class","_toastBtn svelte-1r0vvz1"),k(n,"role","button"),k(n,"tabindex","-1")},m(e,s){var i,a,c,l;$(e,n,s),o||(i=n,a="click",c=t[4],i.addEventListener(a,c,l),r=()=>i.removeEventListener(a,c,l),o=!0)},p:e,d(t){t&&_(n),o=!1,r()}}}function mt(t){let n,o,r,s,i,a=t[0].msg+"",c=t[0].dismissable&>(t);return{c(){n=w("div"),o=w("div"),r=x(),c&&c.c(),s=x(),i=w("progress"),k(o,"class","_toastMsg svelte-1r0vvz1"),k(i,"class","_toastBar svelte-1r0vvz1"),i.value=t[1],k(n,"class","_toastItem svelte-1r0vvz1")},m(t,e){$(t,n,e),h(n,o),o.innerHTML=a,h(n,r),c&&c.m(n,null),h(n,s),h(n,i)},p(t,[e]){1&e&&a!==(a=t[0].msg+"")&&(o.innerHTML=a),t[0].dismissable?c?c.p(t,e):(c=gt(t),c.c(),c.m(n,s)):c&&(c.d(1),c=null),2&e&&(i.value=t[1])},i:e,o:e,d(t){t&&_(n),c&&c.d()}}}function ht(t,e,r){let s,{item:i}=e;const a=function(t,e={}){const r=ct(t);let s,i=t;function a(a,c){if(null==t)return r.set(t=a),Promise.resolve();i=a;let l=s,u=!1,{delay:d=0,duration:p=400,easing:g=n,interpolate:h=dt}=o(o({},e),c);if(0===p)return l&&(l.abort(),l=null),r.set(t=i),Promise.resolve();const v=f()+d;let y;return s=m((e=>{if(e<v)return!0;u||(y=h(t,a),"function"==typeof p&&(p=p(t,a)),u=!0),l&&(l.abort(),l=null);const n=e-v;return n>p?(r.set(t=a),!1):(r.set(t=y(g(n/p))),!0)})),s.promise}return{set:a,update:(e,n)=>a(e(i,t),n),subscribe:r.subscribe}}(i.initial,{duration:i.duration,easing:n});l(t,a,(t=>r(1,s=t)));let c=i.initial;return t.$$set=t=>{"item"in t&&r(0,i=t.item)},t.$$.update=()=>{9&t.$$.dirty&&c!==i.progress&&(1===i.progress||0===i.progress?a.set(i.progress).then((()=>ut.pop(i.id))):a.set(i.progress),r(3,c=i.progress))},[i,s,a,c,()=>ut.pop(i.id)]}class vt extends nt{constructor(t){super(),et(this,t,ht,mt,c,{item:0},pt)}}function yt(t){v(t,"svelte-1wt6bln","ul.svelte-1wt6bln{top:var(--toastContainerTop,1.5rem);right:var(--toastContainerRight,2rem);bottom:var(--toastContainerBottom,auto);left:var(--toastContainerLeft,auto);position:fixed;margin:0;padding:0;list-style-type:none;pointer-events:none;z-index:9999}")}function bt(t,e,n){const o=t.slice();return o[5]=e[n],o}function $t(t,o){let r,s,c,l,u,d,p,g,v=e;return s=new vt({props:{item:o[5]}}),{key:t,first:null,c(){var t;r=w("li"),(t=s.$$.fragment)&&t.c(),c=x(),k(r,"style",l=o[1](o[5].theme)),this.first=r},m(t,e){$(t,r,e),Y(s,r,null),h(r,c),g=!0},p(t,e){o=t;const n={};1&e&&(n.item=o[5]),s.$set(n),(!g||1&e&&l!==(l=o[1](o[5].theme)))&&k(r,"style",l)},r(){p=r.getBoundingClientRect()},f(){!function(t){const e=getComputedStyle(t);if("absolute"!==e.position&&"fixed"!==e.position){const{width:n,height:o}=e,r=t.getBoundingClientRect();t.style.position="absolute",t.style.width=n,t.style.height=o,S(t,r)}}(r),v(),S(r,p)},a(){v(),v=function(t,o,r,s){if(!o)return e;const i=t.getBoundingClientRect();if(o.left===i.left&&o.right===i.right&&o.top===i.top&&o.bottom===i.bottom)return e;const{delay:a=0,duration:c=300,easing:l=n,start:u=f()+a,end:d=u+c,tick:p=e,css:g}=r(t,{from:o,to:i},s);let h,v=!0,y=!1;function b(){g&&M(t,h),v=!1}return m((t=>{if(!y&&t>=u&&(y=!0),y&&t>=d&&(p(1,0),b()),!v)return!1;if(y){const e=0+1*l((t-u)/c);p(e,1-e)}return!0})),g&&(h=B(t,0,1,c,a,l,g)),a||(y=!0),p(0,1),b}(r,p,it,{duration:200})},i(t){g||(Q(s.$$.fragment,t),L((()=>{d&&d.end(1),u=function(t,o,r){let s,i,c=o(t,r),l=!1,u=0;function d(){s&&M(t,s)}function p(){const{delay:o=0,duration:r=300,easing:a=n,tick:p=e,css:g}=c||V;g&&(s=B(t,0,1,r,o,a,g,u++)),p(0,1);const h=f()+o,v=h+r;i&&i.abort(),l=!0,L((()=>G(t,!0,"start"))),i=m((e=>{if(l){if(e>=v)return p(1,0),G(t,!0,"end"),d(),l=!1;if(e>=h){const t=a((e-h)/r);p(t,1-t)}}return l}))}let g=!1;return{start(){g||(g=!0,M(t),a(c)?(c=c(),W().then(p)):p())},invalidate(){g=!1},end(){l&&(d(),l=!1)}}}(r,st,o[5].intro),u.start()})),g=!0)},o(t){U(s.$$.fragment,t),u&&u.invalidate(),d=function(t,o,r){let s,c=o(t,r),l=!0;const u=K;function d(){const{delay:o=0,duration:r=300,easing:a=n,tick:d=e,css:p}=c||V;p&&(s=B(t,1,0,r,o,a,p));const g=f()+o,h=g+r;L((()=>G(t,!1,"start"))),m((e=>{if(l){if(e>=h)return d(0,1),G(t,!1,"end"),--u.r||i(u.c),!1;if(e>=g){const t=a((e-g)/r);d(1-t,t)}}return l}))}return u.r+=1,a(c)?W().then((()=>{c=c(),d()})):d(),{end(e){e&&c.tick&&c.tick(1,0),l&&(s&&M(t,s),l=!1)}}}(r,rt,{}),g=!1},d(t){t&&_(r),Z(s),t&&d&&d.end()}}}function _t(t){let e,n,o=[],r=new Map,s=t[0];const a=t=>t[5].id;for(let e=0;e<s.length;e+=1){let n=bt(t,s,e),i=a(n);r.set(i,o[e]=$t(i,n))}return{c(){e=w("ul");for(let t=0;t<o.length;t+=1)o[t].c();k(e,"class","svelte-1wt6bln")},m(t,r){$(t,e,r);for(let t=0;t<o.length;t+=1)o[t].m(e,null);n=!0},p(t,[n]){if(3&n){s=t[0],K={r:0,c:[],p:K};for(let t=0;t<o.length;t+=1)o[t].r();o=function(t,e,n,o,r,s,i,a,c,l,u,f){let d=t.length,p=s.length,g=d;const m={};for(;g--;)m[t[g].key]=g;const h=[],v=new Map,y=new Map;for(g=p;g--;){const t=f(r,s,g),a=n(t);let c=i.get(a);c?o&&c.p(t,e):(c=l(a,t),c.c()),v.set(a,h[g]=c),a in m&&y.set(a,Math.abs(g-m[a]))}const b=new Set,$=new Set;function _(t){Q(t,1),t.m(a,u),i.set(t.key,t),u=t.first,p--}for(;d&&p;){const e=h[p-1],n=t[d-1],o=e.key,r=n.key;e===n?(u=e.first,d--,p--):v.has(r)?!i.has(o)||b.has(o)?_(e):$.has(r)?d--:y.get(o)>y.get(r)?($.add(o),_(e)):(b.add(r),d--):(c(n,i),d--)}for(;d--;){const e=t[d];v.has(e.key)||c(e,i)}for(;p;)_(h[p-1]);return h}(o,n,a,1,t,s,r,e,X,$t,null,bt);for(let t=0;t<o.length;t+=1)o[t].a();K.r||i(K.c),K=K.p}},i(t){if(!n){for(let t=0;t<s.length;t+=1)Q(o[t]);n=!0}},o(t){for(let t=0;t<o.length;t+=1)U(o[t]);n=!1},d(t){t&&_(e);for(let t=0;t<o.length;t+=1)o[t].d()}}}function wt(t,e,n){let o;l(t,ut,(t=>n(4,o=t)));let r,{options:s={}}=e,{target:i="default"}=e;return t.$$set=t=>{"options"in t&&n(2,s=t.options),"target"in t&&n(3,i=t.target)},t.$$.update=()=>{12&t.$$.dirty&&ut._init(i,s),24&t.$$.dirty&&n(0,r=o.filter((t=>t.target===i)))},[r,t=>Object.keys(t).reduce(((e,n)=>`${e}${n}:${t[n]};`),""),s,i,o]}t.SvelteToast=class extends nt{constructor(t){super(),et(this,t,wt,_t,c,{options:2,target:3},yt)}},t.toast=ut,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@zerodevx/svelte-toast", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Simple elegant toast notifications", | ||
@@ -10,9 +10,2 @@ "author": "Jason Lee <jason@zerodevx.com>", | ||
"types": "src/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"scripts": { | ||
@@ -35,5 +28,5 @@ "start": "sirv docs --no-clear", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^19.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.2", | ||
"@typescript-eslint/eslint-plugin": "^4.28.4", | ||
"@rollup/plugin-commonjs": "^19.0.2", | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"@typescript-eslint/eslint-plugin": "^4.28.5", | ||
"autoprefixer": "^10.3.1", | ||
@@ -53,3 +46,3 @@ "camelcase": "^6.2.0", | ||
"prismjs": "^1.24.1", | ||
"rollup": "^2.53.3", | ||
"rollup": "^2.55.0", | ||
"rollup-plugin-livereload": "^2.0.5", | ||
@@ -59,3 +52,3 @@ "rollup-plugin-svelte": "^7.1.0", | ||
"sirv-cli": "^1.0.12", | ||
"svelte": "^3.40.2", | ||
"svelte": "^3.41.0", | ||
"tailwindcss": "^2.2.7", | ||
@@ -62,0 +55,0 @@ "typescript": "^4.3.5" |
136
README.md
@@ -109,69 +109,2 @@ [![npm (scoped)](https://img.shields.io/npm/v/@zerodevx/svelte-toast)](https://www.npmjs.com/package/@zerodevx/svelte-toast) | ||
### New from `v0.4` | ||
#### Supporting Multiple Toast Containers | ||
It's now easy to send toasts to different container targets within your app. For example: | ||
```html | ||
<script> | ||
import { SvelteToast, toast } from '@zerodevx/svelte-toast' | ||
// Sends a toast to default toast container | ||
toast.push('Yo!') | ||
// Sends a toast to "new" toast container | ||
toast.push('Hey!', { target: 'new' }) | ||
</script> | ||
<style> | ||
.wrap { | ||
--toastContainerTop: 0.5rem; | ||
--toastContainerRight: 2rem; | ||
--toastContainerBottom: auto; | ||
--toastContainerLeft: 2rem; | ||
--toastWidth: 100%; | ||
font-size: 0.875rem; | ||
... | ||
} | ||
</style> | ||
<!-- Default toast container --> | ||
<SvelteToast /> | ||
<!-- Another toast container --> | ||
<div class="wrap"> | ||
<!-- Declare container with a unique `target` name --> | ||
<SvelteToast target="new" options={{ duration: 8000, intro: { y: -64 } }} /> | ||
</div> | ||
``` | ||
#### Removing Multiple Toasts | ||
`pop()` now accepts a filter function. | ||
```js | ||
// Remove all toasts from "new" container | ||
toast.pop(i => i.target !== 'new') | ||
// Or remove ALL active toasts from ALL containers | ||
toast.pop(0) | ||
``` | ||
#### Accepts Object as First Param | ||
`push()` and `set()` can also take an object as its first parameter. | ||
```js | ||
let id = toast.push('Yo!', { duration: 2000 }) | ||
// is semantically equivalent to | ||
id = toast.push({ msg: 'Yo!', duration: 2000 }) | ||
toast.set(id, { msg: 'Waddup!' }) | ||
// is semantically equivalent to | ||
toast.set({ id, msg: 'Waddup!' }) | ||
``` | ||
## Theming | ||
@@ -309,2 +242,69 @@ | ||
### New from `v0.4` | ||
#### Supporting Multiple Toast Containers | ||
It's now easy to send toasts to different container targets within your app. For example: | ||
```html | ||
<script> | ||
import { SvelteToast, toast } from '@zerodevx/svelte-toast' | ||
// Sends a toast to default toast container | ||
toast.push('Yo!') | ||
// Sends a toast to "new" toast container | ||
toast.push('Hey!', { target: 'new' }) | ||
</script> | ||
<style> | ||
.wrap { | ||
--toastContainerTop: 0.5rem; | ||
--toastContainerRight: 2rem; | ||
--toastContainerBottom: auto; | ||
--toastContainerLeft: 2rem; | ||
--toastWidth: 100%; | ||
font-size: 0.875rem; | ||
... | ||
} | ||
</style> | ||
<!-- Default toast container --> | ||
<SvelteToast /> | ||
<!-- Another toast container --> | ||
<div class="wrap"> | ||
<!-- Declare container with a unique `target` name --> | ||
<SvelteToast target="new" options={{ duration: 8000, intro: { y: -64 } }} /> | ||
</div> | ||
``` | ||
#### Removing Multiple Toasts | ||
`pop()` now accepts a filter function. | ||
```js | ||
// Remove all toasts from "new" container | ||
toast.pop(i => i.target !== 'new') | ||
// Or remove ALL active toasts from ALL containers | ||
toast.pop(0) | ||
``` | ||
#### Accepts Object as First Param | ||
`push()` and `set()` can also take an object as its first parameter. | ||
```js | ||
let id = toast.push('Yo!', { duration: 2000 }) | ||
// is semantically equivalent to | ||
id = toast.push({ msg: 'Yo!', duration: 2000 }) | ||
toast.set(id, { msg: 'Waddup!' }) | ||
// is semantically equivalent to | ||
toast.set({ id, msg: 'Waddup!' }) | ||
``` | ||
## Options | ||
@@ -335,3 +335,3 @@ | ||
Standard Github [contributing workflow](https://gist.github.com/Chaser324/ce0505fbed06b947d962) applies. | ||
Standard Github [contribution workflow](https://gist.github.com/Chaser324/ce0505fbed06b947d962) applies. | ||
@@ -338,0 +338,0 @@ ### Tests |
@@ -22,9 +22,12 @@ // index.d.ts | ||
export interface SvelteToastOptions { | ||
duration: number | ||
dismissable: boolean | ||
initial: number | ||
progress: number | ||
reversed: boolean | ||
intro: FlyParams | ||
theme: { [key: string]: string } | ||
id?: number | ||
target?: string | ||
msg?: string | ||
duration?: number | ||
dismissable?: boolean | ||
initial?: number | ||
progress?: number | ||
reversed?: boolean | ||
intro?: FlyParams | ||
theme?: { [key: string]: string } | ||
} | ||
@@ -38,5 +41,7 @@ | ||
declare namespace toast { | ||
export function push (text: string, options?: SvelteToastOptions): number | ||
export function pop (id: number): void | ||
export function set (id: number, options: SvelteToastOptions): void | ||
export function push (msg: string, options?: SvelteToastOptions): number | ||
export function push (options: SvelteToastOptions): number | ||
export function pop (arg?: any): void | ||
export function set (id: number, options?: SvelteToastOptions): void | ||
export function set (options: SvelteToastOptions): void | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
208
0
46960