@paramms/chat-widget 1.0.44 → 1.0.45

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/embed.js CHANGED
@@ -1,8 +1,10 @@
1
- var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X,ce)=>X in J?ni(J,X,{enumerable:!0,configurable:!0,writable:!0,value:ce}):J[X]=ce;var a=(J,X,ce)=>ii(J,typeof X!="symbol"?X+"":X,ce);const X="oc_uid";function ce(n){try{const e=document.cookie.match(new RegExp(`(?:^|; )${n}=([^;]*)`));return e?decodeURIComponent(e[1]):null}catch{return null}}function It(n,e){try{const o=location.protocol==="https:"?"; Secure":"";document.cookie=`${n}=${encodeURIComponent(e)}; Max-Age=31536000; Path=/; SameSite=Lax${o}`}catch{}}function Et(){return`g_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function et(){let n=null;try{n=localStorage.getItem(X)}catch{}n||(n=ce(X));const e=n??Et();try{localStorage.setItem(X,e)}catch{}return It(X,e),e}function Tt(n){const e=n.length;let t=0,o=0;for(;o<e;){let i=n.charCodeAt(o++);if(i&4294967168)if(!(i&4294965248))t+=2;else{if(i>=55296&&i<=56319&&o<e){const s=n.charCodeAt(o);(s&64512)===56320&&(++o,i=((i&1023)<<10)+(s&1023)+65536)}i&4294901760?t+=4:t+=3}else{t++;continue}}return t}function Ut(n,e,t){const o=n.length;let i=t,s=0;for(;s<o;){let r=n.charCodeAt(s++);if(r&4294967168)if(!(r&4294965248))e[i++]=r>>6&31|192;else{if(r>=55296&&r<=56319&&s<o){const p=n.charCodeAt(s);(p&64512)===56320&&(++s,r=((r&1023)<<10)+(p&1023)+65536)}r&4294901760?(e[i++]=r>>18&7|240,e[i++]=r>>12&63|128,e[i++]=r>>6&63|128):(e[i++]=r>>12&15|224,e[i++]=r>>6&63|128)}else{e[i++]=r;continue}e[i++]=r&63|128}}const At=new TextEncoder,Pt=50;function Bt(n,e,t){At.encodeInto(n,e.subarray(t))}function Lt(n,e,t){n.length>Pt?Bt(n,e,t):Ut(n,e,t)}const Mt=4096;function tt(n,e,t){let o=e;const i=o+t,s=[];let r="";for(;o<i;){const p=n[o++];if(!(p&128))s.push(p);else if((p&224)===192){const c=n[o++]&63;s.push((p&31)<<6|c)}else if((p&240)===224){const c=n[o++]&63,u=n[o++]&63;s.push((p&31)<<12|c<<6|u)}else if((p&248)===240){const c=n[o++]&63,u=n[o++]&63,y=n[o++]&63;let d=(p&7)<<18|c<<12|u<<6|y;d>65535&&(d-=65536,s.push(d>>>10&1023|55296),d=56320|d&1023),s.push(d)}else s.push(p);s.length>=Mt&&(r+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(r+=String.fromCharCode(...s)),r}const zt=new TextDecoder,Kt=200;function $t(n,e,t){const o=n.subarray(e,e+t);return zt.decode(o)}function Rt(n,e,t){return t>Kt?$t(n,e,t):tt(n,e,t)}class Te{constructor(e,t){a(this,"type");a(this,"data");this.type=e,this.data=t}}class O extends Error{constructor(e){super(e);const t=Object.create(O.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:O.name})}}const ue=4294967295;function Dt(n,e,t){const o=t/4294967296,i=t;n.setUint32(e,o),n.setUint32(e+4,i)}function nt(n,e,t){const o=Math.floor(t/4294967296),i=t;n.setUint32(e,o),n.setUint32(e+4,i)}function it(n,e){const t=n.getInt32(e),o=n.getUint32(e+4);return t*4294967296+o}function _t(n,e){const t=n.getUint32(e),o=n.getUint32(e+4);return t*4294967296+o}const jt=-1,Ht=4294967296-1,qt=17179869184-1;function Nt({sec:n,nsec:e}){if(n>=0&&e>=0&&n<=qt)if(e===0&&n<=Ht){const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,n),t}else{const t=n/4294967296,o=n&4294967295,i=new Uint8Array(8),s=new DataView(i.buffer);return s.setUint32(0,e<<2|t&3),s.setUint32(4,o),i}else{const t=new Uint8Array(12),o=new DataView(t.buffer);return o.setUint32(0,e),nt(o,4,n),t}}function Ft(n){const e=n.getTime(),t=Math.floor(e/1e3),o=(e-t*1e3)*1e6,i=Math.floor(o/1e9);return{sec:t+i,nsec:o-i*1e9}}function Ot(n){if(n instanceof Date){const e=Ft(n);return Nt(e)}else return null}function Wt(n){const e=new DataView(n.buffer,n.byteOffset,n.byteLength);switch(n.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{const t=e.getUint32(0),o=e.getUint32(4),i=(t&3)*4294967296+o,s=t>>>2;return{sec:i,nsec:s}}case 12:{const t=it(e,4),o=e.getUint32(0);return{sec:t,nsec:o}}default:throw new O(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${n.length}`)}}function Vt(n){const e=Wt(n);return new Date(e.sec*1e3+e.nsec/1e6)}const Xt={type:jt,encode:Ot,decode:Vt},Le=class Le{constructor(){a(this,"__brand");a(this,"builtInEncoders",[]);a(this,"builtInDecoders",[]);a(this,"encoders",[]);a(this,"decoders",[]);this.register(Xt)}register({type:e,encode:t,decode:o}){if(e>=0)this.encoders[e]=t,this.decoders[e]=o;else{const i=-1-e;this.builtInEncoders[i]=t,this.builtInDecoders[i]=o}}tryToEncode(e,t){for(let o=0;o<this.builtInEncoders.length;o++){const i=this.builtInEncoders[o];if(i!=null){const s=i(e,t);if(s!=null){const r=-1-o;return new Te(r,s)}}}for(let o=0;o<this.encoders.length;o++){const i=this.encoders[o];if(i!=null){const s=i(e,t);if(s!=null){const r=o;return new Te(r,s)}}}return e instanceof Te?e:null}decode(e,t,o){const i=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return i?i(e,t,o):new Te(t,e)}};a(Le,"defaultCodec",new Le);let Ue=Le;function Gt(n){return n instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&n instanceof SharedArrayBuffer}function De(n){return n instanceof Uint8Array?n:ArrayBuffer.isView(n)?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):Gt(n)?new Uint8Array(n):Uint8Array.from(n)}const Yt=100,Jt=2048;class _e{constructor(e){a(this,"extensionCodec");a(this,"context");a(this,"useBigInt64");a(this,"maxDepth");a(this,"initialBufferSize");a(this,"sortKeys");a(this,"forceFloat32");a(this,"ignoreUndefined");a(this,"forceIntegerToFloat");a(this,"pos");a(this,"view");a(this,"bytes");a(this,"entered",!1);this.extensionCodec=(e==null?void 0:e.extensionCodec)??Ue.defaultCodec,this.context=e==null?void 0:e.context,this.useBigInt64=(e==null?void 0:e.useBigInt64)??!1,this.maxDepth=(e==null?void 0:e.maxDepth)??Yt,this.initialBufferSize=(e==null?void 0:e.initialBufferSize)??Jt,this.sortKeys=(e==null?void 0:e.sortKeys)??!1,this.forceFloat32=(e==null?void 0:e.forceFloat32)??!1,this.ignoreUndefined=(e==null?void 0:e.ignoreUndefined)??!1,this.forceIntegerToFloat=(e==null?void 0:e.forceIntegerToFloat)??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new _e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){const t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(e){const t=new ArrayBuffer(e),o=new Uint8Array(t),i=new DataView(t);o.set(this.bytes),this.view=i,this.bytes=o}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){const o=Tt(e);this.ensureBufferSizeToWrite(5+o),this.writeStringHeader(o),Lt(e,this.bytes,this.pos),this.pos+=o}encodeObject(e,t){const o=this.extensionCodec.tryToEncode(e,this.context);if(o!=null)this.encodeExtension(o);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,t);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){const t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw new Error(`Too large binary: ${t}`);const o=De(e);this.writeU8a(o)}encodeArray(e,t){const o=e.length;if(o<16)this.writeU8(144+o);else if(o<65536)this.writeU8(220),this.writeU16(o);else if(o<4294967296)this.writeU8(221),this.writeU32(o);else throw new Error(`Too large array: ${o}`);for(const i of e)this.doEncode(i,t+1)}countWithoutUndefined(e,t){let o=0;for(const i of t)e[i]!==void 0&&o++;return o}encodeMap(e,t){const o=Object.keys(e);this.sortKeys&&o.sort();const i=this.ignoreUndefined?this.countWithoutUndefined(e,o):o.length;if(i<16)this.writeU8(128+i);else if(i<65536)this.writeU8(222),this.writeU16(i);else if(i<4294967296)this.writeU8(223),this.writeU32(i);else throw new Error(`Too large map object: ${i}`);for(const s of o){const r=e[s];this.ignoreUndefined&&r===void 0||(this.encodeString(s),this.doEncode(r,t+1))}}encodeExtension(e){if(typeof e.data=="function"){const o=e.data(this.pos+6),i=o.length;if(i>=4294967296)throw new Error(`Too large extension object: ${i}`);this.writeU8(201),this.writeU32(i),this.writeI8(e.type),this.writeU8a(o);return}const t=e.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw new Error(`Too large extension object: ${t}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),Dt(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),nt(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}function Zt(n,e){return new _e(e).encodeSharedRef(n)}function je(n){return`${n<0?"-":""}0x${Math.abs(n).toString(16).padStart(2,"0")}`}const Qt=16,en=16;class tn{constructor(e=Qt,t=en){a(this,"hit",0);a(this,"miss",0);a(this,"caches");a(this,"maxKeyLength");a(this,"maxLengthPerKey");this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let o=0;o<this.maxKeyLength;o++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,o){const i=this.caches[o-1];e:for(const s of i){const r=s.bytes;for(let p=0;p<o;p++)if(r[p]!==e[t+p])continue e;return s.str}return null}store(e,t){const o=this.caches[e.length-1],i={bytes:e,str:t};o.length>=this.maxLengthPerKey?o[Math.random()*o.length|0]=i:o.push(i)}decode(e,t,o){const i=this.find(e,t,o);if(i!=null)return this.hit++,i;this.miss++;const s=tt(e,t,o),r=Uint8Array.prototype.slice.call(e,t,t+o);return this.store(r,s),s}}const He="array",fe="map_key",ot="map_value",nn=n=>{if(typeof n=="string"||typeof n=="number")return n;throw new O("The type of key must be string or number but "+typeof n)};class on{constructor(){a(this,"stack",[]);a(this,"stackHeadPosition",-1)}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const t=this.getUninitializedStateFromPool();t.type=He,t.position=0,t.size=e,t.array=new Array(e)}pushMapState(e){const t=this.getUninitializedStateFromPool();t.type=fe,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===He){const o=e;o.size=0,o.array=void 0,o.position=0,o.type=void 0}if(e.type===fe||e.type===ot){const o=e;o.size=0,o.map=void 0,o.readCount=0,o.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const we=-1,qe=new DataView(new ArrayBuffer(0)),sn=new Uint8Array(qe.buffer);try{qe.getInt8(0)}catch(n){if(!(n instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const st=new RangeError("Insufficient data"),rn=new tn;class Ne{constructor(e){a(this,"extensionCodec");a(this,"context");a(this,"useBigInt64");a(this,"rawStrings");a(this,"maxStrLength");a(this,"maxBinLength");a(this,"maxArrayLength");a(this,"maxMapLength");a(this,"maxExtLength");a(this,"keyDecoder");a(this,"mapKeyConverter");a(this,"totalPos",0);a(this,"pos",0);a(this,"view",qe);a(this,"bytes",sn);a(this,"headByte",we);a(this,"stack",new on);a(this,"entered",!1);this.extensionCodec=(e==null?void 0:e.extensionCodec)??Ue.defaultCodec,this.context=e==null?void 0:e.context,this.useBigInt64=(e==null?void 0:e.useBigInt64)??!1,this.rawStrings=(e==null?void 0:e.rawStrings)??!1,this.maxStrLength=(e==null?void 0:e.maxStrLength)??ue,this.maxBinLength=(e==null?void 0:e.maxBinLength)??ue,this.maxArrayLength=(e==null?void 0:e.maxArrayLength)??ue,this.maxMapLength=(e==null?void 0:e.maxMapLength)??ue,this.maxExtLength=(e==null?void 0:e.maxExtLength)??ue,this.keyDecoder=(e==null?void 0:e.keyDecoder)!==void 0?e.keyDecoder:rn,this.mapKeyConverter=(e==null?void 0:e.mapKeyConverter)??nn}clone(){return new Ne({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=we,this.stack.reset()}setBuffer(e){const t=De(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===we&&!this.hasRemaining(1))this.setBuffer(e);else{const t=this.bytes.subarray(this.pos),o=De(e),i=new Uint8Array(t.length+o.length);i.set(t),i.set(o,t.length),this.setBuffer(i)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:t,pos:o}=this;return new RangeError(`Extra ${t.byteLength-o} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,o;for await(const p of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(p);try{o=this.doDecodeSync(),t=!0}catch(c){if(!(c instanceof RangeError))throw c}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return o}const{headByte:i,pos:s,totalPos:r}=this;throw new RangeError(`Insufficient data in parsing ${je(i)} at ${r} (${s} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let o=t,i=-1;for await(const s of e){if(t&&i===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(s),o&&(i=this.readArraySize(),o=!1,this.complete());try{for(;yield this.doDecodeSync(),--i!==0;);}catch(r){if(!(r instanceof RangeError))throw r}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){const i=e-128;if(i!==0){this.pushMapState(i),this.complete();continue e}else t={}}else if(e<160){const i=e-144;if(i!==0){this.pushArrayState(i),this.complete();continue e}else t=[]}else{const i=e-160;t=this.decodeString(i,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)this.useBigInt64?t=this.readU64AsBigInt():t=this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)this.useBigInt64?t=this.readI64AsBigInt():t=this.readI64();else if(e===217){const i=this.lookU8();t=this.decodeString(i,1)}else if(e===218){const i=this.lookU16();t=this.decodeString(i,2)}else if(e===219){const i=this.lookU32();t=this.decodeString(i,4)}else if(e===220){const i=this.readU16();if(i!==0){this.pushArrayState(i),this.complete();continue e}else t=[]}else if(e===221){const i=this.readU32();if(i!==0){this.pushArrayState(i),this.complete();continue e}else t=[]}else if(e===222){const i=this.readU16();if(i!==0){this.pushMapState(i),this.complete();continue e}else t={}}else if(e===223){const i=this.readU32();if(i!==0){this.pushMapState(i),this.complete();continue e}else t={}}else if(e===196){const i=this.lookU8();t=this.decodeBinary(i,1)}else if(e===197){const i=this.lookU16();t=this.decodeBinary(i,2)}else if(e===198){const i=this.lookU32();t=this.decodeBinary(i,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){const i=this.lookU8();t=this.decodeExtension(i,1)}else if(e===200){const i=this.lookU16();t=this.decodeExtension(i,2)}else if(e===201){const i=this.lookU32();t=this.decodeExtension(i,4)}else throw new O(`Unrecognized type byte: ${je(e)}`);this.complete();const o=this.stack;for(;o.length>0;){const i=o.top();if(i.type===He)if(i.array[i.position]=t,i.position++,i.position===i.size)t=i.array,o.release(i);else continue e;else if(i.type===fe){if(t==="__proto__")throw new O("The key __proto__ is not allowed");i.key=this.mapKeyConverter(t),i.type=ot;continue e}else if(i.map[i.key]=t,i.readCount++,i.readCount===i.size)t=i.map,o.release(i);else{i.key=null,i.type=fe;continue e}}return t}}readHeadByte(){return this.headByte===we&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=we}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new O(`Unrecognized array type byte: ${je(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new O(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new O(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){var s;if(e>this.maxStrLength)throw new O(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw st;const o=this.pos+t;let i;return this.stateIsMapKey()&&((s=this.keyDecoder)!=null&&s.canBeCached(e))?i=this.keyDecoder.decode(this.bytes,o,e):i=Rt(this.bytes,o,e),this.pos+=t+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===fe:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new O(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw st;const o=this.pos+t,i=this.bytes.subarray(o,o+e);return this.pos+=t+e,i}decodeExtension(e,t){if(e>this.maxExtLength)throw new O(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const o=this.view.getInt8(this.pos+t),i=this.decodeBinary(e,t+1);return this.extensionCodec.decode(i,o,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=_t(this.view,this.pos);return this.pos+=8,e}readI64(){const e=it(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}}function an(n,e){return new Ne(e).decode(n)}const cn=new Set(["auth","open","send","sync","history","read","typing","react","edit","delete","invoke","pubkey","ping","annotate","annotate_clear","uploadPrekeys","fetchPrekey","assign","tag","note","agent_status","subscribe_inbox","unsubscribe_inbox"]);function ln(n){return cn.has(n.type)}function Fe(n){return Zt(n)}function rt(n){let e;try{e=an(n)}catch{return null}return typeof e!="object"||e===null||typeof e.type!="string"?null:e}class dn{constructor(e){a(this,"conversationId");a(this,"state","");a(this,"version",0);a(this,"hasMoreHistory",!1);a(this,"lastReadByOthers",0);a(this,"assignedAgentId");a(this,"accent");a(this,"subject");a(this,"name");a(this,"e2e",!1);a(this,"offline",!1);a(this,"offlineMessage","");a(this,"launcherMessage",null);a(this,"preChat",null);a(this,"whiteLabel",!1);a(this,"typing",new Set);a(this,"online",new Set);a(this,"annotations",[]);a(this,"annotationVersion",0);a(this,"sentiment");a(this,"sentimentScore");a(this,"actions",[]);a(this,"byId",new Map);a(this,"keyByClient",new Map);a(this,"_maxSeq",0);a(this,"_sorted",null);this.me=e}messages(){return this._sorted||(this._sorted=[...this.byId.values()].sort((e,t)=>{const o=e.status==="pending",i=t.status==="pending";return o!==i?o?1:-1:o&&i?e.ts-t.ts:e.seq-t.seq})),this._sorted}visibleActions(){return this.actions.filter(e=>!e.availableInStates||e.availableInStates.includes(this.state))}highestSeq(){return this._maxSeq}addOptimistic(e,t){const o={id:e,conversationId:this.conversationId,seq:0,senderId:this.me,senderRole:"guest",content:t,ts:Date.now(),clientMsgId:e,status:"pending"};return this.byId.set(e,o),this.keyByClient.set(e,e),this._sorted=null,o}apply(e){var t;switch(e.type){case"opened":this.conversationId=e.conversation.id,this.state=e.conversation.state,e.subject&&(this.subject=e.subject),e.annotations&&(this.annotations=e.annotations,this.annotationVersion++);return;case"manifest":this.actions=e.actions,this.version=e.version,e.name&&(this.name=e.name),(t=e.theme)!=null&&t.accent&&(this.accent=e.theme.accent),e.e2e&&(this.e2e=!0),this.offline=e.offline===!0,this.offlineMessage=e.offlineMessage??"",e.launcherMessage&&(this.launcherMessage=e.launcherMessage),e.whiteLabel&&(this.whiteLabel=!0),e.preChat&&(this.preChat=e.preChat);return;case"message":this.upsert({...e.message});return;case"ack":{const o=this.keyByClient.get(e.clientMsgId),i=o?this.byId.get(o):void 0;if(i&&o){this.byId.delete(o);const s={...i,id:e.messageId,seq:e.seq,ts:e.ts,status:"sent"};this.byId.set(e.messageId,s),this.keyByClient.set(e.clientMsgId,e.messageId),e.seq>this._maxSeq&&(this._maxSeq=e.seq)}this._sorted=null;return}case"delivered":this.markOwnStatus(e.seq,"delivered");return;case"read":e.by!==this.me&&(this.lastReadByOthers=Math.max(this.lastReadByOthers,e.seq),this.markOwnStatus(e.seq,"read"));return;case"sync":for(const o of e.messages)this.upsert({...o});return;case"history":for(const o of e.messages)this.upsert({...o});this.hasMoreHistory=e.hasMore;return;case"typing":e.userId!==this.me&&(e.isTyping?this.typing.add(e.userId):this.typing.delete(e.userId));return;case"reaction":{const o=this.byId.get(e.messageId);if(!o)return;const i={...o.reactions??{}},s=(i[e.emoji]??[]).filter(r=>r!==e.by);e.removed||s.push(e.by),s.length?i[e.emoji]=s:delete i[e.emoji],this.byId.set(e.messageId,{...o,reactions:i}),this._sorted=null;return}case"edited":{const o=this.byId.get(e.messageId);o&&(this.byId.set(e.messageId,{...o,content:e.content,editedAt:e.editedAt}),this._sorted=null);return}case"deleted":{const o=this.byId.get(e.messageId);o&&(this.byId.set(e.messageId,{...o,deletedAt:e.ts}),this._sorted=null);return}case"state":this.state=e.state;return;case"assigned":this.assignedAgentId=e.agentId??void 0;return;case"presence":e.status==="online"?this.online.add(e.userId):this.online.delete(e.userId);return;case"subjectState":case"invoked":case"authed":case"error":case"pong":return;case"annotation":this.annotations=[...this.annotations,e.stroke],this.annotationVersion++;return;case"annotation_clear":this.annotations=[],this.annotationVersion++;return;case"sentiment":this.sentiment=e.label,this.sentimentScore=e.score;return;default:return}}upsert(e){const t=this.byId.get(e.id);this.byId.set(e.id,t?{...t,...e}:e),e.seq>this._maxSeq&&(this._maxSeq=e.seq),this._sorted=null}markOwnStatus(e,t){const o=at(t);let i=!1;for(const[s,r]of this.byId)r.senderId!==this.me||r.seq<=0||r.seq>e||at(r.status)>=o||(this.byId.set(s,{...r,status:t}),i=!0);i&&(this._sorted=null)}}function at(n){switch(n){case"read":return 3;case"delivered":return 2;case"sent":return 1;default:return 0}}const ct="http://www.w3.org/2000/svg",hn=8e3;class pn{constructor(){a(this,"svg",null);a(this,"timers",new Set)}apply(e){var t;if(e.type==="annotation")this.draw(e.stroke);else if(e.type==="annotation_clear")this.clear();else if(e.type==="opened"&&((t=e.annotations)!=null&&t.length))for(const o of e.annotations)this.draw(o)}ensureSvg(){var t;if((t=this.svg)!=null&&t.isConnected)return this.svg;const e=document.createElementNS(ct,"svg");return e.setAttribute("data-relay-annotations",""),e.setAttribute("aria-hidden","true"),e.setAttribute("style","position:fixed;inset:0;width:100vw;height:100vh;pointer-events:none;z-index:2147483000;"),document.body.append(e),this.svg=e,e}draw(e){var p;if(typeof document>"u"||!((p=e.points)!=null&&p.length))return;const t=this.ensureSvg(),o=window.innerWidth,i=window.innerHeight,s=document.createElementNS(ct,"polyline");s.setAttribute("points",e.points.map(c=>`${(c.x*o).toFixed(1)},${(c.y*i).toFixed(1)}`).join(" ")),s.setAttribute("fill","none"),s.setAttribute("stroke",e.color||"#ff3b30"),s.setAttribute("stroke-width",String(e.width||3)),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),s.setAttribute("data-stroke-id",e.id),t.append(s);const r=setTimeout(()=>{s.style.transition="opacity 600ms",s.style.opacity="0";const c=setTimeout(()=>{s.remove(),this.timers.delete(c)},650);this.timers.add(c),this.timers.delete(r)},hn);this.timers.add(r)}clear(){var e;(e=this.svg)==null||e.replaceChildren()}destroy(){var e;for(const t of this.timers)clearTimeout(t);this.timers.clear(),(e=this.svg)==null||e.remove(),this.svg=null}}class un{constructor(e){a(this,"socket",null);a(this,"state","idle");a(this,"authed",!1);a(this,"everAuthed",!1);a(this,"attempt",0);a(this,"outbox",[]);a(this,"stopped",!1);a(this,"timer",null);a(this,"refreshing",!1);this.opts=e}connect(){var o,i;if(this.state==="connecting"||this.state==="open")return;this.stopped=!1,this.state="connecting",this.authed=!1,(i=(o=this.opts).onStatusChange)==null||i.call(o,this.attempt>0?"reconnecting":"connecting");const t=(this.opts.socketFactory??gn)(this.opts.url);t.binaryType="arraybuffer",this.socket=t,t.onopen=()=>{this.raw({type:"auth",token:this.opts.token})},t.onmessage=s=>{const r=rt(new Uint8Array(s.data));!r||ln(r)||this.handle(r)},t.onclose=()=>this.onClosed(),t.onerror=()=>{try{t.close()}catch{}}}send(e){if(this.state==="open"&&this.authed){this.raw(e);return}this.queue(e)}pendingCount(){return this.outbox.length}close(){var e;this.stopped=!0,this.timer&&clearTimeout(this.timer),this.state="closed";try{(e=this.socket)==null||e.close()}catch{}}handle(e){var t,o,i,s;if(e.type==="authed"&&(this.attempt=0,this.state="open",this.authed=!0,this.everAuthed=!0,(o=(t=this.opts).onStatusChange)==null||o.call(t,"open"),this.raw(this.opts.open),this.opts.open.type!=="open"&&this.flush()),e.type==="opened"&&(this.raw({type:"sync",conversationId:e.conversation.id,sinceSeq:this.opts.getCursor()}),this.flush(e.conversation.id)),e.type==="error"&&fn.has(e.code)){if(e.code==="UNAUTHORIZED"&&this.opts.refreshToken&&!this.refreshing){this.refreshing=!0,(s=(i=this.opts).onStatusChange)==null||s.call(i,"reconnecting","Renewing session…"),this.opts.refreshToken().then(r=>{var p;if(this.refreshing=!1,!r){this.fatal(e);return}this.opts.token=r;try{(p=this.socket)==null||p.close()}catch{}}).catch(()=>{this.refreshing=!1,this.fatal(e)});return}this.fatal(e);return}this.opts.onFrame(e)}fatal(e){var t,o,i;this.stopped=!0;try{(t=this.socket)==null||t.close()}catch{}this.state="closed",(i=(o=this.opts).onStatusChange)==null||i.call(o,"error",wn(e.code)),this.opts.onFrame(e)}flush(e){const t=this.outbox;this.outbox=[];for(const o of t)this.raw(e&&o.type==="send"&&o.conversationId!==e?{...o,conversationId:e}:o)}queue(e){const t=this.opts.maxOutbox??1e3;this.outbox.length>=t&&(this.outbox=this.outbox.slice(this.outbox.length-(t>>1))),this.outbox.push(e)}raw(e){if(!this.socket){this.queue(e);return}try{this.socket.send(Fe(e))}catch{this.queue(e)}}onClosed(){var i,s;if(this.authed=!1,this.socket=null,this.stopped){this.state="closed";return}this.state="idle";const e=this.opts.backoffBaseMs??500,t=this.opts.backoffMaxMs??15e3,o=Math.min(t,e*2**this.attempt)*(.5+Math.random()*.5);this.attempt++,this.attempt>=3&&!this.everAuthed&&((s=(i=this.opts).onStatusChange)==null||s.call(i,"reconnecting","Can't reach chat — retrying…")),this.timer=setTimeout(()=>this.connect(),o)}}const fn=new Set(["UNAUTHORIZED"]);function wn(n){switch(n){case"UNAUTHORIZED":return"Chat unavailable — sign-in/token was rejected";default:return"Chat unavailable"}}function gn(n){return new WebSocket(n)}const lt=200,xn=7*864e5;class yn{constructor(e){a(this,"key");this.key=`ocw_outbox_${e}`}load(){try{const e=localStorage.getItem(this.key);if(!e)return[];const t=JSON.parse(e),o=Date.now()-xn,i=t.filter(s=>s.ts>=o);return i.length!==t.length&&this.save(i),i}catch{return[]}}add(e){try{const t=this.load();t.push(e),this.save(t.length>lt?t.slice(t.length-lt):t)}catch{}}remove(e){try{const t=this.load().filter(o=>o.clientMsgId!==e);this.save(t)}catch{}}save(e){try{localStorage.setItem(this.key,JSON.stringify(e))}catch{}}}const B=()=>globalThis.crypto.subtle;function Ae(n){const e=n instanceof Uint8Array?n:new Uint8Array(n);let t="";for(const o of e)t+=String.fromCharCode(o);return btoa(t)}function Oe(n){const e=atob(n),t=new ArrayBuffer(e.length),o=new Uint8Array(t);for(let i=0;i<e.length;i++)o[i]=e.charCodeAt(i);return o}async function ge(){const n=await B().generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey","deriveBits"]);return{publicKey:n.publicKey,privateKey:n.privateKey}}async function ie(n){return Ae(await B().exportKey("raw",n))}async function le(n){return B().importKey("raw",Oe(n),{name:"ECDH",namedCurve:"P-256"},!1,[])}async function bn(n,e){const t=await le(e);return B().deriveKey({name:"ECDH",public:t},n,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function mn(n,e){const t=globalThis.crypto.getRandomValues(new Uint8Array(12)),o=new TextEncoder().encode(e),i=await B().encrypt({name:"AES-GCM",iv:t},n,o);return{ct:Ae(i),iv:Ae(t)}}async function vn(n,e,t){const o=await B().decrypt({name:"AES-GCM",iv:Oe(t)},n,Oe(e));return new TextDecoder().decode(o)}async function kn(n){var t,o;try{const i=(t=globalThis.localStorage)==null?void 0:t.getItem(n);if(i){const{pub:s,priv:r}=JSON.parse(i),p=await B().importKey("jwk",s,{name:"ECDH",namedCurve:"P-256"},!0,[]),c=await B().importKey("jwk",r,{name:"ECDH",namedCurve:"P-256"},!0,["deriveKey","deriveBits"]);return{publicKey:p,privateKey:c}}}catch{}const e=await ge();try{const i=await B().exportKey("jwk",e.publicKey),s=await B().exportKey("jwk",e.privateKey);(o=globalThis.localStorage)==null||o.setItem(n,JSON.stringify({pub:i,priv:s}))}catch{}return e}async function Sn(n,e){const t=await B().exportKey("raw",e),o=await B().sign({name:"ECDSA",hash:"SHA-256"},n,t);return Ae(o)}async function Cn(){const n=await ge(),e=await B().generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]);return{ecdhKP:n,ecdsaKP:{publicKey:e.publicKey,privateKey:e.privateKey},publicKeyB64:await ie(n.publicKey),sigPublicKeyB64:await ie(e.publicKey)}}async function dt(n){var t,o;try{const i=(t=globalThis.localStorage)==null?void 0:t.getItem(`${n}-identity`);if(i){const s=JSON.parse(i),r=await B().importKey("jwk",s.ecdhPub,{name:"ECDH",namedCurve:"P-256"},!0,[]),p=await B().importKey("jwk",s.ecdhPriv,{name:"ECDH",namedCurve:"P-256"},!0,["deriveKey","deriveBits"]),c=await B().importKey("jwk",s.ecdsaPub,{name:"ECDSA",namedCurve:"P-256"},!0,["verify"]),u=await B().importKey("jwk",s.ecdsaPriv,{name:"ECDSA",namedCurve:"P-256"},!0,["sign"]);return{ecdhKP:{publicKey:r,privateKey:p},ecdsaKP:{publicKey:c,privateKey:u},publicKeyB64:await ie(r),sigPublicKeyB64:await ie(c)}}}catch{}const e=await Cn();try{const i=await B().exportKey("jwk",e.ecdhKP.publicKey),s=await B().exportKey("jwk",e.ecdhKP.privateKey),r=await B().exportKey("jwk",e.ecdsaKP.publicKey),p=await B().exportKey("jwk",e.ecdsaKP.privateKey);(o=globalThis.localStorage)==null||o.setItem(`${n}-identity`,JSON.stringify({ecdhPub:i,ecdhPriv:s,ecdsaPub:r,ecdsaPriv:p}))}catch{}return e}async function In(n,e){const t=await ge(),o=await ie(t.publicKey),i=await le(e.identityKey),s=await le(e.signedPrekey),r=e.oneTimePrekey?await le(e.oneTimePrekey):null,p=await oe(n.privateKey,s),c=await oe(t.privateKey,i),u=await oe(t.privateKey,s),y=r?await oe(t.privateKey,r):null,d=ht(p,c,u,...y?[y]:[]);return{sharedKey:await pt(d),ephemeralPublicKey:o}}async function En(n,e,t,o,i){const s=await le(t),r=await le(o),p=await oe(e.privateKey,s),c=await oe(n.privateKey,r),u=await oe(e.privateKey,r),y=i?await oe(i.privateKey,r):null,d=ht(p,c,u,...y?[y]:[]);return pt(d)}async function oe(n,e){return B().deriveBits({name:"ECDH",public:e},n,256)}function ht(...n){const e=n.reduce((i,s)=>i+s.byteLength,0),t=new Uint8Array(e);let o=0;for(const i of n)t.set(new Uint8Array(i),o),o+=i.byteLength;return t.buffer}async function pt(n){const e=await B().importKey("raw",n,"HKDF",!1,["deriveKey"]);return B().deriveKey({name:"HKDF",hash:"SHA-256",salt:new Uint8Array(32),info:new TextEncoder().encode("ObjectChat X3DH v1")},e,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}const Tn=20;class Un{constructor(e){a(this,"kp");a(this,"shared");a(this,"identityKP");a(this,"signedPreKP");a(this,"signedPrekeyId");a(this,"otpKeys",[]);a(this,"x3dhShared");a(this,"pendingX3DH");this.storageKey=e}get ready(){return!!(this.shared??this.x3dhShared)}async begin(){return this.kp=await kn(this.storageKey),ie(this.kp.publicKey)}async onPeerKey(e){this.kp&&(this.shared=await bn(this.kp.privateKey,e))}async initX3DH(){this.identityKP=await dt(this.storageKey),this.signedPreKP=await ge(),this.signedPrekeyId=`spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;for(let i=0;i<Tn;i++)this.otpKeys.push(await ge());const e=await ie(this.signedPreKP.publicKey),t=await Sn(this.identityKP.ecdsaKP.privateKey,this.signedPreKP.publicKey),o=await Promise.all(this.otpKeys.map(i=>ie(i.publicKey)));return{identityKey:this.identityKP.publicKeyB64,signedPrekey:e,signedPrekeyId:this.signedPrekeyId,signature:t,oneTimePrekeys:o}}async x3dhSendTo(e){this.identityKP||(this.identityKP=await dt(this.storageKey));const{sharedKey:t,ephemeralPublicKey:o}=await In(this.identityKP.ecdhKP,e);return this.x3dhShared=t,{ephemeralKey:o,spkId:e.signedPrekeyId,usedOTP:!!e.oneTimePrekey,senderIK:this.identityKP.publicKeyB64}}async x3dhReceiveFrom(e,t,o){if(!this.identityKP||!this.signedPreKP){this.pendingX3DH={senderIK:e,ephemeralKey:t,spkId:o};return}const i=this.otpKeys.shift();this.x3dhShared=await En(this.identityKP.ecdhKP,this.signedPreKP,e,t,i)}async flushPendingX3DH(){if(!this.pendingX3DH)return;const{senderIK:e,ephemeralKey:t,spkId:o}=this.pendingX3DH;this.pendingX3DH=void 0,await this.x3dhReceiveFrom(e,t,o)}async sealText(e,t){const o=this.x3dhShared??this.shared;if(!o)throw new Error("secure channel not ready");const{ct:i,iv:s}=await mn(o,e);return{kind:"text",text:i,enc:!0,iv:s,...t?{x3dhEK:t.ephemeralKey,x3dhSPK:t.spkId,x3dhIK:t.senderIK}:{}}}async openContent(e){if(e.kind!=="text"||!e.enc||!e.iv)return e;const t=this.x3dhShared??this.shared;if(!t)return{kind:"text",text:"🔒 encrypted"};try{return{kind:"text",text:await vn(t,e.text,e.iv)}}catch{return{kind:"text",text:"🔒 unable to decrypt"}}}async openFrame(e){if(e.type==="message")e.message.content=await this.openContent(e.message.content);else if(e.type==="sync")for(const t of e.messages)t.content=await this.openContent(t.content)}}function An(n){if(n.kind!=="text"||!n.enc)return null;const e=n;return!e.x3dhEK||!e.x3dhSPK||!e.x3dhIK?null:{x3dhEK:e.x3dhEK,x3dhSPK:e.x3dhSPK,x3dhIK:e.x3dhIK}}const ut="objectchat-widget-styles",Pn=["👍","❤️","😂","😮","😢","🙏"],Bn=400,Ln='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',Mn=`
2
- .ocw { --ocw-accent:#4F63F5; --ocw-bg:#f3efe9; --ocw-card:#fff; --ocw-line:#ececec; --ocw-ink:#1c1b1a; --ocw-mut:#9b9690;
1
+ var RelayEmbed=function(Q){"use strict";var ci=Object.defineProperty;var li=(Q,X,le)=>X in Q?ci(Q,X,{enumerable:!0,configurable:!0,writable:!0,value:le}):Q[X]=le;var a=(Q,X,le)=>li(Q,typeof X!="symbol"?X+"":X,le);const X="oc_uid";function le(t){try{const e=document.cookie.match(new RegExp(`(?:^|; )${t}=([^;]*)`));return e?decodeURIComponent(e[1]):null}catch{return null}}function Pt(t,e){try{const o=location.protocol==="https:"?"; Secure":"";document.cookie=`${t}=${encodeURIComponent(e)}; Max-Age=31536000; Path=/; SameSite=Lax${o}`}catch{}}function Bt(){return`g_${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function tt(){let t=null;try{t=localStorage.getItem(X)}catch{}t||(t=le(X));const e=t??Bt();try{localStorage.setItem(X,e)}catch{}return Pt(X,e),e}function At(t){const e=t.length;let n=0,o=0;for(;o<e;){let i=t.charCodeAt(o++);if(i&4294967168)if(!(i&4294965248))n+=2;else{if(i>=55296&&i<=56319&&o<e){const s=t.charCodeAt(o);(s&64512)===56320&&(++o,i=((i&1023)<<10)+(s&1023)+65536)}i&4294901760?n+=4:n+=3}else{n++;continue}}return n}function Lt(t,e,n){const o=t.length;let i=n,s=0;for(;s<o;){let r=t.charCodeAt(s++);if(r&4294967168)if(!(r&4294965248))e[i++]=r>>6&31|192;else{if(r>=55296&&r<=56319&&s<o){const p=t.charCodeAt(s);(p&64512)===56320&&(++s,r=((r&1023)<<10)+(p&1023)+65536)}r&4294901760?(e[i++]=r>>18&7|240,e[i++]=r>>12&63|128,e[i++]=r>>6&63|128):(e[i++]=r>>12&15|224,e[i++]=r>>6&63|128)}else{e[i++]=r;continue}e[i++]=r&63|128}}const zt=new TextEncoder,Mt=50;function Kt(t,e,n){zt.encodeInto(t,e.subarray(n))}function $t(t,e,n){t.length>Mt?Kt(t,e,n):Lt(t,e,n)}const Rt=4096;function nt(t,e,n){let o=e;const i=o+n,s=[];let r="";for(;o<i;){const p=t[o++];if(!(p&128))s.push(p);else if((p&224)===192){const l=t[o++]&63;s.push((p&31)<<6|l)}else if((p&240)===224){const l=t[o++]&63,u=t[o++]&63;s.push((p&31)<<12|l<<6|u)}else if((p&248)===240){const l=t[o++]&63,u=t[o++]&63,f=t[o++]&63;let d=(p&7)<<18|l<<12|u<<6|f;d>65535&&(d-=65536,s.push(d>>>10&1023|55296),d=56320|d&1023),s.push(d)}else s.push(p);s.length>=Rt&&(r+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(r+=String.fromCharCode(...s)),r}const Dt=new TextDecoder,_t=200;function jt(t,e,n){const o=t.subarray(e,e+n);return Dt.decode(o)}function qt(t,e,n){return n>_t?jt(t,e,n):nt(t,e,n)}class Ee{constructor(e,n){a(this,"type");a(this,"data");this.type=e,this.data=n}}class W extends Error{constructor(e){super(e);const n=Object.create(W.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:W.name})}}const fe=4294967295;function Nt(t,e,n){const o=n/4294967296,i=n;t.setUint32(e,o),t.setUint32(e+4,i)}function it(t,e,n){const o=Math.floor(n/4294967296),i=n;t.setUint32(e,o),t.setUint32(e+4,i)}function ot(t,e){const n=t.getInt32(e),o=t.getUint32(e+4);return n*4294967296+o}function Ht(t,e){const n=t.getUint32(e),o=t.getUint32(e+4);return n*4294967296+o}const Ot=-1,Ft=4294967296-1,Wt=17179869184-1;function Vt({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=Wt)if(e===0&&t<=Ft){const n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,t),n}else{const n=t/4294967296,o=t&4294967295,i=new Uint8Array(8),s=new DataView(i.buffer);return s.setUint32(0,e<<2|n&3),s.setUint32(4,o),i}else{const n=new Uint8Array(12),o=new DataView(n.buffer);return o.setUint32(0,e),it(o,4,t),n}}function Xt(t){const e=t.getTime(),n=Math.floor(e/1e3),o=(e-n*1e3)*1e6,i=Math.floor(o/1e9);return{sec:n+i,nsec:o-i*1e9}}function Gt(t){if(t instanceof Date){const e=Xt(t);return Vt(e)}else return null}function Yt(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{const n=e.getUint32(0),o=e.getUint32(4),i=(n&3)*4294967296+o,s=n>>>2;return{sec:i,nsec:s}}case 12:{const n=ot(e,4),o=e.getUint32(0);return{sec:n,nsec:o}}default:throw new W(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${t.length}`)}}function Jt(t){const e=Yt(t);return new Date(e.sec*1e3+e.nsec/1e6)}const Zt={type:Ot,encode:Gt,decode:Jt},ze=class ze{constructor(){a(this,"__brand");a(this,"builtInEncoders",[]);a(this,"builtInDecoders",[]);a(this,"encoders",[]);a(this,"decoders",[]);this.register(Zt)}register({type:e,encode:n,decode:o}){if(e>=0)this.encoders[e]=n,this.decoders[e]=o;else{const i=-1-e;this.builtInEncoders[i]=n,this.builtInDecoders[i]=o}}tryToEncode(e,n){for(let o=0;o<this.builtInEncoders.length;o++){const i=this.builtInEncoders[o];if(i!=null){const s=i(e,n);if(s!=null){const r=-1-o;return new Ee(r,s)}}}for(let o=0;o<this.encoders.length;o++){const i=this.encoders[o];if(i!=null){const s=i(e,n);if(s!=null){const r=o;return new Ee(r,s)}}}return e instanceof Ee?e:null}decode(e,n,o){const i=n<0?this.builtInDecoders[-1-n]:this.decoders[n];return i?i(e,n,o):new Ee(n,e)}};a(ze,"defaultCodec",new ze);let Ue=ze;function Qt(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function _e(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Qt(t)?new Uint8Array(t):Uint8Array.from(t)}const en=100,tn=2048;class je{constructor(e){a(this,"extensionCodec");a(this,"context");a(this,"useBigInt64");a(this,"maxDepth");a(this,"initialBufferSize");a(this,"sortKeys");a(this,"forceFloat32");a(this,"ignoreUndefined");a(this,"forceIntegerToFloat");a(this,"pos");a(this,"view");a(this,"bytes");a(this,"entered",!1);this.extensionCodec=(e==null?void 0:e.extensionCodec)??Ue.defaultCodec,this.context=e==null?void 0:e.context,this.useBigInt64=(e==null?void 0:e.useBigInt64)??!1,this.maxDepth=(e==null?void 0:e.maxDepth)??en,this.initialBufferSize=(e==null?void 0:e.initialBufferSize)??tn,this.sortKeys=(e==null?void 0:e.sortKeys)??!1,this.forceFloat32=(e==null?void 0:e.forceFloat32)??!1,this.ignoreUndefined=(e==null?void 0:e.ignoreUndefined)??!1,this.forceIntegerToFloat=(e==null?void 0:e.forceIntegerToFloat)??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new je({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,n){if(n>this.maxDepth)throw new Error(`Too deep objects in depth ${n}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,n)}ensureBufferSizeToWrite(e){const n=this.pos+e;this.view.byteLength<n&&this.resizeBuffer(n*2)}resizeBuffer(e){const n=new ArrayBuffer(e),o=new Uint8Array(n),i=new DataView(n);o.set(this.bytes),this.view=i,this.bytes=o}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){const o=At(e);this.ensureBufferSizeToWrite(5+o),this.writeStringHeader(o),$t(e,this.bytes,this.pos),this.pos+=o}encodeObject(e,n){const o=this.extensionCodec.tryToEncode(e,this.context);if(o!=null)this.encodeExtension(o);else if(Array.isArray(e))this.encodeArray(e,n);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,n);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){const n=e.byteLength;if(n<256)this.writeU8(196),this.writeU8(n);else if(n<65536)this.writeU8(197),this.writeU16(n);else if(n<4294967296)this.writeU8(198),this.writeU32(n);else throw new Error(`Too large binary: ${n}`);const o=_e(e);this.writeU8a(o)}encodeArray(e,n){const o=e.length;if(o<16)this.writeU8(144+o);else if(o<65536)this.writeU8(220),this.writeU16(o);else if(o<4294967296)this.writeU8(221),this.writeU32(o);else throw new Error(`Too large array: ${o}`);for(const i of e)this.doEncode(i,n+1)}countWithoutUndefined(e,n){let o=0;for(const i of n)e[i]!==void 0&&o++;return o}encodeMap(e,n){const o=Object.keys(e);this.sortKeys&&o.sort();const i=this.ignoreUndefined?this.countWithoutUndefined(e,o):o.length;if(i<16)this.writeU8(128+i);else if(i<65536)this.writeU8(222),this.writeU16(i);else if(i<4294967296)this.writeU8(223),this.writeU32(i);else throw new Error(`Too large map object: ${i}`);for(const s of o){const r=e[s];this.ignoreUndefined&&r===void 0||(this.encodeString(s),this.doEncode(r,n+1))}}encodeExtension(e){if(typeof e.data=="function"){const o=e.data(this.pos+6),i=o.length;if(i>=4294967296)throw new Error(`Too large extension object: ${i}`);this.writeU8(201),this.writeU32(i),this.writeI8(e.type),this.writeU8a(o);return}const n=e.data.length;if(n===1)this.writeU8(212);else if(n===2)this.writeU8(213);else if(n===4)this.writeU8(214);else if(n===8)this.writeU8(215);else if(n===16)this.writeU8(216);else if(n<256)this.writeU8(199),this.writeU8(n);else if(n<65536)this.writeU8(200),this.writeU16(n);else if(n<4294967296)this.writeU8(201),this.writeU32(n);else throw new Error(`Too large extension object: ${n}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const n=e.length;this.ensureBufferSizeToWrite(n),this.bytes.set(e,this.pos),this.pos+=n}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),Nt(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),it(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}function nn(t,e){return new je(e).encodeSharedRef(t)}function qe(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}const on=16,sn=16;class rn{constructor(e=on,n=sn){a(this,"hit",0);a(this,"miss",0);a(this,"caches");a(this,"maxKeyLength");a(this,"maxLengthPerKey");this.maxKeyLength=e,this.maxLengthPerKey=n,this.caches=[];for(let o=0;o<this.maxKeyLength;o++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,n,o){const i=this.caches[o-1];e:for(const s of i){const r=s.bytes;for(let p=0;p<o;p++)if(r[p]!==e[n+p])continue e;return s.str}return null}store(e,n){const o=this.caches[e.length-1],i={bytes:e,str:n};o.length>=this.maxLengthPerKey?o[Math.random()*o.length|0]=i:o.push(i)}decode(e,n,o){const i=this.find(e,n,o);if(i!=null)return this.hit++,i;this.miss++;const s=nt(e,n,o),r=Uint8Array.prototype.slice.call(e,n,n+o);return this.store(r,s),s}}const Ne="array",we="map_key",st="map_value",an=t=>{if(typeof t=="string"||typeof t=="number")return t;throw new W("The type of key must be string or number but "+typeof t)};class cn{constructor(){a(this,"stack",[]);a(this,"stackHeadPosition",-1)}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const n=this.getUninitializedStateFromPool();n.type=Ne,n.position=0,n.size=e,n.array=new Array(e)}pushMapState(e){const n=this.getUninitializedStateFromPool();n.type=we,n.readCount=0,n.size=e,n.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===Ne){const o=e;o.size=0,o.array=void 0,o.position=0,o.type=void 0}if(e.type===we||e.type===st){const o=e;o.size=0,o.map=void 0,o.readCount=0,o.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const ge=-1,He=new DataView(new ArrayBuffer(0)),ln=new Uint8Array(He.buffer);try{He.getInt8(0)}catch(t){if(!(t instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const rt=new RangeError("Insufficient data"),dn=new rn;class Oe{constructor(e){a(this,"extensionCodec");a(this,"context");a(this,"useBigInt64");a(this,"rawStrings");a(this,"maxStrLength");a(this,"maxBinLength");a(this,"maxArrayLength");a(this,"maxMapLength");a(this,"maxExtLength");a(this,"keyDecoder");a(this,"mapKeyConverter");a(this,"totalPos",0);a(this,"pos",0);a(this,"view",He);a(this,"bytes",ln);a(this,"headByte",ge);a(this,"stack",new cn);a(this,"entered",!1);this.extensionCodec=(e==null?void 0:e.extensionCodec)??Ue.defaultCodec,this.context=e==null?void 0:e.context,this.useBigInt64=(e==null?void 0:e.useBigInt64)??!1,this.rawStrings=(e==null?void 0:e.rawStrings)??!1,this.maxStrLength=(e==null?void 0:e.maxStrLength)??fe,this.maxBinLength=(e==null?void 0:e.maxBinLength)??fe,this.maxArrayLength=(e==null?void 0:e.maxArrayLength)??fe,this.maxMapLength=(e==null?void 0:e.maxMapLength)??fe,this.maxExtLength=(e==null?void 0:e.maxExtLength)??fe,this.keyDecoder=(e==null?void 0:e.keyDecoder)!==void 0?e.keyDecoder:dn,this.mapKeyConverter=(e==null?void 0:e.mapKeyConverter)??an}clone(){return new Oe({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=ge,this.stack.reset()}setBuffer(e){const n=_e(e);this.bytes=n,this.view=new DataView(n.buffer,n.byteOffset,n.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===ge&&!this.hasRemaining(1))this.setBuffer(e);else{const n=this.bytes.subarray(this.pos),o=_e(e),i=new Uint8Array(n.length+o.length);i.set(n),i.set(o,n.length),this.setBuffer(i)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:n,pos:o}=this;return new RangeError(`Extra ${n.byteLength-o} of ${n.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const n=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return n}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let n=!1,o;for await(const p of e){if(n)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(p);try{o=this.doDecodeSync(),n=!0}catch(l){if(!(l instanceof RangeError))throw l}this.totalPos+=this.pos}if(n){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return o}const{headByte:i,pos:s,totalPos:r}=this;throw new RangeError(`Insufficient data in parsing ${qe(i)} at ${r} (${s} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,n){if(this.entered){yield*this.clone().decodeMultiAsync(e,n);return}try{this.entered=!0;let o=n,i=-1;for await(const s of e){if(n&&i===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(s),o&&(i=this.readArraySize(),o=!1,this.complete());try{for(;yield this.doDecodeSync(),--i!==0;);}catch(r){if(!(r instanceof RangeError))throw r}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let n;if(e>=224)n=e-256;else if(e<192)if(e<128)n=e;else if(e<144){const i=e-128;if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e<160){const i=e-144;if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else{const i=e-160;n=this.decodeString(i,0)}else if(e===192)n=null;else if(e===194)n=!1;else if(e===195)n=!0;else if(e===202)n=this.readF32();else if(e===203)n=this.readF64();else if(e===204)n=this.readU8();else if(e===205)n=this.readU16();else if(e===206)n=this.readU32();else if(e===207)this.useBigInt64?n=this.readU64AsBigInt():n=this.readU64();else if(e===208)n=this.readI8();else if(e===209)n=this.readI16();else if(e===210)n=this.readI32();else if(e===211)this.useBigInt64?n=this.readI64AsBigInt():n=this.readI64();else if(e===217){const i=this.lookU8();n=this.decodeString(i,1)}else if(e===218){const i=this.lookU16();n=this.decodeString(i,2)}else if(e===219){const i=this.lookU32();n=this.decodeString(i,4)}else if(e===220){const i=this.readU16();if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else if(e===221){const i=this.readU32();if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else if(e===222){const i=this.readU16();if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e===223){const i=this.readU32();if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e===196){const i=this.lookU8();n=this.decodeBinary(i,1)}else if(e===197){const i=this.lookU16();n=this.decodeBinary(i,2)}else if(e===198){const i=this.lookU32();n=this.decodeBinary(i,4)}else if(e===212)n=this.decodeExtension(1,0);else if(e===213)n=this.decodeExtension(2,0);else if(e===214)n=this.decodeExtension(4,0);else if(e===215)n=this.decodeExtension(8,0);else if(e===216)n=this.decodeExtension(16,0);else if(e===199){const i=this.lookU8();n=this.decodeExtension(i,1)}else if(e===200){const i=this.lookU16();n=this.decodeExtension(i,2)}else if(e===201){const i=this.lookU32();n=this.decodeExtension(i,4)}else throw new W(`Unrecognized type byte: ${qe(e)}`);this.complete();const o=this.stack;for(;o.length>0;){const i=o.top();if(i.type===Ne)if(i.array[i.position]=n,i.position++,i.position===i.size)n=i.array,o.release(i);else continue e;else if(i.type===we){if(n==="__proto__")throw new W("The key __proto__ is not allowed");i.key=this.mapKeyConverter(n),i.type=st;continue e}else if(i.map[i.key]=n,i.readCount++,i.readCount===i.size)n=i.map,o.release(i);else{i.key=null,i.type=we;continue e}}return n}}readHeadByte(){return this.headByte===ge&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=ge}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new W(`Unrecognized array type byte: ${qe(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new W(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new W(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,n){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,n):this.decodeBinary(e,n)}decodeUtf8String(e,n){var s;if(e>this.maxStrLength)throw new W(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+n+e)throw rt;const o=this.pos+n;let i;return this.stateIsMapKey()&&((s=this.keyDecoder)!=null&&s.canBeCached(e))?i=this.keyDecoder.decode(this.bytes,o,e):i=qt(this.bytes,o,e),this.pos+=n+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===we:!1}decodeBinary(e,n){if(e>this.maxBinLength)throw new W(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+n))throw rt;const o=this.pos+n,i=this.bytes.subarray(o,o+e);return this.pos+=n+e,i}decodeExtension(e,n){if(e>this.maxExtLength)throw new W(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const o=this.view.getInt8(this.pos+n),i=this.decodeBinary(e,n+1);return this.extensionCodec.decode(i,o,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=Ht(this.view,this.pos);return this.pos+=8,e}readI64(){const e=ot(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}}function hn(t,e){return new Oe(e).decode(t)}const pn=new Set(["auth","open","send","sync","history","read","typing","react","edit","delete","invoke","pubkey","ping","uploadPrekeys","fetchPrekey","assign","tag","note","agent_status","subscribe_inbox","unsubscribe_inbox"]);function un(t){return pn.has(t.type)}function Fe(t){return nn(t)}function at(t){let e;try{e=hn(t)}catch{return null}return typeof e!="object"||e===null||typeof e.type!="string"?null:e}class fn{constructor(e){a(this,"conversationId");a(this,"state","");a(this,"version",0);a(this,"hasMoreHistory",!1);a(this,"lastReadByOthers",0);a(this,"assignedAgentId");a(this,"accent");a(this,"subject");a(this,"name");a(this,"e2e",!1);a(this,"offline",!1);a(this,"offlineMessage","");a(this,"launcherMessage",null);a(this,"preChat",null);a(this,"whiteLabel",!1);a(this,"typing",new Set);a(this,"online",new Set);a(this,"sentiment");a(this,"sentimentScore");a(this,"actions",[]);a(this,"byId",new Map);a(this,"keyByClient",new Map);a(this,"_maxSeq",0);a(this,"_sorted",null);this.me=e}messages(){return this._sorted||(this._sorted=[...this.byId.values()].sort((e,n)=>{const o=e.status==="pending",i=n.status==="pending";return o!==i?o?1:-1:o&&i?e.ts-n.ts:e.seq-n.seq})),this._sorted}visibleActions(){return this.actions.filter(e=>!e.availableInStates||e.availableInStates.includes(this.state))}highestSeq(){return this._maxSeq}addOptimistic(e,n){const o={id:e,conversationId:this.conversationId,seq:0,senderId:this.me,senderRole:"guest",content:n,ts:Date.now(),clientMsgId:e,status:"pending"};return this.byId.set(e,o),this.keyByClient.set(e,e),this._sorted=null,o}apply(e){var n;switch(e.type){case"opened":this.conversationId=e.conversation.id,this.state=e.conversation.state,e.subject&&(this.subject=e.subject);return;case"manifest":this.actions=e.actions,this.version=e.version,e.name&&(this.name=e.name),(n=e.theme)!=null&&n.accent&&(this.accent=e.theme.accent),e.e2e&&(this.e2e=!0),this.offline=e.offline===!0,this.offlineMessage=e.offlineMessage??"",e.launcherMessage&&(this.launcherMessage=e.launcherMessage),e.whiteLabel&&(this.whiteLabel=!0),e.preChat&&(this.preChat=e.preChat);return;case"message":this.upsert({...e.message});return;case"ack":{const o=this.keyByClient.get(e.clientMsgId),i=o?this.byId.get(o):void 0;if(i&&o){this.byId.delete(o);const s={...i,id:e.messageId,seq:e.seq,ts:e.ts,status:"sent"};this.byId.set(e.messageId,s),this.keyByClient.set(e.clientMsgId,e.messageId),e.seq>this._maxSeq&&(this._maxSeq=e.seq)}this._sorted=null;return}case"delivered":this.markOwnStatus(e.seq,"delivered");return;case"read":e.by!==this.me&&(this.lastReadByOthers=Math.max(this.lastReadByOthers,e.seq),this.markOwnStatus(e.seq,"read"));return;case"sync":for(const o of e.messages)this.upsert({...o});return;case"history":for(const o of e.messages)this.upsert({...o});this.hasMoreHistory=e.hasMore;return;case"typing":e.userId!==this.me&&(e.isTyping?this.typing.add(e.userId):this.typing.delete(e.userId));return;case"reaction":{const o=this.byId.get(e.messageId);if(!o)return;const i={...o.reactions??{}},s=(i[e.emoji]??[]).filter(r=>r!==e.by);e.removed||s.push(e.by),s.length?i[e.emoji]=s:delete i[e.emoji],this.byId.set(e.messageId,{...o,reactions:i}),this._sorted=null;return}case"edited":{const o=this.byId.get(e.messageId);o&&(this.byId.set(e.messageId,{...o,content:e.content,editedAt:e.editedAt}),this._sorted=null);return}case"deleted":{const o=this.byId.get(e.messageId);o&&(this.byId.set(e.messageId,{...o,deletedAt:e.ts}),this._sorted=null);return}case"state":this.state=e.state;return;case"assigned":this.assignedAgentId=e.agentId??void 0;return;case"presence":e.status==="online"?this.online.add(e.userId):this.online.delete(e.userId);return;case"subjectState":case"invoked":case"authed":case"error":case"pong":return;case"sentiment":this.sentiment=e.label,this.sentimentScore=e.score;return;default:return}}upsert(e){const n=this.byId.get(e.id);this.byId.set(e.id,n?{...n,...e}:e),e.seq>this._maxSeq&&(this._maxSeq=e.seq),this._sorted=null}markOwnStatus(e,n){const o=ct(n);let i=!1;for(const[s,r]of this.byId)r.senderId!==this.me||r.seq<=0||r.seq>e||ct(r.status)>=o||(this.byId.set(s,{...r,status:n}),i=!0);i&&(this._sorted=null)}}function ct(t){switch(t){case"read":return 3;case"delivered":return 2;case"sent":return 1;default:return 0}}class wn{constructor(e){a(this,"socket",null);a(this,"state","idle");a(this,"authed",!1);a(this,"everAuthed",!1);a(this,"attempt",0);a(this,"outbox",[]);a(this,"stopped",!1);a(this,"timer",null);a(this,"refreshing",!1);this.opts=e}connect(){var o,i;if(this.state==="connecting"||this.state==="open")return;this.stopped=!1,this.state="connecting",this.authed=!1,(i=(o=this.opts).onStatusChange)==null||i.call(o,this.attempt>0?"reconnecting":"connecting");const n=(this.opts.socketFactory??xn)(this.opts.url);n.binaryType="arraybuffer",this.socket=n,n.onopen=()=>{this.raw({type:"auth",token:this.opts.token})},n.onmessage=s=>{const r=at(new Uint8Array(s.data));!r||un(r)||this.handle(r)},n.onclose=()=>this.onClosed(),n.onerror=()=>{try{n.close()}catch{}}}send(e){if(this.state==="open"&&this.authed){this.raw(e);return}this.queue(e)}pendingCount(){return this.outbox.length}close(){var e;this.stopped=!0,this.timer&&clearTimeout(this.timer),this.state="closed";try{(e=this.socket)==null||e.close()}catch{}}handle(e){var n,o,i,s;if(e.type==="authed"&&(this.attempt=0,this.state="open",this.authed=!0,this.everAuthed=!0,(o=(n=this.opts).onStatusChange)==null||o.call(n,"open"),this.raw(this.opts.open),this.opts.open.type!=="open"&&this.flush()),e.type==="opened"&&(this.raw({type:"sync",conversationId:e.conversation.id,sinceSeq:this.opts.getCursor()}),this.flush(e.conversation.id)),e.type==="error"&&gn.has(e.code)){if(e.code==="UNAUTHORIZED"&&this.opts.refreshToken&&!this.refreshing){this.refreshing=!0,(s=(i=this.opts).onStatusChange)==null||s.call(i,"reconnecting","Renewing session…"),this.opts.refreshToken().then(r=>{var p;if(this.refreshing=!1,!r){this.fatal(e);return}this.opts.token=r;try{(p=this.socket)==null||p.close()}catch{}}).catch(()=>{this.refreshing=!1,this.fatal(e)});return}this.fatal(e);return}this.opts.onFrame(e)}fatal(e){var n,o,i;this.stopped=!0;try{(n=this.socket)==null||n.close()}catch{}this.state="closed",(i=(o=this.opts).onStatusChange)==null||i.call(o,"error",yn(e.code)),this.opts.onFrame(e)}flush(e){const n=this.outbox;this.outbox=[];for(const o of n)this.raw(e&&o.type==="send"&&o.conversationId!==e?{...o,conversationId:e}:o)}queue(e){const n=this.opts.maxOutbox??1e3;this.outbox.length>=n&&(this.outbox=this.outbox.slice(this.outbox.length-(n>>1))),this.outbox.push(e)}raw(e){if(!this.socket){this.queue(e);return}try{this.socket.send(Fe(e))}catch{this.queue(e)}}onClosed(){var i,s;if(this.authed=!1,this.socket=null,this.stopped){this.state="closed";return}this.state="idle";const e=this.opts.backoffBaseMs??500,n=this.opts.backoffMaxMs??15e3,o=Math.min(n,e*2**this.attempt)*(.5+Math.random()*.5);this.attempt++,this.attempt>=3&&!this.everAuthed&&((s=(i=this.opts).onStatusChange)==null||s.call(i,"reconnecting","Can't reach chat — retrying…")),this.timer=setTimeout(()=>this.connect(),o)}}const gn=new Set(["UNAUTHORIZED"]);function yn(t){switch(t){case"UNAUTHORIZED":return"Chat unavailable — sign-in/token was rejected";default:return"Chat unavailable"}}function xn(t){return new WebSocket(t)}const lt=200,mn=7*864e5;class bn{constructor(e){a(this,"key");this.key=`ocw_outbox_${e}`}load(){try{const e=localStorage.getItem(this.key);if(!e)return[];const n=JSON.parse(e),o=Date.now()-mn,i=n.filter(s=>s.ts>=o);return i.length!==n.length&&this.save(i),i}catch{return[]}}add(e){try{const n=this.load();n.push(e),this.save(n.length>lt?n.slice(n.length-lt):n)}catch{}}remove(e){try{const n=this.load().filter(o=>o.clientMsgId!==e);this.save(n)}catch{}}save(e){try{localStorage.setItem(this.key,JSON.stringify(e))}catch{}}}const A=()=>globalThis.crypto.subtle;function Pe(t){const e=t instanceof Uint8Array?t:new Uint8Array(t);let n="";for(const o of e)n+=String.fromCharCode(o);return btoa(n)}function We(t){const e=atob(t),n=new ArrayBuffer(e.length),o=new Uint8Array(n);for(let i=0;i<e.length;i++)o[i]=e.charCodeAt(i);return o}async function ye(){const t=await A().generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey","deriveBits"]);return{publicKey:t.publicKey,privateKey:t.privateKey}}async function ie(t){return Pe(await A().exportKey("raw",t))}async function de(t){return A().importKey("raw",We(t),{name:"ECDH",namedCurve:"P-256"},!1,[])}async function vn(t,e){const n=await de(e);return A().deriveKey({name:"ECDH",public:n},t,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function kn(t,e){const n=globalThis.crypto.getRandomValues(new Uint8Array(12)),o=new TextEncoder().encode(e),i=await A().encrypt({name:"AES-GCM",iv:n},t,o);return{ct:Pe(i),iv:Pe(n)}}async function Sn(t,e,n){const o=await A().decrypt({name:"AES-GCM",iv:We(n)},t,We(e));return new TextDecoder().decode(o)}async function In(t){var n,o;try{const i=(n=globalThis.localStorage)==null?void 0:n.getItem(t);if(i){const{pub:s,priv:r}=JSON.parse(i),p=await A().importKey("jwk",s,{name:"ECDH",namedCurve:"P-256"},!0,[]),l=await A().importKey("jwk",r,{name:"ECDH",namedCurve:"P-256"},!0,["deriveKey","deriveBits"]);return{publicKey:p,privateKey:l}}}catch{}const e=await ye();try{const i=await A().exportKey("jwk",e.publicKey),s=await A().exportKey("jwk",e.privateKey);(o=globalThis.localStorage)==null||o.setItem(t,JSON.stringify({pub:i,priv:s}))}catch{}return e}async function Cn(t,e){const n=await A().exportKey("raw",e),o=await A().sign({name:"ECDSA",hash:"SHA-256"},t,n);return Pe(o)}async function Tn(){const t=await ye(),e=await A().generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]);return{ecdhKP:t,ecdsaKP:{publicKey:e.publicKey,privateKey:e.privateKey},publicKeyB64:await ie(t.publicKey),sigPublicKeyB64:await ie(e.publicKey)}}async function dt(t){var n,o;try{const i=(n=globalThis.localStorage)==null?void 0:n.getItem(`${t}-identity`);if(i){const s=JSON.parse(i),r=await A().importKey("jwk",s.ecdhPub,{name:"ECDH",namedCurve:"P-256"},!0,[]),p=await A().importKey("jwk",s.ecdhPriv,{name:"ECDH",namedCurve:"P-256"},!0,["deriveKey","deriveBits"]),l=await A().importKey("jwk",s.ecdsaPub,{name:"ECDSA",namedCurve:"P-256"},!0,["verify"]),u=await A().importKey("jwk",s.ecdsaPriv,{name:"ECDSA",namedCurve:"P-256"},!0,["sign"]);return{ecdhKP:{publicKey:r,privateKey:p},ecdsaKP:{publicKey:l,privateKey:u},publicKeyB64:await ie(r),sigPublicKeyB64:await ie(l)}}}catch{}const e=await Tn();try{const i=await A().exportKey("jwk",e.ecdhKP.publicKey),s=await A().exportKey("jwk",e.ecdhKP.privateKey),r=await A().exportKey("jwk",e.ecdsaKP.publicKey),p=await A().exportKey("jwk",e.ecdsaKP.privateKey);(o=globalThis.localStorage)==null||o.setItem(`${t}-identity`,JSON.stringify({ecdhPub:i,ecdhPriv:s,ecdsaPub:r,ecdsaPriv:p}))}catch{}return e}async function En(t,e){const n=await ye(),o=await ie(n.publicKey),i=await de(e.identityKey),s=await de(e.signedPrekey),r=e.oneTimePrekey?await de(e.oneTimePrekey):null,p=await oe(t.privateKey,s),l=await oe(n.privateKey,i),u=await oe(n.privateKey,s),f=r?await oe(n.privateKey,r):null,d=ht(p,l,u,...f?[f]:[]);return{sharedKey:await pt(d),ephemeralPublicKey:o}}async function Un(t,e,n,o,i){const s=await de(n),r=await de(o),p=await oe(e.privateKey,s),l=await oe(t.privateKey,r),u=await oe(e.privateKey,r),f=i?await oe(i.privateKey,r):null,d=ht(p,l,u,...f?[f]:[]);return pt(d)}async function oe(t,e){return A().deriveBits({name:"ECDH",public:e},t,256)}function ht(...t){const e=t.reduce((i,s)=>i+s.byteLength,0),n=new Uint8Array(e);let o=0;for(const i of t)n.set(new Uint8Array(i),o),o+=i.byteLength;return n.buffer}async function pt(t){const e=await A().importKey("raw",t,"HKDF",!1,["deriveKey"]);return A().deriveKey({name:"HKDF",hash:"SHA-256",salt:new Uint8Array(32),info:new TextEncoder().encode("ObjectChat X3DH v1")},e,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}const Pn=20;class Bn{constructor(e){a(this,"kp");a(this,"shared");a(this,"identityKP");a(this,"signedPreKP");a(this,"signedPrekeyId");a(this,"otpKeys",[]);a(this,"x3dhShared");a(this,"pendingX3DH");this.storageKey=e}get ready(){return!!(this.shared??this.x3dhShared)}async begin(){return this.kp=await In(this.storageKey),ie(this.kp.publicKey)}async onPeerKey(e){this.kp&&(this.shared=await vn(this.kp.privateKey,e))}async initX3DH(){this.identityKP=await dt(this.storageKey),this.signedPreKP=await ye(),this.signedPrekeyId=`spk-${Date.now()}-${Math.random().toString(36).slice(2)}`;for(let i=0;i<Pn;i++)this.otpKeys.push(await ye());const e=await ie(this.signedPreKP.publicKey),n=await Cn(this.identityKP.ecdsaKP.privateKey,this.signedPreKP.publicKey),o=await Promise.all(this.otpKeys.map(i=>ie(i.publicKey)));return{identityKey:this.identityKP.publicKeyB64,signedPrekey:e,signedPrekeyId:this.signedPrekeyId,signature:n,oneTimePrekeys:o}}async x3dhSendTo(e){this.identityKP||(this.identityKP=await dt(this.storageKey));const{sharedKey:n,ephemeralPublicKey:o}=await En(this.identityKP.ecdhKP,e);return this.x3dhShared=n,{ephemeralKey:o,spkId:e.signedPrekeyId,usedOTP:!!e.oneTimePrekey,senderIK:this.identityKP.publicKeyB64}}async x3dhReceiveFrom(e,n,o,i){if(!this.identityKP||!this.signedPreKP){this.pendingX3DH={senderIK:e,ephemeralKey:n,spkId:o,usedOTP:i};return}const s=i?this.otpKeys.shift():void 0;this.x3dhShared=await Un(this.identityKP.ecdhKP,this.signedPreKP,e,n,s)}async flushPendingX3DH(){if(!this.pendingX3DH)return;const{senderIK:e,ephemeralKey:n,spkId:o,usedOTP:i}=this.pendingX3DH;this.pendingX3DH=void 0,await this.x3dhReceiveFrom(e,n,o,i)}async sealText(e,n){const o=this.x3dhShared??this.shared;if(!o)throw new Error("secure channel not ready");const{ct:i,iv:s}=await kn(o,e);return{kind:"text",text:i,enc:!0,iv:s,...n?{x3dhEK:n.ephemeralKey,x3dhSPK:n.spkId,x3dhIK:n.senderIK,x3dhOTP:n.usedOTP}:{}}}async openContent(e){if(e.kind!=="text"||!e.enc||!e.iv)return e;const n=this.x3dhShared??this.shared;if(!n)return{kind:"text",text:"🔒 encrypted"};try{return{kind:"text",text:await Sn(n,e.text,e.iv)}}catch{return{kind:"text",text:"🔒 unable to decrypt"}}}async openFrame(e){if(e.type==="message")e.message.content=await this.openContent(e.message.content);else if(e.type==="sync")for(const n of e.messages)n.content=await this.openContent(n.content)}}function An(t){if(t.kind!=="text"||!t.enc)return null;const e=t;return!e.x3dhEK||!e.x3dhSPK||!e.x3dhIK?null:{x3dhEK:e.x3dhEK,x3dhSPK:e.x3dhSPK,x3dhIK:e.x3dhIK,x3dhOTP:e.x3dhOTP??!1}}const Ln={accent:"#6c5ce7",accent2:"#4c6fff",bg:"#f4f3fb",card:"#fff",tint:"#eeecfb",line:"#e6e2f5",ink:"#221d3a",mut:"#8f8aa8",onaccent:"#fff",rowhover:"#e7e3f8",shadow:"0 12px 32px rgba(108,92,231,.14)"},zn={accent:"#a99cf2",accent2:"#6f8cff",bg:"#221d3a",card:"#2b2550",tint:"#2f2853",line:"#3a3363",ink:"#eceafc",mut:"#9b93c9",onaccent:"#221d3a",rowhover:"#39325e",shadow:"0 12px 32px rgba(0,0,0,.4)"},Mn="'Nunito',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif";function ut(t,e){return Object.entries(e).map(([n,o])=>`--${t}-${n}:${o};`).join(" ")}function ft(t){return`${ut(t,Ln)} --${t}-fb:${Mn}; --${t}-fh:'Baloo 2',var(--${t}-fb);`}function Be(t){return ut(t,zn)}const Kn=`
2
+ .ocw { ${ft("ocw")}
3
3
  position:relative;
4
4
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
5
- font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif; color:var(--ocw-ink); overflow:hidden; }
5
+ font-family:var(--ocw-fb); color:var(--ocw-ink); overflow:hidden; }
6
+ @media (prefers-color-scheme: dark) { .ocw:not([data-theme="light"]) { ${Be("ocw")} } }
7
+ .ocw[data-theme="dark"] { ${Be("ocw")} }
6
8
  /* ── Responsive sizing ──────────────────────────────────────────────────────
7
9
  * Sizing is driven by the WIDGET'S OWN width (ResizeObserver toggles
8
10
  * .ocw-compact below 400px), not the viewport — so a widget embedded in a
@@ -24,38 +26,45 @@ var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X
24
26
  /* RTL support: when the host element has dir=rtl, flip layout direction */
25
27
  [dir="rtl"] .ocw-row.mine { flex-direction:row; }
26
28
  [dir="rtl"] .ocw-row.theirs { flex-direction:row-reverse; }
27
- [dir="rtl"] .mine .ocw-bubble { border-bottom-right-radius:18px; border-bottom-left-radius:6px; }
28
- [dir="rtl"] .theirs .ocw-bubble { border-bottom-left-radius:18px; border-bottom-right-radius:6px; }
29
+ [dir="rtl"] .mine .ocw-bubble { border-bottom-right-radius:18px; border-bottom-left-radius:4px; }
30
+ [dir="rtl"] .theirs .ocw-bubble { border-bottom-left-radius:18px; border-bottom-right-radius:4px; }
29
31
  [dir="rtl"] .ocw-input { flex-direction:row-reverse; }
30
32
  [dir="rtl"] .mine .ocw-meta { text-align:left; }
31
33
  .ocw-head { display:flex; align-items:center; gap:10px; padding:12px 14px; background:var(--ocw-card); border-bottom:1px solid var(--ocw-line); }
32
34
  .ocw-back { flex:none; width:30px; height:30px; margin:-2px -2px -2px -4px; border:none; background:none; color:var(--ocw-ink); font-size:26px; line-height:1; cursor:pointer; border-radius:50%; display:flex; align-items:center; justify-content:center; }
33
35
  .ocw-back:hover { background:var(--ocw-bg); }
34
- .ocw-avatar { width:34px; height:34px; border-radius:50%; background:#ffe9d6; display:flex; align-items:center; justify-content:center; font-size:17px; flex:none; }
36
+ .ocw-avatar { width:34px; height:34px; border-radius:50%; background:var(--ocw-tint); color:var(--ocw-accent); font-family:var(--ocw-fh); font-weight:600; display:flex; align-items:center; justify-content:center; font-size:13px; flex:none; }
35
37
  .ocw-head-main { flex:1; min-width:0; }
36
- .ocw-head-name { font-weight:700; font-size:15px; }
38
+ .ocw-head-name { font-family:var(--ocw-fh); font-weight:600; font-size:15px; }
37
39
  .ocw-head-meta { color:var(--ocw-mut); font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
38
- .ocw-badge { font-size:12px; font-weight:600; color:#15803d; background:#e8f6ec; border-radius:999px; padding:3px 10px; }
39
- .ocw-e2e { font-size:11px; font-weight:700; color:#3730a3; background:#eef2ff; border-radius:999px; padding:3px 9px; align-items:center; }
40
- .ocw-menu { color:var(--ocw-mut); width:30px; height:30px; border-radius:50%; border:1px solid var(--ocw-line); background:#fff; cursor:pointer; }
40
+ .ocw-head-status { font-size:10.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
41
+ .ocw-head-status.online { color:#5cb37a; }
42
+ .ocw-head-status.away { color:#c98b2e; }
43
+ .ocw-msg-sender { font-size:10px; color:var(--ocw-mut); margin-bottom:2px; }
44
+ .ocw-resolved-note { text-align:center; font-size:10.5px; color:var(--ocw-mut); margin:6px 0 12px; }
45
+ .ocw-reopen { display:none; width:calc(100% - 32px); margin:0 16px 14px; height:40px; border:1.5px solid var(--ocw-accent); color:var(--ocw-accent); background:none; border-radius:20px; font:inherit; font-size:13.5px; font-weight:600; cursor:pointer; }
46
+ .ocw-reopen:hover { background:var(--ocw-tint); }
47
+ .ocw-badge { font-size:11px; font-weight:600; color:#2f8a52; background:#eafaf0; border-radius:20px; padding:5px 12px; }
48
+ .ocw-e2e { font-size:11px; font-weight:700; color:var(--ocw-accent); background:var(--ocw-tint); border-radius:20px; padding:5px 12px; align-items:center; }
49
+ .ocw-menu { color:var(--ocw-mut); width:30px; height:30px; border-radius:50%; border:1px solid var(--ocw-line); background:var(--ocw-card); cursor:pointer; }
41
50
  .ocw-chiprow { display:flex; gap:8px; padding:10px 12px; background:var(--ocw-card); border-bottom:1px solid var(--ocw-line); overflow-x:auto; }
42
- .ocw-chip { flex:none; display:flex; align-items:center; gap:6px; border:1px solid #e3ded7; background:#fff; border-radius:999px; padding:7px 13px; font-size:13px; font-weight:600; cursor:pointer; white-space:nowrap; }
51
+ .ocw-chip { flex:none; display:flex; align-items:center; gap:6px; border:none; background:var(--ocw-tint); color:var(--ocw-accent); border-radius:999px; padding:7px 13px; font-size:12px; font-weight:600; cursor:pointer; white-space:nowrap; }
43
52
  .ocw-chip:hover { border-color:var(--ocw-accent); color:var(--ocw-accent); }
44
53
  .ocw-scroll { flex:1; min-height:0; overflow-y:auto; padding:16px 14px; display:flex; flex-direction:column; gap:10px; }
45
- .ocw-subject { background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:16px; padding:14px 16px; }
46
- .ocw-subject-title { font-weight:700; font-size:16px; margin-bottom:2px; }
47
- .ocw-subject-sub { color:var(--ocw-mut); font-size:13px; margin-bottom:10px; }
54
+ .ocw-subject { background:var(--ocw-tint); border:none; border-radius:16px; padding:10px 12px; }
55
+ .ocw-subject-title { font-family:var(--ocw-fh); font-weight:600; font-size:13px; margin-bottom:2px; }
56
+ .ocw-subject-sub { color:var(--ocw-mut); font-size:10.5px; margin-bottom:6px; }
48
57
  .ocw-tags { display:flex; flex-wrap:wrap; gap:6px; }
49
58
  .ocw-tag { font-size:12px; color:#5b554e; background:#efeae3; border-radius:8px; padding:4px 10px; }
50
59
  .ocw-row { display:flex; align-items:flex-end; gap:8px; max-width:86%; }
51
60
  .ocw-row.mine { align-self:flex-end; flex-direction:row-reverse; }
52
61
  .ocw-row.theirs { align-self:flex-start; }
53
- .ocw-dot { width:26px; height:26px; border-radius:50%; background:var(--ocw-accent); color:#fff; font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; flex:none; }
54
- .ocw-bubble { padding:10px 14px; border-radius:18px; font-size:14.5px; line-height:1.4; word-wrap:break-word; }
55
- .theirs .ocw-bubble { background:#fff; border:1px solid var(--ocw-line); border-bottom-left-radius:6px; }
56
- .mine .ocw-bubble { background:var(--ocw-accent); color:#fff; border-bottom-right-radius:6px; }
62
+ .ocw-dot { width:26px; height:26px; border-radius:50%; background:var(--ocw-tint); color:var(--ocw-accent); font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; flex:none; }
63
+ .ocw-bubble { padding:10px 14px; border-radius:18px; font-size:13.5px; line-height:1.45; word-wrap:break-word; max-width:80%; }
64
+ .theirs .ocw-bubble { background:var(--ocw-tint); border-bottom-left-radius:4px; }
65
+ .mine .ocw-bubble { background:var(--ocw-accent2); color:#fff; border-bottom-right-radius:4px; }
57
66
  .ocw-sys { align-self:center; color:var(--ocw-mut); font-size:12.5px; font-style:italic; text-align:center; max-width:90%; }
58
- .ocw-bot .ocw-bubble { background:#f0fdf4; border-color:#cdebd6; }
67
+ .ocw-bot .ocw-bubble { background:var(--ocw-tint); }
59
68
  .ocw-note .ocw-bubble { background:#fffbeb; border:1.5px dashed #f59e0b; color:#78350f; border-radius:12px !important; }
60
69
  .ocw-note .ocw-bubble::before { content:'🔒 Note — '; font-size:11px; font-weight:700; color:#b45309; display:block; margin-bottom:3px; letter-spacing:.3px; }
61
70
  .ocw-time { font-size:10.5px; color:var(--ocw-mut); margin-top:3px; }
@@ -66,20 +75,20 @@ var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X
66
75
  .ocw-deleted { font-style:italic; color:var(--ocw-mut); }
67
76
  .ocw-edited { font-size:10px; color:var(--ocw-mut); margin-left:4px; }
68
77
  .ocw-react { font-size:12px; margin-top:3px; display:flex; flex-wrap:wrap; gap:3px; }
69
- .ocw-react-pill { display:inline-flex; align-items:center; gap:3px; border:1px solid #e3ded7; border-radius:999px; padding:2px 7px; background:#fff; font-size:12px; cursor:pointer; }
78
+ .ocw-react-pill { display:inline-flex; align-items:center; gap:3px; border:1px solid var(--ocw-line); border-radius:999px; padding:2px 7px; background:var(--ocw-card); font-size:12px; cursor:pointer; }
70
79
  .ocw-react-pill:hover { border-color:var(--ocw-accent); }
71
80
  .ocw-react-pill.mine { border-color:var(--ocw-accent); background:#fff8f5; }
72
81
  .ocw-react-wrap { position:relative; }
73
82
  .ocw-react-wrap:not(:hover) .ocw-react-picker { display:none; }
74
- .ocw-react-picker { position:absolute; bottom:calc(100% + 4px); left:0; background:#fff; border:1px solid #e3ded7; border-radius:14px; padding:6px 8px; box-shadow:0 4px 16px rgba(0,0,0,.12); display:flex; gap:4px; z-index:10; white-space:nowrap; }
83
+ .ocw-react-picker { position:absolute; bottom:calc(100% + 4px); left:0; background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:14px; padding:6px 8px; box-shadow:0 4px 16px rgba(0,0,0,.12); display:flex; gap:4px; z-index:10; white-space:nowrap; }
75
84
  .ocw-react-picker button { background:none; border:none; font-size:16px; cursor:pointer; padding:2px; border-radius:6px; }
76
- .ocw-react-picker button:hover { background:#f3efe9; }
77
- .ocw-react-btn { background:none; border:1px solid #e3ded7; border-radius:999px; padding:2px 7px; font-size:12px; cursor:pointer; color:var(--ocw-mut); }
85
+ .ocw-react-picker button:hover { background:var(--ocw-bg); }
86
+ .ocw-react-btn { background:none; border:1px solid var(--ocw-line); border-radius:999px; padding:2px 7px; font-size:12px; cursor:pointer; color:var(--ocw-mut); }
78
87
  .ocw-react-btn:hover { border-color:var(--ocw-accent); color:var(--ocw-accent); }
79
88
  .ocw-msg-menu { position:absolute; top:0; right:0; display:none; gap:3px; }
80
89
  .ocw-row.mine:hover .ocw-msg-menu { display:flex; }
81
90
  .ocw-row.theirs:hover .ocw-msg-menu { display:flex; left:0; right:auto; }
82
- .ocw-msg-menu button { background:#fff; border:1px solid #e3ded7; border-radius:6px; font-size:11px; padding:2px 6px; cursor:pointer; color:var(--ocw-mut); }
91
+ .ocw-msg-menu button { background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:6px; font-size:11px; padding:2px 6px; cursor:pointer; color:var(--ocw-mut); }
83
92
  .ocw-msg-menu button:hover { border-color:var(--ocw-accent); color:var(--ocw-accent); }
84
93
  .ocw-msg-menu button.del:hover { border-color:#e74c3c; color:#e74c3c; }
85
94
  .ocw-bubble-wrap { position:relative; }
@@ -91,25 +100,32 @@ var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X
91
100
  .ocw-appt-desc { font-size:12px; color:var(--ocw-mut); margin-bottom:10px; white-space:pre-wrap; }
92
101
  .ocw-appt-links { display:flex; flex-direction:column; gap:6px; }
93
102
  .ocw-appt-btn { display:block; text-align:center; padding:8px 12px; border-radius:8px; font-size:13px; font-weight:600; text-decoration:none; background:var(--ocw-accent); color:#fff; }
94
- .ocw-appt-btn-sec { background:#fff; color:var(--ocw-accent); border:1px solid var(--ocw-accent); }
103
+ .ocw-appt-btn-sec { background:var(--ocw-card); color:var(--ocw-accent); border:1px solid var(--ocw-accent); }
95
104
  .ocw-conn-status { font-size:10px; color:var(--ocw-mut); margin-left:4px; }
96
105
  .ocw-conn-status.warn { color:#e67e22; }
97
106
  .ocw-conn-status.err { color:#c0392b; font-weight:600; }
98
- .ocw-load-more { display:block; width:100%; background:none; border:1px solid #e3ded7; border-radius:10px; padding:6px 0; font-size:12px; color:var(--ocw-mut); cursor:pointer; margin-bottom:8px; }
107
+ .ocw-load-more { display:block; width:100%; background:none; border:1px solid var(--ocw-line); border-radius:10px; padding:6px 0; font-size:12px; color:var(--ocw-mut); cursor:pointer; margin-bottom:8px; }
99
108
  .ocw-load-more:hover { border-color:var(--ocw-accent); color:var(--ocw-accent); }
100
109
  .ocw-away { margin:0 14px 8px; padding:9px 12px; background:#fff8e6; border:1px solid #f0e2bd; border-radius:10px; font-size:12px; color:#7a5c17; display:flex; gap:7px; align-items:flex-start; line-height:1.45; }
110
+ .ocw button:focus-visible, .ocw textarea:focus-visible, .ocw a:focus-visible, .ocw [tabindex]:focus-visible { outline:2px solid var(--ocw-accent); outline-offset:2px; border-radius:8px; }
111
+ .ocw-sendbtn:active { transform:scale(.92); }
112
+ .ocw-quick button:active, .ocw-chip:active { transform:scale(.97); }
113
+ @media (prefers-color-scheme: dark) { .ocw:not([data-theme="light"]) .ocw-away { background:#3a3018; border-color:#5a4a1f; color:#e8d9a8; } .ocw:not([data-theme="light"]) .ocw-note .ocw-bubble { background:#332b12; border-color:#7a5c17; color:#f0e2bd; } .ocw:not([data-theme="light"]) .ocw-note .ocw-bubble::before { color:#e0c060; } }
114
+ .ocw[data-theme="dark"] .ocw-away { background:#3a3018; border-color:#5a4a1f; color:#e8d9a8; }
115
+ .ocw[data-theme="dark"] .ocw-note .ocw-bubble { background:#332b12; border-color:#7a5c17; color:#f0e2bd; }
116
+ .ocw[data-theme="dark"] .ocw-note .ocw-bubble::before { color:#e0c060; }
101
117
  .ocw-away-icon { flex:none; }
102
118
  /* Shared form styles (used by the pre-chat panel; named for the retired offline form). */
103
119
  .ocw-offline-form { display:flex; flex-direction:column; gap:8px; text-align:left; }
104
- .ocw-offline-input { border:1px solid #e3ded7; border-radius:10px; padding:10px 12px; font-size:13px; font-family:inherit; }
105
- .ocw-offline-input:focus { outline:none; border-color:var(--ocw-accent); }
106
- .ocw-offline-submit { background:var(--ocw-accent); color:#fff; border:none; border-radius:10px; padding:11px; font-size:14px; font-weight:600; cursor:pointer; }
107
- .ocw-prechat { margin:20px 14px; padding:20px; background:#fff; border:1px solid #e3ded7; border-radius:16px; }
108
- .ocw-prechat-title { font-weight:700; font-size:15px; margin-bottom:12px; }
109
- .ocw-prechat select { border:1px solid #e3ded7; border-radius:10px; padding:10px 12px; font:inherit; font-size:13px; background:#fff; }
120
+ .ocw-offline-input { border:none; background:var(--ocw-tint); border-radius:14px; padding:10px 12px; font-size:13px; font-family:inherit; color:var(--ocw-ink); }
121
+ .ocw-offline-input:focus { outline:none; box-shadow:inset 0 0 0 1.5px var(--ocw-accent); }
122
+ .ocw-offline-submit { background:var(--ocw-accent); color:var(--ocw-onaccent); border:none; border-radius:20px; padding:11px; font-family:var(--ocw-fh); font-size:13.5px; font-weight:600; cursor:pointer; box-shadow:var(--ocw-shadow); }
123
+ .ocw-prechat { margin:16px; padding:0; background:none; border:none; }
124
+ .ocw-prechat-title { font-family:var(--ocw-fh); font-weight:600; font-size:20px; margin-bottom:10px; }
125
+ .ocw-prechat select { border:none; border-radius:14px; padding:10px 12px; font:inherit; font-size:13px; background:var(--ocw-tint); color:var(--ocw-ink); }
110
126
  .ocw-prechat-cb { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--ocw-ink); }
111
127
  .ocw-deflect { margin:0 14px 8px; display:flex; flex-direction:column; gap:6px; }
112
- .ocw-deflect-card { text-align:left; background:#fff; border:1px solid #e3ded7; border-radius:12px; padding:10px 12px; font:inherit; font-size:13px; cursor:pointer; }
128
+ .ocw-deflect-card { text-align:left; background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:12px; padding:10px 12px; font:inherit; font-size:13px; cursor:pointer; }
113
129
  .ocw-deflect-card:hover { border-color:var(--ocw-accent); }
114
130
  .ocw-deflect-q { font-weight:600; margin-bottom:2px; }
115
131
  .ocw-deflect-a { color:var(--ocw-mut); font-size:12.5px; display:none; white-space:pre-wrap; }
@@ -122,7 +138,7 @@ var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X
122
138
  .ocw-csat-done { font-size:12px; color:var(--ocw-mut); margin-top:6px; }
123
139
 
124
140
  .ocw-typing { min-height:22px; padding:0 16px 4px; display:flex; align-items:center; }
125
- .ocw-typing-bubble { display:none; align-items:center; gap:3px; background:#fff; border:1px solid var(--ocw-line); border-radius:14px; border-bottom-left-radius:4px; padding:7px 12px; }
141
+ .ocw-typing-bubble { display:none; align-items:center; gap:3px; background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:14px; border-bottom-left-radius:4px; padding:7px 12px; }
126
142
  .ocw-typing.active .ocw-typing-bubble { display:flex; }
127
143
  .ocw-typing-dot { width:6px; height:6px; border-radius:50%; background:var(--ocw-mut); animation:ocw-bounce 1.2s infinite ease-in-out; }
128
144
  .ocw-typing-dot:nth-child(2) { animation-delay:.2s; }
@@ -130,20 +146,20 @@ var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X
130
146
  @keyframes ocw-bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-5px)} }
131
147
  .ocw-quick { display:flex; gap:8px; padding:8px 12px 6px; overflow-x:auto; scrollbar-width:none; flex-shrink:0; }
132
148
  .ocw-quick::-webkit-scrollbar { display:none; }
133
- .ocw-quick button { flex:none; border:1px solid #e3ded7; background:#fff; border-radius:999px; padding:7px 14px; font-size:13px; cursor:pointer; color:#444; white-space:nowrap; transition:border-color .12s,color .12s; }
134
- .ocw-quick button:hover { border-color:var(--ocw-accent); color:var(--ocw-accent); }
149
+ .ocw-quick button { flex:none; border:none; background:var(--ocw-tint); border-radius:999px; padding:7px 14px; font-size:12px; font-weight:600; cursor:pointer; color:var(--ocw-accent); white-space:nowrap; transition:background .12s,color .12s; }
150
+ .ocw-quick button:hover { background:var(--ocw-accent); color:var(--ocw-onaccent); }
135
151
  .ocw-form-host:empty { display:none; }
136
152
  .ocw-form { margin:6px 12px 0; padding:12px; background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:14px; }
137
153
  .ocw-form-title { font-weight:700; font-size:14px; margin-bottom:8px; }
138
154
  .ocw-form-row { display:flex; flex-direction:column; gap:3px; margin-bottom:8px; }
139
155
  .ocw-form-lbl { font-size:12px; color:var(--ocw-mut); }
140
- .ocw-form-input { border:1px solid #e3ded7; border-radius:9px; padding:9px 11px; font:inherit; font-size:14px; outline:none; }
156
+ .ocw-form-input { border:1px solid var(--ocw-line); border-radius:9px; padding:9px 11px; font:inherit; font-size:14px; outline:none; }
141
157
  .ocw-form-input:focus { border-color:var(--ocw-accent); }
142
158
  .ocw-form-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:4px; }
143
159
  .ocw-form-cancel { background:none; border:none; color:var(--ocw-mut); font-size:13px; cursor:pointer; padding:8px 10px; }
144
160
  .ocw-form-submit { background:var(--ocw-accent); color:#fff; border:none; border-radius:999px; padding:8px 18px; font-size:13px; font-weight:600; cursor:pointer; }
145
161
  .ocw-modal { position:absolute; inset:0; background:rgba(20,18,16,.42); display:flex; align-items:center; justify-content:center; z-index:50; }
146
- .ocw-modal-card { background:#fff; border-radius:16px; padding:20px; width:78%; max-width:300px; box-shadow:0 14px 44px rgba(0,0,0,.22); }
162
+ .ocw-modal-card { background:var(--ocw-card); border-radius:16px; padding:20px; width:78%; max-width:300px; box-shadow:0 14px 44px rgba(0,0,0,.22); }
147
163
  .ocw-modal-title { font-weight:700; font-size:16px; margin-bottom:6px; }
148
164
  .ocw-modal-body { color:var(--ocw-mut); font-size:14px; margin-bottom:16px; }
149
165
  .ocw-modal-actions { display:flex; justify-content:flex-end; gap:8px; }
@@ -155,79 +171,72 @@ var RelayEmbed=function(J){"use strict";var ni=Object.defineProperty;var ii=(J,X
155
171
  .ocw-footer a:hover { color:var(--ocw-accent); }
156
172
  .ocw-attach { background:none;border:none;cursor:pointer;font-size:18px;padding:4px 6px;opacity:.6;flex-none; }
157
173
  .ocw-attach:hover { opacity:1; }
158
- .ocw-input textarea { flex:1; min-width:0; resize:none; border:1px solid #e3ded7; border-radius:22px; padding:11px 16px; font:inherit; font-size:14px; line-height:1.4; background:#fff; outline:none; max-height:120px; overflow-y:auto; }
159
- .ocw-input textarea:focus { border-color:var(--ocw-accent); }
174
+ .ocw-input textarea { flex:1; min-width:0; resize:none; border:none; border-radius:20px; padding:11px 16px; font:inherit; font-size:14px; line-height:1.4; background:var(--ocw-tint); outline:none; max-height:120px; overflow-y:auto; }
175
+ .ocw-input textarea:focus { box-shadow:inset 0 0 0 1.5px var(--ocw-accent); }
160
176
  /* Send button auto-sizes to its label: the default is a fixed circle around an
161
177
  * inline SVG; a TEXT label (i18n.send: "Send", "보내기", "Enviar"…) switches to
162
178
  * .ocw-sendbtn-label — a pill whose width follows the text. A fixed 42px
163
179
  * circle with 18px type overflowed the moment anyone localized the label. */
164
- .ocw-sendbtn { min-width:42px; height:42px; border-radius:999px; border:none; background:var(--ocw-accent); color:#fff; font:inherit; font-size:14px; font-weight:600; cursor:pointer; flex:none; display:flex; align-items:center; justify-content:center; padding:0; transition:opacity .15s, transform .1s; }
180
+ .ocw-sendbtn { min-width:38px; height:38px; border-radius:999px; border:none; background:var(--ocw-accent2); color:#fff; font:inherit; font-size:14px; font-weight:600; cursor:pointer; flex:none; display:flex; align-items:center; justify-content:center; padding:0; transition:opacity .15s, transform .1s; }
165
181
  .ocw-sendbtn-label { padding:0 16px; white-space:nowrap; }
166
182
  .ocw-sendbtn svg { width:19px; height:19px; display:block; }
167
183
  .ocw-sendbtn:not(:disabled):hover { transform:scale(1.05); }
168
184
  .ocw-sendbtn:not(:disabled):active { transform:scale(.96); }
169
185
  .ocw-sendbtn:disabled { opacity:.5; cursor:default; }
170
186
  .ocw-sendbtn:focus-visible, .ocw-back:focus-visible, .ocw-chip:focus-visible { outline:2px solid var(--ocw-accent); outline-offset:2px; }
171
- .ocw-cobrowse-btn { display:none; }
172
- .ocw-cobrowse-btn.show { display:inline-flex; }
173
- .ocw-cobrowse-btn.on { color:var(--ocw-accent); border-color:var(--ocw-accent); }
174
- .ocw-cobrowse-canvas { position:absolute; inset:0; z-index:40; touch-action:none; display:none; }
175
- .ocw-cobrowse-canvas.active { display:block; cursor:crosshair; }
176
- .ocw-cobrowse-toolbar { position:absolute; top:8px; right:8px; z-index:41; display:none; gap:6px; background:rgba(255,255,255,.92); border-radius:999px; padding:5px 8px; box-shadow:0 2px 10px rgba(0,0,0,.12); }
177
- .ocw-cobrowse-toolbar.active { display:flex; align-items:center; }
178
- .ocw-cobrowse-swatch { width:18px; height:18px; border-radius:50%; border:2px solid transparent; cursor:pointer; padding:0; }
179
- .ocw-cobrowse-swatch.sel { border-color:#1c1b1a; }
180
- .ocw-cobrowse-clear { background:none; border:1px solid #e3ded7; border-radius:999px; font-size:11px; padding:3px 8px; cursor:pointer; color:var(--ocw-mut); }
181
- .ocw-cobrowse-clear:hover { border-color:#e74c3c; color:#e74c3c; }
182
- .ocw-cobrowse-hint { position:absolute; bottom:8px; left:8px; z-index:41; font-size:11px; color:var(--ocw-mut); background:rgba(255,255,255,.9); border-radius:8px; padding:3px 8px; display:none; }
183
- .ocw-cobrowse-hint.active { display:block; }
184
187
 
185
- .ocw-translate-btn { position:absolute; bottom:2px; right:-26px; background:#fff; border:1px solid #e3ded7; border-radius:50%; width:22px; height:22px; font-size:11px; cursor:pointer; color:var(--ocw-mut); display:flex; align-items:center; justify-content:center; opacity:0; transition:opacity .15s; padding:0; }
188
+ .ocw-translate-btn { position:absolute; bottom:2px; right:-26px; background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:50%; width:22px; height:22px; font-size:11px; cursor:pointer; color:var(--ocw-mut); display:flex; align-items:center; justify-content:center; opacity:0; transition:opacity .15s; padding:0; }
186
189
  .ocw-row.theirs .ocw-translate-btn { right:auto; left:-26px; }
187
190
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
188
191
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
189
- `;function zn(){if(typeof document>"u"||document.getElementById(ut))return;const n=document.createElement("style");n.id=ut,n.textContent=Mn,document.head.appendChild(n)}function l(n,e,t){const o=document.createElement(n);return e&&(o.className=e),t!==void 0&&(o.textContent=t),o}function Kn(n){try{return new Date(n).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function We(n){var e;switch(n.kind){case"text":return n.text;case"system":return typeof((e=n.data)==null?void 0:e.message)=="string"?String(n.data.message):n.event;case"card":return[n.title,n.body].filter(Boolean).join(" — ");case"attachment":return n.name??n.url;case"form":return n.prompt;case"appointment":return`📅 ${n.title} — ${new Date(n.startIso).toLocaleString()}`}}class $n{constructor(e,t,o,i={}){a(this,"scroll");a(this,"chips");a(this,"typing");a(this,"quick");a(this,"formHost");a(this,"csatPanel");a(this,"awayNotice");a(this,"preChatPanel");a(this,"deflectPanel");a(this,"preChatBuilt",!1);a(this,"preChatDone",!1);a(this,"footer");a(this,"input");a(this,"subjectCard");a(this,"e2eBadge");a(this,"statusBadge");a(this,"headerName");a(this,"connStatus");a(this,"typingTimer",null);a(this,"csatSubmitted",!1);a(this,"sendBtn");a(this,"compactObserver",null);a(this,"cobrowseBtn");a(this,"cobrowseCanvas");a(this,"cobrowseToolbar");a(this,"cobrowseHint");a(this,"cobrowseActive",!1);a(this,"cobrowseColor","#f5713c");a(this,"lastAnnotationVersion",-1);a(this,"storeRef",null);a(this,"scrollCleanup",null);a(this,"translationCache",new Map);a(this,"showingTranslation",new Set);a(this,"subjectBuilt",!1);var I,E,L,T,H,D,W,ee,k,$;this.root=e,this.me=t,this.h=o,this.cfg=i,zn(),e.replaceChildren(),e.classList.add("ocw"),i.accent&&e.style.setProperty("--ocw-accent",i.accent);const s=l("div","ocw-head");if(this.h.onBack){const b=l("button","ocw-back","‹");b.type="button",b.setAttribute("aria-label","Back"),b.addEventListener("click",()=>this.h.onBack()),s.append(b)}const r=l("div","ocw-avatar");if((I=i.userInfo)!=null&&I.avatar){const b=document.createElement("img");b.src=i.userInfo.avatar,b.alt=i.userInfo.name??"You",b.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",r.append(b)}else r.textContent=(E=i.userInfo)!=null&&E.name?i.userInfo.name[0].toUpperCase():"🧑";s.append(r);const p=l("div","ocw-head-main");this.headerName=l("div","ocw-head-name",((L=i.subject)==null?void 0:L.ownerLabel)??((T=i.subject)==null?void 0:T.title)??""),p.append(this.headerName),(H=i.subject)!=null&&H.subtitle&&p.append(l("div","ocw-head-meta",i.subject.subtitle)),s.append(p),this.statusBadge=l("span","ocw-badge",((D=i.subject)==null?void 0:D.status)??""),(W=i.subject)!=null&&W.status||(this.statusBadge.style.display="none"),s.append(this.statusBadge),this.e2eBadge=l("span","ocw-e2e","🔒 E2E"),this.e2eBadge.style.display="none",s.append(this.e2eBadge),this.connStatus=l("span","ocw-conn-status"),this.connStatus.style.display="none",s.append(this.connStatus),this.cobrowseBtn=l("button","ocw-menu ocw-cobrowse-btn","🖍"),this.cobrowseBtn.title="Shared whiteboard — draw to point things out together",this.cobrowseBtn.addEventListener("click",()=>{this.cobrowseActive=!this.cobrowseActive,this.updateCobrowseUI()}),s.append(this.cobrowseBtn),s.append(l("button","ocw-menu","⋯")),this.chips=l("div","ocw-chiprow"),this.scroll=l("div","ocw-scroll"),this.subjectCard=l("div","ocw-subject"),this.typing=l("div","ocw-typing");const c=l("div","ocw-typing-bubble");c.append(l("div","ocw-typing-dot"),l("div","ocw-typing-dot"),l("div","ocw-typing-dot")),this.typing.append(l("div","ocw-dot","🧑"),c),this.quick=l("div","ocw-quick");for(const b of i.quickReplies??[]){const P=l("button",void 0,b);P.addEventListener("click",()=>{this.h.onSend(b),this.quick.style.display="none"}),this.quick.append(P)}this.formHost=l("div","ocw-form-host"),this.csatPanel=l("div","ocw-csat"),this.csatPanel.style.display="none",this.awayNotice=l("div","ocw-away"),this.awayNotice.style.display="none",this.preChatPanel=l("div","ocw-prechat"),this.preChatPanel.style.display="none",this.deflectPanel=l("div","ocw-deflect"),this.deflectPanel.style.display="none",this.input=l("textarea",void 0),this.input.rows=1,this.input.placeholder=((ee=i.i18n)==null?void 0:ee.placeholder)??"Message…";const u=l("button","ocw-sendbtn");u.type="button";const y=(k=i.i18n)==null?void 0:k.send;y?(u.textContent=y,u.classList.add("ocw-sendbtn-label"),u.setAttribute("aria-label",y)):(u.innerHTML=Ln,u.setAttribute("aria-label","Send message")),u.disabled=!0,this.sendBtn=u,u.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var b,P;this.sendBtn.disabled=this.input.value.trim().length===0,this.autoGrowInput(),this.storeRef&&!this.storeRef.messages().some(N=>N.senderRole==="guest")?(P=(b=this.h).onDeflectQuery)==null||P.call(b,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",b=>{b.isComposing||b.keyCode===229||(b.key==="Enter"&&!b.shiftKey?(b.preventDefault(),this.flushSend()):this.signalTyping())});const d=l("button","ocw-attach","📎");d.title="Attach image or file";const f=document.createElement("input");f.type="file",f.accept="image/*,.pdf,.txt,.doc,.docx",f.style.display="none",d.addEventListener("click",()=>f.click()),f.addEventListener("change",()=>{var b;(b=f.files)!=null&&b[0]&&this.h.onAttach&&this.h.onAttach(f.files[0]),f.value=""});const w=l("div","ocw-input");w.append(d,f,this.input,u);const C=l("div","ocw-footer");(($=i.i18n)==null?void 0:$.poweredBy)!==void 0?C.textContent=i.i18n.poweredBy:C.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=C,e.append(s,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.preChatPanel,this.deflectPanel,this.awayNotice,w,this.footer),this.cobrowseCanvas=l("canvas","ocw-cobrowse-canvas"),this.cobrowseToolbar=l("div","ocw-cobrowse-toolbar");for(const b of["#f5713c","#1c1b1a","#2563eb","#16a34a","#dc2626"]){const P=l("button","ocw-cobrowse-swatch");P.style.background=b,P.type="button",b===this.cobrowseColor&&P.classList.add("sel"),P.addEventListener("click",()=>{this.cobrowseColor=b;for(const N of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch"))N.classList.remove("sel");P.classList.add("sel")}),this.cobrowseToolbar.append(P)}const v=l("button","ocw-cobrowse-clear","Clear");v.addEventListener("click",()=>{var b,P;return(P=(b=this.h).onAnnotateClear)==null?void 0:P.call(b)}),this.cobrowseToolbar.append(v),this.cobrowseHint=l("div","ocw-cobrowse-hint","🖍 Draw to point things out — visible to both sides"),e.append(this.cobrowseCanvas,this.cobrowseToolbar,this.cobrowseHint),this.bindCobrowsePointerEvents();const g=b=>{e.classList.toggle("ocw-compact",b>0&&b<Bn)};g(e.clientWidth),typeof ResizeObserver<"u"&&(this.compactObserver=new ResizeObserver(b=>{var N;const P=((N=b[0])==null?void 0:N.contentRect.width)??e.clientWidth;g(P)}),this.compactObserver.observe(e))}getScrollEl(){return this.scroll}setScrollCleanup(e){var t;(t=this.scrollCleanup)==null||t.call(this),this.scrollCleanup=e}destroy(){var e,t;(e=this.scrollCleanup)==null||e.call(this),this.scrollCleanup=null,this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),(t=this.compactObserver)==null||t.disconnect(),this.compactObserver=null}flushSend(){this.hideDeflection();const e=this.input.value.trim();e&&(this.input.value="",this.sendBtn.disabled=!0,this.autoGrowInput(),this.h.onTyping(!1),this.h.onSend(e))}autoGrowInput(){this.input.style.height="auto";const e=this.input.scrollHeight;e>0?this.input.style.height=`${Math.min(e,120)}px`:this.input.style.removeProperty("height")}signalTyping(){const e=this.input.value.trim().slice(0,100)||void 0;this.h.onTyping(!0,e),this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.h.onTyping(!1),2e3)}render(e){var d,f,w,C,v;if(this.storeRef=e,this.cobrowseBtn.classList.toggle("show",!!e.subject),!e.subject&&this.cobrowseActive&&(this.cobrowseActive=!1,this.updateCobrowseUI()),this.cobrowseActive&&e.annotationVersion!==this.lastAnnotationVersion&&(this.lastAnnotationVersion=e.annotationVersion,this.resizeCobrowseCanvas(),this.redrawCobrowse()),e.accent&&this.root.style.setProperty("--ocw-accent",e.accent),this.e2eBadge.style.display=e.e2e?"inline-flex":"none",this.buildSubjectCard(e),e.subject){const g=(d=this.cfg.subject)==null?void 0:d.ownerLabel;g&&(this.headerName.textContent=g)}this.quick.style.display=e.messages().length===0?"flex":"none",this.chips.replaceChildren();const t=e.visibleActions();this.chips.style.display=t.length?"flex":"none";for(const g of t)this.chips.append(this.chipEl(g));const o=this.scroll.scrollHeight,i=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const g=l("div","ocw-load-more");g.textContent="↑ Loading earlier messages…",g.style.pointerEvents="none",this.scroll.append(g)}let s=0;for(const g of e.messages())this.scroll.append(this.messageEl(g,e)),g.senderId!==this.me&&g.seq>s&&(s=g.seq);i>20?this.scroll.scrollTop=this.scroll.scrollHeight-o+i:this.scroll.scrollTop=this.scroll.scrollHeight,s>0&&this.h.onReadUpTo(s);const r=[...e.typing];this.typing.classList.toggle("active",r.length>0);const p=this.typing.querySelector(".ocw-typing-bubble");p&&p.setAttribute("aria-label",r.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const c=e.messages().some(g=>g.senderRole==="guest");if(!!((f=e.preChat)!=null&&f.enabled)&&!this.preChatDone&&!c&&(e.preChat.showWhen!=="offline"||e.offline))this.preChatBuilt||this.buildPreChatPanel(e.preChat),this.preChatPanel.style.display="block",this.awayNotice.style.display="none",(w=this.root.querySelector(".ocw-input"))==null||w.style.setProperty("display","none");else{if(this.preChatPanel.style.display="none",e.offline){this.awayNotice.firstChild||this.awayNotice.append(l("span","ocw-away-icon","🌙"),l("span","",""));const g=this.awayNotice.lastChild;g.textContent=e.offlineMessage||((C=this.cfg.i18n)==null?void 0:C.offline)||"We're away right now — send your message and we'll reply as soon as we're back.",this.awayNotice.style.display="flex"}else this.awayNotice.style.display="none";(v=this.root.querySelector(".ocw-input"))==null||v.style.removeProperty("display")}const y=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&y.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block")}setConnStatus(e,t){if(e==="open"){this.connStatus.style.display="none";return}this.connStatus.style.display="";const o=e==="error";this.connStatus.className=`ocw-conn-status${o?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=o?`⚠ ${t??"Chat unavailable"}`:e==="reconnecting"?t??"↻ reconnecting…":"● connecting…"}buildPreChatPanel(e){var c;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(l("div","ocw-prechat-title",e.title??"Before we start…"));const t=l("div","ocw-offline-form"),o={};for(const u of e.fields??["name","email"]){const y=l("input","ocw-offline-input");y.type=u==="email"?"email":u==="phone"?"tel":"text",y.placeholder=u==="name"?"Your name":u==="email"?"Your email":"Your phone number",o[u]=y,t.append(y)}let i=null;if((c=e.topics)!=null&&c.length){i=l("select",void 0);const u=document.createElement("option");u.value="",u.textContent="What is this about?",i.append(u);for(const y of e.topics){const d=document.createElement("option");d.value=y,d.textContent=y,i.append(d)}t.append(i)}let s=null,r=null;if(e.callbackOption){const u=l("label","ocw-prechat-cb");s=document.createElement("input"),s.type="checkbox",u.append(s,document.createTextNode("📞 Request a call back")),t.append(u),o.phone||(r=l("input","ocw-offline-input"),r.type="tel",r.placeholder="Phone number for the call",r.style.display="none",s.addEventListener("change",()=>r.style.setProperty("display",s.checked?"block":"none")),t.append(r))}const p=l("button","ocw-offline-submit","Start chat");p.type="button",p.addEventListener("click",()=>{var f,w,C,v,g,I,E;const u=(f=o.email)==null?void 0:f.value.trim();if(o.email&&(!u||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))){o.email.focus();return}const y=!!(s!=null&&s.checked),d=(((w=o.phone)==null?void 0:w.value)??(r==null?void 0:r.value)??"").trim();if(y&&!d){(C=o.phone??r)==null||C.focus();return}if(i&&((v=e.topics)!=null&&v.length)&&!i.value){i.focus();return}p.disabled=!0,this.completePreChat(),(E=(I=this.h).onPreChat)==null||E.call(I,{...(g=o.name)!=null&&g.value.trim()?{name:o.name.value.trim()}:{},...u?{email:u}:{},...d?{phone:d}:{},...i!=null&&i.value?{topic:i.value}:{},...y?{callback:!0}:{}})}),t.append(p),this.preChatPanel.append(t)}completePreChat(){this.preChatDone=!0,this.preChatPanel.style.display="none",this.storeRef&&this.render(this.storeRef)}showDeflection(e){if(!e.length)return this.hideDeflection();this.deflectPanel.replaceChildren(),this.deflectPanel.append(l("div","ocw-deflect-hint","Instant answers — tap to expand"));for(const t of e.slice(0,3)){const o=l("button","ocw-deflect-card");o.append(l("div","ocw-deflect-q",t.title),l("div","ocw-deflect-a",t.answer)),o.addEventListener("click",()=>o.classList.toggle("open")),this.deflectPanel.append(o)}this.deflectPanel.style.display="flex"}hideDeflection(){this.deflectPanel.style.display="none",this.deflectPanel.replaceChildren()}buildCsatPanel(){this.csatPanel.replaceChildren(),this.csatPanel.append(l("div","ocw-csat-title","How did we do?"));const e=l("div","ocw-csat-stars"),t=[];for(let o=1;o<=5;o++){const i=l("button","ocw-csat-star","★");i.dataset.score=String(o),i.addEventListener("mouseenter",()=>t.forEach((s,r)=>s.classList.toggle("lit",r<o))),i.addEventListener("mouseleave",()=>t.forEach(s=>s.classList.remove("lit"))),i.addEventListener("click",()=>{var s,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(l("div","ocw-csat-done",`Thanks for your ${o}★ rating!`)),(r=(s=this.h).onCsat)==null||r.call(s,o)}),t.push(i),e.append(i)}this.csatPanel.append(e)}updateCobrowseUI(){this.cobrowseCanvas.classList.toggle("active",this.cobrowseActive),this.cobrowseToolbar.classList.toggle("active",this.cobrowseActive),this.cobrowseHint.classList.toggle("active",this.cobrowseActive),this.cobrowseBtn.classList.toggle("on",this.cobrowseActive),this.cobrowseActive&&(this.resizeCobrowseCanvas(),this.redrawCobrowse())}resizeCobrowseCanvas(){this.cobrowseCanvas.width=this.root.clientWidth||1,this.cobrowseCanvas.height=this.root.clientHeight||1}drawStroke(e){const t=this.cobrowseCanvas.getContext("2d");if(!t||e.points.length<2)return;const o=this.cobrowseCanvas.width,i=this.cobrowseCanvas.height;t.strokeStyle=e.color,t.lineWidth=Math.max(1,e.width*Math.min(o,i)),t.lineJoin="round",t.lineCap="round",t.beginPath(),t.moveTo(e.points[0].x*o,e.points[0].y*i);for(const s of e.points.slice(1))t.lineTo(s.x*o,s.y*i);t.stroke()}redrawCobrowse(){var t;const e=this.cobrowseCanvas.getContext("2d");if(e){e.clearRect(0,0,this.cobrowseCanvas.width,this.cobrowseCanvas.height);for(const o of((t=this.storeRef)==null?void 0:t.annotations)??[])this.drawStroke(o)}}bindCobrowsePointerEvents(){let e=!1,t=[];const o=r=>{const p=this.cobrowseCanvas.getBoundingClientRect(),c=p.width>0?(r.clientX-p.left)/p.width:0,u=p.height>0?(r.clientY-p.top)/p.height:0;return{x:Math.min(1,Math.max(0,c)),y:Math.min(1,Math.max(0,u))}},i=.006;this.cobrowseCanvas.addEventListener("pointerdown",r=>{this.cobrowseActive&&(e=!0,t=[o(r)],this.cobrowseCanvas.setPointerCapture(r.pointerId))}),this.cobrowseCanvas.addEventListener("pointermove",r=>{e&&(t.push(o(r)),this.redrawCobrowse(),this.drawStroke({points:t,color:this.cobrowseColor,width:i}))});const s=r=>{var p,c;if(e){e=!1,t.length>1&&((c=(p=this.h).onAnnotate)==null||c.call(p,{id:`an_${Date.now()}_${Math.random().toString(36).slice(2)}`,points:t,color:this.cobrowseColor,width:i})),t=[];try{this.cobrowseCanvas.releasePointerCapture(r.pointerId)}catch{}}};this.cobrowseCanvas.addEventListener("pointerup",s),this.cobrowseCanvas.addEventListener("pointercancel",s)}buildSubjectCard(e){if(this.subjectBuilt)return;const t=e.subject,o=this.cfg.subject,i=(t==null?void 0:t.title)??(o==null?void 0:o.title);if(!i)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(l("div","ocw-subject-title",i)),o!=null&&o.subtitle&&this.subjectCard.append(l("div","ocw-subject-sub",o.subtitle));const s=l("div","ocw-tags");if(t)for(const[p,c]of Object.entries(t.fields))s.append(l("span","ocw-tag",`${p}: ${c}`));else for(const p of(o==null?void 0:o.tags)??[])s.append(l("span","ocw-tag",p));s.childNodes.length&&this.subjectCard.append(s);const r=(t==null?void 0:t.state)??(o==null?void 0:o.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const t=l("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return t.dataset.actionId=e.id,t.addEventListener("click",async()=>{var o;e.confirm&&!await this.confirm(e.label)||((o=e.input)!=null&&o.length?this.openForm(e):this.h.onInvoke(e.id))}),t}confirm(e){return new Promise(t=>{const o=l("div","ocw-modal"),i=l("div","ocw-modal-card");i.append(l("div","ocw-modal-title",e)),i.append(l("div","ocw-modal-body",`Confirm “${e}”?`));const s=l("div","ocw-modal-actions"),r=l("button","ocw-modal-cancel","Cancel"),p=l("button","ocw-modal-ok","Confirm"),c=u=>{o.remove(),t(u)};r.addEventListener("click",()=>c(!1)),p.addEventListener("click",()=>c(!0)),o.addEventListener("click",u=>{u.target===o&&c(!1)}),s.append(r,p),i.append(s),o.append(i),this.root.append(o),p.focus()})}openForm(e){var p,c;this.formHost.replaceChildren();const t=l("div","ocw-form");t.append(l("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const o=new Map;for(const u of e.input??[]){const y=l("label","ocw-form-row");if(y.append(l("span","ocw-form-lbl",u.label)),u.type==="select"&&((p=u.options)!=null&&p.length)){const d=l("select","ocw-form-input");u.required||d.append(l("option",void 0,"— select —"));for(const f of u.options){const w=l("option");w.value=f,w.textContent=f,d.append(w)}u.required&&(d.required=!0),y.append(d),o.set(u.name,d)}else{const d=l("input","ocw-form-input");d.type=u.type==="number"?"number":u.type==="date"?"datetime-local":"text",u.required&&(d.required=!0),y.append(d),o.set(u.name,d)}t.append(y)}const i=l("div","ocw-form-actions"),s=l("button","ocw-form-cancel","Cancel"),r=l("button","ocw-form-submit","Send");s.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const u={};for(const[y,d]of o){if(d.required&&!d.value){d.style.borderColor="#e5484d";return}u[y]=d.type==="number"?Number(d.value):d.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,u)}),i.append(s,r),t.append(i),this.formHost.append(t),(c=o.values().next().value)==null||c.focus()}messageEl(e,t){var d;if(e.senderRole==="system"){const f=l("div","ocw-sys");return f.textContent=e.deletedAt?"message deleted":We(e.content),f}const o=e.senderId===this.me,i=!!e.internal,s=l("div",`ocw-row ${i?"ocw-note mine":o?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!o&&!i&&s.append(l("div","ocw-dot",e.senderRole==="bot"?"🤖":"🧑"));const r=l("div"),p=l("div","ocw-bubble-wrap");if(e.replyToId){const f=l("div","ocw-reply-to","↩ replying to a message");f.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",r.append(f)}const c=l("div","ocw-bubble");let u=null;if(e.deletedAt)c.append(l("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const f=e.content;if((d=f.mime)!=null&&d.startsWith("image/")){const w=document.createElement("img");w.src=f.url,w.alt=f.name??"image",w.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",w.addEventListener("click",()=>window.open(f.url,"_blank")),c.append(w)}else{const w=document.createElement("a");w.href=f.url,w.target="_blank",w.rel="noopener",w.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",w.append(l("span",void 0,"📄"),l("span",void 0,f.name??"file")),c.append(w)}}else if(e.content.kind==="appointment"){const f=e.content,w=l("div","ocw-appt");w.append(l("div","ocw-appt-title",`📅 ${f.title}`)),w.append(l("div","ocw-appt-time",new Date(f.startIso).toLocaleString()+" – "+new Date(f.endIso).toLocaleTimeString())),f.location&&w.append(l("div","ocw-appt-loc",`📍 ${f.location}`)),f.description&&w.append(l("div","ocw-appt-desc",f.description));const C=l("div","ocw-appt-links"),v=document.createElement("a");v.href=f.googleUrl,v.target="_blank",v.rel="noopener",v.className="ocw-appt-btn",v.textContent="📅 Add to Google Calendar";const g=document.createElement("a");g.href=f.icalUrl,g.download=`${f.title}.ics`,g.className="ocw-appt-btn ocw-appt-btn-sec",g.textContent="🍎 Apple / iCal",C.append(v,g),w.append(C),c.append(w)}else u=document.createTextNode(We(e.content)),c.append(u),e.editedAt&&c.append(l("span","ocw-edited","(edited)"));if(p.append(c),!o&&!i&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&u){const f=e.content.text;if(f.trim()){const w=l("button","ocw-translate-btn","🌐");w.type="button",w.title="Translate",w.addEventListener("click",C=>{if(C.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),u.textContent=f,w.textContent="🌐",w.title="Translate";return}const v=this.translationCache.get(e.id);if(v!==void 0){this.showingTranslation.add(e.id),u.textContent=v,w.textContent="↩",w.title="Show original";return}w.textContent="⏳",this.h.onTranslate(f).then(g=>{if(g===null){w.textContent="⚠️",w.title="Translation unavailable",setTimeout(()=>{w.textContent="🌐",w.title="Translate"},1500);return}this.translationCache.set(e.id,g),this.showingTranslation.add(e.id),u.textContent=g,w.textContent="↩",w.title="Show original"})}),p.append(w)}}if(o&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const f=l("div","ocw-msg-menu");if(this.h.onEdit){const w=l("button",void 0,"✏️");w.title="Edit",w.addEventListener("click",C=>{C.stopPropagation();const v=We(e.content),g=document.createElement("textarea");g.value=v,g.rows=Math.min(4,Math.ceil(v.length/40)+1),g.style.cssText="width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";const I=l("button","ocw-form-submit","Save");I.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const E=l("button","ocw-form-cancel","Cancel");E.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const L=l("div");L.style.cssText="display:flex;gap:6px;justify-content:flex-end",L.append(E,I);const T=l("div");T.append(g,L),c.replaceChildren(T),g.focus(),g.select();const H=()=>c.replaceChildren(u??document.createTextNode(v));E.addEventListener("click",H),I.addEventListener("click",()=>{const D=g.value.trim();D&&D!==v&&this.h.onEdit(e.id,D),H()}),g.addEventListener("keydown",D=>{D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),I.click()),D.key==="Escape"&&H()})}),f.append(w)}if(this.h.onDelete){const w=l("button","del","🗑");w.title="Delete",w.addEventListener("click",C=>{C.stopPropagation(),this.h.onDelete(e.id)}),f.append(w)}p.append(f)}if(r.append(p),this.h.onReact&&!e.deletedAt&&e.seq>0){const f=l("div","ocw-react-wrap"),w=l("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[g,I]of Object.entries(e.reactions)){const E=l("button",`ocw-react-pill${I.includes(this.me)?" mine":""}`,`${g} ${I.length}`);E.addEventListener("click",()=>{var L,T;return(T=(L=this.h).onReact)==null?void 0:T.call(L,e.id,g,I.includes(this.me))}),w.append(E)}const C=l("button","ocw-react-btn","+"),v=l("div","ocw-react-picker");for(const g of Pn){const I=l("button",void 0,g);I.addEventListener("click",E=>{var T,H,D,W;E.stopPropagation();const L=(H=(T=e.reactions)==null?void 0:T[g])==null?void 0:H.includes(this.me);(W=(D=this.h).onReact)==null||W.call(D,e.id,g,!!L),v.style.display="none"}),v.append(I)}v.style.display="none",C.addEventListener("click",g=>{g.stopPropagation();const I=v.style.display==="none";v.style.display=I?"flex":"none",I&&document.addEventListener("click",()=>{v.style.display="none"},{once:!0})}),w.append(C),f.append(w,v),r.append(f)}else e.reactions&&Object.keys(e.reactions).length&&r.append(l("div","ocw-react",Object.entries(e.reactions).map(([f,w])=>`${f}${w.length}`).join(" ")));const y=l("div","ocw-time ocw-meta",Kn(e.ts));if(o&&e.status){const f=l("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,Rn(e.status));y.append(f)}return o&&e.seq>0&&t.lastReadByOthers>=e.seq&&y.append(l("span","ocw-seen"," · Seen")),r.append(y),s.append(r),s}}function Rn(n){switch(n){case"read":return"✓✓";case"delivered":return"✓✓";case"sent":return"✓";default:return"🕓"}}const Dn=20;function Ve(n,e){var c;const t=n.trim().replace(/\/+$/,""),o=(c=t.match(/^(https|http|wss|ws):\/\//))==null?void 0:c[1],i=o?o==="https"||o==="wss":!0,s=(o?t.slice(o.length+3):t).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${i?"https":"http"}://${s}`;return{wsUrl:`${i?"wss":"ws"}://${s}/ws`,httpBase:r}}function _n(n){return Ve(n).httpBase}function jn(n,e,t,o){const i=`beforeSeq=${t}&limit=${o}`;return[`${n}/conversations/${e}/messages?${i}`,`${n}/conversations/${e}/history?${i}`]}async function ft(n,e,t,o,i=Dn){let s,r=!1;for(const p of jn(n,e,o,i))try{const c=await fetch(p,{headers:{authorization:`Bearer ${t}`}});if(r=!0,!c.ok)continue;const u=await c.json();return{messages:u.messages??[],hasMore:u.hasMore??!1}}catch(c){s=c}return r?console.error(`[chat-widget] history request to ${n} was rejected for conversation ${e}.`):console.error(`[chat-widget] could not load history from ${n} — the request never reached the server. This is almost always CORS: add this site's origin to the chatroom's allowed origins (dashboard → chatroom → allowed origins) or to the server's CORS_ORIGINS.`,s),null}async function Hn(n,e,t,o,i,s){const r=s?s.replace(/\/+$/,""):_n(n),p=await ft(r,t,e,Number.MAX_SAFE_INTEGER);if(!p||(p.messages.length?(o.apply({type:"sync",conversationId:t,messages:p.messages}),o.apply({type:"history",conversationId:t,messages:[],hasMore:p.hasMore}),i.render(o)):o.apply({type:"history",conversationId:t,messages:[],hasMore:!1}),!p.hasMore))return;let c=!1;const u=async()=>{if(c||!o.hasMoreHistory)return;c=!0;const w=o.messages()[0];if(!w){c=!1;return}const C=await ft(r,t,e,w.seq);C&&(o.apply({type:"history",conversationId:t,messages:C.messages,hasMore:C.hasMore}),i.render(o)),c=!1},y=i.getScrollEl();if(!y)return;let d=!1;setTimeout(()=>{d=!0},300);const f=()=>{d&&y.scrollTop<80&&o.hasMoreHistory&&!c&&u()};y.addEventListener("scroll",f,{passive:!0}),i.setScrollCleanup(()=>y.removeEventListener("scroll",f))}const xe=new WeakMap,Pe=new Map;function wt(n){return`relay-launcher::${n.profileId}::${n.subjectId??""}`}let ye=null;function qn(){if(ye&&ye.state!=="closed")return ye;try{return ye=new AudioContext,ye}catch{return null}}function gt(n){var Se,Ce,bt,mt,vt;xe.has(n.el)&&(xe.get(n.el).close(),xe.delete(n.el)),n.launcher&&((Se=Pe.get(wt(n)))==null||Se.close());const e=et();let t,o=!1;const i=n.token??n.userId??e,s=i!==e?e:void 0,{wsUrl:r,httpBase:p}=Ve(n.url,n.apiUrl);let c=new dn(i);const u=n.subjectId?`${i}::${n.subjectId}`:i,y=new yn(u);let d,f=!1,w=null,C=null,v=null,g=null;!n.launcher&&!n.el.style.height&&n.el.clientHeight===0&&(n.el.style.width=n.el.style.width||"100%",n.el.style.height="600px");for(const h of y.load())c.addOptimistic(h.clientMsgId,h.content);let I=null,E=null,L=0,T=!n.launcher;if(n.launcher){const x=(n.position??"bottom-right").includes("right");I=document.createElement("div"),I.style.cssText=`position:fixed;${x?"right:20px":"left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${x?"flex-end":"flex-start"};gap:12px`;const S=document.createElement("div"),j=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(max-width: 479px)"):null,Ie=R=>{n.el.classList.toggle("ocw-fs",R),S.style.cssText=R?["position:fixed","inset:0","width:100%","height:100dvh","border-radius:0","overflow:hidden","box-shadow:none","display:none","flex-direction:column","background:#fff","transition:opacity .18s","opacity:0","z-index:9998"].join(";"):["width:min(380px, calc(100vw - 40px))","height:min(600px, calc(100dvh - 108px))","border-radius:16px","overflow:hidden","box-shadow:0 8px 40px rgba(0,0,0,.18)","display:none","flex-direction:column","background:#fff","transform-origin:bottom "+(x?"right":"left"),"transition:opacity .18s,transform .18s","opacity:0","transform:scale(.95)"].join(";")};Ie((j==null?void 0:j.matches)??!1);const Ee=R=>Ie(R.matches);j==null||j.addEventListener("change",Ee),w=j,C=Ee,n.el.style.cssText="width:100%;height:100%;overflow:hidden",S.append(n.el);const ze='<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',Ke='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',V=document.createElement("button");V.type="button",V.style.cssText=["width:56px;height:56px;border-radius:50%",`background:${n.accent??"#4F63F5"}`,"color:#fff;border:none;cursor:pointer","box-shadow:0 4px 16px rgba(0,0,0,.25)","position:relative;flex:none","display:flex;align-items:center;justify-content:center","transition:transform .15s"].join(";"),V.onmouseenter=()=>{V.style.transform="scale(1.08)"},V.onmouseleave=()=>{V.style.transform="scale(1)"},E=document.createElement("span"),E.style.cssText="position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";const $e=()=>{V.innerHTML=T?Ke:ze,V.setAttribute("aria-label",T?"Close chat":"Open chat"),V.setAttribute("aria-expanded",String(T)),V.append(E)};$e(),I.append(S,V),document.body.append(I);const Ye=`ocw-teaser-dismissed::${n.profileId}`,Re=typeof n.launcherMessage=="string"?{title:n.launcherMessage}:n.launcherMessage;let K=null;const ei=()=>{try{return sessionStorage.getItem(Ye)==="1"}catch{return!1}},ti='<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',kt=()=>{const R=Re!=null&&Re.title?Re:c.launcherMessage??void 0;if(!(!!(R!=null&&R.title)&&!T&&!ei())){K&&(K.remove(),K=null);return}if(K)return;K=document.createElement("div"),K.setAttribute("role","button"),K.setAttribute("tabindex","0"),K.setAttribute("aria-label",R.title),K.style.cssText=["max-width:280px","background:#fff","border-radius:14px","box-shadow:0 6px 28px rgba(0,0,0,.16)","padding:14px 40px 14px 16px","position:relative","cursor:pointer","font-family:inherit",`align-self:${x?"flex-end":"flex-start"}`,"animation:ocw-teaser-in .22s ease-out"].join(";");const Ze=document.createElement("div");if(Ze.textContent=R.title,Ze.style.cssText="font-size:15px;font-weight:600;color:#111;line-height:1.35",K.append(Ze),R.subtitle){const ne=document.createElement("div");ne.style.cssText="display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";const Qe=document.createElement("span");Qe.innerHTML=ti,Qe.style.cssText=`color:${n.accent??"#4F63F5"};display:inline-flex`;const Ct=document.createElement("span");Ct.textContent=R.subtitle,ne.append(Qe,Ct),K.append(ne)}const pe=document.createElement("button");pe.type="button",pe.setAttribute("aria-label","Dismiss"),pe.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',pe.style.cssText="position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0",pe.addEventListener("click",ne=>{ne.stopPropagation();try{sessionStorage.setItem(Ye,"1")}catch{}K&&(K.remove(),K=null)}),K.append(pe);const St=()=>{T||(T=!0,Je(!0),$e(),L=0,E&&(E.style.display="none"),K&&(K.remove(),K=null))};K.addEventListener("click",St),K.addEventListener("keydown",ne=>{(ne.key==="Enter"||ne.key===" ")&&(ne.preventDefault(),St())}),I.insertBefore(K,V)};if(!document.getElementById("ocw-teaser-style")){const R=document.createElement("style");R.id="ocw-teaser-style",R.textContent="@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",document.head.append(R)}g=kt,kt();const Je=R=>{R?(S.style.display="flex",requestAnimationFrame(()=>{S.style.opacity="1",S.style.transform="scale(1)"})):(S.style.opacity="0",S.style.transform="scale(.95)",setTimeout(()=>{T||(S.style.display="none")},180))};V.addEventListener("click",()=>{if(T=!T,Je(T),$e(),T){L=0,E&&(E.style.display="none");try{sessionStorage.setItem(Ye,"1")}catch{}}g==null||g()}),v=R=>{R.key==="Escape"&&T&&(T=!1,Je(!1),$e())},document.addEventListener("keydown",v)}const H=()=>{T||(L++,E&&(E.textContent=String(L),E.style.display="flex"))},D=()=>{try{const h=qn();if(!h)return;h.state==="suspended"&&h.resume().catch(()=>{});const x=h.createOscillator(),S=h.createGain();x.connect(S),S.connect(h.destination),x.frequency.setValueAtTime(880,h.currentTime),x.frequency.exponentialRampToValueAtTime(440,h.currentTime+.15),S.gain.setValueAtTime(.3,h.currentTime),S.gain.exponentialRampToValueAtTime(.001,h.currentTime+.3),x.start(),x.stop(h.currentTime+.3)}catch{}},W=[],ee=h=>{for(;W.length;){const x=W.shift();y.add({clientMsgId:x.clientMsgId,content:x.content,ts:Date.now()}),k.send({type:"send",conversationId:h,clientMsgId:x.clientMsgId,content:x.content})}};let k;const $=new Un(`ocw-e2e-${n.profileId}`);let b=!1;const P=[],N=[];let ve=!1;const de=(h,x)=>{$.sealText(x).then(S=>{d&&k.send({type:"send",conversationId:d,clientMsgId:h,content:S})})},Me=(h,x,S)=>{$.sealText(x,S).then(j=>{d&&k.send({type:"send",conversationId:d,clientMsgId:h,content:j})})},m=()=>{for(;P.length;){const h=P.shift();de(h.clientMsgId,h.text)}for(;N.length;){const h=N.shift();de(h.clientMsgId,h.text)}},M=h=>{k.send({type:"fetchPrekey",targetUserId:h})},q=n.i18n??{},G=["ar","he","fa","ur"],F=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";G.includes(F)&&!n.el.dir&&(n.el.dir="rtl",n.el.style.fontFamily=n.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const Y=new pn,U=`oc_prechat_${n.profileId}_${i.slice(-8)}`,z=new $n(n.el,i,{onSend(h){const x=`cm_${Math.random().toString(36).slice(2)}`,S={kind:"text",text:h};c.addOptimistic(x,S),z.render(c),c.e2e?$.ready?de(x,h):ve?N.push({clientMsgId:x,text:h}):(P.push({clientMsgId:x,text:h}),c.assignedAgentId&&M(c.assignedAgentId)):d?(y.add({clientMsgId:x,content:S,ts:Date.now()}),k.send({type:"send",conversationId:d,clientMsgId:x,content:S})):W.push({clientMsgId:x,content:S})},async onAttach(h){if(!d)return;const x=`${p}/upload?name=${encodeURIComponent(h.name)}`,S=`cm_${Math.random().toString(36).slice(2)}`;c.addOptimistic(S,{kind:"text",text:`📎 Uploading ${h.name}…`}),z.render(c);try{const j=await fetch(x,{method:"POST",headers:{"content-type":h.type,authorization:`Bearer ${i}`},body:h});if(!j.ok)throw new Error(`Upload failed: ${j.status}`);const{url:Ie,name:Ee,mime:ze,size:Ke}=await j.json();c.addOptimistic(S,{kind:"attachment",url:Ie,name:Ee,mime:ze,size:Ke}),z.render(c),k.send({type:"send",conversationId:d,clientMsgId:S,content:{kind:"attachment",url:Ie,name:Ee,mime:ze,size:Ke}})}catch(j){c.addOptimistic(S,{kind:"text",text:`⚠️ Upload failed: ${j.message}`}),z.render(c)}},onInvoke(h,x){d&&k.send({type:"invoke",conversationId:d,actionId:h,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...x?{inputs:x}:{}})},onTyping(h,x){d&&k.send({type:"typing",conversationId:d,isTyping:h,...x?{preview:x}:{}})},onPreChat(h){try{localStorage.setItem(U,"1")}catch{}k.send({type:"open",profileId:n.profileId,...n.subjectId?{subjectId:n.subjectId}:{},userInfo:{...h.name?{name:h.name}:{},...h.email?{email:h.email}:{},...h.phone||h.topic?{meta:{...h.phone?{phone:h.phone}:{},...h.topic?{topic:h.topic}:{}}}:{}}});const x=h.callback?`📞 Call-back requested${h.phone?`: ${h.phone}`:""}${h.topic?` — ${h.topic}`:""}`:h.topic?`Topic: ${h.topic}`:"";x&&d&&!c.e2e&&k.send({type:"send",conversationId:d,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:x}})},onDeflectQuery(h){if(o)return;clearTimeout(t);const x=h.trim();if(x.length<3){z.hideDeflection();return}t=setTimeout(()=>{fetch(`${p}/kb/search?profileId=${encodeURIComponent(n.profileId)}&q=${encodeURIComponent(x.slice(0,200))}`).then(S=>S.ok?S.json():{articles:[]}).then(S=>z.showDeflection(S.articles??[])).catch(()=>z.hideDeflection())},350)},onReadUpTo(h){d&&k.send({type:"read",conversationId:d,seq:h})},onLoadMore(){if(!d||!c.e2e)return;const h=c.messages()[0];h&&k.send({type:"history",conversationId:d,beforeSeq:h.seq,limit:20})},onEdit(h,x){d&&k.send({type:"edit",conversationId:d,messageId:h,content:{kind:"text",text:x}})},onDelete(h){d&&k.send({type:"delete",conversationId:d,messageId:h})},onReact(h,x,S){d&&k.send({type:"react",conversationId:d,messageId:h,emoji:x,remove:S})},onCsat(h){d&&fetch(`${p}/conversations/${d}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({score:h})}).catch(()=>{})},onAnnotate(h){d&&k.send({type:"annotate",conversationId:d,stroke:h})},onAnnotateClear(){d&&k.send({type:"annotate_clear",conversationId:d})},...n.translateLang?{async onTranslate(h){try{const x=await fetch(`${p}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${i}`},body:JSON.stringify({text:h,targetLang:n.translateLang})});if(!x.ok)return null;const{translated:S}=await x.json();return S}catch{return null}}}:{},...n.onBack?{onBack:n.onBack}:{}},{...n.subject?{subject:n.subject}:{},...n.quickReplies?{quickReplies:n.quickReplies}:{},...n.accent?{accent:n.accent}:{},...(Ce=n.user)!=null&&Ce.name||(bt=n.user)!=null&&bt.avatar?{userInfo:{...n.user.name?{name:n.user.name}:{},...n.user.avatar?{avatar:n.user.avatar}:{}}}:{},i18n:q});try{localStorage.getItem(U)&&z.completePreChat()}catch{}const he=n.user&&(n.user.name||n.user.email||n.user.avatar||n.user.meta)?{...n.user.name?{name:n.user.name}:{},...n.user.email?{email:n.user.email}:{},...n.user.avatar?{avatar:n.user.avatar}:{},...n.user.meta?{meta:n.user.meta}:{}}:void 0,ke={type:"open",profileId:n.profileId,...n.kind==="direct"&&n.peerId?{kind:"direct",peerId:n.peerId}:n.subjectId?{subjectId:n.subjectId}:{},...s?{linkFrom:s}:{},...he?{userInfo:he}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(mt=n.subject)!=null&&mt.title?{subjectTitle:n.subject.title}:{},...(vt=n.subject)!=null&&vt.subtitle?{subjectMeta:n.subject.subtitle}:{}};k=new un({...n.refreshToken?{refreshToken:n.refreshToken}:{},url:r,token:i,open:ke,getCursor:()=>c.highestSeq(),onStatusChange:(h,x)=>z.setConnStatus(h,x),onFrame(h){if(Y.apply(h),h.type==="opened"){if(d=h.conversation.id,!f){f=!0;for(const x of y.load())k.send({type:"send",conversationId:d,clientMsgId:x.clientMsgId,content:x.content})}Hn(r,i,d,c,z,p),W.length&&ee(d)}if(h.type==="ack"&&y.remove(h.clientMsgId),h.type==="prekeyBundle"){h.bundle&&(ve=!0,$.x3dhSendTo(h.bundle).then(x=>{const S=[...P.splice(0),...N.splice(0)];for(const j of S)Me(j.clientMsgId,j.text,x);z.render(c)}));return}if(h.type==="message"&&c.e2e){const x=An(h.message.content);if(x&&!$.ready){$.x3dhReceiveFrom(x.x3dhIK,x.x3dhEK,x.x3dhSPK).then(async()=>{await $.openFrame(h),c.apply(h),z.render(c)});return}}if(h.type==="peerkey"){$.onPeerKey(h.key).then(()=>{m(),z.render(c)});return}(async()=>{if(c.e2e&&await $.openFrame(h),c.apply(h),h.type==="manifest"&&(g==null||g()),h.type==="message"&&h.message.senderId!==i&&!h.message.internal&&(H(),D()),c.e2e&&d&&!b){b=!0;const x=await $.initX3DH();k.send({type:"uploadPrekeys",...x});const S=await $.begin();k.send({type:"pubkey",conversationId:d,key:S})}z.render(c)})()}}),k.connect(),z.render(c);const ae=n.launcher?wt(n):null,te={close:()=>{o=!0,clearTimeout(t),k.close(),I==null||I.remove(),z.destroy(),Y.destroy(),w&&C&&w.removeEventListener("change",C),v&&(document.removeEventListener("keydown",v),v=null),xe.delete(n.el),ae&&Pe.get(ae)===te&&Pe.delete(ae)}};return xe.set(n.el,te),ae&&Pe.set(ae,te),te}const Xe="wss://api.paramms.com/ws";function Nn(n,e){const t=n.profileId??n.appId;if(!t)throw new Error("Relay: `profileId` is required (your chatroom id, e.g. 'p_...').");const o=n.subjectId??(n.listingId?`listing_${n.listingId}`:void 0),i=n.launcher??!0,s=n.contextTitle??n.listingTitle??n.subjectTitle,r=n.contextSubtitle??n.listingMeta??n.subjectMeta,p=n.contextStatus??n.listingStatus??n.subjectStatus,c=n.listingPrice??n.subjectPrice,u=s?{title:s,...r?{subtitle:r}:{},...c!=null?{tags:[`$${c.toLocaleString()}`]}:{},...p?{status:p}:{}}:void 0,y=n.subject??u,d=n.userName??n.name,f=n.userEmail??n.email,w=n.userAvatar??n.avatar,C=d||f||w?{...d?{name:d}:{},...f?{email:f}:{},...w?{avatar:w}:{}}:void 0,v=n.user??C,g=n.launcherMessage&&typeof n.launcherMessage=="object"?n.launcherMessage:n.launcherMessage?n.launcherSubtitle?{title:n.launcherMessage,subtitle:n.launcherSubtitle}:n.launcherMessage:void 0;return{el:e,url:n.url??Xe,profileId:t,...n.apiUrl?{apiUrl:n.apiUrl}:{},...o?{subjectId:o}:{},...n.token?{token:n.token}:{},...n.refreshToken?{refreshToken:n.refreshToken}:{},...n.userId?{userId:n.userId}:{},...y?{subject:y}:{},...v?{user:v}:{},...n.quickReplies?{quickReplies:n.quickReplies}:{},...n.i18n?{i18n:n.i18n}:{},...n.accent?{accent:n.accent}:{},...n.translateLang?{translateLang:n.translateLang}:{},...g?{launcherMessage:g}:{},...xt(n)&&!i?{onBack:()=>{be=!0,me=!1,Be(re)}}:{},launcher:i,position:n.position??"bottom-right"}}let Z=null,_=null,se=!1,re={},be=!1,me=!1;function xt(n){return!!(n.inbox||n.inboxStart)}let Q=null;function Fn(n,e){const t=!e&&!!n.el;if(se&&!t&&(_.innerHTML="",_=null,se=!1),t){const o=typeof n.el=="string"?document.querySelector(n.el):n.el;o instanceof HTMLElement?(_&&_!==o&&!se&&_.remove(),_=o,se=!0):console.error(`[Relay] \`el\` ("${String(n.el)}") did not match any element — falling back to an auto-created host.`)}return(!_||!se&&!_.isConnected)&&(_=document.createElement("div"),_.id="relay-widget-root",document.body.appendChild(_),se=!1),!e&&n.height&&(_.style.height=n.height,_.style.width||(_.style.width="100%")),_}function Be(n){try{const e=n.launcher??!0;Q==null||Q(),Q=null,Z==null||Z.close(),Z=null;const t=Fn(n,e);if(xt(n)&&!e&&be){On(n,t);return}Z=gt(Nn(n,t))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}async function On(n,e){const t=n.profileId??n.appId;if(!t&&!n.tenantId){console.error("[Relay] `inbox` requires `profileId` or `tenantId`.");return}e.innerHTML="";const o=document.createElement("div");o.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;background:#fff";const i=document.createElement("div");i.style.cssText="position:absolute;inset:0";const s=document.createElement("div");s.style.cssText="position:absolute;inset:0;display:none";const r=document.createElement("button");r.type="button",r.setAttribute("aria-label","Close"),r.textContent="✕",r.style.cssText="position:absolute;top:8px;right:8px;z-index:20;width:32px;height:32px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.05);border:none;color:#1c1b1a;font-size:16px;line-height:1;cursor:pointer",r.onclick=()=>{be=!1,Be(re)},o.append(i,s);const p=!me&&!!t;p&&o.append(r),e.appendChild(o);let c=null,u=null;Q=()=>{u==null||u.close(),c==null||c.close(),e.innerHTML=""};let y;try{({mountChatList:y}=await Promise.resolve().then(()=>Qn))}catch(f){console.error("[Relay] could not load the conversation list module.",f),i.isConnected&&(i.style.cssText+=";display:flex;align-items:center;justify-content:center;padding:16px;font:13px system-ui;color:#b91c1c;text-align:center",i.textContent="Could not load conversations.");return}if(!i.isConnected)return;const d=f=>{const w=f.profileId??t;if(!w){console.error("[Relay] conversation row has no chatroom; cannot open it.",f);return}r.style.display="none",u==null||u.close(),u=gt({el:s,url:n.url??Xe,...n.apiUrl?{apiUrl:n.apiUrl}:{},profileId:w,...f.kind==="direct"&&f.peerId?{kind:"direct",peerId:f.peerId}:f.subjectId?{subjectId:f.subjectId}:{},...n.token?{token:n.token}:{},...n.refreshToken?{refreshToken:n.refreshToken}:{},...n.userId?{userId:n.userId}:{},...n.userId||n.userName||n.userEmail||n.userAvatar?{user:{...n.userName?{name:n.userName}:{},...n.userEmail?{email:n.userEmail}:{},...n.userAvatar?{avatar:n.userAvatar}:{}}}:{},...f.subjectTitle?{subject:{title:f.subjectTitle,...f.subjectMeta?{subtitle:f.subjectMeta}:{}}}:{},...n.accent?{accent:n.accent}:{},launcher:!1,onBack:()=>{u==null||u.close(),u=null,s.style.display="none",i.style.display="",r.style.display="",c==null||c.refresh()}}),i.style.display="none",s.style.display=""};c=y({el:i,url:n.url??Xe,...n.apiUrl?{apiUrl:n.apiUrl}:{},...t?{profileId:t}:{},...n.tenantId?{tenantId:n.tenantId}:{},scope:n.inboxScope??"tenant",...p?{reserveCloseSpace:!0}:{},onSelect:d,onNewChat:()=>{const f=t??(c==null?void 0:c.defaultProfileId());f&&d({id:"__new__",profileId:f,state:"open",updatedAt:Date.now()})},...n.token?{token:n.token}:{},...n.userId?{userId:n.userId}:{},...n.accent?{accent:n.accent}:{}})}function yt(n){me=!!(n.inboxStart&&!(n.launcher??!0)),be=me,re={...n},Be(re)}function Wn(n){re={...re,...n},Be(re)}function Vn(){Q==null||Q(),Q=null,Z==null||Z.close(),Z=null,_&&!se&&_.remove(),_=null,se=!1,be=!1,me=!1,re={}}function Ge(n,e){switch(n){case"boot":yt(e??{});break;case"update":case"identify":Wn(e??{});break;case"shutdown":Vn();break;default:console.warn("[Relay] unknown command:",n)}}function Xn(){if(typeof document>"u")return null;const n=document.querySelector("script[data-relay-app]")??document.querySelector("script[data-relay-profile-id]")??document.querySelector("script[data-relay-tenant-id]"),e=n==null?void 0:n.dataset,t=(e==null?void 0:e.relayApp)??(e==null?void 0:e.relayProfileId),o=e==null?void 0:e.relayTenantId;if(!t&&!o)return null;const i=t?{profileId:t}:{};o&&(i.tenantId=o),e.relayUser&&(i.userId=e.relayUser),e.relayToken&&(i.token=e.relayToken),e.relayListing&&(i.listingId=e.relayListing),e.relayAccent&&(i.accent=e.relayAccent),e.relayUrl&&(i.url=e.relayUrl);const s=e.relayPosition;(s==="bottom-left"||s==="bottom-right")&&(i.position=s),e.relayLauncherMessage&&(i.launcherMessage=e.relayLauncherMessage),e.relayLauncherSubtitle&&(i.launcherSubtitle=e.relayLauncherSubtitle),e.relayLauncher==="false"&&(i.launcher=!1),e.relayUserName&&(i.userName=e.relayUserName),e.relayUserEmail&&(i.userEmail=e.relayUserEmail),e.relayUserAvatar&&(i.userAvatar=e.relayUserAvatar),e.relayContextTitle&&(i.contextTitle=e.relayContextTitle),e.relayContextSubtitle&&(i.contextSubtitle=e.relayContextSubtitle),e.relayContextStatus&&(i.contextStatus=e.relayContextStatus),e.relayListingTitle&&(i.listingTitle=e.relayListingTitle),e.relayListingMeta&&(i.listingMeta=e.relayListingMeta),e.relayListingPrice&&(i.listingPrice=Number(e.relayListingPrice)),e.relayListingStatus&&(i.listingStatus=e.relayListingStatus),e.relayTarget&&(i.el=e.relayTarget),e.relayHeight&&(i.height=e.relayHeight),e.relayInbox==="true"&&(i.inbox=!0),e.relayInbox==="false"&&(i.inbox=!1),e.relayInboxStart==="true"&&(i.inboxStart=!0),e.relayInboxStart==="false"&&(i.inboxStart=!1);const r=e.relayInboxScope;return(r==="tenant"||r==="profile")&&(i.inboxScope=r),e.relayTranslateLang&&(i.translateLang=e.relayTranslateLang),i}if(typeof window<"u"){const n=window,e=n.Relay&&n.Relay.q?n.Relay.q:[];n.Relay=Ge;let t=!1;for(const o of e){const[i,s]=o;i==="boot"&&(t=!0),Ge(i,s)}if(!t){const o=n.relaySettings??Xn();o&&yt(o)}}function Gn(n){const e=Math.floor((Date.now()-n)/1e3);if(e<60)return"just now";if(e<3600)return`${Math.floor(e/60)}m`;if(e<86400)return`${Math.floor(e/3600)}h`;const t=Math.floor(e/86400);if(t<=7)return`${t}d`;try{return new Date(n).toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return`${t}d`}}const Yn='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" fill-opacity="0.12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function A(n,e,t){const o=document.createElement(n);return e&&(o.className=e),t!==void 0&&(o.textContent=t),o}const Jn=`
190
- .ocl { --ocl-accent:#f5713c; --ocl-bg:#f3efe9; --ocl-card:#fff; --ocl-line:#ececec; --ocl-ink:#1c1b1a; --ocl-mut:#9b9690;
192
+ `,wt="objectchat-widget-styles",$n=["👍","❤️","😂","😮","😢","🙏"],Rn=400,Dn='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function _n(){if(typeof document>"u"||document.getElementById(wt))return;const t=document.createElement("style");t.id=wt,t.textContent=Kn,document.head.appendChild(t)}function c(t,e,n){const o=document.createElement(t);return e&&(o.className=e),n!==void 0&&(o.textContent=n),o}function jn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function Ve(t){var e;switch(t.kind){case"text":return t.text;case"system":return typeof((e=t.data)==null?void 0:e.message)=="string"?String(t.data.message):t.event;case"card":return[t.title,t.body].filter(Boolean).join(" — ");case"attachment":return t.name??t.url;case"form":return t.prompt;case"appointment":return`📅 ${t.title} — ${new Date(t.startIso).toLocaleString()}`}}class qn{constructor(e,n,o,i={}){a(this,"scroll");a(this,"chips");a(this,"typing");a(this,"quick");a(this,"formHost");a(this,"csatPanel");a(this,"awayNotice");a(this,"headStatus");a(this,"reopenBtn");a(this,"preChatPanel");a(this,"deflectPanel");a(this,"preChatBuilt",!1);a(this,"preChatDone",!1);a(this,"footer");a(this,"input");a(this,"subjectCard");a(this,"e2eBadge");a(this,"statusBadge");a(this,"headerName");a(this,"connStatus");a(this,"typingTimer",null);a(this,"csatSubmitted",!1);a(this,"sendBtn");a(this,"compactObserver",null);a(this,"storeRef",null);a(this,"cfgAccent2");a(this,"scrollCleanup",null);a(this,"translationCache",new Map);a(this,"showingTranslation",new Set);a(this,"subjectBuilt",!1);var w,U,C,x,b,_,R,j,m,P,O;this.root=e,this.me=n,this.h=o,this.cfg=i,_n(),e.replaceChildren(),e.classList.add("ocw"),i.accent&&e.style.setProperty("--ocw-accent",i.accent);const s=i.accent2??i.accent;s&&e.style.setProperty("--ocw-accent2",s),this.cfgAccent2=i.accent2,i.theme&&i.theme!=="auto"&&(e.dataset.theme=i.theme);const r=c("div","ocw-head");if(this.h.onBack){const T=c("button","ocw-back","‹");T.type="button",T.setAttribute("aria-label","Back"),T.addEventListener("click",()=>this.h.onBack()),r.append(T)}const p=c("div","ocw-avatar");if((w=i.userInfo)!=null&&w.avatar){const T=document.createElement("img");T.src=i.userInfo.avatar,T.alt=i.userInfo.name??"You",T.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",p.append(T)}else p.textContent=(U=i.userInfo)!=null&&U.name?i.userInfo.name[0].toUpperCase():"🧑";r.append(p);const l=c("div","ocw-head-main");this.headerName=c("div","ocw-head-name",((C=i.subject)==null?void 0:C.ownerLabel)??((x=i.subject)==null?void 0:x.title)??""),l.append(this.headerName),this.headStatus=c("div","ocw-head-status"),this.headStatus.style.display="none",l.append(this.headStatus),(b=i.subject)!=null&&b.subtitle&&l.append(c("div","ocw-head-meta",i.subject.subtitle)),r.append(l),this.statusBadge=c("span","ocw-badge",((_=i.subject)==null?void 0:_.status)??""),(R=i.subject)!=null&&R.status||(this.statusBadge.style.display="none"),r.append(this.statusBadge),this.e2eBadge=c("span","ocw-e2e","🔒 E2E"),this.e2eBadge.style.display="none",r.append(this.e2eBadge),this.connStatus=c("span","ocw-conn-status"),this.connStatus.style.display="none",r.append(this.connStatus),r.append(c("button","ocw-menu","⋯")),this.chips=c("div","ocw-chiprow"),this.scroll=c("div","ocw-scroll"),this.subjectCard=c("div","ocw-subject"),this.typing=c("div","ocw-typing");const u=c("div","ocw-typing-bubble");u.append(c("div","ocw-typing-dot"),c("div","ocw-typing-dot"),c("div","ocw-typing-dot")),this.typing.append(c("div","ocw-dot","🧑"),u),this.quick=c("div","ocw-quick");for(const T of i.quickReplies??[]){const N=c("button",void 0,T);N.addEventListener("click",()=>{this.h.onSend(T),this.quick.style.display="none"}),this.quick.append(N)}this.formHost=c("div","ocw-form-host"),this.csatPanel=c("div","ocw-csat"),this.csatPanel.style.display="none",this.awayNotice=c("div","ocw-away"),this.awayNotice.style.display="none",this.preChatPanel=c("div","ocw-prechat"),this.preChatPanel.style.display="none",this.deflectPanel=c("div","ocw-deflect"),this.deflectPanel.style.display="none",this.input=c("textarea",void 0),this.input.rows=1,this.input.placeholder=((j=i.i18n)==null?void 0:j.placeholder)??"Message…";const f=c("button","ocw-sendbtn");f.type="button";const d=(m=i.i18n)==null?void 0:m.send;d?(f.textContent=d,f.classList.add("ocw-sendbtn-label"),f.setAttribute("aria-label",d)):(f.innerHTML=Dn,f.setAttribute("aria-label","Send message")),f.disabled=!0,this.sendBtn=f,f.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var T,N;this.sendBtn.disabled=this.input.value.trim().length===0,this.autoGrowInput(),this.storeRef&&!this.storeRef.messages().some(J=>J.senderRole==="guest")?(N=(T=this.h).onDeflectQuery)==null||N.call(T,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",T=>{T.isComposing||T.keyCode===229||(T.key==="Enter"&&!T.shiftKey?(T.preventDefault(),this.flushSend()):this.signalTyping())});const v=c("button","ocw-attach","📎");v.title="Attach image or file";const k=document.createElement("input");k.type="file",k.accept="image/*,.pdf,.txt,.doc,.docx",k.style.display="none",v.addEventListener("click",()=>k.click()),k.addEventListener("change",()=>{var T;(T=k.files)!=null&&T[0]&&this.h.onAttach&&this.h.onAttach(k.files[0]),k.value=""});const L=c("div","ocw-input");L.append(v,k,this.input,f);const z=c("div","ocw-footer");((P=i.i18n)==null?void 0:P.poweredBy)!==void 0?z.textContent=i.i18n.poweredBy:z.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=z,this.reopenBtn=c("button","ocw-reopen",((O=this.cfg.i18n)==null?void 0:O.reopen)??"Reopen conversation"),this.reopenBtn.type="button",this.reopenBtn.addEventListener("click",()=>{this.reopenBtn.style.display="none";const T=this.root.querySelector(".ocw-input textarea");T==null||T.focus()}),e.append(r,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.preChatPanel,this.deflectPanel,this.awayNotice,L,this.reopenBtn,this.footer);const g=T=>{e.classList.toggle("ocw-compact",T>0&&T<Rn)};g(e.clientWidth),typeof ResizeObserver<"u"&&(this.compactObserver=new ResizeObserver(T=>{var J;const N=((J=T[0])==null?void 0:J.contentRect.width)??e.clientWidth;g(N)}),this.compactObserver.observe(e))}getScrollEl(){return this.scroll}setScrollCleanup(e){var n;(n=this.scrollCleanup)==null||n.call(this),this.scrollCleanup=e}destroy(){var e,n;(e=this.scrollCleanup)==null||e.call(this),this.scrollCleanup=null,this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),(n=this.compactObserver)==null||n.disconnect(),this.compactObserver=null}flushSend(){this.hideDeflection();const e=this.input.value.trim();e&&(this.input.value="",this.sendBtn.disabled=!0,this.autoGrowInput(),this.h.onTyping(!1),this.h.onSend(e))}autoGrowInput(){this.input.style.height="auto";const e=this.input.scrollHeight;e>0?this.input.style.height=`${Math.min(e,120)}px`:this.input.style.removeProperty("height")}signalTyping(){const e=this.input.value.trim().slice(0,100)||void 0;this.h.onTyping(!0,e),this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.h.onTyping(!1),2e3)}render(e){var k,L,z,g,w,U,C,x;if(this.storeRef=e,e.accent&&(this.root.style.setProperty("--ocw-accent",e.accent),this.root.style.setProperty("--ocw-accent2",this.cfgAccent2??e.accent)),this.e2eBadge.style.display=e.e2e?"inline-flex":"none",this.buildSubjectCard(e),e.subject){const b=(k=this.cfg.subject)==null?void 0:k.ownerLabel;b&&(this.headerName.textContent=b)}this.quick.style.display=e.messages().length===0?"flex":"none",this.chips.replaceChildren();const n=e.visibleActions();this.chips.style.display=n.length?"flex":"none";for(const b of n)this.chips.append(this.chipEl(b));const o=this.scroll.scrollHeight,i=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const b=c("div","ocw-load-more");b.textContent="↑ Loading earlier messages…",b.style.pointerEvents="none",this.scroll.append(b)}let s=0,r=null;for(const b of e.messages()){const _=b.senderRole!=="system"&&b.senderId!==this.me&&!b.internal&&b.senderId!==r;this.scroll.append(this.messageEl(b,e,_)),b.senderRole!=="system"&&(r=b.senderId),b.senderId!==this.me&&b.seq>s&&(s=b.seq)}i>20?this.scroll.scrollTop=this.scroll.scrollHeight-o+i:this.scroll.scrollTop=this.scroll.scrollHeight,s>0&&this.h.onReadUpTo(s);const p=[...e.typing];this.typing.classList.toggle("active",p.length>0);const l=this.typing.querySelector(".ocw-typing-bubble");l&&l.setAttribute("aria-label",p.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const u=e.messages().some(b=>b.senderRole==="guest");if(!!((L=e.preChat)!=null&&L.enabled)&&!this.preChatDone&&!u&&(e.preChat.showWhen!=="offline"||e.offline))this.preChatBuilt||this.buildPreChatPanel(e.preChat),this.preChatPanel.style.display="block",this.awayNotice.style.display="none",(z=this.root.querySelector(".ocw-input"))==null||z.style.setProperty("display","none");else{if(this.preChatPanel.style.display="none",e.offline){this.awayNotice.firstChild||this.awayNotice.append(c("span","ocw-away-icon","🌙"),c("span","",""));const b=this.awayNotice.lastChild;b.textContent=e.offlineMessage||((g=this.cfg.i18n)==null?void 0:g.offline)||"We're away right now — send your message and we'll reply as soon as we're back.",this.awayNotice.style.display="flex"}else this.awayNotice.style.display="none";(w=this.root.querySelector(".ocw-input"))==null||w.style.removeProperty("display")}const d=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&d.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block");const v=d.includes(e.state);if(e.offline?(this.headStatus.textContent=`● ${e.offlineMessage||((U=this.cfg.i18n)==null?void 0:U.away)||"Away"}`,this.headStatus.className="ocw-head-status away",this.headStatus.style.display=""):e.conversationId?(this.headStatus.textContent=`● ${((C=this.cfg.i18n)==null?void 0:C.online)??"Online"}`,this.headStatus.className="ocw-head-status online",this.headStatus.style.display=""):this.headStatus.style.display="none",v&&e.messages().length>0){const b=c("div","ocw-resolved-note",`— ${((x=this.cfg.i18n)==null?void 0:x.resolved)??"Marked as resolved"} —`);this.scroll.append(b),this.reopenBtn.style.display="block"}else this.reopenBtn.style.display="none"}setConnStatus(e,n){if(e==="open"){this.connStatus.style.display="none";return}this.connStatus.style.display="";const o=e==="error";this.connStatus.className=`ocw-conn-status${o?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=o?`⚠ ${n??"Chat unavailable"}`:e==="reconnecting"?n??"↻ reconnecting…":"● connecting…"}buildPreChatPanel(e){var l;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(c("div","ocw-prechat-title",e.title??"Before we start…"));const n=c("div","ocw-offline-form"),o={};for(const u of e.fields??["name","email"]){const f=c("input","ocw-offline-input");f.type=u==="email"?"email":u==="phone"?"tel":"text",f.placeholder=u==="name"?"Your name":u==="email"?"Your email":"Your phone number",o[u]=f,n.append(f)}let i=null;if((l=e.topics)!=null&&l.length){i=c("select",void 0);const u=document.createElement("option");u.value="",u.textContent="What is this about?",i.append(u);for(const f of e.topics){const d=document.createElement("option");d.value=f,d.textContent=f,i.append(d)}n.append(i)}let s=null,r=null;if(e.callbackOption){const u=c("label","ocw-prechat-cb");s=document.createElement("input"),s.type="checkbox",u.append(s,document.createTextNode("📞 Request a call back")),n.append(u),o.phone||(r=c("input","ocw-offline-input"),r.type="tel",r.placeholder="Phone number for the call",r.style.display="none",s.addEventListener("change",()=>r.style.setProperty("display",s.checked?"block":"none")),n.append(r))}const p=c("button","ocw-offline-submit","Start chat");p.type="button",p.addEventListener("click",()=>{var v,k,L,z,g,w,U;const u=(v=o.email)==null?void 0:v.value.trim();if(o.email&&(!u||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))){o.email.focus();return}const f=!!(s!=null&&s.checked),d=(((k=o.phone)==null?void 0:k.value)??(r==null?void 0:r.value)??"").trim();if(f&&!d){(L=o.phone??r)==null||L.focus();return}if(i&&((z=e.topics)!=null&&z.length)&&!i.value){i.focus();return}p.disabled=!0,this.completePreChat(),(U=(w=this.h).onPreChat)==null||U.call(w,{...(g=o.name)!=null&&g.value.trim()?{name:o.name.value.trim()}:{},...u?{email:u}:{},...d?{phone:d}:{},...i!=null&&i.value?{topic:i.value}:{},...f?{callback:!0}:{}})}),n.append(p),this.preChatPanel.append(n)}completePreChat(){this.preChatDone=!0,this.preChatPanel.style.display="none",this.storeRef&&this.render(this.storeRef)}showDeflection(e){if(!e.length)return this.hideDeflection();this.deflectPanel.replaceChildren(),this.deflectPanel.append(c("div","ocw-deflect-hint","Instant answers — tap to expand"));for(const n of e.slice(0,3)){const o=c("button","ocw-deflect-card");o.append(c("div","ocw-deflect-q",n.title),c("div","ocw-deflect-a",n.answer)),o.addEventListener("click",()=>o.classList.toggle("open")),this.deflectPanel.append(o)}this.deflectPanel.style.display="flex"}hideDeflection(){this.deflectPanel.style.display="none",this.deflectPanel.replaceChildren()}buildCsatPanel(){this.csatPanel.replaceChildren(),this.csatPanel.append(c("div","ocw-csat-title","How did we do?"));const e=c("div","ocw-csat-stars"),n=[];for(let o=1;o<=5;o++){const i=c("button","ocw-csat-star","★");i.dataset.score=String(o),i.addEventListener("mouseenter",()=>n.forEach((s,r)=>s.classList.toggle("lit",r<o))),i.addEventListener("mouseleave",()=>n.forEach(s=>s.classList.remove("lit"))),i.addEventListener("click",()=>{var s,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(c("div","ocw-csat-done",`Thanks for your ${o}★ rating!`)),(r=(s=this.h).onCsat)==null||r.call(s,o)}),n.push(i),e.append(i)}this.csatPanel.append(e)}buildSubjectCard(e){if(this.subjectBuilt)return;const n=e.subject,o=this.cfg.subject,i=(n==null?void 0:n.title)??(o==null?void 0:o.title);if(!i)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(c("div","ocw-subject-title",i)),o!=null&&o.subtitle&&this.subjectCard.append(c("div","ocw-subject-sub",o.subtitle));const s=c("div","ocw-tags");if(n)for(const[p,l]of Object.entries(n.fields))s.append(c("span","ocw-tag",`${p}: ${l}`));else for(const p of(o==null?void 0:o.tags)??[])s.append(c("span","ocw-tag",p));s.childNodes.length&&this.subjectCard.append(s);const r=(n==null?void 0:n.state)??(o==null?void 0:o.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const n=c("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return n.dataset.actionId=e.id,n.addEventListener("click",async()=>{var o;e.confirm&&!await this.confirm(e.label)||((o=e.input)!=null&&o.length?this.openForm(e):this.h.onInvoke(e.id))}),n}confirm(e){return new Promise(n=>{const o=c("div","ocw-modal"),i=c("div","ocw-modal-card");i.append(c("div","ocw-modal-title",e)),i.append(c("div","ocw-modal-body",`Confirm “${e}”?`));const s=c("div","ocw-modal-actions"),r=c("button","ocw-modal-cancel","Cancel"),p=c("button","ocw-modal-ok","Confirm"),l=u=>{o.remove(),n(u)};r.addEventListener("click",()=>l(!1)),p.addEventListener("click",()=>l(!0)),o.addEventListener("click",u=>{u.target===o&&l(!1)}),s.append(r,p),i.append(s),o.append(i),this.root.append(o),p.focus()})}openForm(e){var p,l;this.formHost.replaceChildren();const n=c("div","ocw-form");n.append(c("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const o=new Map;for(const u of e.input??[]){const f=c("label","ocw-form-row");if(f.append(c("span","ocw-form-lbl",u.label)),u.type==="select"&&((p=u.options)!=null&&p.length)){const d=c("select","ocw-form-input");u.required||d.append(c("option",void 0,"— select —"));for(const v of u.options){const k=c("option");k.value=v,k.textContent=v,d.append(k)}u.required&&(d.required=!0),f.append(d),o.set(u.name,d)}else{const d=c("input","ocw-form-input");d.type=u.type==="number"?"number":u.type==="date"?"datetime-local":"text",u.required&&(d.required=!0),f.append(d),o.set(u.name,d)}n.append(f)}const i=c("div","ocw-form-actions"),s=c("button","ocw-form-cancel","Cancel"),r=c("button","ocw-form-submit","Send");s.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const u={};for(const[f,d]of o){if(d.required&&!d.value){d.style.borderColor="#e5484d";return}u[f]=d.type==="number"?Number(d.value):d.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,u)}),i.append(s,r),n.append(i),this.formHost.append(n),(l=o.values().next().value)==null||l.focus()}messageEl(e,n,o=!1){var v,k,L,z;if(e.senderRole==="system"){const g=c("div","ocw-sys");return g.textContent=e.deletedAt?"message deleted":Ve(e.content),g}const i=e.senderId===this.me,s=!!e.internal,r=c("div",`ocw-row ${s?"ocw-note mine":i?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!i&&!s&&r.append(c("div","ocw-dot",e.senderRole==="bot"?"🤖":"🧑"));const p=c("div");if(o){const g=e.senderRole==="bot"?((v=this.cfg.i18n)==null?void 0:v.aiAssistant)??"AI Assistant":((k=this.cfg.subject)==null?void 0:k.ownerLabel)??((L=this.cfg.subject)==null?void 0:L.title)??"Support";p.append(c("div","ocw-msg-sender",g))}const l=c("div","ocw-bubble-wrap");if(e.replyToId){const g=c("div","ocw-reply-to","↩ replying to a message");g.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",p.append(g)}const u=c("div","ocw-bubble");let f=null;if(e.deletedAt)u.append(c("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const g=e.content;if((z=g.mime)!=null&&z.startsWith("image/")){const w=document.createElement("img");w.src=g.url,w.alt=g.name??"image",w.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",w.addEventListener("click",()=>window.open(g.url,"_blank")),u.append(w)}else{const w=document.createElement("a");w.href=g.url,w.target="_blank",w.rel="noopener",w.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",w.append(c("span",void 0,"📄"),c("span",void 0,g.name??"file")),u.append(w)}}else if(e.content.kind==="appointment"){const g=e.content,w=c("div","ocw-appt");w.append(c("div","ocw-appt-title",`📅 ${g.title}`)),w.append(c("div","ocw-appt-time",new Date(g.startIso).toLocaleString()+" – "+new Date(g.endIso).toLocaleTimeString())),g.location&&w.append(c("div","ocw-appt-loc",`📍 ${g.location}`)),g.description&&w.append(c("div","ocw-appt-desc",g.description));const U=c("div","ocw-appt-links"),C=document.createElement("a");C.href=g.googleUrl,C.target="_blank",C.rel="noopener",C.className="ocw-appt-btn",C.textContent="📅 Add to Google Calendar";const x=document.createElement("a");x.href=g.icalUrl,x.download=`${g.title}.ics`,x.className="ocw-appt-btn ocw-appt-btn-sec",x.textContent="🍎 Apple / iCal",U.append(C,x),w.append(U),u.append(w)}else f=document.createTextNode(Ve(e.content)),u.append(f),e.editedAt&&u.append(c("span","ocw-edited","(edited)"));if(l.append(u),!i&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&f){const g=e.content.text;if(g.trim()){const w=c("button","ocw-translate-btn","🌐");w.type="button",w.title="Translate",w.addEventListener("click",U=>{if(U.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),f.textContent=g,w.textContent="🌐",w.title="Translate";return}const C=this.translationCache.get(e.id);if(C!==void 0){this.showingTranslation.add(e.id),f.textContent=C,w.textContent="↩",w.title="Show original";return}w.textContent="⏳",this.h.onTranslate(g).then(x=>{if(x===null){w.textContent="⚠️",w.title="Translation unavailable",setTimeout(()=>{w.textContent="🌐",w.title="Translate"},1500);return}this.translationCache.set(e.id,x),this.showingTranslation.add(e.id),f.textContent=x,w.textContent="↩",w.title="Show original"})}),l.append(w)}}if(i&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const g=c("div","ocw-msg-menu");if(this.h.onEdit){const w=c("button",void 0,"✏️");w.title="Edit",w.addEventListener("click",U=>{U.stopPropagation();const C=Ve(e.content),x=document.createElement("textarea");x.value=C,x.rows=Math.min(4,Math.ceil(C.length/40)+1),x.style.cssText="width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";const b=c("button","ocw-form-submit","Save");b.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const _=c("button","ocw-form-cancel","Cancel");_.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const R=c("div");R.style.cssText="display:flex;gap:6px;justify-content:flex-end",R.append(_,b);const j=c("div");j.append(x,R),u.replaceChildren(j),x.focus(),x.select();const m=()=>u.replaceChildren(f??document.createTextNode(C));_.addEventListener("click",m),b.addEventListener("click",()=>{const P=x.value.trim();P&&P!==C&&this.h.onEdit(e.id,P),m()}),x.addEventListener("keydown",P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),b.click()),P.key==="Escape"&&m()})}),g.append(w)}if(this.h.onDelete){const w=c("button","del","🗑");w.title="Delete",w.addEventListener("click",U=>{U.stopPropagation(),this.h.onDelete(e.id)}),g.append(w)}l.append(g)}if(p.append(l),this.h.onReact&&!e.deletedAt&&e.seq>0){const g=c("div","ocw-react-wrap"),w=c("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[x,b]of Object.entries(e.reactions)){const _=c("button",`ocw-react-pill${b.includes(this.me)?" mine":""}`,`${x} ${b.length}`);_.addEventListener("click",()=>{var R,j;return(j=(R=this.h).onReact)==null?void 0:j.call(R,e.id,x,b.includes(this.me))}),w.append(_)}const U=c("button","ocw-react-btn","+"),C=c("div","ocw-react-picker");for(const x of $n){const b=c("button",void 0,x);b.addEventListener("click",_=>{var j,m,P,O;_.stopPropagation();const R=(m=(j=e.reactions)==null?void 0:j[x])==null?void 0:m.includes(this.me);(O=(P=this.h).onReact)==null||O.call(P,e.id,x,!!R),C.style.display="none"}),C.append(b)}C.style.display="none",U.addEventListener("click",x=>{x.stopPropagation();const b=C.style.display==="none";C.style.display=b?"flex":"none",b&&document.addEventListener("click",()=>{C.style.display="none"},{once:!0})}),w.append(U),g.append(w,C),p.append(g)}else e.reactions&&Object.keys(e.reactions).length&&p.append(c("div","ocw-react",Object.entries(e.reactions).map(([g,w])=>`${g}${w.length}`).join(" ")));const d=c("div","ocw-time ocw-meta",jn(e.ts));if(i&&e.status){const g=c("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,Nn(e.status));d.append(g)}return i&&e.seq>0&&n.lastReadByOthers>=e.seq&&d.append(c("span","ocw-seen"," · Seen")),p.append(d),r.append(p),r}}function Nn(t){switch(t){case"read":return"✓✓";case"delivered":return"✓✓";case"sent":return"✓";default:return"🕓"}}const Hn=20;function Xe(t,e){var l;const n=t.trim().replace(/\/+$/,""),o=(l=n.match(/^(https|http|wss|ws):\/\//))==null?void 0:l[1],i=o?o==="https"||o==="wss":!0,s=(o?n.slice(o.length+3):n).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${i?"https":"http"}://${s}`;return{wsUrl:`${i?"wss":"ws"}://${s}/ws`,httpBase:r}}function On(t){return Xe(t).httpBase}function Fn(t,e,n,o){const i=`beforeSeq=${n}&limit=${o}`;return[`${t}/conversations/${e}/messages?${i}`,`${t}/conversations/${e}/history?${i}`]}async function gt(t,e,n,o,i=Hn){let s,r=!1;for(const p of Fn(t,e,o,i))try{const l=await fetch(p,{headers:{authorization:`Bearer ${n}`}});if(r=!0,!l.ok)continue;const u=await l.json();return{messages:u.messages??[],hasMore:u.hasMore??!1}}catch(l){s=l}return r?console.error(`[chat-widget] history request to ${t} was rejected for conversation ${e}.`):console.error(`[chat-widget] could not load history from ${t} — the request never reached the server. This is almost always CORS: add this site's origin to the chatroom's allowed origins (dashboard → chatroom → allowed origins) or to the server's CORS_ORIGINS.`,s),null}async function Wn(t,e,n,o,i,s){const r=s?s.replace(/\/+$/,""):On(t),p=await gt(r,n,e,Number.MAX_SAFE_INTEGER);if(!p||(p.messages.length?(o.apply({type:"sync",conversationId:n,messages:p.messages}),o.apply({type:"history",conversationId:n,messages:[],hasMore:p.hasMore}),i.render(o)):o.apply({type:"history",conversationId:n,messages:[],hasMore:!1}),!p.hasMore))return;let l=!1;const u=async()=>{if(l||!o.hasMoreHistory)return;l=!0;const k=o.messages()[0];if(!k){l=!1;return}const L=await gt(r,n,e,k.seq);L&&(o.apply({type:"history",conversationId:n,messages:L.messages,hasMore:L.hasMore}),i.render(o)),l=!1},f=i.getScrollEl();if(!f)return;let d=!1;setTimeout(()=>{d=!0},300);const v=()=>{d&&f.scrollTop<80&&o.hasMoreHistory&&!l&&u()};f.addEventListener("scroll",v,{passive:!0}),i.setScrollCleanup(()=>f.removeEventListener("scroll",v))}const xe=new WeakMap,Ae=new Map;function yt(t){return`relay-launcher::${t.profileId}::${t.subjectId??""}`}let me=null;function Vn(){if(me&&me.state!=="closed")return me;try{return me=new AudioContext,me}catch{return null}}function xt(t){var pe,Se,Ie,vt,kt,St,It,Ct;xe.has(t.el)&&(xe.get(t.el).close(),xe.delete(t.el)),t.launcher&&((pe=Ae.get(yt(t)))==null||pe.close());const e=tt();let n,o=!1;const i=t.token??t.userId??e,s=i!==e?e:void 0,{wsUrl:r,httpBase:p}=Xe(t.url,t.apiUrl);let l=new fn(i);const u=t.subjectId?`${i}::${t.subjectId}`:i,f=new bn(u);let d,v=!1,k=null,L=null,z=null,g=null;!t.launcher&&!t.el.style.height&&t.el.clientHeight===0&&(t.el.style.width=t.el.style.width||"100%",t.el.style.height="600px");for(const h of f.load())l.addOptimistic(h.clientMsgId,h.content);let w=null,U=null,C=0,x=!t.launcher;if(t.launcher){const y=(t.position??"bottom-right").includes("right");w=document.createElement("div"),w.style.cssText=`position:fixed;${y?"right:20px":"left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${y?"flex-end":"flex-start"};gap:12px`;const E=document.createElement("div"),q=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(max-width: 479px)"):null,Ce=$=>{t.el.classList.toggle("ocw-fs",$),E.style.cssText=$?["position:fixed","inset:0","width:100%","height:100dvh","border-radius:0","overflow:hidden","box-shadow:none","display:none","flex-direction:column","background:#fff","transition:opacity .18s","opacity:0","z-index:9998"].join(";"):["width:min(380px, calc(100vw - 40px))","height:min(600px, calc(100dvh - 108px))","border-radius:28px","overflow:hidden","box-shadow:0 12px 32px rgba(108,92,231,.14)","display:none","flex-direction:column","background:#fff","transform-origin:bottom "+(y?"right":"left"),"transition:opacity .18s,transform .18s","opacity:0","transform:scale(.95)"].join(";")};Ce((q==null?void 0:q.matches)??!1);const Te=$=>Ce($.matches);q==null||q.addEventListener("change",Te),k=q,L=Te,t.el.style.cssText="width:100%;height:100%;overflow:hidden",E.append(t.el);const Ke='<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',$e='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',V=document.createElement("button");V.type="button",V.style.cssText=["width:56px;height:56px;border-radius:50%",`background:${t.accent??"#6c5ce7"}`,"color:#fff;border:none;cursor:pointer","box-shadow:0 12px 32px rgba(108,92,231,.14)","position:relative;flex:none","display:flex;align-items:center;justify-content:center","transition:transform .15s"].join(";"),V.onmouseenter=()=>{V.style.transform="scale(1.08)"},V.onmouseleave=()=>{V.style.transform="scale(1)"},U=document.createElement("span"),U.style.cssText="position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";const Re=()=>{V.innerHTML=x?$e:Ke,V.setAttribute("aria-label",x?"Close chat":"Open chat"),V.setAttribute("aria-expanded",String(x)),V.append(U)};Re(),w.append(E,V),document.body.append(w);const Je=`ocw-teaser-dismissed::${t.profileId}`,De=typeof t.launcherMessage=="string"?{title:t.launcherMessage}:t.launcherMessage;let K=null;const ri=()=>{try{return sessionStorage.getItem(Je)==="1"}catch{return!1}},ai='<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',Tt=()=>{const $=De!=null&&De.title?De:l.launcherMessage??void 0;if(!(!!($!=null&&$.title)&&!x&&!ri())){K&&(K.remove(),K=null);return}if(K)return;K=document.createElement("div"),K.setAttribute("role","button"),K.setAttribute("tabindex","0"),K.setAttribute("aria-label",$.title),K.style.cssText=["max-width:280px","background:#fff","border-radius:16px","box-shadow:0 12px 32px rgba(108,92,231,.14)","padding:14px 40px 14px 16px","position:relative","cursor:pointer","font-family:inherit",`align-self:${y?"flex-end":"flex-start"}`,"animation:ocw-teaser-in .22s ease-out"].join(";");const Qe=document.createElement("div");if(Qe.textContent=$.title,Qe.style.cssText="font-size:15px;font-weight:600;color:#111;line-height:1.35",K.append(Qe),$.subtitle){const ne=document.createElement("div");ne.style.cssText="display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";const et=document.createElement("span");et.innerHTML=ai,et.style.cssText=`color:${t.accent??"#6c5ce7"};display:inline-flex`;const Ut=document.createElement("span");Ut.textContent=$.subtitle,ne.append(et,Ut),K.append(ne)}const ue=document.createElement("button");ue.type="button",ue.setAttribute("aria-label","Dismiss"),ue.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',ue.style.cssText="position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0",ue.addEventListener("click",ne=>{ne.stopPropagation();try{sessionStorage.setItem(Je,"1")}catch{}K&&(K.remove(),K=null)}),K.append(ue);const Et=()=>{x||(x=!0,Ze(!0),Re(),C=0,U&&(U.style.display="none"),K&&(K.remove(),K=null))};K.addEventListener("click",Et),K.addEventListener("keydown",ne=>{(ne.key==="Enter"||ne.key===" ")&&(ne.preventDefault(),Et())}),w.insertBefore(K,V)};if(!document.getElementById("ocw-teaser-style")){const $=document.createElement("style");$.id="ocw-teaser-style",$.textContent="@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",document.head.append($)}g=Tt,Tt();const Ze=$=>{$?(E.style.display="flex",requestAnimationFrame(()=>{E.style.opacity="1",E.style.transform="scale(1)"})):(E.style.opacity="0",E.style.transform="scale(.95)",setTimeout(()=>{x||(E.style.display="none")},180))};V.addEventListener("click",()=>{if(x=!x,Ze(x),Re(),x){C=0,U&&(U.style.display="none");try{sessionStorage.setItem(Je,"1")}catch{}}g==null||g()}),z=$=>{$.key==="Escape"&&x&&(x=!1,Ze(!1),Re())},document.addEventListener("keydown",z)}const b=()=>{x||(C++,U&&(U.textContent=String(C),U.style.display="flex"))},_=()=>{try{const h=Vn();if(!h)return;h.state==="suspended"&&h.resume().catch(()=>{});const y=h.createOscillator(),E=h.createGain();y.connect(E),E.connect(h.destination),y.frequency.setValueAtTime(880,h.currentTime),y.frequency.exponentialRampToValueAtTime(440,h.currentTime+.15),E.gain.setValueAtTime(.3,h.currentTime),E.gain.exponentialRampToValueAtTime(.001,h.currentTime+.3),y.start(),y.stop(h.currentTime+.3)}catch{}},R=[],j=h=>{for(;R.length;){const y=R.shift();f.add({clientMsgId:y.clientMsgId,content:y.content,ts:Date.now()}),m.send({type:"send",conversationId:h,clientMsgId:y.clientMsgId,content:y.content})}};let m;const P=new Bn(`ocw-e2e-${t.profileId}`);let O=!1;const T=[],N=[];let J=!1;const he=(h,y)=>{P.sealText(y).then(E=>{d&&m.send({type:"send",conversationId:d,clientMsgId:h,content:E})})},Me=(h,y,E)=>{P.sealText(y,E).then(q=>{d&&m.send({type:"send",conversationId:d,clientMsgId:h,content:q})})},S=()=>{for(;T.length;){const h=T.shift();he(h.clientMsgId,h.text)}for(;N.length;){const h=N.shift();he(h.clientMsgId,h.text)}},M=h=>{m.send({type:"fetchPrekey",targetUserId:h})},H=t.i18n??{},G=["ar","he","fa","ur"],F=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";G.includes(F)&&!t.el.dir&&(t.el.dir="rtl",t.el.style.fontFamily=t.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const Y=`oc_prechat_${t.profileId}_${i.slice(-8)}`,I=new qn(t.el,i,{onSend(h){const y=`cm_${Math.random().toString(36).slice(2)}`,E={kind:"text",text:h};l.addOptimistic(y,E),I.render(l),l.e2e?P.ready?he(y,h):J?N.push({clientMsgId:y,text:h}):(T.push({clientMsgId:y,text:h}),l.assignedAgentId&&M(l.assignedAgentId)):d?(f.add({clientMsgId:y,content:E,ts:Date.now()}),m.send({type:"send",conversationId:d,clientMsgId:y,content:E})):R.push({clientMsgId:y,content:E})},async onAttach(h){if(!d)return;const y=`${p}/upload?name=${encodeURIComponent(h.name)}`,E=`cm_${Math.random().toString(36).slice(2)}`;l.addOptimistic(E,{kind:"text",text:`📎 Uploading ${h.name}…`}),I.render(l);try{const q=await fetch(y,{method:"POST",headers:{"content-type":h.type,authorization:`Bearer ${i}`},body:h});if(!q.ok)throw new Error(`Upload failed: ${q.status}`);const{url:Ce,name:Te,mime:Ke,size:$e}=await q.json();l.addOptimistic(E,{kind:"attachment",url:Ce,name:Te,mime:Ke,size:$e}),I.render(l),m.send({type:"send",conversationId:d,clientMsgId:E,content:{kind:"attachment",url:Ce,name:Te,mime:Ke,size:$e}})}catch(q){l.addOptimistic(E,{kind:"text",text:`⚠️ Upload failed: ${q.message}`}),I.render(l)}},onInvoke(h,y){d&&m.send({type:"invoke",conversationId:d,actionId:h,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...y?{inputs:y}:{}})},onTyping(h,y){d&&m.send({type:"typing",conversationId:d,isTyping:h,...y?{preview:y}:{}})},onPreChat(h){try{localStorage.setItem(Y,"1")}catch{}m.send({type:"open",profileId:t.profileId,...t.subjectId?{subjectId:t.subjectId}:{},userInfo:{...h.name?{name:h.name}:{},...h.email?{email:h.email}:{},...h.phone||h.topic?{meta:{...h.phone?{phone:h.phone}:{},...h.topic?{topic:h.topic}:{}}}:{}}});const y=h.callback?`📞 Call-back requested${h.phone?`: ${h.phone}`:""}${h.topic?` — ${h.topic}`:""}`:h.topic?`Topic: ${h.topic}`:"";y&&d&&!l.e2e&&m.send({type:"send",conversationId:d,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:y}})},...((Se=t.features)==null?void 0:Se.deflection)!==!1?{onDeflectQuery(h){if(o)return;clearTimeout(n);const y=h.trim();if(y.length<3){I.hideDeflection();return}n=setTimeout(()=>{fetch(`${p}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(y.slice(0,200))}`).then(E=>E.ok?E.json():{articles:[]}).then(E=>I.showDeflection(E.articles??[])).catch(()=>I.hideDeflection())},350)}}:{},onReadUpTo(h){d&&m.send({type:"read",conversationId:d,seq:h})},onLoadMore(){if(!d||!l.e2e)return;const h=l.messages()[0];h&&m.send({type:"history",conversationId:d,beforeSeq:h.seq,limit:20})},onEdit(h,y){d&&m.send({type:"edit",conversationId:d,messageId:h,content:{kind:"text",text:y}})},onDelete(h){d&&m.send({type:"delete",conversationId:d,messageId:h})},...((Ie=t.features)==null?void 0:Ie.reactions)!==!1?{onReact(h,y,E){d&&m.send({type:"react",conversationId:d,messageId:h,emoji:y,remove:E})}}:{},...((vt=t.features)==null?void 0:vt.csat)!==!1?{onCsat(h){d&&fetch(`${p}/conversations/${d}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({score:h})}).catch(()=>{})}}:{},...t.translateLang?{async onTranslate(h){try{const y=await fetch(`${p}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${i}`},body:JSON.stringify({text:h,targetLang:t.translateLang})});if(!y.ok)return null;const{translated:E}=await y.json();return E}catch{return null}}}:{},...t.onBack?{onBack:t.onBack}:{}},{...t.subject?{subject:t.subject}:{},...t.quickReplies?{quickReplies:t.quickReplies}:{},...t.accent?{accent:t.accent}:{},...t.accent2?{accent2:t.accent2}:{},...t.theme?{theme:t.theme}:{},...(kt=t.user)!=null&&kt.name||(St=t.user)!=null&&St.avatar?{userInfo:{...t.user.name?{name:t.user.name}:{},...t.user.avatar?{avatar:t.user.avatar}:{}}}:{},i18n:H});try{localStorage.getItem(Y)&&I.completePreChat()}catch{}const ae=t.user&&(t.user.name||t.user.email||t.user.avatar||t.user.meta)?{...t.user.name?{name:t.user.name}:{},...t.user.email?{email:t.user.email}:{},...t.user.avatar?{avatar:t.user.avatar}:{},...t.user.meta?{meta:t.user.meta}:{}}:void 0,ke={type:"open",profileId:t.profileId,...t.kind==="direct"&&t.peerId?{kind:"direct",peerId:t.peerId}:t.subjectId?{subjectId:t.subjectId}:{},...s?{linkFrom:s}:{},...ae?{userInfo:ae}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(It=t.subject)!=null&&It.title?{subjectTitle:t.subject.title}:{},...(Ct=t.subject)!=null&&Ct.subtitle?{subjectMeta:t.subject.subtitle}:{}};m=new wn({...t.refreshToken?{refreshToken:t.refreshToken}:{},url:r,token:i,open:ke,getCursor:()=>l.highestSeq(),onStatusChange:(h,y)=>I.setConnStatus(h,y),onFrame(h){if(h.type==="opened"){if(d=h.conversation.id,!v){v=!0;for(const y of f.load())m.send({type:"send",conversationId:d,clientMsgId:y.clientMsgId,content:y.content})}Wn(r,i,d,l,I,p),R.length&&j(d)}if(h.type==="ack"&&f.remove(h.clientMsgId),h.type==="prekeyBundle"){h.bundle&&(J=!0,P.x3dhSendTo(h.bundle).then(y=>{const E=[...T.splice(0),...N.splice(0)];for(const q of E)Me(q.clientMsgId,q.text,y);I.render(l)}));return}if(h.type==="message"&&l.e2e){const y=An(h.message.content);if(y&&!P.ready){P.x3dhReceiveFrom(y.x3dhIK,y.x3dhEK,y.x3dhSPK,y.x3dhOTP).then(async()=>{await P.openFrame(h),l.apply(h),I.render(l)});return}}if(h.type==="peerkey"){P.onPeerKey(h.key).then(()=>{S(),I.render(l)});return}(async()=>{if(l.e2e&&await P.openFrame(h),l.apply(h),h.type==="manifest"&&(g==null||g()),h.type==="message"&&h.message.senderId!==i&&!h.message.internal&&(b(),_()),l.e2e&&d&&!O){O=!0;const y=await P.initX3DH();m.send({type:"uploadPrekeys",...y});const E=await P.begin();m.send({type:"pubkey",conversationId:d,key:E})}I.render(l)})()}}),m.connect(),I.render(l);const ce=t.launcher?yt(t):null,Z={close:()=>{o=!0,clearTimeout(n),m.close(),w==null||w.remove(),I.destroy(),k&&L&&k.removeEventListener("change",L),z&&(document.removeEventListener("keydown",z),z=null),xe.delete(t.el),ce&&Ae.get(ce)===Z&&Ae.delete(ce)}};return xe.set(t.el,Z),ce&&Ae.set(ce,Z),Z}const Ge="wss://api.paramms.com/ws";function Xn(t,e){const n=t.profileId??t.appId;if(!n)throw new Error("Relay: `profileId` is required (your chatroom id, e.g. 'p_...').");const o=t.subjectId??(t.listingId?`listing_${t.listingId}`:void 0),i=t.launcher??!0,s=t.contextTitle??t.listingTitle??t.subjectTitle,r=t.contextSubtitle??t.listingMeta??t.subjectMeta,p=t.contextStatus??t.listingStatus??t.subjectStatus,l=t.listingPrice??t.subjectPrice,u=s?{title:s,...r?{subtitle:r}:{},...l!=null?{tags:[`$${l.toLocaleString()}`]}:{},...p?{status:p}:{}}:void 0,f=t.subject??u,d=t.userName??t.name,v=t.userEmail??t.email,k=t.userAvatar??t.avatar,L=d||v||k?{...d?{name:d}:{},...v?{email:v}:{},...k?{avatar:k}:{}}:void 0,z=t.user??L,g=t.launcherMessage&&typeof t.launcherMessage=="object"?t.launcherMessage:t.launcherMessage?t.launcherSubtitle?{title:t.launcherMessage,subtitle:t.launcherSubtitle}:t.launcherMessage:void 0;return{el:e,url:t.url??Ge,profileId:n,...t.apiUrl?{apiUrl:t.apiUrl}:{},...o?{subjectId:o}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...f?{subject:f}:{},...z?{user:z}:{},...t.quickReplies?{quickReplies:t.quickReplies}:{},...t.i18n?{i18n:t.i18n}:{},...t.features?{features:t.features}:{},...t.accent?{accent:t.accent}:{},...t.accent2?{accent2:t.accent2}:{},...t.theme?{theme:t.theme}:{},...t.translateLang?{translateLang:t.translateLang}:{},...g?{launcherMessage:g}:{},...mt(t)&&!i?{onBack:()=>{be=!0,ve=!1,Le(re)}}:{},launcher:i,position:t.position??"bottom-right"}}let ee=null,D=null,se=!1,re={},be=!1,ve=!1;function mt(t){return!!(t.inbox||t.inboxStart)}let te=null;function Gn(t,e){const n=!e&&!!t.el;if(se&&!n&&(D.innerHTML="",D=null,se=!1),n){const o=typeof t.el=="string"?document.querySelector(t.el):t.el;o instanceof HTMLElement?(D&&D!==o&&!se&&D.remove(),D=o,se=!0):console.error(`[Relay] \`el\` ("${String(t.el)}") did not match any element — falling back to an auto-created host.`)}return(!D||!se&&!D.isConnected)&&(D=document.createElement("div"),D.id="relay-widget-root",document.body.appendChild(D),se=!1),!e&&t.height&&(D.style.height=t.height,D.style.width||(D.style.width="100%")),D}function Le(t){try{const e=t.launcher??!0;te==null||te(),te=null,ee==null||ee.close(),ee=null;const n=Gn(t,e);if(mt(t)&&!e&&be){Yn(t,n);return}ee=xt(Xn(t,n))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}async function Yn(t,e){const n=t.profileId??t.appId;if(!n&&!t.tenantId){console.error("[Relay] `inbox` requires `profileId` or `tenantId`.");return}e.innerHTML="";const o=document.createElement("div");o.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;background:#fff";const i=document.createElement("div");i.style.cssText="position:absolute;inset:0";const s=document.createElement("div");s.style.cssText="position:absolute;inset:0;display:none";const r=document.createElement("button");r.type="button",r.setAttribute("aria-label","Close"),r.textContent="✕",r.style.cssText="position:absolute;top:8px;right:8px;z-index:20;width:32px;height:32px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.05);border:none;color:#1c1b1a;font-size:16px;line-height:1;cursor:pointer",r.onclick=()=>{be=!1,Le(re)},o.append(i,s);const p=!ve&&!!n;p&&o.append(r),e.appendChild(o);let l=null,u=null;te=()=>{u==null||u.close(),l==null||l.close(),e.innerHTML=""};let f;try{({mountChatList:f}=await Promise.resolve().then(()=>si))}catch(v){console.error("[Relay] could not load the conversation list module.",v),i.isConnected&&(i.style.cssText+=";display:flex;align-items:center;justify-content:center;padding:16px;font:13px system-ui;color:#b91c1c;text-align:center",i.textContent="Could not load conversations.");return}if(!i.isConnected)return;const d=v=>{const k=v.profileId??n;if(!k){console.error("[Relay] conversation row has no chatroom; cannot open it.",v);return}r.style.display="none",u==null||u.close(),u=xt({el:s,url:t.url??Ge,...t.apiUrl?{apiUrl:t.apiUrl}:{},profileId:k,...v.kind==="direct"&&v.peerId?{kind:"direct",peerId:v.peerId}:v.subjectId?{subjectId:v.subjectId}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...t.userId||t.userName||t.userEmail||t.userAvatar?{user:{...t.userName?{name:t.userName}:{},...t.userEmail?{email:t.userEmail}:{},...t.userAvatar?{avatar:t.userAvatar}:{}}}:{},...v.subjectTitle?{subject:{title:v.subjectTitle,...v.subjectMeta?{subtitle:v.subjectMeta}:{}}}:{},...t.accent?{accent:t.accent}:{},launcher:!1,onBack:()=>{u==null||u.close(),u=null,s.style.display="none",i.style.display="",r.style.display="",l==null||l.refresh()}}),i.style.display="none",s.style.display=""};l=f({el:i,url:t.url??Ge,...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{profileId:n}:{},...t.tenantId?{tenantId:t.tenantId}:{},scope:t.inboxScope??"tenant",...p?{reserveCloseSpace:!0}:{},onSelect:d,onNewChat:()=>{const v=n??(l==null?void 0:l.defaultProfileId());v&&d({id:"__new__",profileId:v,state:"open",updatedAt:Date.now()})},...t.token?{token:t.token}:{},...t.userId?{userId:t.userId}:{},...t.accent?{accent:t.accent}:{}})}function bt(t){ve=!!(t.inboxStart&&!(t.launcher??!0)),be=ve,re={...t},Le(re)}function Jn(t){re={...re,...t},Le(re)}function Zn(){te==null||te(),te=null,ee==null||ee.close(),ee=null,D&&!se&&D.remove(),D=null,se=!1,be=!1,ve=!1,re={}}function Ye(t,e){switch(t){case"boot":bt(e??{});break;case"update":case"identify":Jn(e??{});break;case"shutdown":Zn();break;default:console.warn("[Relay] unknown command:",t)}}function Qn(){if(typeof document>"u")return null;const t=document.querySelector("script[data-relay-app]")??document.querySelector("script[data-relay-profile-id]")??document.querySelector("script[data-relay-tenant-id]"),e=t==null?void 0:t.dataset,n=(e==null?void 0:e.relayApp)??(e==null?void 0:e.relayProfileId),o=e==null?void 0:e.relayTenantId;if(!n&&!o)return null;const i=n?{profileId:n}:{};o&&(i.tenantId=o),e.relayUser&&(i.userId=e.relayUser),e.relayToken&&(i.token=e.relayToken),e.relayListing&&(i.listingId=e.relayListing),e.relayAccent&&(i.accent=e.relayAccent),e.relayAccent2&&(i.accent2=e.relayAccent2),e.relayTheme&&(i.theme=e.relayTheme),e.relayUrl&&(i.url=e.relayUrl);const s=e.relayPosition;(s==="bottom-left"||s==="bottom-right")&&(i.position=s),e.relayLauncherMessage&&(i.launcherMessage=e.relayLauncherMessage),e.relayLauncherSubtitle&&(i.launcherSubtitle=e.relayLauncherSubtitle),e.relayLauncher==="false"&&(i.launcher=!1),e.relayUserName&&(i.userName=e.relayUserName),e.relayUserEmail&&(i.userEmail=e.relayUserEmail),e.relayUserAvatar&&(i.userAvatar=e.relayUserAvatar),e.relayContextTitle&&(i.contextTitle=e.relayContextTitle),e.relayContextSubtitle&&(i.contextSubtitle=e.relayContextSubtitle),e.relayContextStatus&&(i.contextStatus=e.relayContextStatus),e.relayListingTitle&&(i.listingTitle=e.relayListingTitle),e.relayListingMeta&&(i.listingMeta=e.relayListingMeta),e.relayListingPrice&&(i.listingPrice=Number(e.relayListingPrice)),e.relayListingStatus&&(i.listingStatus=e.relayListingStatus),e.relayTarget&&(i.el=e.relayTarget),e.relayHeight&&(i.height=e.relayHeight),e.relayInbox==="true"&&(i.inbox=!0),e.relayInbox==="false"&&(i.inbox=!1),e.relayInboxStart==="true"&&(i.inboxStart=!0),e.relayInboxStart==="false"&&(i.inboxStart=!1);const r=e.relayInboxScope;return(r==="tenant"||r==="profile")&&(i.inboxScope=r),e.relayTranslateLang&&(i.translateLang=e.relayTranslateLang),i}if(typeof window<"u"){const t=window,e=t.Relay&&t.Relay.q?t.Relay.q:[];t.Relay=Ye;let n=!1;for(const o of e){const[i,s]=o;i==="boot"&&(n=!0),Ye(i,s)}if(!n){const o=t.relaySettings??Qn();o&&bt(o)}}const ei=`
193
+ .ocl { ${ft("ocl")}
191
194
  display:flex; flex-direction:column; height:100%; background:var(--ocl-bg);
192
- font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif; color:var(--ocl-ink); overflow:hidden; }
193
- .ocl-head { display:flex; align-items:center; padding:14px 16px 10px; background:var(--ocl-card); border-bottom:1px solid var(--ocl-line); }
195
+ font-family:var(--ocl-fb); color:var(--ocl-ink); overflow:hidden; }
196
+ @media (prefers-color-scheme: dark) { .ocl:not([data-theme="light"]) { ${Be("ocl")} } }
197
+ .ocl[data-theme="dark"] { ${Be("ocl")} }
198
+ .ocl-head { display:flex; align-items:center; padding:16px 16px 10px; background:var(--ocl-bg); }
194
199
  .ocl-title { flex:1; display:flex; align-items:center; color:var(--ocl-accent); }
195
200
  .ocl-title svg { width:24px; height:24px; display:block; }
196
- .ocl-retry { margin-top:14px; border:none; background:var(--ocl-accent); color:#fff; border-radius:20px; padding:8px 20px; font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
197
- .ocl-search-wrap { padding:8px 12px; background:var(--ocl-card); border-bottom:1px solid var(--ocl-line); }
198
- .ocl-search { width:100%; box-sizing:border-box; border:none; background:var(--ocl-bg); border-radius:20px; padding:8px 14px; font:inherit; font-size:14px; outline:none; }
201
+ .ocl-retry { margin-top:14px; border:none; background:var(--ocl-accent); color:var(--ocl-onaccent); border-radius:20px; padding:8px 20px; font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
202
+ .ocl-search-wrap { padding:4px 12px 8px; background:var(--ocl-bg); }
203
+ .ocl-search { width:100%; box-sizing:border-box; border:none; background:var(--ocl-tint); border-radius:20px; padding:9px 14px; font:inherit; font-size:14px; outline:none; }
199
204
  .ocl-body { flex:1; overflow-y:auto; }
200
- .ocl-section { padding:6px 16px 4px; font-size:11px; font-weight:700; color:var(--ocl-mut); text-transform:uppercase; letter-spacing:.5px; background:var(--ocl-bg); }
205
+ .ocl-section { padding:10px 18px 4px; font-family:var(--ocl-fh); font-size:11px; font-weight:600; color:var(--ocl-mut); text-transform:uppercase; letter-spacing:.5px; background:transparent; }
201
206
  .ocl-empty { padding:40px 20px; text-align:center; color:var(--ocl-mut); font-size:14px; }
202
- .ocl-row { display:flex; align-items:center; gap:12px; padding:11px 16px; background:var(--ocl-card); border:none; width:100%; text-align:left; cursor:pointer; border-bottom:1px solid var(--ocl-line); transition:background .1s; }
203
- .ocl-row:hover { background:#f7f5f2; }
204
- .ocl-row.unread { background:var(--ocl-card); }
205
- .ocl-av { width:46px; height:46px; border-radius:50%; background:var(--ocl-accent); color:#fff; font-size:18px; font-weight:700; display:flex; align-items:center; justify-content:center; flex:none; position:relative; }
206
- .ocl-dot { position:absolute; bottom:1px; right:1px; width:12px; height:12px; border-radius:50%; border:2px solid var(--ocl-card); background:var(--ocl-mut); }
207
- .ocl-dot.open { background:#22c55e; }
208
- .ocl-dot.waiting { background:#f59e0b; }
207
+ .ocl-row { display:flex; align-items:center; gap:12px; padding:10px 12px; margin:6px 12px; background:var(--ocl-tint); border:none; width:calc(100% - 24px); box-sizing:border-box; border-radius:16px; text-align:left; cursor:pointer; transition:background .12s; }
208
+ .ocl-row:hover { background:var(--ocl-rowhover); }
209
+ .ocl-row.unread { background:var(--ocl-rowhover); }
210
+ .ocl-av { width:40px; height:40px; border-radius:50%; background:var(--ocl-accent); color:var(--ocl-onaccent); font-family:var(--ocl-fh); font-size:15px; font-weight:600; display:flex; align-items:center; justify-content:center; flex:none; }
209
211
  .ocl-info { flex:1; min-width:0; }
210
- .ocl-name { font-size:15px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-bottom:2px; }
212
+ .ocl-name { font-family:var(--ocl-fh); font-size:14px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-bottom:2px; }
211
213
  .ocl-row.unread .ocl-name { font-weight:700; }
212
- .ocl-preview { font-size:13px; color:var(--ocl-mut); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
214
+ .ocl-preview { font-size:11.5px; color:var(--ocl-mut); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
213
215
  .ocl-row.unread .ocl-preview { color:var(--ocl-ink); }
214
216
  .ocl-right { display:flex; flex-direction:column; align-items:flex-end; gap:4px; flex:none; }
215
- .ocl-time { font-size:11px; color:var(--ocl-mut); }
217
+ .ocl-time { font-size:10px; color:var(--ocl-mut); }
216
218
  .ocl-row.unread .ocl-time { color:var(--ocl-accent); font-weight:600; }
217
- .ocl-badge { background:var(--ocl-accent); color:#fff; border-radius:999px; font-size:11px; font-weight:700; min-width:20px; height:20px; padding:0 5px; display:flex; align-items:center; justify-content:center; }
219
+ .ocl-badge { background:var(--ocl-accent); color:var(--ocl-onaccent); border-radius:999px; font-size:11px; font-weight:700; min-width:20px; height:20px; padding:0 5px; display:flex; align-items:center; justify-content:center; }
220
+ .ocl-status { font-size:10px; font-weight:600; padding:2px 8px; border-radius:20px; white-space:nowrap; }
221
+ .ocl-status.open { background:#dff3e6; color:#2f8a52; }
222
+ .ocl-status.waiting { background:var(--ocl-tint); color:var(--ocl-accent); border:1px solid var(--ocl-accent); }
223
+ .ocl-status.done { background:#eee; color:#777; }
224
+ .ocl[data-theme="dark"] .ocl-status.done { background:#39325e; color:#b3abd6; }
225
+ @media (prefers-color-scheme: dark) { .ocl:not([data-theme="light"]) .ocl-status.done { background:#39325e; color:#b3abd6; } }
218
226
  .ocl-spinner { padding:24px; text-align:center; color:var(--ocl-mut); font-size:13px; }
219
- .ocl-compose { border:none; background:var(--ocl-bg); color:var(--ocl-ink); width:32px; height:32px; border-radius:50%; font-size:15px; cursor:pointer; }
220
- .ocl-compose:hover { background:var(--ocl-line); }
227
+ .ocl-compose { border:none; background:var(--ocl-accent); color:var(--ocl-onaccent); width:32px; height:32px; border-radius:50%; font-size:18px; line-height:1; cursor:pointer; box-shadow:var(--ocl-shadow); }
228
+ .ocl-compose:hover { filter:brightness(1.08); }
221
229
  /* When the HOST overlays a ✕ (ChatApp's onClose / embed's inbox stack), it is
222
230
  absolutely positioned at top-right and used to land straight on top of the ✎
223
231
  compose button. Reserve the space instead of stacking them. */
224
232
  .ocl-has-close .ocl-head { padding-right:52px; }
225
- .ocl-start { margin-top:12px; border:none; background:var(--ocl-accent); color:#fff; border-radius:20px; padding:8px 18px; font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
233
+ .ocl-start { margin-top:12px; border:none; background:var(--ocl-accent); color:var(--ocl-onaccent); border-radius:20px; padding:8px 18px; font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
226
234
  /* Compact sizing keyed on the LIST'S OWN width (ResizeObserver toggles
227
235
  * .ocl-compact below 400px) — covers phones and narrow desktop embeds alike.
228
236
  * Search must be ≥16px in compact or iOS zooms the page on focus. */
229
237
  .ocl-compact .ocl-row { padding:13px 14px; }
230
238
  .ocl-compact .ocl-search { font-size:16px; }
231
239
  .ocl-compact .ocl-compose { width:36px; height:36px; }
232
- `;function Zn(n){const e=n.token??n.userId??et(),{httpBase:t,wsUrl:o}=Ve(n.url,n.apiUrl),i=n.i18n??{},s=n.accent??"#4F63F5";if(!document.getElementById("ocl-styles")){const m=document.createElement("style");m.id="ocl-styles",m.textContent=Jn,document.head.append(m)}const r=A("div","ocl");r.style.setProperty("--ocl-accent",s),n.reserveCloseSpace&&r.classList.add("ocl-has-close");const p=A("div","ocl-head"),c=A("span","ocl-title");if(c.setAttribute("role","img"),c.setAttribute("aria-label",i.title??"Messages"),c.innerHTML=Yn,p.append(c),n.onNewChat){const m=A("button","ocl-compose","✎");m.title=i.newChat??"New conversation",m.addEventListener("click",()=>n.onNewChat()),p.append(m)}const u=A("div","ocl-search-wrap"),y=A("input","ocl-search");y.placeholder=i.search??"🔍 Search",y.type="search",u.append(y);const d=A("div","ocl-body");d.append(A("div","ocl-spinner","Loading…")),r.append(p,u,d),n.el.replaceChildren(r);const f=m=>{r.classList.toggle("ocl-compact",m>0&&m<400)};f(r.clientWidth);let w=null;if(typeof ResizeObserver<"u"&&(w=new ResizeObserver(m=>{var M;return f(((M=m[0])==null?void 0:M.contentRect.width)??r.clientWidth)}),w.observe(r)),!n.profileId&&!n.tenantId)throw new Error("[relay chatlist] provide profileId or tenantId");let C;const v=`ocl_seen_${n.profileId??`t_${n.tenantId}`}_${(n.userId??e).slice(-8)}`;let g={};try{g=JSON.parse(localStorage.getItem(v)??"{}")}catch{}const I=()=>{try{localStorage.setItem(v,JSON.stringify(g))}catch{}};let E=[],L=!1;const T=async()=>{const m=n.profileId?`profileId=${encodeURIComponent(n.profileId)}${n.scope==="tenant"?"&scope=tenant":""}`:`tenantId=${encodeURIComponent(n.tenantId)}`,M=`${t}/conversations/mine?${m}`,q={authorization:`Bearer ${e}`};let G;try{G=await fetch(M,{headers:q})}catch{G=await fetch(M,{headers:q})}if(!G.ok)return[];const F=await G.json();return F.defaultProfileId&&(C=F.defaultProfileId),(F.conversations??[]).sort((Y,U)=>U.updatedAt-Y.updatedAt)},H=(m,M)=>{if(L)return;const q=M?m.filter(U=>D(U).toLowerCase().includes(M)||(U.lastMessage??"").toLowerCase().includes(M)):m;if(d.replaceChildren(),!q.length){const U=A("div","ocl-empty",M?"No results.":i.empty??"No conversations yet.");if(!M&&n.onNewChat){U.append(A("br"));const z=A("button","ocl-start",i.newChat??"Start a conversation");z.addEventListener("click",()=>n.onNewChat()),U.append(z)}d.append(U);return}const G=U=>(U.lastSeq??0)>(g[U.id]??0),F=q.filter(G),Y=q.filter(U=>!G(U));if(F.length){d.append(A("div","ocl-section",`${i.unread??"Unread"} (${F.length})`));for(const U of F)d.append(W(U,G(U)))}if(Y.length){d.append(A("div","ocl-section",F.length?i.all??"All conversations":""));for(const U of Y)d.append(W(U,!1))}},D=m=>m.subjectTitle??(m.kind==="direct"?m.peerId??"Direct message":"General enquiry"),W=(m,M)=>{var Se;const q=D(m),G=(((Se=q.match(new RegExp("\\p{L}","u")))==null?void 0:Se[0])??q.trim()[0]??"?").toUpperCase(),F=m.lastSeq??0,Y=M?Math.max(1,F-(g[m.id]??0)):0,U=A("button",`ocl-row${M?" unread":""}`),z=A("div","ocl-av",G),he=A("div","ocl-dot");m.state==="open"?he.classList.add("open"):m.state==="awaiting_staff"&&he.classList.add("waiting"),z.append(he),U.append(z);const ke=A("div","ocl-info");ke.append(A("div","ocl-name",q));const ae={open:"Open",awaiting_staff:"Waiting for reply…",resolved:"Resolved ✓",closed:"Closed"};ke.append(A("div","ocl-preview",m.lastMessage??ae[m.state]??m.state)),U.append(ke);const te=A("div","ocl-right");return te.append(A("div","ocl-time",Gn(m.updatedAt))),Y>0&&te.append(A("div","ocl-badge",String(Y>99?"99+":Y))),U.append(te),U.addEventListener("click",()=>{var Ce;F>0&&(g[m.id]=F,I()),U.classList.remove("unread"),(Ce=te.querySelector(".ocl-badge"))==null||Ce.remove(),n.onSelect(m)}),U},ee=()=>{L||T().then(m=>{L||(E=m,H(m,y.value.trim().toLowerCase()))}).catch(m=>{if(L)return;console.error(`[chat-widget] failed to load conversations from ${t}/conversations/mine — check the apiUrl/CORS config.`,m);const M=A("div","ocl-empty",i.error??"Could not load conversations.");M.append(A("br"));const q=A("button","ocl-retry",i.retry??"Retry");q.addEventListener("click",()=>{d.replaceChildren(A("div","ocl-spinner","Loading…")),ee()}),M.append(q),d.replaceChildren(M)})};y.addEventListener("input",()=>H(E,y.value.trim().toLowerCase())),ee();let k=null,$,b,P=0,N=!1;const ve=()=>{b||(b=setTimeout(()=>{b=void 0,ee()},300))},de=()=>{if(!L){try{k=new WebSocket(o)}catch{Me();return}k.binaryType="arraybuffer",k.onopen=()=>{P=0,k.send(Fe({type:"auth",token:e})),k.send(Fe({type:"subscribe_inbox"})),N&&ve(),N=!0},k.onmessage=m=>{const M=rt(new Uint8Array(m.data));M&&M.type==="inbox_event"&&ve()},k.onclose=()=>{k=null,Me()},k.onerror=()=>{try{k==null||k.close()}catch{}}}},Me=()=>{if(L||$)return;const m=Math.min(15e3,500*2**P++)+Math.random()*250;$=setTimeout(()=>{$=void 0,de()},m)};return de(),{refresh:ee,close(){L=!0,$&&clearTimeout($),b&&clearTimeout(b),w==null||w.disconnect(),w=null;try{k==null||k.close()}catch{}k=null,n.el.replaceChildren()},defaultProfileId(){return n.profileId??C}}}const Qn=Object.freeze(Object.defineProperty({__proto__:null,mountChatList:Zn},Symbol.toStringTag,{value:"Module"}));return J.Relay=Ge,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"}),J}({});
240
+ .ocl-row:focus-visible, .ocl button:focus-visible, .ocl input:focus-visible { outline:2px solid var(--ocl-accent); outline-offset:2px; border-radius:12px; }
241
+ `;function ti(t){switch(t){case"open":return{label:"Open",cls:"open"};case"awaiting_staff":return{label:"Waiting on you",cls:"waiting"};case"resolved":return{label:"Resolved",cls:"done"};case"closed":return{label:"Closed",cls:"done"};default:return null}}function ni(t){const e=Math.floor((Date.now()-t)/1e3);if(e<60)return"just now";if(e<3600)return`${Math.floor(e/60)}m`;if(e<86400)return`${Math.floor(e/3600)}h`;const n=Math.floor(e/86400);if(n<=7)return`${n}d`;try{return new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return`${n}d`}}const ii='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" fill-opacity="0.12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function B(t,e,n){const o=document.createElement(t);return e&&(o.className=e),n!==void 0&&(o.textContent=n),o}function oi(t){const e=t.token??t.userId??tt(),{httpBase:n,wsUrl:o}=Xe(t.url,t.apiUrl),i=t.i18n??{},s=t.accent??"#6c5ce7";if(!document.getElementById("ocl-styles")){const S=document.createElement("style");S.id="ocl-styles",S.textContent=ei,document.head.append(S)}const r=B("div","ocl");r.style.setProperty("--ocl-accent",s),t.theme&&t.theme!=="auto"&&(r.dataset.theme=t.theme),t.reserveCloseSpace&&r.classList.add("ocl-has-close");const p=B("div","ocl-head"),l=B("span","ocl-title");if(l.setAttribute("role","img"),l.setAttribute("aria-label",i.title??"Messages"),l.innerHTML=ii,p.append(l),t.onNewChat){const S=B("button","ocl-compose","✎");S.title=i.newChat??"New conversation",S.addEventListener("click",()=>t.onNewChat()),p.append(S)}const u=B("div","ocl-search-wrap"),f=B("input","ocl-search");f.placeholder=i.search??"🔍 Search",f.type="search",u.append(f);const d=B("div","ocl-body");d.append(B("div","ocl-spinner","Loading…")),r.append(p,u,d),t.el.replaceChildren(r);const v=S=>{r.classList.toggle("ocl-compact",S>0&&S<400)};v(r.clientWidth);let k=null;if(typeof ResizeObserver<"u"&&(k=new ResizeObserver(S=>{var M;return v(((M=S[0])==null?void 0:M.contentRect.width)??r.clientWidth)}),k.observe(r)),!t.profileId&&!t.tenantId)throw new Error("[relay chatlist] provide profileId or tenantId");let L;const z=`ocl_seen_${t.profileId??`t_${t.tenantId}`}_${(t.userId??e).slice(-8)}`;let g={};try{g=JSON.parse(localStorage.getItem(z)??"{}")}catch{}const w=()=>{try{localStorage.setItem(z,JSON.stringify(g))}catch{}};let U=[],C=!1;const x=async()=>{const S=t.profileId?`profileId=${encodeURIComponent(t.profileId)}${t.scope==="tenant"?"&scope=tenant":""}`:`tenantId=${encodeURIComponent(t.tenantId)}`,M=`${n}/conversations/mine?${S}`,H={authorization:`Bearer ${e}`};let G;try{G=await fetch(M,{headers:H})}catch{G=await fetch(M,{headers:H})}if(!G.ok)return[];const F=await G.json();return F.defaultProfileId&&(L=F.defaultProfileId),(F.conversations??[]).sort((Y,I)=>I.updatedAt-Y.updatedAt)},b=(S,M)=>{if(C)return;const H=M?S.filter(I=>_(I).toLowerCase().includes(M)||(I.lastMessage??"").toLowerCase().includes(M)):S;if(d.replaceChildren(),!H.length){const I=B("div","ocl-empty",M?"No results.":i.empty??"No conversations yet.");if(!M&&t.onNewChat){I.append(B("br"));const ae=B("button","ocl-start",i.newChat??"Start a conversation");ae.addEventListener("click",()=>t.onNewChat()),I.append(ae)}d.append(I);return}const G=I=>(I.lastSeq??0)>(g[I.id]??0),F=H.filter(G),Y=H.filter(I=>!G(I));if(F.length){d.append(B("div","ocl-section",`${i.unread??"Unread"} (${F.length})`));for(const I of F)d.append(R(I,G(I)))}if(Y.length){d.append(B("div","ocl-section",F.length?i.all??"All conversations":""));for(const I of Y)d.append(R(I,!1))}},_=S=>S.subjectTitle??(S.kind==="direct"?S.peerId??"Direct message":"General enquiry"),R=(S,M)=>{var Se;const H=_(S),G=(((Se=H.match(new RegExp("\\p{L}","u")))==null?void 0:Se[0])??H.trim()[0]??"?").toUpperCase(),F=S.lastSeq??0,Y=M?Math.max(1,F-(g[S.id]??0)):0,I=B("button",`ocl-row${M?" unread":""}`),ae=B("div","ocl-av",G);I.append(ae);const ke=B("div","ocl-info");ke.append(B("div","ocl-name",H));const ce={open:"Open",awaiting_staff:"Waiting for reply…",resolved:"Resolved ✓",closed:"Closed"};ke.append(B("div","ocl-preview",S.lastMessage??ce[S.state]??S.state)),I.append(ke);const Z=B("div","ocl-right");Z.append(B("div","ocl-time",ni(S.updatedAt)));const pe=ti(S.state);return pe&&Z.append(B("div",`ocl-status ${pe.cls}`,pe.label)),Y>0&&Z.append(B("div","ocl-badge",String(Y>99?"99+":Y))),I.append(Z),I.addEventListener("click",()=>{var Ie;F>0&&(g[S.id]=F,w()),I.classList.remove("unread"),(Ie=Z.querySelector(".ocl-badge"))==null||Ie.remove(),t.onSelect(S)}),I},j=()=>{C||x().then(S=>{C||(U=S,b(S,f.value.trim().toLowerCase()))}).catch(S=>{if(C)return;console.error(`[chat-widget] failed to load conversations from ${n}/conversations/mine — check the apiUrl/CORS config.`,S);const M=B("div","ocl-empty",i.error??"Could not load conversations.");M.append(B("br"));const H=B("button","ocl-retry",i.retry??"Retry");H.addEventListener("click",()=>{d.replaceChildren(B("div","ocl-spinner","Loading…")),j()}),M.append(H),d.replaceChildren(M)})};f.addEventListener("input",()=>b(U,f.value.trim().toLowerCase())),j();let m=null,P,O,T=0,N=!1;const J=()=>{O||(O=setTimeout(()=>{O=void 0,j()},300))},he=()=>{if(!C){try{m=new WebSocket(o)}catch{Me();return}m.binaryType="arraybuffer",m.onopen=()=>{T=0,m.send(Fe({type:"auth",token:e})),m.send(Fe({type:"subscribe_inbox"})),N&&J(),N=!0},m.onmessage=S=>{const M=at(new Uint8Array(S.data));M&&M.type==="inbox_event"&&J()},m.onclose=()=>{m=null,Me()},m.onerror=()=>{try{m==null||m.close()}catch{}}}},Me=()=>{if(C||P)return;const S=Math.min(15e3,500*2**T++)+Math.random()*250;P=setTimeout(()=>{P=void 0,he()},S)};return he(),{refresh:j,close(){C=!0,P&&clearTimeout(P),O&&clearTimeout(O),k==null||k.disconnect(),k=null;try{m==null||m.close()}catch{}m=null,t.el.replaceChildren()},defaultProfileId(){return t.profileId??L}}}const si=Object.freeze(Object.defineProperty({__proto__:null,mountChatList:oi},Symbol.toStringTag,{value:"Module"}));return Q.Relay=Ye,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"}),Q}({});
233
242
  //# sourceMappingURL=embed.js.map