@supportwire/messenger-js-sdk 1.0.26 → 1.0.27
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-bfV4xNqW-CRQbrL80.js → index-BWmHLrzv-D5EBMgNv.js} +65 -67
- package/dist/index-BWmHLrzv-D5EBMgNv.js.map +1 -0
- package/dist/{index-bfV4xNqW-ChZOGalc.cjs → index-BWmHLrzv-YDgyeN9x.cjs} +11 -11
- package/dist/index-BWmHLrzv-YDgyeN9x.cjs.map +1 -0
- package/dist/index.cjs +49 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +480 -473
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-bfV4xNqW-CRQbrL80.js.map +0 -1
- package/dist/index-bfV4xNqW-ChZOGalc.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
left: 24px;
|
|
154
154
|
box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.08);
|
|
155
155
|
}
|
|
156
|
-
`,document.head.appendChild(t)},Gt=(e,t,i)=>{qt();const r=e.querySelector(".supportwire-widget-tail");r&&r.remove();const o=document.createElement("div");o.className=`supportwire-widget-tail ${t||"bottom-right"}`,o.style.background=i==="dark"?"#1a1a1a":"#ffffff",e.appendChild(o)},Qe=(e,t)=>{var i,r;const o={position:"fixed",zIndex:"999999",display:"none",opacity:"0",backgroundColor:t.theme==="dark"?"#28282a":"#f1f1f3",transition:"width 200ms ease-out, height 200ms ease-out"},n=!t.selector;switch(t.widgetType){case"popup":{const l=(i=t.triggerPosition)!=null&&i.endsWith("left")?"left":"right",s=(r=t.triggerPosition)!=null&&r.startsWith("top")?"top":"bottom",
|
|
156
|
+
`,document.head.appendChild(t)},Gt=(e,t,i)=>{qt();const r=e.querySelector(".supportwire-widget-tail");r&&r.remove();const o=document.createElement("div");o.className=`supportwire-widget-tail ${t||"bottom-right"}`,o.style.background=i==="dark"?"#1a1a1a":"#ffffff",e.appendChild(o)},Qe=(e,t)=>{var i,r;const o={position:"fixed",zIndex:"999999",display:"none",opacity:"0",backgroundColor:t.theme==="dark"?"#28282a":"#f1f1f3",transition:"width 200ms ease-out, height 200ms ease-out"},n=!t.selector;switch(t.widgetType){case"popup":{const l=(i=t.triggerPosition)!=null&&i.endsWith("left")?"left":"right",s=(r=t.triggerPosition)!=null&&r.startsWith("top")?"top":"bottom",m=A(Se(A({},o),{width:"min(400px, max(0px, -20px + 100vw))",height:"min(704px, 100% - 104px)",minHeight:"80px",maxHeight:"704px",borderRadius:"24px",boxShadow:t.theme==="dark"?"rgba(0, 0, 0, 0.5) 0px 5px 40px 0px":"rgba(9, 14, 21, 0.12) 0px 5px 40px 0px",overflow:"hidden",transformOrigin:`${l} ${s}`}),jt(t.triggerPosition,n));Object.assign(e.style,m);break}case"drawer":Object.assign(e.style,o,{bottom:"0",right:"0",width:"400px",height:"80vh",borderTopLeftRadius:"24px",boxShadow:t.theme==="dark"?"rgba(0, 0, 0, 0.5) 0px 5px 40px 0px":"rgba(9, 14, 21, 0.12) 0px 5px 40px 0px",overflow:"hidden"});break;case"center modal":Object.assign(e.style,o,{top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"90%",maxWidth:"600px",height:"80vh",borderRadius:"24px",boxShadow:t.theme==="dark"?"rgba(0, 0, 0, 0.5) 0px 5px 40px 0px":"rgba(9, 14, 21, 0.12) 0px 5px 40px 0px",overflow:"hidden"});break}},Yt=(e,t,i)=>{if(i==="popup")switch(t){case"bottom-right":e.style.bottom="84px",e.style.right="20px",e.style.top="auto",e.style.left="auto";break;case"bottom-left":e.style.bottom="84px",e.style.left="20px",e.style.top="auto",e.style.right="auto";break;case"top-right":e.style.top="84px",e.style.right="20px",e.style.bottom="auto",e.style.left="auto";break;case"top-left":e.style.top="84px",e.style.left="20px",e.style.bottom="auto",e.style.right="auto";break}},Vt=`
|
|
157
157
|
<svg width="28" height="28" viewBox="0 0 820 820" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
158
158
|
<path d="M306.256 103.089C374.06 121.601 405.862 142.59 421.597 163.509C431.539 176.728 436.259 191.483 438.492 209.449C438.57 210.082 438.643 210.717 438.715 211.352C406.945 214.037 377.275 229.548 354.7 259.981C341.9 277.237 334.444 294.617 333.557 312.794C332.669 330.997 338.511 347.065 346.837 361.327C354.975 375.267 366.267 388.769 377.867 401.971C389.907 415.672 402.475 429.27 415.535 445.247C430.794 463.914 439.389 485.957 441.679 506.319C444.009 527.042 439.644 543.751 432.155 553.715C422.208 566.947 404.553 576.35 383.329 579.578C373.766 558.908 367.432 536.332 364.99 512.317C360.559 468.74 346.585 426.481 324.199 401.287C312.749 388.401 297.053 377.839 277.666 377.481C258.099 377.12 240.782 387.253 226.463 402.846C202.178 429.296 203.512 469.846 215.138 504.134C227.276 539.932 252.808 576.859 289.195 603.059C308.607 617.036 332.485 624.471 356.456 626.188C389.051 678.63 440.001 717.759 499.915 737.633L464.425 790.873C438.535 829.709 381.465 829.709 355.575 790.873L232.25 605.888C227.46 598.704 221.294 592.538 214.11 587.748L29.1257 464.422C-9.70859 438.532-9.70855 381.468 29.1257 355.578L214.11 232.252C221.294 227.462 227.46 221.296 232.25 214.112L306.256 103.089ZM355.575 29.1266C381.465-9.70887 438.535-9.70887 464.425 29.1266L587.75 214.112C592.54 221.296 598.706 227.462 605.891 232.252L790.874 355.578C829.708 381.468 829.708 438.532 790.874 464.422L605.891 587.748C598.706 592.538 592.54 598.704 587.75 605.888L526.423 697.87C478.757 684.856 437.581 657.743 408.598 620.81C431.865 614.079 453.711 601.242 468.756 581.226C485.249 559.283 490.385 529.784 487.171 501.202C483.916 472.257 471.929 441.888 450.986 416.266C437.243 399.454 423.392 384.409 412.264 371.745C400.7 358.583 392.067 347.991 386.376 338.242C380.873 328.815 378.979 321.589 379.298 315.029C379.62 308.442 382.325 299.581 391.473 287.25C405.532 268.298 422.419 259.203 440.574 257.158C440.632 262.282 440.706 267.634 440.836 273.254C441.764 313.257 451.608 353.139 469.184 383.198C486.493 412.8 514.851 437.876 552.829 434.113C574.971 431.918 592.568 421.837 602.933 404.717C612.65 388.669 614.046 369.663 611.774 352.531C607.264 318.532 586.967 281.055 560.251 257.905C537.695 238.36 511.89 223.403 485.121 216.021C484.816 211.889 484.43 207.805 483.933 203.802C481.069 180.754 474.419 157.561 458.191 135.985C435.529 105.855 396.68 82.1759 332.931 63.0831L355.575 29.1266ZM276.816 423.261C279.023 423.301 283.573 424.501 289.975 431.705C303.292 446.695 315.474 477.943 319.44 516.941C321.485 537.048 325.758 556.267 331.954 574.436C326.083 572.154 320.674 569.306 315.946 565.902C287.519 545.433 267.66 516.46 258.497 489.436C248.821 460.902 252.942 441.706 260.189 433.813C269.148 424.057 274.786 423.224 276.816 423.261ZM486.475 264.816C501.078 270.831 515.992 280.136 530.268 292.507C548.705 308.484 563.375 335.868 566.384 358.548C567.87 369.751 566.162 377.039 563.765 381C562.014 383.891 558.471 387.543 548.313 388.55C536.044 389.765 521.828 382.532 508.704 360.087C495.847 338.098 487.398 306.189 486.609 272.194C486.553 269.765 486.511 267.3 486.475 264.816Z" fill="currentColor"/>
|
|
159
159
|
</svg>
|
|
@@ -243,7 +243,7 @@
|
|
|
243
243
|
transform: none !important;
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
`,document.head.appendChild(t)},Xt=(e,t)=>{var i,r;Jt();const o=document.createElement("div");o.className="supportwire-trigger-wrapper";const n=document.createElement("button");n.className="supportwire-widget-trigger",n.setAttribute("aria-label","Open SupportWire chat"),n.style.position="relative";const l=document.createElement("span");l.className="supportwire-trigger-icon supportwire-trigger-icon--visible",l.setAttribute("data-icon","logo"),l.innerHTML=Vt;const s=document.createElement("span");s.className="supportwire-trigger-icon supportwire-trigger-icon--hidden",s.setAttribute("data-icon","chevron"),s.innerHTML=Kt,n.appendChild(l),n.appendChild(s),Object.assign(n.style,{backgroundColor:e.theme==="dark"?"#1a1a1a":"#ffffff",color:e.theme==="dark"?"#ffffff":"#1a1a1a",boxShadow:"0 1px 6px 0 rgba(0, 0, 0, 0.06), 0 2px 32px 0 rgba(0, 0, 0, 0.16)"});const
|
|
246
|
+
`,document.head.appendChild(t)},Xt=(e,t)=>{var i,r;Jt();const o=document.createElement("div");o.className="supportwire-trigger-wrapper";const n=document.createElement("button");n.className="supportwire-widget-trigger",n.setAttribute("aria-label","Open SupportWire chat"),n.style.position="relative";const l=document.createElement("span");l.className="supportwire-trigger-icon supportwire-trigger-icon--visible",l.setAttribute("data-icon","logo"),l.innerHTML=Vt;const s=document.createElement("span");s.className="supportwire-trigger-icon supportwire-trigger-icon--hidden",s.setAttribute("data-icon","chevron"),s.innerHTML=Kt,n.appendChild(l),n.appendChild(s),Object.assign(n.style,{backgroundColor:e.theme==="dark"?"#1a1a1a":"#ffffff",color:e.theme==="dark"?"#ffffff":"#1a1a1a",boxShadow:"0 1px 6px 0 rgba(0, 0, 0, 0.06), 0 2px 32px 0 rgba(0, 0, 0, 0.16)"});const m={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},h=(i=e.triggerPosition)!=null?i:"bottom-right",u=(r=m[h])!=null?r:m["bottom-right"];return Object.assign(o.style,A({position:"fixed",zIndex:"999998"},u)),o.appendChild(n),n.addEventListener("click",t),document.body.appendChild(o),o},Qt=(e,t)=>{const i={"bottom-right":{bottom:"20px",right:"20px",top:"auto",left:"auto"},"bottom-left":{bottom:"20px",left:"20px",top:"auto",right:"auto"},"top-right":{top:"20px",right:"20px",bottom:"auto",left:"auto"},"top-left":{top:"20px",left:"20px",bottom:"auto",right:"auto"}},r=t&&i[t]?t:"bottom-right",o=i[r];Object.assign(e.style,o)},Zt=()=>{const e="supportwire-widget-badge-styles";if(document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent=`
|
|
247
247
|
.supportwire-widget-badge {
|
|
248
248
|
position: absolute;
|
|
249
249
|
top: -4px;
|
|
@@ -296,7 +296,7 @@
|
|
|
296
296
|
animation: none;
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
|
-
`,document.head.appendChild(t)},be=(e,t)=>{Zt();let i=e.querySelector(".supportwire-widget-badge");if(t>0){const r=!i||i.style.display==="none";i||(i=document.createElement("span"),i.className="supportwire-widget-badge",e.appendChild(i)),i.textContent=t>99?"99+":String(t),i.style.display="flex",i.removeAttribute("data-animate"),i.offsetWidth,i.setAttribute("data-animate",r?"pop-in":"pulse")}else i&&(i.style.display="none",i.removeAttribute("data-animate"))},$e=(e,t,i)=>{const r=e.querySelector(".supportwire-widget-trigger");if(!r)return;const o=r.querySelector('[data-icon="logo"]'),n=r.querySelector('[data-icon="chevron"]');o&&n&&(t?(o.className="supportwire-trigger-icon supportwire-trigger-icon--hidden",n.className="supportwire-trigger-icon supportwire-trigger-icon--visible"):(o.className="supportwire-trigger-icon supportwire-trigger-icon--visible",n.className="supportwire-trigger-icon supportwire-trigger-icon--hidden")),t?(r.setAttribute("aria-label","Close SupportWire chat"),r.style.color=i==="dark"?"#ffffff":"#1a1a1a"):(r.setAttribute("aria-label","Open SupportWire chat"),r.style.color="")},ei=(e,t,i,r)=>{const o=document.createElement("iframe");return o.id=t,o.src=`${i}?iframeId=${t}&theme=${r}`,o.style.width="100%",o.style.height="100%",o.style.border="none",o.style.backgroundColor=r==="dark"?"#28282a":"#f1f1f3",o.setAttribute("allow","clipboard-read; clipboard-write"),o.setAttribute("sandbox","allow-same-origin allow-scripts allow-forms allow-popups"),e.appendChild(o),o},ti=(e,t,i,r)=>{if(!e||!e.contentWindow)return;const o=Se(A({},r),{iframeId:t});e.contentWindow.postMessage(o,"*")},ii=(e,t,i,r)=>o=>{var n,l;try{const
|
|
299
|
+
`,document.head.appendChild(t)},be=(e,t)=>{Zt();let i=e.querySelector(".supportwire-widget-badge");if(t>0){const r=!i||i.style.display==="none";i||(i=document.createElement("span"),i.className="supportwire-widget-badge",e.appendChild(i)),i.textContent=t>99?"99+":String(t),i.style.display="flex",i.removeAttribute("data-animate"),i.offsetWidth,i.setAttribute("data-animate",r?"pop-in":"pulse")}else i&&(i.style.display="none",i.removeAttribute("data-animate"))},$e=(e,t,i)=>{const r=e.querySelector(".supportwire-widget-trigger");if(!r)return;const o=r.querySelector('[data-icon="logo"]'),n=r.querySelector('[data-icon="chevron"]');o&&n&&(t?(o.className="supportwire-trigger-icon supportwire-trigger-icon--hidden",n.className="supportwire-trigger-icon supportwire-trigger-icon--visible"):(o.className="supportwire-trigger-icon supportwire-trigger-icon--visible",n.className="supportwire-trigger-icon supportwire-trigger-icon--hidden")),t?(r.setAttribute("aria-label","Close SupportWire chat"),r.style.color=i==="dark"?"#ffffff":"#1a1a1a"):(r.setAttribute("aria-label","Open SupportWire chat"),r.style.color="")},ei=(e,t,i,r)=>{const o=document.createElement("iframe");return o.id=t,o.src=`${i}?iframeId=${t}&theme=${r}`,o.style.width="100%",o.style.height="100%",o.style.border="none",o.style.backgroundColor=r==="dark"?"#28282a":"#f1f1f3",o.setAttribute("allow","clipboard-read; clipboard-write"),o.setAttribute("sandbox","allow-same-origin allow-scripts allow-forms allow-popups"),e.appendChild(o),o},ti=(e,t,i,r)=>{if(!e||!e.contentWindow)return;const o=Se(A({},r),{iframeId:t});e.contentWindow.postMessage(o,"*")},ii=(e,t,i,r)=>o=>{var n,l;try{const m=new URL(t).origin;o.origin!==m&&o.origin}catch{}const s=o.data;if(!(!s||s.iframeId!==e))switch(s.type){case"READY":r.onReady&&r.onReady();break;case"OPENED":i&&(i.style.display="block",ht(i)),r.onOpen();break;case"CLOSED":i&>(i),r.onClose();break;case"ERROR":r.onError(new Error(s.error||"Unknown error"));break;case"UNREAD_COUNT":r.onUnreadCount&&s.count!==void 0&&r.onUnreadCount(s.count);break;case"OPEN_IMAGE_PREVIEW":r.onImagePreview&&s.imagePreview&&r.onImagePreview(s.imagePreview.src,s.imagePreview.alt,s.imagePreview.filename);break;case"TOGGLE_FULLSCREEN":r.onToggleFullscreen&&r.onToggleFullscreen();break;case"MESSAGE_PREVIEW":r.onMessagePreview&&s.messagePreview&&r.onMessagePreview(s.messagePreview.body,s.messagePreview.senderName,s.messagePreview.timestamp);break;case"EVENT_RULES_REGISTERED":r.onEventRulesRegistered&&s.eventRules&&r.onEventRulesRegistered(s.eventRules);break;case"REQUEST_PAGE_SCREENSHOT":r.onScreenshotRequest&&r.onScreenshotRequest((l=(n=s.payload)==null?void 0:n.mode)!=null?l:"full");break}};function oi(e,t,i={}){let r=null;const o=()=>(r||(r=Promise.resolve().then(()=>require("./index-BWmHLrzv-YDgyeN9x.cjs"))),r),n=h=>{var u;(u=e.contentWindow)==null||u.postMessage(Se(A({},h),{iframeId:t}),"*")},l=async h=>{var u;const c=h.data;if(!(!c||typeof c!="object")&&!(c.iframeId&&c.iframeId!==t))switch(c.type){case"RECORDING:START":{const g=await o();(u=i.closeWidget)==null||u.call(i),g.recording.start({guideId:c.guideId,title:c.title});return}case"RECORDING:STOP":{const g=(await o()).recording.stop();g&&n({type:"RECORDING:DONE",guideId:g.guideId,title:g.title,steps:g.steps});return}case"PLAYBACK:START":{const g=await o();g.playback.onDone((y,k,b)=>{n({type:"PLAYBACK:DONE",status:y,end_reason:k,current_step:b})}),g.playback.start({sessionId:c.sessionId,guideId:c.guideId,versionId:c.versionId,version:c.version});return}case"OPEN_URL":{typeof c.url=="string"&&window.open(c.url,"_blank","noopener");return}}},s=h=>{const u=h.detail;u&&n({type:"RECORDING:DONE",guideId:u.guideId,title:u.title,steps:u.steps})};window.addEventListener("message",l),window.addEventListener("sw-guide:recording-done",s),(async()=>{var h;const u=await m();if(!u)return;const c=u.recording.maybeResume();c&&((h=i.closeWidget)==null||h.call(i),u.recording.start({guideId:c.guideId,title:c.title}));const g=u.playback.maybeResume();g&&(u.playback.onDone((k,b,x)=>{n({type:"PLAYBACK:DONE",status:k,end_reason:b,current_step:x})}),u.playback.start({sessionId:g.sessionId,guideId:g.guideId,versionId:g.versionId,version:g.version,resumeStepIndex:g.stepIndex}));const y=new URLSearchParams(location.search).get("sw_guide");y&&n({type:"DEEP_LINK_GUIDE",guideId:y})})();function m(){const h=!!localStorage.getItem("sw.guide.recording"),u=!!localStorage.getItem("sw.guide.playback"),c=new URLSearchParams(location.search).has("sw_guide");return!h&&!u&&!c?Promise.resolve(null):o()}return{teardown:()=>{window.removeEventListener("message",l),window.removeEventListener("sw-guide:recording-done",s)}}}let W=null,se=null,mt="";const ri=`
|
|
300
300
|
.supportwire-image-preview-backdrop {
|
|
301
301
|
position: fixed;
|
|
302
302
|
top: 0;
|
|
@@ -521,8 +521,8 @@
|
|
|
521
521
|
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>
|
|
522
522
|
</svg>`}function Ze(){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
523
523
|
<polyline points="20 6 9 17 4 12"/>
|
|
524
|
-
</svg>`}async function di(e,t){try{const i=await(await fetch(e)).blob(),r=URL.createObjectURL(i),o=document.createElement("a");o.href=r,o.download=t||"image",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}catch{window.open(e,"_blank")}}function oe(){if(!W)return;const e=W;se&&(document.removeEventListener("keydown",se),se=null),document.body.style.overflow=mt,e.classList.remove("visible"),e.classList.add("closing"),window.matchMedia("(prefers-reduced-motion: reduce)").matches?(e.remove(),W=null):setTimeout(()=>{e.remove(),W===e&&(W=null)},200)}function
|
|
525
|
-
.${
|
|
524
|
+
</svg>`}async function di(e,t){try{const i=await(await fetch(e)).blob(),r=URL.createObjectURL(i),o=document.createElement("a");o.href=r,o.download=t||"image",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}catch{window.open(e,"_blank")}}function oe(){if(!W)return;const e=W;se&&(document.removeEventListener("keydown",se),se=null),document.body.style.overflow=mt,e.classList.remove("visible"),e.classList.add("closing"),window.matchMedia("(prefers-reduced-motion: reduce)").matches?(e.remove(),W=null):setTimeout(()=>{e.remove(),W===e&&(W=null)},200)}function ci(e,t,i,r){W&&(W.remove(),W=null),ni(),mt=document.body.style.overflow,document.body.style.overflow="hidden";const o=document.createElement("div");o.className="supportwire-image-preview-backdrop",o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.setAttribute("aria-label",t||"Image preview"),o.onclick=y=>{(y.target===o||y.target.classList.contains("supportwire-image-preview-image-container"))&&oe()};const n=document.createElement("div");n.className="supportwire-image-preview-actions";const l=document.createElement("button");l.className="supportwire-image-preview-button",l.setAttribute("aria-label","Copy link"),l.innerHTML=Re(),l.onclick=async y=>{y.stopPropagation();try{await navigator.clipboard.writeText(e),l.innerHTML=Ze(),setTimeout(()=>{l.innerHTML=Re()},2e3)}catch{const b=document.createElement("textarea");b.value=e,b.style.position="fixed",b.style.opacity="0",document.body.appendChild(b),b.select(),document.execCommand("copy"),document.body.removeChild(b),l.innerHTML=Ze(),setTimeout(()=>{l.innerHTML=Re()},2e3)}};const s=document.createElement("button");s.className="supportwire-image-preview-button",s.setAttribute("aria-label","Download image"),s.innerHTML=si(),s.onclick=y=>{y.stopPropagation(),di(e,i)};let m=null;r&&(m=document.createElement("button"),m.className="supportwire-image-preview-button",m.setAttribute("aria-label","Annotate image"),m.innerHTML=li(),m.onclick=async y=>{y.stopPropagation();try{const k=await(await fetch(e)).blob(),b=await new Promise((x,E)=>{const C=new FileReader;C.onload=()=>x(C.result),C.onerror=E,C.readAsDataURL(k)});oe(),r(b)}catch{const b=document.createElement("canvas"),x=new Image;x.crossOrigin="anonymous",x.onload=()=>{b.width=x.naturalWidth,b.height=x.naturalHeight;const E=b.getContext("2d");if(E){E.drawImage(x,0,0);const C=b.toDataURL("image/png");oe(),r(C)}},x.onerror=()=>{console.warn("Could not load image for annotation")},x.src=e}});const h=document.createElement("button");h.className="supportwire-image-preview-button",h.setAttribute("aria-label","Close preview"),h.innerHTML=ai(),h.onclick=y=>{y.stopPropagation(),oe()},n.appendChild(l),n.appendChild(s),m&&n.appendChild(m),n.appendChild(h);const u=document.createElement("div");u.className="supportwire-image-preview-image-container";const c=document.createElement("div");c.className="supportwire-image-preview-loader",u.appendChild(c);const g=document.createElement("img");if(g.className="supportwire-image-preview-image",g.alt=t||"Image preview",g.onload=()=>{c.remove()},g.onerror=()=>{c.remove();const y=document.createElement("div");y.className="supportwire-image-preview-error",y.textContent="Failed to load image",u.appendChild(y)},g.src=e,u.appendChild(g),i){const y=document.createElement("p");y.className="supportwire-image-preview-filename",y.textContent=i,o.appendChild(y)}o.appendChild(n),o.appendChild(u),document.body.appendChild(o),W=o,requestAnimationFrame(()=>{o.classList.add("visible")}),se=y=>{y.key==="Escape"&&oe()},document.addEventListener("keydown",se),h.focus()}let K=null,ae=null,ft="";const p="supportwire-ss-editor",pi=`
|
|
525
|
+
.${p}-backdrop {
|
|
526
526
|
position: fixed;
|
|
527
527
|
inset: 0;
|
|
528
528
|
z-index: 2147483647;
|
|
@@ -533,7 +533,7 @@
|
|
|
533
533
|
padding: 0;
|
|
534
534
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
535
535
|
}
|
|
536
|
-
.${
|
|
536
|
+
.${p}-modal {
|
|
537
537
|
background: #fff;
|
|
538
538
|
border-radius: 16px;
|
|
539
539
|
box-shadow: 0 25px 50px -12px rgba(0,0,0,0.4);
|
|
@@ -543,19 +543,19 @@
|
|
|
543
543
|
height: 95vh;
|
|
544
544
|
overflow: hidden;
|
|
545
545
|
}
|
|
546
|
-
.${
|
|
546
|
+
.${p}-header {
|
|
547
547
|
display: flex;
|
|
548
548
|
align-items: center;
|
|
549
549
|
justify-content: space-between;
|
|
550
550
|
padding: 12px 16px;
|
|
551
551
|
border-bottom: 1px solid #e5e7eb;
|
|
552
552
|
}
|
|
553
|
-
.${
|
|
553
|
+
.${p}-title {
|
|
554
554
|
font-size: 14px;
|
|
555
555
|
font-weight: 600;
|
|
556
556
|
color: #111;
|
|
557
557
|
}
|
|
558
|
-
.${
|
|
558
|
+
.${p}-close-btn {
|
|
559
559
|
display: flex;
|
|
560
560
|
align-items: center;
|
|
561
561
|
justify-content: center;
|
|
@@ -567,8 +567,8 @@
|
|
|
567
567
|
color: #666;
|
|
568
568
|
cursor: pointer;
|
|
569
569
|
}
|
|
570
|
-
.${
|
|
571
|
-
.${
|
|
570
|
+
.${p}-close-btn:hover { background: #f3f4f6; color: #111; }
|
|
571
|
+
.${p}-canvas-wrap {
|
|
572
572
|
position: relative;
|
|
573
573
|
flex: 1;
|
|
574
574
|
min-height: 300px;
|
|
@@ -576,20 +576,20 @@
|
|
|
576
576
|
cursor: crosshair;
|
|
577
577
|
background: #f9fafb;
|
|
578
578
|
}
|
|
579
|
-
.${
|
|
580
|
-
.${
|
|
581
|
-
.${
|
|
579
|
+
.${p}-canvas-wrap.select-mode { cursor: default; }
|
|
580
|
+
.${p}-canvas-wrap.select-mode-moving { cursor: grabbing; }
|
|
581
|
+
.${p}-img {
|
|
582
582
|
display: block;
|
|
583
583
|
pointer-events: none;
|
|
584
584
|
user-select: none;
|
|
585
585
|
}
|
|
586
|
-
.${
|
|
586
|
+
.${p}-canvas {
|
|
587
587
|
position: absolute;
|
|
588
588
|
left: 0;
|
|
589
589
|
top: 0;
|
|
590
590
|
pointer-events: none;
|
|
591
591
|
}
|
|
592
|
-
.${
|
|
592
|
+
.${p}-toolbar {
|
|
593
593
|
display: flex;
|
|
594
594
|
align-items: center;
|
|
595
595
|
justify-content: space-between;
|
|
@@ -598,12 +598,12 @@
|
|
|
598
598
|
padding: 12px 16px;
|
|
599
599
|
border-top: 1px solid #e5e7eb;
|
|
600
600
|
}
|
|
601
|
-
.${
|
|
601
|
+
.${p}-tools {
|
|
602
602
|
display: flex;
|
|
603
603
|
align-items: center;
|
|
604
604
|
gap: 4px;
|
|
605
605
|
}
|
|
606
|
-
.${
|
|
606
|
+
.${p}-tool-btn {
|
|
607
607
|
display: flex;
|
|
608
608
|
align-items: center;
|
|
609
609
|
justify-content: center;
|
|
@@ -615,9 +615,9 @@
|
|
|
615
615
|
color: #666;
|
|
616
616
|
cursor: pointer;
|
|
617
617
|
}
|
|
618
|
-
.${
|
|
619
|
-
.${
|
|
620
|
-
.${
|
|
618
|
+
.${p}-tool-btn:hover { background: #f3f4f6; color: #111; }
|
|
619
|
+
.${p}-tool-btn.active { background: #0091FF; color: #fff; }
|
|
620
|
+
.${p}-color-picker {
|
|
621
621
|
width: 28px;
|
|
622
622
|
height: 28px;
|
|
623
623
|
border: none;
|
|
@@ -626,18 +626,18 @@
|
|
|
626
626
|
background: transparent;
|
|
627
627
|
padding: 0;
|
|
628
628
|
}
|
|
629
|
-
.${
|
|
629
|
+
.${p}-separator {
|
|
630
630
|
width: 1px;
|
|
631
631
|
height: 24px;
|
|
632
632
|
background: #e5e7eb;
|
|
633
633
|
margin: 0 4px;
|
|
634
634
|
}
|
|
635
|
-
.${
|
|
635
|
+
.${p}-color-swatches {
|
|
636
636
|
display: flex;
|
|
637
637
|
align-items: center;
|
|
638
638
|
gap: 3px;
|
|
639
639
|
}
|
|
640
|
-
.${
|
|
640
|
+
.${p}-swatch {
|
|
641
641
|
width: 22px;
|
|
642
642
|
height: 22px;
|
|
643
643
|
border-radius: 50%;
|
|
@@ -646,28 +646,28 @@
|
|
|
646
646
|
padding: 0;
|
|
647
647
|
box-sizing: border-box;
|
|
648
648
|
}
|
|
649
|
-
.${
|
|
649
|
+
.${p}-swatch.active {
|
|
650
650
|
border-color: #111;
|
|
651
651
|
box-shadow: 0 0 0 1px #fff inset;
|
|
652
652
|
}
|
|
653
|
-
.${
|
|
654
|
-
.${
|
|
653
|
+
.${p}-swatch:hover { opacity: 0.8; }
|
|
654
|
+
.${p}-thickness-wrap {
|
|
655
655
|
display: flex;
|
|
656
656
|
align-items: center;
|
|
657
657
|
gap: 6px;
|
|
658
658
|
}
|
|
659
|
-
.${
|
|
659
|
+
.${p}-thickness-label {
|
|
660
660
|
font-size: 11px;
|
|
661
661
|
color: #888;
|
|
662
662
|
white-space: nowrap;
|
|
663
663
|
}
|
|
664
|
-
.${
|
|
664
|
+
.${p}-thickness-slider {
|
|
665
665
|
width: 80px;
|
|
666
666
|
height: 4px;
|
|
667
667
|
accent-color: #0091FF;
|
|
668
668
|
cursor: pointer;
|
|
669
669
|
}
|
|
670
|
-
.${
|
|
670
|
+
.${p}-radius-btn {
|
|
671
671
|
display: flex;
|
|
672
672
|
align-items: center;
|
|
673
673
|
justify-content: center;
|
|
@@ -681,14 +681,14 @@
|
|
|
681
681
|
font-size: 11px;
|
|
682
682
|
font-weight: 600;
|
|
683
683
|
}
|
|
684
|
-
.${
|
|
685
|
-
.${
|
|
686
|
-
.${
|
|
684
|
+
.${p}-radius-btn:hover { background: #f3f4f6; color: #111; }
|
|
685
|
+
.${p}-radius-btn.active { background: #0091FF; color: #fff; }
|
|
686
|
+
.${p}-actions {
|
|
687
687
|
display: flex;
|
|
688
688
|
gap: 8px;
|
|
689
689
|
align-items: center;
|
|
690
690
|
}
|
|
691
|
-
.${
|
|
691
|
+
.${p}-btn-cancel {
|
|
692
692
|
padding: 8px 16px;
|
|
693
693
|
font-size: 13px;
|
|
694
694
|
border-radius: 8px;
|
|
@@ -698,8 +698,8 @@
|
|
|
698
698
|
cursor: pointer;
|
|
699
699
|
font-family: inherit;
|
|
700
700
|
}
|
|
701
|
-
.${
|
|
702
|
-
.${
|
|
701
|
+
.${p}-btn-cancel:hover { background: #f3f4f6; }
|
|
702
|
+
.${p}-btn-done {
|
|
703
703
|
padding: 8px 16px;
|
|
704
704
|
font-size: 13px;
|
|
705
705
|
border-radius: 8px;
|
|
@@ -709,8 +709,8 @@
|
|
|
709
709
|
cursor: pointer;
|
|
710
710
|
font-family: inherit;
|
|
711
711
|
}
|
|
712
|
-
.${
|
|
713
|
-
.${
|
|
712
|
+
.${p}-btn-done:hover { opacity: 0.9; }
|
|
713
|
+
.${p}-btn-crop-apply {
|
|
714
714
|
padding: 6px 12px;
|
|
715
715
|
font-size: 12px;
|
|
716
716
|
border-radius: 8px;
|
|
@@ -720,7 +720,7 @@
|
|
|
720
720
|
cursor: pointer;
|
|
721
721
|
font-family: inherit;
|
|
722
722
|
}
|
|
723
|
-
.${
|
|
723
|
+
.${p}-text-overlay {
|
|
724
724
|
position: absolute;
|
|
725
725
|
display: flex;
|
|
726
726
|
gap: 4px;
|
|
@@ -731,7 +731,7 @@
|
|
|
731
731
|
padding: 4px;
|
|
732
732
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
733
733
|
}
|
|
734
|
-
.${
|
|
734
|
+
.${p}-text-input {
|
|
735
735
|
width: 140px;
|
|
736
736
|
padding: 4px 8px;
|
|
737
737
|
font-size: 13px;
|
|
@@ -742,7 +742,7 @@
|
|
|
742
742
|
outline: none;
|
|
743
743
|
font-family: inherit;
|
|
744
744
|
}
|
|
745
|
-
.${
|
|
745
|
+
.${p}-text-ok {
|
|
746
746
|
padding: 4px 8px;
|
|
747
747
|
font-size: 12px;
|
|
748
748
|
border-radius: 4px;
|
|
@@ -752,7 +752,7 @@
|
|
|
752
752
|
cursor: pointer;
|
|
753
753
|
font-family: inherit;
|
|
754
754
|
}
|
|
755
|
-
.${
|
|
755
|
+
.${p}-undo-btn {
|
|
756
756
|
display: flex;
|
|
757
757
|
align-items: center;
|
|
758
758
|
justify-content: center;
|
|
@@ -764,13 +764,13 @@
|
|
|
764
764
|
color: #666;
|
|
765
765
|
cursor: pointer;
|
|
766
766
|
}
|
|
767
|
-
.${
|
|
768
|
-
.${
|
|
767
|
+
.${p}-undo-btn:hover { background: #f3f4f6; color: #111; }
|
|
768
|
+
.${p}-undo-btn:disabled { opacity: 0.3; cursor: default; }
|
|
769
769
|
@media (max-width: 540px) {
|
|
770
|
-
.${
|
|
771
|
-
.${
|
|
770
|
+
.${p}-modal { width: 100%; height: 100vh; border-radius: 0; }
|
|
771
|
+
.${p}-backdrop { padding: 0; }
|
|
772
772
|
}
|
|
773
|
-
`;function ui(){if(document.getElementById(`${c}-styles`))return;const e=document.createElement("style");e.id=`${c}-styles`,e.textContent=ci,document.head.appendChild(e)}const Ne={select:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/><path d="M13 13l6 6"/></svg>',pen:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/></svg>',arrow:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M5 12h14"/><path d="M12 5l7 7-7 7"/></svg>',rect:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>',text:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M12 4v16"/></svg>',crop:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M6 3v18"/><path d="M18 3v18"/><path d="M3 6h18"/><path d="M3 18h18"/></svg>',close:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',undo:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 7v6h6"/><path d="M3 13a9 9 0 0 1 15.36-6.36"/></svg>'};function wt(e,t,i,r,o,n){const l=Math.min(n,Math.abs(r)/2,Math.abs(o)/2);e.beginPath(),e.moveTo(t+l,i),e.lineTo(t+r-l,i),e.arcTo(t+r,i,t+r,i+l,l),e.lineTo(t+r,i+o-l),e.arcTo(t+r,i+o,t+r-l,i+o,l),e.lineTo(t+l,i+o),e.arcTo(t,i+o,t,i+o-l,l),e.lineTo(t,i+l),e.arcTo(t,i,t+l,i,l),e.closePath(),e.stroke()}function et(e,t){if(e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth="width"in t?t.width:2,e.lineCap="round",e.lineJoin="round",t.type==="pen"&&t.points.length>=4){e.beginPath(),e.moveTo(t.points[0],t.points[1]);for(let i=2;i<t.points.length;i+=2)e.lineTo(t.points[i],t.points[i+1]);e.stroke()}else if(t.type==="arrow"){e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke();const i=10,r=Math.atan2(t.y2-t.y1,t.x2-t.x1);e.beginPath(),e.moveTo(t.x2,t.y2),e.lineTo(t.x2-i*Math.cos(r-.4),t.y2-i*Math.sin(r-.4)),e.lineTo(t.x2-i*Math.cos(r+.4),t.y2-i*Math.sin(r+.4)),e.closePath(),e.fill()}else t.type==="rect"?t.radius>0?wt(e,t.x,t.y,t.w,t.h,t.radius):e.strokeRect(t.x,t.y,t.w,t.h):t.type==="text"&&(e.font="16px system-ui, sans-serif",e.fillText(t.text,t.x,t.y+16))}function yt(e){if(e.type==="rect")return{x:e.x,y:e.y,w:e.w,h:e.h};if(e.type==="arrow"){const t=Math.min(e.x1,e.x2),i=Math.min(e.y1,e.y2);return{x:t,y:i,w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}}else if(e.type==="pen"&&e.points.length>=4){let t=e.points[0],i=e.points[0],r=e.points[1],o=e.points[1];for(let n=2;n<e.points.length;n+=2)t=Math.min(t,e.points[n]),i=Math.max(i,e.points[n]),r=Math.min(r,e.points[n+1]),o=Math.max(o,e.points[n+1]);return{x:t,y:r,w:i-t,h:o-r}}else if(e.type==="text")return{x:e.x,y:e.y,w:100,h:20};return{x:0,y:0,w:0,h:0}}function hi(e,t,i,r){const o=r;if(e.type==="rect"){const{x:n,y:l,w:s,h:u}=e,d=i>=l-o&&i<=l+o&&t>=n-o&&t<=n+s+o,h=i>=l+u-o&&i<=l+u+o&&t>=n-o&&t<=n+s+o,g=t>=n-o&&t<=n+o&&i>=l-o&&i<=l+u+o,w=t>=n+s-o&&t<=n+s+o&&i>=l-o&&i<=l+u+o,y=t>=n&&t<=n+s&&i>=l&&i<=l+u;return d||h||g||w||y}else{if(e.type==="arrow")return tt(t,i,e.x1,e.y1,e.x2,e.y2)<=o+e.width;if(e.type==="pen"&&e.points.length>=4){for(let n=0;n<e.points.length-2;n+=2)if(tt(t,i,e.points[n],e.points[n+1],e.points[n+2],e.points[n+3])<=o+e.width)return!0;return!1}else if(e.type==="text"){const n=yt(e);return t>=n.x-o&&t<=n.x+n.w+o&&i>=n.y-o&&i<=n.y+n.h+o}}return!1}function tt(e,t,i,r,o,n){const l=o-i,s=n-r,u=l*l+s*s;if(u===0)return Math.hypot(e-i,t-r);let d=((e-i)*l+(t-r)*s)/u;return d=Math.max(0,Math.min(1,d)),Math.hypot(e-(i+d*l),t-(r+d*s))}function gi(e,t,i){if(e.type==="rect")e.x+=t,e.y+=i;else if(e.type==="arrow")e.x1+=t,e.y1+=i,e.x2+=t,e.y2+=i;else if(e.type==="pen")for(let r=0;r<e.points.length;r+=2)e.points[r]+=t,e.points[r+1]+=i;else e.type==="text"&&(e.x+=t,e.y+=i)}function mi(e,t){const i=yt(t),r=6;e.save(),e.strokeStyle="#0091FF",e.lineWidth=1.5,e.setLineDash([4,3]),e.strokeRect(i.x-r,i.y-r,i.w+r*2,i.h+r*2),e.setLineDash([]);const o=5;e.fillStyle="#fff",e.strokeStyle="#0091FF",e.lineWidth=1.5;const n=[[i.x-r,i.y-r],[i.x+i.w+r,i.y-r],[i.x-r,i.y+i.h+r],[i.x+i.w+r,i.y+i.h+r]];for(const[l,s]of n)e.beginPath(),e.arc(l,s,o,0,Math.PI*2),e.fill(),e.stroke();e.restore()}function re(){K&&(ae&&(document.removeEventListener("keydown",ae),ae=null),document.body.style.overflow=ft,K.remove(),K=null)}function it(e,t,i){K&&(K.remove(),K=null),ui(),ft=document.body.style.overflow,document.body.style.overflow="hidden";let r="rect",o="#FF3B30",n=3,l=0,s=[],u=e,d=0,h=0,g=1,w=0,y=0,S=!1,b=[],v=null,k=null,C=null,_=null,M=null,D=null,V=null;const ce=document.createElement("div");ce.className=`${c}-backdrop`;const X=document.createElement("div");X.className=`${c}-modal`,X.onclick=a=>a.stopPropagation();const ue=document.createElement("div");ue.className=`${c}-header`;const Te=document.createElement("span");Te.className=`${c}-title`,Te.textContent="Edit screenshot";const Z=document.createElement("button");Z.className=`${c}-close-btn`,Z.setAttribute("aria-label","Close"),Z.innerHTML=Ne.close,Z.onclick=()=>{re(),i()},ue.appendChild(Te),ue.appendChild(Z);const E=document.createElement("div");E.className=`${c}-canvas-wrap`;const j=document.createElement("img");j.className=`${c}-img`,j.alt="Screenshot";const P=document.createElement("canvas");P.className=`${c}-canvas`,E.appendChild(j),E.appendChild(P);const ee=document.createElement("div");ee.className=`${c}-toolbar`;const O=document.createElement("div");O.className=`${c}-tools`;const Ae={},$t=["select","pen","arrow","rect","text","crop"],De={select:"Select & Move",pen:"Pen",arrow:"Arrow",rect:"Rectangle",text:"Text",crop:"Crop"};for(const a of $t){const p=document.createElement("button");p.className=`${c}-tool-btn${a==="rect"?" active":""}`,p.setAttribute("aria-label",De[a]),p.title=De[a],p.innerHTML=Ne[a],p.onclick=()=>Ye(a),Ae[a]=p,O.appendChild(p)}const We=document.createElement("div");We.className=`${c}-separator`,O.appendChild(We);const Rt=["#FF3B30","#FF9500","#FFCC00","#34C759","#0091FF","#AF52DE","#FF2D55","#000000","#8E8E93"],he=document.createElement("div");he.className=`${c}-color-swatches`;const Be=[];function Ie(a){Be.forEach(p=>p.classList.toggle("active",p.dataset.color===a))}for(const a of Rt){const p=document.createElement("button");p.className=`${c}-swatch${a===o?" active":""}`,p.style.background=a,p.dataset.color=a,p.setAttribute("aria-label",`Color ${a}`),p.onclick=()=>{o=a,F.value=a,Ie(a),ye("color",a)},Be.push(p),he.appendChild(p)}const F=document.createElement("input");F.type="color",F.value=o,F.className=`${c}-color-picker`,F.setAttribute("aria-label","Custom color"),F.title="Custom color",F.oninput=()=>{o=F.value,Ie(""),ye("color",o)},he.appendChild(F),O.appendChild(he);const je=document.createElement("div");je.className=`${c}-separator`,O.appendChild(je);const ge=document.createElement("div");ge.className=`${c}-thickness-wrap`;const te=document.createElement("span");te.className=`${c}-thickness-label`,te.textContent="3px";const U=document.createElement("input");U.type="range",U.min="1",U.max="12",U.value=String(n),U.className=`${c}-thickness-slider`,U.setAttribute("aria-label","Stroke thickness"),U.oninput=()=>{n=parseInt(U.value,10),te.textContent=`${n}px`,ye("width",n)},ge.appendChild(U),ge.appendChild(te),O.appendChild(ge);const qe=document.createElement("div");qe.className=`${c}-separator`,O.appendChild(qe);const q=document.createElement("button");q.className=`${c}-radius-btn`,q.setAttribute("aria-label","Rounded corners"),q.title="Rounded corners",q.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 9a6 6 0 0 1 6-6h6a6 6 0 0 1 6 6v6a6 6 0 0 1-6 6H9a6 6 0 0 1-6-6V9z"/></svg>',q.onclick=()=>{l=l===0?12:0,q.classList.toggle("active",l>0),ye("radius",l)},O.appendChild(q);const Ge=document.createElement("div");Ge.className=`${c}-separator`,O.appendChild(Ge);const I=document.createElement("button");I.className=`${c}-undo-btn`,I.setAttribute("aria-label","Undo"),I.title="Undo",I.innerHTML=Ne.undo,I.disabled=!0,I.onclick=()=>{s.length>0&&(s.pop(),I.disabled=s.length===0,C=null,T())},O.appendChild(I);const H=document.createElement("button");H.className=`${c}-btn-crop-apply`,H.textContent="Apply crop",H.style.display="none",H.onclick=_t;const me=document.createElement("div");me.className=`${c}-actions`;const fe=document.createElement("button");fe.className=`${c}-btn-cancel`,fe.textContent="Cancel",fe.onclick=()=>{re(),i()};const we=document.createElement("button");we.className=`${c}-btn-done`,we.textContent="Done",we.onclick=Ot,me.appendChild(fe),me.appendChild(we),ee.appendChild(O),ee.appendChild(H),ee.appendChild(me),X.appendChild(ue),X.appendChild(E),X.appendChild(ee),ce.appendChild(X),document.body.appendChild(ce),K=ce;function Ye(a){r=a;for(const[p,f]of Object.entries(Ae))f.classList.toggle("active",p===a);a!=="crop"&&(M=null,D=null,H.style.display="none"),a!=="select"&&(C=null),E.classList.toggle("select-mode",a==="select"),E.classList.remove("select-mode-moving"),ie(),T()}function ye(a,p){if(C===null||C>=s.length)return;const f=s[C];a==="color"?f.color=p:a==="width"&&"width"in f?f.width=p:a==="radius"&&f.type==="rect"&&(f.radius=p),T()}function Nt(a){o=a.color,F.value=a.color,Ie(a.color),"width"in a&&(n=a.width,U.value=String(a.width),te.textContent=`${a.width}px`),a.type==="rect"&&(l=a.radius,q.classList.toggle("active",a.radius>0))}function Le(a,p){const f=E.getBoundingClientRect();return{x:Math.round((a-f.left-w)/g),y:Math.round((p-f.top-y)/g)}}function Ve(){if(!d||!h)return;const a=E.clientWidth-32,p=E.clientHeight-32;g=Math.min(a/d,p/h,1),w=(E.clientWidth-d*g)/2,y=(E.clientHeight-h*g)/2,j.style.width=`${d*g}px`,j.style.height=`${h*g}px`,j.style.marginLeft=`${w}px`,j.style.marginTop=`${y}px`,P.width=E.clientWidth,P.height=E.clientHeight,T()}function Ke(){const a=new Image;a.onload=()=>{d=a.naturalWidth,h=a.naturalHeight,j.src=u,Ve()},a.src=u}function T(){const a=P.getContext("2d");if(a){if(a.clearRect(0,0,P.width,P.height),a.save(),a.translate(w,y),a.scale(g,g),s.forEach((p,f)=>{et(a,p),f===C&&mi(a,p)}),S&&b.length>=4&&r==="pen"){a.strokeStyle=o,a.lineWidth=n,a.lineCap="round",a.lineJoin="round",a.beginPath(),a.moveTo(b[0],b[1]);for(let p=2;p<b.length;p+=2)a.lineTo(b[p],b[p+1]);a.stroke()}if(a.restore(),r==="crop"&&M){a.fillStyle="rgba(0,0,0,0.4)",a.fillRect(0,0,P.width,P.height);const p=w+M.x*g,f=y+M.y*g,m=M.w*g,x=M.h*g;a.clearRect(p,f,m,x),a.strokeStyle="#0091FF",a.lineWidth=2,a.strokeRect(p,f,m,x),H.style.display=""}}}function _t(){if(!M||M.w<10||M.h<10)return;const a=new Image;a.onload=()=>{const p=document.createElement("canvas");p.width=M.w,p.height=M.h;const f=p.getContext("2d");f&&(f.drawImage(a,M.x,M.y,M.w,M.h,0,0,M.w,M.h),u=p.toDataURL("image/png"),s=[],I.disabled=!0,C=null,M=null,D=null,H.style.display="none",Ye("rect"),Ke())},a.src=u}function ie(){V&&(V.remove(),V=null)}function Pt(a,p){ie();const f=document.createElement("div");f.className=`${c}-text-overlay`,f.style.left=`${a*g+w}px`,f.style.top=`${p*g+y}px`;const m=document.createElement("input");m.type="text",m.className=`${c}-text-input`,m.placeholder="Text...";const x=document.createElement("button");x.className=`${c}-text-ok`,x.textContent="Add";const z=()=>{const G=m.value.trim();G&&(s.push({type:"text",x:a,y:p,text:G,color:o}),I.disabled=!1,T()),ie()};m.onkeydown=G=>{G.key==="Enter"&&z(),G.key==="Escape"&&ie()},x.onclick=z,f.appendChild(m),f.appendChild(x),E.appendChild(f),V=f,m.focus()}E.onmousedown=a=>{const{x:p,y:f}=Le(a.clientX,a.clientY);if(r==="select"){let m=-1;for(let x=s.length-1;x>=0;x--)if(hi(s[x],p,f,8)){m=x;break}m>=0?(C=m,_={x:p,y:f},Nt(s[m]),E.classList.add("select-mode-moving")):C=null,T();return}if(r==="crop"){D={x:p,y:f},M=null,H.style.display="none";return}V||(C=null,r==="pen"?(S=!0,b=[p,f]):r==="arrow"?v={x:p,y:f}:r==="rect"?k={x:p,y:f}:r==="text"&&Pt(p,f))},E.onmousemove=a=>{const{x:p,y:f}=Le(a.clientX,a.clientY);if(r==="select"&&_&&C!==null){const m=p-_.x,x=f-_.y;(Math.abs(m)>1||Math.abs(x)>1)&&(gi(s[C],m,x),_={x:p,y:f},T());return}if(r==="crop"&&D){const m=Math.min(D.x,p),x=Math.min(D.y,f);M={x:m,y:x,w:Math.max(20,Math.abs(p-D.x)),h:Math.max(20,Math.abs(f-D.y))},T()}else if(S&&r==="pen")b.push(p,f),T();else if(r==="rect"&&k){T();const m=P.getContext("2d");if(m){m.save(),m.translate(w,y),m.scale(g,g),m.strokeStyle=o,m.lineWidth=n,m.lineCap="round",m.lineJoin="round";const x=Math.min(k.x,p),z=Math.min(k.y,f),G=Math.abs(p-k.x),Je=Math.abs(f-k.y);l>0?wt(m,x,z,G,Je,l):m.strokeRect(x,z,G,Je),m.restore()}}else if(r==="arrow"&&v){T();const m=P.getContext("2d");if(m){m.save(),m.translate(w,y),m.scale(g,g),m.strokeStyle=o,m.fillStyle=o,m.lineWidth=n,m.lineCap="round",m.lineJoin="round",m.beginPath(),m.moveTo(v.x,v.y),m.lineTo(p,f),m.stroke();const x=10,z=Math.atan2(f-v.y,p-v.x);m.beginPath(),m.moveTo(p,f),m.lineTo(p-x*Math.cos(z-.4),f-x*Math.sin(z-.4)),m.lineTo(p-x*Math.cos(z+.4),f-x*Math.sin(z+.4)),m.closePath(),m.fill(),m.restore()}}},E.onmouseup=a=>{const{x:p,y:f}=Le(a.clientX,a.clientY);if(r==="select"){_=null,E.classList.remove("select-mode-moving");return}if(r==="crop"){D=null;return}if(r==="pen"&&S)S=!1,b.length>=4&&(s.push({type:"pen",points:[...b],color:o,width:n}),I.disabled=!1,b=[]);else if(r==="arrow"&&v)s.push({type:"arrow",x1:v.x,y1:v.y,x2:p,y2:f,color:o,width:n}),I.disabled=!1,v=null;else if(r==="rect"&&k){const m=Math.min(k.x,p),x=Math.min(k.y,f);s.push({type:"rect",x:m,y:x,w:Math.abs(p-k.x),h:Math.abs(f-k.y),color:o,width:n,radius:l}),I.disabled=!1,k=null}T()},E.onmouseleave=a=>{if(r==="select"&&_){_=null,E.classList.remove("select-mode-moving");return}E.onmouseup(a)};function Ot(){const a=new Image;a.onload=()=>{const p=document.createElement("canvas");p.width=a.naturalWidth,p.height=a.naturalHeight;const f=p.getContext("2d");if(!f)return;f.drawImage(a,0,0),s.forEach(x=>et(f,x));const m=p.toDataURL("image/png");re(),t(m)},a.onerror=()=>{re(),t(u)},a.src=u}ae=a=>{a.key==="Escape"?V?ie():r==="crop"&&M?(M=null,H.style.display="none",T()):C!==null?(C=null,T()):(re(),i()):a.key==="z"&&(a.ctrlKey||a.metaKey)&&!a.shiftKey?(a.preventDefault(),s.length>0&&(s.pop(),I.disabled=s.length===0,C=null,T())):(a.key==="Delete"||a.key==="Backspace")&&C!==null&&!V&&(a.preventDefault(),s.splice(C,1),I.disabled=s.length===0,C=null,T())},document.addEventListener("keydown",ae),new ResizeObserver(()=>{d&&h&&Ve()}).observe(E),Ke()}const Oe=3,ot=8,rt=14,fi=`<svg width="20" height="20" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
773
|
+
`;function ui(){if(document.getElementById(`${p}-styles`))return;const e=document.createElement("style");e.id=`${p}-styles`,e.textContent=pi,document.head.appendChild(e)}const Ne={select:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/><path d="M13 13l6 6"/></svg>',pen:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 19l7-7 3 3-7 7-3-3z"/><path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/></svg>',arrow:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M5 12h14"/><path d="M12 5l7 7-7 7"/></svg>',rect:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>',text:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M12 4v16"/></svg>',crop:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M6 3v18"/><path d="M18 3v18"/><path d="M3 6h18"/><path d="M3 18h18"/></svg>',close:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',undo:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 7v6h6"/><path d="M3 13a9 9 0 0 1 15.36-6.36"/></svg>'};function wt(e,t,i,r,o,n){const l=Math.min(n,Math.abs(r)/2,Math.abs(o)/2);e.beginPath(),e.moveTo(t+l,i),e.lineTo(t+r-l,i),e.arcTo(t+r,i,t+r,i+l,l),e.lineTo(t+r,i+o-l),e.arcTo(t+r,i+o,t+r-l,i+o,l),e.lineTo(t+l,i+o),e.arcTo(t,i+o,t,i+o-l,l),e.lineTo(t,i+l),e.arcTo(t,i,t+l,i,l),e.closePath(),e.stroke()}function et(e,t){if(e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth="width"in t?t.width:2,e.lineCap="round",e.lineJoin="round",t.type==="pen"&&t.points.length>=4){e.beginPath(),e.moveTo(t.points[0],t.points[1]);for(let i=2;i<t.points.length;i+=2)e.lineTo(t.points[i],t.points[i+1]);e.stroke()}else if(t.type==="arrow"){e.beginPath(),e.moveTo(t.x1,t.y1),e.lineTo(t.x2,t.y2),e.stroke();const i=10,r=Math.atan2(t.y2-t.y1,t.x2-t.x1);e.beginPath(),e.moveTo(t.x2,t.y2),e.lineTo(t.x2-i*Math.cos(r-.4),t.y2-i*Math.sin(r-.4)),e.lineTo(t.x2-i*Math.cos(r+.4),t.y2-i*Math.sin(r+.4)),e.closePath(),e.fill()}else t.type==="rect"?t.radius>0?wt(e,t.x,t.y,t.w,t.h,t.radius):e.strokeRect(t.x,t.y,t.w,t.h):t.type==="text"&&(e.font="16px system-ui, sans-serif",e.fillText(t.text,t.x,t.y+16))}function yt(e){if(e.type==="rect")return{x:e.x,y:e.y,w:e.w,h:e.h};if(e.type==="arrow"){const t=Math.min(e.x1,e.x2),i=Math.min(e.y1,e.y2);return{x:t,y:i,w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}}else if(e.type==="pen"&&e.points.length>=4){let t=e.points[0],i=e.points[0],r=e.points[1],o=e.points[1];for(let n=2;n<e.points.length;n+=2)t=Math.min(t,e.points[n]),i=Math.max(i,e.points[n]),r=Math.min(r,e.points[n+1]),o=Math.max(o,e.points[n+1]);return{x:t,y:r,w:i-t,h:o-r}}else if(e.type==="text")return{x:e.x,y:e.y,w:100,h:20};return{x:0,y:0,w:0,h:0}}function hi(e,t,i,r){const o=r;if(e.type==="rect"){const{x:n,y:l,w:s,h:m}=e,h=i>=l-o&&i<=l+o&&t>=n-o&&t<=n+s+o,u=i>=l+m-o&&i<=l+m+o&&t>=n-o&&t<=n+s+o,c=t>=n-o&&t<=n+o&&i>=l-o&&i<=l+m+o,g=t>=n+s-o&&t<=n+s+o&&i>=l-o&&i<=l+m+o,y=t>=n&&t<=n+s&&i>=l&&i<=l+m;return h||u||c||g||y}else{if(e.type==="arrow")return tt(t,i,e.x1,e.y1,e.x2,e.y2)<=o+e.width;if(e.type==="pen"&&e.points.length>=4){for(let n=0;n<e.points.length-2;n+=2)if(tt(t,i,e.points[n],e.points[n+1],e.points[n+2],e.points[n+3])<=o+e.width)return!0;return!1}else if(e.type==="text"){const n=yt(e);return t>=n.x-o&&t<=n.x+n.w+o&&i>=n.y-o&&i<=n.y+n.h+o}}return!1}function tt(e,t,i,r,o,n){const l=o-i,s=n-r,m=l*l+s*s;if(m===0)return Math.hypot(e-i,t-r);let h=((e-i)*l+(t-r)*s)/m;return h=Math.max(0,Math.min(1,h)),Math.hypot(e-(i+h*l),t-(r+h*s))}function gi(e,t,i){if(e.type==="rect")e.x+=t,e.y+=i;else if(e.type==="arrow")e.x1+=t,e.y1+=i,e.x2+=t,e.y2+=i;else if(e.type==="pen")for(let r=0;r<e.points.length;r+=2)e.points[r]+=t,e.points[r+1]+=i;else e.type==="text"&&(e.x+=t,e.y+=i)}function mi(e,t){const i=yt(t),r=6;e.save(),e.strokeStyle="#0091FF",e.lineWidth=1.5,e.setLineDash([4,3]),e.strokeRect(i.x-r,i.y-r,i.w+r*2,i.h+r*2),e.setLineDash([]);const o=5;e.fillStyle="#fff",e.strokeStyle="#0091FF",e.lineWidth=1.5;const n=[[i.x-r,i.y-r],[i.x+i.w+r,i.y-r],[i.x-r,i.y+i.h+r],[i.x+i.w+r,i.y+i.h+r]];for(const[l,s]of n)e.beginPath(),e.arc(l,s,o,0,Math.PI*2),e.fill(),e.stroke();e.restore()}function re(){K&&(ae&&(document.removeEventListener("keydown",ae),ae=null),document.body.style.overflow=ft,K.remove(),K=null)}function it(e,t,i){K&&(K.remove(),K=null),ui(),ft=document.body.style.overflow,document.body.style.overflow="hidden";let r="rect",o="#FF3B30",n=3,l=0,s=[],m=e,h=0,u=0,c=1,g=0,y=0,k=!1,b=[],x=null,E=null,C=null,_=null,M=null,D=null,V=null;const pe=document.createElement("div");pe.className=`${p}-backdrop`;const X=document.createElement("div");X.className=`${p}-modal`,X.onclick=a=>a.stopPropagation();const ue=document.createElement("div");ue.className=`${p}-header`;const Ie=document.createElement("span");Ie.className=`${p}-title`,Ie.textContent="Edit screenshot";const Z=document.createElement("button");Z.className=`${p}-close-btn`,Z.setAttribute("aria-label","Close"),Z.innerHTML=Ne.close,Z.onclick=()=>{re(),i()},ue.appendChild(Ie),ue.appendChild(Z);const S=document.createElement("div");S.className=`${p}-canvas-wrap`;const j=document.createElement("img");j.className=`${p}-img`,j.alt="Screenshot";const P=document.createElement("canvas");P.className=`${p}-canvas`,S.appendChild(j),S.appendChild(P);const ee=document.createElement("div");ee.className=`${p}-toolbar`;const O=document.createElement("div");O.className=`${p}-tools`;const Ae={},$t=["select","pen","arrow","rect","text","crop"],De={select:"Select & Move",pen:"Pen",arrow:"Arrow",rect:"Rectangle",text:"Text",crop:"Crop"};for(const a of $t){const d=document.createElement("button");d.className=`${p}-tool-btn${a==="rect"?" active":""}`,d.setAttribute("aria-label",De[a]),d.title=De[a],d.innerHTML=Ne[a],d.onclick=()=>Ye(a),Ae[a]=d,O.appendChild(d)}const We=document.createElement("div");We.className=`${p}-separator`,O.appendChild(We);const Rt=["#FF3B30","#FF9500","#FFCC00","#34C759","#0091FF","#AF52DE","#FF2D55","#000000","#8E8E93"],he=document.createElement("div");he.className=`${p}-color-swatches`;const Be=[];function Te(a){Be.forEach(d=>d.classList.toggle("active",d.dataset.color===a))}for(const a of Rt){const d=document.createElement("button");d.className=`${p}-swatch${a===o?" active":""}`,d.style.background=a,d.dataset.color=a,d.setAttribute("aria-label",`Color ${a}`),d.onclick=()=>{o=a,F.value=a,Te(a),ye("color",a)},Be.push(d),he.appendChild(d)}const F=document.createElement("input");F.type="color",F.value=o,F.className=`${p}-color-picker`,F.setAttribute("aria-label","Custom color"),F.title="Custom color",F.oninput=()=>{o=F.value,Te(""),ye("color",o)},he.appendChild(F),O.appendChild(he);const je=document.createElement("div");je.className=`${p}-separator`,O.appendChild(je);const ge=document.createElement("div");ge.className=`${p}-thickness-wrap`;const te=document.createElement("span");te.className=`${p}-thickness-label`,te.textContent="3px";const U=document.createElement("input");U.type="range",U.min="1",U.max="12",U.value=String(n),U.className=`${p}-thickness-slider`,U.setAttribute("aria-label","Stroke thickness"),U.oninput=()=>{n=parseInt(U.value,10),te.textContent=`${n}px`,ye("width",n)},ge.appendChild(U),ge.appendChild(te),O.appendChild(ge);const qe=document.createElement("div");qe.className=`${p}-separator`,O.appendChild(qe);const q=document.createElement("button");q.className=`${p}-radius-btn`,q.setAttribute("aria-label","Rounded corners"),q.title="Rounded corners",q.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 9a6 6 0 0 1 6-6h6a6 6 0 0 1 6 6v6a6 6 0 0 1-6 6H9a6 6 0 0 1-6-6V9z"/></svg>',q.onclick=()=>{l=l===0?12:0,q.classList.toggle("active",l>0),ye("radius",l)},O.appendChild(q);const Ge=document.createElement("div");Ge.className=`${p}-separator`,O.appendChild(Ge);const T=document.createElement("button");T.className=`${p}-undo-btn`,T.setAttribute("aria-label","Undo"),T.title="Undo",T.innerHTML=Ne.undo,T.disabled=!0,T.onclick=()=>{s.length>0&&(s.pop(),T.disabled=s.length===0,C=null,I())},O.appendChild(T);const H=document.createElement("button");H.className=`${p}-btn-crop-apply`,H.textContent="Apply crop",H.style.display="none",H.onclick=_t;const me=document.createElement("div");me.className=`${p}-actions`;const fe=document.createElement("button");fe.className=`${p}-btn-cancel`,fe.textContent="Cancel",fe.onclick=()=>{re(),i()};const we=document.createElement("button");we.className=`${p}-btn-done`,we.textContent="Done",we.onclick=Ot,me.appendChild(fe),me.appendChild(we),ee.appendChild(O),ee.appendChild(H),ee.appendChild(me),X.appendChild(ue),X.appendChild(S),X.appendChild(ee),pe.appendChild(X),document.body.appendChild(pe),K=pe;function Ye(a){r=a;for(const[d,w]of Object.entries(Ae))w.classList.toggle("active",d===a);a!=="crop"&&(M=null,D=null,H.style.display="none"),a!=="select"&&(C=null),S.classList.toggle("select-mode",a==="select"),S.classList.remove("select-mode-moving"),ie(),I()}function ye(a,d){if(C===null||C>=s.length)return;const w=s[C];a==="color"?w.color=d:a==="width"&&"width"in w?w.width=d:a==="radius"&&w.type==="rect"&&(w.radius=d),I()}function Nt(a){o=a.color,F.value=a.color,Te(a.color),"width"in a&&(n=a.width,U.value=String(a.width),te.textContent=`${a.width}px`),a.type==="rect"&&(l=a.radius,q.classList.toggle("active",a.radius>0))}function Le(a,d){const w=S.getBoundingClientRect();return{x:Math.round((a-w.left-g)/c),y:Math.round((d-w.top-y)/c)}}function Ve(){if(!h||!u)return;const a=S.clientWidth-32,d=S.clientHeight-32;c=Math.min(a/h,d/u,1),g=(S.clientWidth-h*c)/2,y=(S.clientHeight-u*c)/2,j.style.width=`${h*c}px`,j.style.height=`${u*c}px`,j.style.marginLeft=`${g}px`,j.style.marginTop=`${y}px`,P.width=S.clientWidth,P.height=S.clientHeight,I()}function Ke(){const a=new Image;a.onload=()=>{h=a.naturalWidth,u=a.naturalHeight,j.src=m,Ve()},a.src=m}function I(){const a=P.getContext("2d");if(a){if(a.clearRect(0,0,P.width,P.height),a.save(),a.translate(g,y),a.scale(c,c),s.forEach((d,w)=>{et(a,d),w===C&&mi(a,d)}),k&&b.length>=4&&r==="pen"){a.strokeStyle=o,a.lineWidth=n,a.lineCap="round",a.lineJoin="round",a.beginPath(),a.moveTo(b[0],b[1]);for(let d=2;d<b.length;d+=2)a.lineTo(b[d],b[d+1]);a.stroke()}if(a.restore(),r==="crop"&&M){a.fillStyle="rgba(0,0,0,0.4)",a.fillRect(0,0,P.width,P.height);const d=g+M.x*c,w=y+M.y*c,f=M.w*c,v=M.h*c;a.clearRect(d,w,f,v),a.strokeStyle="#0091FF",a.lineWidth=2,a.strokeRect(d,w,f,v),H.style.display=""}}}function _t(){if(!M||M.w<10||M.h<10)return;const a=new Image;a.onload=()=>{const d=document.createElement("canvas");d.width=M.w,d.height=M.h;const w=d.getContext("2d");w&&(w.drawImage(a,M.x,M.y,M.w,M.h,0,0,M.w,M.h),m=d.toDataURL("image/png"),s=[],T.disabled=!0,C=null,M=null,D=null,H.style.display="none",Ye("rect"),Ke())},a.src=m}function ie(){V&&(V.remove(),V=null)}function Pt(a,d){ie();const w=document.createElement("div");w.className=`${p}-text-overlay`,w.style.left=`${a*c+g}px`,w.style.top=`${d*c+y}px`;const f=document.createElement("input");f.type="text",f.className=`${p}-text-input`,f.placeholder="Text...";const v=document.createElement("button");v.className=`${p}-text-ok`,v.textContent="Add";const z=()=>{const G=f.value.trim();G&&(s.push({type:"text",x:a,y:d,text:G,color:o}),T.disabled=!1,I()),ie()};f.onkeydown=G=>{G.key==="Enter"&&z(),G.key==="Escape"&&ie()},v.onclick=z,w.appendChild(f),w.appendChild(v),S.appendChild(w),V=w,f.focus()}S.onmousedown=a=>{const{x:d,y:w}=Le(a.clientX,a.clientY);if(r==="select"){let f=-1;for(let v=s.length-1;v>=0;v--)if(hi(s[v],d,w,8)){f=v;break}f>=0?(C=f,_={x:d,y:w},Nt(s[f]),S.classList.add("select-mode-moving")):C=null,I();return}if(r==="crop"){D={x:d,y:w},M=null,H.style.display="none";return}V||(C=null,r==="pen"?(k=!0,b=[d,w]):r==="arrow"?x={x:d,y:w}:r==="rect"?E={x:d,y:w}:r==="text"&&Pt(d,w))},S.onmousemove=a=>{const{x:d,y:w}=Le(a.clientX,a.clientY);if(r==="select"&&_&&C!==null){const f=d-_.x,v=w-_.y;(Math.abs(f)>1||Math.abs(v)>1)&&(gi(s[C],f,v),_={x:d,y:w},I());return}if(r==="crop"&&D){const f=Math.min(D.x,d),v=Math.min(D.y,w);M={x:f,y:v,w:Math.max(20,Math.abs(d-D.x)),h:Math.max(20,Math.abs(w-D.y))},I()}else if(k&&r==="pen")b.push(d,w),I();else if(r==="rect"&&E){I();const f=P.getContext("2d");if(f){f.save(),f.translate(g,y),f.scale(c,c),f.strokeStyle=o,f.lineWidth=n,f.lineCap="round",f.lineJoin="round";const v=Math.min(E.x,d),z=Math.min(E.y,w),G=Math.abs(d-E.x),Je=Math.abs(w-E.y);l>0?wt(f,v,z,G,Je,l):f.strokeRect(v,z,G,Je),f.restore()}}else if(r==="arrow"&&x){I();const f=P.getContext("2d");if(f){f.save(),f.translate(g,y),f.scale(c,c),f.strokeStyle=o,f.fillStyle=o,f.lineWidth=n,f.lineCap="round",f.lineJoin="round",f.beginPath(),f.moveTo(x.x,x.y),f.lineTo(d,w),f.stroke();const v=10,z=Math.atan2(w-x.y,d-x.x);f.beginPath(),f.moveTo(d,w),f.lineTo(d-v*Math.cos(z-.4),w-v*Math.sin(z-.4)),f.lineTo(d-v*Math.cos(z+.4),w-v*Math.sin(z+.4)),f.closePath(),f.fill(),f.restore()}}},S.onmouseup=a=>{const{x:d,y:w}=Le(a.clientX,a.clientY);if(r==="select"){_=null,S.classList.remove("select-mode-moving");return}if(r==="crop"){D=null;return}if(r==="pen"&&k)k=!1,b.length>=4&&(s.push({type:"pen",points:[...b],color:o,width:n}),T.disabled=!1,b=[]);else if(r==="arrow"&&x)s.push({type:"arrow",x1:x.x,y1:x.y,x2:d,y2:w,color:o,width:n}),T.disabled=!1,x=null;else if(r==="rect"&&E){const f=Math.min(E.x,d),v=Math.min(E.y,w);s.push({type:"rect",x:f,y:v,w:Math.abs(d-E.x),h:Math.abs(w-E.y),color:o,width:n,radius:l}),T.disabled=!1,E=null}I()},S.onmouseleave=a=>{if(r==="select"&&_){_=null,S.classList.remove("select-mode-moving");return}S.onmouseup(a)};function Ot(){const a=new Image;a.onload=()=>{const d=document.createElement("canvas");d.width=a.naturalWidth,d.height=a.naturalHeight;const w=d.getContext("2d");if(!w)return;w.drawImage(a,0,0),s.forEach(v=>et(w,v));const f=d.toDataURL("image/png");re(),t(f)},a.onerror=()=>{re(),t(m)},a.src=m}ae=a=>{a.key==="Escape"?V?ie():r==="crop"&&M?(M=null,H.style.display="none",I()):C!==null?(C=null,I()):(re(),i()):a.key==="z"&&(a.ctrlKey||a.metaKey)&&!a.shiftKey?(a.preventDefault(),s.length>0&&(s.pop(),T.disabled=s.length===0,C=null,I())):(a.key==="Delete"||a.key==="Backspace")&&C!==null&&!V&&(a.preventDefault(),s.splice(C,1),T.disabled=s.length===0,C=null,I())},document.addEventListener("keydown",ae),new ResizeObserver(()=>{h&&u&&Ve()}).observe(S),Ke()}const Oe=3,ot=8,rt=14,fi=`<svg width="20" height="20" viewBox="0 0 200 200" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
774
774
|
<defs>
|
|
775
775
|
<linearGradient id="sw-preview-grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
776
776
|
<stop offset="0%" stop-color="#0091FF"/>
|
|
@@ -914,8 +914,8 @@
|
|
|
914
914
|
transition: opacity 150ms ease-out !important;
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
|
-
`,document.head.appendChild(e)}function Ce(){if(!(!N||$.length===0))if(le){let e=0;for(let t=0;t<$.length;t++){const{el:i,height:r}=$[t];i.style.zIndex=String(Oe+1-t),i.style.transform=`translateY(-${e}px) scale(1)`,i.style.opacity=i.dataset.visible==="true"?"1":"0",e+=r+ot}N.style.height=`${e-ot}px`}else{for(let e=0;e<$.length;e++){const{el:t}=$[e];t.style.zIndex=String(Oe+1-e),t.style.transform=`translateY(-${e*rt}px) scale(${1-e*.05})`,t.style.opacity=t.dataset.visible==="true"?"1":"0"}N.style.height=`${$[0].height+($.length-1)*rt}px`}}function yi(e){if(!Number.isFinite(e)||e<=0)return"just now";const t=Date.now(),i=e<1e12?e*1e3:e,r=Math.max(0,t-i),o=Math.floor(r/1e3);if(o<60)return"just now";const n=Math.floor(o/60);if(n<60)return`${n}m ago`;const l=Math.floor(n/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function bi(e,t){if(N)return N;const i=document.createElement("div");i.className="sw-preview-stack";const r=e.startsWith("bottom"),o=e.endsWith("right"),n=20,l=48,s=8;return r?i.style.bottom=`${n+l+s}px`:i.style.top=`${n+l+s}px`,o?i.style.right=`${n}px`:i.style.left=`${n}px`,i.addEventListener("mouseenter",()=>{le=!0,Ce()}),i.addEventListener("mouseleave",()=>{le=!1,Ce()}),Y=document.createElement("button"),Y.className=`sw-preview-dismiss sw-dismiss-${t}`,Y.setAttribute("aria-label","Dismiss all message previews"),Y.textContent="×",Y.addEventListener("click",u=>{u.stopPropagation(),ke()}),i.appendChild(Y),document.body.appendChild(i),N=i,i}function xi(e,t,i,r,o,n){wi();const l=bi(r,o);$.length>=Oe&&$.pop().el.remove();const s=document.createElement("div");s.className=`sw-preview-card sw-card-${o}`,s.dataset.visible="false";const u=document.createElement("div");u.className="sw-preview-header";const d=document.createElement("div");d.className="sw-preview-logo",d.innerHTML=fi;const h=document.createElement("div");h.className="sw-preview-meta",h.textContent=`${t||"Support"} · ${yi(i)}`,u.appendChild(d),u.appendChild(h);const g=document.createElement("div");g.className="sw-preview-body",g.textContent=e,s.appendChild(u),s.appendChild(g),s.addEventListener("click",()=>{ke(!0),n()}),l.appendChild(s);const w=s.offsetHeight;$.unshift({el:s,height:w}),Ce(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.dataset.visible="true",Ce()})})}function ke(e){if(e){for(const i of $)i.el.remove();$.length=0,N&&(N.remove(),N=null),Y=null,le=!1;return}const t=[...$];$.length=0;for(const i of t){i.el.dataset.visible="false",i.el.style.opacity="0";const r=()=>{i.el.removeEventListener("transitionend",r),i.el.remove()};i.el.addEventListener("transitionend",r),setTimeout(()=>i.el.remove(),300)}if(N){const i=N;N=null,Y=null,le=!1,setTimeout(()=>i.remove(),350)}}const bt="supportwire-event-rule-executions";function xt(){try{const e=localStorage.getItem(bt);return e?JSON.parse(e):{}}catch{return{}}}function He(e){return xt()[e]||0}function vi(e){try{const t=xt();t[e]=(t[e]||0)+1,localStorage.setItem(bt,JSON.stringify(t))}catch{}}function Ci(e){return e.max_executions==null||e.max_executions<=0?!1:He(e.id)>=e.max_executions}function ki(e,t){try{const i=n=>n.replace(/\/+$/,"");if(!t.includes("*"))return i(e)===i(t);const r=t.split("*").map(n=>{let l="";for(const s of n)"-/\\^$*+?.()|[]{}".indexOf(s)!==-1&&(l+="\\"),l+=s;return l}),o=new RegExp("^"+r.join(".*")+"$");return o.test(e)||o.test(i(e))}catch{return!1}}function Ei(e,t){var i;const r=[];for(const o of e){if(o.event_name!=="SW_PAGE_VIEW")continue;const n=(i=o.event_info)==null?void 0:i.url;if(n){if(Ci(o)){He(o.id);continue}ki(t,n)&&r.push({ruleId:o.id,delay:o.delay,messagesToSend:o.messages_to_send})}}return r}function Si(e,t){var i;for(const h of e)(i=h.event_info)!=null&&i.url,h.max_executions!=null&&String(h.max_executions),He(h.id);const r=new Set,o=new Set;let n="";function l(){const h=window.location.href;if(h===n)return;n=h;const g=Ei(e,h);for(const w of g){if(o.has(w.ruleId))continue;o.add(w.ruleId);const y=(w.delay||0)*1e3,S=setTimeout(()=>{r.delete(S),vi(w.ruleId),t(w)},y);r.add(S)}}const s=history.pushState.bind(history),u=history.replaceState.bind(history);history.pushState=function(...h){s(...h),l()},history.replaceState=function(...h){u(...h),l()};const d=()=>l();return window.addEventListener("popstate",d),l(),()=>{for(const h of r)clearTimeout(h);r.clear(),history.pushState=s,history.replaceState=u,window.removeEventListener("popstate",d)}}const Mi="supportwire",de=(e,t)=>`${Mi}-${t}-${e}`,_e=(e,t)=>{try{t?localStorage.setItem(de(e,"open"),"1"):localStorage.removeItem(de(e,"open"))}catch{}},Ti=e=>{try{return localStorage.getItem(de(e,"open"))==="1"}catch{return!1}},Ii=(e,t)=>{try{localStorage.setItem(de(e,"widget-size"),JSON.stringify(t))}catch{}},Li=e=>{try{const t=localStorage.getItem(de(e,"widget-size"));return t?JSON.parse(t):null}catch{return null}};var $i={success:{pattern:[{duration:30,intensity:.5},{delay:60,duration:40,intensity:1}]},warning:{pattern:[{duration:40,intensity:.8},{delay:100,duration:40,intensity:.6}]},error:{pattern:[{duration:40,intensity:.9},{delay:40,duration:40,intensity:.9},{delay:40,duration:40,intensity:.9}]},light:{pattern:[{duration:15,intensity:.4}]},medium:{pattern:[{duration:25,intensity:.7}]},heavy:{pattern:[{duration:35,intensity:1}]},soft:{pattern:[{duration:40,intensity:.5}]},rigid:{pattern:[{duration:10,intensity:1}]},selection:{pattern:[{duration:8,intensity:.3}]},nudge:{pattern:[{duration:80,intensity:.8},{delay:80,duration:50,intensity:.3}]},buzz:{pattern:[{duration:1e3,intensity:1}]}},Ri=16,Ni=184,st=1e3,xe=20;function _i(e){if(typeof e=="number")return{vibrations:[{duration:e}]};if(typeof e=="string"){let t=$i[e];return t?{vibrations:t.pattern.map(i=>A({},i))}:(console.warn(`[web-haptics] Unknown preset: "${e}"`),null)}if(Array.isArray(e)){if(e.length===0)return{vibrations:[]};if(typeof e[0]=="number"){let t=e,i=[];for(let r=0;r<t.length;r+=2){let o=r>0?t[r-1]:0;i.push(Se(A({},o>0&&{delay:o}),{duration:t[r]}))}return{vibrations:i}}return{vibrations:e.map(t=>A({},t))}}return{vibrations:e.pattern.map(t=>A({},t))}}function Pi(e,t){if(t>=1)return[e];if(t<=0)return[];let i=Math.max(1,Math.round(xe*t)),r=xe-i,o=[],n=e;for(;n>=xe;)o.push(i),o.push(r),n-=xe;if(n>0){let l=Math.max(1,Math.round(n*t));o.push(l);let s=n-l;s>0&&o.push(s)}return o}function Oi(e,t){var i,r;let o=[];for(let n=0;n<e.length;n++){let l=e[n],s=Math.max(0,Math.min(1,(i=l.intensity)!=null?i:t)),u=(r=l.delay)!=null?r:0;u>0&&(o.length>0&&o.length%2===0?o[o.length-1]+=u:(o.length===0&&o.push(0),o.push(u)));let d=Pi(l.duration,s);if(d.length===0){o.length>0&&o.length%2===0?o[o.length-1]+=l.duration:l.duration>0&&(o.push(0),o.push(l.duration));continue}for(let h of d)o.push(h)}return o}var Fi=0,Q,Ui=(Q=class{constructor(e){R(this,"hapticLabel",null),R(this,"domInitialized",!1),R(this,"instanceId"),R(this,"debug"),R(this,"showSwitch"),R(this,"rafId",null),R(this,"patternResolve",null),R(this,"audioCtx",null),R(this,"audioFilter",null),R(this,"audioGain",null),R(this,"audioBuffer",null);var t,i;this.instanceId=++Fi,this.debug=(t=e?.debug)!=null?t:!1,this.showSwitch=(i=e?.showSwitch)!=null?i:!1}async trigger(e=[{duration:25,intensity:.7}],t){var i,r,o,n;let l=_i(e);if(!l)return;let{vibrations:s}=l;if(s.length===0)return;let u=Math.max(0,Math.min(1,(i=t?.intensity)!=null?i:.5));for(let d of s)if(d.duration>st&&(d.duration=st),!Number.isFinite(d.duration)||d.duration<0||d.delay!==void 0&&(!Number.isFinite(d.delay)||d.delay<0)){console.warn("[web-haptics] Invalid vibration values. Durations and delays must be finite non-negative numbers.");return}if(Q.isSupported&&navigator.vibrate(Oi(s,u)),!Q.isSupported||this.debug){if(this.ensureDOM(),!this.hapticLabel)return;this.debug&&await this.ensureAudio(),this.stopPattern();let d=((o=(r=s[0])==null?void 0:r.delay)!=null?o:0)===0;if(d&&(this.hapticLabel.click(),this.debug&&this.audioCtx)){let h=Math.max(0,Math.min(1,(n=s[0].intensity)!=null?n:u));this.playClick(h)}await this.runPattern(s,u,d)}}cancel(){this.stopPattern(),Q.isSupported&&navigator.vibrate(0)}destroy(){this.stopPattern(),this.hapticLabel&&(this.hapticLabel.remove(),this.hapticLabel=null,this.domInitialized=!1),this.audioCtx&&(this.audioCtx.close(),this.audioCtx=null,this.audioFilter=null,this.audioGain=null,this.audioBuffer=null)}setDebug(e){this.debug=e,!e&&this.audioCtx&&(this.audioCtx.close(),this.audioCtx=null,this.audioFilter=null,this.audioGain=null,this.audioBuffer=null)}setShowSwitch(e){if(this.showSwitch=e,this.hapticLabel){let t=this.hapticLabel.querySelector("input");this.hapticLabel.style.display=e?"":"none",t&&(t.style.display=e?"":"none")}}stopPattern(){var e;this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),(e=this.patternResolve)==null||e.call(this),this.patternResolve=null}runPattern(e,t,i){return new Promise(r=>{var o,n;this.patternResolve=r;let l=[],s=0;for(let w of e){let y=Math.max(0,Math.min(1,(o=w.intensity)!=null?o:t)),S=(n=w.delay)!=null?n:0;S>0&&(s+=S,l.push({end:s,isOn:!1,intensity:0})),s+=w.duration,l.push({end:s,isOn:!0,intensity:y})}let u=s,d=0,h=-1,g=w=>{var y,S;d===0&&(d=w);let b=w-d;if(b>=u){this.rafId=null,this.patternResolve=null,r();return}let v=l[0];for(let k of l)if(b<k.end){v=k;break}if(v.isOn){let k=Ri+(1-v.intensity)*Ni;h===-1?(h=w,i||((y=this.hapticLabel)==null||y.click(),this.debug&&this.audioCtx&&this.playClick(v.intensity),i=!0)):w-h>=k&&((S=this.hapticLabel)==null||S.click(),this.debug&&this.audioCtx&&this.playClick(v.intensity),h=w)}this.rafId=requestAnimationFrame(g)};this.rafId=requestAnimationFrame(g)})}playClick(e){if(!this.audioCtx||!this.audioFilter||!this.audioGain||!this.audioBuffer)return;let t=this.audioBuffer.getChannelData(0);for(let n=0;n<t.length;n++)t[n]=(Math.random()*2-1)*Math.exp(-n/25);this.audioGain.gain.value=.5*e;let i=2e3+e*2e3,r=1+(Math.random()-.5)*.3;this.audioFilter.frequency.value=i*r;let o=this.audioCtx.createBufferSource();o.buffer=this.audioBuffer,o.connect(this.audioFilter),o.onended=()=>o.disconnect(),o.start()}async ensureAudio(){var e;if(!this.audioCtx&&typeof AudioContext<"u"){this.audioCtx=new AudioContext,this.audioFilter=this.audioCtx.createBiquadFilter(),this.audioFilter.type="bandpass",this.audioFilter.frequency.value=4e3,this.audioFilter.Q.value=8,this.audioGain=this.audioCtx.createGain(),this.audioFilter.connect(this.audioGain),this.audioGain.connect(this.audioCtx.destination);let t=.004;this.audioBuffer=this.audioCtx.createBuffer(1,this.audioCtx.sampleRate*t,this.audioCtx.sampleRate);let i=this.audioBuffer.getChannelData(0);for(let r=0;r<i.length;r++)i[r]=(Math.random()*2-1)*Math.exp(-r/25)}((e=this.audioCtx)==null?void 0:e.state)==="suspended"&&await this.audioCtx.resume()}ensureDOM(){if(this.domInitialized||typeof document>"u")return;let e=`web-haptics-${this.instanceId}`,t=document.createElement("label");t.setAttribute("for",e),t.textContent="Haptic feedback",t.style.position="fixed",t.style.bottom="10px",t.style.left="10px",t.style.padding="5px 10px",t.style.backgroundColor="rgba(0, 0, 0, 0.7)",t.style.color="white",t.style.fontFamily="sans-serif",t.style.fontSize="14px",t.style.borderRadius="4px",t.style.zIndex="9999",t.style.userSelect="none",this.hapticLabel=t;let i=document.createElement("input");i.type="checkbox",i.setAttribute("switch",""),i.id=e,i.style.all="initial",i.style.appearance="auto",this.showSwitch||(t.style.display="none",i.style.display="none"),t.appendChild(i),document.body.appendChild(t),this.domInitialized=!0}},R(Q,"isSupported",typeof navigator<"u"&&typeof navigator.vibrate=="function"),Q);const ne=new Ui,vt=class ve{constructor(t){var i,r,o;if(this.iframe=null,this.container=null,this.trigger=null,this.isOpen=!1,this.isExpanded=!1,this.messageHandler=null,this.unreadCount=0,this.titleModified=!1,this.visibilityHandler=null,this.eventRuleCleanup=null,this.triggerClickHandler=null,this.guideBridgeTeardown=null,!t.widgetSlug||typeof t.widgetSlug!="string"||t.widgetSlug.trim()==="")throw new Error("widgetSlug is required in widget config");this.config={widgetSlug:t.widgetSlug,appUrl:t.appUrl,selector:t.selector,theme:t.theme||"light",triggerPosition:t.triggerPosition||"bottom-right",widgetType:t.widgetType||"popup",userToken:t.userToken||"",userEmail:t.userEmail||"",userExternalUserId:t.userExternalUserId||"",userSignature:t.userSignature||"",userData:(i=t.userData)!=null?i:{},hideOnLaunch:(r=t.hideOnLaunch)!=null?r:!1,enableScreenshot:(o=t.enableScreenshot)!=null?o:!1,onOpen:t.onOpen||(()=>{}),onClose:t.onClose||(()=>{}),onError:t.onError||(n=>console.error("SupportWireWidget error:",n))},this.iframeId=Wt(),this.widgetUrl=this.buildWidgetUrl(),ve.instances.set(this.iframeId,this),this.init()}updateDocumentTitle(t){t>0&&document.hidden?(document.title=`(${t}) ${document.title.replace(/^\(\d+\) /,"")}`,this.titleModified=!0):this.titleModified&&(document.title=document.title.replace(/^\(\d+\) /,""),this.titleModified=!1)}getUnreadCountKey(){return`supportwire-unread-count-${this.config.widgetSlug}`}loadUnreadCountFromStorage(){if(typeof window>"u")return 0;try{const t=this.getUnreadCountKey(),i=localStorage.getItem(t);if(i){const r=parseInt(i,10);return isNaN(r)?0:r}}catch(t){console.error("Failed to load unread count from localStorage:",t)}return 0}saveUnreadCountToStorage(t){if(typeof window<"u")try{const i=this.getUnreadCountKey();t>0?localStorage.setItem(i,String(t)):localStorage.removeItem(i)}catch(i){console.error("Failed to save unread count to localStorage:",i)}}buildWidgetUrl(){return`${Dt(this.config.appUrl)}/w/${this.config.widgetSlug.trim()}/chat`}init(){try{this.unreadCount=this.loadUnreadCountFromStorage(),this.createContainer(),this.createIframe(),this.setupMessageHandler(),this.setupTrigger(),this.config.hideOnLaunch&&this.trigger&&(this.trigger.style.display="none"),this.unreadCount>0&&(this.trigger&&be(this.trigger,this.unreadCount),this.updateDocumentTitle(this.unreadCount)),this.visibilityHandler=()=>{!document.hidden&&this.titleModified&&this.updateDocumentTitle(0)},document.addEventListener("visibilitychange",this.visibilityHandler),Ti(this.config.widgetSlug)&&this.open()}catch(t){this.config.onError(t instanceof Error?t:new Error(String(t)))}}createContainer(){this.container=document.createElement("div"),this.container.id=`${this.config.widgetSlug}-container`,this.container.className=`supportwire-widget-container supportwire-${this.config.widgetType}`,Bt(),Qe(this.container,this.config);const t=Li(this.config.widgetSlug);t&&this.config.widgetType==="popup"&&(this.container.style.width=`${t.width}px`,this.container.style.height=`${t.height}px`),this.config.widgetType==="popup"&&this.addResizeHandle(this.container),this.config.widgetType==="popup"&&!this.config.selector&&Gt(this.container,this.config.triggerPosition,this.config.theme),document.body.appendChild(this.container)}createIframe(){this.container&&(this.iframe=ei(this.container,this.iframeId,this.widgetUrl,this.config.theme))}setupMessageHandler(){this.messageHandler=ii(this.iframeId,this.widgetUrl,this.container,{onReady:()=>{this.sendMessageToIframe({type:"CONFIG",config:{widgetSlug:this.config.widgetSlug,theme:this.config.theme,triggerPosition:this.config.triggerPosition,widgetType:this.config.widgetType,userToken:this.config.userToken,userEmail:this.config.userEmail,userSignature:this.config.userSignature,userData:this.config.userData,enableScreenshot:this.config.enableScreenshot}})},onOpen:()=>{this.isOpen=!0,this.unreadCount=0,this.saveUnreadCountToStorage(0),this.trigger&&be(this.trigger,0),this.config.onOpen()},onClose:()=>{this.isOpen=!1,_e(this.config.widgetSlug,!1),this.trigger&&($e(this.trigger,!1,this.config.theme),window.innerWidth<=480&&(this.trigger.style.display="")),this.config.onClose()},onError:this.config.onError,onUnreadCount:t=>{t>this.unreadCount&&ne.trigger("selection"),this.unreadCount=t,this.saveUnreadCountToStorage(t),this.trigger&&be(this.trigger,t),this.updateDocumentTitle(t)},onImagePreview:(t,i,r)=>{pi(t,i,r,o=>{it(o,n=>{this.sendMessageToIframe({type:"PAGE_SCREENSHOT_RESULT",payload:{dataUrl:n}})},()=>{})})},onToggleFullscreen:()=>{this.toggleExpand()},onMessagePreview:(t,i,r)=>{this.isOpen||xi(t,i,r,this.config.triggerPosition,this.config.theme,()=>this.open())},onScreenshotRequest:t=>{this.capturePageScreenshot(t)},onEventRulesRegistered:t=>{this.eventRuleCleanup&&(this.eventRuleCleanup(),this.eventRuleCleanup=null),t.length!==0&&(this.eventRuleCleanup=Si(t,i=>{this.sendMessageToIframe({type:"EVENT_RULE_MATCHED",eventRule:{ruleId:i.ruleId,delay:i.delay,messagesToSend:i.messagesToSend}})}))}}),window.addEventListener("message",this.messageHandler),this.iframe&&(this.guideBridgeTeardown=oi(this.iframe,this.iframeId).teardown)}setupTrigger(){if(this.triggerClickHandler=()=>this.toggle(),this.config.selector){const t=document.querySelector(this.config.selector);t?(this.trigger=t,this.trigger.addEventListener("click",this.triggerClickHandler)):(console.warn(`SupportWireWidget: Selector "${this.config.selector}" not found. Creating default trigger.`),this.createDefaultTrigger())}else this.createDefaultTrigger()}createDefaultTrigger(){this.triggerClickHandler||(this.triggerClickHandler=()=>this.toggle()),this.trigger=Xt(this.config,this.triggerClickHandler)}sendMessageToIframe(t){ti(this.iframe,this.iframeId,this.widgetUrl,t)}toggle(){this.isOpen?this.close():this.open()}open(){!this.container||!this.iframe||(ke(!0),this.showTrigger(),this.isOpen=!0,ne.trigger("medium"),_e(this.config.widgetSlug,!0),this.container.style.display="block",ht(this.container),this.unreadCount=0,this.saveUnreadCountToStorage(0),this.updateDocumentTitle(0),this.trigger&&(be(this.trigger,0),$e(this.trigger,!0,this.config.theme),window.innerWidth<=480&&(this.trigger.style.display="none")),this.sendMessageToIframe({type:"OPEN"}))}close(){this.container&&(this.isOpen=!1,ne.trigger("light"),_e(this.config.widgetSlug,!1),this.trigger&&($e(this.trigger,!1,this.config.theme),window.innerWidth<=480&&(this.trigger.style.display="")),gt(this.container),this.sendMessageToIframe({type:"CLOSE"}))}showTrigger(){this.trigger&&(this.trigger.style.display="")}hideTrigger(){this.trigger&&(this.trigger.style.display="none")}addResizeHandle(t){const i=document.createElement("div");i.innerHTML=`<svg width="10" height="10" viewBox="0 0 10 10" fill="none" style="opacity:0.3;transform:rotate(180deg)">
|
|
917
|
+
`,document.head.appendChild(e)}function Ce(){if(!(!N||$.length===0))if(le){let e=0;for(let t=0;t<$.length;t++){const{el:i,height:r}=$[t];i.style.zIndex=String(Oe+1-t),i.style.transform=`translateY(-${e}px) scale(1)`,i.style.opacity=i.dataset.visible==="true"?"1":"0",e+=r+ot}N.style.height=`${e-ot}px`}else{for(let e=0;e<$.length;e++){const{el:t}=$[e];t.style.zIndex=String(Oe+1-e),t.style.transform=`translateY(-${e*rt}px) scale(${1-e*.05})`,t.style.opacity=t.dataset.visible==="true"?"1":"0"}N.style.height=`${$[0].height+($.length-1)*rt}px`}}function yi(e){if(!Number.isFinite(e)||e<=0)return"just now";const t=Date.now(),i=e<1e12?e*1e3:e,r=Math.max(0,t-i),o=Math.floor(r/1e3);if(o<60)return"just now";const n=Math.floor(o/60);if(n<60)return`${n}m ago`;const l=Math.floor(n/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function bi(e,t){if(N)return N;const i=document.createElement("div");i.className="sw-preview-stack";const r=e.startsWith("bottom"),o=e.endsWith("right"),n=20,l=48,s=8;return r?i.style.bottom=`${n+l+s}px`:i.style.top=`${n+l+s}px`,o?i.style.right=`${n}px`:i.style.left=`${n}px`,i.addEventListener("mouseenter",()=>{le=!0,Ce()}),i.addEventListener("mouseleave",()=>{le=!1,Ce()}),Y=document.createElement("button"),Y.className=`sw-preview-dismiss sw-dismiss-${t}`,Y.setAttribute("aria-label","Dismiss all message previews"),Y.textContent="×",Y.addEventListener("click",m=>{m.stopPropagation(),ke()}),i.appendChild(Y),document.body.appendChild(i),N=i,i}function xi(e,t,i,r,o,n){wi();const l=bi(r,o);$.length>=Oe&&$.pop().el.remove();const s=document.createElement("div");s.className=`sw-preview-card sw-card-${o}`,s.dataset.visible="false";const m=document.createElement("div");m.className="sw-preview-header";const h=document.createElement("div");h.className="sw-preview-logo",h.innerHTML=fi;const u=document.createElement("div");u.className="sw-preview-meta",u.textContent=`${t||"Support"} · ${yi(i)}`,m.appendChild(h),m.appendChild(u);const c=document.createElement("div");c.className="sw-preview-body",c.textContent=e,s.appendChild(m),s.appendChild(c),s.addEventListener("click",()=>{ke(!0),n()}),l.appendChild(s);const g=s.offsetHeight;$.unshift({el:s,height:g}),Ce(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.dataset.visible="true",Ce()})})}function ke(e){if(e){for(const i of $)i.el.remove();$.length=0,N&&(N.remove(),N=null),Y=null,le=!1;return}const t=[...$];$.length=0;for(const i of t){i.el.dataset.visible="false",i.el.style.opacity="0";const r=()=>{i.el.removeEventListener("transitionend",r),i.el.remove()};i.el.addEventListener("transitionend",r),setTimeout(()=>i.el.remove(),300)}if(N){const i=N;N=null,Y=null,le=!1,setTimeout(()=>i.remove(),350)}}const bt="supportwire-event-rule-executions";function xt(){try{const e=localStorage.getItem(bt);return e?JSON.parse(e):{}}catch{return{}}}function He(e){return xt()[e]||0}function vi(e){try{const t=xt();t[e]=(t[e]||0)+1,localStorage.setItem(bt,JSON.stringify(t))}catch{}}function Ci(e){return e.max_executions==null||e.max_executions<=0?!1:He(e.id)>=e.max_executions}function ki(e,t){try{const i=n=>n.replace(/\/+$/,"");if(!t.includes("*"))return i(e)===i(t);const r=t.split("*").map(n=>{let l="";for(const s of n)"-/\\^$*+?.()|[]{}".indexOf(s)!==-1&&(l+="\\"),l+=s;return l}),o=new RegExp("^"+r.join(".*")+"$");return o.test(e)||o.test(i(e))}catch{return!1}}function Ei(e,t){var i;const r=[];for(const o of e){if(o.event_name!=="SW_PAGE_VIEW")continue;const n=(i=o.event_info)==null?void 0:i.url;if(n){if(Ci(o)){He(o.id);continue}ki(t,n)&&r.push({ruleId:o.id,delay:o.delay,messagesToSend:o.messages_to_send})}}return r}function Si(e,t){var i;for(const u of e)(i=u.event_info)!=null&&i.url,u.max_executions!=null&&String(u.max_executions),He(u.id);const r=new Set,o=new Set;let n="";function l(){const u=window.location.href;if(u===n)return;n=u;const c=Ei(e,u);for(const g of c){if(o.has(g.ruleId))continue;o.add(g.ruleId);const y=(g.delay||0)*1e3,k=setTimeout(()=>{r.delete(k),vi(g.ruleId),t(g)},y);r.add(k)}}const s=history.pushState.bind(history),m=history.replaceState.bind(history);history.pushState=function(...u){s(...u),l()},history.replaceState=function(...u){m(...u),l()};const h=()=>l();return window.addEventListener("popstate",h),l(),()=>{for(const u of r)clearTimeout(u);r.clear(),history.pushState=s,history.replaceState=m,window.removeEventListener("popstate",h)}}const Mi="supportwire",de=(e,t)=>`${Mi}-${t}-${e}`,_e=(e,t)=>{try{t?localStorage.setItem(de(e,"open"),"1"):localStorage.removeItem(de(e,"open"))}catch{}},Ii=e=>{try{return localStorage.getItem(de(e,"open"))==="1"}catch{return!1}},Ti=(e,t)=>{try{localStorage.setItem(de(e,"widget-size"),JSON.stringify(t))}catch{}},Li=e=>{try{const t=localStorage.getItem(de(e,"widget-size"));return t?JSON.parse(t):null}catch{return null}};var $i={success:{pattern:[{duration:30,intensity:.5},{delay:60,duration:40,intensity:1}]},warning:{pattern:[{duration:40,intensity:.8},{delay:100,duration:40,intensity:.6}]},error:{pattern:[{duration:40,intensity:.9},{delay:40,duration:40,intensity:.9},{delay:40,duration:40,intensity:.9}]},light:{pattern:[{duration:15,intensity:.4}]},medium:{pattern:[{duration:25,intensity:.7}]},heavy:{pattern:[{duration:35,intensity:1}]},soft:{pattern:[{duration:40,intensity:.5}]},rigid:{pattern:[{duration:10,intensity:1}]},selection:{pattern:[{duration:8,intensity:.3}]},nudge:{pattern:[{duration:80,intensity:.8},{delay:80,duration:50,intensity:.3}]},buzz:{pattern:[{duration:1e3,intensity:1}]}},Ri=16,Ni=184,st=1e3,xe=20;function _i(e){if(typeof e=="number")return{vibrations:[{duration:e}]};if(typeof e=="string"){let t=$i[e];return t?{vibrations:t.pattern.map(i=>A({},i))}:(console.warn(`[web-haptics] Unknown preset: "${e}"`),null)}if(Array.isArray(e)){if(e.length===0)return{vibrations:[]};if(typeof e[0]=="number"){let t=e,i=[];for(let r=0;r<t.length;r+=2){let o=r>0?t[r-1]:0;i.push(Se(A({},o>0&&{delay:o}),{duration:t[r]}))}return{vibrations:i}}return{vibrations:e.map(t=>A({},t))}}return{vibrations:e.pattern.map(t=>A({},t))}}function Pi(e,t){if(t>=1)return[e];if(t<=0)return[];let i=Math.max(1,Math.round(xe*t)),r=xe-i,o=[],n=e;for(;n>=xe;)o.push(i),o.push(r),n-=xe;if(n>0){let l=Math.max(1,Math.round(n*t));o.push(l);let s=n-l;s>0&&o.push(s)}return o}function Oi(e,t){var i,r;let o=[];for(let n=0;n<e.length;n++){let l=e[n],s=Math.max(0,Math.min(1,(i=l.intensity)!=null?i:t)),m=(r=l.delay)!=null?r:0;m>0&&(o.length>0&&o.length%2===0?o[o.length-1]+=m:(o.length===0&&o.push(0),o.push(m)));let h=Pi(l.duration,s);if(h.length===0){o.length>0&&o.length%2===0?o[o.length-1]+=l.duration:l.duration>0&&(o.push(0),o.push(l.duration));continue}for(let u of h)o.push(u)}return o}var Fi=0,Q,Ui=(Q=class{constructor(e){R(this,"hapticLabel",null),R(this,"domInitialized",!1),R(this,"instanceId"),R(this,"debug"),R(this,"showSwitch"),R(this,"rafId",null),R(this,"patternResolve",null),R(this,"audioCtx",null),R(this,"audioFilter",null),R(this,"audioGain",null),R(this,"audioBuffer",null);var t,i;this.instanceId=++Fi,this.debug=(t=e?.debug)!=null?t:!1,this.showSwitch=(i=e?.showSwitch)!=null?i:!1}async trigger(e=[{duration:25,intensity:.7}],t){var i,r,o,n;let l=_i(e);if(!l)return;let{vibrations:s}=l;if(s.length===0)return;let m=Math.max(0,Math.min(1,(i=t?.intensity)!=null?i:.5));for(let h of s)if(h.duration>st&&(h.duration=st),!Number.isFinite(h.duration)||h.duration<0||h.delay!==void 0&&(!Number.isFinite(h.delay)||h.delay<0)){console.warn("[web-haptics] Invalid vibration values. Durations and delays must be finite non-negative numbers.");return}if(Q.isSupported&&navigator.vibrate(Oi(s,m)),!Q.isSupported||this.debug){if(this.ensureDOM(),!this.hapticLabel)return;this.debug&&await this.ensureAudio(),this.stopPattern();let h=((o=(r=s[0])==null?void 0:r.delay)!=null?o:0)===0;if(h&&(this.hapticLabel.click(),this.debug&&this.audioCtx)){let u=Math.max(0,Math.min(1,(n=s[0].intensity)!=null?n:m));this.playClick(u)}await this.runPattern(s,m,h)}}cancel(){this.stopPattern(),Q.isSupported&&navigator.vibrate(0)}destroy(){this.stopPattern(),this.hapticLabel&&(this.hapticLabel.remove(),this.hapticLabel=null,this.domInitialized=!1),this.audioCtx&&(this.audioCtx.close(),this.audioCtx=null,this.audioFilter=null,this.audioGain=null,this.audioBuffer=null)}setDebug(e){this.debug=e,!e&&this.audioCtx&&(this.audioCtx.close(),this.audioCtx=null,this.audioFilter=null,this.audioGain=null,this.audioBuffer=null)}setShowSwitch(e){if(this.showSwitch=e,this.hapticLabel){let t=this.hapticLabel.querySelector("input");this.hapticLabel.style.display=e?"":"none",t&&(t.style.display=e?"":"none")}}stopPattern(){var e;this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),(e=this.patternResolve)==null||e.call(this),this.patternResolve=null}runPattern(e,t,i){return new Promise(r=>{var o,n;this.patternResolve=r;let l=[],s=0;for(let g of e){let y=Math.max(0,Math.min(1,(o=g.intensity)!=null?o:t)),k=(n=g.delay)!=null?n:0;k>0&&(s+=k,l.push({end:s,isOn:!1,intensity:0})),s+=g.duration,l.push({end:s,isOn:!0,intensity:y})}let m=s,h=0,u=-1,c=g=>{var y,k;h===0&&(h=g);let b=g-h;if(b>=m){this.rafId=null,this.patternResolve=null,r();return}let x=l[0];for(let E of l)if(b<E.end){x=E;break}if(x.isOn){let E=Ri+(1-x.intensity)*Ni;u===-1?(u=g,i||((y=this.hapticLabel)==null||y.click(),this.debug&&this.audioCtx&&this.playClick(x.intensity),i=!0)):g-u>=E&&((k=this.hapticLabel)==null||k.click(),this.debug&&this.audioCtx&&this.playClick(x.intensity),u=g)}this.rafId=requestAnimationFrame(c)};this.rafId=requestAnimationFrame(c)})}playClick(e){if(!this.audioCtx||!this.audioFilter||!this.audioGain||!this.audioBuffer)return;let t=this.audioBuffer.getChannelData(0);for(let n=0;n<t.length;n++)t[n]=(Math.random()*2-1)*Math.exp(-n/25);this.audioGain.gain.value=.5*e;let i=2e3+e*2e3,r=1+(Math.random()-.5)*.3;this.audioFilter.frequency.value=i*r;let o=this.audioCtx.createBufferSource();o.buffer=this.audioBuffer,o.connect(this.audioFilter),o.onended=()=>o.disconnect(),o.start()}async ensureAudio(){var e;if(!this.audioCtx&&typeof AudioContext<"u"){this.audioCtx=new AudioContext,this.audioFilter=this.audioCtx.createBiquadFilter(),this.audioFilter.type="bandpass",this.audioFilter.frequency.value=4e3,this.audioFilter.Q.value=8,this.audioGain=this.audioCtx.createGain(),this.audioFilter.connect(this.audioGain),this.audioGain.connect(this.audioCtx.destination);let t=.004;this.audioBuffer=this.audioCtx.createBuffer(1,this.audioCtx.sampleRate*t,this.audioCtx.sampleRate);let i=this.audioBuffer.getChannelData(0);for(let r=0;r<i.length;r++)i[r]=(Math.random()*2-1)*Math.exp(-r/25)}((e=this.audioCtx)==null?void 0:e.state)==="suspended"&&await this.audioCtx.resume()}ensureDOM(){if(this.domInitialized||typeof document>"u")return;let e=`web-haptics-${this.instanceId}`,t=document.createElement("label");t.setAttribute("for",e),t.textContent="Haptic feedback",t.style.position="fixed",t.style.bottom="10px",t.style.left="10px",t.style.padding="5px 10px",t.style.backgroundColor="rgba(0, 0, 0, 0.7)",t.style.color="white",t.style.fontFamily="sans-serif",t.style.fontSize="14px",t.style.borderRadius="4px",t.style.zIndex="9999",t.style.userSelect="none",this.hapticLabel=t;let i=document.createElement("input");i.type="checkbox",i.setAttribute("switch",""),i.id=e,i.style.all="initial",i.style.appearance="auto",this.showSwitch||(t.style.display="none",i.style.display="none"),t.appendChild(i),document.body.appendChild(t),this.domInitialized=!0}},R(Q,"isSupported",typeof navigator<"u"&&typeof navigator.vibrate=="function"),Q);const ne=new Ui,vt=class ve{constructor(t){var i,r,o;if(this.iframe=null,this.container=null,this.trigger=null,this.isOpen=!1,this.isExpanded=!1,this.messageHandler=null,this.unreadCount=0,this.titleModified=!1,this.visibilityHandler=null,this.eventRuleCleanup=null,this.triggerClickHandler=null,this.guideBridgeTeardown=null,!t.widgetSlug||typeof t.widgetSlug!="string"||t.widgetSlug.trim()==="")throw new Error("widgetSlug is required in widget config");this.config={widgetSlug:t.widgetSlug,appUrl:t.appUrl,selector:t.selector,theme:t.theme||"light",triggerPosition:t.triggerPosition||"bottom-right",widgetType:t.widgetType||"popup",userToken:t.userToken||"",userEmail:t.userEmail||"",userExternalUserId:t.userExternalUserId||"",userSignature:t.userSignature||"",userData:(i=t.userData)!=null?i:{},hideOnLaunch:(r=t.hideOnLaunch)!=null?r:!1,enableScreenshot:(o=t.enableScreenshot)!=null?o:!1,onOpen:t.onOpen||(()=>{}),onClose:t.onClose||(()=>{}),onError:t.onError||(n=>console.error("SupportWireWidget error:",n))},this.iframeId=Wt(),this.widgetUrl=this.buildWidgetUrl(),ve.instances.set(this.iframeId,this),this.init()}updateDocumentTitle(t){t>0&&document.hidden?(document.title=`(${t}) ${document.title.replace(/^\(\d+\) /,"")}`,this.titleModified=!0):this.titleModified&&(document.title=document.title.replace(/^\(\d+\) /,""),this.titleModified=!1)}getUnreadCountKey(){return`supportwire-unread-count-${this.config.widgetSlug}`}loadUnreadCountFromStorage(){if(typeof window>"u")return 0;try{const t=this.getUnreadCountKey(),i=localStorage.getItem(t);if(i){const r=parseInt(i,10);return isNaN(r)?0:r}}catch(t){console.error("Failed to load unread count from localStorage:",t)}return 0}saveUnreadCountToStorage(t){if(typeof window<"u")try{const i=this.getUnreadCountKey();t>0?localStorage.setItem(i,String(t)):localStorage.removeItem(i)}catch(i){console.error("Failed to save unread count to localStorage:",i)}}buildWidgetUrl(){return`${Dt(this.config.appUrl)}/w/${this.config.widgetSlug.trim()}/chat`}init(){try{this.unreadCount=this.loadUnreadCountFromStorage(),this.createContainer(),this.createIframe(),this.setupMessageHandler(),this.setupTrigger(),this.config.hideOnLaunch&&this.trigger&&(this.trigger.style.display="none"),this.unreadCount>0&&(this.trigger&&be(this.trigger,this.unreadCount),this.updateDocumentTitle(this.unreadCount)),this.visibilityHandler=()=>{!document.hidden&&this.titleModified&&this.updateDocumentTitle(0)},document.addEventListener("visibilitychange",this.visibilityHandler),Ii(this.config.widgetSlug)&&this.open()}catch(t){this.config.onError(t instanceof Error?t:new Error(String(t)))}}createContainer(){this.container=document.createElement("div"),this.container.id=`${this.config.widgetSlug}-container`,this.container.className=`supportwire-widget-container supportwire-${this.config.widgetType}`,Bt(),Qe(this.container,this.config);const t=Li(this.config.widgetSlug);t&&this.config.widgetType==="popup"&&(this.container.style.width=`${t.width}px`,this.container.style.height=`${t.height}px`),this.config.widgetType==="popup"&&this.addResizeHandle(this.container),this.config.widgetType==="popup"&&!this.config.selector&&Gt(this.container,this.config.triggerPosition,this.config.theme),document.body.appendChild(this.container)}createIframe(){this.container&&(this.iframe=ei(this.container,this.iframeId,this.widgetUrl,this.config.theme))}setupMessageHandler(){this.messageHandler=ii(this.iframeId,this.widgetUrl,this.container,{onReady:()=>{this.sendMessageToIframe({type:"CONFIG",config:{widgetSlug:this.config.widgetSlug,theme:this.config.theme,triggerPosition:this.config.triggerPosition,widgetType:this.config.widgetType,userToken:this.config.userToken,userEmail:this.config.userEmail,userSignature:this.config.userSignature,userData:this.config.userData,enableScreenshot:this.config.enableScreenshot}})},onOpen:()=>{this.isOpen=!0,this.unreadCount=0,this.saveUnreadCountToStorage(0),this.trigger&&be(this.trigger,0),this.config.onOpen()},onClose:()=>{this.isOpen=!1,_e(this.config.widgetSlug,!1),this.trigger&&($e(this.trigger,!1,this.config.theme),window.innerWidth<=480&&(this.trigger.style.display="")),this.config.onClose()},onError:this.config.onError,onUnreadCount:t=>{t>this.unreadCount&&ne.trigger("selection"),this.unreadCount=t,this.saveUnreadCountToStorage(t),this.trigger&&be(this.trigger,t),this.updateDocumentTitle(t)},onImagePreview:(t,i,r)=>{ci(t,i,r,o=>{it(o,n=>{this.sendMessageToIframe({type:"PAGE_SCREENSHOT_RESULT",payload:{dataUrl:n}})},()=>{})})},onToggleFullscreen:()=>{this.toggleExpand()},onMessagePreview:(t,i,r)=>{this.isOpen||xi(t,i,r,this.config.triggerPosition,this.config.theme,()=>this.open())},onScreenshotRequest:t=>{this.capturePageScreenshot(t)},onEventRulesRegistered:t=>{this.eventRuleCleanup&&(this.eventRuleCleanup(),this.eventRuleCleanup=null),t.length!==0&&(this.eventRuleCleanup=Si(t,i=>{this.sendMessageToIframe({type:"EVENT_RULE_MATCHED",eventRule:{ruleId:i.ruleId,delay:i.delay,messagesToSend:i.messagesToSend}})}))}}),window.addEventListener("message",this.messageHandler),this.iframe&&(this.guideBridgeTeardown=oi(this.iframe,this.iframeId,{closeWidget:()=>{this.isOpen&&this.close()}}).teardown)}setupTrigger(){if(this.triggerClickHandler=()=>this.toggle(),this.config.selector){const t=document.querySelector(this.config.selector);t?(this.trigger=t,this.trigger.addEventListener("click",this.triggerClickHandler)):(console.warn(`SupportWireWidget: Selector "${this.config.selector}" not found. Creating default trigger.`),this.createDefaultTrigger())}else this.createDefaultTrigger()}createDefaultTrigger(){this.triggerClickHandler||(this.triggerClickHandler=()=>this.toggle()),this.trigger=Xt(this.config,this.triggerClickHandler)}sendMessageToIframe(t){ti(this.iframe,this.iframeId,this.widgetUrl,t)}toggle(){this.isOpen?this.close():this.open()}open(){!this.container||!this.iframe||(ke(!0),this.showTrigger(),this.isOpen=!0,ne.trigger("medium"),_e(this.config.widgetSlug,!0),this.container.style.display="block",ht(this.container),this.unreadCount=0,this.saveUnreadCountToStorage(0),this.updateDocumentTitle(0),this.trigger&&(be(this.trigger,0),$e(this.trigger,!0,this.config.theme),window.innerWidth<=480&&(this.trigger.style.display="none")),this.sendMessageToIframe({type:"OPEN"}))}close(){this.container&&(this.isOpen=!1,ne.trigger("light"),_e(this.config.widgetSlug,!1),this.trigger&&($e(this.trigger,!1,this.config.theme),window.innerWidth<=480&&(this.trigger.style.display="")),gt(this.container),this.sendMessageToIframe({type:"CLOSE"}))}showTrigger(){this.trigger&&(this.trigger.style.display="")}hideTrigger(){this.trigger&&(this.trigger.style.display="none")}addResizeHandle(t){const i=document.createElement("div");i.innerHTML=`<svg width="10" height="10" viewBox="0 0 10 10" fill="none" style="opacity:0.3;transform:rotate(180deg)">
|
|
918
918
|
<line x1="9" y1="1" x2="1" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
|
919
919
|
<line x1="9" y1="5" x2="5" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
|
920
|
-
</svg>`,Object.assign(i.style,{position:"absolute",top:"4px",left:"4px",width:"20px",height:"20px",cursor:"nw-resize",zIndex:"10",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--muted-foreground, #999)",borderRadius:"4px"}),i.addEventListener("mouseenter",()=>{const g=i.querySelector("svg");g&&(g.style.opacity="0.6")}),i.addEventListener("mouseleave",()=>{const g=i.querySelector("svg");g&&(g.style.opacity="0.3")});const r=320,o=700,n=400;i.addEventListener("dblclick",g=>{g.stopPropagation(),ne.trigger("light"),window.matchMedia("(prefers-reduced-motion: reduce)").matches||(t.style.willChange="width, height",t.style.transition="width 250ms cubic-bezier(0.22, 1, 0.36, 1), height 250ms cubic-bezier(0.22, 1, 0.36, 1), max-height 250ms cubic-bezier(0.22, 1, 0.36, 1)",setTimeout(()=>{t.style.willChange="",t.style.transition="width 200ms ease-out, height 200ms ease-out"},270)),t.style.width="min(400px, max(0px, -20px + 100vw))",t.style.height="min(704px, 100% - 104px)",t.style.maxHeight="704px";try{localStorage.removeItem(`supportwire-widget-size-${this.config.widgetSlug}`)}catch{}});let l=!1,s=0,u=0,d=0,h=0;i.addEventListener("pointerdown",g=>{g.stopPropagation(),g.preventDefault(),l=!0,s=g.clientX,u=g.clientY;const w=t.getBoundingClientRect();d=w.width,h=w.height,i.setPointerCapture(g.pointerId),t.style.transition="none"}),i.addEventListener("pointermove",g=>{if(!l)return;const w=s-g.clientX,y=u-g.clientY,S=parseInt(t.style.right)||20,b=parseInt(t.style.bottom)||84,v=Math.min(o,window.innerWidth-S-20),k=window.innerHeight-b-20,C=Math.max(r,Math.min(v,d+w)),_=Math.max(n,Math.min(k,h+y));t.style.width=`${C}px`,t.style.height=`${_}px`,t.style.maxHeight=`${_}px`}),i.addEventListener("pointerup",g=>{if(!l)return;l=!1,i.releasePointerCapture(g.pointerId),t.style.transition="";const w=t.getBoundingClientRect();Ii(this.config.widgetSlug,{width:Math.round(w.width),height:Math.round(w.height)})}),t.appendChild(i)}toggleExpand(){this.container&&(ne.trigger("medium"),window.matchMedia("(prefers-reduced-motion: reduce)").matches||(this.container.style.willChange="width, height",this.container.style.transition="width 300ms cubic-bezier(0.22, 1, 0.36, 1), height 300ms cubic-bezier(0.22, 1, 0.36, 1), max-height 300ms cubic-bezier(0.22, 1, 0.36, 1), bottom 300ms cubic-bezier(0.22, 1, 0.36, 1)",setTimeout(()=>{this.container&&(this.container.style.willChange="",this.container.style.transition="width 200ms ease-out, height 200ms ease-out")},320)),this.isExpanded?(this.container.style.width="min(400px, max(0px, -20px + 100vw))",this.container.style.height="min(704px, 100% - 104px)",this.container.style.maxHeight="704px",this.container.style.bottom="84px",this.isExpanded=!1):(this.container.style.width="min(688px, max(0px, -20px + 100vw))",this.container.style.height="calc(100% - 40px)",this.container.style.maxHeight="calc(100% - 40px)",this.container.style.bottom="20px",this.isExpanded=!0))}async capturePageScreenshot(t){var i,r;try{const o=(i=this.container)==null?void 0:i.style.display,n=(r=this.trigger)==null?void 0:r.style.display;this.container&&(this.container.style.display="none"),this.trigger&&(this.trigger.style.display="none");const{snapdom:l}=await Promise.resolve().then(()=>require("./snapdom-6yvsn_Iv-OVmChxqF.cjs")),s=(await l.toCanvas(document.documentElement,{scale:1})).toDataURL("image/png");this.container&&(this.container.style.display=o??""),this.trigger&&(this.trigger.style.display=n??""),it(s,u=>{this.sendMessageToIframe({type:"PAGE_SCREENSHOT_RESULT",payload:{dataUrl:u}})},()=>{this.sendMessageToIframe({type:"PAGE_SCREENSHOT_ERROR",payload:{error:"Screenshot cancelled"}})})}catch(o){this.container&&(this.container.style.display=""),this.trigger&&(this.trigger.style.display="");const n=o instanceof Error?o.message:"Screenshot capture failed";this.sendMessageToIframe({type:"PAGE_SCREENSHOT_ERROR",payload:{error:n}})}}updateConfig(t){const i=A({},this.config);t.appUrl!==void 0&&(this.config.appUrl=t.appUrl),t.theme!==void 0&&(this.config.theme=t.theme),t.triggerPosition!==void 0&&(this.config.triggerPosition=t.triggerPosition),t.widgetType!==void 0&&(this.config.widgetType=t.widgetType),t.userToken!==void 0&&(this.config.userToken=t.userToken),t.userEmail!==void 0&&(this.config.userEmail=t.userEmail),t.userSignature!==void 0&&(this.config.userSignature=t.userSignature),t.userData!==void 0&&(this.config.userData=t.userData),t.onOpen!==void 0&&(this.config.onOpen=t.onOpen),t.onClose!==void 0&&(this.config.onClose=t.onClose),t.onError!==void 0&&(this.config.onError=t.onError),t.hideOnLaunch!==void 0&&(this.config.hideOnLaunch=t.hideOnLaunch,this.trigger&&(this.trigger.style.display=t.hideOnLaunch?"none":"")),t.enableScreenshot!==void 0&&(this.config.enableScreenshot=t.enableScreenshot);const r=t.appUrl!==void 0&&t.appUrl!==i.appUrl,o=t.theme!==void 0&&t.theme!==i.theme;(r||o)&&(o&&this.sendMessageToIframe({type:"THEME",theme:t.theme}),this.iframe&&(this.widgetUrl=this.buildWidgetUrl(),this.iframe.src=`${this.widgetUrl}?iframeId=${this.iframeId}&theme=${this.config.theme}`)),t.widgetType!==void 0&&t.widgetType!==i.widgetType&&this.container&&Qe(this.container,this.config),t.triggerPosition!==void 0&&this.trigger&&!this.config.selector&&(Qt(this.trigger,this.config.triggerPosition),this.config.widgetType==="popup"&&this.container&&Yt(this.container,this.config.triggerPosition,this.config.widgetType)),this.sendMessageToIframe({type:"UPDATE_CONFIG",config:t})}sendMessage(t,i){if(!t||typeof t!="string"||t.trim()===""){this.config.onError(new Error("Message must be a non-empty string"));return}i?.openWidget!==!1&&!this.isOpen&&this.open(),this.sendMessageToIframe({type:"SEND_MESSAGE",message:t,openWidget:i?.openWidget})}destroy(){ke(!0),this.updateDocumentTitle(0),this.eventRuleCleanup&&(this.eventRuleCleanup(),this.eventRuleCleanup=null),this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.guideBridgeTeardown&&(this.guideBridgeTeardown(),this.guideBridgeTeardown=null),this.trigger&&this.triggerClickHandler&&this.trigger.removeEventListener("click",this.triggerClickHandler),this.trigger&&!this.config.selector&&this.trigger.remove(),this.trigger=null,this.triggerClickHandler=null,this.container&&(this.container.remove(),this.container=null),this.iframe=null,this.isOpen=!1,ve.instances.delete(this.iframeId)}static getInstances(t){const i=Array.from(ve.instances.values());return t!==void 0?i.filter(r=>r.config.widgetSlug===t):i}};vt.instances=new Map;let Hi=vt;const zi=["app_id","user_id","email","user_hash","name","created_at","phone","avatar","unsubscribed_from_emails","language_override","utm_campaign","utm_content","utm_medium","utm_source","utm_term","page_title","company","companies","alignment","horizontal_padding","vertical_padding","hide_default_launcher","hide_notifications","custom_launcher_selector","z_index","action_color","background_color","link_color","theme_mode","session_duration","region","api_base"];function Ct(e){const t={};for(const[i,r]of Object.entries(e))zi.includes(i)||(t[i]=r);return e.name!==void 0&&(t.name=e.name),e.phone!==void 0&&(t.phone=e.phone),e.created_at!==void 0&&(t.created_at=e.created_at),e.company!==void 0&&(t.company=e.company),e.companies!==void 0&&(t.companies=e.companies),e.unsubscribed_from_emails!==void 0&&(t.unsubscribed_from_emails=e.unsubscribed_from_emails),{widgetSlug:String(e.app_id),userEmail:typeof e.email=="string"?e.email:void 0,userExternalUserId:typeof e.user_id=="string"?e.user_id:void 0,userSignature:typeof e.user_hash=="string"?e.user_hash:void 0,userData:t,theme:e.theme_mode==="dark"||e.theme_mode==="light"?e.theme_mode:void 0,selector:typeof e.custom_launcher_selector=="string"?e.custom_launcher_selector:void 0,hideOnLaunch:typeof e.hide_default_launcher=="boolean"?e.hide_default_launcher:void 0,triggerPosition:Ai(e.alignment)}}function Ai(e){if(e==="left")return"bottom-left";if(e==="right")return"bottom-right"}let L=null,J=null;const Fe=new Set,Ue=new Set,at=new Set,Ee=new Set;let kt=0,pe=null;function Di(){if(typeof window>"u")return lt();if(window.SupportWireMessenger)return window.SupportWireMessenger;const e=lt();return window.SupportWireMessenger=e,e}function lt(){const e=[],t=(...i)=>{e.push(i)};return t.q=e,t}function Wi(){if(typeof window>"u")return;const e=window.SupportWireMessenger;if(!e||!e.q)return;const t=e.q.slice();e.q.length=0;const i=(...r)=>{const[o,...n]=r;dt(o,...n)};i.q=[],window.SupportWireMessenger=i;for(const r of t){const[o,...n]=r;dt(o,...n)}}function dt(e,...t){switch(e){case"boot":Me(t[0]);break;case"update":ze(t[0]);break;case"shutdown":Et();break;case"show":St();break;case"hide":Mt();break;case"showNewMessage":Tt(t[0]);break;case"trackEvent":It(t[0],t[1]);break;default:console.warn(`[SupportWireMessenger] unknown command: ${e}`)}}function Me(e){if(typeof window>"u")return;if(!e||typeof e.app_id!="string"||e.app_id==="")throw new Error("[SupportWireMessenger] `app_id` is required");if(Di(),L&&J&&J.app_id===e.app_id){ze(e);return}L&&(L.destroy(),L=null);const t=Ct(e);J=e;const i=t.widgetSlug,r=pe;if(L=new Hi({widgetSlug:i,userEmail:t.userEmail,userExternalUserId:t.userExternalUserId,userSignature:t.userSignature,userData:t.userData,theme:t.theme,selector:t.selector,hideOnLaunch:t.hideOnLaunch,triggerPosition:t.triggerPosition,onOpen:()=>{for(const o of Fe)o()},onClose:()=>{for(const o of Ue)o()}}),t.userEmail&&t.userEmail!==r){pe=t.userEmail;for(const o of Ee)o()}Wi()}function ze(e){if(!L){e&&typeof e.app_id=="string"&&Me(e);return}const t={...J??{},...e},i=pe;J=t;const r=Ct(t);if(L.updateConfig({userEmail:r.userEmail||void 0,userExternalUserId:r.userExternalUserId||void 0,userSignature:r.userSignature||void 0,userData:r.userData,theme:r.theme}),r.userEmail&&r.userEmail!==i){pe=r.userEmail;for(const o of Ee)o()}}function Et(){if(!L)return;const e=J?.app_id;if(L.destroy(),L=null,J=null,pe=null,kt=0,typeof window<"u"&&typeof localStorage<"u"&&typeof e=="string"){for(const t of Object.keys(localStorage))if(t===`supportwire-unread-count-${e}`||t.startsWith("supportwire-widget-")&&t.endsWith(`-${e}`))try{localStorage.removeItem(t)}catch{}}}function St(){L?.open()}function Mt(){L?.close()}function Tt(e){L&&(L.open(),e&&e.trim()!==""&&L.sendMessage(e))}let pt=!1;function It(e,t){pt||(console.warn(`[SupportWireMessenger] trackEvent("${e}", ...) is a no-op until POST /v2/track_event ships.`),pt=!0)}function Bi(e){return Fe.add(e),()=>Fe.delete(e)}function ji(e){return Ue.add(e),()=>Ue.delete(e)}function qi(e){return at.add(e),e(kt),()=>at.delete(e)}function Gi(e){return Ee.add(e),()=>Ee.delete(e)}let ct=!1;function Yi(e){ct||(console.warn("[SupportWireMessenger] hideNotifications is a no-op for now; preview suppression lives in the widget app."),ct=!0)}function Vi(){return null}function Ki(){return null}const ut=new Map;function B(e){return(...t)=>{ut.get(e)||(console.warn(`[SupportWireMessenger] ${e} is not implemented; ignoring call.`),ut.set(e,!0))}}const Ji=B("startTour"),Xi=B("showArticle"),Qi=B("showNews"),Zi=B("startSurvey"),eo=B("startChecklist"),to=B("showTicket"),io=B("showConversation"),oo=B("showSpace"),ro=B("showMessages");function Lt(e){Me(e)}exports.SupportWire=Lt;exports.boot=Me;exports.default=Lt;exports.getVisitorId=Vi;exports.hide=Mt;exports.hideNotifications=Yi;exports.onHide=ji;exports.onShow=Bi;exports.onUnreadCountChange=qi;exports.onUserEmailSupplied=Gi;exports.show=St;exports.showArticle=Xi;exports.showConversation=io;exports.showMessages=ro;exports.showNewMessage=Tt;exports.showNews=Qi;exports.showSpace=oo;exports.showTicket=to;exports.shutdown=Et;exports.startChecklist=eo;exports.startSurvey=Zi;exports.startTour=Ji;exports.trackEvent=It;exports.update=ze;exports.whoami=Ki;
|
|
920
|
+
</svg>`,Object.assign(i.style,{position:"absolute",top:"4px",left:"4px",width:"20px",height:"20px",cursor:"nw-resize",zIndex:"10",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--muted-foreground, #999)",borderRadius:"4px"}),i.addEventListener("mouseenter",()=>{const c=i.querySelector("svg");c&&(c.style.opacity="0.6")}),i.addEventListener("mouseleave",()=>{const c=i.querySelector("svg");c&&(c.style.opacity="0.3")});const r=320,o=700,n=400;i.addEventListener("dblclick",c=>{c.stopPropagation(),ne.trigger("light"),window.matchMedia("(prefers-reduced-motion: reduce)").matches||(t.style.willChange="width, height",t.style.transition="width 250ms cubic-bezier(0.22, 1, 0.36, 1), height 250ms cubic-bezier(0.22, 1, 0.36, 1), max-height 250ms cubic-bezier(0.22, 1, 0.36, 1)",setTimeout(()=>{t.style.willChange="",t.style.transition="width 200ms ease-out, height 200ms ease-out"},270)),t.style.width="min(400px, max(0px, -20px + 100vw))",t.style.height="min(704px, 100% - 104px)",t.style.maxHeight="704px";try{localStorage.removeItem(`supportwire-widget-size-${this.config.widgetSlug}`)}catch{}});let l=!1,s=0,m=0,h=0,u=0;i.addEventListener("pointerdown",c=>{c.stopPropagation(),c.preventDefault(),l=!0,s=c.clientX,m=c.clientY;const g=t.getBoundingClientRect();h=g.width,u=g.height,i.setPointerCapture(c.pointerId),t.style.transition="none"}),i.addEventListener("pointermove",c=>{if(!l)return;const g=s-c.clientX,y=m-c.clientY,k=parseInt(t.style.right)||20,b=parseInt(t.style.bottom)||84,x=Math.min(o,window.innerWidth-k-20),E=window.innerHeight-b-20,C=Math.max(r,Math.min(x,h+g)),_=Math.max(n,Math.min(E,u+y));t.style.width=`${C}px`,t.style.height=`${_}px`,t.style.maxHeight=`${_}px`}),i.addEventListener("pointerup",c=>{if(!l)return;l=!1,i.releasePointerCapture(c.pointerId),t.style.transition="";const g=t.getBoundingClientRect();Ti(this.config.widgetSlug,{width:Math.round(g.width),height:Math.round(g.height)})}),t.appendChild(i)}toggleExpand(){this.container&&(ne.trigger("medium"),window.matchMedia("(prefers-reduced-motion: reduce)").matches||(this.container.style.willChange="width, height",this.container.style.transition="width 300ms cubic-bezier(0.22, 1, 0.36, 1), height 300ms cubic-bezier(0.22, 1, 0.36, 1), max-height 300ms cubic-bezier(0.22, 1, 0.36, 1), bottom 300ms cubic-bezier(0.22, 1, 0.36, 1)",setTimeout(()=>{this.container&&(this.container.style.willChange="",this.container.style.transition="width 200ms ease-out, height 200ms ease-out")},320)),this.isExpanded?(this.container.style.width="min(400px, max(0px, -20px + 100vw))",this.container.style.height="min(704px, 100% - 104px)",this.container.style.maxHeight="704px",this.container.style.bottom="84px",this.isExpanded=!1):(this.container.style.width="min(688px, max(0px, -20px + 100vw))",this.container.style.height="calc(100% - 40px)",this.container.style.maxHeight="calc(100% - 40px)",this.container.style.bottom="20px",this.isExpanded=!0))}async capturePageScreenshot(t){var i,r;try{const o=(i=this.container)==null?void 0:i.style.display,n=(r=this.trigger)==null?void 0:r.style.display;this.container&&(this.container.style.display="none"),this.trigger&&(this.trigger.style.display="none");const{snapdom:l}=await Promise.resolve().then(()=>require("./snapdom-6yvsn_Iv-OVmChxqF.cjs")),s=(await l.toCanvas(document.documentElement,{scale:1})).toDataURL("image/png");this.container&&(this.container.style.display=o??""),this.trigger&&(this.trigger.style.display=n??""),it(s,m=>{this.sendMessageToIframe({type:"PAGE_SCREENSHOT_RESULT",payload:{dataUrl:m}})},()=>{this.sendMessageToIframe({type:"PAGE_SCREENSHOT_ERROR",payload:{error:"Screenshot cancelled"}})})}catch(o){this.container&&(this.container.style.display=""),this.trigger&&(this.trigger.style.display="");const n=o instanceof Error?o.message:"Screenshot capture failed";this.sendMessageToIframe({type:"PAGE_SCREENSHOT_ERROR",payload:{error:n}})}}updateConfig(t){const i=A({},this.config);t.appUrl!==void 0&&(this.config.appUrl=t.appUrl),t.theme!==void 0&&(this.config.theme=t.theme),t.triggerPosition!==void 0&&(this.config.triggerPosition=t.triggerPosition),t.widgetType!==void 0&&(this.config.widgetType=t.widgetType),t.userToken!==void 0&&(this.config.userToken=t.userToken),t.userEmail!==void 0&&(this.config.userEmail=t.userEmail),t.userSignature!==void 0&&(this.config.userSignature=t.userSignature),t.userData!==void 0&&(this.config.userData=t.userData),t.onOpen!==void 0&&(this.config.onOpen=t.onOpen),t.onClose!==void 0&&(this.config.onClose=t.onClose),t.onError!==void 0&&(this.config.onError=t.onError),t.hideOnLaunch!==void 0&&(this.config.hideOnLaunch=t.hideOnLaunch,this.trigger&&(this.trigger.style.display=t.hideOnLaunch?"none":"")),t.enableScreenshot!==void 0&&(this.config.enableScreenshot=t.enableScreenshot);const r=t.appUrl!==void 0&&t.appUrl!==i.appUrl,o=t.theme!==void 0&&t.theme!==i.theme;(r||o)&&(o&&this.sendMessageToIframe({type:"THEME",theme:t.theme}),this.iframe&&(this.widgetUrl=this.buildWidgetUrl(),this.iframe.src=`${this.widgetUrl}?iframeId=${this.iframeId}&theme=${this.config.theme}`)),t.widgetType!==void 0&&t.widgetType!==i.widgetType&&this.container&&Qe(this.container,this.config),t.triggerPosition!==void 0&&this.trigger&&!this.config.selector&&(Qt(this.trigger,this.config.triggerPosition),this.config.widgetType==="popup"&&this.container&&Yt(this.container,this.config.triggerPosition,this.config.widgetType)),this.sendMessageToIframe({type:"UPDATE_CONFIG",config:t})}sendMessage(t,i){if(!t||typeof t!="string"||t.trim()===""){this.config.onError(new Error("Message must be a non-empty string"));return}i?.openWidget!==!1&&!this.isOpen&&this.open(),this.sendMessageToIframe({type:"SEND_MESSAGE",message:t,openWidget:i?.openWidget})}destroy(){ke(!0),this.updateDocumentTitle(0),this.eventRuleCleanup&&(this.eventRuleCleanup(),this.eventRuleCleanup=null),this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.guideBridgeTeardown&&(this.guideBridgeTeardown(),this.guideBridgeTeardown=null),this.trigger&&this.triggerClickHandler&&this.trigger.removeEventListener("click",this.triggerClickHandler),this.trigger&&!this.config.selector&&this.trigger.remove(),this.trigger=null,this.triggerClickHandler=null,this.container&&(this.container.remove(),this.container=null),this.iframe=null,this.isOpen=!1,ve.instances.delete(this.iframeId)}static getInstances(t){const i=Array.from(ve.instances.values());return t!==void 0?i.filter(r=>r.config.widgetSlug===t):i}};vt.instances=new Map;let Hi=vt;const zi=["app_id","user_id","email","user_hash","name","created_at","phone","avatar","unsubscribed_from_emails","language_override","utm_campaign","utm_content","utm_medium","utm_source","utm_term","page_title","company","companies","alignment","horizontal_padding","vertical_padding","hide_default_launcher","hide_notifications","custom_launcher_selector","z_index","action_color","background_color","link_color","theme_mode","session_duration","region","api_base"];function Ct(e){const t={};for(const[i,r]of Object.entries(e))zi.includes(i)||(t[i]=r);return e.name!==void 0&&(t.name=e.name),e.phone!==void 0&&(t.phone=e.phone),e.created_at!==void 0&&(t.created_at=e.created_at),e.company!==void 0&&(t.company=e.company),e.companies!==void 0&&(t.companies=e.companies),e.unsubscribed_from_emails!==void 0&&(t.unsubscribed_from_emails=e.unsubscribed_from_emails),{widgetSlug:String(e.app_id),userEmail:typeof e.email=="string"?e.email:void 0,userExternalUserId:typeof e.user_id=="string"?e.user_id:void 0,userSignature:typeof e.user_hash=="string"?e.user_hash:void 0,userData:t,theme:e.theme_mode==="dark"||e.theme_mode==="light"?e.theme_mode:void 0,selector:typeof e.custom_launcher_selector=="string"?e.custom_launcher_selector:void 0,hideOnLaunch:typeof e.hide_default_launcher=="boolean"?e.hide_default_launcher:void 0,triggerPosition:Ai(e.alignment)}}function Ai(e){if(e==="left")return"bottom-left";if(e==="right")return"bottom-right"}let L=null,J=null;const Fe=new Set,Ue=new Set,at=new Set,Ee=new Set;let kt=0,ce=null;function Di(){if(typeof window>"u")return lt();if(window.SupportWireMessenger)return window.SupportWireMessenger;const e=lt();return window.SupportWireMessenger=e,e}function lt(){const e=[],t=(...i)=>{e.push(i)};return t.q=e,t}function Wi(){if(typeof window>"u")return;const e=window.SupportWireMessenger;if(!e||!e.q)return;const t=e.q.slice();e.q.length=0;const i=(...r)=>{const[o,...n]=r;dt(o,...n)};i.q=[],window.SupportWireMessenger=i;for(const r of t){const[o,...n]=r;dt(o,...n)}}function dt(e,...t){switch(e){case"boot":Me(t[0]);break;case"update":ze(t[0]);break;case"shutdown":Et();break;case"show":St();break;case"hide":Mt();break;case"showNewMessage":It(t[0]);break;case"trackEvent":Tt(t[0],t[1]);break;default:console.warn(`[SupportWireMessenger] unknown command: ${e}`)}}function Me(e){if(typeof window>"u")return;if(!e||typeof e.app_id!="string"||e.app_id==="")throw new Error("[SupportWireMessenger] `app_id` is required");if(Di(),L&&J&&J.app_id===e.app_id){ze(e);return}L&&(L.destroy(),L=null);const t=Ct(e);J=e;const i=t.widgetSlug,r=ce;if(L=new Hi({widgetSlug:i,userEmail:t.userEmail,userExternalUserId:t.userExternalUserId,userSignature:t.userSignature,userData:t.userData,theme:t.theme,selector:t.selector,hideOnLaunch:t.hideOnLaunch,triggerPosition:t.triggerPosition,onOpen:()=>{for(const o of Fe)o()},onClose:()=>{for(const o of Ue)o()}}),t.userEmail&&t.userEmail!==r){ce=t.userEmail;for(const o of Ee)o()}Wi()}function ze(e){if(!L){e&&typeof e.app_id=="string"&&Me(e);return}const t={...J??{},...e},i=ce;J=t;const r=Ct(t);if(L.updateConfig({userEmail:r.userEmail||void 0,userExternalUserId:r.userExternalUserId||void 0,userSignature:r.userSignature||void 0,userData:r.userData,theme:r.theme}),r.userEmail&&r.userEmail!==i){ce=r.userEmail;for(const o of Ee)o()}}function Et(){if(!L)return;const e=J?.app_id;if(L.destroy(),L=null,J=null,ce=null,kt=0,typeof window<"u"&&typeof localStorage<"u"&&typeof e=="string"){for(const t of Object.keys(localStorage))if(t===`supportwire-unread-count-${e}`||t.startsWith("supportwire-widget-")&&t.endsWith(`-${e}`))try{localStorage.removeItem(t)}catch{}}}function St(){L?.open()}function Mt(){L?.close()}function It(e){L&&(L.open(),e&&e.trim()!==""&&L.sendMessage(e))}let ct=!1;function Tt(e,t){ct||(console.warn(`[SupportWireMessenger] trackEvent("${e}", ...) is a no-op until POST /v2/track_event ships.`),ct=!0)}function Bi(e){return Fe.add(e),()=>Fe.delete(e)}function ji(e){return Ue.add(e),()=>Ue.delete(e)}function qi(e){return at.add(e),e(kt),()=>at.delete(e)}function Gi(e){return Ee.add(e),()=>Ee.delete(e)}let pt=!1;function Yi(e){pt||(console.warn("[SupportWireMessenger] hideNotifications is a no-op for now; preview suppression lives in the widget app."),pt=!0)}function Vi(){return null}function Ki(){return null}const ut=new Map;function B(e){return(...t)=>{ut.get(e)||(console.warn(`[SupportWireMessenger] ${e} is not implemented; ignoring call.`),ut.set(e,!0))}}const Ji=B("startTour"),Xi=B("showArticle"),Qi=B("showNews"),Zi=B("startSurvey"),eo=B("startChecklist"),to=B("showTicket"),io=B("showConversation"),oo=B("showSpace"),ro=B("showMessages");function Lt(e){Me(e)}exports.SupportWire=Lt;exports.boot=Me;exports.default=Lt;exports.getVisitorId=Vi;exports.hide=Mt;exports.hideNotifications=Yi;exports.onHide=ji;exports.onShow=Bi;exports.onUnreadCountChange=qi;exports.onUserEmailSupplied=Gi;exports.show=St;exports.showArticle=Xi;exports.showConversation=io;exports.showMessages=ro;exports.showNewMessage=It;exports.showNews=Qi;exports.showSpace=oo;exports.showTicket=to;exports.shutdown=Et;exports.startChecklist=eo;exports.startSurvey=Zi;exports.startTour=Ji;exports.trackEvent=Tt;exports.update=ze;exports.whoami=Ki;
|
|
921
921
|
//# sourceMappingURL=index.cjs.map
|