robot-toast 2.1.7 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -234,21 +234,30 @@ var f=class f{constructor(){typeof document>"u"||f.injected||(f.injected=true,th
234
234
  /* CLOSE BUTTON */
235
235
  /* \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 */
236
236
 
237
+ /*
238
+ * Close button: 28x28 click target anchored at the message-box corner,
239
+ * but the SVG icon is aligned to the TOP-RIGHT of that target (not centered).
240
+ * Centering the SVG put the visible \xD7 ~14px from the corner, which on short
241
+ * single-line toasts looked like it was "in the middle" of the toast. Aligning
242
+ * to the corner with a small padding keeps the icon visually pinned to the
243
+ * top-right regardless of toast height, while preserving a comfortable hit zone.
244
+ */
237
245
  .robot-toast-close {
238
246
  position: absolute;
239
- top: 4px;
240
- right: 4px;
247
+ top: 0;
248
+ right: 0;
241
249
  background: none;
242
250
  border: none;
243
251
  cursor: pointer;
244
252
  opacity: 0.6;
245
253
  transition: opacity 0.2s;
246
- padding: 0;
247
254
  width: 28px;
248
255
  height: 28px;
249
256
  display: flex;
250
- align-items: center;
251
- justify-content: center;
257
+ align-items: flex-start;
258
+ justify-content: flex-end;
259
+ padding: 6px 6px 0 0;
260
+ box-sizing: border-box;
252
261
  color: currentColor;
253
262
  line-height: 0;
254
263
  }
@@ -741,6 +750,7 @@ var f=class f{constructor(){typeof document>"u"||f.injected||(f.injected=true,th
741
750
  .robot-toast-close {
742
751
  width: 24px;
743
752
  height: 24px;
753
+ padding: 5px 5px 0 0;
744
754
  }
745
755
  .robot-toast-close svg {
746
756
  width: 11px;
@@ -805,5 +815,5 @@ var f=class f{constructor(){typeof document>"u"||f.injected||(f.injected=true,th
805
815
  fill="url(#rtAccent${this.id})" stroke="#2B3A55" stroke-width="1.5"/>
806
816
  <rect x="54" y="110" width="16" height="10" rx="5"
807
817
  fill="url(#rtAccent${this.id})" stroke="#2B3A55" stroke-width="1.5"/>
808
- </svg>`}},h=class h{constructor(){this.activeToasts=[];this.queue=[];this.globalLimit=0;new k;}static getInstance(){return h._instance||(h._instance=new h),h._instance}show(t){if(typeof document>"u")return -1;let o=R(),e=t.limit??this.globalLimit;return e>0&&this.activeToasts.length>=e?(this.queue.push({options:t,id:o}),o):(this.spawnToast(t,o),o)}closeAll(){this.queue=[],[...this.activeToasts].forEach(t=>t.close());}closeById(t){let o=this.activeToasts.find(e=>e.id===t);o&&o.close(),this.queue=this.queue.filter(e=>e.id!==t);}spawnToast(t,o){let e=new x(o,t,r=>this.handleRemoved(r));t.newestOnTop??false?this.activeToasts.unshift(e):this.activeToasts.push(e),this.restack();}handleRemoved(t){if(this.activeToasts=this.activeToasts.filter(o=>o.id!==t),this.restack(),this.queue.length>0){let o=this.queue.shift();setTimeout(()=>this.spawnToast(o.options,o.id),120);}}restack(){let t={};this.activeToasts.forEach(o=>{let e=o.options.position;t[e]||(t[e]=[]),t[e].push(o);}),Object.keys(t).forEach(o=>{let e=t[o],s=20;e.forEach(r=>{r.shiftVertical(s),s+=r.getWrapperHeight()+L;});});}};h._instance=null;var c=h;function g(a=5e3){return new Promise((t,o)=>{if(typeof window>"u"){o(new Error("[RobotToast] Cannot run outside of a browser environment."));return}if(window.RobotToast){t(window.RobotToast);return}let e=Date.now(),s=setInterval(()=>{if(window.RobotToast){clearInterval(s),t(window.RobotToast);return}Date.now()-e>=a&&(clearInterval(s),o(new Error(`[RobotToast] Failed to load within ${a}ms.`)));},80);})}async function O(a){try{return (await g()).show(a)}catch(t){return console.error("[RobotToast] showRobotToast failed:",t),-1}}async function S(){try{(await g()).closeAll();}catch(a){console.error("[RobotToast] closeAllRobotToasts failed:",a);}}async function A(){return g()}var I=["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center"],C=["default","info","success","warning","error"],P=["light","dark","colored"],Y=["bounce","slide","zoom","flip"];function u(a){return typeof a=="string"?{message:a}:a}function n(a){return typeof window>"u"?-1:c.getInstance().show(u(a))}n.success=a=>n({...u(a),type:"success"});n.error=a=>n({...u(a),type:"error"});n.info=a=>n({...u(a),type:"info"});n.warning=a=>n({...u(a),type:"warning"});n.closeAll=()=>{typeof window>"u"||c.getInstance().closeAll();};n.closeById=a=>{typeof window>"u"||c.getInstance().closeById(a);};n.promise=(a,t)=>{if(typeof window>"u")return a;let o=typeof t.loading=="string"?{message:t.loading}:{message:"",...t.loading},e=n({autoClose:false,hideProgressBar:true,...o,typeSpeed:o.typeSpeed??0}),s=(r,i)=>{let p=typeof r=="string"?{message:r}:{message:"",...r};return {type:i,...p}};return a.then(r=>{n.closeById(e);let i=typeof t.success=="function"?t.success(r):t.success;return n(s(i,"success")),r},r=>{n.closeById(e);let i=typeof t.error=="function"?t.error(r):t.error;throw n(s(i,"error")),r})};function N(){if(typeof window>"u"||window.__robotToastLoaded)return;window.__robotToastLoaded=true;let a={show:t=>c.getInstance().show(t),closeAll:()=>c.getInstance().closeAll(),closeById:t=>c.getInstance().closeById(t),getInstance:()=>c.getInstance()};window.RobotToast=a;}N();export{c as RobotToast,c as RobotToastManager,I as TOAST_POSITIONS,P as TOAST_THEMES,Y as TOAST_TRANSITIONS,C as TOAST_TYPES,S as closeAllRobotToasts,g as ensureRobotToastReady,A as getRobotToastInstance,O as showRobotToast,n as toast};//# sourceMappingURL=index.mjs.map
818
+ </svg>`}},h=class h{constructor(){this.activeToasts=[];this.queue=[];this.globalLimit=0;new k;}static getInstance(){return h._instance||(h._instance=new h),h._instance}show(t){if(typeof document>"u")return -1;let o=R(),e=t.limit??this.globalLimit;return e>0&&this.activeToasts.length>=e?(this.queue.push({options:t,id:o}),o):(this.spawnToast(t,o),o)}closeAll(){this.queue=[],[...this.activeToasts].forEach(t=>t.close());}closeById(t){let o=this.activeToasts.find(e=>e.id===t);o&&o.close(),this.queue=this.queue.filter(e=>e.id!==t);}spawnToast(t,o){let e=new x(o,t,r=>this.handleRemoved(r));t.newestOnTop??false?this.activeToasts.unshift(e):this.activeToasts.push(e),this.restack();}handleRemoved(t){if(this.activeToasts=this.activeToasts.filter(o=>o.id!==t),this.restack(),this.queue.length>0){let o=this.queue.shift();setTimeout(()=>this.spawnToast(o.options,o.id),120);}}restack(){let t={};this.activeToasts.forEach(o=>{let e=o.options.position;t[e]||(t[e]=[]),t[e].push(o);}),Object.keys(t).forEach(o=>{let e=t[o],s=20;e.forEach(r=>{r.shiftVertical(s),s+=r.getWrapperHeight()+L;});});}};h._instance=null;var c=h;function u(a=5e3){return new Promise((t,o)=>{if(typeof window>"u"){o(new Error("[RobotToast] Cannot run outside of a browser environment."));return}if(window.RobotToast){t(window.RobotToast);return}let e=Date.now(),s=setInterval(()=>{if(window.RobotToast){clearInterval(s),t(window.RobotToast);return}Date.now()-e>=a&&(clearInterval(s),o(new Error(`[RobotToast] Failed to load within ${a}ms.`)));},80);})}async function O(a){try{return (await u()).show(a)}catch(t){return console.error("[RobotToast] showRobotToast failed:",t),-1}}async function S(){try{(await u()).closeAll();}catch(a){console.error("[RobotToast] closeAllRobotToasts failed:",a);}}async function A(){return u()}var I=["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center"],C=["default","info","success","warning","error"],P=["light","dark","colored"],Y=["bounce","slide","zoom","flip"];function g(a){return typeof a=="string"?{message:a}:a}function n(a){return typeof window>"u"?-1:c.getInstance().show(g(a))}n.success=a=>n({...g(a),type:"success"});n.error=a=>n({...g(a),type:"error"});n.info=a=>n({...g(a),type:"info"});n.warning=a=>n({...g(a),type:"warning"});n.closeAll=()=>{typeof window>"u"||c.getInstance().closeAll();};n.closeById=a=>{typeof window>"u"||c.getInstance().closeById(a);};n.promise=(a,t)=>{if(typeof window>"u")return a;let o=typeof t.loading=="string"?{message:t.loading}:{message:"",...t.loading},e=n({autoClose:false,hideProgressBar:true,...o,typeSpeed:o.typeSpeed??0}),s=(r,i)=>{let p=typeof r=="string"?{message:r}:{message:"",...r};return {type:i,...p}};return a.then(r=>{n.closeById(e);let i=typeof t.success=="function"?t.success(r):t.success;return n(s(i,"success")),r},r=>{n.closeById(e);let i=typeof t.error=="function"?t.error(r):t.error;throw n(s(i,"error")),r})};function N(){if(typeof window>"u"||window.__robotToastLoaded)return;window.__robotToastLoaded=true;let a={show:t=>c.getInstance().show(t),closeAll:()=>c.getInstance().closeAll(),closeById:t=>c.getInstance().closeById(t),getInstance:()=>c.getInstance()};window.RobotToast=a;}N();export{c as RobotToast,c as RobotToastManager,I as TOAST_POSITIONS,P as TOAST_THEMES,Y as TOAST_TRANSITIONS,C as TOAST_TYPES,S as closeAllRobotToasts,u as ensureRobotToastReady,A as getRobotToastInstance,O as showRobotToast,n as toast};//# sourceMappingURL=index.mjs.map
809
819
  //# sourceMappingURL=index.mjs.map