robot-toast 1.0.0 → 1.0.1-beta.1

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.js CHANGED
@@ -122,9 +122,10 @@
122
122
 
123
123
  .robot-toast-message {
124
124
  position: relative;
125
- min-width: 280px;
126
- max-width: 400px;
127
- padding: 14px 12px 0 12px;
125
+ width: fit-content;
126
+ min-width: 120px;
127
+ max-width: min(400px, calc(100vw - 120px));
128
+ padding: 14px 40px 0 14px;
128
129
  border-radius: 8px;
129
130
  margin: 0;
130
131
  opacity: 0;
@@ -133,6 +134,11 @@
133
134
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
134
135
  user-select: none;
135
136
  cursor: default;
137
+ box-sizing: border-box;
138
+ }
139
+
140
+ .robot-toast-message.robot-toast-empty {
141
+ display: none;
136
142
  }
137
143
 
138
144
  .robot-toast-message.robot-toast-theme-light {
@@ -269,13 +275,14 @@
269
275
  /* \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 */
270
276
 
271
277
  .robot-toast-text {
272
- padding-right: 24px;
273
278
  padding-bottom: 12px;
274
279
  font-size: 14px;
275
280
  line-height: 1.5;
276
281
  word-break: break-word;
277
282
  white-space: pre-wrap;
278
283
  font-weight: 500;
284
+ min-width: 0;
285
+ min-height: 1.5em;
279
286
  }
280
287
 
281
288
  /* \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 */
@@ -527,6 +534,71 @@
527
534
  from { opacity: 0; transform: perspective(400px) rotateX(-20deg); }
528
535
  to { opacity: 1; transform: perspective(400px) rotateX(0deg); }
529
536
  }
537
+
538
+ /* \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 */
539
+ /* RESPONSIVE - Mobile / small-screen tweaks */
540
+ /* \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 */
541
+
542
+ @media (max-width: 600px) {
543
+ .robot-toast-wrapper {
544
+ gap: 8px;
545
+ max-width: calc(100vw - 24px);
546
+ }
547
+
548
+ .robot-toast-wrapper.robot-toast-top-right,
549
+ .robot-toast-wrapper.robot-toast-bottom-right {
550
+ right: 12px;
551
+ }
552
+ .robot-toast-wrapper.robot-toast-top-left,
553
+ .robot-toast-wrapper.robot-toast-bottom-left {
554
+ left: 12px;
555
+ }
556
+ .robot-toast-wrapper.robot-toast-top-right,
557
+ .robot-toast-wrapper.robot-toast-top-left,
558
+ .robot-toast-wrapper.robot-toast-top-center { top: 12px; }
559
+ .robot-toast-wrapper.robot-toast-bottom-right,
560
+ .robot-toast-wrapper.robot-toast-bottom-left,
561
+ .robot-toast-wrapper.robot-toast-bottom-center { bottom: 12px; }
562
+
563
+ .robot-toast-wrapper.robot-toast-top-center,
564
+ .robot-toast-wrapper.robot-toast-bottom-center {
565
+ width: calc(100vw - 24px);
566
+ justify-content: center;
567
+ }
568
+
569
+ .robot-toast-robot {
570
+ width: 48px;
571
+ height: 52px;
572
+ }
573
+
574
+ .robot-toast-message {
575
+ min-width: 100px;
576
+ max-width: calc(100vw - 48px - 24px - 8px);
577
+ font-size: 13px;
578
+ padding: 12px 36px 0 12px;
579
+ }
580
+
581
+ .robot-toast-text {
582
+ font-size: 13px;
583
+ padding-bottom: 10px;
584
+ }
585
+
586
+ .robot-toast-close {
587
+ width: 24px;
588
+ height: 24px;
589
+ font-size: 20px;
590
+ }
591
+ }
592
+
593
+ @media (max-width: 360px) {
594
+ .robot-toast-robot {
595
+ width: 40px;
596
+ height: 44px;
597
+ }
598
+ .robot-toast-message {
599
+ max-width: calc(100vw - 40px - 20px - 8px);
600
+ }
601
+ }
530
602
  `,e=document.createElement("style");e.id=t,e.textContent=o,document.head.appendChild(e);}};m.injected=false;var k=m,A=k;function n(i){return `data:image/svg+xml;base64,${Buffer.from(i,"utf-8").toString("base64")}`}var l={wave:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100%" height="100%">
531
603
  <defs>
532
604
  <linearGradient id="roboGrad" x1="0" y1="0" x2="1" y2="1">
@@ -928,7 +1000,7 @@
928
1000
  <ellipse cx="72" cy="43" rx="4" ry="2" fill="#FF6B6B" opacity="0.5"/>
929
1001
 
930
1002
  <path d="M 46 44 Q 50 48, 54 44" fill="none" stroke="#2B3A55" stroke-width="3" stroke-linecap="round"/>
931
- </svg>`},u={wave:n(l.wave),base:n(l.base),base2:n(l.base2),success:n(l.success),error:n(l.error),angry:n(l.angry),angry2:n(l.angry2),shock:n(l.shock),think:n(l.think),search:n(l.search),loading:n(l.loading),sleep:n(l.sleep),"head-palm":n(l["head-palm"]),type:n(l.type),validation:n(l.validation),validation2:n(l.validation2)};var F=1;function E(){return F++}var L=16,y=class{constructor(t,o,e){this.progressBar=null;this.timerStart=null;this.closeTimeout=null;this.isDragging=false;this.dragOffsetX=0;this.dragOffsetY=0;this.isHovered=false;this.isFocusLost=false;this.isClosed=false;this.cleanupFns=[];this.id=t,this.onRemove=e;let s={message:o.message,autoClose:o.autoClose??5e3,position:o.position??"bottom-right",type:o.type??"default",theme:o.theme??"light",style:o.style,typeSpeed:o.typeSpeed??30,robotVariant:o.robotVariant??"",hideProgressBar:o.hideProgressBar??false,pauseOnFocusLoss:o.pauseOnFocusLoss??true,draggable:o.draggable??true,nearScreen:o.nearScreen??true,pauseOnHover:o.pauseOnHover??true,rtl:o.rtl??false,transition:o.transition??"bounce",onOpen:o.onOpen,onClose:o.onClose};this.options=s;let r=s.position.includes("left"),a;s.nearScreen?a=r?"left":"right":a=r?"right":"left",this.currentRobotSide=a,this.autoCloseDuration=typeof s.autoClose=="number"?s.autoClose:s.autoClose?5e3:0,this.remainingTime=this.autoCloseDuration,this.wrapper=this.buildWrapper(),this.robotEl=this.buildRobot(),this.messageBox=this.buildMessageBox(),this.messageText=this.messageBox.querySelector(".robot-toast-text"),this.progressBar=this.messageBox.querySelector(".robot-toast-progress-bar"),this.assembleLayout(),document.body.appendChild(this.wrapper),s.draggable&&this.initDrag(),s.pauseOnFocusLoss&&this.initFocusWatcher(),s.pauseOnHover&&this.initHoverWatcher(),requestAnimationFrame(()=>this.playEntrance());}close(){this.isClosed||(this.isClosed=true,this.cancelTimer(),this.cleanupFns.forEach(t=>t()),this.cleanupFns=[],this.playExit(()=>{this.wrapper.parentNode&&this.wrapper.parentNode.removeChild(this.wrapper),this.options.onClose?.(),this.onRemove(this.id);}));}shiftVertical(t){this.options.position.startsWith("bottom")?this.wrapper.style.bottom=`${t}px`:this.wrapper.style.top=`${t}px`;}getWrapperHeight(){return this.wrapper.getBoundingClientRect().height||90}buildWrapper(){let t=document.createElement("div"),o=["robot-toast-wrapper",`robot-toast-${this.options.position}`];return this.options.rtl&&o.push("robot-toast-rtl"),t.className=o.join(" "),t}buildRobot(){let t=document.createElement("div");t.className="robot-toast-robot";let o=this.options.robotVariant;if(o==="none")t.style.display="none";else if(o)if(o in u){let e=document.createElement("img");e.src=u[o],e.alt="Robot",e.setAttribute("width","65"),e.setAttribute("height","70"),e.style.cssText="width:100%;height:100%;object-fit:contain;display:block;",e.onerror=()=>{t.innerHTML=this.getBuiltinSVG();},t.appendChild(e);}else if(![".svg",".png",".jpg",".jpeg",".gif",".webp"].some(r=>o.toLowerCase().endsWith(r)))t.innerHTML=this.getBuiltinSVG();else {let r=document.createElement("img");r.src=o,r.alt="Robot",r.setAttribute("width","65"),r.setAttribute("height","70"),r.style.cssText="width:100%;height:100%;object-fit:contain;display:block;",r.onerror=()=>{t.innerHTML=this.getBuiltinSVG();},t.appendChild(r);}else t.innerHTML=this.getBuiltinSVG();return t}buildMessageBox(){let t=document.createElement("div"),o=["robot-toast-message",`robot-toast-type-${this.options.type}`,`robot-toast-theme-${this.options.theme}`].filter(Boolean);t.className=o.join(" "),t.style.cursor=this.options.draggable?"grab":"default",this.options.style&&Object.entries(this.options.style).forEach(([c,f])=>{let h=c.replace(/-([a-z])/g,x=>x[1].toUpperCase());t.style[h]=f;});let e=document.createElement("button");e.className="robot-toast-close",e.innerHTML="&times;",e.title="Dismiss",e.addEventListener("click",c=>{c.stopPropagation(),this.close();}),t.appendChild(e);let s=document.createElement("div");s.className="robot-toast-text",t.appendChild(s);let r=document.createElement("div");r.className="robot-toast-progress-container",this.options.hideProgressBar&&(r.style.display="none");let a=document.createElement("div");return a.className="robot-toast-progress-bar",r.appendChild(a),t.appendChild(r),t}assembleLayout(){let{rtl:t}=this.options;this.wrapper.innerHTML="",(t?this.currentRobotSide==="right":this.currentRobotSide==="left")?(this.wrapper.appendChild(this.robotEl),this.wrapper.appendChild(this.messageBox)):(this.wrapper.appendChild(this.messageBox),this.wrapper.appendChild(this.robotEl));}playEntrance(){this.wrapper.classList.add("robot-toast-visible");let t=this.options.robotVariant==="none",o=()=>{let e=this.options.transition==="bounce"?"message-enter":`message-enter-${this.options.transition}`;this.messageBox.classList.add(e);let s=()=>{this.messageBox.removeEventListener("animationend",s),this.messageBox.classList.remove(e),this.messageBox.style.opacity="1",this.messageBox.style.transform="none",this.options.onOpen?.(),this.startTyping();};this.messageBox.addEventListener("animationend",s,{once:true});};if(t)o();else {let e=this.currentRobotSide==="left"?"left":"right",s=this.options.transition!=="bounce"?`-${this.options.transition}`:"",r=`robot-enter-${e}${s}`;this.robotEl.classList.add(r);let a=()=>{this.robotEl.removeEventListener("animationend",a),this.robotEl.style.opacity="1",this.robotEl.classList.remove(r),this.robotEl.classList.add("robot-idle"),o();};this.robotEl.addEventListener("animationend",a,{once:true});}}playExit(t){let o=this.options.robotVariant==="none";this.messageBox.classList.add("message-exit");let e=()=>{if(this.messageBox.removeEventListener("animationend",e),o)this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);else {this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right");let s=this.currentRobotSide==="left"?"left":"right",r=this.options.transition!=="bounce"?`-${this.options.transition}`:"",a=`robot-exit-${s}${r}`;this.robotEl.classList.add(a);let c=()=>{this.robotEl.removeEventListener("animationend",c),this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);};this.robotEl.addEventListener("animationend",c,{once:true});}};this.messageBox.addEventListener("animationend",e,{once:true});}startTyping(){let{message:t,typeSpeed:o}=this.options,e=this.messageText;if(o===0){e.textContent=t,this.afterTypingComplete();return}let s=0,r=true;this.cleanupFns.push(()=>{r=false;});let a=()=>{r&&(s<t.length?(e.textContent+=t.charAt(s++),setTimeout(a,o)):this.afterTypingComplete());};a();}afterTypingComplete(){this.autoCloseDuration>0&&!this.options.hideProgressBar&&this.progressBar&&(this.progressBar.style.animationDuration=`${this.autoCloseDuration}ms`,this.progressBar.offsetWidth,this.progressBar.classList.add("robot-toast-progress-auto"),(this.isHovered||this.isFocusLost)&&this.progressBar.classList.add("robot-toast-progress-paused")),!this.isHovered&&!this.isFocusLost&&this.startTimer();}startTimer(){this.autoCloseDuration<=0||this.remainingTime<=0||(this.timerStart=Date.now(),this.closeTimeout=setTimeout(()=>this.close(),this.remainingTime));}pauseTimer(){if(this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null,this.timerStart!==null)){let t=Date.now()-this.timerStart;this.remainingTime=Math.max(0,this.remainingTime-t),this.timerStart=null;}this.progressBar?.classList.add("robot-toast-progress-paused");}resumeTimer(){this.isHovered||this.isFocusLost||this.isDragging||(this.progressBar?.classList.remove("robot-toast-progress-paused"),this.startTimer());}cancelTimer(){this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null);}initHoverWatcher(){let t=()=>{this.isHovered=true,this.pauseTimer();},o=()=>{this.isHovered=false,this.resumeTimer();};this.wrapper.addEventListener("mouseenter",t),this.wrapper.addEventListener("mouseleave",o),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("mouseenter",t),this.wrapper.removeEventListener("mouseleave",o);});}initFocusWatcher(){let t=()=>{this.isFocusLost=true,this.pauseTimer();},o=()=>{this.isFocusLost=false,this.resumeTimer();};window.addEventListener("blur",t),window.addEventListener("focus",o),this.cleanupFns.push(()=>{window.removeEventListener("blur",t),window.removeEventListener("focus",o);});}initDrag(){this.messageBox.style.cursor="grab";let t=s=>{if(s.target.closest(".robot-toast-close")||s.button!==void 0&&s.button!==0)return;s.preventDefault(),this.isDragging=true,this.pauseTimer();let r=this.wrapper.getBoundingClientRect();this.wrapper.classList.add("robot-toast-dragging"),this.wrapper.style.top=`${r.top}px`,this.wrapper.style.left=`${r.left}px`,this.wrapper.style.right="auto",this.wrapper.style.bottom="auto",this.wrapper.style.transform="none",this.dragOffsetX=s.clientX-r.left,this.dragOffsetY=s.clientY-r.top,this.messageBox.style.cursor="grabbing",this.wrapper.setPointerCapture(s.pointerId);},o=s=>{if(!this.isDragging)return;s.preventDefault();let r=this.wrapper.getBoundingClientRect(),a=window.innerWidth-r.width,c=window.innerHeight-r.height,f=Math.max(0,Math.min(s.clientX-this.dragOffsetX,a)),h=Math.max(0,Math.min(s.clientY-this.dragOffsetY,c));this.wrapper.style.left=`${f}px`,this.wrapper.style.top=`${h}px`;},e=s=>{if(!this.isDragging)return;this.isDragging=false,this.wrapper.classList.remove("robot-toast-dragging"),this.messageBox.style.cursor="grab";let r=this.wrapper.getBoundingClientRect(),a=r.left+r.width/2,c=window.innerWidth/2,f=a<c,h=this.options.nearScreen?f?"left":"right":f?"right":"left",x=f?20:window.innerWidth-r.width-20,T=Math.max(20,Math.min(r.top,window.innerHeight-r.height-20));if(this.wrapper.style.transition="left 0.45s cubic-bezier(0.34,1.56,0.64,1), top 0.4s cubic-bezier(0.34,1.56,0.64,1)",this.wrapper.style.left=`${x}px`,this.wrapper.style.top=`${T}px`,h!==this.currentRobotSide){this.currentRobotSide=h;let B=h==="left";this.robotEl.style.order=B?"0":"1",this.messageBox.style.order=B?"1":"0";let v=h==="left"?"robot-snap-left":"robot-snap-right";this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right"),this.robotEl.classList.add(v),this.robotEl.addEventListener("animationend",()=>{this.robotEl.style.opacity="1",this.robotEl.classList.remove(v),this.robotEl.classList.add("robot-idle");},{once:true});}setTimeout(()=>{this.wrapper.style.transition="";},500),this.resumeTimer();};this.wrapper.addEventListener("pointerdown",t),this.wrapper.addEventListener("pointermove",o),this.wrapper.addEventListener("pointerup",e),this.wrapper.addEventListener("pointercancel",e),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("pointerdown",t),this.wrapper.removeEventListener("pointermove",o),this.wrapper.removeEventListener("pointerup",e),this.wrapper.removeEventListener("pointercancel",e);});}getBuiltinSVG(){return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 120"
1003
+ </svg>`},w={wave:n(l.wave),base:n(l.base),base2:n(l.base2),success:n(l.success),error:n(l.error),angry:n(l.angry),angry2:n(l.angry2),shock:n(l.shock),think:n(l.think),search:n(l.search),loading:n(l.loading),sleep:n(l.sleep),"head-palm":n(l["head-palm"]),type:n(l.type),validation:n(l.validation),validation2:n(l.validation2)};var F=1;function E(){return F++}var L=16,y=class{constructor(t,o,e){this.progressBar=null;this.timerStart=null;this.closeTimeout=null;this.isDragging=false;this.dragOffsetX=0;this.dragOffsetY=0;this.isHovered=false;this.isFocusLost=false;this.isClosed=false;this.cleanupFns=[];this.id=t,this.onRemove=e;let r={message:o.message,autoClose:o.autoClose??5e3,position:o.position??"bottom-right",type:o.type??"default",theme:o.theme??"light",style:o.style,typeSpeed:o.typeSpeed??30,robotVariant:o.robotVariant??"",hideProgressBar:o.hideProgressBar??false,pauseOnFocusLoss:o.pauseOnFocusLoss??true,draggable:o.draggable??true,nearScreen:o.nearScreen??true,pauseOnHover:o.pauseOnHover??true,rtl:o.rtl??false,transition:o.transition??"bounce",onOpen:o.onOpen,onClose:o.onClose};this.options=r;let s=r.position.includes("left"),a;r.nearScreen?a=s?"left":"right":a=s?"right":"left",this.currentRobotSide=a,this.autoCloseDuration=typeof r.autoClose=="number"?r.autoClose:r.autoClose?5e3:0,this.remainingTime=this.autoCloseDuration,this.wrapper=this.buildWrapper(),this.robotEl=this.buildRobot(),this.messageBox=this.buildMessageBox(),this.messageText=this.messageBox.querySelector(".robot-toast-text"),this.progressBar=this.messageBox.querySelector(".robot-toast-progress-bar"),r.message===""&&this.messageBox.classList.add("robot-toast-empty"),this.assembleLayout(),document.body.appendChild(this.wrapper),r.draggable&&this.initDrag(),r.pauseOnFocusLoss&&this.initFocusWatcher(),r.pauseOnHover&&this.initHoverWatcher(),requestAnimationFrame(()=>this.playEntrance());}close(){this.isClosed||(this.isClosed=true,this.cancelTimer(),this.cleanupFns.forEach(t=>t()),this.cleanupFns=[],this.playExit(()=>{this.wrapper.parentNode&&this.wrapper.parentNode.removeChild(this.wrapper),this.options.onClose?.(),this.onRemove(this.id);}));}shiftVertical(t){this.options.position.startsWith("bottom")?this.wrapper.style.bottom=`${t}px`:this.wrapper.style.top=`${t}px`;}getWrapperHeight(){return this.wrapper.getBoundingClientRect().height||90}buildWrapper(){let t=document.createElement("div"),o=["robot-toast-wrapper",`robot-toast-${this.options.position}`];return this.options.rtl&&o.push("robot-toast-rtl"),t.className=o.join(" "),t}buildRobot(){let t=document.createElement("div");t.className="robot-toast-robot";let o=this.options.robotVariant;if(o==="none")t.style.display="none";else if(o)if(o in w){let e=document.createElement("img");e.src=w[o],e.alt="Robot",e.setAttribute("width","65"),e.setAttribute("height","70"),e.style.cssText="width:100%;height:100%;object-fit:contain;display:block;",e.onerror=()=>{t.innerHTML=this.getBuiltinSVG();},t.appendChild(e);}else if(![".svg",".png",".jpg",".jpeg",".gif",".webp"].some(s=>o.toLowerCase().endsWith(s)))t.innerHTML=this.getBuiltinSVG();else {let s=document.createElement("img");s.src=o,s.alt="Robot",s.setAttribute("width","65"),s.setAttribute("height","70"),s.style.cssText="width:100%;height:100%;object-fit:contain;display:block;",s.onerror=()=>{t.innerHTML=this.getBuiltinSVG();},t.appendChild(s);}else t.innerHTML=this.getBuiltinSVG();return t}buildMessageBox(){let t=document.createElement("div"),o=["robot-toast-message",`robot-toast-type-${this.options.type}`,`robot-toast-theme-${this.options.theme}`].filter(Boolean);t.className=o.join(" "),t.style.cursor=this.options.draggable?"grab":"default",this.options.style&&Object.entries(this.options.style).forEach(([d,c])=>{let f=d.replace(/-([a-z])/g,x=>x[1].toUpperCase());t.style[f]=c;});let e=document.createElement("button");e.className="robot-toast-close",e.innerHTML="&times;",e.title="Dismiss",e.addEventListener("click",d=>{d.stopPropagation(),this.close();}),t.appendChild(e);let r=document.createElement("div");r.className="robot-toast-text",t.appendChild(r);let s=document.createElement("div");s.className="robot-toast-progress-container",this.options.hideProgressBar&&(s.style.display="none");let a=document.createElement("div");return a.className="robot-toast-progress-bar",s.appendChild(a),t.appendChild(s),t}assembleLayout(){let{rtl:t}=this.options;this.wrapper.innerHTML="",(t?this.currentRobotSide==="right":this.currentRobotSide==="left")?(this.wrapper.appendChild(this.robotEl),this.wrapper.appendChild(this.messageBox)):(this.wrapper.appendChild(this.messageBox),this.wrapper.appendChild(this.robotEl));}playEntrance(){this.wrapper.classList.add("robot-toast-visible");let t=this.options.robotVariant==="none",o=this.options.message==="",e=()=>{if(o){this.options.onOpen?.(),this.afterTypingComplete();return}let r=this.options.transition==="bounce"?"message-enter":`message-enter-${this.options.transition}`;this.messageBox.classList.add(r);let s=()=>{this.messageBox.removeEventListener("animationend",s),this.messageBox.classList.remove(r),this.messageBox.style.opacity="1",this.messageBox.style.transform="none",this.options.onOpen?.(),this.startTyping();};this.messageBox.addEventListener("animationend",s,{once:true});};if(t)e();else {let r=this.currentRobotSide==="left"?"left":"right",s=this.options.transition!=="bounce"?`-${this.options.transition}`:"",a=`robot-enter-${r}${s}`;this.robotEl.classList.add(a);let d=()=>{this.robotEl.removeEventListener("animationend",d),this.robotEl.style.opacity="1",this.robotEl.classList.remove(a),this.robotEl.classList.add("robot-idle"),e();};this.robotEl.addEventListener("animationend",d,{once:true});}}playExit(t){let o=this.options.robotVariant==="none",e=this.options.message==="",r=()=>{if(this.messageBox.removeEventListener("animationend",r),o)this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);else {this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right");let s=this.currentRobotSide==="left"?"left":"right",a=this.options.transition!=="bounce"?`-${this.options.transition}`:"",d=`robot-exit-${s}${a}`;this.robotEl.classList.add(d);let c=()=>{this.robotEl.removeEventListener("animationend",c),this.wrapper.classList.remove("robot-toast-visible"),setTimeout(t,260);};this.robotEl.addEventListener("animationend",c,{once:true});}};e?r():(this.messageBox.classList.add("message-exit"),this.messageBox.addEventListener("animationend",r,{once:true}));}startTyping(){let{message:t,typeSpeed:o}=this.options,e=this.messageText;if(o===0){e.textContent=t,this.afterTypingComplete();return}let r=0,s=true;this.cleanupFns.push(()=>{s=false;});let a=()=>{s&&(r<t.length?(e.textContent+=t.charAt(r++),setTimeout(a,o)):this.afterTypingComplete());};a();}afterTypingComplete(){this.autoCloseDuration>0&&!this.options.hideProgressBar&&this.progressBar&&(this.progressBar.style.animationDuration=`${this.autoCloseDuration}ms`,this.progressBar.offsetWidth,this.progressBar.classList.add("robot-toast-progress-auto"),(this.isHovered||this.isFocusLost)&&this.progressBar.classList.add("robot-toast-progress-paused")),!this.isHovered&&!this.isFocusLost&&this.startTimer();}startTimer(){this.autoCloseDuration<=0||this.remainingTime<=0||(this.timerStart=Date.now(),this.closeTimeout=setTimeout(()=>this.close(),this.remainingTime));}pauseTimer(){if(this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null,this.timerStart!==null)){let t=Date.now()-this.timerStart;this.remainingTime=Math.max(0,this.remainingTime-t),this.timerStart=null;}this.progressBar?.classList.add("robot-toast-progress-paused");}resumeTimer(){this.isHovered||this.isFocusLost||this.isDragging||(this.progressBar?.classList.remove("robot-toast-progress-paused"),this.startTimer());}cancelTimer(){this.closeTimeout&&(clearTimeout(this.closeTimeout),this.closeTimeout=null);}initHoverWatcher(){let t=()=>{this.isHovered=true,this.pauseTimer();},o=()=>{this.isHovered=false,this.resumeTimer();};this.wrapper.addEventListener("mouseenter",t),this.wrapper.addEventListener("mouseleave",o),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("mouseenter",t),this.wrapper.removeEventListener("mouseleave",o);});}initFocusWatcher(){let t=()=>{this.isFocusLost=true,this.pauseTimer();},o=()=>{this.isFocusLost=false,this.resumeTimer();};window.addEventListener("blur",t),window.addEventListener("focus",o),this.cleanupFns.push(()=>{window.removeEventListener("blur",t),window.removeEventListener("focus",o);});}initDrag(){this.messageBox.style.cursor="grab";let t=r=>{if(r.target.closest(".robot-toast-close")||r.button!==void 0&&r.button!==0)return;r.preventDefault(),this.isDragging=true,this.pauseTimer();let s=this.wrapper.getBoundingClientRect();this.wrapper.classList.add("robot-toast-dragging"),this.wrapper.style.top=`${s.top}px`,this.wrapper.style.left=`${s.left}px`,this.wrapper.style.right="auto",this.wrapper.style.bottom="auto",this.wrapper.style.transform="none",this.dragOffsetX=r.clientX-s.left,this.dragOffsetY=r.clientY-s.top,this.messageBox.style.cursor="grabbing",this.wrapper.setPointerCapture(r.pointerId);},o=r=>{if(!this.isDragging)return;r.preventDefault();let s=this.wrapper.getBoundingClientRect(),a=window.innerWidth-s.width,d=window.innerHeight-s.height,c=Math.max(0,Math.min(r.clientX-this.dragOffsetX,a)),f=Math.max(0,Math.min(r.clientY-this.dragOffsetY,d));this.wrapper.style.left=`${c}px`,this.wrapper.style.top=`${f}px`;},e=r=>{if(!this.isDragging)return;this.isDragging=false,this.wrapper.classList.remove("robot-toast-dragging"),this.messageBox.style.cursor="grab";let s=this.wrapper.getBoundingClientRect(),a=s.left+s.width/2,d=window.innerWidth/2,c=a<d,f=this.options.nearScreen?c?"left":"right":c?"right":"left",x=c?20:window.innerWidth-s.width-20,T=Math.max(20,Math.min(s.top,window.innerHeight-s.height-20));if(this.wrapper.style.transition="left 0.45s cubic-bezier(0.34,1.56,0.64,1), top 0.4s cubic-bezier(0.34,1.56,0.64,1)",this.wrapper.style.left=`${x}px`,this.wrapper.style.top=`${T}px`,f!==this.currentRobotSide){this.currentRobotSide=f;let B=f==="left";this.robotEl.style.order=B?"0":"1",this.messageBox.style.order=B?"1":"0";let v=f==="left"?"robot-snap-left":"robot-snap-right";this.robotEl.classList.remove("robot-idle","robot-snap-left","robot-snap-right"),this.robotEl.classList.add(v),this.robotEl.addEventListener("animationend",()=>{this.robotEl.style.opacity="1",this.robotEl.classList.remove(v),this.robotEl.classList.add("robot-idle");},{once:true});}setTimeout(()=>{this.wrapper.style.transition="";},500),this.resumeTimer();};this.wrapper.addEventListener("pointerdown",t),this.wrapper.addEventListener("pointermove",o),this.wrapper.addEventListener("pointerup",e),this.wrapper.addEventListener("pointercancel",e),this.cleanupFns.push(()=>{this.wrapper.removeEventListener("pointerdown",t),this.wrapper.removeEventListener("pointermove",o),this.wrapper.removeEventListener("pointerup",e),this.wrapper.removeEventListener("pointercancel",e);});}getBuiltinSVG(){return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 120"
932
1004
  width="100%" height="100%" role="img" aria-label="Robot">
933
1005
  <defs>
934
1006
  <linearGradient id="rtGrad${this.id}" x1="0" y1="0" x2="1" y2="1">
@@ -976,5 +1048,5 @@
976
1048
  fill="url(#rtAccent${this.id})" stroke="#2B3A55" stroke-width="1.5"/>
977
1049
  <rect x="54" y="110" width="16" height="10" rx="5"
978
1050
  fill="url(#rtAccent${this.id})" stroke="#2B3A55" stroke-width="1.5"/>
979
- </svg>`}},b=class b{constructor(){this.activeToasts=[];this.queue=[];this.globalLimit=0;new A;}static getInstance(){return b._instance||(b._instance=new b),b._instance}show(t){if(typeof document>"u")return -1;let o=E(),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 y(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;});});}};b._instance=null;var d=b;function w(i=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>=i&&(clearInterval(s),o(new Error(`[RobotToast] Failed to load within ${i}ms.`)));},80);})}async function M(i){try{return (await w()).show(i)}catch(t){return console.error("[RobotToast] showRobotToast failed:",t),-1}}async function R(){try{(await w()).closeAll();}catch(i){console.error("[RobotToast] closeAllRobotToasts failed:",i);}}async function G(){return w()}var O=["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center"],S=["default","info","success","warning","error"],C=["light","dark","colored"],I=["bounce","slide","zoom","flip"];function g(i){return typeof i=="string"?{message:i}:i}function p(i){return typeof window>"u"?-1:d.getInstance().show(g(i))}p.success=i=>p({...g(i),type:"success"});p.error=i=>p({...g(i),type:"error"});p.info=i=>p({...g(i),type:"info"});p.warning=i=>p({...g(i),type:"warning"});p.closeAll=()=>{typeof window>"u"||d.getInstance().closeAll();};p.closeById=i=>{typeof window>"u"||d.getInstance().closeById(i);};function D(){if(typeof window>"u"||window.__robotToastLoaded)return;window.__robotToastLoaded=true;let i={show:t=>d.getInstance().show(t),closeAll:()=>d.getInstance().closeAll(),closeById:t=>d.getInstance().closeById(t),getInstance:()=>d.getInstance()};window.RobotToast=i;}D();exports.ROBOT_IMAGES=u;exports.RobotToast=d;exports.RobotToastManager=d;exports.TOAST_POSITIONS=O;exports.TOAST_THEMES=C;exports.TOAST_TRANSITIONS=I;exports.TOAST_TYPES=S;exports.closeAllRobotToasts=R;exports.ensureRobotToastReady=w;exports.getRobotToastInstance=G;exports.showRobotToast=M;exports.toast=p;//# sourceMappingURL=index.js.map
1051
+ </svg>`}},b=class b{constructor(){this.activeToasts=[];this.queue=[];this.globalLimit=0;new A;}static getInstance(){return b._instance||(b._instance=new b),b._instance}show(t){if(typeof document>"u")return -1;let o=E(),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 y(o,t,s=>this.handleRemoved(s));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],r=20;e.forEach(s=>{s.shiftVertical(r),r+=s.getWrapperHeight()+L;});});}};b._instance=null;var p=b;function u(i=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(),r=setInterval(()=>{if(window.RobotToast){clearInterval(r),t(window.RobotToast);return}Date.now()-e>=i&&(clearInterval(r),o(new Error(`[RobotToast] Failed to load within ${i}ms.`)));},80);})}async function M(i){try{return (await u()).show(i)}catch(t){return console.error("[RobotToast] showRobotToast failed:",t),-1}}async function R(){try{(await u()).closeAll();}catch(i){console.error("[RobotToast] closeAllRobotToasts failed:",i);}}async function G(){return u()}var O=["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center"],S=["default","info","success","warning","error"],C=["light","dark","colored"],I=["bounce","slide","zoom","flip"];function g(i){return typeof i=="string"?{message:i}:i}function h(i){return typeof window>"u"?-1:p.getInstance().show(g(i))}h.success=i=>h({...g(i),type:"success"});h.error=i=>h({...g(i),type:"error"});h.info=i=>h({...g(i),type:"info"});h.warning=i=>h({...g(i),type:"warning"});h.closeAll=()=>{typeof window>"u"||p.getInstance().closeAll();};h.closeById=i=>{typeof window>"u"||p.getInstance().closeById(i);};function D(){if(typeof window>"u"||window.__robotToastLoaded)return;window.__robotToastLoaded=true;let i={show:t=>p.getInstance().show(t),closeAll:()=>p.getInstance().closeAll(),closeById:t=>p.getInstance().closeById(t),getInstance:()=>p.getInstance()};window.RobotToast=i;}D();exports.ROBOT_IMAGES=w;exports.RobotToast=p;exports.RobotToastManager=p;exports.TOAST_POSITIONS=O;exports.TOAST_THEMES=C;exports.TOAST_TRANSITIONS=I;exports.TOAST_TYPES=S;exports.closeAllRobotToasts=R;exports.ensureRobotToastReady=u;exports.getRobotToastInstance=G;exports.showRobotToast=M;exports.toast=h;//# sourceMappingURL=index.js.map
980
1052
  //# sourceMappingURL=index.js.map