@supportwire/messenger-js-sdk 1.0.26

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.cjs ADDED
@@ -0,0 +1,921 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var Ft=Object.defineProperty,Ut=Object.defineProperties,Ht=Object.getOwnPropertyDescriptors,Xe=Object.getOwnPropertySymbols,zt=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable,Pe=(e,t,i)=>t in e?Ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,A=(e,t)=>{for(var i in t||(t={}))zt.call(t,i)&&Pe(e,i,t[i]);if(Xe)for(var i of Xe(t))At.call(t,i)&&Pe(e,i,t[i]);return e},Se=(e,t)=>Ut(e,Ht(t)),R=(e,t,i)=>Pe(e,typeof t!="symbol"?t+"":t,i);const Dt=e=>e&&typeof e=="string"&&e.trim()!==""?e.trim().replace(/\/$/,""):"https://widget.supportwire.app",Wt=()=>{const e=Date.now(),t=Math.random().toString(36).substring(2,9);return`supportwire-iframe-${e}-${t}`},Bt=()=>{if(document.getElementById("supportwire-animation-styles"))return;const e=document.createElement("style");e.id="supportwire-animation-styles",e.textContent=`
2
+ /* ── Popup: open (fade + rise + subtle scale) ── */
3
+ @keyframes supportwire-slide-up-fade-in {
4
+ from {
5
+ opacity: 0;
6
+ transform: translateY(12px) scale(0.96);
7
+ }
8
+ to {
9
+ opacity: 1;
10
+ transform: translateY(0) scale(1);
11
+ }
12
+ }
13
+
14
+ /* ── Center modal: open ── */
15
+ @keyframes supportwire-slide-up-fade-in-center {
16
+ from {
17
+ opacity: 0;
18
+ transform: translate(-50%, calc(-50% + 12px)) scale(0.96);
19
+ }
20
+ to {
21
+ opacity: 1;
22
+ transform: translate(-50%, -50%) scale(1);
23
+ }
24
+ }
25
+
26
+ /* ── Popup: close (faster exit, sink + shrink) ── */
27
+ @keyframes supportwire-slide-down-fade-out {
28
+ from {
29
+ opacity: 1;
30
+ transform: translateY(0) scale(1);
31
+ }
32
+ to {
33
+ opacity: 0;
34
+ transform: translateY(8px) scale(0.98);
35
+ }
36
+ }
37
+
38
+ /* ── Center modal: close ── */
39
+ @keyframes supportwire-slide-down-fade-out-center {
40
+ from {
41
+ opacity: 1;
42
+ transform: translate(-50%, -50%) scale(1);
43
+ }
44
+ to {
45
+ opacity: 0;
46
+ transform: translate(-50%, calc(-50% + 8px)) scale(0.98);
47
+ }
48
+ }
49
+
50
+ .supportwire-widget-container {
51
+ transition: opacity 250ms cubic-bezier(0.22, 1, 0.36, 1), transform 250ms cubic-bezier(0.22, 1, 0.36, 1);
52
+ }
53
+
54
+ /* ── Popup (overshoot on open for "pop" feel) ── */
55
+ .supportwire-widget-container.supportwire-opening {
56
+ animation: supportwire-slide-up-fade-in 300ms cubic-bezier(0, 1.2, 1, 1) forwards;
57
+ }
58
+ .supportwire-widget-container.supportwire-closing {
59
+ animation: supportwire-slide-down-fade-out 180ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
60
+ }
61
+
62
+ /* ── Drawer ── */
63
+ .supportwire-widget-container.supportwire-drawer.supportwire-opening {
64
+ animation: supportwire-slide-up-fade-in 350ms cubic-bezier(0, 1.2, 1, 1) forwards;
65
+ }
66
+ .supportwire-widget-container.supportwire-drawer.supportwire-closing {
67
+ animation: supportwire-slide-down-fade-out 220ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
68
+ }
69
+
70
+ /* ── Center modal ── */
71
+ .supportwire-widget-container.supportwire-center\\ modal.supportwire-opening {
72
+ animation: supportwire-slide-up-fade-in-center 300ms cubic-bezier(0, 1.2, 1, 1) forwards;
73
+ }
74
+ .supportwire-widget-container.supportwire-center\\ modal.supportwire-closing {
75
+ animation: supportwire-slide-down-fade-out-center 180ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
76
+ }
77
+
78
+ /* ── Reduced motion: fade only, no movement ── */
79
+ @keyframes supportwire-fade-in {
80
+ from { opacity: 0; }
81
+ to { opacity: 1; }
82
+ }
83
+ @keyframes supportwire-fade-out {
84
+ from { opacity: 1; }
85
+ to { opacity: 0; }
86
+ }
87
+
88
+ /* ── Mobile fullscreen: take over viewport on narrow screens ── */
89
+ @media (max-width: 480px) {
90
+ .supportwire-widget-container.supportwire-popup,
91
+ .supportwire-widget-container.supportwire-drawer,
92
+ .supportwire-widget-container.supportwire-center\\ modal {
93
+ width: 100vw !important;
94
+ height: 100vh !important;
95
+ height: 100dvh !important;
96
+ max-height: none !important;
97
+ min-height: none !important;
98
+ top: 0 !important;
99
+ left: 0 !important;
100
+ right: 0 !important;
101
+ bottom: 0 !important;
102
+ border-radius: 0 !important;
103
+ transform: none !important;
104
+ }
105
+ }
106
+
107
+ @media (prefers-reduced-motion: reduce) {
108
+ .supportwire-widget-container {
109
+ transition: opacity 150ms ease-out !important;
110
+ }
111
+ .supportwire-widget-container.supportwire-opening,
112
+ .supportwire-widget-container.supportwire-drawer.supportwire-opening,
113
+ .supportwire-widget-container.supportwire-center\\ modal.supportwire-opening {
114
+ animation: supportwire-fade-in 150ms ease-out forwards !important;
115
+ }
116
+ .supportwire-widget-container.supportwire-closing,
117
+ .supportwire-widget-container.supportwire-drawer.supportwire-closing,
118
+ .supportwire-widget-container.supportwire-center\\ modal.supportwire-closing {
119
+ animation: supportwire-fade-out 150ms ease-out forwards !important;
120
+ }
121
+ }
122
+ `,document.head.appendChild(e)},ht=e=>{requestAnimationFrame(()=>{e.classList.remove("supportwire-closing"),e.classList.add("supportwire-opening")})},gt=(e,t)=>{e.classList.remove("supportwire-opening"),e.classList.add("supportwire-closing"),setTimeout(()=>{e.style.display="none",e.classList.remove("supportwire-closing")},230)},jt=(e,t)=>{if(!t)return{bottom:"20px",right:"20px"};switch(e){case"bottom-right":return{bottom:"84px",right:"20px"};case"bottom-left":return{bottom:"84px",left:"20px"};case"top-right":return{top:"84px",right:"20px"};case"top-left":return{top:"84px",left:"20px"};default:return{bottom:"84px",right:"20px"}}},qt=()=>{const e="supportwire-widget-tail-styles";if(document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent=`
123
+ .supportwire-widget-tail {
124
+ position: absolute;
125
+ width: 12px;
126
+ height: 12px;
127
+ background: inherit;
128
+ border-radius: 2px;
129
+ transform: rotate(45deg);
130
+ z-index: -1;
131
+ }
132
+
133
+ .supportwire-widget-tail.bottom-right {
134
+ bottom: -6px;
135
+ right: 24px;
136
+ box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.08);
137
+ }
138
+
139
+ .supportwire-widget-tail.bottom-left {
140
+ bottom: -6px;
141
+ left: 24px;
142
+ box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.08);
143
+ }
144
+
145
+ .supportwire-widget-tail.top-right {
146
+ top: -6px;
147
+ right: 24px;
148
+ box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.08);
149
+ }
150
+
151
+ .supportwire-widget-tail.top-left {
152
+ top: -6px;
153
+ left: 24px;
154
+ box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.08);
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",u=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,u);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
+ <svg width="28" height="28" viewBox="0 0 820 820" fill="none" xmlns="http://www.w3.org/2000/svg">
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
+ </svg>
160
+ `,Kt=`
161
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
162
+ <path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
163
+ </svg>
164
+ `,Jt=()=>{const e="supportwire-trigger-styles";if(document.getElementById(e))return;const t=document.createElement("style");t.id=e,t.textContent=`
165
+ /* ── Trigger entrance ── */
166
+ @keyframes supportwire-trigger-enter {
167
+ from {
168
+ opacity: 0;
169
+ transform: scale(0.8);
170
+ }
171
+ to {
172
+ opacity: 1;
173
+ transform: scale(1);
174
+ }
175
+ }
176
+
177
+ .supportwire-trigger-wrapper {
178
+ position: relative;
179
+ width: 48px;
180
+ height: 48px;
181
+ animation: supportwire-trigger-enter 350ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
182
+ }
183
+
184
+ .supportwire-widget-trigger {
185
+ width: 100%;
186
+ height: 100%;
187
+ border-radius: 50%;
188
+ border: none;
189
+ cursor: pointer;
190
+ display: flex;
191
+ align-items: center;
192
+ justify-content: center;
193
+ transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1), opacity 100ms ease-out;
194
+ padding: 0;
195
+ }
196
+
197
+ /* Hover: instant on (0ms via override below), ease off (150ms base) */
198
+ .supportwire-widget-trigger:hover {
199
+ opacity: 0.9;
200
+ transform: translateY(-2px);
201
+ transition-duration: 0ms;
202
+ }
203
+ .supportwire-widget-trigger:not(:hover) {
204
+ transition-duration: 150ms;
205
+ }
206
+
207
+ .supportwire-widget-trigger:active {
208
+ transform: scale(0.97);
209
+ }
210
+
211
+ .supportwire-widget-trigger:focus-visible {
212
+ outline: 2px solid #0091FF;
213
+ outline-offset: 2px;
214
+ }
215
+
216
+ /* ── Icon crossfade ── */
217
+ .supportwire-widget-trigger .supportwire-trigger-icon {
218
+ position: absolute;
219
+ display: flex;
220
+ align-items: center;
221
+ justify-content: center;
222
+ transition: opacity 150ms ease-out, transform 150ms ease-out;
223
+ }
224
+ .supportwire-trigger-icon--hidden {
225
+ opacity: 0;
226
+ transform: scale(0.8);
227
+ }
228
+ .supportwire-trigger-icon--visible {
229
+ opacity: 1;
230
+ transform: scale(1);
231
+ }
232
+
233
+ @media (prefers-reduced-motion: reduce) {
234
+ .supportwire-trigger-wrapper {
235
+ animation: none;
236
+ opacity: 1;
237
+ }
238
+ .supportwire-widget-trigger {
239
+ transition: opacity 100ms ease-out;
240
+ }
241
+ .supportwire-widget-trigger .supportwire-trigger-icon {
242
+ transition: opacity 100ms ease-out;
243
+ transform: none !important;
244
+ }
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 u={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}},d=(i=e.triggerPosition)!=null?i:"bottom-right",h=(r=u[d])!=null?r:u["bottom-right"];return Object.assign(o.style,A({position:"fixed",zIndex:"999998"},h)),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
+ .supportwire-widget-badge {
248
+ position: absolute;
249
+ top: -4px;
250
+ right: -4px;
251
+ min-width: 20px;
252
+ height: 20px;
253
+ padding: 0 6px;
254
+ background-color: #ef4444;
255
+ color: #ffffff;
256
+ border-radius: 10px;
257
+ font-size: 11px;
258
+ font-weight: 600;
259
+ display: flex;
260
+ align-items: center;
261
+ justify-content: center;
262
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
263
+ line-height: 1;
264
+ z-index: 999999;
265
+ }
266
+
267
+ .supportwire-widget-badge[data-animate="pop-in"] {
268
+ animation: supportwire-badge-pop-in 280ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
269
+ }
270
+
271
+ .supportwire-widget-badge[data-animate="pulse"] {
272
+ animation: supportwire-badge-pulse 180ms ease-out;
273
+ }
274
+
275
+ @keyframes supportwire-badge-pop-in {
276
+ 0% { transform: scale(0.95); opacity: 0; }
277
+ 100% { transform: scale(1); opacity: 1; }
278
+ }
279
+
280
+ @keyframes supportwire-badge-pulse {
281
+ 0% { transform: scale(1); }
282
+ 50% { transform: scale(1.05); }
283
+ 100% { transform: scale(1); }
284
+ }
285
+
286
+ @keyframes supportwire-badge-fade-in {
287
+ 0% { opacity: 0; }
288
+ 100% { opacity: 1; }
289
+ }
290
+
291
+ @media (prefers-reduced-motion: reduce) {
292
+ .supportwire-widget-badge[data-animate="pop-in"] {
293
+ animation: supportwire-badge-fade-in 200ms ease-out forwards;
294
+ }
295
+ .supportwire-widget-badge[data-animate="pulse"] {
296
+ animation: none;
297
+ }
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 u=new URL(t).origin;o.origin!==u&&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&&gt(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){let i=null;const r=()=>(i||(i=Promise.resolve().then(()=>require("./index-bfV4xNqW-ChZOGalc.cjs"))),i),o=u=>{var d;(d=e.contentWindow)==null||d.postMessage(Se(A({},u),{iframeId:t}),"*")},n=async u=>{const d=u.data;if(!(!d||typeof d!="object")&&!(d.iframeId&&d.iframeId!==t))switch(d.type){case"RECORDING:START":{(await r()).recording.start({guideId:d.guideId,title:d.title});return}case"RECORDING:STOP":{const h=(await r()).recording.stop();h&&o({type:"RECORDING:DONE",guideId:h.guideId,title:h.title,steps:h.steps});return}case"PLAYBACK:START":{const h=await r();h.playback.onDone((g,w,y)=>{o({type:"PLAYBACK:DONE",status:g,end_reason:w,current_step:y})}),h.playback.start({sessionId:d.sessionId,guideId:d.guideId,versionId:d.versionId,version:d.version});return}case"OPEN_URL":{typeof d.url=="string"&&window.open(d.url,"_blank","noopener");return}}},l=u=>{const d=u.detail;d&&o({type:"RECORDING:DONE",guideId:d.guideId,title:d.title,steps:d.steps})};window.addEventListener("message",n),window.addEventListener("sw-guide:recording-done",l),(async()=>{const u=await s();if(!u)return;const d=u.recording.maybeResume();d&&u.recording.start({guideId:d.guideId,title:d.title});const h=u.playback.maybeResume();h&&(u.playback.onDone((w,y,S)=>{o({type:"PLAYBACK:DONE",status:w,end_reason:y,current_step:S})}),u.playback.start({sessionId:h.sessionId,guideId:h.guideId,versionId:h.versionId,version:h.version,resumeStepIndex:h.stepIndex}));const g=new URLSearchParams(location.search).get("sw_guide");g&&o({type:"DEEP_LINK_GUIDE",guideId:g})})();function s(){const u=!!localStorage.getItem("sw.guide.recording"),d=!!localStorage.getItem("sw.guide.playback"),h=new URLSearchParams(location.search).has("sw_guide");return!u&&!d&&!h?Promise.resolve(null):r()}return{teardown:()=>{window.removeEventListener("message",n),window.removeEventListener("sw-guide:recording-done",l)}}}let W=null,se=null,mt="";const ri=`
300
+ .supportwire-image-preview-backdrop {
301
+ position: fixed;
302
+ top: 0;
303
+ left: 0;
304
+ right: 0;
305
+ bottom: 0;
306
+ background: rgba(0, 0, 0, 0);
307
+ display: flex;
308
+ align-items: center;
309
+ justify-content: center;
310
+ z-index: 2147483647;
311
+ padding: 24px;
312
+ opacity: 0;
313
+ transition: background 200ms ease-out, opacity 200ms ease-out;
314
+ }
315
+
316
+ .supportwire-image-preview-backdrop.visible {
317
+ background: rgba(0, 0, 0, 0.9);
318
+ opacity: 1;
319
+ }
320
+
321
+ .supportwire-image-preview-backdrop.closing {
322
+ background: rgba(0, 0, 0, 0);
323
+ opacity: 0;
324
+ }
325
+
326
+ @media (prefers-reduced-motion: reduce) {
327
+ .supportwire-image-preview-backdrop {
328
+ transition: none;
329
+ }
330
+ }
331
+
332
+ /* Floating buttons in top-right corner */
333
+ .supportwire-image-preview-actions {
334
+ position: fixed;
335
+ top: 16px;
336
+ right: 16px;
337
+ display: flex;
338
+ gap: 8px;
339
+ z-index: 2147483647;
340
+ }
341
+
342
+ .supportwire-image-preview-button {
343
+ display: flex;
344
+ align-items: center;
345
+ justify-content: center;
346
+ width: 36px;
347
+ height: 36px;
348
+ border-radius: 50%;
349
+ background: rgba(255, 255, 255, 0.1);
350
+ backdrop-filter: blur(8px);
351
+ -webkit-backdrop-filter: blur(8px);
352
+ border: 1px solid rgba(255, 255, 255, 0.15);
353
+ color: rgba(255, 255, 255, 0.9);
354
+ cursor: pointer;
355
+ padding: 0;
356
+ transition: background 150ms ease, transform 150ms ease;
357
+ -webkit-tap-highlight-color: transparent;
358
+ }
359
+
360
+ .supportwire-image-preview-button:hover {
361
+ background: rgba(255, 255, 255, 0.2);
362
+ transform: scale(1.05);
363
+ }
364
+
365
+ .supportwire-image-preview-button:active {
366
+ transform: scale(0.95);
367
+ }
368
+
369
+ .supportwire-image-preview-button:focus {
370
+ outline: 2px solid rgba(255, 255, 255, 0.5);
371
+ outline-offset: 2px;
372
+ }
373
+
374
+ @media (prefers-reduced-motion: reduce) {
375
+ .supportwire-image-preview-button {
376
+ transition: none;
377
+ }
378
+ .supportwire-image-preview-button:hover,
379
+ .supportwire-image-preview-button:active {
380
+ transform: none;
381
+ }
382
+ }
383
+
384
+ /* Image container */
385
+ .supportwire-image-preview-image-container {
386
+ display: flex;
387
+ align-items: center;
388
+ justify-content: center;
389
+ position: relative;
390
+ max-width: 90vw;
391
+ max-height: 90vh;
392
+ }
393
+
394
+ .supportwire-image-preview-image {
395
+ max-width: 90vw;
396
+ max-height: 90vh;
397
+ object-fit: contain;
398
+ border-radius: 8px;
399
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
400
+ opacity: 0;
401
+ transform: scale(0.95);
402
+ transition: opacity 200ms ease-out, transform 200ms ease-out;
403
+ }
404
+
405
+ .supportwire-image-preview-backdrop.visible .supportwire-image-preview-image {
406
+ opacity: 1;
407
+ transform: scale(1);
408
+ }
409
+
410
+ .supportwire-image-preview-backdrop.closing .supportwire-image-preview-image {
411
+ opacity: 0;
412
+ transform: scale(0.95);
413
+ }
414
+
415
+ @media (prefers-reduced-motion: reduce) {
416
+ .supportwire-image-preview-image {
417
+ transition: none;
418
+ transform: scale(1);
419
+ opacity: 1;
420
+ }
421
+ }
422
+
423
+ .supportwire-image-preview-loader {
424
+ position: absolute;
425
+ width: 32px;
426
+ height: 32px;
427
+ border: 3px solid rgba(255, 255, 255, 0.2);
428
+ border-top-color: #fff;
429
+ border-radius: 50%;
430
+ animation: supportwire-spin 0.8s linear infinite;
431
+ }
432
+
433
+ @keyframes supportwire-spin {
434
+ to { transform: rotate(360deg); }
435
+ }
436
+
437
+ @media (prefers-reduced-motion: reduce) {
438
+ .supportwire-image-preview-loader {
439
+ animation: none;
440
+ border-top-color: rgba(255, 255, 255, 0.2);
441
+ border-right-color: #fff;
442
+ }
443
+ }
444
+
445
+ .supportwire-image-preview-error {
446
+ color: #fff;
447
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
448
+ font-size: 14px;
449
+ text-align: center;
450
+ padding: 40px;
451
+ }
452
+
453
+ /* Filename at bottom */
454
+ .supportwire-image-preview-filename {
455
+ position: fixed;
456
+ bottom: 16px;
457
+ left: 50%;
458
+ transform: translateX(-50%);
459
+ font-size: 13px;
460
+ color: rgba(255, 255, 255, 0.7);
461
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
462
+ margin: 0;
463
+ padding: 8px 16px;
464
+ background: rgba(0, 0, 0, 0.5);
465
+ backdrop-filter: blur(8px);
466
+ -webkit-backdrop-filter: blur(8px);
467
+ border-radius: 20px;
468
+ max-width: 80vw;
469
+ white-space: nowrap;
470
+ overflow: hidden;
471
+ text-overflow: ellipsis;
472
+ opacity: 0;
473
+ transition: opacity 200ms ease-out;
474
+ }
475
+
476
+ .supportwire-image-preview-backdrop.visible .supportwire-image-preview-filename {
477
+ opacity: 1;
478
+ }
479
+
480
+ @media (prefers-reduced-motion: reduce) {
481
+ .supportwire-image-preview-filename {
482
+ transition: none;
483
+ opacity: 1;
484
+ }
485
+ }
486
+
487
+ /* Mobile responsiveness */
488
+ @media (max-width: 480px) {
489
+ .supportwire-image-preview-backdrop {
490
+ padding: 16px;
491
+ }
492
+
493
+ .supportwire-image-preview-actions {
494
+ top: 12px;
495
+ right: 12px;
496
+ }
497
+
498
+ .supportwire-image-preview-button {
499
+ width: 40px;
500
+ height: 40px;
501
+ }
502
+
503
+ .supportwire-image-preview-filename {
504
+ bottom: 12px;
505
+ font-size: 12px;
506
+ max-width: 90vw;
507
+ }
508
+ }
509
+ `;function ni(){if(document.getElementById("supportwire-image-preview-styles"))return;const e=document.createElement("style");e.id="supportwire-image-preview-styles",e.textContent=ri,document.head.appendChild(e)}function si(){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">
510
+ <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
511
+ <polyline points="7 10 12 15 17 10"/>
512
+ <line x1="12" y1="15" x2="12" y2="3"/>
513
+ </svg>`}function ai(){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">
514
+ <line x1="18" y1="6" x2="6" y2="18"/>
515
+ <line x1="6" y1="6" x2="18" y2="18"/>
516
+ </svg>`}function li(){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">
517
+ <path d="M12 20h9"/>
518
+ <path d="M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z"/>
519
+ </svg>`}function Re(){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">
520
+ <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/>
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
+ </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
+ <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 pi(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 u=null;r&&(u=document.createElement("button"),u.className="supportwire-image-preview-button",u.setAttribute("aria-label","Annotate image"),u.innerHTML=li(),u.onclick=async y=>{y.stopPropagation();try{const S=await(await fetch(e)).blob(),b=await new Promise((v,k)=>{const C=new FileReader;C.onload=()=>v(C.result),C.onerror=k,C.readAsDataURL(S)});oe(),r(b)}catch{const b=document.createElement("canvas"),v=new Image;v.crossOrigin="anonymous",v.onload=()=>{b.width=v.naturalWidth,b.height=v.naturalHeight;const k=b.getContext("2d");if(k){k.drawImage(v,0,0);const C=b.toDataURL("image/png");oe(),r(C)}},v.onerror=()=>{console.warn("Could not load image for annotation")},v.src=e}});const d=document.createElement("button");d.className="supportwire-image-preview-button",d.setAttribute("aria-label","Close preview"),d.innerHTML=ai(),d.onclick=y=>{y.stopPropagation(),oe()},n.appendChild(l),n.appendChild(s),u&&n.appendChild(u),n.appendChild(d);const h=document.createElement("div");h.className="supportwire-image-preview-image-container";const g=document.createElement("div");g.className="supportwire-image-preview-loader",h.appendChild(g);const w=document.createElement("img");if(w.className="supportwire-image-preview-image",w.alt=t||"Image preview",w.onload=()=>{g.remove()},w.onerror=()=>{g.remove();const y=document.createElement("div");y.className="supportwire-image-preview-error",y.textContent="Failed to load image",h.appendChild(y)},w.src=e,h.appendChild(w),i){const y=document.createElement("p");y.className="supportwire-image-preview-filename",y.textContent=i,o.appendChild(y)}o.appendChild(n),o.appendChild(h),document.body.appendChild(o),W=o,requestAnimationFrame(()=>{o.classList.add("visible")}),se=y=>{y.key==="Escape"&&oe()},document.addEventListener("keydown",se),d.focus()}let K=null,ae=null,ft="";const c="supportwire-ss-editor",ci=`
525
+ .${c}-backdrop {
526
+ position: fixed;
527
+ inset: 0;
528
+ z-index: 2147483647;
529
+ background: rgba(0, 0, 0, 0.6);
530
+ display: flex;
531
+ align-items: center;
532
+ justify-content: center;
533
+ padding: 0;
534
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
535
+ }
536
+ .${c}-modal {
537
+ background: #fff;
538
+ border-radius: 16px;
539
+ box-shadow: 0 25px 50px -12px rgba(0,0,0,0.4);
540
+ display: flex;
541
+ flex-direction: column;
542
+ width: 95vw;
543
+ height: 95vh;
544
+ overflow: hidden;
545
+ }
546
+ .${c}-header {
547
+ display: flex;
548
+ align-items: center;
549
+ justify-content: space-between;
550
+ padding: 12px 16px;
551
+ border-bottom: 1px solid #e5e7eb;
552
+ }
553
+ .${c}-title {
554
+ font-size: 14px;
555
+ font-weight: 600;
556
+ color: #111;
557
+ }
558
+ .${c}-close-btn {
559
+ display: flex;
560
+ align-items: center;
561
+ justify-content: center;
562
+ width: 32px;
563
+ height: 32px;
564
+ border-radius: 50%;
565
+ border: none;
566
+ background: transparent;
567
+ color: #666;
568
+ cursor: pointer;
569
+ }
570
+ .${c}-close-btn:hover { background: #f3f4f6; color: #111; }
571
+ .${c}-canvas-wrap {
572
+ position: relative;
573
+ flex: 1;
574
+ min-height: 300px;
575
+ overflow: hidden;
576
+ cursor: crosshair;
577
+ background: #f9fafb;
578
+ }
579
+ .${c}-canvas-wrap.select-mode { cursor: default; }
580
+ .${c}-canvas-wrap.select-mode-moving { cursor: grabbing; }
581
+ .${c}-img {
582
+ display: block;
583
+ pointer-events: none;
584
+ user-select: none;
585
+ }
586
+ .${c}-canvas {
587
+ position: absolute;
588
+ left: 0;
589
+ top: 0;
590
+ pointer-events: none;
591
+ }
592
+ .${c}-toolbar {
593
+ display: flex;
594
+ align-items: center;
595
+ justify-content: space-between;
596
+ flex-wrap: wrap;
597
+ gap: 8px;
598
+ padding: 12px 16px;
599
+ border-top: 1px solid #e5e7eb;
600
+ }
601
+ .${c}-tools {
602
+ display: flex;
603
+ align-items: center;
604
+ gap: 4px;
605
+ }
606
+ .${c}-tool-btn {
607
+ display: flex;
608
+ align-items: center;
609
+ justify-content: center;
610
+ width: 36px;
611
+ height: 36px;
612
+ border-radius: 50%;
613
+ border: none;
614
+ background: transparent;
615
+ color: #666;
616
+ cursor: pointer;
617
+ }
618
+ .${c}-tool-btn:hover { background: #f3f4f6; color: #111; }
619
+ .${c}-tool-btn.active { background: #0091FF; color: #fff; }
620
+ .${c}-color-picker {
621
+ width: 28px;
622
+ height: 28px;
623
+ border: none;
624
+ border-radius: 50%;
625
+ cursor: pointer;
626
+ background: transparent;
627
+ padding: 0;
628
+ }
629
+ .${c}-separator {
630
+ width: 1px;
631
+ height: 24px;
632
+ background: #e5e7eb;
633
+ margin: 0 4px;
634
+ }
635
+ .${c}-color-swatches {
636
+ display: flex;
637
+ align-items: center;
638
+ gap: 3px;
639
+ }
640
+ .${c}-swatch {
641
+ width: 22px;
642
+ height: 22px;
643
+ border-radius: 50%;
644
+ border: 2px solid transparent;
645
+ cursor: pointer;
646
+ padding: 0;
647
+ box-sizing: border-box;
648
+ }
649
+ .${c}-swatch.active {
650
+ border-color: #111;
651
+ box-shadow: 0 0 0 1px #fff inset;
652
+ }
653
+ .${c}-swatch:hover { opacity: 0.8; }
654
+ .${c}-thickness-wrap {
655
+ display: flex;
656
+ align-items: center;
657
+ gap: 6px;
658
+ }
659
+ .${c}-thickness-label {
660
+ font-size: 11px;
661
+ color: #888;
662
+ white-space: nowrap;
663
+ }
664
+ .${c}-thickness-slider {
665
+ width: 80px;
666
+ height: 4px;
667
+ accent-color: #0091FF;
668
+ cursor: pointer;
669
+ }
670
+ .${c}-radius-btn {
671
+ display: flex;
672
+ align-items: center;
673
+ justify-content: center;
674
+ width: 36px;
675
+ height: 36px;
676
+ border-radius: 50%;
677
+ border: none;
678
+ background: transparent;
679
+ color: #666;
680
+ cursor: pointer;
681
+ font-size: 11px;
682
+ font-weight: 600;
683
+ }
684
+ .${c}-radius-btn:hover { background: #f3f4f6; color: #111; }
685
+ .${c}-radius-btn.active { background: #0091FF; color: #fff; }
686
+ .${c}-actions {
687
+ display: flex;
688
+ gap: 8px;
689
+ align-items: center;
690
+ }
691
+ .${c}-btn-cancel {
692
+ padding: 8px 16px;
693
+ font-size: 13px;
694
+ border-radius: 8px;
695
+ background: transparent;
696
+ color: #333;
697
+ border: 1px solid #e5e7eb;
698
+ cursor: pointer;
699
+ font-family: inherit;
700
+ }
701
+ .${c}-btn-cancel:hover { background: #f3f4f6; }
702
+ .${c}-btn-done {
703
+ padding: 8px 16px;
704
+ font-size: 13px;
705
+ border-radius: 8px;
706
+ background: #0091FF;
707
+ color: #fff;
708
+ border: none;
709
+ cursor: pointer;
710
+ font-family: inherit;
711
+ }
712
+ .${c}-btn-done:hover { opacity: 0.9; }
713
+ .${c}-btn-crop-apply {
714
+ padding: 6px 12px;
715
+ font-size: 12px;
716
+ border-radius: 8px;
717
+ background: #0091FF;
718
+ color: #fff;
719
+ border: none;
720
+ cursor: pointer;
721
+ font-family: inherit;
722
+ }
723
+ .${c}-text-overlay {
724
+ position: absolute;
725
+ display: flex;
726
+ gap: 4px;
727
+ z-index: 10;
728
+ background: #fff;
729
+ border: 1px solid #e5e7eb;
730
+ border-radius: 8px;
731
+ padding: 4px;
732
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
733
+ }
734
+ .${c}-text-input {
735
+ width: 140px;
736
+ padding: 4px 8px;
737
+ font-size: 13px;
738
+ border: none;
739
+ border-radius: 4px;
740
+ background: #f3f4f6;
741
+ color: #111;
742
+ outline: none;
743
+ font-family: inherit;
744
+ }
745
+ .${c}-text-ok {
746
+ padding: 4px 8px;
747
+ font-size: 12px;
748
+ border-radius: 4px;
749
+ background: #0091FF;
750
+ color: #fff;
751
+ border: none;
752
+ cursor: pointer;
753
+ font-family: inherit;
754
+ }
755
+ .${c}-undo-btn {
756
+ display: flex;
757
+ align-items: center;
758
+ justify-content: center;
759
+ width: 36px;
760
+ height: 36px;
761
+ border-radius: 50%;
762
+ border: none;
763
+ background: transparent;
764
+ color: #666;
765
+ cursor: pointer;
766
+ }
767
+ .${c}-undo-btn:hover { background: #f3f4f6; color: #111; }
768
+ .${c}-undo-btn:disabled { opacity: 0.3; cursor: default; }
769
+ @media (max-width: 540px) {
770
+ .${c}-modal { width: 100%; height: 100vh; border-radius: 0; }
771
+ .${c}-backdrop { padding: 0; }
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">
774
+ <defs>
775
+ <linearGradient id="sw-preview-grad" x1="0%" y1="0%" x2="100%" y2="100%">
776
+ <stop offset="0%" stop-color="#0091FF"/>
777
+ <stop offset="33%" stop-color="#FF02F0"/>
778
+ <stop offset="66%" stop-color="#F76808"/>
779
+ <stop offset="100%" stop-color="#6647F0"/>
780
+ </linearGradient>
781
+ <linearGradient id="sw-preview-center" x1="81" y1="96" x2="113" y2="130" gradientUnits="userSpaceOnUse">
782
+ <stop stop-color="white"/>
783
+ <stop offset="0.88" stop-color="white" stop-opacity="0.3"/>
784
+ </linearGradient>
785
+ </defs>
786
+ <path d="M100 0C86.1929 0 75 11.1929 75 25V39.2893L65.033 29.3223C55.2699 19.5592 39.4408 19.5592 29.6777 29.3223C19.9146 39.0854 19.9146 54.9146 29.6777 64.6777L40 75H25C11.1929 75 0 86.1929 0 100C0 113.807 11.1929 125 25 125H39L29.2563 134.744C19.4932 144.507 19.4932 160.336 29.2563 170.099C39.0194 179.862 54.8485 179.862 64.6116 170.099L75 159.711V175C75 188.807 86.1929 200 100 200C113.807 200 125 188.807 125 175V160L135.744 170.744C145.507 180.507 161.336 180.507 171.099 170.744C180.862 160.981 180.862 145.151 171.099 135.388L160.711 125H175C188.807 125 200 113.807 200 100C200 86.1929 188.807 75 175 75H159.711L170.678 64.033C180.441 54.2699 180.441 38.4408 170.678 28.6777C160.915 18.9146 145.085 18.9146 135.322 28.6777L125 39V25C125 11.1929 113.807 0 100 0Z" fill="url(#sw-preview-grad)"/>
787
+ <circle cx="100" cy="100" r="30" fill="url(#sw-preview-center)"/>
788
+ </svg>`;let N=null,Y=null;const $=[];let le=!1;const nt="supportwire-message-preview-styles";function wi(){if(document.getElementById(nt))return;const e=document.createElement("style");e.id=nt,e.textContent=`
789
+ .sw-preview-stack {
790
+ position: fixed;
791
+ z-index: 999997;
792
+ width: 320px;
793
+ }
794
+
795
+ .sw-preview-dismiss {
796
+ position: absolute;
797
+ bottom: 100%;
798
+ right: 0;
799
+ width: 24px;
800
+ height: 24px;
801
+ margin-bottom: 4px;
802
+ border: none;
803
+ border-radius: 50%;
804
+ font-size: 15px;
805
+ line-height: 1;
806
+ cursor: pointer;
807
+ display: flex;
808
+ align-items: center;
809
+ justify-content: center;
810
+ opacity: 0;
811
+ transition: opacity 150ms ease, background 150ms ease;
812
+ pointer-events: auto;
813
+ z-index: 10;
814
+ }
815
+ .sw-preview-dismiss.sw-dismiss-dark {
816
+ background: rgba(255, 255, 255, 0.1);
817
+ color: rgba(255, 255, 255, 0.6);
818
+ }
819
+ .sw-preview-dismiss.sw-dismiss-dark:hover {
820
+ background: rgba(255, 255, 255, 0.18);
821
+ color: rgba(255, 255, 255, 0.9);
822
+ }
823
+ .sw-preview-dismiss.sw-dismiss-light {
824
+ background: rgba(0, 0, 0, 0.06);
825
+ color: rgba(0, 0, 0, 0.4);
826
+ }
827
+ .sw-preview-dismiss.sw-dismiss-light:hover {
828
+ background: rgba(0, 0, 0, 0.1);
829
+ color: rgba(0, 0, 0, 0.7);
830
+ }
831
+ .sw-preview-dismiss:active {
832
+ transform: scale(0.95);
833
+ }
834
+ .sw-preview-dismiss:focus-visible {
835
+ outline: 2px solid #0091FF;
836
+ outline-offset: 1px;
837
+ opacity: 1;
838
+ }
839
+ .sw-preview-stack:hover .sw-preview-dismiss {
840
+ opacity: 1;
841
+ }
842
+
843
+ .sw-preview-card {
844
+ position: absolute;
845
+ bottom: 0;
846
+ left: 0;
847
+ width: 100%;
848
+ border-radius: 16px;
849
+ padding: 12px 14px;
850
+ cursor: pointer;
851
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
852
+ box-sizing: border-box;
853
+ pointer-events: auto;
854
+ transition: transform 200ms cubic-bezier(0.32, 0.72, 0, 1), opacity 200ms cubic-bezier(0.32, 0.72, 0, 1);
855
+ transform-origin: bottom center;
856
+ }
857
+ .sw-preview-card:active {
858
+ transform: scale(0.97) !important;
859
+ }
860
+
861
+ .sw-preview-card.sw-card-dark {
862
+ background: #1a1a1a;
863
+ box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
864
+ }
865
+ .sw-preview-card.sw-card-light {
866
+ background: #ffffff;
867
+ border: 1px solid rgba(0, 0, 0, 0.08);
868
+ box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
869
+ }
870
+
871
+ .sw-preview-header {
872
+ display: flex;
873
+ align-items: center;
874
+ gap: 8px;
875
+ margin-bottom: 6px;
876
+ }
877
+ .sw-preview-logo {
878
+ flex-shrink: 0;
879
+ width: 20px;
880
+ height: 20px;
881
+ display: flex;
882
+ align-items: center;
883
+ justify-content: center;
884
+ }
885
+ .sw-preview-meta {
886
+ font-size: 11px;
887
+ line-height: 1.2;
888
+ flex: 1;
889
+ min-width: 0;
890
+ overflow: hidden;
891
+ text-overflow: ellipsis;
892
+ white-space: nowrap;
893
+ }
894
+ .sw-card-dark .sw-preview-meta { color: rgba(255, 255, 255, 0.5); }
895
+ .sw-card-light .sw-preview-meta { color: rgba(0, 0, 0, 0.45); }
896
+
897
+ .sw-preview-body {
898
+ font-size: 13px;
899
+ line-height: 1.4;
900
+ display: -webkit-box;
901
+ -webkit-line-clamp: 2;
902
+ -webkit-box-orient: vertical;
903
+ overflow: hidden;
904
+ word-break: break-word;
905
+ }
906
+ .sw-card-dark .sw-preview-body { color: rgba(255, 255, 255, 0.9); }
907
+ .sw-card-light .sw-preview-body { color: rgba(0, 0, 0, 0.85); }
908
+
909
+ @media (prefers-reduced-motion: reduce) {
910
+ .sw-preview-card {
911
+ transition: opacity 200ms ease-out !important;
912
+ }
913
+ .sw-preview-dismiss {
914
+ transition: opacity 150ms ease-out !important;
915
+ }
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)">
918
+ <line x1="9" y1="1" x2="1" y2="9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
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;
921
+ //# sourceMappingURL=index.cjs.map